Documentation ¶
Overview ¶
Package webp provides an interface to libwebp library to decoding/encoding WebP image.
Index ¶
- Constants
- Variables
- func DecodeNRGBA(data []byte, options *DecoderOptions) (img *image.NRGBA, err error)
- func DecodeRGBA(data []byte, options *DecoderOptions) (img *image.RGBA, err error)
- func EncodeGray(w io.Writer, p *image.Gray, c *Config) (err error)
- func EncodeRGBA(w io.Writer, img image.Image, c *Config) (err error)
- func EncodeYUVA(w io.Writer, img *YUVAImage, c *Config) (err error)
- func GetDecoderVersion() (v int)
- func GetDestinationManagerMapLen() int
- func GetInfo(data []byte) (width, height int)
- type BitstreamFeatures
- type ColorSpace
- type Config
- func (c *Config) AlphaCompression() int
- func (c *Config) AlphaFiltering() int
- func (c *Config) AlphaQuality() int
- func (c *Config) AutoFilter() bool
- func (c *Config) EmulateJPEGSize() bool
- func (c *Config) Exact() bool
- func (c *Config) FilterSharpness() int
- func (c *Config) FilterStrength() int
- func (c *Config) FilterType() FilterType
- func (c *Config) ImageHint() ImageHint
- func (c *Config) Lossless() bool
- func (c *Config) LowMemory() bool
- func (c *Config) Method() int
- func (c *Config) NearLossless() int
- func (c *Config) PartitionLimit() int
- func (c *Config) Partitions() int
- func (c *Config) Pass() int
- func (c *Config) Preprocessing() Preprocessing
- func (c *Config) Quality() float32
- func (c *Config) SNSStrength() int
- func (c *Config) Segments() int
- func (c *Config) SetAlphaCompression(v int)
- func (c *Config) SetAlphaFiltering(v int)
- func (c *Config) SetAlphaQuality(v int)
- func (c *Config) SetAutoFilter(v bool)
- func (c *Config) SetEmulateJPEGSize(v bool)
- func (c *Config) SetExact(v bool)
- func (c *Config) SetFilterSharpness(v int)
- func (c *Config) SetFilterStrength(v int)
- func (c *Config) SetFilterType(v FilterType)
- func (c *Config) SetImageHint(v ImageHint)
- func (c *Config) SetLossless(v bool)
- func (c *Config) SetLowMemory(v bool)
- func (c *Config) SetMethod(v int)
- func (c *Config) SetNearLossless(v int)
- func (c *Config) SetPartitionLimit(v int)
- func (c *Config) SetPartitions(v int)
- func (c *Config) SetPass(v int)
- func (c *Config) SetPreprocessing(v Preprocessing)
- func (c *Config) SetQuality(v float32)
- func (c *Config) SetSNSStrength(v int)
- func (c *Config) SetSegments(v int)
- func (c *Config) SetTargetPSNR(v float32)
- func (c *Config) SetThreadLevel(v int)
- func (c *Config) TargetPSNR() float32
- func (c *Config) ThreadLevel() int
- type DecoderOptions
- type FilterType
- type ImageHint
- type Preprocessing
- type Preset
- type RGB
- type RGBImage
- type YUVAImage
Constants ¶
const ( // PreprocessingNone specifies to disable preprocessing filter. PreprocessingNone = 0 // PreprocessingSegmentSmooth specifies segment-smooth filter. PreprocessingSegmentSmooth = 1 //PreprocessingPseudoRandomDithering specifies pseudo-random dithering filter. PreprocessingPseudoRandomDithering = 2 )
Variables ¶
var RGBModel = color.ModelFunc(rgbModel)
RGBModel is RGB color model instance
Functions ¶
func DecodeNRGBA ¶
func DecodeNRGBA(data []byte, options *DecoderOptions) (img *image.NRGBA, err error)
DecodeNRGBA decodes WebP image into RGBA image and returns it as an *image.NRGBA.
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 ¶
EncodeRGBA encodes and writes image.Image into the writer as WebP. Now supports image.RGBA or image.NRGBA.
func EncodeYUVA ¶
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
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 {
// contains filtered or unexported fields
}
Config specifies WebP encoding configuration.
func ConfigLosslessPreset ¶
ConfigLosslessPreset returns initialized configuration for lossless encoding. Given level specifies desired efficiency level between 0 (fastest, lowest compression) and 9 (slower, best compression).
func ConfigPreset ¶
ConfigPreset returns initialized configuration with given preset and quality factor.
func (*Config) AlphaCompression ¶
AlphaCompression returns alpha compression parameter.
func (*Config) AlphaFiltering ¶
AlphaFiltering returns alpha filtering parameter.
func (*Config) AlphaQuality ¶
AlphaQuality returns alpha quality parameter.
func (*Config) EmulateJPEGSize ¶
EmulateJPEGSize returns the flag whether to enable emulating JPEG size.
func (*Config) FilterSharpness ¶
FilterSharpness returns filter sharpness parameter.
func (*Config) FilterStrength ¶
FilterStrength returns filter strength parameter.
func (*Config) FilterType ¶
func (c *Config) FilterType() FilterType
FilterType returns filter type parameter.
func (*Config) Lossless ¶
Lossless returns lossless parameter flag whether to enable lossless encoding.
func (*Config) NearLossless ¶
NearLossless returns near lossless encoding factor.
func (*Config) PartitionLimit ¶
PartitionLimit returns partition limit parameter.
func (*Config) Partitions ¶
Partitions returns partitions parameter.
func (*Config) Preprocessing ¶
func (c *Config) Preprocessing() Preprocessing
Preprocessing returns preprocessing filter.
func (*Config) SNSStrength ¶
SNSStrength returns SNS strength parameter.
func (*Config) SetAlphaCompression ¶
SetAlphaCompression sets alpha compression parameter.
func (*Config) SetAlphaFiltering ¶
SetAlphaFiltering sets alpha filtering parameter.
func (*Config) SetAlphaQuality ¶
SetAlphaQuality sets alpha quality parameter.
func (*Config) SetAutoFilter ¶
SetAutoFilter sets auto filter flag that specifies whether to auto adjust filter strength.
func (*Config) SetEmulateJPEGSize ¶
SetEmulateJPEGSize sets flag whether the compression parameters remaps to match the expected output size from JPEG compression.
func (*Config) SetExact ¶
SetExact sets the flag whether to preserve the exact RGB values under transparent area.
func (*Config) SetFilterSharpness ¶
SetFilterSharpness sets filter sharpness parameter between 0 (off) and 7 (least sharp).
func (*Config) SetFilterStrength ¶
SetFilterStrength sets filter strength parameter between 0 (off) and 100 (strongest).
func (*Config) SetFilterType ¶
func (c *Config) SetFilterType(v FilterType)
SetFilterType sets filter type parameter.
func (*Config) SetImageHint ¶
SetImageHint sets hint for image type. It is used to only lossless encoding for now.
func (*Config) SetLossless ¶
SetLossless sets lossless parameter that specifies whether to enable lossless encoding.
func (*Config) SetLowMemory ¶
SetLowMemory sets flag whether to reduce memory usage.
func (*Config) SetMethod ¶
SetMethod sets method parameter that specifies quality/speed trade-off (0=fast, 6=slower-better).
func (*Config) SetNearLossless ¶
SetNearLossless sets near lossless encoding factor between 0 (max loss) and 100 (disable near lossless encoding, default).
func (*Config) SetPartitionLimit ¶
SetPartitionLimit returns partition limit parameter.
func (*Config) SetPartitions ¶
SetPartitions sets partitions parameter.
func (*Config) SetPass ¶
SetPass sets pass parameter that specifies number of entropy-analysis passes between 1 and 10.
func (*Config) SetPreprocessing ¶
func (c *Config) SetPreprocessing(v Preprocessing)
SetPreprocessing sets preprocessing filter.
func (*Config) SetQuality ¶
SetQuality sets encoding quality factor between 0 (smallest file) and 100 (biggest).
func (*Config) SetSNSStrength ¶
SetSNSStrength sets SNS strength parameter between 0 (off) and 100 (maximum).
func (*Config) SetSegments ¶
SetSegments sets segments parameter that specifies the maximum number of segments to use, in [1..4].
func (*Config) SetTargetPSNR ¶
SetTargetPSNR sets target PSNR value that specifies the minimal distortion to try to achieve. If it sets 0, disable target PSNR.
func (*Config) SetThreadLevel ¶
SetThreadLevel sets thread level parameter. If non-zero value is specified, try and use multi-threaded encoding.
func (*Config) TargetPSNR ¶
TargetPSNR returns target PSNR value.
func (*Config) ThreadLevel ¶
ThreadLevel returns thread level parameter.
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 ImageHint ¶
type ImageHint int
ImageHint corresponds to C.WebPImageHint.
const ( HintDefault ImageHint = C.WEBP_HINT_DEFAULT HintPicture ImageHint = C.WEBP_HINT_PICTURE HintPhoto ImageHint = C.WEBP_HINT_PHOTO HintGraph ImageHint = C.WEBP_HINT_GRAPH HintLast ImageHint = C.WEBP_HINT_LAST )
type Preprocessing ¶
type Preprocessing int
Preprocessing corresponds to preprocessing filter parameter.
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 RGBImage ¶
type RGBImage struct { // Pix holds the image's stream, in R, G, B order. Pix []uint8 // Stride is the Pix stride (in bytes) between vertically adjacent pixels. Stride int // Rect is the image's bounds. Rect image.Rectangle }
RGBImage represent image data which has RGB colors. RGBImage is compatible with image.RGBA, but does not have alpha channel to reduce using memory.
func NewRGBImage ¶
NewRGBImage allocates and returns RGB image
func (*RGBImage) ColorModel ¶
ColorModel returns RGB color model.
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.