Avoid some warnings for unused parameter.
[synfig.git] / synfig-core / src / modules / mod_openexr / mptr_openexr.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file mptr_openexr.cpp
3 **      \brief ppm Target Module
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
11 **      This package is free software; you can redistribute it and/or
12 **      modify it under the terms of the GNU General Public License as
13 **      published by the Free Software Foundation; either version 2 of
14 **      the License, or (at your option) any later version.
15 **
16 **      This package is distributed in the hope that it will be useful,
17 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
18 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 **      General Public License for more details.
20 **      \endlegal
21 **
22 ** === N O T E S ===========================================================
23 **
24 ** ========================================================================= */
25
26 /* === H E A D E R S ======================================================= */
27
28 #ifdef USING_PCH
29 #       include "pch.h"
30 #else
31 #ifdef HAVE_CONFIG_H
32 #       include <config.h>
33 #endif
34
35 #include "mptr_openexr.h"
36 #include <synfig/general.h>
37 #include <synfig/surface.h>
38 #include <ETL/stringf>
39 #include <cstdio>
40 #include <algorithm>
41 #include <functional>
42
43 #include <ImfArray.h>
44 #include <ImfRgbaFile.h>
45 #include <exception>
46
47 #endif
48
49 /* === M A C R O S ========================================================= */
50
51 using namespace synfig;
52 using namespace std;
53 using namespace etl;
54
55 /* === G L O B A L S ======================================================= */
56
57 SYNFIG_IMPORTER_INIT(exr_mptr);
58 SYNFIG_IMPORTER_SET_NAME(exr_mptr,"openexr");
59 SYNFIG_IMPORTER_SET_EXT(exr_mptr,"exr");
60 SYNFIG_IMPORTER_SET_VERSION(exr_mptr,"0.1");
61 SYNFIG_IMPORTER_SET_CVS_ID(exr_mptr,"$Id$");
62
63 /* === M E T H O D S ======================================================= */
64
65 exr_mptr::exr_mptr(const char *file)
66 {
67         filename=file;
68 }
69
70 exr_mptr::~exr_mptr()
71 {
72 }
73
74 bool
75 exr_mptr::get_frame(synfig::Surface &out_surface, const synfig::RendDesc &/*renddesc*/, Time, synfig::ProgressCallback *cb)
76 {
77     try
78     {
79
80         Imf::RgbaInputFile in(filename.c_str());
81
82     int w = in.dataWindow().max.x - in.dataWindow().min.x + 1;
83     int h = in.dataWindow().max.y - in.dataWindow().min.y + 1;
84     //int dx = in.dataWindow().min.x;
85     //int dy = in.dataWindow().min.y;
86
87 #ifdef USE_HALF_TYPE
88     out_surface.set_wh(w,h);
89         in.setFrameBuffer (reinterpret_cast<Imf::Rgba *>(out_surface[0]), 1, w);
90
91         in.readPixels (in.dataWindow().min.y, in.dataWindow().max.y);
92
93 #else
94         etl::surface<Imf::Rgba> in_surface;
95         in_surface.set_wh(w,h);
96         in.setFrameBuffer (reinterpret_cast<Imf::Rgba *>(in_surface[0]), 1, w);
97
98         in.readPixels (in.dataWindow().min.y, in.dataWindow().max.y);
99
100         int x;
101         int y;
102         out_surface.set_wh(w,h);
103         for(y=0;y<out_surface.get_h();y++)
104                 for(x=0;x<out_surface.get_w();x++)
105                 {
106                         Color &color(out_surface[y][x]);
107                         Imf::Rgba &rgba(in_surface[y][x]);
108                         color.set_r(rgba.r);
109                         color.set_g(rgba.g);
110                         color.set_b(rgba.b);
111                         color.set_a(rgba.a);
112                 }
113 #endif
114         }
115         catch (const std::exception &e)
116     {
117                 if(cb)cb->error(e.what());
118                 else synfig::error(e.what());
119                 return false;
120     }
121
122         return true;
123 }