Avoid some warnings for unused parameter.
[synfig.git] / synfig-core / src / modules / mod_openexr / trgt_openexr.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file trgt_openexr.cpp
3 **      \brief exr_trgt Target Module
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **      Copyright (c) 2007 Chris Moore
10 **
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.
15 **
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.
20 **      \endlegal
21 **
22 ** === N O T E S ===========================================================
23 **
24 ** ========================================================================= */
25
26 /* === H E A D E R S ======================================================= */
27
28 #ifdef USING_PCH
29 #       include "pch.h"
30 #else
31 #ifdef HAVE_CONFIG_H
32 #       include <config.h>
33 #endif
34
35 #include "trgt_openexr.h"
36 #include <ETL/stringf>
37 #include <cstdio>
38 #include <algorithm>
39 #include <functional>
40 #endif
41
42 /* === M A C R O S ========================================================= */
43
44 using namespace synfig;
45 using namespace std;
46 using namespace etl;
47
48 /* === G L O B A L S ======================================================= */
49
50 SYNFIG_TARGET_INIT(exr_trgt);
51 SYNFIG_TARGET_SET_NAME(exr_trgt,"openexr");
52 SYNFIG_TARGET_SET_EXT(exr_trgt,"exr");
53 SYNFIG_TARGET_SET_VERSION(exr_trgt,"1.0.4");
54 SYNFIG_TARGET_SET_CVS_ID(exr_trgt,"$Id$");
55
56 /* === M E T H O D S ======================================================= */
57
58 bool
59 exr_trgt::ready()
60 {
61         return (bool)exr_file;
62 }
63
64 exr_trgt::exr_trgt(const char *Filename,
65                                    const synfig::TargetParam& /* params */):
66         multi_image(false),
67         imagecount(0),
68         filename(Filename),
69         exr_file(0)
70 {
71         buffer=0;
72 #ifndef USE_HALF_TYPE
73         buffer_color=0;
74 #endif
75
76         // OpenEXR uses linear gamma
77         gamma().set_gamma(1.0);
78 }
79
80 exr_trgt::~exr_trgt()
81 {
82         if(exr_file)
83                 delete exr_file;
84
85         if(buffer) delete [] buffer;
86 #ifndef USE_HALF_TYPE
87         if(buffer_color) delete [] buffer_color;
88 #endif
89 }
90
91 bool
92 exr_trgt::set_rend_desc(RendDesc *given_desc)
93 {
94         //given_desc->set_pixel_format(PixelFormat((int)PF_RAW_COLOR));
95         desc=*given_desc;
96         imagecount=desc.get_frame_start();
97         if(desc.get_frame_end()-desc.get_frame_start()>0)
98                 multi_image=true;
99         else
100                 multi_image=false;
101         return true;
102 }
103
104 bool
105 exr_trgt::start_frame(synfig::ProgressCallback *cb)
106 {
107         int w=desc.get_w(),h=desc.get_h();
108
109         String frame_name;
110
111         if(exr_file)
112                 delete exr_file;
113         if(multi_image)
114         {
115                 frame_name = (filename_sans_extension(filename) +
116                                           etl::strprintf(".%04d",imagecount) +
117                                           filename_extension(filename));
118                 if(cb)cb->task(frame_name);
119         }
120         else
121         {
122                 frame_name=filename;
123                 if(cb)cb->task(filename);
124         }
125         exr_file=new Imf::RgbaOutputFile(frame_name.c_str(),w,h,Imf::WRITE_RGBA,desc.get_pixel_aspect());
126 #ifndef USE_HALF_TYPE
127         if(buffer_color) delete [] buffer_color;
128         buffer_color=new Color[w];
129 #endif
130         //if(buffer) delete [] buffer;
131         //buffer=new Imf::Rgba[w];
132         out_surface.set_wh(w,h);
133
134         return true;
135 }
136
137 void
138 exr_trgt::end_frame()
139 {
140         if(exr_file)
141         {
142                 exr_file->setFrameBuffer(out_surface[0],1,desc.get_w());
143                 exr_file->writePixels(desc.get_h());
144
145                 delete exr_file;
146         }
147
148         exr_file=0;
149
150         imagecount++;
151 }
152
153 Color *
154 exr_trgt::start_scanline(int i)
155 {
156         scanline=i;
157 #ifndef USE_HALF_TYPE
158         return reinterpret_cast<Color *>(buffer_color);
159 #else
160         return reinterpret_cast<Color *>(out_surface[scanline]);
161 //      return reinterpret_cast<unsigned char *>(buffer);
162 #endif
163 }
164
165 bool
166 exr_trgt::end_scanline()
167 {
168         if(!ready())
169                 return false;
170
171 #ifndef USE_HALF_TYPE
172         int i;
173         for(i=0;i<desc.get_w();i++)
174         {
175 //              Imf::Rgba &rgba=buffer[i];
176                 Imf::Rgba &rgba=out_surface[scanline][i];
177                 Color &color=buffer_color[i];
178                 rgba.r=color.get_r();
179                 rgba.g=color.get_g();
180                 rgba.b=color.get_b();
181                 rgba.a=color.get_a();
182         }
183 #endif
184
185     //exr_file->setFrameBuffer(buffer,1,desc.get_w());
186         //exr_file->writePixels(1);
187
188         return true;
189 }