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 ======================================================= */
33 #include <synfig/importer.h>
34 #include <synfig/time.h>
35 #include <synfig/surface.h>
36 #include <synfig/general.h>
37 #include <synfig/smartfile.h>
45 /* === M A C R O S ========================================================= */
47 using namespace synfig;
51 /* === G L O B A L S ======================================================= */
53 SYNFIG_IMPORTER_INIT(ppm_mptr);
54 SYNFIG_IMPORTER_SET_NAME(ppm_mptr,"ppm");
55 SYNFIG_IMPORTER_SET_EXT(ppm_mptr,"ppm");
56 SYNFIG_IMPORTER_SET_VERSION(ppm_mptr,"0.1");
57 SYNFIG_IMPORTER_SET_CVS_ID(ppm_mptr,"$Id: mptr_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
59 /* === M E T H O D S ======================================================= */
61 ppm_mptr::ppm_mptr(const char *file)
71 ppm_mptr::get_frame(synfig::Surface &surface,Time, synfig::ProgressCallback *cb)
73 SmartFILE file(fopen(filename.c_str(),"rb"));
76 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str()));
82 if(fgetc(file.get())!='P' || fgetc(file.get())!='6')
84 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("%s was not in PPM format"),filename.c_str()));
89 fscanf(file.get(),"%d %d\n",&w,&h);
90 fscanf(file.get(),"%f",&divisor);
96 for(y=0;y<surface.get_h();y++)
97 for(x=0;x<surface.get_w();x++)
101 (float)(unsigned char)fgetc(file)/divisor,
102 (float)(unsigned char)fgetc(file)/divisor,
103 (float)(unsigned char)fgetc(file)/divisor,
107 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file.get()));
108 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file.get()));
109 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file.get()));