![]() |
How blitting works - Printable Version +- Tilengine - The 2D retro graphics engine forum (http://tilengine.org/forum) +-- Forum: English forums (http://tilengine.org/forum/forumdisplay.php?fid=3) +--- Forum: Support (http://tilengine.org/forum/forumdisplay.php?fid=7) +--- Thread: How blitting works (/showthread.php?tid=2303) |
How blitting works - vonhoff - 02-22-2024 Hi Marc, I'm currently learning about blitting in graphics programming and I'm trying to understand how scaling works. How does it work in Tilengine? The scaling I'm interested in is in the following snippet from Blitters.c Code: /* paints scanline without checking color key (always solid) with scaling */ I wonder why the offset is divided by (1 << 16) or 65536. Thanks! Edit: As I understand it, the reason for dividing the offset by (1 << 16) is to convert it from a fixed-point representation to an integer index in the palette array. And the fixed-point representation is used to allow for fractional increments of offset, which is necessary for smooth scaling. Is that correct? RE: How blitting works - megamarc - 02-23-2024 Hi! That's the reason, it's fixed point math. On low-end hardware, integer math is much faster than floating point. So the fractional accumulation is done in 16.16 fixed point, that is 16 bits for integer part, and another 16 bits for decimal part. However I'll check it, as I would rather write "(offset >> FIXED_BITS)" than "offset / (1 << FIXED_BITS)". This piece of code is quite old and I may be missing something right now RE: How blitting works - vonhoff - 02-23-2024 Thanks! |