Blender V5.3
MOD_white_balance.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
8
10
11#include "BLT_translation.hh"
12
13#include "DNA_sequence_types.h"
14
15#include "PRF_profile.hh"
16
17#include "SEQ_modifier.hh"
18#include "SEQ_render.hh"
19
20#include "UI_interface.hh"
22
23#include "modifier.hh"
24#include "render.hh"
25
26namespace blender::seq {
27
29{
30 WhiteBalanceModifierData *cbmd = reinterpret_cast<WhiteBalanceModifierData *>(smd);
31 copy_v3_fl(cbmd->white_value, 1.0f);
32}
33
35 float multiplier[3];
36
37 template<typename ImageT, typename MaskSampler>
38 void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)
39 {
40 image += y_range.first() * image_x * 4;
41 for (int64_t y : y_range) {
42 mask.begin_row(y);
43 for ([[maybe_unused]] int64_t x : IndexRange(image_x)) {
45
47 result.w = input.w;
48#if 0
50#else
51 /* similar to division without the clipping */
52 for (int i = 0; i < 3; i++) {
53 /* Prevent pow argument from being negative. This whole math
54 * breaks down overall with any HDR colors; would be good to
55 * revisit and do something more proper. */
56 float f = max_ff(1.0f - input[i], 0.0f);
57 result[i] = 1.0f - powf(f, this->multiplier[i]);
58 }
59#endif
60
61 mask.apply_mask(input, result);
63 image += 4;
64 }
65 }
66 }
67};
68
70{
71 PRF_scope_with_name("SeqModWhiteBalance", ProfileCategory::Draw);
72 ensure_ibuf_is_sequencer_space(context.render_data.scene, context.result.image, false);
73 ImBuf *mask = modifier_render_mask_input(context, *smd);
74
75 const WhiteBalanceModifierData *data = reinterpret_cast<const WhiteBalanceModifierData *>(smd);
76
78 op.multiplier[0] = (data->white_value[0] != 0.0f) ? 1.0f / data->white_value[0] : FLT_MAX;
79 op.multiplier[1] = (data->white_value[1] != 0.0f) ? 1.0f / data->white_value[1] : FLT_MAX;
80 op.multiplier[2] = (data->white_value[2] != 0.0f) ? 1.0f / data->white_value[2] : FLT_MAX;
81 apply_modifier_op(op, context.result.image, mask, context.transform);
82 if (mask != nullptr) {
84 }
85}
86
87static void whiteBalance_panel_draw(const bContext *C, Panel *panel)
88{
89 ui::Layout &layout = *panel->layout;
91
92 layout.use_property_split_set(true);
93
94 layout.prop(ptr, "white_value", UI_ITEM_NONE, std::nullopt, ICON_NONE);
95
96 if (ui::Layout *mask_input_layout = layout.panel_prop(
97 C, ptr, "open_mask_input_panel", IFACE_("Mask Input")))
98 {
99 draw_mask_input_type_settings(C, *mask_input_layout, ptr);
100 }
101}
102
107
109 /*idname*/ "WhiteBalance",
110 /*name*/ CTX_N_(BLT_I18NCONTEXT_ID_SEQUENCE, "White Balance"),
111 /*struct_name*/ "WhiteBalanceModifierData",
112 /*struct_size*/ sizeof(WhiteBalanceModifierData),
113 /*init_data*/ whiteBalance_init_data,
114 /*free_data*/ nullptr,
115 /*copy_data*/ nullptr,
116 /*apply*/ whiteBalance_apply,
117 /*panel_register*/ whiteBalance_register,
118 /*blend_write*/ nullptr,
119 /*blend_read*/ nullptr,
120};
121
122}; // namespace blender::seq
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_SEQUENCE
#define IFACE_(msgid)
#define PRF_scope_with_name(ui_name, category)
#define C
Definition RandGen.cpp:29
#define UI_ITEM_NONE
constexpr int64_t first() const
constexpr IndexRange()=default
#define powf(x, y)
#define FLT_MAX
ImBuf * modifier_render_mask_input(const ModifierApplyContext &context, const StripModifierData &smd)
void ensure_ibuf_is_sequencer_space(const Scene *scene, ImBuf *ibuf, bool make_float)
Definition render.cc:170
StripModifierTypeInfo seqModifierType_WhiteBalance
static void whiteBalance_init_data(StripModifierData *smd)
void apply_modifier_op(T &op, ImBuf *ibuf, const ImBuf *mask, const float3x3 &mask_transform)
Definition modifier.hh:277
void store_pixel_premul(float4 pix, uchar *ptr)
static void whiteBalance_apply(ModifierApplyContext &context, StripModifierData *smd)
float4 load_pixel_premul(const uchar *ptr)
static void whiteBalance_register(ARegionType *region_type)
void draw_mask_input_type_settings(const bContext *C, ui::Layout &layout, PointerRNA *ptr)
static void whiteBalance_panel_draw(const bContext *C, Panel *panel)
PanelType * modifier_panel_register(ARegionType *region_type, const eStripModifierType type, PanelDrawFn draw)
PointerRNA * panel_custom_data_get(const Panel *panel)
__int64 int64_t
Definition BKE_text.h:90
VecBase< float, 4 > float4
void IMB_freeImBuf(ImBuf *ibuf)
MINLINE void mul_v3_v3(float r[3], const float a[3])
BMesh const char void * data
MINLINE void copy_v3_fl(float r[3], float f)
MINLINE float max_ff(float a, float b)
@ eSeqModifierType_WhiteBalance
ui::Layout * layout
void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)
void use_property_split_set(bool is_sep)
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)
PanelLayout panel_prop(const bContext *C, PointerRNA *open_prop_owner, StringRefNull open_prop_name)