1 /*
2 * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
3134
3135 int width = img.getWidth(observer);
3136 int height = img.getHeight(observer);
3137
3138 MultiResolutionImage mrImage = (MultiResolutionImage) img;
3139 Image resolutionVariant = getResolutionVariant(mrImage, width, height,
3140 dx1, dy1, dx2, dy2,
3141 sx1, sy1, sx2, sy2,
3142 xform);
3143
3144 if (resolutionVariant != img && resolutionVariant != null) {
3145 // recalculate source region for the resolution variant
3146
3147 ImageObserver rvObserver = MultiResolutionToolkitImage.
3148 getResolutionVariantObserver(img, observer,
3149 width, height, -1, -1);
3150
3151 int rvWidth = resolutionVariant.getWidth(rvObserver);
3152 int rvHeight = resolutionVariant.getHeight(rvObserver);
3153
3154 if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {
3155
3156 double widthScale = ((double) rvWidth) / width;
3157 double heightScale = ((double) rvHeight) / height;
3158
3159 if (resolutionVariant instanceof VolatileImage) {
3160 SurfaceData sd = SurfaceManager
3161 .getManager(resolutionVariant)
3162 .getPrimarySurfaceData();
3163 widthScale *= sd.getDefaultScaleX();
3164 heightScale *= sd.getDefaultScaleY();
3165 }
3166
3167 sx1 = Region.clipScale(sx1, widthScale);
3168 sy1 = Region.clipScale(sy1, heightScale);
3169 sx2 = Region.clipScale(sx2, widthScale);
3170 sy2 = Region.clipScale(sy2, heightScale);
3171
3172 observer = rvObserver;
3173 img = resolutionVariant;
3174
3175 if (xform != null) {
3176 assert dx1 == 0 && dy1 == 0;
3177 assert dx2 == img.getWidth(observer);
3178 assert dy2 == img.getHeight(observer);
3179 AffineTransform renderTX = new AffineTransform(xform);
3180 renderTX.scale(1 / widthScale, 1 / heightScale);
3181 return transformImage(img, renderTX, observer);
3182 }
3183
3184 return scaleImage(img, dx1, dy1, dx2, dy2,
3185 sx1, sy1, sx2, sy2,
3186 bgcolor, observer);
3187 }
3188 }
3189 }
3190 return null;
3191 }
3192
3193 private boolean scaleImage(Image img, int dx1, int dy1, int dx2, int dy2,
3194 int sx1, int sy1, int sx2, int sy2,
3195 Color bgcolor, ImageObserver observer)
3196 {
3197 try {
3198 return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
3199 sx2, sy2, bgcolor, observer);
3200 } catch (InvalidPipeException e) {
3201 try {
3202 revalidateAll();
3203 return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
3204 sy1, sx2, sy2, bgcolor, observer);
3205 } catch (InvalidPipeException e2) {
3206 // Still catching the exception; we are not yet ready to
|
1 /*
2 * Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
3134
3135 int width = img.getWidth(observer);
3136 int height = img.getHeight(observer);
3137
3138 MultiResolutionImage mrImage = (MultiResolutionImage) img;
3139 Image resolutionVariant = getResolutionVariant(mrImage, width, height,
3140 dx1, dy1, dx2, dy2,
3141 sx1, sy1, sx2, sy2,
3142 xform);
3143
3144 if (resolutionVariant != img && resolutionVariant != null) {
3145 // recalculate source region for the resolution variant
3146
3147 ImageObserver rvObserver = MultiResolutionToolkitImage.
3148 getResolutionVariantObserver(img, observer,
3149 width, height, -1, -1);
3150
3151 int rvWidth = resolutionVariant.getWidth(rvObserver);
3152 int rvHeight = resolutionVariant.getHeight(rvObserver);
3153
3154 if (rvWidth < 0 || rvHeight < 0) {
3155 // The resolution variant is not loaded yet, try to use default resolution
3156 resolutionVariant = mrImage.getResolutionVariant(width, height);
3157 rvWidth = resolutionVariant.getWidth(rvObserver);
3158 rvHeight = resolutionVariant.getHeight(rvObserver);
3159 }
3160
3161 if (0 < width && 0 < height && 0 < rvWidth && 0 < rvHeight) {
3162
3163 double widthScale = ((double) rvWidth) / width;
3164 double heightScale = ((double) rvHeight) / height;
3165
3166 if (resolutionVariant instanceof VolatileImage) {
3167 SurfaceData sd = SurfaceManager
3168 .getManager(resolutionVariant)
3169 .getPrimarySurfaceData();
3170 widthScale *= sd.getDefaultScaleX();
3171 heightScale *= sd.getDefaultScaleY();
3172 }
3173
3174 sx1 = Region.clipScale(sx1, widthScale);
3175 sy1 = Region.clipScale(sy1, heightScale);
3176 sx2 = Region.clipScale(sx2, widthScale);
3177 sy2 = Region.clipScale(sy2, heightScale);
3178
3179 observer = rvObserver;
3180 img = resolutionVariant;
3181
3182 if (xform != null) {
3183 assert dx1 == 0 && dy1 == 0;
3184 assert dx2 == img.getWidth(observer);
3185 assert dy2 == img.getHeight(observer);
3186 AffineTransform renderTX = new AffineTransform(xform);
3187 renderTX.scale(1 / widthScale, 1 / heightScale);
3188 return transformImage(img, renderTX, observer);
3189 }
3190
3191 return scaleImage(img, dx1, dy1, dx2, dy2,
3192 sx1, sy1, sx2, sy2,
3193 bgcolor, observer);
3194 } else {
3195 return false; // Image variant is not initialized yet
3196 }
3197 }
3198 }
3199 return null;
3200 }
3201
3202 private boolean scaleImage(Image img, int dx1, int dy1, int dx2, int dy2,
3203 int sx1, int sy1, int sx2, int sy2,
3204 Color bgcolor, ImageObserver observer)
3205 {
3206 try {
3207 return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1, sy1,
3208 sx2, sy2, bgcolor, observer);
3209 } catch (InvalidPipeException e) {
3210 try {
3211 revalidateAll();
3212 return imagepipe.scaleImage(this, img, dx1, dy1, dx2, dy2, sx1,
3213 sy1, sx2, sy2, bgcolor, observer);
3214 } catch (InvalidPipeException e2) {
3215 // Still catching the exception; we are not yet ready to
|