Skip to content

ValueMap

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

public sealed class ValueMap : IEditSurface<GrayPixel>

Editable single-layer raster: one grayscale value (0–255) plus one alpha (0–255) per pixel, bound to a fixed canvas size. Grayscale is guaranteed by construction — there is no way to store independent R/G/B. Materialize an Image only at export/preview.

Remarks

It is an IEditSurface<TPixel>, which is how the generic paint stack reaches it. That costs the guarantee nothing: GrayPixel carries one value and one alpha, so a command written against the generic surface has no color to hand this map even if it holds one. Nothing on this type accepts independent R/G/B, and nothing should be added that does.

Constructors

ValueMap(int, int)

public ValueMap(int width, int height);

Creates a blank map.

Parameters

  • width (int) - Width in pixels; must be positive.
  • height (int) - Height in pixels; must be positive.

Exceptions

  • ArgumentOutOfRangeException - Either dimension is zero or negative.

Properties

Height

public int Height { get; }

Height in pixels.

Width

public int Width { get; }

Width in pixels.

Methods

AlphaOf(GrayPixel)

public byte AlphaOf(GrayPixel pixel);

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

Parameters

  • pixel (GrayPixel) - The pixel to read.

Returns. Alpha, 0-255.

Clone()

public ValueMap Clone();

An independent deep copy — cloned value/alpha buffers, same dimensions.

Returns. A new map with its own buffers.

ForCanvas(Dimensions)

public static ValueMap ForCanvas(Dimensions canvas);

A blank map at the CookBook's canvas size.

Parameters

  • canvas (Dimensions) - The canvas to match.

Returns. A new map.

FromImage(Image<Rgba32>)

public static ValueMap FromImage(Image<Rgba32> img);

Reads a map back out of a decoded variant image.

Parameters

  • img (Image<Rgba32>) - The source image.

Returns. A new map.

Get(int, int)

public GrayPixel Get(int x, int y);

The pixel at a coordinate, as the generic paint stack sees it.

Parameters

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

Returns. Its value and alpha.

GetAlpha(int, int)

public byte GetAlpha(int x, int y);

The alpha at a pixel.

Parameters

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

Returns. 0-255.

GetValue(int, int)

public byte GetValue(int x, int y);

The grayscale value at a pixel.

Parameters

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

Returns. 0-255.

InBounds(int, int)

public bool InBounds(int x, int y);

Whether a coordinate is inside the map.

Parameters

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

Returns. True when the pixel exists.

Set(int, int, GrayPixel)

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

Writes one pixel. Out-of-bounds coordinates are ignored.

Parameters

  • x (int) - Column.
  • y (int) - Row.
  • pixel (GrayPixel) - The value and alpha to store.

Set(int, int, byte, byte)

public void Set(int x, int y, byte value, byte alpha);

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.
  • value (byte) - Grayscale value.
  • alpha (byte) - Alpha.

ToImage()

public Image<Rgba32> ToImage();

Renders to a grayscale RGBA image — the form an .igt stores.

Returns. A new image; the caller owns it.

WithAlpha(GrayPixel, byte)

public GrayPixel WithAlpha(GrayPixel pixel, byte alpha);

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

Parameters

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

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