@@ -380,14 +380,6 @@ public Image(Device device, ImageData data) {
380
380
this .device .registerResourceWithZoomSupport (this );
381
381
}
382
382
383
- private Image (Device device , ImageData data , int zoom ) {
384
- super (device );
385
- if (data == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
386
- this .imageProvider = new PlainImageDataProviderWrapper (data , zoom );
387
- init ();
388
- this .device .registerResourceWithZoomSupport (this );
389
- }
390
-
391
383
/**
392
384
* Constructs an instance of this class, whose type is
393
385
* <code>SWT.ICON</code>, from the two given <code>ImageData</code>
@@ -1951,6 +1943,46 @@ protected final ImageHandle newImageHandle(ImageData data, int zoom) {
1951
1943
return init (data , zoom );
1952
1944
}
1953
1945
}
1946
+
1947
+ protected final ImageHandle createHandle (int width , int height , int zoom ) {
1948
+ long handle = initHandle (width , height , zoom );
1949
+ ImageHandle imageHandle = new ImageHandle (handle , zoom );
1950
+ zoomLevelToImageHandle .put (zoom , imageHandle );
1951
+ return imageHandle ;
1952
+ }
1953
+
1954
+ private long initHandle (int width , int height , int zoom ) {
1955
+ if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
1956
+ int scaledWidth = Win32DPIUtils .pointToPixel (width , zoom );
1957
+ int scaledHeight = Win32DPIUtils .pointToPixel (height , zoom );
1958
+ long hDC = device .internal_new_GC (null );
1959
+ long newHandle = OS .CreateCompatibleBitmap (hDC , scaledWidth , scaledHeight );
1960
+ /*
1961
+ * Feature in Windows. CreateCompatibleBitmap() may fail
1962
+ * for large images. The fix is to create a DIB section
1963
+ * in that case.
1964
+ */
1965
+ if (newHandle == 0 ) {
1966
+ int bits = OS .GetDeviceCaps (hDC , OS .BITSPIXEL );
1967
+ int planes = OS .GetDeviceCaps (hDC , OS .PLANES );
1968
+ int depth = bits * planes ;
1969
+ if (depth < 16 ) depth = 16 ;
1970
+ if (depth > 24 ) depth = 24 ;
1971
+ newHandle = createDIB (scaledWidth , scaledHeight , depth );
1972
+ }
1973
+ if (newHandle != 0 ) {
1974
+ long memDC = OS .CreateCompatibleDC (hDC );
1975
+ long hOldBitmap = OS .SelectObject (memDC , newHandle );
1976
+ OS .PatBlt (memDC , 0 , 0 , scaledWidth , scaledHeight , OS .PATCOPY );
1977
+ OS .SelectObject (memDC , hOldBitmap );
1978
+ OS .DeleteDC (memDC );
1979
+ }
1980
+ device .internal_dispose_GC (hDC , null );
1981
+ if (newHandle == 0 ) {
1982
+ SWT .error (SWT .ERROR_NO_HANDLES , null , device .getLastError ());
1983
+ }
1984
+ return newHandle ;
1985
+ }
1954
1986
}
1955
1987
1956
1988
private class ExistingImageHandleProviderWrapper extends AbstractImageProviderWrapper {
@@ -2179,55 +2211,15 @@ protected ImageHandle newImageHandle(int zoom) {
2179
2211
if (memGC != null ) {
2180
2212
GC currentGC = memGC ;
2181
2213
memGC = null ;
2182
- createHandle (zoom );
2214
+ createHandle (this . width , this . height , zoom );
2183
2215
currentGC .refreshFor (new DrawableWrapper (Image .this , zoom ), zoom );
2184
2216
return zoomLevelToImageHandle .get (zoom );
2185
2217
}
2186
2218
return super .newImageHandle (zoom );
2187
2219
}
2188
2220
private ImageHandle createBaseHandle (int zoom ) {
2189
2221
baseZoom = zoom ;
2190
- return createHandle (zoom );
2191
- }
2192
-
2193
- private ImageHandle createHandle (int zoom ) {
2194
- long handle = initHandle (zoom );
2195
- ImageHandle imageHandle = new ImageHandle (handle , zoom );
2196
- zoomLevelToImageHandle .put (zoom , imageHandle );
2197
- return imageHandle ;
2198
- }
2199
-
2200
- private long initHandle (int zoom ) {
2201
- if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
2202
- int scaledWidth = Win32DPIUtils .pointToPixel (width , zoom );
2203
- int scaledHeight = Win32DPIUtils .pointToPixel (height , zoom );
2204
- long hDC = device .internal_new_GC (null );
2205
- long newHandle = OS .CreateCompatibleBitmap (hDC , scaledWidth , scaledHeight );
2206
- /*
2207
- * Feature in Windows. CreateCompatibleBitmap() may fail
2208
- * for large images. The fix is to create a DIB section
2209
- * in that case.
2210
- */
2211
- if (newHandle == 0 ) {
2212
- int bits = OS .GetDeviceCaps (hDC , OS .BITSPIXEL );
2213
- int planes = OS .GetDeviceCaps (hDC , OS .PLANES );
2214
- int depth = bits * planes ;
2215
- if (depth < 16 ) depth = 16 ;
2216
- if (depth > 24 ) depth = 24 ;
2217
- newHandle = createDIB (scaledWidth , scaledHeight , depth );
2218
- }
2219
- if (newHandle != 0 ) {
2220
- long memDC = OS .CreateCompatibleDC (hDC );
2221
- long hOldBitmap = OS .SelectObject (memDC , newHandle );
2222
- OS .PatBlt (memDC , 0 , 0 , scaledWidth , scaledHeight , OS .PATCOPY );
2223
- OS .SelectObject (memDC , hOldBitmap );
2224
- OS .DeleteDC (memDC );
2225
- }
2226
- device .internal_dispose_GC (hDC , null );
2227
- if (newHandle == 0 ) {
2228
- SWT .error (SWT .ERROR_NO_HANDLES , null , device .getLastError ());
2229
- }
2230
- return newHandle ;
2222
+ return createHandle (this .width , this .height , zoom );
2231
2223
}
2232
2224
2233
2225
@ Override
@@ -2596,27 +2588,26 @@ ImageData newImageData(int zoom) {
2596
2588
protected ImageHandle newImageHandle (int zoom ) {
2597
2589
currentZoom = zoom ;
2598
2590
int gcStyle = drawer .getGcStyle ();
2599
- Image image ;
2600
2591
if ((gcStyle & SWT .TRANSPARENT ) != 0 ) {
2601
2592
int scaledHeight = Win32DPIUtils .pointToPixel (height , zoom );
2602
2593
int scaledWidth = Win32DPIUtils .pointToPixel (width , zoom );
2603
2594
/* Create a 24 bit image data with alpha channel */
2604
2595
final ImageData resultData = new ImageData (scaledWidth , scaledHeight , 24 , new PaletteData (0xFF , 0xFF00 , 0xFF0000 ));
2605
2596
resultData .alphaData = new byte [scaledWidth * scaledHeight ];
2606
- image = new Image ( device , resultData , zoom );
2597
+ init ( resultData , zoom );
2607
2598
} else {
2608
- image = new Image ( device , width , height );
2599
+ createHandle ( width , height , zoom );
2609
2600
}
2610
- GC gc = new GC (new DrawableWrapper (image , zoom ), gcStyle );
2601
+ GC gc = new GC (new DrawableWrapper (Image . this , zoom ), gcStyle );
2611
2602
try {
2612
2603
drawer .drawOn (gc , width , height );
2613
- ImageData imageData = image .getImageMetadata (zoom ).getImageData ();
2604
+ ImageData imageData = Image . this .getImageMetadata (zoom ).getImageData ();
2614
2605
drawer .postProcess (imageData );
2615
- ImageData newData = adaptImageDataIfDisabledOrGray (imageData );
2616
- return init (newData , zoom );
2606
+ zoomLevelToImageHandle .get (zoom ).destroy ();
2607
+ init (imageData , zoom );
2608
+ return zoomLevelToImageHandle .get (zoom );
2617
2609
} finally {
2618
2610
gc .dispose ();
2619
- image .dispose ();
2620
2611
}
2621
2612
}
2622
2613
0 commit comments