-
Notifications
You must be signed in to change notification settings - Fork 187
[Refactoring] Streamline calls to Image#adaptImageDataIfDisabledOrGray() #2795
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
Draft
ShahzaibIbrahim
wants to merge
2
commits into
eclipse-platform:master
Choose a base branch
from
vi-eclipse:master-496-new-tech
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+30
−41
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,8 +172,7 @@ private boolean isReusable(int width, int height) { | |
| private Optional<ImageHandle> createHandleAtExactSize(int width, int height) { | ||
| Optional<ImageData> imageData = imageProvider.loadImageDataAtExactSize(width, height); | ||
| if (imageData.isPresent()) { | ||
| ImageData adaptedData = adaptImageDataIfDisabledOrGray(imageData.get()); | ||
| ImageHandle imageHandle = init(adaptedData, -1); | ||
| ImageHandle imageHandle = init(imageData.get(), -1); | ||
| return Optional.of(imageHandle); | ||
| } | ||
| return Optional.empty(); | ||
|
|
@@ -186,9 +185,8 @@ private ImageHandle getOrCreateImageHandleAtClosestSize(int widthHint, int heigh | |
| int imageZoom = DPIUtil.getZoomForAutoscaleProperty(Math.max(imageZoomForWidth, imageZoomForHeight)); | ||
| ImageHandle bestFittingHandle = zoomLevelToImageHandle.get(imageZoom); | ||
| if (bestFittingHandle == null) { | ||
| ImageData bestFittingImageData = imageProvider.loadImageData(imageZoom).element(); | ||
| ImageData adaptedData = adaptImageDataIfDisabledOrGray(bestFittingImageData); | ||
| bestFittingHandle = init(adaptedData, -1); | ||
| ImageData bestFittingImageData = imageProvider.loadImageDataWithGrayOrDisablement(imageZoom).element(); | ||
| bestFittingHandle = init(bestFittingImageData, -1); | ||
| } | ||
| return bestFittingHandle; | ||
| } | ||
|
|
@@ -333,21 +331,10 @@ public Image(Device device, Image srcImage, int flag) { | |
| } | ||
| break; | ||
| } | ||
| case SWT.IMAGE_DISABLE: { | ||
| for (ImageHandle imageHandle : srcImage.zoomLevelToImageHandle.values()) { | ||
| Rectangle rect = imageHandle.getBounds(); | ||
| ImageData data = srcImage.getImageData(imageHandle.zoom); | ||
| ImageData newData = applyDisableImageData(data, rect.height, rect.width); | ||
| init (newData, imageHandle.zoom); | ||
| } | ||
| break; | ||
| } | ||
| case SWT.IMAGE_DISABLE: | ||
| case SWT.IMAGE_GRAY: { | ||
| for (ImageHandle imageHandle : srcImage.zoomLevelToImageHandle.values()) { | ||
| Rectangle rect = imageHandle.getBounds(); | ||
| ImageData data = srcImage.getImageData(imageHandle.zoom); | ||
| ImageData newData = applyGrayImageData(data, rect.height, rect.width); | ||
| init (newData, imageHandle.zoom); | ||
| srcImage.getImageData(imageHandle.zoom); | ||
| } | ||
| break; | ||
| } | ||
|
|
@@ -698,9 +685,9 @@ public Image(Device device, ImageGcDrawer imageGcDrawer, int width, int height) | |
| init(); | ||
| } | ||
|
|
||
| private ImageData adaptImageDataIfDisabledOrGray(ImageData data) { | ||
| private static ImageData adaptImageDataIfDisabledOrGray(ImageData data, int styleFlag) { | ||
| ImageData returnImageData = null; | ||
| switch (this.styleFlag) { | ||
| switch (styleFlag) { | ||
| case SWT.IMAGE_DISABLE: { | ||
| ImageData newData = applyDisableImageData(data, data.height, data.width); | ||
| returnImageData = newData; | ||
|
|
@@ -726,7 +713,7 @@ void init() { | |
| this.isInitialized = true; | ||
| } | ||
|
|
||
| private ImageData applyDisableImageData(ImageData data, int height, int width) { | ||
| private static ImageData applyDisableImageData(ImageData data, int height, int width) { | ||
| PaletteData palette = data.palette; | ||
| ImageData newData = new ImageData(width, height, 32, new PaletteData(0xFF, 0xFF00, 0xFF0000)); | ||
| newData.alpha = data.alpha; | ||
|
|
@@ -775,7 +762,7 @@ private ImageData applyDisableImageData(ImageData data, int height, int width) { | |
| return newData; | ||
| } | ||
|
|
||
| private ImageData applyGrayImageData(ImageData data, int pHeight, int pWidth) { | ||
| private static ImageData applyGrayImageData(ImageData data, int pHeight, int pWidth) { | ||
| PaletteData palette = data.palette; | ||
| ImageData newData = data; | ||
| if (!palette.isDirect) { | ||
|
|
@@ -1456,7 +1443,7 @@ private static ImageData directToDirect(ImageData src, int newDepth, PaletteData | |
|
|
||
| private record HandleForImageDataContainer(int type, ImageData imageData, long[] handles) {} | ||
|
|
||
| private static HandleForImageDataContainer init(Device device, ImageData i) { | ||
| private static HandleForImageDataContainer init(Device device, ImageData i, int styleFlag) { | ||
| /* Windows does not support 2-bit images. Convert to 4-bit image. */ | ||
| if (i.depth == 2) { | ||
| i = indexToIndex(i, 4); | ||
|
|
@@ -1665,7 +1652,7 @@ private void setImageMetadataForHandle(ImageHandle imageMetadata, int zoom) { | |
|
|
||
| private ImageHandle initIconHandle(Device device, ImageData source, ImageData mask, Integer zoom) { | ||
| ImageData imageData = applyMask(source, mask); | ||
| HandleForImageDataContainer imageDataHandle = init(device, imageData); | ||
| HandleForImageDataContainer imageDataHandle = init(device, imageData, this.styleFlag); | ||
| return initIconHandle(imageDataHandle.handles, zoom); | ||
| } | ||
|
|
||
|
|
@@ -1690,7 +1677,7 @@ private ImageHandle initBitmapHandle(ImageData imageData, long handle, Integer z | |
|
|
||
| static long [] initIcon(Device device, ImageData source, ImageData mask) { | ||
| ImageData imageData = applyMask(source, mask); | ||
| return init(device, imageData).handles; | ||
| return init(device, imageData, SWT.NONE).handles; | ||
| } | ||
|
|
||
| private static ImageData applyMask(ImageData source, ImageData mask) { | ||
|
|
@@ -1770,7 +1757,7 @@ private static ImageData applyMask(ImageData source, ImageData mask) { | |
|
|
||
| private ImageHandle init(ImageData i, int zoom) { | ||
| if (i == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | ||
| HandleForImageDataContainer imageDataHandle = init(device, i); | ||
| HandleForImageDataContainer imageDataHandle = init(device, i, this.styleFlag); | ||
| switch (imageDataHandle.type()) { | ||
| case SWT.ICON: { | ||
| return initIconHandle(imageDataHandle.handles(), zoom); | ||
|
|
@@ -2007,6 +1994,11 @@ public Collection<Integer> getPreservedZoomLevels() { | |
|
|
||
| protected abstract ElementAtZoom<ImageData> loadImageData(int zoom); | ||
|
|
||
| protected ElementAtZoom<ImageData> loadImageDataWithGrayOrDisablement(int zoom) { | ||
| ElementAtZoom<ImageData> imageDataAtZoom = loadImageData(zoom); | ||
| return new ElementAtZoom<>(adaptImageDataIfDisabledOrGray(imageDataAtZoom.element(), styleFlag), imageDataAtZoom.zoom()); | ||
| } | ||
|
|
||
| abstract ImageData newImageData(ZoomContext zoomContext); | ||
|
|
||
| abstract AbstractImageProviderWrapper createCopy(Image image); | ||
|
|
@@ -2119,9 +2111,8 @@ protected ImageHandle newImageHandle(ZoomContext zoomContext) { | |
| } | ||
|
|
||
| private ImageHandle initializeHandleFromSource(ZoomContext zoomContext) { | ||
| ElementAtZoom<ImageData> imageDataAtZoom = loadImageData(zoomContext.targetZoom()); | ||
| ElementAtZoom<ImageData> imageDataAtZoom = loadImageDataWithGrayOrDisablement(zoomContext.targetZoom()); | ||
| ImageData imageData = DPIUtil.scaleImageData(device, imageDataAtZoom.element(), zoomContext.targetZoom(), imageDataAtZoom.zoom()); | ||
| imageData = adaptImageDataIfDisabledOrGray(imageData); | ||
| return newImageHandle(imageData, zoomContext); | ||
| } | ||
| } | ||
|
|
@@ -2271,21 +2262,20 @@ protected Rectangle getBounds(int zoom) { | |
|
|
||
| @Override | ||
| ImageData newImageData(ZoomContext zoomContext) { | ||
| int targetZoom = zoomContext.targetZoom(); | ||
| return loadImageDataWithGrayOrDisablement(zoomContext.targetZoom()).element(); | ||
| } | ||
|
|
||
| @Override | ||
| protected ElementAtZoom<ImageData> loadImageData(int targetZoom) { | ||
| if (zoomLevelToImageHandle.isEmpty()) { | ||
| return createBaseHandle(targetZoom).getImageData(); | ||
| return new ElementAtZoom<> (createBaseHandle(targetZoom).getImageData(), targetZoom); | ||
| } | ||
| // if a GC is initialized with an Image (memGC != null), the image data must not be resized, because it would | ||
| // be a destructive operation. Therefor, a new handle is created for the requested zoom | ||
| if (memGC != null) { | ||
| return newImageHandle(zoomContext).getImageData(); | ||
| return new ElementAtZoom<> (newImageHandle(new ZoomContext(targetZoom)).getImageData(), targetZoom); | ||
| } | ||
| return getScaledImageData(targetZoom); | ||
| } | ||
|
|
||
| @Override | ||
| protected ElementAtZoom<ImageData> loadImageData(int zoom) { | ||
| return getClosestAvailableImageData(zoom); | ||
| return new ElementAtZoom<> (getScaledImageData(targetZoom), targetZoom); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -2413,9 +2403,8 @@ protected ImageHandle newImageHandle(ZoomContext zoomContext) { | |
| } | ||
|
|
||
| private ImageHandle initializeHandleFromSource(int zoom) { | ||
| ElementAtZoom<ImageData> imageDataAtZoom = loadImageData(zoom); | ||
| ElementAtZoom<ImageData> imageDataAtZoom = loadImageDataWithGrayOrDisablement(zoom); | ||
| ImageData imageData = DPIUtil.scaleImageData (device, imageDataAtZoom.element(), zoom, imageDataAtZoom.zoom()); | ||
| imageData = adaptImageDataIfDisabledOrGray(imageData); | ||
| return init(imageData, zoom); | ||
| } | ||
|
|
||
|
|
@@ -2736,7 +2725,7 @@ protected long configureGCData(GCData data) { | |
|
|
||
| @Override | ||
| ImageData newImageData(ZoomContext zoomContext) { | ||
| return loadImageData(zoomContext.targetZoom).element(); | ||
| return loadImageDataWithGrayOrDisablement(zoomContext.targetZoom).element(); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -2765,7 +2754,7 @@ protected ImageHandle newImageHandle(ZoomContext zoomContext) { | |
| drawer.drawOn(gc, width, height); | ||
| ImageData imageData = image.getImageData(targetZoom); | ||
| drawer.postProcess(imageData); | ||
| ImageData newData = adaptImageDataIfDisabledOrGray(imageData); | ||
| ImageData newData = adaptImageDataIfDisabledOrGray(imageData, styleFlag); | ||
|
Contributor
Author
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. I still have to keep it because a new image is created here with plainImageDataProvider which loads the data directly from handle. I am open to suggestions here. |
||
| return init(newData, targetZoom); | ||
| } finally { | ||
| gc.dispose(); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Now we only need to reload the data for other handle if exist in order to apply gray or disable image data.