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 */
174 ImBuf *ibuf= BKE_image_get_ibuf(image, NULL);
176 ibuf->ftype= BKE_imtype_to_ftype(value);
180 static int rna_Image_has_data_get(PointerRNA *ptr)
182 Image *im= (Image*)ptr->data;
190 static void rna_Image_size_get(PointerRNA *ptr,int *values)
192 Image *im= (Image*)ptr->data;
196 ibuf = BKE_image_acquire_ibuf(im, NULL , &lock);
206 BKE_image_release_ibuf(im, lock);
210 static int rna_Image_depth_get(PointerRNA *ptr)
212 Image *im= (Image*)ptr->data;
217 ibuf= BKE_image_acquire_ibuf(im, NULL, &lock);
221 else if(ibuf->rect_float)
226 BKE_image_release_ibuf(im, lock);
233 static void rna_def_imageuser(BlenderRNA *brna)
238 srna= RNA_def_struct(brna, "ImageUser", NULL);
239 RNA_def_struct_ui_text(srna, "Image User", "Parameters defining how an Image datablock is used by another datablock");
240 RNA_def_struct_path_func(srna, "rna_ImageUser_path");
242 prop= RNA_def_property(srna, "use_auto_refresh", PROP_BOOLEAN, PROP_NONE);
243 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANIM_ALWAYS);
244 RNA_def_property_ui_text(prop, "Auto Refresh", "Always refresh image on frame changes");
245 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
248 prop= RNA_def_property(srna, "use_cyclic", PROP_BOOLEAN, PROP_NONE);
249 RNA_def_property_boolean_sdna(prop, NULL, "cycl", 0);
250 RNA_def_property_ui_text(prop, "Cyclic", "Cycle the images in the movie");
251 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
253 prop= RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE);
254 RNA_def_property_int_sdna(prop, NULL, "frames");
255 RNA_def_property_range(prop, 0, MAXFRAMEF);
256 RNA_def_property_ui_text(prop, "Frames", "Sets the number of images of a movie to use");
257 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
259 prop= RNA_def_property(srna, "frame_offset", PROP_INT, PROP_NONE);
260 RNA_def_property_int_sdna(prop, NULL, "offset");
261 RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
262 RNA_def_property_ui_text(prop, "Offset", "Offsets the number of the frame to use in the animation");
263 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
265 prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
266 RNA_def_property_int_sdna(prop, NULL, "sfra");
267 RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
268 RNA_def_property_ui_text(prop, "Start Frame", "Sets the global starting frame of the movie");
269 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
271 prop= RNA_def_property(srna, "fields_per_frame", PROP_INT, PROP_NONE);
272 RNA_def_property_int_sdna(prop, NULL, "fie_ima");
273 RNA_def_property_range(prop, 1, MAXFRAMEF);
274 RNA_def_property_ui_text(prop, "Fields per Frame", "The number of fields per rendered frame (2 fields is 1 image)");
275 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
277 prop= RNA_def_property(srna, "multilayer_layer", PROP_INT, PROP_UNSIGNED);
278 RNA_def_property_int_sdna(prop, NULL, "layer");
279 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
280 RNA_def_property_ui_text(prop, "Layer", "Layer in multilayer image");
282 prop= RNA_def_property(srna, "multilayer_pass", PROP_INT, PROP_UNSIGNED);
283 RNA_def_property_int_sdna(prop, NULL, "pass");
284 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
285 RNA_def_property_ui_text(prop, "Pass", "Pass in multilayer image");
288 static void rna_def_image(BlenderRNA *brna)
292 static const EnumPropertyItem prop_type_items[]= {
293 {IMA_TYPE_IMAGE, "IMAGE", 0, "Image", ""},
294 {IMA_TYPE_MULTILAYER, "MULTILAYER", 0, "Multilayer", ""},
295 {IMA_TYPE_UV_TEST, "UV_TEST", 0, "UV Test", ""},
296 {IMA_TYPE_R_RESULT, "RENDER_RESULT", 0, "Render Result", ""},
297 {IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""},
298 {0, NULL, 0, NULL, NULL}};
299 static const EnumPropertyItem prop_generated_type_items[]= {
300 {0, "BLANK", 0, "Blank", "Generate a blank image"},
301 {1, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"},
302 {2, "COLOR_GRID", 0, "Color Grid", "Generated improved UV grid to test UV mappings"},
303 {0, NULL, 0, NULL, NULL}};
304 static const EnumPropertyItem prop_mapping_items[]= {
305 {0, "UV", 0, "UV Coordinates", "Use UV coordinates for mapping the image"},
306 {IMA_REFLECT, "REFLECTION", 0, "Reflection", "Use reflection mapping for mapping the image"},
307 {0, NULL, 0, NULL, NULL}};
308 static const EnumPropertyItem prop_field_order_items[]= {
309 {0, "EVEN", 0, "Upper First", "Upper field first"},
310 {IMA_STD_FIELD, "ODD", 0, "Lower First", "Lower field first"},
311 {0, NULL, 0, NULL, NULL}};
313 srna= RNA_def_struct(brna, "Image", "ID");
314 RNA_def_struct_ui_text(srna, "Image", "Image datablock referencing an external or packed image");
315 RNA_def_struct_ui_icon(srna, ICON_IMAGE_DATA);
317 prop= RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
318 RNA_def_property_string_sdna(prop, NULL, "name");
319 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name");
320 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_reload_update");
322 /* eek. this is horrible but needed so we can save to a new name without blanking the data :( */
323 prop= RNA_def_property(srna, "filepath_raw", PROP_STRING, PROP_FILEPATH);
324 RNA_def_property_string_sdna(prop, NULL, "name");
325 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name (without data refreshing)");
327 prop= RNA_def_property(srna, "file_format", PROP_ENUM, PROP_NONE);
328 RNA_def_property_enum_items(prop, image_type_items);
329 RNA_def_property_enum_funcs(prop, "rna_Image_file_format_get", "rna_Image_file_format_set", NULL);
330 RNA_def_property_ui_text(prop, "File Format", "Format used for re-saving this file");
332 prop= RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
333 RNA_def_property_enum_items(prop, image_source_items);
334 RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Image_source_itemf");
335 RNA_def_property_ui_text(prop, "Source", "Where the image comes from");
336 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_source_update");
338 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
339 RNA_def_property_enum_items(prop, prop_type_items);
340 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
341 RNA_def_property_ui_text(prop, "Type", "How to generate the image");
342 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
344 prop= RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
345 RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
346 RNA_def_property_ui_text(prop, "Packed File", "");
348 prop= RNA_def_property(srna, "field_order", PROP_ENUM, PROP_NONE);
349 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
350 RNA_def_property_enum_items(prop, prop_field_order_items);
351 RNA_def_property_ui_text(prop, "Field Order", "Order of video fields. Select which lines are displayed first");
352 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
355 prop= RNA_def_property(srna, "use_fields", PROP_BOOLEAN, PROP_NONE);
356 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_FIELDS);
357 RNA_def_property_ui_text(prop, "Fields", "Use fields of the image");
358 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_fields_update");
360 prop= RNA_def_property(srna, "use_premultiply", PROP_BOOLEAN, PROP_NONE);
361 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_DO_PREMUL);
362 RNA_def_property_ui_text(prop, "Premultiply", "Convert RGB from key alpha to premultiplied alpha");
363 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_reload_update");
365 prop= RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
366 RNA_def_property_boolean_funcs(prop, "rna_Image_dirty_get", NULL);
367 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
368 RNA_def_property_ui_text(prop, "Dirty", "Image has changed and is not saved");
370 /* generated image (image_generated_change_cb) */
371 prop= RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE);
372 RNA_def_property_enum_sdna(prop, NULL, "gen_type");
373 RNA_def_property_enum_items(prop, prop_generated_type_items);
374 RNA_def_property_ui_text(prop, "Generated Type", "Generated image type");
375 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
377 prop= RNA_def_property(srna, "generated_width", PROP_INT, PROP_NONE);
378 RNA_def_property_int_sdna(prop, NULL, "gen_x");
379 RNA_def_property_range(prop, 1, 16384);
380 RNA_def_property_ui_text(prop, "Generated Width", "Generated image width");
381 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
383 prop= RNA_def_property(srna, "generated_height", PROP_INT, PROP_NONE);
384 RNA_def_property_int_sdna(prop, NULL, "gen_y");
385 RNA_def_property_range(prop, 1, 16384);
386 RNA_def_property_ui_text(prop, "Generated Height", "Generated image height");
387 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_generated_update");
389 /* realtime properties */
390 prop= RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
391 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
392 RNA_def_property_enum_items(prop, prop_mapping_items);
393 RNA_def_property_ui_text(prop, "Mapping", "Mapping type to use for this image in the game engine");
394 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
396 prop= RNA_def_property(srna, "display_aspect", PROP_FLOAT, PROP_XYZ);
397 RNA_def_property_float_sdna(prop, NULL, "aspx");
398 RNA_def_property_array(prop, 2);
399 RNA_def_property_range(prop, 0.1f, 5000.0f);
400 RNA_def_property_ui_text(prop, "Display Aspect", "Display Aspect for this image, does not affect rendering");
401 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
403 prop= RNA_def_property(srna, "use_animation", PROP_BOOLEAN, PROP_NONE);
404 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TWINANIM);
405 RNA_def_property_ui_text(prop, "Animated", "Use as animated texture in the game engine");
406 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
408 prop= RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE);
409 RNA_def_property_int_sdna(prop, NULL, "twsta");
410 RNA_def_property_range(prop, 0, 128);
411 RNA_def_property_ui_text(prop, "Animation Start", "Start frame of an animated texture");
412 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
414 prop= RNA_def_property(srna, "frame_end", PROP_INT, PROP_NONE);
415 RNA_def_property_int_sdna(prop, NULL, "twend");
416 RNA_def_property_range(prop, 0, 128);
417 RNA_def_property_ui_text(prop, "Animation End", "End frame of an animated texture");
418 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, "rna_Image_animated_update");
420 prop= RNA_def_property(srna, "fps", PROP_INT, PROP_NONE);
421 RNA_def_property_int_sdna(prop, NULL, "animspeed");
422 RNA_def_property_range(prop, 1, 100);
423 RNA_def_property_ui_text(prop, "Animation Speed", "Speed of the animation in frames per second");
424 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
426 prop= RNA_def_property(srna, "use_tiles", PROP_BOOLEAN, PROP_NONE);
427 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TILES);
428 RNA_def_property_ui_text(prop, "Tiles", "Use of tilemode for faces (default shift-LMB to pick the tile for selected faces)");
429 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
431 prop= RNA_def_property(srna, "tiles_x", PROP_INT, PROP_NONE);
432 RNA_def_property_int_sdna(prop, NULL, "xrep");
433 RNA_def_property_range(prop, 1, 16);
434 RNA_def_property_ui_text(prop, "Tiles X", "Degree of repetition in the X direction");
435 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
437 prop= RNA_def_property(srna, "tiles_y", PROP_INT, PROP_NONE);
438 RNA_def_property_int_sdna(prop, NULL, "yrep");
439 RNA_def_property_range(prop, 1, 16);
440 RNA_def_property_ui_text(prop, "Tiles Y", "Degree of repetition in the Y direction");
441 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
443 prop= RNA_def_property(srna, "use_clamp_x", PROP_BOOLEAN, PROP_NONE);
444 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_U);
445 RNA_def_property_ui_text(prop, "Clamp X", "Disable texture repeating horizontally");
446 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
448 prop= RNA_def_property(srna, "use_clamp_y", PROP_BOOLEAN, PROP_NONE);
449 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_V);
450 RNA_def_property_ui_text(prop, "Clamp Y", "Disable texture repeating vertically");
451 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
453 prop= RNA_def_property(srna, "bindcode", PROP_INT, PROP_UNSIGNED);
454 RNA_def_property_int_sdna(prop, NULL, "bindcode");
455 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
456 RNA_def_property_ui_text(prop, "Bindcode", "OpenGL bindcode");
457 RNA_def_property_update(prop, NC_IMAGE|ND_DISPLAY, NULL);
460 Image.has_data and Image.depth are temporary,
461 Update import_obj.py when they are replaced (Arystan)
463 prop= RNA_def_property(srna, "has_data", PROP_BOOLEAN, PROP_NONE);
464 RNA_def_property_boolean_funcs(prop, "rna_Image_has_data_get", NULL);
465 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
466 RNA_def_property_ui_text(prop, "Has data", "True if this image has data");
468 prop= RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
469 RNA_def_property_int_funcs(prop, "rna_Image_depth_get", NULL, NULL);
470 RNA_def_property_ui_text(prop, "Depth", "Image bit depth");
471 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
473 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);
474 RNA_def_property_int_funcs(prop, "rna_Image_size_get" , NULL, NULL);
475 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
480 void RNA_def_image(BlenderRNA *brna)
483 rna_def_imageuser(brna);