1 /* === S Y N F I G ========================================================= */
2 /*! \file mptr_openexr.cpp
3 ** \brief ppm Target Module
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
34 #include "mptr_openexr.h"
35 #include <synfig/general.h>
36 #include <synfig/surface.h>
37 #include <ETL/stringf>
43 #include <ImfRgbaFile.h>
48 /* === M A C R O S ========================================================= */
50 using namespace synfig;
54 /* === G L O B A L S ======================================================= */
56 SYNFIG_IMPORTER_INIT(exr_mptr);
57 SYNFIG_IMPORTER_SET_NAME(exr_mptr,"openexr");
58 SYNFIG_IMPORTER_SET_EXT(exr_mptr,"exr");
59 SYNFIG_IMPORTER_SET_VERSION(exr_mptr,"0.1");
60 SYNFIG_IMPORTER_SET_CVS_ID(exr_mptr,"$Id$");
62 /* === M E T H O D S ======================================================= */
64 exr_mptr::exr_mptr(const char *file)
74 exr_mptr::get_frame(synfig::Surface &out_surface,Time, synfig::ProgressCallback *cb)
79 Imf::RgbaInputFile in(filename.c_str());
81 int w = in.dataWindow().max.x - in.dataWindow().min.x + 1;
82 int h = in.dataWindow().max.y - in.dataWindow().min.y + 1;
83 //int dx = in.dataWindow().min.x;
84 //int dy = in.dataWindow().min.y;
87 out_surface.set_wh(w,h);
88 in.setFrameBuffer (reinterpret_cast<Imf::Rgba *>(out_surface[0]), 1, w);
90 in.readPixels (in.dataWindow().min.y, in.dataWindow().max.y);
93 etl::surface<Imf::Rgba> in_surface;
94 in_surface.set_wh(w,h);
95 in.setFrameBuffer (reinterpret_cast<Imf::Rgba *>(in_surface[0]), 1, w);
97 in.readPixels (in.dataWindow().min.y, in.dataWindow().max.y);
101 out_surface.set_wh(w,h);
102 for(y=0;y<out_surface.get_h();y++)
103 for(x=0;x<out_surface.get_w();x++)
105 Color &color(out_surface[y][x]);
106 Imf::Rgba &rgba(in_surface[y][x]);
114 catch (const std::exception &e)
116 if(cb)cb->error(e.what());
117 else synfig::error(e.what());