Lettori PNG, GIF e BMP e scrittore PNG di casa (C1, passo 2)
Prima parte dei codec d'immagine scritti in casa per togliere SkiaSharp (decisione di Alberto del 18 novembre 2026: niente componenti esterni). In Febe.Core/Codecs/Images: la base comune (RgbaImage RGBA a 8 bit non premoltiplicata, anche dal pool; ImageLimits controllati prima di ogni allocazione; ImageDecodeException e sottotipi per limiti e formati non letti; riconoscimento del formato dai primi byte; facciata ImageDecoder), il lettore PNG (tutti i tipi di colore e le profondità, tavolozza e tRNS, Adam7, i cinque filtri, CRC di ogni blocco, metadati eXIf, iCCP, tEXt, zTXt, iTXt e XMP, numero dei fotogrammi APNG), lo scrittore PNG (RGB/RGBA a 8 bit, filtro adattivo per riga, eXIf, iCCP, XMP), il lettore GIF (LZW, primo fotogramma, trasparenza, interlacciamento, tavolozze, numero dei fotogrammi) e il lettore BMP (1-32 bit, BI_RGB, BITFIELDS, RLE8, RLE4, PNG dentro, dal basso e dall'alto). CRC-32 e LZW sono nostri, zlib è quello della BCL. Le prove leggono i 37 riferimenti PNG, GIF e BMP e li trovano uguali byte per byte alle immagini attese, lette a loro volta con il nostro lettore PNG verificato contro un lettore minimo indipendente; poi andate e ritorno dello scrittore, metadati, file danneggiati e tagliati, limiti, e modifiche casuali a seme fisso che devono dare un'immagine o un'ImageDecodeException e nient'altro. Una riga in decisioni.md dice le scelte di lettura. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e4608c62d
commit
8bf76f18ff
23 files changed
+4382
-4
No files matched your search
@@ -0,0 +1,39 @@
|
||||
namespace Febe.Core.Codecs.Images;
|
||||
|
||||
/// <summary>A text an image carries (PNG tEXt, zTXt, iTXt; GIF comment).</summary>
|
||||
/// <param name="Keyword">The keyword («Title», «Comment», «XML:com.adobe.xmp»...); empty for a GIF 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 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), 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>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);
|
||||
Reference in new issue
Block a user