I'm doing white balance scaling on the raw data I've retrieved based on the values in imgdata.color.pre_mul
Processing data from a Pentax K-5 I'm seeing the following in pre_mul after calling unpack():
White balance co-efficients being used are 2.155461, 0.926686, 1.305787, 0.000000
I'm slightly surprised to see that a) the second value isn't 1.0, and b) that the fourth value is zero.
Based on what I saw in your scale_colors() code, I think that this is what I need to do to get the scaling right based on processing an image array containing only the image data (less left and top margins) copied from imgdata.rawdata.raw_image and with dark subtraction performed.
unsigned maximum = C.maximum - dark; double dmin, dmax; int c = 0; for (dmin = DBL_MAX, dmax = c = 0; c < 4; c++) { if (dmin > pre_mul[geshifilter-c]) dmin = pre_mul[c]; if (dmax < pre_mul[c]) dmax = pre_mul[c]; } float scale_mul[4]; for (c = 0; c < 4; c++) scale_mul[c] = (pre_mul[c] /= dmax) * 65535.0 / maximum; if (0 == scale_mul[3]) scale_mul[3] = scale_mul[1]; ZTRACE_RUNTIME("Maximum value pixel has value %d", maxval); ZTRACE_RUNTIME("Saturation level is %d", C.maximum); ZTRACE_RUNTIME("Applying linear stretch to raw data. Scale values %f, %f, %f, %f", scale_mul[0], scale_mul[1], scale_mul[2], scale_mul[3]); for (row = 0; row < S.height; row++) { for (col = 0; col < S.width; col++) { // What colour will this pixel become register int colour = rawProcessor.COLOR(row, col); register float val = scale_mul[colour] * (float)(RAW(row, col)); RAW(row, col) = max(0, min(int(val), 65535)); } } [/geshifilter-cpp] Is that correct, or have I missed something? I'm applying this scaling to the image data before de-Bayer processing as doing it this way fits with the structure of the existing code. Thanks
Well that's a bitch something
Well that's a bitch something munged up the code I was requesting a sanity check on.
However it was (it turns out) mostly correct. Though I changed the scale_mul calculation to use dmin instead of dmax.
Cheers
David Partridge