Skip to content

Conversation

@ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Jan 7, 2026

Wrapping the input stream handling in an ImageDataProvider. In case stream data belong to a dynamically sizable image we create a provider with ImageDataAtSizeProvider else we use ImageDataProvider.

  • The ImageDataAtSizeProvider will store the stream data and return accordingly loaded image data in its getImageData(width, height) and getImageData(zoom) methods.
  • The ImageDataProvider will only return according image data at 100% and none for the other zoom, so it does not need to store the stream data.

Contributes to: #2917

How to Test

  • Run the Snippet390 on Windows, Mac and Linux and compare the results
  • Currently, In GTK and Cocoa, an image based on an SVG passed as inputStream to Image(Device, InputStream) was blurry. With the current change it should look as good as ImageFileNameProvider as shown in snippet.

Results

Without this PR:
image


After Changes:

GTK:

image

Cocoa:

image

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

Test Results

  176 files  ±0    176 suites  ±0   28m 59s ⏱️ + 2m 36s
4 676 tests ±0  4 654 ✅ ±0  22 💤 ±0  0 ❌ ±0 
  482 runs  ±0    476 ✅ ±0   6 💤 ±0  0 ❌ ±0 

Results for commit 4df8b13. ± Comparison against base commit 9a91cae.

♻️ This comment has been updated with latest results.

@laeubi
Copy link
Contributor

laeubi commented Jan 7, 2026

@ShahzaibIbrahim please provide a consistent PR description and at best show before/after screenshot.
Also commit descriptions seem not sufficient.

@ShahzaibIbrahim
Copy link
Contributor Author

@ShahzaibIbrahim please provide a consistent PR description and at best show before/after screenshot. Also commit descriptions seem not sufficient.

Hi @laeubi, This PR is not ready and hence it's currently drafted.

@laeubi
Copy link
Contributor

laeubi commented Jan 7, 2026

@ShahzaibIbrahim please provide a consistent PR description and at best show before/after screenshot. Also commit descriptions seem not sufficient.

Hi @laeubi, This PR is not ready and hence it's currently drafted.

I appreciate that it's marked as a draft, but even draft PRs should contain a clear title and meaningful description explaining what you're working on and what the expected outcome is. This helps maintainers understand the context and provide better guidance early in the process.

The SWT repository should have draft PRs that clearly communicate:

  • What issue or improvement you're addressing
  • What approach you're taking
  • What the current state is and what still needs to be done

If you need to run CI checks while developing, you can do that on your fork as well. Please update the PR description before continuing, so we can provide better feedback. Thanks!

@ShahzaibIbrahim ShahzaibIbrahim changed the title SVG Sharp Renderring Sharp rendering of SVGs passed as InputStream Jan 7, 2026
@ShahzaibIbrahim
Copy link
Contributor Author

ShahzaibIbrahim commented Jan 7, 2026

I appreciate that it's marked as a draft, but even draft PRs should contain a clear title and meaningful description explaining what you're working on and what the expected outcome is. This helps maintainers understand the context and provide better guidance early in the process.

The SWT repository should have draft PRs that clearly communicate:

  • What issue or improvement you're addressing
  • What approach you're taking
  • What the current state is and what still needs to be done

I have updated the PR description with all the sufficient information I currently have.

@Phillipus
Copy link
Contributor

Some early feedback on Mac for this one...

Here's a screenshot running this Snippet of the changes in this PR and #2924

Screenshot 2026-01-07 at 14 14 49

@ShahzaibIbrahim Thank-you for your work on this and #2924

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the master-567 branch 2 times, most recently from 25abe2b to e4cd2a2 Compare January 8, 2026 12:55
@ShahzaibIbrahim
Copy link
Contributor Author

@HeikoKlare I think tests are fixed. Can you please test my snippet on multiple zoom level on mac to mark this PR ready for review?

@Phillipus
Copy link
Contributor

Mac with latest changes:

Screenshot 2026-01-09 at 17 08 25

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.

Following up on the comment of @laeubi, wouldn't it be cleaner to wrap the input stream handling in an ImageDataProvider to not further mess up the Image implementation with mutual exclusive providers?
It might work as follows (starting from the InputStream constructor):

  • Read stream data from stream
  • Check if stream data belong to a dynamically sizable image, in that case create an ImageDataAtSizeProvider otherwise create an ImageDataProvider.
    • The ImageDataAtSizeProvider will store the stream data and return accordingly loaded image data in its getImageData(width, height) and getImageData(zoom) methods
    • The ImageDataProvider will only return according image data at 100% and none for the other zoom, so it does not need to store the stream data

Nothing needs to be changed for the loadImageDataAtExactSize then, as it reuses the ImageDataAtSizeProvider functionality.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 12, 2026

Test Results (linux)

   88 files  ±0     88 suites  ±0   14m 18s ⏱️ -15s
4 562 tests ±0  4 342 ✅ ±0  220 💤 ±0  0 ❌ ±0 
  211 runs  ±0    208 ✅ ±0    3 💤 ±0  0 ❌ ±0 

Results for commit 8e281f9. ± Comparison against base commit 8afb3c5.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 12, 2026

Test Results (macos)

   54 files  ±0     54 suites  ±0   6m 18s ⏱️ - 1m 14s
4 518 tests ±0  4 275 ✅ ±0  243 💤 ±0  0 ❌ ±0 
  104 runs  ±0    104 ✅ ±0    0 💤 ±0  0 ❌ ±0 

Results for commit 8e281f9. ± Comparison against base commit 8afb3c5.

♻️ This comment has been updated with latest results.

@ShahzaibIbrahim
Copy link
Contributor Author

Following up on the comment of @laeubi, wouldn't it be cleaner to wrap the input stream handling in an ImageDataProvider to not further mess up the Image implementation with mutual exclusive providers? It might work as follows (starting from the InputStream constructor):

  • Read stream data from stream

  • Check if stream data belong to a dynamically sizable image, in that case create an ImageDataAtSizeProvider otherwise create an ImageDataProvider.

    • The ImageDataAtSizeProvider will store the stream data and return accordingly loaded image data in its getImageData(width, height) and getImageData(zoom) methods
    • The ImageDataProvider will only return according image data at 100% and none for the other zoom, so it does not need to store the stream data

Nothing needs to be changed for the loadImageDataAtExactSize then, as it reuses the ImageDataAtSizeProvider functionality.

I have adapted the changes as per your recommendation. It looks good in GTK but some tests are failing in cocoa but I can't figure why. Can you please test for me in mac? @HeikoKlare

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.

I have adapted the changes as per your recommendation. It looks good in GTK but some tests are failing in cocoa but I can't figure why. Can you please test for me in mac?

This change uncovered a bug in the image copy implementation for MacOS. I have created a PR to fix it:

When rebasing your PR on top of that fix, the tests should succeed. Meanwhile, I left some comments for further improvement of the PR.

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the master-567 branch 3 times, most recently from b3701bb to f7b36dc Compare January 13, 2026 12:01
@ShahzaibIbrahim ShahzaibIbrahim marked this pull request as ready for review January 13, 2026 12:02
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.

I tested on MacOS again and it works like expected. Code is also fine now.

Wrapping the input stream handling in an ImageDataProvider. In case
stream data belong to a dynamically sizable image we create a provider
with ImageDataAtSizeProvider else we use ImageDataProvider.

- The ImageDataAtSizeProvider will store the stream data and return
accordingly loaded image data in its getImageData(width, height) and
getImageData(zoom) methods.
- The ImageDataProvider will only return according image data at 100%
and none for the other zoom, so it does not need to store the stream
data.

Contributes to:
eclipse-platform#2917
@HeikoKlare HeikoKlare merged commit 6d69470 into eclipse-platform:master Jan 14, 2026
28 of 29 checks passed
@HeikoKlare HeikoKlare deleted the master-567 branch January 14, 2026 16:45
private static ImageDataProvider createImageDataProvider(InputStream stream) throws IOException {
byte[] streamData = stream.readAllBytes();
if (ImageDataLoader.isDynamicallySizable(new ByteArrayInputStream(streamData))) {
ImageDataAtSizeProvider imageDataAtSizeProvider = (width, height) -> ImageDataLoader
Copy link
Contributor

@ptziegler ptziegler Jan 26, 2026

Choose a reason for hiding this comment

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

This doesn't work when loading the ImageData of an Image by zoom. Because the getDefaultSize() method is not overridden, a 1x1 ImageData is returned at 100% zoom, otherwise null.

default ImageData getImageData(int zoom) {
Point defaultSize = getDefaultSize();
if (new Point(-1, -1).equals(defaultSize)) {
if (zoom == 100) {
return new ImageData(1, 1, 32, new PaletteData(0xFF0000, 0xFF00, 0xFF));
}
return null;
}
return getImageData(DPIUtil.pointToPixel(defaultSize.x, zoom), DPIUtil.pointToPixel(defaultSize.y, zoom));
}

Copy link
Contributor

@HeikoKlare HeikoKlare Jan 26, 2026

Choose a reason for hiding this comment

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

Damn, I even though about that case when reviewing the PR and somehow didn't follow-up on it. Too bad that there was not even a test for it. Thank you for fixing that with #3012!

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.

Sharp rendering of SVGs passed as InputStream to Image constructor when drawing at arbitrary size

5 participants