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

GP< GBitmap > GBitmap::rotate ( int  count = 0  ) 

Rotates bitmap by 90, 180 or 270 degrees anticlockwise and returns a new pixmap, input bitmap is not changed. count can be 1, 2, or 3 for 90, 180, 270 degree rotation. It returns the same bitmap if not rotated. The input bitmap will be uncompressed for rotation

Definition at line 1582 of file GBitmap.cpp.

References columns(), compress(), monitor(), operator[](), rows(), set_grays(), and uncompress().

{
  GP<GBitmap> newbitmap=this;
  count = count & 3;
  if(count)
  {
    if( count & 0x01 )
    {
      newbitmap = new GBitmap(ncolumns, nrows);
    }else
    {
      newbitmap = new GBitmap(nrows, ncolumns);
    }
    GMonitorLock lock(monitor());
    if (!bytes_data)
      uncompress();
    GBitmap &dbitmap = *newbitmap;
    dbitmap.set_grays(grays);
    switch(count)
    {
    case 3: // rotate 90 counter clockwise
      {
        const int lastrow = dbitmap.rows()-1;
        for(int y=0; y<nrows; y++)
        {
          const unsigned char *r=operator[] (y);
          for(int x=0,xnew=lastrow;xnew>=0; x++,xnew--)
          {
            dbitmap[xnew][y] = r[x];
          }
        }
      }
      break;
    case 2: // rotate 180 counter clockwise
      {
        const int lastrow = dbitmap.rows()-1;
        const int lastcolumn = dbitmap.columns()-1;
        for(int y=0,ynew=lastrow;ynew>=0; y++,ynew--)
        {
          const unsigned char *r=operator[] (y);
          unsigned char *d=dbitmap[ynew];
          for(int xnew=lastcolumn;xnew>=0; r++,--xnew)
          {
            d[xnew] = *r;
          }
        }
      }
      break;
    case 1: // rotate 270 counter clockwise
      {
        const int lastcolumn = dbitmap.columns()-1;
        for(int y=0,ynew=lastcolumn;ynew>=0;y++,ynew--)
        {
          const unsigned char *r=operator[] (y);
          for(int x=0; x<ncolumns; x++)
          {
            dbitmap[x][ynew] = r[x];
          }
        }
      }
      break;
    }
    if(grays == 2)
    {
      compress();
      dbitmap.compress();
    }
  }
  return newbitmap;
}


Generated by  Doxygen 1.6.0   Back to index