I'm reading a DNG file on Android with libraw in C++ which works pretty fine. I want to pass the pixel data to Cimg for manipulation purposes (rotating etc.).
The problem is that the image in Cimg looks weird. I think that problem is that the original pixel data from libraw are stored in a different order than in Cimg. In libraw (due to the DNG file) its RGBGRGBGRGBG while Cimg stores the pixel data in the way RRRRRR....GGGGGGG....BBBBBB. Does anyone know how to convert from RGBGRGBGRGBG to RRRRRR....GGGGGGG....BBBBBB?
Here are both images, on the left is dng file and on the right is tiff file exported from cimg (both imported into Photoshop).
Here is my code:
LibRaw rawProcessor;
rawProcessor.open_file("file.dng");
rawProcessor.unpack();
int ret2=rawProcessor.dcraw_process();
libraw_processed_image_t* image = rawProcessor.dcraw_make_mem_image(&ret2);
float xres=72.0;
CImg<unsigned char> cimgOriginal(image->data,image->width,image->height, true);
cimgOriginal.shift(10*(-1), 10*(-1),0,0,0);
cimgOriginal.rotate(360.0-5, (float) 1200, (float) 800,0,0);
cimgOriginal.save_tiff("file.tiff", 0, &xres,0,false);
Thanks!
Mike



librawstores pixels in "packed" (a.k.a. "interleaved") format. So a 3x2 image will be stored like this:CImg, on the other hand, stores pixels in "planar" format, which bunches all the red pixels together in a plane, followed by all the green, then all the blue ones. So that same 3x2 image will be stored like this:I haven't done any C++ for years, so my code will be shockingly awful quality, but it does work at least:
Compiled on Raspberry Pi OS with:
I tested it by downloading the first DNG sample picture from Ken Rockwell, here.