-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -610,10 +610,29 @@ public Image(Device device, ImageDataProvider imageDataProvider) { | |
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, | ||
": ImageDataProvider [" + imageDataProvider + "] returns null ImageData at 100% zoom."); | ||
} | ||
if (Device.strictChecks) { | ||
validateLinearScaling(imageDataProvider); | ||
} | ||
init(); | ||
this.device.registerResourceWithZoomSupport(this); | ||
} | ||
|
||
private void validateLinearScaling(ImageDataProvider provider) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 |
||
final int zoom100 = 100; | ||
final int zoom200 = 200; | ||
final int scaleFactor = zoom200 / zoom100; | ||
ImageData data100 = provider.getImageData(zoom100); | ||
ImageData data200 = provider.getImageData(zoom200); | ||
|
||
if (data200 == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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. |
||
return; | ||
} | ||
|
||
if (data200.width != scaleFactor * data100.width || data200.height != scaleFactor * data100.height) { | ||
SWT.error(SWT.ERROR_INVALID_ARGUMENT, null, "ImageData should be linearly scaled across zooms."); | ||
} | ||
} | ||
|
||
/** | ||
* The provided ImageGcDrawer will be called on demand whenever a new variant of the | ||
* Image for an additional zoom is required. Depending on the OS-specific implementation | ||
|
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
eclipse.platform.swt/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java
Line 323 in 085c1c6
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.
Ah okay, then please put the 100 in a common local variable to use in both places, so it is not changed independently