67 const uchar *bptr = pixels;
83 const float4 *src_ptr = src;
85 for (
const int64_t idx : range) {
108template<
typename MaskSampler>
120 pixel.x /= (d.x == 0.0f) ? 1.0f : d.x;
121 pixel.y /= (d.y == 0.0f) ? 1.0f : d.y;
122 pixel.z /= (d.z == 0.0f) ? 1.0f : d.z;
123 const float igm = avg.
igm;
139template<
typename MaskSampler>
156 float I_l = pixel.x + ic * (
L - pixel.x);
157 float I_g = avg.
cav.x + ic * (avg.
lav - avg.
cav.x);
158 float I_a = I_l + ia * (I_g - I_l);
159 pixel.x /= std::max(pixel.x +
powf(f * I_a, m), 1.0e-30f);
160 I_l = pixel.y + ic * (
L - pixel.y);
161 I_g = avg.
cav.y + ic * (avg.
lav - avg.
cav.y);
162 I_a = I_l + ia * (I_g - I_l);
163 pixel.y /= std::max(pixel.y +
powf(f * I_a, m), 1.0e-30f);
164 I_l = pixel.z + ic * (
L - pixel.z);
165 I_g = avg.
cav.z + ic * (avg.
lav - avg.
cav.z);
166 I_a = I_l + ia * (I_g - I_l);
167 pixel.z /= std::max(pixel.z +
powf(f * I_a, m), 1.0e-30f);
184 template<
typename ImageT,
typename MaskSampler>
188 if constexpr (std::is_same_v<ImageT, float>) {
205 ibuf->byte_buffer.data + pixel_range.
first() * 4,
222 const float4 *scene_linear,
225 for ([[maybe_unused]]
const int y : y_range) {
226 for (
int x = 0;
x < width;
x++) {
227 float4 pixel = *scene_linear;
251 AreaLuminance lum = init;
252 const int64_t chunk_size = y_range.size() * ibuf->x;
255 if (ibuf->float_buffer.data != nullptr) {
256 float4 *fptr = reinterpret_cast<float4 *>(ibuf->float_buffer.data);
257 fptr += y_range.first() * ibuf->x;
258 pixels_to_scene_linear_float(ibuf->float_buffer.colorspace, fptr, chunk_size);
259 tonemap_calc_chunk_luminance(ibuf->x, y_range, fptr, lum);
262 const uchar *bptr = ibuf->byte_buffer.data + y_range.first() * ibuf->x * 4;
263 Array<float4> scene_linear(chunk_size);
264 pixels_to_scene_linear_byte(
265 ibuf->byte_buffer.colorspace, bptr, scene_linear.data(), chunk_size);
266 tonemap_calc_chunk_luminance(ibuf->x, y_range, scene_linear.data(), lum);
271 [&](
const AreaLuminance &a,
const AreaLuminance &
b) {
273 res.pixel_count = a.pixel_count +
b.pixel_count;
274 res.sum = a.sum +
b.sum;
275 res.color_sum = a.color_sum +
b.color_sum;
276 res.log_sum = a.log_sum +
b.log_sum;
292 op.
ibuf = context.image;
303 float maxl =
log(
double(op.
lum.
max) + 1e-5f);
304 float minl =
log(
double(op.
lum.
min) + 1e-5f);
306 op.
data.
auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.0f;
307 float al =
exp(
double(avl));
308 op.
data.
al = (al == 0.0f) ? 0.0f : (tmmd->
key / al);
341 C,
ptr,
"open_mask_input_panel",
IFACE_(
"Mask Input")))
355 "SequencerTonemapModifierData",
blender::ocio::ColorSpace ColorSpace
#define BLI_assert_unreachable()
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4])
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_SEQUENCE
@ SEQ_TONEMAP_RD_PHOTORECEPTOR
@ eSeqModifierType_Tonemap
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, const ColorSpace *colorspace, bool predivide)
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
void IMB_colormanagement_scene_linear_to_colorspace(float *buffer, int width, int height, int channels, const ColorSpace *colorspace)
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
PointerRNA * UI_panel_custom_data_get(const Panel *panel)
constexpr int64_t first() const
constexpr int64_t size() const
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
T min(const T &a, const T &b)
T max(const T &a, const T &b)
static void scene_linear_to_image_chunk_float(ImBuf *ibuf, IndexRange range)
static void tonemap_calc_chunk_luminance(const int width, const IndexRange y_range, const float4 *scene_linear, AreaLuminance &r_lum)
static AreaLuminance tonemap_calc_input_luminance(const ImBuf *ibuf)
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)
static void tonemapmodifier_init_data(StripModifierData *smd)
static void tonemapmodifier_panel_draw(const bContext *C, Panel *panel)
StripModifierTypeInfo seqModifierType_Tonemap
static void tonemapmodifier_apply(ModifierApplyContext &context, StripModifierData *smd, ImBuf *mask)
static void tonemap_simple(float4 *scene_linear, MaskSampler &mask, int image_x, IndexRange y_range, const AvgLogLum &avg)
static void pixels_to_scene_linear_float(const ColorSpace *colorspace, float4 *pixels, int64_t count)
static void tonemapmodifier_register(ARegionType *region_type)
static void pixels_to_scene_linear_byte(const ColorSpace *colorspace, const uchar *pixels, float4 *dst, int64_t count)
static void scene_linear_to_image_chunk_byte(float4 *src, ImBuf *ibuf, IndexRange range)
static void tonemap_rd_photoreceptor(float4 *scene_linear, MaskSampler &mask, int image_x, IndexRange y_range, const AvgLogLum &avg)
Value parallel_reduce(IndexRange range, int64_t grain_size, const Value &identity, const Function &function, const Reduction &reduction)
VecBase< float, 4 > float4
VecBase< float, 3 > float3
static void init(bNodeTree *, bNode *node)
int RNA_enum_get(PointerRNA *ptr, const char *name)
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
const SequencerTonemapModifierData * tmmd
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)
uiLayout & column(bool align)
void use_property_split_set(bool value)