19#ifndef DT_IOP_HIGHLIGHTS_COMMON_H
20#define DT_IOP_HIGHLIGHTS_COMMON_H
68#define DT_HL_BIHARMONIC 1
78#define DT_HL_BAND_OVR 0.9f
80#define HL_PFOR(...) __OMP_PARALLEL_FOR__(__VA_ARGS__)
97 const float mn = fminf(clips[0], fminf(clips[1], clips[2]));
98 const float mx = fmaxf(clips[0], fmaxf(clips[1], clips[2]));
99 const float asym = (mn > 1e-9f) ? mx / mn : 1.f;
100 const float t = CLAMP((asym - 1.25f) / 0.75f, 0.f, 1.f);
101 return t *
t * (3.f - 2.f *
t);
118 const float *
const restrict valid,
121 const float cmean_sum = fmaxf(cmean[0] + cmean[1] + cmean[2], 1e-9f);
122 const float cmean_share[3]
123 = { cmean[0] / cmean_sum, cmean[1] / cmean_sum, cmean[2] / cmean_sum };
124 double share_sum[3] = { 0.0, 0.0, 0.0 };
125 double share_sq[3] = { 0.0, 0.0, 0.0 };
126 double ring_count = 0.0;
127 for(
size_t i = 0;
i < region_pixels;
i++)
129 const int n_clipped = (valid[
i * 4 + 0] < 0.5f) + (valid[
i * 4 + 1] < 0.5f) + (valid[
i * 4 + 2] < 0.5f);
130 if(n_clipped != 1)
continue;
131 const float sum = fmaxf(estimate[
i * 4 + 0] + estimate[
i * 4 + 1] + estimate[
i * 4 + 2], 1e-9f);
132 for(
int c = 0; c < 3; c++)
134 const double share = (
double)(estimate[
i * 4 + c] / sum);
135 share_sum[c] += share;
136 share_sq[c] += share * share;
140 if(ring_count <= 0.0)
return 0.f;
142 float dispersion = 0.f;
143 for(
int c = 0; c < 3; c++)
145 const double mean = share_sum[c] / ring_count;
146 bias += fabsf((
float)mean - cmean_share[c]);
147 dispersion += sqrtf(fmaxf((
float)(share_sq[c] / ring_count - mean * mean), 0.f));
149 const float t = bias / fmaxf(dispersion, 0.02f);
150 const float arg =
t / 5.f;
151 return expf(-arg * arg);
169#define HL_GAUSS_SLOTS 4
181#define DT_HL_PAIR_VARIANCE 1
182#define DT_HL_GUIDE_GATE 2
189#define DT_HL_CLIP_FLOOR 1
204#define CF_EDGE_RANGE 0.15f
208#define CF_EDGE_GUIDE_SIGMA 3.f
213#define CF_JOINT_TAU 0.10f
236#define CF_REGION_LO 0.005f
237#define CF_REGION_HI 0.015f
242 return t *
t * (3.f - 2.f *
t);
259 return t *
t * (3.f - 2.f *
t);
266#define CF_AUTHORED_RAMP 1.12f
268#define DT_HL_A3_COLLAR_PX 24.f
270#define DT_HL_MIN_CLIPPED_PIXELS 25
272#define DT_HL_DOME_NMAX 2000
276#define DT_HL_DOME_NMAX_SPARSE 8192
292#define DT_HL_SELF_DOME 1
298#define DT_HL_ANISO_CHROMA 1
335#define DT_HL_COEFF_FIELD 1
344#define DT_HL_HF_GUIDE 1
372#define DT_HL_CF_K 0.15f
375#define DT_HL_FILL_CL_MAXP 3
380#define DT_HL_SPARSE_SOLVE 1
385#define DT_HL_SPARSE_MAX (1 << 14)
388#define DT_HL_ANISO_SOLVER 2
394#define DT_HL_FILL_MAXP 4
400#define DT_HL_CL_CPU_REGION_PX (1u << 20)
402#define DT_HL_KNEE_LO 0.80f
403#define DT_HL_KNEE_DET 0.995f
404#define DT_HL_KNEE_BINS 24
405#define DT_HL_KNEE_FMIN 0.02f
406#define DT_HL_KNEE_R2MIN 0.25f
407#define DT_HL_KNEE_MINVOTES 100
408#define DT_HL_KNEE_NSIGMA 2.0f
409#define DT_HL_KNEE_ENGAGE 0.005f
410#define DT_HL_KNEE_NSIGMAS 5
681#define MAX_NUM_SCALES 12
684#define SQRT3 1.7320508075688772935274463415058723669L
685#define SQRT12 3.4641016151377545870548926830117447339L
DT_ALIGNED_PIXEL float dt_aligned_pixel_t[4]
static float _hl_ring_flat_mean_vote(const float *const restrict estimate, const float *const restrict valid, const dt_aligned_pixel_t cmean, const size_t region_pixels)
static float _hl_floor_gate(const float clips[4])
@ DT_IOP_HIGHLIGHTS_HARMONIC
@ DT_IOP_HIGHLIGHTS_INPAINT
@ DT_IOP_HIGHLIGHTS_LAPLACIAN
dt_atrous_wavelets_scales_t
diffuse_reconstruct_variant_t
@ DIFFUSE_RECONSTRUCT_RGB
@ DIFFUSE_RECONSTRUCT_CHROMA
dt_iop_highlights_params_t dt_iop_highlights_data_t
static float _hl_floor_worth(const float chroma_gain)
static float _hl_region_worth(const float region_benefit)
const _hl_region_t * region
const dt_dev_pixelpipe_t * pipe
int kernel_highlights_diffuse_color
int kernel_hl_cf_eval_pair
int kernel_hl_cf_pack_joint
int kernel_highlights_1f_clip
int kernel_highlights_bilinear_and_mask_passthrough
int kernel_sparse_chol_final_level
int kernel_hl_cf_fit_pair
int kernel_hl_aniso_splat
int kernel_hl_window_unpack
int kernel_hl_ring_vote_finalize
int kernel_hl_cgrad_write1c
int kernel_hl_aniso_reassemble
int kernel_hl_cf_fit_joint
int kernel_hl_aniso_pyr_down
int kernel_hl_aniso_obs_flags
int kernel_hl_aniso_obs_full
int kernel_hl_knee_apply_interp
int kernel_highlights_guide_laplacians
int kernel_hl_pyr_project
int kernel_hl_knee_joint_reg
int kernel_highlights_normalize_reduce_first_passthrough
int kernel_highlights_count_clipped
int kernel_hl_grad_reduce
int kernel_hl_cg_beta_step
int kernel_hl_vote_reduce
int kernel_hl_pde_scatter
int kernel_hl_cgrad_plateau
int kernel_hl_cg_alpha_step
int kernel_highlights_1f_lch_xtrans
int kernel_hl_cmean_finalize
int kernel_hl_region_benefit
int kernel_hl_fill_jacobi_block
int kernel_highlights_1f_lch_bayer
int kernel_hl_cf_pack_pair
int kernel_hl_cgrad_store
int kernel_highlights_remosaic_and_replace
int kernel_hl_cf_eval_deep
int kernel_sparse_chol_fwd_level
int kernel_hl_cfa_jacobi_block
int kernel_hl_region_gather
int kernel_filmic_bspline_horizontal_local
int kernel_hl_ratio_plane
int kernel_highlights_normalize_reduce_first
int kernel_hl_fill_seed_up
int kernel_hl_region_stats
int kernel_hl_knee_pair_reg
int kernel_hl_ratio_cmean_blend
int kernel_hl_cf_pack_deepmask
int kernel_highlights_remosaic_and_replace_passthrough
int kernel_hl_cf_lref_partials
int kernel_highlights_4f_clip
int kernel_highlights_bilinear_and_mask_xtrans
int kernel_hl_aniso_scatter
int kernel_highlights_normalize_reduce_first_xtrans
int kernel_hl_aniso_iter_block
int kernel_interpolate_bilinear
int kernel_hl_region_worth_finalize
int kernel_filmic_bspline_horizontal
int kernel_hl_aniso_tensor
int kernel_hl_fill_jacobi
int kernel_highlights_box_blur
int kernel_hl_cmean_reduce
int kernel_filmic_bspline_vertical
int kernel_hl_reduce_finalize
int kernel_sparse_chol_bwd_level
int kernel_hl_cgrad_guard
int kernel_hl_window_pack
int kernel_hl_mask_to_img1
int kernel_hl_cgrad_reproject
int kernel_highlights_normalize_reduce_second
int kernel_sparse_chol_update_level
int kernel_hl_region_scatter
int kernel_highlights_remosaic_and_replace_xtrans
int kernel_highlights_false_color
int kernel_hl_clip0_rehue
int kernel_highlights_bilinear_and_mask
int kernel_hl_cgrad_share
int kernel_hl_cf_eval_joint
int kernel_hl_cgrad_anchor
int kernel_hl_aniso_weights
int kernel_filmic_bspline_vertical_local
int kernel_hl_cgrad_hole1c
int kernel_hl_cfa_weights
dt_iop_highlights_mode_t mode
dt_atrous_wavelets_scales_t scales
typedef double((*spd)(unsigned long int wavelength, double TempK))