tj3

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Go JPEG Encode and Decode via TurboJPEG v3

Simple JPEG Encoder and Decoder. Can often be used instead of Go's JPEG encoder and decoder:

 import (
-    "image/jpeg"
+    jpeg "github.com/fzwoch/tj3"
 )

or, if you only want the transparent decoding feature:

 import (
     "image"
-    _ "image/jpeg"
+    _ "github.com/fzwoch/tj3"
 )

Cgo

At build time of your application you will need to tell the Go compiler where to find the TurboJPEG header and library files. Check Go's cgo documentation for more details.

export CGO_CFLAGS="-I/path/to/libjpeg-turbo/header-files"
export CGO_LDFLAGS="-L/path/to/libjpeg-turbo/library"

For example, if your system has pkg-config, here is how to run tests:

CGO_CFLAGS=`pkg-config --cflags libturbojpeg` \
CGO_LDFLAGS=`pkg-config --libs libturbojpeg` \
go test -v

Benchmark

cpu: AMD Ryzen 7 5700X 8-Core Processor
BenchmarkDecodeYUV420_TurboJPEG-16    	    9301	    148467 ns/op
BenchmarkDecodeYUV420_GoJPEG-16       	    1293	    818696 ns/op
BenchmarkEncodeYUV420_TurboJPEG-16    	    7362	    155416 ns/op
BenchmarkEncodeYUV420_GoJPEG-16       	    1129	    972425 ns/op

Documentation

Overview

Package tj3 provides a simple JPEG decoder and encoder wrapper for the TurboJPEG v3 API and library.

Index

Constants

View Source
const DefaultQuality = 75

DefaultQuality is the default quality encoding parameter.

Variables

This section is empty.

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 Encode

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

Encode writes the Image m to w with the given options. Default parameters are used if a nil *Options is passed.

Types

type Options

type Options struct {
	Quality int
}

Options are the encoding parameters. Quality ranges from 1 to 100 inclusive, higher is better.

Jump to

Keyboard shortcuts

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