1 /* === S Y N F I G ========================================================= */
3 ** \brief ppm Target Module
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
37 #include <ETL/stringf>
43 /* === M A C R O S ========================================================= */
45 using namespace synfig;
49 /* === G L O B A L S ======================================================= */
51 SYNFIG_TARGET_INIT(ppm);
52 SYNFIG_TARGET_SET_NAME(ppm,"ppm");
53 SYNFIG_TARGET_SET_EXT(ppm,"ppm");
54 SYNFIG_TARGET_SET_VERSION(ppm,"0.1");
55 SYNFIG_TARGET_SET_CVS_ID(ppm,"$Id$");
57 /* === M E T H O D S ======================================================= */
59 ppm::ppm(const char *Filename)
71 delete [] color_buffer;
75 ppm::set_rend_desc(RendDesc *given_desc)
77 //given_desc->set_pixel_format(PF_RGB);
79 imagecount=desc.get_frame_start();
80 if(desc.get_frame_end()-desc.get_frame_start()>0)
94 ppm::start_frame(synfig::ProgressCallback *callback)
96 int w=desc.get_w(),h=desc.get_h();
100 if(callback)callback->task(strprintf("(stdout) %d",imagecount).c_str());
101 file=SmartFILE(stdout);
106 newfilename(filename),
107 ext(find(filename.begin(),filename.end(),'.'),filename.end());
108 newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
110 newfilename+=etl::strprintf("%04d",imagecount)+ext;
111 file=SmartFILE(fopen(newfilename.c_str(),"wb"));
112 if(callback)callback->task(newfilename);
116 file=SmartFILE(fopen(filename.c_str(),"wb"));
117 if(callback)callback->task(filename);
123 fprintf(file.get(), "P6\n");
124 fprintf(file.get(), "%d %d\n", w, h);
125 fprintf(file.get(), "%d\n", 255);
128 buffer=new unsigned char[3*w];
130 delete [] color_buffer;
131 color_buffer=new Color[desc.get_w()];
137 ppm::start_scanline(int /*scanline*/)
148 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
150 if(!fwrite(buffer,1,desc.get_w()*3,file.get()))