commit
05252eeee9
8 changed files with 19 additions and 34 deletions
17
README.md
17
README.md
|
@ -25,8 +25,8 @@ var p: Path
|
||||||
p.polygon(100, 100, 70, sides=6)
|
p.polygon(100, 100, 70, sides=6)
|
||||||
p.closePath()
|
p.closePath()
|
||||||
|
|
||||||
let mask = newImage(200, 200)
|
let mask = newMask(200, 200)
|
||||||
mask.fillPath(p, rgba(255, 255, 255, 255))
|
mask.fillPath(p)
|
||||||
|
|
||||||
blur.blur(20)
|
blur.blur(20)
|
||||||
blur.draw(mask, blendMode = bmMask)
|
blur.draw(mask, blendMode = bmMask)
|
||||||
|
@ -47,12 +47,7 @@ let
|
||||||
r = 25.0
|
r = 25.0
|
||||||
|
|
||||||
var path: Path
|
var path: Path
|
||||||
path.moveTo(x+r, y)
|
path.roundedRect(vec2(x, y), vec2(w, h), r, r, r, r)
|
||||||
path.arcTo(x+w, y, x+w, y+h, r)
|
|
||||||
path.arcTo(x+w, y+h, x, y+h, r)
|
|
||||||
path.arcTo(x, y+h, x, y, r)
|
|
||||||
path.arcTo(x, y, x+w, y, r)
|
|
||||||
path.closePath()
|
|
||||||
|
|
||||||
image.fillPath(path, rgba(255, 0, 0, 255))
|
image.fillPath(path, rgba(255, 0, 0, 255))
|
||||||
```
|
```
|
||||||
|
@ -62,11 +57,7 @@ image.fillPath(path, rgba(255, 0, 0, 255))
|
||||||
[examples/square.nim](examples/square.nim)
|
[examples/square.nim](examples/square.nim)
|
||||||
```nim
|
```nim
|
||||||
var p: Path
|
var p: Path
|
||||||
p.moveTo(50, 50)
|
p.rect(50, 50, 100, 100)
|
||||||
p.lineTo(50, 150)
|
|
||||||
p.lineTo(150, 150)
|
|
||||||
p.lineTo(150, 50)
|
|
||||||
p.closePath()
|
|
||||||
|
|
||||||
image.fillPath(p, rgba(255, 0, 0, 255))
|
image.fillPath(p, rgba(255, 0, 0, 255))
|
||||||
```
|
```
|
||||||
|
|
|
@ -11,8 +11,8 @@ var p: Path
|
||||||
p.polygon(100, 100, 70, sides=6)
|
p.polygon(100, 100, 70, sides=6)
|
||||||
p.closePath()
|
p.closePath()
|
||||||
|
|
||||||
let mask = newImage(200, 200)
|
let mask = newMask(200, 200)
|
||||||
mask.fillPath(p, rgba(255, 255, 255, 255))
|
mask.fillPath(p)
|
||||||
|
|
||||||
blur.blur(20)
|
blur.blur(20)
|
||||||
blur.draw(mask, blendMode = bmMask)
|
blur.draw(mask, blendMode = bmMask)
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 88 KiB |
|
@ -1,4 +1,4 @@
|
||||||
import pixie, chroma
|
import pixie, chroma, vmath
|
||||||
|
|
||||||
let image = newImage(200, 200)
|
let image = newImage(200, 200)
|
||||||
image.fill(rgba(255, 255, 255, 255))
|
image.fill(rgba(255, 255, 255, 255))
|
||||||
|
@ -11,12 +11,7 @@ let
|
||||||
r = 25.0
|
r = 25.0
|
||||||
|
|
||||||
var path: Path
|
var path: Path
|
||||||
path.moveTo(x+r, y)
|
path.roundedRect(vec2(x, y), vec2(w, h), r, r, r, r)
|
||||||
path.arcTo(x+w, y, x+w, y+h, r)
|
|
||||||
path.arcTo(x+w, y+h, x, y+h, r)
|
|
||||||
path.arcTo(x, y+h, x, y, r)
|
|
||||||
path.arcTo(x, y, x+w, y, r)
|
|
||||||
path.closePath()
|
|
||||||
|
|
||||||
image.fillPath(path, rgba(255, 0, 0, 255))
|
image.fillPath(path, rgba(255, 0, 0, 255))
|
||||||
|
|
||||||
|
|
|
@ -4,11 +4,7 @@ var image = newImage(200, 200)
|
||||||
image.fill(rgba(255, 255, 255, 255))
|
image.fill(rgba(255, 255, 255, 255))
|
||||||
|
|
||||||
var p: Path
|
var p: Path
|
||||||
p.moveTo(50, 50)
|
p.rect(50, 50, 100, 100)
|
||||||
p.lineTo(50, 150)
|
|
||||||
p.lineTo(150, 150)
|
|
||||||
p.lineTo(150, 50)
|
|
||||||
p.closePath()
|
|
||||||
|
|
||||||
image.fillPath(p, rgba(255, 0, 0, 255))
|
image.fillPath(p, rgba(255, 0, 0, 255))
|
||||||
|
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 42 KiB After Width: | Height: | Size: 42 KiB |
|
@ -418,10 +418,13 @@ proc drawCorrect(
|
||||||
p = matInv * vec2(0 + h, 0 + h)
|
p = matInv * vec2(0 + h, 0 + h)
|
||||||
dx = matInv * vec2(1 + h, 0 + h) - p
|
dx = matInv * vec2(1 + h, 0 + h) - p
|
||||||
dy = matInv * vec2(0 + h, 1 + h) - p
|
dy = matInv * vec2(0 + h, 1 + h) - p
|
||||||
while max(dx.length, dy.length) > 2:
|
minFilterBy2 = max(dx.length, dy.length)
|
||||||
|
|
||||||
|
while minFilterBy2 > 2:
|
||||||
b = b.minifyBy2()
|
b = b.minifyBy2()
|
||||||
dx /= 2
|
dx /= 2
|
||||||
dy /= 2
|
dy /= 2
|
||||||
|
minFilterBy2 /= 2
|
||||||
matInv = matInv * scale(vec2(0.5, 0.5))
|
matInv = matInv * scale(vec2(0.5, 0.5))
|
||||||
|
|
||||||
for y in 0 ..< a.height:
|
for y in 0 ..< a.height:
|
||||||
|
@ -476,9 +479,6 @@ proc draw*(
|
||||||
) {.inline.} =
|
) {.inline.} =
|
||||||
mask.draw(image, translate(pos), blendMode)
|
mask.draw(image, translate(pos), blendMode)
|
||||||
|
|
||||||
when defined(release):
|
|
||||||
{.pop.}
|
|
||||||
|
|
||||||
proc gaussianLookup(radius: int): seq[float32] =
|
proc gaussianLookup(radius: int): seq[float32] =
|
||||||
## Compute lookup table for 1d Gaussian kernel.
|
## Compute lookup table for 1d Gaussian kernel.
|
||||||
result.setLen(radius * 2 + 1)
|
result.setLen(radius * 2 + 1)
|
||||||
|
@ -493,6 +493,9 @@ proc gaussianLookup(radius: int): seq[float32] =
|
||||||
for xb in -radius .. radius:
|
for xb in -radius .. radius:
|
||||||
result[xb + radius] = result[xb + radius] / total
|
result[xb + radius] = result[xb + radius] / total
|
||||||
|
|
||||||
|
when defined(release):
|
||||||
|
{.pop.}
|
||||||
|
|
||||||
proc blur*(image: Image, radius: float32) =
|
proc blur*(image: Image, radius: float32) =
|
||||||
## Applies Gaussian blur to the image given a radius.
|
## Applies Gaussian blur to the image given a radius.
|
||||||
let radius = round(radius).int
|
let radius = round(radius).int
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import blends, common, vmath, system/memory
|
import common, vmath, system/memory
|
||||||
|
|
||||||
type
|
type
|
||||||
Mask* = ref object
|
Mask* = ref object
|
||||||
|
@ -40,7 +40,7 @@ proc dataIndex*(mask: Mask, x, y: int): int {.inline.} =
|
||||||
mask.width * y + x
|
mask.width * y + x
|
||||||
|
|
||||||
proc getValueUnsafe*(mask: Mask, x, y: int): uint8 {.inline.} =
|
proc getValueUnsafe*(mask: Mask, x, y: int): uint8 {.inline.} =
|
||||||
## Gets a color from (x, y) coordinates.
|
## Gets a value from (x, y) coordinates.
|
||||||
## * No bounds checking *
|
## * No bounds checking *
|
||||||
## Make sure that x, y are in bounds.
|
## Make sure that x, y are in bounds.
|
||||||
## Failure in the assumptions will case unsafe memory reads.
|
## Failure in the assumptions will case unsafe memory reads.
|
||||||
|
@ -59,7 +59,7 @@ proc setValueUnsafe*(mask: Mask, x, y: int, value: uint8) {.inline.} =
|
||||||
mask.data[mask.dataIndex(x, y)] = value
|
mask.data[mask.dataIndex(x, y)] = value
|
||||||
|
|
||||||
proc `[]=`*(mask: Mask, x, y: int, value: uint8) {.inline.} =
|
proc `[]=`*(mask: Mask, x, y: int, value: uint8) {.inline.} =
|
||||||
## Sets a pixel at (x, y) or does nothing if outside of bounds.
|
## Sets a value at (x, y) or does nothing if outside of bounds.
|
||||||
if mask.inside(x, y):
|
if mask.inside(x, y):
|
||||||
mask.setValueUnsafe(x, y, value)
|
mask.setValueUnsafe(x, y, value)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue