#include <fstream>
#include <qstring.h>
#include <qimage.h>
#include <qfile.h>
#include <qdatastream.h>
#include "imageTools.h"
#include "../config.h"
Include dependency graph for imageTools.cpp:

Go to the source code of this file.
Functions | |
| void | resizeImage (int originalWidth, int originalHeight, int maxWidth, int maxHeight, int &newWidth, int &newHeight) |
| Returns new image dimensions keeping size ratio. | |
| void | copyFile (QString oldFilePath, QString newFilePath) |
| Copies a file from one location to another. | |
| void | createImages (QImage *fullImage, QImage **slideshowImage, QImage **thumbnailImage, QImage **paddedThumbnailImage, int &slideshowWidth, int &slideshowHeight) |
| Given a pointer to a full image, constructs slideshow, thumbnail, and padded thumbnail images. | |
|
||||||||||||
|
Copies a file from one location to another.
Definition at line 63 of file imageTools.cpp. Referenced by Album::exportSubalbumImages(), Album::exportThemeResources(), and Album::reorderSubalbumImages().
00065 {
00066 //if copying file from old location to new just skip, this
00067 //occurs when resaving albums with new themes but to same location
00068 if(oldFilePath == newFilePath)
00069 return;
00070
00071 const int BUFFER_SIZE = 1024;
00072 Q_INT8 buffer[BUFFER_SIZE];
00073
00074 QFile oldFile(oldFilePath);
00075 QFile newFile(newFilePath);
00076 oldFile.open( IO_ReadOnly );
00077 newFile.open( IO_WriteOnly );
00078
00079 QDataStream srcStream(&oldFile);
00080 QDataStream destStream(&newFile);
00081
00082 while(!srcStream.atEnd())
00083 {
00084 int i = 0;
00085 while(!srcStream.atEnd() && i < BUFFER_SIZE)
00086 {
00087 srcStream >> buffer[i];
00088 i++;
00089 }
00090 int k = 0;
00091 for(k = 0; k < i; k++)
00092 {
00093 destStream << buffer[k];
00094 }
00095 }
00096 }
|
|
||||||||||||||||||||||||||||
|
Given a pointer to a full image, constructs slideshow, thumbnail, and padded thumbnail images.
Definition at line 98 of file imageTools.cpp. References resizeImage(), SLIDESHOW_HEIGHT, SLIDESHOW_WIDTH, THUMBNAIL_HEIGHT, and THUMBNAIL_WIDTH. Referenced by Photo::flipHorizontally(), Photo::flipVertically(), Photo::rotate270(), Photo::rotate90(), and Photo::setImage().
00104 {
00105 //---------------------------------------------------------
00106 if((*paddedThumbnailImage) != (*thumbnailImage))
00107 delete (*paddedThumbnailImage);
00108 delete (*thumbnailImage);
00109 delete (*slideshowImage);
00110 //---------------------------------------------------------
00111 int thumbnailW = 0;
00112 int thumbnailH = 0;
00113 //---------------------------------------------------------
00114 resizeImage( fullImage->width(), fullImage->height(),
00115 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT,
00116 thumbnailW, thumbnailH);
00117 resizeImage( fullImage->width(), fullImage->height(),
00118 SLIDESHOW_WIDTH, SLIDESHOW_HEIGHT,
00119 slideshowWidth, slideshowHeight);
00120 //---------------------------------------------------------
00121 //scale slide show image
00122 QImage temp = fullImage->smoothScale( slideshowWidth, slideshowHeight );
00123 temp.setAlphaBuffer(true);
00124 //create full size slide show image
00125
00126 (*slideshowImage) = new QImage(SLIDESHOW_WIDTH, SLIDESHOW_HEIGHT, 32);
00127 (*slideshowImage)->setAlphaBuffer(true);
00128 //copy scaled image into centered portion of real slideshow image
00129 int xDiff = SLIDESHOW_WIDTH - slideshowWidth;
00130 int yDiff = SLIDESHOW_HEIGHT - slideshowHeight;
00131
00132 //set all pixels to white
00133 int x,y;
00134 for(x=0; x< SLIDESHOW_WIDTH; x++)
00135 {
00136 for(y=0; y<SLIDESHOW_HEIGHT; y++)
00137 {
00138 (*slideshowImage)->setPixel(x, y, QColor(255, 255, 255).rgb());
00139 }
00140 }
00141
00142 int x2 = 0;
00143 int y2;
00144 for(x = xDiff/2; x< (xDiff/2) + slideshowWidth; x++)
00145 {
00146 y2 = 0;
00147 for(y = yDiff/2; y < (yDiff/2) + slideshowHeight; y++)
00148 {
00149 (*slideshowImage)->setPixel(x, y, temp.pixel(x2, y2));
00150 y2++;
00151 }
00152 x2++;
00153 }
00154 //---------------------------------------------------------
00155 //scale down thumbnail image
00156 (*thumbnailImage) = new QImage(fullImage->smoothScale( thumbnailW, thumbnailH ));
00157 (*thumbnailImage)->setAlphaBuffer(true);
00158 //---------------------------------------------------------
00159 //if scaled thumbnail image is same size as padded thumbnail should be reuse object
00160 if(thumbnailW == THUMBNAIL_WIDTH &&
00161 thumbnailH == THUMBNAIL_HEIGHT)
00162 {
00163 (*paddedThumbnailImage) = (*thumbnailImage);
00164 }
00165 //else pad thumbnail
00166 else
00167 {
00168 //created padded thumbnail image
00169 (*paddedThumbnailImage) = new QImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, 32);
00170 (*paddedThumbnailImage)->setAlphaBuffer(true);
00171
00172 //copy scaled image into centered portion of padded image
00173 xDiff = THUMBNAIL_WIDTH - thumbnailW;
00174 yDiff = THUMBNAIL_HEIGHT - thumbnailH;
00175
00176 //set all pixels to white
00177 for(x=0; x< THUMBNAIL_WIDTH; x++)
00178 {
00179 for(y=0; y<THUMBNAIL_HEIGHT; y++)
00180 {
00181 (*paddedThumbnailImage)->setPixel(x, y, QColor(255, 255, 255).rgb());
00182 }
00183 }
00184
00185 x2 = 0;
00186 for(x = xDiff/2; x< (xDiff/2) + thumbnailW; x++)
00187 {
00188 y2 = 0;
00189 for(y = yDiff/2; y < (yDiff/2) + thumbnailH; y++)
00190 {
00191 (*paddedThumbnailImage)->setPixel(x, y, (*thumbnailImage)->pixel(x2, y2));
00192 y2++;
00193 }
00194 x2++;
00195 }
00196 }
00197 //---------------------------------------------------------
00198 }
|
|
||||||||||||||||||||||||||||
|
Returns new image dimensions keeping size ratio.
Definition at line 30 of file imageTools.cpp. Referenced by AlbumStatistics::AlbumStatistics(), createImages(), PhotoEditWidget::setPhoto(), Album::setRepresentativeImages(), and Subalbum::setRepresentativeImages().
00036 {
00037 //if original dimensions are within max new size then use
00038 //original dimensions
00039 if(originalWidth <= maxWidth &&
00040 originalHeight <= maxHeight)
00041 {
00042 newWidth = originalWidth;
00043 newHeight = originalHeight;
00044 return;
00045 }
00046
00047 //else find dimension which is way over bounds
00048 float ratWidth = ((float)maxWidth) / ((float)originalWidth);
00049 float ratHeight = ((float)maxHeight) / ((float)originalHeight);
00050
00051 if(ratWidth < ratHeight)
00052 {
00053 newWidth = maxWidth;
00054 newHeight = (int)((((float)maxWidth) / ((float)originalWidth)) * ((float)originalHeight));
00055 }
00056 else
00057 {
00058 newHeight = maxHeight;
00059 newWidth = (int)((((float)maxHeight) / ((float)originalHeight)) * ((float)originalWidth));
00060 }
00061 }
|
1.3.4