2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Brecht Van Lommel
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_image.c
29 #include "DNA_image_types.h"
30 #include "DNA_scene_types.h"
32 #include "BLI_utildefines.h"
34 #include "BKE_context.h"
35 #include "BKE_image.h"
37 #include "DEG_depsgraph.h"
39 #include "RNA_access.h"
40 #include "RNA_define.h"
41 #include "RNA_enum_types.h"
43 #include "rna_internal.h"
48 EnumPropertyItem rna_enum_image_generated_type_items[] = {
49 {IMA_GENTYPE_BLANK, "BLANK", 0, "Blank", "Generate a blank image"},
50 {IMA_GENTYPE_GRID, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"},
51 {IMA_GENTYPE_GRID_COLOR, "COLOR_GRID", 0, "Color Grid", "Generated improved UV grid to test UV mappings"},
52 {0, NULL, 0, NULL, NULL}
55 static EnumPropertyItem image_source_items[] = {
56 {IMA_SRC_FILE, "FILE", 0, "Single Image", "Single image file"},
57 {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Image Sequence", "Multiple image files, as a sequence"},
58 {IMA_SRC_MOVIE, "MOVIE", 0, "Movie", "Movie file"},
59 {IMA_SRC_GENERATED, "GENERATED", 0, "Generated", "Generated image"},
60 {IMA_SRC_VIEWER, "VIEWER", 0, "Viewer", "Compositing node viewer"},
61 {0, NULL, 0, NULL, NULL}
66 #include "BKE_global.h"
70 #include "IMB_imbuf.h"
71 #include "IMB_imbuf_types.h"
73 static void rna_Image_animated_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
75 Image *ima = (Image *)ptr->data;
78 if (ima->flag & IMA_TWINANIM) {
79 nr = ima->xrep * ima->yrep;
80 if (ima->twsta >= nr) ima->twsta = 1;
81 if (ima->twend >= nr) ima->twend = nr - 1;
82 if (ima->twsta > ima->twend) ima->twsta = 1;
86 static int rna_Image_is_stereo_3d_get(PointerRNA *ptr)
88 return BKE_image_is_stereo((Image *)ptr->data);
91 static int rna_Image_is_multiview_get(PointerRNA *ptr)
93 return BKE_image_is_multiview((Image *)ptr->data);
96 static int rna_Image_dirty_get(PointerRNA *ptr)
98 return BKE_image_is_dirty((Image *)ptr->data);
101 static void rna_Image_source_set(PointerRNA *ptr, int value)
103 Image *ima = ptr->id.data;
105 if (value != ima->source) {
107 BKE_image_signal(ima, NULL, IMA_SIGNAL_SRC_CHANGE);
108 DEG_id_tag_update(&ima->id, 0);
112 static void rna_Image_fields_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
114 Image *ima = ptr->id.data;
118 ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
123 if (!(ima->flag & IMA_FIELDS) && (ibuf->flags & IB_fields)) nr = 1;
124 if ((ima->flag & IMA_FIELDS) && !(ibuf->flags & IB_fields)) nr = 1;
127 BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
130 BKE_image_release_ibuf(ima, ibuf, lock);
133 static void rna_Image_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
135 Image *ima = ptr->id.data;
136 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
137 WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
138 DEG_id_tag_update(&ima->id, 0);
141 static void rna_Image_generated_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
143 Image *ima = ptr->id.data;
144 BKE_image_signal(ima, NULL, IMA_SIGNAL_FREE);
147 static void rna_Image_colormanage_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
149 Image *ima = ptr->id.data;
150 BKE_image_signal(ima, NULL, IMA_SIGNAL_COLORMANAGE);
151 DEG_id_tag_update(&ima->id, 0);
152 WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
153 WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
156 static void rna_Image_views_format_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
158 Image *ima = ptr->id.data;
162 ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
165 ImageUser iuser = {NULL};
167 BKE_image_signal(ima, &iuser, IMA_SIGNAL_FREE);
170 BKE_image_release_ibuf(ima, ibuf, lock);
173 static void rna_ImageUser_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
175 ImageUser *iuser = ptr->data;
177 BKE_image_user_frame_calc(iuser, scene->r.cfra, 0);
181 static char *rna_ImageUser_path(PointerRNA *ptr)
184 /* ImageUser *iuser = ptr->data; */
186 switch (GS(((ID *)ptr->id.data)->name)) {
190 return BLI_strdup("image_user");
194 return rna_Node_ImageUser_path(ptr);
201 return BLI_strdup("");
204 static EnumPropertyItem *rna_Image_source_itemf(bContext *UNUSED(C), PointerRNA *ptr,
205 PropertyRNA *UNUSED(prop), bool *r_free)
207 Image *ima = (Image *)ptr->data;
208 EnumPropertyItem *item = NULL;
211 if (ima->source == IMA_SRC_VIEWER) {
212 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_VIEWER);
215 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_FILE);
216 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_SEQUENCE);
217 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_MOVIE);
218 RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_GENERATED);
221 RNA_enum_item_end(&item, &totitem);
227 static int rna_Image_file_format_get(PointerRNA *ptr)
229 Image *image = (Image *)ptr->data;
230 ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
231 int imtype = BKE_image_ftype_to_imtype(ibuf ? ibuf->ftype : 0, ibuf ? &ibuf->foptions : NULL);
233 BKE_image_release_ibuf(image, ibuf, NULL);
238 static void rna_Image_file_format_set(PointerRNA *ptr, int value)
240 Image *image = (Image *)ptr->data;
241 if (BKE_imtype_is_movie(value) == 0) { /* should be able to throw an error here */
242 ImbFormatOptions options;
243 int ftype = BKE_image_imtype_to_ftype(value, &options);
244 BKE_image_file_format_set(image, ftype, &options);
248 static int rna_Image_has_data_get(PointerRNA *ptr)
250 Image *image = (Image *)ptr->data;
252 return BKE_image_has_loaded_ibuf(image);
255 static void rna_Image_size_get(PointerRNA *ptr, int *values)
257 Image *im = (Image *)ptr->data;
261 ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
271 BKE_image_release_ibuf(im, ibuf, lock);
274 static void rna_Image_resolution_get(PointerRNA *ptr, float *values)
276 Image *im = (Image *)ptr->data;
280 ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
282 values[0] = ibuf->ppm[0];
283 values[1] = ibuf->ppm[1];
290 BKE_image_release_ibuf(im, ibuf, lock);
293 static void rna_Image_resolution_set(PointerRNA *ptr, const float *values)
295 Image *im = (Image *)ptr->data;
299 ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
301 ibuf->ppm[0] = values[0];
302 ibuf->ppm[1] = values[1];
305 BKE_image_release_ibuf(im, ibuf, lock);
308 static int rna_Image_depth_get(PointerRNA *ptr)
310 Image *im = (Image *)ptr->data;
315 ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
319 else if (ibuf->rect_float)
320 planes = ibuf->planes * 4;
322 planes = ibuf->planes;
324 BKE_image_release_ibuf(im, ibuf, lock);
329 static int rna_Image_frame_duration_get(PointerRNA *ptr)
331 Image *ima = ptr->id.data;
334 if (BKE_image_has_anim(ima)) {
335 duration = IMB_anim_get_duration(((ImageAnim *)ima->anims.first)->anim, IMB_TC_RECORD_RUN);
338 /* acquire ensures ima->anim is set, if possible! */
340 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
341 BKE_image_release_ibuf(ima, ibuf, lock);
347 static int rna_Image_pixels_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
349 Image *ima = ptr->id.data;
353 ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
356 length[0] = ibuf->x * ibuf->y * ibuf->channels;
360 BKE_image_release_ibuf(ima, ibuf, lock);
365 static void rna_Image_pixels_get(PointerRNA *ptr, float *values)
367 Image *ima = ptr->id.data;
372 ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
375 size = ibuf->x * ibuf->y * ibuf->channels;
377 if (ibuf->rect_float) {
378 memcpy(values, ibuf->rect_float, sizeof(float) * size);
381 for (i = 0; i < size; i++)
382 values[i] = ((unsigned char *)ibuf->rect)[i] * (1.0f / 255.0f);
386 BKE_image_release_ibuf(ima, ibuf, lock);
389 static void rna_Image_pixels_set(PointerRNA *ptr, const float *values)
391 Image *ima = ptr->id.data;
396 ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
399 size = ibuf->x * ibuf->y * ibuf->channels;
401 if (ibuf->rect_float) {
402 memcpy(ibuf->rect_float, values, sizeof(float) * size);
405 for (i = 0; i < size; i++)
406 ((unsigned char *)ibuf->rect)[i] = FTOCHAR(values[i]);
409 ibuf->userflags |= IB_BITMAPDIRTY | IB_DISPLAY_BUFFER_INVALID | IB_MIPMAP_INVALID;
413 WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
416 BKE_image_release_ibuf(ima, ibuf, lock);
419 static int rna_Image_channels_get(PointerRNA *ptr)
421 Image *im = (Image *)ptr->data;
426 ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
428 channels = ibuf->channels;
430 BKE_image_release_ibuf(im, ibuf, lock);
435 static int rna_Image_is_float_get(PointerRNA *ptr)
437 Image *im = (Image *)ptr->data;
440 bool is_float = false;
442 ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
444 is_float = ibuf->rect_float != NULL;
446 BKE_image_release_ibuf(im, ibuf, lock);
451 static PointerRNA rna_Image_packed_file_get(PointerRNA *ptr)
453 Image *ima = (Image *)ptr->id.data;
455 if (BKE_image_has_packedfile(ima)) {
456 ImagePackedFile *imapf = ima->packedfiles.first;
457 return rna_pointer_inherit_refine(ptr, &RNA_PackedFile, imapf->packedfile);
460 return PointerRNA_NULL;
464 static void rna_Image_render_slots_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
466 Image *image = (Image *)ptr->id.data;
467 rna_iterator_array_begin(iter, (void *)image->render_slots, sizeof(RenderSlot), IMA_MAX_RENDER_SLOT, 0, NULL);
470 static PointerRNA rna_render_slots_active_get(PointerRNA *ptr)
472 Image *image = (Image *)ptr->id.data;
473 RenderSlot *render_slot = &image->render_slots[image->render_slot];
475 return rna_pointer_inherit_refine(ptr, &RNA_RenderSlot, render_slot);
478 static void rna_render_slots_active_set(PointerRNA *ptr, PointerRNA value)
480 Image *image = (Image *)ptr->id.data;
481 if (value.id.data == image) {
482 RenderSlot *render_slot = (RenderSlot *)value.data;
483 int index = render_slot - image->render_slots;
484 image->render_slot = CLAMPIS(index, 0, IMA_MAX_RENDER_SLOT - 1);
488 static int rna_render_slots_active_index_get(PointerRNA *ptr)
490 Image *image = (Image *)ptr->id.data;
491 return image->render_slot;
494 static void rna_render_slots_active_index_set(PointerRNA *ptr, int value)
496 Image *image = (Image *)ptr->id.data;
497 image->render_slot = value;
498 CLAMP(image->render_slot, 0, IMA_MAX_RENDER_SLOT - 1);
503 static void rna_def_imageuser(BlenderRNA *brna)
508 srna = RNA_def_struct(brna, "ImageUser", NULL);
509 RNA_def_struct_ui_text(srna, "Image User",
510 "Parameters defining how an Image data-block is used by another data-block");
511 RNA_def_struct_path_func(srna, "rna_ImageUser_path");
513 prop = RNA_def_property(srna, "use_auto_refresh", PROP_BOOLEAN, PROP_NONE);
514 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANIM_ALWAYS);
515 RNA_def_property_ui_text(prop, "Auto Refresh", "Always refresh image on frame changes");
516 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
517 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
519 prop = RNA_def_property(srna, "frame_current", PROP_INT, PROP_TIME);
520 RNA_def_property_int_sdna(prop, NULL, "framenr");
521 RNA_def_property_range(prop, MINAFRAME, MAXFRAME);
522 RNA_def_property_ui_text(prop, "Current Frame", "Current frame number in image sequence or movie");
525 prop = RNA_def_property(srna, "use_cyclic", PROP_BOOLEAN, PROP_NONE);
526 RNA_def_property_boolean_sdna(prop, NULL, "cycl", 0);
527 RNA_def_property_ui_text(prop, "Cyclic", "Cycle the images in the movie");
528 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
529 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
531 prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE);
532 RNA_def_property_int_sdna(prop, NULL, "frames");
533 RNA_def_property_range(prop, 0, MAXFRAMEF);
534 RNA_def_property_ui_text(prop, "Frames", "Number of images of a movie to use");
535 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
536 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
538 prop = RNA_def_property(srna, "frame_offset", PROP_INT, PROP_NONE);
539 RNA_def_property_int_sdna(prop, NULL, "offset");
540 RNA_def_property_ui_text(prop, "Offset", "Offset the number of the frame to use in the animation");
541 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
543 prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
544 RNA_def_property_int_sdna(prop, NULL, "sfra");
545 RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
546 RNA_def_property_ui_text(prop, "Start Frame",
547 "Global starting frame of the movie/sequence, assuming first picture has a #1");
548 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
549 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
551 prop = RNA_def_property(srna, "fields_per_frame", PROP_INT, PROP_NONE);
552 RNA_def_property_int_sdna(prop, NULL, "fie_ima");
553 RNA_def_property_range(prop, 1, 200);
554 RNA_def_property_ui_text(prop, "Fields per Frame", "Number of fields per rendered frame (2 fields is 1 image)");
555 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
556 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
558 prop = RNA_def_property(srna, "multilayer_layer", PROP_INT, PROP_UNSIGNED);
559 RNA_def_property_int_sdna(prop, NULL, "layer");
560 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
561 RNA_def_property_ui_text(prop, "Layer", "Layer in multilayer image");
563 prop = RNA_def_property(srna, "multilayer_pass", PROP_INT, PROP_UNSIGNED);
564 RNA_def_property_int_sdna(prop, NULL, "pass");
565 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
566 RNA_def_property_ui_text(prop, "Pass", "Pass in multilayer image");
568 prop = RNA_def_property(srna, "multilayer_view", PROP_INT, PROP_UNSIGNED);
569 RNA_def_property_int_sdna(prop, NULL, "view");
570 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
571 RNA_def_property_ui_text(prop, "View", "View in multilayer image");
574 /* image.packed_files */
575 static void rna_def_image_packed_files(BlenderRNA *brna)
580 srna = RNA_def_struct(brna, "ImagePackedFile", NULL);
581 RNA_def_struct_sdna(srna, "ImagePackedFile");
583 prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
584 RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
585 RNA_def_property_ui_text(prop, "Packed File", "");
586 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
588 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
589 RNA_def_property_string_sdna(prop, NULL, "filepath");
590 RNA_def_struct_name_property(srna, prop);
592 RNA_api_image_packed_file(srna);
595 static void rna_def_render_slot(BlenderRNA *brna)
599 srna = RNA_def_struct(brna, "RenderSlot", NULL);
600 RNA_def_struct_ui_text(srna, "Render Slot", "Parameters defining the render slot");
602 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
603 RNA_def_property_string_sdna(prop, NULL, "name");
604 RNA_def_property_ui_text(prop, "Name", "Render slot name");
605 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
608 static void rna_def_render_slots(BlenderRNA *brna)
613 srna = RNA_def_struct(brna, "RenderSlots", NULL);
614 RNA_def_struct_sdna(srna, "RenderSlot");
615 RNA_def_struct_ui_text(srna, "Render Slots", "Collection of the render slots");
617 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
618 RNA_def_property_struct_type(prop, "RenderSlot");
619 RNA_def_property_pointer_funcs(prop, "rna_render_slots_active_get", "rna_render_slots_active_set", NULL, NULL);
620 RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
621 RNA_def_property_ui_text(prop, "Active", "Active render slot of the image");
622 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
624 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE);
625 RNA_def_property_int_funcs(prop, "rna_render_slots_active_index_get",
626 "rna_render_slots_active_index_set",
628 RNA_def_property_range(prop, 0, IMA_MAX_RENDER_SLOT);
629 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
630 RNA_def_property_ui_text(prop, "Active Index", "Index of an active render slot of the image");
631 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
634 static void rna_def_image(BlenderRNA *brna)
638 static const EnumPropertyItem prop_type_items[] = {
639 {IMA_TYPE_IMAGE, "IMAGE", 0, "Image", ""},
640 {IMA_TYPE_MULTILAYER, "MULTILAYER", 0, "Multilayer", ""},
641 {IMA_TYPE_UV_TEST, "UV_TEST", 0, "UV Test", ""},
642 {IMA_TYPE_R_RESULT, "RENDER_RESULT", 0, "Render Result", ""},
643 {IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""},
644 {0, NULL, 0, NULL, NULL}
646 static const EnumPropertyItem prop_mapping_items[] = {
647 {0, "UV", 0, "UV Coordinates", "Use UV coordinates for mapping the image"},
648 {IMA_REFLECT, "REFLECTION", 0, "Reflection", "Use reflection mapping for mapping the image"},
649 {0, NULL, 0, NULL, NULL}
651 static const EnumPropertyItem prop_field_order_items[] = {
652 {0, "EVEN", 0, "Upper First", "Upper field first"},
653 {IMA_STD_FIELD, "ODD", 0, "Lower First", "Lower field first"},
654 {0, NULL, 0, NULL, NULL}
656 static const EnumPropertyItem alpha_mode_items[] = {
657 {IMA_ALPHA_STRAIGHT, "STRAIGHT", 0, "Straight", "Transparent RGB and alpha pixels are unmodified"},
658 {IMA_ALPHA_PREMUL, "PREMUL", 0, "Premultiplied", "Transparent RGB pixels are multiplied by the alpha channel"},
659 {0, NULL, 0, NULL, NULL}
662 srna = RNA_def_struct(brna, "Image", "ID");
663 RNA_def_struct_ui_text(srna, "Image", "Image data-block referencing an external or packed image");
664 RNA_def_struct_ui_icon(srna, ICON_IMAGE_DATA);
666 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
667 RNA_def_property_string_sdna(prop, NULL, "name");
668 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name");
669 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_reload_update");
671 /* eek. this is horrible but needed so we can save to a new name without blanking the data :( */
672 prop = RNA_def_property(srna, "filepath_raw", PROP_STRING, PROP_FILEPATH);
673 RNA_def_property_string_sdna(prop, NULL, "name");
674 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name (without data refreshing)");
676 prop = RNA_def_property(srna, "file_format", PROP_ENUM, PROP_NONE);
677 RNA_def_property_enum_items(prop, rna_enum_image_type_items);
678 RNA_def_property_enum_funcs(prop, "rna_Image_file_format_get", "rna_Image_file_format_set", NULL);
679 RNA_def_property_ui_text(prop, "File Format", "Format used for re-saving this file");
681 prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
682 RNA_def_property_enum_items(prop, image_source_items);
683 RNA_def_property_enum_funcs(prop, NULL, "rna_Image_source_set", "rna_Image_source_itemf");
684 RNA_def_property_ui_text(prop, "Source", "Where the image comes from");
685 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
687 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
688 RNA_def_property_enum_items(prop, prop_type_items);
689 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
690 RNA_def_property_ui_text(prop, "Type", "How to generate the image");
691 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
693 prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
694 RNA_def_property_struct_type(prop, "PackedFile");
695 RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
696 RNA_def_property_pointer_funcs(prop, "rna_Image_packed_file_get", NULL, NULL, NULL);
697 RNA_def_property_ui_text(prop, "Packed File", "First packed file of the image");
699 prop = RNA_def_property(srna, "packed_files", PROP_COLLECTION, PROP_NONE);
700 RNA_def_property_collection_sdna(prop, NULL, "packedfiles", NULL);
701 RNA_def_property_struct_type(prop, "ImagePackedFile");
702 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
703 RNA_def_property_ui_text(prop, "Packed Files", "Collection of packed images");
705 prop = RNA_def_property(srna, "field_order", PROP_ENUM, PROP_NONE);
706 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
707 RNA_def_property_enum_items(prop, prop_field_order_items);
708 RNA_def_property_ui_text(prop, "Field Order", "Order of video fields (select which lines are displayed first)");
709 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
712 prop = RNA_def_property(srna, "use_fields", PROP_BOOLEAN, PROP_NONE);
713 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_FIELDS);
714 RNA_def_property_ui_text(prop, "Fields", "Use fields of the image");
715 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_fields_update");
716 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
719 prop = RNA_def_property(srna, "use_view_as_render", PROP_BOOLEAN, PROP_NONE);
720 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_VIEW_AS_RENDER);
721 RNA_def_property_ui_text(prop, "View as Render", "Apply render part of display transformation when displaying this image on the screen");
722 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
724 prop = RNA_def_property(srna, "use_alpha", PROP_BOOLEAN, PROP_NONE);
725 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", IMA_IGNORE_ALPHA);
726 RNA_def_property_ui_text(prop, "Use Alpha", "Use the alpha channel information from the image or make image fully opaque");
727 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_colormanage_update");
729 prop = RNA_def_property(srna, "use_deinterlace", PROP_BOOLEAN, PROP_NONE);
730 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_DEINTERLACE);
731 RNA_def_property_ui_text(prop, "Deinterlace", "Deinterlace movie file on load");
732 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_reload_update");
734 prop = RNA_def_property(srna, "use_multiview", PROP_BOOLEAN, PROP_NONE);
735 RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_USE_VIEWS);
736 RNA_def_property_ui_text(prop, "Use Multi-View", "Use Multiple Views (when available)");
737 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_views_format_update");
739 prop = RNA_def_property(srna, "is_stereo_3d", PROP_BOOLEAN, PROP_NONE);
740 RNA_def_property_boolean_funcs(prop, "rna_Image_is_stereo_3d_get", NULL);
741 RNA_def_property_ui_text(prop, "Stereo 3D", "Image has left and right views");
742 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
744 prop = RNA_def_property(srna, "is_multiview", PROP_BOOLEAN, PROP_NONE);
745 RNA_def_property_boolean_funcs(prop, "rna_Image_is_multiview_get", NULL);
746 RNA_def_property_ui_text(prop, "Multiple Views", "Image has more than one view");
747 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
749 prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
750 RNA_def_property_boolean_funcs(prop, "rna_Image_dirty_get", NULL);
751 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
752 RNA_def_property_ui_text(prop, "Dirty", "Image has changed and is not saved");
754 /* generated image (image_generated_change_cb) */
755 prop = RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE);
756 RNA_def_property_enum_sdna(prop, NULL, "gen_type");
757 RNA_def_property_enum_items(prop, rna_enum_image_generated_type_items);
758 RNA_def_property_ui_text(prop, "Generated Type", "Generated image type");
759 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
760 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
762 prop = RNA_def_property(srna, "generated_width", PROP_INT, PROP_NONE);
763 RNA_def_property_int_sdna(prop, NULL, "gen_x");
764 RNA_def_property_flag(prop, PROP_PROPORTIONAL);
765 RNA_def_property_range(prop, 1, 65536);
766 RNA_def_property_ui_text(prop, "Generated Width", "Generated image width");
767 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
768 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
770 prop = RNA_def_property(srna, "generated_height", PROP_INT, PROP_NONE);
771 RNA_def_property_int_sdna(prop, NULL, "gen_y");
772 RNA_def_property_flag(prop, PROP_PROPORTIONAL);
773 RNA_def_property_range(prop, 1, 65536);
774 RNA_def_property_ui_text(prop, "Generated Height", "Generated image height");
775 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
776 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
778 prop = RNA_def_property(srna, "use_generated_float", PROP_BOOLEAN, PROP_NONE);
779 RNA_def_property_boolean_sdna(prop, NULL, "gen_flag", IMA_GEN_FLOAT);
780 RNA_def_property_ui_text(prop, "Float Buffer", "Generate floating point buffer");
781 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
782 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
784 prop = RNA_def_property(srna, "generated_color", PROP_FLOAT, PROP_COLOR_GAMMA);
785 RNA_def_property_float_sdna(prop, NULL, "gen_color");
786 RNA_def_property_array(prop, 4);
787 RNA_def_property_ui_text(prop, "Color", "Fill color for the generated image");
788 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
789 RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
791 /* realtime properties */
792 prop = RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
793 RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
794 RNA_def_property_enum_items(prop, prop_mapping_items);
795 RNA_def_property_ui_text(prop, "Mapping", "Mapping type to use for this image in the game engine");
796 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
798 prop = RNA_def_property(srna, "display_aspect", PROP_FLOAT, PROP_XYZ);
799 RNA_def_property_float_sdna(prop, NULL, "aspx");
800 RNA_def_property_array(prop, 2);
801 RNA_def_property_range(prop, 0.1f, FLT_MAX);
802 RNA_def_property_ui_range(prop, 0.1f, 5000.f, 1, 2);
803 RNA_def_property_ui_text(prop, "Display Aspect", "Display Aspect for this image, does not affect rendering");
804 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
806 prop = RNA_def_property(srna, "use_animation", PROP_BOOLEAN, PROP_NONE);
807 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TWINANIM);
808 RNA_def_property_ui_text(prop, "Animated", "Use as animated texture in the game engine");
809 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_animated_update");
811 prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE);
812 RNA_def_property_int_sdna(prop, NULL, "twsta");
813 RNA_def_property_range(prop, 0, 255);
814 RNA_def_property_ui_text(prop, "Animation Start", "Start frame of an animated texture");
815 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_animated_update");
817 prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_NONE);
818 RNA_def_property_int_sdna(prop, NULL, "twend");
819 RNA_def_property_range(prop, 0, 255);
820 RNA_def_property_ui_text(prop, "Animation End", "End frame of an animated texture");
821 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_animated_update");
823 prop = RNA_def_property(srna, "fps", PROP_INT, PROP_NONE);
824 RNA_def_property_int_sdna(prop, NULL, "animspeed");
825 RNA_def_property_range(prop, 1, 100);
826 RNA_def_property_ui_text(prop, "Animation Speed", "Speed of the animation in frames per second");
827 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
829 prop = RNA_def_property(srna, "use_tiles", PROP_BOOLEAN, PROP_NONE);
830 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TILES);
831 RNA_def_property_ui_text(prop, "Tiles",
832 "Use of tilemode for faces (default shift-LMB to pick the tile for selected faces)");
833 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
835 prop = RNA_def_property(srna, "tiles_x", PROP_INT, PROP_NONE);
836 RNA_def_property_int_sdna(prop, NULL, "xrep");
837 RNA_def_property_range(prop, 1, 16);
838 RNA_def_property_ui_text(prop, "Tiles X", "Degree of repetition in the X direction");
839 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
841 prop = RNA_def_property(srna, "tiles_y", PROP_INT, PROP_NONE);
842 RNA_def_property_int_sdna(prop, NULL, "yrep");
843 RNA_def_property_range(prop, 1, 16);
844 RNA_def_property_ui_text(prop, "Tiles Y", "Degree of repetition in the Y direction");
845 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
847 prop = RNA_def_property(srna, "use_clamp_x", PROP_BOOLEAN, PROP_NONE);
848 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_U);
849 RNA_def_property_ui_text(prop, "Clamp X", "Disable texture repeating horizontally");
850 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
852 prop = RNA_def_property(srna, "use_clamp_y", PROP_BOOLEAN, PROP_NONE);
853 RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_V);
854 RNA_def_property_ui_text(prop, "Clamp Y", "Disable texture repeating vertically");
855 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
857 prop = RNA_def_property(srna, "bindcode", PROP_INT, PROP_UNSIGNED);
858 RNA_def_property_int_sdna(prop, NULL, "bindcode");
859 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
860 RNA_def_property_ui_text(prop, "Bindcode", "OpenGL bindcode");
861 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
863 prop = RNA_def_property(srna, "render_slots", PROP_COLLECTION, PROP_NONE);
864 RNA_def_property_struct_type(prop, "RenderSlot");
865 RNA_def_property_ui_text(prop, "Render Slots", "Render slots of the image");
866 RNA_def_property_collection_funcs(prop, "rna_Image_render_slots_begin", "rna_iterator_array_next",
867 "rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
868 RNA_def_property_srna(prop, "RenderSlots");
871 * Image.has_data and Image.depth are temporary,
872 * Update import_obj.py when they are replaced (Arystan)
874 prop = RNA_def_property(srna, "has_data", PROP_BOOLEAN, PROP_NONE);
875 RNA_def_property_boolean_funcs(prop, "rna_Image_has_data_get", NULL);
876 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
877 RNA_def_property_ui_text(prop, "Has Data", "True if the image data is loaded into memory");
879 prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
880 RNA_def_property_int_funcs(prop, "rna_Image_depth_get", NULL, NULL);
881 RNA_def_property_ui_text(prop, "Depth", "Image bit depth");
882 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
884 prop = RNA_def_int_vector(srna, "size", 2, NULL, 0, 0, "Size",
885 "Width and height in pixels, zero when image data cant be loaded", 0, 0);
886 RNA_def_property_subtype(prop, PROP_PIXEL);
887 RNA_def_property_int_funcs(prop, "rna_Image_size_get", NULL, NULL);
888 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
890 prop = RNA_def_float_vector(srna, "resolution", 2, NULL, 0, 0, "Resolution", "X/Y pixels per meter", 0, 0);
891 RNA_def_property_float_funcs(prop, "rna_Image_resolution_get", "rna_Image_resolution_set", NULL);
893 prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_UNSIGNED);
894 RNA_def_property_int_funcs(prop, "rna_Image_frame_duration_get", NULL, NULL);
895 RNA_def_property_ui_text(prop, "Duration", "Duration (in frames) of the image (1 when not a video/sequence)");
896 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
898 /* NOTE about pixels/channels/is_floa:
899 * this properties describes how image is stored internally (inside of ImBuf),
900 * not how it was saved to disk or how it'll be saved on disk
902 prop = RNA_def_property(srna, "pixels", PROP_FLOAT, PROP_NONE);
903 RNA_def_property_flag(prop, PROP_DYNAMIC);
904 RNA_def_property_multi_array(prop, 1, NULL);
905 RNA_def_property_ui_text(prop, "Pixels", "Image pixels in floating point values");
906 RNA_def_property_dynamic_array_funcs(prop, "rna_Image_pixels_get_length");
907 RNA_def_property_float_funcs(prop, "rna_Image_pixels_get", "rna_Image_pixels_set", NULL);
909 prop = RNA_def_property(srna, "channels", PROP_INT, PROP_UNSIGNED);
910 RNA_def_property_int_funcs(prop, "rna_Image_channels_get", NULL, NULL);
911 RNA_def_property_ui_text(prop, "Channels", "Number of channels in pixels buffer");
912 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
914 prop = RNA_def_property(srna, "is_float", PROP_BOOLEAN, PROP_NONE);
915 RNA_def_property_boolean_funcs(prop, "rna_Image_is_float_get", NULL);
916 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
917 RNA_def_property_ui_text(prop, "Is Float", "True if this image is stored in float buffer");
919 prop = RNA_def_property(srna, "colorspace_settings", PROP_POINTER, PROP_NONE);
920 RNA_def_property_pointer_sdna(prop, NULL, "colorspace_settings");
921 RNA_def_property_struct_type(prop, "ColorManagedInputColorspaceSettings");
922 RNA_def_property_ui_text(prop, "Color Space Settings", "Input color space settings");
924 prop = RNA_def_property(srna, "alpha_mode", PROP_ENUM, PROP_NONE);
925 RNA_def_property_enum_items(prop, alpha_mode_items);
926 RNA_def_property_ui_text(prop, "Alpha Mode", "Representation of alpha information in the RGBA pixels");
927 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_colormanage_update");
930 prop = RNA_def_property(srna, "views_format", PROP_ENUM, PROP_NONE);
931 RNA_def_property_enum_sdna(prop, NULL, "views_format");
932 RNA_def_property_enum_items(prop, rna_enum_views_format_items);
933 RNA_def_property_ui_text(prop, "Views Format", "Mode to load image views");
934 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_views_format_update");
936 prop = RNA_def_property(srna, "stereo_3d_format", PROP_POINTER, PROP_NONE);
937 RNA_def_property_pointer_sdna(prop, NULL, "stereo3d_format");
938 RNA_def_property_flag(prop, PROP_NEVER_NULL);
939 RNA_def_property_struct_type(prop, "Stereo3dFormat");
940 RNA_def_property_ui_text(prop, "Stereo 3D Format", "Settings for stereo 3d");
945 void RNA_def_image(BlenderRNA *brna)
947 rna_def_render_slot(brna);
948 rna_def_render_slots(brna);
950 rna_def_imageuser(brna);
951 rna_def_image_packed_files(brna);