Function tryConvertAllocated
Allocates one compact one-plane To raster and converts one selected source plane into it.
RasterAllocatedConversionResult!To tryConvertAllocated(To, RasterConversionPolicy Policy = RasterConversionPolicy .exact, From)(
scope RasterView!From source,
size_t sourcePlaneIndex
) @safe
if (Policy == RasterConversionPolicy .exact && isUniversallyExactRasterConversion!(From, To));
The conversion semantic is exactly convertRasterInto!(To, Policy).
Policy defaults to RasterConversionPolicy.exact, the only supported conversion policy in v0.2.
Successful output:
- sample type To; - width/height equal to source; - resident origin (0,0); - exactly one logical plane; - compact sample stride 1 / row stride width; - independently owned writable storage; - no alias with source storage.
A matching zero-area source creates a retained metadata-only one-plane result without pixel allocation.
Failure sequence:
1. invalid source plane; 2. destination size/allocation/backing construction; 3. writable destination capability; 4. convertRasterInto structural failure.
The function contains no conversion loop. All sample semantics are delegated to convertRasterInto().
The destination-oriented API remains preferable when callers already own or wish to reuse destination storage.
Example
Example using allocating exact conversion through UFCS.
import raster;
RasterView!ubyte source;
const result =
source .tryConvertAllocated!float(
0
);
assert(!result .ok);
assert(
result .error
== RasterAllocatedConversionError .invalidSourcePlane
);