x2ppm.cc

 1 const char *help = "\
 2 progname: x2ppm.cc\n\
 3 code2html: This program reads an image and saves it as a ppm.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "xtprobeImageDiskXFile.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   	ImageDiskXFile *image_file = NULL;
33 	Image *colorimage = NULL;
34 
35 	colorimage = new ImageRgb();
36 	colorimage->setBOption("verbose", verbose);
37 	
38 	image_file = new xtprobeImageDiskXFile(image_filename, "r");
39 	colorimage->loadImageXFile(image_file);
40 	delete image_file;
41 
42 	if(verbose)
43 	{
44 		print("Image info:\n");
45 		print("   width = %d\n", colorimage->width);
46 		print("   height = %d\n", colorimage->height);
47 		print("   format = %s (%d)\n", colorimage->coding, colorimage->n_planes);
48 	}
49 
50 	colorimage->save("color.ppm");
51 	
52 	delete colorimage;
53 
54 	return(0);
55 }