Skip to content

IEditSurface<TPixel>

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

public interface IEditSurface<TPixel>

A fixed-size, randomly-addressable raster the edit commands paint on, generic over the pixel it stores: ValueMap supplies GrayPixel, ColorMap supplies Rgba32. The commands hold geometry only — every "what does this pixel become" decision travels as a TPixel, so one implementation of disc stamping, shape rasterising, region scanning and the undo snapshot serves both surfaces.

Type parameters

  • TPixel - The pixel this surface stores.

Remarks

IEditSurface<TPixel>.AlphaOf() and IEditSurface<TPixel>.WithAlpha() are here rather than on the pixel because Rgba32 is ImageSharp's type and cannot be made to implement an interface of ours. They carry format knowledge only — where this surface's pixel keeps its alpha — never policy: the opacity lock's rule lives once in RegionEditCommand<TPixel>, so the two surfaces have nothing to keep in step and nothing to drift apart on.

Properties

Height

public abstract int Height { get; }

Height in pixels.

Width

public abstract int Width { get; }

Width in pixels.

Methods

AlphaOf(TPixel)

public abstract byte AlphaOf(TPixel pixel);

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

Parameters

  • pixel (TPixel) - The pixel to read.

Returns. Alpha, 0-255.

Get(int, int)

public abstract TPixel 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.

InBounds(int, int)

public abstract 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.

Set(int, int, TPixel)

public abstract void Set(int x, int y, TPixel pixel);

Writes one pixel. Out-of-bounds coordinates are ignored, so a brush may run off the edge without the caller clipping first.

Parameters

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

WithAlpha(TPixel, byte)

public abstract TPixel WithAlpha(TPixel pixel, byte alpha);

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

Parameters

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

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