~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/makesrna/intern/rna_image_api.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *
3
2
 * ***** BEGIN GPL LICENSE BLOCK *****
4
3
 *
5
4
 * This program is free software; you can redistribute it and/or
42
41
 
43
42
#include "BIF_gl.h"
44
43
 
 
44
#include "rna_internal.h"  /* own include */
 
45
 
45
46
#ifdef RNA_RUNTIME
46
47
 
47
48
#include "BKE_image.h"
51
52
#include "BKE_global.h" /* grr: G.main->name */
52
53
 
53
54
#include "IMB_imbuf.h"
 
55
#include "IMB_colormanagement.h"
54
56
 
55
57
#include "BIF_gl.h"
56
58
#include "GPU_draw.h"
78
80
                ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock);
79
81
 
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");
82
84
                }
83
85
                else {
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);
 
86
                        ImBuf *write_ibuf;
 
87
 
 
88
                        write_ibuf = IMB_colormanagement_imbuf_for_write(ibuf, TRUE, TRUE, &scene->view_settings,
 
89
                                                                         &scene->display_settings, &scene->r.im_format);
 
90
 
 
91
                        write_ibuf->planes = scene->r.im_format.planes;
 
92
                        write_ibuf->dither = scene->r.dither_intensity;
 
93
 
 
94
                        if (!BKE_imbuf_write(write_ibuf, path, &scene->r.im_format)) {
 
95
                                BKE_reportf(reports, RPT_ERROR, "Could not write image '%s'", path);
91
96
                        }
92
 
                        ibuf->planes = imb_planes_back;
93
 
                        ibuf->dither = dither_back;
 
97
 
 
98
                        if (write_ibuf != ibuf)
 
99
                                IMB_freeImBuf(write_ibuf);
94
100
                }
95
101
 
96
 
                BKE_image_release_ibuf(image, lock);
 
102
                BKE_image_release_ibuf(image, ibuf, lock);
97
103
        }
98
104
        else {
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");
100
106
        }
101
107
}
102
108
 
103
109
static void rna_Image_save(Image *image, ReportList *reports)
104
110
{
105
 
        ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);
 
111
        ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
106
112
        if (ibuf) {
107
113
                char filename[FILE_MAX];
108
114
                BLI_strncpy(filename, image->name, sizeof(filename));
110
116
 
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);
114
120
                        }
115
121
                }
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;
121
127
 
 
128
                        IMB_colormanagment_colorspace_from_ibuf_ftype(&image->colorspace_settings, ibuf);
 
129
 
122
130
                        ibuf->userflags &= ~IB_BITMAPDIRTY;
123
131
                }
124
132
                else {
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);
126
134
                }
127
135
        }
128
136
        else {
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);
130
138
        }
 
139
 
 
140
        BKE_image_release_ibuf(image, ibuf, NULL);
131
141
}
132
142
 
133
143
static void rna_Image_pack(Image *image, ReportList *reports, int as_png)
134
144
{
135
 
        ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);
 
145
        ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
136
146
 
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");
139
149
        }
140
150
        else {
141
151
                if (as_png) {
145
155
                        image->packedfile = newPackedFile(reports, image->name, ID_BLEND_PATH(G.main, &image->id));
146
156
                }
147
157
        }
 
158
 
 
159
        BKE_image_release_ibuf(image, ibuf, NULL);
148
160
}
149
161
 
150
162
static void rna_Image_unpack(Image *image, ReportList *reports, int method)
158
170
        }
159
171
        else {
160
172
                /* reports its own error on failure */
161
 
                unpackImage (reports, image, method);
 
173
                unpackImage(reports, image, method);
162
174
        }
163
175
}
164
176
 
169
181
 
170
182
static void rna_Image_update(Image *image, ReportList *reports)
171
183
{
172
 
        ImBuf *ibuf = BKE_image_get_ibuf(image, NULL);
 
184
        ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
173
185
 
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);
176
188
                return;
177
189
        }
178
190
 
179
 
        IMB_rect_from_float(ibuf);
 
191
        if (ibuf->rect)
 
192
                IMB_rect_from_float(ibuf);
 
193
 
 
194
        ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
 
195
 
 
196
        BKE_image_release_ibuf(image, ibuf, NULL);
 
197
}
 
198
 
 
199
static void rna_Image_scale(Image *image, ReportList *reports, int width, int height)
 
200
{
 
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);
 
203
        }
180
204
}
181
205
 
182
206
static int rna_Image_gl_load(Image *image, ReportList *reports, int filter, int mag)
188
212
        if (*bind)
189
213
                return error;
190
214
 
191
 
        ibuf = BKE_image_get_ibuf(image, NULL);
 
215
        ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
192
216
 
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;
196
221
        }
197
222
 
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);
201
226
 
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);
204
229
 
205
230
        if (!error) {
 
231
                /* clean glError buffer */
 
232
                while (glGetError() != GL_NO_ERROR) {}
 
233
 
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);
213
241
        }
214
242
 
215
243
        if (error) {
216
 
                glDeleteTextures(1, (GLuint*)bind);
 
244
                glDeleteTextures(1, (GLuint *)bind);
217
245
                image->bindcode = 0;
218
246
        }
219
247
 
 
248
        BKE_image_release_ibuf(image, ibuf, NULL);
 
249
 
 
250
        return error;
 
251
}
 
252
 
 
253
static int rna_Image_gl_touch(Image *image, ReportList *reports, int filter, int mag)
 
254
{
 
255
        unsigned int *bind = &image->bindcode;
 
256
        int error = GL_NO_ERROR;
 
257
 
 
258
        BKE_image_tag_time(image);
 
259
 
 
260
        if (*bind == 0)
 
261
                error = rna_Image_gl_load(image, reports, filter, mag);
 
262
 
220
263
        return error;
221
264
}
222
265
 
237
280
 
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);
265
308
 
 
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);
 
316
 
 
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);
 
324
        /* return value */
 
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);
 
327
 
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);