ppmread.cc

 1 const char *help = "\
 2 progname: ppmread.cc\n\
 3 code2html: This program reads/writes a ppm image.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "DiskXFile.h"
 9 #include "CmdLine.h"
10 
11 using namespace Torch;
12 
13 int main(int argc, char **argv)
14 {
15 	char *image_filename;
16 	bool verbose;
17   
18 	// Construct the command line
19   	CmdLine cmd;
20 	cmd.setBOption("write log", false);
21 	
22   	// Put the help line at the beginning
23   	cmd.info(help);
24 
25   	cmd.addText("\nArguments:");
26   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
27   	cmd.addText("\nOptions:");
28   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
29 
30 	cmd.read(argc, argv);
31 
32 
33   	DiskXFile *image_file = NULL;
34 	Image *image = NULL;
35 
36 	image = new ImageRgb();
37 	image->setBOption("verbose", verbose);
38 	
39 	image_file = new DiskXFile(image_filename, "r");
40 	image->loadXFile(image_file);
41 	delete image_file;
42 
43 	if(verbose)
44 	{
45 		print("Image info:\n");
46 		print("   width = %d\n", image->width);
47 		print("   height = %d\n", image->height);
48 		print("   format = %s (%d)\n", image->coding, image->n_planes);
49 	}
50 
51 	image_file = new DiskXFile("test.ppm", "w");
52 	image->saveXFile(image_file);
53 	delete image_file;
54 
55 
56 
57 	delete image;
58 
59 	return(0);
60 }