Skip to content

DepthSurface

Namespace Nfty.Core.Editing in assembly Nfty.Core.

public sealed class DepthSurface : IEditSurface<DepthPixel>

The surface the depth tools edit: one DepthPixel per art pixel, held beside a copy of the art that says which pixels are solid and which share a color.

Remarks

Depth belongs to solid pixels only — a transparent or partially transparent pixel has no body to give thickness to — so DepthSurface.Set() ignores them and a stored map's bytes under them are dropped on load. The alpha members of IEditSurface<TPixel> are inert (ruling 1): a depth pixel has no alpha, so DepthSurface.AlphaOf() is always opaque and DepthSurface.WithAlpha() is the identity, which keeps the opacity lock a no-op here rather than a rule to keep in step.

Constructors

DepthSurface(Image<Rgba32>, DepthMap?)

public DepthSurface(Image<Rgba32> art, DepthMap? stored);

Builds the surface for an image and the depth it already carries.

Parameters

  • art (Image<Rgba32>) - The finished art; copied, so the caller keeps ownership.
  • stored (DepthMap?) - The layer's stored depth, or null for flat paper.

Exceptions

  • ArgumentException - stored is another size than the art.

Properties

Height

public int Height { get; }

Height in pixels.

PartialCount

public int PartialCount { get; }

Pixels with partial alpha, which cannot be risen into a solid.

SolidCount

public int SolidCount { get; }

Pixels that are fully opaque, and so carry depth.

Width

public int Width { get; }

Width in pixels.

Methods

AlphaOf(DepthPixel)

public byte AlphaOf(DepthPixel pixel);

The alpha channel of a pixel in this surface's format.

Parameters

  • pixel (DepthPixel) - The pixel to read.

Returns. Alpha, 0-255.

ArtAt(int, int)

public Rgba32 ArtAt(int x, int y);

The art pixel at a coordinate, in bounds.

Parameters

  • x (int) - Column.
  • y (int) - Row.

Returns. The art color.

Get(int, int)

public DepthPixel Get(int x, int y);

Reads one pixel. The coordinate must be in bounds.

Parameters

  • x (int) - Column.
  • y (int) - Row.

Returns. The stored pixel.

Histogram()

public IReadOnlyList<ThicknessBucket> Histogram();

Solid pixels counted by total thickness (1 + front + back).

Returns. Buckets ascending by thickness.

InBounds(int, int)

public bool InBounds(int x, int y);

Whether a coordinate is inside the surface.

Parameters

  • x (int) - Column.
  • y (int) - Row.

Returns. True when the pixel exists.

IsSolid(int, int)

public bool IsSolid(int x, int y);

Whether a pixel is fully opaque. Out of bounds is not solid.

Parameters

  • x (int) - Column.
  • y (int) - Row.

Returns. True for a solid pixel.

Overwrite(DepthMap?)

public void Overwrite(DepthMap? map);

Replaces the whole depth with a stored map, in place: every solid pixel takes the map's pair, non-solid pixels stay 0. The instance is unchanged, so references to it stay valid.

Parameters

  • map (DepthMap?) - The depth to take, or null for flat paper (0/0 everywhere).

Exceptions

  • ArgumentException - map is another size than the surface.

SameColorRegion(int, int)

public List<(int, int)> SameColorRegion(int x, int y);

The 4-connected run of solid pixels with exactly the seed's art color.

Parameters

  • x (int) - Seed column.
  • y (int) - Seed row.

Returns. The region; empty when the seed is not solid.

SameDepthAs(DepthMap?)

public bool SameDepthAs(DepthMap? other);

Whether this surface's depth equals a stored map, absent counting as all zero.

Parameters

  • other (DepthMap?) - The stored map, or null for flat.

Returns. True when the bytes agree.

Set(int, int, DepthPixel)

public void Set(int x, int y, DepthPixel pixel);

Writes a pixel's depth. Out-of-bounds and non-solid pixels are ignored: transparent pixels have no depth.

Parameters

  • x (int) - Column.
  • y (int) - Row.
  • pixel (DepthPixel) - The depth to store.

Summary()

public DepthSummary Summary();

What the depth looks like overall.

Returns. Empty, paper, uniform (with its depth) or varied.

TakeDirty()

public PixelRect? TakeDirty();

The bounding rectangle of every pixel whose depth CHANGED since the last call (a write of the value a pixel already held changes nothing), and forgets it. A derived view of this surface (the combined stack of a recipe) recomputes just that rectangle.

Returns. The rectangle, or null when nothing changed.

ToDepthMap()

public DepthMap? ToDepthMap();

The depth as a map to store.

Returns. Null when every solid pixel is 0 front and 0 back, so flat has one spelling: absent.

WithAlpha(DepthPixel, byte)

public DepthPixel WithAlpha(DepthPixel pixel, byte alpha);

The same pixel with its alpha replaced and every other channel untouched.

Parameters

  • pixel (DepthPixel) - The pixel to rewrite.
  • alpha (byte) - The alpha it should carry.

Returns. A pixel identical to pixel apart from its alpha.