jpegli

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: BSD-3-Clause Imports: 16 Imported by: 0

README

jpegli

Status Go Reference

Go encoder/decoder for JPEG.

Based on jpegli from libjxl compiled to WASM and used with wazero runtime (CGo-free).

Benchmark

goos: linux
goarch: amd64
pkg: github.com/gen2brain/jpegli
cpu: 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz

BenchmarkDecodeStd-8       	     549	   2187227 ns/op	  407120 B/op	       7 allocs/op
BenchmarkDecode-8          	     554	   2172405 ns/op	  154672 B/op	      44 allocs/op

BenchmarkEncodeStd-8       	     260	   4601558 ns/op	    6109 B/op	       7 allocs/op
BenchmarkEncode-8          	     314	   3791604 ns/op	  394816 B/op	      13 allocs/op

BenchmarkEncodeRGBAStd-8   	     228	   5237803 ns/op	    9762 B/op	       8 allocs/op
BenchmarkEncodeRGBA-8      	     261	   4558648 ns/op	    4862 B/op	      13 allocs/op

Resources

Documentation

Overview

Package jpegli implements an JPEG image encoder/decoder based on jpegli compiled to WASM.

Index

Constants

View Source
const DefaultDCTMethod = DCTISlow

DefaultDCTMethod is the default DCT algorithm method.

View Source
const DefaultQuality = 75

DefaultQuality is the default quality encoding parameter.

Variables

View Source
var (
	ErrMemRead  = errors.New("jpegli: mem read failed")
	ErrMemWrite = errors.New("jpegli: mem write failed")
	ErrDecode   = errors.New("jpegli: decode failed")
	ErrEncode   = errors.New("jpegli: encode failed")
)

Errors .

Functions

func Decode

func Decode(r io.Reader) (image.Image, error)

Decode reads a JPEG image from r and returns it as an image.Image.

func DecodeConfig

func DecodeConfig(r io.Reader) (image.Config, error)

DecodeConfig returns the color model and dimensions of a JPEG image without decoding the entire image.

func DecodeWithOptions

func DecodeWithOptions(r io.Reader, o *DecodingOptions) (image.Image, error)

DecodeWithOptions reads a JPEG image from r with decoding options.

func Encode

func Encode(w io.Writer, m image.Image, o ...*EncodingOptions) error

Encode writes the image m to w with the given options.

Types

type DCTMethod

type DCTMethod int

DCTMethod is the DCT/IDCT method type.

const (
	// DCTISlow is slow but accurate integer algorithm
	DCTISlow DCTMethod = iota
	// DCTIFast is faster, less accurate integer method
	DCTIFast
	// DCTFloat is floating-point: accurate, fast on fast HW
	DCTFloat
)

type DecodingOptions

type DecodingOptions struct {
	// ScaleTarget is the target size to scale image.
	ScaleTarget image.Rectangle
	// Fancy upsampling.
	FancyUpsampling bool
	// Block smoothing.
	BlockSmoothing bool
	// Use arithmetic coding instead of Huffman.
	ArithCode bool
	// DCTMethod is DCT Algorithm method.
	DCTMethod DCTMethod
}

DecodingOptions are the decoding parameters.

type EncodingOptions

type EncodingOptions struct {
	// Quality in the range [0,100]. Default is 75.
	Quality int
	// Chroma subsampling setting, 444|440|422|420.
	ChromaSubsampling image.YCbCrSubsampleRatio
	// Progressive level in the range [0,2], where level 0 is sequential, and greater level value means more progression steps.
	ProgressiveLevel int
	// Huffman code optimization.
	// Enabled by default.
	OptimizeCoding bool
	// Uses adaptive quantization for creating more zero coefficients.
	// Enabled by default.
	AdaptiveQuantization bool
	// Use standard quantization tables from Annex K of the JPEG standard.
	// By default, jpegli uses a different set of quantization tables and different scaling parameters for DC and AC coefficients.
	StandardQuantTables bool
	// Apply fancy downsampling.
	FancyDownsampling bool
	// DCTMethod is the DCT algorithm method.
	DCTMethod DCTMethod
}

EncodingOptions are the encoding parameters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL