Skip to content

DepthMap

Namespace Nfty.Core.Model in assembly Nfty.Ticket.

public sealed class DepthMap

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

public int Height { get; }

The map's height in pixels.

IsFlat

public bool IsFlat { get; }

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

public int Width { get; }

The map's width in pixels.

Methods

Back(int, int)

public byte Back(int x, int y);

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)

public static DepthMap Flat(int width, int height);

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 - width or height is not positive.

FromBytes(int, int, ReadOnlySpan<byte>)

public static DepthMap FromBytes(int width, int height, ReadOnlySpan<byte> bytes);

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 exactly width * height * 2 bytes long.

Returns. A new DepthMap holding a copy of bytes.

Exceptions

  • ArgumentException - bytes is not exactly width * height * 2 bytes long.

Front(int, int)

public byte Front(int x, int y);

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()

public byte[] 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)

public DepthMap With(int x, int y, byte front, byte back);

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.