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); }
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); }
@Test public void testCreateGrayscale16() { assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true), // NOTE: Signed TYPE_USHORT makes no sense... ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT) ); assertEquals( new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0}, false, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_SHORT) ); }
@Test public void testCreateGrayscaleAlpha16() { assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, false, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, false) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, false, true), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, true) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, false) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true, true), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, true) ); assertEquals( new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_SHORT, false) ); assertEquals( new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, true), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_SHORT, true) ); }
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 testCreateGrayscale16() { assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true), // NOTE: Signed TYPE_USHORT makes no sense... ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT) ); assertEquals( new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0}, false, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_SHORT) ); }
@Test public void testCreateGrayscaleAlpha16() { assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, false, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, false) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, false, true), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, true) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, false) ); assertEquals( ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true, true), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_USHORT, true) ); assertEquals( new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, false), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_SHORT, false) ); assertEquals( new Int16ImageTypeSpecifier(ColorSpace.getInstance(ColorSpace.CS_GRAY), new int[] {0, 1}, true, true), ImageTypeSpecifiers.createGrayscale(16, DataBuffer.TYPE_SHORT, true) ); }