The problem is in changing the RGB values so that the white balance stays the same, as the system is not linear. I think this is best done in HSV space. A code snipped for doing pixel value conversion using qimageblitz (http://api.kde.org/kdesupport-api/kd...ageblitz/html/)
Qt Code:
  1. unsigned int *data, *end;
  2. data = (unsigned int *)qimage->bits();
  3. end = data + (qim->width() * qim->height());
  4. InlineHSV hsv;
  5. while(data < end){
  6. // convert pixel to HSV
  7. hsv.convertRGB2HSV(BlitzPrivate::convertFromPremult(*data));
  8. // change H, S or V as needed
  9. hsv.setSaturation(somethingBasedOn(hsv.saturation());
  10. // and back to RGB
  11. hsv.convertHSV2RGB();
  12. (*data) = BlitzPrivate::convertToPremult(qRgba(hsv.red(), hsv.green(),
  13. hsv.blue(), qAlpha(*data)));
  14. data++;
  15. }
To copy to clipboard, switch view to plain text mode