use of java.awt.image.MultiResolutionImage 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 java.awt.image.MultiResolutionImage in project jdk8u_jdk by JetBrains.
the class SunGraphics2D method drawHiDPIImage.
// end of text rendering methods
private Boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgcolor, ImageObserver observer, AffineTransform xform) {
if (img instanceof VolatileImage) {
final SurfaceData sd = SurfaceManager.getManager(img).getPrimarySurfaceData();
final double scaleX = sd.getDefaultScaleX();
final double scaleY = sd.getDefaultScaleY();
if (scaleX == 1 && scaleY == 1) {
return null;
}
sx1 = Region.clipScale(sx1, scaleX);
sx2 = Region.clipScale(sx2, scaleX);
sy1 = Region.clipScale(sy1, scaleY);
sy2 = Region.clipScale(sy2, scaleY);
AffineTransform tx = null;
if (xform != null) {
tx = new AffineTransform(transform);
transform(xform);
}
boolean result = scaleImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
if (tx != null) {
transform.setTransform(tx);
invalidateTransform();
}
return result;
} else if (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_BASE && (img instanceof MultiResolutionImage)) {
// get scaled destination image size
int width = img.getWidth(observer);
int height = img.getHeight(observer);
MultiResolutionImage mrImage = (MultiResolutionImage) img;
Image resolutionVariant = getResolutionVariant(mrImage, width, height, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, xform);
if (resolutionVariant != img && resolutionVariant != null) {
// recalculate source region for the resolution variant
ImageObserver rvObserver = MultiResolutionToolkitImage.getResolutionVariantObserver(img, observer, width, height, -1, -1);
int rvWidth = resolutionVariant.getWidth(rvObserver);
int rvHeight = resolutionVariant.getHeight(rvObserver);
if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {
double widthScale = ((double) rvWidth) / width;
double heightScale = ((double) rvHeight) / height;
sx1 = Region.clipScale(sx1, widthScale);
sy1 = Region.clipScale(sy1, heightScale);
sx2 = Region.clipScale(sx2, widthScale);
sy2 = Region.clipScale(sy2, heightScale);
observer = rvObserver;
img = resolutionVariant;
if (xform != null) {
assert dx1 == 0 && dy1 == 0;
assert dx2 == img.getWidth(observer);
assert dy2 == img.getHeight(observer);
AffineTransform renderTX = new AffineTransform(xform);
renderTX.scale(1 / widthScale, 1 / heightScale);
return transformImage(img, renderTX, observer);
}
return scaleImage(img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgcolor, observer);
}
}
}
return null;
}
use of java.awt.image.MultiResolutionImage in project jdk8u_jdk by JetBrains.
the class MultiResolutionImageTest method testToolkitMultiResolutionImageChache.
static void testToolkitMultiResolutionImageChache(String fileName, URL url) {
Image img1 = Toolkit.getDefaultToolkit().getImage(fileName);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
Image img2 = Toolkit.getDefaultToolkit().getImage(fileName);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
img1 = Toolkit.getDefaultToolkit().getImage(url);
if (!(img1 instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
img2 = Toolkit.getDefaultToolkit().getImage(url);
if (img1 != img2) {
throw new RuntimeException("Image is not cached");
}
}
use of java.awt.image.MultiResolutionImage in project jdk8u_jdk by JetBrains.
the class MultiResolutionImageTest method testToolkitMultiResolutionImage.
static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics();
setImageScalingHint(g1x, false);
g1x.drawImage(image, 0, 0, null);
checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false);
Image resolutionVariant = ((MultiResolutionImage) image).getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);
if (resolutionVariant == null) {
throw new RuntimeException("Resolution variant is null");
}
MediaTracker tracker2x = new MediaTracker(new JPanel());
tracker2x.addImage(resolutionVariant, 0);
tracker2x.waitForID(0);
if (tracker2x.isErrorAny()) {
throw new RuntimeException("Error during scalable image loading");
}
final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics();
setImageScalingHint(g2x, enableImageScaling);
g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling);
if (!(image instanceof MultiResolutionImage)) {
throw new RuntimeException("Not a MultiResolutionImage");
}
MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;
Image image1x = multiResolutionImage.getResolutionVariant(IMAGE_WIDTH, IMAGE_HEIGHT);
Image image2x = multiResolutionImage.getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);
if (image1x.getWidth(null) * 2 != image2x.getWidth(null) || image1x.getHeight(null) * 2 != image2x.getHeight(null)) {
throw new RuntimeException("Wrong resolution variant size");
}
}
use of java.awt.image.MultiResolutionImage in project jdk8u_jdk by JetBrains.
the class MultiResolutionImageTest method testToolkitMultiResolutionImageLoad.
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {
MediaTracker tracker = new MediaTracker(new JPanel());
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorAny()) {
throw new RuntimeException("Error during image loading");
}
tracker.removeImage(image, 0);
testImageLoaded(image);
int w = image.getWidth(null);
int h = image.getHeight(null);
Image resolutionVariant = ((MultiResolutionImage) image).getResolutionVariant(2 * w, 2 * h);
if (image == resolutionVariant) {
throw new RuntimeException("Resolution variant is not loaded");
}
testImageLoaded(resolutionVariant);
}
Aggregations