use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class ImageFactory method createDCMImage.
public static BufferedImage createDCMImage(int type, int cs) {
if (type == BufferedImage.TYPE_INT_RGB && cs == ColorSpace.CS_sRGB) {
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
DataBuffer data = image.getData().getDataBuffer();
fill(image);
return image;
}
ColorSpace cSpace = ColorSpace.getInstance(cs);
DirectColorModel dcm = null;
switch(type) {
case BufferedImage.TYPE_INT_ARGB:
dcm = new DirectColorModel(cSpace, 32, rMask, gMask, bMask, aMask, false, DataBuffer.TYPE_INT);
break;
case BufferedImage.TYPE_INT_RGB:
dcm = new DirectColorModel(cSpace, 24, rMask, gMask, bMask, 0, false, DataBuffer.TYPE_INT);
break;
case BufferedImage.TYPE_INT_BGR:
dcm = new DirectColorModel(cSpace, 24, rMask, gMask, bMask, 0, false, DataBuffer.TYPE_INT);
break;
case BufferedImage.TYPE_USHORT_555_RGB:
dcm = new DirectColorModel(cSpace, 15, r555Mask, g555Mask, b555Mask, 0, false, DataBuffer.TYPE_USHORT);
break;
case BufferedImage.TYPE_USHORT_565_RGB:
dcm = new DirectColorModel(cSpace, 16, r565Mask, g565Mask, b565Mask, 0, false, DataBuffer.TYPE_USHORT);
break;
}
SampleModel sm = dcm.createCompatibleSampleModel(WIDTH, HEIGHT);
WritableRaster raster = dcm.createCompatibleWritableRaster(WIDTH, HEIGHT);
switch(type) {
case BufferedImage.TYPE_INT_ARGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType());
break;
case BufferedImage.TYPE_INT_RGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType());
break;
case BufferedImage.TYPE_INT_BGR:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType());
break;
case BufferedImage.TYPE_USHORT_555_RGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType(), 5, 5, 5);
break;
case BufferedImage.TYPE_USHORT_565_RGB:
fillDCM(raster.getDataBuffer(), sm, cSpace.getType(), 5, 6, 5);
break;
}
return new BufferedImage(dcm, raster, false, null);
}
use of java.awt.image.WritableRaster 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;
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class Write3ByteBgrTest method createTestImage.
private static BufferedImage createTestImage(int type, Color c) {
BufferedImage i = null;
if (type == BufferedImage.TYPE_CUSTOM) {
WritableRaster wr = Raster.createBandedRaster(DataBuffer.TYPE_BYTE, width, height, // scanlineStride
width, // bankIndices[],
new int[] { 0, 1, 2 }, // bankOffsets[],
new int[] { 1, 2, 0 }, null);
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
ColorModel cm = new ComponentColorModel(cs, new int[] { 8, 8, 8 }, false, false, ColorModel.OPAQUE, DataBuffer.TYPE_BYTE);
i = new BufferedImage(cm, wr, false, null);
} else {
i = new BufferedImage(width, height, type);
}
Graphics2D g = i.createGraphics();
g.setColor(c);
g.fillRect(0, 0, width, height);
g.setColor(Color.white);
g.drawRect(10, 10, width - 20, height - 20);
return i;
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class IndexingTest method createComponentImage.
protected static BufferedImage createComponentImage(int w, int h, ComponentColorModel cm) {
WritableRaster wr = cm.createCompatibleWritableRaster(w, h);
BufferedImage img = new BufferedImage(cm, wr, false, null);
Graphics2D g = img.createGraphics();
int width = w / 8;
Color[] colors = new Color[8];
colors[0] = Color.red;
colors[1] = Color.green;
colors[2] = Color.blue;
colors[3] = Color.white;
colors[4] = Color.black;
colors[5] = new Color(0x80, 0x80, 0x80, 0x00);
colors[6] = Color.yellow;
colors[7] = Color.cyan;
for (int i = 0; i < 8; i++) {
g.setColor(colors[i]);
g.fillRect(i * width, 0, width, h);
}
return img;
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class TransparencyTest method createIndexedImage.
protected static BufferedImage createIndexedImage(int w, int h, IndexColorModel icm) {
BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
int mapSize = icm.getMapSize();
int width = w / mapSize;
WritableRaster wr = img.getRaster();
for (int i = 0; i < mapSize; i++) {
for (int y = 0; y < h; y++) {
for (int x = 0; x < width; x++) {
wr.setSample(i * width + x, y, 0, i);
}
}
}
return img;
}
Aggregations