Documentation
¶
Overview ¶
Package gojxl is a pure Go JPEG XL (ISO/IEC 18181) decoder.
Index ¶
- Variables
- func ConvertToJPEG(w io.Writer, data []byte, quality int, opt *Options) (err error)
- func ConvertToJXL(data []byte, opt *EncodeOptions) (out []byte, err error)
- func ConvertToPFM(w io.Writer, data []byte, opt *Options) (err error)
- func ConvertToPNG(w io.Writer, data []byte, opt *Options) (err error)
- func ConvertToPNM(w io.Writer, data []byte, opt *Options) (err error)
- func Decode(r io.Reader) (image.Image, error)
- func DecodeBytes(data []byte) (image.Image, error)
- func DecodeBytesOptions(data []byte, opt *Options) (img image.Image, err error)
- func DecodeConfig(r io.Reader) (image.Config, error)
- func DecodeInput(data []byte) (img image.Image, err error)
- func DistanceFromQuality(q float32) float32
- func Encode(w io.Writer, img image.Image, opt *EncodeOptions) error
- func EncodeAnimation(anim *Animation, opt *EncodeOptions) ([]byte, error)
- func EncodeBytes(img image.Image, opt *EncodeOptions) ([]byte, error)
- func HasJPEG(data []byte) bool
- func ReconstructJPEG(data []byte) (out []byte, err error)
- func SSIMULACRA2(orig, dist image.Image) (float64, error)
- func TranscodeJPEG(data []byte) (out []byte, err error)
- type Animation
- type EncodeOptions
- type Frame
- type Info
- type Options
Constants ¶
This section is empty.
Variables ¶
var ErrNoJPEG = errors.New("gojxl: no JPEG reconstruction data (jbrd box)")
ErrNoJPEG is returned by ReconstructJPEG for files without JPEG reconstruction data.
var ErrUnsupportedColour = enc.ErrColourModel
ErrUnsupportedColour is returned for lossy encoding of samples whose colour space cannot be converted to XYB: ICC profiles other than matrix/TRC RGB or grey ones (such as LUT-based or CMYK profiles), and PQ or HLG transfer functions. Lossless encoding stores any profile.
Functions ¶
func ConvertToJPEG ¶
ConvertToJPEG writes a JPEG XL image to w as JPEG: the original file when it is a losslessly recompressed JPEG (see ReconstructJPEG), else the first frame's pixels encoded at the given quality (1-100), with the colour profile of the decoded pixels and the Exif and XMP metadata. opt (may be nil) applies to the pixel path.
func ConvertToJXL ¶
func ConvertToJXL(data []byte, opt *EncodeOptions) (out []byte, err error)
ConvertToJXL encodes an image file as JPEG XL: PNG or APNG, GIF, JPEG, WebP (still or animated), TIFF, BMP, PGM/PPM/PAM, or any other format registered with package image. The colour space of the input is kept (PNG cICP, iCCP, sRGB and gAMA/cHRM chunks, JPEG ICC profiles; opt.ICC overrides them), as are its Exif and XMP metadata (the Exif orientation becomes the image's). With Distance 0, JPEG files are recompressed losslessly (restorable byte for byte with ReconstructJPEG) when possible, unless opt.JPEGPixels is set; animated GIF and APNG files become animations.
func ConvertToPFM ¶
ConvertToPFM decodes a JPEG XL image and writes the colour samples of its first displayed frame to w as a PFM of 32-bit floats (Pf for grey images): the values of ConvertToPNG's samples before quantisation, which may lie outside [0, 1] (HDR, wide gamut). Alpha is not kept.
func ConvertToPNG ¶
ConvertToPNG decodes a JPEG XL image and writes it to w as PNG: the first displayed frame, or an APNG of all frames for animations, with the colour profile (or cICP code points) of the decoded pixels. The result is that of DecodeBytesOptions followed by PNG encoding, but the rows of a frame go straight to the PNG writer (which filters and compresses strips of rows in parallel): the output image never exists as a whole.
func ConvertToPNM ¶
ConvertToPNM decodes a JPEG XL image and writes its first displayed frame to w as a binary anymap: PGM for grey, PPM for colour, PAM (P7) when some pixel is not opaque; 16 bits per sample when the image has more than 8 (or with opt.Force16). Anymaps carry no colour profile: the samples are those ConvertToPNG writes (opt.SRGB gives sRGB).
func DecodeBytes ¶
DecodeBytes decodes a JPEG XL image held in memory.
func DecodeBytesOptions ¶
DecodeBytesOptions decodes with options.
func DecodeConfig ¶
DecodeConfig returns the colour model and dimensions of a JPEG XL image.
func DecodeInput ¶
DecodeInput decodes an image file of a format ConvertToJXL takes (the first frame of an animation): PNG, JPEG, GIF, WebP, TIFF, BMP, PGM, PPM, PAM or any other format registered with package image.
func DistanceFromQuality ¶
DistanceFromQuality maps a quality from 0 to 100 (100: lossless) to the Distance that libjxl's encoder (cjxl -q) uses for it.
func EncodeAnimation ¶
func EncodeAnimation(anim *Animation, opt *EncodeOptions) ([]byte, error)
EncodeAnimation encodes an animation (lossless, or lossy VarDCT when opt.Distance > 0). All frames must have the same size; each is shown for its Duration (seconds). NumLoops is the number of plays (0 = forever).
func EncodeBytes ¶
func EncodeBytes(img image.Image, opt *EncodeOptions) ([]byte, error)
EncodeBytes encodes img (losslessly unless opt.Distance > 0) and returns the JPEG XL bytes.
func ReconstructJPEG ¶
ReconstructJPEG restores the original JPEG file from a JPEG XL file made by lossless JPEG recompression (by gojxl or libjxl), byte for byte.
func SSIMULACRA2 ¶
SSIMULACRA2 returns the SSIMULACRA 2 perceptual score of dist against orig: 100 = identical, about 90 = visually lossless, 70 = high quality, 50 = medium quality. Both images are taken as sRGB; alpha is blended onto a grey background.
func TranscodeJPEG ¶
TranscodeJPEG losslessly recompresses a JPEG file into JPEG XL: the DCT coefficients are kept, so decoding gives the same image as decoding the JPEG (typically ~20% smaller), and a 'jbrd' box allows decoders to restore the original JPEG file byte for byte.
Types ¶
type Animation ¶
Animation holds all displayed frames.
func DecodeAllOptions ¶
DecodeAllOptions decodes all displayed frames with options.
func DecodeAnimatedInput ¶
DecodeAnimatedInput decodes an animated GIF or APNG into full-canvas frames. It returns nil (and no error) for other or single-frame files.
type EncodeOptions ¶
type EncodeOptions struct {
// Effort trades speed for size; 0 selects the default.
//
// Lossless (1-6, default 4): 1-3 use fixed context models (fast); 4+
// learn an MA tree from the image, choose colour transforms and
// per-group channel palettes, and tune the entropy coder (slower,
// typically 5-40% smaller).
//
// Lossy (1-7, default 7): fewer transform shapes are searched at lower
// efforts: 5-6 skip 32x16/16x32, 4 all rectangular shapes, 3 also
// DCT32, 2 tries only DCT16 besides DCT8 and 1 only 8x8 DCTs. Like
// libjxl, efforts 1-4 use no adaptive quantisation or Gaborish. On a
// 5 MP photo effort 1 takes a third of the CPU time of effort 7.
Effort int
// Distance > 0 selects lossy (VarDCT) encoding with the given
// perceptual distance (1.0 ~ visually lossless). 0 means lossless.
Distance float32
// ICC is the colour profile of the input samples; nil means sRGB (for
// ConvertToJXL: the profile of the input file). It is stored as the
// equivalent enum colour encoding when there is one, as libjxl does,
// else as is; lossy encoding converts the samples to XYB through it,
// which needs a matrix/TRC RGB or grey profile (else
// ErrUnsupportedColour).
ICC []byte
// JPEGPixels makes ConvertToJXL encode the pixels of JPEG input
// instead of recompressing its DCT coefficients losslessly.
JPEGPixels bool
// Exif (TIFF format, as in PNG eXIf chunks) and XMP are stored in
// metadata boxes (for ConvertToJXL: those of the input file, unless
// set). The Exif orientation tag becomes the image's orientation: the
// samples are taken as stored, before that rotation.
Exif, XMP []byte
}
EncodeOptions controls encoding.
type Info ¶
type Info struct {
Width, Height int // displayed size (after orientation)
BitsPerSample int
FloatSamples bool
HasAlpha bool
Grey bool
XYB bool
Animated bool
Orientation int
NumExtraChannels int
ICC []byte
// OutputICC is the profile that describes the decoded pixels, or nil if
// they are sRGB.
OutputICC []byte
// CICP holds H.273 (primaries, transfer) code points for HDR (PQ/HLG)
// output, or nil.
CICP []byte
// Exif (TIFF format) and XMP metadata from the container's boxes, or
// nil. The Exif orientation tag is as stored; Orientation is the one
// decoders apply.
Exif, XMP []byte
// Colour describes the colour encoding of the image header.
Colour string
}
Info describes a JPEG XL image.
type Options ¶
type Options struct {
// Force16 always produces 16-bit images.
Force16 bool
// SRGB converts the output to sRGB (gamut clipped): wide-gamut and
// ICC-tagged images come out untagged, for software without colour
// management. PQ and HLG images, which need tone mapping, keep their
// space.
SRGB bool
}
Options controls decoding.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
gojxl
command
Command gojxl decodes and inspects JPEG XL images.
|
Command gojxl decodes and inspects JPEG XL images. |
|
internal
|
|
|
bitio
Package bitio implements the LSB-first bit reader used by the JPEG XL codestream (ISO/IEC 18181-1, section 4/9).
|
Package bitio implements the LSB-first bit reader used by the JPEG XL codestream (ISO/IEC 18181-1, section 4/9). |
|
bmp
Package bmp reads Windows bitmaps: 1, 4 and 8-bit palette images (also RLE4/RLE8 compressed), 16, 24 and 32-bit images with optional bit fields, bottom-up or top-down.
|
Package bmp reads Windows bitmaps: 1, 4 and 8-bit palette images (also RLE4/RLE8 compressed), 16, 24 and 32-bit images with optional bit fields, bottom-up or top-down. |
|
brotli
Package brotli is a Brotli (RFC 7932) decompressor, used for the compressed parts of JPEG XL containers (jbrd and brob boxes).
|
Package brotli is a Brotli (RFC 7932) decompressor, used for the compressed parts of JPEG XL containers (jbrd and brob boxes). |
|
enc
Package enc implements a JPEG XL encoder (lossless modular mode).
|
Package enc implements a JPEG XL encoder (lossless modular mode). |
|
entropy
Package entropy implements the JPEG XL entropy decoder: ANS and prefix codes, hybrid integer coding, LZ77 and context clustering.
|
Package entropy implements the JPEG XL entropy decoder: ANS and prefix codes, hybrid integer coding, LZ77 and context clustering. |
|
exif
Package exif reads and resets the orientation tag of Exif data in TIFF format (as in PNG eXIf chunks, JPEG APP1 segments after "Exif\0\0" and JPEG XL Exif boxes after their offset field).
|
Package exif reads and resets the orientation tag of Exif data in TIFF format (as in PNG eXIf chunks, JPEG APP1 segments after "Exif\0\0" and JPEG XL Exif boxes after their offset field). |
|
jpeg
Package jpeg parses JPEG files down to quantised DCT coefficients (baseline and progressive Huffman coding) and records everything needed to reproduce the file bit-exactly from those coefficients (the data that JPEG XL stores in its 'jbrd' box).
|
Package jpeg parses JPEG files down to quantised DCT coefficients (baseline and progressive Huffman coding) and records everything needed to reproduce the file bit-exactly from those coefficients (the data that JPEG XL stores in its 'jbrd' box). |
|
metric
Package metric implements image quality metrics.
|
Package metric implements image quality metrics. |
|
pngx
Package pngx adds small extensions to PNG files produced by image/png.
|
Package pngx adds small extensions to PNG files produced by image/png. |
|
pnm
Package pnm reads and writes the Netpbm formats: PGM and PPM (binary P5 and P6, plain P2 and P3), PAM (P7) and PFM (Pf, PF).
|
Package pnm reads and writes the Netpbm formats: PGM and PPM (binary P5 and P6, plain P2 and P3), PAM (P7) and PFM (Pf, PF). |
|
tiff
Package tiff reads baseline TIFF images (the first image of a file): 1-16 bit grey, palette and RGB samples with optional alpha, stored in strips or tiles, chunky or planar, uncompressed or compressed with LZW, Deflate or PackBits (with the horizontal differencing predictor).
|
Package tiff reads baseline TIFF images (the first image of a file): 1-16 bit grey, palette and RGB samples with optional alpha, stored in strips or tiles, chunky or planar, uncompressed or compressed with LZW, Deflate or PackBits (with the horizontal differencing predictor). |
|
webp
Package webp decodes WebP images: lossless (VP8L) and lossy (VP8) bitstreams, alpha, metadata and animations in the RIFF container.
|
Package webp decodes WebP images: lossless (VP8L) and lossy (VP8) bitstreams, alpha, metadata and animations in the RIFF container. |