Documentation
¶
Overview ¶
Package heic decodes HEIF images that carry HEVC-coded item data, the format commonly called HEIC.
Color ¶
Decode returns RGB, converted with the matrix and range the file declares in its nclx color description. Options.ToYCbCr skips that and hands back the planes the bitstream carries: *image.YCbCr, *image.NYCbCrA with alpha, or *image.Gray for monochrome. Above 8 bits there is no such image type, so *image.NRGBA64 is returned anyway.
image.YCbCr reads its planes as full-range BT.601 whatever the file signals, which is rarely what a HEIC file means. DecodeColor reports what they actually are, so ToYCbCr is for reaching the samples rather than for display:
img, ci, err := heic.DecodeColor(r, heic.Options{ToYCbCr: true})
ColorInfo carries the CICP code points and the range flag, plus the ICC profile when the file has one. Matrix and FullRange are what the conversion to RGB uses. Primaries and Transfer are reported but not applied, so RGB output stays in the file's own color space.
Metadata ¶
DecodeExif reads the Exif item a file describes its image with, and RawExif and RawXMP return the payloads unparsed.
Index ¶
Constants ¶
const DefaultFrameSizeLimit = 16384 * 16384
DefaultFrameSizeLimit bounds the pixel area a header may ask to allocate.
Variables ¶
var ErrInvalid = errors.New("heic: invalid file")
ErrInvalid is returned when a file is not a HEIF, or is malformed past the point where anything can be decoded from it.
var ErrNoExif = errors.New("avif: no exif data")
ErrNoExif is returned when the file carries no Exif item.
var ErrNoXMP = errors.New("avif: no xmp data")
ErrNoXMP is returned when the file carries no XMP item.
var ErrUnsupported = errors.New("heic: unsupported image")
ErrUnsupported is returned for a file this package cannot render but which is otherwise well formed: an essential property it does not implement, or a sample format it has no conversion for. A caller that has another decoder to fall back on should test for this one rather than ErrInvalid.
Functions ¶
func DecodeConfig ¶
DecodeConfig returns the dimensions and color model without decoding the image data.
Types ¶
type ColorInfo ¶
type ColorInfo struct {
Primaries uint16
Transfer uint16
Matrix uint16
FullRange bool
// ICCP is the embedded ICC profile, for files that carry one in place of
// an nclx description. It aliases the input, so it is not a copy.
ICCP []byte
}
ColorInfo describes the color space an image was decoded from.
type Exif ¶
type Exif struct {
// Orientation is the Exif orientation, 1 to 8, where 1 is upright.
Orientation int
// Width and Height are the dimensions the Exif tags report, which need
// not be the dimensions the image decodes to.
Width int
Height int
// Make and Model name the camera, Software what wrote the file.
Make string
Model string
Software string
// DateTime and DateTimeOriginal are "YYYY:MM:DD HH:MM:SS", the first the
// file's own time and the second the time the photo was taken.
DateTime string
DateTimeOriginal string
// ExposureTime is in seconds and FocalLength in millimetres.
ExposureTime float64
FNumber float64
ISOSpeed int
FocalLength float64
Flash int
// GPSLatitude and GPSLongitude are decimal degrees, positive north and
// east. GPSAltitude is metres above sea level.
GPSLatitude float64
GPSLongitude float64
GPSAltitude float64
Copyright string
Artist string
}
Exif holds the Exif metadata decoded from an HEIC image.
type HEIC ¶
type HEIC struct {
// Image holds the decoded frames, *image.NRGBA or *image.NRGBA64.
Image []image.Image
// Delay holds each frame's duration in seconds.
Delay []float64
// LoopCount controls how many times the animation restarts, following
// image/gif: zero loops forever, -1 shows each frame once, and any other
// value plays the animation LoopCount+1 times.
LoopCount int
// Color describes the color space the frames were decoded from.
Color ColorInfo
}
HEIC holds the images of a file, which may be an image sequence.
type Options ¶
type Options struct {
// AutoRotate applies the clap/irot/imir transforms, forcing NRGBA output
// when it transforms.
AutoRotate bool
// FrameSizeLimit bounds a frame's area in pixels. Zero means
// DefaultFrameSizeLimit; a negative value removes the limit.
FrameSizeLimit int
// ToYCbCr forces the image's native color space instead of NRGBA:
// *image.YCbCr, *image.NYCbCrA when there is alpha, or *image.Gray when
// the image is monochrome. Above 8 bits NRGBA64 is returned anyway.
// image.YCbCr reads the planes as full-range BT.601 whatever the file
// signals, so this is for reaching the samples, not for display.
// DecodeColor reports what the samples actually are.
ToYCbCr bool
// Threads bounds the goroutines a decode may use, over the tiles of a grid
// and the wavefront rows within each. Zero means GOMAXPROCS; one decodes
// serially.
Threads int
}
Options controls decoding.