use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.
the class MultipleGradientPaintContext method getRaster.
/**
* {@inheritDoc}
*/
public final Raster getRaster(int x, int y, int w, int h) {
// If working raster is big enough, reuse it. Otherwise,
// build a large enough new one.
Raster raster = saved;
if (raster == null || raster.getWidth() < w || raster.getHeight() < h) {
raster = getCachedRaster(model, w, h);
saved = raster;
}
// Access raster internal int array. Because we use a DirectColorModel,
// we know the DataBuffer is of type DataBufferInt and the SampleModel
// is SinglePixelPackedSampleModel.
// Adjust for initial offset in DataBuffer and also for the scanline
// stride.
// These calls make the DataBuffer non-acceleratable, but the
// Raster is never Stable long enough to accelerate anyway...
DataBufferInt rasterDB = (DataBufferInt) raster.getDataBuffer();
int[] pixels = rasterDB.getData(0);
int off = rasterDB.getOffset();
int scanlineStride = ((SinglePixelPackedSampleModel) raster.getSampleModel()).getScanlineStride();
int adjust = scanlineStride - w;
// delegate to subclass
fillRaster(pixels, off, adjust, x, y, w, h);
return raster;
}
use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.
the class PathGraphics method hasTransparentPixels.
/**
* Return true if the BufferedImage argument has non-opaque
* bits in it and therefore can not be directly rendered by
* GDI. Return false if the image is opaque. If this function
* can not tell for sure whether the image has transparent
* pixels then it assumes that it does.
*/
protected boolean hasTransparentPixels(BufferedImage bufferedImage) {
ColorModel colorModel = bufferedImage.getColorModel();
boolean hasTransparency = colorModel == null ? true : colorModel.getTransparency() != ColorModel.OPAQUE;
/*
* For the default INT ARGB check the image to see if any pixels are
* really transparent. If there are no transparent pixels then the
* transparency of the color model can be ignored.
* We assume that IndexColorModel images have already been
* checked for transparency and will be OPAQUE unless they actually
* have transparent pixels present.
*/
if (hasTransparency && bufferedImage != null) {
if (bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB || bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB_PRE) {
DataBuffer db = bufferedImage.getRaster().getDataBuffer();
SampleModel sm = bufferedImage.getRaster().getSampleModel();
if (db instanceof DataBufferInt && sm instanceof SinglePixelPackedSampleModel) {
SinglePixelPackedSampleModel psm = (SinglePixelPackedSampleModel) sm;
// Stealing the data array for reading only...
int[] int_data = SunWritableRaster.stealData((DataBufferInt) db, 0);
int x = bufferedImage.getMinX();
int y = bufferedImage.getMinY();
int w = bufferedImage.getWidth();
int h = bufferedImage.getHeight();
int stride = psm.getScanlineStride();
boolean hastranspixel = false;
for (int j = y; j < y + h; j++) {
int yoff = j * stride;
for (int i = x; i < x + w; i++) {
if ((int_data[yoff + i] & 0xff000000) != 0xff000000) {
hastranspixel = true;
break;
}
}
if (hastranspixel) {
break;
}
}
if (hastranspixel == false) {
hasTransparency = false;
}
}
}
}
return hasTransparency;
}
use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.
the class JLightweightFrame method resizeBuffer.
private void resizeBuffer(int width, int height, int newScaleFactor) {
bbImage = new BufferedImage(width * newScaleFactor, height * newScaleFactor, BufferedImage.TYPE_INT_ARGB_PRE);
int[] pixels = ((DataBufferInt) bbImage.getRaster().getDataBuffer()).getData();
if (copyBufferEnabled) {
syncCopyBuffer(true, 0, 0, width, height, newScaleFactor);
pixels = copyBuffer;
}
content.imageBufferReset(pixels, 0, 0, width, height, width * newScaleFactor, newScaleFactor);
}
use of java.awt.image.DataBufferInt in project jdk8u_jdk by JetBrains.
the class JLightweightFrame method syncCopyBuffer.
private void syncCopyBuffer(boolean reset, int x, int y, int w, int h, int scale) {
content.paintLock();
try {
int[] srcBuffer = ((DataBufferInt) bbImage.getRaster().getDataBuffer()).getData();
if (reset) {
copyBuffer = new int[srcBuffer.length];
}
int linestride = bbImage.getWidth();
x *= scale;
y *= scale;
w *= scale;
h *= scale;
for (int i = 0; i < h; i++) {
int from = (y + i) * linestride + x;
System.arraycopy(srcBuffer, from, copyBuffer, from, w);
}
} finally {
content.paintUnlock();
}
}
use of java.awt.image.DataBufferInt in project jmonkeyengine by jMonkeyEngine.
the class Screenshots method convertScreenShot2.
public static void convertScreenShot2(IntBuffer bgraBuf, BufferedImage out) {
WritableRaster wr = out.getRaster();
DataBufferInt db = (DataBufferInt) wr.getDataBuffer();
int[] cpuArray = db.getData();
bgraBuf.clear();
bgraBuf.get(cpuArray);
// int width = wr.getWidth();
// int height = wr.getHeight();
//
// // flip the components the way AWT likes them
// for (int y = 0; y < height / 2; y++){
// for (int x = 0; x < width; x++){
// int inPtr = (y * width + x);
// int outPtr = ((height-y-1) * width + x);
// int pixel = cpuArray[inPtr];
// cpuArray[inPtr] = cpuArray[outPtr];
// cpuArray[outPtr] = pixel;
// }
// }
}
Aggregations