Java 类sun.awt.image.MultiResolutionImage 实例源码

项目:jdk8u-jdk    文件:MultiResolutionImageTest.java   
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);
    }
项目:jdk8u-jdk    文件:MultiResolutionImageTest.java   
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");
        }
    }
项目:lookaside_java-1.8.0-openjdk    文件:MultiResolutionImageTest.java   
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);
    }
项目:lookaside_java-1.8.0-openjdk    文件:MultiResolutionImageTest.java   
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");
        }
    }
项目:infobip-open-jdk-8    文件:MultiResolutionImageTest.java   
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);
    }
项目:infobip-open-jdk-8    文件:MultiResolutionImageTest.java   
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");
        }
    }
项目:jdk8u-dev-jdk    文件:MultiResolutionImageTest.java   
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);
    }
项目:jdk8u-dev-jdk    文件:MultiResolutionImageTest.java   
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");
        }
    }
项目:OpenJSharp    文件:CImage.java   
public CImage createFromImage(final Image image) {
    if (image instanceof MultiResolutionImage) {
        List<Image> resolutionVariants
                = ((MultiResolutionImage) image).getResolutionVariants();
        return createFromImages(resolutionVariants);
    }

    int[] buffer = imageToArray(image, true);
    if (buffer == null) {
        return null;
    }
    return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
项目:jdk8u-jdk    文件:CImage.java   
private CImage createFromImage(final Image image, final boolean prepareImage) {
    if (image instanceof MultiResolutionImage) {
        List<Image> resolutionVariants
                = ((MultiResolutionImage) image).getResolutionVariants();
        return createFromImages(resolutionVariants, prepareImage);
    }

    int[] buffer = imageToArray(image, prepareImage);
    if (buffer == null) {
        return null;
    }
    return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
项目:jdk8u-jdk    文件:NSImageToMultiResolutionImageTest.java   
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
项目:lookaside_java-1.8.0-openjdk    文件:CImage.java   
private CImage createFromImage(final Image image, final boolean prepareImage) {
    if (image instanceof MultiResolutionImage) {
        List<Image> resolutionVariants
                = ((MultiResolutionImage) image).getResolutionVariants();
        return createFromImages(resolutionVariants, prepareImage);
    }

    int[] buffer = imageToArray(image, prepareImage);
    if (buffer == null) {
        return null;
    }
    return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
项目:lookaside_java-1.8.0-openjdk    文件:NSImageToMultiResolutionImageTest.java   
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
项目:infobip-open-jdk-8    文件:CImage.java   
public CImage createFromImage(final Image image) {
    if (image instanceof MultiResolutionImage) {
        List<Image> resolutionVariants
                = ((MultiResolutionImage) image).getResolutionVariants();
        return createFromImages(resolutionVariants);
    }

    int[] buffer = imageToArray(image, true);
    if (buffer == null) {
        return null;
    }
    return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
项目:infobip-open-jdk-8    文件:NSImageToMultiResolutionImageTest.java   
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
项目:jdk8u-dev-jdk    文件:CImage.java   
public CImage createFromImage(final Image image) {
    if (image instanceof MultiResolutionImage) {
        List<Image> resolutionVariants
                = ((MultiResolutionImage) image).getResolutionVariants();
        return createFromImages(resolutionVariants);
    }

    int[] buffer = imageToArray(image, true);
    if (buffer == null) {
        return null;
    }
    return new CImage(nativeCreateNSImageFromArray(buffer, image.getWidth(null), image.getHeight(null)));
}
项目:jdk8u-dev-jdk    文件:NSImageToMultiResolutionImageTest.java   
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

        String icon = "NSImage://NSApplicationIcon";
        final Image image = Toolkit.getDefaultToolkit().getImage(icon);

        if (!(image instanceof MultiResolutionImage)) {
            throw new RuntimeException("Icon does not have resolution variants!");
        }

        MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

        int width = 0;
        int height = 0;

        for (Image resolutionVariant : multiResolutionImage.getResolutionVariants()) {
            int rvWidth = resolutionVariant.getWidth(null);
            int rvHeight = resolutionVariant.getHeight(null);
            if (rvWidth < width || rvHeight < height) {
                throw new RuntimeException("Resolution variants are not sorted!");
            }
            width = rvWidth;
            height = rvHeight;
        }
    }
项目:OpenJSharp    文件:SunGraphics2D.java   
private boolean isHiDPIImage(final Image img) {
    return (SurfaceManager.getImageScale(img) != 1) ||
           (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF
                && img instanceof MultiResolutionImage);
}
项目:OpenJSharp    文件:SunGraphics2D.java   
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) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        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) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) 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;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
项目:OpenJSharp    文件:SunGraphics2D.java   
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;
}
项目:jdk8u-jdk    文件:SunGraphics2D.java   
private boolean isHiDPIImage(final Image img) {
    return (SurfaceManager.getImageScale(img) != 1) ||
           (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF
                && img instanceof MultiResolutionImage);
}
项目:jdk8u-jdk    文件:SunGraphics2D.java   
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) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        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) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) 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;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
项目:jdk8u-jdk    文件:SunGraphics2D.java   
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;
}
项目:jdk8u-jdk    文件:MultiResolutionImageTest.java   
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");
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:SunGraphics2D.java   
private boolean isHiDPIImage(final Image img) {
    return (SurfaceManager.getImageScale(img) != 1) ||
           (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF
                && img instanceof MultiResolutionImage);
}
项目:lookaside_java-1.8.0-openjdk    文件:SunGraphics2D.java   
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) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        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) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) 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;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:SunGraphics2D.java   
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;
}
项目:lookaside_java-1.8.0-openjdk    文件:MultiResolutionImageTest.java   
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");
    }
}
项目:infobip-open-jdk-8    文件:SunGraphics2D.java   
private boolean isHiDPIImage(final Image img) {
    return (SurfaceManager.getImageScale(img) != 1) ||
           (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF
                && img instanceof MultiResolutionImage);
}
项目:infobip-open-jdk-8    文件:SunGraphics2D.java   
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) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        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) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) 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;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
项目:infobip-open-jdk-8    文件:SunGraphics2D.java   
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;
}
项目:infobip-open-jdk-8    文件:MultiResolutionImageTest.java   
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");
    }
}
项目:jdk8u-dev-jdk    文件:SunGraphics2D.java   
private boolean isHiDPIImage(final Image img) {
    return (SurfaceManager.getImageScale(img) != 1) ||
           (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF
                && img instanceof MultiResolutionImage);
}
项目:jdk8u-dev-jdk    文件:SunGraphics2D.java   
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) {

    if (SurfaceManager.getImageScale(img) != 1) {  // Volatile Image
        final int scale = SurfaceManager.getImageScale(img);
        sx1 = Region.clipScale(sx1, scale);
        sx2 = Region.clipScale(sx2, scale);
        sy1 = Region.clipScale(sy1, scale);
        sy2 = Region.clipScale(sy2, scale);
    } else if (img instanceof MultiResolutionImage) {
        // get scaled destination image size

        int width = img.getWidth(observer);
        int height = img.getHeight(observer);

        Image resolutionVariant = getResolutionVariant(
                (MultiResolutionImage) img, width, height,
                dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2);

        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) {

                float widthScale = ((float) rvWidth) / width;
                float heightScale = ((float) 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;
            }
        }
    }

    try {
        return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
                                    sx2, sy2, bgcolor, observer);
    } catch (InvalidPipeException e) {
        try {
            revalidateAll();
            return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
                                        sy1, sx2, sy2, bgcolor, observer);
        } catch (InvalidPipeException e2) {
            // Still catching the exception; we are not yet ready to
            // validate the surfaceData correctly.  Fail for now and
            // try again next time around.
            return false;
        }
    } finally {
        surfaceData.markDirty();
    }
}
项目:jdk8u-dev-jdk    文件:SunGraphics2D.java   
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;
}
项目:jdk8u-dev-jdk    文件:MultiResolutionImageTest.java   
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");
    }
}