1 /*! ========================================================================
3 ** exr_trgt Target Module
4 ** $Id: trgt_openexr.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
33 #include "trgt_openexr.h"
34 #include <synfig/synfig.h>
35 #include <ETL/stringf>
41 /* === M A C R O S ========================================================= */
43 using namespace synfig;
47 /* === G L O B A L S ======================================================= */
49 SYNFIG_TARGET_INIT(exr_trgt);
50 SYNFIG_TARGET_SET_NAME(exr_trgt,"openexr");
51 SYNFIG_TARGET_SET_EXT(exr_trgt,"exr");
52 SYNFIG_TARGET_SET_VERSION(exr_trgt,"1.0.4");
53 SYNFIG_TARGET_SET_CVS_ID(exr_trgt,"$Id: trgt_openexr.cpp,v 1.1.1.1 2005/01/04 01:23:14 darco Exp $");
55 /* === M E T H O D S ======================================================= */
60 return (bool)exr_file;
63 exr_trgt::exr_trgt(const char *Filename):
74 // OpenEXR uses linear gamma
75 gamma().set_gamma(1.0);
83 if(buffer) delete [] buffer;
85 if(buffer_color) delete [] buffer_color;
90 exr_trgt::set_rend_desc(RendDesc *given_desc)
92 //given_desc->set_pixel_format(PixelFormat((int)PF_RAW_COLOR));
94 imagecount=desc.get_frame_start();
95 if(desc.get_frame_end()-desc.get_frame_start()>0)
103 exr_trgt::start_frame(synfig::ProgressCallback *cb)
105 int w=desc.get_w(),h=desc.get_h();
114 newfilename(filename),
115 ext(find(filename.begin(),filename.end(),'.'),filename.end());
116 newfilename.erase(find(newfilename.begin(),newfilename.end(),'.'),newfilename.end());
118 newfilename+=etl::strprintf("%04d",imagecount)+ext;
119 frame_name=newfilename;
120 if(cb)cb->task(newfilename);
125 if(cb)cb->task(filename);
127 exr_file=new Imf::RgbaOutputFile(frame_name.c_str(),w,h,Imf::WRITE_RGBA,desc.get_pixel_aspect());
128 #ifndef USE_HALF_TYPE
129 if(buffer_color) delete [] buffer_color;
130 buffer_color=new Color[w];
132 //if(buffer) delete [] buffer;
133 //buffer=new Imf::Rgba[w];
134 out_surface.set_wh(w,h);
140 exr_trgt::end_frame()
144 exr_file->setFrameBuffer(out_surface[0],1,desc.get_w());
145 exr_file->writePixels(desc.get_h());
156 exr_trgt::start_scanline(int i)
159 #ifndef USE_HALF_TYPE
160 return reinterpret_cast<Color *>(buffer_color);
162 return reinterpret_cast<Color *>(out_surface[scanline]);
163 // return reinterpret_cast<unsigned char *>(buffer);
168 exr_trgt::end_scanline()
173 #ifndef USE_HALF_TYPE
175 for(i=0;i<desc.get_w();i++)
177 // Imf::Rgba &rgba=buffer[i];
178 Imf::Rgba &rgba=out_surface[scanline][i];
179 Color &color=buffer_color[i];
180 rgba.r=color.get_r();
181 rgba.g=color.get_g();
182 rgba.b=color.get_b();
183 rgba.a=color.get_a();
187 //exr_file->setFrameBuffer(buffer,1,desc.get_w());
188 //exr_file->writePixels(1);