/
rna_image.c
1410 lines (1172 loc) · 49.2 KB
/
rna_image.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup RNA
*/
#include <stdlib.h>
#include "DNA_image_types.h"
#include "DNA_node_types.h"
#include "DNA_scene_types.h"
#include "BLI_utildefines.h"
#include "BKE_image.h"
#include "BKE_image_format.h"
#include "BKE_node_tree_update.h"
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "rna_internal.h"
#include "WM_api.h"
#include "WM_types.h"
const EnumPropertyItem rna_enum_image_generated_type_items[] = {
{IMA_GENTYPE_BLANK, "BLANK", 0, "Blank", "Generate a blank image"},
{IMA_GENTYPE_GRID, "UV_GRID", 0, "UV Grid", "Generated grid to test UV mappings"},
{IMA_GENTYPE_GRID_COLOR,
"COLOR_GRID",
0,
"Color Grid",
"Generated improved UV grid to test UV mappings"},
{0, NULL, 0, NULL, NULL},
};
static const EnumPropertyItem image_source_items[] = {
{IMA_SRC_FILE, "FILE", 0, "Single Image", "Single image file"},
{IMA_SRC_SEQUENCE, "SEQUENCE", 0, "Image Sequence", "Multiple image files, as a sequence"},
{IMA_SRC_MOVIE, "MOVIE", 0, "Movie", "Movie file"},
{IMA_SRC_GENERATED, "GENERATED", 0, "Generated", "Generated image"},
{IMA_SRC_VIEWER, "VIEWER", 0, "Viewer", "Compositing node viewer"},
{IMA_SRC_TILED, "TILED", 0, "UDIM Tiles", "Tiled UDIM image texture"},
{0, NULL, 0, NULL, NULL},
};
#ifdef RNA_RUNTIME
# include "BLI_math_base.h"
# include "BLI_math_vector.h"
# include "BKE_global.h"
# include "GPU_texture.h"
# include "IMB_imbuf.h"
# include "IMB_imbuf_types.h"
# include "ED_node.h"
static bool rna_Image_is_stereo_3d_get(PointerRNA *ptr)
{
return BKE_image_is_stereo((Image *)ptr->data);
}
static bool rna_Image_is_multiview_get(PointerRNA *ptr)
{
return BKE_image_is_multiview((Image *)ptr->data);
}
static bool rna_Image_dirty_get(PointerRNA *ptr)
{
return BKE_image_is_dirty((Image *)ptr->data);
}
static void rna_Image_source_set(PointerRNA *ptr, int value)
{
Image *ima = (Image *)ptr->owner_id;
if (value != ima->source) {
ima->source = value;
BLI_assert(BKE_id_is_in_global_main(&ima->id));
BKE_image_signal(G_MAIN, ima, NULL, IMA_SIGNAL_SRC_CHANGE);
if (ima->source == IMA_SRC_TILED) {
BKE_image_signal(G_MAIN, ima, NULL, IMA_SIGNAL_RELOAD);
}
DEG_id_tag_update(&ima->id, 0);
DEG_id_tag_update(&ima->id, ID_RECALC_EDITORS);
DEG_relations_tag_update(G_MAIN);
}
}
static void rna_Image_reload_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_RELOAD);
WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
DEG_id_tag_update(&ima->id, 0);
DEG_id_tag_update(&ima->id, ID_RECALC_EDITORS);
}
static int rna_Image_generated_type_get(PointerRNA *ptr)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
return base_tile->gen_type;
}
static void rna_Image_generated_type_set(PointerRNA *ptr, int value)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
base_tile->gen_type = value;
}
static int rna_Image_generated_width_get(PointerRNA *ptr)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
return base_tile->gen_x;
}
static void rna_Image_generated_width_set(PointerRNA *ptr, int value)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
base_tile->gen_x = CLAMPIS(value, 1, 65536);
}
static int rna_Image_generated_height_get(PointerRNA *ptr)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
return base_tile->gen_y;
}
static void rna_Image_generated_height_set(PointerRNA *ptr, int value)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
base_tile->gen_y = CLAMPIS(value, 1, 65536);
}
static bool rna_Image_generated_float_get(PointerRNA *ptr)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
return (base_tile->gen_flag & IMA_GEN_FLOAT) != 0;
}
static void rna_Image_generated_float_set(PointerRNA *ptr, bool value)
{
Image *ima = (Image *)ptr->data;
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
if (value) {
base_tile->gen_flag |= IMA_GEN_FLOAT;
}
else {
base_tile->gen_flag &= ~IMA_GEN_FLOAT;
}
}
void rna_Image_generated_color_get(PointerRNA *ptr, float values[4])
{
Image *ima = (Image *)(ptr->data);
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
copy_v4_v4(values, base_tile->gen_color);
}
void rna_Image_generated_color_set(PointerRNA *ptr, const float values[4])
{
Image *ima = (Image *)(ptr->data);
ImageTile *base_tile = BKE_image_get_tile(ima, 0);
for (uint i = 0; i < 4; i++) {
base_tile->gen_color[i] = CLAMPIS(values[i], 0.0f, FLT_MAX);
}
}
static void rna_Image_generated_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_FREE);
BKE_image_partial_update_mark_full_update(ima);
}
static void rna_Image_colormanage_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
BKE_image_signal(bmain, ima, NULL, IMA_SIGNAL_COLORMANAGE);
DEG_id_tag_update(&ima->id, 0);
DEG_id_tag_update(&ima->id, ID_RECALC_EDITORS | ID_RECALC_SOURCE);
WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
}
static void rna_Image_alpha_mode_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
/* When operating on a generated image, avoid re-generating when changing the alpha-mode
* as it doesn't impact generated images, causing them to reload pixel data, see #82785. */
if (ima->source == IMA_SRC_GENERATED) {
return;
}
rna_Image_colormanage_update(bmain, scene, ptr);
}
static void rna_Image_views_format_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
ImBuf *ibuf;
void *lock;
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
if (ibuf) {
ImageUser iuser = {NULL};
iuser.scene = scene;
BKE_image_signal(bmain, ima, &iuser, IMA_SIGNAL_FREE);
}
BKE_image_release_ibuf(ima, ibuf, lock);
BKE_image_partial_update_mark_full_update(ima);
}
static void rna_ImageUser_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
ImageUser *iuser = ptr->data;
ID *id = ptr->owner_id;
if (scene != NULL) {
BKE_image_user_frame_calc(NULL, iuser, scene->r.cfra);
}
if (id) {
if (GS(id->name) == ID_NT) {
/* Special update for nodetrees. */
BKE_ntree_update_tag_image_user_changed((bNodeTree *)id, iuser);
ED_node_tree_propagate_change(NULL, bmain, NULL);
}
else {
/* Update material or texture for render preview. */
DEG_id_tag_update(id, 0);
DEG_id_tag_update(id, ID_RECALC_EDITORS);
}
}
}
static void rna_ImageUser_relations_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
rna_ImageUser_update(bmain, scene, ptr);
DEG_relations_tag_update(bmain);
}
static char *rna_ImageUser_path(const PointerRNA *ptr)
{
if (ptr->owner_id) {
/* ImageUser *iuser = ptr->data; */
switch (GS(ptr->owner_id->name)) {
case ID_OB:
case ID_TE:
return BLI_strdup("image_user");
case ID_NT:
return rna_Node_ImageUser_path(ptr);
case ID_CA:
return rna_CameraBackgroundImage_image_or_movieclip_user_path(ptr);
default:
break;
}
}
return BLI_strdup("");
}
static void rna_Image_gpu_texture_update(Main *UNUSED(bmain),
Scene *UNUSED(scene),
PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
if (!G.background) {
BKE_image_free_gputextures(ima);
}
WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
}
static const EnumPropertyItem *rna_Image_source_itemf(bContext *UNUSED(C),
PointerRNA *ptr,
PropertyRNA *UNUSED(prop),
bool *r_free)
{
Image *ima = (Image *)ptr->data;
EnumPropertyItem *item = NULL;
int totitem = 0;
if (ima->source == IMA_SRC_VIEWER) {
RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_VIEWER);
}
else {
RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_FILE);
RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_SEQUENCE);
RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_MOVIE);
RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_GENERATED);
RNA_enum_items_add_value(&item, &totitem, image_source_items, IMA_SRC_TILED);
}
RNA_enum_item_end(&item, &totitem);
*r_free = true;
return item;
}
static int rna_Image_file_format_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->data;
ImBuf *ibuf = BKE_image_acquire_ibuf(image, NULL, NULL);
int imtype = BKE_ftype_to_imtype(ibuf ? ibuf->ftype : IMB_FTYPE_NONE,
ibuf ? &ibuf->foptions : NULL);
BKE_image_release_ibuf(image, ibuf, NULL);
return imtype;
}
static void rna_Image_file_format_set(PointerRNA *ptr, int value)
{
Image *image = (Image *)ptr->data;
if (BKE_imtype_is_movie(value) == 0) { /* should be able to throw an error here */
ImbFormatOptions options;
int ftype = BKE_imtype_to_ftype(value, &options);
BKE_image_file_format_set(image, ftype, &options);
}
}
static void rna_UDIMTile_size_get(PointerRNA *ptr, int *values)
{
ImageTile *tile = (ImageTile *)ptr->data;
Image *image = (Image *)ptr->owner_id;
ImageUser image_user;
BKE_imageuser_default(&image_user);
image_user.tile = tile->tile_number;
void *lock;
ImBuf *ibuf = BKE_image_acquire_ibuf(image, &image_user, &lock);
if (ibuf) {
values[0] = ibuf->x;
values[1] = ibuf->y;
}
else {
values[0] = 0;
values[1] = 0;
}
BKE_image_release_ibuf(image, ibuf, lock);
}
static int rna_UDIMTile_channels_get(PointerRNA *ptr)
{
ImageTile *tile = (ImageTile *)ptr->data;
Image *image = (Image *)ptr->owner_id;
ImageUser image_user;
BKE_imageuser_default(&image_user);
image_user.tile = tile->tile_number;
int channels = 0;
void *lock;
ImBuf *ibuf = BKE_image_acquire_ibuf(image, &image_user, &lock);
if (ibuf) {
channels = ibuf->channels;
}
BKE_image_release_ibuf(image, ibuf, lock);
return channels;
}
static void rna_UDIMTile_label_get(PointerRNA *ptr, char *value)
{
const ImageTile *tile = (ImageTile *)ptr->data;
const Image *image = (Image *)ptr->owner_id;
/* Pass in a fixed size buffer as the value may be allocated based on the callbacks length. */
char value_buf[sizeof(tile->label)];
int len = BKE_image_get_tile_label(image, tile, value_buf, sizeof(tile->label));
memcpy(value, value_buf, len + 1);
}
static int rna_UDIMTile_label_length(PointerRNA *ptr)
{
const ImageTile *tile = (ImageTile *)ptr->data;
const Image *image = (Image *)ptr->owner_id;
char label[sizeof(tile->label)];
return BKE_image_get_tile_label(image, tile, label, sizeof(label));
}
static void rna_UDIMTile_tile_number_set(PointerRNA *ptr, int value)
{
ImageTile *tile = (ImageTile *)ptr->data;
Image *image = (Image *)ptr->owner_id;
/* Check that no other tile already has that number. */
ImageTile *cur_tile = BKE_image_get_tile(image, value);
if (cur_tile == NULL) {
BKE_image_reassign_tile(image, tile, value);
}
}
static void rna_UDIMTile_generated_update(Main *UNUSED(bmain),
Scene *UNUSED(scene),
PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
ImageTile *tile = (ImageTile *)ptr->data;
/* If the tile is still marked as generated, then update the tile as requested. */
if ((tile->gen_flag & IMA_GEN_TILE) != 0) {
BKE_image_fill_tile(ima, tile);
BKE_image_partial_update_mark_full_update(ima);
}
}
static int rna_Image_active_tile_index_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->data;
return image->active_tile_index;
}
static void rna_Image_active_tile_index_set(PointerRNA *ptr, int value)
{
Image *image = (Image *)ptr->data;
int num_tiles = BLI_listbase_count(&image->tiles);
image->active_tile_index = min_ii(value, num_tiles - 1);
}
static void rna_Image_active_tile_index_range(
PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
{
Image *image = (Image *)ptr->data;
int num_tiles = BLI_listbase_count(&image->tiles);
*min = 0;
*max = max_ii(0, num_tiles - 1);
}
static PointerRNA rna_Image_active_tile_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->data;
ImageTile *tile = BLI_findlink(&image->tiles, image->active_tile_index);
return rna_pointer_inherit_refine(ptr, &RNA_UDIMTile, tile);
}
static void rna_Image_active_tile_set(PointerRNA *ptr,
PointerRNA value,
struct ReportList *UNUSED(reports))
{
Image *image = (Image *)ptr->data;
ImageTile *tile = (ImageTile *)value.data;
const int index = BLI_findindex(&image->tiles, tile);
if (index != -1) {
image->active_tile_index = index;
}
}
static bool rna_Image_has_data_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->data;
return BKE_image_has_loaded_ibuf(image);
}
static void rna_Image_size_get(PointerRNA *ptr, int *values)
{
Image *im = (Image *)ptr->data;
ImBuf *ibuf;
void *lock;
ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
if (ibuf) {
values[0] = ibuf->x;
values[1] = ibuf->y;
}
else {
values[0] = 0;
values[1] = 0;
}
BKE_image_release_ibuf(im, ibuf, lock);
}
static void rna_Image_resolution_get(PointerRNA *ptr, float *values)
{
Image *im = (Image *)ptr->data;
ImBuf *ibuf;
void *lock;
ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
if (ibuf) {
values[0] = ibuf->ppm[0];
values[1] = ibuf->ppm[1];
}
else {
values[0] = 0;
values[1] = 0;
}
BKE_image_release_ibuf(im, ibuf, lock);
}
static void rna_Image_resolution_set(PointerRNA *ptr, const float *values)
{
Image *im = (Image *)ptr->data;
ImBuf *ibuf;
void *lock;
ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
if (ibuf) {
ibuf->ppm[0] = values[0];
ibuf->ppm[1] = values[1];
}
BKE_image_release_ibuf(im, ibuf, lock);
}
static int rna_Image_bindcode_get(PointerRNA *ptr)
{
Image *ima = (Image *)ptr->data;
GPUTexture *tex = ima->gputexture[TEXTARGET_2D][0];
return (tex) ? GPU_texture_opengl_bindcode(tex) : 0;
}
static int rna_Image_depth_get(PointerRNA *ptr)
{
Image *im = (Image *)ptr->data;
ImBuf *ibuf;
void *lock;
int planes;
ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
if (!ibuf) {
planes = 0;
}
else if (ibuf->rect_float) {
planes = ibuf->planes * 4;
}
else {
planes = ibuf->planes;
}
BKE_image_release_ibuf(im, ibuf, lock);
return planes;
}
static int rna_Image_frame_duration_get(PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
int duration = 1;
if (!BKE_image_has_anim(ima)) {
/* Ensure image has been loaded into memory and frame duration is known. */
void *lock;
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
BKE_image_release_ibuf(ima, ibuf, lock);
}
if (BKE_image_has_anim(ima)) {
struct anim *anim = ((ImageAnim *)ima->anims.first)->anim;
if (anim) {
duration = IMB_anim_get_duration(anim, IMB_TC_RECORD_RUN);
}
}
return duration;
}
static int rna_Image_pixels_get_length(const PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
{
Image *ima = (Image *)ptr->owner_id;
ImBuf *ibuf;
void *lock;
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
if (ibuf) {
length[0] = ibuf->x * ibuf->y * ibuf->channels;
}
else {
length[0] = 0;
}
BKE_image_release_ibuf(ima, ibuf, lock);
return length[0];
}
static void rna_Image_pixels_get(PointerRNA *ptr, float *values)
{
Image *ima = (Image *)ptr->owner_id;
ImBuf *ibuf;
void *lock;
int i, size;
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
if (ibuf) {
size = ibuf->x * ibuf->y * ibuf->channels;
if (ibuf->rect_float) {
memcpy(values, ibuf->rect_float, sizeof(float) * size);
}
else {
for (i = 0; i < size; i++) {
values[i] = ((uchar *)ibuf->rect)[i] * (1.0f / 255.0f);
}
}
}
BKE_image_release_ibuf(ima, ibuf, lock);
}
static void rna_Image_pixels_set(PointerRNA *ptr, const float *values)
{
Image *ima = (Image *)ptr->owner_id;
ImBuf *ibuf;
void *lock;
int i, size;
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
if (ibuf) {
size = ibuf->x * ibuf->y * ibuf->channels;
if (ibuf->rect_float) {
memcpy(ibuf->rect_float, values, sizeof(float) * size);
}
else {
for (i = 0; i < size; i++) {
((uchar *)ibuf->rect)[i] = unit_float_to_uchar_clamp(values[i]);
}
}
/* NOTE: Do update from the set() because typically pixels.foreach_set() is used to update
* the values, and it does not invoke the update(). */
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID | IB_MIPMAP_INVALID;
BKE_image_mark_dirty(ima, ibuf);
if (!G.background) {
BKE_image_free_gputextures(ima);
}
BKE_image_partial_update_mark_full_update(ima);
WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
}
BKE_image_release_ibuf(ima, ibuf, lock);
}
static int rna_Image_channels_get(PointerRNA *ptr)
{
Image *im = (Image *)ptr->data;
ImBuf *ibuf;
void *lock;
int channels = 0;
ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
if (ibuf) {
channels = ibuf->channels;
}
BKE_image_release_ibuf(im, ibuf, lock);
return channels;
}
static bool rna_Image_is_float_get(PointerRNA *ptr)
{
Image *im = (Image *)ptr->data;
ImBuf *ibuf;
void *lock;
bool is_float = false;
ibuf = BKE_image_acquire_ibuf(im, NULL, &lock);
if (ibuf) {
is_float = ibuf->rect_float != NULL;
}
BKE_image_release_ibuf(im, ibuf, lock);
return is_float;
}
static PointerRNA rna_Image_packed_file_get(PointerRNA *ptr)
{
Image *ima = (Image *)ptr->owner_id;
if (BKE_image_has_packedfile(ima)) {
ImagePackedFile *imapf = ima->packedfiles.first;
return rna_pointer_inherit_refine(ptr, &RNA_PackedFile, imapf->packedfile);
}
else {
return PointerRNA_NULL;
}
}
static void rna_RenderSlot_clear(ID *id, RenderSlot *slot, ImageUser *iuser)
{
Image *image = (Image *)id;
int index = BLI_findindex(&image->renderslots, slot);
BKE_image_clear_renderslot(image, iuser, index);
WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, image);
}
static PointerRNA rna_render_slots_active_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->owner_id;
RenderSlot *render_slot = BKE_image_get_renderslot(image, image->render_slot);
return rna_pointer_inherit_refine(ptr, &RNA_RenderSlot, render_slot);
}
static void rna_render_slots_active_set(PointerRNA *ptr,
PointerRNA value,
struct ReportList *UNUSED(reports))
{
Image *image = (Image *)ptr->owner_id;
if (value.owner_id == &image->id) {
RenderSlot *slot = (RenderSlot *)value.data;
int index = BLI_findindex(&image->renderslots, slot);
if (index != -1) {
image->render_slot = index;
BKE_image_partial_update_mark_full_update(image);
}
}
}
static int rna_render_slots_active_index_get(PointerRNA *ptr)
{
Image *image = (Image *)ptr->owner_id;
return image->render_slot;
}
static void rna_render_slots_active_index_set(PointerRNA *ptr, int value)
{
Image *image = (Image *)ptr->owner_id;
int num_slots = BLI_listbase_count(&image->renderslots);
image->render_slot = value;
BKE_image_partial_update_mark_full_update(image);
CLAMP(image->render_slot, 0, num_slots - 1);
}
static void rna_render_slots_active_index_range(
PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
{
Image *image = (Image *)ptr->owner_id;
*min = 0;
*max = max_ii(0, BLI_listbase_count(&image->renderslots) - 1);
}
static ImageTile *rna_UDIMTile_new(Image *image, int tile_number, const char *label)
{
ImageTile *tile = BKE_image_add_tile(image, tile_number, label);
WM_main_add_notifier(NC_IMAGE | ND_DRAW, NULL);
return tile;
}
static void rna_UDIMTile_remove(Image *image, PointerRNA *ptr)
{
ImageTile *tile = (ImageTile *)ptr->data;
BKE_image_remove_tile(image, tile);
WM_main_add_notifier(NC_IMAGE | ND_DRAW, NULL);
}
#else
static void rna_def_imageuser(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "ImageUser", NULL);
RNA_def_struct_ui_text(
srna,
"Image User",
"Parameters defining how an Image data-block is used by another data-block");
RNA_def_struct_path_func(srna, "rna_ImageUser_path");
RNA_define_lib_overridable(true);
prop = RNA_def_property(srna, "use_auto_refresh", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_ANIM_ALWAYS);
RNA_def_property_ui_text(prop, "Auto Refresh", "Always refresh image on frame changes");
RNA_def_property_update(prop, 0, "rna_ImageUser_relations_update");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
prop = RNA_def_property(srna, "frame_current", PROP_INT, PROP_TIME);
RNA_def_property_int_sdna(prop, NULL, "framenr");
RNA_def_property_range(prop, MINAFRAME, MAXFRAME);
RNA_def_property_ui_text(
prop, "Current Frame", "Current frame number in image sequence or movie");
/* animation */
prop = RNA_def_property(srna, "use_cyclic", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "cycl", 0);
RNA_def_property_ui_text(prop, "Cyclic", "Cycle the images in the movie");
RNA_def_property_update(prop, 0, "rna_ImageUser_update");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "frames");
RNA_def_property_range(prop, 0, MAXFRAMEF);
RNA_def_property_ui_text(prop, "Frames", "Number of images of a movie to use");
RNA_def_property_update(prop, 0, "rna_ImageUser_update");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
prop = RNA_def_property(srna, "frame_offset", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "offset");
RNA_def_property_ui_text(
prop, "Offset", "Offset the number of the frame to use in the animation");
RNA_def_property_update(prop, 0, "rna_ImageUser_update");
prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME);
RNA_def_property_int_sdna(prop, NULL, "sfra");
RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
RNA_def_property_ui_text(
prop,
"Start Frame",
"Global starting frame of the movie/sequence, assuming first picture has a #1");
RNA_def_property_update(prop, 0, "rna_ImageUser_update");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
prop = RNA_def_property(srna, "multilayer_layer", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "layer");
RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
RNA_def_property_ui_text(prop, "Layer", "Layer in multilayer image");
prop = RNA_def_property(srna, "multilayer_pass", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "pass");
RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
RNA_def_property_ui_text(prop, "Pass", "Pass in multilayer image");
prop = RNA_def_property(srna, "multilayer_view", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "view");
RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* image_multi_cb */
RNA_def_property_ui_text(prop, "View", "View in multilayer image");
prop = RNA_def_property(srna, "tile", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "tile");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_ui_text(prop, "Tile", "Tile in tiled image");
RNA_define_lib_overridable(false);
}
/* image.packed_files */
static void rna_def_image_packed_files(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "ImagePackedFile", NULL);
RNA_def_struct_sdna(srna, "ImagePackedFile");
prop = RNA_def_property(srna, "packed_file", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "packedfile");
RNA_def_property_ui_text(prop, "Packed File", "");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
RNA_def_property_string_sdna(prop, NULL, "filepath");
RNA_def_struct_name_property(srna, prop);
prop = RNA_def_property(srna, "view", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "view");
RNA_def_property_ui_text(prop, "View Index", "");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "tile_number", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "tile_number");
RNA_def_property_ui_text(prop, "Tile Number", "");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_api_image_packed_file(srna);
}
static void rna_def_render_slot(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop, *parm;
FunctionRNA *func;
srna = RNA_def_struct(brna, "RenderSlot", NULL);
RNA_def_struct_ui_text(srna, "Render Slot", "Parameters defining the render slot");
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "name");
RNA_def_property_ui_text(prop, "Name", "Render slot name");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
func = RNA_def_function(srna, "clear", "rna_RenderSlot_clear");
RNA_def_function_flag(func, FUNC_USE_SELF_ID);
RNA_def_function_ui_description(func, "Clear the render slot");
parm = RNA_def_pointer(func, "iuser", "ImageUser", "ImageUser", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
}
static void rna_def_render_slots(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
FunctionRNA *func;
PropertyRNA *prop, *parm;
RNA_def_property_srna(cprop, "RenderSlots");
srna = RNA_def_struct(brna, "RenderSlots", NULL);
RNA_def_struct_sdna(srna, "Image");
RNA_def_struct_ui_text(srna, "Render Layers", "Collection of render layers");
prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "render_slot");
RNA_def_property_int_funcs(prop,
"rna_render_slots_active_index_get",
"rna_render_slots_active_index_set",
"rna_render_slots_active_index_range");
RNA_def_property_ui_text(prop, "Active", "Active render slot of the image");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "RenderSlot");
RNA_def_property_pointer_funcs(
prop, "rna_render_slots_active_get", "rna_render_slots_active_set", NULL, NULL);
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Active", "Active render slot of the image");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
func = RNA_def_function(srna, "new", "BKE_image_add_renderslot");
RNA_def_function_ui_description(func, "Add a render slot to the image");
parm = RNA_def_string(func, "name", NULL, 0, "Name", "New name for the render slot");
parm = RNA_def_pointer(func, "result", "RenderSlot", "", "Newly created render layer");
RNA_def_function_return(func, parm);
}
static void rna_def_udim_tile(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "UDIMTile", NULL);
RNA_def_struct_sdna(srna, "ImageTile");
RNA_def_struct_ui_text(srna, "UDIM Tile", "Properties of the UDIM tile");
prop = RNA_def_property(srna, "label", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "label");
RNA_def_property_ui_text(prop, "Label", "Tile label");
RNA_def_property_string_funcs(prop, "rna_UDIMTile_label_get", "rna_UDIMTile_label_length", NULL);
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
prop = RNA_def_property(srna, "number", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "tile_number");
RNA_def_property_ui_text(prop, "Number", "Number of the position that this tile covers");
RNA_def_property_int_funcs(prop, NULL, "rna_UDIMTile_tile_number_set", NULL);
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
prop = RNA_def_int_vector(
srna,
"size",
2,
NULL,
0,
0,
"Size",
"Width and height of the tile buffer in pixels, zero when image data can't be loaded",
0,
0);
RNA_def_property_subtype(prop, PROP_PIXEL);
RNA_def_property_int_funcs(prop, "rna_UDIMTile_size_get", NULL, NULL);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "channels", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_funcs(prop, "rna_UDIMTile_channels_get", NULL, NULL);
RNA_def_property_ui_text(prop, "Channels", "Number of channels in the tile pixels buffer");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
/* Generated tile information. */