ppmread2.cc

 1 const char *help = "\
 2 progname: ppmread2.cc\n\
 3 code2html: This program reads/write two ppm images in two different ways.\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 "ppmDiskXFile.h"
10 #include "CmdLine.h"
11 
12 using namespace Torch;
13 
14 int main(int argc, char **argv)
15 {
16 	char *image_filename1;
17 	char *image_filename2;
18 	bool verbose;
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 1", &image_filename1, "image filename 1");
29   	cmd.addSCmdArg("image filename 2", &image_filename2, "image filename 2");
30   	cmd.addText("\nOptions:");
31   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
32 
33 	cmd.read(argc, argv);
34 
35 	Image *image = NULL;
36   	DiskXFile *image_file = NULL;
37   	ImageDiskXFile *ppm_file = NULL;
38 
39 	//
40 	// reads image 1 using default format
41 	image = new ImageRgb(image_filename1);
42 	image->setBOption("verbose", verbose);
43 
44 	if(verbose)
45 	{
46 		print("Image info (%s):\n", image_filename1);
47 		print("   width  = %d\n", image->width);
48 		print("   height = %d\n", image->height);
49 		print("   format = %s (%d)\n", image->coding, image->n_planes);
50 	}
51 
52 	//
53 	// save image 1 using default format
54 	image_file = new DiskXFile("test1.ppm", "w");
55 	image->saveXFile(image_file);
56 	delete image_file;
57 
58 	//
59 	// reads image 2 using a specific ImageDiskXFile
60 	ppm_file = new ppmDiskXFile(image_filename2, "r");
61 	image->loadImageXFile(ppm_file);
62 	delete ppm_file;
63 
64 	if(verbose)
65 	{
66 		print("Image info (%s):\n", image_filename2);
67 		print("   width = %d\n", image->width);
68 		print("   height = %d\n", image->height);
69 		print("   format = %s (%d)\n", image->coding, image->n_planes);
70 	}
71 
72 	ppm_file = new ppmDiskXFile("test2.ppm", "w");
73 	image->saveImageXFile(ppm_file);
74 	delete ppm_file;
75 
76 	delete image;
77 
78 	return(0);
79 }