namespace Febe.Core.Codecs.Images;
/// A text an image carries (PNG tEXt, zTXt, iTXt; GIF comment; JPEG COM).
/// The keyword («Title», «Comment», «XML:com.adobe.xmp»...); empty for a GIF or JPEG comment.
/// The text.
/// The language tag of an iTXt chunk, empty otherwise.
/// The translated keyword of an iTXt chunk, empty otherwise.
public sealed record ImageText(string Keyword, string Text, string Language = "", string TranslatedKeyword = "");
/// Metadata read from an image file, without interpreting it.
public sealed class ImageMetadata
{
/// No metadata.
public static ImageMetadata Empty { get; } = new();
/// The EXIF block as a TIFF structure (starts with «II*\0» or «MM\0*»), or null.
public byte[]? Exif { get; init; }
///
/// The EXIF orientation, 1-8 (T.81 has none of its own: it is the Orientation tag of ); 1 when the
/// image has no EXIF block, no such tag or an invalid value. The decoders never apply it to the pixels.
///
public int Orientation { get; init; } = 1;
/// The ICC colour profile, decompressed, or null.
public byte[]? IccProfile { get; init; }
/// The name of the ICC profile as the file gives it, or null.
public string? IccProfileName { get; init; }
/// The XMP packet (from the iTXt chunk «XML:com.adobe.xmp» of a PNG, the APP1 segment of a JPEG), or null.
public string? Xmp { get; init; }
/// The texts, in file order (the XMP packet is in , not here).
public IReadOnlyList Texts { get; init; } = [];
///
/// The PNG chunks that describe the colour of the pixels (gAMA, cHRM, sRGB) the file has, in file order. They are
/// not applied to the pixels and no encoder writes them, so a conversion says they are left behind.
///
public IReadOnlyList ColorChunks { get; init; } = [];
///
/// Blocks of the file that hold data no reader of Febe interprets and no encoder writes, in file order and once
/// each: JPEG segments («APP13» for IPTC/Photoshop, «ExtendedXmp», «APP2» for MPF, other «APPn»), PNG ancillary
/// chunks («pHYs», «tIME»...), WebP chunks. A conversion reports them as not kept.
///
public IReadOnlyList Unread { get; init; } = [];
}
/// What a file says about its image, read without decoding the pixels.
/// The format.
/// Width in pixels, as stored (no EXIF orientation applied).
/// Height in pixels, as stored.
/// Frames of an animation (GIF images, APNG frames); 1 for a still image.
/// Whether the format of the pixels can carry transparency (not whether any pixel is transparent).
/// The metadata.
public sealed record ImageInfo(ImageFormat Format, int Width, int Height, int FrameCount, bool HasAlpha, ImageMetadata Metadata)
{
///
/// Bits of one sample as the file stores them (PNG bit depth, JPEG precision, BMP mask width; 8 for palettes and
/// for GIF and WebP). The decoders give 8-bit samples, so above 8 the decoded pixels have lost precision.
///
public int BitsPerSample { get; init; } = 8;
///
/// Whether the file is an animation, by the presence of its marks (spec §4.10): a PNG with an acTL chunk
/// before its image data, a WebP with an ANIM or ANMF chunk, a GIF with more than one image.
///
public bool IsAnimated { get; init; }
/// Whether the pixels are stored as CMYK or YCCK (a JPEG with four components).
public bool IsCmyk { get; init; }
///
/// The working memory a full decode asks besides the decoded image, as the decoder checks it against
/// (a progressive or lossless JPEG keeps its coefficients or samples:
/// up to 9 bytes a pixel); 0 when the format's decoder needs none worth counting before it starts.
///
public long DecodeWorkingBytes { get; init; }
}