#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <qstring.h>
#include <qimage.h>
#include "imageTools.h"
#include "../config.h"
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 oldFile, QString newFile) |
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().
00065 { 00066 ifstream inputstream(oldFile.ascii(), ios::binary|ios::in); 00067 ofstream outputstream(newFile.ascii(), ios::binary|ios::out); 00068 00069 char buffer[500]; 00070 while(inputstream.is_open() && inputstream) 00071 { 00072 inputstream.read(buffer, 500); 00073 outputstream.write(buffer, 500); 00074 } 00075 00076 inputstream.close(); 00077 outputstream.close(); 00078 } |
|
Given a pointer to a full image, constructs slideshow, thumbnail, and padded thumbnail images.
Definition at line 80 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().
00086 { 00087 //--------------------------------------------------------- 00088 if((*paddedThumbnailImage) != (*thumbnailImage)) 00089 delete (*paddedThumbnailImage); 00090 delete (*thumbnailImage); 00091 delete (*slideshowImage); 00092 //--------------------------------------------------------- 00093 int thumbnailW = 0; 00094 int thumbnailH = 0; 00095 //--------------------------------------------------------- 00096 resizeImage( fullImage->width(), fullImage->height(), 00097 THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, 00098 thumbnailW, thumbnailH); 00099 resizeImage( fullImage->width(), fullImage->height(), 00100 SLIDESHOW_WIDTH, SLIDESHOW_HEIGHT, 00101 slideshowWidth, slideshowHeight); 00102 //--------------------------------------------------------- 00103 //scale slide show image 00104 QImage temp = fullImage->smoothScale( slideshowWidth, slideshowHeight ); 00105 temp.setAlphaBuffer(true); 00106 //create full size slide show image 00107 (*slideshowImage) = new QImage(SLIDESHOW_WIDTH, SLIDESHOW_HEIGHT, fullImage->depth()); 00108 (*slideshowImage)->setAlphaBuffer(true); 00109 //copy scaled image into centered portion of real slideshow image 00110 int xDiff = SLIDESHOW_WIDTH - slideshowWidth; 00111 int yDiff = SLIDESHOW_HEIGHT - slideshowHeight; 00112 00113 //set all pixels to white 00114 int x,y; 00115 for(x=0; x< SLIDESHOW_WIDTH; x++) 00116 { 00117 for(y=0; y<SLIDESHOW_HEIGHT; y++) 00118 { 00119 (*slideshowImage)->setPixel(x, y, QColor(255, 255, 255).rgb()); 00120 } 00121 } 00122 00123 int x2 = 0; 00124 int y2; 00125 for(x = xDiff/2; x< (xDiff/2) + slideshowWidth; x++) 00126 { 00127 y2 = 0; 00128 for(y = yDiff/2; y < (yDiff/2) + slideshowHeight; y++) 00129 { 00130 (*slideshowImage)->setPixel(x, y, temp.pixel(x2, y2)); 00131 y2++; 00132 } 00133 x2++; 00134 } 00135 //--------------------------------------------------------- 00136 //scale down thumbnail image 00137 (*thumbnailImage) = new QImage(fullImage->smoothScale( thumbnailW, thumbnailH )); 00138 (*thumbnailImage)->setAlphaBuffer(true); 00139 //--------------------------------------------------------- 00140 //if scaled thumbnail image is same size as padded thumbnail should be reuse object 00141 if(thumbnailW == THUMBNAIL_WIDTH && 00142 thumbnailH == THUMBNAIL_HEIGHT) 00143 { 00144 (*paddedThumbnailImage) = (*thumbnailImage); 00145 } 00146 //else pad thumbnail 00147 else 00148 { 00149 //created padded thumbnail image 00150 (*paddedThumbnailImage) = new QImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, fullImage->depth()); 00151 (*paddedThumbnailImage)->setAlphaBuffer(true); 00152 00153 //copy scaled image into centered portion of padded image 00154 xDiff = THUMBNAIL_WIDTH - thumbnailW; 00155 yDiff = THUMBNAIL_HEIGHT - thumbnailH; 00156 00157 //set all pixels to white 00158 for(x=0; x< THUMBNAIL_WIDTH; x++) 00159 { 00160 for(y=0; y<THUMBNAIL_HEIGHT; y++) 00161 { 00162 (*paddedThumbnailImage)->setPixel(x, y, QColor(255, 255, 255).rgb()); 00163 } 00164 } 00165 00166 x2 = 0; 00167 for(x = xDiff/2; x< (xDiff/2) + thumbnailW; x++) 00168 { 00169 y2 = 0; 00170 for(y = yDiff/2; y < (yDiff/2) + thumbnailH; y++) 00171 { 00172 (*paddedThumbnailImage)->setPixel(x, y, (*thumbnailImage)->pixel(x2, y2)); 00173 y2++; 00174 } 00175 x2++; 00176 } 00177 } 00178 //--------------------------------------------------------- 00179 } |
|
Returns new image dimensions keeping size ratio.
Definition at line 30 of file imageTools.cpp. Referenced by 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 } |