1 /*! ========================================================================
4 ** $Id: trgt_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
33 #include <sinfg/sinfg.h>
34 #include <ETL/stringf>
40 /* === M A C R O S ========================================================= */
42 using namespace sinfg;
46 /* === G L O B A L S ======================================================= */
48 SINFG_TARGET_INIT(ppm);
49 SINFG_TARGET_SET_NAME(ppm,"ppm");
50 SINFG_TARGET_SET_EXT(ppm,"ppm");
51 SINFG_TARGET_SET_VERSION(ppm,"0.1");
52 SINFG_TARGET_SET_CVS_ID(ppm,"$Id: trgt_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
54 /* === M E T H O D S ======================================================= */
56 ppm::ppm(const char *Filename)
68 delete [] color_buffer;
72 ppm::set_rend_desc(RendDesc *given_desc)
74 //given_desc->set_pixel_format(PF_RGB);
76 imagecount=desc.get_frame_start();
77 if(desc.get_frame_end()-desc.get_frame_start()>0)
91 ppm::start_frame(sinfg::ProgressCallback *callback)
93 int w=desc.get_w(),h=desc.get_h();
97 if(callback)callback->task(strprintf("(stdout) %d",imagecount).c_str());
98 file=SmartFILE(stdout);
103 newfilename(filename),
104 ext(find(filename.begin(),filename.end(),'.'),filename.end());
105 newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
107 newfilename+=etl::strprintf("%04d",imagecount)+ext;
108 file=SmartFILE(fopen(newfilename.c_str(),"wb"));
109 if(callback)callback->task(newfilename);
113 file=SmartFILE(fopen(filename.c_str(),"wb"));
114 if(callback)callback->task(filename);
120 fprintf(file.get(), "P6\n");
121 fprintf(file.get(), "%d %d\n", w, h);
122 fprintf(file.get(), "%d\n", 255);
125 buffer=new unsigned char[3*w];
127 delete [] color_buffer;
128 color_buffer=new Color[desc.get_w()];
134 ppm::start_scanline(int scanline)
145 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
147 if(!fwrite(buffer,1,desc.get_w()*3,file.get()))