Skip to content
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

Feature request: Mask union #76

Open
Pr0methean opened this issue Apr 25, 2023 · 6 comments
Open

Feature request: Mask union #76

Pr0methean opened this issue Apr 25, 2023 · 6 comments

Comments

@Pr0methean
Copy link

Pr0methean commented Apr 25, 2023

I have an app where I load layers from SVGs, repaint them various colors, stack them, and output the results as PNGs. To minimize the memory consumed by intermediate results, I always union together masks that are being painted the same color for the same output PNG, unless I need to avoid doing so for Z-order reasons. Thus, being able to take the union of two masks via a tiny-skia routine rather than a loop I had to write myself, would be very useful.

As well, I could get by with fewer SVGs given subtraction and XOR operations on masks.

@RazrFalcon
Copy link
Collaborator

Yes, the Mask API is very primitive right now. Will add more operations.

@Pr0methean
Copy link
Author

Another useful operation would be to multiply all pixels in an alpha mask by a fraction.

@RazrFalcon
Copy link
Collaborator

Can you explain the use case? And it would be easier to implement on your side via data_mut. I don't think SIMD would help here much.

@Pr0methean
Copy link
Author

The use case would involve merging consecutive layers that have the same color but different opacity, so that the layers can be masks rather than pixmaps until they've been combined.

Also, would SIMD help at all in stacking two masks where one has the same alpha for the whole image? I'd use this to make stained-glass window textures (where the background is the same color as the frame but 75% transparent).

@Pr0methean
Copy link
Author

Pr0methean commented Apr 25, 2023

And is there any chance that once from_pixmap is optimized, a version can be provided that would replace the contents of a mutably-borrowed Mask rather than create a new one? I'd use that with an object pool.

@RazrFalcon
Copy link
Collaborator

Will take a look.

a version can be provided that would replace the contents of a mutably-borrowed Mask rather than create a new one?

You mean something like Pixmap::to_mask(&self, mask_type: MaskType, mask: &mut Mask)?
Yes, reducing allocations the goal.

The current tiny-skia API is incredibly bare-bone, mainly because it contains only stuff I use in resvg. So any suggestions are welcome, as long as I have time implementing them.

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

No branches or pull requests

2 participants