4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
32 #include "MEM_guardedalloc.h"
34 #include "IMB_imbuf.h"
35 #include "IMB_imbuf_types.h"
37 #include "BLI_blenlib.h"
39 #include "DNA_scene_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_space_types.h"
43 #include "BKE_context.h"
44 #include "BKE_global.h"
45 #include "BKE_image.h"
46 #include "BKE_utildefines.h"
48 #include "RE_pipeline.h"
50 #include "file_intern.h"
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;}
60 /* ------------------------------------------------------------------------- */
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)
65 Scene *scene= NULL; // XXX
66 char str[FILE_MAXDIR+FILE_MAXFILE];
69 if(BLI_testextensie(name,".blend")) {
70 error("Wrong filename");
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);
80 BLI_path_abs(str, G.sce);
83 overwrite = saveover(str);
88 if(scene->r.imtype==R_MULTILAYER) {
89 Render *re= RE_GetRender(scene->id.name);
90 RenderResult *rr= RE_AcquireResultRead(re);
92 RE_WriteRenderResult(rr, str, scene->r.quality);
96 Render *re= RE_GetRender(scene->id.name);
100 RE_AcquireResultImage(re, &rres);
102 waitcursor(1); /* from screen.c */
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;
109 /* float factor for random dither, imbuf takes care of it */
110 ibuf->dither= scene->r.dither_intensity;
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 */
115 RE_ReleaseResultImage(re);
125 void save_image_filesel_str(Scene *scene, char *str)
127 switch(scene->r.imtype) {
129 strcpy(str, "Save Radiance HDR");
136 strcpy(str, "Save PNG");
140 strcpy(str, "Save DDS");
144 strcpy(str, "Save BMP");
148 strcpy(str, "Save TIFF");
153 strcpy(str, "Save OpenEXR");
157 strcpy(str, "Save Cineon");
160 strcpy(str, "Save DPX");
163 strcpy(str, "Save Raw Targa");
166 strcpy(str, "Save IRIS");
169 strcpy(str, "Save IRIS");
172 strcpy(str, "Save HAMX");
175 strcpy(str, "Save Targa");
178 strcpy(str, "Save Multi Layer EXR");
182 strcpy(str, "Save JPEG2000");
185 /* default we save jpeg, also for all movie formats */
191 strcpy(str, "Save JPEG");
196 static void save_rendered_image_cb(char *name)
198 save_rendered_image_cb_real(name, 1);
201 /* no fileselect, no confirm */
202 void BIF_save_rendered_image(char *name)
204 save_rendered_image_cb_real(name, 0);
207 /* calls fileselect */
208 void BIF_save_rendered_image_fs(Scene *scene)
210 Render *re= RE_GetRender(scene->id.name);
213 RE_AcquireResultImage(re, &rres);
215 if(!rres.rectf && !rres.rect32) {
216 error("No image rendered");
219 char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
223 BLI_splitdirstring(dir, str);
227 save_image_filesel_str(scene, str);
228 activate_fileselect(FILE_SPECIAL, str, G.ima, save_rendered_image_cb);
231 RE_ReleaseResultImage(re);