Blender V4.5
rna_image.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "DNA_image_types.h"
12#include "DNA_scene_types.h"
13
14#include "BLT_translation.hh"
15
16#include "RNA_define.hh"
17#include "RNA_enum_types.hh"
18
19#include "rna_internal.hh"
20
21#include "WM_api.hh"
22#include "WM_types.hh"
23
25 {IMA_GENTYPE_BLANK, "BLANK", 0, "Blank", "Generate a blank image"},
26 {IMA_GENTYPE_GRID, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"},
28 "COLOR_GRID",
29 0,
30 "Color Grid",
31 "Generated improved UV grid to test UV mappings"},
32 {0, nullptr, 0, nullptr, nullptr},
33};
34
36 {IMA_SRC_FILE, "FILE", 0, "Single Image", "Single image file"},
37 {IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Image Sequence", "Multiple image files, as a sequence"},
38 {IMA_SRC_MOVIE, "MOVIE", 0, "Movie", "Movie file"},
39 {IMA_SRC_GENERATED, "GENERATED", 0, "Generated", "Generated image"},
40 {IMA_SRC_VIEWER, "VIEWER", 0, "Viewer", "Compositing node viewer"},
41 {IMA_SRC_TILED, "TILED", 0, "UDIM Tiles", "Tiled UDIM image texture"},
42 {0, nullptr, 0, nullptr, nullptr},
43};
44
45#ifdef RNA_RUNTIME
46
47# include <algorithm>
48# include <fmt/format.h>
49
50# include "BLI_math_base.h"
51# include "BLI_math_vector.h"
52
53# include "BKE_global.hh"
54# include "BKE_image.hh"
55# include "BKE_image_format.hh"
56# include "BKE_lib_id.hh"
57# include "BKE_main.hh"
58# include "BKE_main_invariants.hh"
60# include "BKE_screen.hh"
61
62# include "GPU_texture.hh"
63
64# include "IMB_imbuf.hh"
65# include "IMB_imbuf_types.hh"
66
67# include "MOV_read.hh"
68
69# include "ED_node.hh"
70
71# include "DNA_space_types.h"
72
73# include "DEG_depsgraph.hh"
74# include "DEG_depsgraph_build.hh"
75
76static bool rna_Image_is_stereo_3d_get(PointerRNA *ptr)
77{
78 return BKE_image_is_stereo((Image *)ptr->data);
79}
80
81static bool rna_Image_is_multiview_get(PointerRNA *ptr)
82{
83 return BKE_image_is_multiview((Image *)ptr->data);
84}
85
86static bool rna_Image_dirty_get(PointerRNA *ptr)
87{
88 return BKE_image_is_dirty((Image *)ptr->data);
89}
90
91static void rna_Image_source_set(PointerRNA *ptr, int value)
92{
93 Image *ima = (Image *)ptr->owner_id;
94
95 if (value != ima->source) {
96 ima->source = value;
99 if (ima->source == IMA_SRC_TILED) {
101 }
102
103 DEG_id_tag_update(&ima->id, 0);
106 }
107}
108
109static void rna_Image_reload_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
110{
111 Image *ima = (Image *)ptr->owner_id;
112 BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_RELOAD);
114 DEG_id_tag_update(&ima->id, 0);
116}
117
118static int rna_Image_generated_type_get(PointerRNA *ptr)
119{
120 Image *ima = (Image *)ptr->data;
121 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
122 return base_tile->gen_type;
123}
124
125static void rna_Image_generated_type_set(PointerRNA *ptr, int value)
126{
127 Image *ima = (Image *)ptr->data;
128 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
129 base_tile->gen_type = value;
130}
131
132static int rna_Image_generated_width_get(PointerRNA *ptr)
133{
134 Image *ima = (Image *)ptr->data;
135 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
136 return base_tile->gen_x;
137}
138
139static void rna_Image_generated_width_set(PointerRNA *ptr, int value)
140{
141 Image *ima = (Image *)ptr->data;
142 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
143 base_tile->gen_x = std::clamp(value, 1, 65536);
144}
145
146static int rna_Image_generated_height_get(PointerRNA *ptr)
147{
148 Image *ima = (Image *)ptr->data;
149 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
150 return base_tile->gen_y;
151}
152
153static void rna_Image_generated_height_set(PointerRNA *ptr, int value)
154{
155 Image *ima = (Image *)ptr->data;
156 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
157 base_tile->gen_y = std::clamp(value, 1, 65536);
158}
159
160static bool rna_Image_generated_float_get(PointerRNA *ptr)
161{
162 Image *ima = (Image *)ptr->data;
163 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
164 return (base_tile->gen_flag & IMA_GEN_FLOAT) != 0;
165}
166
167static void rna_Image_generated_float_set(PointerRNA *ptr, bool value)
168{
169 Image *ima = (Image *)ptr->data;
170 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
171 if (value) {
172 base_tile->gen_flag |= IMA_GEN_FLOAT;
173 }
174 else {
175 base_tile->gen_flag &= ~IMA_GEN_FLOAT;
176 }
177}
178
179void rna_Image_generated_color_get(PointerRNA *ptr, float values[4])
180{
181 Image *ima = (Image *)(ptr->data);
182 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
183 copy_v4_v4(values, base_tile->gen_color);
184}
185
186void rna_Image_generated_color_set(PointerRNA *ptr, const float values[4])
187{
188 Image *ima = (Image *)(ptr->data);
189 ImageTile *base_tile = BKE_image_get_tile(ima, 0);
190 for (uint i = 0; i < 4; i++) {
191 base_tile->gen_color[i] = std::clamp(values[i], 0.0f, FLT_MAX);
192 }
193}
194
195static void rna_Image_generated_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
196{
197 Image *ima = (Image *)ptr->owner_id;
198 BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_FREE);
201}
202
203static void rna_Image_colormanage_update(Main *bmain, Scene * /*scene*/, PointerRNA *ptr)
204{
205 Image *ima = (Image *)ptr->owner_id;
206 BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_COLORMANAGE);
207 DEG_id_tag_update(&ima->id, 0);
211}
212
213static void rna_Image_alpha_mode_update(Main *bmain, Scene *scene, PointerRNA *ptr)
214{
215 Image *ima = (Image *)ptr->owner_id;
216 /* When operating on a generated image, avoid re-generating when changing the alpha-mode
217 * as it doesn't impact generated images, causing them to reload pixel data, see #82785. */
218 if (ima->source == IMA_SRC_GENERATED) {
219 return;
220 }
221 rna_Image_colormanage_update(bmain, scene, ptr);
222}
223
224static void rna_Image_views_format_update(Main *bmain, Scene *scene, PointerRNA *ptr)
225{
226 Image *ima = (Image *)ptr->owner_id;
227 ImBuf *ibuf;
228 void *lock;
229
230 ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
231
232 if (ibuf) {
233 ImageUser iuser = {nullptr};
234 iuser.scene = scene;
235 BKE_image_signal(bmain, ima, &iuser, IMA_SIGNAL_FREE);
236 }
237
238 BKE_image_release_ibuf(ima, ibuf, lock);
241}
242
243static void rna_ImageUser_update(Main *bmain, Scene *scene, PointerRNA *ptr)
244{
245 ImageUser *iuser = static_cast<ImageUser *>(ptr->data);
246 ID *id = ptr->owner_id;
247
248 if (scene != nullptr) {
249 BKE_image_user_frame_calc(nullptr, iuser, scene->r.cfra);
250 }
251
252 if (id) {
253 if (GS(id->name) == ID_NT) {
254 /* Special update for node-trees. */
257 }
258 else {
259 /* Update material or texture for render preview. */
260 DEG_id_tag_update(id, 0);
262 }
263 }
264}
265
266static void rna_ImageUser_relations_update(Main *bmain, Scene *scene, PointerRNA *ptr)
267{
268 rna_ImageUser_update(bmain, scene, ptr);
270}
271
272static std::optional<std::string> rna_ImageUser_path(const PointerRNA *ptr)
273{
274 if (ptr->owner_id) {
275 switch (GS(ptr->owner_id->name)) {
276 case ID_OB:
277 case ID_TE:
278 return "image_user";
279 case ID_NT:
281 case ID_CA:
283 case ID_SCR: {
284 const bScreen *screen = reinterpret_cast<bScreen *>(ptr->owner_id);
285 const ImageUser *iuser = static_cast<ImageUser *>(ptr->data);
286 int area_index;
287 int space_index;
288 LISTBASE_FOREACH_INDEX (ScrArea *, area, &screen->areabase, area_index) {
289 LISTBASE_FOREACH_INDEX (SpaceLink *, sl, &area->spacedata, space_index) {
290 if (sl->spacetype == SPACE_IMAGE) {
291 SpaceImage *sima = reinterpret_cast<SpaceImage *>(sl);
292 if (&sima->iuser == iuser) {
293 return fmt::format("areas[{}].spaces[{}].image_user", area_index, space_index);
294 }
295 }
296 }
297 }
298 return " ... image_user";
299 }
300 default:
301 break;
302 }
303 }
304
305 return "";
306}
307
308static void rna_Image_gpu_texture_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
309{
310 Image *ima = (Image *)ptr->owner_id;
311
312 if (!G.background) {
314 }
315
317}
318
319static const EnumPropertyItem *rna_Image_source_itemf(bContext * /*C*/,
321 PropertyRNA * /*prop*/,
322 bool *r_free)
323{
324 Image *ima = (Image *)ptr->data;
325 EnumPropertyItem *item = nullptr;
326 int totitem = 0;
327
328 if (ima->source == IMA_SRC_VIEWER) {
330 }
331 else {
337 }
338
339 RNA_enum_item_end(&item, &totitem);
340 *r_free = true;
341
342 return item;
343}
344
345static int rna_Image_file_format_get(PointerRNA *ptr)
346{
347 Image *image = (Image *)ptr->data;
348 ImBuf *ibuf = BKE_image_acquire_ibuf(image, nullptr, nullptr);
349 int imtype = BKE_ftype_to_imtype(ibuf ? ibuf->ftype : IMB_FTYPE_NONE,
350 ibuf ? &ibuf->foptions : nullptr);
351
352 BKE_image_release_ibuf(image, ibuf, nullptr);
353
354 return imtype;
355}
356
357static void rna_Image_file_format_set(PointerRNA *ptr, int value)
358{
359 Image *image = (Image *)ptr->data;
360 if (BKE_imtype_is_movie(value) == 0) { /* should be able to throw an error here */
362 int ftype = BKE_imtype_to_ftype(value, &options);
363 BKE_image_file_format_set(image, ftype, &options);
364 }
365}
366
367static void rna_UDIMTile_size_get(PointerRNA *ptr, int *values)
368{
369 ImageTile *tile = (ImageTile *)ptr->data;
370 Image *image = (Image *)ptr->owner_id;
371
372 ImageUser image_user;
373 BKE_imageuser_default(&image_user);
374 image_user.tile = tile->tile_number;
375
376 void *lock;
377 ImBuf *ibuf = BKE_image_acquire_ibuf(image, &image_user, &lock);
378 if (ibuf) {
379 values[0] = ibuf->x;
380 values[1] = ibuf->y;
381 }
382 else {
383 values[0] = 0;
384 values[1] = 0;
385 }
386
387 BKE_image_release_ibuf(image, ibuf, lock);
388}
389
390static int rna_UDIMTile_channels_get(PointerRNA *ptr)
391{
392 ImageTile *tile = (ImageTile *)ptr->data;
393 Image *image = (Image *)ptr->owner_id;
394
395 ImageUser image_user;
396 BKE_imageuser_default(&image_user);
397 image_user.tile = tile->tile_number;
398
399 int channels = 0;
400
401 void *lock;
402 ImBuf *ibuf = BKE_image_acquire_ibuf(image, &image_user, &lock);
403 if (ibuf) {
404 channels = ibuf->channels;
405 }
406
407 BKE_image_release_ibuf(image, ibuf, lock);
408
409 return channels;
410}
411
412static void rna_UDIMTile_label_get(PointerRNA *ptr, char *value)
413{
414 const ImageTile *tile = (ImageTile *)ptr->data;
415 const Image *image = (Image *)ptr->owner_id;
416
417 /* Pass in a fixed size buffer as the value may be allocated based on the callbacks length. */
418 char value_buf[sizeof(tile->label)];
419 int len = BKE_image_get_tile_label(image, tile, value_buf, sizeof(tile->label));
420 memcpy(value, value_buf, len + 1);
421}
422
423static int rna_UDIMTile_label_length(PointerRNA *ptr)
424{
425 const ImageTile *tile = (ImageTile *)ptr->data;
426 const Image *image = (Image *)ptr->owner_id;
427
428 char label[sizeof(tile->label)];
429 return BKE_image_get_tile_label(image, tile, label, sizeof(label));
430}
431
432static void rna_UDIMTile_tile_number_set(PointerRNA *ptr, int value)
433{
434 ImageTile *tile = (ImageTile *)ptr->data;
435 Image *image = (Image *)ptr->owner_id;
436
437 /* Check that no other tile already has that number. */
438 ImageTile *cur_tile = BKE_image_get_tile(image, value);
439 if (cur_tile == nullptr) {
440 BKE_image_reassign_tile(image, tile, value);
441 }
442}
443
444static void rna_UDIMTile_generated_update(Main * /*bmain*/, Scene * /*scene*/, PointerRNA *ptr)
445{
446 Image *ima = (Image *)ptr->owner_id;
447 ImageTile *tile = (ImageTile *)ptr->data;
448
449 /* If the tile is still marked as generated, then update the tile as requested. */
450 if ((tile->gen_flag & IMA_GEN_TILE) != 0) {
453 }
454}
455
456static int rna_Image_active_tile_index_get(PointerRNA *ptr)
457{
458 Image *image = (Image *)ptr->data;
459 return image->active_tile_index;
460}
461
462static void rna_Image_active_tile_index_set(PointerRNA *ptr, int value)
463{
464 Image *image = (Image *)ptr->data;
465 int num_tiles = BLI_listbase_count(&image->tiles);
466
467 image->active_tile_index = min_ii(value, num_tiles - 1);
468}
469
470static void rna_Image_active_tile_index_range(
471 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
472{
473 Image *image = (Image *)ptr->data;
474 int num_tiles = BLI_listbase_count(&image->tiles);
475
476 *min = 0;
477 *max = max_ii(0, num_tiles - 1);
478}
479
480static PointerRNA rna_Image_active_tile_get(PointerRNA *ptr)
481{
482 Image *image = (Image *)ptr->data;
483 ImageTile *tile = static_cast<ImageTile *>(
484 BLI_findlink(&image->tiles, image->active_tile_index));
485
486 return RNA_pointer_create_with_parent(*ptr, &RNA_UDIMTile, tile);
487}
488
489static void rna_Image_active_tile_set(PointerRNA *ptr, PointerRNA value, ReportList * /*reports*/)
490{
491 Image *image = (Image *)ptr->data;
492 ImageTile *tile = (ImageTile *)value.data;
493 const int index = BLI_findindex(&image->tiles, tile);
494 if (index != -1) {
495 image->active_tile_index = index;
496 }
497}
498
499static bool rna_Image_has_data_get(PointerRNA *ptr)
500{
501 Image *image = (Image *)ptr->data;
502
503 return BKE_image_has_loaded_ibuf(image);
504}
505
506static void rna_Image_size_get(PointerRNA *ptr, int *values)
507{
508 Image *im = (Image *)ptr->data;
509 ImBuf *ibuf;
510 void *lock;
511
512 ibuf = BKE_image_acquire_ibuf(im, nullptr, &lock);
513 if (ibuf) {
514 values[0] = ibuf->x;
515 values[1] = ibuf->y;
516 }
517 else {
518 values[0] = 0;
519 values[1] = 0;
520 }
521
522 BKE_image_release_ibuf(im, ibuf, lock);
523}
524
525static void rna_Image_resolution_get(PointerRNA *ptr, float *values)
526{
527 Image *im = (Image *)ptr->data;
528 ImBuf *ibuf;
529 void *lock;
530
531 ibuf = BKE_image_acquire_ibuf(im, nullptr, &lock);
532 if (ibuf) {
533 values[0] = ibuf->ppm[0];
534 values[1] = ibuf->ppm[1];
535 }
536 else {
537 values[0] = 0;
538 values[1] = 0;
539 }
540
541 BKE_image_release_ibuf(im, ibuf, lock);
542}
543
544static void rna_Image_resolution_set(PointerRNA *ptr, const float *values)
545{
546 Image *im = (Image *)ptr->data;
547 ImBuf *ibuf;
548 void *lock;
549
550 ibuf = BKE_image_acquire_ibuf(im, nullptr, &lock);
551 if (ibuf) {
552 ibuf->ppm[0] = values[0];
553 ibuf->ppm[1] = values[1];
554 }
555
556 BKE_image_release_ibuf(im, ibuf, lock);
557}
558
559static int rna_Image_bindcode_get(PointerRNA *ptr)
560{
561 Image *ima = (Image *)ptr->data;
562 GPUTexture *tex = ima->gputexture[TEXTARGET_2D][0];
563 return (tex) ? GPU_texture_opengl_bindcode(tex) : 0;
564}
565
566static int rna_Image_depth_get(PointerRNA *ptr)
567{
568 Image *im = (Image *)ptr->data;
569 ImBuf *ibuf;
570 void *lock;
571 int planes;
572
573 ibuf = BKE_image_acquire_ibuf(im, nullptr, &lock);
574
575 if (!ibuf) {
576 planes = 0;
577 }
578 else if (ibuf->float_buffer.data) {
579 planes = ibuf->planes * 4;
580 }
581 else {
582 planes = ibuf->planes;
583 }
584
585 BKE_image_release_ibuf(im, ibuf, lock);
586
587 return planes;
588}
589
590static int rna_Image_frame_duration_get(PointerRNA *ptr)
591{
592 Image *ima = (Image *)ptr->owner_id;
593 int duration = 1;
594
595 if (!BKE_image_has_anim(ima)) {
596 /* Ensure image has been loaded into memory and frame duration is known. */
597 void *lock;
598 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
599 BKE_image_release_ibuf(ima, ibuf, lock);
600 }
601
602 if (BKE_image_has_anim(ima)) {
603 MovieReader *anim = ((ImageAnim *)ima->anims.first)->anim;
604 if (anim) {
606 }
607 }
608
609 return duration;
610}
611
612static int rna_Image_pixels_get_length(const PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
613{
614 Image *ima = (Image *)ptr->owner_id;
615 ImBuf *ibuf;
616 void *lock;
617
618 ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
619
620 if (ibuf) {
621 length[0] = IMB_get_pixel_count(ibuf) * size_t(ibuf->channels);
622 }
623 else {
624 length[0] = 0;
625 }
626
627 BKE_image_release_ibuf(ima, ibuf, lock);
628
629 return length[0];
630}
631
632static void rna_Image_pixels_get(PointerRNA *ptr, float *values)
633{
634 Image *ima = (Image *)ptr->owner_id;
635 ImBuf *ibuf;
636 void *lock;
637
638 ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
639
640 if (ibuf) {
641 const size_t size = IMB_get_pixel_count(ibuf) * size_t(ibuf->channels);
642
643 if (ibuf->float_buffer.data) {
644 memcpy(values, ibuf->float_buffer.data, sizeof(float) * size);
645 }
646 else {
647 for (size_t i = 0; i < size; i++) {
648 values[i] = ibuf->byte_buffer.data[i] * (1.0f / 255.0f);
649 }
650 }
651 }
652
653 BKE_image_release_ibuf(ima, ibuf, lock);
654}
655
656static void rna_Image_pixels_set(PointerRNA *ptr, const float *values)
657{
658 Image *ima = (Image *)ptr->owner_id;
659 ImBuf *ibuf;
660 void *lock;
661
662 ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock);
663
664 if (ibuf) {
665 const size_t size = IMB_get_pixel_count(ibuf) * size_t(ibuf->channels);
666
667 if (ibuf->float_buffer.data) {
668 memcpy(ibuf->float_buffer.data, values, sizeof(float) * size);
669 }
670 else {
671 for (size_t i = 0; i < size; i++) {
672 ibuf->byte_buffer.data[i] = unit_float_to_uchar_clamp(values[i]);
673 }
674 }
675
676 /* NOTE: Do update from the set() because typically pixels.foreach_set() is used to update
677 * the values, and it does not invoke the update(). */
678
680 BKE_image_mark_dirty(ima, ibuf);
681 if (!G.background) {
683 }
684
687 }
688
689 BKE_image_release_ibuf(ima, ibuf, lock);
690}
691
692static int rna_Image_channels_get(PointerRNA *ptr)
693{
694 Image *im = (Image *)ptr->data;
695 ImBuf *ibuf;
696 void *lock;
697 int channels = 0;
698
699 ibuf = BKE_image_acquire_ibuf(im, nullptr, &lock);
700 if (ibuf) {
701 channels = ibuf->channels;
702 }
703
704 BKE_image_release_ibuf(im, ibuf, lock);
705
706 return channels;
707}
708
709static bool rna_Image_is_float_get(PointerRNA *ptr)
710{
711 Image *im = (Image *)ptr->data;
712 ImBuf *ibuf;
713 void *lock;
714 bool is_float = false;
715
716 ibuf = BKE_image_acquire_ibuf(im, nullptr, &lock);
717 if (ibuf) {
718 is_float = ibuf->float_buffer.data != nullptr;
719 }
720
721 BKE_image_release_ibuf(im, ibuf, lock);
722
723 return is_float;
724}
725
726static PointerRNA rna_Image_packed_file_get(PointerRNA *ptr)
727{
728 Image *ima = (Image *)ptr->owner_id;
729
730 if (BKE_image_has_packedfile(ima)) {
731 ImagePackedFile *imapf = static_cast<ImagePackedFile *>(ima->packedfiles.first);
732 return RNA_pointer_create_with_parent(*ptr, &RNA_PackedFile, imapf->packedfile);
733 }
734 return PointerRNA_NULL;
735}
736
737static void rna_RenderSlot_clear(ID *id, RenderSlot *slot, ImageUser *iuser)
738{
739 Image *image = (Image *)id;
740 int index = BLI_findindex(&image->renderslots, slot);
741 BKE_image_clear_renderslot(image, iuser, index);
742
744}
745
746static PointerRNA rna_render_slots_active_get(PointerRNA *ptr)
747{
748 Image *image = (Image *)ptr->owner_id;
749 RenderSlot *render_slot = BKE_image_get_renderslot(image, image->render_slot);
750
751 return RNA_pointer_create_with_parent(*ptr, &RNA_RenderSlot, render_slot);
752}
753
754static void rna_render_slots_active_set(PointerRNA *ptr,
755 PointerRNA value,
756 ReportList * /*reports*/)
757{
758 Image *image = (Image *)ptr->owner_id;
759 if (value.owner_id == &image->id) {
760 RenderSlot *slot = (RenderSlot *)value.data;
761 int index = BLI_findindex(&image->renderslots, slot);
762 if (index != -1) {
763 image->render_slot = index;
765 }
766 }
767}
768
769static int rna_render_slots_active_index_get(PointerRNA *ptr)
770{
771 Image *image = (Image *)ptr->owner_id;
772 return image->render_slot;
773}
774
775static void rna_render_slots_active_index_set(PointerRNA *ptr, int value)
776{
777 Image *image = (Image *)ptr->owner_id;
778 int num_slots = BLI_listbase_count(&image->renderslots);
779 image->render_slot = value;
781 CLAMP(image->render_slot, 0, num_slots - 1);
782}
783
784static void rna_render_slots_active_index_range(
785 PointerRNA *ptr, int *min, int *max, int * /*softmin*/, int * /*softmax*/)
786{
787 Image *image = (Image *)ptr->owner_id;
788 *min = 0;
789 *max = max_ii(0, BLI_listbase_count(&image->renderslots) - 1);
790}
791
792static ImageTile *rna_UDIMTile_new(Image *image, int tile_number, const char *label)
793{
794 ImageTile *tile = BKE_image_add_tile(image, tile_number, label);
795
797
798 return tile;
799}
800
801static void rna_UDIMTile_remove(Image *image, PointerRNA *ptr)
802{
803 ImageTile *tile = (ImageTile *)ptr->data;
805
807}
808
809#else
810
812{
813 StructRNA *srna;
814 PropertyRNA *prop;
815
816 srna = RNA_def_struct(brna, "ImageUser", nullptr);
818 srna,
819 "Image User",
820 "Parameters defining how an Image data-block is used by another data-block");
821 RNA_def_struct_path_func(srna, "rna_ImageUser_path");
822
824
825 prop = RNA_def_property(srna, "use_auto_refresh", PROP_BOOLEAN, PROP_NONE);
826 RNA_def_property_boolean_sdna(prop, nullptr, "flag", IMA_ANIM_ALWAYS);
827 RNA_def_property_ui_text(prop, "Auto Refresh", "Always refresh image on frame changes");
828 RNA_def_property_update(prop, 0, "rna_ImageUser_relations_update");
830
831 prop = RNA_def_property(srna, "frame_current", PROP_INT, PROP_TIME);
832 RNA_def_property_int_sdna(prop, nullptr, "framenr");
835 prop, "Current Frame", "Current frame number in image sequence or movie");
836
837 /* animation */
838 prop = RNA_def_property(srna, "use_cyclic", PROP_BOOLEAN, PROP_NONE);
839 RNA_def_property_boolean_sdna(prop, nullptr, "cycl", 0);
840 RNA_def_property_ui_text(prop, "Cyclic", "Cycle the images in the movie");
841 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
843
844 prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE);
845 RNA_def_property_int_sdna(prop, nullptr, "frames");
847 RNA_def_property_ui_text(prop, "Frames", "Number of images of a movie to use");
848 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
850
851 prop = RNA_def_property(srna, "frame_offset", PROP_INT, PROP_NONE);
852 RNA_def_property_int_sdna(prop, nullptr, "offset");
854 prop, "Offset", "Offset the number of the frame to use in the animation");
855 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
856
857 prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
858 RNA_def_property_int_sdna(prop, nullptr, "sfra");
861 prop,
862 "Start Frame",
863 "Global starting frame of the movie/sequence, assuming first picture has a #1");
864 RNA_def_property_update(prop, 0, "rna_ImageUser_update");
866
867 prop = RNA_def_property(srna, "multilayer_layer", PROP_INT, PROP_UNSIGNED);
868 RNA_def_property_int_sdna(prop, nullptr, "layer");
869 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
870 RNA_def_property_ui_text(prop, "Layer", "Layer in multilayer image");
871
872 prop = RNA_def_property(srna, "multilayer_pass", PROP_INT, PROP_UNSIGNED);
873 RNA_def_property_int_sdna(prop, nullptr, "pass");
874 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
875 RNA_def_property_ui_text(prop, "Pass", "Pass in multilayer image");
876
877 prop = RNA_def_property(srna, "multilayer_view", PROP_INT, PROP_UNSIGNED);
878 RNA_def_property_int_sdna(prop, nullptr, "view");
879 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
880 RNA_def_property_ui_text(prop, "View", "View in multilayer image");
881
882 prop = RNA_def_property(srna, "tile", PROP_INT, PROP_UNSIGNED);
883 RNA_def_property_int_sdna(prop, nullptr, "tile");
885 RNA_def_property_ui_text(prop, "Tile", "Tile in tiled image");
886
888}
889
890/* image.packed_files */
892{
893 StructRNA *srna;
894 PropertyRNA *prop;
895
896 srna = RNA_def_struct(brna, "ImagePackedFile", nullptr);
897 RNA_def_struct_sdna(srna, "ImagePackedFile");
898
899 prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
900 RNA_def_property_pointer_sdna(prop, nullptr, "packedfile");
901 RNA_def_property_ui_text(prop, "Packed File", "");
903
904 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
905 RNA_def_property_string_sdna(prop, nullptr, "filepath");
908
909 prop = RNA_def_property(srna, "view", PROP_INT, PROP_NONE);
910 RNA_def_property_int_sdna(prop, nullptr, "view");
911 RNA_def_property_ui_text(prop, "View Index", "");
913
914 prop = RNA_def_property(srna, "tile_number", PROP_INT, PROP_NONE);
915 RNA_def_property_int_sdna(prop, nullptr, "tile_number");
916 RNA_def_property_ui_text(prop, "Tile Number", "");
918
920}
921
923{
924 StructRNA *srna;
925 PropertyRNA *prop, *parm;
926 FunctionRNA *func;
927
928 srna = RNA_def_struct(brna, "RenderSlot", nullptr);
929 RNA_def_struct_ui_text(srna, "Render Slot", "Parameters defining the render slot");
930
931 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
932 RNA_def_property_string_sdna(prop, nullptr, "name");
933 RNA_def_property_ui_text(prop, "Name", "Render slot name");
935
936 func = RNA_def_function(srna, "clear", "rna_RenderSlot_clear");
938 RNA_def_function_ui_description(func, "Clear the render slot");
939 parm = RNA_def_pointer(func, "iuser", "ImageUser", "ImageUser", "");
941}
942
944{
945 StructRNA *srna;
946 FunctionRNA *func;
947 PropertyRNA *prop, *parm;
948
949 RNA_def_property_srna(cprop, "RenderSlots");
950 srna = RNA_def_struct(brna, "RenderSlots", nullptr);
951 RNA_def_struct_sdna(srna, "Image");
952 RNA_def_struct_ui_text(srna, "Render Layers", "Collection of render layers");
953
954 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
955 RNA_def_property_int_sdna(prop, nullptr, "render_slot");
957 "rna_render_slots_active_index_get",
958 "rna_render_slots_active_index_set",
959 "rna_render_slots_active_index_range");
960 RNA_def_property_ui_text(prop, "Active", "Active render slot of the image");
962
963 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
964 RNA_def_property_struct_type(prop, "RenderSlot");
966 prop, "rna_render_slots_active_get", "rna_render_slots_active_set", nullptr, nullptr);
968 RNA_def_property_ui_text(prop, "Active", "Active render slot of the image");
970
971 func = RNA_def_function(srna, "new", "BKE_image_add_renderslot");
972 RNA_def_function_ui_description(func, "Add a render slot to the image");
973 parm = RNA_def_string(func, "name", nullptr, 0, "Name", "New name for the render slot");
974 parm = RNA_def_pointer(func, "result", "RenderSlot", "", "Newly created render layer");
975 RNA_def_function_return(func, parm);
976}
977
979{
980 StructRNA *srna;
981 PropertyRNA *prop;
982
983 srna = RNA_def_struct(brna, "UDIMTile", nullptr);
984 RNA_def_struct_sdna(srna, "ImageTile");
985 RNA_def_struct_ui_text(srna, "UDIM Tile", "Properties of the UDIM tile");
986
987 prop = RNA_def_property(srna, "label", PROP_STRING, PROP_NONE);
988 RNA_def_property_string_sdna(prop, nullptr, "label");
989 RNA_def_property_ui_text(prop, "Label", "Tile label");
991 prop, "rna_UDIMTile_label_get", "rna_UDIMTile_label_length", nullptr);
993
994 prop = RNA_def_property(srna, "number", PROP_INT, PROP_NONE);
995 RNA_def_property_int_sdna(prop, nullptr, "tile_number");
996 RNA_def_property_ui_text(prop, "Number", "Number of the position that this tile covers");
997 RNA_def_property_int_funcs(prop, nullptr, "rna_UDIMTile_tile_number_set", nullptr);
999
1000 prop = RNA_def_int_vector(
1001 srna,
1002 "size",
1003 2,
1004 nullptr,
1005 0,
1006 0,
1007 "Size",
1008 "Width and height of the tile buffer in pixels, zero when image data can't be loaded",
1009 0,
1010 0);
1012 RNA_def_property_int_funcs(prop, "rna_UDIMTile_size_get", nullptr, nullptr);
1014
1015 prop = RNA_def_property(srna, "channels", PROP_INT, PROP_UNSIGNED);
1016 RNA_def_property_int_funcs(prop, "rna_UDIMTile_channels_get", nullptr, nullptr);
1017 RNA_def_property_ui_text(prop, "Channels", "Number of channels in the tile pixels buffer");
1019
1020 /* Generated tile information. */
1021 prop = RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE);
1022 RNA_def_property_enum_sdna(prop, nullptr, "gen_type");
1024 RNA_def_property_ui_text(prop, "Generated Type", "Generated image type");
1025 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update");
1027
1028 prop = RNA_def_property(srna, "generated_width", PROP_INT, PROP_PIXEL);
1029 RNA_def_property_int_sdna(prop, nullptr, "gen_x");
1031 RNA_def_property_range(prop, 1, 65536);
1032 RNA_def_property_ui_text(prop, "Generated Width", "Generated image width");
1033 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update");
1035
1036 prop = RNA_def_property(srna, "generated_height", PROP_INT, PROP_PIXEL);
1037 RNA_def_property_int_sdna(prop, nullptr, "gen_y");
1039 RNA_def_property_range(prop, 1, 65536);
1040 RNA_def_property_ui_text(prop, "Generated Height", "Generated image height");
1041 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update");
1043
1044 prop = RNA_def_property(srna, "use_generated_float", PROP_BOOLEAN, PROP_NONE);
1045 RNA_def_property_boolean_sdna(prop, nullptr, "gen_flag", IMA_GEN_FLOAT);
1046 RNA_def_property_ui_text(prop, "Float Buffer", "Generate floating-point buffer");
1047 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update");
1049
1050 prop = RNA_def_property(srna, "is_generated_tile", PROP_BOOLEAN, PROP_NONE);
1051 RNA_def_property_boolean_sdna(prop, nullptr, "gen_flag", IMA_GEN_TILE);
1052 RNA_def_property_ui_text(prop, "Is Generated Tile", "Is this image tile generated");
1054
1055 prop = RNA_def_property(srna, "generated_color", PROP_FLOAT, PROP_COLOR_GAMMA);
1056 RNA_def_property_float_sdna(prop, nullptr, "gen_color");
1057 RNA_def_property_array(prop, 4);
1058 RNA_def_property_ui_text(prop, "Color", "Fill color for the generated image");
1059 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update");
1061}
1062
1064{
1065 StructRNA *srna;
1066 PropertyRNA *prop;
1067
1068 FunctionRNA *func;
1069 PropertyRNA *parm;
1070
1071 RNA_def_property_srna(cprop, "UDIMTiles");
1072 srna = RNA_def_struct(brna, "UDIMTiles", nullptr);
1073 RNA_def_struct_sdna(srna, "Image");
1074 RNA_def_struct_ui_text(srna, "UDIM Tiles", "Collection of UDIM tiles");
1075
1076 prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
1077 RNA_def_property_int_sdna(prop, nullptr, "active_tile_index");
1079 "rna_Image_active_tile_index_get",
1080 "rna_Image_active_tile_index_set",
1081 "rna_Image_active_tile_index_range");
1082 RNA_def_property_ui_text(prop, "Active Tile Index", "Active index in tiles array");
1083
1084 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1085 RNA_def_property_struct_type(prop, "UDIMTile");
1087 prop, "rna_Image_active_tile_get", "rna_Image_active_tile_set", nullptr, nullptr);
1089 RNA_def_property_ui_text(prop, "Active Image Tile", "Active Image Tile");
1090
1091 func = RNA_def_function(srna, "new", "rna_UDIMTile_new");
1092 RNA_def_function_ui_description(func, "Add a tile to the image");
1093 parm = RNA_def_int(
1094 func, "tile_number", 1, 1, INT_MAX, "", "Number of the newly created tile", 1, 100);
1096 parm = RNA_def_string(func, "label", nullptr, 0, "", "Optional label for the tile");
1097 parm = RNA_def_pointer(func, "result", "UDIMTile", "", "Newly created image tile");
1098 RNA_def_function_return(func, parm);
1099
1100 func = RNA_def_function(srna, "get", "BKE_image_get_tile");
1101 RNA_def_function_ui_description(func, "Get a tile based on its tile number");
1102 parm = RNA_def_int(func, "tile_number", 0, 0, INT_MAX, "", "Number of the tile", 0, 100);
1104 parm = RNA_def_pointer(func, "result", "UDIMTile", "", "The tile");
1105 RNA_def_function_return(func, parm);
1106
1107 func = RNA_def_function(srna, "remove", "rna_UDIMTile_remove");
1108 RNA_def_function_ui_description(func, "Remove an image tile");
1109 parm = RNA_def_pointer(func, "tile", "UDIMTile", "", "Image tile to remove");
1112}
1113
1114static void rna_def_image(BlenderRNA *brna)
1115{
1116 StructRNA *srna;
1117 PropertyRNA *prop;
1118 static const EnumPropertyItem prop_type_items[] = {
1119 {IMA_TYPE_IMAGE, "IMAGE", 0, "Image", ""},
1120 {IMA_TYPE_MULTILAYER, "MULTILAYER", 0, "Multilayer", ""},
1121 {IMA_TYPE_UV_TEST, "UV_TEST", 0, "UV Test", ""},
1122 {IMA_TYPE_R_RESULT, "RENDER_RESULT", 0, "Render Result", ""},
1123 {IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""},
1124 {0, nullptr, 0, nullptr, nullptr},
1125 };
1126 static const EnumPropertyItem alpha_mode_items[] = {
1128 "STRAIGHT",
1129 0,
1130 "Straight",
1131 "Store RGB and alpha channels separately with alpha acting as a mask, also known as "
1132 "unassociated alpha. Commonly used by image editing applications and file formats like "
1133 "PNG."},
1135 "PREMUL",
1136 0,
1137 "Premultiplied",
1138 "Store RGB channels with alpha multiplied in, also known as associated alpha. The natural "
1139 "format for renders and used by file formats like OpenEXR."},
1141 "CHANNEL_PACKED",
1142 0,
1143 "Channel Packed",
1144 "Different images are packed in the RGB and alpha channels, and they should not "
1145 "affect each other. Channel packing is commonly used by game engines to save memory."},
1147 "NONE",
1148 0,
1149 "None",
1150 "Ignore alpha channel from the file and make image fully opaque"},
1151 {0, nullptr, 0, nullptr, nullptr},
1152 };
1153
1154 srna = RNA_def_struct(brna, "Image", "ID");
1156 srna, "Image", "Image data-block referencing an external or packed image");
1157 RNA_def_struct_ui_icon(srna, ICON_IMAGE_DATA);
1158
1159 prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
1161 RNA_def_property_string_sdna(prop, nullptr, "filepath");
1163 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name");
1164 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_reload_update");
1165
1166 /* eek. this is horrible but needed so we can save to a new name without blanking the data :( */
1167 prop = RNA_def_property(srna, "filepath_raw", PROP_STRING, PROP_FILEPATH);
1168 RNA_def_property_string_sdna(prop, nullptr, "filepath");
1170 RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name (without data refreshing)");
1171
1172 prop = RNA_def_property(srna, "file_format", PROP_ENUM, PROP_NONE);
1175 prop, "rna_Image_file_format_get", "rna_Image_file_format_set", nullptr);
1176 RNA_def_property_ui_text(prop, "File Format", "Format used for re-saving this file");
1177
1178 prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
1181 RNA_def_property_enum_funcs(prop, nullptr, "rna_Image_source_set", "rna_Image_source_itemf");
1182 RNA_def_property_ui_text(prop, "Source", "Where the image comes from");
1184
1185 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
1186 RNA_def_property_enum_items(prop, prop_type_items);
1188 RNA_def_property_ui_text(prop, "Type", "How to generate the image");
1190
1191 prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
1192 RNA_def_property_struct_type(prop, "PackedFile");
1193 RNA_def_property_pointer_sdna(prop, nullptr, "packedfile");
1194 RNA_def_property_pointer_funcs(prop, "rna_Image_packed_file_get", nullptr, nullptr, nullptr);
1195 RNA_def_property_ui_text(prop, "Packed File", "First packed file of the image");
1196
1197 prop = RNA_def_property(srna, "packed_files", PROP_COLLECTION, PROP_NONE);
1198 RNA_def_property_collection_sdna(prop, nullptr, "packedfiles", nullptr);
1199 RNA_def_property_struct_type(prop, "ImagePackedFile");
1201 RNA_def_property_ui_text(prop, "Packed Files", "Collection of packed images");
1202
1203 prop = RNA_def_property(srna, "use_view_as_render", PROP_BOOLEAN, PROP_NONE);
1205 RNA_def_property_boolean_sdna(prop, nullptr, "flag", IMA_VIEW_AS_RENDER);
1207 prop,
1208 "View as Render",
1209 "Apply render part of display transformation when displaying this image on the screen");
1211
1212 prop = RNA_def_property(srna, "use_deinterlace", PROP_BOOLEAN, PROP_NONE);
1214 RNA_def_property_boolean_sdna(prop, nullptr, "flag", IMA_DEINTERLACE);
1215 RNA_def_property_ui_text(prop, "Deinterlace", "Deinterlace movie file on load");
1216 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_reload_update");
1217
1218 prop = RNA_def_property(srna, "use_multiview", PROP_BOOLEAN, PROP_NONE);
1220 RNA_def_property_boolean_sdna(prop, nullptr, "flag", IMA_USE_VIEWS);
1221 RNA_def_property_ui_text(prop, "Use Multi-View", "Use Multiple Views (when available)");
1222 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_views_format_update");
1223
1224 prop = RNA_def_property(srna, "is_stereo_3d", PROP_BOOLEAN, PROP_NONE);
1226 RNA_def_property_boolean_funcs(prop, "rna_Image_is_stereo_3d_get", nullptr);
1227 RNA_def_property_ui_text(prop, "Stereo 3D", "Image has left and right views");
1229
1230 prop = RNA_def_property(srna, "is_multiview", PROP_BOOLEAN, PROP_NONE);
1232 RNA_def_property_boolean_funcs(prop, "rna_Image_is_multiview_get", nullptr);
1233 RNA_def_property_ui_text(prop, "Multiple Views", "Image has more than one view");
1235
1236 prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
1238 RNA_def_property_boolean_funcs(prop, "rna_Image_dirty_get", nullptr);
1240 RNA_def_property_ui_text(prop, "Dirty", "Image has changed and is not saved");
1241
1242 /* generated image (image_generated_change_cb) */
1243 prop = RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE);
1244 RNA_def_property_enum_sdna(prop, nullptr, "gen_type");
1246 RNA_def_property_ui_text(prop, "Generated Type", "Generated image type");
1248 prop, "rna_Image_generated_type_get", "rna_Image_generated_type_set", nullptr);
1249 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
1251
1252 prop = RNA_def_property(srna, "generated_width", PROP_INT, PROP_PIXEL);
1253 RNA_def_property_int_sdna(prop, nullptr, "gen_x");
1255 RNA_def_property_range(prop, 1, 65536);
1256 RNA_def_property_ui_text(prop, "Generated Width", "Generated image width");
1258 prop, "rna_Image_generated_width_get", "rna_Image_generated_width_set", nullptr);
1259 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
1261
1262 prop = RNA_def_property(srna, "generated_height", PROP_INT, PROP_PIXEL);
1263 RNA_def_property_int_sdna(prop, nullptr, "gen_y");
1265 RNA_def_property_range(prop, 1, 65536);
1266 RNA_def_property_ui_text(prop, "Generated Height", "Generated image height");
1268 prop, "rna_Image_generated_height_get", "rna_Image_generated_height_set", nullptr);
1269 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
1271
1272 prop = RNA_def_property(srna, "use_generated_float", PROP_BOOLEAN, PROP_NONE);
1273 RNA_def_property_boolean_sdna(prop, nullptr, "gen_flag", IMA_GEN_FLOAT);
1274 RNA_def_property_ui_text(prop, "Float Buffer", "Generate floating-point buffer");
1276 prop, "rna_Image_generated_float_get", "rna_Image_generated_float_set");
1277 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
1279
1280 prop = RNA_def_property(srna, "generated_color", PROP_FLOAT, PROP_COLOR_GAMMA);
1281 RNA_def_property_float_sdna(prop, nullptr, "gen_color");
1282 RNA_def_property_array(prop, 4);
1283 RNA_def_property_ui_text(prop, "Color", "Fill color for the generated image");
1285 prop, "rna_Image_generated_color_get", "rna_Image_generated_color_set", nullptr);
1286 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
1288
1289 prop = RNA_def_property(srna, "display_aspect", PROP_FLOAT, PROP_XYZ);
1291 RNA_def_property_float_sdna(prop, nullptr, "aspx");
1292 RNA_def_property_array(prop, 2);
1293 RNA_def_property_range(prop, 0.1f, FLT_MAX);
1294 RNA_def_property_ui_range(prop, 0.1f, 5000.0f, 1, 2);
1296 prop, "Display Aspect", "Display Aspect for this image, does not affect rendering");
1298
1299 prop = RNA_def_property(srna, "bindcode", PROP_INT, PROP_UNSIGNED);
1300 RNA_def_property_int_funcs(prop, "rna_Image_bindcode_get", nullptr, nullptr);
1302 RNA_def_property_ui_text(prop, "Bindcode", "OpenGL bindcode");
1304
1305 prop = RNA_def_property(srna, "render_slots", PROP_COLLECTION, PROP_NONE);
1306 RNA_def_property_struct_type(prop, "RenderSlot");
1307 RNA_def_property_collection_sdna(prop, nullptr, "renderslots", nullptr);
1308 RNA_def_property_ui_text(prop, "Render Slots", "Render slots of the image");
1309 rna_def_render_slots(brna, prop);
1310
1311 prop = RNA_def_property(srna, "tiles", PROP_COLLECTION, PROP_NONE);
1312 RNA_def_property_struct_type(prop, "UDIMTile");
1313 RNA_def_property_collection_sdna(prop, nullptr, "tiles", nullptr);
1314 RNA_def_property_ui_text(prop, "Image Tiles", "Tiles of the image");
1315 rna_def_udim_tiles(brna, prop);
1316
1317 prop = RNA_def_property(srna, "has_data", PROP_BOOLEAN, PROP_NONE);
1318 RNA_def_property_boolean_funcs(prop, "rna_Image_has_data_get", nullptr);
1320 RNA_def_property_ui_text(prop, "Has Data", "True if the image data is loaded into memory");
1321
1322 prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
1323 RNA_def_property_int_funcs(prop, "rna_Image_depth_get", nullptr, nullptr);
1324 RNA_def_property_ui_text(prop, "Depth", "Image bit depth");
1326
1327 prop = RNA_def_int_vector(
1328 srna,
1329 "size",
1330 2,
1331 nullptr,
1332 0,
1333 0,
1334 "Size",
1335 "Width and height of the image buffer in pixels, zero when image data can't be loaded",
1336 0,
1337 0);
1339 RNA_def_property_int_funcs(prop, "rna_Image_size_get", nullptr, nullptr);
1341
1342 prop = RNA_def_float_vector(srna,
1343 "resolution",
1344 2,
1345 nullptr,
1346 0,
1347 0,
1348 "Resolution",
1349 "X/Y pixels per meter, for the image buffer",
1350 0,
1351 0);
1354 prop, "rna_Image_resolution_get", "rna_Image_resolution_set", nullptr);
1355
1356 prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_UNSIGNED);
1357 RNA_def_property_int_funcs(prop, "rna_Image_frame_duration_get", nullptr, nullptr);
1359 prop, "Duration", "Duration (in frames) of the image (1 when not a video/sequence)");
1361
1362 /* NOTE: About pixels/channels/is_float:
1363 * These properties describe how the image is stored internally (inside of ImBuf),
1364 * not how it was saved to disk or how it'll be saved on disk.
1365 */
1366 prop = RNA_def_property(srna, "pixels", PROP_FLOAT, PROP_NONE);
1368 RNA_def_property_multi_array(prop, 1, nullptr);
1369 RNA_def_property_ui_text(prop, "Pixels", "Image buffer pixels in floating-point values");
1370 RNA_def_property_dynamic_array_funcs(prop, "rna_Image_pixels_get_length");
1371 RNA_def_property_float_funcs(prop, "rna_Image_pixels_get", "rna_Image_pixels_set", nullptr);
1372
1373 prop = RNA_def_property(srna, "channels", PROP_INT, PROP_UNSIGNED);
1374 RNA_def_property_int_funcs(prop, "rna_Image_channels_get", nullptr, nullptr);
1375 RNA_def_property_ui_text(prop, "Channels", "Number of channels in pixels buffer");
1377
1378 prop = RNA_def_property(srna, "is_float", PROP_BOOLEAN, PROP_NONE);
1379 RNA_def_property_boolean_funcs(prop, "rna_Image_is_float_get", nullptr);
1382 prop, "Is Float", "True if this image is stored in floating-point buffer");
1383
1384 prop = RNA_def_property(srna, "colorspace_settings", PROP_POINTER, PROP_NONE);
1385 RNA_def_property_pointer_sdna(prop, nullptr, "colorspace_settings");
1386 RNA_def_property_struct_type(prop, "ColorManagedInputColorspaceSettings");
1387 RNA_def_property_ui_text(prop, "Color Space Settings", "Input color space settings");
1388
1389 prop = RNA_def_property(srna, "alpha_mode", PROP_ENUM, PROP_NONE);
1391 RNA_def_property_enum_items(prop, alpha_mode_items);
1393 "Alpha Mode",
1394 "Representation of alpha in the image file, to convert to and from "
1395 "when saving and loading the image");
1396 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_alpha_mode_update");
1397
1398 prop = RNA_def_property(srna, "use_half_precision", PROP_BOOLEAN, PROP_NONE);
1401 "Half Float Precision",
1402 "Use 16 bits per channel to lower the memory usage during rendering");
1403 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_gpu_texture_update");
1404
1405 prop = RNA_def_property(srna, "seam_margin", PROP_INT, PROP_NONE);
1407 prop,
1408 "Seam Margin",
1409 "Margin to take into account when fixing UV seams during painting. Higher "
1410 "number would improve seam-fixes for mipmaps, but decreases performance.");
1411 RNA_def_property_ui_range(prop, 1, 100, 1, 1);
1412
1413 /* multiview */
1414 prop = RNA_def_property(srna, "views_format", PROP_ENUM, PROP_NONE);
1416 RNA_def_property_enum_sdna(prop, nullptr, "views_format");
1418 RNA_def_property_ui_text(prop, "Views Format", "Mode to load image views");
1419 RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_views_format_update");
1420
1421 prop = RNA_def_property(srna, "stereo_3d_format", PROP_POINTER, PROP_NONE);
1422 RNA_def_property_pointer_sdna(prop, nullptr, "stereo3d_format");
1424 RNA_def_property_struct_type(prop, "Stereo3dFormat");
1425 RNA_def_property_ui_text(prop, "Stereo 3D Format", "Settings for stereo 3d");
1426
1427 RNA_api_image(srna);
1428}
1429
1431{
1432 rna_def_render_slot(brna);
1433 rna_def_udim_tile(brna);
1434 rna_def_image(brna);
1435 rna_def_imageuser(brna);
1437}
1438
1439#endif
#define G_MAIN
RenderSlot * BKE_image_get_renderslot(Image *ima, int index)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
void BKE_image_user_frame_calc(Image *ima, ImageUser *iuser, int cfra)
void BKE_image_mark_dirty(Image *image, ImBuf *ibuf)
bool BKE_image_fill_tile(Image *ima, ImageTile *tile)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
bool BKE_image_is_dirty(Image *image)
#define IMA_SIGNAL_COLORMANAGE
Definition BKE_image.hh:167
int BKE_image_get_tile_label(const Image *ima, const ImageTile *tile, char *label, int label_maxncpy)
bool BKE_image_has_anim(Image *image)
#define IMA_SIGNAL_FREE
Definition BKE_image.hh:162
void BKE_imageuser_default(ImageUser *iuser)
void BKE_image_free_gputextures(Image *ima)
Definition image_gpu.cc:570
#define IMA_SIGNAL_SRC_CHANGE
Definition BKE_image.hh:164
bool BKE_image_is_stereo(const Image *ima)
bool BKE_image_is_multiview(const Image *ima)
#define IMA_SIGNAL_RELOAD
Definition BKE_image.hh:161
bool BKE_image_has_packedfile(const Image *image)
void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
void BKE_image_reassign_tile(Image *ima, ImageTile *tile, int new_tile_number)
bool BKE_image_clear_renderslot(Image *ima, ImageUser *iuser, int slot)
ImageTile * BKE_image_add_tile(Image *ima, int tile_number, const char *label)
void BKE_image_file_format_set(Image *image, int ftype, const ImbFormatOptions *options)
bool BKE_image_remove_tile(Image *ima, ImageTile *tile)
void BKE_image_partial_update_mark_full_update(Image *image)
Mark the whole image to be updated.
bool BKE_image_has_loaded_ibuf(Image *image)
char BKE_ftype_to_imtype(int ftype, const ImbFormatOptions *options)
int BKE_imtype_to_ftype(char imtype, ImbFormatOptions *r_options)
bool BKE_imtype_is_movie(char imtype)
bool BKE_id_is_in_global_main(ID *id)
Definition lib_id.cc:2480
void BKE_main_ensure_invariants(Main &bmain, std::optional< blender::Span< ID * > > modified_ids=std::nullopt)
void BKE_ntree_update_tag_image_user_changed(bNodeTree *ntree, ImageUser *iuser)
#define BLI_assert(a)
Definition BLI_assert.h:46
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:534
#define LISTBASE_FOREACH_INDEX(type, var, list, index_var)
int BLI_listbase_count(const ListBase *listbase) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:524
MINLINE int min_ii(int a, int b)
MINLINE int max_ii(int a, int b)
MINLINE void copy_v4_v4(float r[4], const float a[4])
unsigned int uint
#define CLAMP(a, b, c)
#define BLT_I18NCONTEXT_ID_IMAGE
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1051
@ ID_RECALC_EDITORS
Definition DNA_ID.h:1019
@ ID_CA
@ ID_TE
@ ID_NT
@ ID_SCR
@ ID_OB
@ IMA_GEN_TILE
@ IMA_GEN_FLOAT
@ IMA_ANIM_ALWAYS
@ IMA_SRC_FILE
@ IMA_SRC_MOVIE
@ IMA_SRC_GENERATED
@ IMA_SRC_VIEWER
@ IMA_SRC_TILED
@ IMA_SRC_SEQUENCE
@ IMA_ALPHA_IGNORE
@ IMA_ALPHA_STRAIGHT
@ IMA_ALPHA_PREMUL
@ IMA_ALPHA_CHANNEL_PACKED
@ IMA_DEINTERLACE
@ IMA_HIGH_BITDEPTH
@ IMA_USE_VIEWS
@ IMA_VIEW_AS_RENDER
@ IMA_TYPE_MULTILAYER
@ IMA_TYPE_UV_TEST
@ IMA_TYPE_R_RESULT
@ IMA_TYPE_COMPOSITE
@ IMA_TYPE_IMAGE
@ IMA_GENTYPE_GRID_COLOR
@ IMA_GENTYPE_GRID
@ IMA_GENTYPE_BLANK
@ TEXTARGET_2D
#define MINAFRAME
#define MAXFRAMEF
#define MINAFRAMEF
#define MAXFRAME
@ SPACE_IMAGE
int GPU_texture_opengl_bindcode(const GPUTexture *texture)
size_t IMB_get_pixel_count(const ImBuf *ibuf)
Get the length of the data of the given image buffer in pixels.
@ IMB_FTYPE_NONE
@ IB_MIPMAP_INVALID
@ IB_DISPLAY_BUFFER_INVALID
@ IMB_TC_RECORD_RUN
Definition MOV_enums.hh:54
#define RNA_MAX_ARRAY_DIMENSION
Definition RNA_define.hh:26
ParameterFlag
Definition RNA_types.hh:510
@ PARM_RNAPTR
Definition RNA_types.hh:513
@ PARM_REQUIRED
Definition RNA_types.hh:511
@ FUNC_USE_SELF_ID
Definition RNA_types.hh:792
@ PROP_FLOAT
Definition RNA_types.hh:152
@ PROP_BOOLEAN
Definition RNA_types.hh:150
@ PROP_ENUM
Definition RNA_types.hh:154
@ PROP_INT
Definition RNA_types.hh:151
@ PROP_STRING
Definition RNA_types.hh:153
@ PROP_POINTER
Definition RNA_types.hh:155
@ PROP_COLLECTION
Definition RNA_types.hh:156
@ PROPOVERRIDE_OVERRIDABLE_LIBRARY
Definition RNA_types.hh:469
PropertyFlag
Definition RNA_types.hh:286
@ PROP_THICK_WRAP
Definition RNA_types.hh:397
@ PROP_DYNAMIC
Definition RNA_types.hh:402
@ PROP_ANIMATABLE
Definition RNA_types.hh:305
@ PROP_PROPORTIONAL
Definition RNA_types.hh:335
@ PROP_PATH_SUPPORTS_BLEND_RELATIVE
Definition RNA_types.hh:430
@ PROP_EDITABLE
Definition RNA_types.hh:292
@ PROP_NEVER_NULL
Definition RNA_types.hh:351
@ PROP_TIME
Definition RNA_types.hh:241
@ PROP_XYZ
Definition RNA_types.hh:257
@ PROP_PIXEL
Definition RNA_types.hh:236
@ PROP_NONE
Definition RNA_types.hh:221
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:260
@ PROP_UNSIGNED
Definition RNA_types.hh:237
@ PROP_FILEPATH
Definition RNA_types.hh:224
#define ND_DRAW
Definition WM_types.hh:458
#define ND_DISPLAY
Definition WM_types.hh:488
#define NA_EDITED
Definition WM_types.hh:581
#define NC_IMAGE
Definition WM_types.hh:381
volatile int lock
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
CCL_NAMESPACE_BEGIN struct Options options
float length(VecOp< float, D >) RET
#define GS(a)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile const int num_tiles
const ccl_global KernelWorkTile * tile
MINLINE unsigned char unit_float_to_uchar_clamp(float val)
#define G(x, y, z)
int MOV_get_duration_frames(MovieReader *anim, IMB_Timecode_Type tc)
const PointerRNA PointerRNA_NULL
PointerRNA RNA_pointer_create_with_parent(const PointerRNA &parent, StructRNA *type, void *data)
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_struct_name_property(StructRNA *srna, PropertyRNA *prop)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_define_lib_overridable(const bool make_overridable)
void RNA_def_struct_path_func(StructRNA *srna, const char *path)
void RNA_def_parameter_clear_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_srna(PropertyRNA *prop, const char *type)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
PropertyRNA * RNA_def_float_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const float *default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_property_dynamic_array_funcs(PropertyRNA *prop, const char *getlength)
void RNA_def_property_multi_array(PropertyRNA *prop, int dimension, const int length[])
PropertyRNA * RNA_def_int_vector(StructOrFunctionRNA *cont_, const char *identifier, const int len, const int *default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_property_collection_sdna(PropertyRNA *prop, const char *structname, const char *propname, const char *lengthpropname)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_struct_ui_icon(StructRNA *srna, int icon)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
void RNA_def_property_float_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_enum_items_add_value(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item, int value)
void RNA_def_property_ui_range(PropertyRNA *prop, double min, double max, double step, int precision)
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_property_boolean_negative_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
void RNA_def_property_override_flag(PropertyRNA *prop, PropertyOverrideFlag flag)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
void RNA_def_image(BlenderRNA *brna)
static void rna_def_image(BlenderRNA *brna)
static void rna_def_render_slot(BlenderRNA *brna)
Definition rna_image.cc:922
static void rna_def_render_slots(BlenderRNA *brna, PropertyRNA *cprop)
Definition rna_image.cc:943
static const EnumPropertyItem image_source_items[]
Definition rna_image.cc:35
static void rna_def_image_packed_files(BlenderRNA *brna)
Definition rna_image.cc:891
static void rna_def_udim_tile(BlenderRNA *brna)
Definition rna_image.cc:978
static void rna_def_udim_tiles(BlenderRNA *brna, PropertyRNA *cprop)
static void rna_def_imageuser(BlenderRNA *brna)
Definition rna_image.cc:811
const EnumPropertyItem rna_enum_image_generated_type_items[]
Definition rna_image.cc:24
void RNA_api_image(StructRNA *srna)
void RNA_api_image_packed_file(StructRNA *srna)
std::optional< std::string > rna_CameraBackgroundImage_image_or_movieclip_user_path(const PointerRNA *ptr)
std::optional< std::string > rna_Node_ImageUser_path(const PointerRNA *ptr)
const EnumPropertyItem rna_enum_image_type_items[]
Definition rna_scene.cc:362
const EnumPropertyItem rna_enum_views_format_items[]
Definition rna_scene.cc:481
#define min(a, b)
Definition sort.cc:36
#define FLT_MAX
Definition stdcycles.h:14
Definition DNA_ID.h:404
char name[66]
Definition DNA_ID.h:415
ImBufFloatBuffer float_buffer
ImbFormatOptions foptions
ImBufByteBuffer byte_buffer
unsigned char planes
enum eImbFileType ftype
double ppm[2]
struct PackedFile * packedfile
float gen_color[4]
struct Scene * scene
ListBase renderslots
short source
struct RenderData r
struct ImageUser iuser
ListBase areabase
void * BKE_image_get_tile
Definition stubs.c:36
i
Definition text_draw.cc:230
max
Definition text_draw.cc:251
uint len
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4227