Use higher-resolution image data in SWTGraphics if available #922#925
Draft
ptziegler wants to merge 1 commit intoeclipse-gef:masterfrom
Draft
Use higher-resolution image data in SWTGraphics if available #922#925ptziegler wants to merge 1 commit intoeclipse-gef:masterfrom
ptziegler wants to merge 1 commit intoeclipse-gef:masterfrom
Conversation
…gef#922 When drawing an image on a scaled `Graphics` object, the image data at 100% zoom is taken and then artificially up-scaled. This results in blurry images when scaling by high factors. This change adapts the `FileImageDataProvider` and the `SWTGraphics` to take this problem into consideration, especially when dealing with SVGs. The `FileImageDataProvider` is currently not able to return the `ImageData` at arbitrary zoom levels, as this is not supported by SWT, which requires the `ImageFileNameProvider` (or the internal `ImageDataAtSizeProvider`) to be implemented. The problem with the `ImageFileNameProvider` is that it can only return proper file paths. So if an image is embedded inside a jar, it first needs to be extracted into a temporary file. The `SWTGraphics` then needs to use the new `drawImage(Image,int,int,int,int)` method so that SWT uses this provider to probler scale the image to the correct size.
Contributor
Author
ptziegler
commented
Dec 22, 2025
Comment on lines
+420
to
+448
| if (transform == null) { | ||
| gc.drawImage(srcImage, x + translateX, y + translateY); | ||
| } else { | ||
| float[] transformElements = new float[6]; | ||
| transform.getElements(transformElements); | ||
|
|
||
| float scaleHor = transformElements[0]; | ||
| float scaleVer = transformElements[3]; | ||
|
|
||
| if (scaleHor == 1.0 && scaleVer == 1.0) { | ||
| gc.drawImage(srcImage, x + translateX, y + translateY); | ||
| return; | ||
| } | ||
|
|
||
| ImageData srcImageData = srcImage.getImageData(100); | ||
| int scaledX = (int) ((x + translateX) * scaleHor); | ||
| int scaledY = (int) ((y + translateY) * scaleVer); | ||
| int scaledWidth = (int) (srcImageData.width * scaleHor); | ||
| int scaledHeight = (int) (srcImageData.height * scaleVer); | ||
|
|
||
| transform.scale(1 / scaleHor, 1 / scaleVer); | ||
| gc.setTransform(transform); | ||
| try { | ||
| gc.drawImage(srcImage, scaledX, scaledY, scaledWidth, scaledHeight); | ||
| } finally { | ||
| transform.scale(scaleHor, scaleVer); | ||
| gc.setTransform(transform); | ||
| } | ||
| } |
Contributor
Author
There was a problem hiding this comment.
It's probably safer to add a new drawImage(Image,int,int,int,int) method, rather than changing the behavior of an existing method.
azoitl
reviewed
Dec 22, 2025
| float[] transformElements = new float[6]; | ||
| transform.getElements(transformElements); | ||
|
|
||
| float scaleHor = transformElements[0]; |
Contributor
There was a problem hiding this comment.
For #926 I brushed up my knowledge on vector math and transformation matrices. If you want to be correct in cases when rotation is applied then you need to take the elements 1 and 2 also into account.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

When drawing an image on a scaled
Graphicsobject, the image data at 100% zoom is taken and then artificially up-scaled. This results in blurry images when scaling by high factors.This change adapts the
FileImageDataProviderand theSWTGraphicsto take this problem into consideration, especially when dealing with SVGs.The
FileImageDataProvideris currently not able to return theImageDataat arbitrary zoom levels, as this is not supported by SWT, which requires theImageFileNameProvider(or the internalImageDataAtSizeProvider) to be implemented. The problem with theImageFileNameProvideris that it can only return proper file paths. So if an image is embedded inside a jar, it first needs to be extracted into a temporary file.The
SWTGraphicsthen needs to use the newdrawImage(Image,int,int,int,int)method so that SWT uses this provider to probler scale the image to the correct size.