Add new comment

What to do with rgb_cam matrix

I'm confused about how to apply the conversion matrix given by rd.color.rgb_cam. Here's the sequence of what I do:

-Load the raw pixel values with libraw_unpack(rd)
-Subtract the black levels and normalise to 1.0
-Multiply each pixel by its bayer filter colour times 2 for green and times 4 for red/blue
-Debayer roughly but ultra simply using a half pixel by half pixel shift
-Do the matrix multiplication with rd->color.rgb_cam
-Apply the camera's rd->color.cam_mul white balance correction, or whatever white balance the user sees fit

At that point I'd expect good colours, but instead I get a very yellow image. What's strange is that if I reverse the last two steps by applying the white balance before the matrix multiplication then I get good colours except in the clipped highlights that turn dark purple. But it doesn't make sense that something arbitrary like white balance should be done before something fixed like colour space conversion. But still it seems like there should be something somewhat similar to white balance being done before the matrix multiplication to bring the colours to the illuminant expected by the colour space conversion, but what exactly?

I tried figuring out what LibRaw does about that when running libraw_dcraw_process() but it's a bit hard to follow what it does with matrices, explanations would be most welcome.

Forums: