White balance scaling and values in pre_mul array

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])&#10;						dmin = pre_mul[c];&#10;					if (dmax &lt; pre_mul[c])&#10;						dmax = pre_mul[c];&#10;				}&#10;&#10;				float scale_mul[4];&#10;&#10;				for (c = 0; c &lt; 4; c++) scale_mul[c] = (pre_mul[c] /= dmax) * 65535.0 / maximum;&#10;				if (0 == scale_mul[3]) scale_mul[3] = scale_mul[1];&#10;&#10;				ZTRACE_RUNTIME(&quot;Maximum value pixel has value %d&quot;, maxval);&#10;				ZTRACE_RUNTIME(&quot;Saturation level is %d&quot;, C.maximum);&#10;				ZTRACE_RUNTIME(&quot;Applying linear stretch to raw data.  Scale values %f, %f, %f, %f&quot;,&#10;					scale_mul[0], scale_mul[1], scale_mul[2], scale_mul[3]);&#10;&#10;				for (row = 0; row &lt; S.height; row++)&#10;				{&#10;					for (col = 0; col &lt; S.width; col++)&#10;					{&#10;						// What colour will this pixel become&#10;						register int colour = rawProcessor.COLOR(row, col);&#10;&#10;						register float val = scale_mul[colour] *&#10;							(float)(RAW(row, col));&#10;						RAW(row, col) = max(0, min(int(val), 65535));&#10;&#10;					}&#10;				}&#10;[/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

Forums: 

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