Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

imageTools.h File Reference

#include <qcolor.h>

Include dependency graph for imageTools.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Enumerations

enum  TRANSFORM_CODE { ROTATE_90, ROTATE_270, FLIP_H, FLIP_V }

Functions

bool isJpeg (const char *filename)
 Checks to see if an image is a valid jpg by seeing if the image dimensions can be read.
void calcScaledImageDimensions (int origWidth, int origHeight, int idealWidth, int idealHeight, int &width, int &height)
 Computes scale of image dimensions while respecting aspect ratio, equivalent to a QImage::scaleMin without actually scaling any image.
void constructImages (QString imageName, QImage &slideshowImage, QImage &thumbnailImage)
 Constructs slideshow and thumbnail images for a full sized image.
bool transformImage (QString fileIn, QString fileOut, TRANSFORM_CODE transformation)
 Apply image transformation on image.
bool scaleImage (QString fileIn, QString fileOut, int newWidth, int newHeight)
 Scale image and save copy to disk.
bool scaleImage (QString fileIn, QImage &scaledImage, int targetWidth, int targetHeight)
 Loaded scaled version of image.
bool getImageSize (const char *filename, QSize &size)
 Get image dimensions.
bool getImageSize (const char *filename, int &width, int &height)
 Get image dimensions.
double RGBtoL (QRgb *rgb)
 find luminance of a rgb color triplet
void RGBtoHSV (double r, double g, double b, double *h, double *s, double *v)
 Convert a RGB color triplet to HSV.
void HSVtoRGB (double *r, double *g, double *b, double h, double s, double v)
 Convert a HSV color triplet to RGB.


Enumeration Type Documentation

enum TRANSFORM_CODE
 

Enumeration values:
ROTATE_90 
ROTATE_270 
FLIP_H 
FLIP_V 

Definition at line 24 of file imageTools.h.

00025 {
00026   ROTATE_90,    //rotate clockwise 90 degrees
00027   ROTATE_270,  //rotate counter-clockwise 90 degrees
00028   FLIP_H,              //flip left-to-right
00029   FLIP_V,              //flip top-to-bottom
00030 } TRANSFORM_CODE;


Function Documentation

void calcScaledImageDimensions int  origWidth,
int  origHeight,
int  idealWidth,
int  idealHeight,
int &  width,
int &  height
 

Computes scale of image dimensions while respecting aspect ratio, equivalent to a QImage::scaleMin without actually scaling any image.

Definition at line 39 of file imageTools.cpp.

References height, and width.

Referenced by AlbumStatistics::AlbumStatistics(), constructImages(), SubalbumPreviewWidget::createSubalbumPixmap(), PhotoDescEdit::PhotoDescEdit(), EditingInterface::rotateSelection(), EditingInterface::selectAspectRatio(), Subalbum::setRepresentativeImage(), and Album::setRepresentativeImages().

00042 {
00043   //if original dimensions are within ideal new size then use
00044   //original dimensions
00045   if(origWidth <= idealWidth &&
00046      origHeight <= idealHeight)
00047   {
00048     width = origWidth;
00049     height = origHeight;
00050     return;
00051   }
00052 
00053   //else find dimension which is way over bounds
00054   float widthRatio = ((float)idealWidth) / ((float)origWidth);
00055   float heightRatio = ((float)idealHeight) / ((float)origHeight);
00056 
00057   if(widthRatio < heightRatio)
00058   {
00059     width = idealWidth;
00060     height = (int)((((float)idealWidth) / ((float)origWidth)) * ((float)origHeight));
00061   }
00062   else
00063   {
00064     height = idealHeight;
00065     width = (int)((((float)idealHeight) / ((float)origHeight)) * ((float)origWidth));
00066   }
00067 }

void constructImages QString  imageName,
QImage &  slideshowImage,
QImage &  thumbnailImage
 

Constructs slideshow and thumbnail images for a full sized image.

Definition at line 69 of file imageTools.cpp.

References calcScaledImageDimensions(), getImageSize(), scaleImage(), SLIDESHOW_HEIGHT, SLIDESHOW_WIDTH, THUMBNAIL_HEIGHT, and THUMBNAIL_WIDTH.

Referenced by Photo::constructSmallerImages().

00071 {
00072   //---------------------------------------------------------
00073   //obtain original image width and height
00074   int origWidth, origHeight;
00075   getImageSize( imageName, origWidth, origHeight );
00076   
00077   //compute dimensions of unhapped scaled thumbnail and slideshow images
00078   int thumbWidth, thumbHeight;
00079   calcScaledImageDimensions( origWidth, origHeight,
00080                              THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
00081                              thumbWidth, thumbHeight);
00082   
00083   int slideWidth, slideHeight;
00084   calcScaledImageDimensions( origWidth, origHeight,
00085                              SLIDESHOW_WIDTH, SLIDESHOW_HEIGHT,
00086                              slideWidth, slideHeight);
00087   //---------------------------------------------------------
00088   //create slide show image
00089   
00090   //first scale full image to unpadded dimensions
00091   QImage temp;
00092   scaleImage( imageName, temp, slideWidth, slideHeight );
00093   slideWidth = temp.width();
00094   slideHeight = temp.height();
00095  
00096   //create slideshow image and fill with white
00097   slideshowImage.create( SLIDESHOW_WIDTH, SLIDESHOW_HEIGHT, 32 );
00098   slideshowImage.fill( Qt::white.rgb() );
00099   
00100   //paint unpadded scaled image
00101   int xDiff = SLIDESHOW_WIDTH - slideWidth;
00102   int yDiff = SLIDESHOW_HEIGHT - slideHeight;
00103   bitBlt( &slideshowImage, xDiff/2, yDiff/2,
00104           &temp, 0, 0, slideWidth, slideHeight );
00105    
00106   //---------------------------------------------------------
00107   //create thumnail image
00108   scaleImage( imageName, thumbnailImage, thumbWidth, thumbHeight );
00109   //---------------------------------------------------------
00110 }

bool getImageSize const char *  filename,
int &  width,
int &  height
 

Get image dimensions.

Definition at line 203 of file imageTools.cpp.

References getJPEGSize(), height, and width.

Referenced by EditingInterface::applyImageUpdate(), constructImages(), getImageSize(), GrainEditor::GrainEditor(), HistogramInterface::HistogramInterface(), PhotoDescEdit::PhotoDescEdit(), EditingInterface::revertCurrentPhoto(), EditingInterface::rotateFlip(), GeneratePreviewThread::run(), ScaledPreviewInterface::ScaledPreviewInterface(), SelectionPlacementInterface::SelectionPlacementInterface(), SelectionInterface::setPhoto(), EditingInterface::setPhoto(), Subalbum::setRepresentativeImage(), Album::setRepresentativeImages(), setWallpaper(), and EditingInterface::showNextPrevFirstLastPhoto().

00204 {
00205   //if file is jpeg use faster method
00206   QString extension = QFileInfo(filename).extension(false).lower();
00207   if( extension.compare("jpeg") == 0 ||
00208       extension.compare("jpg") == 0 )
00209     return getJPEGSize( QFile::encodeName(filename),
00210                         width, height );
00211 
00212   //load entire image to qimage object in order to determine size
00213   QImage image(filename);
00214   width = image.width();
00215   height = image.height();
00216   return true;
00217 }

bool getImageSize const char *  filename,
QSize &  size
 

Get image dimensions.

Definition at line 194 of file imageTools.cpp.

References getImageSize().

00195 {
00196   int w,h;
00197   bool result = getImageSize( filename, w, h );
00198   size.setWidth( w );
00199   size.setHeight( h );
00200   return result;
00201 }

void HSVtoRGB double *  r,
double *  g,
double *  b,
double  h,
double  s,
double  v
 

Convert a HSV color triplet to RGB.

Definition at line 266 of file imageTools.cpp.

References b, and q.

Referenced by HistogramEditor::adjustImage(), SelectionInterface::constructDisplayImages(), embossEffect(), enhanceImageContrast(), SelectionPlacementInterface::SelectionPlacementInterface(), and sharpenImage().

00268 {
00269         int i;
00270         double f, p, q, t;
00271   
00272         if( s == 0 ) {
00273                 // achromatic (grey)
00274                 *r = *g = *b = v;
00275                 return;
00276         }
00277   
00278         h /= 60;                        // sector 0 to 5
00279         i = (int)floor( h );
00280         f = h - i;                      // factorial part of h
00281         p = v * ( 1 - s );
00282         q = v * ( 1 - s * f );
00283         t = v * ( 1 - s * ( 1 - f ) );
00284   
00285         switch( i ) {
00286                 case 0:
00287                         *r = v;
00288                         *g = t;
00289                         *b = p;
00290                         break;
00291                 case 1:
00292                         *r = q;
00293                         *g = v;
00294                         *b = p;
00295                         break;
00296                 case 2:
00297                         *r = p;
00298                         *g = v;
00299                         *b = t;
00300                         break;
00301                 case 3:
00302                         *r = p;
00303                         *g = q;
00304                         *b = v;
00305                         break;
00306                 case 4:
00307                         *r = t;
00308                         *g = p;
00309                         *b = v;
00310                         break;
00311                 default:                // case 5:
00312                         *r = v;
00313                         *g = p;
00314                         *b = q;
00315                         break;
00316         }  
00317 }

bool isJpeg const char *  filename  ) 
 

Checks to see if an image is a valid jpg by seeing if the image dimensions can be read.

Definition at line 33 of file imageTools.cpp.

References getJPEGSize().

Referenced by Photo::setImage(), and transformImage().

00034 {
00035   int w,h;
00036   return getJPEGSize( QFile::encodeName(filename), w, h );
00037 }

void RGBtoHSV double  r,
double  g,
double  b,
double *  h,
double *  s,
double *  v
 

Convert a RGB color triplet to HSV.

Definition at line 233 of file imageTools.cpp.

References b.

Referenced by HistogramEditor::adjustImage(), SelectionInterface::constructDisplayImages(), embossEffect(), enhanceImageContrast(), RGBtoL(), SelectionPlacementInterface::SelectionPlacementInterface(), and sharpenImage().

00235 {
00236         double min, max, delta;
00237   
00238         min = QMIN(QMIN( r, g), b );
00239         max = QMAX(QMAX( r, g), b );
00240         *v = max;                               // v
00241   
00242         delta = max - min;
00243   
00244         if( max != 0 )
00245                 *s = delta / max;               // s
00246         else {
00247                 // r = g = b = 0                // s = 0, v is undefined
00248                 *s = 0;
00249                 *h = -1;
00250                 return;
00251         }
00252   
00253         if( r == max )
00254                 *h = ( g - b ) / delta;         // between yellow & magenta
00255         else if( g == max )
00256                 *h = 2 + ( b - r ) / delta;     // between cyan & yellow
00257         else
00258                 *h = 4 + ( r - g ) / delta;     // between magenta & cyan
00259   
00260         *h *= 60;                               // degrees
00261         if( *h < 0 )
00262                 *h += 360;
00263   
00264 }

double RGBtoL QRgb *  rgb  ) 
 

find luminance of a rgb color triplet

Definition at line 219 of file imageTools.cpp.

References b, and RGBtoHSV().

Referenced by enhanceImageContrast().

00220 {
00221   double r = ((double)qRed(*rgb)   )/255.0;
00222   double g = ((double)qGreen(*rgb) )/255.0;
00223   double b = ((double)qBlue(*rgb)  )/255.0;
00224 
00225   double h,s,v;
00226   RGBtoHSV(r,g,b,&h,&s,&v);
00227   return 255.0*v;
00228 }

bool scaleImage QString  fileIn,
QImage &  scaledImage,
int  targetWidth,
int  targetHeight
 

Loaded scaled version of image.

Definition at line 173 of file imageTools.cpp.

References scaleJPEG().

Referenced by EditingInterface::applyImageUpdate(), constructImages(), GrainEditor::GrainEditor(), HistogramInterface::HistogramInterface(), SlideshowWidget::loadPhoto(), RecentAlbumMenuItem::RecentAlbumMenuItem(), TitleWidget::refreshOpenRecentMenu(), EditingInterface::revertCurrentPhoto(), EditingInterface::rotateFlip(), GeneratePreviewThread::run(), ScaledPreviewInterface::ScaledPreviewInterface(), scaleImage(), SelectionPlacementInterface::SelectionPlacementInterface(), SelectionInterface::setPhoto(), EditingInterface::setPhoto(), Subalbum::setRepresentativeImage(), Album::setRepresentativeImages(), setWallpaper(), and EditingInterface::showNextPrevFirstLastPhoto().

00174 {
00175   //if file is jpeg use faster method
00176   QString extension = QFileInfo(fileIn).extension(false).lower();
00177   if( extension.compare("jpeg") == 0 ||
00178       extension.compare("jpg") == 0 )
00179     return scaleJPEG( QFile::encodeName(fileIn), scaledImage, targetWidth, targetHeight );
00180   
00181   //use slow smooth-scale method for scaling image.
00182   //clamp scaling to <= 2x
00183   QImage orig(fileIn);  
00184   if(QMIN( ((float)targetWidth)/orig.width(), ((float)targetHeight)/orig.height() ) > 2)    
00185   {
00186     targetWidth = 2*orig.width();
00187     targetHeight = 2*orig.height();
00188   }
00189   
00190   scaledImage = orig.smoothScale( targetWidth, targetHeight, QImage::ScaleMin );
00191   return true;
00192 }

bool scaleImage QString  fileIn,
QString  fileOut,
int  newWidth,
int  newHeight
 

Scale image and save copy to disk.

Definition at line 159 of file imageTools.cpp.

References scaleImage().

00161 {
00162   //scale image
00163   QImage scaledImage;
00164   if( scaleImage(fileIn, scaledImage, newWidth, newHeight ) )
00165   {
00166     scaledImage.save( fileOut, "JPEG", 95 );
00167     return true;
00168   }
00169   else
00170     return false;
00171 }

bool transformImage QString  fileIn,
QString  fileOut,
TRANSFORM_CODE  transformation
 

Apply image transformation on image.

Definition at line 112 of file imageTools.cpp.

References isJpeg(), and transformJPEG().

Referenced by Photo::applyTransformation(), and EditingInterface::rotateFlip().

00113 {
00114   //chicago
00115   
00116   //if file is jpeg use faster method
00117   if( isJpeg(fileIn) )
00118     return transformJPEG( fileIn, fileOut, transformation );
00119   
00120   //load image
00121   QImage origImage(fileIn);
00122   QImage transformedImage;
00123   
00124   //transform image
00125   if(transformation == ROTATE_90)
00126   {
00127     if(!transformedImage.create( origImage.height(), origImage.width(), origImage.depth() ) )
00128       return false;
00129     
00130     int x,y;
00131     for(x=0; x < origImage.height(); x++)
00132     {
00133       for(y=0; y < origImage.width(); y++)
00134         transformedImage.setPixel(origImage.height() - 1 - x, y, origImage.pixel(y, x) );
00135     }
00136   }
00137   else if(transformation == ROTATE_270)
00138   {
00139     if(!transformedImage.create( origImage.height(), origImage.width(), origImage.depth() ) )
00140       return false;
00141     
00142     int x,y;
00143     for(x=0; x < origImage.height(); x++)
00144     {
00145       for(y=0; y < origImage.width(); y++)
00146           transformedImage.setPixel(x, origImage.width() - 1 - y, origImage.pixel(y, x) );
00147     }
00148   }
00149   else if(transformation == FLIP_H)
00150   {  transformedImage = origImage.mirror(false,true); }
00151   else
00152   {  transformedImage = origImage.mirror(true,false); }
00153   
00154   //save out transformed image  
00155   transformedImage.save( fileOut, "JPEG", 95 );
00156   return true;  
00157 }


Generated on Sat Apr 2 05:44:22 2005 for AlbumShaper by  doxygen 1.3.9.1