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: [email protected]
        ReportedBy: [email protected]


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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to