@@ -1911,6 +1911,47 @@ protected final ImageHandle newImageHandle(ImageData data, int zoom) {
1911
1911
return init (data , zoom );
1912
1912
}
1913
1913
}
1914
+
1915
+ protected final ImageHandle createBaseHandle (int zoom , int width , int height ) {
1916
+ long handle = initBaseHandle (zoom , width , height );
1917
+ ImageHandle imageHandle = new ImageHandle (handle , zoom );
1918
+ zoomLevelToImageHandle .put (zoom , imageHandle );
1919
+ return imageHandle ;
1920
+ }
1921
+
1922
+
1923
+ private long initBaseHandle (int zoom , int width , int height ) {
1924
+ if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
1925
+ int scaledWidth = DPIUtil .scaleUp (width , zoom );
1926
+ int scaledHeight = DPIUtil .scaleUp (height , zoom );
1927
+ long hDC = device .internal_new_GC (null );
1928
+ long newHandle = OS .CreateCompatibleBitmap (hDC , scaledWidth , scaledHeight );
1929
+ /*
1930
+ * Feature in Windows. CreateCompatibleBitmap() may fail
1931
+ * for large images. The fix is to create a DIB section
1932
+ * in that case.
1933
+ */
1934
+ if (newHandle == 0 ) {
1935
+ int bits = OS .GetDeviceCaps (hDC , OS .BITSPIXEL );
1936
+ int planes = OS .GetDeviceCaps (hDC , OS .PLANES );
1937
+ int depth = bits * planes ;
1938
+ if (depth < 16 ) depth = 16 ;
1939
+ if (depth > 24 ) depth = 24 ;
1940
+ newHandle = createDIB (scaledWidth , scaledHeight , depth );
1941
+ }
1942
+ if (newHandle != 0 ) {
1943
+ long memDC = OS .CreateCompatibleDC (hDC );
1944
+ long hOldBitmap = OS .SelectObject (memDC , newHandle );
1945
+ OS .PatBlt (memDC , 0 , 0 , scaledWidth , scaledHeight , OS .PATCOPY );
1946
+ OS .SelectObject (memDC , hOldBitmap );
1947
+ OS .DeleteDC (memDC );
1948
+ }
1949
+ device .internal_dispose_GC (hDC , null );
1950
+ if (newHandle == 0 ) {
1951
+ SWT .error (SWT .ERROR_NO_HANDLES , null , device .getLastError ());
1952
+ }
1953
+ return newHandle ;
1954
+ }
1914
1955
}
1915
1956
1916
1957
private class ExistingImageHandleProviderWrapper extends AbstractImageProviderWrapper {
@@ -2121,59 +2162,22 @@ protected Rectangle getBounds(int zoom) {
2121
2162
@ Override
2122
2163
ImageData newImageData (int zoom ) {
2123
2164
if (zoomLevelToImageHandle .isEmpty ()) {
2124
- return createBaseHandle (zoom ).getImageData ();
2165
+ baseZoom = zoom ;
2166
+ return createBaseHandle (zoom , width , height ).getImageData ();
2125
2167
}
2126
2168
return getScaledImageData (zoom );
2127
2169
}
2128
2170
2129
2171
@ Override
2130
2172
protected ImageHandle newImageHandle (int zoom ) {
2131
2173
if (zoomLevelToImageHandle .isEmpty ()) {
2132
- return createBaseHandle (zoom );
2174
+ baseZoom = zoom ;
2175
+ return createBaseHandle (zoom , width , height );
2133
2176
}
2134
2177
return super .newImageHandle (zoom );
2135
2178
}
2136
2179
2137
- private ImageHandle createBaseHandle (int zoom ) {
2138
- long handle = initBaseHandle (zoom );
2139
- baseZoom = zoom ;
2140
- ImageHandle imageHandle = new ImageHandle (handle , zoom );
2141
- zoomLevelToImageHandle .put (zoom , imageHandle );
2142
- return imageHandle ;
2143
- }
2144
2180
2145
- private long initBaseHandle (int zoom ) {
2146
- if (isDisposed ()) SWT .error (SWT .ERROR_GRAPHIC_DISPOSED );
2147
- int scaledWidth = DPIUtil .scaleUp (width , zoom );
2148
- int scaledHeight = DPIUtil .scaleUp (height , zoom );
2149
- long hDC = device .internal_new_GC (null );
2150
- long newHandle = OS .CreateCompatibleBitmap (hDC , scaledWidth , scaledHeight );
2151
- /*
2152
- * Feature in Windows. CreateCompatibleBitmap() may fail
2153
- * for large images. The fix is to create a DIB section
2154
- * in that case.
2155
- */
2156
- if (newHandle == 0 ) {
2157
- int bits = OS .GetDeviceCaps (hDC , OS .BITSPIXEL );
2158
- int planes = OS .GetDeviceCaps (hDC , OS .PLANES );
2159
- int depth = bits * planes ;
2160
- if (depth < 16 ) depth = 16 ;
2161
- if (depth > 24 ) depth = 24 ;
2162
- newHandle = createDIB (scaledWidth , scaledHeight , depth );
2163
- }
2164
- if (newHandle != 0 ) {
2165
- long memDC = OS .CreateCompatibleDC (hDC );
2166
- long hOldBitmap = OS .SelectObject (memDC , newHandle );
2167
- OS .PatBlt (memDC , 0 , 0 , scaledWidth , scaledHeight , OS .PATCOPY );
2168
- OS .SelectObject (memDC , hOldBitmap );
2169
- OS .DeleteDC (memDC );
2170
- }
2171
- device .internal_dispose_GC (hDC , null );
2172
- if (newHandle == 0 ) {
2173
- SWT .error (SWT .ERROR_NO_HANDLES , null , device .getLastError ());
2174
- }
2175
- return newHandle ;
2176
- }
2177
2181
2178
2182
@ Override
2179
2183
AbstractImageProviderWrapper createCopy (Image image ) {
@@ -2541,28 +2545,25 @@ ImageData newImageData(int zoom) {
2541
2545
protected ImageHandle newImageHandle (int zoom ) {
2542
2546
currentZoom = zoom ;
2543
2547
int gcStyle = drawer .getGcStyle ();
2544
- Image image ;
2545
2548
if ((gcStyle & SWT .TRANSPARENT ) != 0 ) {
2546
2549
int scaledHeight = DPIUtil .scaleUp (height , zoom );
2547
2550
int scaledWidth = DPIUtil .scaleUp (width , zoom );
2548
2551
/* Create a 24 bit image data with alpha channel */
2549
2552
final ImageData resultData = new ImageData (scaledWidth , scaledHeight , 24 , new PaletteData (0xFF , 0xFF00 , 0xFF0000 ));
2550
2553
resultData .alphaData = new byte [scaledWidth * scaledHeight ];
2551
- image = new Image ( device , resultData , zoom );
2554
+ init ( resultData , zoom );
2552
2555
} else {
2553
- image = new Image ( device , width , height );
2554
- }
2555
- GC gc = new GC (new DrawableWrapper (image , zoom ), gcStyle );
2556
+ createBaseHandle ( zoom , width , height );
2557
+ };
2558
+ GC gc = new GC (new DrawableWrapper (Image . this , zoom ), gcStyle );
2556
2559
try {
2557
2560
gc .data .nativeZoom = zoom ;
2558
2561
drawer .drawOn (gc , width , height );
2559
- ImageData imageData = image .getImageMetadata (zoom ).getImageData ();
2562
+ ImageData imageData = Image . this .getImageMetadata (zoom ).getImageData ();
2560
2563
drawer .postProcess (imageData );
2561
- ImageData newData = adaptImageDataIfDisabledOrGray (imageData );
2562
- return init (newData , zoom );
2564
+ return zoomLevelToImageHandle .get (zoom );
2563
2565
} finally {
2564
2566
gc .dispose ();
2565
- image .dispose ();
2566
2567
}
2567
2568
}
2568
2569
0 commit comments