I have a list of numbers that needs to be interpolated for the purpose of upscaling an image. I am using bilinear interpolation. The boundary must be of "clamp" type. Now consider the a scanline containing
0, 1, 2, 3, 3, 2, 1, 0
If upscaling by a factor of 4, it becomes
0, 0.25, 0.5, 0.75,
1, 1.25, 1.5, 1.75
...
0, 0, 0, 0
Before upscaling, the values are symmetric. After upscaling, the "center of mass" has been shifted to the left. How to correct for the offset?
Interpolation involves mapping input points to output points. In your case you're doing the simplest possible thing, dividing the output coordinate by 4. So output 0 maps to input 0, output 1 maps to input 0.25, etc until output 31 maps to 7.75. But anything past 7.0 gets clipped.
There are two ways to fix this. First is to change the scaling factor so both ends line up, instead of multiplying by 1/4 multiply by 7/31. Second is to line up the middle instead of the ends by adding an offset before multiplying so an equal amount of clipping occurs both left and right.