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 <ETL/stringf>
43 /* === M A C R O S ========================================================= */
45 using namespace synfig;
49 /* === G L O B A L S ======================================================= */
51 SYNFIG_TARGET_INIT(exr_trgt);
52 SYNFIG_TARGET_SET_NAME(exr_trgt,"openexr");
53 SYNFIG_TARGET_SET_EXT(exr_trgt,"exr");
54 SYNFIG_TARGET_SET_VERSION(exr_trgt,"1.0.4");
55 SYNFIG_TARGET_SET_CVS_ID(exr_trgt,"$Id$");
57 /* === M E T H O D S ======================================================= */
62 return (bool)exr_file;
65 exr_trgt::exr_trgt(const char *Filename):
76 // OpenEXR uses linear gamma
77 gamma().set_gamma(1.0);
85 if(buffer) delete [] buffer;
87 if(buffer_color) delete [] buffer_color;
92 exr_trgt::set_rend_desc(RendDesc *given_desc)
94 //given_desc->set_pixel_format(PixelFormat((int)PF_RAW_COLOR));
96 imagecount=desc.get_frame_start();
97 if(desc.get_frame_end()-desc.get_frame_start()>0)
105 exr_trgt::start_frame(synfig::ProgressCallback *cb)
107 int w=desc.get_w(),h=desc.get_h();
116 newfilename(filename),
117 ext(find(filename.begin(),filename.end(),'.'),filename.end());
118 newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
120 newfilename+=etl::strprintf("%04d",imagecount)+ext;
121 frame_name=newfilename;
122 if(cb)cb->task(newfilename);
127 if(cb)cb->task(filename);
129 exr_file=new Imf::RgbaOutputFile(frame_name.c_str(),w,h,Imf::WRITE_RGBA,desc.get_pixel_aspect());
130 #ifndef USE_HALF_TYPE
131 if(buffer_color) delete [] buffer_color;
132 buffer_color=new Color[w];
134 //if(buffer) delete [] buffer;
135 //buffer=new Imf::Rgba[w];
136 out_surface.set_wh(w,h);
142 exr_trgt::end_frame()
146 exr_file->setFrameBuffer(out_surface[0],1,desc.get_w());
147 exr_file->writePixels(desc.get_h());
158 exr_trgt::start_scanline(int i)
161 #ifndef USE_HALF_TYPE
162 return reinterpret_cast<Color *>(buffer_color);
164 return reinterpret_cast<Color *>(out_surface[scanline]);
165 // return reinterpret_cast<unsigned char *>(buffer);
170 exr_trgt::end_scanline()
175 #ifndef USE_HALF_TYPE
177 for(i=0;i<desc.get_w();i++)
179 // Imf::Rgba &rgba=buffer[i];
180 Imf::Rgba &rgba=out_surface[scanline][i];
181 Color &color=buffer_color[i];
182 rgba.r=color.get_r();
183 rgba.g=color.get_g();
184 rgba.b=color.get_b();
185 rgba.a=color.get_a();
189 //exr_file->setFrameBuffer(buffer,1,desc.get_w());
190 //exr_file->writePixels(1);