View Full Version : Changing brightness & contrast of image with alpha channel

24th March 2011, 19:37
I have the ability to change the brightness & contrast of my grayscale images by changing the 256 entries of the color map (setColorTable()). However, setColorTable() has no effect on an image that hasAlphaChannel(). In the case of hasAlphaChannel() and before setColorTable(), colorTable() returns a valid vector and all of the alpha components are set to opaque even though the image is clearly displayed with transparent. After calling setColorTable(), the colorTable() has the updated values, but the image looks the same. I am sure this is something simple and thank you in advance for your help.

25th March 2011, 02:33
That only works in case of monochrome and 8-bit images. You may use pixel() and setPixel() to manipulate RGB or RGBA image instead of colorTable() and setColorTable().

25th March 2011, 03:25
The images that works on is gray-8 with 256 "colors". The images that it does not work on is gray-8+alpha which still only has 256 "colors". I would think that it still apply the color map before and'ing with the alpha mask before or'ing to the scene (basically, not exactly). Getting and setting pixels would be way too expensive as they are rather large images. Thank you for your reply and I hope to hear more ideas soon.

25th March 2011, 06:08
If the format is QImage::Format_Indexed8 (8-bit indexed), setColorTable() work perfectly no matter the image has alpha channel or not.

25th March 2011, 16:33
The images that work were created with PNG_COLOR_TYPE_GRAY and the ones that do not PNG_COLOR_TYPE_GRAY_ALPHA. In terms of what Qt sees:
SIMILARITIES: allGray=isGrayScale=true, colorCount=numColors=256
DIFFERENCES (respectively): hasAlphaChannel = false & true, bitPlaneCount = 8 & 32, format = Format_Indexed8 & Format_ARGB32

So, I am wondering if it is possible to have Format_Indexed8 with 8 bitPlaneCount, yet hasAlphaChannel (not just an alpha within the color map).