public void testCreateGrayscale() { // create a 8-bit grayscale ImageTypeSpecifier ImageTypeSpecifier type = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, true); ColorModel model = type.getColorModel(); assertEquals( "Failed to return the colorspace type", ColorSpace.TYPE_GRAY, model.getColorSpace().getType()); assertEquals("Failed to return the transparency", Transparency.OPAQUE, model.getTransparency()); assertEquals( "Failed to return the transfer type", DataBuffer.TYPE_BYTE, model.getTransferType()); assertEquals("Failed to return the pixel size", 8, model.getPixelSize()); // create a 16-bit grayscale AlphaPremultiplied ImageTypeSpecifier type = ImageTypeSpecifier.createGrayscale(16, DataBuffer.TYPE_USHORT, true, false); model = type.getColorModel(); assertEquals( "Failed to return the colorspace type", ColorSpace.TYPE_GRAY, model.getColorSpace().getType()); assertEquals( "Failed to return the transparency", Transparency.TRANSLUCENT, model.getTransparency()); assertEquals( "Failed to return the transfer type", DataBuffer.TYPE_USHORT, model.getTransferType()); assertEquals("Failed to return the pixel size", 32, model.getPixelSize()); }
public void testGetBufferedImageType() { ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, true); assertEquals( "Failed to return the correct type", BufferedImage.TYPE_BYTE_GRAY, typeSpecifier.getBufferedImageType()); }
public void testCreateBufferedImage() { ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createGrayscale(8, DataBuffer.TYPE_BYTE, true); int width = 10; int height = 10; BufferedImage image = typeSpecifier.createBufferedImage(width, height); assertEquals( "Failed to create with the correct ColorModel", typeSpecifier.getColorModel(), image.getColorModel()); assertEquals( "Failed to create with the correct SampleModel", typeSpecifier.getSampleModel().getClass(), image.getSampleModel().getClass()); assertEquals("Failed to create with the correct width", width, image.getWidth()); assertEquals("Failed to create with the correct height", height, image.getHeight()); }