linebender / resvg

An SVG rendering library.
Mozilla Public License 2.0
2.79k stars 225 forks source link

Add support for additional image-rendering attributes #833

Closed LaurenzV closed 1 week ago

LaurenzV commented 1 week ago

Fixes #828

RazrFalcon commented 1 week ago

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 commented 1 week ago

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

LaurenzV commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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

LaurenzV commented 1 week ago

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

LaurenzV commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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

RazrFalcon commented 1 week ago

Thanks!