View Single Post
Old 24 February 2022, 10:45   #811
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Quote:
Originally Posted by axilmar View Post
Code:
let source_pixel_step = source_width / destination_width
let source_pixel_index = 0
for dst_pixel_index = 0 to destination_width
    let actual_source_pixel_index = round(source_pixel_index)
    destination[dst_pixel_index] = source[actual_source_pixel_index]
    source_pixel_index += source_pixel_step
end for
Once the pixels are produced, then they can be fed to the regular blitter functions, for actual blitting.

It can actually be much simpler than that - at least for scaling up (scaling down is trickier, but also arguably less useful)

Internally almost everything is already built in terms of shift registers - so for example a 16-bit wide word of sprite data arrives from DMA, is latched into a shift register and shifted out one bit at a time.
To make the sprite wider, maintain an internal counter and make the shifting happen only when that counter overflows, instead of on every pixel.
The value added to that counter per pixel would be software-controlled. If that value's at its maximum, the counter overflows every pixel and the sprite is its usual size. If that value is at 50%, the sprite ends up twice the size, and so on.
robinsonb5 is offline  
 
Page generated in 0.04920 seconds with 11 queries