def filter.convolution.parse

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

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-xml-doc@0.1.0.1/xml.bend as XML

4976def filter.convolution.parse(+as: List<&2, XML.Attr>, +units: Matrix, +input: FilterInput, +format: Raster) -> FilterOp:
4977  +order = U.numbers(XML.attr.get(as, "order", "3"))
4978  +ox = F32.floor(U.nth(order, 0n, 3.0))
4979  +oy = F32.floor(U.nth(order, 1n, U.nth(order, 0n, 3.0)))
4980  +width = F32.to_u32(U.clamp(ox, 1.0, 4096.0))
4981  +height = F32.to_u32(U.clamp(oy, 1.0, 4096.0))
4982  +tx = F32.floor(U.scalar(XML.attr.get(as, "targetX", ""), F32.floor((ox * 0.5 : F32))))
4983  +ty = F32.floor(U.scalar(XML.attr.get(as, "targetY", ""), F32.floor((oy * 0.5 : F32))))
4984  +vs = U.numbers(XML.attr.get(as, "kernelMatrix", ""))
4985  +sum = floats.sum(vs)
4986  +defaultDivisor = U.choose(F32, F32.is_eq(sum, 0.0), 1.0, sum)
4987  +divisor = U.scalar(XML.attr.get(as, "divisor", ""), defaultDivisor)
4988  +lengths = U.numbers(XML.attr.get(as, "kernelUnitLength", ""))
4989  +ux = U.nth(lengths, 0n, 0.0)
4990  +uy = U.nth(lengths, 1n, ux)
4991  +explicit = F32.is_gt(ux, 0.0) && F32.is_gt(uy, 0.0)
4992  +step = raster.scale(format)
4993  +dx = U.choose(Point, explicit, matrix.vector(units, Point{ux, 0.0}), Point{step, 0.0})
4994  +dy = U.choose(Point, explicit, matrix.vector(units, Point{0.0, uy}), Point{0.0, step})
4995  +edge = XML.attr.get(as, "edgeMode", "duplicate")
4996  +valid = F32.is_ge(ox, 1.0) && F32.is_ge(oy, 1.0) && F32.is_le(ox, 4096.0) && F32.is_le(oy, 4096.0) && F32.is_le((ox * oy : F32), 4096.0) && U32.is_eq(floats.count(vs), (width * height : U32)) && F32.is_ge(tx, 0.0) && F32.is_lt(tx, ox) && F32.is_ge(ty, 0.0) && F32.is_lt(ty, oy)
4997  U.branch(FilterOp, valid, _ => FilterConvolution{Convolution{filter.convolution.taps(vs, 0, width, height, tx, ty, dx, dy), U.choose(F32, F32.is_eq(divisor, 0.0), defaultDivisor, divisor), U.scalar(XML.attr.get(as, "bias", "0"), 0.0), U.string.equal(XML.attr.get(as, "preserveAlpha", "false"), "true"), U.choose(U32, U.string.equal(edge, "wrap"), 1, U.choose(U32, U.string.equal(edge, "none"), 2, 0)), filter.convolution.limits(input, units)}}, _ => FilterCopy{})

Uses (35)

Used by (1)