use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class OffScreenImageSource method sendPixels.
private void sendPixels() {
ColorModel cm = image.getColorModel();
WritableRaster raster = image.getRaster();
int numDataElements = raster.getNumDataElements();
int dataType = raster.getDataBuffer().getDataType();
int[] scanline = new int[width * numDataElements];
boolean needToCvt = true;
if (cm instanceof IndexColorModel) {
byte[] pixels = new byte[width];
theConsumer.setColorModel(cm);
if (raster instanceof ByteComponentRaster) {
needToCvt = false;
for (int y = 0; y < height; y++) {
raster.getDataElements(0, y, width, 1, pixels);
theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width);
}
} else if (raster instanceof BytePackedRaster) {
needToCvt = false;
// Binary image. Need to unpack it
for (int y = 0; y < height; y++) {
raster.getPixels(0, y, width, 1, scanline);
for (int x = 0; x < width; x++) {
pixels[x] = (byte) scanline[x];
}
theConsumer.setPixels(0, y, width, 1, cm, pixels, 0, width);
}
} else if (dataType == DataBuffer.TYPE_SHORT || dataType == DataBuffer.TYPE_INT) {
// Probably a short or int "GRAY" image
needToCvt = false;
for (int y = 0; y < height; y++) {
raster.getPixels(0, y, width, 1, scanline);
theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width);
}
}
} else if (cm instanceof DirectColorModel) {
theConsumer.setColorModel(cm);
needToCvt = false;
switch(dataType) {
case DataBuffer.TYPE_INT:
for (int y = 0; y < height; y++) {
raster.getDataElements(0, y, width, 1, scanline);
theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width);
}
break;
case DataBuffer.TYPE_BYTE:
byte[] bscanline = new byte[width];
for (int y = 0; y < height; y++) {
raster.getDataElements(0, y, width, 1, bscanline);
for (int x = 0; x < width; x++) {
scanline[x] = bscanline[x] & 0xff;
}
theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width);
}
break;
case DataBuffer.TYPE_USHORT:
short[] sscanline = new short[width];
for (int y = 0; y < height; y++) {
raster.getDataElements(0, y, width, 1, sscanline);
for (int x = 0; x < width; x++) {
scanline[x] = sscanline[x] & 0xffff;
}
theConsumer.setPixels(0, y, width, 1, cm, scanline, 0, width);
}
break;
default:
needToCvt = true;
}
}
if (needToCvt) {
// REMIND: Need to add other types of CMs here
ColorModel newcm = ColorModel.getRGBdefault();
theConsumer.setColorModel(newcm);
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
scanline[x] = image.getRGB(x, y);
}
theConsumer.setPixels(0, y, width, 1, newcm, scanline, 0, width);
}
}
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class ImageRepresentation method getOpaqueRGBImage.
public BufferedImage getOpaqueRGBImage() {
if (bimage.getType() == BufferedImage.TYPE_INT_ARGB) {
int w = bimage.getWidth();
int h = bimage.getHeight();
int size = w * h;
// Note that we steal the data array here, but only for reading...
DataBufferInt db = (DataBufferInt) biRaster.getDataBuffer();
int[] pixels = SunWritableRaster.stealData(db, 0);
for (int i = 0; i < size; i++) {
if ((pixels[i] >>> 24) != 0xff) {
return bimage;
}
}
ColorModel opModel = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
int[] bandmasks = { 0x00ff0000, 0x0000ff00, 0x000000ff };
WritableRaster opRaster = Raster.createPackedRaster(db, w, h, w, bandmasks, null);
try {
BufferedImage opImage = createImage(opModel, opRaster, false, null);
return opImage;
} catch (Exception e) {
return bimage;
}
}
return bimage;
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class CGLGraphicsConfig method createAcceleratedImage.
@Override
public Image createAcceleratedImage(Component target, int width, int height) {
ColorModel model = getColorModel(Transparency.OPAQUE);
WritableRaster wr = model.createCompatibleWritableRaster(width, height);
return new OffScreenImage(target, model, wr, model.isAlphaPremultiplied());
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class CGLGraphicsConfig method createCompatibleImage.
@Override
public BufferedImage createCompatibleImage(int width, int height) {
ColorModel model = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
WritableRaster raster = model.createCompatibleWritableRaster(width, height);
return new BufferedImage(model, raster, model.isAlphaPremultiplied(), null);
}
use of java.awt.image.WritableRaster in project jdk8u_jdk by JetBrains.
the class JPEGImageWriter method grabPixels.
/**
* Put the scanline y of the source ROI view Raster into the
* 1-line Raster for writing. This handles ROI and band
* rearrangements, and expands indexed images. Subsampling is
* done in the native code.
* This is called by the native code.
*/
private void grabPixels(int y) {
Raster sourceLine = null;
if (indexed) {
sourceLine = srcRas.createChild(sourceXOffset, sourceYOffset + y, sourceWidth, 1, 0, 0, new int[] { 0 });
// If the image has BITMASK transparency, we need to make sure
// it gets converted to 32-bit ARGB, because the JPEG encoder
// relies upon the full 8-bit alpha channel.
boolean forceARGB = (indexCM.getTransparency() != Transparency.OPAQUE);
BufferedImage temp = indexCM.convertToIntDiscrete(sourceLine, forceARGB);
sourceLine = temp.getRaster();
} else {
sourceLine = srcRas.createChild(sourceXOffset, sourceYOffset + y, sourceWidth, 1, 0, 0, srcBands);
}
if (convertTosRGB) {
if (debug) {
System.out.println("Converting to sRGB");
}
// The first time through, converted is null, so
// a new raster is allocated. It is then reused
// on subsequent lines.
converted = convertOp.filter(sourceLine, converted);
sourceLine = converted;
}
if (isAlphaPremultiplied) {
WritableRaster wr = sourceLine.createCompatibleWritableRaster();
int[] data = null;
data = sourceLine.getPixels(sourceLine.getMinX(), sourceLine.getMinY(), sourceLine.getWidth(), sourceLine.getHeight(), data);
wr.setPixels(sourceLine.getMinX(), sourceLine.getMinY(), sourceLine.getWidth(), sourceLine.getHeight(), data);
srcCM.coerceData(wr, false);
sourceLine = wr.createChild(wr.getMinX(), wr.getMinY(), wr.getWidth(), wr.getHeight(), 0, 0, srcBands);
}
raster.setRect(sourceLine);
if ((y > 7) && (y % 8 == 0)) {
// Every 8 scanlines
cbLock.lock();
try {
processImageProgress((float) y / (float) sourceHeight * 100.0F);
} finally {
cbLock.unlock();
}
}
}
Aggregations