Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
highlights.c File Reference
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "bauhaus/bauhaus.h"
#include "common/box_filters.h"
#include "common/bspline.h"
#include "common/opencl.h"
#include "common/imagebuf.h"
#include "common/fast_guided_filter.h"
#include "control/control.h"
#include "develop/develop.h"
#include "develop/imageop.h"
#include "develop/imageop_math.h"
#include "develop/imageop_gui.h"
#include "develop/noise_generator.h"
#include "develop/tiling.h"
#include "gui/gtk.h"
#include "iop/iop_api.h"
#include <gtk/gtk.h>
#include <inttypes.h>
+ Include dependency graph for highlights.c:

Data Structures

struct  dt_iop_highlights_params_t
 
struct  dt_iop_highlights_gui_data_t
 
struct  dt_iop_highlights_global_data_t
 

Macros

#define MAX_NUM_SCALES   12
 
#define REDUCESIZE   64
 
#define DS_FACTOR   4
 
#define DEBUG_DUMP_PFM   0
 
#define SQRT3   1.7320508075688772935274463415058723669L
 
#define SQRT12   3.4641016151377545870548926830117447339L
 

Typedefs

typedef enum dt_iop_highlights_mode_t dt_iop_highlights_mode_t
 
typedef enum dt_atrous_wavelets_scales_t dt_atrous_wavelets_scales_t
 
typedef struct dt_iop_highlights_params_t dt_iop_highlights_params_t
 
typedef struct dt_iop_highlights_gui_data_t dt_iop_highlights_gui_data_t
 
typedef dt_iop_highlights_params_t dt_iop_highlights_data_t
 
typedef struct dt_iop_highlights_global_data_t dt_iop_highlights_global_data_t
 
typedef enum diffuse_reconstruct_variant_t diffuse_reconstruct_variant_t
 

Enumerations

enum  dt_iop_highlights_mode_t {
  DT_IOP_HIGHLIGHTS_CLIP = 0 ,
  DT_IOP_HIGHLIGHTS_LCH = 1 ,
  DT_IOP_HIGHLIGHTS_INPAINT = 2 ,
  DT_IOP_HIGHLIGHTS_LAPLACIAN = 3
}
 
enum  dt_atrous_wavelets_scales_t {
  WAVELETS_1_SCALE = 0 ,
  WAVELETS_2_SCALE = 1 ,
  WAVELETS_3_SCALE = 2 ,
  WAVELETS_4_SCALE = 3 ,
  WAVELETS_5_SCALE = 4 ,
  WAVELETS_6_SCALE = 5 ,
  WAVELETS_7_SCALE = 6 ,
  WAVELETS_8_SCALE = 7 ,
  WAVELETS_9_SCALE = 8 ,
  WAVELETS_10_SCALE = 9 ,
  WAVELETS_11_SCALE = 10 ,
  WAVELETS_12_SCALE = 11
}
 
enum  diffuse_reconstruct_variant_t {
  DIFFUSE_RECONSTRUCT_RGB = 0 ,
  DIFFUSE_RECONSTRUCT_CHROMA
}
 
enum  wavelets_scale_t {
  ANY_SCALE = 1 << 0 ,
  FIRST_SCALE = 1 << 1 ,
  LAST_SCALE = 1 << 2
}
 

Functions

const char * name ()
 
const char ** description (struct dt_iop_module_t *self)
 
int default_group ()
 
int flags ()
 
int default_colorspace (dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece)
 
void output_format (dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece, dt_iop_buffer_dsc_t *dsc)
 
int legacy_params (dt_iop_module_t *self, const void *const old_params, const int old_version, void *new_params, const int new_version)
 
void tiling_callback (struct dt_iop_module_t *self, const struct dt_dev_pixelpipe_t *pipe, const struct dt_dev_pixelpipe_iop_t *piece, struct dt_develop_tiling_t *tiling)
 
static float interp_pix_xtrans (const int ratio_next, const ssize_t offset_next, const float clip0, const float clip_next, const float *const in, const float *const ratios)
 
static void interpolate_color_xtrans (const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, int dim, int dir, int other, const float *const clip, const uint8_t(*const xtrans)[6], const int pass)
 
static void interpolate_color (const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_out, int dim, int dir, int other, const float *clip, const uint32_t filters, const int pass)
 
static void process_lch_bayer (dt_iop_module_t *self, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const float clip)
 
static void process_lch_xtrans (dt_iop_module_t *self, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const float clip)
 
static void _interpolate_and_mask (const float *const restrict input, float *const restrict interpolated, float *const restrict clipping_mask, const dt_aligned_pixel_t clips, const dt_aligned_pixel_t wb, const uint32_t filters, const size_t width, const size_t height)
 
static void _compute_laplacian_normalization (const float *const restrict input, const dt_iop_roi_t *const roi_in, const uint32_t filters, const uint8_t(*const xtrans)[6], dt_aligned_pixel_t normalization)
 
static void _build_xtrans_bilinear_lookup (int32_t lookup[6][6][32], const dt_iop_roi_t *const roi_in, const uint8_t(*const xtrans)[6])
 
static void _interpolate_and_mask_xtrans (const float *const restrict input, float *const restrict interpolated, float *const restrict clipping_mask, const dt_aligned_pixel_t clips, const dt_aligned_pixel_t wb, const dt_iop_roi_t *const roi_in, const int32_t lookup[6][6][32], const uint8_t(*const xtrans)[6], const size_t width, const size_t height)
 
static void _remosaic_and_replace (const float *const restrict input, const float *const restrict interpolated, const float *const restrict clipping_mask, float *const restrict output, const dt_aligned_pixel_t wb, const uint32_t filters, const size_t width, const size_t height)
 
static void _remosaic_and_replace_xtrans (const float *const restrict input, const float *const restrict interpolated, const float *const restrict clipping_mask, float *const restrict output, const dt_aligned_pixel_t wb, const dt_iop_roi_t *const roi_in, const uint8_t(*const xtrans)[6], const size_t width, const size_t height)
 
static uint8_t scale_type (const int s, const int scales)
 
static void guide_laplacians (const float *const restrict high_freq, const float *const restrict low_freq, const float *const restrict clipping_mask, float *const restrict output, const size_t width, const size_t height, const int mult, const float noise_level, const int salt, const uint8_t scale, const float radius_sq)
 
static void heat_PDE_diffusion (const float *const restrict high_freq, const float *const restrict low_freq, const float *const restrict clipping_mask, float *const restrict output, const size_t width, const size_t height, const int mult, const uint8_t scale, const float first_order_factor)
 
static int wavelets_process (const float *const restrict in, float *const restrict reconstructed, const float *const restrict clipping_mask, const size_t width, const size_t height, const int scales, float *const restrict HF, float *const restrict LF_odd, float *const restrict LF_even, const diffuse_reconstruct_variant_t variant, const float noise_level, const int salt, const float first_order_factor)
 
static int process_laplacian_bayer (struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const restrict ivoid, void *const restrict ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const dt_aligned_pixel_t clips)
 
static int process_laplacian_xtrans (struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const restrict ivoid, void *const restrict ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const dt_aligned_pixel_t clips)
 
static void process_clip (const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const float clip)
 
static void process_visualize (const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out, const uint32_t filters, dt_iop_highlights_data_t *data)
 
int process (struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, const void *const ivoid, void *const ovoid)
 
void commit_params (struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
 
static gboolean enable (dt_image_t *image)
 
gboolean force_enable (struct dt_iop_module_t *self, const gboolean current_state)
 
void init_global (dt_iop_module_so_t *module)
 
void cleanup_global (dt_iop_module_so_t *module)
 
void init_pipe (struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
 
void cleanup_pipe (struct dt_iop_module_t *self, dt_dev_pixelpipe_t *pipe, dt_dev_pixelpipe_iop_t *piece)
 
void gui_changed (dt_iop_module_t *self, GtkWidget *w, void *previous)
 
void gui_update (struct dt_iop_module_t *self)
 Refresh GUI controls from current params and configuration.
 
void reload_defaults (dt_iop_module_t *module)
 
static void _visualize_callback (GtkWidget *quad, gpointer user_data)
 
void gui_focus (struct dt_iop_module_t *self, gboolean in)
 
void gui_init (struct dt_iop_module_t *self)
 

Macro Definition Documentation

◆ DEBUG_DUMP_PFM

#define DEBUG_DUMP_PFM   0

◆ DS_FACTOR

#define DS_FACTOR   4

◆ MAX_NUM_SCALES

#define MAX_NUM_SCALES   12

◆ REDUCESIZE

#define REDUCESIZE   64

◆ SQRT12

#define SQRT12   3.4641016151377545870548926830117447339L

◆ SQRT3

#define SQRT3   1.7320508075688772935274463415058723669L

Typedef Documentation

◆ diffuse_reconstruct_variant_t

◆ dt_atrous_wavelets_scales_t

◆ dt_iop_highlights_data_t

◆ dt_iop_highlights_global_data_t

◆ dt_iop_highlights_gui_data_t

◆ dt_iop_highlights_mode_t

◆ dt_iop_highlights_params_t

Enumeration Type Documentation

◆ diffuse_reconstruct_variant_t

Enumerator
DIFFUSE_RECONSTRUCT_RGB 
DIFFUSE_RECONSTRUCT_CHROMA 

◆ dt_atrous_wavelets_scales_t

Enumerator
WAVELETS_1_SCALE 
WAVELETS_2_SCALE 
WAVELETS_3_SCALE 
WAVELETS_4_SCALE 
WAVELETS_5_SCALE 
WAVELETS_6_SCALE 
WAVELETS_7_SCALE 
WAVELETS_8_SCALE 
WAVELETS_9_SCALE 
WAVELETS_10_SCALE 
WAVELETS_11_SCALE 
WAVELETS_12_SCALE 

◆ dt_iop_highlights_mode_t

Enumerator
DT_IOP_HIGHLIGHTS_CLIP 
DT_IOP_HIGHLIGHTS_LCH 
DT_IOP_HIGHLIGHTS_INPAINT 
DT_IOP_HIGHLIGHTS_LAPLACIAN 

◆ wavelets_scale_t

Enumerator
ANY_SCALE 
FIRST_SCALE 
LAST_SCALE 

Function Documentation

◆ _build_xtrans_bilinear_lookup()

static void _build_xtrans_bilinear_lookup ( int32_t  lookup[6][6][32],
const dt_iop_roi_t *const  roi_in,
const uint8_t(*)  xtrans[6] 
)
static

Build the X-Trans bilinear interpolation lookup for the current ROI phase.

The lookup keeps the contributing 3x3 neighbours explicit for each position of the 6x6 X-Trans period so CPU and OpenCL guided-laplacian paths start from the same simple bilinear reconstruction.

References c, f, FCxtrans(), lookup(), row, weight(), and x.

Referenced by process_laplacian_xtrans().

◆ _compute_laplacian_normalization()

static void _compute_laplacian_normalization ( const float *const restrict  input,
const dt_iop_roi_t *const  roi_in,
const uint32_t  filters,
const uint8_t(*)  xtrans[6],
dt_aligned_pixel_t  normalization 
)
static

Compute channel normalization factors from the current raw ROI.

Guided Laplacians only needs a relative RGB normalization before the temporary bilinear reconstruction. Using the average measured value of each CFA color in the current tile keeps the normalization explicit and local to the data being reconstructed, instead of relying on the white balance declared upstream.

References ALPHA, BLUE, c, FC(), FCxtrans(), GREEN, dt_iop_roi_t::height, i, RED, value, and dt_iop_roi_t::width.

Referenced by process_laplacian_bayer(), and process_laplacian_xtrans().

◆ _interpolate_and_mask()

static void _interpolate_and_mask ( const float *const restrict  input,
float *const restrict  interpolated,
float *const restrict  clipping_mask,
const dt_aligned_pixel_t  clips,
const dt_aligned_pixel_t  wb,
const uint32_t  filters,
const size_t  width,
const size_t  height 
)
static

References B, BLUE, c, FC(), for_each_channel, GREEN, height, i, R, RED, RGB, sqf(), and width.

Referenced by process_laplacian_bayer().

◆ _interpolate_and_mask_xtrans()

static void _interpolate_and_mask_xtrans ( const float *const restrict  input,
float *const restrict  interpolated,
float *const restrict  clipping_mask,
const dt_aligned_pixel_t  clips,
const dt_aligned_pixel_t  wb,
const dt_iop_roi_t *const  roi_in,
const int32_t  lookup[6][6][32],
const uint8_t(*)  xtrans[6],
const size_t  width,
const size_t  height 
)
static

Bilinearly demosaic the X-Trans raw mosaic and record clipped colors.

Guided Laplacians operates on temporary RGB data. For X-Trans we use the same lightweight bilinear neighbourhood as the linear VNG stage so the diffusion begins from a simple and explicit reconstruction.

References ALPHA, BLUE, c, f, FCxtrans(), for_each_channel, GREEN, height, i, lookup(), MAX, MIN, RED, RGB, sqf(), value, width, and x.

Referenced by process_laplacian_xtrans().

◆ _remosaic_and_replace()

static void _remosaic_and_replace ( const float *const restrict  input,
const float *const restrict  interpolated,
const float *const restrict  clipping_mask,
float *const restrict  output,
const dt_aligned_pixel_t  wb,
const uint32_t  filters,
const size_t  width,
const size_t  height 
)
static

References ALPHA, c, FC(), height, i, and width.

Referenced by process_laplacian_bayer().

◆ _remosaic_and_replace_xtrans()

static void _remosaic_and_replace_xtrans ( const float *const restrict  input,
const float *const restrict  interpolated,
const float *const restrict  clipping_mask,
float *const restrict  output,
const dt_aligned_pixel_t  wb,
const dt_iop_roi_t *const  roi_in,
const uint8_t(*)  xtrans[6],
const size_t  width,
const size_t  height 
)
static

Reproject the reconstructed RGB back onto the X-Trans mosaic.

References ALPHA, c, FCxtrans(), height, i, and width.

Referenced by process_laplacian_xtrans().

◆ _visualize_callback()

◆ cleanup_global()

◆ cleanup_pipe()

void cleanup_pipe ( struct dt_iop_module_t self,
dt_dev_pixelpipe_t pipe,
dt_dev_pixelpipe_iop_t piece 
)

◆ commit_params()

◆ default_colorspace()

int default_colorspace ( dt_iop_module_t self,
dt_dev_pixelpipe_t pipe,
const dt_dev_pixelpipe_iop_t piece 
)

◆ default_group()

int default_group ( )

References IOP_GROUP_REPAIR.

◆ description()

const char ** description ( struct dt_iop_module_t self)

◆ enable()

◆ flags()

int flags ( )

◆ force_enable()

gboolean force_enable ( struct dt_iop_module_t self,
const gboolean  current_state 
)

◆ gui_changed()

◆ gui_focus()

◆ gui_init()

◆ gui_update()

◆ guide_laplacians()

static void guide_laplacians ( const float *const restrict  high_freq,
const float *const restrict  low_freq,
const float *const restrict  clipping_mask,
float *const restrict  output,
const size_t  width,
const size_t  height,
const int  mult,
const float  noise_level,
const int  salt,
const uint8_t  scale,
const float  radius_sq 
)
inlinestatic

◆ heat_PDE_diffusion()

static void heat_PDE_diffusion ( const float *const restrict  high_freq,
const float *const restrict  low_freq,
const float *const restrict  clipping_mask,
float *const restrict  output,
const size_t  width,
const size_t  height,
const int  mult,
const uint8_t  scale,
const float  first_order_factor 
)
inlinestatic

◆ init_global()

◆ init_pipe()

◆ interp_pix_xtrans()

static float interp_pix_xtrans ( const int  ratio_next,
const ssize_t  offset_next,
const float  clip0,
const float  clip_next,
const float *const  in,
const float *const  ratios 
)
inlinestatic

◆ interpolate_color()

static void interpolate_color ( const void *const  ivoid,
void *const  ovoid,
const dt_iop_roi_t *const  roi_out,
int  dim,
int  dir,
int  other,
const float *  clip,
const uint32_t  filters,
const int  pass 
)
inlinestatic

References FC(), dt_iop_roi_t::height, i, out, and dt_iop_roi_t::width.

Referenced by process().

◆ interpolate_color_xtrans()

static void interpolate_color_xtrans ( const void *const  ivoid,
void *const  ovoid,
const dt_iop_roi_t *const  roi_in,
const dt_iop_roi_t *const  roi_out,
int  dim,
int  dir,
int  other,
const float *const  clip,
const uint8_t(*)  xtrans[6],
const int  pass 
)
inlinestatic

◆ legacy_params()

int legacy_params ( dt_iop_module_t self,
const void *const  old_params,
const int  old_version,
void new_params,
const int  new_version 
)

◆ name()

const char * name ( )

Referenced by wavelets_process().

◆ output_format()

void output_format ( dt_iop_module_t self,
dt_dev_pixelpipe_t pipe,
dt_dev_pixelpipe_iop_t piece,
dt_iop_buffer_dsc_t dsc 
)

◆ process()

◆ process_clip()

static void process_clip ( const dt_dev_pixelpipe_iop_t piece,
const void *const  ivoid,
void *const  ovoid,
const dt_iop_roi_t *const  roi_in,
const dt_iop_roi_t *const  roi_out,
const float  clip 
)
static

◆ process_laplacian_bayer()

◆ process_laplacian_xtrans()

◆ process_lch_bayer()

static void process_lch_bayer ( dt_iop_module_t self,
const dt_dev_pixelpipe_iop_t piece,
const void *const  ivoid,
void *const  ovoid,
const dt_iop_roi_t *const  roi_in,
const dt_iop_roi_t *const  roi_out,
const float  clip 
)
static

◆ process_lch_xtrans()

static void process_lch_xtrans ( dt_iop_module_t self,
const dt_dev_pixelpipe_iop_t piece,
const void *const  ivoid,
void *const  ovoid,
const dt_iop_roi_t *const  roi_in,
const dt_iop_roi_t *const  roi_out,
const float  clip 
)
static

◆ process_visualize()

static void process_visualize ( const dt_dev_pixelpipe_iop_t piece,
const void *const  ivoid,
void *const  ovoid,
const dt_iop_roi_t *const  roi_in,
const dt_iop_roi_t *const  roi_out,
const uint32_t  filters,
dt_iop_highlights_data_t data 
)
static

◆ reload_defaults()

◆ scale_type()

static uint8_t scale_type ( const int  s,
const int  scales 
)
static

References ANY_SCALE, FIRST_SCALE, and LAST_SCALE.

Referenced by wavelets_process().

◆ tiling_callback()

◆ wavelets_process()

static int wavelets_process ( const float *const restrict  in,
float *const restrict  reconstructed,
const float *const restrict  clipping_mask,
const size_t  width,
const size_t  height,
const int  scales,
float *const restrict  HF,
float *const restrict  LF_odd,
float *const restrict  LF_even,
const diffuse_reconstruct_variant_t  variant,
const float  noise_level,
const int  salt,
const float  first_order_factor 
)
inlinestatic