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)

defect
Not set
normal

Tracking

()

RESOLVED INACTIVE

People

(Reporter: jgilbert, Assigned: jgilbert)

References

(Depends on 1 open bug)

Details

(Whiteboard: [rplus])

Attachments

(1 file, 1 obsolete file)

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.
Depends on: 713146
OS: Windows 7 → All
Hardware: x86_64 → All
Assignee: nobody → jgilbert
Attachment #583969 - Flags: review?(joe)
Blocks: 696569
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+
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
There are issues with touching the BMP encoder/decoder, as we actually don't currently support encoding RGBA BMPs.
Attached patch Premultiply JPG data correctly (obsolete) (deleted) — Splinter Review
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)
Depends on: 722555
Try push for JPG is clean.
Depends on: 723221
Splitting off JPG encode/decode to bug 723221.
Attachment #592910 - Attachment is obsolete: true
Attachment #592910 - Flags: review?(joe)
Whiteboard: [rplus]
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.

Attachment

General

Created:
Updated:
Size: