@@ -408,7 +408,7 @@ public Image(Device device, ImageData source, ImageData mask) {
408
408
source = DPIUtil .autoScaleUp (device , source );
409
409
mask = DPIUtil .autoScaleUp (device , mask );
410
410
mask = ImageData .convertMask (mask );
411
- init (this .device , this , source , mask , getZoom ());
411
+ initIconHandle (this .device , source , mask , getZoom ());
412
412
init ();
413
413
this .device .registerResourceWithZoomSupport (this );
414
414
}
@@ -777,7 +777,7 @@ private ImageHandle getImageMetadata(int zoom) {
777
777
// to image data without transparency mask, this will create invalid images
778
778
// so this fallback will "repair" the image data by explicitly passing
779
779
// the transparency mask created from the scaled image data
780
- init (this .device , this , newData , newData .getTransparencyMask (), zoom );
780
+ initIconHandle (this .device , newData , newData .getTransparencyMask (), zoom );
781
781
} else {
782
782
init (newData , zoom );
783
783
}
@@ -1542,7 +1542,9 @@ static ImageData directToDirect(ImageData src, int newDepth, PaletteData newPale
1542
1542
return img ;
1543
1543
}
1544
1544
1545
- static long [] init (Device device , Image image , ImageData i , Integer zoom ) {
1545
+ private record HandleForImageDataContainer (int type , ImageData imageData , long [] handles ) {}
1546
+
1547
+ private static HandleForImageDataContainer init (Device device , ImageData i ) {
1546
1548
/* Windows does not support 2-bit images. Convert to 4-bit image. */
1547
1549
if (i .depth == 2 ) {
1548
1550
i = indexToIndex (i , 4 );
@@ -1708,7 +1710,6 @@ else if (i.alphaData != null) {
1708
1710
}
1709
1711
OS .MoveMemory (pBits [0 ], data , data .length );
1710
1712
1711
- long [] result = null ;
1712
1713
if (i .getTransparencyType () == SWT .TRANSPARENCY_MASK ) {
1713
1714
/* Get the HDC for the device */
1714
1715
long hDC = device .internal_new_GC (null );
@@ -1735,31 +1736,10 @@ else if (i.alphaData != null) {
1735
1736
OS .DeleteDC (hdcDest );
1736
1737
OS .DeleteObject (hDib );
1737
1738
1738
- if (image == null ) {
1739
- result = new long []{hBitmap , hMask };
1740
- } else {
1741
- /* Create the icon */
1742
- ICONINFO info = new ICONINFO ();
1743
- info .fIcon = true ;
1744
- info .hbmColor = hBitmap ;
1745
- info .hbmMask = hMask ;
1746
- long hIcon = OS .CreateIconIndirect (info );
1747
- if (hIcon == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
1748
- OS .DeleteObject (hBitmap );
1749
- OS .DeleteObject (hMask );
1750
- image .type = SWT .ICON ;
1751
- image .new ImageHandle (hIcon , zoom );
1752
- }
1739
+ return new HandleForImageDataContainer (SWT .ICON , i , new long []{hBitmap , hMask });
1753
1740
} else {
1754
- if (image == null ) {
1755
- result = new long []{hDib };
1756
- } else {
1757
- image .type = SWT .BITMAP ;
1758
- image .transparentPixel = i .transparentPixel ;
1759
- image .new ImageHandle (hDib , zoom );
1760
- }
1741
+ return new HandleForImageDataContainer (SWT .BITMAP , i , new long []{hDib });
1761
1742
}
1762
- return result ;
1763
1743
}
1764
1744
1765
1745
private void setImageMetadataForHandle (ImageHandle imageMetadata , Integer zoom ) {
@@ -1771,9 +1751,35 @@ private void setImageMetadataForHandle(ImageHandle imageMetadata, Integer zoom)
1771
1751
zoomLevelToImageHandle .put (zoom , imageMetadata );
1772
1752
}
1773
1753
1774
- static long [] init (Device device , Image image , ImageData source , ImageData mask , Integer zoom ) {
1754
+ private ImageHandle initIconHandle (Device device , ImageData source , ImageData mask , Integer zoom ) {
1755
+ ImageData imageData = applyMask (source , mask );
1756
+ HandleForImageDataContainer imageDataHandle = init (device , imageData );
1757
+ return initIconHandle (imageDataHandle .handles , zoom );
1758
+ }
1759
+
1760
+ private ImageHandle initIconHandle (long [] handles , int zoom ) {
1761
+ /* Create the icon */
1762
+ ICONINFO info = new ICONINFO ();
1763
+ info .fIcon = true ;
1764
+ info .hbmColor = handles [0 ];
1765
+ info .hbmMask = handles [1 ];
1766
+ long hIcon = OS .CreateIconIndirect (info );
1767
+ if (hIcon == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
1768
+ OS .DeleteObject (handles [0 ]);
1769
+ OS .DeleteObject (handles [1 ]);
1770
+ type = SWT .ICON ;
1771
+ return new ImageHandle (hIcon , zoom );
1772
+ }
1773
+
1774
+ private ImageHandle initBitmapHandle (ImageData imageData , long handle , Integer zoom ) {
1775
+ type = SWT .BITMAP ;
1776
+ transparentPixel = imageData .transparentPixel ;
1777
+ return new ImageHandle (handle , zoom );
1778
+ }
1779
+
1780
+ static long [] initIcon (Device device , ImageData source , ImageData mask ) {
1775
1781
ImageData imageData = applyMask (source , mask );
1776
- return init (device , image , imageData , zoom ) ;
1782
+ return init (device , imageData ). handles ;
1777
1783
}
1778
1784
1779
1785
private static ImageData applyMask (ImageData source , ImageData mask ) {
@@ -1851,9 +1857,20 @@ private static ImageData applyMask(ImageData source, ImageData mask) {
1851
1857
}
1852
1858
1853
1859
1854
- void init (ImageData i , Integer zoom ) {
1860
+ private ImageHandle init (ImageData i , int zoom ) {
1855
1861
if (i == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
1856
- init (device , this , i , zoom );
1862
+ HandleForImageDataContainer imageDataHandle = init (device , i );
1863
+ switch (imageDataHandle .type ()) {
1864
+ case SWT .ICON : {
1865
+ return initIconHandle (imageDataHandle .handles (), zoom );
1866
+ }
1867
+ case SWT .BITMAP : {
1868
+ return initBitmapHandle (imageDataHandle .imageData (), imageDataHandle .handles ()[0 ], zoom );
1869
+ }
1870
+ default :
1871
+ SWT .error (SWT .ERROR_INVALID_ARGUMENT );
1872
+ return null ;
1873
+ }
1857
1874
}
1858
1875
1859
1876
/**
0 commit comments