ppm2pgm.cc

 1 const char *help = "\
 2 progname: ppm2pgm.cc\n\
 3 code2html: This program reads a ppm image and saves it as a pgm.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "ImageGray.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   
19 	// Construct the command line
20   	CmdLine cmd;
21 	cmd.setBOption("write log", false);
22 	
23   	// Put the help line at the beginning
24   	cmd.info(help);
25 
26   	cmd.addText("\nArguments:");
27   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
28   	cmd.addText("\nOptions:");
29   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
30 
31 	cmd.read(argc, argv);
32 
33 
34   	DiskXFile *image_file = NULL;
35 	Image *colorimage = NULL;
36 	Image *grayimage = NULL;
37 
38 	colorimage = new ImageRgb();
39 	colorimage->setBOption("verbose", verbose);
40 	
41 	image_file = new DiskXFile(image_filename, "r");
42 	colorimage->loadXFile(image_file);
43 	delete image_file;
44 
45 	if(verbose)
46 	{
47 		print("Image info:\n");
48 		print("   width = %d\n", colorimage->width);
49 		print("   height = %d\n", colorimage->height);
50 		print("   format = %s (%d)\n", colorimage->coding, colorimage->n_planes);
51 	}
52 
53 	grayimage = new ImageGray();
54 	grayimage->setBOption("verbose", verbose);
55 
56 	grayimage->copyFrom(colorimage);
57 	//grayimage->copyFrom(colorimage->width, colorimage->height, colorimage->pixmap, colorimage->coding);
58 	//grayimage->copyFrom(colorimage->width, colorimage->height, colorimage->data, colorimage->coding);
59 	
60 	image_file = new DiskXFile("test.pgm", "w");
61 	grayimage->saveXFile(image_file);
62 	delete image_file;
63 
64 	delete colorimage;
65 	delete grayimage;
66 
67 	return(0);
68 }