toUnsigned

Convert floating point input to unsigned.

Slice!(ReturnType*, dims)
toUnsigned
(
ReturnType = ubyte
InputType
size_t dims
)
(
Slice!(InputType*, dims) input
)

Examples

import std.math : approxEqual;
import mir.ndslice : sliced;

// dfmt off
Slice!(double*, 3) rgb = [
    1.0, 0.0, 0.0,
    0.0, 1.0, 0.0,
    0.0, 0.0, 1.0,
    0.470588, 0.470588, 0.470588
].sliced(4, 1, 3);

ubyte[] rgbU = [
    255, 0, 0,
    0, 255, 0,
    0, 0, 255,
    120, 120, 120
];
Slice!(ubyte*, 3) rgbUnsigned = rgbU.sliced(4, 1, 3);
//dfmt on

assert(approxEqual(rgb.toUnsigned, rgbUnsigned));

Meta