Skip to content

PreviewLayer

Namespace Nfty.Core.Imaging in assembly Nfty.Core.

public readonly struct PreviewLayer : IEquatable<PreviewLayer>

One reference layer in a stack preview: which ingredient, which of its variants, and the color to draw it in.

Constructors

PreviewLayer(LoadedIngredient, string, string?, RolledColor?)

public PreviewLayer(LoadedIngredient Ingredient, string VariantId, string? ColorSpec, RolledColor? Rolled = null);

Parameters

  • Ingredient (LoadedIngredient) - The layer to draw. Its images stay owned by it — StackPreview.Render() renders through VariantPreview, which never hands out a borrowed image, so nothing here ever disposes what an ingredient owns.
  • VariantId (string) - Which variant to draw. StackPreview.PickVariant() is the deterministic default when the caller has no opinion.
  • ColorSpec (string?) - A prefixed color spec (hex:, rgb:, hsl:, hsv:) for a Dynamic or Static layer; ignored by a Custom one, which is composited as-is and never colorized. Which kinds need one is VariantPreview.NeedsColor()'s answer and the requirement is VariantPreview.Render's to enforce — restating either here would be a second copy of a rule that has exactly one owner.
  • Rolled (RolledColor?) - The rolled hue and saturation, unrounded — set for a layer whose color was rolled rather than authored. When present it is what gets drawn, and ColorSpec becomes display only. Both exist because they answer different questions. A spec is what a human reads, pastes and re-runs; a RolledColor is what generation actually hands the colorizer. Every spec resolves through 8-bit RGB, so a rolled hue that fell between two representable colors cannot be spelled exactly — carrying only the string put the preview a rounding step off the asset it claims to show. Carrying both keeps the printed spec readable AND the rendered pixel exact. Null for Static (an author-written spec, resolved identically by generation, so already exact) and for Custom (no color at all).

Properties

ColorSpec

public string? ColorSpec { get; init; }

A prefixed color spec (hex:, rgb:, hsl:, hsv:) for a Dynamic or Static layer; ignored by a Custom one, which is composited as-is and never colorized. Which kinds need one is VariantPreview.NeedsColor()'s answer and the requirement is VariantPreview.Render's to enforce — restating either here would be a second copy of a rule that has exactly one owner.

Ingredient

public LoadedIngredient Ingredient { get; init; }

The layer to draw. Its images stay owned by it — StackPreview.Render() renders through VariantPreview, which never hands out a borrowed image, so nothing here ever disposes what an ingredient owns.

Rolled

public RolledColor? Rolled { get; init; }

The rolled hue and saturation, unrounded — set for a layer whose color was rolled rather than authored. When present it is what gets drawn, and ColorSpec becomes display only.

Both exist because they answer different questions. A spec is what a human reads, pastes and re-runs; a RolledColor is what generation actually hands the colorizer. Every spec resolves through 8-bit RGB, so a rolled hue that fell between two representable colors cannot be spelled exactly — carrying only the string put the preview a rounding step off the asset it claims to show. Carrying both keeps the printed spec readable AND the rendered pixel exact.

Null for Static (an author-written spec, resolved identically by generation, so already exact) and for Custom (no color at all).

VariantId

public string VariantId { get; init; }

Which variant to draw. StackPreview.PickVariant() is the deterministic default when the caller has no opinion.

Methods

Render()

public Image<Rgba32> Render();

Renders this layer through VariantPreview: the rolled color when there is one (it is exact; the spec beside it is only its 8-bit spelling), the spec otherwise. The one place that choice is made, for the stack preview and the CLI's model alike.

Returns. The rendered layer; the caller owns and disposes it.