Logo Search packages:      
Sourcecode: djvulibre version File versions

void GPixmap::blit ( const GBitmap bm,
int  x,
int  y,
const GPixmap color 
)

Blits pixmap color# through transparency mask bm#. Bitmap bm# is positionned at location x#,y# over this color image. The matching color image pixels are then modified by adding the corresponding pixel color in pixmap color#, multiplied by Alpha#, where Alpha# denotes the gray value, in range #[0,1]#, represented by the corresponding pixel of bitmap bm#.

Definition at line 1405 of file GPixmap.cpp.

References GPixel::b, columns(), GBitmap::columns(), GPixel::g, GBitmap::get_grays(), GPixel::r, rows(), GBitmap::rows(), rowsize(), and GBitmap::rowsize().

{
  // Check
  if (!bm) G_THROW( ERR_MSG("GPixmap.null_alpha") );
  if (!color) G_THROW( ERR_MSG("GPixmap.null_color") );
  if (!clipok) compute_clip();
  if (bm->rows()!=color->rows() || bm->columns()!=color->columns())
    G_THROW( ERR_MSG("GPixmap.diff_size") );
  // Compute number of rows and columns
  int xrows = mini(ypos + (int)bm->rows(), nrows) - maxi(0, ypos),
      xcolumns = mini(xpos + (int) bm->columns(), ncolumns) - maxi(0, xpos);
  if(xrows <= 0 || xcolumns <= 0)
    return;
  // Precompute multiplier map
  unsigned int multiplier[256];
  unsigned int maxgray = bm->get_grays() - 1;
  for (unsigned int i=1; i<maxgray ; i++)
    multiplier[i] = 0x10000 * i / maxgray;
  // Cache target color
  // Compute starting point
  const unsigned char *src = (*bm)[0] - mini(0,ypos)*bm->rowsize()-mini(0,xpos);
  const GPixel *src2 = (*color)[0] + maxi(0, ypos)*color->rowsize()+maxi(0, xpos);
  GPixel *dst = (*this)[0] + maxi(0, ypos)*rowsize()+maxi(0, xpos);
  // Loop over rows
  for (int y=0; y<xrows; y++)
    {
      // Loop over columns
      for (int x=0; x<xcolumns; x++)
        {
          unsigned char srcpix = src[x];
          // Perform pixel operation
          if (srcpix > 0)
            {
              if (srcpix >= maxgray)
                {
                  dst[x].b = clip[dst[x].b + src2[x].b];
                  dst[x].g = clip[dst[x].g + src2[x].g];
                  dst[x].r = clip[dst[x].r + src2[x].r];
                }
              else
                {
                  unsigned int level = multiplier[srcpix];
                  dst[x].b = clip[dst[x].b + ((src2[x].b * level) >> 16)];
                  dst[x].g = clip[dst[x].g + ((src2[x].g * level) >> 16)];
                  dst[x].r = clip[dst[x].r + ((src2[x].r * level) >> 16)];
                }
            }
        }
      // Next line
      dst += rowsize();
      src += bm->rowsize();
      src2 += color->rowsize();
    }
}


Generated by  Doxygen 1.6.0   Back to index