Skip to content

Conversation

@ShahzaibIbrahim
Copy link
Contributor

@ShahzaibIbrahim ShahzaibIbrahim commented Jan 7, 2026

Storing input stream content to be later used for executeOnImageHandleAtBestFittingSize() to sharply render the svg images when created using Image(Display, InputStream)

In addition, on Linux an image can be refreshed for a new zoom (Image#refreshImageForZoom()), which was also not supported for the case that the image is based on an InputStream. Since we are storing the input stream content anyway, this case is should be covered here too.

Contribute to: #2917

How to Test

  • Run this Snippet on Windows, Mac and Linux and compare the results:
package org.eclipse.swt.snippets;
import java.nio.file.Path;

import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class SVGImageTests {

    public static void main(String[] args) throws Exception {
        final Display display = new Display();

        final Shell shell = new Shell(display);
        shell.setText("SVG Image Test");
        shell.setLayout(new FillLayout());
        shell.setBounds(250, 50, 1000, 400);
        shell.setBackground(new Color(255, 255, 255));

        String imgPath = "eclipse16.svg";
        Path fullPath = Path.of(SVGImageTests.class.getResource(imgPath).toURI());

        // Image loaded in stream
        Image image1 = new Image(display, SVGImageTests.class.getResourceAsStream(imgPath));

        // Image loaded in ImageFileNameProvider
        Image image3 = new Image(display, (ImageFileNameProvider) zoom -> {
            return zoom == 100 ? fullPath.toString() : null;
        });

        shell.addPaintListener(e -> {
            e.gc.drawImage(image1, 20, 10, 300, 300);
            e.gc.drawText("Image(Display, InputStream)", 80, 300);

            e.gc.drawImage(image3, 340, 10, 300, 300);
            e.gc.drawText("Image(Display, String)", 420, 300);
        });

        shell.open();

        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) {
                display.sleep();
            }
        }

        display.dispose();
    }
}

Use this SVG image for the Snippet:

eclipse16
  • 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:

To be Tested

@github-actions
Copy link
Contributor

github-actions bot commented Jan 7, 2026

Test Results

  176 files  ±0    176 suites  ±0   26m 57s ⏱️ - 2m 13s
4 676 tests ±0  4 654 ✅ ±0  22 💤 ±0  0 ❌ ±0 
  482 runs  ±0    476 ✅ ±0   6 💤 ±0  0 ❌ ±0 

Results for commit 4cdd05f. ± Comparison against base commit bbb21e5.

♻️ 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.

/**
* Byte array to store input stream data to draw on various Zoom levels
*/
private byte[] inputStreamData;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this not better be part of a supplier instead of part of the image?

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 need o make it part of Image class because I have to use it in private class CachedImageAtSize#loadImageDataAtExactSize not just in initWithSupplier. Or do you mean something else?

@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?

Storing input stream content to be later used for executeOnImageHandleAtBestFittingSize() to sharply render the svg images when created using Image(Display, InputStream)
@Phillipus
Copy link
Contributor

Mac with latest changes:

Screenshot 2026-01-09 at 17 08 25

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

3 participants