Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How blitting works
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
/* paints scanline without checking color key (always solid) with scaling */
static void blitFastScaling_8_32 (uint8_t *srcpixel, TLN_Palette palette, void* dstptr, int width, int dx, int offset, uint8_t* blend)
  uint32_t* dstpixel = (uint32_t*)dstptr;
  uint32_t* color = (uint32_t*)palette->data;
  while (width)
    uint32_t src = *(srcpixel + offset/(1 << FIXED_BITS));
    *dstpixel++ = color[src];
    offset += dx;

I wonder why the offset is divided by (1 << 16) or 65536.


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?
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

Forum Jump:

Users browsing this thread: 1 Guest(s)