Blender V5.0
wm_files_colorspace.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "BLI_colorspace.hh"
12#include "BLI_listbase.h"
13#include "BLI_string.h"
14
15#include "BKE_context.hh"
16#include "BKE_image.hh"
17#include "BKE_main.hh"
18#include "BKE_movieclip.h"
19#include "BKE_report.hh"
20
23#include "RNA_access.hh"
24#include "RNA_define.hh"
25#include "RNA_enum_types.hh"
26
28
29#include "DEG_depsgraph.hh"
30
31#include "UI_interface_c.hh"
32#include "UI_interface_icons.hh"
34
35#include "BLT_translation.hh"
36
37#include "ED_image.hh"
38#include "ED_render.hh"
39
40#include "RE_pipeline.h"
41
42#include "SEQ_prefetch.hh"
43#include "SEQ_relations.hh"
44
45#include "WM_api.hh"
46#include "WM_types.hh"
47
48#include "wm_files.hh"
49
50/* -------------------------------------------------------------------- */
53
55 PointerRNA * /*ptr*/,
56 PropertyRNA * /*prop*/,
57 bool *r_free)
58{
59 EnumPropertyItem *item = nullptr;
60 int totitem = 0;
62 RNA_enum_item_end(&item, &totitem);
63 *r_free = true;
64 return item;
65}
66
68{
69 const wmWindowManager *wm = CTX_wm_manager(C);
70 const Main *bmain = CTX_data_main(C);
71 const Scene *scene = CTX_data_scene(C);
72
73 if (WM_jobs_test(wm, scene, WM_JOB_TYPE_ANY)) {
75 op->reports, RPT_WARNING, RPT_("Can't change working space while jobs are running"));
76 return false;
77 }
78
82 RPT_("Can't change working space with modified images, save them first"));
83 return false;
84 }
85
86 return true;
87}
88
90{
91 Main *bmain = CTX_data_main(C);
92 const bool convert_colors = RNA_boolean_get(op->ptr, "convert_colors");
93 const int working_space_index = RNA_enum_get(op->ptr, "working_space");
95 working_space_index);
96
98 return OPERATOR_CANCELLED;
99 }
100
101 if (working_space[0] == '\0' || STREQ(working_space, bmain->colorspace.scene_linear_name)) {
102 return OPERATOR_CANCELLED;
103 }
104
105 /* Stop all viewport renders. */
106 ED_render_engine_changed(bmain, true);
108
109 /* Change working space. */
111
112 if (convert_colors) {
113 const bool depsgraph_tag = true;
117 depsgraph_tag);
118 }
119
120 STRNCPY(bmain->colorspace.scene_linear_name, working_space);
122
123 /* Free all render, compositor and sequencer caches. */
127 LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) {
129 }
130
131 /* Free all images, they may have scene linear float buffers. */
132 LISTBASE_FOREACH (Image *, image, &bmain->images) {
134 BKE_image_signal(bmain, image, nullptr, IMA_SIGNAL_COLORMANAGE);
136 }
137 LISTBASE_FOREACH (MovieClip *, clip, &bmain->movieclips) {
141 }
142
143 /* Redraw everything. */
148
149 return OPERATOR_FINISHED;
150}
151
153 wmOperator *op,
154 const wmEvent *event)
155{
157 return OPERATOR_CANCELLED;
158 }
159
160 if (RNA_enum_get(op->ptr, "working_space") == -1) {
161 RNA_enum_set(op->ptr,
162 "working_space",
165 }
166
167 const Main *bmain = CTX_data_main(C);
168 const char *working_space = IMB_colormanagement_working_space_get_indexed_name(
169 RNA_enum_get(op->ptr, "working_space"));
170 if (STREQ(working_space, bmain->colorspace.scene_linear_name)) {
171 return OPERATOR_CANCELLED;
172 }
173
175 C,
176 op,
177 event,
178 std::nullopt,
179 IFACE_("Apply"),
180 false,
181 IFACE_("To match renders with the previous working space as closely as possible,\n"
182 "colors in all materials, lights and geometry must be converted.\n\n"
183 "Some nodes graphs cannot be converted accurately and may need manual fix-ups."));
184}
185
187{
188 ot->name = "Set Blend File Working Color Space";
189 ot->idname = "WM_OT_set_working_color_space";
190 ot->description = "Change the working color space of all colors in this blend file";
191
194
196
197 RNA_def_boolean(ot->srna,
198 "convert_colors",
199 true,
200 "Convert Colors in All Data-blocks",
201 "Change colors in all data-blocks to the new working space");
202 PropertyRNA *prop = RNA_def_enum(ot->srna,
203 "working_space",
205 -1,
206 "Working Space",
207 "Color space to set");
209
210 ot->prop = prop;
211}
212
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
wmWindowManager * CTX_wm_manager(const bContext *C)
#define IMA_SIGNAL_COLORMANAGE
Definition BKE_image.hh:174
void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
void BKE_image_partial_update_mark_full_update(Image *image)
Mark the whole image to be updated.
void BKE_movieclip_clear_cache(struct MovieClip *clip)
void BKE_movieclip_free_gputexture(struct MovieClip *clip)
@ RPT_WARNING
Definition BKE_report.hh:38
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#define LISTBASE_FOREACH(type, var, list)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
#define STREQ(a, b)
#define RPT_(msgid)
#define IFACE_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1143
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
bool ED_image_should_save_modified(const Main *bmain)
void ED_render_engine_changed(Main *bmain, bool update_scene_data)
bool IMB_colormanagement_working_space_set_from_name(const char *name)
int IMB_colormanagement_working_space_get_named_index(const char *name)
const char * IMB_colormanagement_working_space_get_default()
void IMB_colormanagement_working_space_items_add(EnumPropertyItem **items, int *totitem)
void IMB_colormanagement_working_space_convert(Main *bmain, const blender::float3x3 &current_scene_linear_to_xyz, const blender::float3x3 &new_xyz_to_scene_linear, const bool depsgraph_tag=false, const bool linked_only=false, const bool editable_assets_only=false)
const char * IMB_colormanagement_working_space_get_indexed_name(int index)
#define C
Definition RandGen.cpp:29
@ WM_JOB_TYPE_ANY
Definition WM_api.hh:1775
#define ND_SEQUENCER
Definition WM_types.hh:437
#define NC_WINDOW
Definition WM_types.hh:375
#define ND_RENDER_OPTIONS
Definition WM_types.hh:435
#define NC_SCENE
Definition WM_types.hh:378
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define ND_NODES
Definition WM_types.hh:436
void prefetch_stop_all()
Definition prefetch.cc:300
void cache_cleanup(Scene *scene)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void RNA_enum_set(PointerRNA *ptr, const char *name, int value)
int RNA_enum_get(PointerRNA *ptr, const char *name)
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 RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:26
void RE_FreeInteractiveCompositorRenders()
char scene_linear_name[64]
Definition BKE_main.hh:150
blender::float3x3 scene_linear_to_xyz
Definition BKE_main.hh:151
ListBase scenes
Definition BKE_main.hh:278
ListBase movieclips
Definition BKE_main.hh:311
ListBase images
Definition BKE_main.hh:286
MainColorspace colorspace
Definition BKE_main.hh:274
struct ReportList * reports
struct PointerRNA * ptr
void WM_main_add_notifier(uint type, void *reference)
wmOperatorType * ot
Definition wm_files.cc:4237
static const EnumPropertyItem * working_space_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static wmOperatorStatus wm_set_working_color_space_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool wm_set_working_space_check_safe(bContext *C, wmOperator *op)
void WM_OT_set_working_color_space(wmOperatorType *ot)
static wmOperatorStatus wm_set_working_color_space_exec(bContext *C, wmOperator *op)
bool WM_jobs_test(const wmWindowManager *wm, const void *owner, int job_type)
Definition wm_jobs.cc:247
wmOperatorStatus WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message)