def tile.sample

gralha-svg-render@0.1.0.1 · svg.bend:2361

import gralha-svg-render@0.1.0.1/svg.bend as Svg
import Base
import gralha-text-scan@0.1.0.1/scan.bend as U
import gralha-image@0.1.0.1/image.bend as Img

2361# A grid of one reads the tile bilinearly at the point (aligned tiles at device
2362# density); a larger grid averages nearest reads of a denser tile over the
2363# device pixel's footprint, the pattern-space vectors u and v.
2364def tile.sample(+r: Raster, +q: Point, +w: F32, +h: F32, +opacity: F32, +u: Point, +v: Point, +grid: U32) -> Img.Color:
2365  Raster{origin, step, width, height, depth, linear, pixels} = r
2366  Point{x, y} = q
2367  +wd = width
2368  +ht = height
2369  +px = pixels
2370  +side = U32.shln(1, depth)
2371  U.branch(Img.Color, U32.is_eq(wd, 0) || U32.is_eq(ht, 0), _ => Img.clear(),
2372    _ => color.fade(U.branch(Img.Color, U32.is_le(grid, 1),
2373      _ => tile.blend(px, side, wd, ht, (tile.wrap(x, w) * U32.to_f32(wd) / w - 0.5 : F32), (tile.wrap(y, h) * U32.to_f32(ht) / h - 0.5 : F32)),
2374      _ => color.fade(tile.grid(px, side, wd, ht, w, h, Point{x, y}, u, v, grid, U32.to_nat((grid * grid : U32)), 0, Img.clear()), (1.0 / U32.to_f32((grid * grid : U32)) : F32))), opacity))

Uses (21)

Used by (1)