Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.containsKey(zoom)) {
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,19 @@ public void setUp() {
display = Display.getDefault();
}

@Test
public void testImageDataForDifferentFractionalZoomsShouldBeDifferent() {
Image image = new Image(display, 10, 10);
int zoom1 = 125;
int zoom2 = 150;
ImageData imageDataAtZoom1 = image.getImageData(zoom1);
ImageData imageDataAtZoom2 = image.getImageData(zoom2);
assertNotEquals("ImageData::height should not be the same for imageData at different zoom levels",
imageDataAtZoom1.height, imageDataAtZoom2.height);
assertNotEquals("ImageData::width should not be the same for imageData at different zoom levels",
imageDataAtZoom1.width, imageDataAtZoom2.width);
}

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