-
Notifications
You must be signed in to change notification settings - Fork 210
Feature Proposal: Rasterization of SVGs at Runtime for Eclipse Icons #2593
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
Conversation
I just pushed the changes I made for/in our yesterdays 1:1 meeting, mainly adapt to the change that |
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/URLImageDescriptor.java
Outdated
Show resolved
Hide resolved
I removed the added SVGs from this PR. Please see the new PR for the SVGs if you want to test this feature. In the meantime I locally changed all PNGs I could find in Platform UI, Platform, JDT UI and SWT for testing the Performance. I had no problems whatsoever when starting Eclipse and it was also quite easy and fast to add the SVGs and change the paths. I did not delete any PNGs in this process but changed ".png" to ".svg" in most places. I will report the performance data soon. |
6084260
to
ced1410
Compare
ced1410
to
27e477f
Compare
bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WorkbenchImages.java
Outdated
Show resolved
Hide resolved
9141d4e
to
9d1a0f1
Compare
9d1a0f1
to
0e4f755
Compare
c759836
to
3dd870e
Compare
3dd870e
to
07b9efe
Compare
726d82b
to
35edccc
Compare
734bccd
to
26f1fe9
Compare
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.
If I am not mistaken, I am afraid that the proposed change is a no-op.
The purpose of the PR is to make the providers capable of processing files that can be used for retrieving images in a different zoom than what is currently provided by patterns for raster graphics files (like @2x
, 32x32
and so on).
However, all used methods just return an element when the requested zoom exactly matches a file according to the above mentioned patterns. This means, the introduced SourceAtZoom
will only contain an element if the zoom of that element fits to the zoom that was passed to the method returning it. So the zoom information in SourceAtZoom is not needed, as it's implicitly given by the contained element not being null anyway.
What really needs to be changed is that when, e.g., requesting image data for a path not following any of the patterns (i.e., currently being treated as a file of 100% zoom) and passing a zoom of, e.g., 175%, it should still be possible to retrieve data in that zoom from that file if the file access itself is capable of processing the zoom (as is available for SVGs). This does currently not happen.
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java
Outdated
Show resolved
Hide resolved
bundles/org.eclipse.jface/src/org/eclipse/jface/resource/FileImageDescriptor.java
Outdated
Show resolved
Hide resolved
Is this only the case for the |
The Consider for example the Lines 134 to 144 in b6af990
The first call will yield |
0243c7b
to
e70b512
Compare
44a43c3
to
ff017e9
Compare
The discussed problems should be fixed by commit 6a23f97. I utilized the new |
df741bc
to
e769db4
Compare
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.
After a reviewing session Michael and I agreed that the the canLoad()
check should not be present for the zoom == 100
case in the ImageFileNameProviders
of both descriptor types as they always have to return the path for exactly the requested file-zoom.
The SWT Image class subsequently then can scale the image, depending on the type of Image (i.e. static vs. dynamically sizeable), while rasterizing it with a matching factor that reflects the relation of target-zoom to file-zoom. That doesn't work for SVGs if the filenameProvider returns the default (100%) file if the zoom is e.g. 150.
The ImageDataProvider
is different as it returns an ImageData
object that represents the image as it will be finally, without any (lossless) post-processing.
So while the ImageDataProvider
returns an exact representation of an image for the requested zoom, the ImageFilenameProvider
returns only a suitable source of an image (i.e. the file) at the requested zoom. But since the latter does not allow to supply any information about the 'native-zoom' of a file, the returned file must exactly match the expectation of the caller, i.e. the specified zoom or otherwise the subsequent rasterization of an SVG will be conducted with the wrong scaling factor. Therefore the ImageFilenameProvider
implementations must not be smart and must just behave as before.
However, all used methods just return an element when the requested zoom exactly matches a file according to the above mentioned patterns. This means, the introduced
SourceAtZoom
will only contain an element if the zoom of that element fits to the zoom that was passed to the method returning it. So the zoom information in SourceAtZoom is not needed, as it's implicitly given by the contained element not being null anyway.
That's actually right and I also checked this and step-by-step removed the SourceAtZoom
and it showed that the passed zoom is actually not needed. At least except for the zoom == 100
case in the FileImgeDescriptor.getStream(int)
method, but that could have been resolved by refactoring the code a bit and adapting it more to the URLImageDescriptor
class.
With that it was possible to avoid the SourceAtZoom
entirely.
Then only changes to load ImageData directly where necessary, which also reflects the findings described above that the ImageFilenameProviders
should be unchanged.
@@ -196,15 +202,16 @@ static String getxPath(String name, int zoom) { | |||
int desiredHeight = Math.round((zoom / 100f) * currentHeight); | |||
String lead = name.substring(0, matcher.start(1)); | |||
String tail = name.substring(matcher.end(2)); | |||
return lead + desiredWidth + "x" + desiredHeight + tail; //$NON-NLS-1$ | |||
String xPath = lead + desiredWidth + "x" + desiredHeight + tail; //$NON-NLS-1$ | |||
return new SourceAtZoom<>(xPath, desiredHeight); |
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.
I think this should have been the specified zoom. E.g. if I pass a path that contains a /16x16/
folder and a zoom of 200
, the resulting desiredHeight/Width
will be 32
and that's not the zoom of the result.
return new SourceAtZoom<>(xPath, desiredHeight); | |
return new SourceAtZoom<>(xPath, zoom); |
Requested changes have been applied.
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.
When the tests pass, I think this is ready for submission.
Thank you for the session @HannesWell. It was really insightful for me. :) |
@HannesWell The tests passed. I also tested it manually again and it works perfectly. Would be great if we can submit. For everyone interested in trying this out: |
Great. Thanks for testing again! Thanks for all your awesome work on this topic! |
See the following PR in Eclipse SWT for a detailed description of the changes.
Fixes eclipse-platform/eclipse.platform.swt#1438.