Skip to content

Ensure DrawImage deals with scenario ImageData not linearly scaled #2250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

arunjose696
Copy link
Contributor

This change makes sure DrawImage handles the scenario where ImageData may not be linearly scaled across zooms.

Copy link
Contributor

github-actions bot commented Jun 18, 2025

Test Results

   545 files  ±0     545 suites  ±0   31m 36s ⏱️ +17s
 4 406 tests +4   4 388 ✅ +4   18 💤 ±0  0 ❌ ±0 
16 736 runs  +4  16 596 ✅ +4  140 💤 ±0  0 ❌ ±0 

Results for commit 9b0b4a0. ± Comparison against base commit f92b752.

♻️ This comment has been updated with latest results.

@arunjose696 arunjose696 force-pushed the arunjose696/313/FixDrawImageScaling branch 3 times, most recently from 573ed10 to 7ede441 Compare June 23, 2025 09:12
This change makes sure DrawImage handles the scenario where ImageData
may not be linearly scaled across zooms.
@arunjose696 arunjose696 force-pushed the arunjose696/313/FixDrawImageScaling branch from 7ede441 to 9b0b4a0 Compare June 23, 2025 09:15
Comment on lines +1026 to +1028
float scalingFactor = (float) scaledBounds.height / unScaledBound.height;
scaledImageZoom = (int) (scalingFactor * 100);
return scaledImageZoom;
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the overall approach and I think we could achieve to properly deal with the situation of non-linearly scaled image data. But I think the implementation would need to be a bit more sophisticated. With this approach, since the corrected scaledImageZoom may be an arbitrary value, we would potentially start loading images at arbitrary zooms and thus create more and more unwanted handles. In addition, there is no guarantee that the image data that the image yields for such a zoom have fitting width/height as it depends on which original image data (such as the 100%, 150% or 200% data for PNGs) are used and scaled.
I think what we might actually need to adapt is the srcWidth and srcHeight as they must not be treated as points with an ordinary point-to-pixel conversion based on the zoom if the zoom is not appropriate. However, if you have an image with non-linear image data, you do not even know to which the original point-based srcWidth and srcHeight should fit. We currently assume that it's the 100% version of the image, but it may also be the case that someone creats an ImageDataProvider that always yields image data at the same zoom, which could, for example, also be the current device zoom. If that is not 100%, there might be unexpected results.

I have just tested again the snippet in vi-eclipse/Eclipse-Platform#313 that led to an exception before and found that it now (silently) works. So I wonder whether we should focus on improving the API (adding a note to ImageDataProvider that implementations must return linearly scaled data) and rely on the just added strict check and adaptations of consumers (if necessary) instead of making the logic here more complex.

What do you think, @akoch-yatta @arunjose696?

Copy link
Contributor Author

@arunjose696 arunjose696 Jul 25, 2025

Choose a reason for hiding this comment

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

I wonder whether we should focus on improving the API (adding a note to ImageDataProvider that implementations must return linearly scaled data) and rely on the just added strict check and adaptations of consumers (if necessary) instead of making the logic here more complex.

I think the better approach would be to document clearly in ImageDataProvider that implementations must return linearly scaled data. Adding complexity to drawImage to "fix" bad input risks hiding these issues rather than solving them at the actual ( a incorrect ImageDataProvider implementation).

Copy link
Contributor

Choose a reason for hiding this comment

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

Fully agree. Just for the sake of completeness: the risk is of course that implementations of ImageDataProvider usually have been there for years already, so the contract improvement may stay unnoticed and the implementations will stay somehow incompatible. Still, I think that's the best we can do.
So, concrete proposal: We drop this PR and instead improve the contract of ImageDataProvider. We write a short news as a means to make aware of the potential issue and the contract adaptatino (as actually the assumption that image data is linearly scaled was always there but violations were silently accepted in a more or less resilient way).
@akoch-yatta would then also be good to have your final opinion when you are back before proceeding with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree. Everything else seem like a workaround, that would only cover up the overall issue, that this contract was (at least implicitly) there from the introduction of HiDPI support, but not enforced.

@arunjose696
Copy link
Contributor Author

Closing this PR as discussed

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.

Resilient handling of Images with non-linearly-scaled ImageData
3 participants