Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
brush.c File Reference
#include "iop/drawlayer/brush.h"
#include "iop/drawlayer/cache.h"
#include "iop/drawlayer/paint.h"
#include "iop/drawlayer/brush_profile.h"
#include "common/darktable.h"
#include "develop/noise_generator.h"
#include <math.h>
#include <string.h>
+ Include dependency graph for iop/drawlayer/brush.c:

Data Structures

struct  dt_drawlayer_sprinkle_preview_t
 
struct  dt_drawlayer_brush_runtime_view_t
 
struct  dt_drawlayer_brush_pixel_eval_t
 

Typedefs

typedef struct dt_drawlayer_sprinkle_preview_t dt_drawlayer_sprinkle_preview_t
 
typedef struct dt_drawlayer_brush_runtime_view_t dt_drawlayer_brush_runtime_view_t
 
typedef struct dt_drawlayer_brush_pixel_eval_t dt_drawlayer_brush_pixel_eval_t
 

Functions

static float _clamp01 (const float v)
 Clamp scalar to [0,1].
 
static float _lerpf (const float a, const float b, const float t)
 Linear interpolation helper.
 
static float _cell_hash01_from_seed (const uint64_t cell_seed, const uint64_t salt)
 Stable scalar hash in [0,1] from precomputed cell seed.
 
static float _cellular_grain_2d (const uint64_t seed, const float x, const float y)
 Grain-like round cellular field. Peaks at grain centers, falls off radially.
 
static void _sprinkle_octave_weights (const float coarseness, float *w0, float *w1, float *w2)
 Resolve octave weights from coarseness control.
 
static float _sprinkle_noise_at_pixel_precomputed (const float px, const float py, const float scale, const float strength, const float w0, const float w1, const float w2, const uint64_t seed0, const uint64_t seed1, const uint64_t seed2)
 Evaluate sprinkle modulation from precomputed dab constants.
 
static void _prepare_sprinkle_preview (const dt_drawlayer_brush_dab_t *dab, const float center_x, const float center_y, const float radius, dt_drawlayer_sprinkle_preview_t *preview)
 
static float _sample_sprinkle_preview (const dt_drawlayer_sprinkle_preview_t *preview, const float px, const float py)
 
static gboolean _brush_runtime_view_from_state (const dt_drawlayer_paint_stroke_t *stroke, const dt_drawlayer_brush_dab_t *dab, const int origin_x, const int origin_y, const float scale, dt_drawlayer_brush_runtime_view_t *view)
 Build immutable per-dab raster view from stroke runtime state.
 
static float _sample_alpha_noise_raw (const dt_drawlayer_brush_dab_t *dab, const dt_drawlayer_brush_runtime_view_t *view, const int pixel_x, const int pixel_y)
 Resolve multiplicative alpha noise at one pixel.
 
static float _estimate_alpha_noise_gain (const dt_drawlayer_brush_dab_t *dab, const dt_drawlayer_brush_runtime_view_t *view)
 Estimate per-dab texture gain so noise preserves average opacity across samples.
 
static float _stroke_flow_alpha (const dt_drawlayer_brush_dab_t *dab, const float opacity, const float flow, const float sample_opacity_scale, const float profile, const float brush_alpha, const float old_alpha, const float stroke_old_alpha, const gboolean have_stroke_alpha)
 Compute per-pixel source alpha from opacity/flow model.
 
static gboolean _prepare_analytic_pixel_context (const dt_drawlayer_brush_runtime_view_t *view, const float sample_opacity_scale, float *stroke_mask, const int stroke_mask_width, const int stroke_mask_height, const int x, const int y, const float old_alpha, dt_drawlayer_brush_pixel_eval_t *pixel_eval)
 Compute full analytic per-pixel brush context.
 
static gboolean _prepare_blur_context (dt_aligned_pixel_simd_t *blur_px, const float *buffer, const int width, const dt_drawlayer_brush_runtime_view_t *view)
 Build blur gather color for current dab footprint.
 
static float _smudge_hash_signed (const int x, const int y, const int lane)
 Stable signed pseudo-random helper in [-1,1].
 
static __attribute__ ((always_inline))
 Bilinear RGBA sample from float buffer.
 
static float _smudge_deposit_alpha (const float src_alpha, const float carried_alpha, const float opacity)
 Resolve effective smudge deposit alpha for one pixel.
 
static dt_aligned_pixel_simd_t _apply_smudge_stroke_mode (float *buffer, const int width, const int height, dt_drawlayer_paint_stroke_t *runtime_private, const dt_drawlayer_brush_runtime_view_t *view, const float scale, const int origin_x, const int origin_y, const int x, const int y, const float src_alpha, const dt_aligned_pixel_simd_t old_px)
 Apply smudge mode for one pixel and update carried sample.
 
gboolean dt_drawlayer_brush_rasterize (dt_drawlayer_cache_patch_t *patch, const float scale, const dt_drawlayer_brush_dab_t *dab, const float sample_opacity_scale, dt_drawlayer_cache_patch_t *stroke_mask, dt_drawlayer_paint_stroke_t *runtime_private)
 Public dab rasterization entry point.
 
gboolean dt_drawlayer_brush_rasterize_dab_argb8 (const dt_drawlayer_brush_dab_t *dab, uint8_t *argb, const int width, const int height, const int stride, const float center_x, const float center_y, const float opacity_multiplier)
 Render one dab to 8-bit ARGB surface for GUI cursor preview.
 
gboolean dt_drawlayer_brush_rasterize_dab_rgbaf (const dt_drawlayer_brush_dab_t *dab, float *rgba, const int width, const int height, const float center_x, const float center_y, const float opacity_multiplier, const float background_rgb[3])
 Rasterize a single dab preview in linear float RGBA over an opaque background.
 

Typedef Documentation

◆ dt_drawlayer_brush_pixel_eval_t

◆ dt_drawlayer_brush_runtime_view_t

◆ dt_drawlayer_sprinkle_preview_t

Function Documentation

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Bilinear RGBA sample from float buffer.

Multi-tap smudge source sample with directional jitter.

Note
Coordinates are clamped to valid image bounds.
Parameters
motion_dxMotion X used to orient anisotropic taps.
motion_dyMotion Y used to orient anisotropic taps.

References dt_simd_set1(), fx, height, MIN, width, and x.

◆ _apply_smudge_stroke_mode()

static dt_aligned_pixel_simd_t _apply_smudge_stroke_mode ( float *  buffer,
const int  width,
const int  height,
dt_drawlayer_paint_stroke_t runtime_private,
const dt_drawlayer_brush_runtime_view_t view,
const float  scale,
const int  origin_x,
const int  origin_y,
const int  x,
const int  y,
const float  src_alpha,
const dt_aligned_pixel_simd_t  old_px 
)
static

◆ _brush_runtime_view_from_state()

◆ _cell_hash01_from_seed()

static float _cell_hash01_from_seed ( const uint64_t  cell_seed,
const uint64_t  salt 
)
inlinestatic

Stable scalar hash in [0,1] from precomputed cell seed.

References splitmix32().

Referenced by _cellular_grain_2d().

◆ _cellular_grain_2d()

static float _cellular_grain_2d ( const uint64_t  seed,
const float  x,
const float  y 
)
inlinestatic

Grain-like round cellular field. Peaks at grain centers, falls off radially.

References _cell_hash01_from_seed(), _clamp01(), and x.

Referenced by _sprinkle_noise_at_pixel_precomputed().

◆ _clamp01()

◆ _estimate_alpha_noise_gain()

static float _estimate_alpha_noise_gain ( const dt_drawlayer_brush_dab_t dab,
const dt_drawlayer_brush_runtime_view_t view 
)
inlinestatic

Estimate per-dab texture gain so noise preserves average opacity across samples.

References _sample_alpha_noise_raw(), and view().

Referenced by dt_drawlayer_brush_rasterize().

◆ _lerpf()

static float _lerpf ( const float  a,
const float  b,
const float  t 
)
inlinestatic

Linear interpolation helper.

References a, b, and t.

Referenced by _sprinkle_octave_weights(), and _stroke_flow_alpha().

◆ _prepare_analytic_pixel_context()

static gboolean _prepare_analytic_pixel_context ( const dt_drawlayer_brush_runtime_view_t view,
const float  sample_opacity_scale,
float *  stroke_mask,
const int  stroke_mask_width,
const int  stroke_mask_height,
const int  x,
const int  y,
const float  old_alpha,
dt_drawlayer_brush_pixel_eval_t pixel_eval 
)
static

◆ _prepare_blur_context()

static gboolean _prepare_blur_context ( dt_aligned_pixel_simd_t *  blur_px,
const float *  buffer,
const int  width,
const dt_drawlayer_brush_runtime_view_t view 
)
static

Build blur gather color for current dab footprint.

Returns
TRUE when footprint contributed at least one weighted sample.

References dt_drawlayer_brush_profile_eval(), dt_simd_set1(), FALSE, TRUE, view(), width, and x.

Referenced by dt_drawlayer_brush_rasterize().

◆ _prepare_sprinkle_preview()

◆ _sample_alpha_noise_raw()

static float _sample_alpha_noise_raw ( const dt_drawlayer_brush_dab_t dab,
const dt_drawlayer_brush_runtime_view_t view,
const int  pixel_x,
const int  pixel_y 
)
inlinestatic

Resolve multiplicative alpha noise at one pixel.

Returns
Texture factor.

References _sprinkle_noise_at_pixel_precomputed(), and view().

Referenced by _estimate_alpha_noise_gain(), and _prepare_analytic_pixel_context().

◆ _sample_sprinkle_preview()

◆ _smudge_deposit_alpha()

static float _smudge_deposit_alpha ( const float  src_alpha,
const float  carried_alpha,
const float  opacity 
)
inlinestatic

Resolve effective smudge deposit alpha for one pixel.

References _clamp01().

Referenced by _apply_smudge_stroke_mode().

◆ _smudge_hash_signed()

static float _smudge_hash_signed ( const int  x,
const int  y,
const int  lane 
)
inlinestatic

Stable signed pseudo-random helper in [-1,1].

References h, and x.

◆ _sprinkle_noise_at_pixel_precomputed()

static float _sprinkle_noise_at_pixel_precomputed ( const float  px,
const float  py,
const float  scale,
const float  strength,
const float  w0,
const float  w1,
const float  w2,
const uint64_t  seed0,
const uint64_t  seed1,
const uint64_t  seed2 
)
inlinestatic

Evaluate sprinkle modulation from precomputed dab constants.

References _cellular_grain_2d(), strength(), w1, w2, and x.

Referenced by _prepare_sprinkle_preview(), _sample_alpha_noise_raw(), and _sample_sprinkle_preview().

◆ _sprinkle_octave_weights()

static void _sprinkle_octave_weights ( const float  coarseness,
float *  w0,
float *  w1,
float *  w2 
)
inlinestatic

Resolve octave weights from coarseness control.

References _clamp01(), _lerpf(), c, t, w1, and w2.

Referenced by _brush_runtime_view_from_state(), and _prepare_sprinkle_preview().

◆ _stroke_flow_alpha()

static float _stroke_flow_alpha ( const dt_drawlayer_brush_dab_t dab,
const float  opacity,
const float  flow,
const float  sample_opacity_scale,
const float  profile,
const float  brush_alpha,
const float  old_alpha,
const float  stroke_old_alpha,
const gboolean  have_stroke_alpha 
)
inlinestatic

Compute per-pixel source alpha from opacity/flow model.

Assumptions:

  • flow uses internal brush convention (see caller conversion),
  • sample_opacity_scale already reflects spacing normalization.

References _clamp01(), _lerpf(), DT_DRAWLAYER_BRUSH_MODE_BLUR, DT_DRAWLAYER_BRUSH_MODE_ERASE, DT_DRAWLAYER_BRUSH_MODE_SMUDGE, dt_drawlayer_brush_dab_t::mode, and void().

Referenced by _prepare_analytic_pixel_context().

◆ dt_drawlayer_brush_rasterize()

◆ dt_drawlayer_brush_rasterize_dab_argb8()

gboolean dt_drawlayer_brush_rasterize_dab_argb8 ( const dt_drawlayer_brush_dab_t dab,
uint8_t *  argb,
const int  width,
const int  height,
const int  stride,
const float  center_x,
const float  center_y,
const float  opacity_multiplier 
)

Render one dab to 8-bit ARGB surface for GUI cursor preview.

Rasterize a single dab preview into ARGB8 for GUI overlays.

Returns
TRUE on success.

References _clamp01(), _prepare_sprinkle_preview(), _sample_sprinkle_preview(), dt_drawlayer_brush_dab_t::display_color, dt_drawlayer_brush_profile_eval(), FALSE, height, dt_drawlayer_brush_dab_t::opacity, dt_drawlayer_brush_dab_t::radius, TRUE, width, and x.

Referenced by _ensure_cursor_stamp_surface().

◆ dt_drawlayer_brush_rasterize_dab_rgbaf()

gboolean dt_drawlayer_brush_rasterize_dab_rgbaf ( const dt_drawlayer_brush_dab_t dab,
float *  rgba,
int  width,
int  height,
float  center_x,
float  center_y,
float  opacity_multiplier,
const float  background_rgb[3] 
)

Rasterize a single dab preview in linear float RGBA over an opaque background.

Parameters
dabInput dab descriptor.
rgbaDestination float RGBA buffer (width*height*4), filled in linear display RGB.
widthSurface width.
heightSurface height.
center_xDab center X in surface coordinates.
center_yDab center Y in surface coordinates.
opacity_multiplierAdditional UI-time opacity scalar in [0,1].
background_rgbOpaque linear RGB background color, or NULL for white.
Returns
TRUE on success, FALSE on invalid inputs.

References _clamp01(), _prepare_sprinkle_preview(), _sample_sprinkle_preview(), dt_drawlayer_brush_dab_t::color, dt_drawlayer_brush_profile_eval(), FALSE, height, i, dt_drawlayer_brush_dab_t::opacity, dt_drawlayer_brush_dab_t::radius, TRUE, width, and x.

Referenced by _render_brush_profile_cell().