Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 318294

Summary: Support native scaling of the Images
Product: [Eclipse Project] Platform Reporter: Gorkem Ercan <gorkem.ercan>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: enhancement    
Priority: P3 CC: eclipse.felipe, petru.motrescu, Silenio_Quarti
Version: 3.6   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Gorkem Ercan CLA 2010-06-29 07:53:44 EDT
Currently the only way to scale an Image is to use the ImageData.scaleTo() method. However, the scaling quality provided by this implementation is not good. Also Since ImageData is a java side object it is not possible to provide an implementation that takes the advantage of  native scaling. I would like to suggest a new constructor to the Image that takes another source Image and a target Size and possibly scaling hint. SWT implementations in turn can implement the constructor using native algorithms which will be higher quality and better performant then the current scaleTo implementation. 

Also please note that this is an enhancement that is also required by the eSWT project.
Comment 1 Felipe Heidrich CLA 2010-06-29 12:34:24 EDT
What about this:
Image imageSrc = new Image(display, fileName);
Rectangle rect = imageSrc.getBounds();
Image imageDst = new Image(display, rect.width * 2, rect.height * 2);
GC gc = new GC(imageDst);
gc.drawImage(imageSrc, 0, 0, rect.width, rect.height, 0, 0,rect.width * 2, rect.height * 2);
gc.dispose();

This will use native scalling.

Does it work for you ?
Comment 2 Petru Motrescu CLA 2010-06-30 06:15:54 EDT
I would like us to have more control over the quality of the scale. With the GC solution, there is no such control. In S60, at least, the quality of the scale performed with the GC defaults to "low & quick" a.k.a. "nearest neighbour" scaling.

With the new API addition we could hint (by declaring the param as hint we do not force all platform to conform) the desired scale quality & speed:
- high & slow - nearest neighbour (quality param SWT.MAX ?)
- medium      - bilinear          (quality param SWT.DEFAULT ?)
- low & quick - bicubic           (quality param SWT.MIN ?)

The new API, I believe (personal opinion) is clearer and easier to find.
Comment 3 Felipe Heidrich CLA 2010-06-30 15:40:08 EDT
You have this control in the current API already.
Before drawing the image with the GC you need to call setAdvance(true) and 
setInterpolation() with one of the following:

SWT.DEFAULT (Gdip.InterpolationModeDefault), 
SWT.NONE (Gdip.InterpolationModeNearestNeighbor), 
SWT.LOW (Gdip.InterpolationModeLowQuality), 
SWT.HIGH (Gdip.InterpolationModeHighQuality).


Closing as works for me. Agreed ?
Comment 4 Petru Motrescu CLA 2010-07-01 02:29:26 EDT
I have failed to spot that. Thank you.