Pure-managed, SIMD-accelerated image codecs for .NET: JPEG, PNG, WebP, TIFF, GIF, JPEG 2000 and JBIG2, plus EXIF and ICC. No native dependencies, NativeAOT-compatible; the JPEG decoder beats libjpeg-turbo on our benchmark corpus.
翻译准备中
正在加载完整 README。
查看完整 README ↗English | 简体中文
Pure-managed image codecs for .NET 10: JPEG, PNG, TIFF, WebP, GIF, BMP, ICO / CUR, QOI, Netpbm, JPEG 2000 and JBIG2, plus EXIF and ICC, and HEIF / HEIC decoding as an opt-in package.
Every tile above was decoded by this library; the files are the LINQPad samples' images (how they were made).
dotnet add package Sdcb.SimdCodecs
using Sdcb.SimdCodecs;
using Sdcb.SimdCodecs.Abstractions;
using Sdcb.SimdCodecs.Jpeg;
byte[] file = File.ReadAllBytes("photo.webp"); // JPEG, PNG, TIFF, WebP, GIF, BMP, ICO, CUR, QOI, Netpbm, JPEG 2000 or JBIG2
// The facade sniffs the format from the magic bytes. One call gives the pixels in the layout you ask for,
// turned upright by the EXIF orientation; it throws NotSupportedException for a format it does not decode
// and InvalidDataException with the codec's reason for a damaged file.
using PixelBuffer image = ImageCodecs.Decode(file, PixelFormat.Rgba32, new DecodeOptions { ApplyOrientation = true });
// Encode it as a JPEG: SIMD, baseline / optimised Huffman / progressive, 4:2:0 or 4:4:4.
// Passing image.Metadata keeps the ICC profile and Exif (its Orientation is already reset to 1).
using FileStream output = File.Create("photo.jpg");
ImageCodecs.Encode(image.Pixels, image.Width, image.Height, image.Format, ImageFormat.Jpeg, output,
stride: image.Stride, options: new JpegEncodeOptions { Quality = 90 }, metadata: image.Metadata);
Common tasks:
// A server checks the header before it allocates anything.
if (!ImageCodecs.TryReadInfo(file, out ImageInfo info) || (long)info.Width * info.Height > 50_000_000)
return Results.BadRequest();
// Decode into memory you own (a bitmap, a Mat, an upload buffer) in any layout, at any row stride.
// See the skiasharp and opencvsharp samples for an SKBitmap and a Mat.
ImageCodecs.TryDecodeInto(file, buffer, stride, PixelFormat.Bgra32Premultiplied);
// A thumbnail: JPEG scales by 1/2-1/8 in the DCT domain, every other format by a box filter.
using IDecodedImage small = ImageCodecs.Decode(file, new DecodeOptions { ScaleDenominator = 8 });
// HEIF / HEIC (iPhone photos): install Sdcb.SimdCodecs.Heif and register it once at start-up.
ImageCodecs.Register(HeifImageDecoder.Registration);
以上为 README 的开头部分。其余内容请阅读原文。 查看完整 README ↗