Skip to content

TDD: pure C# PNG/JPEG/BMP and full-frame animated GIF/APNG codecs with coverage gates - #31

Open
mikasoukhov wants to merge 85 commits into
masterfrom
feature/drawing-image-utilities
Open

mikasoukhov wants to merge 85 commits into
masterfrom
feature/drawing-image-utilities

Conversation

@mikasoukhov

@mikasoukhov mikasoukhov commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Pure-managed PNG/JPEG/BMP/GIF/APNG with end-to-end animated frame preservation

No GDI+, SkiaSharp, ImageSharp, P/Invoke or OS-native image codecs. Cross-platform .NET 6 / .NET 10 (Windows, Linux, macOS).

Public functionality

  • GetImageSize: PNG/APNG, JPEG, BMP and GIF dimensions.
  • ResizeImage: preserve source container and aspect ratio. PNG → PNG, JPEG → JPEG, BMP → BMP (portable top-down BGRA32 V4), GIF → animated GIF and APNG → animated APNG. Every frame is resized, retaining delays and looping; no upscaling.
  • ConvertToPng: all still formats → RGBA8 PNG; GIF → animated PNG (APNG) with every displayed frame and its delay/loop count. APNG → validated unchanged APNG.
  • AddTextWatermark: render on every GIF/APNG frame, returning GIF/APNG respectively; BMP → BMP; PNG/JPEG → PNG. Original image data never mutated; managed TrueType/Verdana fallback.
  • GetGifFrames, GetGifLoopCount, GetAnimationFrames, GetAnimationLoopCount: access full-canvas RGBA8 frames and timing, including APNG.

Image formats implemented

  • PNG: all 15 legal color type/depth pairs, 5 filters, alpha, palette, Adam7; APNG decoder supports frame rectangles, source/over blending and three disposal modes.
  • JPEG: baseline + progressive 8-bit, grayscale, YCbCr, Adobe CMYK/YCCK, restart markers; managed baseline JPEG output.
  • BMP: palette 1/4/8-bit; 16/24/32-bit; RGB555/RGB565/custom bitfields; top-down/bottom-up; Windows/OS2 headers; RLE4/RLE8; encoder retains alpha using BGRA32.
  • GIF87a/GIF89a: every frame, global/local palettes, LZW, interlace, GCE transparency, disposal methods 0–3, per-frame timings, Netscape loop extension; managed GIF encoder outputs full-canvas independently composited frames.

Test-first evidence

  • Previous original image utility RED→GREEN: RED → GREEN.
  • BMP/GIF regression tests were committed before implementation in BmpGifTddTests.cs; BMP/GIF code then added in BmpCodec.cs, GifCodec.cs, ApngEncoder.cs and ApngDecoder.cs.
  • New tests build on independent Pillow-created BMP and four-frame GIF fixtures (including disposal 2/3, differing delays and NETSCAPE looping). Additional programmatically generated BMP RLE4/RLE8/indexed/masks/OS2 and GIF interlace/local palette/LZW fixtures. APNG tests independently decompress each frame's IDAT/fdAT and verify pixel colors, ordered frame controls, alpha blend/disposal, and corrupt chunk rejection.
  • 101 Drawing tests including 91 dedicated image tests; PNG/JPEG original fixtures and TrueType fuzz tests remain. Tests check corrupted/truncated files and exact RGBA pixel buffers.
  • Drawing coverage collects Cobertura with Coverlet and requires >=90% lines and >=85% branches; most recent expanded measurements: 91.8% line / 86.1% branch (green run 38050821446). Both BMP and GIF codecs are included.
  • Full test suite across Windows/Linux/macOS on .NET 6 and .NET 10, plus DB/Azurite integrations, must pass before merge.

Known format limitations

GIF has palette/binary-transparency limitations by specification: output preserves exact RGB for up to 255 opaque distinct colors/frame; otherwise uses palette quantization. Alpha under 128 becomes transparent. GIF encoder favors deterministic validity over maximum compression.

Unsupported specialized BMP embedded JPEG/PNG, GIF plain-text overlay rendering, arithmetic/lossless/12-bit JPEG and unrelated WebP/TIFF/HEIC/AVIF/SVG formats. No bundled licensed fonts. Native code packages are not introduced. Input/frame limits guard memory usage.

PR is ready for review; do not merge to master until review.

@mikasoukhov mikasoukhov changed the title Add cross-platform image helpers to Ecng.Drawing Implement dependency-free managed PNG/JPEG and TrueType image utilities Oct 10, 2026
@mikasoukhov mikasoukhov changed the title TDD: dependency-free managed PNG/JPEG codecs, format-preserving resize and TrueType watermark TDD: pure C# PNG/JPEG/TrueType image utilities with regression-gated coverage Oct 10, 2026
…atermark, GIF frame access and APNG conversion
@mikasoukhov mikasoukhov changed the title TDD: pure C# PNG/JPEG/TrueType image utilities with regression-gated coverage TDD: pure C# PNG/JPEG/BMP and full-frame animated GIF/APNG codecs with coverage gates Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant