I managed to write the correct output file headers, but when I went to actually implementing the resize logic, things got a bit complicated.

I can pretty much understand factors of resize bigger than 1,but there is absolutely no way I can find out a way to implement the logic behind less than one factors.

I feel like there is no way to do the task precisely since there is too much about finding the "right" pixels to not replicate on the new image.

I tried watching Computerphile bilinear/bicubic interpolation video but there is something else they seem to be missing.

I would appreciate very much if someone could clarify how this pixel information loss could be handled from a logic point of view, if that make sense.

Thanks in advance!

1 Answer 1


The most basic version is copying/dropping pixels.

This could be like

diff = input_height/2
repeat input_height times
    diff += output_height
    read input line
    skip input padding
    while diff >= input_height
        diff -= input_height
        write horizontally resized line
        write output padding

which covers up- and downsize. Upsize means inner loop will trigger multiple times, downsize means inner loop will run once every few input lines.

Most important is to use the factor once in determining the new image's size, and then work with the image dimensions, not the factor. That way, you avoid rounding in different directions and resulting inconsistencies.

Another way is calculating the corresponding input pixel, fseeking to that position, and copying.

But yeah, more sophisticated methods resize without dropping any pixels.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .