Blender V5.3
image_ops.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cerrno>
10#include <cstddef>
11#include <cstdlib>
12#include <cstring>
13#include <fcntl.h>
14#include <string>
15#ifndef WIN32
16# include <unistd.h>
17#else
18# include <io.h>
19#endif
20
21#include "MEM_guardedalloc.h"
22
23#include "BLI_fileops.hh"
24#include "BLI_listbase.hh"
25#include "BLI_path_utils.hh"
26#include "BLI_set.hh"
27#include "BLI_string.hh"
28#include "BLI_time.hh"
29#include "BLI_utildefines.hh"
30
31#include "BLT_translation.hh"
32
33#include "DNA_camera_types.h"
34#include "DNA_node_types.h"
35#include "DNA_object_types.h"
36#include "DNA_scene_types.h"
37#include "DNA_screen_types.h"
38
39#include "BKE_colortools.hh"
40#include "BKE_context.hh"
41#include "BKE_global.hh"
42#include "BKE_icons.hh"
43#include "BKE_image.hh"
44#include "BKE_image_format.hh"
45#include "BKE_image_save.hh"
46#include "BKE_layer.hh"
47#include "BKE_lib_id.hh"
48#include "BKE_library.hh"
49#include "BKE_main.hh"
50#include "BKE_mask.hh"
51#include "BKE_packedFile.hh"
52#include "BKE_report.hh"
53#include "BKE_scene.hh"
54
55#include "DEG_depsgraph.hh"
56
57#include "IMB_cache.hh"
59#include "IMB_imbuf.hh"
60#include "IMB_imbuf_types.hh"
61#include "IMB_partial_update.hh"
62
63#include "MOV_read.hh"
64
65#include "RE_pipeline.h"
66
67#include "RNA_access.hh"
68#include "RNA_define.hh"
69#include "RNA_enum_types.hh"
70#include "RNA_prototypes.hh"
71
72#include "ED_image.hh"
73#include "ED_mask.hh"
74#include "ED_paint.hh"
75#include "ED_render.hh"
76#include "ED_screen.hh"
77#include "ED_undo.hh"
78#include "ED_util.hh"
79#include "ED_util_imbuf.hh"
80#include "ED_uvedit.hh"
81
82#include "UI_interface.hh"
84#include "UI_resources.hh"
85#include "UI_view2d.hh"
86
87#include "WM_api.hh"
88#include "WM_types.hh"
89
90#include "RE_engine.h"
91
92#include "image_intern.hh"
93
94namespace blender {
95
96/* -------------------------------------------------------------------- */
99
100static void sima_zoom_set(
101 SpaceImage *sima, ARegion *region, float zoom, const float location[2], const bool zoom_to_pos)
102{
103 float oldzoom = sima->zoom;
104 int width, height;
105
106 sima->zoom = zoom;
107
108 ED_space_image_get_size(sima, &width, &height);
109
110 /* Preset zoom limits.
111 * Zoom `min` is based on ratio of apparent image size to largest screen dimension.
112 * Zoom `max` is based on ratio of apparent pixel size to largest screen dimension.
113 * (The reason being so the user can still zoom in on very large images.)
114 */
115 const float sima_minzoom_image_over_screen = 1.0f / 100.0f;
116 const float sima_maxzoom_pixel_over_screen = 10.0f / 1.0f;
117 /* Check zoom limits. */
118 /* Get largest dimensions for image and workspace for comparison. */
119 float comp_image = std::max(width, height);
120 float comp_screen = std::max(BLI_rcti_size_x(&region->winrct), BLI_rcti_size_y(&region->winrct));
121 /* Stop when image size is less than minzoom ratio compared to screen size. */
122 if (comp_image * sima->zoom < comp_screen * sima_minzoom_image_over_screen &&
123 sima->zoom < oldzoom)
124 {
125 sima->zoom = oldzoom;
126 }
127 /* Stop when max relative screen bounds is smaller than apparent pixel size. */
128 else if (comp_screen * sima_maxzoom_pixel_over_screen <= sima->zoom && sima->zoom > oldzoom) {
129 sima->zoom = oldzoom;
130 }
131
132 if (zoom_to_pos && location) {
133 float aspx, aspy, w, h;
134
135 ED_space_image_get_size(sima, &width, &height);
136 ED_space_image_get_aspect(sima, &aspx, &aspy);
137
138 w = width * aspx;
139 h = height * aspy;
140
141 sima->xof += ((location[0] - 0.5f) * w - sima->xof) * (sima->zoom - oldzoom) / sima->zoom;
142 sima->yof += ((location[1] - 0.5f) * h - sima->yof) * (sima->zoom - oldzoom) / sima->zoom;
143 }
144
145 Image *ima = ED_space_image(sima);
146 if (ima) {
147 ima->runtime->view_zoom = sima->zoom;
148 ima->runtime->view_offset[0] = sima->xof;
149 ima->runtime->view_offset[1] = sima->yof;
150 }
151}
152
154 ARegion *region,
155 float zoomfac,
156 const float location[2],
157 const bool zoom_to_pos)
158{
159 sima_zoom_set(sima, region, sima->zoom * zoomfac, location, zoom_to_pos);
160}
161
165static void sima_zoom_set_from_bounds(SpaceImage *sima, ARegion *region, const rctf *bounds)
166{
167 int image_size[2];
168 float aspx, aspy;
169
170 ED_space_image_get_size(sima, &image_size[0], &image_size[1]);
171 ED_space_image_get_aspect(sima, &aspx, &aspy);
172
173 image_size[0] = image_size[0] * aspx;
174 image_size[1] = image_size[1] * aspy;
175
176 /* adjust offset and zoom */
177 sima->xof = roundf((BLI_rctf_cent_x(bounds) - 0.5f) * image_size[0]);
178 sima->yof = roundf((BLI_rctf_cent_y(bounds) - 0.5f) * image_size[1]);
179
180 float size_xy[2], size;
181 size_xy[0] = BLI_rcti_size_x(&region->winrct) / (BLI_rctf_size_x(bounds) * image_size[0]);
182 size_xy[1] = BLI_rcti_size_y(&region->winrct) / (BLI_rctf_size_y(bounds) * image_size[1]);
183
184 size = min_ff(size_xy[0], size_xy[1]);
185 CLAMP_MAX(size, 100.0f);
186
187 sima_zoom_set(sima, region, size, nullptr, false);
188}
189
191{
192 /* Edit image is set by templates used throughout the interface, so image
193 * operations work outside the image editor. */
194 Image *ima = static_cast<Image *>(CTX_data_pointer_get_type(C, "edit_image", RNA_Image).data);
195
196 if (ima) {
197 return ima;
198 }
199
200 /* Image editor. */
202 return (sima) ? sima->image : nullptr;
203}
204
206{
207 /* Edit image user is set by templates used throughout the interface, so
208 * image operations work outside the image editor. */
209 ImageUser *iuser = static_cast<ImageUser *>(
210 CTX_data_pointer_get_type(C, "edit_image_user", RNA_ImageUser).data);
211
212 if (iuser) {
213 return iuser;
214 }
215
216 /* Image editor. */
218 return (sima) ? &sima->iuser : nullptr;
219}
220
222{
223 /* Try to get image user from context if available, otherwise use default. */
224 ImageUser *iuser_context = image_user_from_context(C);
225 ImageUser iuser;
226 if (iuser_context) {
227 iuser = *iuser_context;
228 }
229 else {
230 BKE_imageuser_default(&iuser);
231 }
232
233 /* Use the file associated with the active tile. Otherwise use the first tile. */
234 if (ima && ima->source == IMA_SRC_TILED) {
235 const ImageTile *active = static_cast<ImageTile *>(
236 BLI_findlink(&ima->tiles, ima->active_tile_index));
237 iuser.tile = active ? active->tile_number : (ima->tiles.first())->tile_number;
238 }
239
240 return iuser;
241}
242
244{
245 Image *ima = image_from_context(C);
247
248 if (ima == nullptr) {
249 return false;
250 }
251
252 void *lock;
253 ImBuf *ibuf = BKE_image_acquire_ibuf_gpu(ima, iuser, &lock);
254 const bool has_buffer = (ibuf && (ibuf->byte_data() || ibuf->float_data() || ibuf->gpu.texture));
255 BKE_image_release_ibuf(ima, ibuf, lock);
256 return has_buffer;
257}
258
263{
264 Image *ima = image_from_context(C);
265
266 if (ima && !ID_IS_EDITABLE(&ima->id)) {
267 CTX_wm_operator_poll_msg_set(C, "Image is not editable");
268 return false;
269 }
270
272
273 return BKE_image_has_ibuf(ima, &iuser);
274}
275
277{
278 /* Do not run 'replace' on packed images, it does not give user expected results at all. */
279 Image *ima = image_from_context(C);
280 return (ima && ima->packedfiles.is_empty());
281}
282
283static void image_view_all(SpaceImage *sima, ARegion *region, wmOperator *op)
284{
285 float aspx, aspy, zoomx, zoomy, w, h;
286 int width, height;
287 const bool fit_view = RNA_boolean_get(op->ptr, "fit_view");
288
289 ED_space_image_get_size(sima, &width, &height);
290 ED_space_image_get_aspect(sima, &aspx, &aspy);
291
292 w = width * aspx;
293 h = height * aspy;
294
295 float xof = 0.0f, yof = 0.0f;
296 if ((sima->image == nullptr) || (sima->image->source == IMA_SRC_TILED)) {
297 /* Extend the shown area to cover all UDIM tiles. */
298 int x_tiles, y_tiles;
299 if (sima->image == nullptr) {
300 x_tiles = sima->tile_grid_shape[0];
301 y_tiles = sima->tile_grid_shape[1];
302 }
303 else {
304 x_tiles = y_tiles = 1;
305 for (ImageTile &tile : sima->image->tiles) {
306 int tile_x = (tile.tile_number - 1001) % 10;
307 int tile_y = (tile.tile_number - 1001) / 10;
308 x_tiles = max_ii(x_tiles, tile_x + 1);
309 y_tiles = max_ii(y_tiles, tile_y + 1);
310 }
311 }
312 xof = 0.5f * (x_tiles - 1.0f) * w;
313 yof = 0.5f * (y_tiles - 1.0f) * h;
314 w *= x_tiles;
315 h *= y_tiles;
316 }
317
318 /* check if the image will fit in the image with (zoom == 1) */
319 width = BLI_rcti_size_x(&region->winrct) + 1;
320 height = BLI_rcti_size_y(&region->winrct) + 1;
321
322 if (fit_view) {
323 const int margin = 5; /* margin from border */
324
325 zoomx = float(width) / (w + 2 * margin);
326 zoomy = float(height) / (h + 2 * margin);
327
328 sima_zoom_set(sima, region, min_ff(zoomx, zoomy), nullptr, false);
329 }
330 else {
331 if ((w >= width || h >= height) && (width > 0 && height > 0)) {
332 zoomx = float(width) / w;
333 zoomy = float(height) / h;
334
335 /* find the zoom value that will fit the image in the image space */
336 sima_zoom_set(sima, region, 1.0f / power_of_2(1.0f / min_ff(zoomx, zoomy)), nullptr, false);
337 }
338 else {
339 sima_zoom_set(sima, region, 1.0f, nullptr, false);
340 }
341 }
342
343 sima->xof = xof;
344 sima->yof = yof;
345
346 Image *ima = ED_space_image(sima);
347 if (ima) {
348 ima->runtime->view_zoom = sima->zoom;
349 ima->runtime->view_offset[0] = sima->xof;
350 ima->runtime->view_offset[1] = sima->yof;
351 }
352}
353
355{
357 if (sima == nullptr) {
358 return false;
359 }
360 return true;
361}
362
364{
366 if (sima == nullptr) {
367 return false;
368 }
369 ARegion *region = CTX_wm_region(C);
370 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
371 return false;
372 }
373 return true;
374}
375
378{
380 if (sima == nullptr) {
381 return false;
382 }
383 ARegion *region = CTX_wm_region(C);
384 if (!(region && region->regiontype == RGN_TYPE_WINDOW)) {
385 return false;
386 }
387 if (CTX_data_edit_object(C)) {
388 return false;
389 }
390 return true;
391}
392
394
395/* -------------------------------------------------------------------- */
398
399namespace {
400
401struct ViewPanData {
402 float x, y;
403 float xof, yof;
404 int launch_event;
405 bool own_cursor;
406};
407
408} // namespace
409
410static void image_view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
411{
412 wmWindow *win = CTX_wm_window(C);
414 ViewPanData *vpd;
415
416 op->customdata = vpd = MEM_new_zeroed<ViewPanData>("ImageViewPanData");
417
418 /* Grab will be set when running from gizmo. */
419 vpd->own_cursor = WM_cursor_modal_is_set_ok(win);
420 if (vpd->own_cursor) {
422 }
423
424 vpd->x = event->xy[0];
425 vpd->y = event->xy[1];
426 vpd->xof = sima->xof;
427 vpd->yof = sima->yof;
428 vpd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
429
431}
432
433static void image_view_pan_exit(bContext *C, wmOperator *op, bool cancel)
434{
436 ViewPanData *vpd = static_cast<ViewPanData *>(op->customdata);
437
438 if (cancel) {
439 sima->xof = vpd->xof;
440 sima->yof = vpd->yof;
442 }
443
444 if (vpd->own_cursor) {
446 }
447 MEM_delete(vpd);
448}
449
451{
453 float offset[2];
454
455 RNA_float_get_array(op->ptr, "offset", offset);
456 sima->xof += offset[0];
457 sima->yof += offset[1];
458
460
461 Image *ima = ED_space_image(sima);
462 if (ima) {
463 ima->runtime->view_offset[0] = sima->xof;
464 ima->runtime->view_offset[1] = sima->yof;
465 }
466
467 return OPERATOR_FINISHED;
468}
469
471{
472 if (event->type == MOUSEPAN) {
474 float offset[2];
475
476 offset[0] = (event->prev_xy[0] - event->xy[0]) / sima->zoom;
477 offset[1] = (event->prev_xy[1] - event->xy[1]) / sima->zoom;
478 RNA_float_set_array(op->ptr, "offset", offset);
479
481 return OPERATOR_FINISHED;
482 }
483
484 image_view_pan_init(C, op, event);
486}
487
489{
491 ViewPanData *vpd = static_cast<ViewPanData *>(op->customdata);
492 float offset[2];
493
494 switch (event->type) {
495 case MOUSEMOVE:
496 sima->xof = vpd->xof;
497 sima->yof = vpd->yof;
498 offset[0] = (vpd->x - event->xy[0]) / sima->zoom;
499 offset[1] = (vpd->y - event->xy[1]) / sima->zoom;
500 RNA_float_set_array(op->ptr, "offset", offset);
502 break;
503 default:
504 if (event->type == vpd->launch_event && event->val == KM_RELEASE) {
505 image_view_pan_exit(C, op, false);
506 return OPERATOR_FINISHED;
507 }
508 break;
509 }
510
512}
513
515{
516 image_view_pan_exit(C, op, true);
517}
518
520{
521 /* identifiers */
522 ot->name = "Pan View";
523 ot->idname = "IMAGE_OT_view_pan";
524 ot->description = "Pan the view";
525
526 /* API callbacks. */
532
533 /* flags */
535
536 /* properties */
538 "offset",
539 2,
540 nullptr,
541 -FLT_MAX,
542 FLT_MAX,
543 "Offset",
544 "Offset in floating-point units, 1.0 is the width and height of the image",
545 -FLT_MAX,
546 FLT_MAX);
547}
548
550
551/* -------------------------------------------------------------------- */
554
555namespace {
556
557struct ViewZoomData {
558 float origx, origy;
559 float zoom;
560 int launch_event;
561 float location[2];
562 bool snap;
563
564 /* needed for continuous zoom */
565 wmTimer *timer;
566 double timer_lastdraw;
567 bool own_cursor;
568
569 /* */
570 SpaceImage *sima;
571 ScrArea *area;
572 ARegion *region;
573};
574
575} // namespace
576
577static void image_view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
578{
579 wmWindow *win = CTX_wm_window(C);
581 ARegion *region = CTX_wm_region(C);
582 ViewZoomData *vpd;
583
584 op->customdata = vpd = MEM_new_zeroed<ViewZoomData>("ImageViewZoomData");
585
586 /* Grab will be set when running from gizmo. */
587 vpd->own_cursor = WM_cursor_modal_is_set_ok(win);
588 if (vpd->own_cursor) {
590 }
591
592 vpd->origx = event->xy[0];
593 vpd->origy = event->xy[1];
594 vpd->zoom = sima->zoom;
595 vpd->snap = false;
596 vpd->launch_event = WM_userdef_event_type_from_keymap_type(event->type);
597
599 &region->v2d, event->mval[0], event->mval[1], &vpd->location[0], &vpd->location[1]);
600
601 if (U.viewzoom == USER_ZOOM_CONTINUE) {
602 /* needs a timer to continue redrawing */
603 vpd->timer = WM_event_timer_add(CTX_wm_manager(C), CTX_wm_window(C), TIMER, 0.01f);
604 vpd->timer_lastdraw = BLI_time_now_seconds();
605 }
606
607 vpd->sima = sima;
608 vpd->area = CTX_wm_area(C);
609 vpd->region = region;
610
612}
613
614static void image_view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
615{
617 ViewZoomData *vpd = static_cast<ViewZoomData *>(op->customdata);
618
619 if (cancel) {
620 sima->zoom = vpd->zoom;
622 }
623
624 ED_area_status_text(vpd->area, nullptr);
625 ED_workspace_status_text(C, nullptr);
626
627 if (vpd->timer) {
628 WM_event_timer_remove(CTX_wm_manager(C), vpd->timer->win, vpd->timer);
629 }
630
631 if (vpd->own_cursor) {
633 }
634 MEM_delete(vpd);
635}
636
638{
640 ARegion *region = CTX_wm_region(C);
641
642 sima_zoom_set_factor(sima, region, RNA_float_get(op->ptr, "factor"), nullptr, false);
643
644 ED_region_tag_redraw(region);
645
646 return OPERATOR_FINISHED;
647}
648
649enum {
653};
654
656{
657 if (ELEM(event->type, MOUSEZOOM, MOUSEPAN)) {
659 ARegion *region = CTX_wm_region(C);
660 float delta, factor, location[2];
661
663 &region->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
664
665 delta = event->prev_xy[0] - event->xy[0] + event->prev_xy[1] - event->xy[1];
666
667 if (U.uiflag & USER_ZOOM_INVERT) {
668 delta *= -1;
669 }
670
671 factor = 1.0f + delta / 300.0f;
672 RNA_float_set(op->ptr, "factor", factor);
673 const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
674 sima_zoom_set(sima,
675 region,
676 sima->zoom * factor,
677 location,
678 (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)));
679 ED_region_tag_redraw(region);
680
681 return OPERATOR_FINISHED;
682 }
683
684 image_view_zoom_init(C, op, event);
686}
687
688static void image_zoom_apply(ViewZoomData *vpd,
689 wmOperator *op,
690 const int x,
691 const int y,
692 const short viewzoom,
693 const short zoom_invert,
694 const bool zoom_to_pos,
695 const bool snap,
696 const bool precision)
697{
698 float factor;
699 float delta;
700
701 if (viewzoom != USER_ZOOM_SCALE) {
702 if (U.uiflag & USER_ZOOM_HORIZ) {
703 delta = float(x - vpd->origx);
704 }
705 else {
706 delta = float(y - vpd->origy);
707 }
708 }
709 else {
710 delta = x - vpd->origx + y - vpd->origy;
711 }
712
713 delta /= U.pixelsize;
714
715 if (zoom_invert) {
716 delta = -delta;
717 }
718
719 if (precision) {
720 delta /= 10.0f;
721 }
722
723 if (viewzoom == USER_ZOOM_CONTINUE) {
724 double time = BLI_time_now_seconds();
725 float time_step = float(time - vpd->timer_lastdraw);
726 float zfac;
727 zfac = 1.0f + ((delta / 20.0f) * time_step);
728 vpd->timer_lastdraw = time;
729 /* this is the final zoom, but instead make it into a factor */
730 factor = (vpd->sima->zoom * zfac) / vpd->zoom;
731 }
732 else {
733 factor = 1.0f + delta / 300.0f;
734 }
735
736 float zoom = vpd->zoom * factor;
737 if (snap) {
738 zoom = round(zoom * 10.0f) / 10.0f;
739 }
740 char str[10];
741 if (precision) {
742 SNPRINTF(str, "%4.2f%%", vpd->sima->zoom * 100.0f);
743 }
744 else {
745 SNPRINTF(str, "%i%%", int(round(vpd->sima->zoom * 100.0f)));
746 }
747
748 ED_area_status_text(vpd->area, str);
749
750 RNA_float_set(op->ptr, "factor", factor);
751 sima_zoom_set(vpd->sima, vpd->region, zoom, vpd->location, zoom_to_pos);
752 ED_region_tag_redraw(vpd->region);
753}
754
756{
757 ViewZoomData *vpd = static_cast<ViewZoomData *>(op->customdata);
758 short event_code = VIEW_PASS;
760
761 /* Execute the events. */
762 if (event->type == MOUSEMOVE) {
763 event_code = VIEW_APPLY;
764 }
765 else if (event->type == TIMER) {
766 /* Continuous zoom. */
767 if (event->customdata == vpd->timer) {
768 event_code = VIEW_APPLY;
769 }
770 }
771 else if (event->type == vpd->launch_event) {
772 if (event->val == KM_RELEASE) {
773 event_code = VIEW_CONFIRM;
774 }
775 }
776 else if (ELEM(event->type, EVT_LEFTCTRLKEY, EVT_RIGHTCTRLKEY)) {
777 /* Snapping should be off when the operator starts, regardless
778 * of ctrl key state. Only change with subsequent presses. */
779 vpd->snap = (event->val == KM_PRESS);
780 }
781
782 switch (event_code) {
783 case VIEW_APPLY: {
784 const bool use_cursor_init = RNA_boolean_get(op->ptr, "use_cursor_init");
786 op,
787 event->xy[0],
788 event->xy[1],
789 U.viewzoom,
790 (U.uiflag & USER_ZOOM_INVERT) != 0,
791 (use_cursor_init && (U.uiflag & USER_ZOOM_TO_MOUSEPOS)),
792 vpd->snap,
793 event->modifier & KM_SHIFT);
794 break;
795 }
796 case VIEW_CONFIRM: {
798 break;
799 }
800 }
801
802 WorkspaceStatus status(C);
803 status.item_bool(IFACE_("Snap"), vpd->snap, ICON_EVENT_CTRL);
804 status.item_bool(IFACE_("Precision"), event->modifier & KM_SHIFT, ICON_EVENT_SHIFT);
805
806 if ((ret & OPERATOR_RUNNING_MODAL) == 0) {
807 image_view_zoom_exit(C, op, false);
808 }
809
810 return ret;
811}
812
814{
815 image_view_zoom_exit(C, op, true);
816}
817
819{
820 PropertyRNA *prop;
821
822 /* identifiers */
823 ot->name = "Zoom View";
824 ot->idname = "IMAGE_OT_view_zoom";
825 ot->description = "Zoom in/out the image";
826
827 /* API callbacks. */
833
834 /* flags */
836
837 /* properties */
838 prop = RNA_def_float(ot->srna,
839 "factor",
840 0.0f,
841 -FLT_MAX,
842 FLT_MAX,
843 "Factor",
844 "Zoom factor, values higher than 1.0 zoom in, lower values zoom out",
845 -FLT_MAX,
846 FLT_MAX);
848
850}
851
853
854#ifdef WITH_INPUT_NDOF
855
856/* -------------------------------------------------------------------- */
859
860/* Combined pan/zoom from a 3D mouse device.
861 * Z zooms, XY pans
862 * "view" (not "paper") control -- user moves the viewpoint, not the image being viewed
863 * that explains the negative signs in the code below
864 */
865
866static wmOperatorStatus image_view_ndof_invoke(bContext *C,
867 wmOperator * /*op*/,
868 const wmEvent *event)
869{
870 if (event->type != NDOF_MOTION) {
871 return OPERATOR_CANCELLED;
872 }
873
875 ARegion *region = CTX_wm_region(C);
876
877 const wmNDOFMotionData &ndof = *static_cast<const wmNDOFMotionData *>(event->customdata);
878 const float pan_speed = NDOF_PIXELS_PER_SECOND;
879
880 float3 pan_vec = ndof.time_delta * WM_event_ndof_translation_get_for_navigation(ndof);
881
882 mul_v2_fl(pan_vec, pan_speed / sima->zoom);
883
884 sima_zoom_set_factor(sima, region, max_ff(0.0f, 1.0f - pan_vec[2]), nullptr, false);
885 sima->xof += pan_vec[0];
886 sima->yof += pan_vec[1];
887
888 ED_region_tag_redraw(region);
889
890 return OPERATOR_FINISHED;
891}
892
893void IMAGE_OT_view_ndof(wmOperatorType *ot)
894{
895 /* identifiers */
896 ot->name = "NDOF Pan/Zoom";
897 ot->idname = "IMAGE_OT_view_ndof";
898 ot->description = "Use a 3D mouse device to pan/zoom the view";
899
900 /* API callbacks. */
901 ot->invoke = image_view_ndof_invoke;
903
904 /* flags */
905 ot->flag = OPTYPE_LOCK_BYPASS;
906}
907
909
910#endif /* WITH_INPUT_NDOF */
911
912/* -------------------------------------------------------------------- */
915
916/* Updates the fields of the View2D member of the SpaceImage struct.
917 * Default behavior is to reset the position of the image and set the zoom to 1
918 * If the image will not fit within the window rectangle, the zoom is adjusted */
919
921{
922 SpaceImage *sima;
923 ARegion *region;
924
925 /* retrieve state */
926 sima = CTX_wm_space_image(C);
927 region = CTX_wm_region(C);
928
929 image_view_all(sima, region, op);
930
931 ED_region_tag_redraw(region);
932
933 return OPERATOR_FINISHED;
934}
935
937{
938 PropertyRNA *prop;
939
940 /* identifiers */
941 ot->name = "Frame All";
942 ot->idname = "IMAGE_OT_view_all";
943 ot->description = "View the entire image";
944
945 /* API callbacks. */
948
949 /* flags */
951
952 /* properties */
953 prop = RNA_def_boolean(ot->srna, "fit_view", false, "Fit View", "Fit frame to the viewport");
955}
956
958
959/* -------------------------------------------------------------------- */
962
964{
965 SpaceImage *sima;
966 ARegion *region;
967
968 sima = CTX_wm_space_image(C);
969 region = CTX_wm_region(C);
970
971 image_view_all(sima, region, op);
972
973 sima->cursor[0] = 0.5f;
974 sima->cursor[1] = 0.5f;
975
976 /* Needed for updating the cursor. */
978
979 return OPERATOR_FINISHED;
980}
981
983{
984 PropertyRNA *prop;
985
986 /* identifiers */
987 ot->name = "Cursor To Center View";
988 ot->description = "Set 2D cursor to center view location";
989 ot->idname = "IMAGE_OT_view_cursor_center";
990
991 /* API callbacks. */
994
995 /* properties */
996 prop = RNA_def_boolean(ot->srna, "fit_view", false, "Fit View", "Fit frame to the viewport");
998}
999
1001
1002/* -------------------------------------------------------------------- */
1005
1007{
1009 ARegion *region = CTX_wm_region(C);
1010
1011 ED_image_view_center_to_point(sima, sima->cursor[0], sima->cursor[1]);
1012
1013 ED_region_tag_redraw(region);
1014
1015 return OPERATOR_FINISHED;
1016}
1017
1019{
1020 /* identifiers */
1021 ot->name = "Center View to Cursor";
1022 ot->description = "Center the view so that the cursor is in the middle of the view";
1023 ot->idname = "IMAGE_OT_view_center_cursor";
1024
1025 /* API callbacks. */
1028}
1029
1031
1032/* -------------------------------------------------------------------- */
1035
1037{
1038 SpaceImage *sima;
1039 ARegion *region;
1040 Scene *scene;
1041 ViewLayer *view_layer;
1042 Object *obedit;
1043
1044 const Main *bmain = CTX_data_main(C);
1045
1046 /* retrieve state */
1047 sima = CTX_wm_space_image(C);
1048 region = CTX_wm_region(C);
1049 scene = CTX_data_scene(C);
1050 view_layer = CTX_data_view_layer(C);
1051 obedit = CTX_data_edit_object(C);
1052
1053 /* get bounds */
1054 float min[2], max[2];
1055 if (ED_space_image_show_uvedit(sima, obedit)) {
1057 *bmain, scene, view_layer, nullptr);
1058 bool success = ED_uvedit_minmax_multi(scene, objects, min, max);
1059 if (!success) {
1060 return OPERATOR_CANCELLED;
1061 }
1062 }
1063 else if (ED_space_image_check_show_maskedit(sima, obedit)) {
1064 if (!ED_mask_selected_minmax(C, min, max, false, false)) {
1065 return OPERATOR_CANCELLED;
1066 }
1067 BKE_mask_coord_to_image(sima->image, &sima->iuser, min, min);
1068 BKE_mask_coord_to_image(sima->image, &sima->iuser, max, max);
1069 }
1070 rctf bounds{};
1071 bounds.xmin = min[0];
1072 bounds.ymin = min[1];
1073 bounds.xmax = max[0];
1074 bounds.ymax = max[1];
1075
1076 /* add some margin */
1077 BLI_rctf_scale(&bounds, 1.4f);
1078
1079 sima_zoom_set_from_bounds(sima, region, &bounds);
1080
1081 ED_region_tag_redraw(region);
1082
1083 return OPERATOR_FINISHED;
1084}
1085
1090
1092{
1093 /* identifiers */
1094 ot->name = "View Center";
1095 ot->idname = "IMAGE_OT_view_selected";
1096 ot->description = "View all selected UVs";
1097
1098 /* API callbacks. */
1101}
1102
1104
1105/* -------------------------------------------------------------------- */
1108
1110{
1112 ARegion *region = CTX_wm_region(C);
1113 float location[2];
1114
1115 RNA_float_get_array(op->ptr, "location", location);
1116
1118 sima, region, powf(2.0f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS);
1119
1120 ED_region_tag_redraw(region);
1121
1122 return OPERATOR_FINISHED;
1123}
1124
1126 wmOperator *op,
1127 const wmEvent *event)
1128{
1129 ARegion *region = CTX_wm_region(C);
1130 float location[2];
1131
1133 &region->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
1134 RNA_float_set_array(op->ptr, "location", location);
1135
1136 return image_view_zoom_in_exec(C, op);
1137}
1138
1140{
1141 PropertyRNA *prop;
1142
1143 /* identifiers */
1144 ot->name = "Zoom In";
1145 ot->idname = "IMAGE_OT_view_zoom_in";
1146 ot->description = "Zoom in the image (centered around 2D cursor)";
1147
1148 /* API callbacks. */
1152
1153 /* flags */
1155
1156 /* properties */
1157 prop = RNA_def_float_vector(ot->srna,
1158 "location",
1159 2,
1160 nullptr,
1161 -FLT_MAX,
1162 FLT_MAX,
1163 "Location",
1164 "Cursor location in screen coordinates",
1165 -10.0f,
1166 10.0f);
1168}
1169
1171{
1173 ARegion *region = CTX_wm_region(C);
1174 float location[2];
1175
1176 RNA_float_get_array(op->ptr, "location", location);
1177
1179 sima, region, powf(0.5f, 1.0f / 3.0f), location, U.uiflag & USER_ZOOM_TO_MOUSEPOS);
1180
1181 ED_region_tag_redraw(region);
1182
1183 return OPERATOR_FINISHED;
1184}
1185
1187 wmOperator *op,
1188 const wmEvent *event)
1189{
1190 ARegion *region = CTX_wm_region(C);
1191 float location[2];
1192
1194 &region->v2d, event->mval[0], event->mval[1], &location[0], &location[1]);
1195 RNA_float_set_array(op->ptr, "location", location);
1196
1197 return image_view_zoom_out_exec(C, op);
1198}
1199
1201{
1202 PropertyRNA *prop;
1203
1204 /* identifiers */
1205 ot->name = "Zoom Out";
1206 ot->idname = "IMAGE_OT_view_zoom_out";
1207 ot->description = "Zoom out the image (centered around 2D cursor)";
1208
1209 /* API callbacks. */
1213
1214 /* flags */
1216
1217 /* properties */
1218 prop = RNA_def_float_vector(ot->srna,
1219 "location",
1220 2,
1221 nullptr,
1222 -FLT_MAX,
1223 FLT_MAX,
1224 "Location",
1225 "Cursor location in screen coordinates",
1226 -10.0f,
1227 10.0f);
1229}
1230
1232
1233/* -------------------------------------------------------------------- */
1236
1238{
1240 ARegion *region = CTX_wm_region(C);
1241
1242 sima_zoom_set(sima, region, RNA_float_get(op->ptr, "ratio"), nullptr, false);
1243
1244 /* ensure pixel exact locations for draw */
1245 sima->xof = int(sima->xof);
1246 sima->yof = int(sima->yof);
1247
1248 ED_region_tag_redraw(region);
1249
1250 return OPERATOR_FINISHED;
1251}
1252
1254{
1255 /* identifiers */
1256 ot->name = "View Zoom Ratio";
1257 ot->idname = "IMAGE_OT_view_zoom_ratio";
1258 ot->description = "Set zoom ratio of the view";
1259
1260 /* API callbacks. */
1263
1264 /* flags */
1266
1267 /* properties */
1268 RNA_def_float(ot->srna,
1269 "ratio",
1270 0.0f,
1271 -FLT_MAX,
1272 FLT_MAX,
1273 "Ratio",
1274 "Zoom ratio, 1.0 is 1:1, higher is zoomed in, lower is zoomed out",
1275 -FLT_MAX,
1276 FLT_MAX);
1277}
1278
1280
1281/* -------------------------------------------------------------------- */
1284
1286{
1288 ARegion *region = CTX_wm_region(C);
1289 rctf bounds;
1290 const bool zoom_in = !RNA_boolean_get(op->ptr, "zoom_out");
1291
1293
1295
1296 struct {
1297 float xof;
1298 float yof;
1299 float zoom;
1300 } sima_view_prev{};
1301 sima_view_prev.xof = sima->xof;
1302 sima_view_prev.yof = sima->yof;
1303 sima_view_prev.zoom = sima->zoom;
1304
1305 sima_zoom_set_from_bounds(sima, region, &bounds);
1306
1307 /* zoom out */
1308 if (!zoom_in) {
1309 sima->xof = sima_view_prev.xof + (sima->xof - sima_view_prev.xof);
1310 sima->yof = sima_view_prev.yof + (sima->yof - sima_view_prev.yof);
1311 sima->zoom = sima_view_prev.zoom * (sima_view_prev.zoom / sima->zoom);
1312 }
1313
1314 ED_region_tag_redraw(region);
1315
1316 return OPERATOR_FINISHED;
1317}
1318
1320{
1321 /* identifiers */
1322 ot->name = "Zoom to Border";
1323 ot->description = "Zoom in the view to the nearest item contained in the border";
1324 ot->idname = "IMAGE_OT_view_zoom_border";
1325
1326 /* API callbacks. */
1331
1333
1334 /* rna */
1336}
1337
1338/* load/replace/save callbacks */
1339static void image_filesel(bContext *C, wmOperator *op, const char *path)
1340{
1341 RNA_string_set(op->ptr, "filepath", path);
1343}
1344
1346
1347/* -------------------------------------------------------------------- */
1350
1356
1358{
1359 ImageOpenData *iod;
1360 op->customdata = iod = MEM_new<ImageOpenData>(__func__);
1361 iod->iuser = static_cast<ImageUser *>(
1362 CTX_data_pointer_get_type(C, "image_user", RNA_ImageUser).data);
1364}
1365
1366static void image_open_cancel(bContext * /*C*/, wmOperator *op)
1367{
1368 ImageOpenData *iod = static_cast<ImageOpenData *>(op->customdata);
1369 op->customdata = nullptr;
1370 MEM_delete(iod);
1371}
1372
1374 Library *owner_library,
1375 wmOperator *op,
1376 const ImageFrameRange *range,
1377 const bool use_multiview)
1378{
1379 bool exists = false;
1380 Image *ima = nullptr;
1381
1382 errno = 0;
1383 ima = BKE_image_load_exists_in_lib(bmain, owner_library, range->filepath, true, &exists);
1384
1385 if (!ima) {
1386 BKE_reportf(op->reports,
1387 RPT_ERROR,
1388 "Cannot read '%s': %s",
1389 range->filepath,
1390 errno ? strerror(errno) : RPT_("unsupported image format"));
1391 return nullptr;
1392 }
1393
1394 /* If image already exists, update its file path based on relative path property, see: #109561.
1395 */
1396 if (exists) {
1397 STRNCPY(ima->filepath, range->filepath);
1398 return ima;
1399 }
1400
1401 /* handle multiview images */
1402 if (use_multiview) {
1403 ImageOpenData *iod = static_cast<ImageOpenData *>(op->customdata);
1404 ImageFormatData *imf = &iod->im_format;
1405
1406 ima->flag |= IMA_USE_VIEWS;
1407 ima->views_format = imf->views_format;
1408 *ima->stereo3d_format = imf->stereo3d_format;
1409 }
1410 else {
1411 ima->flag &= ~IMA_USE_VIEWS;
1413 }
1414
1415 if (ima->source == IMA_SRC_FILE) {
1416 if (range->udims_detected && range->udim_tiles.first_) {
1417 ima->source = IMA_SRC_TILED;
1418 ImageTile *first_tile = ima->tiles.first();
1419 first_tile->tile_number = range->offset;
1420 for (LinkData &node : range->udim_tiles) {
1421 BKE_image_add_tile(ima, POINTER_AS_INT(node.data), nullptr);
1422 }
1423 }
1424 else if (range->length > 1) {
1425 ima->source = IMA_SRC_SEQUENCE;
1426 }
1427 }
1428
1429 return ima;
1430}
1431
1433{
1434 Main *bmain = CTX_data_main(C);
1435 ScrArea *area = CTX_wm_area(C);
1436 Scene *scene = CTX_data_scene(C);
1437 ImageUser *iuser = nullptr;
1438 Image *ima = nullptr;
1439 int frame_seq_len = 0;
1440 int frame_ofs = 1;
1441
1442 const bool use_multiview = RNA_boolean_get(op->ptr, "use_multiview");
1443 const bool use_udim = RNA_boolean_get(op->ptr, "use_udim_detecting");
1444
1445 if (!op->customdata) {
1446 image_open_init(C, op);
1447 }
1448
1449 ImageOpenData *iod = static_cast<ImageOpenData *>(op->customdata);
1450 ID *owner_id = iod->pprop.ptr.owner_id;
1451 Library *owner_library = owner_id ? owner_id->lib : nullptr;
1452 StringRefNull blendfile_path = BKE_main_blendfile_path(bmain);
1453 StringRefNull root_path = owner_library ? owner_library->runtime->filepath_abs : blendfile_path;
1454
1455 ListBaseT<ImageFrameRange> ranges = ED_image_filesel_detect_sequences(
1456 blendfile_path, root_path, op, use_udim);
1457 for (ImageFrameRange &range : ranges) {
1458 Image *ima_range = image_open_single(bmain, owner_library, op, &range, use_multiview);
1459
1460 /* take the first image */
1461 if ((ima == nullptr) && ima_range) {
1462 ima = ima_range;
1463 frame_seq_len = range.length;
1464 frame_ofs = range.offset;
1465 }
1466
1467 range.udim_tiles.free_no_destruct();
1468 range.frames.free_no_destruct();
1469 }
1470 ranges.free_no_destruct();
1471
1472 if (ima == nullptr) {
1473 op->customdata = nullptr;
1474 MEM_delete(iod);
1475 return OPERATOR_CANCELLED;
1476 }
1477
1478 /* hook into UI */
1479 if (iod->pprop.prop) {
1480 /* when creating new ID blocks, use is already 1, but RNA
1481 * pointer use also increases user, so this compensates it */
1482 id_us_min(&ima->id);
1483
1484 if (iod->pprop.ptr.owner_id) {
1485 BKE_id_move_to_same_lib(*bmain, ima->id, *iod->pprop.ptr.owner_id);
1486 }
1487
1488 PointerRNA imaptr = RNA_id_pointer_create(&ima->id);
1489 RNA_property_pointer_set(&iod->pprop.ptr, iod->pprop.prop, imaptr, nullptr);
1490 RNA_property_update(C, &iod->pprop.ptr, iod->pprop.prop);
1491 }
1492
1493 if (iod->iuser) {
1494 iuser = iod->iuser;
1495 }
1496 else if (area && area->spacetype == SPACE_IMAGE) {
1497 SpaceImage *sima = area->spacedata.first_as<SpaceImage>();
1498 ED_space_image_set(bmain, sima, ima, false);
1499 iuser = &sima->iuser;
1500 }
1501 else {
1502 Tex *tex = static_cast<Tex *>(CTX_data_pointer_get_type(C, "texture", RNA_Texture).data);
1503 if (tex && tex->type == TEX_IMAGE) {
1504 iuser = &tex->iuser;
1505 }
1506
1507 if (iuser == nullptr) {
1508 Camera *cam = static_cast<Camera *>(CTX_data_pointer_get_type(C, "camera", RNA_Camera).data);
1509 if (cam) {
1510 for (CameraBGImage &bgpic : cam->bg_images) {
1511 if (bgpic.ima == ima) {
1512 iuser = &bgpic.iuser;
1513 break;
1514 }
1515 }
1516 }
1517 }
1518 }
1519
1520 /* initialize because of new image */
1521 if (iuser) {
1522 /* If the sequence was a tiled image, we only have one frame. */
1523 iuser->frames = (ima->source == IMA_SRC_SEQUENCE) ? frame_seq_len : 1;
1524 iuser->sfra = 1;
1525 iuser->framenr = 1;
1526 if (ima->source == IMA_SRC_MOVIE) {
1527 iuser->offset = 0;
1528 }
1529 else {
1530 iuser->offset = frame_ofs - 1;
1531 }
1532 iuser->scene = scene;
1533 BKE_image_init_imageuser(ima, iuser);
1534 }
1535
1536 /* XXX BKE_packedfile_unpack_image frees image buffers */
1538
1539 BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD);
1541
1542 op->customdata = nullptr;
1543 MEM_delete(iod);
1544
1545 return OPERATOR_FINISHED;
1546}
1547
1549{
1550 SpaceImage *sima = CTX_wm_space_image(C); /* XXX other space types can call */
1551 const char *path = U.textudir;
1552 Image *ima = nullptr;
1553 Scene *scene = CTX_data_scene(C);
1554
1555 if (sima) {
1556 ima = sima->image;
1557 }
1558
1559 if (ima == nullptr) {
1560 Tex *tex = static_cast<Tex *>(CTX_data_pointer_get_type(C, "texture", RNA_Texture).data);
1561 if (tex && tex->type == TEX_IMAGE) {
1562 ima = tex->ima;
1563 }
1564 }
1565
1566 if (ima == nullptr) {
1567 PointerRNA ptr;
1568 PropertyRNA *prop;
1569
1570 /* hook into UI */
1572
1573 if (prop) {
1574 PointerRNA oldptr;
1575 Image *oldima;
1576
1577 oldptr = RNA_property_pointer_get(&ptr, prop);
1578 oldima = id_cast<Image *>(oldptr.owner_id);
1579 /* unlikely to fail but better avoid strange crash */
1580 if (oldima && GS(oldima->id.name) == ID_IM) {
1581 ima = oldima;
1582 }
1583 }
1584 }
1585
1586 if (ima) {
1587 path = ima->filepath;
1588 }
1589
1590 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
1591 return image_open_exec(C, op);
1592 }
1593
1594 image_open_init(C, op);
1595
1596 /* Show multi-view save options only if scene has multi-views. */
1597 PropertyRNA *prop;
1598 prop = RNA_struct_find_property(op->ptr, "show_multiview");
1599 RNA_property_boolean_set(op->ptr, prop, (scene->r.scemode & R_MULTIVIEW) != 0);
1600
1601 image_filesel(C, op, path);
1602
1604}
1605
1607 PropertyRNA *prop,
1608 void * /*user_data*/)
1609{
1610 const char *prop_id = RNA_property_identifier(prop);
1611
1612 return !STR_ELEM(prop_id, "filepath", "directory", "filename");
1613}
1614
1615static void image_open_draw(bContext * /*C*/, wmOperator *op)
1616{
1617 ui::Layout &layout = *op->layout;
1618 ImageOpenData *iod = static_cast<ImageOpenData *>(op->customdata);
1619 ImageFormatData *imf = &iod->im_format;
1620
1621 /* main draw call */
1622 uiDefAutoButsRNA(&layout,
1623 op->ptr,
1625 nullptr,
1626 nullptr,
1628 false);
1629
1630 /* image template */
1631 PointerRNA imf_ptr = RNA_pointer_create_discrete(nullptr, RNA_ImageFormatSettings, imf);
1632
1633 /* multiview template */
1634 if (RNA_boolean_get(op->ptr, "show_multiview")) {
1635 uiTemplateImageFormatViews(&layout, &imf_ptr, op->ptr);
1636 }
1637}
1638
1640{
1642 ot->srna, "allow_path_tokens", true, "", "Allow the path to contain substitution tokens");
1644}
1645
1647{
1648 /* identifiers */
1649 ot->name = "Open Image";
1650 ot->description = "Open image";
1651 ot->idname = "IMAGE_OT_open";
1652
1653 /* API callbacks. */
1654 ot->exec = image_open_exec;
1657 ot->ui = image_open_draw;
1658
1659 /* flags */
1661
1662 /* properties */
1672
1674 ot->srna,
1675 "use_sequence_detection",
1676 true,
1677 "Detect Sequences",
1678 "Automatically detect animated sequences in selected images (based on file names)");
1680 "use_udim_detecting",
1681 true,
1682 "Detect UDIMs",
1683 "Detect selected UDIM files and load all matching tiles");
1684}
1685
1687
1688/* -------------------------------------------------------------------- */
1691
1693{
1694 Image *ima = static_cast<Image *>(op->customdata);
1695 if (ima == nullptr) {
1696 return OPERATOR_CANCELLED;
1697 }
1698
1699 char filepath[FILE_MAX];
1700 RNA_string_get(op->ptr, "filepath", filepath);
1701 if (BLI_path_is_rel(filepath)) {
1702 Main *bmain = CTX_data_main(C);
1703 /* Relative path created by the file-browser are always relative to the current blend-file,
1704 * need to be made relative to the library blend-file path in case image is an editable
1705 * linked data. */
1706 BLI_path_abs(filepath, BKE_main_blendfile_path(bmain));
1707 /* TODO(@mont29): make this a BKE_lib_id helper (already a static function in BKE_image too),
1708 * we likely need this in more places in the future. */
1709 BLI_path_rel(filepath, ID_BLEND_PATH(bmain, &ima->id));
1710 }
1711
1712 /* If loading into a tiled texture, ensure that the filename is tokenized. */
1713 if (ima->source == IMA_SRC_TILED) {
1714 BKE_image_ensure_tile_token(filepath, sizeof(filepath));
1715 }
1716
1717 PropertyRNA *imaprop;
1718 PointerRNA imaptr = RNA_id_pointer_create(&ima->id);
1719 imaprop = RNA_struct_find_property(&imaptr, "filepath");
1720
1721 RNA_property_string_set(&imaptr, imaprop, filepath);
1722 RNA_property_update(C, &imaptr, imaprop);
1723
1724 return OPERATOR_FINISHED;
1725}
1726
1728{
1729 Image *ima = image_from_context(C);
1730 if (!ima) {
1731 return OPERATOR_CANCELLED;
1732 }
1733
1734 Main *bmain = CTX_data_main(C);
1735 char filepath[FILE_MAX];
1736 STRNCPY(filepath, ima->filepath);
1737 BLI_path_abs(filepath, ID_BLEND_PATH(bmain, &ima->id));
1738
1739 /* Shift+Click to open the file, Alt+Click to browse a folder in the OS's browser. */
1740 if (event->modifier & (KM_SHIFT | KM_ALT)) {
1741 wmOperatorType *ot = WM_operatortype_find("WM_OT_path_open", true);
1742
1743 if (event->modifier & KM_ALT) {
1744 char *lslash = const_cast<char *>(BLI_path_slash_rfind(filepath));
1745 if (lslash) {
1746 *lslash = '\0';
1747 }
1748 }
1749 else if (ima->source == IMA_SRC_TILED) {
1751 BKE_image_user_file_path(&iuser, ima, filepath);
1752 }
1753
1755 RNA_string_set(&props_ptr, "filepath", filepath);
1757 WM_operator_properties_free(&props_ptr);
1758
1759 return OPERATOR_CANCELLED;
1760 }
1761
1762 /* The image is typically passed to the operator via layout/button context
1763 * (e.g. #ui::Layout::context_ptr_set).
1764 * The File Browser doesn't support restoring this context when calling `exec()` though,
1765 * so we have to pass it the image via custom data. */
1766 op->customdata = ima;
1767
1768 image_filesel(C, op, filepath);
1769
1771}
1772
1774{
1775 Image *ima = image_from_context(C);
1776 return (ima && ID_IS_EDITABLE(ima));
1777}
1778
1780{
1781 /* identifiers */
1782 ot->name = "Browse Image";
1783 ot->description =
1784 "Open an image file browser, hold Shift to open the file, Alt to browse containing "
1785 "directory";
1786 ot->idname = "IMAGE_OT_file_browse";
1787
1788 /* API callbacks. */
1792
1793 /* flags */
1794 ot->flag = OPTYPE_UNDO;
1795
1796 /* properties */
1804}
1805
1807
1808/* -------------------------------------------------------------------- */
1811
1813{
1814 Scene *scene = CTX_data_scene(C);
1815 Image *ima = image_from_context(C);
1817
1818 if (!ima || !iuser) {
1819 /* Try to get a Texture, or a SpaceImage from context... */
1820 Tex *tex = static_cast<Tex *>(CTX_data_pointer_get_type(C, "texture", RNA_Texture).data);
1821 if (tex && tex->type == TEX_IMAGE) {
1822 ima = tex->ima;
1823 iuser = &tex->iuser;
1824 }
1825 }
1826
1827 if (!ima || !iuser || !BKE_image_has_anim(ima)) {
1828 return OPERATOR_CANCELLED;
1829 }
1830
1831 MovieReader *anim = (ima->anims.first())->anim;
1832 if (!anim) {
1833 return OPERATOR_CANCELLED;
1834 }
1835 iuser->frames = MOV_get_duration_frames(anim);
1836 BKE_image_user_frame_calc(ima, iuser, scene->r.cfra);
1837
1838 return OPERATOR_FINISHED;
1839}
1840
1842{
1843 /* identifiers */
1844 ot->name = "Match Movie Length";
1845 ot->description = "Set the image's frame range to match the video's duration";
1846 ot->idname = "IMAGE_OT_match_movie_length";
1847
1848 /* API callbacks. */
1850
1851 /* flags */
1852 /* Don't think we need undo for that. */
1853 ot->flag = OPTYPE_REGISTER | OPTYPE_INTERNAL /* | OPTYPE_UNDO */;
1854}
1855
1857
1858/* -------------------------------------------------------------------- */
1861
1863{
1864 Main *bmain = CTX_data_main(C);
1866 char filepath[FILE_MAX];
1867
1868 if (!sima->image) {
1869 return OPERATOR_CANCELLED;
1870 }
1871
1872 RNA_string_get(op->ptr, "filepath", filepath);
1873
1874 /* we can't do much if the filepath is longer than FILE_MAX :/ */
1875 STRNCPY(sima->image->filepath, filepath);
1876
1877 if (sima->image->source == IMA_SRC_GENERATED) {
1878 sima->image->source = IMA_SRC_FILE;
1879 BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_SRC_CHANGE);
1880 }
1881
1883 sima->image->source = IMA_SRC_MOVIE;
1884 }
1885 else {
1886 sima->image->source = IMA_SRC_FILE;
1887 }
1888
1889 /* XXX BKE_packedfile_unpack_image frees image buffers */
1891
1893 BKE_image_signal(bmain, sima->image, &sima->iuser, IMA_SIGNAL_RELOAD);
1894 DEG_id_tag_update(&sima->image->id, 0);
1896
1897 return OPERATOR_FINISHED;
1898}
1899
1901 wmOperator *op,
1902 const wmEvent * /*event*/)
1903{
1905
1906 if (!sima->image) {
1907 return OPERATOR_CANCELLED;
1908 }
1909
1910 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
1911 return image_replace_exec(C, op);
1912 }
1913
1914 if (!RNA_struct_property_is_set(op->ptr, "relative_path")) {
1915 RNA_boolean_set(op->ptr, "relative_path", BLI_path_is_rel(sima->image->filepath));
1916 }
1917
1918 image_filesel(C, op, sima->image->filepath);
1919
1921}
1922
1924{
1925 /* identifiers */
1926 ot->name = "Replace Image";
1927 ot->idname = "IMAGE_OT_replace";
1928 ot->description = "Replace current image by another one from disk";
1929
1930 /* API callbacks. */
1934
1935 /* flags */
1937
1938 /* properties */
1946}
1947
1949
1950/* -------------------------------------------------------------------- */
1953
1959
1961{
1962 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
1963 RNA_string_get(op->ptr, "filepath", opts->filepath);
1965 }
1966
1967 opts->relative = (RNA_struct_find_property(op->ptr, "relative_path") &&
1968 RNA_boolean_get(op->ptr, "relative_path"));
1969 opts->save_copy = (RNA_struct_find_property(op->ptr, "copy") &&
1970 RNA_boolean_get(op->ptr, "copy"));
1971 opts->save_as_render = (RNA_struct_find_property(op->ptr, "save_as_render") &&
1972 RNA_boolean_get(op->ptr, "save_as_render"));
1973}
1974
1975static bool save_image_op(
1976 Main *bmain, Image *ima, ImageUser *iuser, wmOperator *op, const ImageSaveOptions *opts)
1977{
1978 WM_cursor_wait(true);
1979
1980 bool ok = BKE_image_save(op->reports, bmain, ima, iuser, opts);
1981
1982 WM_cursor_wait(false);
1983
1984 /* Remember file path for next save. */
1985 STRNCPY(G.filepath_last_image, opts->filepath);
1986
1988
1989 return ok;
1990}
1991
1993{
1994 Main *bmain = CTX_data_main(C);
1997 Scene *scene = CTX_data_scene(C);
1998
1999 ImageSaveData *isd = MEM_new<ImageSaveData>(__func__);
2000 isd->image = image;
2001 isd->iuser = iuser;
2002
2003 if (!BKE_image_save_options_init(&isd->opts, bmain, scene, image, iuser, true, false)) {
2005 MEM_delete(isd);
2006 return nullptr;
2007 }
2008
2009 isd->opts.do_newpath = true;
2010
2011 if (!RNA_struct_property_is_set(op->ptr, "filepath")) {
2012 RNA_string_set(op->ptr, "filepath", isd->opts.filepath);
2013 }
2014
2015 /* Enable save_copy by default for render results. */
2016 if (image->source == IMA_SRC_VIEWER && !RNA_struct_property_is_set(op->ptr, "copy")) {
2017 RNA_boolean_set(op->ptr, "copy", true);
2018 }
2019
2020 if (!RNA_struct_property_is_set(op->ptr, "save_as_render")) {
2021 RNA_boolean_set(op->ptr, "save_as_render", isd->opts.save_as_render);
2022 }
2023
2024 /* Show multi-view save options only if image has multi-views. */
2025 PropertyRNA *prop;
2026 prop = RNA_struct_find_property(op->ptr, "show_multiview");
2028 prop = RNA_struct_find_property(op->ptr, "use_multiview");
2030
2031 op->customdata = isd;
2032
2033 return isd;
2034}
2035
2037{
2038 if (op->customdata) {
2039 ImageSaveData *isd = static_cast<ImageSaveData *>(op->customdata);
2041
2042 MEM_delete(isd);
2043 op->customdata = nullptr;
2044 }
2045}
2046
2048{
2049 Main *bmain = CTX_data_main(C);
2050 ImageSaveData *isd;
2051
2052 if (op->customdata) {
2053 isd = static_cast<ImageSaveData *>(op->customdata);
2054 }
2055 else {
2056 isd = image_save_as_init(C, op);
2057 if (isd == nullptr) {
2058 return OPERATOR_CANCELLED;
2059 }
2060 }
2061
2062 image_save_options_from_op(bmain, &isd->opts, op);
2064
2065 save_image_op(bmain, isd->image, isd->iuser, op, &isd->opts);
2066
2067 if (isd->opts.save_copy == false) {
2069 }
2070
2072
2073 return OPERATOR_FINISHED;
2074}
2075
2077{
2078 Main *bmain = CTX_data_main(C);
2079 ImageSaveData *isd = static_cast<ImageSaveData *>(op->customdata);
2080
2081 image_save_options_from_op(bmain, &isd->opts, op);
2083
2085}
2086
2088 wmOperator *op,
2089 const wmEvent * /*event*/)
2090{
2091 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
2092 return image_save_as_exec(C, op);
2093 }
2094
2096 if (isd == nullptr) {
2097 return OPERATOR_CANCELLED;
2098 }
2099
2100 image_filesel(C, op, isd->opts.filepath);
2101
2103}
2104
2106{
2108}
2109
2110static bool image_save_as_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop, void *user_data)
2111{
2112 ImageSaveData *isd = static_cast<ImageSaveData *>(user_data);
2113 const char *prop_id = RNA_property_identifier(prop);
2114
2115 return !(STREQ(prop_id, "filepath") || STREQ(prop_id, "directory") ||
2116 STREQ(prop_id, "filename") ||
2117 /* when saving a copy, relative path has no effect */
2118 (STREQ(prop_id, "relative_path") && RNA_boolean_get(ptr, "copy")) ||
2119 (STREQ(prop_id, "save_as_render") && isd->image->source == IMA_SRC_VIEWER));
2120}
2121
2123{
2124 ui::Layout &layout = *op->layout;
2125 ImageSaveData *isd = static_cast<ImageSaveData *>(op->customdata);
2126 const bool is_multiview = RNA_boolean_get(op->ptr, "show_multiview");
2127 const bool save_as_render = RNA_boolean_get(op->ptr, "save_as_render");
2128
2129 layout.use_property_split_set(true);
2130 layout.use_property_decorate_set(false);
2131
2132 /* Operator settings. */
2133 uiDefAutoButsRNA(&layout,
2134 op->ptr,
2136 isd,
2137 nullptr,
2139 false);
2140
2141 layout.separator();
2142
2143 /* Image format settings. */
2145 nullptr, RNA_ImageFormatSettings, &isd->opts.im_format);
2146 uiTemplateImageSettings(&layout, C, &imf_ptr, save_as_render);
2147
2148 if (!save_as_render) {
2149 PointerRNA linear_settings_ptr = RNA_pointer_get(&imf_ptr, "linear_colorspace_settings");
2150 ui::Layout &col = layout.column(true);
2151 col.separator();
2152 col.prop_with_menu(&linear_settings_ptr,
2153 "name",
2155 IFACE_("Color Space"),
2156 ICON_NONE,
2157 "UI_MT_color_space_select");
2158 }
2159
2160 /* Multiview settings. */
2161 if (is_multiview) {
2162 uiTemplateImageFormatViews(&layout, &imf_ptr, op->ptr);
2163 }
2164}
2165
2167{
2169 return false;
2170 }
2171
2172 if (G.is_rendering) {
2173 /* no need to nullptr check here */
2174 Image *ima = image_from_context(C);
2175
2176 if (ima->source == IMA_SRC_VIEWER) {
2177 CTX_wm_operator_poll_msg_set(C, "Cannot save image while rendering");
2178 return false;
2179 }
2180 }
2181
2182 return true;
2183}
2184
2186{
2187 /* identifiers */
2188 ot->name = "Save As Image";
2189 ot->idname = "IMAGE_OT_save_as";
2190 ot->description = "Save the image with another name and/or settings";
2191
2192 /* API callbacks. */
2197 ot->ui = image_save_as_draw;
2199
2200 /* flags */
2202
2203 /* properties */
2204 PropertyRNA *prop;
2205 prop = RNA_def_boolean(
2206 ot->srna,
2207 "save_as_render",
2208 false,
2209 "Save As Render",
2210 "Save image with render color management.\n"
2211 "For display image formats like PNG, apply view and display transform.\n"
2212 "For intermediate image formats like OpenEXR, use the default render output color space");
2214 prop = RNA_def_boolean(ot->srna,
2215 "copy",
2216 false,
2217 "Copy",
2218 "Create a new image file without modifying the current image in Blender");
2220
2225 FILE_SAVE,
2229}
2230
2232
2233/* -------------------------------------------------------------------- */
2236
2241{
2242 void *lock;
2243 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
2244 bool ret = false;
2245
2246 if (ibuf && BKE_image_buffer_format_writable(ibuf)) {
2247 ret = true;
2248 }
2249
2250 BKE_image_release_ibuf(ima, ibuf, lock);
2251 return ret;
2252}
2253
2255{
2256 /* Can't save if there are no pixels. */
2257 if (image_from_context_has_data_poll(C) == false) {
2258 return false;
2259 }
2260
2261 if (G.is_rendering) {
2262 /* no need to nullptr check here */
2263 Image *ima = image_from_context(C);
2264
2265 if (ima->source == IMA_SRC_VIEWER) {
2266 CTX_wm_operator_poll_msg_set(C, "Cannot save image while rendering");
2267 return false;
2268 }
2269 }
2270
2271 /* Check if there is a valid file path and image format we can write
2272 * outside of the 'poll' so we can show a report with a pop-up. */
2273
2274 /* Can always repack images.
2275 * Images without a filepath will go to "Save As". */
2276 return true;
2277}
2278
2280{
2281 Main *bmain = CTX_data_main(C);
2284 Scene *scene = CTX_data_scene(C);
2285 ImageSaveOptions opts;
2286 bool ok = false;
2287
2289 /* Save packed files to memory. */
2291 /* Report since this can be called from key shortcuts. */
2292 BKE_reportf(op->reports, RPT_INFO, "Packed to memory image \"%s\"", image->filepath);
2293 return OPERATOR_FINISHED;
2294 }
2295
2296 if (!BKE_image_save_options_init(&opts, bmain, scene, image, iuser, false, false)) {
2298 return OPERATOR_CANCELLED;
2299 }
2300 image_save_options_from_op(bmain, &opts, op);
2301
2302 /* Check if file write permission is ok. */
2303 if (BLI_exists(opts.filepath) && !BLI_file_is_writable(opts.filepath)) {
2305 op->reports, RPT_ERROR, "Cannot save image, path \"%s\" is not writable", opts.filepath);
2306 }
2307 else if (save_image_op(bmain, image, iuser, op, &opts)) {
2308 /* Report since this can be called from key shortcuts. */
2309 BKE_reportf(op->reports, RPT_INFO, "Saved image \"%s\"", opts.filepath);
2310 ok = true;
2311 }
2312
2314
2315 if (ok) {
2316 return OPERATOR_FINISHED;
2317 }
2318
2319 return OPERATOR_CANCELLED;
2320}
2321
2323{
2324 Image *ima = image_from_context(C);
2326
2327 /* Not writable formats or images without a file-path will go to "Save As". */
2328 if (!BKE_image_has_packedfile(ima) &&
2329 (!BKE_image_has_filepath(ima) || !image_file_format_writable(ima, iuser)))
2330 {
2331 WM_operator_name_call(C, "IMAGE_OT_save_as", wm::OpCallContext::InvokeDefault, nullptr, event);
2332 return OPERATOR_CANCELLED;
2333 }
2334 return image_save_exec(C, op);
2335}
2336
2338{
2339 /* identifiers */
2340 ot->name = "Save Image";
2341 ot->idname = "IMAGE_OT_save";
2342 ot->description = "Save the image with current name and settings";
2343
2344 /* API callbacks. */
2345 ot->exec = image_save_exec;
2347 ot->poll = image_save_poll;
2348
2349 /* flags */
2351}
2352
2354
2355/* -------------------------------------------------------------------- */
2358
2360{
2362 ImBuf *ibuf, *first_ibuf = nullptr;
2363 int tot = 0;
2364 char di[FILE_MAX];
2365 ImBufCacheIter *iter;
2366
2367 if (image == nullptr) {
2368 return OPERATOR_CANCELLED;
2369 }
2370
2371 if (image->source != IMA_SRC_SEQUENCE) {
2372 BKE_report(op->reports, RPT_ERROR, "Can only save sequence on image sequences");
2373 return OPERATOR_CANCELLED;
2374 }
2375
2376 if (image->type == IMA_TYPE_MULTILAYER) {
2377 BKE_report(op->reports, RPT_ERROR, "Cannot save multilayer sequences");
2378 return OPERATOR_CANCELLED;
2379 }
2380
2381 /* get total dirty buffers and first dirty buffer which is used for menu */
2382 ibuf = nullptr;
2383 if (image->runtime->cache != nullptr) {
2384 iter = IMB_cacheIter_new(image->runtime->cache);
2385 while (!IMB_cacheIter_done(iter)) {
2386 ibuf = IMB_cacheIter_getImBuf(iter);
2387 if (ibuf != nullptr && ibuf->userflags & IB_BITMAPDIRTY) {
2388 if (first_ibuf == nullptr) {
2389 first_ibuf = ibuf;
2390 }
2391 tot++;
2392 }
2393 IMB_cacheIter_step(iter);
2394 }
2395 IMB_cacheIter_free(iter);
2396 }
2397
2398 if (tot == 0) {
2399 BKE_report(op->reports, RPT_WARNING, "No images have been changed");
2400 return OPERATOR_CANCELLED;
2401 }
2402
2403 /* get a filename for menu */
2404 BLI_path_split_dir_part(first_ibuf->filepath.c_str(), di, sizeof(di));
2405 BKE_reportf(op->reports, RPT_INFO, "%d image(s) will be saved in %s", tot, di);
2406
2407 iter = IMB_cacheIter_new(image->runtime->cache);
2408 while (!IMB_cacheIter_done(iter)) {
2409 ibuf = IMB_cacheIter_getImBuf(iter);
2410
2411 if (ibuf != nullptr && ibuf->userflags & IB_BITMAPDIRTY) {
2412 if (0 == IMB_save_image(ibuf, ibuf->filepath.c_str(), ImBufFlags::ByteData)) {
2413 BKE_reportf(op->reports, RPT_ERROR, "Could not write image: %s", strerror(errno));
2414 break;
2415 }
2416
2417 BKE_reportf(op->reports, RPT_INFO, "Saved %s", ibuf->filepath.c_str());
2418 ibuf->userflags &= ~IB_BITMAPDIRTY;
2419 }
2420
2421 IMB_cacheIter_step(iter);
2422 }
2423 IMB_cacheIter_free(iter);
2424
2425 return OPERATOR_FINISHED;
2426}
2427
2429{
2430 /* identifiers */
2431 ot->name = "Save Sequence";
2432 ot->idname = "IMAGE_OT_save_sequence";
2433 ot->description = "Save a sequence of images";
2434
2435 /* API callbacks. */
2438
2439 /* flags */
2441}
2442
2444
2445/* -------------------------------------------------------------------- */
2448
2450{
2451 return !ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE);
2452}
2453
2454static bool image_should_be_saved(Image *ima, bool *r_is_format_writable)
2455{
2456 if (BKE_image_is_dirty_writable(ima, r_is_format_writable) &&
2458 {
2460 }
2461 return false;
2462}
2463
2465{
2466 return strchr(ima->filepath, '\\') || strchr(ima->filepath, '/');
2467}
2468
2470{
2471 /* Images without a filepath (implied with IMA_SRC_GENERATED) should
2472 * be packed during a save_all operation. */
2473 return (ima->source == IMA_SRC_GENERATED) ||
2474 (ima->source == IMA_SRC_TILED && !BKE_image_has_filepath(ima));
2475}
2476
2478{
2479 ReportList reports;
2480 BKE_reports_init(&reports, RPT_STORE);
2481
2482 uint modified_images_count = ED_image_save_all_modified_info(bmain, &reports);
2483 bool should_save = modified_images_count || !reports.list.is_empty();
2484
2485 BKE_reports_free(&reports);
2486
2487 return should_save;
2488}
2489
2491{
2492 Set<std::string> unique_paths;
2493
2494 int num_saveable_images = 0;
2495
2496 for (Image *ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
2497 bool is_format_writable;
2498
2499 if (image_should_be_saved(ima, &is_format_writable)) {
2501 if (ID_IS_EDITABLE(ima)) {
2502 num_saveable_images++;
2503 }
2504 else {
2505 BKE_reportf(reports,
2507 "Packed library image cannot be saved: \"%s\" from \"%s\"",
2508 ima->id.name + 2,
2509 ima->id.lib->filepath);
2510 }
2511 }
2512 else if (!is_format_writable) {
2513 BKE_reportf(reports,
2515 "Image cannot be saved, use a different file format: \"%s\"",
2516 ima->id.name + 2);
2517 }
2518 else {
2519 if (image_has_valid_path(ima)) {
2520 num_saveable_images++;
2521 if (unique_paths.contains_as(ima->filepath)) {
2522 BKE_reportf(reports,
2524 "Multiple images cannot be saved to an identical path: \"%s\"",
2525 ima->filepath);
2526 }
2527 else {
2528 unique_paths.add(ima->filepath);
2529 }
2530 }
2531 else {
2532 BKE_reportf(reports,
2534 "Image cannot be saved, no valid file path: \"%s\"",
2535 ima->filepath);
2536 }
2537 }
2538 }
2539 }
2540
2541 return num_saveable_images;
2542}
2543
2545{
2546 Main *bmain = CTX_data_main(C);
2547
2548 ED_image_save_all_modified_info(bmain, reports);
2549
2550 bool ok = true;
2551
2552 for (Image *ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
2553 bool is_format_writable;
2554
2555 if (image_should_be_saved(ima, &is_format_writable)) {
2558 }
2559 else if (is_format_writable) {
2560 if (image_has_valid_path(ima)) {
2561 ImageSaveOptions opts;
2562 Scene *scene = CTX_data_scene(C);
2563 if (BKE_image_save_options_init(&opts, bmain, scene, ima, nullptr, false, false)) {
2564 bool saved_successfully = BKE_image_save(reports, bmain, ima, nullptr, &opts);
2565 ok = ok && saved_successfully;
2566 }
2568 }
2569 }
2570 }
2571 }
2572 return ok;
2573}
2574
2576{
2577 for (Image *ima = bmain->images.first(); ima; ima = static_cast<Image *>(ima->id.next)) {
2578 bool is_format_writable;
2579
2580 if (image_should_be_saved(ima, &is_format_writable)) {
2582 (is_format_writable && image_has_valid_path(ima)))
2583 {
2585 }
2586 }
2587 }
2588}
2589
2591{
2592 int num_files = ED_image_save_all_modified_info(CTX_data_main(C), nullptr);
2593 return num_files > 0;
2594}
2595
2601
2603{
2604 /* identifiers */
2605 ot->name = "Save All Modified";
2606 ot->idname = "IMAGE_OT_save_all_modified";
2607 ot->description = "Save all modified images";
2608
2609 /* API callbacks. */
2612
2613 /* flags */
2615}
2616
2618
2619/* -------------------------------------------------------------------- */
2622
2624{
2625 Main *bmain = CTX_data_main(C);
2626 Image *ima = image_from_context(C);
2628
2629 if (!ima) {
2630 return OPERATOR_CANCELLED;
2631 }
2632
2634
2635 /* XXX BKE_packedfile_unpack_image frees image buffers */
2637
2638 BKE_image_signal(bmain, ima, iuser, IMA_SIGNAL_RELOAD);
2639 DEG_id_tag_update(&ima->id, 0);
2641
2643
2644 return OPERATOR_FINISHED;
2645}
2646
2648{
2649 /* identifiers */
2650 ot->name = "Reload Image";
2651 ot->idname = "IMAGE_OT_reload";
2652 ot->description = "Reload current image from disk";
2653
2654 /* API callbacks. */
2655 ot->exec = image_reload_exec;
2656
2657 /* flags */
2658 ot->flag = OPTYPE_REGISTER; /* no undo, image buffer is not handled by undo */
2659}
2660
2662
2663/* -------------------------------------------------------------------- */
2666
2667#define IMA_DEF_NAME N_("Untitled")
2668
2669enum {
2673};
2674
2678
2680{
2681 if (op->customdata) {
2682 return static_cast<ImageNewData *>(op->customdata);
2683 }
2684
2685 ImageNewData *data = MEM_new<ImageNewData>(__func__);
2686 ui::context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop);
2687 op->customdata = data;
2688 return data;
2689}
2690
2692{
2693 if (op->customdata) {
2694 MEM_delete(static_cast<ImageNewData *>(op->customdata));
2695 }
2696}
2697
2699{
2700 SpaceImage *sima;
2701 Image *ima;
2702 Main *bmain;
2703 PropertyRNA *prop;
2704 char name_buffer[MAX_ID_NAME - 2];
2705 const char *name;
2706 float color[4];
2707 int width, height, floatbuf, gen_type, alpha;
2708 int stereo3d;
2709
2710 /* retrieve state */
2711 sima = CTX_wm_space_image(C);
2712 bmain = CTX_data_main(C);
2713
2714 prop = RNA_struct_find_property(op->ptr, "name");
2715 RNA_property_string_get(op->ptr, prop, name_buffer);
2716 if (!RNA_property_is_set(op->ptr, prop)) {
2717 /* Default value, we can translate! */
2718 name = DATA_(name_buffer);
2719 }
2720 else {
2721 name = name_buffer;
2722 }
2723 width = RNA_int_get(op->ptr, "width");
2724 height = RNA_int_get(op->ptr, "height");
2725 floatbuf = RNA_boolean_get(op->ptr, "float");
2726 gen_type = RNA_enum_get(op->ptr, "generated_type");
2727 RNA_float_get_array(op->ptr, "color", color);
2728 alpha = RNA_boolean_get(op->ptr, "alpha");
2729 stereo3d = RNA_boolean_get(op->ptr, "use_stereo_3d");
2730 bool tiled = RNA_boolean_get(op->ptr, "tiled");
2731
2732 if (!alpha) {
2733 color[3] = 1.0f;
2734 }
2735
2736 ima = BKE_image_add_generated(bmain,
2737 width,
2738 height,
2739 name,
2740 alpha ? 32 : 24,
2741 floatbuf,
2742 gen_type,
2743 color,
2744 stereo3d,
2745 false,
2746 tiled);
2747
2748 if (!ima) {
2749 image_new_free(op);
2750 return OPERATOR_CANCELLED;
2751 }
2752
2753 /* hook into UI */
2755
2756 if (data->pprop.prop) {
2757 /* when creating new ID blocks, use is already 1, but RNA
2758 * pointer use also increases user, so this compensates it */
2759 id_us_min(&ima->id);
2760
2761 if (data->pprop.ptr.owner_id) {
2762 BKE_id_move_to_same_lib(*bmain, ima->id, *data->pprop.ptr.owner_id);
2763 }
2764
2765 PointerRNA imaptr = RNA_id_pointer_create(&ima->id);
2766 RNA_property_pointer_set(&data->pprop.ptr, data->pprop.prop, imaptr, nullptr);
2767 RNA_property_update(C, &data->pprop.ptr, data->pprop.prop);
2768 }
2769 else if (sima) {
2770 ED_space_image_set(bmain, sima, ima, false);
2771 }
2772 else {
2773 /* #BKE_image_add_generated creates one user by default, remove it if image is not linked to
2774 * anything. ref. #94599. */
2775 id_us_min(&ima->id);
2776 }
2777
2778 BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : nullptr, IMA_SIGNAL_USER_NEW_IMAGE);
2779
2781
2782 image_new_free(op);
2783
2784 return OPERATOR_FINISHED;
2785}
2786
2788{
2789 /* Get property in advance, it doesn't work after WM_operator_props_dialog_popup. */
2791 op->customdata = data = MEM_new<ImageNewData>(__func__);
2792 ui::context_active_but_prop_get_templateID(C, &data->pprop.ptr, &data->pprop.prop);
2793
2794 /* Better for user feedback. */
2795 RNA_string_set(op->ptr, "name", DATA_(IMA_DEF_NAME));
2797 C, op, 300, IFACE_("Create a New Image"), IFACE_("New Image"));
2798}
2799
2800static void image_new_draw(bContext * /*C*/, wmOperator *op)
2801{
2802 /* TODO: Deduplicate with texture_paint_add_texture_paint_slot_ui */
2803 ui::Layout &layout = *op->layout;
2804
2805 /* copy of WM_operator_props_dialog_popup() layout */
2806
2807 layout.use_property_split_set(true);
2808 layout.use_property_decorate_set(false);
2809
2810 layout.prop(op->ptr, "name", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2811 ui::Layout &dim_col = layout.column(true);
2812 dim_col.prop(op->ptr, "width", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2813 dim_col.prop(op->ptr, "height", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2814
2815 ui::Layout &col = layout.column(false);
2816 col.prop(op->ptr, "generated_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2817
2818 const int gen_type = RNA_enum_get(op->ptr, "generated_type");
2819 ui::Layout &color_col = col.column(false);
2820 if (gen_type == IMA_GENTYPE_BLANK) {
2821 color_col.prop(op->ptr, "color", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2822 }
2823
2824 col.prop(op->ptr, "alpha", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2825 col.prop(op->ptr, "float", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2826 col.prop(op->ptr, "tiled", UI_ITEM_NONE, std::nullopt, ICON_NONE);
2827}
2828
2829static void image_new_cancel(bContext * /*C*/, wmOperator *op)
2830{
2831 image_new_free(op);
2832}
2833
2835{
2836 PropertyRNA *prop;
2837 static const float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
2838
2839 /* identifiers */
2840 ot->name = "New Image";
2841 ot->description = "Create a new image";
2842 ot->idname = "IMAGE_OT_new";
2843
2844 /* API callbacks. */
2845 ot->exec = image_new_exec;
2847 ot->ui = image_new_draw;
2849
2850 /* flags */
2851 ot->flag = OPTYPE_UNDO;
2852
2853 /* properties */
2854 ot->prop = RNA_def_string(
2855 ot->srna, "name", IMA_DEF_NAME, MAX_ID_NAME - 2, "Name", "Image data-block name");
2856 prop = RNA_def_int(ot->srna, "width", 1024, 1, INT_MAX, "Width", "Image width", 1, 16384);
2858 prop = RNA_def_int(ot->srna, "height", 1024, 1, INT_MAX, "Height", "Image height", 1, 16384);
2860 prop = RNA_def_float_color(
2861 ot->srna, "color", 4, nullptr, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f);
2863 RNA_def_property_float_array_default(prop, default_color);
2864 RNA_def_boolean(ot->srna, "alpha", true, "Alpha", "Create an image with an alpha channel");
2865 RNA_def_enum(ot->srna,
2866 "generated_type",
2869 "Generated Type",
2870 "Fill the image with a grid for UV map testing");
2872 "float",
2873 false,
2874 "32-bit Float",
2875 "Create image with 32-bit floating-point bit depth");
2877 prop = RNA_def_boolean(
2878 ot->srna, "use_stereo_3d", false, "Stereo 3D", "Create an image with left and right views");
2880 prop = RNA_def_boolean(ot->srna, "tiled", false, "Tiled", "Create a tiled image");
2882}
2883
2884#undef IMA_DEF_NAME
2885
2887
2888/* -------------------------------------------------------------------- */
2891
2893{
2894 Image *ima = image_from_context(C);
2896 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
2898 const bool is_paint = ((sima != nullptr) && (sima->mode == SI_MODE_PAINT));
2899
2900 if (ibuf == nullptr) {
2901 /* TODO: this should actually never happen, but does for render-results -> cleanup. */
2902 return OPERATOR_CANCELLED;
2903 }
2904
2905 const bool use_flip_x = RNA_boolean_get(op->ptr, "use_flip_x");
2906 const bool use_flip_y = RNA_boolean_get(op->ptr, "use_flip_y");
2907
2908 if (!use_flip_x && !use_flip_y) {
2909 BKE_image_release_ibuf(ima, ibuf, nullptr);
2910 return OPERATOR_FINISHED;
2911 }
2912
2913 ED_image_undo_push_begin_with_image(op->type->name, ima, ibuf, &iuser);
2914
2915 if (is_paint) {
2917 }
2918
2919 const int size_x = ibuf->x;
2920 const int size_y = ibuf->y;
2921
2922 if (ibuf->float_data()) {
2923 float *float_pixels = ibuf->float_data_for_write();
2924
2925 float *orig_float_pixels = MEM_dupalloc(float_pixels);
2926 for (int x = 0; x < size_x; x++) {
2927 const int source_pixel_x = use_flip_x ? size_x - x - 1 : x;
2928 for (int y = 0; y < size_y; y++) {
2929 const int source_pixel_y = use_flip_y ? size_y - y - 1 : y;
2930
2931 const float *source_pixel =
2932 &orig_float_pixels[4 * (source_pixel_x + source_pixel_y * size_x)];
2933 float *target_pixel = &float_pixels[4 * (x + y * size_x)];
2934
2935 copy_v4_v4(target_pixel, source_pixel);
2936 }
2937 }
2938 MEM_delete(orig_float_pixels);
2939
2940 if (ibuf->byte_data()) {
2941 IMB_byte_from_float(ibuf);
2942 }
2943 }
2944 else if (uchar *char_pixels = ibuf->byte_data_for_write()) {
2945 uchar *orig_char_pixels = MEM_dupalloc(char_pixels);
2946 for (int x = 0; x < size_x; x++) {
2947 const int source_pixel_x = use_flip_x ? size_x - x - 1 : x;
2948 for (int y = 0; y < size_y; y++) {
2949 const int source_pixel_y = use_flip_y ? size_y - y - 1 : y;
2950
2951 const uchar *source_pixel =
2952 &orig_char_pixels[4 * (source_pixel_x + source_pixel_y * size_x)];
2953 uchar *target_pixel = &char_pixels[4 * (x + y * size_x)];
2954
2955 copy_v4_v4_uchar(target_pixel, source_pixel);
2956 }
2957 }
2958 MEM_delete(orig_char_pixels);
2959 }
2960 else {
2961 BKE_image_release_ibuf(ima, ibuf, nullptr);
2962 return OPERATOR_CANCELLED;
2963 }
2964
2966 IMB_mark_dirty(ibuf);
2967
2969
2972
2973 BKE_image_release_ibuf(ima, ibuf, nullptr);
2974
2975 return OPERATOR_FINISHED;
2976}
2977
2979{
2980 /* identifiers */
2981 ot->name = "Flip Image";
2982 ot->idname = "IMAGE_OT_flip";
2983 ot->description = "Flip the image";
2984
2985 /* API callbacks. */
2986 ot->exec = image_flip_exec;
2988
2989 /* properties */
2990 PropertyRNA *prop;
2991 prop = RNA_def_boolean(
2992 ot->srna, "use_flip_x", false, "Horizontal", "Flip the image horizontally");
2994 prop = RNA_def_boolean(ot->srna, "use_flip_y", false, "Vertical", "Flip the image vertically");
2996
2997 /* flags */
2998 ot->flag = OPTYPE_REGISTER;
2999}
3000
3002
3003/* -------------------------------------------------------------------- */
3006
3008{
3009 Image *ima = image_from_context(C);
3011 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
3013 const bool is_paint = ((sima != nullptr) && (sima->mode == SI_MODE_PAINT));
3014
3015 if (ibuf == nullptr) {
3016 /* TODO: this should actually never happen, but does for render-results -> cleanup. */
3017 return OPERATOR_CANCELLED;
3018 }
3019
3020 int degrees = RNA_enum_get(op->ptr, "degrees");
3021
3022 ED_image_undo_push_begin_with_image(op->type->name, ima, ibuf, &iuser);
3023
3024 if (is_paint) {
3026 }
3027
3028 if (!IMB_rotate_orthogonal(ibuf, degrees)) {
3029 BKE_image_release_ibuf(ima, ibuf, nullptr);
3030 return OPERATOR_CANCELLED;
3031 }
3032
3034 IMB_mark_dirty(ibuf);
3035
3037
3039
3041 BKE_image_release_ibuf(ima, ibuf, nullptr);
3042
3043 return OPERATOR_FINISHED;
3044}
3045
3047{
3048 static const EnumPropertyItem orthogonal_rotation_items[] = {
3049 {90, "90", 0, "90 Degrees", "Rotate 90 degrees clockwise"},
3050 {180, "180", 0, "180 Degrees", "Rotate 180 degrees clockwise"},
3051 {270, "270", 0, "270 Degrees", "Rotate 270 degrees clockwise"},
3052 {0, nullptr, 0, nullptr, nullptr},
3053 };
3054
3055 /* identifiers */
3056 ot->name = "Rotate Image Orthogonal";
3057 ot->idname = "IMAGE_OT_rotate_orthogonal";
3058 ot->description = "Rotate the image";
3059
3060 /* API callbacks. */
3063
3064 /* properties */
3065 PropertyRNA *prop;
3066 prop = RNA_def_enum(ot->srna,
3067 "degrees",
3068 orthogonal_rotation_items,
3069 90,
3070 "Degrees",
3071 "Amount of rotation in degrees (90, 180, 270)");
3073
3074 /* flags */
3075 ot->flag = OPTYPE_REGISTER;
3076}
3077
3079
3080/* -------------------------------------------------------------------- */
3083
3085{
3086 Scene *scene = CTX_data_scene(C);
3087 Image *ima = image_from_context(C);
3088 if (ima == nullptr) {
3089 return OPERATOR_CANCELLED;
3090 }
3091
3092 if (G.is_rendering && ima->source == IMA_SRC_VIEWER) {
3093 BKE_report(op->reports, RPT_ERROR, "Images cannot be copied while rendering");
3094 return OPERATOR_CANCELLED;
3095 }
3096
3098 WM_cursor_wait(true);
3099 void *lock;
3100 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, &lock);
3101 bool changed = false;
3102 if (ibuf) {
3103 /* Clipboard uses byte buffer, so match saving an 8 bit PNG for color management. */
3104 const bool save_as_render = ima->flag & IMA_VIEW_AS_RENDER;
3105
3106 ImageFormatData image_format;
3107 BKE_image_format_init_for_write(&image_format, scene, nullptr);
3108 BKE_image_format_set(&image_format, nullptr, R_IMF_IMTYPE_PNG);
3109 image_format.depth = R_IMF_CHAN_DEPTH_8;
3110
3111 ImBuf *colormanaged_ibuf = IMB_colormanagement_imbuf_for_write(
3112 ibuf, save_as_render, true, &image_format);
3113
3114 if (WM_clipboard_image_set_byte_buffer(colormanaged_ibuf)) {
3115 changed = true;
3116 }
3117
3118 if (colormanaged_ibuf != ibuf) {
3119 IMB_freeImBuf(colormanaged_ibuf);
3120 }
3121 BKE_image_format_free(&image_format);
3122 }
3123 BKE_image_release_ibuf(ima, ibuf, lock);
3124 WM_cursor_wait(false);
3125
3126 return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
3127}
3128
3130{
3132 CTX_wm_operator_poll_msg_set(C, "No images available");
3133 return false;
3134 }
3135
3136 return true;
3137}
3138
3140{
3141 /* identifiers */
3142 ot->name = "Copy Image";
3143 ot->idname = "IMAGE_OT_clipboard_copy";
3144 ot->description = "Copy the image to the clipboard";
3145
3146 /* API callbacks. */
3149
3150 /* flags */
3151 ot->flag = OPTYPE_REGISTER;
3152}
3153
3155
3156/* -------------------------------------------------------------------- */
3159
3161{
3162 bool changed = false;
3163
3164 WM_cursor_wait(true);
3165 ImBuf *ibuf = WM_clipboard_image_get();
3166 if (ibuf) {
3167 ED_undo_push_op(C, op);
3168
3169 Main *bmain = CTX_data_main(C);
3171 Image *ima = BKE_image_add_from_imbuf(bmain, ibuf, "Clipboard");
3172 IMB_freeImBuf(ibuf);
3173
3174 ED_space_image_set(bmain, sima, ima, false);
3175 BKE_image_signal(bmain, ima, (sima) ? &sima->iuser : nullptr, IMA_SIGNAL_USER_NEW_IMAGE);
3177 changed = true;
3178 }
3179 WM_cursor_wait(false);
3180
3181 return changed ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
3182}
3183
3185{
3187 if (!sima) {
3188 CTX_wm_operator_poll_msg_set(C, "Image Editor not found");
3189 return false;
3190 }
3191
3193 CTX_wm_operator_poll_msg_set(C, "No compatible images are on the clipboard");
3194 return false;
3195 }
3196
3197 return true;
3198}
3199
3201{
3202 /* identifiers */
3203 ot->name = "Paste Image";
3204 ot->idname = "IMAGE_OT_clipboard_paste";
3205 ot->description = "Paste new image from the clipboard";
3206
3207 /* API callbacks. */
3210
3211 /* flags */
3212 ot->flag = OPTYPE_REGISTER;
3213}
3214
3216
3217/* -------------------------------------------------------------------- */
3220
3222{
3223 Image *ima = image_from_context(C);
3225 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
3227 const bool is_paint = ((sima != nullptr) && (sima->mode == SI_MODE_PAINT));
3228
3229 /* flags indicate if this channel should be inverted */
3230 const bool r = RNA_boolean_get(op->ptr, "invert_r");
3231 const bool g = RNA_boolean_get(op->ptr, "invert_g");
3232 const bool b = RNA_boolean_get(op->ptr, "invert_b");
3233 const bool a = RNA_boolean_get(op->ptr, "invert_a");
3234
3235 size_t i;
3236
3237 if (ibuf == nullptr) {
3238 /* TODO: this should actually never happen, but does for render-results -> cleanup */
3239 return OPERATOR_CANCELLED;
3240 }
3241
3242 ED_image_undo_push_begin_with_image(op->type->name, ima, ibuf, &iuser);
3243
3244 if (is_paint) {
3246 }
3247
3248 /* TODO: make this into an IMB_invert_channels(ibuf,r,g,b,a) method!? */
3249 if (float *float_data = ibuf->float_data_for_write()) {
3250
3251 float *fp = float_data;
3252 for (i = size_t(ibuf->x) * ibuf->y; i > 0; i--, fp += 4) {
3253 if (r) {
3254 fp[0] = 1.0f - fp[0];
3255 }
3256 if (g) {
3257 fp[1] = 1.0f - fp[1];
3258 }
3259 if (b) {
3260 fp[2] = 1.0f - fp[2];
3261 }
3262 if (a) {
3263 fp[3] = 1.0f - fp[3];
3264 }
3265 }
3266
3267 if (ibuf->byte_data()) {
3268 IMB_byte_from_float(ibuf);
3269 }
3270 }
3271 else if (uchar *cp = ibuf->byte_data_for_write()) {
3272 for (i = size_t(ibuf->x) * ibuf->y; i > 0; i--, cp += 4) {
3273 if (r) {
3274 cp[0] = 255 - cp[0];
3275 }
3276 if (g) {
3277 cp[1] = 255 - cp[1];
3278 }
3279 if (b) {
3280 cp[2] = 255 - cp[2];
3281 }
3282 if (a) {
3283 cp[3] = 255 - cp[3];
3284 }
3285 }
3286 }
3287 else {
3288 BKE_image_release_ibuf(ima, ibuf, nullptr);
3289 return OPERATOR_CANCELLED;
3290 }
3291
3293 IMB_mark_dirty(ibuf);
3294
3296
3298
3300
3301 BKE_image_release_ibuf(ima, ibuf, nullptr);
3302
3303 return OPERATOR_FINISHED;
3304}
3305
3307{
3308 PropertyRNA *prop;
3309
3310 /* identifiers */
3311 ot->name = "Invert Channels";
3312 ot->idname = "IMAGE_OT_invert";
3313 ot->description = "Invert image's channels";
3314
3315 /* API callbacks. */
3316 ot->exec = image_invert_exec;
3318
3319 /* properties */
3320 prop = RNA_def_boolean(ot->srna, "invert_r", false, "Red", "Invert red channel");
3322 prop = RNA_def_boolean(ot->srna, "invert_g", false, "Green", "Invert green channel");
3324 prop = RNA_def_boolean(ot->srna, "invert_b", false, "Blue", "Invert blue channel");
3326 prop = RNA_def_boolean(ot->srna, "invert_a", false, "Alpha", "Invert alpha channel");
3328
3329 /* flags */
3330 ot->flag = OPTYPE_REGISTER;
3331}
3332
3334
3335/* -------------------------------------------------------------------- */
3338
3340{
3341 Image *ima = image_from_context(C);
3343 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size");
3344 if (!RNA_property_is_set(op->ptr, prop)) {
3345 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
3346 const int size[2] = {ibuf->x, ibuf->y};
3347 RNA_property_int_set_array(op->ptr, prop, size);
3348 BKE_image_release_ibuf(ima, ibuf, nullptr);
3349 }
3351 C, op, 200, IFACE_("Scale Image to New Size"), IFACE_("Resize"));
3352}
3353
3355{
3356 Image *ima = image_from_context(C);
3359 const bool is_paint = ((sima != nullptr) && (sima->mode == SI_MODE_PAINT));
3360
3361 if (is_paint) {
3363 }
3364
3365 const bool is_scaling_all = RNA_boolean_get(op->ptr, "all_udims");
3366
3367 if (!is_scaling_all) {
3368 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
3369
3370 if (ibuf == nullptr) {
3371 /* TODO: this should actually never happen, but does for render-results -> cleanup */
3372 return OPERATOR_CANCELLED;
3373 }
3374
3375 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size");
3376 int size[2];
3377 if (RNA_property_is_set(op->ptr, prop)) {
3378 RNA_property_int_get_array(op->ptr, prop, size);
3379 }
3380 else {
3381 size[0] = ibuf->x;
3382 size[1] = ibuf->y;
3383 RNA_property_int_set_array(op->ptr, prop, size);
3384 }
3385
3386 ED_image_undo_push_begin_with_image(op->type->name, ima, ibuf, &iuser);
3387 IMB_scale(ibuf, size[0], size[1], IMBScaleFilter::Box, false);
3389 IMB_mark_dirty(ibuf);
3390 BKE_image_release_ibuf(ima, ibuf, nullptr);
3392 }
3393 else {
3394 /* Ensure that an image buffer can be acquired for all UDIM tiles. */
3395 for (ImageTile &current_tile : ima->tiles) {
3396 iuser.tile = current_tile.tile_number;
3397
3398 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
3399
3400 if (ibuf == nullptr) {
3401 /* TODO: this should actually never happen, but does for render-results -> cleanup */
3402 return OPERATOR_CANCELLED;
3403 }
3404
3405 BKE_image_release_ibuf(ima, ibuf, nullptr);
3406 }
3407
3409 for (ImageTile &current_tile : ima->tiles) {
3410 iuser.tile = current_tile.tile_number;
3411
3412 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
3413
3414 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "size");
3415 int size[2];
3416 if (RNA_property_is_set(op->ptr, prop)) {
3417 RNA_property_int_get_array(op->ptr, prop, size);
3418 }
3419 else {
3420 size[0] = ibuf->x;
3421 size[1] = ibuf->y;
3422 RNA_property_int_set_array(op->ptr, prop, size);
3423 }
3424
3425 IMB_scale(ibuf, size[0], size[1], IMBScaleFilter::Box, false);
3427 IMB_mark_dirty(ibuf);
3428 BKE_image_release_ibuf(ima, ibuf, nullptr);
3429 }
3431 }
3432
3433 DEG_id_tag_update(&ima->id, 0);
3435
3436 return OPERATOR_FINISHED;
3437}
3438
3440{
3441 /* identifiers */
3442 ot->name = "Resize Image";
3443 ot->idname = "IMAGE_OT_resize";
3444 ot->description = "Resize the image";
3445
3446 /* API callbacks. */
3448 ot->exec = image_scale_exec;
3450
3451 /* properties */
3452 RNA_def_int_vector(ot->srna, "size", 2, nullptr, 1, INT_MAX, "Size", "", 1, SHRT_MAX);
3454 ot->srna, "all_udims", false, "All UDIM Tiles", "Scale all the image's UDIM tiles");
3455
3456 /* flags */
3457 ot->flag = OPTYPE_REGISTER;
3458}
3459
3461
3462/* -------------------------------------------------------------------- */
3465
3466static bool image_pack_test(Image *ima, const char **r_error_message)
3467{
3468 if (!ima) {
3469 return false;
3470 }
3471
3472 if (!ID_IS_EDITABLE(&ima->id)) {
3473 *r_error_message = N_("Image is not editable");
3474 return false;
3475 }
3476
3477 if (!BKE_image_is_dirty(ima) && ima->source == IMA_SRC_GENERATED) {
3478 *r_error_message = N_("Unedited generated images do not support packing");
3479 return false;
3480 }
3481
3482 if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
3483 *r_error_message = N_("Movies or image sequences do not support packing");
3484 return false;
3485 }
3486
3487 if (ELEM(ima->type, IMA_TYPE_R_RESULT, IMA_TYPE_COMPOSITE)) {
3488 *r_error_message = N_("Render Result and Viewer Nodes cannot be packed");
3489 return false;
3490 }
3491
3492 return true;
3493}
3494
3496{
3497 Image *ima = image_from_context(C);
3498 const char *error_message = nullptr;
3499
3500 if (image_pack_test(ima, &error_message)) {
3501 return true;
3502 }
3503
3504 if (error_message) {
3505 CTX_wm_operator_poll_msg_set(C, error_message);
3506 }
3507 return false;
3508}
3509
3511{
3512 Main *bmain = CTX_data_main(C);
3513 Image *ima = image_from_context(C);
3514
3515 const char *error_message = nullptr;
3516 if (!image_pack_test(ima, &error_message)) {
3517 if (error_message) {
3518 BKE_report(op->reports, RPT_ERROR, error_message);
3519 }
3520 return OPERATOR_CANCELLED;
3521 }
3522
3523 if (BKE_image_is_dirty(ima)) {
3525 }
3526 else {
3527 BKE_image_packfiles(op->reports, ima, ID_BLEND_PATH(bmain, &ima->id));
3528 }
3529
3531
3532 return OPERATOR_FINISHED;
3533}
3534
3536{
3537 /* identifiers */
3538 ot->name = "Pack Image";
3539 ot->description = "Pack an image as embedded data into the .blend file";
3540 ot->idname = "IMAGE_OT_pack";
3541
3542 /* API callbacks. */
3543 ot->exec = image_pack_exec;
3544 ot->poll = image_pack_poll;
3545
3546 /* flags */
3548}
3549
3551
3552/* -------------------------------------------------------------------- */
3555
3557{
3558 Main *bmain = CTX_data_main(C);
3559 Image *ima = image_from_context(C);
3560 int method = RNA_enum_get(op->ptr, "method");
3561
3562 /* find the supplied image by name */
3563 if (RNA_struct_property_is_set(op->ptr, "id")) {
3564 char imaname[MAX_ID_NAME - 2];
3565 RNA_string_get(op->ptr, "id", imaname);
3566 ima = static_cast<Image *>(BLI_findstring(&bmain->images, imaname, offsetof(ID, name) + 2));
3567 if (!ima) {
3568 ima = image_from_context(C);
3569 }
3570 }
3571
3572 if (!ima || !BKE_image_has_packedfile(ima)) {
3573 return OPERATOR_CANCELLED;
3574 }
3575
3576 if (!ID_IS_EDITABLE(&ima->id)) {
3577 BKE_report(op->reports, RPT_ERROR, "Image is not editable");
3578 return OPERATOR_CANCELLED;
3579 }
3580
3581 if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
3582 BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
3583 return OPERATOR_CANCELLED;
3584 }
3585
3586 if (G.fileflags & G_FILE_AUTOPACK) {
3587 BKE_report(op->reports,
3589 "AutoPack is enabled, so image will be packed again on file save");
3590 }
3591
3592 /* XXX BKE_packedfile_unpack_image frees image buffers */
3594
3596
3598
3599 return OPERATOR_FINISHED;
3600}
3601
3603{
3604 Image *ima = image_from_context(C);
3605
3606 if (RNA_struct_property_is_set(op->ptr, "id")) {
3607 return image_unpack_exec(C, op);
3608 }
3609
3610 if (!ima || !BKE_image_has_packedfile(ima)) {
3611 return OPERATOR_CANCELLED;
3612 }
3613
3614 if (!ID_IS_EDITABLE(&ima->id)) {
3615 BKE_report(op->reports, RPT_ERROR, "Image is not editable");
3616 return OPERATOR_CANCELLED;
3617 }
3618
3619 if (ELEM(ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) {
3620 BKE_report(op->reports, RPT_ERROR, "Unpacking movies or image sequences not supported");
3621 return OPERATOR_CANCELLED;
3622 }
3623
3624 if (G.fileflags & G_FILE_AUTOPACK) {
3625 BKE_report(op->reports,
3627 "AutoPack is enabled, so image will be packed again on file save");
3628 }
3629
3630 unpack_menu(C,
3631 "IMAGE_OT_unpack",
3632 ima->id.name + 2,
3633 ima->filepath,
3634 "textures",
3635 BKE_image_has_packedfile(ima) ? (ima->packedfiles.first())->packedfile : nullptr);
3636
3637 return OPERATOR_FINISHED;
3638}
3639
3641{
3642 /* identifiers */
3643 ot->name = "Unpack Image";
3644 ot->description = "Save an image packed in the .blend file to disk";
3645 ot->idname = "IMAGE_OT_unpack";
3646
3647 /* API callbacks. */
3648 ot->exec = image_unpack_exec;
3650 ot->poll = image_pack_poll;
3651
3652 /* flags */
3654
3655 /* properties */
3657 ot->srna, "method", rna_enum_unpack_method_items, PF_USE_LOCAL, "Method", "How to unpack");
3658 /* XXX, weak!, will fail with library, name collisions */
3660 ot->srna, "id", nullptr, MAX_ID_NAME - 2, "Image Name", "Image data-block name to unpack");
3661}
3662
3664
3665/* -------------------------------------------------------------------- */
3668
3670 ARegion *region,
3671 const int mval[2],
3672 float r_fpos[2])
3673{
3674 void *lock;
3675 ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, 0, false);
3676
3677 if (ibuf == nullptr) {
3679 return false;
3680 }
3681
3682 ui::view2d_region_to_view(&region->v2d, mval[0], mval[1], &r_fpos[0], &r_fpos[1]);
3683
3685 return true;
3686}
3687
3689 SpaceImage *sima, ARegion *region, const int mval[2], float r_col[3], bool *r_is_data)
3690{
3691 if (r_is_data) {
3692 *r_is_data = false;
3693 }
3694 if (sima->image == nullptr) {
3695 return false;
3696 }
3697
3698 float uv[2];
3699 ui::view2d_region_to_view(&region->v2d, mval[0], mval[1], &uv[0], &uv[1]);
3700 const int tile = BKE_image_get_tile_from_pos(sima->image, uv, uv, nullptr);
3701 const bool is_repeat_display = sima->image->source != IMA_SRC_TILED &&
3702 ((sima->flag & SI_DRAW_TILE) != 0);
3703 if (is_repeat_display) {
3704 /* When displaying with "Repeat Image" and the mouse outside the main view, make sure we still
3705 * sample from the ImBuf (so warp back the uv), otherwise we would sample directly from the GPU
3706 * buffer. */
3707 uv[0] -= floorf(uv[0]);
3708 uv[1] -= floorf(uv[1]);
3709 }
3710
3711 void *lock;
3712 ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, tile, true);
3713 bool ret = false;
3714
3715 if (ibuf == nullptr) {
3717 return false;
3718 }
3719
3720 if (uv[0] >= 0.0f && uv[1] >= 0.0f && uv[0] < 1.0f && uv[1] < 1.0f) {
3721 const float *fp;
3722 const uchar *cp;
3723 int x = int(uv[0] * ibuf->x), y = int(uv[1] * ibuf->y);
3724
3725 CLAMP(x, 0, ibuf->x - 1);
3726 CLAMP(y, 0, ibuf->y - 1);
3727
3728 if (ibuf->float_data()) {
3729 fp = (ibuf->float_data() + (ibuf->channels) * (y * ibuf->x + x));
3730 copy_v3_v3(r_col, fp);
3731 ret = true;
3732 }
3733 else if (ibuf->byte_data()) {
3734 cp = ibuf->byte_data() + 4 * (y * ibuf->x + x);
3735 rgb_uchar_to_float(r_col, cp);
3737 ret = true;
3738 }
3739 }
3740
3741 if (r_is_data) {
3742 *r_is_data = ibuf->colorspace_is_data();
3743 }
3744
3746 return ret;
3747}
3748
3750{
3751 /* identifiers */
3752 ot->name = "Sample Color";
3753 ot->idname = "IMAGE_OT_sample";
3754 ot->description = "Use mouse to sample a color in current image";
3755
3756 /* API callbacks. */
3761
3762 /* flags */
3763 ot->flag = OPTYPE_BLOCKING;
3764
3765 PropertyRNA *prop;
3766 prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
3769}
3770
3772
3773/* -------------------------------------------------------------------- */
3776
3778{
3780 ARegion *region = CTX_wm_region(C);
3781 Scene *scene = CTX_data_scene(C);
3782 Image *ima = ED_space_image(sima);
3783
3784 int x_start = RNA_int_get(op->ptr, "xstart");
3785 int y_start = RNA_int_get(op->ptr, "ystart");
3786 int x_end = RNA_int_get(op->ptr, "xend");
3787 int y_end = RNA_int_get(op->ptr, "yend");
3788
3789 float uv1[2], uv2[2], ofs[2];
3790 ui::view2d_region_to_view(&region->v2d, x_start, y_start, &uv1[0], &uv1[1]);
3791 ui::view2d_region_to_view(&region->v2d, x_end, y_end, &uv2[0], &uv2[1]);
3792
3793 if (ima == nullptr) {
3794 return OPERATOR_CANCELLED;
3795 }
3796 /* If the image has tiles, shift the positions accordingly. */
3797 int tile = BKE_image_get_tile_from_pos(ima, uv1, uv1, ofs);
3798 sub_v2_v2(uv2, ofs);
3799
3800 void *lock;
3801 ImBuf *ibuf = ED_space_image_acquire_buffer(sima, &lock, tile, true);
3802 Histogram *hist = &sima->sample_line_hist;
3803
3804 if (ibuf == nullptr) {
3806 return OPERATOR_CANCELLED;
3807 }
3808 /* hmmmm */
3809 if (ibuf->channels < 3) {
3811 return OPERATOR_CANCELLED;
3812 }
3813
3814 copy_v2_v2(hist->co[0], uv1);
3815 copy_v2_v2(hist->co[1], uv2);
3816
3817 /* enable line drawing */
3818 hist->flag |= HISTO_FLAG_SAMPLELINE;
3819
3821
3822 /* reset y zoom */
3823 hist->ymax = 1.0f;
3824
3826
3828
3829 return OPERATOR_FINISHED;
3830}
3831
3833{
3835
3836 Histogram *hist = &sima->sample_line_hist;
3838
3839 if (!ED_space_image_has_buffer(sima)) {
3840 return OPERATOR_CANCELLED;
3841 }
3842
3843 return WM_gesture_straightline_invoke(C, op, event);
3844}
3845
3847{
3848 /* identifiers */
3849 ot->name = "Sample Line";
3850 ot->idname = "IMAGE_OT_sample_line";
3851 ot->description = "Sample a line and show it in Scope panels";
3852
3853 /* API callbacks. */
3859
3860 /* flags */
3861 ot->flag = 0; /* no undo/register since this operates on the space */
3862
3864}
3865
3867
3868/* -------------------------------------------------------------------- */
3871
3873{
3874 static const EnumPropertyItem point_items[] = {
3875 {0, "BLACK_POINT", 0, "Black Point", ""},
3876 {1, "WHITE_POINT", 0, "White Point", ""},
3877 {0, nullptr, 0, nullptr, nullptr},
3878 };
3879
3880 /* identifiers */
3881 ot->name = "Set Curves Point";
3882 ot->idname = "IMAGE_OT_curves_point_set";
3883 ot->description = "Set black point or white point for curves";
3884
3885 /* flags */
3887
3888 /* API callbacks. */
3893
3894 /* properties */
3896 ot->srna, "point", point_items, 0, "Point", "Set black point or white point for curves");
3897
3898 PropertyRNA *prop;
3899 prop = RNA_def_int(ot->srna, "size", 1, 1, 128, "Sample Size", "", 1, 64);
3902}
3903
3905
3906/* -------------------------------------------------------------------- */
3909
3911{
3912 Image *ima = image_from_context(C);
3913
3914 return (ima && ima->type == IMA_TYPE_R_RESULT);
3915}
3916
3918{
3919 Image *ima = image_from_context(C);
3920 const int direction = RNA_boolean_get(op->ptr, "reverse") ? -1 : 1;
3921
3922 if (!ED_image_slot_cycle(ima, direction)) {
3923 return OPERATOR_CANCELLED;
3924 }
3925
3927
3928 /* no undo push for browsing existing */
3929 RenderSlot *slot = BKE_image_get_renderslot(ima, ima->render_slot);
3930 if ((slot && slot->render) || ima->render_slot == ima->last_render_slot) {
3931 return OPERATOR_CANCELLED;
3932 }
3933
3934 return OPERATOR_FINISHED;
3935}
3936
3938{
3939 /* identifiers */
3940 ot->name = "Cycle Render Slot";
3941 ot->idname = "IMAGE_OT_cycle_render_slot";
3942 ot->description = "Cycle through all non-void render slots";
3943
3944 /* API callbacks. */
3947
3948 /* flags */
3949 ot->flag = OPTYPE_REGISTER;
3950
3951 RNA_def_boolean(ot->srna, "reverse", false, "Cycle in Reverse", "");
3952}
3953
3955
3956/* -------------------------------------------------------------------- */
3959
3961{
3962 Image *ima = image_from_context(C);
3964
3965 if (!BKE_image_clear_renderslot(ima, iuser, ima->render_slot)) {
3966 return OPERATOR_CANCELLED;
3967 }
3968
3970
3971 return OPERATOR_FINISHED;
3972}
3973
3975{
3976 /* identifiers */
3977 ot->name = "Clear Render Slot";
3978 ot->idname = "IMAGE_OT_clear_render_slot";
3979 ot->description = "Clear the currently selected render slot";
3980
3981 /* API callbacks. */
3984
3985 /* flags */
3986 ot->flag = OPTYPE_REGISTER;
3987}
3988
3990
3991/* -------------------------------------------------------------------- */
3994
3996{
3997 Image *ima = image_from_context(C);
3998
3999 RenderSlot *slot = BKE_image_add_renderslot(ima, nullptr);
4000 ima->render_slot = BLI_findindex(&ima->renderslots, slot);
4001
4003
4004 return OPERATOR_FINISHED;
4005}
4006
4008{
4009 /* identifiers */
4010 ot->name = "Add Render Slot";
4011 ot->idname = "IMAGE_OT_add_render_slot";
4012 ot->description = "Add a new render slot";
4013
4014 /* API callbacks. */
4017
4018 /* flags */
4019 ot->flag = OPTYPE_REGISTER;
4020}
4021
4023
4024/* -------------------------------------------------------------------- */
4027
4029{
4030 Image *ima = image_from_context(C);
4032
4033 if (!BKE_image_remove_renderslot(ima, iuser, ima->render_slot)) {
4034 return OPERATOR_CANCELLED;
4035 }
4036
4038
4039 return OPERATOR_FINISHED;
4040}
4041
4043{
4044 /* identifiers */
4045 ot->name = "Remove Render Slot";
4046 ot->idname = "IMAGE_OT_remove_render_slot";
4047 ot->description = "Remove the current render slot";
4048
4049 /* API callbacks. */
4052
4053 /* flags */
4054 ot->flag = OPTYPE_REGISTER;
4055}
4056
4058
4059/* -------------------------------------------------------------------- */
4062
4064{
4065 /* prevent changes during render */
4066 if (G.is_rendering) {
4067 return false;
4068 }
4069
4071}
4072
4074{
4075 Scene *scene = CTX_data_scene(C);
4076
4077 /* set the new frame number */
4078 scene->r.cfra = RNA_int_get(op->ptr, "frame");
4080 scene->r.subframe = 0.0f;
4081
4082 /* do updates */
4085}
4086
4088{
4089 change_frame_apply(C, op);
4090
4091 return OPERATOR_FINISHED;
4092}
4093
4094static int frame_from_event(bContext *C, const wmEvent *event)
4095{
4096 ARegion *region = CTX_wm_region(C);
4097 Scene *scene = CTX_data_scene(C);
4098 int framenr = 0;
4099
4100 if (region->regiontype == RGN_TYPE_WINDOW) {
4101 float sfra = scene->r.sfra, efra = scene->r.efra, framelen = region->winx / (efra - sfra + 1);
4102
4103 framenr = sfra + event->mval[0] / framelen;
4104 }
4105 else {
4106 float viewx, viewy;
4107
4108 ui::view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &viewx, &viewy);
4109
4110 framenr = round_fl_to_int(viewx);
4111 }
4112
4113 return framenr;
4114}
4115
4117{
4118 ARegion *region = CTX_wm_region(C);
4119
4120 if (region->regiontype == RGN_TYPE_WINDOW) {
4121 const SpaceImage *sima = CTX_wm_space_image(C);
4122 if (!ED_space_image_show_cache_and_mval_over(sima, region, event->mval)) {
4123 return OPERATOR_PASS_THROUGH;
4124 }
4125 }
4126
4127 RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
4128
4129 change_frame_apply(C, op);
4130
4131 /* add temp handler */
4133
4135}
4136
4138{
4139 switch (event->type) {
4140 case EVT_ESCKEY:
4141 return OPERATOR_FINISHED;
4142
4143 case MOUSEMOVE:
4144 RNA_int_set(op->ptr, "frame", frame_from_event(C, event));
4145 change_frame_apply(C, op);
4146 break;
4147
4148 case LEFTMOUSE:
4149 case RIGHTMOUSE:
4150 if (event->val == KM_RELEASE) {
4151 return OPERATOR_FINISHED;
4152 }
4153 break;
4154 default: {
4155 break;
4156 }
4157 }
4158
4160}
4161
4163{
4164 /* identifiers */
4165 ot->name = "Change Frame";
4166 ot->idname = "IMAGE_OT_change_frame";
4167 ot->description = "Interactively change the current frame number";
4168
4169 /* API callbacks. */
4170 ot->exec = change_frame_exec;
4173 ot->poll = change_frame_poll;
4174
4175 /* flags */
4177
4178 /* rna */
4179 RNA_def_int(ot->srna, "frame", 0, MINAFRAME, MAXFRAME, "Frame", "", MINAFRAME, MAXFRAME);
4180}
4181
4182/* Reload cached render results... */
4183/* goes over all scenes, reads render layers */
4185{
4186 Main *bmain = CTX_data_main(C);
4187 Scene *scene = CTX_data_scene(C);
4189 Image *ima;
4190
4191 ima = BKE_image_ensure_viewer(bmain, IMA_TYPE_R_RESULT, "Render Result");
4192 if (sima->image == nullptr) {
4193 ED_space_image_set(bmain, sima, ima, false);
4194 }
4195
4196 RE_ReadRenderResult(scene, scene);
4197
4199 return OPERATOR_FINISHED;
4200}
4201
4203{
4204 ot->name = "Open Cached Render";
4205 ot->idname = "IMAGE_OT_read_viewlayers";
4206 ot->description = "Read all the current scene's view layers from cache, as needed";
4207
4208 ot->poll = space_image_poll;
4210
4211 /* flags */
4212 ot->flag = 0;
4213}
4214
4216
4217/* -------------------------------------------------------------------- */
4220
4222{
4223 ARegion *region = CTX_wm_region(C);
4224 Scene *scene = CTX_data_scene(C);
4225 Render *re = RE_GetSceneRender(scene);
4227
4228 if (re == nullptr) {
4229 /* Shouldn't happen, but better be safe close to the release. */
4230 return OPERATOR_CANCELLED;
4231 }
4232
4233 /* Get information about the previous render, or current scene if no render yet. */
4234 int width, height;
4235 BKE_render_resolution(&scene->r, false, &width, &height);
4237 &scene->r;
4238
4239 /* Get rectangle from the operator. */
4240 rctf border;
4242 ui::view2d_region_to_view_rctf(&region->v2d, &border, &border);
4243
4244 /* Adjust for cropping. */
4245 if ((rd->mode & (R_BORDER | R_CROP)) == (R_BORDER | R_CROP)) {
4246 border.xmin = rd->border.xmin + border.xmin * (rd->border.xmax - rd->border.xmin);
4247 border.xmax = rd->border.xmin + border.xmax * (rd->border.xmax - rd->border.xmin);
4248 border.ymin = rd->border.ymin + border.ymin * (rd->border.ymax - rd->border.ymin);
4249 border.ymax = rd->border.ymin + border.ymax * (rd->border.ymax - rd->border.ymin);
4250 }
4251
4252 CLAMP(border.xmin, 0.0f, 1.0f);
4253 CLAMP(border.ymin, 0.0f, 1.0f);
4254 CLAMP(border.xmax, 0.0f, 1.0f);
4255 CLAMP(border.ymax, 0.0f, 1.0f);
4256
4257 /* Drawing a border surrounding the entire camera view switches off border rendering
4258 * or the border covers no pixels. */
4259 if ((border.xmin <= 0.0f && border.xmax >= 1.0f && border.ymin <= 0.0f && border.ymax >= 1.0f) ||
4260 (border.xmin == border.xmax || border.ymin == border.ymax))
4261 {
4262 scene->r.mode &= ~R_BORDER;
4263 }
4264 else {
4265 /* Snap border to pixel boundaries, so drawing a border within a pixel selects that pixel. */
4266 border.xmin = floorf(border.xmin * width) / width;
4267 border.xmax = ceilf(border.xmax * width) / width;
4268 border.ymin = floorf(border.ymin * height) / height;
4269 border.ymax = ceilf(border.ymax * height) / height;
4270
4271 /* Set border. */
4272 scene->r.border = border;
4273 scene->r.mode |= R_BORDER;
4274 }
4275
4278
4279 return OPERATOR_FINISHED;
4280}
4281
4283{
4284 /* identifiers */
4285 ot->name = "Render Region";
4286 ot->description = "Set the boundaries of the render region and enable render region";
4287 ot->idname = "IMAGE_OT_render_border";
4288
4289 /* API callbacks. */
4295
4296 /* flags */
4298
4299 /* rna */
4301}
4302
4304
4305/* -------------------------------------------------------------------- */
4308
4310{
4311 Scene *scene = CTX_data_scene(C);
4312 scene->r.mode &= ~R_BORDER;
4313 BLI_rctf_init(&scene->r.border, 0.0f, 1.0f, 0.0f, 1.0f);
4314
4317
4318 return OPERATOR_FINISHED;
4319}
4320
4322{
4323 /* identifiers */
4324 ot->name = "Clear Render Region";
4325 ot->description = "Clear the boundaries of the render region and disable render region";
4326 ot->idname = "IMAGE_OT_clear_render_border";
4327
4328 /* API callbacks. */
4331
4332 /* flags */
4334}
4335
4337
4338/* -------------------------------------------------------------------- */
4341
4342static bool do_fill_tile(PointerRNA *ptr, Image *ima, ImageTile *tile)
4343{
4344 RNA_float_get_array(ptr, "color", tile->gen_color);
4345 tile->gen_type = eImageGenType(RNA_enum_get(ptr, "generated_type"));
4346 tile->gen_x = RNA_int_get(ptr, "width");
4347 tile->gen_y = RNA_int_get(ptr, "height");
4348 bool is_float = RNA_boolean_get(ptr, "float");
4349
4350 tile->gen_flag = is_float ? IMA_GEN_FLOAT : eImage_GenFlag{};
4351 tile->gen_depth = RNA_boolean_get(ptr, "alpha") ? 32 : 24;
4352
4353 return BKE_image_fill_tile(ima, tile);
4354}
4355
4356static void draw_fill_tile(PointerRNA *ptr, ui::Layout &layout)
4357{
4358 layout.use_property_split_set(true);
4359 layout.use_property_decorate_set(false);
4360
4361 ui::Layout &col = layout.column(false);
4362 col.prop(ptr, "color", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4363 col.prop(ptr, "width", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4364 col.prop(ptr, "height", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4365 col.prop(ptr, "alpha", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4366 col.prop(ptr, "generated_type", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4367 col.prop(ptr, "float", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4368}
4369
4371{
4372 ImageUser iuser;
4373 BKE_imageuser_default(&iuser);
4374 if (tile != nullptr) {
4375 iuser.tile = tile->tile_number;
4376 }
4377
4378 /* Acquire ibuf to get the default values.
4379 * If the specified tile has no ibuf, try acquiring the main tile instead
4380 * (unless the specified tile already was the first tile). */
4381 ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
4382 if (ibuf == nullptr && (tile != nullptr) && (tile != ima->tiles.first_)) {
4383 ibuf = BKE_image_acquire_ibuf(ima, nullptr, nullptr);
4384 }
4385
4386 if (ibuf != nullptr) {
4387 /* Initialize properties from reference tile. */
4388 RNA_int_set(ptr, "width", ibuf->x);
4389 RNA_int_set(ptr, "height", ibuf->y);
4390 RNA_boolean_set(ptr, "float", ibuf->float_data() != nullptr);
4391 RNA_boolean_set(ptr, "alpha", ibuf->can_contain_alpha());
4392
4393 BKE_image_release_ibuf(ima, ibuf, nullptr);
4394 }
4395}
4396
4398{
4399 PropertyRNA *prop;
4400 static const float default_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
4401 prop = RNA_def_float_color(
4402 srna, "color", 4, nullptr, 0.0f, FLT_MAX, "Color", "Default fill color", 0.0f, 1.0f);
4404 RNA_def_property_float_array_default(prop, default_color);
4405 RNA_def_enum(srna,
4406 "generated_type",
4409 "Generated Type",
4410 "Fill the image with a grid for UV map testing");
4411 prop = RNA_def_int(srna, "width", 1024, 1, INT_MAX, "Width", "Image width", 1, 16384);
4413 prop = RNA_def_int(srna, "height", 1024, 1, INT_MAX, "Height", "Image height", 1, 16384);
4415
4416 /* Only needed when filling the first tile. */
4418 srna, "float", false, "32-bit Float", "Create image with 32-bit floating-point bit depth");
4419 RNA_def_boolean(srna, "alpha", true, "Alpha", "Create an image with an alpha channel");
4420}
4421
4423{
4424 Image *ima = CTX_data_edit_image(C);
4425
4426 return (ima != nullptr && ima->source == IMA_SRC_TILED && BKE_image_has_ibuf(ima, nullptr));
4427}
4428
4430{
4431 Image *ima = CTX_data_edit_image(C);
4432
4433 int start_tile = RNA_int_get(op->ptr, "number");
4434 int end_tile = start_tile + RNA_int_get(op->ptr, "count") - 1;
4435
4436 if (start_tile < 1001 || end_tile > IMA_UDIM_MAX) {
4437 BKE_report(op->reports, RPT_ERROR, "Invalid UDIM index range was specified");
4438 return OPERATOR_CANCELLED;
4439 }
4440
4441 bool fill_tile = RNA_boolean_get(op->ptr, "fill");
4442 std::string label = RNA_string_get(op->ptr, "label");
4443
4444 /* BKE_image_add_tile assumes a pre-sorted list of tiles. */
4446
4447 ImageTile *last_tile_created = nullptr;
4448 for (int tile_number = start_tile; tile_number <= end_tile; tile_number++) {
4449 ImageTile *tile = BKE_image_add_tile(ima, tile_number, label.c_str());
4450
4451 if (tile != nullptr) {
4452 if (fill_tile) {
4453 do_fill_tile(op->ptr, ima, tile);
4454 }
4455
4456 last_tile_created = tile;
4457 }
4458 }
4459
4460 if (!last_tile_created) {
4461 BKE_report(op->reports, RPT_WARNING, "No UDIM tiles were created");
4462 return OPERATOR_CANCELLED;
4463 }
4464
4465 ima->active_tile_index = BLI_findindex(&ima->tiles, last_tile_created);
4466
4468 return OPERATOR_FINISHED;
4469}
4470
4472{
4473 Image *ima = CTX_data_edit_image(C);
4474
4475 /* Find the first gap in tile numbers or the number after the last if
4476 * no gap exists. */
4477 int next_number = 0;
4478 for (ImageTile &tile : ima->tiles) {
4479 next_number = tile.tile_number + 1;
4480 if (tile.next == nullptr || tile.next->tile_number > next_number) {
4481 break;
4482 }
4483 }
4484
4485 ImageTile *tile = static_cast<ImageTile *>(BLI_findlink(&ima->tiles, ima->active_tile_index));
4486 tile_fill_init(op->ptr, ima, tile);
4487
4488 RNA_int_set(op->ptr, "number", next_number);
4489 RNA_int_set(op->ptr, "count", 1);
4490 RNA_string_set(op->ptr, "label", "");
4491
4493 op,
4494 300,
4495 IFACE_("Add Tile to Image"),
4497}
4498
4499static void tile_add_draw(bContext * /*C*/, wmOperator *op)
4500{
4501 ui::Layout &layout = *op->layout;
4502
4503 layout.use_property_split_set(true);
4504 layout.use_property_decorate_set(false);
4505
4506 ui::Layout &col = layout.column(false);
4507 col.prop(op->ptr, "number", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4508 col.prop(op->ptr, "count", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4509 col.prop(op->ptr, "label", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4510 layout.prop(op->ptr, "fill", UI_ITEM_NONE, std::nullopt, ICON_NONE);
4511
4512 if (RNA_boolean_get(op->ptr, "fill")) {
4513 draw_fill_tile(op->ptr, layout);
4514 }
4515}
4516
4518{
4519 PropertyRNA *prop;
4520
4521 /* identifiers */
4522 ot->name = "Add Tile";
4523 ot->description = "Adds a tile to the image";
4524 ot->idname = "IMAGE_OT_tile_add";
4525
4526 /* API callbacks. */
4527 ot->poll = tile_add_poll;
4528 ot->exec = tile_add_exec;
4529 ot->invoke = tile_add_invoke;
4530 ot->ui = tile_add_draw;
4531
4532 /* flags */
4534
4535 RNA_def_int(ot->srna,
4536 "number",
4537 1002,
4538 1001,
4540 "Number",
4541 "UDIM number of the tile",
4542 1001,
4543 1099);
4544 RNA_def_int(ot->srna, "count", 1, 1, INT_MAX, "Count", "How many tiles to add", 1, 1000);
4545 RNA_def_string(ot->srna, "label", nullptr, 0, "Label", "Optional tile label");
4546 prop = RNA_def_boolean(ot->srna, "fill", true, "Fill", "Fill new tile with a generated image");
4548 def_fill_tile(ot->srna);
4549}
4550
4552
4553/* -------------------------------------------------------------------- */
4556
4558{
4559 Image *ima = CTX_data_edit_image(C);
4560
4561 return (ima != nullptr && ima->source == IMA_SRC_TILED && !ima->tiles.is_single());
4562}
4563
4565{
4566 Image *ima = CTX_data_edit_image(C);
4567
4568 ImageTile *tile = static_cast<ImageTile *>(BLI_findlink(&ima->tiles, ima->active_tile_index));
4569 if (!BKE_image_remove_tile(ima, tile)) {
4570 return OPERATOR_CANCELLED;
4571 }
4572
4573 /* Ensure that the active index is valid. */
4574 ima->active_tile_index = min_ii(ima->active_tile_index, ima->tiles.count() - 1);
4575
4577
4578 return OPERATOR_FINISHED;
4579}
4580
4582{
4583 /* identifiers */
4584 ot->name = "Remove Tile";
4585 ot->description = "Removes a tile from the image";
4586 ot->idname = "IMAGE_OT_tile_remove";
4587
4588 /* API callbacks. */
4589 ot->poll = tile_remove_poll;
4590 ot->exec = tile_remove_exec;
4591
4592 /* flags */
4594}
4595
4597
4598/* -------------------------------------------------------------------- */
4601
4603{
4604 Image *ima = CTX_data_edit_image(C);
4605
4606 if (ima != nullptr && ima->source == IMA_SRC_TILED) {
4607 /* Filling secondary tiles is only allowed if the primary tile exists. */
4608 return (ima->active_tile_index == 0) || BKE_image_has_ibuf(ima, nullptr);
4609 }
4610 return false;
4611}
4612
4614{
4615 Image *ima = CTX_data_edit_image(C);
4616
4617 ImageTile *tile = static_cast<ImageTile *>(BLI_findlink(&ima->tiles, ima->active_tile_index));
4618 if (!do_fill_tile(op->ptr, ima, tile)) {
4619 return OPERATOR_CANCELLED;
4620 }
4621
4623
4624 return OPERATOR_FINISHED;
4625}
4626
4628{
4629 tile_fill_init(op->ptr, CTX_data_edit_image(C), nullptr);
4630
4632 op,
4633 300,
4634 IFACE_("Fill Tile With Generated Image"),
4636}
4637
4638static void tile_fill_draw(bContext * /*C*/, wmOperator *op)
4639{
4640 draw_fill_tile(op->ptr, *op->layout);
4641}
4642
4644{
4645 /* identifiers */
4646 ot->name = "Fill Tile";
4647 ot->description = "Fill the current tile with a generated image";
4648 ot->idname = "IMAGE_OT_tile_fill";
4649
4650 /* API callbacks. */
4651 ot->poll = tile_fill_poll;
4652 ot->exec = tile_fill_exec;
4654 ot->ui = tile_fill_draw;
4655
4656 /* flags */
4658
4659 def_fill_tile(ot->srna);
4660}
4661
4663
4664} // namespace blender
#define IMA_UDIM_MAX
Definition BKE_image.hh:56
#define IMA_SIGNAL_SRC_CHANGE
Definition BKE_image.hh:181
#define IMA_SIGNAL_USER_NEW_IMAGE
Definition BKE_image.hh:183
#define IMA_SIGNAL_RELOAD
Definition BKE_image.hh:178
File and directory operations.
#define FILE_MAX
#define STR_ELEM(...)
#define SNPRINTF(dst, format,...)
Platform independent time functions.
#define RPT_(msgid)
#define BLT_I18NCONTEXT_ID_IMAGE
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
#define DATA_(msgid)
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define ID_BLEND_PATH(_bmain, _id)
Definition DNA_ID.h:688
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
Object is a sort of wrapper for general info.
#define MINAFRAME
#define MAXFRAME
#define FRAMENUMBER_MIN_CLAMP(cfra)
#define NDOF_PIXELS_PER_SECOND
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
#define ND_DRAW
Definition WM_types.hh:502
#define ND_RENDER_OPTIONS
Definition WM_types.hh:454
#define NC_SCENE
Definition WM_types.hh:391
#define NA_ADDED
Definition WM_types.hh:636
#define ND_SPACE_IMAGE
Definition WM_types.hh:565
#define NA_EDITED
Definition WM_types.hh:634
#define NC_IMAGE
Definition WM_types.hh:397
#define ND_FRAME
Definition WM_types.hh:453
#define NC_SPACE
Definition WM_types.hh:405
volatile int lock
#define CLAMP(a, b, c)
#define CLAMP_MAX(a, c)
#define POINTER_AS_INT(i)
#define ELEM(...)
#define STREQ(a, b)
btScalar max
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
bool contains_as(const ForwardKey &key) const
Definition BLI_set.hh:314
bool add(const Key &key)
Definition BLI_set.hh:248
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
Definition area.cc:1097
#define powf(x, y)
#define roundf(x)
#define offsetof(t, d)
#define str(s)
#define SHRT_MAX
#define FLT_MAX
#define INT_MAX
#define round
constexpr T degrees(T) RET
const ccl_global KernelWorkTile * tile
void view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1651
void context_active_but_prop_get_templateID(const bContext *C, PointerRNA *r_ptr, PropertyRNA **r_prop)
void view2d_region_to_view_rctf(const View2D *v2d, const rctf *rect_src, rctf *rect_dst) ATTR_NONNULL()
Definition view2d.cc:1657
BMesh Iterators.
bool BKE_image_is_multiview(const Image *ima)
int BKE_image_get_tile_from_pos(Image *ima, const float uv[2], float r_uv[2], float r_ofs[2])
MINLINE float min_ff(float a, float b)
static ImageNewData * image_new_init(bContext *C, wmOperator *op)
void WM_main_add_notifier(uint type, void *reference)
void BKE_image_user_frame_calc(Image *ima, ImageUser *iuser, int cfra)
static Image * image_from_context(const bContext *C)
Definition image_ops.cc:190
bool IMB_rotate_orthogonal(ImBuf *ibuf, int degrees)
static bool image_from_context_editable_has_data_poll_active_tile(bContext *C)
Definition image_ops.cc:262
UserDef U
Definition blender.cc:58
void RNA_float_set_array(PointerRNA *ptr, const char *name, const float *values)
void IMB_cacheIter_step(ImBufCacheIter *iter)
Definition cache.cc:597
static wmOperatorStatus image_view_zoom_ratio_exec(bContext *C, wmOperator *op)
void IMAGE_OT_rotate_orthogonal(wmOperatorType *ot)
static bool image_should_be_saved_when_modified(Image *ima)
static void sima_zoom_set_factor(SpaceImage *sima, ARegion *region, float zoomfac, const float location[2], const bool zoom_to_pos)
Definition image_ops.cc:153
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
bool ED_operator_uvedit(bContext *C)
static void draw_fill_tile(PointerRNA *ptr, ui::Layout &layout)
ScrArea * CTX_wm_area(const bContext *C)
ImBuf * WM_clipboard_image_get()
static bool image_save_as_check(bContext *C, wmOperator *op)
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
static wmOperatorStatus image_sample_line_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus image_view_pan_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition image_ops.cc:488
static wmOperatorStatus image_view_all_exec(bContext *C, wmOperator *op)
Definition image_ops.cc:920
static bool tile_remove_poll(bContext *C)
bool ED_image_slot_cycle(Image *image, int direction)
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 IMAGE_OT_tile_remove(wmOperatorType *ot)
@ IMA_TYPE_MULTILAYER
void IMAGE_OT_view_pan(wmOperatorType *ot)
Definition image_ops.cc:519
@ RPT_WARNING
Definition BKE_report.hh:40
void uiTemplateImageFormatViews(ui::Layout *layout, PointerRNA *imfptr, PointerRNA *ptr)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static wmOperatorStatus render_border_exec(bContext *C, wmOperator *op)
void BKE_image_format_set(ImageFormatData *imf, ID *owner_id, const char imtype)
bool BKE_image_clear_renderslot(Image *ima, ImageUser *iuser, int slot)
static bool image_pack_test(Image *ima, const char **r_error_message)
bool ED_space_image_show_cache_and_mval_over(const SpaceImage *sima, ARegion *region, const int mval[2])
static wmOperatorStatus tile_add_exec(bContext *C, wmOperator *op)
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
void IMAGE_OT_view_zoom_border(wmOperatorType *ot)
static wmOperatorStatus image_view_zoom_out_exec(bContext *C, wmOperator *op)
void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr_value, ReportList *reports)
wmOperatorStatus WM_gesture_box_invoke(bContext *C, wmOperator *op, const wmEvent *event)
MINLINE void copy_v3_v3(float r[3], const float a[3])
unsigned int uint
Definition BKE_text.h:55
static wmOperatorStatus image_view_zoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition image_ops.cc:755
void ED_space_image_get_aspect(SpaceImage *sima, float *r_aspx, float *r_aspy)
void IMAGE_OT_replace(wmOperatorType *ot)
bool BLI_path_abs(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1
void IMAGE_OT_read_viewlayers(wmOperatorType *ot)
static void sima_zoom_set_from_bounds(SpaceImage *sima, ARegion *region, const rctf *bounds)
Definition image_ops.cc:165
void unpack_menu(bContext *C, const char *opname, const char *id_name, const char *abs_name, const char *folder, PackedFile *pf)
Definition ed_util.cc:367
static void image_filesel(bContext *C, wmOperator *op, const char *path)
void BKE_reports_free(ReportList *reports)
Definition report.cc:106
void ED_imapaint_clear_partial_redraw()
bool ED_space_image_check_show_maskedit(SpaceImage *sima, Object *obedit)
static void tile_add_draw(bContext *, wmOperator *op)
static void image_view_zoom_init(bContext *C, wmOperator *op, const wmEvent *event)
Definition image_ops.cc:577
MINLINE int round_fl_to_int(float a)
static wmOperatorStatus view_center_cursor_exec(bContext *C, wmOperator *)
Definition clip_ops.cc:1001
void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
int BKE_icon_id_ensure(ID *id)
Definition icons.cc:279
void IMAGE_OT_clipboard_copy(wmOperatorType *ot)
static void image_open_draw(bContext *, wmOperator *op)
PointerRNA RNA_id_pointer_create(ID *id)
wmOperatorStatus WM_gesture_straightline_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus tile_fill_exec(bContext *C, wmOperator *op)
MINLINE void mul_v2_fl(float r[2], float f)
PropertyRNA * RNA_def_float_color(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 ED_image_undo_push_end()
void WM_operator_properties_free(PointerRNA *ptr)
void IMAGE_OT_sample(wmOperatorType *ot)
bool WM_clipboard_image_available()
const char * RNA_property_identifier(const PropertyRNA *prop)
MINLINE void copy_v2_v2(float r[2], const float a[2])
static void image_view_all(SpaceImage *sima, ARegion *region, wmOperator *op)
Definition image_ops.cc:283
static wmOperatorStatus image_view_pan_exec(bContext *C, wmOperator *op)
Definition image_ops.cc:450
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
static void image_view_pan_exit(bContext *C, wmOperator *op, bool cancel)
Definition image_ops.cc:433
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:91
bool BLI_exists(const char *path) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition storage.cc:404
static wmOperatorStatus image_remove_render_slot_exec(bContext *C, wmOperator *)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static wmOperatorStatus image_match_len_exec(bContext *C, wmOperator *)
bool BKE_image_has_filepath(const Image *ima)
static wmOperatorStatus image_view_pan_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition image_ops.cc:470
void IMB_mark_dirty(ImBuf *ibuf)
wmOperatorStatus WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *event)
void WM_cursor_modal_set(wmWindow *win, int val)
ImBuf * ED_space_image_acquire_buffer(SpaceImage *sima, void **r_lock, int tile, const bool ensure_host_buffer)
void IMAGE_OT_view_all(wmOperatorType *ot)
Definition image_ops.cc:936
void IMAGE_OT_clear_render_border(wmOperatorType *ot)
void ED_space_image_get_size(SpaceImage *sima, int *r_width, int *r_height)
static wmOperatorStatus image_new_invoke(bContext *C, wmOperator *op, const wmEvent *)
Image * CTX_data_edit_image(const bContext *C)
bool BKE_image_fill_tile(Image *ima, ImageTile *tile)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void IMAGE_OT_invert(wmOperatorType *ot)
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)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
static Image * image_open_single(Main *bmain, Library *owner_library, wmOperator *op, const ImageFrameRange *range, const bool use_multiview)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:615
void IMAGE_OT_view_center_cursor(wmOperatorType *ot)
void WM_operator_properties_border(wmOperatorType *ot)
@ HISTO_FLAG_SAMPLELINE
ImBuf * IMB_cacheIter_getImBuf(ImBufCacheIter *iter)
Definition cache.cc:602
static wmOperatorStatus image_view_zoom_out_invoke(bContext *C, wmOperator *op, const wmEvent *event)
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
static bool image_save_all_modified_poll(bContext *C)
static wmOperatorStatus image_replace_invoke(bContext *C, wmOperator *op, const wmEvent *)
int RNA_int_get(PointerRNA *ptr, const char *name)
wmWindow * CTX_wm_window(const bContext *C)
void BKE_image_user_file_path(const ImageUser *iuser, const Image *ima, char *filepath)
bool ED_uvedit_minmax_multi(const Scene *scene, Span< Object * > objects_edit, float r_min[2], float r_max[2])
static wmOperatorStatus image_view_zoom_in_exec(bContext *C, wmOperator *op)
bool ED_space_image_region_cursor_poll(bContext *C)
static wmOperatorStatus image_invert_exec(bContext *C, wmOperator *op)
MINLINE int max_ii(int a, int b)
static wmOperatorStatus image_scale_invoke(bContext *C, wmOperator *op, const wmEvent *)
void IMAGE_OT_view_selected(wmOperatorType *ot)
static ImageUser image_user_from_context_and_active_tile(const bContext *C, Image *ima)
Definition image_ops.cc:221
bool BKE_image_save_options_init(ImageSaveOptions *opts, Main *bmain, Scene *scene, Image *ima, ImageUser *iuser, bool guess_path, bool save_as_render)
Definition image_save.cc:51
void ED_undo_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:553
ImageTile * BKE_image_add_tile(Image *ima, int tile_number, const char *label)
void BLI_rctf_scale(rctf *rect, float scale)
Definition rct.cc:691
bool ED_space_image_get_position(SpaceImage *sima, ARegion *region, const int mval[2], float r_fpos[2])
static bool image_file_format_writable(Image *ima, ImageUser *iuser)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
void ED_space_image_release_buffer(SpaceImage *sima, ImBuf *ibuf, void *lock)
void IMAGE_OT_view_cursor_center(wmOperatorType *ot)
Definition image_ops.cc:982
static bool image_save_as_draw_check_prop(PointerRNA *ptr, PropertyRNA *prop, void *user_data)
static wmOperatorStatus image_open_exec(bContext *C, wmOperator *op)
void ED_space_image_set(Main *bmain, SpaceImage *sima, Image *ima, bool automatic)
Definition image_edit.cc:49
void WM_operator_properties_filesel(wmOperatorType *ot, const int filter, const short type, const eFileSel_Action action, const eFileSel_Flag flag, const short display, const short sort)
static void tile_fill_init(PointerRNA *ptr, Image *ima, ImageTile *tile)
static wmOperatorStatus clear_render_border_exec(bContext *C, wmOperator *)
ViewLayer * CTX_data_view_layer(const bContext *C)
static wmOperatorStatus image_save_as_exec(bContext *C, wmOperator *op)
void BKE_render_resolution(const RenderData *r, const bool use_crop, int *r_width, int *r_height)
Definition scene.cc:3168
void RNA_def_property_float_array_default(PropertyRNA *prop, const float *array)
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)
static bool image_from_context_has_data_poll(bContext *C)
Definition image_ops.cc:243
bool ED_image_save_all_modified(const bContext *C, ReportList *reports)
static wmOperatorStatus image_save_sequence_exec(bContext *C, wmOperator *op)
void WM_operator_properties_use_cursor_init(wmOperatorType *ot)
static wmOperatorStatus image_clipboard_paste_exec(bContext *C, wmOperator *op)
Global G
Definition blender.cc:57
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
static wmOperatorStatus image_new_exec(bContext *C, wmOperator *op)
void RNA_property_int_set_array(PointerRNA *ptr, PropertyRNA *prop, const int *values)
static ImageUser * image_user_from_context(const bContext *C)
Definition image_ops.cc:205
static wmOperatorStatus image_open_invoke(bContext *C, wmOperator *op, const wmEvent *)
bool BKE_image_is_dirty_writable(Image *image, bool *r_is_writable)
bool IMB_save_image(ImBuf *ibuf, const char *filepath, ImBufFlags flags)
Definition writeimage.cc:40
void WM_operator_properties_border_to_rctf(wmOperator *op, rctf *r_rect)
void ED_preview_kill_jobs(wmWindowManager *wm, Main *bmain)
RenderSlot * BKE_image_add_renderslot(Image *ima, const char *name)
void IMAGE_OT_clipboard_paste(wmOperatorType *ot)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:541
RenderData * RE_engine_get_render_data(Render *re)
static wmOperatorStatus image_file_browse_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void image_new_draw(bContext *, wmOperator *op)
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:593
Render * RE_GetSceneRender(const Scene *scene)
void IMB_colormanagement_colorspace_to_scene_linear_v3(float pixel[3], const ColorSpace *colorspace)
@ G_FILE_AUTOPACK
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
Definition BLI_rect.hh:207
ImBuf * BKE_image_acquire_ibuf_gpu(Image *ima, ImageUser *iuser, void **r_lock, bool *r_load_failed=nullptr, bool cached_only=false)
static wmOperatorStatus image_save_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
static wmOperatorStatus image_save_exec(bContext *C, wmOperator *op)
void IMAGE_OT_sample_line(wmOperatorType *ot)
static wmOperatorStatus tile_add_invoke(bContext *C, wmOperator *op, const wmEvent *)
void void BLI_path_split_dir_part(const char *filepath, char *dir, size_t dir_maxncpy) ATTR_NONNULL(1
void IMAGE_OT_flip(wmOperatorType *ot)
void IMAGE_OT_cycle_render_slot(wmOperatorType *ot)
bool BKE_image_remove_tile(Image *ima, ImageTile *tile)
void IMB_freeImBuf(ImBuf *ibuf)
void BKE_icon_changed(int icon_id)
Definition icons.cc:215
static ImageSaveData * image_save_as_init(bContext *C, wmOperator *op)
void IMAGE_OT_open(wmOperatorType *ot)
bool space_image_poll(bContext *C)
Definition image_ops.cc:354
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
ListBaseT< ImageFrameRange > ED_image_filesel_detect_sequences(StringRefNull blendfile_path, StringRefNull root_path, wmOperator *op, bool detect_udim)
ImBufCacheIter * IMB_cacheIter_new(ImBufCache *cache)
Definition cache.cc:577
static wmOperatorStatus image_unpack_invoke(bContext *C, wmOperator *op, const wmEvent *)
unsigned char uchar
Definition BKE_text.h:58
static bool image_has_valid_path(Image *ima)
static wmOperatorStatus image_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *)
void ED_imbuf_sample_cancel(bContext *C, wmOperator *op)
static wmOperatorStatus image_flip_exec(bContext *C, wmOperator *op)
void DEG_id_tag_update(ID *id, unsigned int flags)
void RNA_property_int_get_array(PointerRNA *ptr, PropertyRNA *prop, int *values)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
int BKE_packedfile_unpack_image(Main *bmain, ReportList *reports, Image *ima, enum ePF_FileStatus how)
BMesh const char void * data
bool ED_maskedit_poll(bContext *C)
Definition mask_edit.cc:29
@ WM_FILESEL_DIRECTORY
Definition WM_api.hh:1330
@ WM_FILESEL_RELPATH
Definition WM_api.hh:1329
@ WM_FILESEL_SHOW_PROPS
Definition WM_api.hh:1335
@ WM_FILESEL_FILES
Definition WM_api.hh:1333
@ WM_FILESEL_FILEPATH
Definition WM_api.hh:1332
static void image_save_as_free(wmOperator *op)
void BKE_image_free_packedfiles(Image *image)
void IMAGE_OT_add_render_slot(wmOperatorType *ot)
static void image_view_pan_init(bContext *C, wmOperator *op, const wmEvent *event)
Definition image_ops.cc:410
BLI_INLINE float BLI_rctf_size_y(const struct rctf *rct)
Definition BLI_rect.hh:215
wmWindowManager * CTX_wm_manager(const bContext *C)
static float frame_from_event(bContext *C, const wmEvent *event)
Definition anim_ops.cc:621
Object * CTX_data_edit_object(const bContext *C)
void WM_operator_properties_gesture_straightline(wmOperatorType *ot, int cursor)
void BKE_image_packfiles(ReportList *reports, Image *ima, const char *basepath)
static bool do_fill_tile(PointerRNA *ptr, Image *ima, ImageTile *tile)
void ED_image_internal_autosave_flush(const Main *bmain)
static bool image_open_draw_check_prop(PointerRNA *, PropertyRNA *prop, void *)
static wmOperatorStatus change_frame_exec(bContext *C, wmOperator *op)
Definition anim_ops.cc:611
RenderSlot * BKE_image_get_renderslot(Image *ima, int index)
void IMAGE_OT_file_browse(wmOperatorType *ot)
bool WM_clipboard_image_set_byte_buffer(ImBuf *ibuf)
void RNA_def_property_subtype(PropertyRNA *prop, PropertySubType subtype)
void WM_cursor_modal_restore(wmWindow *win)
static void image_zoom_apply(ViewZoomData *vpd, wmOperator *op, const int x, const int y, const short viewzoom, const short zoom_invert, const bool zoom_to_pos, const bool snap, const bool precision)
Definition image_ops.cc:688
MINLINE float power_of_2(float f)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
void ED_image_undo_push_begin_with_image_all_udims(const char *name, Image *image, ImageUser *iuser)
void WM_operator_properties_gesture_box_zoom(wmOperatorType *ot)
void IMAGE_OT_save_as(wmOperatorType *ot)
static wmOperatorStatus change_frame_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition anim_ops.cc:696
bool ED_space_image_has_buffer(SpaceImage *sima)
@ VIEW_CONFIRM
Definition image_ops.cc:652
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
static bool image_pack_poll(bContext *C)
void IMB_partial_update_mark_full(ImBuf *ibuf)
const EnumPropertyItem rna_enum_unpack_method_items[]
bool BLI_file_is_writable(const char *filepath) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition fileops_c.cc:293
static void image_view_zoom_exit(bContext *C, wmOperator *op, bool cancel)
Definition image_ops.cc:614
Image * BKE_image_add_from_imbuf(Main *bmain, ImBuf *ibuf, const char *name)
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
static bool image_view_selected_poll(bContext *C)
void BKE_image_free_views(Image *image)
wmOperatorStatus WM_operator_name_call(bContext *C, const char *opstring, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
static wmOperatorStatus image_file_browse_exec(bContext *C, wmOperator *op)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void uiTemplateImageSettings(ui::Layout *layout, bContext *C, PointerRNA *imfptr, bool color_management, const char *panel_idname=nullptr)
void IMAGE_OT_tile_add(wmOperatorType *ot)
@ GEN_CONTEXT_PAINT_CANVAS
@ GEN_CONTEXT_PAINT_STENCIL
@ GEN_CONTEXT_NONE
static bool image_save_as_poll(bContext *C)
bool IMB_cacheIter_done(ImBufCacheIter *iter)
Definition cache.cc:592
static bool tile_fill_poll(bContext *C)
MINLINE void copy_v4_v4_uchar(unsigned char r[4], const unsigned char a[4])
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
Definition BLI_rect.hh:203
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
static wmOperatorStatus change_frame_modal(bContext *C, wmOperator *op, const wmEvent *event)
Definition anim_ops.cc:790
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
void BKE_image_ensure_tile_token(char *filepath, size_t filepath_maxncpy)
wmOperatorStatus ED_imbuf_sample_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus image_unpack_exec(bContext *C, wmOperator *op)
Image * BKE_image_load_exists_in_lib(Main *bmain, std::optional< Library * > owner_library, const char *filepath, bool check_open=true, bool *r_exists=nullptr)
void BKE_image_format_free(ImageFormatData *imf)
void BKE_image_format_init_for_write(ImageFormatData *imf, const Scene *scene_src, const ImageFormatData *imf_src, const bool allow_video=false)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
ImBuf * IMB_colormanagement_imbuf_for_write(ImBuf *ibuf, bool save_as_render, bool allocate_result, const ImageFormatData *image_format)
static wmOperatorStatus image_view_zoom_in_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void BKE_image_init_imageuser(Image *ima, ImageUser *iuser)
static void sima_zoom_set(SpaceImage *sima, ARegion *region, float zoom, const float location[2], const bool zoom_to_pos)
Definition image_ops.cc:100
static void image_new_cancel(bContext *, wmOperator *op)
bool BKE_image_autosave_memorypack(Image *ima)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
static void image_operator_prop_allow_tokens(wmOperatorType *ot)
static wmOperatorStatus image_view_zoom_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Definition image_ops.cc:655
static bool image_should_be_saved(Image *ima, bool *r_is_format_writable)
ImBuf * BKE_image_acquire_ibuf(Image *ima, ImageUser *iuser, void **r_lock)
void IMAGE_OT_tile_fill(wmOperatorType *ot)
static wmOperatorStatus tile_fill_invoke(bContext *C, wmOperator *op, const wmEvent *)
static wmOperatorStatus image_add_render_slot_exec(bContext *C, wmOperator *)
void IMAGE_OT_remove_render_slot(wmOperatorType *ot)
SpaceImage * CTX_wm_space_image(const bContext *C)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void IMAGE_OT_save_all_modified(wmOperatorType *ot)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
wmOperatorStatus WM_gesture_box_modal(bContext *C, wmOperator *op, const wmEvent *event)
static wmOperatorStatus image_cycle_render_slot_exec(bContext *C, wmOperator *op)
void IMAGE_OT_view_zoom_ratio(wmOperatorType *ot)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
static wmOperatorStatus tile_remove_exec(bContext *C, wmOperator *)
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 IMAGE_OT_unpack(wmOperatorType *ot)
void IMAGE_OT_view_zoom(wmOperatorType *ot)
Definition image_ops.cc:818
static bool image_clipboard_copy_poll(bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
@ FILE_SAVE
Definition WM_api.hh:1342
@ FILE_OPENFILE
Definition WM_api.hh:1341
@ WM_CURSOR_EDIT
Definition wm_cursors.hh:21
@ WM_CURSOR_NSEW_SCROLL
Definition wm_cursors.hh:54
static wmOperatorStatus image_view_selected_exec(bContext *C, wmOperator *)
void IMAGE_OT_curves_point_set(wmOperatorType *ot)
static wmOperatorStatus image_replace_exec(bContext *C, wmOperator *op)
Main * CTX_data_main(const bContext *C)
static void image_save_as_cancel(bContext *, wmOperator *op)
void StructOrFunctionRNA
void IMB_byte_from_float(ImBuf *ibuf)
BLI_INLINE float BLI_rctf_size_x(const struct rctf *rct)
Definition BLI_rect.hh:211
static wmOperatorStatus view_cursor_center_exec(bContext *C, wmOperator *op)
Definition image_ops.cc:963
bool BLI_path_extension_check_array(const char *path, const char **ext_array) ATTR_NONNULL(1
static bool image_save_poll(bContext *C)
static wmOperatorStatus image_save_all_modified_exec(bContext *C, wmOperator *op)
bool BLI_path_is_rel(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
static void image_view_zoom_cancel(bContext *C, wmOperator *op)
Definition image_ops.cc:813
MINLINE float max_ff(float a, float b)
static wmOperatorStatus image_view_zoom_exec(bContext *C, wmOperator *op)
Definition image_ops.cc:637
static wmOperatorStatus image_pack_exec(bContext *C, wmOperator *op)
Image * BKE_image_ensure_viewer(Main *bmain, int type, const char *name)
BLI_INLINE float BLI_rctf_cent_y(const struct rctf *rct)
Definition BLI_rect.hh:198
void BKE_image_save_options_free(ImageSaveOptions *opts)
static bool save_image_op(Main *bmain, Image *ima, ImageUser *iuser, wmOperator *op, const ImageSaveOptions *opts)
static wmOperatorStatus image_clear_render_slot_exec(bContext *C, wmOperator *)
static bool image_cycle_render_slot_poll(bContext *C)
static wmOperatorStatus image_view_zoom_border_exec(bContext *C, wmOperator *op)
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1143
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_FRAME_CHANGE
Definition DNA_ID.h:1125
@ ID_RECALC_EDITORS
Definition DNA_ID.h:1111
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
@ PROP_HIDDEN
Definition RNA_types.hh:408
void IMAGE_OT_render_border(wmOperatorType *ot)
bool BKE_image_has_ibuf(Image *ima, ImageUser *iuser)
void IMAGE_OT_change_frame(wmOperatorType *ot)
static wmOperatorStatus image_scale_exec(bContext *C, wmOperator *op)
void WM_gesture_box_cancel(bContext *C, wmOperator *op)
void IMAGE_OT_clear_render_slot(wmOperatorType *ot)
void IMAGE_OT_reload(wmOperatorType *ot)
@ KM_RELEASE
Definition WM_types.hh:325
void BKE_id_move_to_same_lib(Main &bmain, ID &id, const ID &owner_id)
Definition lib_id.cc:953
bool ED_imbuf_sample_poll(bContext *C)
MINLINE void rgb_uchar_to_float(float r_col[3], const unsigned char col_ub[3])
static wmOperatorStatus image_read_viewlayers_exec(bContext *C, wmOperator *)
double BLI_time_now_seconds()
Definition time.cc:30
static bool space_image_main_area_not_uv_brush_poll(bContext *C)
Definition image_ops.cc:377
static void image_open_init(bContext *C, wmOperator *op)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
Scene * CTX_data_scene(const bContext *C)
static wmOperatorStatus image_reload_exec(bContext *C, wmOperator *)
void WM_event_timer_remove(wmWindowManager *wm, wmWindow *, wmTimer *timer)
void BKE_mask_coord_to_image(Image *image, ImageUser *iuser, float r_co[2], const float co[2])
MINLINE void copy_v4_v4(float r[4], const float a[4])
MINLINE void sub_v2_v2(float r[2], const float a[2])
void BKE_image_save_options_update(ImageSaveOptions *opts, const Image *image)
bool ED_mask_selected_minmax(const bContext *C, float min[2], float max[2], bool handles_as_knot, bool handles_as_knot_selected_only)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_LOCK_BYPASS
Definition WM_types.hh:213
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_GRAB_CURSOR_XY
Definition WM_types.hh:196
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
void BKE_image_clear_autosave(Image *image)
static bool tile_add_poll(bContext *C)
std::string RNA_string_get(PointerRNA *ptr, const char *name)
void IMAGE_OT_match_movie_length(wmOperatorType *ot)
wmTimer * WM_event_timer_add(wmWindowManager *wm, wmWindow *win, const wmEventType event_type, const double time_step)
void ED_image_undo_push_begin_with_image(const char *name, Image *image, ImBuf *ibuf, ImageUser *iuser)
bool ED_space_image_cursor_poll(bContext *C)
VecBase< float, 3 > float3
bool BKE_image_has_packedfile(const Image *image)
bool WM_cursor_modal_is_set_ok(const wmWindow *win)
Vector< Object * > BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(const Main &bmain, const Scene *scene, ViewLayer *view_layer, const View3D *v3d)
static wmOperatorStatus image_sample_line_exec(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void IMAGE_OT_view_zoom_out(wmOperatorType *ot)
@ PROP_COLOR_GAMMA
Definition RNA_types.hh:329
bool IMB_scale(ImBuf *ibuf, int2 new_size, IMBScaleFilter filter, bool threaded=true)
Definition scaling.cc:467
void IMAGE_OT_resize(wmOperatorType *ot)
static void image_new_free(wmOperator *op)
int MOV_get_duration_frames(const MovieReader *anim)
const EnumPropertyItem rna_enum_image_generated_type_items[]
Definition rna_image.cc:26
int WM_userdef_event_type_from_keymap_type(int kmitype)
static wmOperatorStatus image_rotate_orthogonal_exec(bContext *C, wmOperator *op)
void ED_image_view_center_to_point(SpaceImage *sima, float x, float y)
Image * BKE_image_add_generated(Main *bmain, unsigned int width, unsigned int height, const char *name, int depth, int floatbuf, short gen_type, const float color[4], bool stereo3d, bool is_data, bool tiled)
bool RE_ReadRenderResult(Scene *scene, Scene *scenode)
void BKE_imageuser_default(ImageUser *iuser)
static wmOperatorStatus image_clipboard_copy_exec(bContext *C, wmOperator *op)
static bool image_not_packed_poll(bContext *C)
Definition image_ops.cc:276
void WM_cursor_wait(bool val)
static void image_open_cancel(bContext *, wmOperator *op)
MINLINE int min_ii(int a, int b)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, 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 id_us_min(ID *id)
Definition lib_id.cc:441
int ED_image_save_all_modified_info(const Main *bmain, ReportList *reports)
static bool image_should_pack_during_save_all(const Image *ima)
bool BKE_image_remove_renderslot(Image *ima, ImageUser *iuser, int slot)
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
static bool image_clipboard_paste_poll(bContext *C)
static void image_save_options_from_op(Main *bmain, ImageSaveOptions *opts, wmOperator *op)
BLI_INLINE float BLI_rctf_cent_x(const struct rctf *rct)
Definition BLI_rect.hh:194
Image * ED_space_image(const SpaceImage *sima)
Definition image_edit.cc:43
static bool change_frame_poll(bContext *C)
Definition anim_ops.cc:116
bool ED_space_image_show_uvedit(const SpaceImage *sima, Object *obedit)
void IMB_cacheIter_free(ImBufCacheIter *iter)
Definition cache.cc:587
bool space_image_main_region_poll(bContext *C)
Definition image_ops.cc:363
float RNA_float_get(PointerRNA *ptr, const char *name)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
void BKE_histogram_update_sample_line(Histogram *hist, ImBuf *ibuf, const ColorManagedViewSettings *view_settings, const ColorManagedDisplaySettings *display_settings)
bool ED_image_should_save_modified(const Main *bmain)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const ImageFormatData *im_format)
wmOperatorStatus ED_imbuf_sample_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static void image_save_as_draw(bContext *C, wmOperator *op)
const char * BLI_path_slash_rfind(const char *path) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
static void change_frame_apply(bContext *C, wmOperator *op, const bool always_update)
Definition anim_ops.cc:560
static void tile_fill_draw(bContext *, wmOperator *op)
static bool image_file_browse_poll(bContext *C)
void IMAGE_OT_view_zoom_in(wmOperatorType *ot)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
bool BKE_image_save(ReportList *reports, Main *bmain, Image *ima, ImageUser *iuser, const ImageSaveOptions *opts)
void IMAGE_OT_new(wmOperatorType *ot)
static void def_fill_tile(StructOrFunctionRNA *srna)
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
bool ED_space_image_color_sample(SpaceImage *sima, ARegion *region, const int mval[2], float r_col[3], bool *r_is_data)
void IMAGE_OT_pack(wmOperatorType *ot)
static void image_view_pan_cancel(bContext *C, wmOperator *op)
Definition image_ops.cc:514
void BLI_rctf_init(struct rctf *rect, float xmin, float xmax, float ymin, float ymax)
Definition rct.cc:418
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
bool BKE_image_buffer_format_writable(ImBuf *ibuf)
void WM_gesture_straightline_cancel(bContext *C, wmOperator *op)
void IMAGE_OT_save(wmOperatorType *ot)
void IMAGE_OT_save_sequence(wmOperatorType *ot)
void BKE_image_release_ibuf(Image *ima, ImBuf *ibuf, void *lock)
vector snap(vector a, vector b)
Definition node_math.h:147
#define IMA_DEF_NAME
#define floorf
#define ceilf
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
eRegion_Type regiontype
eHistogram_Flag flag
struct Library * lib
Definition DNA_ID.h:421
const ColorSpace * colorspace
std::atomic< gpu::Texture * > texture
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
Definition allocimbuf.cc:60
bool colorspace_is_data() const
const float * float_data() const
std::string filepath
float * float_data_for_write()
Definition allocimbuf.cc:79
bool can_contain_alpha() const
eImageFormat_ViewsFormat views_format
char filepath[FILE_MAX]
Definition ED_image.hh:214
ListBaseT< LinkData > udim_tiles
Definition ED_image.hh:222
PropertyPointerRNA pprop
PropertyPointerRNA pprop
ImageFormatData im_format
ImageSaveOptions opts
struct Scene * scene
bke::library::LibraryRuntime * runtime
Definition DNA_ID.h:591
ListBaseT< Image > images
Definition BKE_main.hh:394
struct RenderResult * render
ListBaseT< Report > list
Definition BKE_report.hh:79
ColorManagedViewSettings view_settings
ColorManagedDisplaySettings display_settings
struct RenderData r
ListBaseT< SpaceLink > spacedata
struct ImageUser iuser
struct Histogram sample_line_hist
eSpaceImage_Mode mode
eSpaceImage_Flag flag
struct ImageUser iuser
struct Image * ima
void use_property_decorate_set(bool is_decorate)
void use_property_split_set(bool is_sep)
void prop_with_menu(PointerRNA *ptr, blender::StringRefNull propname, eUI_Item_Flag flag, std::optional< blender::StringRefNull > name, int icon, const char *menu_type)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)
Layout & column(bool align)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
wmEventType type
Definition WM_types.hh:817
wmEventModifierFlag modifier
Definition WM_types.hh:834
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) check(bContext *C, wmOperator *op)
Definition WM_types.hh:1133
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
struct ReportList * reports
struct wmOperatorType * type
#define N_(msgid)