Add a second renderer for scaling to non-integer sizes #262
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related issues:
The current state of this PR adds an example which implements a custom renderer for doing two-pass scaling to maintain high quality with the sharpest pixels possible on arbitrary image sizes. I would like to evolve this a bit to pull this custom renderer into the library and make it customizable.
There are a few gotchas to consider:
Pixels
maintains an inverse scaling matrix for translating pointer coordinates to pixel buffer coordinates and back. Using a two-pass renderer needs to be aware of this.A
be the scaling matrix for the first pass andB
be the scaling matrix for the second pass.A-1
(AB)-1
Pixels::render_with()
and ourPixelsContext
would allow referencing both renderers. I now see this is error prone. Not only because the inverse matrix will complicate this, but also because it would be possible to accidentally swap the two passes and end up with a bad result.ScalingRenderer
is recreated every time the pixel buffer is resized. This has been fine up to now, but it complicates things with multiple passes. I think it makes more sense to make the renderer mutable and design a trait that can generically update the renderer when properties like the pixel buffer size changes.For these reasons, I think a better API would be allowing some configuration at the
PixelsBuilder
level to choose whether you want one-pass or two-pass scaling, plus any scaling options. And those options can all follow through to correctly initialize and update the inverse scaling matrix and renderer.It would be nice if
PixelsContext
could own a trait object for the renderer. Instead of owning two separate renderers, it would just own one (and the two-pass renderer would own the first pass). This would make swapping renderers easy in the future and could also allow changing the renderer at runtime (if that's a thing we want to do).This might be YAGNI, but given that we have at least the one issue regarding the border and the fact that it is not at all obvious why the border exists, I think dealing with this head-on is appropriate.