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
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 ======================================================= */
36 #include "trgt_openexr.h"
37 #include <synfig/synfig.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();
117 newfilename(filename),
118 ext(find(filename.begin(),filename.end(),'.'),filename.end());
119 newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
121 newfilename+=etl::strprintf("%04d",imagecount)+ext;
122 frame_name=newfilename;
123 if(cb)cb->task(newfilename);
128 if(cb)cb->task(filename);
130 exr_file=new Imf::RgbaOutputFile(frame_name.c_str(),w,h,Imf::WRITE_RGBA,desc.get_pixel_aspect());
131 #ifndef USE_HALF_TYPE
132 if(buffer_color) delete [] buffer_color;
133 buffer_color=new Color[w];
135 //if(buffer) delete [] buffer;
136 //buffer=new Imf::Rgba[w];
137 out_surface.set_wh(w,h);
143 exr_trgt::end_frame()
147 exr_file->setFrameBuffer(out_surface[0],1,desc.get_w());
148 exr_file->writePixels(desc.get_h());
159 exr_trgt::start_scanline(int i)
162 #ifndef USE_HALF_TYPE
163 return reinterpret_cast<Color *>(buffer_color);
165 return reinterpret_cast<Color *>(out_surface[scanline]);
166 // return reinterpret_cast<unsigned char *>(buffer);
171 exr_trgt::end_scanline()
176 #ifndef USE_HALF_TYPE
178 for(i=0;i<desc.get_w();i++)
180 // Imf::Rgba &rgba=buffer[i];
181 Imf::Rgba &rgba=out_surface[scanline][i];
182 Color &color=buffer_color[i];
183 rgba.r=color.get_r();
184 rgba.g=color.get_g();
185 rgba.b=color.get_b();
186 rgba.a=color.get_a();
190 //exr_file->setFrameBuffer(buffer,1,desc.get_w());
191 //exr_file->writePixels(1);