Changeset 13397 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2018-02-10T00:13:49+01:00 (7 years ago)
Author:
michael2402
Message:

Fix #15878: Implement colorfullness filter for indexed images.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/imagery/ColorfulImageProcessorTest.java

    r10547 r13397  
    88import java.awt.Graphics2D;
    99import java.awt.image.BufferedImage;
     10import java.awt.image.DataBuffer;
     11import java.awt.image.IndexColorModel;
    1012
    1113import org.junit.Rule;
     
    2224
    2325    private static final int TEST_IMAGE_SIZE = 5;
     26
     27    private static final int[] PALETTE = {
     28            Color.BLACK.getRGB(),
     29            Color.WHITE.getRGB(),
     30            Color.GRAY.getRGB(),
     31            Color.GREEN.getRGB(),
     32            Color.RED.getRGB(),
     33            Color.BLUE.getRGB(),
     34            0xff908050,
     35            0xff908070,
     36            0xff908070,
     37            0xff908070,
     38            0xfff02080,
     39    };
     40
     41    private static final IndexColorModel COLOR_MODEL = new IndexColorModel(8, PALETTE.length, PALETTE, 0, true, 255, DataBuffer.TYPE_BYTE);
    2442
    2543    /**
     
    7997                    BufferedImage.TYPE_3BYTE_BGR,
    8098                    BufferedImage.TYPE_4BYTE_ABGR,
    81                     BufferedImage.TYPE_4BYTE_ABGR_PRE }) {
     99                    BufferedImage.TYPE_4BYTE_ABGR_PRE,
     100                    BufferedImage.TYPE_BYTE_INDEXED }) {
    82101                assertTrue(runProcessing(data, type));
    83102            }
     
    104123
    105124    private BufferedImage createImage(Color color, int type) {
    106         BufferedImage image = new BufferedImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, type);
     125        BufferedImage image = type == BufferedImage.TYPE_BYTE_INDEXED
     126                ? new BufferedImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, type, COLOR_MODEL)
     127                : new BufferedImage(TEST_IMAGE_SIZE, TEST_IMAGE_SIZE, type);
    107128        Graphics2D graphics = image.createGraphics();
    108129        graphics.setColor(color);
    109130        graphics.fillRect(0, 0, TEST_IMAGE_SIZE, TEST_IMAGE_SIZE);
     131        assertEquals(color.getRGB(), image.getRGB(1, 1));
    110132        return image;
    111133    }
Note: See TracChangeset for help on using the changeset viewer.