This commit is contained in:
Ryan Oldenburg 2021-02-26 23:37:42 -06:00
parent 36b10a62d6
commit 6ec7ec0fbb
3 changed files with 7 additions and 8 deletions

View file

@ -348,7 +348,7 @@ proc blur*(image: Image, radius: float32, outOfBounds = ColorRGBX()) =
)
# Blur in the X direction.
var blurX = newImage(image.width, image.height)
let blurX = newImage(image.width, image.height)
for y in 0 ..< image.height:
for x in 0 ..< image.width:
var values: array[4, uint32]

View file

@ -11,15 +11,14 @@ proc gaussianLookup*(radius: int): seq[uint32] =
var
floats = newSeq[float32](result.len)
total = 0.0
for xb in -radius .. radius:
for step in -radius .. radius:
let
s = radius.float32 / 2.2 # 2.2 matches Figma.
x = xb.float32
a = 1 / sqrt(2 * PI * s^2) * exp(-1 * x^2 / (2 * s^2))
floats[xb + radius] = a
a = 1 / sqrt(2 * PI * s^2) * exp(-1 * step.float32^2 / (2 * s^2))
floats[step + radius] = a
total += a
for xb in -radius .. radius:
floats[xb + radius] = floats[xb + radius] / total
for step in -radius .. radius:
floats[step + radius] = floats[step + radius] / total
for i, f in floats:
result[i] = round(f * 255 * 1024).uint32

View file

@ -163,7 +163,7 @@ proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) =
let lookup = gaussianLookup(radius)
# Blur in the X direction.
var blurX = newMask(mask.width, mask.height)
let blurX = newMask(mask.width, mask.height)
for y in 0 ..< mask.height:
for x in 0 ..< mask.width:
var value: uint32