use of java.awt.image.DataBuffer in project playn by threerings.
the class JavaGLContext method updateTexture.
void updateTexture(int tex, BufferedImage image) {
// Convert the image into a format for quick uploading
image = convertImage(image);
DataBuffer dbuf = image.getRaster().getDataBuffer();
ByteBuffer bbuf;
int format, type;
if (image.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {
DataBufferInt ibuf = (DataBufferInt) dbuf;
int iSize = ibuf.getSize() * 4;
bbuf = checkGetImageBuffer(iSize);
bbuf.asIntBuffer().put(ibuf.getData());
bbuf.position(bbuf.position() + iSize);
bbuf.flip();
format = GL12.GL_BGRA;
type = GL12.GL_UNSIGNED_INT_8_8_8_8_REV;
} else if (image.getType() == BufferedImage.TYPE_4BYTE_ABGR) {
DataBufferByte dbbuf = (DataBufferByte) dbuf;
bbuf = checkGetImageBuffer(dbbuf.getSize());
bbuf.put(dbbuf.getData());
bbuf.flip();
format = GL11.GL_RGBA;
type = GL12.GL_UNSIGNED_INT_8_8_8_8;
} else {
// except we don't know how to deal with it
throw new RuntimeException("Image type wasn't converted to usable: " + image.getType());
}
bindTexture(tex);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, image.getWidth(), image.getHeight(), 0, format, type, bbuf);
checkGLError("updateTexture");
}
use of java.awt.image.DataBuffer in project jdk8u_jdk by JetBrains.
the class IncorrectClipXorModeSW2Surface method getBufferedImage.
private static BufferedImage getBufferedImage(int sw) {
final BufferedImage bi = new BufferedImage(sw, sw, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = bi.createGraphics();
g2d.setColor(Color.RED);
g2d.fillRect(0, 0, sw, sw);
g2d.dispose();
final DataBuffer db = bi.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
bi.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return bi;
}
use of java.awt.image.DataBuffer in project jdk8u_jdk by JetBrains.
the class InvalidTransformParameterTest method main.
public static void main(String[] args) {
int count = 0;
final int testScenarios = 12;
double NaNArg = 0.0 / 0.0;
double positiveInfArg = 1.0 / 0.0;
double negativeInfArg = -1.0 / 0.0;
BufferedImage img = new BufferedImage(5, 5, BufferedImage.TYPE_INT_ARGB);
AffineTransform[] inputTransforms = new AffineTransform[testScenarios];
for (int i = 0; i < inputTransforms.length; i++) {
inputTransforms[i] = new AffineTransform();
}
inputTransforms[0].rotate(NaNArg, img.getWidth() / 2, img.getHeight() / 2);
inputTransforms[1].translate(NaNArg, NaNArg);
inputTransforms[2].scale(NaNArg, NaNArg);
inputTransforms[3].shear(NaNArg, NaNArg);
inputTransforms[4].rotate(positiveInfArg, img.getWidth() / 2, img.getHeight() / 2);
inputTransforms[5].translate(positiveInfArg, positiveInfArg);
inputTransforms[6].scale(positiveInfArg, positiveInfArg);
inputTransforms[7].shear(positiveInfArg, positiveInfArg);
inputTransforms[8].rotate(negativeInfArg, img.getWidth() / 2, img.getHeight() / 2);
inputTransforms[9].translate(negativeInfArg, negativeInfArg);
inputTransforms[10].scale(negativeInfArg, negativeInfArg);
inputTransforms[11].shear(negativeInfArg, negativeInfArg);
for (int i = 0; i < inputTransforms.length; i++) {
try {
testImageTransform(img, inputTransforms[i]);
} catch (ImagingOpException ex) {
count++;
}
}
if (count != testScenarios) {
throw new RuntimeException("Test failed. All test scenarios did not" + " result in exception as expected.");
}
// Test Raster AffineTransform ---------------------------------
count = 0;
int[] bandOffsets = { 0 };
Point location = new Point(0, 0);
DataBuffer db = new DataBufferByte(10 * 10);
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, 10, 10, 1, 10, bandOffsets);
Raster src = Raster.createRaster(sm, db, location);
WritableRaster dst = Raster.createWritableRaster(sm, db, location);
for (int i = 0; i < inputTransforms.length; i++) {
try {
testRasterTransform(src, dst, inputTransforms[i]);
} catch (ImagingOpException ex) {
count++;
}
}
if (count != testScenarios) {
throw new RuntimeException("Test failed. All test scenarios did not" + " result in exception as expected.");
}
}
use of java.awt.image.DataBuffer in project jdk8u_jdk by JetBrains.
the class IncorrectSampleMaskTest method doTest.
private static void doTest(int dataType) {
int maxSize = DataBuffer.getDataTypeSize(dataType);
System.out.println("Type size: " + maxSize);
int theMask = (int) (1L << (maxSize + 2)) - 1;
System.out.printf("theMask=%x\n", theMask);
SinglePixelPackedSampleModel sm = new SinglePixelPackedSampleModel(dataType, w, h, new int[] { theMask });
int[] sampleSize = sm.getSampleSize();
for (int s : sampleSize) {
if (s > maxSize) {
throw new RuntimeException("Test failed: sample size is too big:" + s);
}
}
System.out.println("Test medialib...");
DataBuffer buf = createDataBuffer(dataType);
WritableRaster wr = Raster.createWritableRaster(sm, buf, null);
op.filter(wr, null);
System.out.println("Test PASSED.");
}
use of java.awt.image.DataBuffer in project jdk8u_jdk by JetBrains.
the class IncorrectUnmanagedImageRotatedClip method makeUnmanagedBI.
private static BufferedImage makeUnmanagedBI() {
final BufferedImage bi = new BufferedImage(500, 200, TYPE_INT_ARGB);
final DataBuffer db = bi.getRaster().getDataBuffer();
if (db instanceof DataBufferInt) {
((DataBufferInt) db).getData();
} else if (db instanceof DataBufferShort) {
((DataBufferShort) db).getData();
} else if (db instanceof DataBufferByte) {
((DataBufferByte) db).getData();
} else {
try {
bi.setAccelerationPriority(0.0f);
} catch (final Throwable ignored) {
}
}
return bi;
}
Aggregations