Skip to content

Commit ddd5ac8

Browse files
committed
Obtain ImageData for any requested zoom value
This contribution helps retrieve the imageData for the requested zoom by searching for the zoom in the zoomToHandleMap followed by (if not available) scaling the handle at the zoom nearest to it while getting rid of only searching among the autoscaled zoom values. Contributes to #62 and #127
1 parent d7febc4 commit ddd5ac8

File tree

1 file changed

+7
-5
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+7
-5
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,10 +1359,10 @@ public ImageData getImageData() {
13591359
*/
13601360
public ImageData getImageData (int zoom) {
13611361
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
1362-
int currentZoom = getZoom();
1363-
if (zoom == currentZoom) {
1364-
return getImageDataAtCurrentZoom();
1365-
} else if (imageProvider != null) {
1362+
if (zoomLevelToImageHandle.get(zoom) != null) {
1363+
return zoomLevelToImageHandle.get(zoom).getImageData();
1364+
}
1365+
if (imageProvider != null) {
13661366
return imageProvider.getImageData(zoom);
13671367
}
13681368

@@ -1371,7 +1371,9 @@ public ImageData getImageData (int zoom) {
13711371
if (memGC != null) {
13721372
return getImageDataAtCurrentZoom();
13731373
}
1374-
return DPIUtil.scaleImageData (device, getImageMetadata(currentZoom).getImageData(), zoom, currentZoom);
1374+
TreeSet<Integer> availableZooms = new TreeSet<>(zoomLevelToImageHandle.keySet());
1375+
int closestZoom = Optional.ofNullable(availableZooms.higher(zoom)).orElse(availableZooms.lower(zoom));
1376+
return DPIUtil.scaleImageData (device, getImageMetadata(closestZoom).getImageData(), zoom, closestZoom);
13751377
}
13761378

13771379
/**

0 commit comments

Comments
 (0)