Welcome to mirror list, hosted at ThFree Co, Russian Federation.

writeimage.c « space_file « editors « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 750cf98727abc6c198d4df73e59089598c44673b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
 * $Id$
 *
 * ***** BEGIN GPL LICENSE BLOCK *****
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
 * All rights reserved.
 *
 * The Original Code is: all of this file.
 *
 * Contributor(s): none yet.
 *
 * ***** END GPL LICENSE BLOCK *****
 */

#include <string.h>


#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"

#include "BLI_blenlib.h"

#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"

#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_image.h"

#include "RE_pipeline.h"

#include "file_intern.h"

/* XXX */
static void error(const char *UNUSED(dummy)) {}
static void waitcursor(int UNUSED(val)) {}
static void activate_fileselect(int UNUSED(d1), char *UNUSED(d2), char *UNUSED(d3), void *UNUSED(d4)) {}
static int saveover(const char *UNUSED(dummy)) {return 0;}
/* XXX */


/* ------------------------------------------------------------------------- */

/* callback for fileselect to save rendered image, renderresult was checked to exist */
static void save_rendered_image_cb_real(char *name, int confirm)
{
	Scene *scene= NULL; // XXX
	char str[FILE_MAXDIR+FILE_MAXFILE];
	int overwrite;
	
	if(BLI_testextensie(name,".blend")) {
		error("Wrong filename");
		return;
	}
	
	/* BKE_add_image_extension() checks for if extension was already set */
	if(scene->r.scemode & R_EXTENSION) 
		if(strlen(name)<FILE_MAXDIR+FILE_MAXFILE-5)
			BKE_add_image_extension(name, scene->r.imtype);

	strcpy(str, name);
	BLI_path_abs(str, G.main->name);

	if (confirm)
		overwrite = saveover(str);
	else
		overwrite = 1;
	
	if(overwrite) {
		if(scene->r.imtype==R_MULTILAYER) {
			Render *re= RE_GetRender(scene->id.name);
			RenderResult *rr= RE_AcquireResultRead(re);
			if(rr) 
				RE_WriteRenderResult(rr, str, scene->r.quality);
			RE_ReleaseResult(re);
		}
		else {
			Render *re= RE_GetRender(scene->id.name);
			RenderResult rres;
			ImBuf *ibuf;
			
			RE_AcquireResultImage(re, &rres);

			waitcursor(1); /* from screen.c */

			ibuf= IMB_allocImBuf(rres.rectx, rres.recty, scene->r.planes, 0);
			ibuf->rect= (unsigned int *)rres.rect32;
			ibuf->rect_float= rres.rectf;
			ibuf->zbuf_float= rres.rectz;
			
			/* float factor for random dither, imbuf takes care of it */
			ibuf->dither= scene->r.dither_intensity;
			
			BKE_write_ibuf(scene, ibuf, str, scene->r.imtype, scene->r.subimtype, scene->r.quality);
			IMB_freeImBuf(ibuf);	/* imbuf knows rects are not part of ibuf */

			RE_ReleaseResultImage(re);
		}
		
		strcpy(G.ima, name);
		
		waitcursor(0);
	}
}


void save_image_filesel_str(Scene *scene, char *str)
{
	switch(scene->r.imtype) {
#ifdef WITH_HDR
		case R_RADHDR:
			strcpy(str, "Save Radiance HDR");
			break;
#endif
		case R_FFMPEG:
		case R_H264:
		case R_XVID:
		case R_THEORA:
		case R_PNG:
			strcpy(str, "Save PNG");
			break;
#ifdef WITH_DDS
		case R_DDS:
			strcpy(str, "Save DDS");
			break;
#endif
		case R_BMP:
			strcpy(str, "Save BMP");
			break;
#ifdef WITH_TIFF
		case R_TIFF:
			strcpy(str, "Save TIFF");
			break;
#endif
#ifdef WITH_OPENEXR
		case R_OPENEXR:
			strcpy(str, "Save OpenEXR");
			break;
#endif
#ifdef WITH_CINEON
		case R_CINEON:
			strcpy(str, "Save Cineon");
			break;
		case R_DPX:
			strcpy(str, "Save DPX");
			break;
#endif
		case R_RAWTGA:
			strcpy(str, "Save Raw Targa");
			break;
		case R_IRIS:
			strcpy(str, "Save IRIS");
			break;
		case R_IRIZ:
			strcpy(str, "Save IRIS");
			break;
		case R_TARGA:
			strcpy(str, "Save Targa");
			break;
		case R_MULTILAYER:
			strcpy(str, "Save Multi Layer EXR");
			break;
#ifdef WITH_OPENJPEG
		case R_JP2:
			strcpy(str, "Save JPEG2000");
			break;
#endif
			/* default we save jpeg, also for all movie formats */
		case R_JPEG90:
		case R_AVICODEC:
		case R_AVIRAW:
		case R_AVIJPEG:
		default:
			strcpy(str, "Save JPEG");
			break;
	}	
}

static void save_rendered_image_cb(char *name) 
{
	save_rendered_image_cb_real(name, 1);
}

/* no fileselect, no confirm */
void BIF_save_rendered_image(char *name)
{
	save_rendered_image_cb_real(name, 0);
}
	
/* calls fileselect */
void BIF_save_rendered_image_fs(Scene *scene)
{
	Render *re= RE_GetRender(scene->id.name);
	RenderResult rres;
	
	RE_AcquireResultImage(re, &rres);

	if(!rres.rectf && !rres.rect32) {
		error("No image rendered");
	} 
	else {
		char dir[FILE_MAXDIR * 2], str[FILE_MAXFILE * 2];
		
		if(G.ima[0]==0) {
			strcpy(dir, G.main->name);
			BLI_splitdirstring(dir, str);
			strcpy(G.ima, dir);
		}
		
		save_image_filesel_str(scene, str);
		activate_fileselect(FILE_SPECIAL, str, G.ima, save_rendered_image_cb);
	}

	RE_ReleaseResultImage(re);
}