Closed
Bug 713143
Opened 13 years ago
Closed 6 years ago
Image encoders should consistently alpha-(un)premultiply RGBA data based on input format
Categories
(Core :: Graphics: ImageLib, defect)
Core
Graphics: ImageLib
Tracking
()
RESOLVED
INACTIVE
People
(Reporter: jgilbert, Assigned: jgilbert)
References
(Depends on 1 open bug)
Details
(Whiteboard: [rplus])
Attachments
(1 file, 1 obsolete file)
(deleted),
patch
|
joe
:
review+
|
Details | Diff | Splinter Review |
PNG (by spec) stores RGBA data alpha-nonpremultiplied. Internally, we have two RGBA input formats for encoding: INPUT_FORMAT_RGBA (nonpremultiplied) and INPUT_FORMAT_HOSTARGB (premultiplied).
PNG correctly unpremults data encoded from INPUT_FORMAT_HOSTARGB, while leaving _RGBA data alone.
Prior to bug 650720, JPG did the same, as did BMP. Since, both JPG and BMP do not unpremult data coming from _HOSTARGB.
It seems to me that the older behavior was correct for RGBA BMPs, though I haven't found mention of it in the spec.
It also seems that it makes the most sense to premultiply while encoding from RGBA to RGB formats. Thus, JPGs and non-RGBA BMPs should be premultiplied when encoded from nonpremult sources, while PNGs and RGBA BMPs should be instead unpremult'd when encoded from premult sources.
Assignee | ||
Updated•13 years ago
|
Assignee | ||
Comment 1•13 years ago
|
||
Assignee: nobody → jgilbert
Attachment #583969 -
Flags: review?(joe)
Comment 2•13 years ago
|
||
Comment on attachment 583969 [details] [diff] [review]
Respect alpha-premult when encoding HOSTARGB/RGBA formats
Review of attachment 583969 [details] [diff] [review]:
-----------------------------------------------------------------
::: image/encoders/bmp/nsBMPEncoder.cpp
@@ +433,5 @@
> + return (c*a + 127) / 255;
> +}
> +
> +static int UnpremultByte(int c, int a) {
> + return (c*255 + a/2) / a;
We actually already have GFX_PREMULTIPLY (in gfxColor.h); you could add GFX_UNPREMULTIPLY if you wanted, and use those.
Attachment #583969 -
Flags: review?(joe) → review+
Assignee | ||
Comment 3•13 years ago
|
||
I'll add GFX_UNPREMULTIPLY for now, but ideally my premult/unpremult unification work will be ready soon.
Also the try run here seems full of mochi-1 fails, so I'll look into that.
Status: NEW → ASSIGNED
Assignee | ||
Comment 4•13 years ago
|
||
There are issues with touching the BMP encoder/decoder, as we actually don't currently support encoding RGBA BMPs.
Assignee | ||
Comment 5•13 years ago
|
||
This patch just fixes the JPG encoder/decoder, and passes canvas tests on my machine. Running try push at: https://tbpl.mozilla.org/?tree=Try&rev=334cf17cf17e
Attachment #592910 -
Flags: review?(joe)
Assignee | ||
Comment 6•13 years ago
|
||
Try push for JPG is clean.
Assignee | ||
Comment 7•13 years ago
|
||
Splitting off JPG encode/decode to bug 723221.
Assignee | ||
Updated•13 years ago
|
Attachment #592910 -
Attachment is obsolete: true
Attachment #592910 -
Flags: review?(joe)
Assignee | ||
Updated•13 years ago
|
Whiteboard: [rplus]
Assignee | ||
Updated•6 years ago
|
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → INACTIVE
You need to log in
before you can comment on or make changes to this bug.
Description
•