Function histogram256

Counts all ubyte values of one selected logical raster plane.

RasterHistogram256Result histogram256(
  scope RasterView!(ubyte) source,
  ulong planeIndex
) nothrow @nogc @safe;

The source may be a full resident view or a zero-copy ROI. Counts are indexed by the exact numeric sample value, from 0 through 255 inclusive; there are no interval boundaries, out-of-range values, floating values, masks, channel interpretation or implicit NoData filtering.

The selected plane must exist. A valid empty plane succeeds with 256 zero counts. An invalid plane fails with invalidPlane; a count that cannot be represented in ulong fails with countOverflow. In either failure case all bins are zero. RasterHistogram256Result.init is failure.

All validated resident layouts are supported, including planar, interleaved and signed row/sample strides. Traversal covers each represented logical sample exactly once, regardless of physical layout. The operation does not modify or retain the source, allocate from the heap, create worker threads or materialize a larger raster.

Adjacent non-overlapping windows using the same value domain are exactly

composable

for every v, whole.bins[v] equals the sum of the windows' bins[v]. Callers merging counts must check ulong overflow themselves; this first API does not publish a redundant merge operation.

Time complexity: O(width * height). Auxiliary storage: 256 ulong counts, independent of raster size.

Parameters

NameDescription
source Borrowed, validated read-only raster view.
planeIndex Zero-based logical plane to count.

Returns

A self-contained 256-bin value result with explicit error/ok state.

Example

Example counting exact raster values through the public, owned import API.

import core.stdc.stdlib : malloc;
import raster;

void* memory = malloc(4);
assert(memory !is null);

auto bytes = (cast(ubyte*) memory)[0 .. 4];
bytes[] = [0, 1, 1, 255];

OwnedByteResource resource;
assert(tryAdoptMallocResource(memory, 4, resource));

const PlaneByteLayout[1] layout = [PlaneByteLayout(0, 2, 1)];
RasterLease!ubyte lease;
assert(tryImportOwnedRaster!ubyte(
    resource, layout[], Region2D(0, 0, 2, 2), lease
).ok);

scope auto source = lease.view();
const result = source.histogram256(0);
assert(result.ok);
assert(result.bins[0] == 1);
assert(result.bins[1] == 2);
assert(result.bins[255] == 1);