-
Notifications
You must be signed in to change notification settings - Fork 162
Move ImageData Scaling Impl to Image for all platforms #1933
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
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 |
---|---|---|
|
@@ -1408,7 +1408,39 @@ public ImageData getImageData(int zoom) { | |
} finally { | ||
if (pool != null) pool.release(); | ||
} | ||
return DPIUtil.scaleImageData (device, getImageData(100), zoom, 100); | ||
ImageData imageData = getImageData(100); | ||
return scaledTo (imageData, zoom, 100, DPIUtil.getScalingType(imageData)); | ||
} | ||
|
||
private ImageData scaledTo(ImageData imageData, int targetZoom, int currentZoom, int scaleType) { | ||
if (imageData == null || currentZoom == targetZoom || !device.isAutoScalable()) { | ||
return imageData; | ||
} | ||
float scaleFactor = (float) targetZoom / (float) currentZoom; | ||
int scaledWidth = Math.round (imageData.width * scaleFactor); | ||
int scaledHeight = Math.round (imageData.height * scaleFactor); | ||
switch (scaleType) { | ||
case SWT.SMOOTH: | ||
return scaleUsingSmoothScaling(imageData, scaledWidth, scaledHeight); | ||
default: | ||
return imageData.scaledTo(scaledWidth, scaledHeight); | ||
} | ||
} | ||
|
||
private ImageData scaleUsingSmoothScaling(ImageData imageData, int width, int height) { | ||
Image original = new Image (device, (ImageDataProvider) zoom -> imageData); | ||
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 do we create a new image here and not using 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. Wouldn't that create an endless loop? When you try to create image data at a specific zoom by painting the image into a GC, which requires requesting the image data at that specific zoom, this will likely produce a stack overflow. 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. The idea was that at the Image level we can access any internal API as required (including a painting the current |
||
/* Create a 24 bit image data with alpha channel */ | ||
final ImageData resultData = new ImageData (width, height, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000)); | ||
resultData.alphaData = new byte [width * height]; | ||
Image resultImage = new Image (device, (ImageDataProvider) zoom -> resultData); | ||
GC gc = new GC (resultImage); | ||
gc.setAntialias (SWT.ON); | ||
gc.drawImage (original, 0, 0, imageData.width, imageData.height, 0, 0, width, height, false); | ||
gc.dispose (); | ||
original.dispose (); | ||
ImageData result = resultImage.getImageData (DPIUtil.getDeviceZoom()); | ||
resultImage.dispose (); | ||
return result; | ||
} | ||
|
||
/** Returns the best available representation. May be 100% or 200% iff there is an image 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.
so the caller can operate on the Image (dispose it or use it or ...) also current zoom seems always
100
, the image data can also better be fetched by the method itselfThere 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 always being 100 is a specifics of the MacOS implementation. Independent from that making a
scaledTo
method return anImage
would not really make sense, as there is no image being scaled (from which you could retrieve the data scaled according to different zooms again), but the data itself is scaled.