Skip to content

Conversation

@ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Nov 19, 2025

Enabling a consistent pattern to apply disablement or graying of an Image. They are applied whenever a handle is being created from init method. Ensuring streamline usage and avoid double calls to this method.


How to test

  • Run the Snippet382 with following VM Argument: swt.autoScale.updateOnRuntime=true
  • Move the shell between different zoom levels (100,125,150,175,200,250)
  • The snippet tests different kind of image providers to create an Image.
  • Expected result would be that we don't lose disabled or grayed image attributes.
image

This adaption is made on the basis of this comment: #2737 (comment)

Instead of calling the adaptImageDataIfDisabledOrGray method from init method (which could be executed even when temporary handle is created) we will now call it only when data is loaded for the first time. So instead of calling loadImageData, all providers must call loadImageDataWithGrayOrDisablement and also provide loadImageData implementation of its own. In this way we can achieve one common place to call adaptImageDataIfDisabledOrGray from.

@ShahzaibIbrahim ShahzaibIbrahim marked this pull request as draft November 19, 2025 13:27
Enabling a consistent pattern to apply disablement or graying of an
Image. They are applied whenever a handle is being created from init
method. Ensuring streamline usage and avoid double calls to this method.
Comment on lines +334 to 338
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);
}
Copy link
Contributor Author

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.

ImageData imageData = image.getImageData(targetZoom);
drawer.postProcess(imageData);
ImageData newData = adaptImageDataIfDisabledOrGray(imageData);
ImageData newData = adaptImageDataIfDisabledOrGray(imageData, styleFlag);
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@ShahzaibIbrahim
Copy link
Contributor Author

@akoch-yatta @HeikoKlare Please review the PR and comments, It might not be in final shape but here I could use some suggestions.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 19, 2025

Test Results

  111 files  ±0    111 suites  ±0   17m 48s ⏱️ +7s
4 597 tests ±0  4 582 ✅ +1  14 💤  - 1  1 ❌ ±0 
  282 runs  ±0    281 ✅ ±0   1 💤 ±0  0 ❌ ±0 

For more details on these failures, see this check.

Results for commit eb0405c. ± Comparison against base commit 63d5582.

♻️ This comment has been updated with latest results.

@ShahzaibIbrahim
Copy link
Contributor Author

@akoch-yatta can you please have a look/review if you got time?

Copy link
Contributor

@HeikoKlare HeikoKlare left a comment

Choose a reason for hiding this comment

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

Can you please explain the underlying pattern where the application of gray/disablement is supposed to be done now? The PR description states:

In this way we can achieve one common place to call adaptImageDataIfDisabledOrGray from.

But I see calls of that method from at least:

  • initializeHandleFromSource
  • newImageData
  • getOrCreateImageHandleAtClosestSize

To assess if this is a good concept/systematics where to apply gray/disablement, it would be helpful to have a description of that concept.

In addition to that, the PR seems to contain unnecessary changes (e.g., addition of unused parameters, duplicate application of adaptImageDataIfDisabledOrGray) and also seems to remove crucial code (handle initialization in copy constructor).

if (imageData.isPresent()) {
ImageData adaptedData = adaptImageDataIfDisabledOrGray(imageData.get());
ImageHandle imageHandle = init(adaptedData, -1);
ImageHandle imageHandle = init(imageData.get(), -1);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we apply gray/disablement here anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because data will already be loaded with disablement/gray properties.

ImageData data = srcImage.getImageData(imageHandle.zoom);
ImageData newData = applyGrayImageData(data, rect.height, rect.width);
init (newData, imageHandle.zoom);
srcImage.getImageData(imageHandle.zoom);
Copy link
Contributor

Choose a reason for hiding this comment

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

Wny do we remove the gray/disabled adaptation and, especially, the init call here? Won't this lead to the new image not being initalized with appropriate handles anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the logic to apply gray/disablement is moved to whenever image data is loaded, we don't need to apply adaptions here (also the init method).

Copy link
Contributor

Choose a reason for hiding this comment

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

This is an image constructor, which copied/adapts the handles of the original image. Not doing that will leave the new image empty. How should that work, e.g., in case you have an image based on an existing handle? The new Image instance with GRAY/DISABLED flag would simply be empty.

Comment on lines +2265 to +2278
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this semantics change of the methods necessary? In case of a PlainImageProviderWrapper there is no need to apply any gray/disabled if we just create an empty handle. And if we rescale an existing handle, that one should already have gray/disablement applied.

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.

Streamline calls to Image#adaptImageDataIfDisabledOrGray()

2 participants