Closed Bug 1220021 Opened 9 years ago Closed 9 years ago

0RGB ICO files treated as if they're transparent

Categories

(Core :: Graphics: ImageLib, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla45
Tracking Status
firefox42 --- unaffected
firefox43 + wontfix
firefox44 + fixed
firefox45 + fixed
b2g-v2.5 --- fixed

People

(Reporter: n.nethercote, Assigned: n.nethercote)

References

Details

(Keywords: regression)

Attachments

(5 files, 3 obsolete files)

BMPs within ICO files have this fun feature whereby:

- if all the alpha values are zero (i.e. it's 0RGB) we treat is as opaque;

- otherwise, we treat it as having an alpha channel.

However, bug 1062066 broke the first case. The BMP decoders SetPixel() uses gfxPackedPixel(), which sets the entire color to 0x0 if the alpha channel is zero. As a result, such images are shown as fully transparent.
Here's a test case that currently renders transparent. Prior to bug 1062066 it (correctly) rendered as opaque.
Here's a nice counter-example to the previous test. It differs only in that one pixel in the middle of the image has an alpha value of 0xff instead of 0. This should (and does) cause us to render it as ARGB instead of 0RGB, and thus the icon is entirely transparent except for that one blue pixel.
I tried using a variant of getPackedPixel that doesn't set the RGB channels to zero if A is zero, and this fixed the 0RGB test case.

However, it also caused *4* pixels in the ARGB test case to show up (in a horizontal line) as non-transparent, instead of the 1 pixel that's supposed to show up. Not sure what's wrong there.
Seth: this bug is on Beta now and less than a month away from hitting release. You said on IRC that you would take it on. Is that still your plan?
Flags: needinfo?(seth)
I took another look at this.

> I tried using a variant of getPackedPixel that doesn't set the RGB channels
> to zero if A is zero, and this fixed the 0RGB test case.

This is still true, but the ARGB case has a problem: in SetPixel() we need to use the *pre-multiplied* color values. But the change above doesn't do that for fully transparent pixels; instead it stores the "straight" alpha values. And we never go back and adjust them, so the fully transparent pixels end up contributing some color instead of no color.

I think we're going to have to do something like, when we come across the first non-zero-alpha pixel, go back and reset any pixels we've seen so far, which must be fully transparent.
> I think we're going to have to do something like, when we come across the
> first non-zero-alpha pixel, go back and reset any pixels we've seen so far,
> which must be fully transparent.

That was how it was done prior to bug 1062066 strategy and I've got it working locally. Now I just need to get a reftest working.
Assignee: nobody → n.nethercote
> That was how it was done prior to bug 1062066 strategy and I've got it
> working locally.

Oh, except it's not working when downscaling is applied. E.g. when I view the image directly, the copy in the main window looks good but the downscaled version used as the tab icon is messed up. I think I understand bug 1062066 comment 5 better now:

> If it ever encounters a non-zero alpha byte, it goes back over the image
> data and rewrites all the alpha bytes. That's not great for DDD, though, since
> we're not storing the input data once we process it. It's possible to rewrite
> the already-scaled output data, but the problem is that the wrong values will
> remain in the Downscaler's "window" of rows and will be used when subsequent
> rows are downscaled.

To make this work I need a way to tell the Downscaler to go back to the start. I'm not sure if that's possible.
> To make this work I need a way to tell the Downscaler to go back to the
> start. I'm not sure if that's possible.

ResetForNextProgressivePass() seems to fit the bill...
This approach is much the same as the one we had before bug 1062066 caused the
regression.
Attachment #8688827 - Flags: review?(seth)
Attached patch (part 2) - Add two reftests (obsolete) — Splinter Review
Attachment #8688828 - Flags: review?(seth)
(In reply to Nicholas Nethercote [:njn] from comment #10)
> Created attachment 8688828 [details] [diff] [review]
> (part 2) - Add two reftests

This doesn't test the downscale case. I'm not sure how to test that. Put the image in a webpage and set the dimensions manually?
Attached patch (part 2) - Add four reftests (obsolete) — Splinter Review
I added downscaled tests and some fuzziness on Mac that is required to pass on
try server.
Attachment #8689284 - Flags: review?(seth)
Attachment #8688828 - Attachment is obsolete: true
Attachment #8688828 - Flags: review?(seth)
Try looks good: https://treeherder.mozilla.org/#/jobs?repo=try&revision=9ef0facad3f2

I cleared the NEEDINFO request. What's needed now is a review.
Flags: needinfo?(seth)
Hmm, the downscaled test isn't working as I expected. I tried deliberately breaking the downscaling handling, and yet the reftest still passes. If I use the Inspector to take a screenshot of the downscaled image the output is correct... so presumably in the reftest the non-downscaled image is being used somehow for the comparison?
Attached patch (part 2) - Add four reftests (obsolete) — Splinter Review
This enables DDD for the reftests :)  The fuzziness was needed locally for me
on Linux. I'll do a try push to see if the numbers need to be tweaked at all.
Attachment #8689740 - Flags: review?(seth)
Attachment #8689284 - Attachment is obsolete: true
Attachment #8689284 - Flags: review?(seth)
Comment on attachment 8689740 [details] [diff] [review]
(part 2) - Add four reftests

Review of attachment 8689740 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good, just need to move these tests to the appropriate directory.

::: image/test/reftest/ico/ico-bmp-32bpp/downscale-wrapper.html
@@ +7,5 @@
> +</style>
> +<script>
> +  // The image is loaded async after the page loads
> +  // wait for it to finish loading
> +  function onImageLoad() { 

Nit: whitespace.

::: image/test/reftest/ico/ico-bmp-32bpp/reftest.list
@@ +27,5 @@
> +
> +default-preferences pref(image.downscale-during-decode.enabled,true)
> +
> +fuzzy(1,3) == downscale-wrapper.html?ff-0RGB.ico downscale-wrapper.html?ff-0RGB.png
> +fuzzy(7,6) == downscale-wrapper.html?ff-ARGB.ico downscale-wrapper.html?ff-ARGB-downscaled.png

These tests belong in image/test/reftest/downscaling. Please follow the pattern there of running identical tests with and without the DDD pref enabled.
Attachment #8689740 - Flags: review?(seth) → review+
Comment on attachment 8688827 [details] [diff] [review]
(part 1) - Don't treat 0RGB ICO files as transparent

Review of attachment 8688827 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good. Thanks for fixing this, Nick.
Attachment #8688827 - Flags: review?(seth) → review+
The patch that landed.
Attachment #8689740 - Attachment is obsolete: true
Comment on attachment 8691718 [details] [diff] [review]
(part 2) - Add four reftests

Carrying over r+.
Attachment #8691718 - Flags: review+
Blocks: 1062066
No longer depends on: 1062066
Comment on attachment 8688827 [details] [diff] [review]
(part 1) - Don't treat 0RGB ICO files as transparent

Approval Request Comment
[Feature/regressing bug #]: bug 1062066

[User impact if declined]: Fully-opaque favicons are rendered as fully transparent, i.e. don't show up at all.

[Describe test coverage new/current, TreeHerder]: Four new reftests were added.

[Risks and why]: Low risk. Patch is fairly small. Behaviour of the new code is similar to the pre-1062066 behaviour.

[String/UUID change made/needed]: None.
Attachment #8688827 - Flags: approval-mozilla-beta?
Attachment #8691718 - Flags: approval-mozilla-beta?
Attachment #8688827 - Flags: approval-mozilla-aurora?
Attachment #8691718 - Flags: approval-mozilla-aurora?
https://hg.mozilla.org/mozilla-central/rev/0a5b47980443
https://hg.mozilla.org/mozilla-central/rev/37ecff04dcd1
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
Tracking since this is a recent regression.
This explains why my pinned tabs look so mysterious lately!
Comment on attachment 8688827 [details] [diff] [review]
(part 1) - Don't treat 0RGB ICO files as transparent

Fix for icon regression in 43, includes new reftests, please uplift to aurora and beta.
Attachment #8688827 - Flags: approval-mozilla-beta?
Attachment #8688827 - Flags: approval-mozilla-beta+
Attachment #8688827 - Flags: approval-mozilla-aurora?
Attachment #8688827 - Flags: approval-mozilla-aurora+
Comment on attachment 8691718 [details] [diff] [review]
(part 2) - Add four reftests

Adds downscaling reftests. OK to uplift to aurora and beta.
Attachment #8691718 - Flags: approval-mozilla-beta?
Attachment #8691718 - Flags: approval-mozilla-beta+
Attachment #8691718 - Flags: approval-mozilla-aurora?
Attachment #8691718 - Flags: approval-mozilla-aurora+
(In reply to Liz Henry (:lizzard) (needinfo? me) from comment #23)
> Tracking since this is a recent regression.
> This explains why my pinned tabs look so mysterious lately!

Do you have a URL for an affected site(s)? I found this regression by code inspection and then hand-constructed an ICO file that demonstrated it(!)  So I haven't actually seen the problem in the wild myself and I would be interested to do so. Thank you.
Flags: needinfo?(lhenry)
I just restarted and updated to beta 7, and my favicons are back. The one I noticed disappearing was the google calendar icon.
Flags: needinfo?(lhenry)
this has problems during uplift to beta:

grafting 317597:9bb2dd1ff7f6 "Bug 1220021 (part 1) - Don't treat 0RGB ICO files as transparent. r=seth, a=lizzard"
merging image/decoders/nsBMPDecoder.cpp
warning: conflicts while merging image/decoders/nsBMPDecoder.cpp! (edit, then use 'hg resolve --mark')
abort: unresolved conflicts, can't continue
(use hg resolve and hg graft --continue)
Tomcats-MacBook-Pro-2:mozilla-central Tomcat$ hg revert -a

could you take a look, thanks!
Flags: needinfo?(n.nethercote)
I don't think this will make beta 8, since I'm about to go to build this morning. It could still make beta 9 though.
Seth, I had to rework this quite a bit to backport to Beta because Beta
doesn't have the big rewrite of nsBMPDecoder. It's now a mixture of (a) the
current trunk code, and (b) the old pre-bug 1062066 code.

It passes tests:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=cf0b8dbbf5d2
Attachment #8694584 - Flags: review?(seth)
Flags: needinfo?(n.nethercote)
Good that it passes tests. This could potentially still make it into the beta 9 build tomorrow morning if it gets an r+, but then we only have the weekend (while the entire company is traveling to the work week) to catch anything going wrong.   Do you think it would be annoying enough of a regression to users to be worth the risk of having to back out or do an rc2 next week?
Flags: needinfo?(n.nethercote)
> Do you think it would be annoying enough of a regression to users
> to be worth the risk of having to back out or do an rc2 next week?

Given that nobody has noticed it so far (as mentioned, I found the problem via code inspection) I'd be happy to not take the patch on beta and tolerate the regression for one release. Seth might have something to add.
Flags: needinfo?(n.nethercote)
Comment on attachment 8688827 [details] [diff] [review]
(part 1) - Don't treat 0RGB ICO files as transparent

Too late for the RC build. This can ride with 44
Attachment #8688827 - Flags: approval-mozilla-beta+ → approval-mozilla-beta-
Attachment #8691718 - Flags: approval-mozilla-beta+ → approval-mozilla-beta-
A French user reported his website (http://www.annees-marabout.com/) has a broken favicon (black square) in FF43, but it's fixed by this bug.
(In reply to Loic from comment #36)
> A French user reported his website (http://www.annees-marabout.com/) has a
> broken favicon (black square) in FF43, but it's fixed by this bug.

Yeah, I can see that. Firefox 42 shows the favicon, Firefox 43 shows a black square, Firefox 46 shows the favicon again. Based on comment 35 this should be fixed when Firefox 44 is released, tentatively scheduled for January 26, 2016.
Attachment #8694584 - Flags: review?(seth)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: