jpegenc

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

README

jpegenc

CGO bindings package for JPEGENC C library. All credits to its authors.

installation

go get github.com/Hypnotriod/jpegenc

usage

params := jpegenc.EncodeParams{
  QualityFactor: jpegenc.QualityFactorBest,
  PixelType:     jpegenc.PixelTypeRGB565,
  Subsample:     jpegenc.Subsample444,
}
buffer := make([]byte, max(1024, width*height))
// encode raw pixel bytes directly into buffer, no any data allocations/copying by encoder
bytesEncoded, err := jpegenc.Encode(width, height, params, pixelsRGB656[:], buffer)
err = os.WriteFile("file.jpg", buffer[:bytesEncoded], 0644)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidParameter   error = errors.New("jpegenc: invalid parameter")
	ErrEncodeError        error = errors.New("jpegenc: encode error")
	ErrMemoryError        error = errors.New("jpegenc: memory error")
	ErrNoBufferError      error = errors.New("jpegenc: no buffer error")
	ErrUnsupportedFeature error = errors.New("jpegenc: unsupported feature")
	ErrInvalidFile        error = errors.New("jpegenc: invalid file")
)

Functions

func Encode

func Encode(width int, height int, params EncodeParams, pixels []byte, buffer []byte) (bytesEncoded int, err error)

Types

type EncodeParams

type EncodeParams struct {
	QualityFactor QualityFactor
	PixelType     PixelType
	Subsample     Subsample
	ChromaSwap    bool
}

type ErrorCode

type ErrorCode int
const (
	Success                     ErrorCode = iota
	InvalidParameterErrorCode   ErrorCode = iota
	EncodeErrorCode             ErrorCode = iota
	MemoryErrorCode             ErrorCode = iota
	NoBufferErrorCode           ErrorCode = iota
	UnsupportedFeatureErrorCode ErrorCode = iota
	InvalidFileErrorCode        ErrorCode = iota
)

type PixelType

type PixelType int
const (
	PixelTypeGrayscale PixelType = iota
	PixelTypeRGB565    PixelType = iota
	PixelTypeRGB888    PixelType = iota
	PixelTypeARGB8888  PixelType = iota
)

type QualityFactor

type QualityFactor int
const (
	QualityFactorBest   QualityFactor = iota
	QualityFactorHigh   QualityFactor = iota
	QualityFactorMedium QualityFactor = iota
	QualityFactorLow    QualityFactor = iota
)

type Subsample

type Subsample int
const (
	Subsample444 Subsample = iota
	Subsample424 Subsample = iota
)

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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