Avoid some warnings for unused parameter.
[synfig.git] / synfig-core / src / modules / mod_ppm / mptr_ppm.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file mptr_ppm.cpp
3 **      \brief ppm Target Module
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
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.
14 **
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.
19 **      \endlegal
20 **
21 ** === N O T E S ===========================================================
22 **
23 ** ========================================================================= */
24
25 /* === H E A D E R S ======================================================= */
26
27 #ifdef USING_PCH
28 #       include "pch.h"
29 #else
30 #ifdef HAVE_CONFIG_H
31 #       include <config.h>
32 #endif
33
34 #include "mptr_ppm.h"
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>
40
41 #include <cstdio>
42 #include <algorithm>
43 #include <functional>
44
45 #endif
46
47 /* === M A C R O S ========================================================= */
48
49 using namespace synfig;
50 using namespace std;
51 using namespace etl;
52
53 /* === G L O B A L S ======================================================= */
54
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$");
60
61 /* === M E T H O D S ======================================================= */
62
63 ppm_mptr::ppm_mptr(const char *file)
64 {
65         filename=file;
66 }
67
68 ppm_mptr::~ppm_mptr()
69 {
70 }
71
72 bool
73 ppm_mptr::get_frame(synfig::Surface &surface, const synfig::RendDesc &/*renddesc*/, Time, synfig::ProgressCallback *cb)
74 {
75         SmartFILE file(fopen(filename.c_str(),"rb"));
76         if(!file)
77         {
78                 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("Unable to open %s"),filename.c_str()));
79                 return false;
80         }
81         int w,h;
82         float divisor;
83
84         if(fgetc(file.get())!='P' || fgetc(file.get())!='6')
85         {
86                 if(cb)cb->error("pp_mptr::GetFrame(): "+strprintf(_("%s was not in PPM format"),filename.c_str()));
87                 return false;
88         }
89
90         fgetc(file.get());
91         fscanf(file.get(),"%d %d\n",&w,&h);
92         fscanf(file.get(),"%f",&divisor);
93         fgetc(file.get());
94
95         int x;
96         int y;
97         surface.set_wh(w,h);
98         for(y=0;y<surface.get_h();y++)
99                 for(x=0;x<surface.get_w();x++)
100                 {
101 /*
102                         surface[y][x]=Color(
103                                 (float)(unsigned char)fgetc(file)/divisor,
104                                 (float)(unsigned char)fgetc(file)/divisor,
105                                 (float)(unsigned char)fgetc(file)/divisor,
106                                 1.0
107                         );
108 */
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()));
112                         surface[y][x]=Color(
113                                 r,
114                                 g,
115                                 b,
116                                 1.0
117                         );
118                 }
119         return true;
120 }