I don't understand why I get only 2 components data in all pixels
I tried to find some topic that already exists, and describes this problem, but I did not find one. Therefore, I decided to create this topic to seek help. I have a CR2 raw file, and I just want to get the raw pixel values, without "demosaic". Here is my source code so far:
int main() { char* image_path = "../../assets/example_images/IMG_8117.CR2"; libraw_data_t *libraw = libraw_init(0); libraw->rawparams.use_rawspeed = 1; int open_status = libraw_open_file(libraw, image_path); if (open_status != LIBRAW_SUCCESS) { printf("Failed to open\n"); exit(1); } int unpack_status = libraw_unpack(libraw); if (unpack_status != LIBRAW_SUCCESS) { printf("Failed to unpack\n"); exit(1); } int rawimage_status = libraw_raw2image(libraw); if (rawimage_status != LIBRAW_SUCCESS) { printf("Failed to rawimage\n"); exit(1); } int i = 0; int j = 0; ushort width = libraw->sizes.width; ushort height = libraw->sizes.height; for(; i < height; i++) { for(; j < width; j++) { int color = libraw_COLOR(libraw, i, j); char cname = libraw->idata.cdesc[color]; ushort v1 = libraw->image[(i * width) + j][0]; ushort v2 = libraw->image[(i * width) + j][1]; ushort v3 = libraw->image[(i * width) + j][2]; ushort v4 = libraw->image[(i * width) + j][3]; printf("Color: %c, A=%d B=%d C=%d D=%d\n", cname, v1, v2, v3, v4); } } printf("Width: %d | Height: %d\n", width, height); printf("Size: %d | Index: %d\n", total_size, i); return 0; }
I can execute libraw_init
, libraw_unpack
and libraw_raw2image
successfully. When I look at libraw->idata.colors
I get 3, and when I look at libraw->idata.cdesc
I get "RGBG".
The problem is that, inside my doubly-nested for loop, the libraw_COLOR
function return only 0 (RED) and 1 (GREEN) for all pixels in libraw->image
. I would expect to get the value 2 (which represents BLUE) in some of the pixels, to represent the blue channel of the image. Why I'm getting only RED and GREEN values in the pixels? Is my for loop wrong?
Recent comments