#!/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_planarPlanar 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) 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_planar.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 : 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.
sliced, Universal;
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_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.
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.
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.
vmap;
import (package) sparklessparkles.(package) sparkles.basebase.(module) sparkles.base.bufferA @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.StorageWhat 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 = ulongsize_t (constant) ulong images_mir_slice_planar.width = 9LUwidth = 9, (constant) ulong images_mir_slice_planar.height = 5LUheight = 5;
enum (alias) object.size_t = ulongsize_t (constant) ulong images_mir_slice_planar.chromaWidth = 5LUchromaWidth = ((constant) ulong images_mir_slice_planar.width = 9LUwidth + 1) / 2, (constant) ulong images_mir_slice_planar.chromaHeight = 3LUchromaHeight = ((constant) ulong images_mir_slice_planar.height = 5LUheight + 1) / 2;
/// Row strides in bytes, padded as a decoder or a GPU would (16 and 8).
enum (alias) object.size_t = ulongsize_t (constant) ulong images_mir_slice_planar.lumaStride = 16LURow strides in bytes, padded as a decoder or a GPU would (16 and 8).
lumaStride = 16, (constant) ulong images_mir_slice_planar.chromaStride = 8LURow strides in bytes, padded as a decoder or a GPU would (16 and 8).
chromaStride = 8;
enum (alias) object.size_t = ulongsize_t (constant) ulong images_mir_slice_planar.lumaBytes = 80LUlumaBytes = (constant) ulong images_mir_slice_planar.lumaStride = 16LURow strides in bytes, padded as a decoder or a GPU would (16 and 8).
lumaStride * (constant) ulong images_mir_slice_planar.height = 5LUheight;
enum (alias) object.size_t = ulongsize_t (constant) ulong images_mir_slice_planar.chromaBytes = 24LUchromaBytes = (constant) ulong images_mir_slice_planar.chromaStride = 8LURow strides in bytes, padded as a decoder or a GPU would (16 and 8).
chromaStride * (constant) ulong images_mir_slice_planar.chromaHeight = 3LUchromaHeight;
struct (struct) images_mir_slice_planar.Rgb8Rgb8
{
ubyte (field) ubyte images_mir_slice_planar.Rgb8.rr, (field) ubyte images_mir_slice_planar.Rgb8.gg, (field) ubyte images_mir_slice_planar.Rgb8.bb;
}
static assert((struct) images_mir_slice_planar.Rgb8Rgb8.(constant) ulong images_mir_slice_planar.Rgb8.sizeof = 3LUsizeof == 3);
ubyte ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safeclamp8(int (parameter) int vv) @safe pure nothrow @nogc => cast(ubyte) ((parameter) int vv < 0 ? 0 : (parameter) int vv > 255 ? 255 : (parameter) int vv);
/// BT.601 full-range YCbCr to RGB, 8.8 fixed point.
(struct) images_mir_slice_planar.Rgb8Rgb8 images_mir_slice_planar.Rgb8 images_mir_slice_planar.yuvToRgb(ubyte y, ubyte u, ubyte v) pure nothrow @nogc @safeBT.601 full-range YCbCr to RGB, 8.8 fixed point.
yuvToRgb(ubyte (parameter) ubyte yy, ubyte (parameter) ubyte uu, ubyte (parameter) ubyte vv) @safe pure nothrow @nogc
{
const int (local variable) const(int) cc = (parameter) ubyte yy, (local variable) const(int) dd = (parameter) ubyte uu - 128, (local variable) const(int) ee = (parameter) ubyte vv - 128;
return (struct) images_mir_slice_planar.Rgb8Rgb8(ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safeclamp8((local variable) const(int) cc + ((359 * (local variable) const(int) ee + 128) >> 8)), ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safeclamp8((local variable) const(int) cc - ((88 * (local variable) const(int) dd + 183 * (local variable) const(int) ee + 128) >> 8)),
ubyte images_mir_slice_planar.clamp8(int v) pure nothrow @nogc @safeclamp8((local variable) const(int) cc + ((454 * (local variable) const(int) dd + 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 @safeOne 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[] bytesbytes, (alias) object.size_t = ulongsize_t (parameter) ulong rowsrows, (alias) object.size_t = ulongsize_t (parameter) ulong colscols, (alias) object.size_t = ulongsize_t (parameter) ulong stridestride)
@safe pure nothrow @nogc
=> (parameter) ubyte[] bytesbytes.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((parameter) ulong rowsrows, (parameter) ulong stridestride)[0 .. $, 0 .. (parameter) ulong colscols];
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 @safefnv1a(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) ss)
{
uint (local variable) uint hh = 2_166_136_261;
foreach ((local variable) ubyte bb; (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) ss.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 @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;
}
/// 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.Yuv420The 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.ypyp, (field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.upup, (field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.vpvp;
(struct) images_mir_slice_planar.Rgb8Rgb8 images_mir_slice_planar.Rgb8 images_mir_slice_planar.Yuv420.opCall(ulong[2] i) const pure nothrow @nogc @safeopCall((alias) object.size_t = ulongsize_t[2] (parameter) ulong[2] ii) const @safe pure nothrow @nogc
=> images_mir_slice_planar.Rgb8 images_mir_slice_planar.yuvToRgb(ubyte y, ubyte u, ubyte v) pure nothrow @nogc @safeBT.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.ypyp[(parameter) ulong[2] ii[0], (parameter) ulong[2] ii[1]], (field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.upup[(parameter) ulong[2] ii[0] / 2, (parameter) ulong[2] ii[1] / 2], (field) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) images_mir_slice_planar.Yuv420.vpvp[(parameter) ulong[2] ii[0] / 2, (parameter) ulong[2] ii[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 @safeConverts 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) ypyp, Slice!(ubyte*, 2, Canonical) (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) upup, Slice!(ubyte*, 2, Canonical) (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vpvp,
Slice!(Rgb8*, 2) (parameter) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) dstdst) @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.Yuv420The 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 ff = {yp: (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) ypyp, up: (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) upup, vp: (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vpvp};
(parameter) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) dstdst[] = 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 @safeAssignment 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 @safeAssignment 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 @safeAssignment of a value of Slice type to a fully defined slice.
length!0, (parameter) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) ypyp.ulong mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.length!1LU() const pure nothrow @nogc @property scope @safeMultidimensional length property.
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 @safeImplements 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.
vmap((local variable) images_mir_slice_planar.Yuv420 ff);
}
void void D main() @safemain() @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.StorageWhat 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)4umove-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) frameframe;
(local variable) sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u) frameframe.void sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u).length(ulong newLength) pure nothrow @nogc @property @trustedSets 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 = 80LUlumaBytes + 2 * (constant) ulong images_mir_slice_planar.chromaBytes = 24LUchromaBytes;
ubyte[] (local variable) ubyte[] bytesbytes = (local variable) sparkles.base.buffer.Buffer!(ubyte, 0LU, cast(Storage)cast(ubyte)6u) frameframe[];
(local variable) ubyte[] bytesbytes[] = 0xEE; // padding is visible if anything reads it
auto (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) ypyp = 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 @safeOne 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[] bytesbytes[0 .. (constant) ulong images_mir_slice_planar.lumaBytes = 80LUlumaBytes], (constant) ulong images_mir_slice_planar.height = 5LUheight, (constant) ulong images_mir_slice_planar.width = 9LUwidth, (constant) ulong images_mir_slice_planar.lumaStride = 16LURow 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) upup = 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 @safeOne 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[] bytesbytes[(constant) ulong images_mir_slice_planar.lumaBytes = 80LUlumaBytes .. (constant) ulong images_mir_slice_planar.lumaBytes = 80LUlumaBytes + (constant) ulong images_mir_slice_planar.chromaBytes = 24LUchromaBytes], (constant) ulong images_mir_slice_planar.chromaHeight = 3LUchromaHeight, (constant) ulong images_mir_slice_planar.chromaWidth = 5LUchromaWidth, (constant) ulong images_mir_slice_planar.chromaStride = 8LURow 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) vpvp = 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 @safeOne 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[] bytesbytes[(constant) ulong images_mir_slice_planar.lumaBytes = 80LUlumaBytes + (constant) ulong images_mir_slice_planar.chromaBytes = 24LUchromaBytes .. $], (constant) ulong images_mir_slice_planar.chromaHeight = 3LUchromaHeight, (constant) ulong images_mir_slice_planar.chromaWidth = 5LUchromaWidth, (constant) ulong images_mir_slice_planar.chromaStride = 8LURow strides in bytes, padded as a decoder or a GPU would (16 and 8).
chromaStride);
foreach ((local variable) ulong yy; 0 .. (constant) ulong images_mir_slice_planar.height = 5LUheight)
foreach ((local variable) ulong xx; 0 .. (constant) ulong images_mir_slice_planar.width = 9LUwidth)
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) ypyp[(local variable) ulong yy, (local variable) ulong xx] = cast(ubyte) (16 + (local variable) ulong yy * 40 + (local variable) ulong xx * 20);
foreach ((local variable) ulong yy; 0 .. (constant) ulong images_mir_slice_planar.chromaHeight = 3LUchromaHeight)
foreach ((local variable) ulong xx; 0 .. (constant) ulong images_mir_slice_planar.chromaWidth = 5LUchromaWidth)
{
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) upup[(local variable) ulong yy, (local variable) ulong xx] = cast(ubyte) (64 + (local variable) ulong xx * 32);
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vpvp[(local variable) ulong yy, (local variable) ulong xx] = cast(ubyte) (192 - (local variable) ulong yy * 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) @safeEquivalent 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) ypyp.ulong[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.shape!()() const pure nothrow @nogc @property scope @trustedshape, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) ypyp.long[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.strides!()() const pure nothrow @nogc @property scope @trustedstrides,
(local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) upup.ulong[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.shape!()() const pure nothrow @nogc @property scope @trustedshape, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) upup.long[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.strides!()() const pure nothrow @nogc @property scope @trustedstrides, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vpvp.ulong[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.shape!()() const pure nothrow @nogc @property scope @trustedshape, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vpvp.long[2] mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical).mir_slice.strides!()() const pure nothrow @nogc @property scope @trustedstrides);
void std.stdio.writefln!(char, uint, uint, uint)(in char[] fmt, uint __param_1, uint __param_2, uint __param_3) @safeEquivalent 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 @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) ypyp), 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 @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) upup), 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 @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vpvp));
auto (local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgbrgb = new (struct) images_mir_slice_planar.Rgb8Rgb8[]((constant) ulong images_mir_slice_planar.width = 9LUwidth * (constant) ulong images_mir_slice_planar.height = 5LUheight).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 @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_planar.height = 5LUheight, (constant) ulong images_mir_slice_planar.width = 9LUwidth);
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 @safeConverts 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) ypyp, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) upup, (local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) vpvp, (local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgbrgb);
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) @safeEquivalent 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) rgbrgb[0, 0], (local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgbrgb[4, 8]);
void std.stdio.writefln!(char, uint)(in char[] fmt, uint __param_1) @safeEquivalent 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 @safefnv1a((cast(ubyte[]) (local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgbrgb.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 @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_planar.height = 5LUheight, (constant) ulong images_mir_slice_planar.width = 9LUwidth, 3)));
// A packed RGB image, 9 pixels = 27 bytes a row, padded to a 32-byte stride.
enum (alias) object.size_t = ulongsize_t (constant) ulong images_mir_slice_planar.main.rgbStride = 32LUrgbStride = 32;
auto (local variable) ubyte[] packedpacked = new ubyte[]((constant) ulong images_mir_slice_planar.main.rgbStride = 32LUrgbStride * (constant) ulong images_mir_slice_planar.height = 5LUheight);
(local variable) ubyte[] packedpacked[] = 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) rowsrows = (local variable) ubyte[] packedpacked.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_planar.height = 5LUheight, (constant) ulong images_mir_slice_planar.main.rgbStride = 32LUrgbStride)[0 .. $, 0 .. (constant) ulong images_mir_slice_planar.width = 9LUwidth * 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) @safeEquivalent 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 = 32LUrgbStride % (struct) images_mir_slice_planar.Rgb8Rgb8.(constant) ulong images_mir_slice_planar.Rgb8.sizeof = 3LUsizeof);
// 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) pxpx = () @trusted {
return Slice!(ubyte*, 3, Universal)([(constant) ulong images_mir_slice_planar.height = 5LUheight, (constant) ulong images_mir_slice_planar.width = 9LUwidth, 3], [cast((alias) object.ptrdiff_t = longptrdiff_t) (constant) ulong images_mir_slice_planar.main.rgbStride = 32LUrgbStride, 3, 1], (local variable) ubyte[] packedpacked.(field) ubyte* ubyte[].ptrptr);
}();
foreach ((local variable) ulong yy; 0 .. (constant) ulong images_mir_slice_planar.height = 5LUheight)
foreach ((local variable) ulong xx; 0 .. (constant) ulong images_mir_slice_planar.width = 9LUwidth)
{
const (local variable) const(images_mir_slice_planar.Rgb8) pp = (local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgbrgb[(local variable) ulong yy, (local variable) ulong xx];
(local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) pxpx[(local variable) ulong yy, (local variable) ulong xx, 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 @trustedAssignment 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 @trustedAssignment 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) pxpx[(local variable) ulong yy, (local variable) ulong xx, 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 @trustedAssignment 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 @trustedAssignment 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) pxpx[(local variable) ulong yy, (local variable) ulong xx, 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 @trustedAssignment 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 @trustedAssignment 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) @safeEquivalent 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) pxpx.ulong[3] mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.shape!()() const pure nothrow @nogc @property scope @trustedshape, (local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) pxpx.long[3] mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal).mir_slice.strides!()() const pure nothrow @nogc @property scope @trustedstrides, (local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) pxpx[4, 8]);
void std.stdio.writefln!(char, uint, bool, uint)(in char[] fmt, uint __param_1, bool __param_2, uint __param_3) @safeEquivalent 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 @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) pxpx),
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 @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 3LU, mir_slice_kind.universal) pxpx) == 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 @safefnv1a((cast(ubyte[]) (local variable) mir.ndslice.slice.Slice!(Rgb8*, 2LU, mir_slice_kind.contiguous) rgbrgb.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 @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_planar.height = 5LUheight, (constant) ulong images_mir_slice_planar.width = 9LUwidth, 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 @safefnv1a((local variable) mir.ndslice.slice.Slice!(ubyte*, 2LU, mir_slice_kind.canonical) rowsrows));
void std.stdio.writefln!(char, ubyte)(in char[] fmt, ubyte __param_1) @safeEquivalent to writef(fmt, args, '\n').
writefln("padding byte packed[27] = 0x%02X (untouched)", (local variable) ubyte[] packedpacked[27]);
}