use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class BMPPluginTest method compare.
private boolean compare(BufferedImage in, BufferedImage out) {
int width = in.getWidth();
int height = in.getHeight();
if (out.getWidth() != width || out.getHeight() != height) {
throw new RuntimeException("Dimensions changed!");
}
Raster oldras = in.getRaster();
ColorModel oldcm = in.getColorModel();
Raster newras = out.getRaster();
ColorModel newcm = out.getColorModel();
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
Object oldpixel = oldras.getDataElements(i, j, null);
int oldrgb = oldcm.getRGB(oldpixel);
int oldalpha = oldcm.getAlpha(oldpixel);
Object newpixel = newras.getDataElements(i, j, null);
int newrgb = newcm.getRGB(newpixel);
int newalpha = newcm.getAlpha(newpixel);
if (newrgb != oldrgb || newalpha != oldalpha) {
throw new RuntimeException("Pixels differ at " + i + ", " + j);
}
}
}
return true;
}
use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class BMPSubsamplingTest method getTestImage.
private BufferedImage getTestImage(int type) {
BufferedImage dst = null;
ColorModel colorModel = null;
WritableRaster raster = null;
switch(type) {
case TYPE_INT_GRB:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x00ff0000, 0x000000ff);
break;
case TYPE_INT_GBR:
colorModel = new DirectColorModel(24, 0x000000ff, 0x00ff0000, 0x0000ff00);
break;
case TYPE_INT_RBG:
colorModel = new DirectColorModel(24, 0x00ff0000, 0x000000ff, 0x0000ff00);
break;
case TYPE_INT_BRG:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x000000ff, 0x00ff0000);
break;
case TYPE_3BYTE_RGB:
dst = create3ByteImage(new int[] { 8, 8, 8 }, new int[] { 0, 1, 2 });
break;
case TYPE_3BYTE_GRB:
dst = create3ByteImage(new int[] { 8, 8, 8 }, new int[] { 1, 0, 2 });
break;
case TYPE_USHORT_555_GRB:
colorModel = new DirectColorModel(16, 0x03E0, 0x7C00, 0x001F);
break;
case TYPE_USHORT_555_BGR:
colorModel = new DirectColorModel(16, 0x001F, 0x03E0, 0x7C00);
break;
case TYPE_USHORT_565_BGR:
colorModel = new DirectColorModel(16, 0x001F, 0x07E0, 0xf800);
break;
case TYPE_4BPP_INDEXED:
dst = createIndexImage(4);
break;
default:
dst = new BufferedImage(w, h, type);
}
if (dst == null) {
raster = colorModel.createCompatibleWritableRaster(w, h);
dst = new BufferedImage(colorModel, raster, false, null);
}
Graphics2D g = dst.createGraphics();
for (int i = 0; i < colors.length; i++) {
g.setColor(colors[i]);
g.fillRect(i * dx, 0, dx, h);
}
g.dispose();
return dst;
}
use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class BMPSubsamplingTest method create3ByteImage.
private BufferedImage create3ByteImage(int[] nBits, int[] bOffs) {
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, bOffs, null);
return new BufferedImage(colorModel, raster, false, null);
}
use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class BMPWriteParamTest method compare.
private static boolean compare(final BufferedImage in, final BufferedImage out) {
final int width = in.getWidth();
int height = in.getHeight();
if (out.getWidth() != width || out.getHeight() != height) {
throw new RuntimeException("Dimensions changed!");
}
Raster oldras = in.getRaster();
ColorModel oldcm = in.getColorModel();
Raster newras = out.getRaster();
ColorModel newcm = out.getColorModel();
for (int j = 0; j < height; j++) {
for (int i = 0; i < width; i++) {
Object oldpixel = oldras.getDataElements(i, j, null);
int oldrgb = oldcm.getRGB(oldpixel);
int oldalpha = oldcm.getAlpha(oldpixel);
Object newpixel = newras.getDataElements(i, j, null);
int newrgb = newcm.getRGB(newpixel);
int newalpha = newcm.getAlpha(newpixel);
if (newrgb != oldrgb || newalpha != oldalpha) {
// showDiff(in, out);
throw new RuntimeException("Pixels differ at " + i + ", " + j + " new = " + Integer.toHexString(newrgb) + " old = " + Integer.toHexString(oldrgb));
}
}
}
return true;
}
use of java.awt.image.ColorModel in project jdk8u_jdk by JetBrains.
the class NoExtraBytesTest method createTestImage.
private static BufferedImage createTestImage(int type) {
BufferedImage dst = null;
ColorModel colorModel = null;
WritableRaster raster = null;
ColorSpace cs = null;
System.out.println("Create image for " + getImageTypeName(type));
switch(type) {
case TYPE_INT_GRB:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x00ff0000, 0x000000ff);
break;
case TYPE_INT_GBR:
colorModel = new DirectColorModel(24, 0x000000ff, 0x00ff0000, 0x0000ff00);
break;
case TYPE_INT_RBG:
colorModel = new DirectColorModel(24, 0x00ff0000, 0x000000ff, 0x0000ff00);
break;
case TYPE_INT_BRG:
colorModel = new DirectColorModel(24, 0x0000ff00, 0x000000ff, 0x00ff0000);
break;
case TYPE_INT_555_GRB:
colorModel = new DirectColorModel(24, 0x0000001F, 0x000003e0, 0x00007c00);
break;
case TYPE_3BYTE_RGB:
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = { 8, 8, 8 };
int[] bOffs = { 0, 1, 2 };
colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, bOffs, null);
break;
case TYPE_3BYTE_GRB:
cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
//nBits = {8, 8, 8};
//bOffs = {0, 1, 2};
colorModel = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, w, h, w * 3, 3, new int[] { 1, 0, 2 }, null);
break;
default:
dst = new BufferedImage(w, h, type);
}
if (dst == null) {
if (raster == null) {
raster = colorModel.createCompatibleWritableRaster(w, h);
}
dst = new BufferedImage(colorModel, raster, false, null);
}
Graphics g = dst.createGraphics();
for (int i = 0; i < usedColors.length; i++) {
g.setColor(usedColors[i]);
g.fillRect(i * dx, 0, dx, h);
}
g.dispose();
return dst;
}
Aggregations