rez: github.com/bamiaux/rez Index | Files | Directories

package rez

import "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.

Index

Package Files

filters.go fixedscalers.go image.go kernels.go resize.go scalers.go scalers_amd64.go utils.go

Constants

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

func Convert Uses

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 Uses

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

DumpImage dumps each img planes to disk using the input prefix

func Psnr Uses

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

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

type ChromaRatio Uses

type ChromaRatio int

ChromaRatio is a chroma subsampling ratio

const (
    // Ratio411 is 4:1:1
    Ratio411 ChromaRatio = iota
    // 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 Uses

func GetRatio(value image.YCbCrSubsampleRatio) ChromaRatio

GetRatio returns a ChromaRatio from an image.YCbCrSubsampleRatio

type Converter Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (d *Descriptor) Check() error

Check returns whether the descriptor is valid

func (*Descriptor) GetHeight Uses

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

GetHeight returns the height in pixels for the input plane

func (*Descriptor) GetWidth Uses

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

GetWidth returns the width in pixels for the input plane

type Filter Uses

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 Uses

func NewBicubicFilter() Filter

NewBicubicFilter exports a classic bicubic filter

func NewBilinearFilter Uses

func NewBilinearFilter() Filter

NewBilinearFilter exports a bilinear filter

func NewCustomBicubicFilter Uses

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 Uses

func NewLanczosFilter(alpha int) Filter

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

type Plane Uses

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 Uses

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 Uses

func NewResize(cfg *ResizerConfig, filter Filter) Resizer

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

type ResizerConfig Uses

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

PathSynopsis
asm
rezgen

Package rez imports 7 packages (graph) and is imported by 8 packages. Updated 2017-04-19. Refresh now. Tools for package owners.