-
Notifications
You must be signed in to change notification settings - Fork 287
fix: ensure filter is also an acceptable size #948
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: main
Are you sure you want to change the base?
Conversation
|
Sorry for the lack of response, I'll try to take a closer look soon. |
|
Thanks! |
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.
Sorry again about the delay. It's a bit hard for me to judge whether it's completely correct as I'm not familiar with that part of the code, but given that Chrome can also render the SVG I believe it should be fine to merge. Just two small comments.
| let s_w = shrunk.width() as f32 / tf_rect.to_int_rect().width() as f32; | ||
| let s_h = shrunk.height() as f32 / tf_rect.to_int_rect().height() as f32; | ||
| transform.pre_scale(s_w, s_h) |
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.
Can't it also happen that the shrunken bbox has a different x/y starting point? In which case we probably also have to apply a translational transform? Or am I missing something?
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 believe that pre_scale will apply the scaling to any translation that follows as well, unless I've misunderstood what you mean. Maybe an extra test could be good 😅
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.
Let's say that the original bbox was top-left: (-30, -30) bottom-right: (120, 120) and is then shrunk to top-left: (0, 0) bottom-right: (75, 75). In this case, you will correctly apply a scale of (0.5, 0.5) to reduce the width from 150 to 75, but you also need to translate by (30, 30) to move the origin to (0, 0), or am I missing something?
Would indeed be good to have a test, but not sure how easy it is to construct one.
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.
Looking at the rendering of firefox and chrome, I can see that the huge region example gaussian blur is much more noticeable than the output, so it is still not 100% correct, I guess, but it doesn't panic at least.
In addition, if i make a new test that shifts the blur to an x and y of 50, the image is sharp on the top left corner and the result is clipped. It is not rendered any differently by resvg though. I think that the primitive transform handling in apply_inner may not be correct, but I'll have to look more into it.
Rendering currently panics for SVGs with extremely large filters, like https://github.com/Davidoc26/wallpaper-selector/blob/main/data/icons/io.github.davidoc26.wallpaper_selector.svg.
I am not terribly familiar with this project, but it seems that while the layer will be shrunk if it is too large, the filters are left unchanged, which eventually causes a source / dest size mismatch and panics when they are asserted to be the same. This change shrinks the filter via the transform as well, if necessary, which resolves the issue when I test it and matches the correct rendering.