slice-planar.dhover×297all
#!/usr/bin/env dub
/+ dub.sdl:
    name "images_mir_slice_planar"
    dependency "sparkles:base" path="../../../../.."
    dependency "mir-algorithm" version="==3.22.4"
    dflags "-preview=in" "-preview=dip1000"
    buildType "checked" {
        buildOptions "optimize" "inline" "debugInfo"
    }
+/
/**
 * Planar YUV 4:2:0 as three mir `Slice`s of different extents over one
 * allocation, each with a padded row stride, and a lazy RGB view computed from
 * them; then a packed 3-byte RGB image whose padded row stride is not a whole
 * number of pixels, which a `Slice` of a pixel struct cannot express.
 *
 * The frame is 9 x 5, so the chroma planes are ceil(9/2) x ceil(5/2) = 5 x 3:
 * odd extents are where 4:2:0 code usually goes wrong.
 *
 * Backs ./slice-experiment.md (section "Planar YUV and padded strides").
 *
 * Run with: `dub run --single slice-planar.d`
 */
module 
(module) images_mir_slice_planar

Planar YUV 4:2:0 as three mir Slices of different extents over one allocation, each with a padded row stride, and a lazy RGB view computed from them; then a packed 3-byte RGB image whose padded row stride is not a whole number of pixels, which a Slice of a pixel struct cannot express.

The frame is 9 x 5, so the chroma planes are ceil(9/2) x ceil(5/2) = 5 x 3: odd extents are where 4:2:0 code usually goes wrong.

Backs ./slice-experiment.md (section "Planar YUV and padded strides").

Run with: dub run --single slice-planar.d

images_mir_slice_planar
;
import
(package) std
std
.
(module) std.stdio
Category 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:

  1. The lowest layer is the operating system layer. The two main schemes are Windows and Posix.

  2. C's stdio.h which unifies the two operating system schemes.

  3. std.stdio, this module, unifies the various stdio.h implementations into a high level package for D programs.

Source

std/stdio.d

@copyrightCopyright The D Language Foundation 2007-.@licenseBoost License 1.0.@authorsWalter Bright, Andrei Alexandrescu, Alex Rønne Petersen
stdio
:
(alias template) images_mir_slice_planar.writefln = std.stdio.writefln(alias fmt, A...)(A args) if (isSomeString!(typeof(fmt)))

Equivalent to writef(fmt, args, '\n').

writefln
;
import
(package) mir
mir
.
(package) mir.ndslice
ndslice
.
(module) mir.ndslice.slice

This 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.

@licenseApache-2.0@copyright2020 Ilia Ki, Kaleidic Associates Advisory Limited, Symmetry Investments@authors

Ilia Ki

Name Description
Slice N-dimensional slice.
SliceKind SliceKind of Slice enumeration.
Universal Alias for .SliceKind.universal.
Canonical Alias for .SliceKind.canonical.
Contiguous Alias for .SliceKind.contiguous.
sliced Creates a slice on top of an iterator, a pointer, or an array's pointer.
slicedField Creates a slice on top of a field, a random access range, or an array.
slicedNdField Creates a slice on top of an ndField.
kindOf Extracts SliceKind.
isSlice Checks if the type is Slice instance.
Structure A tuple of lengths and strides.
slice
: Canonical, Slice,
(alias template) images_mir_slice_planar.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.

@paramiterator An iterator, a pointer, or an array.@paramlengths A list of lengths for each dimension@returnsn-dimensional slice
sliced
, Universal;
import
(package) mir
mir
.
(package) mir.ndslice
ndslice
.
(module) mir.ndslice.topology

This 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.

@licenseApache-2.0@copyright2020 Ilia Ki, Kaleidic Associates Advisory Limited, Symmetry Investments@authorsIlia Ki, John Michael Hall, Shigeki Karita (original numir code)
topology
:
(alias template) images_mir_slice_planar.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.

@paramslice slice to be iterated@returnscontiguous 1-dimensional slice of elements of the slice
flattened
,
(alias template) images_mir_slice_planar.ndiota = mir.ndslice.topology.ndiota(ulong N)(size_t[N] lengths...) if (N)

Returns a slice, the elements of which are equal to the initial multidimensional index value. For a flattened (contiguous) index, see iota.

@paramN dimension count@paramlengths list of dimension lengths@returnsN-dimensional slice composed of indices@seeiota
ndiota
,
(alias template) images_mir_slice_planar.vmap = mir.ndslice.topology.vmap(Iterator, ulong N, mir_slice_kind kind, Callable)(Slice!(Iterator, N, kind) slice, Callable callable)

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call slice.vmap(fun) 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.

@paramslice ndslice@paramcallable callable object, structure, delegate, or function pointer.@seecached, map, rcmap, indexed, pairwise, subSlices, slide, zip, Map (higher-order function)
vmap
;
import
(package) sparkles
sparkles
.
(package) sparkles.base
base
.
(module) sparkles.base.buffer

A @nogc container with Small Buffer Optimization (SBO).

Provides an append-only buffer that stores small amounts of data inline (avoiding heap allocation) and automatically switches to heap storage when capacity is exceeded.

Primary use case: appending elements in a temporary scope where GC allocation is not desired.

buffer
:
(alias template) images_mir_slice_planar.HeapBuffer = sparkles.base.buffer.HeapBuffer(T, Storage extra = Storage.none) if (!(extra & ~Storage.unique))

A buffer with no inline array: the elements always live on the heap.

For a sequence whose typical size makes an inline array dead weight — the struct costs one slice regardless of how much it holds. Size it up front with reserve; there is no N to raise.

HeapBuffer
,
(enum) sparkles.base.buffer.Storage

What storage a buffer may use, and whether it may be copied.

The bits are capabilities, so the combination is the policy: inline alone never allocates, heap alone carries no inline array, and both together is the small-buffer optimization. ``Storage.none is the empty set — the neutral default for an alias's extra parameter — but a buffer with neither storage bit has nowhere to put anything and fails Buffer's constraint.

Storage
;
enum
(alias) object.size_t = ulong
size_t
(constant) ulong images_mir_slice_planar.width = 9LU
width
= 9,
(constant) ulong images_mir_slice_planar.height = 5LU
height
= 5;
enum
(alias) object.size_t = ulong
size_t
(constant) ulong images_mir_slice_planar.chromaWidth = 5LU
chromaWidth
= (
(constant) ulong images_mir_slice_planar.width = 9LU
width
+ 1) / 2,
(constant) ulong images_mir_slice_planar.chromaHeight = 3LU
chromaHeight
= (
(constant) ulong images_mir_slice_planar.height = 5LU
height
+ 1) / 2;
/// Row strides in bytes, padded as a decoder or a GPU would (16 and 8). enum
(alias) object.size_t = ulong
size_t
(constant) ulong images_mir_slice_planar.lumaStride = 16LU

Row strides in bytes, padded as a decoder or a GPU would (16 and 8).

lumaStride
= 16,
(constant) ulong images_mir_slice_planar.chromaStride = 8LU

Row strides in bytes, padded as a decoder or a GPU would (16 and 8).

chromaStride
= 8;
enum
(alias) object.size_t = ulong
size_t
(constant) ulong images_mir_slice_planar.lumaBytes = 80LU
lumaBytes
=
(constant) ulong images_mir_slice_planar.lumaStride = 16LU

Row strides in bytes, padded as a decoder or a GPU would (16 and 8).

lumaStride
*
(constant) ulong images_mir_slice_planar.height = 5LU
height
;
enum
(alias) object.size_t = ulong
size_t
(constant) ulong images_mir_slice_planar.chromaBytes = 24LU
chromaBytes
=
(constant) ulong images_mir_slice_planar.chromaStride = 8LU

Row strides in bytes, padded as a decoder or a GPU would (16 and 8).

chromaStride
*
(constant) ulong images_mir_slice_planar.chromaHeight = 3LU
chromaHeight
;
struct
(struct) images_mir_slice_planar.Rgb8
Rgb8
{ ubyte
(field) ubyte images_mir_slice_planar.Rgb8.r
r
,
(field) ubyte images_mir_slice_planar.Rgb8.g
g
,
(field) ubyte images_mir_slice_planar.Rgb8.b
b
;
} static assert(
(struct) images_mir_slice_planar.Rgb8
Rgb8
.
(constant) ulong images_mir_slice_planar.Rgb8.sizeof = 3LU
sizeof
== 3);
ubyte
ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safe
clamp8
(int
(parameter) int v
v
) @safe pure nothrow @nogc => cast(ubyte) (
(parameter) int v
v
< 0 ? 0 :
(parameter) int v
v
> 255 ? 255 :
(parameter) int v
v
);
/// BT.601 full-range YCbCr to RGB, 8.8 fixed point.
(struct) images_mir_slice_planar.Rgb8
Rgb8
images_mir_slice_planar.Rgb8 images_mir_slice_planar.yuvToRgb(ubyte y, ubyte u, ubyte v) pure nothrow @nogc @safe

BT.601 full-range YCbCr to RGB, 8.8 fixed point.

yuvToRgb
(ubyte
(parameter) ubyte y
y
, ubyte
(parameter) ubyte u
u
, ubyte
(parameter) ubyte v
v
) @safe pure nothrow @nogc
{ const int
(local variable) const(int) c
c
=
(parameter) ubyte y
y
,
(local variable) const(int) d
d
=
(parameter) ubyte u
u
- 128,
(local variable) const(int) e
e
=
(parameter) ubyte v
v
- 128;
return
(struct) images_mir_slice_planar.Rgb8
Rgb8
(
ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safe
clamp8
(
(local variable) const(int) c
c
+ ((359 *
(local variable) const(int) e
e
+ 128) >> 8)),
ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safe
clamp8
(
(local variable) const(int) c
c
- ((88 *
(local variable) const(int) d
d
+ 183 *
(local variable) const(int) e
e
+ 128) >> 8)),
ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safe
clamp8
(
(local variable) const(int) c
c
+ ((454 *
(local variable) const(int) d
d
+ 128) >> 8)));
} /// One plane: a contiguous `rows x stride` matrix over the bytes, cropped to /// `rows x cols`. The crop of the last dimension makes it Canonical: the row /// stride is stored, the column stride is 1. Slice!(ubyte*, 2, Canonical)
mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.plane(return scope ubyte[] bytes, ulong rows, ulong cols, ulong stride) pure nothrow @nogc @safe

One plane: a contiguous rows` x `stride matrix over the bytes, cropped to rows` x `cols. The crop of the last dimension makes it Canonical: the row stride is stored, the column stride is 1.

plane
(return scope ubyte[]
(parameter) ubyte[] bytes
bytes
,
(alias) object.size_t = ulong
size_t
(parameter) ulong rows
rows
,
(alias) object.size_t = ulong
size_t
(parameter) ulong cols
cols
,
(alias) object.size_t = ulong
size_t
(parameter) ulong stride
stride
)
@safe pure nothrow @nogc =>
(parameter) ubyte[] bytes
bytes
.
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 @safe

Creates 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);
@paramiterator An iterator, a pointer, or an array.@paramlengths A list of lengths for each dimension@returnsn-dimensional slice
sliced
(
(parameter) ulong rows
rows
,
(parameter) ulong stride
stride
)[0 .. $, 0 ..
(parameter) ulong cols
cols
];
uint
uint images_mir_slice_planar.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical))(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) s) pure nothrow @nogc @safe
fnv1a
(S)(
(alias) S = mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical)
S
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) s
s
)
{ uint
(local variable) uint h
h
= 2_166_136_261;
foreach (
(local variable) ubyte b
b
;
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) s
s
.
mir.ndslice.slice.Slice!(FlattenedIterator!(ubyte*, 2LU, mir_slice_kind.canonical), 1LU, mir_slice_kind.contiguous) mir.ndslice.topology.flattened!(ubyte*, 2LU, mir_slice_kind.canonical)(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) slice) pure nothrow @nogc @safe

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.

@paramslice slice to be iterated@returnscontiguous 1-dimensional slice of elements of the slice
flattened
)
{
(local variable) uint h
h
^=
(local variable) ubyte b
b
;
(local variable) uint h
h
*= 16_777_619;
} return
(local variable) uint h
h
;
} /// The three planes as one callable: index (y, x) to RGB, chroma at half /// resolution. A struct, not a lambda: see `convert`. struct
(struct) images_mir_slice_planar.Yuv420

The three planes as one callable: index (y, x) to RGB, chroma at half resolution. A struct, not a lambda: see convert.

Yuv420
{ Slice!(ubyte*, 2, Canonical)
(field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.yp
yp
,
(field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.up
up
,
(field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.vp
vp
;
(struct) images_mir_slice_planar.Rgb8
Rgb8
images_mir_slice_planar.Rgb8 images_mir_slice_planar.Yuv420.opCall(ulong[2] i) const pure nothrow @nogc @safe
opCall
(
(alias) object.size_t = ulong
size_t
[2]
(parameter) ulong[2] i
i
) const @safe pure nothrow @nogc
=>
images_mir_slice_planar.Rgb8 images_mir_slice_planar.yuvToRgb(ubyte y, ubyte u, ubyte v) pure nothrow @nogc @safe

BT.601 full-range YCbCr to RGB, 8.8 fixed point.

yuvToRgb
(
(field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.yp
yp
[
(parameter) ulong[2] i
i
[0],
(parameter) ulong[2] i
i
[1]],
(field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.up
up
[
(parameter) ulong[2] i
i
[0] / 2,
(parameter) ulong[2] i
i
[1] / 2],
(field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.vp
vp
[
(parameter) ulong[2] i
i
[0] / 2,
(parameter) ulong[2] i
i
[1] / 2]);
} /// Converts the frame into `dst`: a lazy `ndiota` view over the luma extent, /// mapped through `Yuv420`; assigning it runs it. `ndiota(...).map!(i => ...)` /// with a lambda reading the planes is rejected under `@nogc` ("allocates /// closure"), so the planes travel in the functor `vmap` takes. void
void images_mir_slice_planar.convert(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp, mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safe

Converts the frame into dst: a lazy ndiota view over the luma extent, mapped through Yuv420; assigning it runs it. ndiota(...).map!(i => ...) with a lambda reading the planes is rejected under @nogc ("allocates closure"), so the planes travel in the functor vmap takes.

convert
(Slice!(ubyte*, 2, Canonical)
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
, Slice!(ubyte*, 2, Canonical)
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
, Slice!(ubyte*, 2, Canonical)
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
,
Slice!(Rgb8*, 2)
(parameter) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) dst
dst
) @safe pure nothrow @nogc
{ // A struct initialiser, not `Yuv420(yp, up, vp)`: with an `opCall` // member DMD 2.112 resolves that call syntax to `opCall` (LDC 1.43 does not).
(struct) images_mir_slice_planar.Yuv420

The three planes as one callable: index (y, x) to RGB, chroma at half resolution. A struct, not a lambda: see convert.

Yuv420
(local variable) images_mir_slice_planar.Yuv420 f
f
= {yp:
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
, up:
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
, vp:
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
};
(parameter) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) dst
dst
[] =
void mir.ndslice.slice.Slice!(images_mir_slice_planar.Rgb8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.VmapIterator!(FieldIterator!(ndIotaField!2LU), Yuv420), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(VmapIterator!(FieldIterator!(ndIotaField!2LU), Yuv420), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safe

Assignment of a value of Slice type to a fully defined slice.

ndiota
(
void mir.ndslice.slice.Slice!(images_mir_slice_planar.Rgb8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.VmapIterator!(FieldIterator!(ndIotaField!2LU), Yuv420), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(VmapIterator!(FieldIterator!(ndIotaField!2LU), Yuv420), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safe

Assignment of a value of Slice type to a fully defined slice.

yp
.
void mir.ndslice.slice.Slice!(images_mir_slice_planar.Rgb8*, 2LU, mir_slice_kind.contiguous).mir_slice.opIndexAssign!(mir.ndslice.iterator.VmapIterator!(FieldIterator!(ndIotaField!2LU), Yuv420), 2LU, mir_slice_kind.contiguous)(mir.ndslice.slice.Slice!(VmapIterator!(FieldIterator!(ndIotaField!2LU), Yuv420), 2LU, mir_slice_kind.contiguous) value) pure nothrow @nogc scope @safe

Assignment of a value of Slice type to a fully defined slice.

length
!0,
(parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
.
ulong mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.length!1LU() const pure nothrow @nogc @property scope @safe

Multidimensional length property.

@returnslength of the corresponding dimension@see.Slice.shape, .Slice.structure
length
!1).
mir.ndslice.slice.Slice!(VmapIterator!(FieldIterator!(ndIotaField!2LU), Yuv420), 2LU, mir_slice_kind.contiguous) mir.ndslice.topology.vmap!(mir.ndslice.iterator.FieldIterator!(ndIotaField!2LU), 2LU, mir_slice_kind.contiguous, images_mir_slice_planar.Yuv420)(mir.ndslice.slice.Slice!(FieldIterator!(ndIotaField!2LU), 2LU, mir_slice_kind.contiguous) slice, images_mir_slice_planar.Yuv420 callable) pure nothrow @nogc @safe

Implements the homonym function (also known as transform) present in many languages of functional flavor. The call slice`.`vmap`(fun)` 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.

@paramslice ndslice@paramcallable callable object, structure, delegate, or function pointer.@seecached, map, rcmap, indexed, pairwise, subSlices, slide, zip, Map (higher-order function)
vmap
(
(local variable) images_mir_slice_planar.Yuv420 f
f
);
} void
void D main() @safe
main
() @safe
{ // One owner for the whole frame: Y, then U, then V, each plane padded. // Heap-only and move-only (`UniqueBuffer!(ubyte, 0)` is rejected: an // inline policy needs N > 0).
(alias) sparkles.base.buffer.HeapBuffer!(ubyte, Storage.unique) = sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u)

A buffer with no inline array: the elements always live on the heap.

For a sequence whose typical size makes an inline array dead weight — the struct costs one slice regardless of how much it holds. Size it up front with reserve; there is no N to raise.

HeapBuffer
!(ubyte,
(enum) sparkles.base.buffer.Storage

What storage a buffer may use, and whether it may be copied.

The bits are capabilities, so the combination is the policy: inline alone never allocates, heap alone carries no inline array, and both together is the small-buffer optimization. ``Storage.none is the empty set — the neutral default for an alias's extra parameter — but a buffer with neither storage bit has nowhere to put anything and fails Buffer's constraint.

Storage
.
(enum value) sparkles.base.buffer.Storage.unique = cast(ubyte)4u

move-only: copying is disabled, so the grow path is refcount-free

unique
)
(local variable) sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u) frame
frame
;
(local variable) sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u) frame
frame
.
void sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u).length(ulong newLength) pure nothrow @nogc @property @trusted

Sets the element count. Growing appends T.init-filled elements (one storage growth); shrinking drops elements from the back and keeps the storage, whichever it is (BUF13) — a buffer that has spilled to the heap stays there until clear or the destructor, so a shrink costs neither a copy back into the inline slots nor a free.

Output range interface: appends a single element.

length
=
(constant) ulong images_mir_slice_planar.lumaBytes = 80LU
lumaBytes
+ 2 *
(constant) ulong images_mir_slice_planar.chromaBytes = 24LU
chromaBytes
;
ubyte[]
(local variable) ubyte[] bytes
bytes
=
(local variable) sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u) frame
frame
[];
(local variable) ubyte[] bytes
bytes
[] = 0xEE; // padding is visible if anything reads it
auto
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
=
mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.plane(return scope ubyte[] bytes, ulong rows, ulong cols, ulong stride) pure nothrow @nogc @safe

One plane: a contiguous rows` x `stride matrix over the bytes, cropped to rows` x `cols. The crop of the last dimension makes it Canonical: the row stride is stored, the column stride is 1.

plane
(
(local variable) ubyte[] bytes
bytes
[0 ..
(constant) ulong images_mir_slice_planar.lumaBytes = 80LU
lumaBytes
],
(constant) ulong images_mir_slice_planar.height = 5LU
height
,
(constant) ulong images_mir_slice_planar.width = 9LU
width
,
(constant) ulong images_mir_slice_planar.lumaStride = 16LU

Row strides in bytes, padded as a decoder or a GPU would (16 and 8).

lumaStride
);
auto
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
=
mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.plane(return scope ubyte[] bytes, ulong rows, ulong cols, ulong stride) pure nothrow @nogc @safe

One plane: a contiguous rows` x `stride matrix over the bytes, cropped to rows` x `cols. The crop of the last dimension makes it Canonical: the row stride is stored, the column stride is 1.

plane
(
(local variable) ubyte[] bytes
bytes
[
(constant) ulong images_mir_slice_planar.lumaBytes = 80LU
lumaBytes
..
(constant) ulong images_mir_slice_planar.lumaBytes = 80LU
lumaBytes
+
(constant) ulong images_mir_slice_planar.chromaBytes = 24LU
chromaBytes
],
(constant) ulong images_mir_slice_planar.chromaHeight = 3LU
chromaHeight
,
(constant) ulong images_mir_slice_planar.chromaWidth = 5LU
chromaWidth
,
(constant) ulong images_mir_slice_planar.chromaStride = 8LU

Row strides in bytes, padded as a decoder or a GPU would (16 and 8).

chromaStride
);
auto
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
=
mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.plane(return scope ubyte[] bytes, ulong rows, ulong cols, ulong stride) pure nothrow @nogc @safe

One plane: a contiguous rows` x `stride matrix over the bytes, cropped to rows` x `cols. The crop of the last dimension makes it Canonical: the row stride is stored, the column stride is 1.

plane
(
(local variable) ubyte[] bytes
bytes
[
(constant) ulong images_mir_slice_planar.lumaBytes = 80LU
lumaBytes
+
(constant) ulong images_mir_slice_planar.chromaBytes = 24LU
chromaBytes
.. $],
(constant) ulong images_mir_slice_planar.chromaHeight = 3LU
chromaHeight
,
(constant) ulong images_mir_slice_planar.chromaWidth = 5LU
chromaWidth
,
(constant) ulong images_mir_slice_planar.chromaStride = 8LU

Row strides in bytes, padded as a decoder or a GPU would (16 and 8).

chromaStride
);
foreach (
(local variable) ulong y
y
; 0 ..
(constant) ulong images_mir_slice_planar.height = 5LU
height
)
foreach (
(local variable) ulong x
x
; 0 ..
(constant) ulong images_mir_slice_planar.width = 9LU
width
)
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
[
(local variable) ulong y
y
,
(local variable) ulong x
x
] = cast(ubyte) (16 +
(local variable) ulong y
y
* 40 +
(local variable) ulong x
x
* 20);
foreach (
(local variable) ulong y
y
; 0 ..
(constant) ulong images_mir_slice_planar.chromaHeight = 3LU
chromaHeight
)
foreach (
(local variable) ulong x
x
; 0 ..
(constant) ulong images_mir_slice_planar.chromaWidth = 5LU
chromaWidth
)
{
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
[
(local variable) ulong y
y
,
(local variable) ulong x
x
] = cast(ubyte) (64 +
(local variable) ulong x
x
* 32);
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
[
(local variable) ulong y
y
,
(local variable) ulong x
x
] = cast(ubyte) (192 -
(local variable) ulong y
y
* 48);
}
void std.stdio.writefln!(char, ulong[2], long[2], ulong[2], long[2], ulong[2], long[2])(in char[] fmt, ulong[2] __param_1, long[2] __param_2, ulong[2] __param_3, long[2] __param_4, ulong[2] __param_5, long[2] __param_6) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("Y lengths %s strides %s U lengths %s strides %s V lengths %s strides %s",
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
.
ulong[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.shape!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
shape
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
.
long[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.strides!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
strides
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
.
ulong[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.shape!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
shape
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
.
long[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.strides!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
strides
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
.
ulong[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.shape!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
shape
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
.
long[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.strides!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
strides
);
void std.stdio.writefln!(char, uint, uint, uint)(in char[] fmt, uint __param_1, uint __param_2, uint __param_3) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("fnv1a Y %08x U %08x V %08x (padding not visited)",
uint images_mir_slice_planar.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical))(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) s) pure nothrow @nogc @safe
fnv1a
(
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
),
uint images_mir_slice_planar.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical))(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) s) pure nothrow @nogc @safe
fnv1a
(
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
),
uint images_mir_slice_planar.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical))(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) s) pure nothrow @nogc @safe
fnv1a
(
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
));
auto
(local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgb
rgb
= new
(struct) images_mir_slice_planar.Rgb8
Rgb8
[](
(constant) ulong images_mir_slice_planar.width = 9LU
width
*
(constant) ulong images_mir_slice_planar.height = 5LU
height
).
mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) mir.ndslice.slice.sliced!(2LU, images_mir_slice_planar.Rgb8[])(return scope images_mir_slice_planar.Rgb8[] iterator, ulong[2] lengths...) pure nothrow @nogc @safe

Creates 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);
@paramiterator An iterator, a pointer, or an array.@paramlengths A list of lengths for each dimension@returnsn-dimensional slice
sliced
(
(constant) ulong images_mir_slice_planar.height = 5LU
height
,
(constant) ulong images_mir_slice_planar.width = 9LU
width
);
void images_mir_slice_planar.convert(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up, mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp, mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) dst) pure nothrow @nogc @safe

Converts the frame into dst: a lazy ndiota view over the luma extent, mapped through Yuv420; assigning it runs it. ndiota(...).map!(i => ...) with a lambda reading the planes is rejected under @nogc ("allocates closure"), so the planes travel in the functor vmap takes.

convert
(
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) yp
yp
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) up
up
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vp
vp
,
(local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgb
rgb
);
void std.stdio.writefln!(char, images_mir_slice_planar.Rgb8, images_mir_slice_planar.Rgb8)(in char[] fmt, images_mir_slice_planar.Rgb8 __param_1, images_mir_slice_planar.Rgb8 __param_2) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("rgb[0, 0] %s rgb[4, 8] %s",
(local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgb
rgb
[0, 0],
(local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgb
rgb
[4, 8]);
void std.stdio.writefln!(char, uint)(in char[] fmt, uint __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("fnv1a rgb %08x",
uint images_mir_slice_planar.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 @safe
fnv1a
((cast(ubyte[])
(local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgb
rgb
.
images_mir_slice_planar.Rgb8[] mir.ndslice.slice.Slice!(images_mir_slice_planar.Rgb8*, 2LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trusted

Field (array) data.

Constraints

Field is defined only for contiguous slices.

@returnsRaw data slice.
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 @safe

Creates 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);
@paramiterator An iterator, a pointer, or an array.@paramlengths A list of lengths for each dimension@returnsn-dimensional slice
sliced
(
(constant) ulong images_mir_slice_planar.height = 5LU
height
,
(constant) ulong images_mir_slice_planar.width = 9LU
width
, 3)));
// A packed RGB image, 9 pixels = 27 bytes a row, padded to a 32-byte stride. enum
(alias) object.size_t = ulong
size_t
(constant) ulong images_mir_slice_planar.main.rgbStride = 32LU
rgbStride
= 32;
auto
(local variable) ubyte[] packed
packed
= new ubyte[](
(constant) ulong images_mir_slice_planar.main.rgbStride = 32LU
rgbStride
*
(constant) ulong images_mir_slice_planar.height = 5LU
height
);
(local variable) ubyte[] packed
packed
[] = 0xEE;
// As bytes it is a Canonical 2-D slice (rows x 27). auto
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) rows
rows
=
(local variable) ubyte[] packed
packed
.
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 @safe

Creates 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);
@paramiterator An iterator, a pointer, or an array.@paramlengths A list of lengths for each dimension@returnsn-dimensional slice
sliced
(
(constant) ulong images_mir_slice_planar.height = 5LU
height
,
(constant) ulong images_mir_slice_planar.main.rgbStride = 32LU
rgbStride
)[0 .. $, 0 ..
(constant) ulong images_mir_slice_planar.width = 9LU
width
* 3];
// As pixels it is not a Slice at all: mir strides count elements, and a // 32-byte stride is 10 2/3 `Rgb8`s.
void std.stdio.writefln!(char, ulong)(in char[] fmt, ulong __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("rgbStride %% Rgb8.sizeof = %s, so no Slice!(Rgb8*, 2) has this stride",
(constant) ulong images_mir_slice_planar.main.rgbStride = 32LU
rgbStride
%
(struct) images_mir_slice_planar.Rgb8
Rgb8
.
(constant) ulong images_mir_slice_planar.Rgb8.sizeof = 3LU
sizeof
);
// As a 3-D byte slice it is Universal, built from the public fields. That // struct literal is `@system` here only because of the pointer; mir does // not check it against the array's length (see the experiment write-up). auto
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
= () @trusted {
return Slice!(ubyte*, 3, Universal)([
(constant) ulong images_mir_slice_planar.height = 5LU
height
,
(constant) ulong images_mir_slice_planar.width = 9LU
width
, 3], [cast(
(alias) object.ptrdiff_t = long
ptrdiff_t
)
(constant) ulong images_mir_slice_planar.main.rgbStride = 32LU
rgbStride
, 3, 1],
(local variable) ubyte[] packed
packed
.
(field) ubyte* ubyte[].ptr
ptr
);
}(); foreach (
(local variable) ulong y
y
; 0 ..
(constant) ulong images_mir_slice_planar.height = 5LU
height
)
foreach (
(local variable) ulong x
x
; 0 ..
(constant) ulong images_mir_slice_planar.width = 9LU
width
)
{ const
(local variable) const(images_mir_slice_planar.Rgb8) p
p
=
(local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgb
rgb
[
(local variable) ulong y
y
,
(local variable) ulong x
x
];
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
[
(local variable) ulong y
y
,
(local variable) ulong x
x
, 0] =
ubyte mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.opIndexAssign!()(ubyte value, ulong[3] _indices...) pure nothrow @nogc ref return scope @trusted

Assignment of a value (e.g. a number) to a fully defined index.

p
.
ubyte mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.opIndexAssign!()(ubyte value, ulong[3] _indices...) pure nothrow @nogc ref return scope @trusted

Assignment of a value (e.g. a number) to a fully defined index.

r
;
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
[
(local variable) ulong y
y
,
(local variable) ulong x
x
, 1] =
ubyte mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.opIndexAssign!()(ubyte value, ulong[3] _indices...) pure nothrow @nogc ref return scope @trusted

Assignment of a value (e.g. a number) to a fully defined index.

p
.
ubyte mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.opIndexAssign!()(ubyte value, ulong[3] _indices...) pure nothrow @nogc ref return scope @trusted

Assignment of a value (e.g. a number) to a fully defined index.

g
;
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
[
(local variable) ulong y
y
,
(local variable) ulong x
x
, 2] =
ubyte mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.opIndexAssign!()(ubyte value, ulong[3] _indices...) pure nothrow @nogc ref return scope @trusted

Assignment of a value (e.g. a number) to a fully defined index.

p
.
ubyte mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.opIndexAssign!()(ubyte value, ulong[3] _indices...) pure nothrow @nogc ref return scope @trusted

Assignment of a value (e.g. a number) to a fully defined index.

b
;
}
void std.stdio.writefln!(char, ulong[3], long[3], mir.ndslice.slice.Slice!(ubyte*, 1LU, mir_slice_kind.universal))(in char[] fmt, ulong[3] __param_1, long[3] __param_2, mir.ndslice.slice.Slice!(ubyte*, 1LU, mir_slice_kind.universal) __param_3) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("packed 3-D lengths %s strides %s px[4, 8] %s",
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
.
ulong[3] mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.shape!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
shape
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
.
long[3] mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.strides!()() const pure nothrow @nogc @property scope @trusted
@returnsstatic array of lengths@see.Slice.structure
strides
,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
[4, 8]);
void std.stdio.writefln!(char, uint, bool, uint)(in char[] fmt, uint __param_1, bool __param_2, uint __param_3) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("fnv1a packed %08x == fnv1a rgb: %s row bytes fnv1a %08x",
uint images_mir_slice_planar.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal))(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) s) pure nothrow @nogc @safe
fnv1a
(
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
),
uint images_mir_slice_planar.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal))(mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) s) pure nothrow @nogc @safe
fnv1a
(
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) px
px
) ==
uint images_mir_slice_planar.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 @safe
fnv1a
((cast(ubyte[])
(local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgb
rgb
.
images_mir_slice_planar.Rgb8[] mir.ndslice.slice.Slice!(images_mir_slice_planar.Rgb8*, 2LU, mir_slice_kind.contiguous).mir_slice.field!()() pure nothrow @nogc @property return scope @trusted

Field (array) data.

Constraints

Field is defined only for contiguous slices.

@returnsRaw data slice.
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 @safe

Creates 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);
@paramiterator An iterator, a pointer, or an array.@paramlengths A list of lengths for each dimension@returnsn-dimensional slice
sliced
(
(constant) ulong images_mir_slice_planar.height = 5LU
height
,
(constant) ulong images_mir_slice_planar.width = 9LU
width
, 3)),
uint images_mir_slice_planar.fnv1a!(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical))(mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) s) pure nothrow @nogc @safe
fnv1a
(
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) rows
rows
));
void std.stdio.writefln!(char, ubyte)(in char[] fmt, ubyte __param_1) @safe

Equivalent to writef(fmt, args, '\n').

writefln
("padding byte packed[27] = 0x%02X (untouched)",
(local variable) ubyte[] packed
packed
[27]);
}