@@ -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>
@@ -1957,6 +1949,46 @@ protected final ImageHandle newImageHandle(ImageData data, ZoomContext zoomConte
1957
1949
return init (data , zoomContext .targetZoom ());
1958
1950
}
1959
1951
}
1952
+
1953
+ protected final ImageHandle createHandle (int width , int height , int zoom ) {
1954
+ long handle = initHandle (width , height , zoom );
1955
+ ImageHandle imageHandle = new ImageHandle (handle , zoom );
1956
+ zoomLevelToImageHandle .put (zoom , imageHandle );
1957
+ return imageHandle ;
1958
+ }
1959
+
1960
+ private long initHandle (int width , int height , int zoom ) {
1961
+ if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
1962
+ int scaledWidth = Win32DPIUtils .pointToPixel (width , zoom );
1963
+ int scaledHeight = Win32DPIUtils .pointToPixel (height , zoom );
1964
+ long hDC = device .internal_new_GC (null );
1965
+ long newHandle = OS .CreateCompatibleBitmap (hDC , scaledWidth , scaledHeight );
1966
+ /*
1967
+ * Feature in Windows. CreateCompatibleBitmap() may fail
1968
+ * for large images. The fix is to create a DIB section
1969
+ * in that case.
1970
+ */
1971
+ if (newHandle == 0 ) {
1972
+ int bits = OS .GetDeviceCaps (hDC , OS .BITSPIXEL );
1973
+ int planes = OS .GetDeviceCaps (hDC , OS .PLANES );
1974
+ int depth = bits * planes ;
1975
+ if (depth < 16 ) depth = 16 ;
1976
+ if (depth > 24 ) depth = 24 ;
1977
+ newHandle = createDIB (scaledWidth , scaledHeight , depth );
1978
+ }
1979
+ if (newHandle != 0 ) {
1980
+ long memDC = OS .CreateCompatibleDC (hDC );
1981
+ long hOldBitmap = OS .SelectObject (memDC , newHandle );
1982
+ OS .PatBlt (memDC , 0 , 0 , scaledWidth , scaledHeight , OS .PATCOPY );
1983
+ OS .SelectObject (memDC , hOldBitmap );
1984
+ OS .DeleteDC (memDC );
1985
+ }
1986
+ device .internal_dispose_GC (hDC , null );
1987
+ if (newHandle == 0 ) {
1988
+ SWT .error (SWT .ERROR_NO_HANDLES , null , device .getLastError ());
1989
+ }
1990
+ return newHandle ;
1991
+ }
1960
1992
}
1961
1993
1962
1994
private class ExistingImageHandleProviderWrapper extends AbstractImageProviderWrapper {
@@ -2196,7 +2228,7 @@ protected ImageHandle newImageHandle(ZoomContext zoomContext) {
2196
2228
if (memGC .getZoom () != targetZoom ) {
2197
2229
GC currentGC = memGC ;
2198
2230
memGC = null ;
2199
- createHandle (targetZoom );
2231
+ createHandle (this . width , this . height , targetZoom );
2200
2232
currentGC .refreshFor (new DrawableWrapper (Image .this , zoomContext ));
2201
2233
}
2202
2234
return zoomLevelToImageHandle .get (targetZoom );
@@ -2205,47 +2237,7 @@ protected ImageHandle newImageHandle(ZoomContext zoomContext) {
2205
2237
}
2206
2238
private ImageHandle createBaseHandle (int zoom ) {
2207
2239
baseZoom = zoom ;
2208
- return createHandle (zoom );
2209
- }
2210
-
2211
- private ImageHandle createHandle (int zoom ) {
2212
- long handle = initHandle (zoom );
2213
- ImageHandle imageHandle = new ImageHandle (handle , zoom );
2214
- zoomLevelToImageHandle .put (zoom , imageHandle );
2215
- return imageHandle ;
2216
- }
2217
-
2218
- private long initHandle (int zoom ) {
2219
- if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
2220
- int scaledWidth = Win32DPIUtils .pointToPixel (width , zoom );
2221
- int scaledHeight = Win32DPIUtils .pointToPixel (height , zoom );
2222
- long hDC = device .internal_new_GC (null );
2223
- long newHandle = OS .CreateCompatibleBitmap (hDC , scaledWidth , scaledHeight );
2224
- /*
2225
- * Feature in Windows. CreateCompatibleBitmap() may fail
2226
- * for large images. The fix is to create a DIB section
2227
- * in that case.
2228
- */
2229
- if (newHandle == 0 ) {
2230
- int bits = OS .GetDeviceCaps (hDC , OS .BITSPIXEL );
2231
- int planes = OS .GetDeviceCaps (hDC , OS .PLANES );
2232
- int depth = bits * planes ;
2233
- if (depth < 16 ) depth = 16 ;
2234
- if (depth > 24 ) depth = 24 ;
2235
- newHandle = createDIB (scaledWidth , scaledHeight , depth );
2236
- }
2237
- if (newHandle != 0 ) {
2238
- long memDC = OS .CreateCompatibleDC (hDC );
2239
- long hOldBitmap = OS .SelectObject (memDC , newHandle );
2240
- OS .PatBlt (memDC , 0 , 0 , scaledWidth , scaledHeight , OS .PATCOPY );
2241
- OS .SelectObject (memDC , hOldBitmap );
2242
- OS .DeleteDC (memDC );
2243
- }
2244
- device .internal_dispose_GC (hDC , null );
2245
- if (newHandle == 0 ) {
2246
- SWT .error (SWT .ERROR_NO_HANDLES , null , device .getLastError ());
2247
- }
2248
- return newHandle ;
2240
+ return createHandle (this .width , this .height , zoom );
2249
2241
}
2250
2242
2251
2243
@ Override
@@ -2621,27 +2613,26 @@ protected ImageHandle newImageHandle(ZoomContext zoomContext) {
2621
2613
currentZoom = zoomContext ;
2622
2614
int targetZoom = zoomContext .targetZoom ();
2623
2615
int gcStyle = drawer .getGcStyle ();
2624
- Image image ;
2625
2616
if ((gcStyle & SWT .TRANSPARENT ) != 0 ) {
2626
2617
int scaledHeight = Win32DPIUtils .pointToPixel (height , targetZoom );
2627
2618
int scaledWidth = Win32DPIUtils .pointToPixel (width , targetZoom );
2628
2619
/* Create a 24 bit image data with alpha channel */
2629
2620
final ImageData resultData = new ImageData (scaledWidth , scaledHeight , 24 , new PaletteData (0xFF , 0xFF00 , 0xFF0000 ));
2630
2621
resultData .alphaData = new byte [scaledWidth * scaledHeight ];
2631
- image = new Image ( device , resultData , targetZoom );
2622
+ init ( resultData , targetZoom );
2632
2623
} else {
2633
- image = new Image ( device , width , height );
2624
+ createHandle ( width , height , targetZoom );
2634
2625
}
2635
- GC gc = new GC (new DrawableWrapper (image , zoomContext ), gcStyle );
2626
+ GC gc = new GC (new DrawableWrapper (Image . this , zoomContext ), gcStyle );
2636
2627
try {
2637
2628
drawer .drawOn (gc , width , height );
2638
- ImageData imageData = image .getImageData (targetZoom );
2629
+ ImageData imageData = Image . this .getImageData (targetZoom );
2639
2630
drawer .postProcess (imageData );
2640
- ImageData newData = adaptImageDataIfDisabledOrGray (imageData );
2641
- return init (newData , targetZoom );
2631
+ zoomLevelToImageHandle .get (targetZoom ).destroy ();
2632
+ init (imageData , targetZoom );
2633
+ return zoomLevelToImageHandle .get (targetZoom );
2642
2634
} finally {
2643
2635
gc .dispose ();
2644
- image .dispose ();
2645
2636
}
2646
2637
}
2647
2638
0 commit comments