Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
dither.c File Reference
#include "widgets/bauhaus.h"
#include "system/macros.h"
#include "system/openmp.h"
#include "system/target_clones.h"
#include "system/mem_alloc.h"
#include "system/simd.h"
#include "common/logging.h"
#include "common/module_versioning.h"
#include "database/database.h"
#include "common/imagebuf.h"
#include "imageio/imageio_core.h"
#include "math/math.h"
#include "common/opencl.h"
#include "pixel/tea.h"
#include "develop/develop.h"
#include "develop/imageop.h"
#include "develop/imageop_math.h"
#include "develop/imageop_gui.h"
#include "gui/presets.h"
#include "iop/iop_api.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <gtk/gtk.h>
#include <inttypes.h>
+ Include dependency graph for dither.c:

Go to the source code of this file.

Data Structures

struct  dt_iop_dither_params_t
 
struct  dt_iop_dither_gui_data_t
 
struct  dt_iop_dither_data_t
 
struct  dt_iop_dither_global_data_t
 

Macros

#define clipnan_pixel_sse   clipnan_pixel
 
#define RIGHT_WT   (7.0f/16.0f)
 
#define DOWNRIGHT_WT   (1.0f/16.0f)
 
#define DOWN_WT   (5.0f/16.0f)
 
#define DOWNLEFT_WT   (3.0f/16.0f)
 
#define PROCESS_PIXEL_FULL(_pixel, inpix)
 
#define PROCESS_PIXEL_LEFT(_pixel, inpix)
 
#define PROCESS_PIXEL_RIGHT(pixel)
 

Typedefs

typedef enum dt_iop_dither_type_t dt_iop_dither_type_t
 
typedef struct dt_iop_dither_params_t dt_iop_dither_params_t
 
typedef struct dt_iop_dither_gui_data_t dt_iop_dither_gui_data_t
 
typedef struct dt_iop_dither_data_t dt_iop_dither_data_t
 
typedef struct dt_iop_dither_global_data_t dt_iop_dither_global_data_t
 

Enumerations

enum  dt_iop_dither_type_t {
  DITHER_RANDOM ,
  DITHER_FS1BIT ,
  DITHER_FS4BIT_GRAY ,
  DITHER_FS8BIT ,
  DITHER_FS16BIT ,
  DITHER_FSAUTO
}
 

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 init_presets (dt_iop_module_so_t *self)
 
void reload_defaults (dt_iop_module_t *module)
 
static float _quantize (const float val, const float f, const float rf)
 
static float _rgb_to_gray (const float *const restrict val)
 
static void nearest_color (float *const restrict val, float *const restrict err, int graymode, const float f, const float rf)
 
static void _diffuse_error (float *const restrict val, const float *const restrict err, const float factor)
 
static float clipnan (const float x)
 
static void clipnan_pixel (float *const restrict out, const float *const restrict in)
 
static __attribute__ ((always_inline))
 
static __DT_CLONE_TARGETS__ void process_floyd_steinberg (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, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
 
static __DT_CLONE_TARGETS__ void process_random (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, const dt_iop_roi_t *const roi_in, const dt_iop_roi_t *const roi_out)
 
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)
 
int process_cl (struct dt_iop_module_t *self, const dt_dev_pixelpipe_t *pipe, const dt_dev_pixelpipe_iop_t *piece, cl_mem dev_in, cl_mem dev_out)
 
void gui_changed (dt_iop_module_t *self, GtkWidget *w, void *previous)
 
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)
 
gboolean runtime_data_hash (struct dt_iop_module_t *self __attribute__((unused)), dt_dev_pixelpipe_t *pipe __attribute__((unused)), const dt_dev_pixelpipe_iop_t *piece __attribute__((unused)))
 
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 init_global (dt_iop_module_so_t *module)
 
void cleanup_global (dt_iop_module_so_t *module)
 
void gui_update (struct dt_iop_module_t *self)
 
void gui_init (struct dt_iop_module_t *self)
 

Macro Definition Documentation

◆ clipnan_pixel_sse

#define clipnan_pixel_sse   clipnan_pixel

Definition at line 260 of file dither.c.

◆ DOWN_WT

#define DOWN_WT   (5.0f/16.0f)

Definition at line 334 of file dither.c.

◆ DOWNLEFT_WT

#define DOWNLEFT_WT   (3.0f/16.0f)

Definition at line 335 of file dither.c.

◆ DOWNRIGHT_WT

#define DOWNRIGHT_WT   (1.0f/16.0f)

Definition at line 333 of file dither.c.

◆ PROCESS_PIXEL_FULL

#define PROCESS_PIXEL_FULL (   _pixel,
  inpix 
)
Value:
{ \
float *const pixel_ = (_pixel); \
nearest_color(pixel_, err, graymode, f, rf); /* quantize pixel */ \
clipnan_pixel(pixel_ + downright,(inpix) + downright); /* prepare downright for first access */ \
_diffuse_error(pixel_ + right, err, RIGHT_WT); /* diffuse quantization error to neighbors */ \
_diffuse_error(pixel_ + downleft, err, DOWNLEFT_WT); \
_diffuse_error(pixel_ + down, err, DOWN_WT); \
_diffuse_error(pixel_ + downright, err, DOWNRIGHT_WT); \
}
const float f
#define RIGHT_WT
Definition dither.c:332
#define DOWNRIGHT_WT
Definition dither.c:333
#define DOWNLEFT_WT
Definition dither.c:335
#define DOWN_WT
Definition dither.c:334
static uint32_t _pixel(cairo_surface_t *surface, const int x, const int y)

◆ PROCESS_PIXEL_LEFT

#define PROCESS_PIXEL_LEFT (   _pixel,
  inpix 
)
Value:
{ \
float *const pixel_ = (_pixel); \
nearest_color(pixel_, err, graymode, f, rf); /* quantize pixel */ \
clipnan_pixel(pixel_ + down,(inpix) + down); /* prepare down for first access */ \
clipnan_pixel(pixel_ + downright,(inpix) + downright); /* prepare downright for first access */ \
_diffuse_error(pixel_ + right, err, RIGHT_WT); /* diffuse quantization error to neighbors */ \
_diffuse_error(pixel_ + down, err, DOWN_WT); \
_diffuse_error(pixel_ + downright, err, DOWNRIGHT_WT); \
}

◆ PROCESS_PIXEL_RIGHT

#define PROCESS_PIXEL_RIGHT (   pixel)
Value:
nearest_color(pixel, err, graymode, f, rf); /* quantize pixel */ \
_diffuse_error(pixel + downleft, err, DOWNLEFT_WT); /* diffuse quantization error to neighbors */ \
_diffuse_error(pixel + down, err, DOWN_WT);
static void nearest_color(float *const restrict val, float *const restrict err, int graymode, const float f, const float rf)
Definition dither.c:196

◆ RIGHT_WT

#define RIGHT_WT   (7.0f/16.0f)

Definition at line 332 of file dither.c.

Typedef Documentation

◆ dt_iop_dither_data_t

◆ dt_iop_dither_global_data_t

◆ dt_iop_dither_gui_data_t

◆ dt_iop_dither_params_t

◆ dt_iop_dither_type_t

Enumeration Type Documentation

◆ dt_iop_dither_type_t

Enumerator
DITHER_RANDOM 
DITHER_FS1BIT 
DITHER_FS4BIT_GRAY 
DITHER_FS8BIT 
DITHER_FS16BIT 
DITHER_FSAUTO 

Definition at line 72 of file dither.c.

Function Documentation

◆ __attribute__()

◆ _diffuse_error()

static void _diffuse_error ( float *const restrict  val,
const float *const restrict  err,
const float  factor 
)
inlinestatic

Definition at line 225 of file dither.c.

References __OMP_SIMD__, and factor.

Referenced by process_floyd_steinberg().

◆ _quantize()

static float _quantize ( const float  val,
const float  f,
const float  rf 
)
inlinestatic

Definition at line 180 of file dither.c.

References f.

Referenced by nearest_color().

◆ _rgb_to_gray()

static float _rgb_to_gray ( const float *const restrict  val)
inlinestatic

Definition at line 190 of file dither.c.

Referenced by nearest_color().

◆ cleanup_global()

◆ cleanup_pipe()

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

Definition at line 637 of file dither.c.

References dt_free_align, and piece.

◆ clipnan()

static float clipnan ( const float  x)
inlinestatic

Definition at line 242 of file dither.c.

References x.

Referenced by clipnan_pixel().

◆ clipnan_pixel()

static void clipnan_pixel ( float *const restrict  out,
const float *const restrict  in 
)
inlinestatic

Definition at line 252 of file dither.c.

References __OMP_SIMD__, clipnan(), and out.

Referenced by process_floyd_steinberg().

◆ commit_params()

◆ default_colorspace()

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

Definition at line 151 of file dither.c.

References IOP_CS_RGB_DISPLAY.

◆ default_group()

int default_group ( )

Definition at line 141 of file dither.c.

References IOP_GROUP_TECHNICAL.

◆ description()

const char ** description ( struct dt_iop_module_t *  self)

Definition at line 132 of file dither.c.

References dt_iop_set_description().

◆ flags()

int flags ( )

Definition at line 146 of file dither.c.

References IOP_FLAGS_ONE_INSTANCE.

◆ gui_changed()

void gui_changed ( dt_iop_module_t *  self,
GtkWidget *  w,
void *  previous 
)

Definition at line 556 of file dither.c.

References DITHER_RANDOM, dt_iop_gui_data(), g, p, and dt_iop_module_t::params.

◆ gui_init()

◆ gui_update()

◆ init_global()

void init_global ( dt_iop_module_so_t *  module)

◆ init_pipe()

void init_pipe ( struct dt_iop_module_t *  self,
dt_dev_pixelpipe_t *  pipe,
dt_dev_pixelpipe_iop_t *  piece 
)

Definition at line 631 of file dither.c.

References dt_calloc_align(), and piece.

◆ init_presets()

◆ name()

const char * name ( )

Definition at line 127 of file dither.c.

◆ nearest_color()

static void nearest_color ( float *const restrict  val,
float *const restrict  err,
int  graymode,
const float  f,
const float  rf 
)
inlinestatic

Definition at line 196 of file dither.c.

References __OMP_SIMD__, _quantize(), _rgb_to_gray(), and f.

Referenced by process_floyd_steinberg().

◆ process()

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 
)

◆ process_cl()

◆ process_floyd_steinberg()

static __DT_CLONE_TARGETS__ void process_floyd_steinberg ( 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,
const dt_iop_roi_t *const  roi_in,
const dt_iop_roi_t *const  roi_out 
)
static

◆ process_random()

◆ reload_defaults()

void reload_defaults ( dt_iop_module_t *  module)

Definition at line 172 of file dither.c.

◆ runtime_data_hash()

gboolean runtime_data_hash ( struct dt_iop_module_t *self   __attribute__(unused),
dt_dev_pixelpipe_t *pipe   __attribute__(unused),
const dt_dev_pixelpipe_iop_t *piece   __attribute__(unused) 
)

Definition at line 624 of file dither.c.

References TRUE.