poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 48274] New: HSSFPalette.findSimilarColor treats 0 and 255 as adjacent
Date Tue, 24 Nov 2009 15:03:08 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=48274

           Summary: HSSFPalette.findSimilarColor treats 0 and 255 as
                    adjacent
           Product: POI
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: HSSF
        AssignedTo: dev@poi.apache.org
        ReportedBy: jeremys.poibugs@hotmail.com


Created an attachment (id=24605)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=24605)
patch for HSSFPalette.java and TestHSSFPalette.java

HSSFPalette.findSimilarColor considers a color value of 0 to be closer than 255
it is to 127.  Thus, for example,

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFPalette palette = workbook.getCustomPalette();
HSSFColor color = palette.findSimilarColor(0,102,255);
short[] rgb = color.getTriplet();
System.out.println(java.util.Arrays.toString(rgb));

prints "[255,102,0]".  The input color is not unlike turquoise, but the output
color is a light red!

The reason findSimilarColor behaves this way is because it implements the
Manhattan distance in byte space.  byte is signed, and thus 255 is really -1,
which is adjacent to 0.

A patch is enclosed which first converts the bytes to positive integers so that
255 is maximally far from 0.  Then the above example returns [0,102,204] which
is much closer to the original [0,102,255].  The patch also includes additional
tests for TestHSSFPalette.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message