Canvas rgb values inaccurate with low alpha channel values
Reported by
jwdu...@gmail.com,
Aug 14 2016
|
||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Steps to reproduce the problem: 1. Write a rgba value to canvas (using either fillStyle or putImageData). 2. Read back using getImageData. 3. Low alpha values corrupt the rgb values. Please see jsFiddle here: http://jsfiddle.net/intrinsica/eesLjfaa/ What is the expected behavior? rgb values should be left untouched when changing the alpha channel. What went wrong? In the attached test case, the rgb values returned were +/-1. A lower alpha setting increases the difference. Did this work before? No Chrome version: 52.0.2743.116 Channel: stable OS Version: 10.0 Flash Version: Shockwave Flash 22.0 r0 For reference: http://stackoverflow.com/questions/22384423/canvas-corrupts-rgb-when-alpha-0 Possibly related: https://bugs.chromium.org/p/chromium/issues/detail?id=234014 Reproducible in other browsers such as IE, Edge, Firefox, Safari, Opera. This test case arose from a need to pack data into a png for transfer and later unpack it. Presently, a work-around is to avoid the alpha channel. Ideally and academically, the fourth byte would be useful if it did not corrupt the rgb values.
,
Aug 15 2016
Yes, the behavior is expected. As pointed out by fs@, the reason is that canvas is always backed by a premultiplied sksurface. The lower alpha value is, the bigger the precision loss. If you change the alpha to be 0, the result will be all 0.
,
May 28 2018
doers this mean it's impossible to use canvas or img to load 4-byte data in textures for webgl shaders? as far as i can tell this basically renders (NPI) the alpha channel useless for anything but low-precision image data.
,
May 28 2018
Reading through a <canvas> context will definitely not guarantee anything. <img> (or ImageBitmap) should work I believe. |
||
►
Sign in to add a comment |
||
Comment 1 by f...@opera.com
, Aug 15 2016