00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <iostream.h>
00019 #include <fstream.h>
00020 #include <stdio.h>
00021 #include <qstring.h>
00022 #include <qimage.h>
00023
00024
00025 #include "imageTools.h"
00026 #include "../config.h"
00027
00028
00030 void resizeImage(int originalWidth,
00031 int originalHeight,
00032 int maxWidth,
00033 int maxHeight,
00034 int& newWidth,
00035 int& newHeight)
00036 {
00037
00038
00039 if(originalWidth <= maxWidth &&
00040 originalHeight <= maxHeight)
00041 {
00042 newWidth = originalWidth;
00043 newHeight = originalHeight;
00044 return;
00045 }
00046
00047
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 }
00062
00063 void copyFile(QString oldFile,
00064 QString newFile)
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 }
00079
00080 void createImages(QImage* fullImage,
00081 QImage** slideshowImage,
00082 QImage** thumbnailImage,
00083 QImage** paddedThumbnailImage,
00084 int &slideshowWidth,
00085 int &slideshowHeight)
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
00104 QImage temp = fullImage->smoothScale( slideshowWidth, slideshowHeight );
00105 temp.setAlphaBuffer(true);
00106
00107 (*slideshowImage) = new QImage(SLIDESHOW_WIDTH, SLIDESHOW_HEIGHT, fullImage->depth());
00108 (*slideshowImage)->setAlphaBuffer(true);
00109
00110 int xDiff = SLIDESHOW_WIDTH - slideshowWidth;
00111 int yDiff = SLIDESHOW_HEIGHT - slideshowHeight;
00112
00113
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
00137 (*thumbnailImage) = new QImage(fullImage->smoothScale( thumbnailW, thumbnailH ));
00138 (*thumbnailImage)->setAlphaBuffer(true);
00139
00140
00141 if(thumbnailW == THUMBNAIL_WIDTH &&
00142 thumbnailH == THUMBNAIL_HEIGHT)
00143 {
00144 (*paddedThumbnailImage) = (*thumbnailImage);
00145 }
00146
00147 else
00148 {
00149
00150 (*paddedThumbnailImage) = new QImage(THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, fullImage->depth());
00151 (*paddedThumbnailImage)->setAlphaBuffer(true);
00152
00153
00154 xDiff = THUMBNAIL_WIDTH - thumbnailW;
00155 yDiff = THUMBNAIL_HEIGHT - thumbnailH;
00156
00157
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 }
00180
00181