diff --git a/README.md b/README.md index 0eaa9f1..5472448 100644 --- a/README.md +++ b/README.md @@ -21,13 +21,16 @@ This library is being actively developed and is not yet ready for use. Since you ### Blur [examples/blur.nim](examples/blur.nim) ```nim -var p = newPath() +var p: Path p.polygon(100, 100, 70, sides=6) p.closePath() -var mask = newImage(200, 200) + +let mask = newImage(200, 200) mask.fillPath(p, rgba(255, 255, 255, 255)) + blur.blur(20) blur.draw(mask, blendMode = bmMask) + image.draw(trees) image.draw(blur) ``` @@ -36,19 +39,21 @@ image.draw(blur) ### Rounded rectangle [examples/rounded_rectangle.nim](examples/rounded_rectangle.nim) ```nim -var path = newPath() let x = 50.0 y = 50.0 w = 100.0 h = 100.0 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() + image.fillPath(path, rgba(255, 0, 0, 255)) ``` ![example output](examples/rounded_rectangle.png) @@ -56,12 +61,13 @@ image.fillPath(path, rgba(255, 0, 0, 255)) ### Square [examples/square.nim](examples/square.nim) ```nim -var p = newPath() +var p: Path p.moveTo(50, 50) p.lineTo(50, 150) p.lineTo(150, 150) p.lineTo(150, 50) p.closePath() + image.fillPath(p, rgba(255, 0, 0, 255)) ``` ![example output](examples/square.png) @@ -69,7 +75,8 @@ image.fillPath(p, rgba(255, 0, 0, 255)) ### Tiger [examples/tiger.nim](examples/tiger.nim) ```nim -var tiger = readImage("examples/data/tiger.svg") +let tiger = readImage("examples/data/tiger.svg") + image.draw( tiger, translate(vec2(100, 100)) * diff --git a/examples/blur.nim b/examples/blur.nim index 7cb4216..e3b11f0 100644 --- a/examples/blur.nim +++ b/examples/blur.nim @@ -1,17 +1,22 @@ import pixie, chroma, vmath -var trees = readImage("examples/data/trees.png") -var blur = trees.copy() -var image = newImage(200, 200) +let + trees = readImage("examples/data/trees.png") + blur = trees.copy() + image = newImage(200, 200) + image.fill(rgba(255, 255, 255, 255)) -var p = newPath() +var p: Path p.polygon(100, 100, 70, sides=6) p.closePath() -var mask = newImage(200, 200) + +let mask = newImage(200, 200) mask.fillPath(p, rgba(255, 255, 255, 255)) + blur.blur(20) blur.draw(mask, blendMode = bmMask) + image.draw(trees) image.draw(blur) diff --git a/examples/blur.png b/examples/blur.png index 3705165..f350a4f 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 28be1ff..63a0d31 100644 --- a/examples/rounded_rectangle.nim +++ b/examples/rounded_rectangle.nim @@ -1,21 +1,23 @@ import pixie, chroma -var image = newImage(200, 200) +let image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) -var path = newPath() let x = 50.0 y = 50.0 w = 100.0 h = 100.0 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() + image.fillPath(path, rgba(255, 0, 0, 255)) image.writeFile("examples/rounded_rectangle.png") diff --git a/examples/rounded_rectangle.png b/examples/rounded_rectangle.png index 996594e..d79c77c 100644 Binary files a/examples/rounded_rectangle.png and b/examples/rounded_rectangle.png differ diff --git a/examples/square.nim b/examples/square.nim index 3155e18..9f17fee 100644 --- a/examples/square.nim +++ b/examples/square.nim @@ -3,12 +3,13 @@ import pixie, chroma var image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) -var p = newPath() +var p: Path p.moveTo(50, 50) p.lineTo(50, 150) p.lineTo(150, 150) p.lineTo(150, 50) p.closePath() + image.fillPath(p, rgba(255, 0, 0, 255)) image.writeFile("examples/square.png") diff --git a/examples/tiger.nim b/examples/tiger.nim index 192e184..00f741e 100644 --- a/examples/tiger.nim +++ b/examples/tiger.nim @@ -1,9 +1,10 @@ import pixie, chroma, vmath -var image = newImage(200, 200) +let image = newImage(200, 200) image.fill(rgba(255, 255, 255, 255)) -var tiger = readImage("examples/data/tiger.svg") +let tiger = readImage("examples/data/tiger.svg") + image.draw( tiger, translate(vec2(100, 100)) * diff --git a/examples/tiger.png b/examples/tiger.png index a59d012..daad6d9 100644 Binary files a/examples/tiger.png and b/examples/tiger.png differ diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim index 9ba66f0..3037594 100644 --- a/src/pixie/blends.nim +++ b/src/pixie/blends.nim @@ -554,13 +554,6 @@ proc blendHardLight(backdrop, source: ColorRGBA): ColorRGBA = result = result.toStraightAlpha() proc blendSoftLight(backdrop, source: ColorRGBA): ColorRGBA = - # proc softLight(backdrop, source: int32): uint8 {.inline.} = - # ## Pegtop - # ( - # ((255 - 2 * source) * backdrop ^ 2) div 255 ^ 2 + - # (2 * source * backdrop) div 255 - # ).uint8 - when defined(amd64) and not defined(pixieNoSimd): let vb = mm_setr_ps(backdrop.r.float32, backdrop.g.float32, backdrop.b.float32, 0) @@ -577,6 +570,16 @@ proc blendSoftLight(backdrop, source: ColorRGBA): ColorRGBA = result = alphaFix(backdrop, source, vb, vs, vm) else: blendSoftLightFloats(backdrop.color, source.color).rgba + # proc softLight(backdrop, source: int32): uint8 {.inline.} = + # ## Pegtop + # ( + # ((255 - 2 * source) * (backdrop ^ 2)) div (255 ^ 2) + + # (2 * source * backdrop) div 255 + # ).uint8 + # result.r = softLight(backdrop.r.int32, source.r.int32) + # result.g = softLight(backdrop.g.int32, source.g.int32) + # result.b = softLight(backdrop.b.int32, source.b.int32) + # result = alphaFix(backdrop, source, result) proc blendDifference(backdrop, source: ColorRGBA): ColorRGBA = let diff --git a/src/pixie/common.nim b/src/pixie/common.nim index 3ad1be1..b9e120c 100644 --- a/src/pixie/common.nim +++ b/src/pixie/common.nim @@ -39,14 +39,14 @@ func lerp*(a, b: Color, v: float32): Color {.inline.} = result.a = lerp(a.a, b.a, v) proc toPremultipliedAlpha*(c: Color): Color {.inline.} = - ## Converts a color to premultiplied alpha from straight. + ## Converts a color to premultiplied alpha from straight alpha. result.r = c.r * c.a result.g = c.g * c.a result.b = c.b * c.a result.a = c.a proc toStraightAlpha*(c: Color): Color {.inline.} = - ## Converts a color to from premultiplied alpha to straight. + ## Converts a color from premultiplied alpha to straight alpha. if c.a != 0 and c.a != 1: result = c else: