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 ======================================================= */
35 #include <synfig/importer.h>
36 #include <synfig/time.h>
37 #include <synfig/surface.h>
38 #include <synfig/general.h>
39 #include <synfig/smartfile.h>
47 /* === M A C R O S ========================================================= */
49 using namespace synfig;
53 /* === G L O B A L S ======================================================= */
55 SYNFIG_IMPORTER_INIT(ppm_mptr);
56 SYNFIG_IMPORTER_SET_NAME(ppm_mptr,"ppm");
57 SYNFIG_IMPORTER_SET_EXT(ppm_mptr,"ppm");
58 SYNFIG_IMPORTER_SET_VERSION(ppm_mptr,"0.1");
59 SYNFIG_IMPORTER_SET_CVS_ID(ppm_mptr,"$Id$");
61 /* === M E T H O D S ======================================================= */
63 ppm_mptr::ppm_mptr(const char *file)
73 ppm_mptr::get_frame(synfig::Surface &surface,Time, synfig::ProgressCallback *cb)
75 SmartFILE file(fopen(filename.c_str(),"rb"));
78 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str()));
84 if(fgetc(file.get())!='P' || fgetc(file.get())!='6')
86 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("%s was not in PPM format"),filename.c_str()));
91 fscanf(file.get(),"%d %d\n",&w,&h);
92 fscanf(file.get(),"%f",&divisor);
98 for(y=0;y<surface.get_h();y++)
99 for(x=0;x<surface.get_w();x++)
103 (float)(unsigned char)fgetc(file)/divisor,
104 (float)(unsigned char)fgetc(file)/divisor,
105 (float)(unsigned char)fgetc(file)/divisor,
109 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file.get()));
110 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file.get()));
111 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file.get()));