I am looking for the math behind how to calculate the gain factors for each channel after capturing an image with wrong white balance factors (basically I want to feed this information back to the camera API).
Not quite sure whether CAT (Chromatic Adaptation Transform) applies here or something else given the fact that a camera has "no concrete idea" about the illuminant in the scene (outdoor, indoor, fluorescent, tungesten...etc.). However, when selecting a gray/white point on the camera screen to calculate white balance it gets it right and that is what I am looking for.
PS: I assume also that the camera is not doing calculation over the entire set of image's pixels but rather only a small region of interest what the user/eyedropper selected.