Skip to content

NumberStamp

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

public static class NumberStamp

Stamps an asset's set number into a corner, for telling loose sprites apart.

Remarks

The digits are PIXELS, not a typeface, and that is the whole design. Every image this project touches is generated pixel art shown at a size unrelated to its pixel count, and nothing anywhere resamples, blurs or anti-aliases. A real font would need SixLabors.Fonts and ImageSharp.Drawing — a new dependency beside an ImageSharp deliberately pinned at 3.1.11 — and would render a grey, anti-aliased number onto art that has no grey in it. A 3x5 bitmap font is twelve constants, needs nothing, and scales by an integer factor, so a stamped asset is still exactly the kind of image the rest of the product promises.

It is a DEBUG mark and it is destructive, so it only ever happens on the way out. Nothing here writes back into a Set: the export renders a stamped copy and ships that, which is why the same option cannot quietly corrupt the author's collection. The number stamped is the asset's own set number, so a folder of loose sprites sorts and cross-references against nfty/NNNN.json without anything else being recorded.

White on black, both drawn. An asset can be any colour, including white, and a bare white number vanishes on pale art while a bare black one vanishes on dark art. The glyph is drawn in white over a one-pixel black halo, which is legible on every ground and costs nothing but a second pass over the same cells.

Methods

Draw(Image<Rgba32>, int, StampCorner, int?)

public static void Draw(Image<Rgba32> image, int number, StampCorner corner, int? scale = null);

Draws a number into one corner of an image, in place.

Parameters

  • image (Image<Rgba32>) - The image to stamp. Modified.
  • number (int) - The number to draw. Negative is drawn as its absolute value.
  • corner (StampCorner) - Which corner it sits in.
  • scale (int?) - Font pixel size, or null for NumberStamp.ScaleFor().

Remarks

It draws nothing rather than clipping when the stamp will not fit the canvas. A half-drawn number is worse than none: the point of the mark is that it can be read, and a "12" cropped to "1" on a tiny sprite is a wrong answer rather than a missing one.

ScaleFor(int, int)

public static int ScaleFor(int canvasWidth, int canvasHeight);

How large one font pixel is drawn on a canvas of this size.

Parameters

  • canvasWidth (int) - The art's width.
  • canvasHeight (int) - The art's height.

Returns. An integer scale, at least 1.

Remarks

Derived rather than chosen, and capped at both ends. A stamp fixed at one pixel is invisible on a 1000px asset and a stamp fixed at eight covers a 16px one entirely. A thirty-secondth of the short side keeps it roughly the same fraction of the picture at every canvas size; the floor of 1 is what a small sprite needs and the ceiling of 8 is where a debug mark stops being a mark and starts being the image.