diff --git a/README.md b/README.md index 5472448..488386f 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ var p: Path p.polygon(100, 100, 70, sides=6) p.closePath() -let mask = newImage(200, 200) -mask.fillPath(p, rgba(255, 255, 255, 255)) +let mask = newMask(200, 200) +mask.fillPath(p) blur.blur(20) blur.draw(mask, blendMode = bmMask) @@ -47,12 +47,7 @@ let r = 25.0 var path: Path -path.moveTo(x+r, y) -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() +path.roundedRect(vec2(x, y), vec2(w, h), r, r, r, r) 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) ```nim var p: Path -p.moveTo(50, 50) -p.lineTo(50, 150) -p.lineTo(150, 150) -p.lineTo(150, 50) -p.closePath() +p.rect(50, 50, 100, 100) image.fillPath(p, rgba(255, 0, 0, 255)) ``` diff --git a/examples/blur.nim b/examples/blur.nim index e3b11f0..aa34a4f 100644 --- a/examples/blur.nim +++ b/examples/blur.nim @@ -11,8 +11,8 @@ var p: Path p.polygon(100, 100, 70, sides=6) p.closePath() -let mask = newImage(200, 200) -mask.fillPath(p, rgba(255, 255, 255, 255)) +let mask = newMask(200, 200) +mask.fillPath(p) blur.blur(20) blur.draw(mask, blendMode = bmMask) diff --git a/examples/blur.png b/examples/blur.png index f350a4f..0f4e20b 100644 Binary files a/examples/blur.png and b/examples/blur.png differ diff --git a/examples/rounded_rectangle.nim b/examples/rounded_rectangle.nim index 63a0d31..164a76b 100644 --- a/examples/rounded_rectangle.nim +++ b/examples/rounded_rectangle.nim @@ -1,4 +1,4 @@ -import pixie, chroma +import pixie, chroma, vmath let image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) @@ -11,12 +11,7 @@ let r = 25.0 var path: Path -path.moveTo(x+r, y) -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() +path.roundedRect(vec2(x, y), vec2(w, h), r, r, r, r) image.fillPath(path, rgba(255, 0, 0, 255)) diff --git a/examples/square.nim b/examples/square.nim index 9f17fee..528d3ab 100644 --- a/examples/square.nim +++ b/examples/square.nim @@ -4,11 +4,7 @@ var image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) var p: Path -p.moveTo(50, 50) -p.lineTo(50, 150) -p.lineTo(150, 150) -p.lineTo(150, 50) -p.closePath() +p.rect(50, 50, 100, 100) image.fillPath(p, rgba(255, 0, 0, 255)) diff --git a/examples/tiger.png b/examples/tiger.png index daad6d9..da08162 100644 Binary files a/examples/tiger.png and b/examples/tiger.png differ diff --git a/src/pixie/images.nim b/src/pixie/images.nim index c2fc65d..9d00bd6 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -418,10 +418,13 @@ proc drawCorrect( p = matInv * vec2(0 + h, 0 + h) dx = matInv * vec2(1 + h, 0 + 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() dx /= 2 dy /= 2 + minFilterBy2 /= 2 matInv = matInv * scale(vec2(0.5, 0.5)) for y in 0 ..< a.height: @@ -476,9 +479,6 @@ proc draw*( ) {.inline.} = mask.draw(image, translate(pos), blendMode) -when defined(release): - {.pop.} - proc gaussianLookup(radius: int): seq[float32] = ## Compute lookup table for 1d Gaussian kernel. result.setLen(radius * 2 + 1) @@ -493,6 +493,9 @@ proc gaussianLookup(radius: int): seq[float32] = for xb in -radius .. radius: result[xb + radius] = result[xb + radius] / total +when defined(release): + {.pop.} + proc blur*(image: Image, radius: float32) = ## Applies Gaussian blur to the image given a radius. let radius = round(radius).int diff --git a/src/pixie/masks.nim b/src/pixie/masks.nim index e43347a..50c076e 100644 --- a/src/pixie/masks.nim +++ b/src/pixie/masks.nim @@ -1,4 +1,4 @@ -import blends, common, vmath, system/memory +import common, vmath, system/memory type Mask* = ref object @@ -40,7 +40,7 @@ proc dataIndex*(mask: Mask, x, y: int): int {.inline.} = mask.width * y + x 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 * ## Make sure that x, y are in bounds. ## 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 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): mask.setValueUnsafe(x, y, value)