public static ImageTypeSpecifier createBanded(final ColorSpace colorSpace, final int[] bankIndices, final int[] bandOffsets, final int dataType, final boolean hasAlpha, final boolean isAlphaPremultiplied) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version if (dataType == DataBuffer.TYPE_INT) { return UInt32ImageTypeSpecifier.createBanded(colorSpace, bankIndices, bandOffsets, hasAlpha, isAlphaPremultiplied); } // ...or fall back to default for anything else return ImageTypeSpecifier.createBanded(colorSpace, bankIndices, bandOffsets, dataType, hasAlpha, isAlphaPremultiplied); }
public static ImageTypeSpecifier createInterleaved(final ColorSpace colorSpace, final int[] bandOffsets, final int dataType, final boolean hasAlpha, final boolean isAlphaPremultiplied) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version if (dataType == DataBuffer.TYPE_INT) { return UInt32ImageTypeSpecifier.createInterleaved(colorSpace, bandOffsets, hasAlpha, isAlphaPremultiplied); } // ...or fall back to default for anything else return ImageTypeSpecifier.createInterleaved(colorSpace, bandOffsets, dataType, hasAlpha, isAlphaPremultiplied); }
static ImageTypeSpecifier createBanded(final ColorSpace cs, final int[] bandIndices, final int[] bandOffsets, final boolean hasAlpha, final boolean isAlphaPremultiplied) { return create( cs, hasAlpha, isAlphaPremultiplied, new BandedSampleModel( DataBuffer.TYPE_INT, 1, 1, 1, bandIndices, bandOffsets ) ); }
public static ImageTypeSpecifier createGrayscale(final int bits, final int dataType) { if (bits == 16 && dataType == DataBuffer.TYPE_SHORT) { // As the ComponentColorModel is broken for 16 bit signed int, we'll use our own version return new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0}, false, false); } else if (bits == 32 && dataType == DataBuffer.TYPE_INT) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version return UInt32ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0}, false, false); } else if (dataType == DataBuffer.TYPE_FLOAT || dataType == DataBuffer.TYPE_DOUBLE) { return ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0}, dataType, false, false); } // NOTE: The isSigned boolean is stored but *not used for anything* in the Grayscale ImageTypeSpecifier... return ImageTypeSpecifier.createGrayscale(bits, dataType, false); }
@Test public void testCreateBanded32() { assertEquals( UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2}, new int[] {0, 0, 0}, false, false), ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2}, new int[] {0, 0, 0}, DataBuffer.TYPE_INT, false, false) ); assertEquals( UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, true, false), ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_INT, true, false) ); assertEquals( UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 1000, 2000, 3000}, true, true), ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 1000, 2000, 3000}, DataBuffer.TYPE_INT, true, true) ); }
static ImageTypeSpecifier createInterleaved(final ColorSpace cs, final int[] bandOffsets, final boolean hasAlpha, final boolean isAlphaPremultiplied) { return create( cs, hasAlpha, isAlphaPremultiplied, new PixelInterleavedSampleModel( DataBuffer.TYPE_INT, 1, 1, cs.getNumComponents() + (hasAlpha ? 1 : 0), cs.getNumComponents() + (hasAlpha ? 1 : 0), bandOffsets ) ); }
public static ImageTypeSpecifier createGrayscale(final int bits, final int dataType, final boolean isAlphaPremultiplied) { if (bits == 16 && dataType == DataBuffer.TYPE_SHORT) { // As the ComponentColorModel is broken for 16 bit signed int, we'll use our own version return new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, isAlphaPremultiplied); } else if (bits == 32 && dataType == DataBuffer.TYPE_INT) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version return UInt32ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, isAlphaPremultiplied); } else if (dataType == DataBuffer.TYPE_FLOAT || dataType == DataBuffer.TYPE_DOUBLE) { return ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, dataType, true, isAlphaPremultiplied); } // NOTE: The isSigned boolean is stored but *not used for anything* in the Grayscale ImageTypeSpecifier... return ImageTypeSpecifier.createGrayscale(bits, dataType, false, isAlphaPremultiplied); }
public static ImageTypeSpecifier createBanded(final ColorSpace colorSpace, final int[] bankIndices, final int[] bandOffsets, final int dataType, final boolean hasAlpha, final boolean isAlphaPremultiplied) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version if (dataType == DataBuffer.TYPE_INT) { return UInt32ImageTypeSpecifier.createBanded(colorSpace, bankIndices, bandOffsets, hasAlpha, isAlphaPremultiplied); } // ...or fall back to default for anything else return ImageTypeSpecifier.createBanded(colorSpace, bankIndices, bandOffsets, dataType, hasAlpha, isAlphaPremultiplied); }
static ImageTypeSpecifier createBanded(final ColorSpace cs, final int[] bandIndices, final int[] bandOffsets, final boolean hasAlpha, final boolean isAlphaPremultiplied) { return create( cs, hasAlpha, isAlphaPremultiplied, new BandedSampleModel( DataBuffer.TYPE_INT, 1, 1, 1, bandIndices, bandOffsets ) ); }
@Test public void testCreateGrayscaleAlpha32() { assertEquals( UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, false), ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, false) ); assertEquals( UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, false), ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, false) ); assertEquals( UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, true), ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, true) ); assertEquals( UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, true), ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT, true) ); }
@Test public void testCreateBanded32() { assertEquals( UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2}, new int[] {0, 0, 0}, false, false), ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2}, new int[] {0, 0, 0}, DataBuffer.TYPE_INT, false, false) ); assertEquals( UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, true, false), ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 0, 0, 0}, DataBuffer.TYPE_INT, true, false) ); assertEquals( UInt32ImageTypeSpecifier.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 1000, 2000, 3000}, true, true), ImageTypeSpecifiers.createBanded(sRGB, new int[] {0, 1, 2, 3}, new int[] {0, 1000, 2000, 3000}, DataBuffer.TYPE_INT, true, true) ); }
static ImageTypeSpecifier createInterleaved(final ColorSpace cs, final int[] bandOffsets, final boolean hasAlpha, final boolean isAlphaPremultiplied) { return create( cs, hasAlpha, isAlphaPremultiplied, new PixelInterleavedSampleModel( DataBuffer.TYPE_INT, 1, 1, cs.getNumComponents() + (hasAlpha ? 1 : 0), cs.getNumComponents() + (hasAlpha ? 1 : 0), bandOffsets ) ); }
@Test public void testCreateGrayscale32() { assertEquals( UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0}, false, false), ImageTypeSpecifiers.createGrayscale(32, DataBuffer.TYPE_INT) ); }
@Test public void testCreateInterleaved32() { // 32 bits/sample assertEquals( UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0}, false, false), ImageTypeSpecifiers.createInterleaved(GRAY, new int[] {0}, DataBuffer.TYPE_INT, false, false) ); assertEquals( UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int[] {0, 1}, true, false), ImageTypeSpecifiers.createInterleaved(GRAY, new int[] {0, 1}, DataBuffer.TYPE_INT, true, false) ); assertEquals( UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int[] {0, 1, 2}, false, false), ImageTypeSpecifiers.createInterleaved(sRGB, new int[] {0, 1, 2}, DataBuffer.TYPE_INT, false, false) ); assertEquals( UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, true, false), ImageTypeSpecifiers.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, DataBuffer.TYPE_INT, true, false) ); assertEquals( UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, true, true), ImageTypeSpecifiers.createInterleaved(sRGB, new int[] {0, 1, 2, 3}, DataBuffer.TYPE_INT, true, true) ); }
@Test public void testHashCode() { ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false); ImageTypeSpecifier other = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false); ImageTypeSpecifier different = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, false); // Equivalent, but broken, not equal ImageTypeSpecifier broken = ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, DataBuffer.TYPE_INT, false, false); assertEquals(spec.hashCode(), other.hashCode()); assertFalse(spec.hashCode() == different.hashCode()); assertFalse(spec.hashCode() == broken.hashCode()); } }
@Test public void testEquals() { ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false); ImageTypeSpecifier other = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, false, false); ImageTypeSpecifier different = UInt32ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2, 3}, true, false); // Equivalent, but broken, not equal ImageTypeSpecifier broken = ImageTypeSpecifier.createInterleaved(sRGB, new int [] {0, 1, 2}, DataBuffer.TYPE_INT, false, false); assertEquals(spec, other); assertEquals(other, spec); assertTrue(spec.equals(other)); assertTrue(other.equals(spec)); assertFalse(spec.equals(different)); assertFalse(different.equals(spec)); assertFalse(spec.equals(broken)); assertFalse(broken.equals(spec)); }
public static ImageTypeSpecifier createInterleaved(final ColorSpace colorSpace, final int[] bandOffsets, final int dataType, final boolean hasAlpha, final boolean isAlphaPremultiplied) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version if (dataType == DataBuffer.TYPE_INT) { return UInt32ImageTypeSpecifier.createInterleaved(colorSpace, bandOffsets, hasAlpha, isAlphaPremultiplied); } // ...or fall back to default for anything else return ImageTypeSpecifier.createInterleaved(colorSpace, bandOffsets, dataType, hasAlpha, isAlphaPremultiplied); }
public static ImageTypeSpecifier createGrayscale(final int bits, final int dataType) { if (bits == 16 && dataType == DataBuffer.TYPE_SHORT) { // As the ComponentColorModel is broken for 16 bit signed int, we'll use our own version return new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0}, false, false); } else if (bits == 32 && dataType == DataBuffer.TYPE_INT) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version return UInt32ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0}, false, false); } // NOTE: The isSigned boolean is stored but *not used for anything* in the Grayscale ImageTypeSpecifier... return ImageTypeSpecifier.createGrayscale(bits, dataType, false); }
public static ImageTypeSpecifier createGrayscale(final int bits, final int dataType, final boolean isAlphaPremultiplied) { if (bits == 16 && dataType == DataBuffer.TYPE_SHORT) { // As the ComponentColorModel is broken for 16 bit signed int, we'll use our own version return new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, isAlphaPremultiplied); } else if (bits == 32 && dataType == DataBuffer.TYPE_INT) { // As the ComponentColorModel is broken for 32 bit unsigned int, we'll use our own version return UInt32ImageTypeSpecifier.createInterleaved(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, isAlphaPremultiplied); } // NOTE: The isSigned boolean is stored but *not used for anything* in the Grayscale ImageTypeSpecifier... return ImageTypeSpecifier.createGrayscale(bits, dataType, false, isAlphaPremultiplied); }
@Test public void testGray() { ImageTypeSpecifier spec = UInt32ImageTypeSpecifier.createInterleaved(GRAY, new int [] {0}, false, false); assertEquals(1, spec.getNumBands()); assertEquals(1, spec.getNumComponents()); assertEquals(32, spec.getBitsPerBand(0)); assertThat(spec.getColorModel(), is(ComponentColorModel.class)); assertFalse(spec.getColorModel().hasAlpha()); assertFalse(spec.getColorModel().isAlphaPremultiplied()); assertEquals(1, spec.getColorModel().getNumComponents()); assertEquals(1, spec.getColorModel().getNumColorComponents()); assertThat(spec.getSampleModel(), is(PixelInterleavedSampleModel.class)); assertEquals(1, spec.getSampleModel().getNumBands()); assertEquals(1, spec.getSampleModel().getNumDataElements()); }