shorter
This commit is contained in:
parent
9e132b6457
commit
205f091012
2 changed files with 22 additions and 26 deletions
|
@ -517,16 +517,12 @@ proc getRgbaSmooth*(image: Image, x, y: float32, wrapped = false): ColorRGBX =
|
||||||
## Gets a interpolated color with float point coordinates.
|
## Gets a interpolated color with float point coordinates.
|
||||||
## Pixes outside the image are transparent.
|
## Pixes outside the image are transparent.
|
||||||
let
|
let
|
||||||
minX = floor(x)
|
x0 = x.int
|
||||||
minY = floor(y)
|
y0 = y.int
|
||||||
diffX = x - minX
|
x1 = x0 + 1
|
||||||
diffY = y - minY
|
y1 = y0 + 1
|
||||||
x = minX.int
|
xFractional = x.fractional
|
||||||
y = minY.int
|
yFractional = y.fractional
|
||||||
x0 = (x + 0)
|
|
||||||
y0 = (y + 0)
|
|
||||||
x1 = (x + 1)
|
|
||||||
y1 = (y + 1)
|
|
||||||
|
|
||||||
var x0y0, x1y0, x0y1, x1y1: ColorRGBX
|
var x0y0, x1y0, x0y1, x1y1: ColorRGBX
|
||||||
if wrapped:
|
if wrapped:
|
||||||
|
@ -541,10 +537,10 @@ proc getRgbaSmooth*(image: Image, x, y: float32, wrapped = false): ColorRGBX =
|
||||||
x1y1 = image[x1, y1]
|
x1y1 = image[x1, y1]
|
||||||
|
|
||||||
let
|
let
|
||||||
bottomMix = lerp(x0y0, x1y0, diffX)
|
bottomMix = lerp(x0y0, x1y0, xFractional)
|
||||||
topMix = lerp(x0y1, x1y1, diffX)
|
topMix = lerp(x0y1, x1y1, xFractional)
|
||||||
|
|
||||||
lerp(bottomMix, topMix, diffY)
|
lerp(bottomMix, topMix, yFractional)
|
||||||
|
|
||||||
proc drawCorrect(
|
proc drawCorrect(
|
||||||
a, b: Image | Mask, mat = mat3(), tiled = false, blendMode = bmNormal
|
a, b: Image | Mask, mat = mat3(), tiled = false, blendMode = bmNormal
|
||||||
|
|
|
@ -159,22 +159,22 @@ proc fill*(mask: Mask, value: uint8) {.inline.} =
|
||||||
proc getValueSmooth*(mask: Mask, x, y: float32): uint8 =
|
proc getValueSmooth*(mask: Mask, x, y: float32): uint8 =
|
||||||
## Gets a interpolated value with float point coordinates.
|
## Gets a interpolated value with float point coordinates.
|
||||||
let
|
let
|
||||||
minX = floor(x)
|
x0 = x.int
|
||||||
minY = floor(y)
|
y0 = y.int
|
||||||
diffX = x - minX
|
x1 = x0 + 1
|
||||||
diffY = y - minY
|
y1 = y0 + 1
|
||||||
x = minX.int
|
xFractional = x.fractional
|
||||||
y = minY.int
|
yFractional = y.fractional
|
||||||
|
|
||||||
x0y0 = mask[x + 0, y + 0]
|
x0y0 = mask[x0, y0]
|
||||||
x1y0 = mask[x + 1, y + 0]
|
x1y0 = mask[x1, y0]
|
||||||
x0y1 = mask[x + 0, y + 1]
|
x0y1 = mask[x0, y1]
|
||||||
x1y1 = mask[x + 1, y + 1]
|
x1y1 = mask[x1, y1]
|
||||||
|
|
||||||
bottomMix = lerp(x0y0, x1y0, diffX)
|
bottomMix = lerp(x0y0, x1y0, xFractional)
|
||||||
topMix = lerp(x0y1, x1y1, diffX)
|
topMix = lerp(x0y1, x1y1, xFractional)
|
||||||
|
|
||||||
lerp(bottomMix, topMix, diffY)
|
lerp(bottomMix, topMix, yFractional)
|
||||||
|
|
||||||
proc spread*(mask: Mask, spread: float32) =
|
proc spread*(mask: Mask, spread: float32) =
|
||||||
## Grows the mask by spread.
|
## Grows the mask by spread.
|
||||||
|
|
Loading…
Reference in a new issue