Skip to content

Commit

Permalink
Obtain ImageData for any requested zoom value
Browse files Browse the repository at this point in the history
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
  • Loading branch information
amartya4256 committed Jan 9, 2025
1 parent d7febc4 commit a2785fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1359,10 +1359,10 @@ public ImageData getImageData() {
*/
public ImageData getImageData (int zoom) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
int currentZoom = getZoom();
if (zoom == currentZoom) {
return getImageDataAtCurrentZoom();
} else if (imageProvider != null) {
if (zoomLevelToImageHandle.get(zoom) != null) {
return zoomLevelToImageHandle.get(zoom).getImageData();
}
if (imageProvider != null) {
return imageProvider.getImageData(zoom);
}

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

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import org.eclipse.swt.internal.DPIUtil;
import org.eclipse.swt.widgets.Display;
Expand All @@ -36,6 +37,15 @@ public void setUp() {
display = Display.getDefault();
}

@Test
public void testImageDataForDifferentZoomsShouldNotBeScaledToTheAutoScaledZoom() {
Image image = new Image(display, 10, 10);
ImageData imageDataAt125 = image.getImageData(125);
ImageData imageDataAt150 = image.getImageData(150);
assertNotEquals("ImageData::height should not be the same for imageData at different zoom levels within the same autoScale zoom bounds", imageDataAt125.height, imageDataAt150.height);
assertNotEquals("ImageData::width should not be the same for imageData at different zoom levels within the same autoScale zoom bounds", imageDataAt125.width, imageDataAt150.width);
}

@Test
public void testImageShouldHaveDimesionAsPerZoomLevel() {
int zoom = DPIUtil.getDeviceZoom();
Expand Down

0 comments on commit a2785fe

Please sign in to comment.