AlbumShaper  1.0a3
Functions
crop.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

QImage * cropImage (QString filename, QPoint topLeft, QPoint bottomRight)
 

Function Documentation

§ cropImage()

QImage* cropImage ( QString  filename,
QPoint  topLeft,
QPoint  bottomRight 
)

Definition at line 36 of file crop.cpp.

Referenced by EditingInterface::crop().

37 {
38  //load original image
39  QImage origImage( filename );
40 
41  //convert to 32-bit depth if necessary
42  if( origImage.depth() < 32 ) { origImage = origImage.convertDepth( 32, Qt::AutoColor ); }
43 
44  //construct cropped image
45  QImage* croppedImage = new QImage(bottomRight.x() - topLeft.x() + 1,
46  bottomRight.y() - topLeft.y() + 1,
47  origImage.depth());
48 
49  //iterate over each selected scanline
50  int xOrig, yOrig;
51  int xCropped, yCropped;
52  uchar *origScanLine, *croppedScanLine;
53 
54  for( yOrig=topLeft.y(),yCropped=0; yOrig<=bottomRight.y(); yOrig++, yCropped++)
55  {
56  //iterate over each selected pixel in scanline
57  origScanLine = origImage.scanLine(yOrig);
58  croppedScanLine = croppedImage->scanLine(yCropped);
59 
60  for( xOrig=topLeft.x(),xCropped=0; xOrig<=bottomRight.x(); xOrig++,xCropped++)
61  {
62  //copy pixel color from original image to cropped image
63  *((QRgb*)croppedScanLine+xCropped) = *((QRgb*)origScanLine+xOrig);
64  }
65  }
66 
67  //return pointer to cropped image
68  return croppedImage;
69 }
QPoint bottomRight
QPoint topLeft