Documentation
¶
Overview ¶
Package jxl decodes and encodes JPEG XL images.
Decoding covers both Modular and VarDCT codestreams. Encoding writes a single frame from sRGB input, lossy VarDCT by default and Modular when EncodeOptions.Lossless is set. An alpha channel is always kept losslessly.
DecodeExif parses the Exif metadata of a file, while RawExif and RawXMP return the payloads whole. All three report ErrNoExif or ErrNoXMP when the file carries no such box, and ErrUnsupported when it carries one Brotli compressed.
Index ¶
- Constants
- Variables
- func Decode(r io.Reader, opts ...Options) (image.Image, error)
- func DecodeConfig(r io.Reader) (image.Config, error)
- func Encode(w io.Writer, m image.Image, opts ...EncodeOptions) error
- func RawExif(r io.Reader) ([]byte, error)
- func RawXMP(r io.Reader) ([]byte, error)
- type ColorInfo
- type EncodeOptions
- type Exif
- type Float
- type JXL
- type Options
Constants ¶
const ( // DefaultQuality is the quality used when EncodeOptions.Quality is zero. DefaultQuality = 90 // DefaultEffort is the effort used when EncodeOptions.Effort is zero. DefaultEffort = 7 // MaxEffort is the highest effort the encoder implements. MaxEffort = 7 )
const DefaultFrameSizeLimit = min(16384*16384, math.MaxInt>>6)
DefaultFrameSizeLimit is the frame area, in pixels, accepted when Options.FrameSizeLimit is zero.
const DefaultLevel = 5
DefaultLevel is the codestream level enforced when Options.Level is zero.
const DefaultMaxFrames = 1024
DefaultMaxFrames bounds the frames a decode reads from a codestream.
Variables ¶
var ( ErrInvalid = errors.New("jxl: invalid bitstream") ErrUnsupported = errors.New("jxl: unsupported feature") )
ErrInvalid means the bitstream is malformed. ErrUnsupported means it is well-formed but uses a feature this decoder does not implement.
var ErrFrameTooLarge = errors.New("jxl: frame exceeds size limit")
ErrFrameTooLarge is returned when a frame's area exceeds Options.FrameSizeLimit.
var ErrNoExif = errors.New("jxl: no exif data")
ErrNoExif is returned when the file carries no Exif box.
var ErrNoXMP = errors.New("jxl: no xmp data")
ErrNoXMP is returned when the file carries no XMP box.
Functions ¶
func Decode ¶
Decode reads a JPEG XL image as *image.NRGBA, or *image.NRGBA64 above 8 bits. Grayscale without alpha gives *image.Gray or *image.Gray16.
func DecodeConfig ¶
DecodeConfig reads the dimensions and color model without decoding pixels.
func Encode ¶
Encode writes m as a JPEG XL codestream, lossy VarDCT by default and Modular when EncodeOptions.Lossless is set. Samples are treated as sRGB. An alpha channel is kept losslessly, and dropped when every pixel is opaque.
Types ¶
type ColorInfo ¶
ColorInfo reports the color space of the decoded samples, as CICP code points or as the ICC profile the codestream carried.
type EncodeOptions ¶
type EncodeOptions struct {
// Quality runs from 1 to 100, where 100 is the least lossy. Zero means
// DefaultQuality.
Quality int
// Effort runs from 1 to MaxEffort, spending encode time on a wider block
// search for a smaller file at the same quality. Zero means DefaultEffort,
// higher values are clamped.
Effort int
// Lossless reproduces the source samples exactly, ignoring Quality.
Lossless bool
// Threads bounds the goroutines encoding one frame. Zero means GOMAXPROCS,
// one encodes serially.
Threads int
}
EncodeOptions controls the encoder. The zero value is a reasonable default.
type Exif ¶ added in v0.1.2
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 a JPEG XL image.
type Float ¶
type Float struct {
Width int
Height int
Channels int
// Frames each hold Width*Height*Channels samples, row-major.
Frames [][]float32
Color ColorInfo
}
Float is the decoder's native output: interleaved float32 samples per frame, in the image's own color space.
type Options ¶
type Options struct {
// Level is the codestream level to accept. Zero means DefaultLevel.
Level int
// Threads bounds the goroutines decoding one frame. Zero means GOMAXPROCS,
// one decodes serially.
Threads int
// FrameSizeLimit bounds a frame's area in pixels, so that a corrupt or
// hostile header cannot ask for an unbounded allocation. Zero means
// DefaultFrameSizeLimit; a negative value removes the limit.
FrameSizeLimit int
// MaxFrames bounds the frames a decode reads from a codestream. Zero
// means DefaultMaxFrames; a negative value removes the limit.
MaxFrames int
}
Options configure a decode.
Source Files
¶
- adaptivequant_write.go
- ans.go
- ans_write.go
- arena.go
- bitreader.go
- bitwriter.go
- blending.go
- brotli.go
- brotlidata.go
- colorencoding.go
- colorencoding_write.go
- container.go
- dct.go
- decoder.go
- dsp.go
- dsp_amd64.go
- encoder.go
- epf0.go
- exif.go
- filter.go
- frame.go
- frame_write.go
- frameheader.go
- frameheader_write.go
- headers.go
- headers_write.go
- histogram.go
- histogram_write.go
- huffman.go
- huffman_write.go
- hybriduint.go
- hybriduint_write.go
- icc.go
- image.go
- jxl.go
- matree.go
- matree_write.go
- metadata.go
- metadata_write.go
- modular.go
- modular_write.go
- noise.go
- palette_tables.go
- patches.go
- permutation.go
- predict.go
- quantweights.go
- quantweights_tables.go
- signature.go
- source.go
- splines.go
- threads.go
- toc.go
- transform.go
- transform_tables.go
- transformdata.go
- transformdata_tables.go
- upsample.go
- vardct.go
- vardct_write.go
- xyb.go
- xyb_write.go