use of sun.awt.image.ToolkitImage 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.ToolkitImage 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.ToolkitImage in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method getResolutionVariant.
private Image getResolutionVariant(MultiResolutionImage img, int srcWidth, int srcHeight, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, AffineTransform xform) {
if (srcWidth <= 0 || srcHeight <= 0) {
return null;
}
int sw = sx2 - sx1;
int sh = sy2 - sy1;
if (sw == 0 || sh == 0) {
return null;
}
AffineTransform tx;
if (xform == null) {
tx = transform;
} else {
tx = new AffineTransform(transform);
tx.concatenate(xform);
}
int type = tx.getType();
int dw = dx2 - dx1;
int dh = dy2 - dy1;
double destImageWidth;
double destImageHeight;
if (resolutionVariantHint == SunHints.INTVAL_RESOLUTION_VARIANT_BASE) {
destImageWidth = srcWidth;
destImageHeight = srcHeight;
} else if (resolutionVariantHint == SunHints.INTVAL_RESOLUTION_VARIANT_DPI_FIT) {
AffineTransform configTransform = getDefaultTransform();
if (configTransform.isIdentity()) {
destImageWidth = srcWidth;
destImageHeight = srcHeight;
} else {
destImageWidth = srcWidth * configTransform.getScaleX();
destImageHeight = srcHeight * configTransform.getScaleY();
}
} else {
double destRegionWidth;
double destRegionHeight;
if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) {
destRegionWidth = dw;
destRegionHeight = dh;
} else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) {
destRegionWidth = dw * transform.getScaleX();
destRegionHeight = dh * transform.getScaleY();
} else {
destRegionWidth = dw * Math.hypot(transform.getScaleX(), transform.getShearY());
destRegionHeight = dh * Math.hypot(transform.getShearX(), transform.getScaleY());
}
destImageWidth = Math.abs(srcWidth * destRegionWidth / sw);
destImageHeight = Math.abs(srcHeight * destRegionHeight / sh);
}
Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight);
if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) {
return null;
}
return resolutionVariant;
}
use of sun.awt.image.ToolkitImage 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);
}
}
use of sun.awt.image.ToolkitImage in project jdk8u_jdk by JetBrains.
the class XIconWindow method setIconImage.
void setIconImage(Image img) {
if (img == null) {
//if image is null, reset to default image
replaceImage(null);
replaceMask(null);
} else {
//get image size
int width;
int height;
if (img instanceof ToolkitImage) {
ImageRepresentation ir = ((ToolkitImage) img).getImageRep();
ir.reconstruct(ImageObserver.ALLBITS);
width = ir.getWidth();
height = ir.getHeight();
} else {
width = img.getWidth(null);
height = img.getHeight(null);
}
Dimension iconSize = getIconSize(width, height);
if (iconSize != null) {
if (log.isLoggable(PlatformLogger.Level.FINEST)) {
log.finest("Icon size: {0}", iconSize);
}
iconWidth = iconSize.width;
iconHeight = iconSize.height;
} else {
log.finest("Error calculating image size");
iconWidth = 0;
iconHeight = 0;
}
replaceImage(img);
replaceMask(img);
}
//create icon window and set XWMHints
XToolkit.awtLock();
try {
AwtGraphicsConfigData adata = parent.getGraphicsConfigurationData();
awtImageData awtImage = adata.get_awtImage(0);
XVisualInfo visInfo = adata.get_awt_visInfo();
XWMHints hints = parent.getWMHints();
window = hints.get_icon_window();
if (window == 0) {
log.finest("Icon window wasn't set");
XCreateWindowParams params = getDelayedParams();
params.add(BORDER_PIXEL, Long.valueOf(XToolkit.getAwtDefaultFg()));
params.add(BACKGROUND_PIXMAP, iconPixmap);
params.add(COLORMAP, adata.get_awt_cmap());
params.add(DEPTH, awtImage.get_Depth());
params.add(VISUAL_CLASS, (int) XConstants.InputOutput);
params.add(VISUAL, visInfo.get_visual());
params.add(VALUE_MASK, XConstants.CWBorderPixel | XConstants.CWColormap | XConstants.CWBackPixmap);
params.add(PARENT_WINDOW, XlibWrapper.RootWindow(XToolkit.getDisplay(), visInfo.get_screen()));
params.add(BOUNDS, new Rectangle(0, 0, iconWidth, iconHeight));
params.remove(DELAYED);
init(params);
if (getWindow() == 0) {
log.finest("Can't create new icon window");
} else {
log.finest("Created new icon window");
}
}
if (getWindow() != 0) {
XlibWrapper.XSetWindowBackgroundPixmap(XToolkit.getDisplay(), getWindow(), iconPixmap);
XlibWrapper.XClearWindow(XToolkit.getDisplay(), getWindow());
}
// Provide both pixmap and window, WM or Taskbar will use the one they find more appropriate
long newFlags = hints.get_flags() | XUtilConstants.IconPixmapHint | XUtilConstants.IconMaskHint;
if (getWindow() != 0) {
newFlags |= XUtilConstants.IconWindowHint;
}
hints.set_flags(newFlags);
hints.set_icon_pixmap(iconPixmap);
hints.set_icon_mask(iconMask);
hints.set_icon_window(getWindow());
XlibWrapper.XSetWMHints(XToolkit.getDisplay(), parent.getShell(), hints.pData);
log.finest("Set icon window hint");
} finally {
XToolkit.awtUnlock();
}
}
Aggregations