build options to disable image formats WITH_CINEON, WITH_HDR.
[blender-staging.git] / source / blender / editors / space_file / writeimage.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <string.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "IMB_imbuf.h"
35 #include "IMB_imbuf_types.h"
36
37 #include "BLI_blenlib.h"
38
39 #include "DNA_scene_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_space_types.h"
42
43 #include "BKE_context.h"
44 #include "BKE_global.h"
45 #include "BKE_image.h"
46 #include "BKE_utildefines.h"
47
48 #include "RE_pipeline.h"
49
50 #include "file_intern.h"
51
52 /* XXX */
53 static void error(const char *dummy) {}
54 static void waitcursor(int val) {}
55 static void activate_fileselect(int d1, char *d2, char *d3, void *d4) {}
56 static int saveover(const char *dummy) {return 0;}
57 /* XXX */
58
59
60 /* ------------------------------------------------------------------------- */
61
62 /* callback for fileselect to save rendered image, renderresult was checked to exist */
63 static void save_rendered_image_cb_real(char *name, int confirm)
64 {
65         Scene *scene= NULL; // XXX
66         char str[FILE_MAXDIR+FILE_MAXFILE];
67         int overwrite;
68         
69         if(BLI_testextensie(name,".blend")) {
70                 error("Wrong filename");
71                 return;
72         }
73         
74         /* BKE_add_image_extension() checks for if extension was already set */
75         if(scene->r.scemode & R_EXTENSION) 
76                 if(strlen(name)<FILE_MAXDIR+FILE_MAXFILE-5)
77                         BKE_add_image_extension(name, scene->r.imtype);
78
79         strcpy(str, name);
80         BLI_path_abs(str, G.sce);
81
82         if (confirm)
83                 overwrite = saveover(str);
84         else
85                 overwrite = 1;
86         
87         if(overwrite) {
88                 if(scene->r.imtype==R_MULTILAYER) {
89                         Render *re= RE_GetRender(scene->id.name);
90                         RenderResult *rr= RE_AcquireResultRead(re);
91                         if(rr) 
92                                 RE_WriteRenderResult(rr, str, scene->r.quality);
93                         RE_ReleaseResult(re);
94                 }
95                 else {
96                         Render *re= RE_GetRender(scene->id.name);
97                         RenderResult rres;
98                         ImBuf *ibuf;
99                         
100                         RE_AcquireResultImage(re, &rres);
101
102                         waitcursor(1); /* from screen.c */
103
104                         ibuf= IMB_allocImBuf(rres.rectx, rres.recty, scene->r.planes, 0, 0);
105                         ibuf->rect= (unsigned int *)rres.rect32;
106                         ibuf->rect_float= rres.rectf;
107                         ibuf->zbuf_float= rres.rectz;
108                         
109                         /* float factor for random dither, imbuf takes care of it */
110                         ibuf->dither= scene->r.dither_intensity;
111                         
112                         BKE_write_ibuf(scene, ibuf, str, scene->r.imtype, scene->r.subimtype, scene->r.quality);
113                         IMB_freeImBuf(ibuf);    /* imbuf knows rects are not part of ibuf */
114
115                         RE_ReleaseResultImage(re);
116                 }
117                 
118                 strcpy(G.ima, name);
119                 
120                 waitcursor(0);
121         }
122 }
123
124
125 void save_image_filesel_str(Scene *scene, char *str)
126 {
127         switch(scene->r.imtype) {
128 #ifdef WITH_HDR
129                 case R_RADHDR:
130                         strcpy(str, "Save Radiance HDR");
131                         break;
132 #endif
133                 case R_FFMPEG:
134                 case R_H264:
135                 case R_XVID:
136                 case R_THEORA:
137                 case R_PNG:
138                         strcpy(str, "Save PNG");
139                         break;
140 #ifdef WITH_DDS
141                 case R_DDS:
142                         strcpy(str, "Save DDS");
143                         break;
144 #endif
145                 case R_BMP:
146                         strcpy(str, "Save BMP");
147                         break;
148 #ifdef WITH_TIFF
149                 case R_TIFF:
150                         strcpy(str, "Save TIFF");
151                         break;
152 #endif
153 #ifdef WITH_OPENEXR
154                 case R_OPENEXR:
155                         strcpy(str, "Save OpenEXR");
156                         break;
157 #endif
158 #ifdef WITH_CINEON
159                 case R_CINEON:
160                         strcpy(str, "Save Cineon");
161                         break;
162                 case R_DPX:
163                         strcpy(str, "Save DPX");
164                         break;
165 #endif
166                 case R_RAWTGA:
167                         strcpy(str, "Save Raw Targa");
168                         break;
169                 case R_IRIS:
170                         strcpy(str, "Save IRIS");
171                         break;
172                 case R_IRIZ:
173                         strcpy(str, "Save IRIS");
174                         break;
175                 case R_TARGA:
176                         strcpy(str, "Save Targa");
177                         break;
178                 case R_MULTILAYER:
179                         strcpy(str, "Save Multi Layer EXR");
180                         break;
181 #ifdef WITH_OPENJPEG
182                 case R_JP2:
183                         strcpy(str, "Save JPEG2000");
184                         break;
185 #endif
186                         /* default we save jpeg, also for all movie formats */
187                 case R_JPEG90:
188                 case R_AVICODEC:
189                 case R_AVIRAW:
190                 case R_AVIJPEG:
191                 default:
192                         strcpy(str, "Save JPEG");
193                         break;
194         }       
195 }
196
197 static void save_rendered_image_cb(char *name) 
198 {
199         save_rendered_image_cb_real(name, 1);
200 }
201
202 /* no fileselect, no confirm */
203 void BIF_save_rendered_image(char *name)
204 {
205         save_rendered_image_cb_real(name, 0);
206 }
207         
208 /* calls fileselect */
209 void BIF_save_rendered_image_fs(Scene *scene)
210 {
211         Render *re= RE_GetRender(scene->id.name);
212         RenderResult rres;
213         
214         RE_AcquireResultImage(re, &rres);
215
216         if(!rres.rectf && !rres.rect32) {
217                 error("No image rendered");
218         } 
219         else {
220                 char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
221                 
222                 if(G.ima[0]==0) {
223                         strcpy(dir, G.sce);
224                         BLI_splitdirstring(dir, str);
225                         strcpy(G.ima, dir);
226                 }
227                 
228                 save_image_filesel_str(scene, str);
229                 activate_fileselect(FILE_SPECIAL, str, G.ima, save_rendered_image_cb);
230         }
231
232         RE_ReleaseResultImage(re);
233 }
234
235