Skip to content

[Win32] Fix image handle zoom selection for asymmetric image dimensions#3455

Closed
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:gc-drawimage-image-zoom
Closed

[Win32] Fix image handle zoom selection for asymmetric image dimensions#3455
HeikoKlare wants to merge 1 commit into
eclipse-platform:masterfrom
HeikoKlare:gc-drawimage-image-zoom

Conversation

@HeikoKlare

Copy link
Copy Markdown
Contributor

For images where width and height differ greatly (e.g. 500x2), computing the required zoom independently per axis using integer division can give a larger zoom estimate for the smaller axis. The old code selected the maximum of both estimates, which reliably picks the less accurate value and creates a handle at the wrong zoom level, causing noticeably incorrect scaling.

The axis with more pixels has a proportionally smaller integer-division truncation error. The fix therefore derives the zoom from the axis whose pixel hint is larger, giving the most accurate zoom estimate.

Contributes to #3454

For images where width and height differ greatly (e.g. 500x2), computing
the required zoom independently per axis using integer division can give
a larger zoom estimate for the smaller axis. The old code selected the
maximum of both estimates, which reliably picks the less accurate value
and creates a handle at the wrong zoom level, causing noticeably
incorrect scaling.

The axis with more pixels has a proportionally smaller integer-division
truncation error. The fix therefore derives the zoom from the axis whose
pixel hint is larger, giving the most accurate zoom estimate.

Contributes to
eclipse-platform#3454

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Test Results (win32)

   33 files  ±  0     33 suites  ±0   5m 24s ⏱️ +55s
4 818 tests +100  4 742 ✅ +100  76 💤 ±0  0 ❌ ±0 
1 347 runs  +100  1 323 ✅ +100  24 💤 ±0  0 ❌ ±0 

Results for commit a5a988a. ± Comparison against base commit c76abe1.

}

private static Stream<Arguments> provideZoomAndHeightCombinations() {
int[] zooms = { 100, 125, 150, 175, 200 };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't zooms < 100 also be considered here?

@HeikoKlare

Copy link
Copy Markdown
Contributor Author

I am currently not sure how to best enhance the zoom calculation. The goal was to choose the axis for zoom calculation with the lower rounding error, but just doing that based on the given hint for the target dimension does not seem to be correct. Though that value is already rounded because point-to-pixel and pixel-to-point conversions, small bounds of the image in one of the dimensions may also influence the rounding error. In addition, the change optimizes precision of the calculated zoom while ignoring the dominating axis in case the image is scaled asymmetrically (e.g., by factor 5 in y direction and by factor 1 in x direction), where it is most reasonable to better use an image version that is too large rather than using one that is too small.

This was intended to be a preparation step for:

This is because for heights between 1 and 3 pixels and a much larger widths, the dimensions of the handle being returned here are not as expected, due to large rounding errors with such a small size. However, images of 1 to 3 pixel in height do not seem to be that relevant use cases (as you cannot see anything relevant in them anyway, not matter if a higher or lower resolution version is used) that it justifies the drawback mentioned about and the risk of other unintended changes in behavior / regressions.

For the mentioned reasons, I close this PR for now. Thanks to @r-mennig for challenging the change, leading to this conclusion.

@HeikoKlare HeikoKlare closed this Jul 22, 2026
@HeikoKlare
HeikoKlare deleted the gc-drawimage-image-zoom branch July 22, 2026 18:27
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.

2 participants