1 /*! ========================================================================
4 ** $Id: mptr_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This software and associated documentation
9 ** are CONFIDENTIAL and PROPRIETARY property of
10 ** the above-mentioned copyright holder.
12 ** You may not copy, print, publish, or in any
13 ** other way distribute this software without
14 ** a prior written agreement with
15 ** the copyright holder.
17 ** === N O T E S ===========================================================
19 ** ========================================================================= */
21 /* === H E A D E R S ======================================================= */
31 #include <sinfg/importer.h>
32 #include <sinfg/time.h>
33 #include <sinfg/surface.h>
34 #include <sinfg/general.h>
35 #include <sinfg/smartfile.h>
43 /* === M A C R O S ========================================================= */
45 using namespace sinfg;
49 /* === G L O B A L S ======================================================= */
51 SINFG_IMPORTER_INIT(ppm_mptr);
52 SINFG_IMPORTER_SET_NAME(ppm_mptr,"ppm_mptr");
53 SINFG_IMPORTER_SET_EXT(ppm_mptr,"ppm");
54 SINFG_IMPORTER_SET_VERSION(ppm_mptr,"0.1");
55 SINFG_IMPORTER_SET_CVS_ID(ppm_mptr,"$Id: mptr_ppm.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
57 /* === M E T H O D S ======================================================= */
59 ppm_mptr::ppm_mptr(const char *file)
69 ppm_mptr::get_frame(sinfg::Surface &surface,Time, sinfg::ProgressCallback *cb)
71 SmartFILE file(fopen(filename.c_str(),"rb"));
74 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str()));
80 if(fgetc(file.get())!='P' || fgetc(file.get())!='6')
82 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("%s was not in PPM format"),filename.c_str()));
87 fscanf(file.get(),"%d %d\n",&w,&h);
88 fscanf(file.get(),"%f",&divisor);
94 for(y=0;y<surface.get_h();y++)
95 for(x=0;x<surface.get_w();x++)
99 (float)(unsigned char)fgetc(file)/divisor,
100 (float)(unsigned char)fgetc(file)/divisor,
101 (float)(unsigned char)fgetc(file)/divisor,
105 float r=gamma().r_U8_to_F32((unsigned char)fgetc(file.get()));
106 float g=gamma().g_U8_to_F32((unsigned char)fgetc(file.get()));
107 float b=gamma().b_U8_to_F32((unsigned char)fgetc(file.get()));