Palette¶
Namespace Nfty.Core.Imaging in assembly Nfty.Core.
The palette a painting front-end offers: Palette.Slots ramp entries that change with the PaletteMode, plus the rules for the swatches a user saves beside them.
It lives in Core, not in a front-end, for the same reason VariantPreview does: the CLI and the GUI must agree on what "the fifth gray" is, and two copies is how that stops being true. The ramps are also computed rather than typed out, so the grays are reproducible and evenly spaced by construction instead of by whoever transcribed them.
Both ramps are exactly Palette.Slots long, and swapping the mode reuses the same ten slots — the palette's shape never changes, only its contents.
Fields¶
Slots¶
How many ramp slots there are, in either mode.
Properties¶
GrayRamp¶
Ten ascending grays from black to white, evenly spaced across the full 0..255 range.
Both endpoints are included — unlike the half-open ranges ColorRoller samples, this is a fixed ten-entry table rather than a sampled interval, and a gray ramp that could not reach white would be missing the color authors reach for most.
RainbowRamp¶
Ten fully saturated hues spread evenly around the wheel, starting at red.
The step is 360/10, and the last slot is 324° rather than 360°: 360 wraps to 0, so including it would spend two of the ten slots on the same red.
Methods¶
Combine(IEnumerable<RgbColor>?, IEnumerable<RgbColor>?)¶
public static IReadOnlyList<RgbColor> Combine(IEnumerable<RgbColor>? book, IEnumerable<RgbColor>? app);
The two palette scopes resolved into one list: the open CookBook's swatches first, the app-wide ones beneath, with anything present in both appearing once, at its book position.
Parameters
book(IEnumerable<RgbColor>?) - The open CookBook's swatches, or null when no book is open — in which case the app palette is all there is.app(IEnumerable<RgbColor>?) - The app-wide swatches from the.nftystore.
Returns. The combined list, in precedence order.
FromSpecs(IEnumerable<string?>?)¶
Reads swatches out of the prefixed color specs a manifest or a store file holds.
An entry that will not parse is SKIPPED rather than thrown on. A palette is convenience state — one mangled swatch must never be the reason a CookBook cannot be opened — and the same read has to survive a hand-edited manifest. Anything that must reject a bad spec loudly should call ColorSpec.Parse() itself.
Parameters
specs(IEnumerable<string?>?) - Prefixed specs (hex:,rgb:,hsl:,hsv:), or null.
Returns. The colors that parsed, in order.
InMode(IEnumerable<RgbColor>?, PaletteMode)¶
The swatches that belong to a mode's palette.
Parameters
colors(IEnumerable<RgbColor>?) - Swatches from a source that records no mode.mode(PaletteMode) - The mode being offered.
Returns. The swatches that belong in that mode, in order.
Remarks
The two palettes are separate, and the rule is the color itself. Grayscale mode paints a value-map, where a color has no meaning beyond its lightness: a saved vermilion offered there is a cell that silently arms a mid gray, and a row of twenty of them is twenty cells the author cannot tell apart. Color mode has the opposite problem — the grays a value-map is authored in are the least useful entries in a rainbow.
Saving always writes to the palette for the mode in force, so a grayscale palette can only ever contain grays by construction. This is for the swatches that arrive carrying no mode at all: a CookBook's own palette, which travels in its archive. Routing them by GRAYNESS is the only answer that needs no stored field and agrees with what saving would have done.
IsGray(RgbColor)¶
Whether a color is a gray — the same channel in all three.
Parameters
color(RgbColor) - The color to test.
Returns. True when the color carries no hue.
RampFor(PaletteMode)¶
The ramp for a mode.
Parameters
mode(PaletteMode) - Which ramp is wanted.
Returns. Exactly Palette.Slots colors.
ToSpecs(IEnumerable<RgbColor>)¶
Writes swatches as the prefixed hex: specs a manifest or store file holds — the same form an author types, so a palette stays readable and re-runnable by hand.
Parameters
colors(IEnumerable<RgbColor>) - The swatches to write.
Returns. One spec per color, in order.