Martin Mirchev created IMAGING-393:
--------------------------------------

             Summary: PaletteFactory counts no transparent colors when their 
alpha is 0x80 or more
                 Key: IMAGING-393
                 URL: https://issues.apache.org/jira/browse/IMAGING-393
             Project: Commons Imaging
          Issue Type: Bug
            Reporter: Martin Mirchev


{{PaletteFactory.countTransparentColors(BufferedImage)}} and 
{{countTrasparentColors(int[])}} use {{first = -1}} as "no transparent color 
seen yet" and test it with {{first < 0}}. An ARGB value with an alpha of 0x80 
or more is negative, so once such a color is stored the methods still treat it 
as "none yet": they never return 2 for two different such colors, and return 0 
instead of 1 at the end.

Reproducer:
{code:java}
PaletteFactory factory = new PaletteFactory();
factory.countTrasparentColors(new int[] { 0x80FFFFFF, 0x80FFFFFF }); // 0, 
expected 1
factory.countTrasparentColors(new int[] { 0x80FFFFFF, 0x80FFFF00 }); // 0, 
expected 2
factory.countTrasparentColors(new int[] { 0x00FFFFFF, 0x00FFFF00 }); // 2, as 
expected
{code}
The image variant behaves the same for a {{TYPE_INT_ARGB}} image with these 
pixels.

Suggested fix: track "seen" with a boolean. A pull request with the fix and a 
test follows.

This issue was found by an LLM-Enhanced Static Analysis Engine and verified 
manually.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to