78
80
ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
80
82
if (ibuf == NULL) {
81
BKE_reportf(reports, RPT_ERROR, "Couldn't acquire buffer from image");
83
BKE_report(reports, RPT_ERROR, "Could not acquire buffer from image");
84
/* temp swap out the color */
85
const unsigned char imb_planes_back = ibuf->planes;
86
const float dither_back = ibuf->dither;
87
ibuf->planes = scene->r.im_format.planes;
88
ibuf->dither = scene->r.dither_intensity;
89
if (!BKE_write_ibuf(ibuf, path, &scene->r.im_format)) {
90
BKE_reportf(reports, RPT_ERROR, "Couldn't write image: %s", path);
88
write_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, TRUE, TRUE, &scene->view_settings,
89
&scene->display_settings, &scene->r.im_format);
91
write_ibuf->planes = scene->r.im_format.planes;
92
write_ibuf->dither = scene->r.dither_intensity;
94
if (!BKE_imbuf_write(write_ibuf, path, &scene->r.im_format)) {
95
BKE_reportf(reports, RPT_ERROR, "Could not write image '%s'", path);
92
ibuf->planes = imb_planes_back;
93
ibuf->dither = dither_back;
98
if (write_ibuf != ibuf)
99
IMB_freeImBuf(write_ibuf);
96
BKE_image_release_ibuf(image, lock);
102
BKE_image_release_ibuf(image, ibuf, lock);
99
BKE_reportf(reports, RPT_ERROR, "Scene not in context, couldn't get save parameters");
105
BKE_report(reports, RPT_ERROR, "Scene not in context, could not get save parameters");
103
109
static void rna_Image_save(Image *image, ReportList *reports)
105
ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);
111
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
107
113
char filename[FILE_MAX];
108
114
BLI_strncpy(filename, image->name, sizeof(filename));
111
117
if (image->packedfile) {
112
118
if (writePackedFile(reports, image->name, image->packedfile, 0) != RET_OK) {
113
BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could saved packed file to \"%s\"", image->id.name+2, image->name);
119
BKE_reportf(reports, RPT_ERROR, "Image '%s' could not save packed file to '%s'", image->id.name + 2, image->name);
116
122
else if (IMB_saveiff(ibuf, filename, ibuf->flags)) {
119
125
if (image->source == IMA_SRC_GENERATED)
120
126
image->source = IMA_SRC_FILE;
128
IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);
122
130
ibuf->userflags &= ~IB_BITMAPDIRTY;
125
BKE_reportf(reports, RPT_ERROR, "Image \"%s\" could not be saved to \"%s\"", image->id.name+2, image->name);
133
BKE_reportf(reports, RPT_ERROR, "Image '%s' could not be saved to '%s'", image->id.name + 2, image->name);
129
BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any image data", image->id.name+2);
137
BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
140
BKE_image_release_ibuf(image, ibuf, NULL);
133
143
static void rna_Image_pack(Image *image, ReportList *reports, int as_png)
135
ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);
145
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
137
147
if (!as_png && (ibuf && (ibuf->userflags & IB_BITMAPDIRTY))) {
138
BKE_reportf(reports, RPT_ERROR, "Can't pack edited image from disk, only as internal PNG");
148
BKE_report(reports, RPT_ERROR, "Cannot pack edited image from disk, only as internal PNG");
145
155
image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(G.main, &image->id));
159
BKE_image_release_ibuf(image, ibuf, NULL);
150
162
static void rna_Image_unpack(Image *image, ReportList *reports, int method)
170
182
static void rna_Image_update(Image *image, ReportList *reports)
172
ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);
184
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
174
186
if (ibuf == NULL) {
175
BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any image data", image->id.name+2);
187
BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
179
IMB_rect_from_float(ibuf);
192
IMB_rect_from_float(ibuf);
194
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
196
BKE_image_release_ibuf(image, ibuf, NULL);
199
static void rna_Image_scale(Image *image, ReportList *reports, int width, int height)
201
if (!BKE_image_scale(image, width, height)) {
202
BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
182
206
static int rna_Image_gl_load(Image *image, ReportList *reports, int filter, int mag)
191
ibuf = BKE_image_get_ibuf(image, NULL);
215
ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
193
if (ibuf == NULL || ibuf->rect == NULL ) {
194
BKE_reportf(reports, RPT_ERROR, "Image \"%s\" does not have any image data", image->id.name+2);
217
if (ibuf == NULL || ibuf->rect == NULL) {
218
BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2);
219
BKE_image_release_ibuf(image, ibuf, NULL);
195
220
return (int)GL_INVALID_OPERATION;
198
223
/* could be made into a function? */
199
glGenTextures(1, (GLuint*)bind);
224
glGenTextures(1, (GLuint *)bind);
200
225
glBindTexture(GL_TEXTURE_2D, *bind);
202
227
if (filter != GL_NEAREST && filter != GL_LINEAR)
203
228
error = (int)gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
231
/* clean glError buffer */
232
while (glGetError() != GL_NO_ERROR) {}
206
234
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, image->tpageflag & IMA_CLAMP_U ? GL_CLAMP : GL_REPEAT);
207
235
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, image->tpageflag & IMA_CLAMP_V ? GL_CLAMP : GL_REPEAT);
208
236
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)filter);
216
glDeleteTextures(1, (GLuint*)bind);
244
glDeleteTextures(1, (GLuint *)bind);
217
245
image->bindcode = 0;
248
BKE_image_release_ibuf(image, ibuf, NULL);
253
static int rna_Image_gl_touch(Image *image, ReportList *reports, int filter, int mag)
255
unsigned int *bind = &image->bindcode;
256
int error = GL_NO_ERROR;
258
BKE_image_tag_time(image);
261
error = rna_Image_gl_load(image, reports, filter, mag);
238
281
func = RNA_def_function(srna, "save_render", "rna_Image_save_render");
239
282
RNA_def_function_ui_description(func, "Save image to a specific path using a scenes render settings");
240
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
283
RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
241
284
parm = RNA_def_string_file_path(func, "filepath", "", 0, "", "Save path");
242
285
RNA_def_property_flag(parm, PROP_REQUIRED);
243
286
RNA_def_pointer(func, "scene", "Scene", "", "Scene to take image parameters from");
263
306
RNA_def_function_ui_description(func, "Update the display image from the floating point buffer");
264
307
RNA_def_function_flag(func, FUNC_USE_REPORTS);
309
func = RNA_def_function(srna, "scale", "rna_Image_scale");
310
RNA_def_function_ui_description(func, "Scale the image in pixels");
311
RNA_def_function_flag(func, FUNC_USE_REPORTS);
312
parm = RNA_def_int(func, "width", 1, 1, 10000, "", "Width", 1, 10000);
313
RNA_def_property_flag(parm, PROP_REQUIRED);
314
parm = RNA_def_int(func, "height", 1, 1, 10000, "", "Height", 1, 10000);
315
RNA_def_property_flag(parm, PROP_REQUIRED);
317
func = RNA_def_function(srna, "gl_touch", "rna_Image_gl_touch");
318
RNA_def_function_ui_description(func, "Delay the image from being cleaned from the cache due inactivity");
319
RNA_def_function_flag(func, FUNC_USE_REPORTS);
320
RNA_def_int(func, "filter", GL_LINEAR_MIPMAP_NEAREST, -INT_MAX, INT_MAX, "Filter",
321
"The texture minifying function to use if the image wasn't loaded", -INT_MAX, INT_MAX);
322
RNA_def_int(func, "mag", GL_LINEAR, -INT_MAX, INT_MAX, "Magnification",
323
"The texture magnification function to use if the image wasn't loaded", -INT_MAX, INT_MAX);
325
parm = RNA_def_int(func, "error", 0, -INT_MAX, INT_MAX, "Error", "OpenGL error value", -INT_MAX, INT_MAX);
326
RNA_def_function_return(func, parm);
266
328
func = RNA_def_function(srna, "gl_load", "rna_Image_gl_load");
267
329
RNA_def_function_ui_description(func, "Load the image into OpenGL graphics memory");
268
330
RNA_def_function_flag(func, FUNC_USE_REPORTS);