zoomjpeg.cc

 1 const char *help = "\
 2 progname: zoomjpeg.cc\n\
 3 code2html: This program reads a color image and zoom its content.\n\
 4 version: Torch3 vision2.1, 2003-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "ipZoom.h"
 9 #include "xtprobeImageDiskXFile.h"
10 #include "jpegDiskXFile.h"
11 #include "DiskXFile.h"
12 #include "CmdLine.h"
13 
14 using namespace Torch;
15 
16 int main(int argc, char **argv)
17 {
18 	char *image_filename;
19 	bool verbose;
20 	int zoom;
21   
22 	// Construct the command line
23   	CmdLine cmd;
24 	cmd.setBOption("write log", false);
25 	
26   	// Put the help line at the beginning
27   	cmd.info(help);
28 
29   	cmd.addText("\nArguments:");
30   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
31   	cmd.addICmdArg("zoom factor", &zoom, "zoom");
32   	cmd.addText("\nOptions:");
33   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
34 
35 	cmd.read(argc, argv);
36 
37 
38   	ImageDiskXFile *image_file = NULL;
39 	Image *image_in = NULL;
40 	Image *image_out = NULL;
41 
42 	image_in = new ImageRgb();
43 	image_in->setBOption("verbose", verbose);
44 	
45         image_file = new xtprobeImageDiskXFile(image_filename, "r");
46         image_in->loadImageXFile(image_file);
47         delete image_file;
48 
49 	if(verbose)
50 	{
51 		print("Image info:\n");
52 		print("   width = %d\n", image_in->width);
53 		print("   height = %d\n", image_in->height);
54 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
55 	}
56 
57 	ipCore *ip = NULL;
58 
59 	ip = new ipZoom(image_in->width, image_in->height, "rgb", zoom);
60 	ip->setBOption("verbose", verbose);
61 	ip->process(image_in);
62 	
63 	image_out = new ImageRgb();
64 	image_out->setBOption("verbose", verbose);
65 
66 	image_out->copyFrom(ip->getWidthOut(), ip->getHeightOut(), ip->seq_out->frames[0], "rgb");
67 	
68 	jpegDiskXFile *jpeg_file = new jpegDiskXFile("zoom.jpeg", "w");
69 	image_out->saveImageXFile(jpeg_file);	
70 	delete jpeg_file;
71 
72 	delete ip;
73 	delete image_out;
74 	delete image_in;
75 
76 	return(0);
77 }