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 * Contributor(s): Brecht Van Lommel
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_enum_types.h"
30 #include "rna_internal.h"
32 #include "DNA_image_types.h"
33 #include "DNA_scene_types.h"
35 #include "BKE_context.h"
36 #include "BKE_depsgraph.h"
37 #include "BKE_image.h"
41 static EnumPropertyItem image_source_items[]= {
42 {IMA_SRC_FILE, "FILE", 0, "File", "Single image file"},
43 {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Sequence", "Multiple image files, as a sequence"},
44 {IMA_SRC_MOVIE, "MOVIE", 0, "Movie", "Movie file"},
45 {IMA_SRC_GENERATED, "GENERATED", 0, "Generated", "Generated image"},
46 {IMA_SRC_VIEWER, "VIEWER", 0, "Viewer", "Compositing node viewer"},
47 {0, NULL, 0, NULL, NULL}};
51 #include "IMB_imbuf_types.h"
53 static void rna_Image_animated_update(Main *bmain, Scene *scene, PointerRNA *ptr)
55 Image *ima= (Image*)ptr->data;
58 if(ima->flag & IMA_TWINANIM) {
59 nr= ima->xrep*ima->yrep;
60 if(ima->twsta>=nr) ima->twsta= 1;
61 if(ima->twend>=nr) ima->twend= nr-1;
62 if(ima->twsta>ima->twend) ima->twsta= 1;
66 static int rna_Image_dirty_get(PointerRNA *ptr)
68 Image *ima= (Image*)ptr->data;
71 for(ibuf=ima->ibufs.first; ibuf; ibuf=ibuf->next)
72 if(ibuf->userflags & IB_BITMAPDIRTY)
78 static void rna_Image_source_update(Main *bmain, Scene *scene, PointerRNA *ptr)
80 Image *ima= ptr->id.data;
81 BKE_image_signal(ima, NULL, IMA_SIGNAL_SRC_CHANGE);
82 DAG_id_flush_update(&ima->id, 0);
85 static void rna_Image_fields_update(Main *bmain, Scene *scene, PointerRNA *ptr)
87 Image *ima= ptr->id.data;
91 ibuf= BKE_image_acquire_ibuf(ima, NULL, &lock);
96 if(!(ima->flag & IMA_FIELDS) && (ibuf->flags & IB_fields)) nr= 1;
97 if((ima->flag & IMA_FIELDS) && !(ibuf->flags & IB_fields)) nr= 1;
100 BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
103 BKE_image_release_ibuf(ima, lock);
106 static void rna_Image_reload_update(Main *bmain, Scene *scene, PointerRNA *ptr)
108 Image *ima= ptr->id.data;
109 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
110 DAG_id_flush_update(&ima->id, 0);
113 static void rna_Image_generated_update(Main *bmain, Scene *scene, PointerRNA *ptr)
115 Image *ima= ptr->id.data;
116 BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
119 static void rna_ImageUser_update(Main *bmain, Scene *scene, PointerRNA *ptr)
121 ImageUser *iuser= ptr->data;
123 BKE_image_user_calc_frame(iuser, scene->r.cfra, 0);
127 char *rna_ImageUser_path(PointerRNA *ptr)
130 // ImageUser *iuser= ptr->data;
132 switch(GS(((ID *)ptr->id.data)->name)) {
134 return BLI_strdup("image_user");
138 return BLI_strdup("");
141 static EnumPropertyItem *rna_Image_source_itemf(bContext *C, PointerRNA *ptr, int *free)
143 Image *ima= (Image*)ptr->data;
144 EnumPropertyItem *item= NULL;
147 if(ima->source == IMA_SRC_VIEWER) {
148 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_VIEWER);
151 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_FILE);
152 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_SEQUENCE);
153 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_MOVIE);
154 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_GENERATED);
157 RNA_enum_item_end(&item, &totitem);
163 static int rna_Image_file_format_get(PointerRNA *ptr)
165 Image *image= (Image*)ptr->data;
166 ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
167 return BKE_ftype_to_imtype(ibuf ? ibuf->ftype : 0);
170 static void rna_Image_file_format_set(PointerRNA *ptr, int value)
172 Image *image= (Image*)ptr->data;
173 if(BKE_imtype_is_movie(value) == 0) { /* should be able to throw an error here */
175 int ftype= BKE_imtype_to_ftype(value);
178 ibuf= BKE_image_get_ibuf(image, NULL);
183 /* to be safe change all buffer file types */
184 for(ibuf= image->ibufs.first; ibuf; ibuf= ibuf->next) {
190 static int rna_Image_has_data_get(PointerRNA *ptr)
192 Image *im= (Image*)ptr->data;
200 static void rna_Image_size_get(PointerRNA *ptr,int *values)
202 Image *im= (Image*)ptr->data;
206 ibuf = BKE_image_acquire_ibuf(im, NULL , &lock);
216 BKE_image_release_ibuf(im, lock);
220 static int rna_Image_depth_get(PointerRNA *ptr)
222 Image *im= (Image*)ptr->data;
227 ibuf= BKE_image_acquire_ibuf(im, NULL, &lock);
231 else if(ibuf->rect_float)
236 BKE_image_release_ibuf(im, lock);
243 static void rna_def_imageuser(BlenderRNA *brna)
248 srna= RNA_def_struct(brna, "ImageUser", NULL);
249 RNA_def_struct_ui_text(srna, "Image User", "Parameters defining how an Image datablock is used by another datablock");
250 RNA_def_struct_path_func(srna, "rna_ImageUser_path");
252 prop= RNA_def_property(srna, "use_auto_refresh", PROP_BOOLEAN, PROP_NONE);
253 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANIM_ALWAYS);
254 RNA_def_property_ui_text(prop, "Auto Refresh", "Always refresh image on frame changes");
255 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
258 prop= RNA_def_property(srna, "use_cyclic", PROP_BOOLEAN, PROP_NONE);
259 RNA_def_property_boolean_sdna(prop, NULL, "cycl", 0);
260 RNA_def_property_ui_text(prop, "Cyclic", "Cycle the images in the movie");
261 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
263 prop= RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE);
264 RNA_def_property_int_sdna(prop, NULL, "frames");
265 RNA_def_property_range(prop, 0, MAXFRAMEF);
266 RNA_def_property_ui_text(prop, "Frames", "Sets the number of images of a movie to use");
267 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
269 prop= RNA_def_property(srna, "frame_offset", PROP_INT, PROP_NONE);
270 RNA_def_property_int_sdna(prop, NULL, "offset");
271 RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
272 RNA_def_property_ui_text(prop, "Offset", "Offsets the number of the frame to use in the animation");
273 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
275 prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
276 RNA_def_property_int_sdna(prop, NULL, "sfra");
277 RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
278 RNA_def_property_ui_text(prop, "Start Frame", "Sets the global starting frame of the movie");
279 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
281 prop= RNA_def_property(srna, "fields_per_frame", PROP_INT, PROP_NONE);
282 RNA_def_property_int_sdna(prop, NULL, "fie_ima");
283 RNA_def_property_range(prop, 1, MAXFRAMEF);
284 RNA_def_property_ui_text(prop, "Fields per Frame", "The number of fields per rendered frame (2 fields is 1 image)");
285 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
287 prop= RNA_def_property(srna, "multilayer_layer", PROP_INT, PROP_UNSIGNED);
288 RNA_def_property_int_sdna(prop, NULL, "layer");
289 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
290 RNA_def_property_ui_text(prop, "Layer", "Layer in multilayer image");
292 prop= RNA_def_property(srna, "multilayer_pass", PROP_INT, PROP_UNSIGNED);
293 RNA_def_property_int_sdna(prop, NULL, "pass");
294 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
295 RNA_def_property_ui_text(prop, "Pass", "Pass in multilayer image");
298 static void rna_def_image(BlenderRNA *brna)
302 static const EnumPropertyItem prop_type_items[]= {
303 {IMA_TYPE_IMAGE, "IMAGE", 0, "Image", ""},
304 {IMA_TYPE_MULTILAYER, "MULTILAYER", 0, "Multilayer", ""},
305 {IMA_TYPE_UV_TEST, "UV_TEST", 0, "UV Test", ""},
306 {IMA_TYPE_R_RESULT, "RENDER_RESULT", 0, "Render Result", ""},
307 {IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""},
308 {0, NULL, 0, NULL, NULL}};
309 static const EnumPropertyItem prop_generated_type_items[]= {
310 {0, "BLANK", 0, "Blank", "Generate a blank image"},
311 {1, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"},
312 {2, "COLOR_GRID", 0, "Color Grid", "Generated improved UV grid to test UV mappings"},
313 {0, NULL, 0, NULL, NULL}};
314 static const EnumPropertyItem prop_mapping_items[]= {
315 {0, "UV", 0, "UV Coordinates", "Use UV coordinates for mapping the image"},
316 {IMA_REFLECT, "REFLECTION", 0, "Reflection", "Use reflection mapping for mapping the image"},
317 {0, NULL, 0, NULL, NULL}};
318 static const EnumPropertyItem prop_field_order_items[]= {
319 {0, "EVEN", 0, "Upper First", "Upper field first"},
320 {IMA_STD_FIELD, "ODD", 0, "Lower First", "Lower field first"},
321 {0, NULL, 0, NULL, NULL}};
323 srna= RNA_def_struct(brna, "Image", "ID");
324 RNA_def_struct_ui_text(srna, "Image", "Image datablock referencing an external or packed image");
325 RNA_def_struct_ui_icon(srna, ICON_IMAGE_DATA);
327 prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
328 RNA_def_property_string_sdna(prop, NULL, "name");
329 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name");
330 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_reload_update");
332 /* eek. this is horrible but needed so we can save to a new name without blanking the data :( */
333 prop= RNA_def_property(srna, "filepath_raw", PROP_STRING, PROP_FILEPATH);
334 RNA_def_property_string_sdna(prop, NULL, "name");
335 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name (without data refreshing)");
337 prop= RNA_def_property(srna, "file_format", PROP_ENUM, PROP_NONE);
338 RNA_def_property_enum_items(prop, image_type_items);
339 RNA_def_property_enum_funcs(prop, "rna_Image_file_format_get", "rna_Image_file_format_set", NULL);
340 RNA_def_property_ui_text(prop, "File Format", "Format used for re-saving this file");
342 prop= RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
343 RNA_def_property_enum_items(prop, image_source_items);
344 RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Image_source_itemf");
345 RNA_def_property_ui_text(prop, "Source", "Where the image comes from");
346 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_source_update");
348 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
349 RNA_def_property_enum_items(prop, prop_type_items);
350 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
351 RNA_def_property_ui_text(prop, "Type", "How to generate the image");
352 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
354 prop= RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
355 RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
356 RNA_def_property_ui_text(prop, "Packed File", "");
358 prop= RNA_def_property(srna, "field_order", PROP_ENUM, PROP_NONE);
359 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
360 RNA_def_property_enum_items(prop, prop_field_order_items);
361 RNA_def_property_ui_text(prop, "Field Order", "Order of video fields. Select which lines are displayed first");
362 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
365 prop= RNA_def_property(srna, "use_fields", PROP_BOOLEAN, PROP_NONE);
366 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_FIELDS);
367 RNA_def_property_ui_text(prop, "Fields", "Use fields of the image");
368 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_fields_update");
370 prop= RNA_def_property(srna, "use_premultiply", PROP_BOOLEAN, PROP_NONE);
371 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_DO_PREMUL);
372 RNA_def_property_ui_text(prop, "Premultiply", "Convert RGB from key alpha to premultiplied alpha");
373 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_reload_update");
375 prop= RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
376 RNA_def_property_boolean_funcs(prop, "rna_Image_dirty_get", NULL);
377 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
378 RNA_def_property_ui_text(prop, "Dirty", "Image has changed and is not saved");
380 /* generated image (image_generated_change_cb) */
381 prop= RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE);
382 RNA_def_property_enum_sdna(prop, NULL, "gen_type");
383 RNA_def_property_enum_items(prop, prop_generated_type_items);
384 RNA_def_property_ui_text(prop, "Generated Type", "Generated image type");
385 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
387 prop= RNA_def_property(srna, "generated_width", PROP_INT, PROP_NONE);
388 RNA_def_property_int_sdna(prop, NULL, "gen_x");
389 RNA_def_property_range(prop, 1, 16384);
390 RNA_def_property_ui_text(prop, "Generated Width", "Generated image width");
391 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
393 prop= RNA_def_property(srna, "generated_height", PROP_INT, PROP_NONE);
394 RNA_def_property_int_sdna(prop, NULL, "gen_y");
395 RNA_def_property_range(prop, 1, 16384);
396 RNA_def_property_ui_text(prop, "Generated Height", "Generated image height");
397 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
399 /* realtime properties */
400 prop= RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
401 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
402 RNA_def_property_enum_items(prop, prop_mapping_items);
403 RNA_def_property_ui_text(prop, "Mapping", "Mapping type to use for this image in the game engine");
404 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
406 prop= RNA_def_property(srna, "display_aspect", PROP_FLOAT, PROP_XYZ);
407 RNA_def_property_float_sdna(prop, NULL, "aspx");
408 RNA_def_property_array(prop, 2);
409 RNA_def_property_range(prop, 0.1f, 5000.0f);
410 RNA_def_property_ui_text(prop, "Display Aspect", "Display Aspect for this image, does not affect rendering");
411 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
413 prop= RNA_def_property(srna, "use_animation", PROP_BOOLEAN, PROP_NONE);
414 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TWINANIM);
415 RNA_def_property_ui_text(prop, "Animated", "Use as animated texture in the game engine");
416 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
418 prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE);
419 RNA_def_property_int_sdna(prop, NULL, "twsta");
420 RNA_def_property_range(prop, 0, 128);
421 RNA_def_property_ui_text(prop, "Animation Start", "Start frame of an animated texture");
422 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
424 prop= RNA_def_property(srna, "frame_end", PROP_INT, PROP_NONE);
425 RNA_def_property_int_sdna(prop, NULL, "twend");
426 RNA_def_property_range(prop, 0, 128);
427 RNA_def_property_ui_text(prop, "Animation End", "End frame of an animated texture");
428 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
430 prop= RNA_def_property(srna, "fps", PROP_INT, PROP_NONE);
431 RNA_def_property_int_sdna(prop, NULL, "animspeed");
432 RNA_def_property_range(prop, 1, 100);
433 RNA_def_property_ui_text(prop, "Animation Speed", "Speed of the animation in frames per second");
434 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
436 prop= RNA_def_property(srna, "use_tiles", PROP_BOOLEAN, PROP_NONE);
437 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TILES);
438 RNA_def_property_ui_text(prop, "Tiles", "Use of tilemode for faces (default shift-LMB to pick the tile for selected faces)");
439 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
441 prop= RNA_def_property(srna, "tiles_x", PROP_INT, PROP_NONE);
442 RNA_def_property_int_sdna(prop, NULL, "xrep");
443 RNA_def_property_range(prop, 1, 16);
444 RNA_def_property_ui_text(prop, "Tiles X", "Degree of repetition in the X direction");
445 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
447 prop= RNA_def_property(srna, "tiles_y", PROP_INT, PROP_NONE);
448 RNA_def_property_int_sdna(prop, NULL, "yrep");
449 RNA_def_property_range(prop, 1, 16);
450 RNA_def_property_ui_text(prop, "Tiles Y", "Degree of repetition in the Y direction");
451 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
453 prop= RNA_def_property(srna, "use_clamp_x", PROP_BOOLEAN, PROP_NONE);
454 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_U);
455 RNA_def_property_ui_text(prop, "Clamp X", "Disable texture repeating horizontally");
456 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
458 prop= RNA_def_property(srna, "use_clamp_y", PROP_BOOLEAN, PROP_NONE);
459 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_V);
460 RNA_def_property_ui_text(prop, "Clamp Y", "Disable texture repeating vertically");
461 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
463 prop= RNA_def_property(srna, "bindcode", PROP_INT, PROP_UNSIGNED);
464 RNA_def_property_int_sdna(prop, NULL, "bindcode");
465 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
466 RNA_def_property_ui_text(prop, "Bindcode", "OpenGL bindcode");
467 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
470 Image.has_data and Image.depth are temporary,
471 Update import_obj.py when they are replaced (Arystan)
473 prop= RNA_def_property(srna, "has_data", PROP_BOOLEAN, PROP_NONE);
474 RNA_def_property_boolean_funcs(prop, "rna_Image_has_data_get", NULL);
475 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
476 RNA_def_property_ui_text(prop, "Has data", "True if this image has data");
478 prop= RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
479 RNA_def_property_int_funcs(prop, "rna_Image_depth_get", NULL, NULL);
480 RNA_def_property_ui_text(prop, "Depth", "Image bit depth");
481 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
483 prop= RNA_def_int_vector(srna, "size" , 2 , NULL , 0, 0, "Size" , "Width and height in pixels, zero when image data cant be loaded" , 0 , 0);
484 RNA_def_property_int_funcs(prop, "rna_Image_size_get" , NULL, NULL);
485 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
490 void RNA_def_image(BlenderRNA *brna)
493 rna_def_imageuser(brna);