@@ -985,20 +985,20 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei
985
985
if (image == null ) SWT .error (SWT .ERROR_NULL_ARGUMENT );
986
986
if (image .isDisposed ()) SWT .error (SWT .ERROR_INVALID_ARGUMENT );
987
987
988
- int deviceZoom = getZoom ();
989
- Rectangle src = DPIUtil .scaleUp (drawable , new Rectangle (srcX , srcY , srcWidth , srcHeight ), deviceZoom );
990
- Rectangle dest = DPIUtil .scaleUp (drawable , new Rectangle (destX , destY , destWidth , destHeight ), deviceZoom );
991
- if (deviceZoom != 100 ) {
988
+ int imageZoom = getZoom ();
989
+ Rectangle src = DPIUtil .scaleUp (drawable , new Rectangle (srcX , srcY , srcWidth , srcHeight ), imageZoom );
990
+ Rectangle dest = DPIUtil .scaleUp (drawable , new Rectangle (destX , destY , destWidth , destHeight ), imageZoom );
991
+ if (imageZoom != 100 ) {
992
992
/*
993
993
* This is a HACK! Due to rounding errors at fractional scale factors,
994
994
* the coordinates may be slightly off. The workaround is to restrict
995
995
* coordinates to the allowed bounds.
996
996
*/
997
- Rectangle b = image .getBounds (deviceZoom );
997
+ Rectangle b = image .getBounds (imageZoom );
998
998
int errX = src .x + src .width - b .width ;
999
999
int errY = src .y + src .height - b .height ;
1000
1000
if (errX != 0 || errY != 0 ) {
1001
- if (errX <= deviceZoom / 100 && errY <= deviceZoom / 100 ) {
1001
+ if (errX <= imageZoom / 100 && errY <= imageZoom / 100 ) {
1002
1002
src .intersect (b );
1003
1003
} else {
1004
1004
SWT .error (SWT .ERROR_INVALID_ARGUMENT );
@@ -1009,12 +1009,14 @@ public void drawImage (Image image, int srcX, int srcY, int srcWidth, int srcHei
1009
1009
}
1010
1010
1011
1011
void drawImage (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1012
+ int imageZoom = getZoom ();
1012
1013
if (data .gdipGraphics != 0 ) {
1013
1014
//TODO - cache bitmap
1014
- long [] gdipImage = srcImage .createGdipImage (getZoom () );
1015
+ long [] gdipImage = srcImage .createGdipImage (imageZoom );
1015
1016
long img = gdipImage [0 ];
1016
1017
int imgWidth = Gdip .Image_GetWidth (img );
1017
1018
int imgHeight = Gdip .Image_GetHeight (img );
1019
+
1018
1020
if (simple ) {
1019
1021
srcWidth = destWidth = imgWidth ;
1020
1022
srcHeight = destHeight = imgHeight ;
@@ -1065,17 +1067,18 @@ void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
1065
1067
}
1066
1068
return ;
1067
1069
}
1070
+ long imageHandle = Image .win32_getHandle (srcImage , imageZoom );
1068
1071
switch (srcImage .type ) {
1069
1072
case SWT .BITMAP :
1070
- drawBitmap (srcImage , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1073
+ drawBitmap (srcImage , imageHandle , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1071
1074
break ;
1072
1075
case SWT .ICON :
1073
- drawIcon (srcImage , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1076
+ drawIcon (imageHandle , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1074
1077
break ;
1075
1078
}
1076
1079
}
1077
1080
1078
- void drawIcon (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1081
+ void drawIcon (long imageHandle , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1079
1082
int technology = OS .GetDeviceCaps (handle , OS .TECHNOLOGY );
1080
1083
1081
1084
boolean drawIcon = true ;
@@ -1099,14 +1102,14 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i
1099
1102
/* Simple case: no stretching, entire icon */
1100
1103
if (simple && technology != OS .DT_RASPRINTER && drawIcon ) {
1101
1104
if (offsetX != 0 || offsetY != 0 ) OS .SetWindowOrgEx (handle , 0 , 0 , null );
1102
- OS .DrawIconEx (handle , destX - offsetX , destY - offsetY , Image . win32_getHandle ( srcImage , getZoom ()) , 0 , 0 , 0 , 0 , flags );
1105
+ OS .DrawIconEx (handle , destX - offsetX , destY - offsetY , imageHandle , 0 , 0 , 0 , 0 , flags );
1103
1106
if (offsetX != 0 || offsetY != 0 ) OS .SetWindowOrgEx (handle , offsetX , offsetY , null );
1104
1107
return ;
1105
1108
}
1106
1109
1107
1110
/* Get the icon info */
1108
1111
ICONINFO srcIconInfo = new ICONINFO ();
1109
- OS .GetIconInfo (Image . win32_getHandle ( srcImage , getZoom ()) , srcIconInfo );
1112
+ OS .GetIconInfo (imageHandle , srcIconInfo );
1110
1113
1111
1114
/* Get the icon width and height */
1112
1115
long hBitmap = srcIconInfo .hbmColor ;
@@ -1128,11 +1131,11 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i
1128
1131
srcWidth == destWidth && srcHeight == destHeight &&
1129
1132
srcWidth == iconWidth && srcHeight == iconHeight ;
1130
1133
if (!drawIcon ) {
1131
- drawBitmapMask (srcImage , srcIconInfo .hbmColor , srcIconInfo .hbmMask , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple , iconWidth , iconHeight , false );
1134
+ drawBitmapMask (srcIconInfo .hbmColor , srcIconInfo .hbmMask , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple , iconWidth , iconHeight , false );
1132
1135
} else if (simple && technology != OS .DT_RASPRINTER ) {
1133
1136
/* Simple case: no stretching, entire icon */
1134
1137
if (offsetX != 0 || offsetY != 0 ) OS .SetWindowOrgEx (handle , 0 , 0 , null );
1135
- OS .DrawIconEx (handle , destX - offsetX , destY - offsetY , Image . win32_getHandle ( srcImage , getZoom ()) , 0 , 0 , 0 , 0 , flags );
1138
+ OS .DrawIconEx (handle , destX - offsetX , destY - offsetY , imageHandle , 0 , 0 , 0 , 0 , flags );
1136
1139
if (offsetX != 0 || offsetY != 0 ) OS .SetWindowOrgEx (handle , offsetX , offsetY , null );
1137
1140
} else {
1138
1141
/* Create the icon info and HDC's */
@@ -1205,9 +1208,9 @@ void drawIcon(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, i
1205
1208
if (failed ) SWT .error (SWT .ERROR_INVALID_ARGUMENT );
1206
1209
}
1207
1210
1208
- void drawBitmap (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1211
+ void drawBitmap (Image srcImage , long imageHandle , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1209
1212
BITMAP bm = new BITMAP ();
1210
- OS .GetObject (Image . win32_getHandle ( srcImage , getZoom ()) , BITMAP .sizeof , bm );
1213
+ OS .GetObject (imageHandle , BITMAP .sizeof , bm );
1211
1214
int imgWidth = bm .bmWidth ;
1212
1215
int imgHeight = bm .bmHeight ;
1213
1216
if (simple ) {
@@ -1235,27 +1238,27 @@ void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
1235
1238
boolean isDib = bm .bmBits != 0 ;
1236
1239
int depth = bm .bmPlanes * bm .bmBitsPixel ;
1237
1240
if (isDib && depth == 32 ) {
1238
- drawBitmapAlpha (srcImage , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1241
+ drawBitmapAlpha (imageHandle , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1239
1242
} else if (srcImage .transparentPixel != -1 ) {
1240
- drawBitmapTransparent (srcImage , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple , bm , imgWidth , imgHeight );
1243
+ drawBitmapTransparent (srcImage , imageHandle , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple , bm , imgWidth , imgHeight );
1241
1244
} else {
1242
- drawBitmapColor (srcImage , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1245
+ drawBitmapColor (imageHandle , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1243
1246
}
1244
1247
if (mustRestore ) {
1245
- long hOldBitmap = OS .SelectObject (memGC .handle , Image . win32_getHandle ( srcImage , getZoom ()) );
1248
+ long hOldBitmap = OS .SelectObject (memGC .handle , imageHandle );
1246
1249
memGC .data .hNullBitmap = hOldBitmap ;
1247
1250
}
1248
1251
}
1249
1252
1250
- void drawBitmapAlpha (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1253
+ void drawBitmapAlpha (long imageHandle , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1251
1254
boolean alphaBlendSupport = true ;
1252
1255
boolean isPrinter = OS .GetDeviceCaps (handle , OS .TECHNOLOGY ) == OS .DT_RASPRINTER ;
1253
1256
int sourceAlpha = -1 ;
1254
1257
if (isPrinter ) {
1255
1258
int caps = OS .GetDeviceCaps (handle , OS .SHADEBLENDCAPS );
1256
1259
if (caps != 0 ) {
1257
1260
long srcHdc = OS .CreateCompatibleDC (handle );
1258
- long oldSrcBitmap = OS .SelectObject (srcHdc , Image . win32_getHandle ( srcImage , getZoom ()) );
1261
+ long oldSrcBitmap = OS .SelectObject (srcHdc , imageHandle );
1259
1262
long memDib = Image .createDIB (srcWidth , srcHeight , 32 );
1260
1263
if (memDib == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
1261
1264
long memHdc = OS .CreateCompatibleDC (handle );
@@ -1282,7 +1285,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe
1282
1285
if (sourceAlpha != -1 ) {
1283
1286
if (sourceAlpha == 0 ) return ;
1284
1287
if (sourceAlpha == 255 ) {
1285
- drawBitmapColor (srcImage , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1288
+ drawBitmapColor (imageHandle , srcX , srcY , srcWidth , srcHeight , destX , destY , destWidth , destHeight , simple );
1286
1289
return ;
1287
1290
}
1288
1291
alphaBlendSupport = (caps & OS .SB_CONST_ALPHA ) != 0 ;
@@ -1296,7 +1299,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe
1296
1299
BLENDFUNCTION blend = new BLENDFUNCTION ();
1297
1300
blend .BlendOp = OS .AC_SRC_OVER ;
1298
1301
long srcHdc = OS .CreateCompatibleDC (handle );
1299
- long oldSrcBitmap = OS .SelectObject (srcHdc , Image . win32_getHandle ( srcImage , getZoom ()) );
1302
+ long oldSrcBitmap = OS .SelectObject (srcHdc , imageHandle );
1300
1303
blend .SourceConstantAlpha = (byte )sourceAlpha ;
1301
1304
blend .AlphaFormat = OS .AC_SRC_ALPHA ;
1302
1305
OS .AlphaBlend (handle , destX , destY , destWidth , destHeight , srcHdc , srcX , srcY , srcWidth , srcHeight , blend );
@@ -1329,7 +1332,7 @@ void drawBitmapAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHe
1329
1332
1330
1333
/* Create resources */
1331
1334
long srcHdc = OS .CreateCompatibleDC (handle );
1332
- long oldSrcBitmap = OS .SelectObject (srcHdc , Image . win32_getHandle ( srcImage , getZoom ()) );
1335
+ long oldSrcBitmap = OS .SelectObject (srcHdc , imageHandle );
1333
1336
long memHdc = OS .CreateCompatibleDC (handle );
1334
1337
long memDib = Image .createDIB (Math .max (srcWidth , destWidth ), Math .max (srcHeight , destHeight ), 32 );
1335
1338
if (memDib == 0 ) SWT .error (SWT .ERROR_NO_HANDLES );
@@ -1445,7 +1448,7 @@ void drawBitmapTransparentByClipping(long srcHdc, long maskHdc, int srcX, int sr
1445
1448
OS .DeleteObject (rgn );
1446
1449
}
1447
1450
1448
- void drawBitmapMask (Image srcImage , long srcColor , long srcMask , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple , int imgWidth , int imgHeight , boolean offscreen ) {
1451
+ void drawBitmapMask (long srcColor , long srcMask , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple , int imgWidth , int imgHeight , boolean offscreen ) {
1449
1452
int srcColorY = srcY ;
1450
1453
if (srcColor == 0 ) {
1451
1454
srcColor = srcMask ;
@@ -1497,11 +1500,11 @@ void drawBitmapMask(Image srcImage, long srcColor, long srcMask, int srcX, int s
1497
1500
OS .DeleteDC (srcHdc );
1498
1501
}
1499
1502
1500
- void drawBitmapTransparent (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple , BITMAP bm , int imgWidth , int imgHeight ) {
1503
+ void drawBitmapTransparent (Image srcImage , long imageHandle , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple , BITMAP bm , int imgWidth , int imgHeight ) {
1501
1504
1502
1505
/* Find the RGB values for the transparent pixel. */
1503
1506
boolean isDib = bm .bmBits != 0 ;
1504
- long hBitmap = Image . win32_getHandle ( srcImage , getZoom ()) ;
1507
+ long hBitmap = imageHandle ;
1505
1508
long srcHdc = OS .CreateCompatibleDC (handle );
1506
1509
long oldSrcBitmap = OS .SelectObject (srcHdc , hBitmap );
1507
1510
byte [] originalColors = null ;
@@ -1546,7 +1549,7 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int
1546
1549
bmiHeader .biBitCount = bm .bmBitsPixel ;
1547
1550
byte [] bmi = new byte [BITMAPINFOHEADER .sizeof + numColors * 4 ];
1548
1551
OS .MoveMemory (bmi , bmiHeader , BITMAPINFOHEADER .sizeof );
1549
- OS .GetDIBits (srcHdc , Image . win32_getHandle ( srcImage , getZoom ()) , 0 , 0 , null , bmi , OS .DIB_RGB_COLORS );
1552
+ OS .GetDIBits (srcHdc , imageHandle , 0 , 0 , null , bmi , OS .DIB_RGB_COLORS );
1550
1553
int offset = BITMAPINFOHEADER .sizeof + 4 * srcImage .transparentPixel ;
1551
1554
transRed = bmi [offset + 2 ] & 0xFF ;
1552
1555
transGreen = bmi [offset + 1 ] & 0xFF ;
@@ -1619,13 +1622,13 @@ void drawBitmapTransparent(Image srcImage, int srcX, int srcY, int srcWidth, int
1619
1622
OS .DeleteObject (maskBitmap );
1620
1623
}
1621
1624
OS .SelectObject (srcHdc , oldSrcBitmap );
1622
- if (hBitmap != Image . win32_getHandle ( srcImage , getZoom ()) ) OS .DeleteObject (hBitmap );
1625
+ if (hBitmap != imageHandle ) OS .DeleteObject (hBitmap );
1623
1626
OS .DeleteDC (srcHdc );
1624
1627
}
1625
1628
1626
- void drawBitmapColor (Image srcImage , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1629
+ void drawBitmapColor (long imageHandle , int srcX , int srcY , int srcWidth , int srcHeight , int destX , int destY , int destWidth , int destHeight , boolean simple ) {
1627
1630
long srcHdc = OS .CreateCompatibleDC (handle );
1628
- long oldSrcBitmap = OS .SelectObject (srcHdc , Image . win32_getHandle ( srcImage , getZoom ()) );
1631
+ long oldSrcBitmap = OS .SelectObject (srcHdc , imageHandle );
1629
1632
int dwRop = OS .GetROP2 (handle ) == OS .R2_XORPEN ? OS .SRCINVERT : OS .SRCCOPY ;
1630
1633
if (!simple && (srcWidth != destWidth || srcHeight != destHeight )) {
1631
1634
int mode = OS .SetStretchBltMode (handle , OS .COLORONCOLOR );
0 commit comments