Skip to content

[GTK] Consider transformation scale in GC.drawImage(image, x, y) #2919#3201

Merged
ptziegler merged 1 commit intoeclipse-platform:masterfrom
ptziegler:gc-transform
Apr 17, 2026
Merged

[GTK] Consider transformation scale in GC.drawImage(image, x, y) #2919#3201
ptziegler merged 1 commit intoeclipse-platform:masterfrom
ptziegler:gc-transform

Conversation

@ptziegler
Copy link
Copy Markdown
Contributor

With e97143c, support was added on Windows to take the Transform scaling into consideration when calling drawImage(image,x,y). Especially when used in combination with an SVG-based image, this leads to better results as the best-fitting image is used for painting, rather than relying on interpolation.

This change follows a similar logic to what has been done for Windows; The call to drawImage(image,x,y) is delegated to drawImage(x,y,w,h) when a Transform has been set. Within this method, the width and height of the image are used as size after being multiplied by the transformation scale.

Contributes to
#2919

@ptziegler
Copy link
Copy Markdown
Contributor Author

A side-by-side comparison of how this change affects GEF:

image

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Test Results (linux)

   88 files  + 3     88 suites  +3   14m 10s ⏱️ -22s
4 557 tests + 1  4 337 ✅ + 2  220 💤 ±0  0 ❌  - 1 
3 275 runs  +37  3 206 ✅ +36   69 💤 +2  0 ❌  - 1 

Results for commit 00f0547. ± Comparison against base commit 9e86574.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates GTK GC#drawImage(...) so that when a Transform with scaling is applied, SWT requests an image rendered at the effective (scaled) destination size, improving best-fit selection for multi-resolution/SVG images (parity with the earlier Windows change).

Changes:

  • Add a helper to compute an effective transformation scale from the current GC transform.
  • Delegate drawImage(image, x, y) to the width/height overload when a non-identity transform is active.
  • Multiply destination dimensions by the transformation scale before calling Image#executeOnImageAtSize(...).

Copy link
Copy Markdown
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change looks sound to me. The comment regarding tests made by Copilot seems valid. There are two test cases in Test...GC, one is even missing an @Test annotation, so we could take the chance of properly enabling it. The other is @EnabledOnOS(OS.WINDOWS), which we now may change to @DisabledOnOS(OS.MAC) until we have applied the same change to macOS.

@ptziegler ptziegler force-pushed the gc-transform branch 3 times, most recently from f3ee03c to 84bb450 Compare April 16, 2026 20:44
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 16, 2026

Test Results

  182 files  ±0    182 suites  ±0   24m 54s ⏱️ - 2m 9s
4 703 tests +1  4 682 ✅ +1   21 💤 ±0  0 ❌ ±0 
6 716 runs  +6  6 561 ✅ +9  155 💤  - 3  0 ❌ ±0 

Results for commit f7c0acb. ± Comparison against base commit f1bf0d3.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you. I consider this ready to be merged.

HeikoKlare added a commit to HeikoKlare/eclipse.platform.swt that referenced this pull request Apr 16, 2026
…lipse-platform#2919

With e97143c, support was added on
Windows to take the Transform scaling into consideration when calling
drawImage(image, x, y). Especially when used in combination with an
SVG-based image, this leads to better results as the best-fitting image
representation is used for painting, rather than relying on
interpolation.

This change follows the same logic for Cocoa/macOS, equivalent to what
has already been done for Windows and is being done for GTK in eclipse-platform#3201.

When a Transform is active on the GC, the call to drawImage(image, x, y)
is delegated to drawImage(image, x, y, w, h), using the image's natural
bounds as the destination size. Within that method, the destination
dimensions are multiplied by the effective transformation scale before
being passed to executeOnImageAtSizeBestFittingSize(), so that the
higher-resolution image representation is selected and rendered at its
full quality rather than being upscaled from a lower-resolution variant.

The effective scale is derived from the active NSAffineTransform via
Math.hypot() on the matrix columns, which correctly handles transforms
that combine scaling with rotation.

The existing test test_drawImageLorg_eclipse_swt_graphics_ImageIIII_withTransform,
which was previously restricted to Windows only, is now enabled on all
platforms (the @EnabledOnOs(OS.WINDOWS) guard and its now-unused imports
are removed). The previously un-annotated companion test
test_drawImageLorg_eclipse_swt_graphics_ImageIIII_withTransform_zeroTargetSize
receives the missing @test annotation so it is actually executed.

Contributes to
eclipse-platform#2919
…pse-platform#2919

With e97143c, support was added on
Windows to take the `Transform` scaling into consideration when calling
`drawImage(image,x,y)`. Especially when used in combination with an
SVG-based image, this leads to better results as the best-fitting image
is used for painting, rather than relying on interpolation.

This change follows a similar logic to what has been done for Windows;
The call to `drawImage(image,x,y)` is delegated to `drawImage(x,y,w,h)`
when a `Transform` has been set. Within this method, the width and
height of the image are used as size after being multiplied by the
transformation scale.

Contributes to
eclipse-platform#2919
@ptziegler ptziegler merged commit 6425e28 into eclipse-platform:master Apr 17, 2026
24 checks passed
@ptziegler ptziegler deleted the gc-transform branch April 17, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants