예제 #1
0
/* not to be used outside of here */
void _png_copy_texture(uint8 *buffer, uint16 *temp_tex,
                      uint32 channels, uint32 stride,
                      uint32 mask, uint32 w, uint32 h)
{
  uint32 i,j;
  uint16 *ourbuffer;
  uint8 *pRow;
  
  for(i = 0; i < h; i++)
  {
    pRow = &buffer[i*stride];
    ourbuffer = &temp_tex[i*w];
    
    if (channels == 3)
    {
      if (mask == PNG_NO_ALPHA)
        for(j = 0; j < w; j++)
          ourbuffer[j] = LOAD565(pRow[j*3], pRow[j*3+1], pRow[j*3+2]);
      else if (mask == PNG_MASK_ALPHA)
        for(j = 0; j < w; j++)
          ourbuffer[j] = LOAD1555(pRow[j*3],pRow[j*3+1],pRow[j*3+2],255);
      else if (mask == PNG_FULL_ALPHA)
        for(j = 0; j < w; j++)
          ourbuffer[j] = LOAD4444(pRow[j*3],pRow[j*3+1],pRow[j*3+2],255);
          
    }
    else if (channels == 4)
    {
      if (mask == PNG_NO_ALPHA)
      {
        for(j = 0; j < w; j++)
          ourbuffer[j] = LOAD565(pRow[j*4], pRow[j*4+1], pRow[j*4+2]);
      }
      else if (mask == PNG_MASK_ALPHA)
        for(j = 0; j < w; j++)
          ourbuffer[j] = LOAD1555(pRow[j*4],pRow[j*4+1],pRow[j*4+2],pRow[j*4+3]);
      else if (mask == PNG_FULL_ALPHA)
        for(j = 0; j < w; j++)
          ourbuffer[j] = LOAD4444(pRow[j*4],pRow[j*4+1],pRow[j*4+2],pRow[j*4+3]);
    }
  }
}
예제 #2
0
void
img_copy_texture(uint16 *dest, uint8 *source, uint32 channels, uint32 stride,
                 const IMG_INFO *info, uint32 w, uint32 h)
{
  uint32 i,j;
  uint16 *destRow;
  uint8 *pRow;
  uint8 r,g,b;
  
  for(i = 0; i < h; i++)
  {
    pRow = &source[i*stride];
    destRow = &dest[i*w];
    
    if (channels == 3)
    {
      switch(info->alpha)
        {
        case IMG_ALPHA_NONE:
          for(j = 0; j < w; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*3],0,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*3+1],1,2,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*3+2],2,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*3];
              g = pRow[j*3+1];
              b = pRow[j*3+2];
            }
            destRow[j] = LOAD565(r,g,b);
          }
          break;
        case IMG_ALPHA_MASK:
          for(j = 0; j < w; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*3],0,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*3+1],1,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*3+2],2,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*3];
              g = pRow[j*3+1];
              b = pRow[j*3+2];
            }
            destRow[j] = LOAD1555(r,g,b,255);
          }
          break;
        case IMG_ALPHA_FULL:
          for(j = 0; j < w; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*3],0,4,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*3+1],1,4,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*3+2],2,4,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*3];
              g = pRow[j*3+1];
              b = pRow[j*3+2];
            }
            destRow[j] = LOAD4444(r,g,b,255);
          }
          break;
        case IMG_ALPHA_KEYED:
          for(j = 0; j < w; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*3],0,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*3+1],1,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*3+2],2,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*3];
              g = pRow[j*3+1];
              b = pRow[j*3+2];
            }
            if (info->key == LOAD8888(pRow[j*3],pRow[j*3+1],pRow[j*3+2],0))
              destRow[j] = LOAD1555(r,g,b,0);
            else
              destRow[j] = LOAD1555(r,g,b,255);
          }
      }
    }
    else if (channels == 4)
    {
      switch(info->alpha)
        {
        case IMG_ALPHA_NONE:
          for(j = 0; j < h; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*4],0,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*4+1],1,2,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*4+2],2,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*4];
              g = pRow[j*4+1];
              b = pRow[j*4+2];
            }
            destRow[j] = LOAD565(r, g, b);
          }
          break;
        case IMG_ALPHA_MASK:
          for(j = 0; j < h; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*4],0,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*4+1],1,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*4+2],2,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*4];
              g = pRow[j*4+1];
              b = pRow[j*4+2];
            }
            destRow[j] = LOAD1555(r,g,b,pRow[j*4+3]);
          }
          break;
        case IMG_ALPHA_FULL:
          for(j = 0; j < h; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*4],0,4,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*4+1],1,4,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*4+2],2,4,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*4];
              g = pRow[j*4+1];
              b = pRow[j*4+2];
            }
            destRow[j] = LOAD4444(r,g,b,pRow[j*4+3]);
          }
          break;
        case IMG_ALPHA_KEYED:
          for(j = 0; j < h; j++)
          {
            if (info->dither == IMG_DITHER_JITTER)
            {
              r = jitter(pRow[j*4],0,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              g = jitter(pRow[j*4+1],1,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
              b = jitter(pRow[j*4+2],2,3,info->noise,
                         i%info->dither_height,j%info->dither_width);
            }
            else
            {
              r = pRow[j*4];
              g = pRow[j*4+1];
              b = pRow[j*4+2];
            }
            if (info->key == LOAD8888(pRow[j*4],pRow[j*4+1],pRow[j*4+2],0))
              destRow[j] = LOAD1555(r,g,b,0);
            else
              destRow[j] = LOAD1555(r,g,b,pRow[j*4+3]);
          }
          break;
        }
    }
  }
}