1 /* === S Y N F I G ========================================================= */
3 ** \brief ppm Target Module
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
19 ** === N O T E S ===========================================================
21 ** ========================================================================= */
23 /* === H E A D E R S ======================================================= */
35 #include <synfig/synfig.h>
36 #include <ETL/stringf>
42 /* === M A C R O S ========================================================= */
44 using namespace synfig;
48 /* === G L O B A L S ======================================================= */
50 SYNFIG_TARGET_INIT(ppm);
51 SYNFIG_TARGET_SET_NAME(ppm,"ppm");
52 SYNFIG_TARGET_SET_EXT(ppm,"ppm");
53 SYNFIG_TARGET_SET_VERSION(ppm,"0.1");
54 SYNFIG_TARGET_SET_CVS_ID(ppm,"$Id: trgt_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
56 /* === M E T H O D S ======================================================= */
58 ppm::ppm(const char *Filename)
70 delete [] color_buffer;
74 ppm::set_rend_desc(RendDesc *given_desc)
76 //given_desc->set_pixel_format(PF_RGB);
78 imagecount=desc.get_frame_start();
79 if(desc.get_frame_end()-desc.get_frame_start()>0)
93 ppm::start_frame(synfig::ProgressCallback *callback)
95 int w=desc.get_w(),h=desc.get_h();
99 if(callback)callback->task(strprintf("(stdout) %d",imagecount).c_str());
100 file=SmartFILE(stdout);
105 newfilename(filename),
106 ext(find(filename.begin(),filename.end(),'.'),filename.end());
107 newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
109 newfilename+=etl::strprintf("%04d",imagecount)+ext;
110 file=SmartFILE(fopen(newfilename.c_str(),"wb"));
111 if(callback)callback->task(newfilename);
115 file=SmartFILE(fopen(filename.c_str(),"wb"));
116 if(callback)callback->task(filename);
122 fprintf(file.get(), "P6\n");
123 fprintf(file.get(), "%d %d\n", w, h);
124 fprintf(file.get(), "%d\n", 255);
127 buffer=new unsigned char[3*w];
129 delete [] color_buffer;
130 color_buffer=new Color[desc.get_w()];
136 ppm::start_scanline(int scanline)
147 convert_color_format(buffer, color_buffer, desc.get_w(), PF_RGB, gamma());
149 if(!fwrite(buffer,1,desc.get_w()*3,file.get()))