Correggo i difetti confermati dalla revisione di funzione/codec-immagini e aggiungo le prove che li avrebbero trovati. - JPEG: una tabella di Huffman con troppi codici corti dava ArgumentOutOfRangeException invece di ImageDecodeException, e un file rovinato faceva fallire importazione e ricostruzione; ora il controllo si fa prima di scrivere le voci. La prova che diceva di coprirlo cadeva invece su «tabella troncata»: ora tiene il totale giusto e controlla il messaggio. - JPEG: il troncamento delle scansioni di Huffman si vede a ogni riga di MCU, non dopo l'ultimo MCU (un file tagliato dopo le intestazioni costava 6,7 s). - JPEG: IDCT ridotta a 1/2 e 1/4 calcolata dai coefficienti; miniatura di una foto 4000x3000 da 126 a 59 ms in Release. Il predittore senza perdita non cerca più l'indice della componente a ogni campione. - WebP: con livello del filtro del fotogramma 0 il filtro è spento, come nei decodificatori di riferimento; VP8L costruisce solo i gruppi nominati dai meta codici (prima fino a 335 MB di tabelle da 160 KB di file). - BMP OS/2: altezza senza segno e sempre dal basso. - Array di lavoro dei codec oltre 16 MiB fuori dal pool condiviso, che li avrebbe tenuti dopo l'uso. - Conversione: profilo ICC copiato solo se RGB, profondità oltre 8 bit e blocchi gAMA/cHRM/sRGB dichiarati in NotCarried, Lossy vero quando si perde precisione. - Impronta e misure di una foto da una sola lettura e decodifica; ReadSize legge solo l'inizio di JPEG, GIF e BMP. - docs: decisioni (righe aggiunte, con la correzione dei 2,0 MB del set di riferimento) e windows.md (Febe.exe rimisurato: 85,6 MB, a capo sistemato). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
3.2 KiB
C#
59 lines
3.2 KiB
C#
namespace Febe.Core.Codecs.Images;
|
|
|
|
/// <summary>A text an image carries (PNG tEXt, zTXt, iTXt; GIF comment; JPEG COM).</summary>
|
|
/// <param name="Keyword">The keyword («Title», «Comment», «XML:com.adobe.xmp»...); empty for a GIF or JPEG comment.</param>
|
|
/// <param name="Text">The text.</param>
|
|
/// <param name="Language">The language tag of an iTXt chunk, empty otherwise.</param>
|
|
/// <param name="TranslatedKeyword">The translated keyword of an iTXt chunk, empty otherwise.</param>
|
|
public sealed record ImageText(string Keyword, string Text, string Language = "", string TranslatedKeyword = "");
|
|
|
|
/// <summary>Metadata read from an image file, without interpreting it.</summary>
|
|
public sealed class ImageMetadata
|
|
{
|
|
/// <summary>No metadata.</summary>
|
|
public static ImageMetadata Empty { get; } = new();
|
|
|
|
/// <summary>The EXIF block as a TIFF structure (starts with «II*\0» or «MM\0*»), or null.</summary>
|
|
public byte[]? Exif { get; init; }
|
|
|
|
/// <summary>
|
|
/// The EXIF orientation, 1-8 (T.81 has none of its own: it is the Orientation tag of <see cref="Exif"/>); 1 when the
|
|
/// image has no EXIF block, no such tag or an invalid value. The decoders never apply it to the pixels.
|
|
/// </summary>
|
|
public int Orientation { get; init; } = 1;
|
|
|
|
/// <summary>The ICC colour profile, decompressed, or null.</summary>
|
|
public byte[]? IccProfile { get; init; }
|
|
|
|
/// <summary>The name of the ICC profile as the file gives it, or null.</summary>
|
|
public string? IccProfileName { get; init; }
|
|
|
|
/// <summary>The XMP packet (from the iTXt chunk «XML:com.adobe.xmp» of a PNG, the APP1 segment of a JPEG), or null.</summary>
|
|
public string? Xmp { get; init; }
|
|
|
|
/// <summary>The texts, in file order (the XMP packet is in <see cref="Xmp"/>, not here).</summary>
|
|
public IReadOnlyList<ImageText> Texts { get; init; } = [];
|
|
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public IReadOnlyList<string> ColorChunks { get; init; } = [];
|
|
}
|
|
|
|
/// <summary>What a file says about its image, read without decoding the pixels.</summary>
|
|
/// <param name="Format">The format.</param>
|
|
/// <param name="Width">Width in pixels, as stored (no EXIF orientation applied).</param>
|
|
/// <param name="Height">Height in pixels, as stored.</param>
|
|
/// <param name="FrameCount">Frames of an animation (GIF images, APNG frames); 1 for a still image.</param>
|
|
/// <param name="HasAlpha">Whether the format of the pixels can carry transparency (not whether any pixel is transparent).</param>
|
|
/// <param name="Metadata">The metadata.</param>
|
|
public sealed record ImageInfo(ImageFormat Format, int Width, int Height, int FrameCount, bool HasAlpha, ImageMetadata Metadata)
|
|
{
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public int BitsPerSample { get; init; } = 8;
|
|
}
|