ppm2jpeg.cc

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