1 /* === S Y N F I G ========================================================= */
3 ** \brief ppm Target Module
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
38 #include <ETL/stringf>
44 /* === M A C R O S ========================================================= */
46 using namespace synfig;
50 /* === G L O B A L S ======================================================= */
52 SYNFIG_TARGET_INIT(ppm);
53 SYNFIG_TARGET_SET_NAME(ppm,"ppm");
54 SYNFIG_TARGET_SET_EXT(ppm,"ppm");
55 SYNFIG_TARGET_SET_VERSION(ppm,"0.1");
56 SYNFIG_TARGET_SET_CVS_ID(ppm,"$Id$");
58 /* === M E T H O D S ======================================================= */
60 ppm::ppm(const char *Filename)
72 delete [] color_buffer;
76 ppm::set_rend_desc(RendDesc *given_desc)
78 //given_desc->set_pixel_format(PF_RGB);
80 imagecount=desc.get_frame_start();
81 if(desc.get_frame_end()-desc.get_frame_start()>0)
95 ppm::start_frame(synfig::ProgressCallback *callback)
97 int w=desc.get_w(),h=desc.get_h();
101 if(callback)callback->task(strprintf("(stdout) %d",imagecount).c_str());
102 file=SmartFILE(stdout);
106 String newfilename(filename_sans_extension(filename) +
107 etl::strprintf(".%04d",imagecount) +
108 filename_extension(filename));
109 file=SmartFILE(fopen(newfilename.c_str(),POPEN_BINARY_WRITE_TYPE));
110 if(callback)callback->task(newfilename);
114 file=SmartFILE(fopen(filename.c_str(),POPEN_BINARY_WRITE_TYPE));
115 if(callback)callback->task(filename);
121 fprintf(file.get(), "P6\n");
122 fprintf(file.get(), "%d %d\n", w, h);
123 fprintf(file.get(), "%d\n", 255);
126 buffer=new unsigned char[3*w];
128 delete [] color_buffer;
129 color_buffer=new Color[desc.get_w()];
135 ppm::start_scanline(int /*scanline*/)
146 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
148 if(!fwrite(buffer,1,desc.get_w()*3,file.get()))