Traverse-Research / ispc-downsampler

Image downsampler using a Lanczos filter implemented in ISPC
Other
11 stars 1 forks source link

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

Closed MarijnS95 closed 1 year ago

MarijnS95 commented 1 year ago

Depends on #28

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...).