app-fzoom.C
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 #include "Image/Image.H"
00036 #include "Image/ShapeOps.H"
00037 #include "Raster/Raster.H"
00038 #include "Util/Assert.H"
00039 #include "Util/CpuTimer.H"
00040 #include "Util/StringUtil.H"
00041 #include "Util/Types.H"
00042 #include "Util/log.H"
00043 #include "Util/sformat.H"
00044
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <string.h>
00048 #include <math.h>
00049 #include <unistd.h>
00050 #include <vector>
00051
00052
00053
00054
00055
00056
00057 static
00058 void
00059 usage(const char* argv0)
00060 {
00061 fprintf(stderr, "usage: %s [-options] input output\n", argv0);
00062 fprintf(stderr, "\
00063 options:\n\
00064 -x xsize output x size\n\
00065 -y ysize output y size\n\
00066 -f filter filter type\n\
00067 {b=box, t=triangle, q=bell, B=B-spline, h=hermite, l=Lanczos3, m=Mitchell}\n\
00068 input, output files to read/write.\n\
00069 ");
00070 exit(1);
00071 }
00072
00073 int
00074 main(int argc, char* argv[])
00075 {
00076 int c;
00077 int xsize = 0, ysize = 0;
00078
00079 RescaleType ftype = RESCALE_FILTER_TRIANGLE;
00080
00081 while ((c = getopt(argc, argv, "x:y:f:")) != EOF) {
00082 switch(c) {
00083 case 'x': xsize = atoi(optarg); break;
00084 case 'y': ysize = atoi(optarg); break;
00085 case 'f': ftype = getRescaleTypeFromChar(*optarg); break;
00086 case '?': usage(argv[0]);
00087 default: usage(argv[0]);
00088 }
00089 }
00090
00091 if ((argc - optind) != 2) usage(argv[0]);
00092 const char* srcfile = argv[optind];
00093 const char* dstfile = argv[optind + 1];
00094
00095 const Image<byte> src = Raster::ReadGray(srcfile);
00096
00097 const Dims newdims(xsize <= 0 ? src.getWidth() : xsize,
00098 ysize <= 0 ? src.getHeight() : ysize);
00099
00100 CpuTimer tm;
00101
00102 const Image<byte> dst = rescale(src, newdims, ftype);
00103
00104 tm.mark();
00105 tm.report(sformat("%8s %dx%d -> %dx%d",
00106 convertToString(ftype).c_str(),
00107 src.getWidth(), src.getHeight(),
00108 newdims.w(), newdims.h()).c_str());
00109
00110 Raster::WriteGray(dst, dstfile);
00111
00112 return 0;
00113 }
00114
00115
00116
00117
00118
00119
00120