DepthMap¶
Namespace Nfty.Core.Model in assembly Nfty.Ticket.
A per-pixel front/back depth pair for one layer's artwork, so a 2D asset can be lifted into a scene with real parallax. Two bytes per pixel — front then back, each 0..255 — laid out row-major with the top row first and, within a row, left to right: pixel (x, y) lives at byte offset (y * Width + x) * 2, front then back. A byte cannot spell more than 255 levels of depth; that is the whole precision this format carries.
Properties¶
Height¶
The map's height in pixels.
IsFlat¶
Whether every byte is zero — a map nobody has painted, front and back both at the surface for every pixel. Computed once when the map is built, never lazily, so it is always consistent with the bytes it describes.
Width¶
The map's width in pixels.
Methods¶
Back(int, int)¶
The back depth (0..255) at a pixel.
Parameters
x(int) - Column, 0-based.y(int) - Row, 0-based.
Returns. The back depth, 0 for flat paper.
Flat(int, int)¶
Builds a flat map — every pixel's front and back at zero — for a canvas of the given size.
Parameters
width(int) - Width in pixels; must be positive.height(int) - Height in pixels; must be positive.
Returns. A new, all-zero DepthMap.
Exceptions
ArgumentOutOfRangeException-widthorheightis not positive.
FromBytes(int, int, ReadOnlySpan<byte>)¶
Builds a map from its raw bytes, copying them so the caller cannot mutate the map afterwards.
Parameters
width(int) - Width in pixels; must be positive.height(int) - Height in pixels; must be positive.bytes(ReadOnlySpan<byte>) - Front/back pairs, row-major, top row first — see the type summary for the exact layout. Must be exactlywidth * height * 2bytes long.
Returns. A new DepthMap holding a copy of bytes.
Exceptions
ArgumentException-bytesis not exactlywidth * height * 2bytes long.
Front(int, int)¶
The front depth (0..255) at a pixel.
Parameters
x(int) - Column, 0-based.y(int) - Row, 0-based.
Returns. The front depth, 0 for flat paper.
ToBytes()¶
A copy of the map's raw bytes, in the same front/back row-major layout described on the type.
Returns. A new array; mutating it does not affect this map.
With(int, int, byte, byte)¶
Returns a new map with one pixel's front and back depth replaced, leaving this map unchanged.
Parameters
x(int) - Column, 0-based.y(int) - Row, 0-based.front(byte) - The new front depth.back(byte) - The new back depth.
Returns. A new DepthMap with the one pixel changed.