Logo Search packages:      
Sourcecode: djvulibre version File versions

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

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

Definition at line 1642 of file GPixmap.cpp.

References columns(), operator[](), and rows().

{
  GP<GPixmap> newpixmap(this);
  count = count & 3;
  if(count)
  {
    if( count&0x01)
      newpixmap = new GPixmap(ncolumns, nrows);
    else
      newpixmap = new GPixmap(nrows, ncolumns);

    GPixmap &dpixmap = *newpixmap;

    GMonitorLock lock(&pixmap_monitor());
    switch(count)
    {
    case 3: //// rotate 90 counter clockwise
        {
            int lastrow = dpixmap.rows()-1;

            for(int y=0; y<nrows; y++)
            {
                const GPixel *r=operator [] (y);
                for(int x=0,xnew=lastrow; xnew>=0; x++,xnew--)
                {
                    dpixmap[xnew][y] = r[x];
                }
            }
        }
        break;
    case 2: //// rotate 180 counter clockwise
        {
            int lastrow = dpixmap.rows()-1;
            int lastcolumn = dpixmap.columns()-1;

            for(int y=0,ynew=lastrow; ynew>=0; y++,ynew--)
            {
                const GPixel *r=operator [] (y);
                GPixel *d=dpixmap[ynew];
                for(int xnew=lastcolumn; xnew>=0; r++,xnew--)
                {
                    d[xnew] = *r;
                }
            }
        }
        break;
    case 1: //// rotate 270 counter clockwise
        {
            int lastcolumn = dpixmap.columns()-1;

            for(int y=0,ynew=lastcolumn; ynew>=0; y++,ynew--)
            {
                const GPixel *r=operator [] (y);
                for(int x=0; x<ncolumns; x++)
                {
                    dpixmap[x][ynew] = r[x];
                }
            }
        }
        break;
    }
  }
  return newpixmap;
}


Generated by  Doxygen 1.6.0   Back to index