use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.
the class PathGraphics method drawBitmaskImage.
/* An optimisation for the special case of ICM images which have
* bitmask transparency.
*/
protected boolean drawBitmaskImage(BufferedImage bufferedImage, AffineTransform xform, Color bgcolor, int srcX, int srcY, int srcWidth, int srcHeight) {
ColorModel colorModel = bufferedImage.getColorModel();
IndexColorModel icm;
int[] pixels;
if (!(colorModel instanceof IndexColorModel)) {
return false;
} else {
icm = (IndexColorModel) colorModel;
}
if (colorModel.getTransparency() != ColorModel.BITMASK) {
return false;
}
// with alpha 128 as opaque
if (bgcolor != null && bgcolor.getAlpha() < 128) {
return false;
}
if ((xform.getType() & ~(AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION | AffineTransform.TYPE_QUADRANT_ROTATION)) != 0) {
return false;
}
if ((getTransform().getType() & ~(AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION | AffineTransform.TYPE_QUADRANT_ROTATION)) != 0) {
return false;
}
BufferedImage subImage = null;
Raster raster = bufferedImage.getRaster();
int transpixel = icm.getTransparentPixel();
byte[] alphas = new byte[icm.getMapSize()];
icm.getAlphas(alphas);
if (transpixel >= 0) {
alphas[transpixel] = 0;
}
/* don't just use srcWidth & srcHeight from application - they
* may exceed the extent of the image - may need to clip.
* The image xform will ensure that points are still mapped properly.
*/
int rw = raster.getWidth();
int rh = raster.getHeight();
if (srcX > rw || srcY > rh) {
return false;
}
int right, bottom, wid, hgt;
if (srcX + srcWidth > rw) {
right = rw;
wid = right - srcX;
} else {
right = srcX + srcWidth;
wid = srcWidth;
}
if (srcY + srcHeight > rh) {
bottom = rh;
hgt = bottom - srcY;
} else {
bottom = srcY + srcHeight;
hgt = srcHeight;
}
pixels = new int[wid];
for (int j = srcY; j < bottom; j++) {
int startx = -1;
raster.getPixels(srcX, j, wid, 1, pixels);
for (int i = srcX; i < right; i++) {
if (alphas[pixels[i - srcX]] == 0) {
if (startx >= 0) {
subImage = bufferedImage.getSubimage(startx, j, i - startx, 1);
xform.translate(startx, j);
drawImageToPlatform(subImage, xform, bgcolor, 0, 0, i - startx, 1, true);
xform.translate(-startx, -j);
startx = -1;
}
} else if (startx < 0) {
startx = i;
}
}
if (startx >= 0) {
subImage = bufferedImage.getSubimage(startx, j, right - startx, 1);
xform.translate(startx, j);
drawImageToPlatform(subImage, xform, bgcolor, 0, 0, right - startx, 1, true);
xform.translate(-startx, -j);
}
}
return true;
}
use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.
the class TopDownTest method createTestImage.
private static BufferedImage createTestImage(int bpp) {
BufferedImage img = null;
switch(bpp) {
case 8:
img = new BufferedImage(100, 100, TYPE_BYTE_INDEXED);
break;
case 4:
{
byte[] r = new byte[16];
byte[] g = new byte[16];
byte[] b = new byte[16];
r[1] = (byte) 0xff;
b[0] = (byte) 0xff;
IndexColorModel icm = new IndexColorModel(4, 16, r, g, b);
img = new BufferedImage(100, 100, TYPE_BYTE_INDEXED, icm);
}
break;
case 24:
default:
img = new BufferedImage(100, 100, TYPE_INT_RGB);
}
Graphics g = img.createGraphics();
g.setColor(Color.blue);
g.fillRect(0, 0, 100, 50);
g.setColor(Color.red);
g.fillRect(0, 50, 100, 50);
g.dispose();
return img;
}
use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.
the class AnimationTest method initFrame.
private void initFrame() {
if (img != null) {
return;
}
byte[] r = new byte[256];
byte[] g = new byte[256];
byte[] b = new byte[256];
for (int i = 0; i < 256; i++) {
r[i] = g[i] = b[i] = (byte) 0x00;
}
r[0] = (byte) 0x00;
g[0] = (byte) 0x00;
b[0] = (byte) 0x00;
r[1] = (byte) 0xFF;
g[1] = (byte) 0xFF;
b[1] = (byte) 0xFF;
r[2] = (byte) 0xFF;
g[3] = (byte) 0xFF;
b[4] = (byte) 0xFF;
IndexColorModel icm = new IndexColorModel(8, 256, r, g, b);
img = new BufferedImage(w, h, BufferedImage.TYPE_BYTE_INDEXED, icm);
}
use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.
the class RleEncodingTest method encodeRLE4Test.
private static void encodeRLE4Test() throws IOException {
// create 4bpp image
byte[] r = new byte[16];
r[0] = (byte) 0xff;
byte[] g = new byte[16];
g[1] = (byte) 0xff;
byte[] b = new byte[16];
b[2] = (byte) 0xff;
IndexColorModel icm = new IndexColorModel(4, 16, r, g, b);
BufferedImage bimg = new BufferedImage(100, 100, BufferedImage.TYPE_BYTE_BINARY, icm);
Graphics gr = bimg.getGraphics();
gr.setColor(Color.green);
gr.fillRect(0, 0, 100, 100);
doTest(bimg, "BI_RLE4", ImageWriteParam.MODE_EXPLICIT);
}
use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.
the class GrayPngTest method getTestImage.
private BufferedImage getTestImage(int trans_type, int trans_pixel) {
IndexColorModel icm = null;
switch(trans_type) {
case Transparency.OPAQUE:
icm = new IndexColorModel(bpp, numColors, r, g, b);
break;
case Transparency.BITMASK:
icm = new IndexColorModel(bpp, numColors, r, g, b, trans_pixel);
break;
case Transparency.TRANSLUCENT:
a = Arrays.copyOf(r, r.length);
icm = new IndexColorModel(bpp, numColors, r, g, b, a);
break;
default:
throw new RuntimeException("Invalid transparency: " + trans_type);
}
int w = 256 * 2;
int h = 200;
dx = w / (numColors);
WritableRaster wr = icm.createCompatibleWritableRaster(w, h);
for (int i = 0; i < numColors; i++) {
int rx = i * dx;
int[] samples = new int[h * dx];
Arrays.fill(samples, i);
wr.setPixels(rx, 0, dx, h, samples);
}
// horizontal line with transparent color
int[] samples = new int[w * 10];
Arrays.fill(samples, trans_pixel);
wr.setPixels(0, h / 2 - 5, w, 10, samples);
// create index color model
return new BufferedImage(icm, wr, false, null);
}
Aggregations