Equivalent of scale_colors() for raw_image

I'm starting a new thread for this.

AFAICT the difference between dcraw -d and dcraw -D isn't just black subraction. It would seem the dcraw-d calls scale_colors() on the image.

This appears to operates on an (internal?) 4 component image array rather than on the single component raw_image and the code is (to say the least) somewhat complex.

I'm not an expert on image processing - just trying to convert some existing code to use libraw instead of the orphaned dcraw, so can you recommend how best to scale the raw image in this case.

Sorry if I'm being a pain.



1) subtracts black
2)applies white balance
3) scales values to 0...65535 range

-- Alex Tutubalin

Yes, I can read the code well

Yes, I can read the code well enough to understand the basics of what scale_colors does to the de-Bayered 4 colour image array. My problem is to understand the code well enough to perform a "correct" transform on the raw_image array. As an example, it really is not clear what the gory details of the six component cblack array processing are - IOW why you don't/can't just subtract the basic black level and what the algorithm being used is precisely and so on. I'm sure that Dave Coffin and you are real experts on image processing, and fully understand the code and algorithms without needing lots of comments to understand the code in detail - we mere mortals struggle to grok such dense and relatively uncommented code.

Without that information I can only apply a trivial subtraction of the basic black level value from all the raw_image values and then scale linearly from 0- 65535! Clearly I cannot do any white balance calculation on the raw image as that requires that the data is already converted to 4 component RGB (does that mean it is LRGB?), and that I have access to the camera white balance data (unless doing "auto wb").


David Partridge

black level data in LibRaw

black level data in LibRaw (and dcraw) is split into several pieces
color.black - 'base' black level (common for all channels)
color.cblack[0..3] - per channel level
color.cblack[6...] - pattern level for cblack[4] x cblack[5] pattern.

I did not understand your comments regarding white balance.

BTW, if you want to *only* replace de-bayer with your own code, but do not want to know other raw processing details (black level/bias, white balance, scaling, color profiles, etc, etc, etc)
than you may provide your own demosaic via callbacks.interpolate_bayer_cb
Your callback will be called instead pre-defined demosaic(s) built-in in LibRaw, while other processing steps will be called in sequence.
You may use LibRaw::lin_interpolate() code as an example.

-- Alex Tutubalin