1 /* === S Y N F I G ========================================================= */
2 /*! \file trgt_openexr.cpp
3 ** \brief exr_trgt Target Module
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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.
22 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
37 #include "trgt_openexr.h"
38 #include <ETL/stringf>
44 /* === M A C R O S ========================================================= */
46 using namespace synfig;
50 /* === G L O B A L S ======================================================= */
52 SYNFIG_TARGET_INIT(exr_trgt);
53 SYNFIG_TARGET_SET_NAME(exr_trgt,"openexr");
54 SYNFIG_TARGET_SET_EXT(exr_trgt,"exr");
55 SYNFIG_TARGET_SET_VERSION(exr_trgt,"1.0.4");
56 SYNFIG_TARGET_SET_CVS_ID(exr_trgt,"$Id$");
58 /* === M E T H O D S ======================================================= */
63 return (bool)exr_file;
66 exr_trgt::exr_trgt(const char *Filename):
77 // OpenEXR uses linear gamma
78 gamma().set_gamma(1.0);
86 if(buffer) delete [] buffer;
88 if(buffer_color) delete [] buffer_color;
93 exr_trgt::set_rend_desc(RendDesc *given_desc)
95 //given_desc->set_pixel_format(PixelFormat((int)PF_RAW_COLOR));
97 imagecount=desc.get_frame_start();
98 if(desc.get_frame_end()-desc.get_frame_start()>0)
106 exr_trgt::start_frame(synfig::ProgressCallback *cb)
108 int w=desc.get_w(),h=desc.get_h();
116 frame_name = (filename_sans_extension(filename) +
117 etl::strprintf(".%04d",imagecount) +
118 filename_extension(filename));
119 if(cb)cb->task(frame_name);
124 if(cb)cb->task(filename);
126 exr_file=new Imf::RgbaOutputFile(frame_name.c_str(),w,h,Imf::WRITE_RGBA,desc.get_pixel_aspect());
127 #ifndef USE_HALF_TYPE
128 if(buffer_color) delete [] buffer_color;
129 buffer_color=new Color[w];
131 //if(buffer) delete [] buffer;
132 //buffer=new Imf::Rgba[w];
133 out_surface.set_wh(w,h);
139 exr_trgt::end_frame()
143 exr_file->setFrameBuffer(out_surface[0],1,desc.get_w());
144 exr_file->writePixels(desc.get_h());
155 exr_trgt::start_scanline(int i)
158 #ifndef USE_HALF_TYPE
159 return reinterpret_cast<Color *>(buffer_color);
161 return reinterpret_cast<Color *>(out_surface[scanline]);
162 // return reinterpret_cast<unsigned char *>(buffer);
167 exr_trgt::end_scanline()
172 #ifndef USE_HALF_TYPE
174 for(i=0;i<desc.get_w();i++)
176 // Imf::Rgba &rgba=buffer[i];
177 Imf::Rgba &rgba=out_surface[scanline][i];
178 Color &color=buffer_color[i];
179 rgba.r=color.get_r();
180 rgba.g=color.get_g();
181 rgba.b=color.get_b();
182 rgba.a=color.get_a();
186 //exr_file->setFrameBuffer(buffer,1,desc.get_w());
187 //exr_file->writePixels(1);