Rename lookup to kernel.

This commit is contained in:
treeform 2021-02-26 23:06:13 -08:00
parent 9508150e99
commit a79cad9d90
3 changed files with 15 additions and 15 deletions

View file

@ -323,7 +323,7 @@ proc blur*(image: Image, radius: float32, outOfBounds = ColorRGBX()) =
if radius == 0:
return
let lookup = gaussianLookup(radius)
let kernel = gaussianKernel(radius)
proc `*`(sample: ColorRGBX, a: uint32): array[4, uint32] {.inline.} =
[
@ -353,13 +353,13 @@ proc blur*(image: Image, radius: float32, outOfBounds = ColorRGBX()) =
for x in 0 ..< image.width:
var values: array[4, uint32]
for xx in x - radius ..< min(x + radius, 0):
values += outOfBounds * lookup[xx - x + radius]
values += outOfBounds * kernel[xx - x + radius]
for xx in max(x - radius, 0) .. min(x + radius, image.width - 1):
values += image.getRgbaUnsafe(xx, y) * lookup[xx - x + radius]
values += image.getRgbaUnsafe(xx, y) * kernel[xx - x + radius]
for xx in max(x - radius, image.width) .. x + radius:
values += outOfBounds * lookup[xx - x + radius]
values += outOfBounds * kernel[xx - x + radius]
blurX.setRgbaUnsafe(y, x, values.rgbx())
@ -368,13 +368,13 @@ proc blur*(image: Image, radius: float32, outOfBounds = ColorRGBX()) =
for x in 0 ..< image.width:
var values: array[4, uint32]
for yy in y - radius ..< min(y + radius, 0):
values += outOfBounds * lookup[yy - y + radius]
values += outOfBounds * kernel[yy - y + radius]
for yy in max(y - radius, 0) .. min(y + radius, image.height - 1):
values += blurX.getRgbaUnsafe(yy, x) * lookup[yy - y + radius]
values += blurX.getRgbaUnsafe(yy, x) * kernel[yy - y + radius]
for yy in max(y - radius, image.height) .. y + radius:
values += outOfBounds * lookup[yy - y + radius]
values += outOfBounds * kernel[yy - y + radius]
image.setRgbaUnsafe(x, y, values.rgbx())

View file

@ -3,7 +3,7 @@ import chroma, vmath
when defined(amd64) and not defined(pixieNoSimd):
import nimsimd/sse2
proc gaussianLookup*(radius: int): seq[uint32] =
proc gaussianKernel*(radius: int): seq[uint32] =
## Compute lookup table for 1d Gaussian kernel.
## Values are [0, 255] * 1024.
result.setLen(radius * 2 + 1)

View file

@ -162,7 +162,7 @@ proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) =
if radius < 0:
raise newException(PixieError, "Cannot apply negative blur")
let lookup = gaussianLookup(radius)
let kernel = gaussianKernel(radius)
# Blur in the X direction. Store with dimensions swapped for reading later.
let blurX = newMask(mask.height, mask.width)
@ -170,13 +170,13 @@ proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) =
for x in 0 ..< mask.width:
var value: uint32
for xx in x - radius ..< min(x + radius, 0):
value += outOfBounds * lookup[xx - x + radius]
value += outOfBounds * kernel[xx - x + radius]
for xx in max(x - radius, 0) .. min(x + radius, mask.width - 1):
value += mask.getValueUnsafe(xx, y) * lookup[xx - x + radius]
value += mask.getValueUnsafe(xx, y) * kernel[xx - x + radius]
for xx in max(x - radius, mask.width) .. x + radius:
value += outOfBounds * lookup[xx - x + radius]
value += outOfBounds * kernel[xx - x + radius]
blurX.setValueUnsafe(y, x, (value div 1024 div 255).uint8)
@ -185,13 +185,13 @@ proc blur*(mask: Mask, radius: float32, outOfBounds: uint8 = 0) =
for x in 0 ..< mask.width:
var value: uint32
for yy in y - radius ..< min(y + radius, 0):
value += outOfBounds * lookup[yy - y + radius]
value += outOfBounds * kernel[yy - y + radius]
for yy in max(y - radius, 0) .. min(y + radius, mask.height - 1):
value += blurX.getValueUnsafe(yy, x) * lookup[yy - y + radius]
value += blurX.getValueUnsafe(yy, x) * kernel[yy - y + radius]
for yy in max(y - radius, mask.height) .. y + radius:
value += outOfBounds * lookup[yy - y + radius]
value += outOfBounds * kernel[yy - y + radius]
mask.setValueUnsafe(x, y, (value div 1024 div 255).uint8)