-
Notifications
You must be signed in to change notification settings - Fork 172
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
base: master
Are you sure you want to change the base?
A strict check 200% image data is double the size of 100% image data #2249
Conversation
a31c3d0
to
9a302a0
Compare
560fc50
to
085c1c6
Compare
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
Outdated
Show resolved
Hide resolved
Image original = new Image(device, (ImageDataProvider) zoom -> { | ||
if (zoom == 100) { | ||
return imageData; | ||
} | ||
return null; | ||
}); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Line 323 in 085c1c6
ImageData result = resultImage.getImageData (100); |
085c1c6
to
d78d6ae
Compare
init(); | ||
this.device.registerResourceWithZoomSupport(this); | ||
} | ||
|
||
private void validateLinearScaling(ImageDataProvider provider) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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."); | |
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
d78d6ae
to
db68f87
Compare
A strict check to be used only for debugging means, this ensures the imageData is scaled linearly for 100 and 200 zooms.