|
AlbumShaper
1.0a3
|

Go to the source code of this file.
Functions | |
| QImage * | cropImage (QString filename, QPoint topLeft, QPoint bottomRight) |
| QImage* cropImage | ( | QString | filename, |
| QPoint | topLeft, | ||
| QPoint | bottomRight | ||
| ) |
Definition at line 36 of file crop.cpp.
Referenced by EditingInterface::crop().
{
//load original image
QImage origImage( filename );
//convert to 32-bit depth if necessary
if( origImage.depth() < 32 ) { origImage = origImage.convertDepth( 32, Qt::AutoColor ); }
//construct cropped image
QImage* croppedImage = new QImage(bottomRight.x() - topLeft.x() + 1,
bottomRight.y() - topLeft.y() + 1,
origImage.depth());
//iterate over each selected scanline
int xOrig, yOrig;
int xCropped, yCropped;
uchar *origScanLine, *croppedScanLine;
for( yOrig=topLeft.y(),yCropped=0; yOrig<=bottomRight.y(); yOrig++, yCropped++)
{
//iterate over each selected pixel in scanline
origScanLine = origImage.scanLine(yOrig);
croppedScanLine = croppedImage->scanLine(yCropped);
for( xOrig=topLeft.x(),xCropped=0; xOrig<=bottomRight.x(); xOrig++,xCropped++)
{
//copy pixel color from original image to cropped image
*((QRgb*)croppedScanLine+xCropped) = *((QRgb*)origScanLine+xOrig);
}
}
//return pointer to cropped image
return croppedImage;
}
1.7.5.1