![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#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 struct dt_drawlayer_brush_pixel_eval_t dt_drawlayer_brush_pixel_eval_t |
| typedef struct dt_drawlayer_sprinkle_preview_t dt_drawlayer_sprinkle_preview_t |
|
inlinestatic |
Bilinear RGBA sample from float buffer.
Multi-tap smudge source sample with directional jitter.
| motion_dx | Motion X used to orient anisotropic taps. |
| motion_dy | Motion Y used to orient anisotropic taps. |
|
static |
Apply smudge mode for one pixel and update carried sample.
References _clamp01(), _smudge_deposit_alpha(), dt_drawlayer_paint_runtime_get_smudge_pickup(), dt_drawlayer_paint_runtime_have_smudge_pickup(), dt_drawlayer_paint_runtime_smudge_pixels(), dt_drawlayer_paint_runtime_smudge_width(), dt_simd_set1(), dt_store_simd(), height, dt_drawlayer_brush_dab_t::opacity, view(), width, and x.
Referenced by dt_drawlayer_brush_rasterize().
|
static |
Build immutable per-dab raster view from stroke runtime state.
References _clamp01(), _sprinkle_octave_weights(), dt_drawlayer_paint_stroke_t::bounds, dt_drawlayer_brush_dab_t::dir_x, dt_drawlayer_brush_dab_t::dir_y, DT_DRAWLAYER_BRUSH_MODE_ERASE, DT_DRAWLAYER_BRUSH_MODE_PAINT, FALSE, dt_drawlayer_brush_dab_t::mode, dt_drawlayer_damaged_rect_t::nw, dt_drawlayer_brush_dab_t::radius, dt_drawlayer_damaged_rect_t::se, dt_drawlayer_brush_dab_t::sprinkle_coarseness, dt_drawlayer_brush_dab_t::sprinkle_size, dt_drawlayer_brush_dab_t::sprinkles, dt_drawlayer_brush_dab_t::stroke_batch, TRUE, dt_drawlayer_damaged_rect_t::valid, view(), dt_drawlayer_brush_dab_t::x, and dt_drawlayer_brush_dab_t::y.
Referenced by dt_drawlayer_brush_rasterize().
Stable scalar hash in [0,1] from precomputed cell seed.
References splitmix32().
Referenced by _cellular_grain_2d().
|
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().
|
inlinestatic |
Clamp scalar to [0,1].
References v.
Referenced by _apply_smudge_stroke_mode(), _brush_runtime_view_from_state(), _cellular_grain_2d(), _prepare_analytic_pixel_context(), _prepare_sprinkle_preview(), _smudge_deposit_alpha(), _sprinkle_octave_weights(), _stroke_flow_alpha(), dt_drawlayer_brush_rasterize(), dt_drawlayer_brush_rasterize_dab_argb8(), and dt_drawlayer_brush_rasterize_dab_rgbaf().
|
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().
|
inlinestatic |
Linear interpolation helper.
Referenced by _sprinkle_octave_weights(), and _stroke_flow_alpha().
|
static |
Compute full analytic per-pixel brush context.
References _clamp01(), _sample_alpha_noise_raw(), _stroke_flow_alpha(), dt_drawlayer_brush_pixel_eval_t::brush_alpha, dt_drawlayer_brush_profile_eval(), FALSE, dt_drawlayer_brush_dab_t::flow, dt_drawlayer_brush_dab_t::opacity, dt_drawlayer_brush_pixel_eval_t::profile, dt_drawlayer_brush_pixel_eval_t::src_alpha, dt_drawlayer_brush_pixel_eval_t::stroke_alpha, dt_drawlayer_brush_pixel_eval_t::stroke_old_alpha, view(), and x.
Referenced by dt_drawlayer_brush_rasterize().
|
static |
Build blur gather color for current dab footprint.
References dt_drawlayer_brush_profile_eval(), dt_simd_set1(), FALSE, TRUE, view(), width, and x.
Referenced by dt_drawlayer_brush_rasterize().
|
inlinestatic |
References _clamp01(), _sprinkle_noise_at_pixel_precomputed(), _sprinkle_octave_weights(), dt_drawlayer_sprinkle_preview_t::enabled, FALSE, dt_drawlayer_sprinkle_preview_t::gain, dt_drawlayer_sprinkle_preview_t::scale, dt_drawlayer_sprinkle_preview_t::seed0, dt_drawlayer_sprinkle_preview_t::seed1, dt_drawlayer_sprinkle_preview_t::seed2, dt_drawlayer_brush_dab_t::sprinkle_coarseness, dt_drawlayer_brush_dab_t::sprinkle_size, dt_drawlayer_brush_dab_t::sprinkles, dt_drawlayer_sprinkle_preview_t::strength, dt_drawlayer_brush_dab_t::stroke_batch, TRUE, dt_drawlayer_sprinkle_preview_t::w0, dt_drawlayer_sprinkle_preview_t::w1, and dt_drawlayer_sprinkle_preview_t::w2.
Referenced by dt_drawlayer_brush_rasterize_dab_argb8(), and dt_drawlayer_brush_rasterize_dab_rgbaf().
|
inlinestatic |
Resolve multiplicative alpha noise at one pixel.
References _sprinkle_noise_at_pixel_precomputed(), and view().
Referenced by _estimate_alpha_noise_gain(), and _prepare_analytic_pixel_context().
|
inlinestatic |
References _sprinkle_noise_at_pixel_precomputed(), dt_drawlayer_sprinkle_preview_t::enabled, dt_drawlayer_sprinkle_preview_t::gain, dt_drawlayer_sprinkle_preview_t::scale, dt_drawlayer_sprinkle_preview_t::seed0, dt_drawlayer_sprinkle_preview_t::seed1, dt_drawlayer_sprinkle_preview_t::seed2, dt_drawlayer_sprinkle_preview_t::strength, dt_drawlayer_sprinkle_preview_t::w0, dt_drawlayer_sprinkle_preview_t::w1, and dt_drawlayer_sprinkle_preview_t::w2.
Referenced by dt_drawlayer_brush_rasterize_dab_argb8(), and dt_drawlayer_brush_rasterize_dab_rgbaf().
|
inlinestatic |
Resolve effective smudge deposit alpha for one pixel.
References _clamp01().
Referenced by _apply_smudge_stroke_mode().
|
inlinestatic |
|
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().
|
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().
|
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().
| 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.
Rasterize one dab into a float RGBA buffer.
Assumes caller already converted coordinates to layer space.
References _apply_smudge_stroke_mode(), _brush_runtime_view_from_state(), _clamp01(), _estimate_alpha_noise_gain(), _prepare_analytic_pixel_context(), _prepare_blur_context(), dt_drawlayer_brush_runtime_view_t::alpha_noise_gain, dt_drawlayer_paint_stroke_t::bounds, DT_DRAWLAYER_BRUSH_MODE_BLUR, DT_DRAWLAYER_BRUSH_MODE_ERASE, DT_DRAWLAYER_BRUSH_MODE_PAINT, DT_DRAWLAYER_BRUSH_MODE_SMUDGE, dt_drawlayer_paint_runtime_ensure_smudge_pixels(), dt_drawlayer_paint_runtime_prepare_dab_context(), dt_simd_set1(), dt_store_simd(), FALSE, dt_drawlayer_brush_dab_t::flow, height, dt_drawlayer_cache_patch_t::height, dt_drawlayer_brush_dab_t::opacity, dt_drawlayer_cache_patch_t::pixels, dt_drawlayer_brush_dab_t::radius, dt_drawlayer_damaged_rect_t::se, dt_drawlayer_brush_pixel_eval_t::src_alpha, dt_drawlayer_brush_pixel_eval_t::stroke_alpha, dt_drawlayer_brush_pixel_eval_t::stroke_old_alpha, TRUE, view(), width, dt_drawlayer_cache_patch_t::width, x, dt_drawlayer_cache_patch_t::x, and dt_drawlayer_cache_patch_t::y.
Referenced by dt_drawlayer_paint_rasterize_segment_to_buffer().
| 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.
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().
| 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.
| dab | Input dab descriptor. |
| rgba | Destination float RGBA buffer (width*height*4), filled in linear display RGB. |
| width | Surface width. |
| height | Surface height. |
| center_x | Dab center X in surface coordinates. |
| center_y | Dab center Y in surface coordinates. |
| opacity_multiplier | Additional UI-time opacity scalar in [0,1]. |
| background_rgb | Opaque linear RGB background color, or NULL for white. |
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().