Skip to content

A strict check 200% image data is double the size of 100% image data #2249

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

arunjose696
Copy link
Contributor

A strict check to be used only for debugging means, this ensures the imageData is scaled linearly for 100 and 200 zooms.

Copy link
Contributor

github-actions bot commented Jun 18, 2025

Test Results

   545 files  + 6     545 suites  +6   33m 28s ⏱️ + 2m 11s
 4 404 tests +38   4 386 ✅ +36   18 💤 +3  0 ❌  - 1 
16 737 runs  +41  16 597 ✅ +39  140 💤 +3  0 ❌  - 1 

Results for commit db68f87. ± Comparison against base commit a413b4b.

♻️ This comment has been updated with latest results.

Comment on lines +304 to +309
Image original = new Image(device, (ImageDataProvider) zoom -> {
if (zoom == 100) {
return imageData;
}
return null;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

is zoom == 100 always correct, is it? Will it always be fetched for 100 and then scaled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ImageData is only requested for 100 zoom, so only 100 is required

@arunjose696 arunjose696 force-pushed the arunjose696/313/StrictCheck branch from 085c1c6 to d78d6ae Compare June 23, 2025 11:33
init();
this.device.registerResourceWithZoomSupport(this);
}

private void validateLinearScaling(ImageDataProvider provider) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method seems tightly coupled using a lot of magic numbers. Maybe adapt it a little?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using magic numbers for 100 and 200 seems unavoidable, have converted them to final variables, if they are any better

Comment on lines 621 to 633
ImageData data100 = provider.getImageData(100);
ImageData data200 = provider.getImageData(200);

if (data200 == null) {
return;
}

if (data200.width != 2 * data100.width || data200.height != 2 * data100.height) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "ImageData should be linearly scaled across zooms.");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ImageData data100 = provider.getImageData(100);
ImageData data200 = provider.getImageData(200);
if (data200 == null) {
return;
}
if (data200.width != 2 * data100.width || data200.height != 2 * data100.height) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "ImageData should be linearly scaled across zooms.");
}
final int scaledZoom = 200;
ImageData baseImageData = provider.getImageData(100);
ImageData scaledImageData = provider.getImageData(scaledZoom);
if (baseImageData == null || scaledImageData == null) {
return;
}
int expectedWidth = DPIUtil.scaleUp(baseImage.width, scaledZoom);
int expectedHeight = DPIUtil.scaleUp(baseImage.height, scaledZoom);
if (scaledImage.width != expectedWidth || scaledImage.height != expectedHeight) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "ImageData should be linearly scaled across zooms.");
}

Copy link
Contributor Author

@arunjose696 arunjose696 Jun 24, 2025

Choose a reason for hiding this comment

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

I agree about avoiding magic numbers. However, I felt that using DPIUtil.scaleUp here would slightly overcomplicate things for readability. Instead, I introduced a scaleFactor variable to clarify the scaling logic.

ImageData data100 = provider.getImageData(100);
ImageData data200 = provider.getImageData(200);

if (data200 == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not check for data100 as well?

Copy link
Contributor Author

@arunjose696 arunjose696 Jun 24, 2025

Choose a reason for hiding this comment

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

data200 may be null in a valid ImageDataProvider implementation which should pass the strict check(in this check we just make sure we dont throw exceptions if data200 is null). But data100 is guaranteed to exist and will have already been validated before this line is reached, so no additional checks are necessary here.

A strict check to be used only for debugging means, this ensures the
imageData is scaled linearly for 100 and 200 zooms.
@arunjose696 arunjose696 force-pushed the arunjose696/313/StrictCheck branch from d78d6ae to db68f87 Compare June 24, 2025 14:12
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