Java Code Examples for sun.awt.image.MultiResolutionImage#getResolutionVariant()
The following examples show how to use
sun.awt.image.MultiResolutionImage#getResolutionVariant() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiResolutionImageTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 2
Source File: MultiResolutionImageTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 3
Source File: SunGraphics2D.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 4
Source File: MultiResolutionImageTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 5
Source File: SunGraphics2D.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 6
Source File: MultiResolutionImageTest.java From hottub with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 7
Source File: SunGraphics2D.java From hottub with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 8
Source File: MultiResolutionImageTest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 9
Source File: SunGraphics2D.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 10
Source File: SunGraphics2D.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 11
Source File: SunGraphics2D.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 12
Source File: MultiResolutionImageTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 13
Source File: SunGraphics2D.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 14
Source File: MultiResolutionImageTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 15
Source File: SunGraphics2D.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 16
Source File: MultiResolutionImageTest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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"); } }
Example 17
Source File: SunGraphics2D.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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) { if (srcWidth <= 0 || srcHeight <= 0) { return null; } int sw = sx2 - sx1; int sh = sy2 - sy1; if (sw == 0 || sh == 0) { return null; } int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; 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()); } int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight); if (resolutionVariant instanceof ToolkitImage && ((ToolkitImage) resolutionVariant).hasError()) { return null; } return resolutionVariant; }
Example 18
Source File: MultiResolutionImageTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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"); } }