README
¶
manael.org/x/image
Pure Go image codecs for WebP, AVIF, animated PNG, HDR PNG and Ultra HDR JPEG, written from the format specifications.
Status: the
webppackage decodes and encodes still and animated WebP images, theapngpackage decodes and encodes animated PNG images, thehdrpngpackage decodes and encodes PNG images with HDR colour signalling, and theultrahdrpackage decodes and encodes Ultra HDR JPEG images. Theavifpackage exports no identifiers yet, and nothing marked "Planned" below is available until a release says so.
Packages
| Package | Format | Specification |
|---|---|---|
manael.org/x/image/webp |
WebP | RFC 9649 |
manael.org/x/image/avif |
AVIF | AV1 Image File Format, AV1 Bitstream, ITU-T H.273 |
manael.org/x/image/apng |
APNG | PNG Specification (Third Edition) |
manael.org/x/image/hdrpng |
HDR PNG | PNG Specification (Third Edition), ITU-T H.273, ITU-R BT.2100 |
manael.org/x/image/ultrahdr |
Ultra HDR JPEG | Ultra HDR Image Format v1.1, ITU-T T.81 |
All live in a single module, manael.org/x/image, and are versioned together. Code shared between them, or too specific to export, goes under internal/.
Design principles
- Specification first. Each codec is developed from its specification. Existing codecs may be consulted to understand behaviour or to cross-check output, but are not translated wholesale; see CONTRIBUTING.md. JPEG XL, which is being written under
internal/and has no package yet, is the exception: the licence terms of its specification, ISO/IEC 18181, forbid using it with AI models, so it is written from an article describing the format and from libjxl, and checked against libjxl and its conformance suite rather than against the specification. HDR gain maps, which theultrahdrpackage applies and generates, are an exception for the same reason: ISO's licence terms forbid using ISO 21496-1 with AI models, so they are written from the Ultra HDR Image Format and from libultrahdr, and checked against libultrahdr rather than against ISO 21496-1. - Portable Go. Production code builds with
CGO_ENABLED=0on every platform Go supports: no cgo, WASM runtimes, external executables, handwritten assembly, or experimental SIMD packages. Dependencies are limited to the standard library and maintainedgolang.org/xpackages. - Untrusted input. Decoders are written to be fed arbitrary bytes. Malformed input returns an error; it does not panic, loop, or allocate without bound.
Initial scope
The first releases cover still images, animated WebP, animated PNG, the decoding and encoding of PNG images with HDR colour signalling, and the decoding and encoding of Ultra HDR JPEG.
WebP
| Feature | Decode | Encode |
|---|---|---|
Lossy (VP8 ) |
Supported | Supported |
Lossless (VP8L) |
Supported | Supported |
Alpha (ALPH with lossy, VP8L alpha) |
Supported | Supported |
Extended format header (VP8X) |
Supported | Supported |
Animation (ANIM, ANMF) |
Supported | Supported |
Metadata (ICCP, EXIF, XMP ) |
Skipped | Not written |
The decoder and the encoder are written from the specifications, for the container and for the VP8 and VP8L bitstreams and the ALPH data alike; each frame of an animation is decoded as a still image would be. golang.org/x/image/webp serves only as an independent control in the interoperability tests and benchmarks.
Compression
The WebP encoders were measured against cwebp from libwebp 1.6.0, the pinned reference, on 29 November 2026, over the 14 images of the benchmark corpus in internal/imagetest: one photograph of 750 × 562 pixels and 13 generated images of at most 256 × 192. Each figure is that of webp.Encode divided by that of cwebp, so 1.10 means 10% larger or slower.
Relative to cwebp |
Lossy | Lossless |
|---|---|---|
| Size, geometric mean of the corpus | 0.93 | 1.01 |
| Size, photograph | 1.01 | 1.02 |
| Encode time, total of the corpus | 3.0 | 1.4 |
| Encode time, photograph | 3.6 | 1.2 |
| Peak memory, photograph | 1.9 | 0.77 |
- Size comes from
BenchmarkWebPSize, as CONTRIBUTING.md describes. Lossy files are compared at equal SSIM, over the range of SSIM that both encoders reach asQualityand-qrun from 5 to 100, againstcwebpat its default settings; lossless files are compared withcwebp -lossless -exact. The lossy lead comes mostly from the generated gradients and illustrations, which are up to 21% smaller; on the four photographs, the real one and three generated, the two encoders are within 2.5% of each other. Lossless files range from 33% smaller, for a radial gradient, to 20% larger, for an illustration. SSIM is the only measure of quality taken, so the ratio at equal PSNR or by a perceptual metric is not known.cwebpmakes smaller files at its slower settings:-lossless -exact -z 9is a further 4.9% smaller over the corpus, sowebp.Encodeis 6% larger than that, and the lossy-m 6was not measured. - Encode time is the median of six runs of
BenchmarkWebPEncodeforwebp.Encode, and forcwebpthe encoding time thatcwebp -vreports to the millisecond, which leaves out starting the process and reading the PNG. Lossy figures are at quality 75; over the corpus, quality 50 takes 3.0 times as long and quality 90 3.4 times. Both encoders run on a single core of an Intel Core Ultra 5 125H,cwebpwithout-mt. Losslessly, the small generated images take several times as long as withcwebp, because the search for transforms, a palette and prefix code tiles costs about the same whatever the image holds. - Peak memory is the peak resident set size of a process that reads the PNG and encodes it once, measured outside the benchmarks: 8.6 MiB against 4.6 MiB lossy, and 20.8 MiB against 27.0 MiB lossless. For the smaller images both processes stay within a few MiB of an empty one, which this measure cannot separate from the encoding.
BenchmarkWebPEncodereports the bytes allocated per encode instead, 3.1 MiB lossy and 31 MiB lossless for the photograph, which is the figure a change to an encoder reports.
The gap that remains, and the time the encoders take, follow from choices the project makes on purpose:
- Encoder-side methods claimed by patents in force are left out. The WebM bitstream licence covers only what the specifications require, so the encoders keep clear of the claimed ways of making the choices the specifications leave to an encoder, as PATENTS.md records with the claims. The VP8L encoder finds its backward references in a single greedy pass, compared by match length, and never selects them again from a model of the references it found or by a cost of their distance (US 8,175,403 and US 8,160,372, expected to expire in 2031 and 2030). It chooses each predictor block's mode without weighing the modes of the blocks around it, fits the color transform without an estimate of entropy, and gives prefix code groups to fixed tiles rather than to clusters of blocks with similar statistics (the family of US 8,615,138, expected to expire in 2031 in the US and 2032 in China).
- The VP8 encoder uses one quantizer and one loop filter level for the whole frame.
cwebpdivides a frame into four segments by default, each with its own quantizer and filter level, ascwebp -vreports. Segmentation and per-macroblock loop filter adjustment are the features that US 9,924,161 and US 8,897,591 are named after, so adding either first repeats the check of PATENTS.md against their claims. Rate control, which would aim at a file size, is not implemented either. - Maintainability and compression ratio come before peak speed. Each choice is a plain search whose cost the code states: every macroblock is coded with each 16 × 16 luma mode and with
B_PRED, and with each chroma mode, and keeps the cheapest; each block's levels are chosen on its own, with the specification's default probabilities, rather than by a trellis over the token contexts; the VP8L transforms and block sizes are chosen by an estimate of entropy, and the prefix code tiles by the exact size of the result. The search costs time, lossy encoding taking about three times as long as withcwebp, andOptionsoffers no setting that trades size for speed. - No handwritten assembly or experimental SIMD. The encoders are portable Go, as the design principles require, whereas libwebp has SSE2, SSE4.1 and NEON versions of its inner loops. Part of the difference in time is that, and it is not meant to be closed.
The encoders also run in one goroutine, as cwebp runs on one thread without -mt. That is not a choice: the design principles allow goroutines, and the AV1 encoder searches in several, but the WebP encoders have not been made to.
AVIF
The decoder is an AV1 Main profile decoder, because the AOMedia Patent License covers only a decoder that conforms to every non-optional part of the AV1 specification; see PATENTS.md. Decode is not exposed until it conforms.
| Feature | Decode | Encode |
|---|---|---|
| AV1 Main profile: 8-bit and 10-bit, 4:2:0 and monochrome | Planned | 8-bit 4:2:0 |
| Film grain synthesis | Planned | Not in scope |
| Alpha auxiliary image | Planned | Planned |
| AV1 High profile (4:4:4), Professional profile (12-bit) | Later | Not in scope |
Grid (grid) derived images |
Later | Not in scope |
Image sequences (avis) |
Not in scope | Not in scope |
| Metadata (ICC, Exif, XMP) | Skipped | Not written |
Compression
The AV1 encoder that avif.Encode will expose was measured against avifenc from libavif 1.4.2 with libaom, the pinned reference, on 29 November 2026, and its encode time again on 30 November 2026, over the 10 opaque images of the benchmark corpus in internal/imagetest: one photograph of 750 × 562 pixels and 9 generated images of at most 256 × 192. Until avif.Encode exists, the measured encoder is av1.Encode, given the image converted to 4:2:0 and its output wrapped in a file by the tests. avifenc runs at its default speed, -s 6, and writes 4:2:0 with -y 420, since 4:2:0 is all the encoder codes. Each figure is that of av1.Encode divided by that of avifenc, so 1.10 means 10% larger or slower.
Relative to avifenc |
Lossy |
|---|---|
| Size, geometric mean of the corpus | 1.01 |
| Size, photograph | 0.97 |
| Encode time, total of the corpus, one thread | 4.6 |
| Encode time, photograph, one thread | 3.7 |
| Encode time, total of the corpus, 18 threads | 4.0 |
| Encode time, photograph, 18 threads | 3.3 |
- Size comes from
BenchmarkAVIFSize, as CONTRIBUTING.md describes: the files are compared at equal SSIM, over the range of SSIM that both encoders reach asQualityand-qrun from 5 to 100. On the four photographs, the real one and three generated, the encoder is 2% to 6% smaller; the two illustrations are 11% and 22% larger, and the gradients range from 14% smaller to 18% larger. The images with alpha are left out, since the encoder codes no alpha yet. SSIM is the only measure of quality taken, and it is computed on luma, so the ratio at equal PSNR, or with the chroma weighed, is not known; neither is the ratio againstavifenc's slower speeds. - Encode time is the median of six runs of
BenchmarkAVIFEncodeat quality 75 on an Intel Core Ultra 5 125H, which has 14 cores and 18 threads: once with both encoders on one thread,GOMAXPROCS=1andavifenc -j 1, and once with both on all 18,av1.Encodesearching in up to 18 goroutines andavifencwith-j 18. The time ofavifencis that of its whole process, including starting it and reading the PNG, so the ratios understate the difference, most for the small generated images. Over the corpus, quality 50 takes 5.5 times as long asavifencon one thread and 4.4 times on 18, and quality 90 4.0 and 3.8 times. The encoder searches the rows of 64 × 64 superblocks in a wavefront, each row two superblocks behind the one above, so it runs in no more goroutines than the image has rows of superblocks, or half as many as it has columns: on 18 threads it encodes the photograph, in six, 2.8 times as fast as on one, and the generated images of 256 × 192, in two, 1.4 times as fast, while the gradients take one, as on one thread.avifencencodes the photograph 2.5 times as fast on 18 threads as on one. The encoder allocates 4.9 MiB per encode of the photograph on one thread and 15 MiB on 18, about 2 MiB for each goroutine more; the allocations ofavifenc, a separate process, are not measured.
Where the encoder falls behind, and the time it takes, follow from choices the project makes on purpose:
- The in-loop filters and the optional coding tools are off. At its default speed
avifencapplies the deblocking filter and CDEF, which remove the blocking and ringing at the edges that the illustrations are full of, may choose each block's transform size, and enables filter intra, the intra edge filter and the screen content tools, palette among them, as its frame headers show. The encoder uses none of them, nor chroma from luma, the extended partitions or 4 × 4 blocks. Using one is a choice that the specification leaves to the encoder, and how an encoder makes such choices is outside what the AOMedia licence covers, so adding one first records its check in PATENTS.md, as the choices made so far are recorded. - The rate-distortion search has fixed bounds. Each choice is the one that costs least by the squared error plus a multiple of the bits, among a fixed number of candidates: the four partitions of every block from 64 × 64 down to 16 × 16 and three of an 8 × 8 block, the two luma modes and the one chroma mode whose predictions cost least, the angle deltas of one directional mode, and every transform type for the chosen mode only. The work per pixel therefore does not depend on the image, and the documentation of
rdChooserininternal/av1states what each bound saves and costs. The search takes most of the time, andOptionsoffers no setting that trades size for speed. - No handwritten assembly or experimental SIMD. The encoder is portable Go, whereas libaom has SIMD versions of its inner loops. Part of the difference in time is that, and it is not meant to be closed.
APNG
| Feature | Decode | Encode |
|---|---|---|
Every colour type and bit depth, with PLTE, tRNS and Adam7 interlacing |
Supported | Those image/png writes, without interlacing |
Animation (acTL, fcTL, fdAT), default image in or out of it |
Supported | Supported |
Blending (SOURCE, OVER) and disposal (NONE, BACKGROUND, PREVIOUS) |
Supported | Supported, as each frame gives them |
Colour space and metadata (gAMA, cHRM, sRGB, iCCP, cICP, text, eXIf, ...) |
Skipped | Not written |
The decoder reads and checks the chunks itself, from the specification, and decodes the default image and each frame with image/png, from a datastream that carries the frame's size and the IHDR, PLTE and tRNS chunks that every frame inherits, so the zlib decompression, filtering and interlacing are the standard library's. A PNG file without an acTL chunk is read as an animation of one frame. The encoder likewise writes the chunks itself and compresses the default image and each frame with png.Encoder, so the filtering and zlib compression are the standard library's too; it writes indexed colour, greyscale and truecolour, with or without alpha, at the bit depths that png.Encode chooses.
Ultra HDR
| Feature | Decode | Encode |
|---|---|---|
SDR primary image, as image/jpeg decodes it |
Supported | Supported, as image/jpeg encodes it |
| Gain map image, single- and multi-channel, located by GContainer XMP or MPF | Supported | Supported, located by both |
| Gain map generated from SDR and HDR renditions | — | Supported, from linear, PQ or HLG HDR |
| hdrgm XMP metadata, single values and per-channel arrays | Supported | Supported, written with ISO 21496-1 |
| ISO 21496-1 metadata, preferred when both are present | Supported, minimum version 0 | Supported, version 0 |
| HDR rendition for a given display boost | Supported, in linear light | — |
| Colour profile of the primary image | Kept; BT.709, Display P3, BT.2100 named | Written as given; none generated |
| ISO 21496-1 metadata whose base image is the HDR rendition | Unsupported | Not written |
| Gain map applied in the colour space of the alternate rendition | Unsupported unless it is the base image's | Not written |
JPEG encodings that image/jpeg does not read (arithmetic, 12-bit, lossless) |
Unsupported | Not written; baseline, chroma 4:2:0, as image/jpeg |
| EXIF metadata | Skipped | Not written |
The decoder reads and checks the container itself, from the specification and, for what the specification leaves to ISO 21496-1 or to the Multi-Picture Format, from libultrahdr: the JPEG marker segments, the MPF segment, the GContainer directory of the primary image's XMP packet, and the hdrgm XMP and ISO 21496-1 metadata of the gain map image. Both images are decoded by image/jpeg, so the primary image is exactly what jpeg.Decode returns for the file, and the gain map is applied by the formulas of the specification, sampled bilinearly. Its result is checked against ultrahdr_app from libultrahdr, as CONTRIBUTING.md describes; conformance to ISO 21496-1 is not claimed.
The encoder generates the gain map from an SDR and an HDR rendition by the formulas of the specification, with the defaults of its tips: a single-channel gain map of a quarter of the base image's width and height, a gamma of 1.0 and offsets of 1/64. It compresses both images with image/jpeg and writes the container itself: the GContainer directory and an MPF segment that both locate the gain map, and the gain map metadata as hdrgm XMP and as ISO 21496-1, both, as the specification says an encoder should, holding the same values. ultrahdr_app reads the files it writes, and reconstructs from them the HDR rendition that the specification's formula gives, as CONTRIBUTING.md describes. The encoder writes the ICC profile it is given and generates none, so an SDR rendition in Display P3 or BT.2100 primaries needs the caller's profile; the ICC specification is not among the sources yet.
Measured on 29 November 2026 with BenchmarkUltraHDREncode over the 11 opaque images of the benchmark corpus, single-channel gain maps of a quarter size, against ultrahdr_app from libultrahdr 2.0.2 at the same qualities, -q 75 -Q 85: the files are 14% smaller, the HDR rendition reconstructed at full weight is 0.073 stops from the one it was generated from in luminance on average, against 0.079, and generation and encoding take 0.96 times as long over the corpus and 1.3 times on the photograph, ultrahdr_app's time including its process. The two are not compared at equal quality: ultrahdr_app writes the base image of RGBA input with full-resolution chroma, and image/jpeg always subsamples it 4:2:0, so on the colourful illustrations the base image is 7 to 8 dB lower in PSNR. The photograph of 750 × 562 pixels allocates 12 MiB per encode, mostly the linear renditions of 12 bytes per pixel that generation works on.
HDR PNG
| Feature | Decode | Encode |
|---|---|---|
Every colour type and bit depth, as image/png decodes them, with alpha |
Supported | As png.Encode writes them |
cICP, mDCV and cLLI (Section 11.3.2) |
Read and checked, kept as coded | Checked and written as given |
iCCP, sRGB, gAMA and cHRM |
Read and checked, kept as coded; the profile is not applied | Checked and written as given; the profile is not read |
| Linear light from sRGB, PQ or HLG, BT.709, Display P3 or BT.2100 primaries | Supported, full range | Encoded as PQ or HLG with its cICP |
Linear light from an ICC profile, gAMA and cHRM, narrow range, other code points |
Unsupported | — |
| APNG frames | Skipped; the default image is read | Not written |
The decoder reads and checks the chunks itself, from the specification, and decodes the image with image/png, from a datastream of the IHDR, PLTE, tRNS, IDAT and IEND chunks, so the samples are exactly those that png.Decode returns and the zlib decompression, filtering and interlacing are the standard library's. It takes the colour space from the colour chunk of highest precedence (Section 4.3, Table 1), and converts it to linear light with the colour handling of internal/hdrcolor. The encoder writes the colour chunks as they are given between the IHDR chunk and the image data that png.Encoder writes, so a file read is written again with its colour chunks and the compression is the standard library's; it checks them against the rules of PNG Third Edition before writing anything. Both are checked against FFmpeg's png encoder and decoder, and the decoder also against avifdec, as CONTRIBUTING.md describes.
Limitations
DecodeandDecodeConfigreject animated WebP and AVIF image sequences with an unsupported-feature error rather than decode them as their first frame, so callers can tell them apart from a still image. Animated WebP is decoded bywebp.DecodeAllinstead.- A binary that includes the
avifpackage must carry AOM_PATENT_LICENSE in its legal notices, as Section 1.2.1 of that licence requires. - Colour management is limited to what HDR renditions need, described under HDR colour: ICC profiles and colour information boxes are not applied, and decoded pixels are returned in the coded colour space. The
hdrpngpackage returns the colour chunks of a PNG image as they are coded and writes them as they are given, converts sRGB, PQ and HLG samples in the BT.709, Display P3 and BT.2100 primaries to linear light, and encodes linear light as PQ or HLG, but applies no ICC profile. Theultrahdrpackage returns the primary image's ICC profile and the primaries it names, which an HDR rendition shares, and on request converts an HDR rendition between BT.709, Display P3 and BT.2100 primaries, tone-maps it to SDR and encodes it as sRGB, PQ or HLG, but applies no profile. - The WebP encoders' size, speed and memory against
cwebp, and the trade-offs behind them, are described under Compression. The AVIF encoder targets correct, conformant output first; compression efficiency and speed come after.
API conventions
Each package follows image/jpeg and image/png, so that it is a drop-in for code using those packages.
func Decode(r io.Reader) (image.Image, error)
func DecodeConfig(r io.Reader) (image.Config, error)
func Encode(w io.Writer, m image.Image, o *Options) error
Registration
Importing webp or avif registers its format with image.RegisterFormat, so a blank import makes image.Decode understand it. The avif package registers "avif" with its ftyp brand in its own init. The webp package registers "webp" in its own init, so image.Decode reads WebP with webp.Decode, with the checks and errors below.
golang.org/x/image/webp registers the same name and magic, and image.Decode uses the first registered format whose magic matches. A program that links both therefore gets whichever registration comes first, which by the Go specification's initialization order is that of golang.org/x/image/webp. Such a program calls webp.Decode directly where the checks matter.
The apng package registers nothing: an APNG file starts with the PNG signature, which image/png registers as "png", and image.Decode reads its default image, which is what a caller that asks for one image should get. Nor does the ultrahdr package, for the same reason: an Ultra HDR file starts with the JPEG signature, which image/jpeg registers as "jpeg", and image.Decode reads its primary image, the SDR rendition. Nor does the hdrpng package: image.Decode reads the samples of an HDR PNG file with png.Decode, without its colour chunks.
Image types
Decode returns the standard library type that matches the coded data, converting only when none does: *image.YCbCr for opaque 8-bit lossy data, *image.NYCbCrA for 8-bit lossy data with alpha, *image.Gray for 8-bit monochrome, and *image.NRGBA for WebP lossless. The standard library has no YCbCr type deeper than 8 bits, so 10-bit AVIF is returned as *image.NRGBA64, or *image.Gray16 when monochrome.
The standard library's YCbCr types hold samples that image/color converts by the BT.601 matrix in the full range, as JFIF defines them, and *image.Gray holds full-range samples. AVIF samples are returned in those types as they are only when they mean the same, and converted otherwise, so that no colour is misread:
- 8-bit 4:2:0 samples coded with the BT.601 matrix (matrix coefficients 5 or 6), or with an unspecified one (2), in the full range are returned as
*image.YCbCr, or*image.NYCbCrAwith alpha. With another matrix or in the limited range, they are converted to RGB and returned as*image.NRGBA. - 8-bit monochrome samples are returned as
*image.Gray, converted from the limited range if they are coded in it, and as*image.NRGBAwith alpha. - 10-bit samples are converted to
*image.NRGBA64, or to*image.Gray16when monochrome without alpha. - Colour premultiplied by alpha, which a 'prem' item reference signals, is returned as
*image.RGBA, or*image.RGBA64for 10-bit samples, the types whose colour the standard library takes to be premultiplied.
The colour description that applies is that of the colr property of the image when it has one of type nclx, and that of the AV1 sequence header otherwise; an unspecified matrix is read as BT.601, as image/color reads a YCbCr image. The conversion inverts the equations of ITU-T H.273, Section 8.3, for BT.709, BT.601 and BT.2020 non-constant luminance in either range, and each pixel takes the chroma sample that covers it, as image/color reads *image.YCbCr. The colour primaries and transfer characteristics are not converted, so the values are those that the file codes. Decode returns an UnsupportedError rather than colours it would misread: the PQ and HLG transfer characteristics, other matrices such as YCgCo, ICtCp and the constant luminance ones, and 12-bit, 4:4:4 and 4:2:2 samples.
Options
Encode and EncodeAll accept a nil *Options for defaults, which is lossy at DefaultQuality, 75, as in image/jpeg. Quality ranges from 1 to 100 as in jpeg.Options, and out-of-range values are clamped, so a zero Quality means 1. WebP additionally offers Lossless, which ignores Quality. EncodeAll applies the options to every frame, as Encode does to a still image.
APNG is lossless, so apng.Options has no quality. It holds the CompressionLevel of png.Encoder, applied to every image, and ReduceFrames, described with apng.EncodeAll below; a nil *Options means png.DefaultCompression with frames written as they are given. hdrpng.Options holds only the CompressionLevel, applied to the image data and to the ICC profile, and a nil *Options means png.DefaultCompression.
No Options sets how many goroutines an encoder runs in, since the output does not depend on it; see Concurrency and cancellation.
Image bounds
Encode accepts any image from 1 × 1 to the format's maximum, whose bounds need not start at the origin, and returns a FormatError for a nil or larger image before writing anything. Decode returns an image whose bounds start at the origin.
Alpha
Alpha is preserved when present, exactly in lossy WebP as well, whose ALPH chunk is coded losslessly. An image whose alpha is fully opaque is encoded without an alpha channel.
Lossless WebP also keeps the colour of fully transparent pixels, as image/png does, so that decoding returns exactly the pixels that were encoded. Lossy WebP does not keep it: the encoder replaces it, so that it costs nothing to code and does not bleed into the visible pixels at the edge.
Errors
Malformed input returns a FormatError, and valid input that uses a feature outside the scope returns an UnsupportedError, both string types as in image/png. A truncated stream returns io.ErrUnexpectedEOF. Errors from the io.Reader or io.Writer are returned as is.
Animation
Animated WebP is decoded and encoded by functions modelled on image/gif's DecodeAll and EncodeAll, the standard library's precedent for animation:
func DecodeAll(r io.Reader) (*Animation, error)
func DecodeAllConfig(r io.Reader) (AnimationConfig, error)
func EncodeAll(w io.Writer, a *Animation, o *Options) error
func (a *Animation) Canvases() iter.Seq2[int, *image.NRGBA]
DecodeAll returns the frames as they are coded, as image/gif does. Each Frame holds its image, whose bounds are its rectangle on the canvas, its duration, and its blending and disposal methods; the Animation holds the canvas size, the loop count and the background colour. Frames as coded keep memory in proportion to the input and let an animation be encoded again without loss, whereas whole canvases would cost frames × canvas pixels, which a small file can make very large. A frame duration of 0, whose meaning the specification leaves to the application, is returned as 0. DecodeAll also reads a still file, as one frame that covers the canvas, played once.
Canvases assembles the canvas as RFC 9649, Section 2.7.2, describes, one frame at a time into a single canvas that it updates in place. That canvas is as large as the VP8X chunk declares, whatever the size of the frames, so a caller checks Animation.Config against its budget before calling Canvases. The background colour is a hint that a viewer need not use, and Canvases uses transparent black instead, at the start and on disposal, as libwebp's anim_dump does. Frames are alpha-blended with the formula of Section 2.7.1.1 on the coded values, rounded to nearest, rather than in linear light as that section recommends, since colour management is out of scope.
DecodeAllConfig is to DecodeAll what DecodeConfig is to Decode. It returns an AnimationConfig with the canvas configuration, as Animation.Config holds it, the number of frames, and the number of pixels of all the frames together. It reports a still file as its one frame, so that one check serves every file.
EncodeAll takes an Animation of the same form and writes each frame as it is given, with its rectangle, duration, blending and disposal, so that DecodeAll returns it again. It returns a FormatError, before writing anything, for an animation without frames, a frame outside the canvas or at an odd offset, a canvas larger than the format's maximum, or a duration or loop count that its field cannot hold. Durations are rounded to the nearest millisecond.
EncodeAll makes no choice of its own: it does not compare frames, reduce them to the rectangle that changes, or choose their blending, disposal or format. An encoder such as img2webp searches for those, and the specification leaves them to the encoder.
APNG
The apng package has the same animation API and nothing else, since image/png already decodes and encodes a still PNG file:
func DecodeAll(r io.Reader) (*Animation, error)
func DecodeAllConfig(r io.Reader) (AnimationConfig, error)
func EncodeAll(w io.Writer, a *Animation, o *Options) error
func (a *Animation) Canvases() iter.Seq2[int, image.Image]
func (f *Frame) Duration() time.Duration
apng.DecodeAll departs from the WebP form where APNG differs. Animation.Default is the default image, the static image that a decoder without APNG support displays. DefaultIsFrame says whether it is also the first frame, as it is when an fcTL chunk precedes IDAT, or is outside the animation (PNG Third Edition, Section 4.9.1). A file without an acTL chunk returns its image as the default image and as one frame, played once.
Each frame is the type that image/png returns for the file's colour type and bit depth, with its region as its bounds. Its delay is kept as the coded fraction, DelayNum and DelayDen, which a time.Duration cannot always hold exactly; Frame.Duration interprets it, with a denominator of 0 meaning 100 as Section 11.3.6.2 says. Blending and disposal are those of fcTL, including DisposalPrevious, which Canvases treats as DisposalBackground on the first frame, as that section says.
Canvases assembles a canvas of the bit depth of the file: an *image.NRGBA, or an *image.NRGBA64 for 16 bits, so that nothing is rounded away. It starts transparent black, as Section 4.9.1 requires, and composites BlendOver with the OVER operation of Section 13.16 on the coded values, rounded to nearest.
apng.EncodeAll writes an Animation of the same form with each frame as it is given: its region, delay fraction, blending and disposal. It writes Default as the default image unless DefaultIsFrame is set, when Frames[0] is the default image and must cover the output buffer.
Every frame of an APNG file has the colour type, bit depth and palette of its IHDR and PLTE chunks (Section 11.3.6.3), whereas png.Encode chooses them for each image. EncodeAll therefore chooses one format from what png.Encode chooses for each image alone:
- indexed colour when every image has the same palette of at most 256 colours;
- greyscale when every image is greyscale;
- truecolour otherwise, at 16 bits when any image is written at 16 bits, and with alpha when any image has a pixel that is not opaque.
An image that png.Encode would write otherwise is converted without changing its colours, an 8-bit sample v becoming v × 257 at 16 bits, so that each frame decodes to what image/png decodes for it written alone. An opaque image in a file with alpha is written with an alpha of 255 or 65535.
EncodeAll returns a FormatError, before writing anything, for an animation without frames, a frame outside the output buffer, a field its chunk cannot hold, or a paletted image with an empty palette or an index beyond it. Like webp.EncodeAll, it does not choose a frame's blending or disposal, and by default it makes no other choice either, writing each region as it is given.
Options.ReduceFrames reduces each frame to the region that changes, so that frames given as whole canvases are written as partial frames where the pixels stay the same. EncodeAll assembles the output buffer as Canvases does, at the bit depth of the file, and writes each frame over the bounding rectangle of the pixels whose displayed colour differs from the buffer before it, together with those that DisposalBackground clears from a colour other than transparent black. The frame keeps its image within that rectangle, its delay, blending and disposal, so Canvases assembles the same canvases from the file with the option as without it; a pixel that DisposalPrevious restores was unchanged while the frame was displayed. A frame that changes nothing is written as one pixel, since APNG has no empty frame, and a first frame that is the default image keeps the whole output buffer. The option costs an output buffer of 4 or 8 bytes per pixel, as Canvases does, so a caller that encodes animations of sizes it does not control checks Animation.Config first.
Ultra HDR
The ultrahdr package has no Decode, DecodeConfig or Encode of its own, since image/jpeg already decodes and encodes the SDR primary image of an Ultra HDR file. It has a DecodeAll and an EncodeAll, modelled on image/gif's for a file that holds several images, which read and write the primary image and the gain map:
func DecodeAll(r io.Reader) (*Image, error)
func (m *Image) HDR(maxDisplayBoost float64) (*LinearImage, error)
func (m *LinearImage) ConvertPrimaries(p Primaries) error
func (m *LinearImage) ToneMap(headroom float64) error
func (m *LinearImage) PQ(white float64) (*image.RGBA64, int, error)
func (m *LinearImage) HLG(white, peak float64) (*image.RGBA64, int, error)
func (m *LinearImage) SRGB() (*image.RGBA64, int, error)
func EncodeAll(w io.Writer, m *Image, o *Options) error
func GenerateGainMap(sdr image.Image, hdr *LinearImage, o *GainMapOptions) (*Image, error)
func FromPQ(m image.Image, p Primaries, white float64) (*LinearImage, error)
func FromHLG(m image.Image, p Primaries, white, peak float64) (*LinearImage, error)
Image.Base is the primary image as jpeg.Decode returns it, Image.GainMap the gain map image, an *image.Gray or an *image.YCbCr, and Image.Metadata the metadata with the fields and units of the hdrgm XMP metadata, whichever kind the file holds. DecodeAll reads every JPEG file: one that signals no gain map is returned with a nil GainMap.
The SDR fallback that the specification asks for is explicit, and departs from the error convention below. A gain map or metadata that is invalid or unsupported makes the specification display the SDR image, so DecodeAll returns the primary image with a nil error and a nil GainMap, and the reason in Image.GainMapError, a FormatError, an UnsupportedError or io.ErrUnexpectedEOF. Only an error in the primary image, or from the reader, is returned as the error. Image.HDR returns ErrNoGainMap for an image without a gain map rather than the SDR rendition, so that a missing gain map is not mistaken for one that does nothing.
Image.HDR returns a LinearImage of float32 linear-light samples, with 1.0 at SDR white, since the HDR rendition has no standard library type. It is not clipped or tone-mapped; PQ, HLG and SRGB encode it as an *image.RGBA64 and report how many samples they clipped, and ToneMap maps it to SDR first, as HDR colour describes.
EncodeAll writes an Image, the one that DecodeAll returns or the one that GenerateGainMap returns, so that a file read is written again with its metadata and ICC profile, both images encoded anew. GenerateGainMap takes the SDR rendition as an image.Image and the HDR one as a LinearImage, which FromPQ and FromHLG make from a BT.2100 PQ or HLG image, the inverses of PQ and HLG; it returns an Image with the gain map and the metadata that the specification derives from the two renditions. GainMapOptions holds the choices the specification leaves to the encoder, and a nil *GainMapOptions means DefaultGainMapOptions, the specification's tips. Options follows the convention below with two qualities, Quality for the base image and GainMapQuality for the gain map, and a nil *Options means DefaultQuality, 75, and DefaultGainMapQuality, 85, the lower end of the 85 to 90 that the specification suggests for the gain map. An Image without a gain map is written as a JPEG file with its ICC profile. EncodeAll returns a FormatError, before writing anything, for what the format cannot hold, such as invalid metadata or a gain map of another aspect ratio than the base image, and an UnsupportedError for a gain map larger than the base image, which DecodeAll would not read, or for primaries other than BT.709 without an ICC profile.
HDR PNG
The hdrpng package departs from Decode, DecodeConfig and Encode of image/png in what they take and return, since an HDR PNG image is its samples and the colour chunks that say how to read them, and image.Image has no room for the latter:
func Decode(r io.Reader) (*Image, error)
func DecodeConfig(r io.Reader) (Config, error)
func Encode(w io.Writer, m *Image, o *Options) error
func (c *Color) Space() (Primaries, Transfer, error)
func (m *Image) Linear(white, peak float64) (*LinearImage, error)
func (m *LinearImage) PQImage(white float64) (*Image, int, error)
func (m *LinearImage) HLGImage(white, peak float64) (*Image, int, error)
Image.Pixels is the image that png.Decode returns for the file, of the standard library type for its colour type and bit depth, with its alpha, and Image.Color holds the colour chunks as they are coded, cICP, mDCV, cLLI, iCCP with its profile decompressed, sRGB, gAMA and cHRM, in the units of each chunk, so that nothing is rounded. Config is the image.Config that png.DecodeConfig returns, with the same Color.
A 16-bit image is not taken for an HDR one. Color.Space returns the primaries and transfer function from the colour chunk of highest precedence, cICP, then iCCP, then sRGB, then cHRM and gAMA (PNG Third Edition, Section 4.3, Table 1), and Transfer.HDR reports whether that is PQ or HLG. A file without colour chunks is sRGB with the BT.709 primaries, as browsers display it and as Section 13.14 suggests. An ICC profile, cHRM and gAMA, narrow range, and code points other than those of BT.709, Display P3 and BT.2100 with sRGB, PQ or HLG return an UnsupportedError rather than being taken for sRGB. Image.Linear converts the samples to a LinearImage, whose methods are those of ultrahdr.LinearImage, under HDR colour: PQ takes the luminance of SDR white, usually ReferenceWhite, and HLG also the peak of the display its OOTF renders for, usually DefaultHLGPeak, 1000 cd/m². The mDCV and cLLI metadata are returned, not applied; a caller that tone-maps can take its headroom from them.
Decode departs from png.Decode in what it rejects, too. Section 13.2 suggests that a decoder ignore an ancillary chunk with an unexpected value, but a wrong colour chunk would have the samples read in the wrong colour space, so Decode returns a FormatError for a colour chunk with a wrong length or value, one after PLTE or IDAT or given twice, an mDCV chunk without cICP, IDAT chunks that are not consecutive, and a CRC error in any chunk, and an UnsupportedError for an unknown critical chunk, all of which png.Decode may accept. A caller that wants the samples whatever the colour chunks hold calls png.Decode.
Encode writes an Image, the one that Decode returns or one that PQImage or HLGImage makes, so that a file read is written again with its colour chunks. Image.Pixels is written by png.Encoder, in the colour type and at the bit depth that png.Encode chooses for it, and an Image without colour chunks is written byte for byte as png.Encode writes its pixels. The colour chunks are written as given, after IHDR in the order of their precedence, and none is chosen or converted; the ICC profile is compressed but not read. Encode returns a FormatError, before writing anything, for what PNG Third Edition does not allow, among them cICP matrix coefficients other than 0, mDCV without cICP, an invalid iCCP profile name, iCCP with sRGB, an unknown rendering intent, gAMA or cHRM values other than those of Table 17 with sRGB, and values above 231 − 1. A Gamma of 0 stands for no gAMA chunk and CICP.FullRange is a flag, so neither a zero gamma nor a full-range flag other than 0 or 1 can be given.
PQImage and HLGImage encode a LinearImage as PQ and HLG do and return it as an Image with the cICP chunk of its primaries and transfer function, in full range, with the number of samples they clipped; a caller that knows the mastering display or the light levels of the content adds mDCV or cLLI to it.
HDR colour
The colour handling that HDR renditions share, whatever format holds them, is in internal/hdrcolor, which ultrahdr.LinearImage and hdrpng.LinearImage expose and which every native HDR codec is meant to use. It is written from ITU-R BT.2100, BT.709 and Report ITU-R BT.2408, CSS Color Module Level 4, ITU-T T.871 and, for its tone curve, Reinhard et al. (2002), as CONTRIBUTING.md lists under "HDR colour". A LinearImage has these semantics:
- Samples are linear light, relative to SDR white, which is 1.0, and to one of three sets of primaries, BT.709, Display P3 and BT.2100, all with the D65 white point. Other primaries are rejected with an error. PQ and HLG carry absolute luminance, so
PQ,HLG,FromPQandFromHLGtake the luminance of SDR white, usuallyReferenceWhite, 203 cd/m², the HDR Reference White of BT.2100 and BT.2408;HLGandFromHLGalso take the nominal peak of the display that the HLG OOTF renders for, usually 1000 cd/m². - Nothing happens implicitly.
ConvertPrimariesconverts the gamut by a matrix in linear light and keeps colours outside the new gamut as samples below 0 or above white;ToneMapcompresses luminance into the range of SDR without clipping;SRGB,PQandHLGclip to what their signal carries and return how many samples they clipped. The SDR rendition of an HDR image isToneMap, thenConvertPrimariesto the SDR primaries, thenSRGB. ToneMap(headroom)applies the global operator of Reinhard et al. (2002) to the luminance of each pixel,Y·(1 + Y/headroom²)/(1 + Y), and scales its channels with it, which keeps its chromaticity; the peak,headroomtimes SDR white, becomes white. The curve is the same for every image and adapts to no display or metadata. libultrahdr applies the same curve to the greatest channel instead, which PATENTS.md explains this package does not.- A sample that is NaN or infinite is an error, not a colour.
ConvertPrimariesandToneMapcheck every sample, and every result, before changing any, so that an error leaves the image as it was. - Samples are computed in float64 and stored as float32; the encoders quantise to 16 bits, and
FromPQandFromHLGinvert them to within that. - A
LinearImagehas no alpha.FromPQ,FromHLGand the conversion of an SDR image take the colour of each pixel without its alpha, the stored colour of an*image.NRGBAor*image.NRGBA64and the colour divided out of a premultiplied image otherwise, and the encoders return opaque images.
Resource limits
DecodeConfig reads only the headers; for WebP it reads past, without keeping, the chunks that precede the bitstream. Decode checks the dimensions from the headers before allocating the image, and rejects ones that would overflow or exceed the format's maximum: 16383 × 16383 for WebP, with an UnsupportedError for a larger VP8X canvas or VP8L image. The limit for AVIF is documented with the decoder.
Memory use is proportional to the size of the input and of the image, and no allocation is sized from a field of the stream before the data it describes has been read: WebP's Decode reads the compressed data into memory as it arrives, and decodes it only once it is complete. Its lossless decoder also bounds the prefix code tables that a stream can ask for, at 4 bytes per pixel plus 16 MiB, and returns an UnsupportedError for a stream that needs more; cwebp output stays far below that.
The image itself is still as large as its headers declare, and a file of a few dozen bytes can declare the largest one, about 1 GiB at 4 bytes per pixel for WebP's maximum. A caller decoding untrusted input therefore limits the bytes it reads and checks the size from DecodeConfig against its own budget before calling Decode, as the package documentation and example show.
DecodeAll reads and checks every chunk and frame header of an animation before it decodes a frame. It returns an UnsupportedError for more than 65536 frames, or for frames that hold more pixels together than the largest still image. Its memory use is proportional to the size of the input and of the frames, whatever the canvas size.
Those limits remain a ceiling for a caller that checks nothing. A caller with a smaller budget calls DecodeAllConfig first, which checks the same headers and returns the same errors for them without keeping or decoding a frame, and allocates a fixed amount whatever the input. The caller then rejects an animation whose frame count, or whose frame pixels plus the canvas that Canvases adds, exceed its budget before calling DecodeAll. Reading an animation's headers means reading past every ANMF chunk to the end of the file, so the caller keeps the bytes that DecodeAllConfig reads, with io.TeeReader, and gives them to DecodeAll rather than reading the input twice, as the package example shows.
apng.DecodeAll likewise reads and checks every chunk, CRCs and sequence numbers included, before it decodes an image. It returns an UnsupportedError for a default image of more than 228 pixels, for more than 65536 frames, or for images that hold more than 228 pixels together. The limit on the default image is 228 − 1 where an int is 32 bits, so that an int can index the canvas of 8 bytes per pixel that Canvases allocates. apng.DecodeAllConfig reports the same counts with a fixed allocation, and is used in the same way. The images that image/png decodes take up to 8 bytes per pixel, for 16-bit RGBA, so 2 GiB at that limit, and it allocates as much again for an interlaced image while it decodes it, since it decodes each of the seven Adam7 passes into an image of its own and merges them into the result.
In both packages Canvases draws each frame in time proportional to its region, but what it yields for each frame is the whole canvas. A caller that reads, copies or encodes each one therefore does work in proportion to the number of frames times the canvas size, which the pixel counts do not bound: an APNG file of a few megabytes can hold 65536 one-pixel frames on a canvas of nearly 228 pixels. Such a caller also checks the frame count times the canvas size from DecodeAllConfig against its budget, as the apng example shows.
ultrahdr.DecodeAll reads its input to the end and keeps it in memory. It reads the container in time linear in the size of the file, and the images that an MPF segment lists may not overlap, so that searching them for the gain map reads each byte at most once more. image/jpeg allocates the primary image from its frame header, as jpeg.Decode does, with what it needs to decode it: 1.5 bytes per pixel for a baseline image subsampled 4:2:0, as image/jpeg writes it, and up to 24 for a progressive image of four components, whose coefficients it keeps until the last scan, so a file of a few hundred bytes that declares 65535 × 65535 pixels takes up to 96 GiB. The gain map image is decoded only when the primary image is YCbCr or greyscale, and once its frame header shows that it is no larger than the primary image and has its aspect ratio, so DecodeAll allocates at most 30 bytes per pixel of the primary image in all, besides the file. Image.HDR adds 24 bytes per pixel of the primary image and up to 12 per pixel of the gain map, so up to 36. These counts are of the primary image with its sides rounded up to whole minimum coded units (MCUs), of up to 32 × 32 pixels. Besides the images, DecodeAll joins the ICC profile, which up to 255 segments hold in parts, into one no larger than the file, and parses each XMP packet, of at most 64 KiB, with up to a few MiB that do not add up, since it parses one packet at a time. A caller decoding untrusted input therefore limits the bytes it reads, counting that limit twice, for the file and the ICC profile, and checks the size of the primary image from jpeg.DecodeConfig against its budget at those rates before calling DecodeAll; the gain map's size is bounded by it and need not be read. jpeg.DecodeConfig reads only the headers of the primary image, past the metadata segments, without allocating for the image, and the caller keeps the bytes it reads and gives them to DecodeAll, as the package example shows. image/jpeg sizes the buffers it decodes an image into with int arithmetic, and panics on one that an int cannot count, so DecodeAll checks the frame header of each image first and returns an UnsupportedError for the primary image, or a GainMapError for the gain map, when one of its buffers would be larger than an int counts in bytes. Nothing is rejected where an int is 64 bits; where it is 32 bits the limit is 2 GiB − 1 per buffer, so a progressive image, at 4 bytes per sample for its coefficients, and one that image/jpeg converts to RGB or CMYK, at 4 bytes per pixel, have fewer than 229 pixels, and other images fewer than 231 bytes at 1 to 3 bytes per pixel. ultrahdr.Image.HDR, ultrahdr.GenerateGainMap, ultrahdr.FromPQ and ultrahdr.FromHLG likewise return an UnsupportedError, before reading a pixel, for an image whose linear version, of 12 bytes per pixel, whose gain map's recovery values, of up to 12 bytes per pixel, or whose gain map accumulators in GenerateGainMap, of 8 bytes per sample, an int cannot count in bytes. Nothing is rejected where an int is 64 bits; where it is 32 bits the image has fewer than 231/12 pixels, about 1.79 × 108, and a multi-channel gain map at a Scale of 1 half as many, so a primary image that DecodeAll decodes, such as a greyscale one of 20000 × 20000 pixels at 400 MB, can still be too large for Image.HDR. ultrahdr.GenerateGainMap allocates 12 bytes per pixel of the base image, twice when it converts the primaries of the HDR rendition, and ultrahdr.EncodeAll keeps the whole file in memory before writing it, so where an int is 32 bits it returns an UnsupportedError for a file of 2 GiB or more, which a byte slice cannot hold.
hdrpng.Decode reads its input to the end of the IEND chunk and checks every chunk before image/png decodes the image, keeping in memory only the chunks that image/png reads, IHDR, PLTE, tRNS, IDAT and IEND. It returns an UnsupportedError for an image of more than 228 pixels, 228 − 1 where an int is 32 bits, as apng.DecodeAll does for its default image, and for an ICC profile that decompresses to more than 16 MiB. image/png allocates up to 8 bytes per pixel, and as much again for an interlaced image, and Image.Linear 12 more. hdrpng.DecodeConfig reads up to the header of the first IDAT chunk, where every colour chunk has been read, keeps only IHDR, PLTE, tRNS and the colour chunks, and checks them as Decode does, so a caller checks the size it returns against its budget and gives the bytes it read to Decode, as the package example shows.
Concurrency and cancellation
The packages keep no mutable state, so Decode, DecodeConfig, DecodeAll, DecodeAllConfig, Encode and EncodeAll, in every package, may run in any number of goroutines at once, each with its own reader or writer. ultrahdr.Image.HDR, ultrahdr.GenerateGainMap and ultrahdr.EncodeAll only read the Image and LinearImage they are given, so several goroutines may call them on the same ones as long as none of them changes them.
The AV1 encoder that avif.Encode will expose searches in up to GOMAXPROCS goroutines besides the one that calls it, and writes the same bytes whatever their number, so no option sets it. It runs in fewer when the image is small, as the AVIF results under Compression describe, and each goroutine holds about 2 MiB of scratch space while the encode runs. Every other encoder, and every decoder, runs in the goroutine that calls it. A server that encodes many images at once bounds how many encodes run, as it bounds decodes, and the Go scheduler shares the cores among their goroutines; the only way to keep one encode to fewer goroutines is a lower GOMAXPROCS for the whole program.
As in image/jpeg and image/png, they take no context. A reader that returns an error stops Decode or DecodeAll while it is reading, but not once it is decoding, so a server bounds how many decodes run at once rather than relying on cancellation. ultrahdr.DecodeAll reads its input to the end before it decodes either image, so such a reader stops it before it decodes anything, and ultrahdr.Image.HDR and ultrahdr.GenerateGainMap run to their end once called. ultrahdr.EncodeAll compresses both images before it writes the file, so an error from its writer does not stop it early.
Canvases is an iterator, so a caller stops it between frames by leaving its loop. It only reads the Animation, so several goroutines may call it on the same Animation as long as none of them changes it.
License
MIT. The MIT License grants no patent rights; see PATENTS.md for the patent terms that apply to WebP, AV1, APNG, HDR PNG, HDR gain maps and Ultra HDR, and THIRD_PARTY.md for the provenance of third-party code and assets.
This product includes Gain Map technology under license by Adobe. The ultrahdr package and the HDR gain map code under internal/gainmap that it uses carry the notice that Adobe's Gain Map Specification Patent License requires.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package apng implements an animated PNG (APNG) decoder and encoder.
|
Package apng implements an animated PNG (APNG) decoder and encoder. |
|
Package avif will implement an AVIF image decoder and encoder.
|
Package avif will implement an AVIF image decoder and encoder. |
|
Package hdrpng implements a decoder and an encoder for PNG images with the HDR colour signalling of the PNG Specification, Third Edition.
|
Package hdrpng implements a decoder and an encoder for PNG images with the HDR colour signalling of the PNG Specification, Third Edition. |
|
internal
|
|
|
alph
Package alph decodes and encodes the alpha channel of a lossy WebP image, the payload of an 'ALPH' chunk, RFC 9649, Section 2.7.1.2.
|
Package alph decodes and encodes the alpha channel of a lossy WebP image, the payload of an 'ALPH' chunk, RFC 9649, Section 2.7.1.2. |
|
apngtest
Package apngtest writes the APNG datastreams that the tests of package apng decode, and that the interoperability tests give a reference decoder too.
|
Package apngtest writes the APNG datastreams that the tests of package apng decode, and that the interoperability tests give a reference decoder too. |
|
av1
Package av1 implements the bitstream primitives of the AV1 Bitstream & Decoding Process Specification that an AV1 still-image decoder and encoder share: the bit-level descriptors, the OBU framing, the sequence header, the frame header of an intra frame, the tile groups, the symbol decoder and encoder with the adaptation of their CDFs, and the inverse transforms with forward transforms that match them.
|
Package av1 implements the bitstream primitives of the AV1 Bitstream & Decoding Process Specification that an AV1 still-image decoder and encoder share: the bit-level descriptors, the OBU framing, the sequence header, the frame header of an intra frame, the tile groups, the symbol decoder and encoder with the adaptation of their CDFs, and the inverse transforms with forward transforms that match them. |
|
gainmap
Package gainmap generates and applies HDR gain maps.
|
Package gainmap generates and applies HDR gain maps. |
|
hdrcolor
Package hdrcolor holds the colour handling that HDR images share, whatever format holds them: linear-light RGB samples, the primaries they are relative to, the SDR white point and its luminance, the sRGB, PQ and HLG transfer functions, conversion between primaries, and tone mapping to SDR.
|
Package hdrcolor holds the colour handling that HDR images share, whatever format holds them: linear-light RGB samples, the primaries they are relative to, the SDR white point and its luminance, the sRGB, PQ and HLG transfer functions, conversion between primaries, and tone mapping to SDR. |
|
heif
Package heif reads and writes the HEIF (ISO/IEC 23008-12) structure of a still AVIF image: the ISO base media file format (ISO/IEC 14496-12) boxes that locate an AV1 image item, its alpha auxiliary image and their properties, as the AV1 Image File Format v1.2.0 (AVIF) requires them.
|
Package heif reads and writes the HEIF (ISO/IEC 23008-12) structure of a still AVIF image: the ISO base media file format (ISO/IEC 14496-12) boxes that locate an AV1 image item, its alpha auxiliary image and their properties, as the AV1 Image File Format v1.2.0 (AVIF) requires them. |
|
imagetest
Package imagetest provides the test corpus, animated sequences built from its generators, image comparison metrics, malformed-input generators and benchmark reporting shared by the codec tests.
|
Package imagetest provides the test corpus, animated sequences built from its generators, image comparison metrics, malformed-input generators and benchmark reporting shared by the codec tests. |
|
interop
Package interop holds the differential tests and benchmarks that check the codecs against the reference implementations, libwebp's cwebp, dwebp, img2webp, webpmux and anim_dump, libavif's avifenc and avifdec, libultrahdr's ultrahdr_app, and FFmpeg's ffmpeg.
|
Package interop holds the differential tests and benchmarks that check the codecs against the reference implementations, libwebp's cwebp, dwebp, img2webp, webpmux and anim_dump, libavif's avifenc and avifdec, libultrahdr's ultrahdr_app, and FFmpeg's ffmpeg. |
|
riff
Package riff writes the Resource Interchange File Format chunks that container formats such as WebP are built from.
|
Package riff writes the Resource Interchange File Format chunks that container formats such as WebP are built from. |
|
vp8
Package vp8 implements the VP8 key frames that hold the lossy bitstream of WebP, RFC 6386: a decoder, and an encoder whose output the webp package wraps in the RIFF container of RFC 9649.
|
Package vp8 implements the VP8 key frames that hold the lossy bitstream of WebP, RFC 6386: a decoder, and an encoder whose output the webp package wraps in the RIFF container of RFC 9649. |
|
vp8l
Package vp8l implements the WebP lossless (VP8L) bitstream, RFC 9649, Section 3: an encoder, whose output the webp package wraps in a RIFF container, and a decoder.
|
Package vp8l implements the WebP lossless (VP8L) bitstream, RFC 9649, Section 3: an encoder, whose output the webp package wraps in a RIFF container, and a decoder. |
|
ycbcr
Package ycbcr converts between images and the Y′CbCr samples that an AV1 frame codes, by the matrix coefficients and range of ITU-T H.273 (07/2024), Section 8.3, so that the samples mean what the colour description of the frame says they mean.
|
Package ycbcr converts between images and the Y′CbCr samples that an AV1 frame codes, by the matrix coefficients and range of ITU-T H.273 (07/2024), Section 8.3, so that the samples mean what the colour description of the frame says they mean. |
|
Package ultrahdr implements an Ultra HDR JPEG decoder and encoder.
|
Package ultrahdr implements an Ultra HDR JPEG decoder and encoder. |
|
Package webp implements a WebP image decoder and encoder.
|
Package webp implements a WebP image decoder and encoder. |