webp

package
v0.0.0-...-e06c707 Latest Latest
Warning

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

Go to latest
Published: May 12, 2016 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package webp provides an interface to libwebp library to decoding/encoding WebP image.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeRGBA

func DecodeRGBA(data []byte, options *DecoderOptions) (img *image.RGBA, err error)

DecodeRGBA decodes WebP image into RGBA image and returns it as an *image.RGBA.

func EncodeRGBA

func EncodeRGBA(w io.Writer, img image.Image, c Config) (err error)

EncodeRGBA encodes and writes image.Image into the writer as WebP. Now supports image.RGBA or image.NRGBA.

func EncodeYUVA

func EncodeYUVA(w io.Writer, img *YUVAImage, c Config) (err error)

EncodeYUVA encodes and writes YUVA Image data into the writer as WebP.

func GetDecoderVersion

func GetDecoderVersion() (v int)

GetDecoderVersion returns decoder's version number, packed in hexadecimal. e.g; v0.4.2 is 0x000402

func GetDestinationManagerMapLen

func GetDestinationManagerMapLen() int

GetDestinationManagerMapLen returns the number of globally working sourceManagers for debug

func GetInfo

func GetInfo(data []byte) (width, height int)

GetInfo retrives width/height from data bytes.

Types

type BitstreamFeatures

type BitstreamFeatures struct {
	Width        int  // Image width in pixels
	Height       int  // Image height in pixles
	HasAlpha     bool // True if data stream contains a alpha channel.
	HasAnimation bool // True if data stream is an animation
	Format       int  // Image compression format
}

BitstreamFeatures represents the image properties which are retrived from data stream.

func GetFeatures

func GetFeatures(data []byte) (f *BitstreamFeatures, err error)

GetFeatures returns features as BitstreamFeatures retrived from data stream.

type ColorSpace

type ColorSpace int

ColorSpace represents encoding color space in WebP

const (
	// YUV420 specifies YUV4:2:0
	YUV420 ColorSpace = C.WEBP_YUV420
	// YUV420A specifies YUV4:2:0 with alpha channel
	YUV420A ColorSpace = C.WEBP_YUV420A
)

type Config

type Config struct {
	Preset          Preset     // Parameters Preset
	Lossless        bool       // True if use lossless encoding
	Quality         float32    // WebP quality factor, 0-100
	Method          int        // Quality/Speed trade-off factor, 0=faster / 6=slower-better
	TargetSize      int        // Target size of encoded file in bytes
	TargetPSNR      float32    // Target PSNR, takes precedence over TargetSize
	Segments        int        // Maximum number of segments to use, 1..4
	SNSStrength     int        // Strength of spartial noise shaping, 0..100=maximum
	FilterStrength  int        // Strength of filter, 0..100=strength
	FilterSharpness int        // Sharpness of filter, 0..7=sharpness
	FilterType      FilterType // Filtering type
	Pass            int        // Number of entropy-analysis passes, 0..100
}

Config specifies WebP encoding configuration.

type DecoderOptions

type DecoderOptions struct {
	BypassFiltering        bool            // If true, bypass filtering process
	NoFancyUpsampling      bool            // If true, do not fancy upsampling
	Crop                   image.Rectangle // Do cropping if image.Rectangle is not empty.
	Scale                  image.Rectangle // Do scaling if image.Rectangle is not empty.
	UseThreads             bool            // If true, use multi threads
	DitheringStrength      int             // Specify dithering strength [0=Off .. 100=full]
	Flip                   bool            // If true, flip output vertically
	AlphaDitheringStrength int             // Specify alpha dithering strength in [0..100]
}

DecoderOptions specifies decoding options of WebP.

type FilterType

type FilterType int

FilterType corresponds to filter types in compression parameters.

const (
	// SimpleFilter (=0, default)
	SimpleFilter FilterType = iota
	// StrongFilter (=1)
	StrongFilter
)

type Preset

type Preset int

Preset corresponds to C.WebPPreset.

const (
	// PresetDefault corresponds to WEBP_PRESET_DEFAULT, for default preset.
	PresetDefault Preset = C.WEBP_PRESET_DEFAULT
	// PresetPicture corresponds to WEBP_PRESET_PICTURE, for digital picture, like portrait, inner shot
	PresetPicture Preset = C.WEBP_PRESET_PICTURE
	// PresetPhoto corresponds to WEBP_PRESET_PHOTO, for outdoor photograph, with natural lighting
	PresetPhoto Preset = C.WEBP_PRESET_PHOTO
	// PresetDrawing corresponds to WEBP_PRESET_DRAWING, for hand or line drawing, with high-contrast details
	PresetDrawing Preset = C.WEBP_PRESET_DRAWING
	// PresetIcon corresponds to WEBP_PRESET_ICON, for small-sized colorful images
	PresetIcon Preset = C.WEBP_PRESET_ICON
	// PresetText corresponds to WEBP_PRESET_TEXT, for text-like
	PresetText Preset = C.WEBP_PRESET_TEXT
)

type YUVAImage

type YUVAImage struct {
	Y, Cb, Cr, A []uint8
	YStride      int
	CStride      int
	AStride      int
	ColorSpace   ColorSpace
	Rect         image.Rectangle
}

YUVAImage represents a image of YUV colors with alpha channel image.

YUVAImage contains decoded YCbCr image data with alpha channel, but it is not compatible with image.YCbCr. Because, the RGB-YCbCr conversion that used in WebP is following to ITU-R BT.601 standard. In contrast, the conversion of Image.YCbCr (and color.YCbCrModel) is following to the JPEG standard (JFIF). If you need the image as image.YCBCr, you will first convert from WebP to RGB image, then convert from RGB image to JPEG's YCbCr image.

See: http://en.wikipedia.org/wiki/YCbCr

func DecodeYUVA

func DecodeYUVA(data []byte, options *DecoderOptions) (img *YUVAImage, err error)

DecodeYUVA decodes WebP image into YUV image with alpha channel, and returns it as *YUVAImage.

func NewYUVAImage

func NewYUVAImage(r image.Rectangle, c ColorSpace) (image *YUVAImage)

NewYUVAImage creates and allocates image buffer.

Jump to

Keyboard shortcuts

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