Logo Search packages:      
Sourcecode: djvulibre version File versions

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

Performs alpha blending. This function is similar to first calling {attenuate} with alpha map bm# and then calling {blit} with alpha map bm# and color map color#. Both operations are performed together for efficiency reasons.

Definition at line 1497 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 = src2[x].b;
                  dst[x].g = src2[x].g;
                  dst[x].r = src2[x].r;
                }
              else
                {
                  unsigned int level = multiplier[srcpix];
                  dst[x].b -= (((int)dst[x].b - (int)src2[x].b) * level) >> 16;
                  dst[x].g -= (((int)dst[x].g - (int)src2[x].g) * level) >> 16;
                  dst[x].r -= (((int)dst[x].r - (int)src2[x].r) * level) >> 16;
                }
            }
        }
      // Next line
      dst += rowsize();
      src += bm->rowsize();
      src2 += color->rowsize();
    }
}


Generated by  Doxygen 1.6.0   Back to index