@@ -1887,6 +1887,11 @@ <T> T applyUsingAnyHandle(Function<ImageHandle, T> function) {
18871887 return function .apply (zoomLevelToImageHandle .values ().iterator ().next ());
18881888}
18891889
1890+ private int getClosestAvailableZoom (int zoom ) {
1891+ TreeSet <Integer > availableZooms = new TreeSet <>(zoomLevelToImageHandle .keySet ());
1892+ return Optional .ofNullable (availableZooms .higher (zoom )).orElse (availableZooms .lower (zoom ));
1893+ }
1894+
18901895/**
18911896 * Invokes platform specific functionality to allocate a new image.
18921897 * <p>
@@ -1939,13 +1944,14 @@ public Collection<Integer> getPreservedZoomLevels() {
19391944 return Collections .emptySet ();
19401945 }
19411946
1947+ protected abstract ElementAtZoom <ImageData > loadImageData (int zoom );
1948+
19421949 abstract ImageData newImageData (ZoomContext zoomContext );
19431950
19441951 abstract AbstractImageProviderWrapper createCopy (Image image );
19451952
19461953 ImageData getScaledImageData (int zoom ) {
1947- TreeSet <Integer > availableZooms = new TreeSet <>(zoomLevelToImageHandle .keySet ());
1948- int closestZoom = Optional .ofNullable (availableZooms .higher (zoom )).orElse (availableZooms .lower (zoom ));
1954+ int closestZoom = getClosestAvailableZoom (zoom );
19491955 return DPIUtil .scaleImageData (device , getImageMetadata (new ZoomContext (closestZoom )).getImageData (), zoom , closestZoom );
19501956 }
19511957
@@ -2004,12 +2010,18 @@ AbstractImageProviderWrapper createCopy(Image image) {
20042010 public Collection <Integer > getPreservedZoomLevels () {
20052011 return Collections .singleton (zoomForHandle );
20062012 }
2013+
2014+ @ Override
2015+ protected ElementAtZoom <ImageData > loadImageData (int zoom ) {
2016+ int closestZoom = getClosestAvailableZoom (zoom );
2017+ ImageData imageData = getImageMetadata (new ZoomContext (closestZoom )).getImageData ();
2018+ return new ElementAtZoom <>(imageData , closestZoom );
2019+ }
20072020}
20082021
20092022private abstract class ImageFromImageDataProviderWrapper extends AbstractImageProviderWrapper {
20102023 private final Map <Integer , ImageData > cachedImageData = new HashMap <>();
20112024
2012- protected abstract ElementAtZoom <ImageData > loadImageData (int zoom );
20132025
20142026 void initImage () {
20152027 // As the init call configured some Image attributes (e.g. type)
@@ -2180,6 +2192,20 @@ protected Rectangle getBounds(int zoom) {
21802192 return Win32DPIUtils .pointToPixel (rectangle , zoom );
21812193 }
21822194
2195+ private ImageData resolveBaseOrNewImage (ZoomContext zoomContext ) {
2196+ int targetZoom = zoomContext .targetZoom ();
2197+ if (zoomLevelToImageHandle .isEmpty ()) {
2198+ return createBaseHandle (targetZoom ).getImageData ();
2199+ }
2200+ // if a GC is initialized with an Image (memGC != null), the image data must not be resized, because it would
2201+ // be a destructive operation. Therefor, a new handle is created for the requested zoom
2202+ if (memGC != null ) {
2203+ return newImageHandle (zoomContext ).getImageData ();
2204+ }
2205+
2206+ return null ;
2207+ }
2208+
21832209 @ Override
21842210 ImageData newImageData (ZoomContext zoomContext ) {
21852211 int targetZoom = zoomContext .targetZoom ();
@@ -2194,6 +2220,12 @@ ImageData newImageData(ZoomContext zoomContext) {
21942220 return getScaledImageData (targetZoom );
21952221 }
21962222
2223+ @ Override
2224+ protected ElementAtZoom <ImageData > loadImageData (int zoom ) {
2225+ int closestZoom = getClosestAvailableZoom (zoom );
2226+ return new ElementAtZoom <>(getImageMetadata (new ZoomContext (closestZoom )).getImageData (), closestZoom );
2227+ }
2228+
21972229 @ Override
21982230 protected ImageHandle newImageHandle (ZoomContext zoomContext ) {
21992231 int targetZoom = zoomContext .targetZoom ();
@@ -2326,7 +2358,6 @@ private ImageHandle initializeHandleFromSource(int zoom) {
23262358 return init (imageData , zoom );
23272359 }
23282360
2329- protected abstract ElementAtZoom <ImageData > loadImageData (int zoom );
23302361
23312362 @ Override
23322363 protected Rectangle getBounds (int zoom ) {
@@ -2624,6 +2655,11 @@ ImageData newImageData(ZoomContext zoomContext) {
26242655 return getImageMetadata (zoomContext ).getImageData ();
26252656 }
26262657
2658+ @ Override
2659+ protected ElementAtZoom <ImageData > loadImageData (int zoom ) {
2660+ return new ElementAtZoom <>(newImageData (new ZoomContext (zoom )), zoom );
2661+ }
2662+
26272663 @ Override
26282664 protected ImageHandle newImageHandle (ZoomContext zoomContext ) {
26292665 currentZoom = zoomContext ;
0 commit comments