GP32 Anamorphic Sprite Scaling For Mirkosdk


synkro

0xdeadbeef
Joined
Aug 26, 2003
Messages
823
Location
Germany
Website
Visit site
hi there! Here is my code have look/try and feel free to use ti or add it to your SDK ;) .. there is a minor bug, some pixels are on the wrong positions, I dunno why ... :(


Code:
/*
 * Anamorphic Sprite Scaling for MirkoSDK
 *
 * Scales and draws a sprite with header, transparency
 *
 * u16*   sprite      sprite data with header
 * short  put_x       [0-319] x-pos on screen
 * short  put_y       [0-239] y-pos on screen
 * short  size_x      [0-...] desired width in pixel
 * short  size_y      [0-...] desired height in pixel
 * u16*   buffer      sprite destination
 * u16    trans       transparent color, 16bit
 *
 * synkro 30.09.2004 23:52:32
 */
void gp_scaleSpriteH(u16 *sprite, short put_x, short put_y, short size_x, short size_y, u16* buffer)
{
  SHEADER* sheader;
  sheader = (SHEADER*) sprite;
  short src_x_size = sheader->size_x;
  short src_y_size = sheader->size_y;
  u16 color;
  int sx, sy, dy, dx;
  int temp_x, temp_y;

  for(dy=0; dy<size_y; dy++)
  {
    sy = ((dy*src_y_size) / size_y);
    for(dx==; dx<size_x; dx++)
    {
      sx = ((dx*src_x_size) / size_x);
      color = sprite[(sx*src_x_size)+sy];
      temp_x = dx + put_x;
      temp_y = dy + put_y;
      if( !((temp_x<0) || (temp_x>319) || (temp_y<0) || (temp_y>239)) )
        *(buffer +(239-temp_x)+(240*temp_y)) = color;
    }
  }
}

void gp_scaleSpriteHT(u16 *sprite, short put_x, short put_y, short size_x, short size_y, u16* buffer, u16 trans)
{
  SHEADER* sheader;
  sheader = (SHEADER*) sprite;
  short src_x_size = sheader->size_x;
  short src_y_size = sheader->size_y;
  u16 color;
  int sx, sy, dy, dx;
  int temp_x, temp_y;

  for(dy=0; dy<size_y; dy++)
  {
    sy = ((dy*src_y_size) / size_y);
    for(dx=0; dx<size_x; dx++)
    {
      sx = ((dx*src_x_size) / size_x);
      color = sprite[(sx*src_x_size)+sy];
      temp_x = dx + put_x;
      temp_y = dy + put_y;
      if( !((temp_x<0) || (temp_x>319) || (temp_y<0) || (temp_y>239) || (color==trans)) )
        *(buffer +(239-temp_x)+(240*temp_y)) = color;
    }
  }
}
 
Back
Top