1 /*! ========================================================================
4 ** $Id: mptr_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 ======================================================= */
32 #include <synfig/importer.h>
33 #include <synfig/time.h>
34 #include <synfig/surface.h>
35 #include <synfig/general.h>
36 #include <synfig/smartfile.h>
44 /* === M A C R O S ========================================================= */
46 using namespace synfig;
50 /* === G L O B A L S ======================================================= */
52 SYNFIG_IMPORTER_INIT(ppm_mptr);
53 SYNFIG_IMPORTER_SET_NAME(ppm_mptr,"ppm_mptr");
54 SYNFIG_IMPORTER_SET_EXT(ppm_mptr,"ppm");
55 SYNFIG_IMPORTER_SET_VERSION(ppm_mptr,"0.1");
56 SYNFIG_IMPORTER_SET_CVS_ID(ppm_mptr,"$Id: mptr_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
58 /* === M E T H O D S ======================================================= */
60 ppm_mptr::ppm_mptr(const char *file)
70 ppm_mptr::get_frame(synfig::Surface &surface,Time, synfig::ProgressCallback *cb)
72 SmartFILE file(fopen(filename.c_str(),"rb"));
75 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str()));
81 if(fgetc(file.get())!='P' || fgetc(file.get())!='6')
83 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("%s was not in PPM format"),filename.c_str()));
88 fscanf(file.get(),"%d %d\n",&w,&h);
89 fscanf(file.get(),"%f",&divisor);
95 for(y=0;y<surface.get_h();y++)
96 for(x=0;x<surface.get_w();x++)
100 (float)(unsigned char)fgetc(file)/divisor,
101 (float)(unsigned char)fgetc(file)/divisor,
102 (float)(unsigned char)fgetc(file)/divisor,
106 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file.get()));
107 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file.get()));
108 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file.get()));