1 /*! ========================================================================
4 ** $Id: trgt_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
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.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
34 #include <synfig/synfig.h>
35 #include <ETL/stringf>
41 /* === M A C R O S ========================================================= */
43 using namespace synfig;
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_TARGET_INIT(ppm);
50 SYNFIG_TARGET_SET_NAME(ppm,"ppm");
51 SYNFIG_TARGET_SET_EXT(ppm,"ppm");
52 SYNFIG_TARGET_SET_VERSION(ppm,"0.1");
53 SYNFIG_TARGET_SET_CVS_ID(ppm,"$Id: trgt_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
55 /* === M E T H O D S ======================================================= */
57 ppm::ppm(const char *Filename)
69 delete [] color_buffer;
73 ppm::set_rend_desc(RendDesc *given_desc)
75 //given_desc->set_pixel_format(PF_RGB);
77 imagecount=desc.get_frame_start();
78 if(desc.get_frame_end()-desc.get_frame_start()>0)
92 ppm::start_frame(synfig::ProgressCallback *callback)
94 int w=desc.get_w(),h=desc.get_h();
98 if(callback)callback->task(strprintf("(stdout) %d",imagecount).c_str());
99 file=SmartFILE(stdout);
104 newfilename(filename),
105 ext(find(filename.begin(),filename.end(),'.'),filename.end());
106 newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
108 newfilename+=etl::strprintf("%04d",imagecount)+ext;
109 file=SmartFILE(fopen(newfilename.c_str(),"wb"));
110 if(callback)callback->task(newfilename);
114 file=SmartFILE(fopen(filename.c_str(),"wb"));
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()))