bug fix for PNGHelper.java
Eric Bloch <[email protected]> Fri, 3 Oct 2003 15:24:20 -0700 (PDT)
| Newsgroups | gmane.comp.java.jgenerator.devel |
|---|---|
| Message-ID | <[email protected]> |
Hey Folks,
I think I've found (and fixed) a bug in PNGHelper in its handling
of the alpha channel.
PNG files come w/out pre-multiplied alpha and flash
seems to assume alpha values are premultiplied into the rgbs.
I couldn't find this written anywhere, but it seems to be the case.
Anyway, there's code in PNGHelper.java to "apply" the alpha,
but it does it incorrectly. It substracts rather than multiplies.
I've tested the fix below
for the 32bit RGBA case and it works.
This diff is for the old 1.4-src code base so the line numbers
may be off. Look for 'apply alpha'.
-Eric
< cr -= (255 - ca);
---
> float fa = (float)ca/255.0f;
> cr = (int)(cr*fa);
1475c1476
< aa -= (1.0f - ab);
---
> aa *= ab;
1499,1501c1500,1507
< cr -= (255 - ca);
< cg -= (255 - ca);
< cb -= (255 - ca);
---
> if (ca == 0) {
> cr = cg = cb = 0;
> } else {
> float fa = (float)ca/255.0f;
> cr = (int)((cr)*fa);
> cg = (int)((cg)*fa);
> cb = (int)((cb)*fa);
> }
1523,1525c1529,1531
< aa -= (1.0f - ad);
< ab -= (1.0f - ad);
< ac -= (1.0f - ad);
---
> aa *= ad;
> ab *= ad;
> ac *= ad;
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf