@@ -1265,7 +1265,7 @@ private ImageData getScaledImageData (int zoom) {
12651265 }
12661266 TreeSet <Integer > availableZooms = new TreeSet <>(zoomLevelToImageHandle .keySet ());
12671267 int closestZoom = Optional .ofNullable (availableZooms .higher (zoom )).orElse (availableZooms .lower (zoom ));
1268- return scaleImageData ( getImageMetadata (closestZoom ).getImageData (), zoom , closestZoom );
1268+ return DPIUtil . scaleImageData ( device , getImageMetadata (closestZoom ).getImageData (), zoom , closestZoom );
12691269}
12701270
12711271
@@ -1855,40 +1855,6 @@ public void setBackground(Color color) {
18551855 zoomLevelToImageHandle .values ().forEach (imageHandle -> imageHandle .setBackground (backgroundColor ));
18561856}
18571857
1858- private ImageData scaleImageData (final ImageData imageData , int targetZoom , int currentZoom ) {
1859- if (imageData == null || targetZoom == currentZoom || (device != null && !device .isAutoScalable ())) return imageData ;
1860- float scaleFactor = (float ) targetZoom / (float ) currentZoom ;
1861- int width = imageData .width ;
1862- int height = imageData .height ;
1863- int scaledWidth = Math .round (width * scaleFactor );
1864- int scaledHeight = Math .round (height * scaleFactor );
1865- boolean useSmoothScaling = DPIUtil .isSmoothScalingEnabled () && imageData .getTransparencyType () != SWT .TRANSPARENCY_MASK ;
1866- if (useSmoothScaling ) {
1867- return scaleToUsingSmoothScaling (scaledWidth , scaledHeight , imageData );
1868- }
1869- return imageData .scaledTo (scaledWidth , scaledHeight );
1870- }
1871-
1872- private ImageData scaleToUsingSmoothScaling (int width , int height , ImageData imageData ) {
1873- Image original = new Image (device , (ImageDataProvider ) zoom -> imageData );
1874- /* Create a 24 bit image data with alpha channel */
1875- final ImageData resultData = new ImageData (width , height , 24 , new PaletteData (0xFF , 0xFF00 , 0xFF0000 ));
1876- resultData .alphaData = new byte [width * height ];
1877- Image resultImage = new Image (device , (ImageDataProvider ) zoom -> resultData );
1878- GC gc = new GC (resultImage );
1879- gc .setAntialias (SWT .ON );
1880- gc .drawImage (original , 0 , 0 , imageData .width , imageData .height ,
1881- /* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
1882- * Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
1883- */
1884- 0 , 0 , width , height , false );
1885- gc .dispose ();
1886- original .dispose ();
1887- ImageData result = resultImage .getImageData (resultImage .getZoom ());
1888- resultImage .dispose ();
1889- return result ;
1890- }
1891-
18921858private int getZoom () {
18931859 return DPIUtil .getZoomForAutoscaleProperty (initialNativeZoom );
18941860}
@@ -2233,7 +2199,7 @@ ImageData getImageData(int zoom) {
22332199
22342200 private ImageData scaleIfNecessary (ElementAtZoom <ImageData > imageDataAtZoom , int zoom ) {
22352201 if (imageDataAtZoom .zoom () != zoom ) {
2236- return scaleImageData (imageDataAtZoom . element (), zoom , imageDataAtZoom . zoom () );
2202+ return DPIUtil . scaleImageData (device , imageDataAtZoom , zoom );
22372203 }
22382204 return imageDataAtZoom .element ();
22392205 }
@@ -2457,13 +2423,13 @@ private class ImageDataProviderWrapper extends BaseImageProviderWrapper<ImageDat
24572423 @ Override
24582424 ImageData getImageData (int zoom ) {
24592425 ElementAtZoom <ImageData > data = DPIUtil .validateAndGetImageDataAtZoom (provider , zoom );
2460- return scaleImageData ( data .element (), zoom , data .zoom ());
2426+ return DPIUtil . scaleImageData ( device , data .element (), zoom , data .zoom ());
24612427 }
24622428
24632429 @ Override
24642430 ImageHandle getImageMetadata (int zoom ) {
24652431 ElementAtZoom <ImageData > imageCandidate = DPIUtil .validateAndGetImageDataAtZoom (provider , zoom );
2466- ImageData resizedData = scaleImageData ( imageCandidate .element (), zoom , imageCandidate .zoom ());
2432+ ImageData resizedData = DPIUtil . scaleImageData ( device , imageCandidate .element (), zoom , imageCandidate .zoom ());
24672433 ImageData newData = adaptImageDataIfDisabledOrGray (resizedData );
24682434 init (newData , zoom );
24692435 return zoomLevelToImageHandle .get (zoom );
0 commit comments