From 5e3e489f619f465051c3faf253d45db50872d1b6 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Thu, 25 Feb 2021 12:14:58 -0600 Subject: [PATCH 1/2] internal.nim --- src/pixie/blends.nim | 52 +++++++----------------------------------- src/pixie/images.nim | 2 +- src/pixie/internal.nim | 38 ++++++++++++++++++++++++++++++ src/pixie/paths.nim | 3 ++- 4 files changed, 49 insertions(+), 46 deletions(-) create mode 100644 src/pixie/internal.nim diff --git a/src/pixie/blends.nim b/src/pixie/blends.nim index aca4bbc..72c7246 100644 --- a/src/pixie/blends.nim +++ b/src/pixie/blends.nim @@ -35,10 +35,10 @@ type bmIntersectMask bmExcludeMask - Blender* = proc(backdrop, source: ColorRGBA): ColorRGBA ## Function signature - ## returned by blender. - Masker* = proc(backdrop, source: uint8): uint8 ## Function signature returned - ## by masker. + Blender* = proc(backdrop, source: ColorRGBA): ColorRGBA + ## Function signature returned by blender. + Masker* = proc(backdrop, source: uint8): uint8 + ## Function signature returned by masker. when defined(release): {.push checks: off.} @@ -515,46 +515,10 @@ when defined(amd64) and not defined(pixieNoSimd): import nimsimd/sse2 type - BlenderSimd* = proc(blackdrop, source: M128i): M128i ## Function signature - ## returned by blenderSimd. - MaskerSimd* = proc(blackdrop, source: M128i): M128i ## Function signature - ## returned by maskerSimd. - - proc packAlphaValues*(v: M128i): M128i {.inline.} = - ## Shuffle the alpha values for these 4 colors to the first 4 bytes - result = mm_srli_epi32(v, 24) - let - i = mm_srli_si128(result, 3) - j = mm_srli_si128(result, 6) - k = mm_srli_si128(result, 9) - first32 = cast[M128i]([uint32.high, 0, 0, 0]) - result = mm_or_si128(mm_or_si128(result, i), mm_or_si128(j, k)) - result = mm_and_si128(result, first32) - - proc unpackAlphaValues*(v: M128i): M128i {.inline.} = - ## Unpack the first 32 bits into 4 rgba(0, 0, 0, value) - let - first32 = cast[M128i]([uint32.high, 0, 0, 0]) # First 32 bits - alphaMask = mm_set1_epi32(cast[int32](0xff000000)) # Only `a` - - result = mm_shuffle_epi32(v, MM_SHUFFLE(0, 0, 0, 0)) - - var - i = mm_and_si128(result, first32) - j = mm_and_si128(result, mm_slli_si128(first32, 4)) - k = mm_and_si128(result, mm_slli_si128(first32, 8)) - l = mm_and_si128(result, mm_slli_si128(first32, 12)) - - # Shift the values to `a` - i = mm_slli_si128(i, 3) - j = mm_slli_si128(j, 2) - k = mm_slli_si128(k, 1) - # l = mm_slli_si128(l, 0) - - result = mm_and_si128( - mm_or_si128(mm_or_si128(i, j), mm_or_si128(k, l)), - alphaMask - ) + BlenderSimd* = proc(blackdrop, source: M128i): M128i + ## Function signature returned by blenderSimd. + MaskerSimd* = proc(blackdrop, source: M128i): M128i + ## Function signature returned by maskerSimd. proc blendNormalSimd(backdrop, source: M128i): M128i = let diff --git a/src/pixie/images.nim b/src/pixie/images.nim index 6bd4d59..bf908c2 100644 --- a/src/pixie/images.nim +++ b/src/pixie/images.nim @@ -1,4 +1,4 @@ -import blends, bumpy, chroma, common, masks, system/memory, vmath +import blends, bumpy, chroma, common, masks, pixie/internal, system/memory, vmath when defined(amd64) and not defined(pixieNoSimd): import nimsimd/sse2 diff --git a/src/pixie/internal.nim b/src/pixie/internal.nim new file mode 100644 index 0000000..c2fc581 --- /dev/null +++ b/src/pixie/internal.nim @@ -0,0 +1,38 @@ +when defined(amd64) and not defined(pixieNoSimd): + import nimsimd/sse2 + + proc packAlphaValues*(v: M128i): M128i {.inline.} = + ## Shuffle the alpha values for these 4 colors to the first 4 bytes + result = mm_srli_epi32(v, 24) + let + i = mm_srli_si128(result, 3) + j = mm_srli_si128(result, 6) + k = mm_srli_si128(result, 9) + first32 = cast[M128i]([uint32.high, 0, 0, 0]) + result = mm_or_si128(mm_or_si128(result, i), mm_or_si128(j, k)) + result = mm_and_si128(result, first32) + + proc unpackAlphaValues*(v: M128i): M128i {.inline.} = + ## Unpack the first 32 bits into 4 rgba(0, 0, 0, value) + let + first32 = cast[M128i]([uint32.high, 0, 0, 0]) # First 32 bits + alphaMask = mm_set1_epi32(cast[int32](0xff000000)) # Only `a` + + result = mm_shuffle_epi32(v, MM_SHUFFLE(0, 0, 0, 0)) + + var + i = mm_and_si128(result, first32) + j = mm_and_si128(result, mm_slli_si128(first32, 4)) + k = mm_and_si128(result, mm_slli_si128(first32, 8)) + l = mm_and_si128(result, mm_slli_si128(first32, 12)) + + # Shift the values to `a` + i = mm_slli_si128(i, 3) + j = mm_slli_si128(j, 2) + k = mm_slli_si128(k, 1) + # l = mm_slli_si128(l, 0) + + result = mm_and_si128( + mm_or_si128(mm_or_si128(i, j), mm_or_si128(k, l)), + alphaMask + ) diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index 66af2df..777c9da 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -1,4 +1,5 @@ -import blends, bumpy, chroma, common, images, masks, paints, strutils, vmath +import blends, bumpy, chroma, common, images, masks, paints, pixie/internal, + strutils, vmath when defined(amd64) and not defined(pixieNoSimd): import nimsimd/sse2 From 44a4f903318a67b08c6781637be0351e12a67f9e Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Thu, 25 Feb 2021 12:16:04 -0600 Subject: [PATCH 2/2] updated docs --- docs/pixie.html | 4 +- docs/pixie/blends.html | 26 +----- docs/pixie/blends.idx | 2 - docs/pixie/common.html | 2 +- docs/pixie/fileformats/bmp.html | 2 +- docs/pixie/fileformats/jpg.html | 2 +- docs/pixie/fileformats/png.html | 2 +- docs/pixie/fileformats/svg.html | 2 +- docs/pixie/images.html | 4 +- docs/pixie/internal.html | 152 ++++++++++++++++++++++++++++++++ docs/pixie/internal.idx | 2 + docs/pixie/masks.html | 2 +- docs/pixie/paints.html | 2 +- docs/pixie/paths.html | 4 +- docs/theindex.html | 8 +- 15 files changed, 172 insertions(+), 44 deletions(-) create mode 100644 docs/pixie/internal.html create mode 100644 docs/pixie/internal.idx diff --git a/docs/pixie.html b/docs/pixie.html index 11511a2..9b5b344 100644 --- a/docs/pixie.html +++ b/docs/pixie.html @@ -528,7 +528,7 @@ Strokes a polygon.

Exports

-unpackAlphaValues, Masker, maskerSimd, blender, hasSimdBlender, Blender, BlenderSimd, MaskerSimd, packAlphaValues, blenderSimd, hasSimdMasker, masker, BlendMode, blendAlpha, toPremultipliedAlpha, toPremultipliedAlpha, toStraightAlpha, PixieError, lerp, lerp, fractional, toStraightAlpha, 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, toPremultipliedAlpha, drawTiled, applyOpacity, resize, superImage, fillUnsafe, draw, toStraightAlpha, [], $, 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, toPremultipliedAlpha, toPremultipliedAlpha, toStraightAlpha, PixieError, lerp, lerp, fractional, toStraightAlpha, 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, toPremultipliedAlpha, drawTiled, applyOpacity, resize, superImage, fillUnsafe, draw, toStraightAlpha, [], $, 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
@@ -538,7 +538,7 @@ Strokes a polygon. diff --git a/docs/pixie/blends.html b/docs/pixie/blends.html index df6f9f5..d605418 100644 --- a/docs/pixie/blends.html +++ b/docs/pixie/blends.html @@ -156,16 +156,6 @@ function main() {
  • maskerSimd,BlendMode
  • - - - @@ -252,20 +242,6 @@ Blends alphas of backdrop, source. - - -
    proc packAlphaValues(v: M128i): M128i {...}{.inline, raises: [], tags: [].}
    -
    - -Shuffle the alpha values for these 4 colors to the first 4 bytes - -
    - -
    proc unpackAlphaValues(v: M128i): M128i {...}{.inline, raises: [], tags: [].}
    -
    - -Unpack the first 32 bits into 4 rgba(0, 0, 0, value) -
    proc blenderSimd(blendMode: BlendMode): BlenderSimd {...}{.raises: [PixieError],
    @@ -307,7 +283,7 @@ Is there a blend masking function with SIMD support?
           
         
       
    diff --git a/docs/pixie/blends.idx b/docs/pixie/blends.idx
    index fde94db..0d796a7 100644
    --- a/docs/pixie/blends.idx
    +++ b/docs/pixie/blends.idx
    @@ -27,8 +27,6 @@ blender	pixie/blends.html#blender,BlendMode	blends: blender(blendMode: BlendMode
     masker	pixie/blends.html#masker,BlendMode	blends: masker(blendMode: BlendMode): Masker	
     BlenderSimd	pixie/blends.html#BlenderSimd	blends: BlenderSimd	
     MaskerSimd	pixie/blends.html#MaskerSimd	blends: MaskerSimd	
    -packAlphaValues	pixie/blends.html#packAlphaValues,M128i	blends: packAlphaValues(v: M128i): M128i	
    -unpackAlphaValues	pixie/blends.html#unpackAlphaValues,M128i	blends: unpackAlphaValues(v: M128i): M128i	
     blenderSimd	pixie/blends.html#blenderSimd,BlendMode	blends: blenderSimd(blendMode: BlendMode): BlenderSimd	
     hasSimdBlender	pixie/blends.html#hasSimdBlender,BlendMode	blends: hasSimdBlender(blendMode: BlendMode): bool	
     maskerSimd	pixie/blends.html#maskerSimd,BlendMode	blends: maskerSimd(blendMode: BlendMode): MaskerSimd	
    diff --git a/docs/pixie/common.html b/docs/pixie/common.html
    index eca7409..54133c5 100644
    --- a/docs/pixie/common.html
    +++ b/docs/pixie/common.html
    @@ -239,7 +239,7 @@ Linearly interpolate between a and b using t.
           
         
       
    diff --git a/docs/pixie/fileformats/bmp.html b/docs/pixie/fileformats/bmp.html
    index 2e1862b..a6e9758 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.
           
         
       
    diff --git a/docs/pixie/fileformats/jpg.html b/docs/pixie/fileformats/jpg.html
    index 963880a..d704c61 100644
    --- a/docs/pixie/fileformats/jpg.html
    +++ b/docs/pixie/fileformats/jpg.html
    @@ -182,7 +182,7 @@ Encodes Image into a JPEG data string.
           
         
       
    diff --git a/docs/pixie/fileformats/png.html b/docs/pixie/fileformats/png.html
    index 82165e6..acc4387 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.
           
         
       
    diff --git a/docs/pixie/fileformats/svg.html b/docs/pixie/fileformats/svg.html
    index 9cdb4df..0f7162a 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.
           
         
       
    diff --git a/docs/pixie/images.html b/docs/pixie/images.html
    index 50efb5f..e544fd1 100644
    --- a/docs/pixie/images.html
    +++ b/docs/pixie/images.html
    @@ -288,7 +288,7 @@ function main() {
       
     

    Types

    @@ -601,7 +601,7 @@ Create a shadow of the image with the offset, spread and blur.
    diff --git a/docs/pixie/internal.html b/docs/pixie/internal.html new file mode 100644 index 0000000..8c1a79f --- /dev/null +++ b/docs/pixie/internal.html @@ -0,0 +1,152 @@ + + + + + + + + + + + + + + + + + + +pixie/internal + + + + + + + + +
    +
    +

    pixie/internal

    +
    +
    +
    + +     Dark Mode +
    + +
    + Search: +
    +
    + Group by: + +
    + + +
    +
    +
    + +

    +
    +

    Procs

    +
    + +
    proc packAlphaValues(v: M128i): M128i {...}{.inline, raises: [], tags: [].}
    +
    + +Shuffle the alpha values for these 4 colors to the first 4 bytes + +
    + +
    proc unpackAlphaValues(v: M128i): M128i {...}{.inline, raises: [], tags: [].}
    +
    + +Unpack the first 32 bits into 4 rgba(0, 0, 0, value) + +
    + +
    + +
    +
    + +
    + +
    +
    +
    + + + diff --git a/docs/pixie/internal.idx b/docs/pixie/internal.idx new file mode 100644 index 0000000..38f86be --- /dev/null +++ b/docs/pixie/internal.idx @@ -0,0 +1,2 @@ +packAlphaValues pixie/internal.html#packAlphaValues,M128i internal: packAlphaValues(v: M128i): M128i +unpackAlphaValues pixie/internal.html#unpackAlphaValues,M128i internal: unpackAlphaValues(v: M128i): M128i diff --git a/docs/pixie/masks.html b/docs/pixie/masks.html index 8a2546f..3310c50 100644 --- a/docs/pixie/masks.html +++ b/docs/pixie/masks.html @@ -354,7 +354,7 @@ A value of 0 stays 0. Anything else turns into 255. diff --git a/docs/pixie/paints.html b/docs/pixie/paints.html index dca9d0b..3bbc62c 100644 --- a/docs/pixie/paints.html +++ b/docs/pixie/paints.html @@ -243,7 +243,7 @@ Angular gradient. diff --git a/docs/pixie/paths.html b/docs/pixie/paths.html index b1685f3..5220dc4 100644 --- a/docs/pixie/paths.html +++ b/docs/pixie/paths.html @@ -289,7 +289,7 @@ function main() {

    Types

    @@ -662,7 +662,7 @@ Return elements in pairs: (1st, 2nd), (2nd, 3rd) ... (n - 1, last).
    diff --git a/docs/theindex.html b/docs/theindex.html index 2bfc9bf..aac6e02 100644 --- a/docs/theindex.html +++ b/docs/theindex.html @@ -63,7 +63,7 @@ function main() {

    Index

    - Modules: pixie, pixie/blends, pixie/common, pixie/fileformats/bmp, pixie/fileformats/jpg, pixie/fileformats/png, pixie/fileformats/svg, pixie/images, pixie/masks, pixie/paints, pixie/paths.

    API symbols

    + Modules: pixie, pixie/blends, pixie/common, pixie/fileformats/bmp, pixie/fileformats/jpg, pixie/fileformats/png, pixie/fileformats/svg, pixie/images, pixie/internal, pixie/masks, pixie/paints, pixie/paths.

    API symbols

    `$`:
    packAlphaValues:
    • blends: packAlphaValues(v: M128i): M128i
    • + data-doc-search-tag="internal: packAlphaValues(v: M128i): M128i" href="pixie/internal.html#packAlphaValues%2CM128i">internal: packAlphaValues(v: M128i): M128i
    Paint:
    unpackAlphaValues:
    • blends: unpackAlphaValues(v: M128i): M128i
    • + data-doc-search-tag="internal: unpackAlphaValues(v: M128i): M128i" href="pixie/internal.html#unpackAlphaValues%2CM128i">internal: unpackAlphaValues(v: M128i): M128i
    VLine: