-
Notifications
You must be signed in to change notification settings - Fork 171
Remove duplicate representation of alpha values in image data from SVG #2254
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
base: master
Are you sure you want to change the base?
Remove duplicate representation of alpha values in image data from SVG #2254
Conversation
7473374
to
67ce839
Compare
The image data generated for a rasterized SVG currently uses a 32 bit data array and an alpha values array. The alpha values for every pixel are stored in both the alpha values array as well as the alpha channel of the 32 bit data array. This is a redundant representation not giving any benefits but just leading to unnecessary memory consumption. This change adapts the SVG rasterization to create image data with a 24 bit data array, such that the alpha values are only stored in the alpha array.
67ce839
to
04918a4
Compare
This pull request changes some projects for the first time in this development cycle.
Git patch
Further information are available in Common Build Issues - Missing version increments. |
@HannesWell since you were deeply involved in the development of the SVG feature, maybe you want to have a look at this? |
Unfortunately I'm not familiar with these details either, but I wonder why there is a separated array for alpha values in the first place, if they can be represented in 32bit arrays? |
It all depends on the color model. Even though RGBA is quite common one can have any other kind of encoding e.g. with 4bits/color (what would only need 2 bytes) and one alpha channel. But one can of course also use model with higher resolution (even floats). Such an Alpha mask could even be 1 bit only that is common for old formats like GIF files (but of course gives not quite smooth results). |
Strike that.. SWT uses a byte array here. |
The image data generated for a rasterized SVG currently uses a 32 bit data array and an alpha values array. The alpha values for every pixel are stored in both the alpha values array as well as the alpha channel of the 32 bit data array. This is a redundant representation not giving any benefits but just leading to unnecessary memory consumption.
This change adapts the SVG rasterization to create image data with a 24 bit data array, such that the alpha values are only stored in the alpha array.
This was detected via and would also resolve:
I have to admit that I am not completely sure when a 32 bit data array can/must be used together with an alpha data array, thus having duplicate representation of alpha data. When searching in platform code, I see several places creating a 24bit data array and an additional alpha array, but I see about the same number of places that create a 32bit data array and an additional alpha array. I guess there is some difference depending on whether the RGB values encode the alpha values as well (I have seen something like in disabled image generation on Linux/GTK), but if that's not the case I am not sure whether or when one or the other option is useful or even necessary.
If possible, I would be in favor of having a redundancy-free representation of data, which is why I think the proposed change is reasonable. Even more considering that it will fix the mentioned issue.
So far, I have tested this change on macOS and Windows and did not find any issues.
It needs to be tested on Linux as well to ensure that there is no different in how the Linux implementation ofImage
treats such data.I've also tested the proposal on Linux and did not find any issues with the loaded SVGs.
I would assume that whether this works or not does not depend on the usage context but as long as we see that the alpha value handling of the loaded image data works in general, it will work everywhere since after loading the image data it is usually transformed into an image with an according OS handle to which the data is transformed.