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/)
unsigned int *data, *end;
data = (unsigned int *)qimage->bits();
end = data + (qim->width() * qim->height());
InlineHSV hsv;
while(data < end){
// convert pixel to HSV
hsv.convertRGB2HSV(BlitzPrivate::convertFromPremult(*data));
// change H, S or V as needed
hsv.setSaturation(somethingBasedOn(hsv.saturation());
// and back to RGB
hsv.convertHSV2RGB();
(*data) = BlitzPrivate::convertToPremult(qRgba(hsv.red(), hsv.green(),
hsv.blue(), qAlpha(*data)));
data++;
}
unsigned int *data, *end;
data = (unsigned int *)qimage->bits();
end = data + (qim->width() * qim->height());
InlineHSV hsv;
while(data < end){
// convert pixel to HSV
hsv.convertRGB2HSV(BlitzPrivate::convertFromPremult(*data));
// change H, S or V as needed
hsv.setSaturation(somethingBasedOn(hsv.saturation());
// and back to RGB
hsv.convertHSV2RGB();
(*data) = BlitzPrivate::convertToPremult(qRgba(hsv.red(), hsv.green(),
hsv.blue(), qAlpha(*data)));
data++;
}
To copy to clipboard, switch view to plain text mode
Bookmarks