Commenting out code from commit 22457 by Genscher for PointCache.
[blender.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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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_image_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_screen_types.h"
42 #include "DNA_space_types.h"
43 #include "DNA_texture_types.h"
44
45 #include "BKE_context.h"
46 #include "BKE_global.h"
47 #include "BKE_image.h"
48 #include "BKE_utildefines.h"
49
50 #include "RE_pipeline.h"
51
52 #include "file_intern.h"
53
54 /* XXX */
55 static void error() {}
56 static void waitcursor(int val) {}
57 static void activate_fileselect() {}
58 static int saveover() {return 0;}
59 /* XXX */
60
61
62 /* ------------------------------------------------------------------------- */
63
64
65 void BIF_save_envmap(Scene *scene, EnvMap *env, char *str)
66 {
67         ImBuf *ibuf;
68 /*      extern rectcpy(); */
69         int dx;
70         
71         /* all interactive stuff is handled in buttons.c */
72         if(env->cube[0]==NULL) return;
73                 
74         dx= env->cube[0]->x;
75         ibuf= IMB_allocImBuf(3*dx, 2*dx, 24, IB_rect, 0);
76         
77         IMB_rectcpy(ibuf, env->cube[0], 0, 0, 0, 0, dx, dx);
78         IMB_rectcpy(ibuf, env->cube[1], dx, 0, 0, 0, dx, dx);
79         IMB_rectcpy(ibuf, env->cube[2], 2*dx, 0, 0, 0, dx, dx);
80         IMB_rectcpy(ibuf, env->cube[3], 0, dx, 0, 0, dx, dx);
81         IMB_rectcpy(ibuf, env->cube[4], dx, dx, 0, 0, dx, dx);
82         IMB_rectcpy(ibuf, env->cube[5], 2*dx, dx, 0, 0, dx, dx);
83         
84         BKE_write_ibuf(scene, ibuf, str, scene->r.imtype, scene->r.subimtype, scene->r.quality);
85         IMB_freeImBuf(ibuf);
86 }
87
88
89
90 /* callback for fileselect to save rendered image, renderresult was checked to exist */
91 static void save_rendered_image_cb_real(char *name, int confirm)
92 {
93         Scene *scene= NULL; // XXX
94         char str[FILE_MAXDIR+FILE_MAXFILE];
95         int overwrite;
96         
97         if(BLI_testextensie(name,".blend")) {
98                 error("Wrong filename");
99                 return;
100         }
101         
102         /* BKE_add_image_extension() checks for if extension was already set */
103         if(scene->r.scemode & R_EXTENSION) 
104                 if(strlen(name)<FILE_MAXDIR+FILE_MAXFILE-5)
105                         BKE_add_image_extension(scene, name, scene->r.imtype);
106
107         strcpy(str, name);
108         BLI_convertstringcode(str, G.sce);
109         BLI_convertstringframe(str, scene->r.cfra); /* TODO - is this even used? */
110
111         if (confirm)
112                 overwrite = saveover(str);
113         else
114                 overwrite = 1;
115         
116         if(overwrite) {
117                 if(scene->r.imtype==R_MULTILAYER) {
118                         RenderResult *rr= RE_GetResult(RE_GetRender(scene->id.name));
119                         if(rr) 
120                                 RE_WriteRenderResult(rr, str, scene->r.quality);
121                 }
122                 else {
123                         RenderResult rres;
124                         ImBuf *ibuf;
125                         
126                         RE_GetResultImage(RE_GetRender(scene->id.name), &rres);
127
128                         waitcursor(1); /* from screen.c */
129
130                         ibuf= IMB_allocImBuf(rres.rectx, rres.recty, scene->r.planes, 0, 0);
131                         ibuf->rect= (unsigned int *)rres.rect32;
132                         ibuf->rect_float= rres.rectf;
133                         ibuf->zbuf_float= rres.rectz;
134                         
135                         /* float factor for random dither, imbuf takes care of it */
136                         ibuf->dither= scene->r.dither_intensity;
137                         
138                         BKE_write_ibuf(scene, ibuf, str, scene->r.imtype, scene->r.subimtype, scene->r.quality);
139                         IMB_freeImBuf(ibuf);    /* imbuf knows rects are not part of ibuf */
140                 }
141                 
142                 strcpy(G.ima, name);
143                 
144                 waitcursor(0);
145         }
146 }
147
148
149 void save_image_filesel_str(Scene *scene, char *str)
150 {
151         switch(scene->r.imtype) {
152                 case R_RADHDR:
153                         strcpy(str, "Save Radiance HDR");
154                         break;
155                 case R_FFMPEG:
156                 case R_H264:
157                 case R_XVID:
158                 case R_THEORA:
159                 case R_PNG:
160                         strcpy(str, "Save PNG");
161                         break;
162 #ifdef WITH_DDS
163                 case R_DDS:
164                         strcpy(str, "Save DDS");
165                         break;
166 #endif
167                 case R_BMP:
168                         strcpy(str, "Save BMP");
169                         break;
170                 case R_TIFF:
171                         if (G.have_libtiff)
172                                 strcpy(str, "Save TIFF");
173                         break;
174 #ifdef WITH_OPENEXR
175                 case R_OPENEXR:
176                         strcpy(str, "Save OpenEXR");
177                         break;
178 #endif
179                 case R_CINEON:
180                         strcpy(str, "Save Cineon");
181                         break;
182                 case R_DPX:
183                         strcpy(str, "Save DPX");
184                         break;
185                 case R_RAWTGA:
186                         strcpy(str, "Save Raw Targa");
187                         break;
188                 case R_IRIS:
189                         strcpy(str, "Save IRIS");
190                         break;
191                 case R_IRIZ:
192                         strcpy(str, "Save IRIS");
193                         break;
194                 case R_HAMX:
195                         strcpy(str, "Save HAMX");
196                         break;
197                 case R_TARGA:
198                         strcpy(str, "Save Targa");
199                         break;
200                 case R_MULTILAYER:
201                         strcpy(str, "Save Multi Layer EXR");
202                         break;
203 #ifdef WITH_OPENJPEG
204                 case R_JP2:
205                         strcpy(str, "Save JPEG2000");
206                         break;
207 #endif
208                         /* default we save jpeg, also for all movie formats */
209                 case R_JPEG90:
210                 case R_MOVIE:
211                 case R_AVICODEC:
212                 case R_AVIRAW:
213                 case R_AVIJPEG:
214                 default:
215                         strcpy(str, "Save JPEG");
216                         break;
217         }       
218 }
219
220 static void save_rendered_image_cb(char *name) 
221 {
222         save_rendered_image_cb_real(name, 1);
223 }
224
225 /* no fileselect, no confirm */
226 void BIF_save_rendered_image(char *name)
227 {
228         save_rendered_image_cb_real(name, 0);
229 }
230         
231 /* calls fileselect */
232 void BIF_save_rendered_image_fs(Scene *scene)
233 {
234         RenderResult rres;
235         
236         RE_GetResultImage(RE_GetRender(scene->id.name), &rres);
237
238         if(!rres.rectf && !rres.rect32) {
239                 error("No image rendered");
240         } 
241         else {
242                 char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
243                 
244                 if(G.ima[0]==0) {
245                         strcpy(dir, G.sce);
246                         BLI_splitdirstring(dir, str);
247                         strcpy(G.ima, dir);
248                 }
249                 
250                 save_image_filesel_str(scene, str);
251                 activate_fileselect(FILE_SPECIAL, str, G.ima, save_rendered_image_cb);
252         }
253 }
254
255