def bitmap.sample

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

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

2311def bitmap.sample(+raster: Raster, +p: Point, +center: Point, nearest: Bool) -> Img.Color:
2312  Raster{origin, step, width, height, depth, linear, pixels} = raster
2313  Point{x, y} = p
2314  Point{cx, cy} = center
2315  +w = U32.to_f32(width)
2316  +h = U32.to_f32(height)
2317  U.branch(Img.Color, nearest, _ => raster.pixel(raster, U.clamp(bitmap.nearest(cx), 0.0, (w - 1.0 : F32)), U.clamp(bitmap.nearest(cy), 0.0, (h - 1.0 : F32))),
2318    _ => raster.sample(raster, Point{U.clamp(cx, 0.5, (w - 0.5 : F32)), U.clamp(cy, 0.5, (h - 0.5 : F32))}))

Uses (12)

Used by (1)