@Test public void testTranslatedImage() { BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_BYTE_GRAY); Graphics g = image.createGraphics(); g.setColor(Color.WHITE); g.fillRect(236, 236, 20, 20); g.setColor(new Color(80, 80, 80)); // A dark gray g.fillRect(216, 216, 20, 20); g.setColor(new Color(200, 200, 200)); // A light gray g.fillRect(216, 236, 20, 20); g.dispose(); image = image.getSubimage(128, 128, 128, 128); CustomPaletteBuilder builder = new CustomPaletteBuilder(image, 256, 1, 1, 1); RenderedImage indexed = builder.buildPalette().getIndexedImage(); assertTrue(indexed.getColorModel() instanceof IndexColorModel); IndexColorModel icm = (IndexColorModel) indexed.getColorModel(); assertEquals( 4, icm .getMapSize()); // Black background, white fill, light gray fill, dark gray fill = 4 // colors // check image not black ImageWorker iw = new ImageWorker(indexed).forceComponentColorModel().intensity(); double[] mins = iw.getMinimums(); double[] maxs = iw.getMaximums(); boolean result = true; for (int i = 0; i < mins.length; i++) { result = mins[i] == maxs[i] ? false : result; } assertTrue(result); }