Documentation
¶
Overview ¶
Package webp implements a decoder and encoder for WEBP images.
WEBP is defined at: https://developers.google.com/speed/webp/docs/riff_container
Install ¶
Install `GCC` or `MinGW` (http://tdm-gcc.tdragon.net/download) at first, and then run these commands:
- `go get github.com/coalaura/webp`
- `go run hello.go`
Examples ¶
This is a simple example:
package main
import (
"bytes"
"fmt"
"os"
"log"
"github.com/coalaura/webp"
)
func main() {
var buf bytes.Buffer
var width, height int
var data []byte
var err error
// Load file data
if data, err = os.ReadFile("./testdata/1_webp_ll.webp"); err != nil {
log.Fatal(err)
}
// GetInfo
if width, height, _, err = webp.GetInfo(data); err != nil {
log.Fatal(err)
}
fmt.Printf("width = %d, height = %d\n", width, height)
// GetMetadata
if metadata, err := webp.GetMetadata(data, "ICCP"); err != nil {
fmt.Printf("Metadata: err = %v\n", err)
} else {
fmt.Printf("Metadata: %s\n", string(metadata))
}
// Decode webp
m, err := webp.Decode(bytes.NewReader(data), nil)
if err != nil {
log.Fatal(err)
}
// Encode lossless webp
if err = webp.Encode(&buf, m, &webp.Options{Lossless: true}); err != nil {
log.Fatal(err)
}
if err = os.WriteFile("output.webp", buf.Bytes(), 0666); err != nil {
log.Fatal(err)
}
fmt.Printf("Save output.webp ok\n")
}
Decode and Encode as RGB format:
m, err := webp.DecodeRGB(data, nil)
if err != nil {
log.Fatal(err)
}
data, err := webp.EncodeRGB(m, 90.0, 0)
if err != nil {
log.Fatal(err)
}
BUGS ¶
Report bugs to <[email protected]>.
Thanks!
Index ¶
- Constants
- func C_webpFree(p unsafe.Pointer)
- func C_webpMalloc(size C_size_t) unsafe.Pointer
- func ChannelsOf(m image.Image) int
- func ColorModel(channels int, dataType reflect.Kind) color.Model
- func Decode(r io.Reader, opt *DecodeOptions) (m image.Image, err error)
- func DecodeConfig(r io.Reader) (config image.Config, err error)
- func DecodeGray(data []byte, opt *DecodeOptions) (m *image.Gray, err error)
- func DecodeGrayToSize(data []byte, width, height int, opt *DecodeOptions) (m *image.Gray, err error)
- func DecodeRGBA(data []byte, opt *DecodeOptions) (m *image.RGBA, err error)
- func DecodeRGBAToSize(data []byte, width, height int, opt *DecodeOptions) (m *image.RGBA, err error)
- func DepthOf(m image.Image) int
- func Encode(w io.Writer, m image.Image, opt *Options) (err error)
- func EncodeAll(w io.Writer, anim *Animation, opt *Options) error
- func EncodeExactLosslessRGBA(m image.Image, method int) (data []byte, err error)
- func EncodeGray(m image.Image, quality float32, method int) (data []byte, err error)
- func EncodeLosslessGray(m image.Image, method int) (data []byte, err error)
- func EncodeLosslessRGB(m image.Image, method int) (data []byte, err error)
- func EncodeLosslessRGBA(m image.Image, method int) (data []byte, err error)
- func EncodeRGB(m image.Image, quality float32, method int) (data []byte, err error)
- func EncodeRGBA(m image.Image, quality float32, method int) (data []byte, err error)
- func GetInfo(data []byte) (width, height int, hasAlpha bool, hasAnimation bool, format int, err error)
- func GetMetadata(data []byte, format string) (metadata []byte, err error)
- func Load(name string) (m image.Image, err error)
- func LoadConfig(name string) (config image.Config, err error)
- func Save(name string, m image.Image, opt *Options) (err error)
- func SetMetadata(data, metadata []byte, format string) (newData []byte, err error)
- func SizeofImage(m image.Image) int
- func SizeofKind(dataType reflect.Kind) int
- func SizeofPixel(channels int, dataType reflect.Kind) int
- func WebPGetDecoderVersion() uint
- func WebPGetInfo(data []byte) (width, height int, ok bool)
- type Animation
- type C_double
- type C_float
- type C_int
- func C_webpDecodeGrayToSize(data *C_uint8_t, data_size C_size_t, width C_int, height C_int, ...) C_int
- func C_webpDecodeRGBAToSize(data *C_uint8_t, data_size C_size_t, width C_int, height C_int, ...) C_int
- func C_webpDecodeRGBToSize(data *C_uint8_t, data_size C_size_t, width C_int, height C_int, ...) C_int
- func C_webpGetInfo(data *C_uint8_t, data_size C_size_t, width *C_int, height *C_int, ...) C_int
- type C_int8_t
- type C_int16_t
- type C_int32_t
- type C_int64_t
- type C_size_t
- type C_uint
- type C_uint8_t
- func C_webpDecodeGray(data *C_uint8_t, data_size C_size_t, width *C_int, height *C_int) *C_uint8_t
- func C_webpDecodeRGB(data *C_uint8_t, data_size C_size_t, width *C_int, height *C_int) *C_uint8_t
- func C_webpDecodeRGBA(data *C_uint8_t, data_size C_size_t, width *C_int, height *C_int) *C_uint8_t
- func C_webpEncodeGray(pix *C_uint8_t, width C_int, height C_int, stride C_int, ...) *C_uint8_t
- func C_webpEncodeLosslessGray(pix *C_uint8_t, width C_int, height C_int, stride C_int, method C_int, ...) *C_uint8_t
- func C_webpEncodeLosslessRGB(pix *C_uint8_t, width C_int, height C_int, stride C_int, method C_int, ...) *C_uint8_t
- func C_webpEncodeLosslessRGBA(exact C_int, pix *C_uint8_t, width C_int, height C_int, stride C_int, ...) *C_uint8_t
- func C_webpEncodeRGB(pix *C_uint8_t, width C_int, height C_int, stride C_int, ...) *C_uint8_t
- func C_webpEncodeRGBA(pix *C_uint8_t, width C_int, height C_int, stride C_int, ...) *C_uint8_t
- type C_uint16_t
- type C_uint32_t
- type C_uint64_t
- type ColorModelInterface
- type Config
- type DecodeOptions
- type MemP
- type MemPColor
- type MemPImage
- func (p *MemPImage) AsStdImage() (m image.Image, ok bool)
- func (p *MemPImage) At(x, y int) color.Color
- func (p *MemPImage) Bounds() image.Rectangle
- func (p *MemPImage) Channels() int
- func (p *MemPImage) Clone() *MemPImage
- func (p *MemPImage) ColorModel() color.Model
- func (p *MemPImage) DataType() reflect.Kind
- func (p *MemPImage) MemPMagic() string
- func (p *MemPImage) Pix() []byte
- func (p *MemPImage) PixOffset(x, y int) int
- func (p *MemPImage) PixelAt(x, y int) []byte
- func (p *MemPImage) Set(x, y int, c color.Color)
- func (p *MemPImage) SetPixel(x, y int, c []byte)
- func (p *MemPImage) StdImage() image.Image
- func (p *MemPImage) Stride() int
- func (p *MemPImage) SubImage(r image.Rectangle) image.Image
- type Options
- type PixSlice
- func (d PixSlice) Bytes() (v []byte)
- func (d PixSlice) Complex64s() (v []complex64)
- func (d PixSlice) Complex128s() (v []complex128)
- func (d PixSlice) Float32s() (v []float32)
- func (d PixSlice) Float64s() (v []float64)
- func (d PixSlice) Int8s() (v []int8)
- func (d PixSlice) Int16s() (v []int16)
- func (d PixSlice) Int32s() (v []int32)
- func (d PixSlice) Int64s() (v []int64)
- func (d PixSlice) SetValue(i int, dataType reflect.Kind, v float64)
- func (d PixSlice) Slice(newSliceType reflect.Type) interface{}
- func (d PixSlice) SwapEndian(dataType reflect.Kind)
- func (d PixSlice) Uint8s() []uint8
- func (d PixSlice) Uint16s() (v []uint16)
- func (d PixSlice) Uint32s() (v []uint32)
- func (d PixSlice) Uint64s() (v []uint64)
- func (d PixSlice) Value(i int, dataType reflect.Kind) float64
- type RGB48Image
- func (p *RGB48Image) At(x, y int) color.Color
- func (p *RGB48Image) Bounds() image.Rectangle
- func (p *RGB48Image) Channels() int
- func (p *RGB48Image) ColorModel() color.Model
- func (p *RGB48Image) DataType() reflect.Kind
- func (p *RGB48Image) MemPMagic() string
- func (p *RGB48Image) Opaque() bool
- func (p *RGB48Image) Pix() []byte
- func (p *RGB48Image) PixOffset(x, y int) int
- func (p *RGB48Image) RGB48At(x, y int) [3]uint16
- func (p *RGB48Image) Set(x, y int, c color.Color)
- func (p *RGB48Image) SetRGB48(x, y int, c [3]uint16)
- func (p *RGB48Image) Stride() int
- func (p *RGB48Image) SubImage(r image.Rectangle) image.Image
- type RGBImage
- func (p *RGBImage) At(x, y int) color.Color
- func (p *RGBImage) Bounds() image.Rectangle
- func (p *RGBImage) Channels() int
- func (p *RGBImage) ColorModel() color.Model
- func (p *RGBImage) DataType() reflect.Kind
- func (p *RGBImage) MemPMagic() string
- func (p *RGBImage) Opaque() bool
- func (p *RGBImage) Pix() []byte
- func (p *RGBImage) PixOffset(x, y int) int
- func (p *RGBImage) RGBAt(x, y int) [3]uint8
- func (p *RGBImage) Set(x, y int, c color.Color)
- func (p *RGBImage) SetRGB(x, y int, c [3]uint8)
- func (p *RGBImage) Stride() int
- func (p *RGBImage) SubImage(r image.Rectangle) image.Image
- type SizeofImager
Examples ¶
Constants ¶
const DefaultAlphaQuality = 100
DefaultAlphaQuality is the default alpha plane quality used by Encode.
const DefaultMethod = 4
DefaultMethod is the default encoding method used by Encode.
const DefaultQuality = 90
DefaultQuality is the default lossy quality used by Encode.
const (
MemPMagic = "MemP" // See https://github.com/chai2010/image
)
MemPMagic is the magic string used by MemP images.
const (
WEBP_DECODER_ABI_VERSION = 0x0210 // MAJOR(8b) + MINOR(8b)
)
WEBP_DECODER_ABI_VERSION is the libwebp decoder ABI version.
Variables ¶
This section is empty.
Functions ¶
func C_webpFree ¶
func C_webpMalloc ¶
func ChannelsOf ¶
ChannelsOf returns the number of color channels in m.
func ColorModel ¶
ColorModel returns a color.Model for the given channels and data type.
Example ¶
rgba := color.RGBA{R: 101, G: 102, B: 103, A: 104}
c := ColorModel(4, reflect.Uint8).Convert(rgba).(MemPColor)
fmt.Printf("c = %v\n", c)
Output: c = {4 uint8 [101 102 103 104]}
func Decode ¶
Decode reads a WEBP image from r and returns it as an image.Image. If opt is nil, defaults are used.
func DecodeConfig ¶
DecodeConfig returns the color model and dimensions of a WEBP image without decoding the entire image.
func DecodeGray ¶
func DecodeGray(data []byte, opt *DecodeOptions) (m *image.Gray, err error)
DecodeGray decodes a WebP payload into a Gray image. If opt is nil, defaults are used.
func DecodeGrayToSize ¶
func DecodeGrayToSize(data []byte, width, height int, opt *DecodeOptions) (m *image.Gray, err error)
DecodeGrayToSize decodes a Gray image scaled to the given dimensions. For large images, the DecodeXXXToSize methods are significantly faster and require less memory compared to decoding a full-size image and then resizing it. If opt is nil, defaults are used.
func DecodeRGBA ¶
func DecodeRGBA(data []byte, opt *DecodeOptions) (m *image.RGBA, err error)
DecodeRGBA decodes a WebP payload into an RGBA image. If opt is nil, defaults are used.
func DecodeRGBAToSize ¶
func DecodeRGBAToSize(data []byte, width, height int, opt *DecodeOptions) (m *image.RGBA, err error)
DecodeRGBAToSize decodes an RGBA image scaled to the given dimensions. If opt is nil, defaults are used.
func Encode ¶
Encode writes the image m to w in WEBP format.
Example ¶
m, err := Load("./testdata/1_webp_ll.webp")
if err != nil {
log.Fatal(err)
}
var buf bytes.Buffer
if err := Encode(&buf, m, nil); err != nil {
log.Fatal(err)
}
_ = buf.Bytes()
Example (Lossless) ¶
m, err := Load("./testdata/1_webp_ll.webp")
if err != nil {
log.Fatal(err)
}
var buf bytes.Buffer
if err := Encode(&buf, m, &Options{Lossless: true}); err != nil {
log.Fatal(err)
}
_ = buf.Bytes()
Example (Rgb) ¶
rgb := NewRGBImage(image.Rect(0, 0, 400, 300))
var buf bytes.Buffer
if err := Encode(&buf, rgb, nil); err != nil {
log.Fatal(err)
}
_ = buf.Bytes()
Example (Rgb48MemP) ¶
rgb48 := NewMemPImage(image.Rect(0, 0, 400, 300), 3, reflect.Uint16)
var buf bytes.Buffer
if err := Encode(&buf, rgb48, nil); err != nil {
log.Fatal(err)
}
_ = buf.Bytes()
func EncodeAll ¶ added in v1.6.2
EncodeAll writes all frames in anim to w as an animated WEBP. Delay values are in milliseconds. If opt is nil, defaults are used.
func EncodeExactLosslessRGBA ¶
EncodeExactLosslessRGBA encodes lossless RGBA WebP and preserves RGB values in transparent areas.
func EncodeGray ¶
EncodeGray encodes an image as lossy grayscale WebP.
func EncodeLosslessGray ¶
EncodeLosslessGray encodes an image as lossless grayscale WebP.
func EncodeLosslessRGB ¶
EncodeLosslessRGB encodes an image as lossless RGB WebP.
func EncodeLosslessRGBA ¶
EncodeLosslessRGBA encodes an image as lossless RGBA WebP.
func EncodeRGBA ¶
EncodeRGBA encodes an image as lossy RGBA WebP.
func GetInfo ¶
func GetInfo(data []byte) (width, height int, hasAlpha bool, hasAnimation bool, format int, err error)
GetInfo returns image dimensions and WebP bitstream flags.
Example ¶
data := xLoadData("1_webp_a.webp")
width, height, hasAlpha, hasAnimation, format, err := GetInfo(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("width: %v\n", width)
fmt.Printf("height: %v\n", height)
fmt.Printf("hasAlpha: %v\n", hasAlpha)
fmt.Printf("hasAnimation: %v\n", hasAnimation)
fmt.Printf("format: %v\n", format)
Output: width: 400 height: 301 hasAlpha: true hasAnimation: false format: 0
Example (NoAlpha) ¶
data := xLoadData("video-001.webp")
width, height, hasAlpha, hasAnimation, format, err := GetInfo(data)
if err != nil {
log.Fatal(err)
}
fmt.Printf("width: %v\n", width)
fmt.Printf("height: %v\n", height)
fmt.Printf("hasAlpha: %v\n", hasAlpha)
fmt.Printf("hasAnimation: %v\n", hasAnimation)
fmt.Printf("format: %v\n", format)
Output: width: 150 height: 103 hasAlpha: false hasAnimation: false format: 1
func GetMetadata ¶
GetMetadata returns EXIF/ICCP/XMP metadata from a WebP payload.
func Load ¶
Load reads a WebP file from disk and returns it as an RGBA image.
Example ¶
m, err := Load("./testdata/1_webp_ll.webp")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Bounds = %v\n", m.Bounds())
Output: Bounds = (0,0)-(400,301)
func LoadConfig ¶
LoadConfig reads a file header and returns image.Config metadata.
Example ¶
cfg, err := LoadConfig("./testdata/1_webp_ll.webp")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Width = %d\n", cfg.Width)
fmt.Printf("Height = %d\n", cfg.Height)
Output: Width = 400 Height = 301
func Save ¶
Save encodes m as WebP and writes it to the named file.
Example ¶
tmpname := "z_test_ExampleSave.webp"
defer os.Remove(tmpname)
gray := NewMemPImage(image.Rect(0, 0, 400, 300), 1, reflect.Uint8)
if err := Save(tmpname, gray, &Options{Quality: 75}); err != nil {
log.Fatal(err)
}
func SetMetadata ¶
SetMetadata writes EXIF/ICCP/XMP metadata into a WebP payload.
func SizeofImage ¶
SizeofImage returns an approximate in-memory size for m.
func SizeofKind ¶
SizeofKind returns the size in bytes for the provided kind.
Example ¶
fmt.Printf("%v = %v\n", reflect.Uint8, SizeofKind(reflect.Uint8))
fmt.Printf("%v = %v\n", reflect.Uint16, SizeofKind(reflect.Uint16))
fmt.Printf("%v = %v\n", reflect.Uint32, SizeofKind(reflect.Uint32))
fmt.Printf("%v = %v\n", reflect.Float32, SizeofKind(reflect.Float32))
fmt.Printf("%v = %v\n", reflect.Float64, SizeofKind(reflect.Float64))
Output: uint8 = 1 uint16 = 2 uint32 = 4 float32 = 4 float64 = 8
func SizeofPixel ¶
SizeofPixel returns the size in bytes for a pixel of the given shape.
Example ¶
fmt.Printf("sizeof(gray) = %d\n", SizeofPixel(1, reflect.Uint8))
fmt.Printf("sizeof(gray16) = %d\n", SizeofPixel(1, reflect.Uint16))
fmt.Printf("sizeof(rgb) = %d\n", SizeofPixel(3, reflect.Uint8))
fmt.Printf("sizeof(rgb48) = %d\n", SizeofPixel(3, reflect.Uint16))
fmt.Printf("sizeof(rgba) = %d\n", SizeofPixel(4, reflect.Uint8))
fmt.Printf("sizeof(rgba64) = %d\n", SizeofPixel(4, reflect.Uint16))
fmt.Printf("sizeof(float32) = %d\n", SizeofPixel(1, reflect.Float32))
Output: sizeof(gray) = 1 sizeof(gray16) = 2 sizeof(rgb) = 3 sizeof(rgb48) = 6 sizeof(rgba) = 4 sizeof(rgba64) = 8 sizeof(float32) = 4
func WebPGetDecoderVersion ¶
func WebPGetDecoderVersion() uint
WebPGetDecoderVersion returns the decoder version packed in hex using 8 bits each for major/minor/revision.
func WebPGetInfo ¶
WebPGetInfo returns width and height from a WebP header and reports whether the header is valid.
Types ¶
type Animation ¶ added in v1.6.2
Animation represents an animated WebP image. Delay values are in milliseconds.
type C_int ¶
func C_webpDecodeGrayToSize ¶
func C_webpDecodeRGBAToSize ¶
func C_webpDecodeRGBToSize ¶
type C_uint8_t ¶
func C_webpDecodeGray ¶
func C_webpDecodeRGB ¶
func C_webpDecodeRGBA ¶
func C_webpEncodeGray ¶
func C_webpEncodeLosslessRGB ¶
func C_webpEncodeRGB ¶
type C_uint16_t ¶
type C_uint32_t ¶
type C_uint64_t ¶
type ColorModelInterface ¶
ColorModelInterface exposes channel count and data type for a color model.
type Config ¶ added in v1.6.2
type Config struct {
ColorModel color.Model
Width int // Width in pixels, as read from the bitstream.
Height int // Height in pixels, as read from the bitstream.
HasAlpha bool // True if the bitstream contains an alpha channel.
HasAnimation bool // True if the bitstream is an animation.
Format int // 0 = undefined (/mixed), 1 = lossy, 2 = lossless
}
Config is like image.Config with alpha and animation metadata.
func DecodeConfigEx ¶ added in v1.6.2
DecodeConfigEx returns the color model, dimensions and animation flag of a WEBP image without decoding the entire image.
func LoadConfigEx ¶ added in v1.6.2
LoadConfigEx reads a file header and returns Config metadata.
type DecodeOptions ¶ added in v1.6.3
type DecodeOptions struct {
UseThreads bool // Enable libwebp multi-threading (default true)
}
DecodeOptions controls WebP decoding behavior. A nil options value uses defaults.
type MemP ¶
type MemP interface {
MemPMagic() string
Bounds() image.Rectangle
Channels() int
DataType() reflect.Kind
Pix() []byte // PixSilce type
// Stride is the Pix stride (in bytes, must align with SizeofKind(p.DataType))
// between vertically adjacent pixels.
Stride() int
}
MemP defines a native-endian packed pixel format. See https://github.com/chai2010/image.
type MemPImage ¶
type MemPImage struct {
XMemPMagic string // MemP
XRect image.Rectangle
XChannels int
XDataType reflect.Kind
XPix PixSlice
XStride int
}
MemPImage stores pixels in a packed native-endian layout.
func AsMemPImage ¶
AsMemPImage wraps supported images as MemPImage without copying when possible. m may be a MemP implementation or a standard image type.
func NewMemPImage ¶
NewMemPImage allocates a MemPImage with the given bounds, channels, and data type.
func NewMemPImageFrom ¶
NewMemPImageFrom converts m into a MemPImage.
func (*MemPImage) AsStdImage ¶
AsStdImage returns a standard library image if p can be represented directly.
func (*MemPImage) ColorModel ¶
ColorModel returns the image's color model.
type Options ¶
type Options struct {
Lossless bool
Quality float32 // 0 ~ 100
TargetSize int // Target byte size (overrides Quality)
AlphaQuality int // Alpha plane quality 0-100 (default 100)
AutoFilter bool // Auto-adjust filter for each image
Exact bool // Preserve RGB values in transparent area.
Method int // Quality/speed trade-off (0=fast, 6=slower-better)
UseThreads bool // Enable libwebp multi-threading (default true)
}
Options are the encoding parameters.
type PixSlice ¶
type PixSlice []byte
PixSlice is a byte-backed view over pixel data.
func AsPixSilce ¶
func AsPixSilce(slice interface{}) (d PixSlice)
AsPixSilce converts a slice to a PixSlice view.
Convert []X to []byte:
x := make([]X, xLen) y := AsPixSilce(x)
Example ¶
a := []int32{101, 102, 103}
b := AsPixSilce(a)
b.Int32s()[0] = 12345
b.SetValue(1, reflect.Int32, 1002)
b.SetValue(2, reflect.Int32, 1003.5)
fmt.Printf("len(b) = %d\n", len(b))
fmt.Printf("b.Int32s() = %v\n", b.Int32s())
Output: len(b) = 12 b.Int32s() = [12345 1002 1003]
Example (SwapEndian) ¶
rgba64 := image.NewRGBA64(image.Rect(0, 0, 1, 1))
rgba64.SetRGBA64(0, 0, color.RGBA64{
R: 0x0102,
G: 0x0304,
B: 0x0506,
A: 0x0708,
})
// pix is big-endian format
fmt.Printf("big-endian: %v\n", rgba64.Pix)
AsPixSilce(rgba64.Pix).SwapEndian(reflect.Uint16)
fmt.Printf("little-endian: %v\n", rgba64.Pix)
Output: big-endian: [1 2 3 4 5 6 7 8] little-endian: [2 1 4 3 6 5 8 7]
func (PixSlice) Complex64s ¶
Complex64s reinterprets the data as []complex64.
func (PixSlice) Complex128s ¶
func (d PixSlice) Complex128s() (v []complex128)
Complex128s reinterprets the data as []complex128.
func (PixSlice) Slice ¶
Slice converts PixSlice to a slice of the provided type.
Convert []byte to []Y:
x := make([]byte, xLen) y := PixSlice(x).Slice(reflect.TypeOf([]Y(nil))).([]Y)
func (PixSlice) SwapEndian ¶
SwapEndian swaps byte order for elements of the provided kind.
type RGB48Image ¶
type RGB48Image struct {
XPix []uint8 // XPix use Native Endian (same as MemP) !!!
XStride int
XRect image.Rectangle
}
RGB48Image stores an RGB image with 16-bit channels in native endian order.
func NewRGB48Image ¶
func NewRGB48Image(r image.Rectangle) *RGB48Image
NewRGB48Image returns a new RGB48Image with the given bounds.
func NewRGB48ImageFrom ¶
func NewRGB48ImageFrom(m image.Image) *RGB48Image
NewRGB48ImageFrom converts m into an RGB48Image.
func (*RGB48Image) At ¶
func (p *RGB48Image) At(x, y int) color.Color
At returns the color of the pixel at (x, y).
func (*RGB48Image) Bounds ¶
func (p *RGB48Image) Bounds() image.Rectangle
Bounds returns the image bounds.
func (*RGB48Image) Channels ¶
func (p *RGB48Image) Channels() int
Channels returns the number of channels.
func (*RGB48Image) ColorModel ¶
func (p *RGB48Image) ColorModel() color.Model
ColorModel returns the image's color model.
func (*RGB48Image) DataType ¶
func (p *RGB48Image) DataType() reflect.Kind
DataType returns the underlying element kind.
func (*RGB48Image) MemPMagic ¶
func (p *RGB48Image) MemPMagic() string
MemPMagic returns the MemP magic string.
func (*RGB48Image) Opaque ¶
func (p *RGB48Image) Opaque() bool
Opaque scans the entire image and reports whether it is fully opaque.
func (*RGB48Image) PixOffset ¶
func (p *RGB48Image) PixOffset(x, y int) int
PixOffset returns the index of the first element of XPix that corresponds to the pixel at (x, y).
func (*RGB48Image) RGB48At ¶
func (p *RGB48Image) RGB48At(x, y int) [3]uint16
RGB48At returns the RGB values at (x, y).
func (*RGB48Image) Set ¶
func (p *RGB48Image) Set(x, y int, c color.Color)
Set sets the pixel at (x, y) to c.
func (*RGB48Image) SetRGB48 ¶
func (p *RGB48Image) SetRGB48(x, y int, c [3]uint16)
SetRGB48 sets the pixel at (x, y) to an RGB triplet.
func (*RGB48Image) Stride ¶
func (p *RGB48Image) Stride() int
Stride returns the byte stride between rows.
type RGBImage ¶
RGBImage stores an RGB image in packed 8-bit format.
func DecodeRGB ¶
func DecodeRGB(data []byte, opt *DecodeOptions) (m *RGBImage, err error)
DecodeRGB decodes a WebP payload into an RGBImage. If opt is nil, defaults are used.
func DecodeRGBToSize ¶
func DecodeRGBToSize(data []byte, width, height int, opt *DecodeOptions) (m *RGBImage, err error)
DecodeRGBToSize decodes an RGB image scaled to the given dimensions. If opt is nil, defaults are used.
func NewRGBImage ¶
NewRGBImage returns a new RGBImage with the given bounds.
func NewRGBImageFrom ¶
NewRGBImageFrom converts m into an RGBImage.
func (*RGBImage) ColorModel ¶
ColorModel returns the image's color model.
func (*RGBImage) PixOffset ¶
PixOffset returns the index of the first element of Pix that corresponds to the pixel at (x, y).
type SizeofImager ¶
type SizeofImager interface {
SizeofImage() int
}
SizeofImager reports the approximate size in bytes of an image.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package webp_bench provides more benchmark for webp.
|
Package webp_bench provides more benchmark for webp. |
|
See https://github.com/dvyukov/go-fuzz
|
See https://github.com/dvyukov/go-fuzz |
|
internal
|
|
