Darnelix.Webp
1.2.0
dotnet add package Darnelix.Webp --version 1.2.0
NuGet\Install-Package Darnelix.Webp -Version 1.2.0
<PackageReference Include="Darnelix.Webp" Version="1.2.0" />
<PackageVersion Include="Darnelix.Webp" Version="1.2.0" />
<PackageReference Include="Darnelix.Webp" />
paket add Darnelix.Webp --version 1.2.0
#r "nuget: Darnelix.Webp, 1.2.0"
#:package Darnelix.Webp@1.2.0
#addin nuget:?package=Darnelix.Webp&version=1.2.0
#tool nuget:?package=Darnelix.Webp&version=1.2.0
Darnelix.Webp
A WebP codec written entirely in C#. It decodes and encodes WebP — lossy, lossless, near-lossless, with alpha, still and animated — implemented from the published WebP container, VP8 and VP8L specifications. One managed assembly, no native code, zero runtime dependencies. This package targets .NET 8, .NET 9, .NET 10 and .NET 11.
What ships
- Decode. Still images (lossy VP8 and lossless VP8L, with alpha) into RGBA32, BGRA32, ARGB32, RGB24 or BGR24; cropped and scaled decode; incremental decode from bytes as they arrive; header-only feature reads; animated WebP played frame by frame onto a composited canvas.
- Encode. Still images, lossy (quality, effort, target size or PSNR, alpha quality and compression, sharp YUV, loop-filter settings) or lossless (effort, near-lossless preprocessing; the RGB under transparent pixels is always preserved); animated WebP assembled from full-canvas frames with per-frame durations, a loop count and a background colour.
- Deterministic. The same input and options produce the same bytes — with or without the optional
worker threads (
UseThreadson the decode and encode options, off by default). - Defined failure. A truncated, corrupt or unsupported file raises a
WebpExceptionsubtype (WebpFormatException,WebpDecodeException,WebpUnsupportedFeatureException); a bad argument raises anArgumentException. - SIMD-accelerated DSP kernels on every framework this package carries, each proven bit-identical to the scalar reference implementation they replace.
Two API styles cover the same functionality. The idiomatic API — WebpDecoder, WebpEncoder,
WebpAnimDecoder, WebpAnimEncoder, each with an options type — exposes everything; the static Webp
class mirrors the shape of the reference C API's classic entry points for the common cases (Decode,
EncodeLossy, EncodeLossless, GetFeatures). Container metadata (ICC, EXIF, XMP) and animation
parameters are edited with the companion command-line tool (below).
Quick start
using System;
using System.IO;
using Darnelix.Webp;
using Darnelix.Webp.Animation;
using Darnelix.Webp.Decoding;
using Darnelix.Webp.Encoding;
byte[] file = File.ReadAllBytes("input.webp");
// Header only — no pixels decoded; false (never an exception) when the bytes are not a WebP header.
if (WebpDecoder.TryGetInfo(file, out WebpImageInfo info))
{
Console.WriteLine($"{info.Width}x{info.Height} {info.Format} alpha={info.HasAlpha} animated={info.HasAnimation}");
}
// Decode. The image owns a pooled pixel buffer: dispose it when you are done with the pixels.
using (WebpImage image = WebpDecoder.Decode(file))
{
Span<byte> rgba = image.Pixels; // RGBA32, top-down, 4 bytes per pixel, no row padding
Console.WriteLine($"{image.Width}x{image.Height} {image.Format}, {rgba.Length} bytes");
}
// Encode RGBA32 pixels. The Webp facade applies the recommended defaults (effort 4, loop-filter
// strength 60, lossless alpha at effort 100); EncodeLossy takes the quality.
int width = 64, height = 64;
byte[] pixels = new byte[width * height * 4]; // RGBA32, top-down
byte[] lossless = Webp.EncodeLossless(pixels, width, height);
byte[] lossy = Webp.EncodeLossy(pixels, width, height, 85f);
File.WriteAllBytes("output.webp", lossy);
// For anything else, build the options yourself and set every field you rely on: a new
// WebpEncodeOptions starts at zero throughout, and zero means "off" for the loop filter and the
// alpha effort. Nothing is filled in for you.
var options = new WebpEncodeOptions { Quality = 85, Method = 4, FilterStrength = 60, AlphaQuality = 100, SharpYuv = true };
byte[] tuned = WebpEncoder.Encode(pixels, width, height, PixelFormat.Rgba32, options);
Animated WebP, frame by frame:
using (var animation = new WebpAnimDecoder(file))
{
Console.WriteLine($"{animation.Info.CanvasWidth}x{animation.Info.CanvasHeight}, {animation.Info.FrameCount} frames");
while (animation.TryGetNextFrame(out WebpFrame frame))
{
// frame.Pixels is the full composited canvas (RGBA32); frame.DurationMs is its display time.
}
}
Command-line tool
The same codec drives webpx, packaged separately as Darnelix.Webp.Cli: encode, decode, inspect, edit
container metadata and animation parameters, and build or extract animations from the shell.
dotnet tool install --global Darnelix.Webp.Cli
webpx encode photo.ppm photo.webp -q 90
License
Free of charge under a proprietary licence (not open source); the full terms are in LICENSE, packed with
this package.
Project site: https://www.darnelix.com/products/webp-dotnet/
Support: support@darnelix.com
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. net11.0 is compatible. |
-
net10.0
- No dependencies.
-
net11.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
1.2.0 — adds a .NET 11 build: the package now targets .NET 8, .NET 9, .NET 10 and .NET 11, with SIMD-accelerated DSP kernels on all four. The public API is unchanged from 1.1.0, and the decode and encode paths on .NET 8, 9 and 10 are the ones 1.1.0 shipped. What the package contains: Darnelix.Webp, a WebP codec written entirely in C#: one managed assembly, no native code, zero runtime dependencies. Decode: lossy and lossless still images, with alpha, into RGBA32, BGRA32, ARGB32, RGB24 or BGR24; cropped and scaled decode; incremental decode from bytes as they arrive; header-only feature reads; animated WebP frame by frame onto a composited canvas. Encode: lossy or lossless still images, with alpha, a target size or PSNR, sharp YUV and near-lossless preprocessing; animated WebP from full-canvas frames with per-frame durations, a loop count and a background colour. The same input and options produce the same bytes, with or without the optional worker threads. A truncated, corrupt or unsupported file raises a WebpException subtype. Container metadata and animation parameters are edited with the companion tool, Darnelix.Webp.Cli.