@@ -789,10 +789,6 @@ private ImageHandle getImageMetadata(int zoom) {
789789 return imageProvider .newImageHandle (zoom );
790790}
791791
792- private ImageHandle getImageMetadata (int targetWidth , int targetHeight ) {
793- return this .imageProvider .newImageHandle (targetWidth , targetHeight );
794- }
795-
796792
797793/**
798794 * <b>IMPORTANT:</b> This method is not part of the public
@@ -820,11 +816,10 @@ public static long win32_getHandle (Image image, int zoom) {
820816/**
821817 * @since 4.0
822818 */
823- public static long win32_getHandle (Image image , int targetWidth , int targetHeight ) {
824- if (image .isDisposed ()) {
825- return 0L ;
826- }
827- return image .getImageMetadata (targetWidth , targetHeight ).handle ;
819+ public void drawOnGCAtTargetSize (Consumer <Long > drawFunction , int targetWidth , int targetHeight ) {
820+ ImageData imageData = this .imageProvider .newImageData (targetWidth , targetHeight );
821+ long tempHandle = init (device , imageData ).handles ()[0 ];
822+ drawFunction .accept (tempHandle );
828823}
829824
830825/**
@@ -1625,12 +1620,6 @@ private ImageHandle initBitmapHandle(ImageData imageData, long handle, Integer z
16251620 return new ImageHandle (handle , zoom );
16261621}
16271622
1628- private ImageHandle initBitmapHandle (ImageData imageData , long handle , int targetWidth , int targetHeight ) {
1629- type = SWT .BITMAP ;
1630- transparentPixel = imageData .transparentPixel ;
1631- return new ImageHandle (handle , targetWidth , targetHeight );
1632- }
1633-
16341623static long [] initIcon (Device device , ImageData source , ImageData mask ) {
16351624 ImageData imageData = applyMask (source , mask );
16361625 return init (device , imageData ).handles ;
@@ -1727,23 +1716,6 @@ private ImageHandle init(ImageData i, int zoom) {
17271716 }
17281717}
17291718
1730- private ImageHandle init (ImageData i , int targetWidth , int targetHeight ) {
1731- if (i == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
1732- HandleForImageDataContainer imageDataHandle = init (device , i );
1733- switch (imageDataHandle .type ()) {
1734- //TODO implement
1735- // case SWT.ICON: {
1736- // return initIconHandle(imageDataHandle.handles(), targetWidth, targetHeight);
1737- // }
1738- case SWT .BITMAP : {
1739- return initBitmapHandle (imageDataHandle .imageData (), imageDataHandle .handles ()[0 ], targetWidth , targetHeight );
1740- }
1741- default :
1742- SWT .error (SWT .ERROR_INVALID_ARGUMENT );
1743- return null ;
1744- }
1745- }
1746-
17471719/**
17481720 * Invokes platform specific functionality to allocate a new GC handle.
17491721 * <p>
@@ -1970,11 +1942,6 @@ protected ImageHandle newImageHandle(int zoom) {
19701942 return newImageHandle (resizedData , zoom );
19711943 }
19721944
1973- protected ImageHandle newImageHandle (int targetWidth , int targetHeight ) {
1974- ImageData imageData = getImageData (targetWidth , targetHeight );
1975- return init (imageData , targetWidth , targetHeight );
1976- }
1977-
19781945 protected final ImageHandle newImageHandle (ImageData data , int zoom ) {
19791946 if (type == SWT .ICON && data .getTransparencyType () != SWT .TRANSPARENCY_MASK ) {
19801947 // If the original type was an icon with transparency mask and re-scaling leads
@@ -2018,7 +1985,7 @@ ImageData newImageData(int zoom) {
20181985
20191986 @ Override
20201987 ImageData newImageData (int targetWidth , int targetHeight ) {
2021- ImageData imageData = super . newImageHandle (targetWidth , targetHeight ). getImageData ( );
1988+ ImageData imageData = getImageData (targetWidth , targetHeight );
20221989 return DPIUtil .autoScaleImageData (device , imageData , targetWidth , targetHeight );
20231990 }
20241991
@@ -2059,10 +2026,10 @@ ImageData newImageData(int zoom) {
20592026
20602027 @ Override
20612028 ImageData newImageData (int targetWidth , int targetHeight ) {
2062- ImageHandle handle = initializeHandleFromSource (targetWidth , targetHeight );
2063- ImageData data = handle . getImageData ( );
2064- handle . destroy ( );
2065- return data ;
2029+ ElementAtTargetSize < ImageData > imageDataAtTargetSize = loadImageData (targetWidth , targetHeight );
2030+ ImageData imageData = DPIUtil . autoScaleImageData ( device , imageDataAtTargetSize . element (), targetWidth , targetHeight );
2031+ imageData = adaptImageDataIfDisabledOrGray ( imageData );
2032+ return imageData ;
20662033 }
20672034
20682035 @ Override
@@ -2074,26 +2041,12 @@ protected ImageHandle newImageHandle(int zoom) {
20742041 return initializeHandleFromSource (zoom );
20752042 }
20762043
2077- @ Override
2078- protected ImageHandle newImageHandle (int targetWidth , int targetHeight ) {
2079- return initializeHandleFromSource (targetWidth , targetHeight );
2080- }
2081-
20822044 private ImageHandle initializeHandleFromSource (int zoom ) {
20832045 ElementAtZoom <ImageData > imageDataAtZoom = loadImageData (zoom );
20842046 ImageData imageData = DPIUtil .scaleImageData (device , imageDataAtZoom .element (), zoom , imageDataAtZoom .zoom ());
20852047 imageData = adaptImageDataIfDisabledOrGray (imageData );
20862048 return newImageHandle (imageData , zoom );
20872049 }
2088-
2089- //TODO also handle IconHandle in addition to Bitmap
2090- private ImageHandle initializeHandleFromSource (int targetWidth , int targetHeight ) {
2091- ElementAtTargetSize <ImageData > imageDataAtTargetSize = loadImageData (targetWidth , targetHeight );
2092- ImageData imageData = DPIUtil .autoScaleImageData (device , imageDataAtTargetSize .element (), targetWidth , targetHeight );
2093- imageData = adaptImageDataIfDisabledOrGray (imageData );
2094- return init (imageData , targetWidth , targetHeight );
2095- }
2096-
20972050}
20982051
20992052private class PlainImageDataProviderWrapper extends ImageFromImageDataProviderWrapper {
@@ -2252,8 +2205,7 @@ ImageData newImageData(int zoom) {
22522205
22532206 @ Override
22542207 ImageData newImageData (int targetWidth , int targetHeight ) {
2255- ImageData imageData = super .newImageHandle (targetWidth , targetHeight ).getImageData ();
2256- return DPIUtil .autoScaleImageData (device , imageData , targetWidth , targetHeight );
2208+ return null ;
22572209 }
22582210
22592211 @ Override
@@ -2369,10 +2321,10 @@ ImageData newImageData(int zoom) {
23692321
23702322 @ Override
23712323 ImageData newImageData (int targetWidth , int targetHeight ) {
2372- ImageHandle handle = initializeHandleFromSource (targetWidth , targetHeight );
2373- ImageData data = handle . getImageData ( );
2374- handle . destroy ( );
2375- return data ;
2324+ ElementAtTargetSize < ImageData > imageDataAtTargetSize = loadImageData (targetWidth , targetHeight );
2325+ ImageData imageData = DPIUtil . autoScaleImageData ( device , imageDataAtTargetSize . element (), targetWidth , targetHeight );
2326+ imageData = adaptImageDataIfDisabledOrGray ( imageData );
2327+ return imageData ;
23762328 }
23772329
23782330 @ Override
@@ -2384,25 +2336,13 @@ protected ImageHandle newImageHandle(int zoom) {
23842336 return initializeHandleFromSource (zoom );
23852337 }
23862338
2387- @ Override
2388- protected ImageHandle newImageHandle (int targetWidth , int targetHeight ) {
2389- return initializeHandleFromSource (targetWidth , targetHeight );
2390- }
2391-
23922339 private ImageHandle initializeHandleFromSource (int zoom ) {
23932340 ElementAtZoom <ImageData > imageDataAtZoom = loadImageData (zoom );
23942341 ImageData imageData = DPIUtil .scaleImageData (device ,imageDataAtZoom .element (), zoom , imageDataAtZoom .zoom ());
23952342 imageData = adaptImageDataIfDisabledOrGray (imageData );
23962343 return init (imageData , zoom );
23972344 }
23982345
2399- private ImageHandle initializeHandleFromSource (int targetWidth , int targetHeight ) {
2400- ElementAtTargetSize <ImageData > imageDataAtTargetSize = loadImageData (targetWidth , targetHeight );
2401- ImageData imageData = DPIUtil .autoScaleImageData (device ,imageDataAtTargetSize .element (), targetWidth , targetHeight );
2402- imageData = adaptImageDataIfDisabledOrGray (imageData );
2403- return init (imageData , targetWidth , targetHeight );
2404- }
2405-
24062346 protected abstract ElementAtZoom <ImageData > loadImageData (int zoom );
24072347
24082348 protected abstract ElementAtTargetSize <ImageData > loadImageData (int targetWidth , int targetHeight );
@@ -2721,7 +2661,7 @@ ImageData newImageData(int zoom) {
27212661
27222662 @ Override
27232663 ImageData newImageData (int targetWidth , int targetHeight ) {
2724- return getImageMetadata ( targetWidth , targetHeight ). getImageData () ;
2664+ return null ;
27252665 }
27262666
27272667 @ Override
@@ -2752,12 +2692,6 @@ protected ImageHandle newImageHandle(int zoom) {
27522692 }
27532693 }
27542694
2755- //TODO
2756- @ Override
2757- protected ImageHandle newImageHandle (int targetWidth , int targetHeight ) {
2758- return null ;
2759- }
2760-
27612695 @ Override
27622696 Object getProvider () {
27632697 return drawer ;
@@ -2816,16 +2750,6 @@ public ImageHandle(long handle, int zoom) {
28162750 setImageMetadataForHandle (this , zoom );
28172751 }
28182752
2819- public ImageHandle (long handle , int targetWidth , int targetHeight ) {
2820- this .handle = handle ;
2821- //TODO set right zoom here
2822- this .zoom = 100 ;
2823- updateBoundsInPixelsFromNative ();
2824- if (backgroundColor != null ) {
2825- setBackground (backgroundColor );
2826- }
2827- }
2828-
28292753 public Rectangle getBounds () {
28302754 return new Rectangle (0 , 0 , width , height );
28312755 }
0 commit comments