Blender V5.3
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.hh"
13#include "BLI_string.hh"
14
15#include "BKE_context.hh"
16#include "BKE_image.hh"
17#include "BKE_main.hh"
18#include "BKE_movieclip.hh"
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
33#include "BLT_translation.hh"
34
35#include "ED_image.hh"
36#include "ED_render.hh"
37
38#include "RE_pipeline.h"
39
40#include "SEQ_prefetch.hh"
41#include "SEQ_relations.hh"
42
43#include "WM_api.hh"
44#include "WM_types.hh"
45
46#include "wm_files.hh"
47
48namespace blender {
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{
70 const Main *bmain = CTX_data_main(C);
71 const Scene *scene = CTX_data_scene(C);
72
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 for (Scene &scene : bmain->scenes) {
129 }
130
131 /* Free all images, they may have scene linear float buffers. */
132 for (Image &image : bmain->images) {
135 }
136 for (MovieClip &clip : bmain->movieclips) {
140 }
141
142 /* Redraw everything. */
147
148 return OPERATOR_FINISHED;
149}
150
152 wmOperator *op,
153 const wmEvent *event)
154{
156 return OPERATOR_CANCELLED;
157 }
158
159 if (RNA_enum_get(op->ptr, "working_space") == -1) {
160 RNA_enum_set(op->ptr,
161 "working_space",
164 }
165
166 const Main *bmain = CTX_data_main(C);
167 const char *working_space = IMB_colormanagement_working_space_get_indexed_name(
168 RNA_enum_get(op->ptr, "working_space"));
169 if (STREQ(working_space, bmain->colorspace.scene_linear_name)) {
170 return OPERATOR_CANCELLED;
171 }
172
174 C,
175 op,
176 event,
177 std::nullopt,
178 IFACE_("Apply"),
179 false,
180 IFACE_("To match renders with the previous working space as closely as possible, "
181 "colors in all materials, lights and geometry must be converted.\n\n"
182 "Some node graphs cannot be converted accurately and may need manual fix-ups."));
183}
184
186{
187 ot->name = "Set Blend File Working Color Space";
188 ot->idname = "WM_OT_set_working_color_space";
189 ot->description = "Change the working color space of all colors in this blend file";
190
193
195
197 "convert_colors",
198 true,
199 "Convert Colors in All Data-blocks",
200 "Change colors in all data-blocks to the new working space");
201 PropertyRNA *prop = RNA_def_enum(ot->srna,
202 "working_space",
204 -1,
205 "Working Space",
206 "Color space to set");
209
210 ot->prop = prop;
211}
212
214
215} // namespace blender
#define IMA_SIGNAL_COLORMANAGE
Definition BKE_image.hh:184
#define RPT_(msgid)
#define BLT_I18NCONTEXT_COLOR_MANAGEMENT
#define IFACE_(msgid)
#define C
Definition RandGen.cpp:29
#define ND_SEQUENCER
Definition WM_types.hh:456
#define NC_WINDOW
Definition WM_types.hh:388
#define ND_RENDER_OPTIONS
Definition WM_types.hh:454
#define NC_SCENE
Definition WM_types.hh:391
#define ND_NODES
Definition WM_types.hh:455
#define STREQ(a, b)
void prefetch_stop_all()
Definition prefetch.cc:327
void cache_cleanup(Scene *scene, CacheCleanup mode)
BMesh Iterators.
void WM_main_add_notifier(uint type, void *reference)
void RNA_def_enum_funcs(PropertyRNA *prop, EnumPropertyItemFunc itemfunc)
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
@ RPT_WARNING
Definition BKE_report.hh:40
void BKE_image_signal(Main *bmain, Image *ima, ImageUser *iuser, int signal)
void WM_OT_set_working_color_space(wmOperatorType *ot)
void BKE_movieclip_clear_cache(MovieClip *clip)
@ WM_JOB_TYPE_ANY
Definition WM_api.hh:2008
void IMB_colormanagement_working_space_items_add(EnumPropertyItem **items, int *totitem)
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_set(PointerRNA *ptr, const char *name, int value)
static wmOperatorStatus wm_set_working_color_space_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@ WM_JOB_BACKGROUND
Definition WM_api.hh:1999
const char * IMB_colormanagement_working_space_get_default()
int IMB_colormanagement_working_space_get_named_index(const char *name)
static bool wm_set_working_space_check_safe(bContext *C, wmOperator *op)
void ED_render_engine_changed(Main *bmain, bool update_scene_data)
void DEG_id_tag_update(ID *id, unsigned int flags)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
Definition wm_jobs.cc:809
wmWindowManager * CTX_wm_manager(const bContext *C)
static const EnumPropertyItem * working_space_itemf(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static wmOperatorStatus wm_set_working_color_space_exec(bContext *C, wmOperator *op)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void IMB_colormanagement_working_space_convert(Main *bmain, const float3x3 &current_scene_linear_to_xyz, const float3x3 &new_xyz_to_scene_linear, bool depsgraph_tag=false, bool linked_only=false, bool editable_assets_only=false)
const EnumPropertyItem rna_enum_dummy_NULL_items[]
Definition rna_rna.cc:28
bool IMB_colormanagement_working_space_set_from_name(const char *name)
void RNA_def_property_translation_context(PropertyRNA *prop, const char *context)
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)
Main * CTX_data_main(const bContext *C)
@ ID_RECALC_SOURCE
Definition DNA_ID.h:1143
Scene * CTX_data_scene(const bContext *C)
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
const char * IMB_colormanagement_working_space_get_indexed_name(int index)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void BKE_movieclip_free_gputexture(MovieClip *clip)
bool ED_image_should_save_modified(const Main *bmain)
MainColorspace colorspace
Definition BKE_main.hh:371
ListBaseT< MovieClip > movieclips
Definition BKE_main.hh:419
ListBaseT< Image > images
Definition BKE_main.hh:394
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
const char * description
Definition WM_types.hh:1115
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
struct ReportList * reports