@@ -246,6 +246,55 @@ public void test_dispose() {
246246 gc .dispose ();
247247}
248248
249+
250+ @ Test
251+ public void test_drawImage_nonAutoScalableGC_bug_2504 () {
252+ Shell shell = new Shell (display );
253+ float targetScale = 2f ;
254+ int srcSize = 50 ;
255+ Image image = new Image (display , srcSize , srcSize );
256+ GC gcSrc = new GC (image );
257+ gcSrc .setBackground (display .getSystemColor (SWT .COLOR_BLACK ));
258+ gcSrc .fillRectangle (0 , 0 , srcSize , srcSize );
259+ gcSrc .setBackground (display .getSystemColor (SWT .COLOR_WHITE ));
260+ gcSrc .fillRectangle (2 , 2 , srcSize - 4 , srcSize - 4 );
261+ gcSrc .dispose ();
262+
263+ Rectangle bounds = image .getBounds ();
264+
265+ Canvas canvas = new Canvas (shell , SWT .NONE ) {
266+ @ Override
267+ public boolean isAutoScalable () {
268+ return false ;
269+ }
270+ };
271+
272+ int canvasWidth = Math .round (bounds .width * targetScale );
273+ int canvasHeight = Math .round (bounds .height * targetScale );
274+ canvas .setSize (canvasWidth , canvasHeight );
275+ canvas .addPaintListener (e -> {
276+ e .gc .drawImage (image , 0 , 0 , bounds .width , bounds .height ,
277+ 0 , 0 , canvasWidth , canvasHeight );
278+ });
279+
280+ shell .open ();
281+ Image target = new Image (display , canvasWidth , canvasHeight );
282+ GC gcCopy = new GC (canvas );
283+ gcCopy .copyArea (target , 0 , 0 );
284+ gcCopy .dispose ();
285+
286+ ImageData data = target .getImageData ();
287+
288+ int bottomRightX = canvasWidth - 1 ;
289+ int bottomRightY = canvasHeight - 1 ;
290+ RGB bottomRight = data .palette .getRGB (data .getPixel (bottomRightX , bottomRightY ));
291+ RGB black = new RGB (0 , 0 , 0 );
292+ assertEquals ( black , bottomRight , "Bottom-right pixel is not black! when source GC is not autoScalable" );
293+ shell .dispose ();
294+ target .dispose ();
295+ image .dispose ();
296+ }
297+
249298@ Test
250299public void test_drawArcIIIIII () {
251300 gc .drawArc (10 , 20 , 50 , 25 , 90 , 90 );
0 commit comments