1 | initial version |
if you intent to fill buffer with an image file (jpeg, png etc..) you need to use imdecode (probably the best thing to do because in this case you do not have to manage the colorspace of the input image imdecode did it for you if you use it wth IMREAD_COLOR (BGR colospace) or IMREAD_GRAYSCALE flag). then use cvtColor with the image from imdecode.
if you intent to fill buffer with raw pixel data you need more informations to use cvtColor, you need a 2d Mat so you need cols size and rows size. then you need to know the number of channels to use the good opencv datatype Flag (CV_8UC1-2-3-4) finaly you need to know in wich colospace is the input image (RGB? BGR? RGBa?) and manage all possible case.( and there is a lot of case.......)
to construct the image juste use mat constructor as follow Mat Image = Mat(ImageRows, ImageCols, CV_8UC4, buffer);// here image have 4 channels so you have to use CV_8UC4
then to return a result you have 2 options : java own the memory so you have to compute and allocate final image size inside java and give output buffer to c++. c++ own the memory so you have to allocate it in c++ but be very carrefull to memory clear and memory leak.