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

lanczos3: Inline uv -> source pixel coord calculation and drop inv_src_size #30

Merged
merged 1 commit into from
Aug 25, 2023

Conversation

MarijnS95
Copy link
Member

Recreating #29 because GitHub deleted the wrong branch, and even after restoring it the PR cannot be opened because "the branch has been deleted". Pfff.

By inlining this function it becomes clear that we're once again unnecessarily converting between uniform and pixel space. We only need the size of the source image to convert from uv to pixel coordinates, as the kernel after that is just integer additions in whole pixels. No need to first convert the kernel x/y index to uv space wrt the inverse of the source image size, only to immediately convert it back to "whole" pixels (rounding issues left aside!) again.

Finally, remove the unnecessary 0.5 offset that comes out of this, as the uv coordinate is already centered on the target image and adding yet another centering for the destination image only puts the kernel more to the bottom-right of the desired pixel, giving it the wrong values. It is already indecisive what should happen when e.g. a 2x downsampling is happening, where the midpoint of a target pixel ends up at exactly the corner of four pixels: this should sample an even amount of pixels, while we now "sample" an uneven 7x7 kernel (but disregard the last row/column because the weight becomes 0...).

…rc_size`

By inlining this function it becomes clear that we're once again
unnecessarily converting between uniform and pixel space.  We only need
the size of the source image to convert from `uv` to pixel coordinates,
as the kernel after that is just integer additions in whole pixels.  No
need to first convert the kernel `x`/`y` index to `uv` space wrt the
inverse of the source image size, only to immediately convert it back to
"whole" pixels (rounding issues left aside!) again.

Finally, remove the unnecessary `0.5` offset that comes out of this, as
the `uv` coordinate is already centered on the target image and adding
yet another centering for the destination image only puts the kernel
more to the bottom-right of the desired pixel, giving it the wrong
values.  It is already indecisive what should happen when e.g. a 2x
downsampling is happening, where the midpoint of a target pixel ends up
at exactly the corner of four pixels: this should sample an even amount
of pixels, while we now "sample" an uneven 7x7 kernel (but disregard the
last row/column because the weight becomes `0`...).
@MarijnS95 MarijnS95 force-pushed the lanczos3-inline-pixel-coord-calculation branch from 2b3f4c4 to 99fc217 Compare August 23, 2023 13:52
@Athosvk Athosvk merged commit 7c579d3 into main Aug 25, 2023
10 checks passed
@MarijnS95 MarijnS95 deleted the lanczos3-inline-pixel-coord-calculation branch August 26, 2023 08:08
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.

2 participants