Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How blitting works
#1
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 */
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;
    width--;
  }
}

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


Messages In This Thread
How blitting works - by vonhoff - 02-22-2024, 06:28 AM
RE: How blitting works - by megamarc - 02-23-2024, 04:57 PM
RE: How blitting works - by vonhoff - 02-23-2024, 06:40 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)