Logo Search packages:      
Sourcecode: djvulibre version File versions  Download package

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

Performs an additive blit of the GBitmap bm#. The GBitmap bm# is first positioned above the current GBitmap in such a way that position (u#,v#) in GBitmap bm# corresponds to position (u#+x#,v#+y#) in the current GBitmap. The value of each pixel in GBitmap bm# is then added to the value of the corresponding pixel in the current GBitmap.

{ Example}: Assume for instance that the current GBitmap is initially white (all pixels have value zero). This operation copies the pixel values of GBitmap bm# at position (x#,y#) into the current GBitmap. Note that function blit# does not change the number of gray levels in the current GBitmap. You may have to call {set_grays} to specify how the pixel values should be interpreted.

Definition at line 551 of file GBitmap.cpp.

References border, bytes, bytes_per_row, columns(), monitor(), ncolumns, nrows, read_run(), rle, rows(), and uncompress().

Referenced by blit().

{
  // Check boundaries
  if ((x >= ncolumns)              || 
      (y >= nrows)                 ||
      (x + (int)bm->columns() < 0) || 
      (y + (int)bm->rows() < 0)     )
    return;

  // Perform blit
  GMonitorLock lock1(monitor());
  GMonitorLock lock2(bm->monitor());
  if (bm->bytes)
    {
      if (!bytes_data)
        uncompress();
      // Blit from bitmap
      const unsigned char *srow = bm->bytes + bm->border;
      unsigned char *drow = bytes_data + border + y*bytes_per_row + x;
      for (int sr = 0; sr < bm->nrows; sr++)
        {
          if (sr+y>=0 && sr+y<nrows) 
            {
              int sc = max(0, -x);
              int sc1 = min(bm->ncolumns, ncolumns-x);
              while (sc < sc1)
                {
                  drow[sc] += srow[sc];
                  sc += 1;
                }
            }
          srow += bm->bytes_per_row;
          drow += bytes_per_row;
        }
    }
  else if (bm->rle)
    {
      if (!bytes_data)
        uncompress();
      // Blit from rle
      const unsigned char *runs = bm->rle;
      unsigned char *drow = bytes_data + border + y*bytes_per_row + x;
      int sr = bm->nrows - 1;
      drow += sr * bytes_per_row;
      int sc = 0;
      char p = 0;
      while (sr >= 0)
        {
          const int z = read_run(runs);
          if (sc+z > bm->ncolumns)
            G_THROW( ERR_MSG("GBitmap.lost_sync") );
          int nc = sc + z;
          if (p && sr+y>=0 && sr+y<nrows) 
            {
              if (sc + x < 0) 
                sc = min(-x, nc); 
              while (sc < nc && sc + x<ncolumns)
                drow[sc++] += 1;
            }
          sc = nc;
          p = 1 - p;
          if (sc >= bm->ncolumns) 
            {
              p = 0;
              sc = 0;
              drow -= bytes_per_row;
              sr -= 1; 
            }
        }
    }
}


Generated by  Doxygen 1.6.0   Back to index