Created attachment 24605 [details] 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.
Thanks for this, applied to trunk in r884061, with a few slight tweaks