-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[Web, engine] Decoding a semi-transparent image gives slightly incorrect results #92958
Copy link
Copy link
Closed
Closed
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagese: web_htmlHTML rendering backend for WebHTML rendering backend for Webengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-webWeb applications specificallyWeb applications specificallyteam-webOwned by Web platform teamOwned by Web platform teamtriaged-webTriaged by Web platform teamTriaged by Web platform team
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: imagesLoading, displaying, rendering imagesLoading, displaying, rendering imagese: web_htmlHTML rendering backend for WebHTML rendering backend for Webengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.platform-webWeb applications specificallyWeb applications specificallyteam-webOwned by Web platform teamOwned by Web platform teamtriaged-webTriaged by Web platform teamTriaged by Web platform team
Type
Fields
Give feedbackNo fields configured for issues without a type.
When decoding a bitmap image, the resulting pixels might be slightly off if any of the pixels are partially transparent, i.e. contain alpha between 1 ~ 254. This does not occur if all pixels have alpha of either 0 or 255.
This is observed on HTML renderer. I have not tested if it reproduces on canvaskit, but I suspect not.
Following is the testing code:
In the code above,
descriptorcontains a BMP representation of the source image,encodedis anHtmlImage, andencoded.toByteDatadecodes the data back into raw pixels.If any pixel is partially transparent, then all pixels might be slightly off, including the alpha channel:
In comparison, if all pixels have either 0 or 255 on alpha, the accurate pixels are decoded:
Note that the fully transparent pixel is turned all 0, which is fine since it's transparent anyway.
The reason is unknown, but I suspect it's because
HtmlImagedecides image data usingcanvas.drawImage, which might blend semi-transparent image using a different algorithm that introduces rounding errors. Note that the deviation also depends on browser. Running on Firefox gives a different value from Chrome, neither correct.