diff --git a/docs/pixie.html b/docs/pixie.html
index d93d23e..cab9ece 100644
--- a/docs/pixie.html
+++ b/docs/pixie.html
@@ -528,7 +528,7 @@ Strokes a polygon.
-maskerSimd, Masker, blender, hasSimdBlender, Blender, BlenderSimd, MaskerSimd, blenderSimd, hasSimdMasker, masker, BlendMode, blendAlpha, PixieError, lerp, lerp, fractional, lerp, getRgbaUnsafe, draw, []=, Image, copy, wh, setRgbaUnsafe, getRgbaSmooth, invert, flipVertical, magnifyBy2, draw, draw, flipHorizontal, shadow, subImage, inside, $, draw, shift, dataIndex, minifyBy2, draw, draw, fill, draw, newMask, blur, newImage, drawTiled, applyOpacity, resize, superImage, fillUnsafe, draw, [], $, setValueUnsafe, ceil, dataIndex, []=, spread, copy, wh, newMask, minifyBy2, fill, Mask, getValueUnsafe, getValueSmooth, fillUnsafe, inside, [], ColorStop, PaintKind, fillLinearGradient, fillRadialGradient, fillAngularGradient, Paint, bezierCurveTo, LineCap, arcTo, LineJoin, rect, bezierCurveTo, SomePath, strokePath, $, parsePath, fillPath, lineTo, polygon, roundedRect, quadraticCurveTo, fillPath, strokePath, ellipticalArcTo, Path, lineTo, ellipse, quadraticCurveTo, arcTo, moveTo, roundedRect, PathCommandKind, polygon, strokePath, transform, PathCommand, roundedRect, rect, fillPath, segments, closePath, addPath, rect, strokePath, commandsToShapes, ellipse, WindingRule, fillPath, moveTo, fillPath
+maskerSimd, Masker, blender, hasSimdBlender, Blender, BlenderSimd, MaskerSimd, blenderSimd, hasSimdMasker, masker, BlendMode, blendAlpha, PixieError, lerp, lerp, fractional, lerp, getRgbaUnsafe, draw, []=, Image, copy, wh, setRgbaUnsafe, getRgbaSmooth, invert, flipVertical, magnifyBy2, draw, draw, flipHorizontal, shadow, subImage, inside, $, draw, shift, dataIndex, minifyBy2, draw, draw, fill, draw, newMask, blur, newImage, drawTiled, applyOpacity, resize, superImage, fillUnsafe, draw, [], $, setValueUnsafe, ceil, dataIndex, []=, spread, copy, wh, newMask, minifyBy2, fill, Mask, getValueUnsafe, getValueSmooth, blur, fillUnsafe, inside, [], ColorStop, PaintKind, fillLinearGradient, fillRadialGradient, fillAngularGradient, Paint, bezierCurveTo, LineCap, arcTo, LineJoin, rect, bezierCurveTo, SomePath, strokePath, $, parsePath, fillPath, lineTo, polygon, roundedRect, quadraticCurveTo, fillPath, strokePath, ellipticalArcTo, Path, lineTo, ellipse, quadraticCurveTo, arcTo, moveTo, roundedRect, PathCommandKind, polygon, strokePath, transform, PathCommand, roundedRect, rect, fillPath, segments, closePath, addPath, rect, strokePath, commandsToShapes, ellipse, WindingRule, fillPath, moveTo, fillPath
@@ -538,7 +538,7 @@ Strokes a polygon.
- Made with Nim. Generated: 2021-02-26 01:51:49 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/blends.html b/docs/pixie/blends.html
index 6b26424..a3f5abc 100644
--- a/docs/pixie/blends.html
+++ b/docs/pixie/blends.html
@@ -283,7 +283,7 @@ Is there a blend masking function with SIMD support?
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/common.html b/docs/pixie/common.html
index ee15117..24522ff 100644
--- a/docs/pixie/common.html
+++ b/docs/pixie/common.html
@@ -196,7 +196,7 @@ Linearly interpolate between a and b using t.
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/fileformats/bmp.html b/docs/pixie/fileformats/bmp.html
index 988b096..3ba126d 100644
--- a/docs/pixie/fileformats/bmp.html
+++ b/docs/pixie/fileformats/bmp.html
@@ -182,7 +182,7 @@ Encodes an image into the BMP file format.
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/fileformats/jpg.html b/docs/pixie/fileformats/jpg.html
index a9090e8..de97893 100644
--- a/docs/pixie/fileformats/jpg.html
+++ b/docs/pixie/fileformats/jpg.html
@@ -182,7 +182,7 @@ Encodes Image into a JPEG data string.
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/fileformats/png.html b/docs/pixie/fileformats/png.html
index 9b3099c..1ae53fd 100644
--- a/docs/pixie/fileformats/png.html
+++ b/docs/pixie/fileformats/png.html
@@ -201,7 +201,7 @@ Encodes the mask data into the PNG file format.
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/fileformats/svg.html b/docs/pixie/fileformats/svg.html
index 72a3b76..bc25c55 100644
--- a/docs/pixie/fileformats/svg.html
+++ b/docs/pixie/fileformats/svg.html
@@ -171,7 +171,7 @@ Render SVG file and return the image. Defaults to the SVG's view box size.
- Made with Nim. Generated: 2021-02-26 01:51:49 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/images.html b/docs/pixie/images.html
index 74fbf5d..c9e47b6 100644
--- a/docs/pixie/images.html
+++ b/docs/pixie/images.html
@@ -230,8 +230,8 @@ function main() {
dataIndex
@@ -450,8 +450,8 @@ Multiplies alpha of the image by opacity.
Inverts all of the colors and alpha.
-
-proc blur(target: Image | Mask; radius: float32; offBounds: uint32 = 0)
+
+proc blur(image: Image; radius: float32) {...}{.raises: [PixieError], tags: [].}
-
Applies Gaussian blur to the image given a radius.
@@ -577,7 +577,7 @@ Create a shadow of the image with the offset, spread and blur.
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/images.idx b/docs/pixie/images.idx
index 380844e..9d0229e 100644
--- a/docs/pixie/images.idx
+++ b/docs/pixie/images.idx
@@ -19,7 +19,7 @@ minifyBy2 pixie/images.html#minifyBy2,Image,int images: minifyBy2(image: Image;
magnifyBy2 pixie/images.html#magnifyBy2,Image,int images: magnifyBy2(image: Image; power = 1): Image
applyOpacity pixie/images.html#applyOpacity,,float32 images: applyOpacity(target: Image | Mask; opacity: float32)
invert pixie/images.html#invert images: invert(target: Image | Mask)
-blur pixie/images.html#blur,,float32,uint32 images: blur(target: Image | Mask; radius: float32; offBounds: uint32 = 0)
+blur pixie/images.html#blur,Image,float32 images: blur(image: Image; radius: float32)
newMask pixie/images.html#newMask,Image images: newMask(image: Image): Mask
getRgbaSmooth pixie/images.html#getRgbaSmooth,Image,float32,float32 images: getRgbaSmooth(image: Image; x, y: float32; wrapped = false): ColorRGBX
draw pixie/images.html#draw,Image,Image,Mat3 images: draw(a, b: Image; mat: Mat3; blendMode = bmNormal)
diff --git a/docs/pixie/internal.html b/docs/pixie/internal.html
index bc4eeb3..d08b156 100644
--- a/docs/pixie/internal.html
+++ b/docs/pixie/internal.html
@@ -98,6 +98,11 @@ function main() {
- toPremultipliedAlpha,seq[]
+
+
unpackAlphaValues
-
+
+proc gaussianLookup(radius: int): seq[uint32] {...}{.raises: [], tags: [].}
+-
+
+Compute lookup table for 1d Gaussian kernel. Values are [0, 255] * 1024.
+
+
proc toStraightAlpha(data: var seq[ColorRGBA | ColorRGBX])
-
@@ -166,7 +178,7 @@ Unpack the first 32 bits into 4 rgba(0, 0, 0, value)
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/internal.idx b/docs/pixie/internal.idx
index f38462f..139733f 100644
--- a/docs/pixie/internal.idx
+++ b/docs/pixie/internal.idx
@@ -1,3 +1,4 @@
+gaussianLookup pixie/internal.html#gaussianLookup,int internal: gaussianLookup(radius: int): seq[uint32]
toStraightAlpha pixie/internal.html#toStraightAlpha,seq[] internal: toStraightAlpha(data: var seq[ColorRGBA | ColorRGBX])
toPremultipliedAlpha pixie/internal.html#toPremultipliedAlpha,seq[] internal: toPremultipliedAlpha(data: var seq[ColorRGBA | ColorRGBX])
packAlphaValues pixie/internal.html#packAlphaValues,M128i internal: packAlphaValues(v: M128i): M128i
diff --git a/docs/pixie/masks.html b/docs/pixie/masks.html
index a5c4e80..187f214 100644
--- a/docs/pixie/masks.html
+++ b/docs/pixie/masks.html
@@ -159,6 +159,11 @@ function main() {
- getValueUnsafe,Mask,int,int
+
+
dataIndex
-
-common
+common, internal
@@ -343,6 +348,14 @@ Grows the mask by spread.
A value of 0 stays 0. Anything else turns into 255.
+
+
+
proc blur(mask: Mask; radius: float32; outOfBounds: uint8 = 0) {...}{.
+ raises: [PixieError], tags: [].}
+
-
+
+Applies Gaussian blur to the image given a radius.
+
@@ -354,7 +367,7 @@ A value of 0 stays 0. Anything else turns into 255.
- Made with Nim. Generated: 2021-02-26 01:51:48 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/masks.idx b/docs/pixie/masks.idx
index cc7f367..f84462e 100644
--- a/docs/pixie/masks.idx
+++ b/docs/pixie/masks.idx
@@ -15,3 +15,4 @@ fill pixie/masks.html#fill,Mask,uint8 masks: fill(mask: Mask; value: uint8)
getValueSmooth pixie/masks.html#getValueSmooth,Mask,float32,float32 masks: getValueSmooth(mask: Mask; x, y: float32): uint8
spread pixie/masks.html#spread,Mask,float32 masks: spread(mask: Mask; spread: float32)
ceil pixie/masks.html#ceil,Mask masks: ceil(mask: Mask)
+blur pixie/masks.html#blur,Mask,float32,uint8 masks: blur(mask: Mask; radius: float32; outOfBounds: uint8 = 0)
diff --git a/docs/pixie/paints.html b/docs/pixie/paints.html
index b0b6bb0..a8805f9 100644
--- a/docs/pixie/paints.html
+++ b/docs/pixie/paints.html
@@ -243,7 +243,7 @@ Angular gradient.
- Made with Nim. Generated: 2021-02-26 01:51:49 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/pixie/paths.html b/docs/pixie/paths.html
index ea48e66..bc5cfea 100644
--- a/docs/pixie/paths.html
+++ b/docs/pixie/paths.html
@@ -662,7 +662,7 @@ Return elements in pairs: (1st, 2nd), (2nd, 3rd) ... (n - 1, last).
- Made with Nim. Generated: 2021-02-26 01:51:49 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/docs/theindex.html b/docs/theindex.html
index bbe5645..d1c4bad 100644
--- a/docs/theindex.html
+++ b/docs/theindex.html
@@ -134,7 +134,9 @@ function main() {
blur:
bmColor:
+gaussianLookup:
getRgbaSmooth:
- images: getRgbaSmooth(image: Image; x, y: float32; wrapped = false): ColorRGBX
@@ -915,7 +921,7 @@ function main() {
- Made with Nim. Generated: 2021-02-26 01:51:49 UTC
+ Made with Nim. Generated: 2021-02-27 00:46:16 UTC
diff --git a/pixie.nimble b/pixie.nimble
index 836640d..cd3cadb 100644
--- a/pixie.nimble
+++ b/pixie.nimble
@@ -1,4 +1,4 @@
-version = "1.0.0"
+version = "1.0.1"
author = "Andre von Houck and Ryan Oldenburg"
description = "Full-featured 2d graphics library for Nim."
license = "MIT"
diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim
index 2af2546..019d3f7 100644
--- a/src/pixie/blends.nim
+++ b/src/pixie/blends.nim
@@ -451,7 +451,7 @@ proc blendOverwrite(backdrop, source: ColorRGBX): ColorRGBX =
# proc blendWhite(backdrop, source: ColorRGBX): ColorRGBX =
# ## For testing
-# rgba(255, 255, 255, 255)
+# rgbx(255, 255, 255, 255)
proc blender*(blendMode: BlendMode): Blender =
## Returns a blend function for a given blend mode.
diff --git a/src/pixie/images.nim b/src/pixie/images.nim
index 6767622..008319c 100644
--- a/src/pixie/images.nim
+++ b/src/pixie/images.nim
@@ -309,7 +309,7 @@ proc invert*(target: Image | Mask) =
rgba.a = 255 - rgba.a
target.data[j] = rgba
- # Inverting rgba(50, 100, 150, 200) becomes rgba(205, 155, 105, 55). This
+ # Inverting rgbx(50, 100, 150, 200) becomes rgbx(205, 155, 105, 55). This
# is not a valid premultiplied alpha color.
# We need to convert back to premultiplied alpha after inverting.
target.data.toPremultipliedAlpha()
@@ -327,7 +327,7 @@ proc blur*(image: Image, radius: float32) =
# TODO support offBounds for images.
- template `*`(sample: ColorRGBA, a: uint32): array[4, uint32] =
+ template `*`(sample: ColorRGBX, a: uint32): array[4, uint32] =
[
sample.r * a,
sample.g * a,
@@ -341,8 +341,8 @@ proc blur*(image: Image, radius: float32) =
values[2] += sample[2]
values[3] += sample[3]
- template rgba(values: array[4, uint32]): ColorRGBA =
- rgba(
+ template rgbx(values: array[4, uint32]): ColorRGBX =
+ rgbx(
(values[0] div 1024 div 255).uint8,
(values[1] div 1024 div 255).uint8,
(values[2] div 1024 div 255).uint8,
@@ -367,7 +367,7 @@ proc blur*(image: Image, radius: float32) =
a = lookup[step + radius].uint32
values += sample * a
- blurX.setRgbaUnsafe(x, y, values.rgba())
+ blurX.setRgbaUnsafe(x, y, values.rgbx())
# Blur in the Y direction.
for y in 0 ..< image.height:
@@ -386,7 +386,7 @@ proc blur*(image: Image, radius: float32) =
a = lookup[step + radius].uint32
values += sample * a
- image.setRgbaUnsafe(x, y, values.rgba())
+ image.setRgbaUnsafe(x, y, values.rgbx())
proc newMask*(image: Image): Mask =
## Returns a new mask using the alpha values of the parameter image.
@@ -497,7 +497,7 @@ proc drawCorrect(
else: # b is a Mask
let
sample = b.getValueSmooth(xFloat, yFloat)
- blended = blender(backdrop, rgba(0, 0, 0, sample))
+ blended = blender(backdrop, rgbx(0, 0, 0, sample))
a.setRgbaUnsafe(x, y, blended)
else: # a is a Mask
let backdrop = a.getValueUnsafe(x, y)
@@ -767,7 +767,7 @@ proc shift*(target: Image | Mask, offset: Vec2) =
# Reset target for being drawn to
when type(target) is Image:
- target.fill(rgba(0, 0, 0, 0))
+ target.fill(rgbx(0, 0, 0, 0))
else:
target.fill(0)
diff --git a/tests/benchmark_images.nim b/tests/benchmark_images.nim
index 8112f1b..fc9a184 100644
--- a/tests/benchmark_images.nim
+++ b/tests/benchmark_images.nim
@@ -1,4 +1,4 @@
-import benchy, chroma, pixie
+import benchy, chroma, pixie, pixie/internal
let image = newImage(2560, 1440)
@@ -46,12 +46,12 @@ timeIt "applyOpacity":
reset()
timeIt "toPremultipliedAlpha":
- image.toPremultipliedAlpha()
+ image.data.toPremultipliedAlpha()
reset()
timeIt "toStraightAlpha":
- image.toStraightAlpha()
+ image.data.toStraightAlpha()
reset()
diff --git a/tests/images/imageblur20.png b/tests/images/imageblur20.png
new file mode 100644
index 0000000..9704d36
Binary files /dev/null and b/tests/images/imageblur20.png differ
diff --git a/tests/images/maskblur20.png b/tests/images/maskblur20.png
new file mode 100644
index 0000000..bab2143
Binary files /dev/null and b/tests/images/maskblur20.png differ
diff --git a/tests/test_images.nim b/tests/test_images.nim
index e51e74b..08fa617 100644
--- a/tests/test_images.nim
+++ b/tests/test_images.nim
@@ -104,3 +104,10 @@ block:
a.fill(rgbx(50, 100, 150, 200))
a.invert()
doAssert a[0, 0] == rgbx(44, 33, 22, 55)
+
+block:
+ let image = newImage(100, 100)
+ image.fill(rgba(0, 0, 0, 255))
+ image.fillRect(rect(25, 25, 50, 50), rgba(255, 255, 255, 255))
+ image.blur(20)
+ image.writeFile("tests/images/imageblur20.png")
diff --git a/tests/test_masks.nim b/tests/test_masks.nim
index a2b8018..4414f28 100644
--- a/tests/test_masks.nim
+++ b/tests/test_masks.nim
@@ -149,3 +149,9 @@ block:
let mask = newMask(100, 100)
mask.strokePolygon(vec2(50, 50), 30, 6, 10)
writeFile("tests/images/masks/strokePolygon.png", mask.encodePng())
+
+block:
+ let mask = newMask(100, 100)
+ mask.fillRect(rect(25, 25, 50, 50))
+ mask.blur(20)
+ writeFile("tests/images/maskblur20.png", mask.encodePng())