fx#
effects and adjustments -- crate root lib/fx/lib.rs
fx -- the effect and adjustment kernels: the FXDESC registry, prepare / render on ROIs from
worker threads, deterministic per pixel [src/fx/*.s, inc/fx.inc]
The contract (fx.inc). An application (JFPainter, efftest) runs an effect by
1. copying the source layer (FMT_ARGB, straight alpha) -> FxArgs::src,
2. calling desc.prepare once when it has one (global statistics, LUTs, noise tables):
Ok(Some(aux)) / Ok(None) / Err(ERR_*) -- ERR_CANCEL when the job was cancelled,
3. calling desc.render for many rectangles (ROIs) -- from several worker threads at once
-- until the ROIs cover the area to change; every call gets the aux of step 2,
4. blending the destination back through the selection mask itself
(gfx::straight::lerp_mask_row).
Rules: render writes the destination only inside its ROI (Dst holds exactly those pixels)
and may read the whole source; the result of a pixel depends only on (source, params, aux)
-- never on the ROI split or the thread count (bit-identical); render polls the job's
cancel flag once per row (FxArgs::cancelled) and returns ERR_CANCEL at once. Pixels are
straight ARGB (0xAARRGGBB = bytes B, G, R, A). Random effects use hash32(x, y, seed,
stream), never a sequential generator. FXF_BANDS: render wants full-width row bands (the
runner splits by rows only); FXF_WHOLE: one call over the whole image.
API (the asm records as Rust types):
FxDesc FXDESC: id (FX_*), flags (FXF_*), name (ASCII key), prepare / render (fn
pointers; FXD_FREE is the Drop of the aux), props (FXPROP records), category
(FXC_*), user (free for the registering code, e.g. a plugin index)
FxProp FXPROP: typ (FP_*), dec, slot, flags (FPF_*), name, min, max, def (FP_COLOR:
the f64 bits are the ARGB colour -- color()), def_y (FP_PAN: the y default),
choices (FP_CHOICE keys)
Params the parameter block: FX_NSLOTS u64 slots (i64 for FP_INT / BOOL / CHOICE / SEED,
f64 bits for FP_DEC / ANGLE / PAN, ARGB in the low half for FP_COLOR, raw bytes
for FP_BLOB); defaults(desc, &mut params) fills it
FxArgs FXARGS without the destination: src, ROI x0 y0 x1 y1, params, aux, job (a
Cancel flag: the worker pool's JobCtl, an AtomicBool / AtomicU32), sel (the
selection TMask: statistics may be limited to it)
Dst the destination pixels of one render call: one &mut [u8] per ROI row with the
pixels x0..x1 -- of_surface (one call owns the whole rectangle), tiles (disjoint
rectangles of one surface for parallel calls; the row slices of all of them live
in one caller-owned Vec), strided (rows of a tile buffer), or new (a row list)
Aux Box<dyn Any + Send + Sync>: the result of prepare, read by render (aux::<T>())
registry use_all() registers the built-in groups (menu order), register(group) adds a
group (&'static [FxDesc], e.g. plugin effects), count(), get(i), find(name),
find_id(id), defaults(desc, params)
hash32(x, y, seed, stream) deterministic per-pixel random bits (fx_common.s)
rows(a, dst, f) fx_rows: f(dst_row, src_row, x0, y) for every ROI row
Modules: lut (fx_lut.s), hist (fx_hist.s), adj (fx_adj.s), color (fx_color.s), stylize
(fx_stylize.s), conv (fx_conv.s), lochist (fx_lochist.s), blur (fx_blur.s), artistic
(fx_artistic.s), noise (fx_noise.s), photo (fx_photo.s), object (fx_object.s), warp
(fx_warp.s), perlin (fx_perlin.s), distort (fx_distort.s), render (fx_render.s).
fx crate root#
Re-exports: gfx::tmask::TMask
Re-exports: gfx::Surface
Re-exports: plat::JobCtl
constants (fx.inc)
FX_NSLOTS: usize = 32 // parameter slots per effect
FXF_ADJ: u32 = 1 // adjustment (Korrekturen) rather than effect
FXF_PREPARE: u32 = 2 // has a prepare step (statistics over the source / selection)
FXF_SEED: u32 = 4 // uses a random seed (has an FP_SEED property)
FXF_BANDS: u32 = 8 // render wants full-width row bands
FXF_WHOLE: u32 = 16 // render must get the whole image in one call
FXF_NO_DIALOG: u32 = 32 // applied immediately (e.g. Invert Colors, Sepia)
FXF_SLOW: u32 = 64 // hint: show progress
FXC_ADJUST: u32 = 0
FXC_ARTISTIC: u32 = 1
FXC_BLUR: u32 = 2
FXC_COLOR: u32 = 3
FXC_DISTORT: u32 = 4
FXC_NOISE: u32 = 5
FXC_OBJECT: u32 = 6
FXC_PHOTO: u32 = 7
FXC_RENDER: u32 = 8
FXC_STYLIZE: u32 = 9
FP_INT: u8 = 1 // slot: i64
FP_DEC: u8 = 2 // slot: f64
FP_BOOL: u8 = 3 // slot: i64 0/1
FP_CHOICE: u8 = 4 // slot: i64 index
FP_ANGLE: u8 = 5 // slot: f64 degrees
FP_PAN: u8 = 6 // slots: f64 x, f64 y (normalised -1..1, 0 = centre)
FP_COLOR: u8 = 7 // slot: u32 straight ARGB in the low half
FP_SEED: u8 = 8 // slot: i64 seed
FP_BLOB: u8 = 9 // slots slot .. slot + max - 1 hold raw bytes (default all 0)
FPF_LOG: u8 = 1 // slider maps logarithmically
FX_AUTO_LEVEL: u32 = 1 // Korrekturen
FX_BLACK_WHITE: u32 = 2
FX_BRIGHT_CONTRAST: u32 = 3
FX_CURVES: u32 = 4
FX_EXPOSURE: u32 = 5
FX_HIGHLIGHTS_SHADOWS: u32 = 6
FX_HUE_SATURATION: u32 = 7
FX_INVERT_ALPHA: u32 = 8
FX_INVERT_COLORS: u32 = 9
FX_LEVELS: u32 = 10
FX_POSTERIZE: u32 = 11
FX_SEPIA: u32 = 12
FX_TEMP_TINT: u32 = 13
FX_INK_SKETCH: u32 = 20 // Künstlerisch
FX_OIL_PAINTING: u32 = 21
FX_PENCIL_SKETCH: u32 = 22
FX_BOKEH_BLUR: u32 = 30 // Weichzeichnen
FX_FRAGMENT_BLUR: u32 = 31
FX_GAUSSIAN_BLUR: u32 = 32
FX_MEDIAN: u32 = 33
FX_MOTION_BLUR: u32 = 34
FX_RADIAL_BLUR: u32 = 35
FX_SKETCH_BLUR: u32 = 36
FX_SQUARE_BLUR: u32 = 37
FX_SURFACE_BLUR: u32 = 38
FX_UNFOCUS: u32 = 39
FX_ZOOM_BLUR: u32 = 40
FX_QUANTIZE: u32 = 50 // Farbe
FX_BULGE: u32 = 60 // Verzerren
FX_CRYSTALIZE: u32 = 61
FX_DENTS: u32 = 62
FX_FROSTED_GLASS: u32 = 63
FX_MORPHOLOGY: u32 = 64
FX_PIXELATE: u32 = 65
FX_POLAR_INVERSION: u32 = 66
FX_TILE_REFLECTION: u32 = 67
FX_TWIST: u32 = 68
FX_ADD_NOISE: u32 = 70 // Rauschen
FX_REDUCE_NOISE: u32 = 71
FX_DROP_SHADOW: u32 = 80 // Objekt
FX_GLOW: u32 = 90 // Foto
FX_RED_EYE: u32 = 91
FX_SHARPEN: u32 = 92
FX_SOFTEN_PORTRAIT: u32 = 93
FX_STRAIGHTEN: u32 = 94
FX_VIGNETTE: u32 = 95
FX_CLOUDS: u32 = 100 // Rendern
FX_JULIA: u32 = 101
FX_MANDELBROT: u32 = 102
FX_TURBULENCE: u32 = 103
FX_EDGE_DETECT: u32 = 110 // Stilisieren
FX_EMBOSS: u32 = 111
FX_OUTLINE: u32 = 112
FX_RELIEF: u32 = 113
ERR_NOMEM: i32 = -8
ERR_DIMS: i32 = -12
ERR_CANCEL: i32 = -14
ERR_LIMIT: i32 = -15
type Aux = Box<dyn Any + Send + Sync>the result of prepare (read-only in render; FXD_FREE = its Drop)type PrepareFn = fn(&FxArgs) -> Result<Option<Aux>, i32>FXD_PREPARE: Ok(Some(aux)) / Ok(None) / Err(ERR_*)type RenderFn = fn(&FxArgs, &mut Dst) -> i32FXD_RENDER: 0 / ERR_CANCEL / ERR_*struct FxDescan effect (FXDESC)id: u32flags: u32name: &'static strprepare: Option<PrepareFn>render: RenderFnprops: &'static [FxProp]category: u32user: usize-- free for the code that registers the group (0 for the built-in effects)
struct FxPropa property (FXPROP); slot i of the parameter block belongs to property i, except FP_PAN (2 slots) and FP_BLOB (max slots)typ: u8dec: u8slot: u8flags: u8name: &'static strmin: f64max: f64def: f64-- the default (FP_COLOR: the bits of this f64 are the ARGB colour)def_y: f64-- FP_PAN: the y default (FXP_CHOICES of the asm record)choices: &'static [&'static str]
impl FxProp
const fn new(typ: u8, dec: u8, slot: u8, flags: u8, name: &'static str, min: f64, max: f64, def: f64) -> FxPropan FP_INT / DEC / BOOL / ANGLE / SEED / BLOB property (FXPROP)const fn choice(slot: u8, name: &'static str, max: f64, def: f64, choices: &'static [&'static str]) -> FxPropan FP_CHOICE propertyconst fn color(slot: u8, name: &'static str, argb: u32) -> FxPropan FP_COLOR property (FXPROPC: the default's bits are the colour)const fn pan(slot: u8, name: &'static str, dec: u8, min: f64, max: f64, x: f64, y: f64) -> FxPropan FP_PAN property (default x, y)fn def_color(&self) -> u32the default colour of an FP_COLOR propertystruct Params(pub [u64; FX_NSLOTS])the parameter block (FX_NSLOTS 8-byte slots)
impl Params
fn i(&self, slot: usize) -> i64slot as i64fn f(&self, slot: usize) -> f64slot as f64fn int(&self, slot: usize, lo: i32, hi: i32) -> i32the i64 slot clamped to lo..=hi [prm_int]fn dbl(&self, slot: usize, lo: f64, hi: f64) -> f64the f64 slot clamped to lo..=hi, NaN -> lo [prm_f64]fn byte(&self, slot: usize, i: usize) -> u8byte i of the block counted from slotslot(FP_BLOB)fn set_i(&mut self, slot: usize, v: i64)fn set_f(&mut self, slot: usize, v: f64)fn set_byte(&mut self, slot: usize, i: usize, v: u8)trait Cancela cancel flag render / prepare poll (JOB_CANCEL of FXA_JOB): the pool's JobCtl, or any flag of the caller'sfn cancelled(&self) -> bool
struct FxArgs<'a>the arguments of prepare / render (FXARGS without the destination)src: &'a Surfacex0: i32y0: i32x1: i32y1: i32params: &'a Paramsaux: Option<&'a (dyn Any + Send + Sync)>job: Option<&'a (dyn Cancel + Sync)>sel: Option<&'a TMask>
impl<'a> FxArgs<'a>
fn new(src: &'a Surface, roi: [i32; 4], params: &'a Params) -> FxArgs<'a>arguments for the ROI (x0, y0) - (x1, y1) without aux, job and selectionfn cancelled(&self) -> boolthe job's cancel flag is set (JOB_CANCEL)fn aux<T: 'static>(&self) -> Option<&'a T>the aux of prepare as Tfn src_row(&self, y: i32) -> &'a [u8]source row y (w * 4 bytes)fn row(sf: &Surface, y: i32) -> &[u8]row y of a surface (w * 4 bytes)fn px(b: &[u8], i: usize) -> u32pixel i of a rowfn put(b: &mut [u8], i: usize, v: u32)set pixel i of a rowstruct Dst<'a>the destination pixels of one render call: row k holds the pixels x0..x1 of row y0 + kx0: i32y0: i32x1: i32y1: i32
impl<'a> Dst<'a>
fn new(roi: [i32; 4], rows: Vec<&'a mut [u8]>) -> Dst<'a>a destination from row slices (each (x1 - x0) * 4 bytes, y1 - y0 of them)fn strided(roi: [i32; 4], buf: &'a mut [u8], stride: usize) -> Dst<'a>a destination in one buffer: row y0 + k at k * stride (e.g. a tile buffer with stride (x1 - x0) * 4)fn of_surface(sf: &'a mut Surface, roi: [i32; 4]) -> Dst<'a>the rectangle of a surface (clamped to it) as one destinationfn row(&mut self, y: i32) -> &mut [u8]the pixels x0..x1 of row y (y0 <= y < y1)fn tiles<'a>(sf: &'a mut Surface, rects: &[[i32; 4]], store: &'a mut Vec<&'a mut [u8]>) -> Vec<Dst<'a>>disjoint rectangles of a surface as destinations (clamped to the surface; empty ones are empty destinations); panics when two rectangles overlap.storeholds the row slices of all destinations (one allocation, cleared first; pass a new or reused empty Vec):let mut store = Vec::new(); let dsts = fx::tiles(&mut surface, &rects, &mut store);fn rows(a: &FxArgs, dst: &mut Dst, mut f: impl FnMut(&mut [u8], &[u8], i32, i32)) -> i32fx_rows: f(dst_row, src_row, x0, y) for every row of the ROI (rows = the pixels x0..x1); polls the cancel flag before every row -> 0 | ERR_CANCELfn register(group: &'static [FxDesc]) -> i32add a group of effects; a group already registered is ignored -> 0 | ERR_LIMITfn use_all()register every built-in group in menu order (adjustments first) [fx_use_all]fn count() -> usizethe number of registered effectsfn get(i: usize) -> Option<&'static FxDesc>the i-th registered effect (group order, then table order)fn find(name: &str) -> Option<&'static FxDesc>the effect with this ASCII keyfn find_id(id: u32) -> Option<&'static FxDesc>the effect with this FX_* idfn defaults(desc: &FxDesc, p: &mut Params)every property's default into its slot(s); slots without a property are 0fn hash32(x: u32, y: u32, seed: u32, stream: u32) -> u32deterministic per-pixel random bits: a murmur3-style finaliser over the inputs [fx_hash32]
fx/adj.rs#
Source: lib/fx/adj.rs
adj -- the 13 adjustments (Korrekturen) of paint.net 5.1 as pure kernels [src/fx/fx_adj.s]
FXTAB the group table (menu order of paint.net)
Pixels are straight ARGB; every adjustment keeps alpha (except Invert Alpha) and changes the
colour of transparent pixels like any other. Intensity I = (7471 B + 38470 G + 19595 R) >> 16.
auto_level prepare: histogram (alpha > 0, selection > 0) -> paint.net
HistogramRgb.MakeLevelsAuto -> Level lut
black_white B = G = R = I
brightness_contrast paint.net 3.x BrightnessAndContrastAdjustment (integer tables)
curves natural cubic spline luts (Luminosity: c + curve[I] - I, or R/G/B)
exposure linear light: out = enc(dec(c) * 2^ev) per channel lut
highlights_shadows blurred alpha-weighted intensity grid (prepare) -> gain
2^(2 s (1-m)^2 - 2 h m^2) on linear light
hue_saturation paint.net HueSaturationLightness (f32 lanes as the asm's SSE code)
invert_alpha A = 255 - A
invert_colors B, G, R = 255 - c
levels paint.net UnaryPixelOps.Level (lut::levels_lut) with a channel mask
posterize paint.net PosterizePixel levels per channel
sepia Desaturate, then Level with gamma B 1.2, G 1.0, R 0.8 (constant tables)
temperature_tint luminance-normalised linear-light channel gains
static FXTAB: [FxDesc; 13]the group table (menu order of paint.net) [fxtab_adj]
fx/artistic.rs#
Source: lib/fx/artistic.rs
artistic -- effect group "artistic" (Künstlerisch): ink_sketch, oil_painting, pencil_sketch
[src/fx/fx_artistic.s]
FXTAB the group table
oil_painting brush size b (1..8), coarseness L (3..255): paint.net 3's oil painting: the
(2b+1)^2 square window bucketed by intensity FastScale(I, L); the fullest
bucket (lowest index on ties) gives the pixel: alpha = sum A / n, colour =
sum (c A) / sum A
pencil_sketch tip t (1..20), colour range c: D = desaturate(invert(BrightnessContrast(
GaussianBlur(src, t), c, -c))); dst = ColorDodge(desaturate(src), D)
ink_sketch outline k (0..99), colouring c: Glow (radius 6, b = c = -(c - 50) * 2)
screened over the source, then a 5x5 edge kernel (centre 24, others -1) on
the premultiplied source darkens it: d = min(255, I (k + 5) >> 6)
static FXTAB: [FxDesc; 3]the group table [fxtab_artistic]
fx/enhance.rs#
Source: lib/fx/enhance.rs
Native equivalents of the additional photographic and object operations used by
the handbook. These kernels do not copy or claim pixel identity with third-party DLLs.
COLOR_BALANCE: u32 = 14
BLACK_WHITE_PLUS: u32 = 15
DREAM: u32 = 23
OIL_PLUS: u32 = 24
PASTEL: u32 = 25
FEATHER: u32 = 81
INNER_SHADOW: u32 = 82
BEVEL: u32 = 83
DODGE_BURN: u32 = 96
CONTENT_FILL: u32 = 97
PORTRAIT: u32 = 98
static FXTAB: [FxDesc; 11]
fx/blur.rs#
Source: lib/fx/blur.rs
blur -- effect group "blur" (Weichzeichnen) [src/fx/fx_blur.s]
FXTAB the group table
Effects: bokeh_blur, fragment_blur, gaussian_blur, median, motion_blur, radial_blur,
sketch_blur, square_blur, surface_blur, unfocus, zoom_blur
gaussian_blur radius r (0..200): Gaussian with 12 sigma^2 = 2 r (r + 2), premultiplied,
edges clamped (conv::sep_run)
square_blur mean of the (2r+1)^2 square (box, running sums)
unfocus mean over the paint.net disc (conv::disc_run)
median per channel percentile of the disc (lochist; colour histograms skip alpha 0)
motion_blur N = (1 + d) * 3 / 2 bilinear samples (1/16 px) along the direction, mean of
the valid ones (interior pixels: collapsed taps, the same integer sum)
zoom_blur paint.net 3's zoom blur in 64-bit fixed point, ColorBgra.Blend
radial_blur paint.net 3's radial blur (64-bit), ColorBgra.Blend
fragment_blur paint.net 3's FragmentEffect
surface_blur histogram bilateral filter over the disc
bokeh_blur disc mean in linear light with boosted highlights (f32 sums)
sketch_blur three layers of stroke cells, 2R + 1 bilinear samples along each cell's
direction
static FXTAB: [FxDesc; 11]the group table [fxtab_blur]
fx/color.rs#
Source: lib/fx/color.rs
color -- Farbe: Quantize [src/fx/fx_color.s]
FXTAB the group table
quantize: colors 2..256, algorithm octree | median_cut, dithering 0..8, alpha keep | binary.
prepare (single thread, polls the cancel flag per row) does everything over the ROI and keeps
the result image in aux; render copies rows (so tiles / threads cannot change the result).
considered pixels (palette statistics): inside the ROI, selection coverage > 0, alpha > 0
(keep) / alpha >= 128 (binary); row-major order
palette: <= K distinct colours -> exactly those (first appearance); else
octree Gervautz-Purgathofer: 8 levels, child = bit (7-L) of R, G, B; after every pixel,
while leaves > K the most recently created internal node of the deepest level
with internal nodes absorbs its children; palette = leaves depth first
median_cut Heckbert on a 32^3 histogram: split the box with the most pixels (ties:
first) along its longest cell extent after the first slice s with 2 * count(lo..s)
>= count, boxes shrunk to their occupied cells; colour = round(sum / count)
mapping: nearest palette colour (squared RGB distance, ties -> lowest index, through lazily
built candidate lists per 16^3 cell), Floyd-Steinberg (7 / 3 / 5 / 1 in 16ths) when
dithering L > 0: v = clamp(c + ((E L + 64) >> 7)); only "opaque" pixels take and pass
on error
alpha: keep -> unchanged; binary -> 255 when alpha >= 128, else 0
static FXTAB: [FxDesc; 1]the group table [fxtab_color]
fx/conv.rs#
Source: lib/fx/conv.rs
conv -- shared convolution helpers of the fx kernels [src/fx/fx_conv.s]
exp(x) / ln(x) / pow(x, y) f64 e^x (Cody-Waite + degree 12 Taylor), ln (2 atanh), x^y
roi(a) -> Option<[i32; 4]> the ROI clamped to the image (fxc_roi), None when empty
copy_roi(a, dst) -> 0 | ERR_CANCEL destination ROI = source ROI
pint(a, slot, lo, hi) / pdbl(a, slot) clamped i64 / f64 parameters (pdbl: NaN / inf -> 0,
clamped to +-1e6)
load_row(w16, src, y, x0, x1, mode) working pixels (4 x i16 premultiplied, full 16320)
of (x0 .. x1-1, y); outside: edge pixels or 0 (FXL_ZERO);
FXL_GAMMA: linear light
var12(r), Kern::gauss(var12), Kern::boxk(h) separable kernels (exact FIR for sigma <= 6,
else a cascade of 3 boxes)
sep_run(sep, io) -> 0 | ERR_* separable convolution of a ROI in strips: H pass of the
rows (clamped / loaded), V pass, io.emit per row
disc_run(disc, io) -> 0 | ERR_* sums over the paint.net disc of every ROI pixel (prefix
sums per row, i32 or f32 accumulation)
disc_edges(r) -> (E, area) half widths of the disc rows
bac_init(b, c) -> (tab, mode), bac_row, desat_row paint.net 3 Brightness / Contrast
blurbac(a, dst, r, b, c, f) Gaussian blur then Brightness / Contrast of the ROI;
f(dst, y, x0, row) finishes each output row
Exactness: every sum is an integer (running box sums, FIR dot products), so the result of
a pixel never depends on the ROI split; box means are rounded through f32
(rint(f32(S) * f32(1 / w))), FIR sums as (S + 8192) >> 14 saturated to i16.
FXL_GAMMA: u32 = 1 // linear light (RS_GAMMA)
FXL_ZERO: u32 = 2 // outside the image = transparent (default: clamp to the edge)
KT_COPY: u32 = 0
KT_FIR: u32 = 1
KT_BOX: u32 = 2
KN_MAXTAPS: usize = 255
KN_MAXBOX: usize = 8
DSF_F32: u32 = 1 // disc: accumulate the per-row sums in f32
fn exp(x: f64) -> f64e^x: k = rint(x / ln 2), r = x - k ln2 (Cody-Waite), degree 12 Taylor [fxc_exp]fn ln(x: f64) -> f64ln x: x = m 2^e, ln m = 2 atanh((m - 1) / (m + 1)); x <= 0 or denormal -> -745 [fxc_ln]fn pow(x: f64, y: f64) -> f64x^y = exp(y ln x) for x > 0, else 0 [fxc_pow]fn roi(a: &FxArgs) -> Option<[i32; 4]>the ROI clamped to the image (x0, y0 >= 0, x1 <= w, y1 <= h); None when empty [fxc_roi]fn copy_roi(a: &FxArgs, dst: &mut Dst) -> i32destination ROI = source ROI [fxc_copy_roi]fn dst_px<'d>(dst: &'d mut Dst, y: i32, x0: i32, n: i32) -> &'d mut [u8]the destination pixels x0 .. x0 + n of row yfn pint(a: &FxArgs, slot: usize, lo: i32, hi: i32) -> i32i64 parameter slot clamped to [lo, hi] [fxc_pint]fn pdbl(a: &FxArgs, slot: usize) -> f64f64 parameter slot; NaN / infinite -> 0, clamped to -1e6 .. 1e6 [fxc_pdbl]fn load_row(dst: &mut [i16], src: &Surface, y: i32, x0: i32, x1: i32, mode: u32)w16 = working pixels of (x0 .. x1-1, y); outside columns / rows: the edge pixel (clamp) or 0 (mode & FXL_ZERO); mode & FXL_GAMMA: linear light [fxc_load_row]fn var12(r: i32) -> i32paint.net-like blur radius -> 12 sigma^2 = 2 r (r + 2) (r <= 0 -> 0) [fxc_var12]struct Kerna separable 1-D kernel (KERN)typ: u32halo: i32n: i32-- FIR taps (odd) / number of boxesw: [i16; 256]-- FIR weights (+ a 0 pad tap)h: [i32; KN_MAXBOX]-- box half widths
impl Kern
fn copy() -> Kernthe identityfn boxk(h: i32) -> Kernone box of width 2h + 1 (h <= 0: identity) [fxc_kern_box]fn gauss(var12: i32) -> KernGaussian with 12 sigma^2 = var12 (<= 0: identity) [fxc_kern_gauss]FIR (var12 <= 432): h = ceil(sqrt(0.75 var12)) (1..18), g_i = exp(-6 i^2 / var12), sum = g_0 + 2 g_1 + ..., q_i = trunc(g_i (16384 / sum) + 0.5), the centre absorbs 16384 - (q_0 + 2 sum q_i). Boxes: wl = largest odd w with 3 w^2 <= var12 + 3, m = (2 num + den) / (2 den) (num = 3 wl^2 + 12 wl + 9 - var12, den = 4 wl + 4, m <= 3): m boxes of width wl, then 3 - m of wl + 2.struct Sep<'a>a separable run (SEP): source, job, kernels, the output ROI, loader modesrc: &'a Surfacejob: Option<&'a (dyn Cancel + Sync)>kh: &'a Kernkv: Option<&'a Kern>x0: i32y0: i32x1: i32y1: i32mode: u32custom_load: bool-- io.load replaces fxc_load_row (rows are then not clamped to the image)
impl<'a> Sep<'a>
fn new(a: &FxArgs<'a>, k: &'a Kern) -> Option<Sep<'a>>the standard run of an effect: source / job / ROI of a (None when the ROI is empty) [fxc_sep_init]trait SepIothe row source and sink of sep_run (SP_LOAD / SP_EMIT)fn load(&mut self, _sep: &Sep, _w16: &mut [i16], _y: i32, _x0: i32, _x1: i32)a custom loader (when Sep::custom_load): w16 of (x0 .. x1-1, y)fn emit(&mut self, sep: &Sep, y: i32, row: &[i16])output row y (columns sep.x0 .. sep.x1-1) as working pixels
struct EmitArgb<'d, 'e>(pub &'d mut Dst<'e>)the standard emitter: working row -> straight ARGB in the destination [fxc_emit_argb]fn sep_run(sep: &Sep, io: &mut impl SepIo) -> i32separable convolution of a ROI -> 0 | ERR_CANCEL [fxc_sep_run] Strips of S rows: H pass for the rows sy0 - HY .. sy1 + HY (clamped rows computed once), then the V pass over a row table, then io.emit per row.fn disc_edges(r: i32) -> (Vec<i32>, i32)half widths of the disc rows E[0..r] (paint.net LocalHistogramEffect: largest u with u^2 + v^2 <= ((2r+1)^2 + 2) / 4) and the area [fxc_disc_edges]struct Disc<'a>a disc run (DSC)src: &'a Surfacejob: Option<&'a (dyn Cancel + Sync)>r: i32flags: u32x0: i32y0: i32x1: i32y1: i32mode: u32area: i32-- pixels in the disc (set by disc_run)custom_prep: bool-- io.prep replaces the default row preparation
impl<'a> Disc<'a>
fn new(a: &FxArgs<'a>, r: i32) -> Option<Disc<'a>>the standard run of an effect (None when the ROI is empty) [fxc_disc_init]enum DiscRow<'r>the summed row of a disc run: i32 x 4 per pixel, or f32 x 4 with DSF_F32I(&'r mut [i32])F(&'r mut [f32])
trait DiscIothe row source and sink of disc_run (DS_PREP / DS_EMIT)fn prep(&mut self, _d: &Disc, _v: &mut [i32], _y: i32, _x0: i32, _x1: i32)custom preparation (Disc::custom_prep): i32 x 4 values of (x0 .. x1-1, y)fn emit(&mut self, d: &Disc, y: i32, row: DiscRow)
struct DiscArgb<'d, 'e>(pub &'d mut Dst<'e>)the standard emitter (i32 sums): W16 = rint(f32(sum) * f32(1 / area)), then straight ARGB [fxc_disc_emit_argb]fn disc_run(d: &mut Disc, io: &mut impl DiscIo) -> i32disc sums of a ROI -> 0 | ERR_CANCEL [fxc_disc_run] Per source row a prefix sum P (i32, wrapping) makes each disc row one difference P[x + e + 1] - P[x - e]; rows are clamped to the image; the rows are summed in i32 or (DSF_F32) in f32 in the order v = -r .. r.fn bac_init(b: i32, c: i32) -> ([i32; 256], u32)paint.net 3 BrightnessAndContrast as used inside Glow / Soften Portrait / Pencil / Ink: (tab, mode) -- mode 0 (div = 100) / 1: shift tables, mode 2 (contrast 100): threshold [fxc_bac_init]fn bac_row_inplace(row: &mut [u8], tab: &[i32; 256], mode: u32)apply bac_init's table to a straight ARGB row (dst may be src: pass the same slice twice through bac_row_inplace) [fxc_bac_row]fn desat_row(dst: &mut [u8], src: &[u8])B = G = R = intensity, alpha kept [fxc_desat_row]fn desat_inplace(row: &mut [u8])desat_row in placefn blurbac(a: &FxArgs, dst: &mut Dst, r: i32, b: i32, c: i32, mut f: impl FnMut(&mut Dst, i32, i32, &mut [u8])) -> i32the paint.net 3 chain "Gaussian blur (radius r) of the source, then Brightness / Contrast" for the ROI; f(dst, y, x0, row) receives the straight ARGB result of each row (columns x0 ..) and writes the destination itself -> 0 | ERR_* [fxc_blurbac]fn w16_of(p: u32) -> [i16; 4]working values of one straight pixel (rs_to_work, no gamma)
fx/distort.rs#
Source: lib/fx/distort.rs
distort -- effect group "distort" (Verzerren): Bulge, Crystalize, Dents, Frosted Glass,
Morphology, Pixelate, Polar Inversion, Tile Reflection, Twist [src/fx/fx_distort.s]
FXTAB the group table
The warp effects are small mapping functions for the warp framework (warp.rs); Pixelate and
Morphology have their own loops. Every pixel depends only on (source, parameters, aux).
bulge a = amount / 100, R = default radius: |p| < R: p (1 - a (1 - |p| / R)^2)
twist R = size * default radius, k = sign(amount) amount^2 / 100: p rotated by
k (1 - |p| / R)^3
polar_inversion p lerp(1, R^2 / |p|^2, amount)
tile_reflection (s, t) = p rotated by -angle, s += k tan(s pi / size) (t likewise), back
dents p + d (-sin a, cos a), a = theta * 4 octaves of perlin noise
frosted_glass samples moved by r ((1 - s) w + s n): w random point of the unit disc, n two
perlin fields
crystalize Voronoi cells of a jittered grid: the colour of the source pixel under the
nearest site
pixelate blocks filled with their premultiplied average (exact integers)
morphology max (dilate) / min (erode) / open / close of the premultiplied channels over
a circle / square / diamond (exact window maxima by doubling)
static FXTAB: [FxDesc; 9]the group table [fxtab_distort]
fx/hist.rs#
Source: lib/fx/hist.rs
hist -- histogram helpers of the effect kernels (thread safe, explicit buffers) [src/fx/fx_hist.s]
hist_rgba(a, hist) -> count | ERR_CANCEL u32[4][256] (B, G, R, A) of the ROI pixels with
alpha != 0 and (with a selection) coverage != 0; polls the cancel flag once per row
hist_percentile(h, total, fraction) -> j smallest j with h[0] + .. + h[j] > total *
fraction (f64 compare); 0 when there is none (paint.net HistogramRgb.GetPercentile)
hist_mean(h) -> f64 f32(sum j h[j]) / f32(sum h[j]) (paint.net GetMean)
lochist(a, dst, rad, f) -> 0 | ERR_CANCEL paint.net LocalHistogramEffect.RenderRect: for
every ROI pixel the histograms (LocHist) of the source pixels (x+u, y+v) inside the
image with u^2 + v^2 <= ((2 rad + 1)^2 + 2) / 4; dst = f(hist, area, srcpixel).
Histograms start at the ROI's left edge of every row and slide to the right (with
paint.net's edge loops), so the result does not depend on the ROI split.
FX_LOCHIST_MAX: i32 = 1024
struct LocHisthistograms B, G, R, A and their block sums (block k = bins 16k .. 16k + 15)h: [[u32; 256]; 4]blk: [[u32; 16]; 4]
fn hist_rgba(a: &FxArgs, hist: &mut [[u32; 256]; 4]) -> i64histograms of the ROI (alpha > 0, selection > 0) -> pixels counted | ERR_CANCEL [fx_hist_rgba]fn hist_percentile(h: &[u32; 256], total: i64, fraction: f64) -> u32smallest j with h[0] + .. + h[j] > total * fraction, else 0 [fx_hist_percentile]fn hist_mean(h: &[u32; 256]) -> f64f32(sum j h[j]) / f32(sum h[j]) as f64, 0 when empty [fx_hist_mean]fn lochist(a: &FxArgs, dst: &mut Dst, rad: i32, mut f: impl FnMut(&LocHist, u32, u32) -> u32) -> i32paint.net LocalHistogramEffect.RenderRect over the ROI -> 0 | ERR_CANCEL [fx_lochist]
fx/lochist.rs#
Source: lib/fx/lochist.rs
lochist -- sliding local histograms for median / percentile / oil / surface style effects
[src/fx/fx_lochist.s]
lh_run(a, dst, r, shape, alpha0, f) for every ROI pixel (x, y): the histograms (Hist) of
the window around it (LHS_DISC = paint.net disc of radius
r, LHS_SQUARE = (2r+1)^2), then dst(x, y) = f(hist)
lh_run_oil(a, dst, r, shape, levels, f) the same with pixels bucketed by intensity (Oil)
lh_percentile(hist, ch, target) smallest v with count(<= v) >= max(target, 1) (255 when
fewer pixels)
lh_rank(hist, ch, v) pixels with value < v
lh_edges(r, shape) -> (E, area) half widths of the window rows
Window: pixels outside the image are not counted. alpha0 (LHF_ALPHA0) keeps pixels with
alpha 0 out of the colour histograms (ncol counts the rest; the alpha histogram sees every
pixel, nall). Oil: bucket = FastScale(I, levels), alpha-0 pixels count as transparent black.
Traversal: the histogram of the first ROI column slides down one row per ROI row, is
copied, then slides right along the row; every result depends on the window content only.
LHS_DISC: u32 = 0
LHS_SQUARE: u32 = 1
struct Histthe per-channel histograms of a window (HIST): fine counts B, G, R, A, coarse counts (bins v >> 4), pixel counts and the centre pixelfine: [[u32; 256]; 4]coarse: [[u32; 16]; 4]nall: u32ncol: u32src: u32
struct Oilthe intensity buckets of a window (OIL): pixels per bucket, per bucket sum B*A, G*A, R*A, Acnt: [u32; 256]sum: [[u32; 4]; 256]n: u32src: u32
fn lh_edges(r: i32, shape: u32) -> (Vec<i32>, i32)half widths of the window rows E[0..r] and the area [lh_edges]fn lh_percentile(h: &Hist, ch: usize, target: i32) -> u32smallest v with count(<= v) >= max(target, 1) in channel ch, 255 when fewer [lh_percentile]fn lh_rank(h: &Hist, ch: usize, v: i32) -> u32pixels with channel value < v (v clamped to 0..256) [lh_rank]fn lh_run(a: &FxArgs, dst: &mut Dst, r: i32, shape: u32, alpha0: bool, f: impl FnMut(&Hist, i32, i32) -> u32) -> i32histograms of every ROI pixel's window -> dst = f(hist, x, y) [lh_run, LHK_HIST]fn lh_run_oil(a: &FxArgs, dst: &mut Dst, r: i32, shape: u32, levels: i32, f: impl FnMut(&Oil, i32, i32) -> u32) -> i32intensity buckets of every ROI pixel's window -> dst = f(oil, x, y) [lh_run, LHK_OIL]
fx/lut.rs#
Source: lib/fx/lut.rs
lut -- shared helpers of the effect kernels: per-channel tables, intensity, sRGB, Levels
and spline tables, the x87 maths [src/fx/fx_lut.s]
lut_row(dst, src, lut) per channel table lookup; lut = 4 x 256 bytes B, G, R, A
lut_ident(lut) four identity tables
luma(argb) -> u32 paint.net intensity (7471 B + 38470 G + 19595 R) >> 16
luma_row(dst8, src) the intensity of every pixel as a byte
pow / exp2 / log2 / cos / sin x87 maths (rt::x87; fx_pow, fx_exp2, fx_log2, fx_cos, fx_sin)
srgb_dec(c) / srgb_enc(l) sRGB 0..1 <-> linear 0..1 (IEC 61966-2-1, f64)
lin_table(out) f32[256]: srgb_dec(i / 255)
srgb_table(out, n) u8[n]: round(255 srgb_enc(i / (n - 1))), n >= 2
levels_lut(lut, lvl) paint.net UnaryPixelOps.Level as a 1024-byte lut
spline_lut(lut, pts) u8[256] from control points {x, y}: natural cubic spline
(the values of paint.net's Curves), ClampToByte
Levels, channel i (B, G, R) and input j: v = f32(j) - in_lo; v < 0 -> out_lo; j >= in_hi
-> out_hi; else trunc(clamp(out_lo + (out_hi - out_lo) pow(f64(f32(v / f32(in_hi -
in_lo))), f64(gamma)), 0, 255)). A channel with in_hi <= in_lo is the identity; gamma is
clamped to 0.1 .. 10 (NaN -> 1).
Re-exports: rt::x87::{cos, exp2, log2, pow, sin}
FX_SPLINE_MAX: usize = 64
fn lut_row(dst: &mut [u8], src: &[u8], lut: &[u8; 1024])dst[i] = {lut[B], lut[256 + G], lut[512 + R], lut[768 + A]} [fx_lut_row]fn lut_ident(lut: &mut [u8])four identity tables [fx_lut_ident]fn luma(c: u32) -> u32(7471 B + 38470 G + 19595 R) >> 16 [fx_luma]fn luma_row(dst: &mut [u8], src: &[u8])the intensity of every pixel [fx_luma_row]fn srgb_dec(c: f64) -> f64c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055)^2.4 [fx_srgb_dec]fn srgb_enc(l: f64) -> f64l <= 0.0031308 ? 12.92 l : 1.055 l^(1/2.4) - 0.055, clamped to 0..1 [fx_srgb_enc]fn lin_table(out: &mut [f32])f32[256] linear values of the sRGB bytes [fx_lin_table]fn srgb_table(out: &mut [u8], n: usize)u8[n]: trunc(255 srgb_enc(i / (n - 1)) + 0.5) [fx_srgb_table]struct Lvlthe LVL record of levels_lut (channel order B, G, R)inlo: [u8; 4]inhi: [u8; 4]outlo: [u8; 4]outhi: [u8; 4]gamma: [f32; 3]
fn levels_lut(lut: &mut [u8; 1024], lvl: &Lvl)paint.net UnaryPixelOps.Level as a 1024-byte lut (alpha identity) [fx_levels_lut]fn spline_lut(lut: &mut [u8], pts: &[u8], n: usize)u8[256] from up to FX_SPLINE_MAX control points {x, y} (pts = 2 n bytes, any order, a repeated x: the last wins); n = 0: identity, n = 1: constant [fx_spline_lut]
fx/noise.rs#
Source: lib/fx/noise.rs
noise -- effect group "noise" (Rauschen): add_noise, reduce_noise [src/fx/fx_noise.s]
FXTAB the group table
add_noise intensity (0..100), colour saturation (0..400), coverage (0..100), seed:
paint.net 3's Add Noise with per-pixel hashes h_k = hash32(x, y, seed, k):
changed when h_0 mod 100 < coverage; n_k = ((sum of the 4 bytes of h_k) -
510) * 1774 >> 8 for R (1), G (2), B (3); i = (4899 r + 9618 g + 1867 b) >> 14,
c = i + (((c - i) sat) >> 12), sat = saturation * 4096 / 100, dev = I^2 / 4,
channel' = clamp(channel + ((c dev + 32768) >> 16)); alpha kept
reduce_noise radius (0..200), strength (0..1): per channel the median m of the disc,
f = strength (1 - 0.75 I), v' = trunc(clamp(v + f (m - v), 0, 255))
static FXTAB: [FxDesc; 2]the group table [fxtab_noise]
fx/object.rs#
Source: lib/fx/object.rs
object -- effect group "object" (Objekt): drop_shadow [src/fx/fx_object.s]
FXTAB the group table
drop_shadow colour, angle (deg, 0 = right, 90 = down), distance d (0..100), blur radius r
(0..100), opacity (0..100), shadow only: offset o = (rint(d cos a), rint(d sin a));
shadow alpha S = Gaussian blur (Kern::gauss(2 r (r + 2)), W16) of the source
alpha moved by o (transparent outside the image); shadow pixel = colour with
alpha (S opacity colour.a + 816000) / 1632000; result = source over shadow
(Normal blend), or the shadow alone
static FXTAB: [FxDesc; 1]the group table [fxtab_object]
fx/perlin.rs#
Source: lib/fx/perlin.rs
perlin -- deterministic 2-D gradient noise for the fx kernels (Clouds, Turbulence, Dents,
Frosted Glass) [src/fx/fx_perlin.s]
perlin(x, y, seed, stream) -> f64 gradient noise, about -1 .. 1
perlin_row(rec, acc) acc[j] += amp * noise(x_j, y) along a row
Improved Perlin noise (quintic fade 6t^5 - 15t^4 + 10t^3) on the integer lattice; the gradient
of lattice point (ix, iy) is G[h & 15], h = hash32(ix, iy, seed, stream), G_k = sqrt(2)
(cos, sin)(2 pi (k + 0.5) / 16). g00 = G00.x fx + G00.y fy, g10 = G10.x (fx - 1) + G10.y fy,
g01 = G01.x fx + G01.y (fy - 1), g11 = G11.x (fx - 1) + G11.y (fy - 1); a = g00 + u (g10 -
g00), b = g01 + u (g11 - g01), noise = a + v (b - a), u / v = fade(fx / fy) computed as
((((f 6) - 15) f + 10) f) f f. Coordinates are clamped to +-2^30; fixed operation order:
perlin and perlin_row give bit-identical values.
fn perlin(x: f64, y: f64, seed: u32, stream: u32) -> f64gradient noise at (x, y) [fxn_perlin]struct PerlinRowa row of noise samples (PERLIN_ROW): x_j = (x0 + j step) * inv + ofsxn: usizex0: i32step: i32abs: boolseed: u32stream: u32inv: f64ofsx: f64y: f64amp: f64
fn perlin_row(r: &PerlinRow, acc: &mut [f64])acc[j] += amp * noise(x_j, y) (|noise| when abs); the lattice gradients are reused while consecutive x_j stay in one cell [fxn_perlin_row]
fx/photo.rs#
Source: lib/fx/photo.rs
photo -- effect group "photo" (Foto): glow, red_eye_removal, sharpen, soften_portrait,
straighten, vignette [src/fx/fx_photo.s]
FXTAB the group table
glow paint.net 3's Glow: G = BrightnessContrast(GaussianBlur(src, r)), dst =
Screen(lhs = src, rhs = G)
soften_portrait G = BrightnessContrast(GaussianBlur(src, 3 softness), lighting,
-lighting / 2); L = warm grey of src; dst = Overlay(L, G), alpha = src
sharpen local median m of the disc (radius = amount): clamp((3 s - m) >> 1)
red_eye_removal paint.net 3's RedEyeRemove op on every ROI pixel
straighten rotation about the image centre (img_core::xform bicubic); zoom scales
by cos|a| + max(w / h, h / w) sin|a| (edges clamped), else transparent
corners
vignette smoothstep darkening towards a colour in linear light
static FXTAB: [FxDesc; 6]the group table [fxtab_photo]
fx/render.rs#
Source: lib/fx/render.rs
render -- effect group "render" (Rendern): Clouds, Julia Fractal, Mandelbrot Fractal,
Turbulence [src/fx/fx_render.s]
FXTAB the group table
All four are per-pixel functions of (x, y, image size, parameters).
clouds paint.net 3.x algorithm, own lattice noise: dx = 2x - w, dy = 2y - h; octaves
i = 0, 1, ... while i < 12, amp > 0.03 and div > 0 (amp = power^i, div = scale
>> i): val += perlin(dx / div + ox_i, dy / div + oy_i, seed, i) amp;
t = clamp((val + 1) / 2, 0, 1)
turbulence octaves i < detail while div > 0, amp = roughness^i; val = sum |perlin| amp;
t = clamp(2 val / sum amp, 0, 1)
Colour = round(c1 + (c2 - c1) t) per channel (f32), blended over the source
with the blend mode (gfx::blendmode)
julia_fractal / mandelbrot_fractal paint.net 3.x algorithms, count samples per pixel,
escape iteration per sample (the asm runs 6 / 12 packed lanes; every sample
does the same IEEE operations), colour schemes classic / grayscale / palette /
rainbow, channel sums divided by count (truncating)
static FXTAB: [FxDesc; 4]the group table [fxtab_render]
fx/stylize.rs#
Source: lib/fx/stylize.rs
stylize -- Stilisieren: Edge Detect, Emboss, Outline, Relief [src/fx/fx_stylize.s]
FXTAB the group table
Edge Detect, Emboss and Relief are paint.net 3.x ColorDifferenceEffect kernels: a 3 x 3
weight matrix rotated by the angle (r = angle * 2 * pi / 360, dr = pi / 4):
cos(r + dr) cos(r + 2dr) cos(r + 3dr)
cos(r) CENTER cos(r + 4dr)
cos(r - dr) cos(r - 2dr) cos(r - 3dr)
Weights are quantised to wq = floor(w * 16384 + 0.5) (integer sums, bit-exact, tile
independent); taps outside the image count as 0. Per channel v = trunc(sum wq * c / 16384)
(towards zero) + OFFSET, clamped to 0..255; alpha = the centre pixel's alpha.
edge_detect CENTER 0, OFFSET 128, channels B, G, R (angle default 45)
relief CENTER 1, OFFSET 0, channels B, G, R (angle default 45)
emboss CENTER 0, OFFSET 128, on the intensity, output B = G = R = v (angle default 0)
outline paint.net 3.x OutlineEffect (hist::lochist): per channel over the circle of
radius `thickness`: skip empty bins, count up to area (100 - intensity) / 200
-> c1, on up to area (100 + intensity) / 200 -> c2, c = 255 - (c2 - c1);
alpha = a2 (the alpha scan skips on the BLUE histogram like paint.net)
static FXTAB: [FxDesc; 4]the group table [fxtab_stylize]
fx/warp.rs#
Source: lib/fx/warp.rs
warp -- warp framework of the distort effects: inverse mapping per destination pixel, n x n
supersampling, bilinear sampling in premultiplied space, edge behaviour; the f64 maths the
fx kernels share [src/fx/fx_warp.s]
prepare(a) -> aux bounds for centre / radius (the selection's bounding box)
Warp::new(a) the WARP record of a render call (fxw_init)
wr.center(x, y) centre from an FP_PAN pair (fxw_center)
wr.run(a, dst, map) -> 0 | ERR_CANCEL render the ROI through map (fxw_run)
sincos(x) -> (sin, cos) f64, |x| <= 1e9 (fdlibm kernels) [fxm_sincos]
log(x) f64 ln, x clamped to [DBL_MIN, DBL_MAX] [fxm_log]
Coordinates: pixel (x, y) is the POINT (x, y) (pixel centres at integers); the image covers
[-0.5, w - 0.5) x [-0.5, h - 0.5). For every destination pixel of the ROI run takes n x n
sample points p = (x - cx + ox_i, y - cy + oy_i) relative to the centre (paint.net's rotated
grid: oy_i = (i + 1) / (n*n + 1) - 0.5, ox_i = frac(n (i + 1) / (n*n + 1)) - 0.5; n = 1:
one sample at the centre) and calls map(wr, cur, pt) -> identity? pt = the point relative to
the centre on entry, the SOURCE point on return (identity: the sample is the pixel's own
source pixel, exactly). A source point is sampled bilinearly from the 2 x 2 pixels around it
with f32 weights, alpha-weighted (each tap contributes w (c a, a)); taps outside the image
follow the edge mode (CLAMP / WRAP / REFLECT per tap; PRIMARY / SECONDARY / TRANSPARENT /
ORIGINAL replace a sample outside the image area by that colour). The pixel = sum of its
samples: a = round(S_a / (n n)), c = round(S_c / S_a); a = 0 -> 0. Pixels farther than
rin + 0.75 from the centre (rin > 0) are copied unchanged.
FXW_CLAMP: i32 = 0 // clamp taps to the image
FXW_WRAP: i32 = 1 // tile the image
FXW_REFLECT: i32 = 2 // mirror (period 2n, edge pixels repeated)
FXW_PRIMARY: i32 = 3 // samples outside the image = col1
FXW_SECONDARY: i32 = 4 // samples outside the image = col2
FXW_TRANSPARENT: i32 = 5 // samples outside the image = transparent
FXW_ORIGINAL: i32 = 6 // samples outside the image = the destination's own pixel
FXW_NEDGE: i32 = 7
struct Bounds(pub [i32; 4])the aux of prepare: the bounds x0, y0, x1, y1fn prepare(a: &FxArgs) -> Result<Option<Aux>, i32>the bounding box of the selection (clipped to the image) or the whole image [fxw_prepare]struct Warp<'a>the WARP record of one render callsrc: &'a Surfacew: i32h: i32x0: i32y0: i32x1: i32y1: i32job: Option<&'a (dyn Cancel + Sync)>q: i32-- quality 1..5: n x n samples per pixeledge: i32col1: u32col2: u32cx: f64cy: f64rin: f64-- radius of influence (0 = map every pixel)rdef: f64-- default radius = min(bounds w, h) / 2bx0: i32by0: i32bx1: i32by1: i32p: [f64; 16]-- effect parameters (WR_P)seed: u32
struct Curthe pixel and sample a map function is called for (WR_CURX / CURY / CURS)x: i32y: i32s: i32
impl<'a> Warp<'a>
fn new(a: &FxArgs<'a>) -> Warp<'a>the record from the arguments: ROI clipped to the image, bounds (aux of prepare or the image), rdef, centre of the bounds, q = 1, edge CLAMP, rin = 0 [fxw_init]fn center(&mut self, x: f64, y: f64)centre from an FP_PAN value (-1 = left / top edge of the bounds, 1 = right / bottom; clamped to -2 .. 2): cx = bx0 - 0.5 + bw (1 + x) / 2 [fxw_center]fn run(&mut self, dst: &mut Dst, mut map: impl FnMut(&Warp, Cur, &mut [f64; 2]) -> bool) -> i32render the ROI through map -> 0 | ERR_CANCEL [fxw_run]fn sincos(x: f64) -> (f64, f64)(sin x, cos x): k = rint(x 2/pi), Cody-Waite reduction, fdlibm kernels; x clamped to +-1e9 (NaN -> 0) [fxm_sincos]fn log(x: f64) -> f64ln x (fdlibm e_log.c); x clamped to [DBL_MIN, DBL_MAX] (NaN, 0, negatives -> ln DBL_MIN) [fxm_log]