Skip to content

[Win32] Improve size calculation for cropped and scaled image drawing#3431

Draft
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:gc-drawimage-rounding
Draft

[Win32] Improve size calculation for cropped and scaled image drawing#3431
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:gc-drawimage-rounding

Conversation

@HeikoKlare

Copy link
Copy Markdown
Contributor

When drawing cropped and scaled images, the calculation for the source rectangle to draw is quite error prone:

  • It does not distinguish between different scale factor in X and Y direction, leading to large rounding errors if the extent in one directions is highly different from the extent in the other direction
  • It does not apply rounding that is consistent to the scaling done by the Image class, thus leading to differently rounded sizes when scaling an image in the Image class and drawing that same image in the GC
  • The "error correction" to deal with rounding at fractional scale factors is too restrictive, in particular when the scale factor is less than 1

This change reimplements the source rectangle calculation as follows:

  • It treats the scale factors for both axes independently
  • It applies the same rounding method to the rectangle extents than done by Image scaling implementation
  • It rounds up the scale factor when checking for the allowed size error on fractional scaling, such that a scale factor less than 1 still allows for an error of 1 in size.

This is currently a draft for the sake of visibility that may address eclipse-gef/gef-classic#1146 and other not-yet-properly-documented issues (as sketched in the description above).

When drawing cropped and scaled images, the calculation for the source
rectangle to draw is quite error prone:
- It does not distinguish between different scale factor in X and Y
direction, leading to large rounding errors if the extent in one
directions is highly different from the extent in the other direction
- It does not apply rounding that is consistent to the scaling done by
the Image class, thus leading to differently rounded sizes when scaling
an image in the Image class and drawing that same image in the GC
- The "error correction" to deal with rounding at fractional scale
factors is too restrictive, in particular when the scale factor is less
than 1

This change reimplements the source rectangle calculation as follows:
- It treats the scale factors for both axes independently
- It applies the same rounding method to the rectangle extents than done
by Image scaling implementation
- It rounds up the scale factor when checking for the allowed size error
on fractional scaling, such that a scale factor less than 1 still allows
for an error of 1 in size.
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Test Results (win32)

   33 files  ±0     33 suites  ±0   4m 30s ⏱️ +14s
4 718 tests ±0  4 642 ✅ ±0  76 💤 ±0  0 ❌ ±0 
1 247 runs  ±0  1 223 ✅ ±0  24 💤 ±0  0 ❌ ±0 

Results for commit 31181b5. ± Comparison against base commit 28ddc85.

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.

1 participant