Blender V5.0
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
9#include "BLI_math_vector.h"
10
11#include "BLT_translation.hh"
12
13#include "DNA_sequence_types.h"
14
15#include "SEQ_modifier.hh"
16
17#include "UI_interface.hh"
19
20#include "modifier.hh"
21
22namespace blender::seq {
23
29
31 float multiplier[3];
32
33 template<typename ImageT, typename MaskSampler>
34 void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)
35 {
36 image += y_range.first() * image_x * 4;
37 for (int64_t y : y_range) {
38 mask.begin_row(y);
39 for ([[maybe_unused]] int64_t x : IndexRange(image_x)) {
41
43 result.w = input.w;
44#if 0
46#else
47 /* similar to division without the clipping */
48 for (int i = 0; i < 3; i++) {
49 /* Prevent pow argument from being negative. This whole math
50 * breaks down overall with any HDR colors; would be good to
51 * revisit and do something more proper. */
52 float f = max_ff(1.0f - input[i], 0.0f);
53 result[i] = 1.0f - powf(f, this->multiplier[i]);
54 }
55#endif
56
57 mask.apply_mask(input, result);
59 image += 4;
60 }
61 }
62 }
63};
64
66{
68
70 op.multiplier[0] = (data->white_value[0] != 0.0f) ? 1.0f / data->white_value[0] : FLT_MAX;
71 op.multiplier[1] = (data->white_value[1] != 0.0f) ? 1.0f / data->white_value[1] : FLT_MAX;
72 op.multiplier[2] = (data->white_value[2] != 0.0f) ? 1.0f / data->white_value[2] : FLT_MAX;
73 apply_modifier_op(op, context.image, mask, context.transform);
74}
75
76static void whiteBalance_panel_draw(const bContext *C, Panel *panel)
77{
78 uiLayout *layout = panel->layout;
80
81 layout->use_property_split_set(true);
82
83 layout->prop(ptr, "white_value", UI_ITEM_NONE, std::nullopt, ICON_NONE);
84
85 if (uiLayout *mask_input_layout = layout->panel_prop(
86 C, ptr, "open_mask_input_panel", IFACE_("Mask Input")))
87 {
88 draw_mask_input_type_settings(C, mask_input_layout, ptr);
89 }
90}
91
96
98 /*idname*/ "WhiteBalance",
99 /*name*/ CTX_N_(BLT_I18NCONTEXT_ID_SEQUENCE, "White Balance"),
100 /*struct_name*/ "WhiteBalanceModifierData",
101 /*struct_size*/ sizeof(WhiteBalanceModifierData),
102 /*init_data*/ whiteBalance_init_data,
103 /*free_data*/ nullptr,
104 /*copy_data*/ nullptr,
105 /*apply*/ whiteBalance_apply,
106 /*panel_register*/ whiteBalance_register,
107 /*blend_write*/ nullptr,
108 /*blend_read*/ nullptr,
109};
110
111}; // namespace blender::seq
MINLINE float max_ff(float a, float b)
MINLINE void mul_v3_v3(float r[3], const float a[3])
MINLINE void copy_v3_fl(float r[3], float f)
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_SEQUENCE
#define IFACE_(msgid)
@ eSeqModifierType_WhiteBalance
#define C
Definition RandGen.cpp:29
PointerRNA * UI_panel_custom_data_get(const Panel *panel)
#define UI_ITEM_NONE
BMesh const char void * data
long long int int64_t
constexpr int64_t first() const
#define powf(x, y)
#define input
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
StripModifierTypeInfo seqModifierType_WhiteBalance
static void whiteBalance_init_data(StripModifierData *smd)
void draw_mask_input_type_settings(const bContext *C, uiLayout *layout, PointerRNA *ptr)
void apply_modifier_op(T &op, ImBuf *ibuf, const ImBuf *mask, const float3x3 &mask_transform)
Definition modifier.hh:263
void store_pixel_premul(float4 pix, uchar *ptr)
float4 load_pixel_premul(const uchar *ptr)
static void whiteBalance_register(ARegionType *region_type)
static void whiteBalance_panel_draw(const bContext *C, Panel *panel)
PanelType * modifier_panel_register(ARegionType *region_type, const eStripModifierType type, PanelDrawFn draw)
static void whiteBalance_apply(ModifierApplyContext &context, StripModifierData *smd, ImBuf *mask)
VecBase< float, 4 > float4
#define FLT_MAX
Definition stdcycles.h:14
struct uiLayout * layout
void apply(ImageT *image, MaskSampler &mask, int image_x, IndexRange y_range)
PanelLayout panel_prop(const bContext *C, PointerRNA *open_prop_owner, blender::StringRefNull open_prop_name)
void use_property_split_set(bool value)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
i
Definition text_draw.cc:230
PointerRNA * ptr
Definition wm_files.cc:4238