public static ImageTypeSpecifier createFromIndexColorModel(final IndexColorModel pColorModel) { return IndexedImageTypeSpecifier.createFromIndexColorModel(pColorModel); }
@Test(expected = IllegalArgumentException.class) public void testCreateNull() { IndexedImageTypeSpecifier.createFromIndexColorModel(null); }
@Test public void testHashCode() { IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier other = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier different = IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE)); // TODO: There is still a problem that IndexColorModel does not override hashCode, // so any model with the same number of bits, transparency, and transfer type will have same hash assertEquals(spec.hashCode(), other.hashCode()); assertFalse(spec.hashCode() == different.hashCode()); }
@Test public void testCreateBufferedImageBinary() { IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); BufferedImage image = spec.createBufferedImage(2, 2); assertNotNull(image); assertEquals(BufferedImage.TYPE_BYTE_BINARY, image.getType()); assertEquals(cm, image.getColorModel()); }
@Test public void testCreateBufferedImageIndexed() { IndexColorModel cm = new IndexColorModel(8, 256, new int[256], 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); BufferedImage image = spec.createBufferedImage(2, 2); assertNotNull(image); assertEquals(BufferedImage.TYPE_BYTE_INDEXED, image.getType()); assertEquals(cm, image.getColorModel()); } }
@Test public void testCreateIndexedIntArray16() { int[] colors = createIntLut(1 << 16); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT)), ImageTypeSpecifiers.createIndexed(colors, false, -1, 16, DataBuffer.TYPE_USHORT) ); }
public static ImageTypeSpecifier createFromIndexColorModel(final IndexColorModel pColorModel) { return IndexedImageTypeSpecifier.createFromIndexColorModel(pColorModel); }
@Test public void testCreateFromIndexedColorModel1to8() { for (int bits = 1; bits <= 8; bits <<= 1) { int[] colors = createIntLut(1 << bits); IndexColorModel colorModel = new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel), ImageTypeSpecifiers.createFromIndexColorModel(colorModel) ); } }
@Test public void testCreateIndexedIntArray1to8() { for (int bits = 1; bits <= 8; bits <<= 1) { int[] colors = createIntLut(1 << bits); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE)), ImageTypeSpecifiers.createIndexed(colors, false, -1, bits, DataBuffer.TYPE_BYTE) ); } }
@Test public void testCreateFromIndexedColorModel16() { int[] colors = createIntLut(1 << 16); IndexColorModel colorModel = new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel), ImageTypeSpecifiers.createFromIndexColorModel(colorModel) ); }
@Test public void testEquals() { IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier other = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier different = IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE)); assertEquals(spec, other); assertEquals(other, spec); assertEquals(spec.hashCode(), other.hashCode()); assertTrue(spec.equals(other)); assertTrue(other.equals(spec)); // TODO: There is still a problem that IndexColorModel does not override equals, // so any model with the same number of bits, transparency, and transfer type will be treated as equal assertFalse(other.equals(different)); }
@Test(expected = IllegalArgumentException.class) public void testCreateNull() { IndexedImageTypeSpecifier.createFromIndexColorModel(null); }
@Test public void testHashCode() { IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier other = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier different = IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE)); // TODO: There is still a problem that IndexColorModel does not override hashCode, // so any model with the same number of bits, transparency, and transfer type will have same hash assertEquals(spec.hashCode(), other.hashCode()); assertFalse(spec.hashCode() == different.hashCode()); }
@Test public void testCreateBufferedImageIndexed() { IndexColorModel cm = new IndexColorModel(8, 256, new int[256], 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); BufferedImage image = spec.createBufferedImage(2, 2); assertNotNull(image); assertEquals(BufferedImage.TYPE_BYTE_INDEXED, image.getType()); assertEquals(cm, image.getColorModel()); } }
@Test public void testCreateBufferedImageBinary() { IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); BufferedImage image = spec.createBufferedImage(2, 2); assertNotNull(image); assertEquals(BufferedImage.TYPE_BYTE_BINARY, image.getType()); assertEquals(cm, image.getColorModel()); }
@Test public void testCreateIndexedIntArray16() { int[] colors = createIntLut(1 << 16); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT)), ImageTypeSpecifiers.createIndexed(colors, false, -1, 16, DataBuffer.TYPE_USHORT) ); }
@Test public void testCreateFromIndexedColorModel1to8() { for (int bits = 1; bits <= 8; bits <<= 1) { int[] colors = createIntLut(1 << bits); IndexColorModel colorModel = new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel), ImageTypeSpecifiers.createFromIndexColorModel(colorModel) ); } }
@Test public void testCreateIndexedIntArray1to8() { for (int bits = 1; bits <= 8; bits <<= 1) { int[] colors = createIntLut(1 << bits); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(bits, colors.length, colors, 0, false, -1, DataBuffer.TYPE_BYTE)), ImageTypeSpecifiers.createIndexed(colors, false, -1, bits, DataBuffer.TYPE_BYTE) ); } }
@Test public void testCreateFromIndexedColorModel16() { int[] colors = createIntLut(1 << 16); IndexColorModel colorModel = new IndexColorModel(16, colors.length, colors, 0, false, -1, DataBuffer.TYPE_USHORT); assertEquals( IndexedImageTypeSpecifier.createFromIndexColorModel(colorModel), ImageTypeSpecifiers.createFromIndexColorModel(colorModel) ); }
@Test public void testEquals() { IndexColorModel cm = new IndexColorModel(1, 2, new int[]{0xffffff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE); ImageTypeSpecifier spec = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier other = IndexedImageTypeSpecifier.createFromIndexColorModel(cm); ImageTypeSpecifier different = IndexedImageTypeSpecifier.createFromIndexColorModel(new IndexColorModel(2, 2, new int[]{0xff00ff, 0x00, 0xff00ff, 0x00}, 0, false, -1, DataBuffer.TYPE_BYTE)); assertEquals(spec, other); assertEquals(other, spec); assertEquals(spec.hashCode(), other.hashCode()); assertTrue(spec.equals(other)); assertTrue(other.equals(spec)); // TODO: There is still a problem that IndexColorModel does not override equals, // so any model with the same number of bits, transparency, and transfer type will be treated as equal assertFalse(other.equals(different)); }