rez

package module
Version: v0.0.0-...-29f4463 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2017 License: MIT Imports: 7 Imported by: 20

README

rez GoDoc Build Status

Package rez provides image resizing in pure Go and SIMD.

Download:

go get github.com/bamiaux/rez

Full documentation at http://godoc.org/github.com/bamiaux/rez


Package rez provides image resizing in pure Go and SIMD.

Featuring:

- YCbCr, RGBA, NRGBA & Gray resizes
- YCbCr Chroma subsample ratio conversions
- Optional interlaced-aware resizes
- Parallel resizes
- SIMD optimisations on AMD64

The easiest way to use it is:

err := Convert(output, input, NewBicubicFilter())

However, if you plan to convert video, where resize parameters are the same for multiple images, the best way is:

cfg, err := PrepareConversion(output, input)
converter, err := NewConverter(cfg, NewBicubicFilter())
for i := 0; i < N; i++ {
    err := converter.Convert(output[i], input[i])
}

Note that by default, images are resized in parallel with GOMAXPROCS slices. Best performance is obtained when GOMAXPROCS is at least equal to your CPU count.


Automatically generated by autoreadme on 2014.11.25

Documentation

Overview

Package rez provides image resizing in pure Go and SIMD.

Featuring:

- YCbCr, RGBA, NRGBA & Gray resizes
- YCbCr Chroma subsample ratio conversions
- Optional interlaced-aware resizes
- Parallel resizes
- SIMD optimisations on AMD64

The easiest way to use it is:

err := Convert(output, input, NewBicubicFilter())

However, if you plan to convert video, where resize parameters are the same for multiple images, the best way is:

cfg, err := PrepareConversion(output, input)
converter, err := NewConverter(cfg, NewBicubicFilter())
for i := 0; i < N; i++ {
    err := converter.Convert(output[i], input[i])
}

Note that by default, images are resized in parallel with GOMAXPROCS slices. Best performance is obtained when GOMAXPROCS is at least equal to your CPU count.

Index

Constants

View Source
const (
	// Bits exports the number of significant bits used by kernels
	Bits = 14
)

Variables

This section is empty.

Functions

func Convert

func Convert(output, input image.Image, filter Filter) error

Convert converts an input image into output, applying any color conversion and/or resizing, using the input filter for interpolation. Note that if you plan to do the same conversion over and over, it is faster to use a Converter interface

func DumpImage

func DumpImage(prefix string, img image.Image) error

DumpImage dumps each img planes to disk using the input prefix

func Psnr

func Psnr(a, b image.Image) ([]float64, error)

Psnr computes the PSNR between two input images Only ycbcr is currently supported

Types

type ChromaRatio

type ChromaRatio int

ChromaRatio is a chroma subsampling ratio

const (
	// Ratio410 is 4:1:0
	Ratio410 ChromaRatio = iota
	// Ratio411 is 4:1:1
	Ratio411
	// Ratio420 is 4:2:0
	Ratio420
	// Ratio422 is 4:2:2
	Ratio422
	// Ratio440 is 4:4:0
	Ratio440
	// Ratio444 is 4:4:4
	Ratio444
)

func GetRatio

func GetRatio(value image.YCbCrSubsampleRatio) ChromaRatio

GetRatio returns a ChromaRatio from an image.YCbCrSubsampleRatio

type Converter

type Converter interface {
	// Converts one image into another, applying any necessary colorspace
	// conversion and/or resizing
	// dst = destination image
	// src = source image
	// Result is undefined if src points to the same data as dst
	// Returns an error if the conversion fails
	Convert(dst, src image.Image) error
}

Converter is an interface that implements conversion between images It is currently able to convert only between ycbcr images

func NewConverter

func NewConverter(cfg *ConverterConfig, filter Filter) (Converter, error)

NewConverter returns a Converter interface cfg = converter configuration filter = filter used for resizing Returns an error if the conversion is invalid or not implemented

type ConverterConfig

type ConverterConfig struct {
	Input      Descriptor // input description
	Output     Descriptor // output description
	Threads    int        // number of allowed "threads"
	DisableAsm bool       // disable asm optimisations
}

ConverterConfig is a configuration used with NewConverter

func PrepareConversion

func PrepareConversion(output, input image.Image) (*ConverterConfig, error)

PrepareConversion returns a ConverterConfig properly set for a conversion from input images to output images Returns an error if the conversion is not possible

type Descriptor

type Descriptor struct {
	Width      int         // width in pixels
	Height     int         // height in pixels
	Ratio      ChromaRatio // chroma ratio
	Pack       int         // pixels per pack
	Interlaced bool        // progressive or interlaced
	Planes     int         // number of planes
}

Descriptor describes an image properties

func (*Descriptor) Check

func (d *Descriptor) Check() error

Check returns whether the descriptor is valid

func (*Descriptor) GetHeight

func (d *Descriptor) GetHeight(plane int) int

GetHeight returns the height in pixels for the input plane

func (*Descriptor) GetWidth

func (d *Descriptor) GetWidth(plane int) int

GetWidth returns the width in pixels for the input plane

type Filter

type Filter interface {
	Taps() int
	Name() string
	Get(dx float64) float64
}

Filter is an interpolation filter interface It is used to compute weights for every input pixel

func NewBicubicFilter

func NewBicubicFilter() Filter

NewBicubicFilter exports a classic bicubic filter

func NewBilinearFilter

func NewBilinearFilter() Filter

NewBilinearFilter exports a bilinear filter

func NewCustomBicubicFilter

func NewCustomBicubicFilter(b, c float64) Filter

NewCustomBicubicFilter exports a bicubic filter where <b> and <c> can be customized. For example, the Mitchell-Netravali bicubic filter is b = c = 1/3

func NewLanczosFilter

func NewLanczosFilter(alpha int) Filter

NewLanczosFilter exports a lanczos filter where <alpha> is filter size

type Plane

type Plane struct {
	Data   []byte // plane buffer
	Width  int    // width in pixels
	Height int    // height in pixels
	Pitch  int    // pitch in bytes
	Pack   int    // pixels per pack
}

Plane describes a single image plane

type Resizer

type Resizer interface {
	// Resize one plane into another
	// dst, src = destination and source buffer
	// width, height = plane dimensions in pixels
	// dstPitch, srcPitch = destination and source pitchs/strides in bytes
	Resize(dst, src []byte, width, height, dstPitch, srcPitch int)
}

Resizer is a interface that implements resizes

func NewResize

func NewResize(cfg *ResizerConfig, filter Filter) Resizer

NewResize returns a new resizer cfg = resize configuration filter = filter used for computing weights

type ResizerConfig

type ResizerConfig struct {
	Depth      int  // bits per pixel
	Input      int  // input size in pixels
	Output     int  // output size in pixels
	Vertical   bool // true for vertical resizes
	Interlaced bool // true if input/output is interlaced
	Pack       int  // pixels per pack [default=1]
	Threads    int  // number of threads, [default=0]
	DisableAsm bool // disable asm optimisations
}

ResizerConfig is a configuration used with NewResizer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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