app-create-thumbnails.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Image/Image.H"
00039 #include "Image/FilterOps.H"
00040 #include "Image/ShapeOps.H"
00041 #include "Image/Pixels.H"
00042 #include "Raster/Raster.H"
00043
00044 #include <cstdio>
00045
00046 #define TSIZEX 64
00047 #define TBORDER 2
00048 #define TSIZEY (TSIZEX + TBORDER)
00049 #define TNAME "thumbnails.ppm"
00050
00051 int main(int argc, char** argv)
00052 {
00053 PixRGB<byte> cpix(255, 0, 0);
00054
00055 if (argc == 1)
00056 {
00057 LERROR("USAGE: %s <image.ppm> .. <image.ppm>\n"
00058 " puts the thumbnails in 'thumbnails.ppm'\n", argv[0]);
00059 return 1;
00060 }
00061
00062 Image< PixRGB<byte> > thumb(TSIZEX * (argc - 1) + TBORDER * (argc - 2),
00063 TSIZEY, ZEROS);
00064
00065 for (int i = 1; i < argc; i ++)
00066 {
00067 bool compressed = false;
00068 if (argv[i][strlen(argv[i])-1] == 'z') {
00069 char t[1000]; sprintf(t, "gunzip %s",argv[i]);
00070 if (system(t)) LERROR("Error in system()");
00071 argv[i][strlen(argv[i])-3]='\0'; compressed = true;
00072 }
00073 Image< PixRGB<byte> > tmp = Raster::ReadRGB(argv[i]);
00074 if (compressed) {
00075 char t[1000]; sprintf(t, "gzip -9 %s", argv[i]);
00076 if (system(t)) LERROR("Error in system()");
00077 }
00078
00079
00080 tmp = lowPass9(lowPass9(lowPass9(tmp)));
00081
00082
00083 float sx = ((float)TSIZEX) / ((float)tmp.getWidth());
00084 float sy = ((float)TSIZEX) / ((float)tmp.getHeight());
00085 float scale = (sx <= sy ? sx : sy);
00086 int w = (int)(scale * ((float)tmp.getWidth()));
00087 int h = (int)(scale * ((float)tmp.getHeight()));
00088 if (w > TSIZEX) w = TSIZEX;
00089 if (h > TSIZEY) h = TSIZEY;
00090
00091 int xoffset = (TSIZEX + TBORDER) * (i - 1) + (TSIZEX - w) / 2;
00092 int yoffset = (TSIZEY - h) / 2;
00093
00094 LDEBUG("%s: (%d, %d) at (%d, %d)", argv[i], w, h, xoffset, yoffset);
00095 tmp = rescale(tmp, w, h);
00096
00097 PixRGB<byte> pix;
00098 for (int yy = 0; yy < h; yy ++)
00099 for (int xx = 0; xx < w; xx ++)
00100 {
00101 tmp.getVal(xx, yy, pix);
00102 thumb.setVal(xx + xoffset, yy + yoffset, pix);
00103 }
00104
00105
00106 if (i < argc - 1)
00107 for (int yy = 0; yy < TSIZEY; yy ++)
00108 for (int xx = TSIZEX; xx < TSIZEX+TBORDER; xx ++)
00109 thumb.setVal(xx + (TSIZEX+TBORDER)*(i-1), yy, cpix);
00110
00111 }
00112 Raster::WriteRGB(thumb, TNAME, RASFMT_PNM);
00113 return 0;
00114 }
00115
00116
00117
00118
00119
00120