Skip to content

ImageImport

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

public static class ImageImport

Turning a picture somebody drew elsewhere into something a layer can hold.

Remarks

Two kinds of layer take an image two different ways, and the difference is the whole reason this is one place rather than two. A Custom layer keeps every channel: the art IS the art, composited untouched. A Dynamic or Static layer is a value-map, which stores lightness only and is colorized at generation time — so foreign art has to be collapsed to one channel first, and whatever color it had is gone.

It lives in Core because two screens now do it: the editor replaces one variant's raster from a file, and importing a picture as a whole new layer builds the first one. Two copies of "what happens to a color image on a value-map layer" is how the same PNG comes to import differently depending on which button was pressed.

Methods

HasColor(Image<Rgba32>)

public static bool HasColor(Image<Rgba32> image);

Whether any pixel carries color — channels that are not all equal.

Parameters

  • image (Image<Rgba32>) - The picture to examine.

Returns. True when at least one visible pixel is not gray.

Remarks

What a value-map import WARNS about: the conversion is lossy exactly when this is true, and silently lossless when it is not. A fully transparent pixel cannot show color, so it is skipped — otherwise a stray colored pixel under zero alpha would warn about art that looks identical before and after.

Load(string, bool, PictureProfile)

public static Image<Rgba32> Load(string path, bool convertToSrgb, out PictureProfile profile);

Reads a picture for import: decodes it, reads its embedded color profile with nfty's own reader, and converts it to sRGB when asked and possible.

Parameters

  • path (string) - The PNG or JPEG.
  • convertToSrgb (bool) - Convert a non-sRGB profile's pixels to sRGB.
  • profile (PictureProfile) - What the picture's profile was.

Returns. The decoded picture, converted when convertToSrgb and the profile allow; the caller owns it.

Exceptions

  • PictureUnreadableException - The file is missing, locked, not a PNG/JPEG, or damaged — with a sentence in the product's words.

Remarks

The one load every picture import shares (the CLI's add variant and new ingredient, the editor's variant import); the Import image form holds both forms for its live preview and calls PictureProfile.ConvertToSrgb() itself.

ToValueMap(Image<Rgba32>)

public static ValueMap ToValueMap(Image<Rgba32> image);

The value-map a picture becomes on a Dynamic or Static layer.

Parameters

  • image (Image<Rgba32>) - The source picture. It is NOT modified.

Returns. Its lightness, as a value-map.

Remarks

Desaturated FIRST, rather than handing the color image straight to ValueMap.FromImage(). That reads the RED channel — exact and lossless for its real job, round-tripping a layer's own already-grayscale PNG, and arbitrary for foreign art: pure green would import as pure BLACK and pure red as pure WHITE, though both read as mid-bright to the eye. Grayscale() is ITU-R BT.709 luminance, so R==G==B afterwards and FromImage's own contract is left exactly as it was. Alpha is untouched either way.

Unreadable(string, Exception)

public static string? Unreadable(string leaf, Exception ex);

The product's sentence for a picture that could not be read, or null for an exception that is not about the file (a bug, which should surface as itself).

Parameters

  • leaf (string) - The file's name, as the sentence prints it.
  • ex (Exception) - What reading it threw.

Returns. The sentence, or null.

Remarks

No exception's own message reaches a screen: a decoder's or the OS's wording names internals at someone who only chose the wrong file. Every sentence says what to do next.