use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.
the class DrawImage method scaleImage.
public boolean scaleImage(SunGraphics2D sg, Image img, int x, int y, int width, int height, Color bgColor, ImageObserver observer) {
if (!(img instanceof ToolkitImage)) {
return scaleImage(sg, img, x, y, width, height, bgColor);
} else {
ToolkitImage sunimg = (ToolkitImage) img;
if (!imageReady(sunimg, observer)) {
return false;
}
ImageRepresentation ir = sunimg.getImageRep();
return ir.drawToBufImage(sg, sunimg, x, y, width, height, bgColor, observer);
}
}
use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.
the class HTMLCodec method imageToPlatformBytes.
@Override
protected byte[] imageToPlatformBytes(Image image, long format) throws IOException {
String mimeType = null;
if (format == CF_PNG) {
mimeType = "image/png";
} else if (format == CF_JFIF) {
mimeType = "image/jpeg";
}
if (mimeType != null) {
return imageToStandardBytes(image, mimeType);
}
int width = 0;
int height = 0;
if (image instanceof ToolkitImage) {
ImageRepresentation ir = ((ToolkitImage) image).getImageRep();
ir.reconstruct(ImageObserver.ALLBITS);
width = ir.getWidth();
height = ir.getHeight();
} else {
width = image.getWidth(null);
height = image.getHeight(null);
}
// Fix for 4919639.
// Some Windows native applications (e.g. clipbrd.exe) do not handle
// 32-bpp DIBs correctly.
// As a workaround we switched to 24-bpp DIBs.
// MSDN prescribes that the bitmap array for a 24-bpp should consist of
// 3-byte triplets representing blue, green and red components of a
// pixel respectively. Additionally each scan line must be padded with
// zeroes to end on a LONG data-type boundary. LONG is always 32-bit.
// We render the given Image to a BufferedImage of type TYPE_3BYTE_BGR
// with non-default scanline stride and pass the resulting data buffer
// to the native code to fill the BITMAPINFO structure.
int mod = (width * 3) % 4;
int pad = mod > 0 ? 4 - mod : 0;
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB);
int[] nBits = { 8, 8, 8 };
int[] bOffs = { 2, 1, 0 };
ColorModel colorModel = new ComponentColorModel(cs, nBits, false, false, Transparency.OPAQUE, DataBuffer.TYPE_BYTE);
WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, height, width * 3 + pad, 3, bOffs, null);
BufferedImage bimage = new BufferedImage(colorModel, raster, false, null);
// Some Windows native applications (e.g. clipbrd.exe) do not understand
// top-down DIBs.
// So we flip the image vertically and create a bottom-up DIB.
AffineTransform imageFlipTransform = new AffineTransform(1, 0, 0, -1, 0, height);
Graphics2D g2d = bimage.createGraphics();
try {
g2d.drawImage(image, imageFlipTransform, null);
} finally {
g2d.dispose();
}
DataBufferByte buffer = (DataBufferByte) raster.getDataBuffer();
byte[] imageData = buffer.getData();
return imageDataToPlatformImageBytes(imageData, width, height, format);
}
use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.
the class ToolkitImage method reconstruct.
private synchronized void reconstruct(int flags) {
if ((flags & ~availinfo) != 0) {
if ((availinfo & ImageObserver.ERROR) != 0) {
return;
}
ImageRepresentation ir = getImageRep();
ir.startProduction();
while ((flags & ~availinfo) != 0) {
try {
wait();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return;
}
if ((availinfo & ImageObserver.ERROR) != 0) {
return;
}
}
}
}
use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.
the class ToolkitImage method addWatcher.
private synchronized void addWatcher(ImageObserver iw, boolean load) {
if ((availinfo & ImageObserver.ERROR) != 0) {
if (iw != null) {
iw.imageUpdate(this, ImageObserver.ERROR | ImageObserver.ABORT, -1, -1, -1, -1);
}
return;
}
ImageRepresentation ir = getImageRep();
ir.addWatcher(iw);
if (load) {
ir.startProduction();
}
}
use of sun.awt.image.ImageRepresentation in project jdk8u_jdk by JetBrains.
the class DrawImage method copyImage.
public boolean copyImage(SunGraphics2D sg, Image img, int x, int y, Color bgColor, ImageObserver observer) {
if (!(img instanceof ToolkitImage)) {
return copyImage(sg, img, x, y, bgColor);
} else {
ToolkitImage sunimg = (ToolkitImage) img;
if (!imageReady(sunimg, observer)) {
return false;
}
ImageRepresentation ir = sunimg.getImageRep();
return ir.drawToBufImage(sg, sunimg, x, y, bgColor, observer);
}
}
Aggregations