Documentation
¶
Overview ¶
Package heif reads HEIF/HEIC still images (ISO/IEC 23008-12 over the ISO base media file format of ISO/IEC 14496-12) in pure Go. The HEVC pictures are decoded by github.com/go-avkit/h265.
What it reads: the primary item of a file whose ftyp brands include heic, heix, hevc, hevx, heim, heis, mif1 or msf1, when that item is an hvc1 image, a grid of hvc1 tiles, or an identity (iden) of one of them, with the transformative properties irot, imir and clap applied in the order the file lists them. 8-bit and deeper (to 16-bit) 4:0:0, 4:2:0, 4:2:2 and 4:4:4 pictures are supported. Colour is converted with the matrix and range of the nclx colr property (BT.601 full range without one); the primaries and transfer characteristic are not applied, and an ICC profile is returned, not applied.
What it does not read: alpha auxiliary images (Result.HasAlpha says one exists), depth maps, HDR gain maps, overlays (iovl), thumbnails, image sequences, other codecs (AV1, JPEG, VVC), and items stored in another file.
The input is untrusted: see Limits.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotHEIF: the data is not a HEIF file (no ftyp box with a still-image brand). ErrNotHEIF = errors.New("heif: not a HEIF still-image file") // ErrTruncated: a box, a field or an item's data runs past the end of its container. ErrTruncated = errors.New("heif: truncated data") // ErrInvalid: the file breaks the format (a size, offset, reference or count that // cannot be right). ErrInvalid = errors.New("heif: invalid file") // ErrUnsupported: the file is valid but uses something this reader does not decode // (an item type other than hvc1, grid and iden, an overlay, a matrix, an essential // property it does not know). ErrUnsupported = errors.New("heif: unsupported feature") // ErrNoPrimaryItem: the file has no primary item, or it is not an image. ErrNoPrimaryItem = errors.New("heif: no primary image item") // ErrCorrupt: the HEVC bitstream of an item could not be decoded. ErrCorrupt = errors.New("heif: the HEVC bitstream could not be decoded") // ErrFileTooLarge: the file is longer than Limits.MaxBytes. ErrFileTooLarge = errors.New("heif: file larger than the limit") // ErrImageTooLarge: an image (a tile, a grid, the result) has more pixels than // Limits.MaxPixels, or its buffers cannot be addressed on this platform. ErrImageTooLarge = errors.New("heif: image larger than the limit") // ErrTooManyBoxes: the file holds more than Limits.MaxBoxes boxes. ErrTooManyBoxes = errors.New("heif: too many boxes") // ErrNestingTooDeep: boxes nest deeper than Limits.MaxDepth, or items derive from // one another deeper than that. ErrNestingTooDeep = errors.New("heif: boxes or derivations nested too deeply") // ErrTooManyItems: more than Limits.MaxItems items (or item entries). ErrTooManyItems = errors.New("heif: too many items") // ErrTooManyTiles: a grid has more than Limits.MaxTiles tiles. ErrTooManyTiles = errors.New("heif: too many tiles") )
Errors of the reader. Every error returned by this package wraps one of them (test with errors.Is); the text after the colon says where.
Functions ¶
func DecodeConfig ¶
DecodeConfig returns the size and colour model of the primary image without decoding it; only the boxes up to meta are read.
func DecodeConfigOptions ¶
DecodeConfigOptions is DecodeConfig under the given options.
func DecodeWork ¶
DecodeWork is the number of pixels the decoder processes to read the primary image, from the head of the file and without decoding any picture. It is what a caller sets a budget against: a grid decodes every tile in full, so a grid of large tiles cropped to a sliver costs far more than the size DecodeConfig reports.
Types ¶
type Limits ¶
type Limits struct {
// MaxBytes is the longest file read (default 256 MiB). It also bounds the bytes
// one item may assemble from its extents.
MaxBytes int64
// MaxPixels is the most pixels of one image: a tile, a grid, the decoded base image
// and the result (default 1<<26, which holds a 48-megapixel photo and 8192x8192).
//
// It sets the memory of a decode: the planes of the HEVC decoder and the converted
// image are alive together, 1.5 bytes a pixel for the planes of an 8-bit 4:2:0 picture
// and 4 for its RGBA result, 5.5 bytes a pixel live at the peak. MaxMemory bounds
// that product; MaxPixels bounds the size of a picture (a value above 2^40 is
// lowered to 2^40).
MaxPixels int64
// MaxMemory is the most live data a decode may need, estimated before anything is
// decoded from the parameter sets (default 320 MiB): the planes of the coded picture
// (1.5 bytes a pixel for 8-bit 4:2:0, 6 for 16-bit 4:4:4; a grid holds those of one
// tile and of the assembled picture) plus the converted result (4 bytes a pixel, 8
// for 16 bits, 1 or 2 for grey). It is an estimate of live data, not a bound of the
// heap: the peak heap, the garbage the collector has not yet taken included, is about
// 1.25 times MaxMemory (measured 437 MiB against an estimate of 352, so about 400 MiB
// at the 320 MiB default). It does not count the input: reading the file and
// assembling an item hold up to 2 times MaxBytes besides. At the default a
// 48-megapixel 8-bit 4:2:0 photo (about 250 MiB) is decoded, 8192x8192 8-bit 4:2:0
// (352 MiB) is not, 10-bit 4:2:2 (12 bytes a pixel) stops at about 28 megapixels and
// 16-bit 4:4:4 (14) at about 24. DecodeWork applies the same check.
MaxMemory int64
// MaxTiles is the most tiles of one grid (default 4096).
MaxTiles int
// MaxBoxes is the most boxes of the file, nested ones included (default 65536).
MaxBoxes int
// MaxDepth is the deepest box nesting, and the longest chain of derived items
// (default 8).
MaxDepth int
// MaxItems is the most items, references and property associations the reader
// accepts in one box (default 16384).
MaxItems int
// MaxDecoderBytes bounds the memory of the HEVC decoder's picture buffer, as the
// decoder estimates it for the pictures the stream states: 9 bytes a luma sample of a
// 4:2:0 picture, for each of the pictures its buffer may hold (default 4 GiB, which
// holds the 4 pictures an x265 stream states at 8192x8192). An item holds one picture
// and one decoder is alive at a time, so what is allocated is that of one picture.
// It is the limit of the file, not of each tile.
MaxDecoderBytes int64
}
Limits bound what an untrusted file can make the reader read, count or allocate. A zero field stands for its default.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits are the limits a zero Limits stands for.
type Nclx ¶
type Nclx = nclx
Nclx is a colour description by code points (ITU-T H.273): colour primaries, transfer characteristics, matrix coefficients and range.
type Result ¶
type Result struct {
// Image is the primary image, transformations applied. It is an *image.YCbCr or
// *image.Gray sharing the HEVC decoder's planes when no transformation applies
// and the picture is 8-bit full-range BT.601, else an *image.RGBA, *image.RGBA64,
// *image.Gray or *image.Gray16.
Image image.Image
// ICCProfile is the colr ICC profile of the primary item, as stored (nil if none).
ICCProfile []byte
// Nclx is the nclx colr property of the primary item (nil if none).
Nclx *Nclx
// HasAlpha says an alpha plane is attached to the primary item; it is not decoded.
HasAlpha bool
}
Result is a decoded file.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
covergate
command
Command covergate reads a Go coverage profile and exits 1 unless every statement of it was executed.
|
Command covergate reads a Go coverage profile and exits 1 unless every statement of it was executed. |
|
mkhevc
command
Command mkhevc encodes one intra picture of each pixel format the tests need with ffmpeg's libx265: mkhevc <source.png> <dir> writes <dir>/<pix_fmt>.hevc, Annex B streams that the tests wrap in HEIF items.
|
Command mkhevc encodes one intra picture of each pixel format the tests need with ffmpeg's libx265: mkhevc <source.png> <dir> writes <dir>/<pix_fmt>.hevc, Annex B streams that the tests wrap in HEIF items. |
|
mkpng
command
Command mkpng writes the synthetic source images the testdata HEIC files are made from: mkpng <dir> writes small.png (67x45, odd sizes) and big.png (1100x700, which an encoder splits into a grid), each an asymmetric pattern so a rotation or mirror shows.
|
Command mkpng writes the synthetic source images the testdata HEIC files are made from: mkpng <dir> writes small.png (67x45, odd sizes) and big.png (1100x700, which an encoder splits into a grid), each an asymmetric pattern so a rotation or mirror shows. |