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

Add support for additional image-rendering attributes #833

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

LaurenzV
Copy link
Contributor

Fixes #828

@RazrFalcon
Copy link
Collaborator

RazrFalcon commented Oct 14, 2024

Not sure if we should update docs/svg2-changelog.md, Painting section, as well. Does it classify as SVG 2 feature? No one knows... But I guess so.

We should also update CLI help for resvg/usvg. The --image-rendering flag.

@RazrFalcon
Copy link
Collaborator

Also, aren't pixelated requires integer scaling?
https://developer.mozilla.org/en-US/docs/Web/CSS/image-rendering#pixelated

@LaurenzV
Copy link
Contributor Author

Also, aren't pixelated requires integer scaling?

Looks like it, but tiny-skia doesn't support that, right? I basically just used the closest match we have for each attribute, it's possible that some are not 100% as required by the spec. Should I document that somewhere or?

@RazrFalcon
Copy link
Collaborator

I don't think tiny-skia should support this. This is purely a resvg/usvg task. We have to readjust/reset image size. At least this is my understanding. I haven't looked deep into it.

The only way to "document" it is to create a test that would be failing.

I personally thought the whole point of this feature is pixelated, otherwise you could achieve the same with imageRendering. Or is it purely to support CSS variants?

@LaurenzV
Copy link
Contributor Author

Yes, the main intention was to support the CSS attributes in the first place, so that you don’t end up with bicubic rendering if “pixelated” was requested.

But I will see whether I can figure it out.

@RazrFalcon
Copy link
Collaborator

@LaurenzV can you ping on email? I haven't been able to find your email.

@LaurenzV
Copy link
Contributor Author

Sent you an e-mail with the content "animation-charred-annoying-otter".

@LaurenzV
Copy link
Contributor Author

I think getting pixelated 100% correct is going to be very difficult. I think what we would have to do is

  1. Determine the actual size the image will take up in the resulting image.
  2. Find the best integer that scales to that size. Draw the image to the pixmap with a transform to scale to that size, using "Nearest".
  3. Turn the resulting pixmap into an image.
  4. Proceed as with all other rendering modes, but now we use bilinear rendering for the "final smoothing".

But this is pretty hard because it requires us to change the transform in the parent group of the image that scales the raster image to the intended size.

Would it be okay for you if I simply remark in the source code that pixelated doesn't work completely correctly yet?

@RazrFalcon
Copy link
Collaborator

Yes, we can "skip" pixelated as part of this commit.

As for parent transforms, yes, I'm not sure what is the expected output here. We need a bunch of tests to figure it out.
If the spec expects the image to be pixelated in canvas coordinates and not object coordinates (not transforms) then we're screwed. That would be a serious change.

And I'm not even sure what we're expected to do when rotation and/or skew transforms are present.
Preserving integer scaling in all situation would be hard.

@RazrFalcon
Copy link
Collaborator

Let's add image-rendering to docs/svg2-changelog.md and note that pixelated is partially supported there.

@RazrFalcon RazrFalcon merged commit fc4d020 into linebender:master Oct 15, 2024
3 checks passed
@RazrFalcon
Copy link
Collaborator

Thanks!

@LaurenzV LaurenzV deleted the image-rendering branch October 15, 2024 07:29
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.

Support more values for imageRendering
2 participants