#!/usr/bin/env dub
/+ dub.sdl:
name "images_mir_slice_algorithms"
dependency "sparkles:math" path="../../../../.."
dependency "mir-algorithm" version="==3.22.4"
dflags "-preview=in" "-preview=dip1000"
buildType "checked" {
buildOptions "optimize" "inline" "debugInfo"
}
+/
/**
* Two image algorithms over mir `Slice` views: a per-pixel map (straight to
* premultiplied alpha) and a 3x3 box blur over overlapping `windows`, each
* written once against a pixel struct and once against `sparkles.math`'s
* `Vector` as the pixel type, plus a hand-written loop blur over one 8-bit
* plane for the generated-code comparison.
*
* Every kernel is a non-template `@safe pure nothrow @nogc` function, so the
* compiler checks those attributes rather than inferring them.
*
* Backs ./slice-experiment.md (sections "Per-pixel map", "Box blur over
* windows", "sparkles.math Vector as the pixel" and "Generated code").
*
* Run with: `dub run --single slice-algorithms.d`
*/
module (module) images_mir_slice_algorithmsTwo image algorithms over mir Slice views: a per-pixel map (straight to
premultiplied alpha) and a 3x3 box blur over overlapping windows, each
written once against a pixel struct and once against sparkles.math's
Vector as the pixel type, plus a hand-written loop blur over one 8-bit
plane for the generated-code comparison.
Every kernel is a non-template @safe pure nothrow @nogc function, so the
compiler checks those attributes rather than inferring them.
Backs ./slice-experiment.md (sections "Per-pixel map", "Box blur over
windows", "sparkles.math Vector as the pixel" and "Generated code").
Run with: dub run --single slice-algorithms.d
images_mir_slice_algorithms;
import (package) stdstd.(module) std.stdioCategory Symbols File handles _popen File isFileHandle openNetwork stderr stdin stdout Reading chunks lines readf readfln readln Writing toFile write writef writefln writeln Misc KeepTerminator LockType StdioException
Standard I/O functions that extend core.stdc.stdio. core.stdc.stdio
is publically imported when importing std.stdio.
There are three layers of I/O:
The lowest layer is the operating system layer. The two main schemes are Windows and Posix.
C's stdio.h which unifies the two operating system schemes.
std.stdio, this module, unifies the various stdio.h implementations into
a high level package for D programs.
Source
std/stdio.d
stdio : (alias template) images_mir_slice_algorithms.writefln = std.stdio.writefln(alias fmt, A...)(A args) if (isSomeString!(typeof(fmt)))Equivalent to writef(fmt, args, '\n').
writefln;
import (package) mirmir.(package) mir.ndslicendslice.(module) mir.ndslice.sliceThis is a submodule of mir.ndslice.
Safety note
User-defined iterators should care about their safety except bounds checks.
Bounds are checked in ndslice code.
slice : Slice, (alias template) images_mir_slice_algorithms.sliced = mir.ndslice.slice.sliced(ulong N, Iterator)(return scope Iterator iterator, size_t[N] lengths...) if (!__traits(isStaticArray, Iterator) && N && !is(Iterator : Slice!(_Iterator, _N, kind), _Iterator, size_t _N, SliceKind kind))Creates an n-dimensional slice-shell over an iterator.
sliced;
import (package) mirmir.(package) mir.ndslicendslice.(module) mir.ndslice.topologyThis is a submodule of mir.ndslice.
Selectors create new views and iteration patterns over the same data, without copying.
Function Name Description
| cycle | Cycle repeates 1-dimensional field/range/array/slice in a fixed length 1-dimensional slice |
| iota | Contiguous Slice with initial flattened (contiguous) index. |
| linspace | Evenly spaced numbers over a specified interval. |
| magic | Magic square. |
| ndiota | Contiguous Slice with initial multidimensional index. |
| repeat | Slice with identical values |
Function Name Description
| blocks | n-dimensional slice composed of n-dimensional non-overlapping blocks. If the slice has two dimensions, it is a block matrix. |
| diagonal | 1-dimensional slice composed of diagonal elements |
| dropBorders | Drops borders for all dimensions. |
| reshape | New slice view with changed dimensions |
| squeeze | New slice view of an n-dimensional slice with dimension removed |
| unsqueeze | New slice view of an n-dimensional slice with a dimension added |
| windows | n-dimensional slice of n-dimensional overlapping windows. If the slice has two dimensions, it is a sliding window. |
Function Name Description
| alongDim | Returns a slice that can be iterated along dimension. |
| byDim | Returns a slice that can be iterated by dimension. |
| pack | Returns slice of slices. |
| ipack | Returns slice of slices. |
| unpack | Merges two hight dimension packs. See also fuse . |
| evertPack | Reverses dimension packs. |
Function Name Description
| asKindOf | Converts a slice to a user provied kind SliceKind . |
| universal | Converts a slice to universal SliceKind . |
| canonical | Converts a slice to canonical SliceKind . |
| assumeCanonical | Converts a slice to canonical SliceKind . Does only assert checks. |
| assumeContiguous | Converts a slice to contiguous SliceKind . Does only assert checks. |
| assumeHypercube | Helps the compiler to use optimisations related to the shape form. Does only assert checks. |
| assumeSameShape | Helps the compiler to use optimisations related to the shape form. Does only assert checks. |
Function Name Description
| cartesian | Cartesian product. |
| kronecker | Kronecker product. |
Function Name Description
| as | Convenience function that creates a lazy view, where each element of the original slice is converted to a type T. |
| bitpack | Bitpack slice over an unsigned integral slice. |
| bitwise | Bitwise slice over an unsigned integral slice. |
| bytegroup | Groups existing slice into fixed length chunks and uses them as data store for destination type. |
| cached | Random access cache. It is usefull in combiation with map and vmap. |
| cachedGC | Random access cache auto-allocated in GC heap. It is usefull in combiation with map and vmap. |
| diff | Differences between vector elements. |
| flattened | Contiguous 1-dimensional slice of all elements of a slice. |
| map | Multidimensional functional map. |
| member | Field (element's member) projection. |
| orthogonalReduceField | Functional deep-element wise reduce of a slice composed of fields or iterators. |
| pairwise | Pairwise map for vectors. |
| pairwiseMapSubSlices | Maps pairwise index pairs to subslices. |
| retro | Reverses order of iteration for all dimensions. |
| slide | Lazy convolution for tensors. |
| slideAlong | Lazy convolution for tensors. |
| stairs | Two functions to pack, unpack, and iterate triangular and symmetric matrix storage. |
| stride | Strides 1-dimensional slice. |
| subSlices | Maps index pairs to subslices. |
| triplets | Constructs a lazy view of triplets with left, center, and right members. The topology is usefull for Math and Physics. |
| unzip | Selects a slice from a zipped slice. |
| withNeighboursSum | Zip view of elements packed with sum of their neighbours. |
| zip | Zips slices into a slice of refTuples. |
Subspace selectors serve to generalize and combine other selectors easily.
For a slice of Slice!(Iterator, N, kind) type slice.pack!K creates a slice of
slices of Slice!(kind, [N - K, K], Iterator) type by packing
the last K dimensions of the top dimension pack,
and the type of element of flattened is Slice!(Iterator, K).
Another way to use pack is transposition of dimension packs using
evertPack.
Examples of use of subspace selectors are available for selectors,
Slice.shape , and Slice.elementCount .
Sponsors
Part of this work has been sponsored by Symmetry Investments and Kaleidic Associates.
topology : (alias template) images_mir_slice_algorithms.flattened = mir.ndslice.topology.flattened(Iterator, ulong N, mir_slice_kind kind)(Slice!(Iterator, N, kind) slice) if (N != 1 && (kind != Contiguous))A contiguous 1-dimensional slice of all elements of a slice.
flattened iterates existing data.
The order of elements is preserved.
flattened can be generalized with other selectors.
flattened, (alias template) images_mir_slice_algorithms.map = mir.ndslice.topology.map(fun...) if (fun.length)Implements the homonym function (also known as transform) present
in many languages of functional flavor. The call ``map!(fun)(slice)
returns a slice of which elements are obtained by applying fun
for all elements in slice. The original slices are
not changed. Evaluation is done lazily.
Note
dynamic, transposed and
topology, pack can be used to specify dimensions.
map, (alias template) images_mir_slice_algorithms.windows = mir.ndslice.topology.windows(Iterator, ulong N, mir_slice_kind kind)(Slice!(Iterator, N, kind) slice, size_t[N] rlengths...)Returns an n-dimensional slice of n-dimensional overlapping windows.
windows can be generalized with other selectors.
For example, windows in combination with diagonal can be used to get a multi-diagonal slice.
windows;
import (package) sparklessparkles.(module) sparkles.mathmath : (alias struct) images_mir_slice_algorithms.Vector = sparkles.math.vector.Vector(T, ulong N, Layout layout = Layout.packed, string[] names = defaultNames!N) if (isNumeric!T && (N > 0))A vector of N components of type T, laid out as layout, with the
components named names.
Vector;
struct (struct) images_mir_slice_algorithms.Rgba8Rgba8
{
ubyte (field) ubyte images_mir_slice_algorithms.Rgba8.rr, (field) ubyte images_mir_slice_algorithms.Rgba8.gg, (field) ubyte images_mir_slice_algorithms.Rgba8.bb, (field) ubyte images_mir_slice_algorithms.Rgba8.aa;
}
/// `sparkles.math`'s vector as the pixel: four packed `ubyte`s, the same
/// 4 bytes as `Rgba8`, with `rgba` swizzles from the default `xyzw` names.
alias (alias) images_mir_slice_algorithms.Px = sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])sparkles.math's vector as the pixel: four packed ubytes, the same
4 bytes as Rgba8, with rgba swizzles from the default xyzw names.
Px = (struct) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])A vector of N components of type T, laid out as layout, with the
components named names.
Vector!(ubyte, 4);
static assert((struct) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])Px.sizeof == 4);
/// The accumulator a blur needs: the same vector, widened.
alias (alias) images_mir_slice_algorithms.Px32 = sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])The accumulator a blur needs: the same vector, widened.
Px32 = (struct) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])A vector of N components of type T, laid out as layout, with the
components named names.
Vector!(uint, 4);
enum (alias) object.size_t = ulongsize_t (constant) ulong images_mir_slice_algorithms.width = 8LUwidth = 8;
enum (alias) object.size_t = ulongsize_t (constant) ulong images_mir_slice_algorithms.height = 6LUheight = 6;
ubyte ubyte images_mir_slice_algorithms.sample(ulong y, ulong x, ulong c) pure nothrow @nogc @safesample((alias) object.size_t = ulongsize_t (parameter) ulong yy, (alias) object.size_t = ulongsize_t (parameter) ulong xx, (alias) object.size_t = ulongsize_t (parameter) ulong cc) @safe pure nothrow @nogc
=> cast(ubyte) (((parameter) ulong xx * 37 + (parameter) ulong yy * 101 + (parameter) ulong cc * 59 + (parameter) ulong xx * (parameter) ulong yy * 13) & 0xFF);
/// `(v * a + 127) / 255`, the rounded 8-bit premultiply.
ubyte ubyte images_mir_slice_algorithms.mul8(uint v, uint a) pure nothrow @nogc @safe(v * a + 127) / 255, the rounded 8-bit premultiply.
mul8(uint (parameter) uint vv, uint (parameter) uint aa) @safe pure nothrow @nogc => cast(ubyte) (((parameter) uint vv * (parameter) uint aa + 127) / 255);
// ---------------------------------------------------------------- per-pixel map
(struct) images_mir_slice_algorithms.Rgba8Rgba8 images_mir_slice_algorithms.Rgba8 images_mir_slice_algorithms.premultiply(images_mir_slice_algorithms.Rgba8 p) pure nothrow @nogc @safepremultiply((struct) images_mir_slice_algorithms.Rgba8Rgba8 (parameter) images_mir_slice_algorithms.Rgba8 pp) @safe pure nothrow @nogc
=> (struct) images_mir_slice_algorithms.Rgba8Rgba8(ubyte images_mir_slice_algorithms.mul8(uint v, uint a) pure nothrow @nogc @safe(v * a + 127) / 255, the rounded 8-bit premultiply.
mul8((parameter) images_mir_slice_algorithms.Rgba8 pp.(field) ubyte images_mir_slice_algorithms.Rgba8.rr, (parameter) images_mir_slice_algorithms.Rgba8 pp.(field) ubyte images_mir_slice_algorithms.Rgba8.aa), ubyte images_mir_slice_algorithms.mul8(uint v, uint a) pure nothrow @nogc @safe(v * a + 127) / 255, the rounded 8-bit premultiply.
mul8((parameter) images_mir_slice_algorithms.Rgba8 pp.(field) ubyte images_mir_slice_algorithms.Rgba8.gg, (parameter) images_mir_slice_algorithms.Rgba8 pp.(field) ubyte images_mir_slice_algorithms.Rgba8.aa), ubyte images_mir_slice_algorithms.mul8(uint v, uint a) pure nothrow @nogc @safe(v * a + 127) / 255, the rounded 8-bit premultiply.
mul8((parameter) images_mir_slice_algorithms.Rgba8 pp.(field) ubyte images_mir_slice_algorithms.Rgba8.bb, (parameter) images_mir_slice_algorithms.Rgba8 pp.(field) ubyte images_mir_slice_algorithms.Rgba8.aa), (parameter) images_mir_slice_algorithms.Rgba8 pp.(field) ubyte images_mir_slice_algorithms.Rgba8.aa);
/// The map is lazy (`src.map!premultiply` is a view); assigning it to `dst[]`
/// runs it. No allocation, no copy of `src`.
void void images_mir_slice_algorithms.premultiplyInto(mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeThe map is lazy (src`.map!premultiply` is a view); assigning it to dst[]
runs it. No allocation, no copy of src.
premultiplyInto(Slice!(const(Rgba8)*, 2) (parameter) mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.contiguous) srcsrc, Slice!(Rgba8*, 2) (parameter) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dstdst) @safe pure nothrow @nogc
{
(parameter) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dstdst[] = void mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.MapIterator!(const(Rgba8)*, premultiply), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(MapIterator!(const(Rgba8)*, premultiply), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
src.void mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.MapIterator!(const(Rgba8)*, premultiply), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(MapIterator!(const(Rgba8)*, premultiply), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
map!void mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.MapIterator!(const(Rgba8)*, premultiply), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(MapIterator!(const(Rgba8)*, premultiply), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
premultiply;
}
/// The same with `Vector` arithmetic: widen to `uint` lanes, multiply the
/// `rgb` swizzle by `a`, narrow back. `Vector` has no converting constructor,
/// so both conversions are spelled per component.
(alias) images_mir_slice_algorithms.Px = sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])sparkles.math's vector as the pixel: four packed ubytes, the same
4 bytes as Rgba8, with rgba swizzles from the default xyzw names.
Px sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) images_mir_slice_algorithms.premultiplyVec(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) p) pure nothrow @nogc @safeThe same with Vector arithmetic: widen to uint lanes, multiply the
rgb swizzle by a, narrow back. Vector has no converting constructor,
so both conversions are spelled per component.
premultiplyVec((alias) images_mir_slice_algorithms.Px = sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])sparkles.math's vector as the pixel: four packed ubytes, the same
4 bytes as Rgba8, with rgba swizzles from the default xyzw names.
Px (parameter) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) pp) @safe pure nothrow @nogc
{
const (local variable) const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) ww = (struct) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])Px32(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).this(uint x, uint y, uint z, uint w) pure nothrow @nogc ref @safep.sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).this(uint x, uint y, uint z, uint w) pure nothrow @nogc ref @safex, (parameter) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) pp.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).y() inout pure nothrow @nogc @property return ref @safey, (parameter) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) pp.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).z() inout pure nothrow @nogc @property return ref @safez, (parameter) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) pp.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).w() inout pure nothrow @nogc @property return ref @safew);
const (local variable) const(sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"])) rgbrgb = ((local variable) const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) ww.sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"]) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).opDispatch!"rgb"() const pure nothrow @nogc @safeA swizzle: the components named by the letters of s, in order and
repeating as they like (v.yx, v.xxz; v.rgb where the names are
the default ones), as a vector. A name that is not a swizzle is not a
member.
rgb * sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"]) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).opDispatch!"rgb"() const pure nothrow @nogc @safeA swizzle: the components named by the letters of s, in order and
repeating as they like (v.yx, v.xxz; v.rgb where the names are
the default ones), as a vector. A name that is not a swizzle is not a
member.
w.sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"]) sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"]).opBinary!("*", uint)(const(uint) rhs) const pure nothrow @nogc @safeComponent-wise arithmetic against one value, on either side.
a + 127u) / 255u;
return (struct) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])Px(cast(ubyte) (local variable) const(sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"])) rgbrgb.inout(uint) sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"]).x() inout pure nothrow @nogc @property return ref @safex, cast(ubyte) (local variable) const(sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"])) rgbrgb.inout(uint) sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"]).y() inout pure nothrow @nogc @property return ref @safey, cast(ubyte) (local variable) const(sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"])) rgbrgb.inout(uint) sparkles.math.vector.Vector!(uint, 3LU, Layout.packed, ["x", "y", "z"]).z() inout pure nothrow @nogc @property return ref @safez, (parameter) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) pp.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).w() inout pure nothrow @nogc @property return ref @safew);
}
void void images_mir_slice_algorithms.premultiplyVecInto(mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safepremultiplyVecInto(Slice!(const(Px)*, 2) (parameter) mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.contiguous) srcsrc, Slice!(Px*, 2) (parameter) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dstdst) @safe pure nothrow @nogc
{
(parameter) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dstdst[] = void mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.MapIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, premultiplyVec), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(MapIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, premultiplyVec), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
src.void mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.MapIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, premultiplyVec), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(MapIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, premultiplyVec), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
map!void mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.MapIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, premultiplyVec), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(MapIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, premultiplyVec), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
premultiplyVec;
}
// ---------------------------------------------------------------- 3x3 box blur
/// Mean of one 3x3 window of `Rgba8`, channel by channel, rounded.
(struct) images_mir_slice_algorithms.Rgba8Rgba8 images_mir_slice_algorithms.Rgba8 images_mir_slice_algorithms.boxMean!(mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.canonical))(mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.canonical) w) pure nothrow @nogc @safeMean of one 3x3 window of Rgba8, channel by channel, rounded.
boxMean(W)((alias) W = mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.canonical)W (parameter) mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.canonical) ww)
{
uint (local variable) uint rr, (local variable) uint gg, (local variable) uint bb, (local variable) uint aa;
foreach ((local variable) const(images_mir_slice_algorithms.Rgba8) pp; (parameter) mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.canonical) ww.mir.ndslice.slice.Slice!(FlattenedIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), 1LU, mir_slice_kind.contiguous) mir.ndslice.topology.flattened!(const(images_mir_slice_algorithms.Rgba8)*, 2LU, mir_slice_kind.canonical)(mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.canonical) slice) pure nothrow @nogc @safeA contiguous 1-dimensional slice of all elements of a slice.
flattened iterates existing data.
The order of elements is preserved.
flattened can be generalized with other selectors.
flattened)
{
(local variable) uint rr += (local variable) const(images_mir_slice_algorithms.Rgba8) pp.(field) ubyte images_mir_slice_algorithms.Rgba8.rr;
(local variable) uint gg += (local variable) const(images_mir_slice_algorithms.Rgba8) pp.(field) ubyte images_mir_slice_algorithms.Rgba8.gg;
(local variable) uint bb += (local variable) const(images_mir_slice_algorithms.Rgba8) pp.(field) ubyte images_mir_slice_algorithms.Rgba8.bb;
(local variable) uint aa += (local variable) const(images_mir_slice_algorithms.Rgba8) pp.(field) ubyte images_mir_slice_algorithms.Rgba8.aa;
}
return (struct) images_mir_slice_algorithms.Rgba8Rgba8(cast(ubyte) (((local variable) uint rr + 4) / 9), cast(ubyte) (((local variable) uint gg + 4) / 9), cast(ubyte) (((local variable) uint bb + 4) / 9),
cast(ubyte) (((local variable) uint aa + 4) / 9));
}
/// The blur writes the interior: `windows(3, 3)` has `(h - 2) x (w - 2)`
/// windows, one per interior pixel, each a 3x3 view of `src`.
void void images_mir_slice_algorithms.boxBlurInto(mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeThe blur writes the interior: windows(3, 3) has (h - 2) x (w - 2)
windows, one per interior pixel, each a 3x3 view of src.
boxBlurInto(Slice!(const(Rgba8)*, 2) (parameter) mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.contiguous) srcsrc, Slice!(Rgba8*, 2) (parameter) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dstdst) @safe pure nothrow @nogc
{
(parameter) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dstdst[1 .. $ - 1, 1 .. $ - 1] = void mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(images_mir_slice_algorithms.boxBlurInto.MapIterator!(SliceIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), __lambda_L105_C58), 2LU, mir_slice_kind.universal, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous), mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), __lambda_L105_C58), 2LU, mir_slice_kind.universal) value, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_1, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_2) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
src.void mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(images_mir_slice_algorithms.boxBlurInto.MapIterator!(SliceIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), __lambda_L105_C58), 2LU, mir_slice_kind.universal, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous), mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), __lambda_L105_C58), 2LU, mir_slice_kind.universal) value, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_1, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_2) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
windows(3, 3).mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), __lambda_L105_C58), 2LU, mir_slice_kind.universal) images_mir_slice_algorithms.boxBlurInto.map!(mir.ndslice.iterator.SliceIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), 2LU, mir_slice_kind.universal)(mir.ndslice.slice.Slice!(SliceIterator!(const(Rgba8)*, 2LU, mir_slice_kind.canonical), 2LU, mir_slice_kind.universal) slice) pure nothrow @nogc @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call map`!(fun)(`slice`)`
returns a `slice` of which elements are obtained by applying `fun`
for all elements in slice``. The original slices are
not changed. Evaluation is done lazily.
Note
dynamic, transposed and
topology, pack can be used to specify dimensions.
map!(w => boxMean(w));
}
/// The same with `Vector` accumulation: one `+=` per pixel instead of four.
(alias) images_mir_slice_algorithms.Px = sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])sparkles.math's vector as the pixel: four packed ubytes, the same
4 bytes as Rgba8, with rgba swizzles from the default xyzw names.
Px sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]) images_mir_slice_algorithms.boxMeanVec!(mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical))(mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical) w) pure nothrow @nogc @safeThe same with Vector accumulation: one += per pixel instead of four.
boxMeanVec(W)((alias) W = mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical)W (parameter) mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical) ww)
{
(alias) images_mir_slice_algorithms.Px32 = sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])The accumulator a blur needs: the same vector, widened.
Px32 (local variable) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]) accacc;
foreach ((local variable) const(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])) pp; (parameter) mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical) ww.mir.ndslice.slice.Slice!(FlattenedIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), 1LU, mir_slice_kind.contiguous) mir.ndslice.topology.flattened!(const(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical)(mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical) slice) pure nothrow @nogc @safeA contiguous 1-dimensional slice of all elements of a slice.
flattened iterates existing data.
The order of elements is preserved.
flattened can be generalized with other selectors.
flattened)
(local variable) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]) accacc += sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).opOpAssign!("+", sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]))(const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) rhs) pure nothrow @nogc return ref @safeIn-place component-wise arithmetic, against a vector or a value.
Px32(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).opOpAssign!("+", sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]))(const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) rhs) pure nothrow @nogc return ref @safeIn-place component-wise arithmetic, against a vector or a value.
p.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).x() inout pure nothrow @nogc @property return ref @safex, (local variable) const(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])) pp.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).y() inout pure nothrow @nogc @property return ref @safey, (local variable) const(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])) pp.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).z() inout pure nothrow @nogc @property return ref @safez, (local variable) const(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])) pp.inout(ubyte) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).w() inout pure nothrow @nogc @property return ref @safew);
const (local variable) const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) mm = ((local variable) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]) accacc + 4u) / 9u;
return (struct) sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])Px(cast(ubyte) (local variable) const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) mm.inout(uint) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).x() inout pure nothrow @nogc @property return ref @safex, cast(ubyte) (local variable) const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) mm.inout(uint) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).y() inout pure nothrow @nogc @property return ref @safey, cast(ubyte) (local variable) const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) mm.inout(uint) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).z() inout pure nothrow @nogc @property return ref @safez, cast(ubyte) (local variable) const(sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"])) mm.inout(uint) sparkles.math.vector.Vector!(uint, 4LU, Layout.packed, ["x", "y", "z", "w"]).w() inout pure nothrow @nogc @property return ref @safew);
}
void void images_mir_slice_algorithms.boxBlurVecInto(mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeboxBlurVecInto(Slice!(const(Px)*, 2) (parameter) mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.contiguous) srcsrc, Slice!(Px*, 2) (parameter) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dstdst) @safe pure nothrow @nogc
{
(parameter) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dstdst[1 .. $ - 1, 1 .. $ - 1] = void mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(images_mir_slice_algorithms.boxBlurVecInto.MapIterator!(SliceIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), __lambda_L120_C58), 2LU, mir_slice_kind.universal, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous), mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), __lambda_L120_C58), 2LU, mir_slice_kind.universal) value, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_1, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_2) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
src.void mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(images_mir_slice_algorithms.boxBlurVecInto.MapIterator!(SliceIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), __lambda_L120_C58), 2LU, mir_slice_kind.universal, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous), mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), __lambda_L120_C58), 2LU, mir_slice_kind.universal) value, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_1, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_2) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
windows(3, 3).mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), __lambda_L120_C58), 2LU, mir_slice_kind.universal) images_mir_slice_algorithms.boxBlurVecInto.map!(mir.ndslice.iterator.SliceIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), 2LU, mir_slice_kind.universal)(mir.ndslice.slice.Slice!(SliceIterator!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.canonical), 2LU, mir_slice_kind.universal) slice) pure nothrow @nogc @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call map`!(fun)(`slice`)`
returns a `slice` of which elements are obtained by applying `fun`
for all elements in slice``. The original slices are
not changed. Evaluation is done lazily.
Note
dynamic, transposed and
topology, pack can be used to specify dimensions.
map!(w => boxMeanVec(w));
}
/// One 8-bit plane, `windows` form: the kernel the generated-code section reads.
void void images_mir_slice_algorithms.blurPlaneMir(mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeOne 8-bit plane, windows form: the kernel the generated-code section reads.
blurPlaneMir(Slice!(const(ubyte)*, 2) (parameter) mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) srcsrc, Slice!(ubyte*, 2) (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dstdst) @safe pure nothrow @nogc
{
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dstdst[1 .. $ - 1, 1 .. $ - 1] = void mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(images_mir_slice_algorithms.blurPlaneMir.MapIterator!(SliceIterator!(const(ubyte)*, 2LU, mir_slice_kind.canonical), __lambda_L126_C58), 2LU, mir_slice_kind.universal, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous), mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(ubyte)*, 2LU, mir_slice_kind.canonical), __lambda_L126_C58), 2LU, mir_slice_kind.universal) value, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_1, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_2) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
src.void mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(images_mir_slice_algorithms.blurPlaneMir.MapIterator!(SliceIterator!(const(ubyte)*, 2LU, mir_slice_kind.canonical), __lambda_L126_C58), 2LU, mir_slice_kind.universal, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous), mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(ubyte)*, 2LU, mir_slice_kind.canonical), __lambda_L126_C58), 2LU, mir_slice_kind.universal) value, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_1, mir.ndslice.slice.Slice!(IotaIterator!ulong, 1LU, mir_slice_kind.contiguous) __param_2) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
windows(3, 3).mir.ndslice.slice.Slice!(MapIterator!(SliceIterator!(const(ubyte)*, 2LU, mir_slice_kind.canonical), __lambda_L126_C58), 2LU, mir_slice_kind.universal) images_mir_slice_algorithms.blurPlaneMir.map!(mir.ndslice.iterator.SliceIterator!(const(ubyte)*, 2LU, mir_slice_kind.canonical), 2LU, mir_slice_kind.universal)(mir.ndslice.slice.Slice!(SliceIterator!(const(ubyte)*, 2LU, mir_slice_kind.canonical), 2LU, mir_slice_kind.universal) slice) pure nothrow @nogc @safeImplements the homonym function (also known as transform) present
in many languages of functional flavor. The call map`!(fun)(`slice`)`
returns a `slice` of which elements are obtained by applying `fun`
for all elements in slice``. The original slices are
not changed. Evaluation is done lazily.
Note
dynamic, transposed and
topology, pack can be used to specify dimensions.
map!((w) {
uint s = 0;
foreach (v; w.flattened)
s += v;
return cast(ubyte) ((s + 4) / 9);
});
}
/// One 8-bit plane, hand-written loops over the same `Slice` (rows indexed
/// through the slice, columns through a plain array row).
void void images_mir_slice_algorithms.blurPlaneLoop(mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeOne 8-bit plane, hand-written loops over the same Slice (rows indexed
through the slice, columns through a plain array row).
blurPlaneLoop(Slice!(const(ubyte)*, 2) (parameter) mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) srcsrc, Slice!(ubyte*, 2) (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dstdst) @safe pure nothrow @nogc
{
foreach ((local variable) ulong yy; 1 .. (parameter) mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) srcsrc.ulong mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous).mir_slice.length!0LU() const pure nothrow @nogc @property scope @safeMultidimensional length property.
length!0 - 1)
{
const(ubyte)[] (local variable) const(ubyte)[] r0r0 = (parameter) mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) srcsrc[(local variable) ulong yy - 1].const(ubyte)[] mir.ndslice.slice.Slice!(const(ubyte)*, 1LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field, (local variable) const(ubyte)[] r1r1 = (parameter) mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) srcsrc[(local variable) ulong yy].const(ubyte)[] mir.ndslice.slice.Slice!(const(ubyte)*, 1LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field, (local variable) const(ubyte)[] r2r2 = (parameter) mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) srcsrc[(local variable) ulong yy + 1].const(ubyte)[] mir.ndslice.slice.Slice!(const(ubyte)*, 1LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field;
ubyte[] (local variable) ubyte[] oo = (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dstdst[(local variable) ulong yy].ubyte[] mir.ndslice.slice.mir_slice!(ubyte*, 1LU, mir_slice_kind.contiguous).field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field;
foreach ((local variable) ulong xx; 1 .. (parameter) mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) srcsrc.ulong mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous).mir_slice.length!1LU() const pure nothrow @nogc @property scope @safeMultidimensional length property.
length!1 - 1)
{
const uint (local variable) const(uint) ss = (local variable) const(ubyte)[] r0r0[(local variable) ulong xx - 1] + (local variable) const(ubyte)[] r0r0[(local variable) ulong xx] + (local variable) const(ubyte)[] r0r0[(local variable) ulong xx + 1] + (local variable) const(ubyte)[] r1r1[(local variable) ulong xx - 1] + (local variable) const(ubyte)[] r1r1[(local variable) ulong xx] + (local variable) const(ubyte)[] r1r1[(local variable) ulong xx + 1] + (local variable) const(ubyte)[] r2r2[(local variable) ulong xx - 1] + (local variable) const(ubyte)[] r2r2[(local variable) ulong xx]
+ (local variable) const(ubyte)[] r2r2[(local variable) ulong xx + 1];
(local variable) ubyte[] oo[(local variable) ulong xx] = cast(ubyte) (((local variable) const(uint) ss + 4) / 9);
}
}
}
uint uint images_mir_slice_algorithms.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) s) pure nothrow @nogc @safefnv1a(S)((alias) S = mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous)S (parameter) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) ss)
{
uint (local variable) uint hh = 2_166_136_261;
foreach ((local variable) ubyte bb; (parameter) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) ss.mir.ndslice.slice.mir_slice!(ubyte*, 1LU, mir_slice_kind.contiguous) mir.ndslice.topology.flattened!(ubyte*, 3LU)(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) slice) pure nothrow @nogc @safeA contiguous 1-dimensional slice of all elements of a slice.
flattened iterates existing data.
The order of elements is preserved.
flattened can be generalized with other selectors.
flattened)
{
(local variable) uint hh ^= (local variable) ubyte bb;
(local variable) uint hh *= 16_777_619;
}
return (local variable) uint hh;
}
void void D main() @safemain() @safe
{
// Interleaved storage, filled once; three views over it.
auto (local variable) ubyte[] bytesbytes = new ubyte[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight * 4);
foreach ((local variable) ulong yy; 0 .. (constant) ulong images_mir_slice_algorithms.height = 6LUheight)
foreach ((local variable) ulong xx; 0 .. (constant) ulong images_mir_slice_algorithms.width = 8LUwidth)
foreach ((local variable) int cc; 0 .. 4)
(local variable) ubyte[] bytesbytes[((local variable) ulong yy * (constant) ulong images_mir_slice_algorithms.width = 8LUwidth + (local variable) ulong xx) * 4 + (local variable) int cc] = ubyte images_mir_slice_algorithms.sample(ulong y, ulong x, ulong c) pure nothrow @nogc @safesample((local variable) ulong yy, (local variable) ulong xx, (local variable) int cc);
auto (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) imgimg = (cast((struct) images_mir_slice_algorithms.Rgba8Rgba8[]) (local variable) ubyte[] bytesbytes).mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, images_mir_slice_algorithms.Rgba8[])(return scope images_mir_slice_algorithms.Rgba8[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
auto (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) imgVimgV = (cast((alias) images_mir_slice_algorithms.Px = sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])sparkles.math's vector as the pixel: four packed ubytes, the same
4 bytes as Rgba8, with rgba swizzles from the default xyzw names.
Px[]) (local variable) ubyte[] bytesbytes).mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[])(return scope sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) img3img3 = (local variable) ubyte[] bytesbytes.mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(3LU, ubyte[])(return scope ubyte[] iterator, ulong[3] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth, 4);
void std.stdio.writefln!(char, uint, images_mir_slice_algorithms.Rgba8, ubyte[4])(in char[] fmt, uint __param_1, images_mir_slice_algorithms.Rgba8 __param_2, ubyte[4] __param_3) @safeEquivalent to writef(fmt, args, '\n').
writefln("source fnv1a %08x img[1, 2] %s imgV[1, 2] %s", uint images_mir_slice_algorithms.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) s) pure nothrow @nogc @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) img3img3), (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) imgimg[1, 2], (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) imgVimgV[1, 2].ubyte[4] sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]).array() const pure nothrow @nogc @safeThe components, as a static array.
array);
// Per-pixel map.
auto (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) pmpm = new (struct) images_mir_slice_algorithms.Rgba8Rgba8[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight).mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, images_mir_slice_algorithms.Rgba8[])(return scope images_mir_slice_algorithms.Rgba8[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
auto (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) pmVpmV = new (alias) images_mir_slice_algorithms.Px = sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])sparkles.math's vector as the pixel: four packed ubytes, the same
4 bytes as Rgba8, with rgba swizzles from the default xyzw names.
Px[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight).mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[])(return scope sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
void images_mir_slice_algorithms.premultiplyInto(mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeThe map is lazy (src`.map!premultiply` is a view); assigning it to dst[]
runs it. No allocation, no copy of src.
premultiplyInto((local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) imgimg, (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) pmpm);
void images_mir_slice_algorithms.premultiplyVecInto(mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safepremultiplyVecInto((local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) imgVimgV, (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) pmVpmV);
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) pmBytespmBytes = (cast(ubyte[]) (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) pmpm.images_mir_slice_algorithms.Rgba8[] mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field).mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(3LU, ubyte[])(return scope ubyte[] iterator, ulong[3] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth, 4);
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) pmVBytespmVBytes = (cast(ubyte[]) (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) pmVpmV.sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[] mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field).mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(3LU, ubyte[])(return scope ubyte[] iterator, ulong[3] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth, 4);
void std.stdio.writefln!(char, uint, bool, images_mir_slice_algorithms.Rgba8)(in char[] fmt, uint __param_1, bool __param_2, images_mir_slice_algorithms.Rgba8 __param_3) @safeEquivalent to writef(fmt, args, '\n').
writefln("premultiplied fnv1a %08x struct == Vector: %s pm[1, 2] %s", uint images_mir_slice_algorithms.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) s) pure nothrow @nogc @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) pmBytespmBytes),
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) pmBytespmBytes == bool mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous).mir_slice.opEquals!(ubyte*, mir_slice_kind.contiguous)(ref const(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous)) rslice) const pure nothrow @nogc scope @trustedpmVBytes, (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) pmpm[1, 2]);
// 3x3 box blur, border copied from the source.
auto (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) blbl = new (struct) images_mir_slice_algorithms.Rgba8Rgba8[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight).mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, images_mir_slice_algorithms.Rgba8[])(return scope images_mir_slice_algorithms.Rgba8[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
auto (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) blVblV = new (alias) images_mir_slice_algorithms.Px = sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])sparkles.math's vector as the pixel: four packed ubytes, the same
4 bytes as Rgba8, with rgba swizzles from the default xyzw names.
Px[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight).mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[])(return scope sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
(local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) blbl[] = void mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
img;
(local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) blVblV[] = void mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
imgV;
void images_mir_slice_algorithms.boxBlurInto(mir.ndslice.slice.Slice!(const(Rgba8)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeThe blur writes the interior: windows(3, 3) has (h - 2) x (w - 2)
windows, one per interior pixel, each a 3x3 view of src.
boxBlurInto((local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) imgimg, (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) blbl);
void images_mir_slice_algorithms.boxBlurVecInto(mir.ndslice.slice.Slice!(const(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"]))*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeboxBlurVecInto((local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) imgVimgV, (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) blVblV);
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) blBytesblBytes = (cast(ubyte[]) (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) blbl.images_mir_slice_algorithms.Rgba8[] mir.ndslice.slice.Slice!(images_mir_slice_algorithms.Rgba8*, 2LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field).mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(3LU, ubyte[])(return scope ubyte[] iterator, ulong[3] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth, 4);
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) blVBytesblVBytes = (cast(ubyte[]) (local variable) mir.ndslice.slice.Slice!(Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous) blVblV.sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])[] mir.ndslice.slice.Slice!(sparkles.math.vector.Vector!(ubyte, 4LU, Layout.packed, ["x", "y", "z", "w"])*, 2LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trustedField (array) data.
Constraints
Field is defined only for contiguous slices.
field).mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(3LU, ubyte[])(return scope ubyte[] iterator, ulong[3] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth, 4);
void std.stdio.writefln!(char, uint, bool, images_mir_slice_algorithms.Rgba8)(in char[] fmt, uint __param_1, bool __param_2, images_mir_slice_algorithms.Rgba8 __param_3) @safeEquivalent to writef(fmt, args, '\n').
writefln("box blur fnv1a %08x struct == Vector: %s bl[2, 3] %s", uint images_mir_slice_algorithms.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) s) pure nothrow @nogc @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) blBytesblBytes),
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous) blBytesblBytes == bool mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous).mir_slice.opEquals!(ubyte*, mir_slice_kind.contiguous)(ref const(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.contiguous)) rslice) const pure nothrow @nogc scope @trustedblVBytes, (local variable) mir.ndslice.slice.Slice!(Rgba8*, 2LU, mir_slice_kind.contiguous) blbl[2, 3]);
// One plane (the red channel, copied out contiguous), both blur forms.
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) redred = new ubyte[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight).mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, ubyte[])(return scope ubyte[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) redred[] = void mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(ubyte*, 2LU, mir_slice_kind.universal)(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.universal) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
img3[0 .. $, 0 .. $, 0];
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) aa = new ubyte[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight).mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, ubyte[])(return scope ubyte[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) bb = new ubyte[]((constant) ulong images_mir_slice_algorithms.width = 8LUwidth * (constant) ulong images_mir_slice_algorithms.height = 6LUheight).mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, ubyte[])(return scope ubyte[] iterator, ulong[2] lengths...) pure nothrow @nogc @safeCreates an n-dimensional slice-shell over an iterator.
Examples
Random access range primitives for slices over user defined types
struct MyIota
{
//`[index]` operator overloading
auto opIndex(size_t index) @safe nothrow
{
return index;
}
auto lightConst()() const @property { return MyIota(); }
auto lightImmutable()() immutable @property { return MyIota(); }
}
import mir.ndslice.iterator: FieldIterator;
alias Iterator = FieldIterator!MyIota;
alias S = Slice!(Iterator, 2);
import std.range.primitives;
static assert(hasLength!S);
static assert(hasSlicing!S);
static assert(isRandomAccessRange!S);
auto slice = Iterator().sliced(20, 10);
assert(slice[1, 2] == 12);
auto sCopy = slice.save;
assert(slice[1, 2] == 12);
sliced((constant) ulong images_mir_slice_algorithms.height = 6LUheight, (constant) ulong images_mir_slice_algorithms.width = 8LUwidth);
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) aa[] = void mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(ubyte*, 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
red;
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) bb[] = void mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(ubyte*, 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safeAssignment of a value of Slice type to a fully defined slice.
red;
void images_mir_slice_algorithms.blurPlaneMir(mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeOne 8-bit plane, windows form: the kernel the generated-code section reads.
blurPlaneMir((local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) redred, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) aa);
void images_mir_slice_algorithms.blurPlaneLoop(mir.ndslice.slice.Slice!(const(ubyte)*, 2LU, mir_slice_kind.contiguous) src, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safeOne 8-bit plane, hand-written loops over the same Slice (rows indexed
through the slice, columns through a plain array row).
blurPlaneLoop((local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) redred, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) bb);
void std.stdio.writefln!(char, uint, bool, bool)(in char[] fmt, uint __param_1, bool __param_2, bool __param_3) @safeEquivalent to writef(fmt, args, '\n').
writefln("plane blur fnv1a %08x windows == loop: %s red-channel of RGBA blur agrees: %s", uint images_mir_slice_algorithms.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous))(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) s) pure nothrow @nogc @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) aa), (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) aa == bool mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous).mir_slice.opEquals!(ubyte*, mir_slice_kind.contiguous)(ref const(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous)) rslice) const pure nothrow @nogc scope @trustedb,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous) aa == bool mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.contiguous).mir_slice.opEquals!(ubyte*, mir_slice_kind.universal)(const(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.universal)) rslice) const pure nothrow @nogc scope @trustedblBytes[0 .. $, 0 .. $, 0]);
}