zoomppm.cc

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