61 reinterpret_cast<float *
>(pixels),
int(count), 1, 4,
colorspace,
false);
70 const uchar *bptr = pixels;
72 for (
int64_t i = 0; i < count; i++) {
78 reinterpret_cast<float *
>(dst),
int(count), 1, 4,
colorspace,
false);
85 reinterpret_cast<float *
>(src),
int(range.
size()), 1, 4,
colorspace);
86 const float4 *src_ptr = src;
88 for (
const int64_t idx : range) {
111template<
typename MaskSampler>
118 float4 input = *scene_linear;
121 float3 pixel = input.xyz() * avg.
al;
123 pixel.x /= (d.x == 0.0f) ? 1.0f : d.x;
124 pixel.y /= (d.y == 0.0f) ? 1.0f : d.y;
125 pixel.z /= (d.z == 0.0f) ? 1.0f : d.z;
126 const float igm = avg.
igm;
142template<
typename MaskSampler>
154 float4 input = *scene_linear;
157 float3 pixel = input.xyz();
159 float I_l = pixel.x + ic * (
L - pixel.x);
160 float I_g = avg.
cav.x + ic * (avg.
lav - avg.
cav.x);
161 float I_a = I_l + ia * (I_g - I_l);
162 pixel.x /= std::max(pixel.x +
powf(f * I_a, m), 1.0e-30f);
163 I_l = pixel.y + ic * (
L - pixel.y);
164 I_g = avg.
cav.y + ic * (avg.
lav - avg.
cav.y);
165 I_a = I_l + ia * (I_g - I_l);
166 pixel.y /= std::max(pixel.y +
powf(f * I_a, m), 1.0e-30f);
167 I_l = pixel.z + ic * (
L - pixel.z);
168 I_g = avg.
cav.z + ic * (avg.
lav - avg.
cav.z);
169 I_a = I_l + ia * (I_g - I_l);
170 pixel.z /= std::max(pixel.z +
powf(f * I_a, m), 1.0e-30f);
187 template<
typename ImageT,
typename MaskSampler>
191 if constexpr (std::is_same_v<ImageT, float>) {
225 const float4 *scene_linear,
228 for ([[maybe_unused]]
const int y : y_range) {
229 for (
int x = 0;
x < width;
x++) {
230 float4 pixel = *scene_linear;
255 AreaLuminance lum = init;
256 const int64_t chunk_size = y_range.size() * ibuf->x;
259 if (float_data != nullptr) {
260 float4 *fptr = reinterpret_cast<float4 *>(float_data);
261 fptr += y_range.first() * ibuf->x;
262 pixels_to_scene_linear_float(ibuf->float_buffer.colorspace, fptr, chunk_size);
263 tonemap_calc_chunk_luminance(ibuf->x, y_range, fptr, lum);
266 const uchar *bptr = ibuf->byte_data() + y_range.first() * ibuf->x * 4;
267 Array<float4> scene_linear(chunk_size);
268 pixels_to_scene_linear_byte(
269 ibuf->byte_buffer.colorspace, bptr, scene_linear.data(), chunk_size);
270 tonemap_calc_chunk_luminance(ibuf->x, y_range, scene_linear.data(), lum);
275 [&](
const AreaLuminance &a,
const AreaLuminance &
b) {
277 res.pixel_count = a.pixel_count +
b.pixel_count;
278 res.sum = a.sum +
b.sum;
279 res.color_sum = a.color_sum +
b.color_sum;
280 res.log_sum = a.log_sum +
b.log_sum;
299 op.
ibuf = context.result.image;
310 float maxl =
log(
double(op.
lum.
max) + 1e-5f);
311 float minl =
log(
double(op.
lum.
min) + 1e-5f);
313 op.
data.
auto_key = (maxl > minl) ? ((maxl - avl) / (maxl - minl)) : 1.0f;
314 float al =
exp(
double(avl));
315 op.
data.
al = (al == 0.0f) ? 0.0f : (tmmd->
key / al);
320 if (
mask !=
nullptr) {
330 const int tonemap_type =
RNA_enum_get(ptr,
"tonemap_type");
352 C, ptr,
"open_mask_input_panel",
IFACE_(
"Mask Input")))
366 "SequencerTonemapModifierData",
#define CTX_N_(context, msgid)
#define BLT_I18NCONTEXT_ID_SEQUENCE
#define PRF_scope_with_name(ui_name, category)
#define BLI_assert_unreachable()
constexpr int64_t first() const
constexpr int64_t size() const
constexpr IndexRange()=default
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)
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)
static void tonemap_calc_chunk_luminance(const int width, const IndexRange y_range, const float4 *scene_linear, AreaLuminance &r_lum)
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 AreaLuminance tonemap_calc_input_luminance(ImBuf *ibuf)
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_apply(ModifierApplyContext &context, StripModifierData *smd)
static void tonemapmodifier_register(ARegionType *region_type)
void draw_mask_input_type_settings(const bContext *C, ui::Layout &layout, PointerRNA *ptr)
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)
PanelType * modifier_panel_register(ARegionType *region_type, const eStripModifierType type, PanelDrawFn draw)
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)
PointerRNA * panel_custom_data_get(const Panel *panel)
@ SEQ_TONEMAP_RD_PHOTORECEPTOR
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void IMB_colormanagement_scene_linear_to_colorspace(float *buffer, int width, int height, int channels, const ColorSpace *colorspace)
VecBase< float, 4 > float4
void IMB_freeImBuf(ImBuf *ibuf)
MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned char color[4])
BLI_INLINE float IMB_colormanagement_get_luminance(const float rgb[3])
VecBase< float, 3 > float3
@ eSeqModifierType_Tonemap
MINLINE void premul_float_to_straight_uchar(unsigned char *result, const float color[4])
void IMB_colormanagement_colorspace_to_scene_linear(float *buffer, int width, int height, int channels, const ColorSpace *colorspace, bool predivide)
ocio::ColorSpace ColorSpace
const ColorSpace * colorspace
const ColorSpace * colorspace
ImBufFloatBuffer float_buffer
ImBufByteBuffer byte_buffer
const uint8_t * byte_data() const
uint8_t * byte_data_for_write()
float * float_data_for_write()
const SequencerTonemapModifierData * tmmd
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)
Layout & column(bool align)
PanelLayout panel_prop(const bContext *C, PointerRNA *open_prop_owner, StringRefNull open_prop_name)