SharpAstro.Codecs.Abstractions
3.32.1561
dotnet add package SharpAstro.Codecs.Abstractions --version 3.32.1561
NuGet\Install-Package SharpAstro.Codecs.Abstractions -Version 3.32.1561
<PackageReference Include="SharpAstro.Codecs.Abstractions" Version="3.32.1561" />
<PackageVersion Include="SharpAstro.Codecs.Abstractions" Version="3.32.1561" />
<PackageReference Include="SharpAstro.Codecs.Abstractions" />
paket add SharpAstro.Codecs.Abstractions --version 3.32.1561
#r "nuget: SharpAstro.Codecs.Abstractions, 3.32.1561"
#:package SharpAstro.Codecs.Abstractions@3.32.1561
#addin nuget:?package=SharpAstro.Codecs.Abstractions&version=3.32.1561
#tool nuget:?package=SharpAstro.Codecs.Abstractions&version=3.32.1561
SharpAstro Codecs
A family of pure-managed, AOT-compatible image-codec packages for .NET 10 — no native binaries.
Each format ships as an independent NuGet, and SharpAstro.Codecs is a thin facade that sniffs a
byte stream by its magic bytes and dispatches to the right decoder, so a consumer can reference one
package instead of cherry-picking codecs.
| Format | Decode | Encode | Notes |
|---|---|---|---|
| PNG | ✅ | ✅ | 8/16-bit RGBA/Gray, ICC + HDR chunks (cICP / mDCv / cLLI) |
| JPEG | ✅ | ✅ | baseline + progressive; scaled 1/2–1/8 LOD decode; baseline encode. Plus lossless JPEG (T.81 Annex H) as a separate decoder |
| Ultra HDR | ✅ | ✅ | gain-map JPEG; decodes transparently through the facade — float path is HDR, 8-bit path the SDR base |
| TIFF | ✅ | ✅ | multi-page, 8/16/32-bit uint + float, Deflate/Zlib/LZW, Predictor 2 |
| JPEG XR | ✅ | ✅ | jxrlib-exact — codestream byte-identical to the reference encoder |
| OpenEXR | ✅ | ✅ | scanline, HALF/FLOAT/UINT, NONE/RLE/ZIP/ZIPS/PIZ |
| Radiance RGBE | ✅ | ✅ | .hdr / .pic to scene-linear float RGB; RGBE and XYZE, new/old RLE, EXPOSURE reported; value-exact vs Magick.NET both ways |
| JPEG XL | ✅ | ✅ | clean-room; lossless Modular + lossy VarDCT |
| JBIG2 | ✅ | — | bilevel, for PDF's /JBIG2Decode. Every region type T.88 defines, on the arithmetic path |
| PNM / PAM | ✅ | ✅ | Netpbm P1–P7 read; writes P5/P6 and P7 (grey, RGB, ± alpha) at 8 and 16 bit |
| WebP | ✅ | — | VP8 lossy, VP8L lossless, ALPH, animation + seek, ICC/EXIF/XMP metadata |
| BMP | ✅ | ✅ | Windows + OS/2 DIB, 1–32 bpp, RLE4/RLE8, bit-field masks, V5 ICC; writes 24-bit BGR and 32-bit BGRA with alpha |
| GIF | ✅ (stills + animation frames) | — | GIF87a/GIF89a, global/local palettes, interlace, transparency, disposal; composited full-canvas frames; LZW shared with TIFF |
| TGA | ✅ | ✅ | types 1/2/3 + RLE 9/10/11, 8–32-bit; writes 24/32-bit raw or RLE. The facade recognises it only by the TGA 2.0 footer (TRUEVISION-XFILE.): TGA has no magic number, so footerless files decode via SharpAstro.Tga.TgaReader directly |
| EXIF | ✅ | — | metadata only, from JPEG / TIFF / PNG |
See CODECS.md for the full per-package matrix, what each codec does and does not
support, and how to pick the right one. A bundled sRGB ICC profile ships in
SharpAstro.Color.Icc for embedding.
The facade decodes WebP still images and frame 0 of animated WebP. Use
SharpAstro.Webp.WebpDecoder.DecodeAnimation or WebpAnimationDecoder to access animation frames
and seek through the timeline.
Likewise the facade returns frame 0 of a GIF. SharpAstro.Gif.GifDecoder.DecodeAnimation returns every
frame as a full-canvas RGBA8 copy (disposal applied, raw 1/100 s delays, loop count), and
GifAnimationDecoder streams them through one canvas. GIF is decode-only, by design.
All packages target net10.0, are IsAotCompatible, ship SourceLink debugging, and publish in
lockstep (shared Major.Minor + CI run-number patch).
NuGet
# One facade for sniff-and-decode (PNG, JPEG incl. Ultra HDR, TIFF, JXR, EXR, JXL, WebP, GIF, Radiance .hdr, Netpbm, BMP, TGA with footer, .jb2):
dotnet add package SharpAstro.Codecs
# ...or reference just the format(s) you need:
dotnet add package SharpAstro.Png
dotnet add package SharpAstro.Jxr
dotnet add package SharpAstro.Webp
dotnet add package SharpAstro.Gif
Usage
Decode any supported still image through the facade — sniff the header, size a buffer, decode into it:
using SharpAstro.Codecs;
var bytes = File.ReadAllBytes(path);
if (ImageCodecs.TryReadInfo(bytes, out var info))
{
var rgba = new byte[info.Width * info.Height * 4];
ImageCodecs.TryDecodeIntoRgba8(bytes, rgba); // zero-copy into your buffer
// ...or ImageCodecs.TryDecode(bytes, out IDecodedImage img) for the full-fidelity raster.
}
Each codec is also usable directly — e.g. PngReader / PngWriter, JpegDecoder.Decode / DecodeTo,
TiffReader / TiffWriter, JxrImageCodec, ExrImageCodec, JxlImageCodec. See CODECS.md.
JBIG2 is the one format whose main entry point is not the facade. A PDF-embedded JBIG2 stream has
no file header to sniff, keeps its shared segment dictionaries in a separate /JBIG2Globals stream,
and takes its dimensions from the image dictionary — so those callers pass all three explicitly:
using SharpAstro.Jbig2;
// `embedded` / `globals` are the PDF streams; width/height come from the image dictionary.
var page = Jbig2Decoder.Decode(embedded, globals, width, height);
var bits = page.Bits; // one byte per pixel, 1 = black (T.88 polarity)
var gray = page.ToGray8(); // ...or the 8-bit projection, black 0 / white 255
Standalone .jb2 files do have a signature, and decode through the facade like anything else —
generic, symbol-coded and halftone pages alike.
JBIG2 covers every region type T.88 defines on the arithmetic path: generic regions (both the template coder and MMR / ITU-T T.6, the Group 4 fax coding), refinement regions, symbol dictionaries and text regions, and pattern dictionaries with halftone regions. The Huffman-coded variants (SDHUFF / SBHUFF) are refused rather than guessed at — no available encoder emits them, so an implementation would have nothing to validate itself against.
Building from source
git clone https://github.com/SharpAstro/Codecs
cd Codecs
dotnet build Codecs.JustTests.sln -c Release
dotnet test Codecs.JustTests.sln -c Release
Requires the .NET 10 SDK.
License
Unlicense (public domain).
Credits
This repository began as a fork of StbSharp/StbImageSharp
(Roman Shapiro's C# port of Sean Barrett's stb_image.h, via the
Hebron C-to-C# transpiler). SharpAstro.Jpeg's decoder was
ported from and validated byte-exact against that reference decoder before the stb port itself was
retired from the repo.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages (17)
Showing the top 5 NuGet packages that depend on SharpAstro.Codecs.Abstractions:
| Package | Downloads |
|---|---|
|
SharpAstro.Png
Pure-managed PNG encoder + decoder for .NET. Writer: adaptive per-row filter selection (libpng "minimum sum of absolute values" heuristic), 8/16-bit RGBA/Gray. Reader: chunk parsing with CRC validation, color types 0/2/4/6 at 8/16-bit. Both sides handle iCCP / sRGB / gAMA / cHRM / eXIf metadata plus PNG-3 HDR signaling chunks cICP (Coding-Independent Code Points), mDCv (Mastering Display Color Volume), cLLI (Content Light Level Info) — full HDR10 / HLG round-trip. Also exports PngPredictor as a reusable row-unfilter building block (TIFF Predictor=2 / PDF FlateDecode). AOT-compatible. |
|
|
SharpAstro.Color.Icc
ICC v4 colour-management primitives for .NET image-codec consumers. Bundled sRGB v4 profile (588-byte LittleCMS-generated, ReadOnlyMemory<byte> for embedding in TIFF/PNG/JPEG) plus a WithCicp(...) helper that injects an ICC v4.4 cicp tag carrying H.273 colour-primaries / transfer-function codepoints, so HDR10, HLG, wide-gamut, and linear-scene-light signalling can be added on top of any base profile. The H.273 ColorPrimaries / TransferFunction / MatrixCoefficients enums (shared with SharpAstro.Png's PNG-3 cICP chunk) live in SharpAstro.Codecs.Abstractions as of 3.5. AOT-compatible. |
|
|
SharpAstro.Jpeg
Pure-managed JPEG (ITU-T T.81 / ISO 10918) codec for .NET. Decoder: baseline sequential + progressive DCT, restart intervals, 4:4:4 / 4:2:2 / 4:2:0 / arbitrary chroma subsampling, grayscale, YCbCr, RGB-marked, and Adobe CMYK / YCCK (APP14) streams, plus scaled decode at 1/2, 1/4, 1/8 resolution via reduced inverse DCT — a 33-megapixel source can decode straight to a thumbnail-sized raster without the full-resolution intermediate ever existing. Region and fitted decode (3.25): DecodeRegionTo decodes one rectangle of the output, skipping ahead over restart intervals so a one-third-height region costs a third of a full decode, and DecodeFittedTo box-filters straight to a target size inside the row loop, byte-exact against decode-then-box-filter; both run on a strip pipeline that holds a few MCU rows of samples (the width of the image, not its height) instead of whole component planes. Encoder (3.6): baseline sequential DCT, 4:4:4 / 4:2:0, quality 1..100 — a faithful port of the stb_image_write JPEG writer, byte-for-byte identical to that reference; metadata write (3.22): JpegEncodeOptions.Exif embeds an EXIF blob and JpegEncodeOptions.Xmp an XMP packet (CreatorTool, description, custom-namespace properties) as APP1 segments, built as escaped string templates with no XmlSerializer or DTD, so still AOT-clean. Decode-to-caller-buffer API with ArrayPool-backed internals; JpegSegmentScanner surfaces APPn metadata segments. Full-scale decode is byte-exact against the StbImageSharp (stb_image) reference decoder. AOT-compatible. |
|
|
SharpAstro.Tiff
Pure-managed TIFF reader/writer for .NET. Supports multi-page, 8/16/32-bit uint and IEEE-Float samples, Uncompressed/Deflate/ZlibPkzip/LZW, Predictor 2 (horizontal differencing) on read, contig planar config, SampleFormat/SMin/SMax/ICC round-trip, both II and MM byte order. AOT-compatible. |
|
|
SharpAstro.Jxr
Pure-managed JPEG XR (ITU-T T.832 / ISO/IEC 29199-2) encoder/decoder for .NET. AOT-compatible. The codec core is ported faithfully from Microsoft's jxrlib reference implementation and validated bit-exactly against it (byte-for-byte vs JxrEncApp; round-trips through JxrDecApp and Windows Photo / WIC). Reuses SharpAstro.Tiff for the T.833 .jxr container. Current pipeline: single-tile spatial YUV444 BD8 RGB, lossless and lossy, all three overlap levels. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.32.1561 | 0 | 11/3/2026 |
| 3.32.1541 | 0 | 11/3/2026 |
| 3.31.1511 | 1 | 11/3/2026 |
| 3.30.1461 | 43 | 11/3/2026 |
| 3.29.1431 | 37 | 11/3/2026 |
| 3.29.1401 | 40 | 11/3/2026 |
| 3.29.1361 | 39 | 11/3/2026 |
| 3.28.1341 | 65 | 11/3/2026 |
| 3.27.1311 | 39 | 11/3/2026 |
| 3.26.1281 | 41 | 11/3/2026 |
| 3.25.1261 | 55 | 11/3/2026 |
| 3.24.1241 | 105 | 11/3/2026 |
| 3.24.1231 | 38 | 11/2/2026 |
| 3.24.1221 | 1,563 | 10/27/2026 |
| 3.23.1201 | 3,427 | 10/25/2026 |
| 3.22.1171 | 460 | 10/25/2026 |
| 3.21.1151 | 101 | 10/25/2026 |
| 3.20.1121 | 87 | 10/25/2026 |
| 3.19.1091 | 90 | 10/24/2026 |
| 3.18.1061 | 108 | 10/20/2026 |