In Version 30.0.1558.0 canary, creating a webgl RGBA 8888 framebuffer and gl.teximage2d loading it with an image with alpha channel (not premultiplied), and then reading it back using gl.readpixels, causes the image to have different color values.
I've attached a jsfiddle url to support it.
For at small 4x4 image this is the console log:
compare (index):84
pixels differ at 0 1 channel 0 v1:65 v2:64 (index):95
pixels differ at 0 1 channel 1 v1:65 v2:64 (index):95
pixels differ at 0 1 channel 2 v1:65 v2:64 (index):95
pixels differ at 1 1 channel 0 v1:65 v2:64 (index):95
pixels differ at 1 1 channel 1 v1:65 v2:64 (index):95
pixels differ at 1 1 channel 2 v1:65 v2:64 (index):95
pixels differ at 2 1 channel 0 v1:65 v2:64 (index):95
pixels differ at 2 1 channel 1 v1:65 v2:64 (index):95
pixels differ at 2 1 channel 2 v1:65 v2:64 (index):95
pixels differ at 3 1 channel 0 v1:65 v2:64 (index):95
pixels differ at 3 1 channel 1 v1:65 v2:64 (index):95
pixels differ at 3 1 channel 2 v1:65 v2:64 (index):95
pixels differ at 0 3 channel 0 v1:191 v2:190 (index):95
pixels differ at 0 3 channel 1 v1:191 v2:190 (index):95
pixels differ at 0 3 channel 2 v1:191 v2:190 (index):95
pixels differ at 1 3 channel 0 v1:191 v2:190 (index):95
pixels differ at 1 3 channel 1 v1:191 v2:190 (index):95
pixels differ at 1 3 channel 2 v1:191 v2:190 (index):95
pixels differ at 2 3 channel 0 v1:191 v2:190 (index):95
pixels differ at 2 3 channel 1 v1:191 v2:190 (index):95
pixels differ at 2 3 channel 2 v1:191 v2:190 (index):95
pixels differ at 3 3 channel 0 v1:191 v2:190 (index):95
pixels differ at 3 3 channel 1 v1:191 v2:190 (index):95
pixels differ at 3 3 channel 2 v1:191 v2:190 (index):95
done (index):100
As you can see, the colors are off by one (sometimes even two).
Please note, it works fine with solid alpha (255)
It also fails in the older Chrome Version 28.0.1500.71 beta-m and -m, but for larger resolutions, eg. 256 x 256.
According to the webgl spec:
"If the source image is an RGB or RGBA lossless image with 8 bits per channel, the browser guarantees that the full precision of all channels is preserved.
If the original image contains an alpha channel and the UNPACK_PREMULTIPLY_ALPHA_WEBGL pixel storage parameter is false, then the RGB values are guaranteed to never have been premultiplied by the alpha channel, whether those values are derived directly from the original file format or converted from some other color format. "
Since the jsfiddle works fine in Firefox, I have reported a bug in chrome.
However, I would like to know if there is a fix or a workaround, or if this is a known bugzilla bug ?
Thank you.