github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/image/webp/webp.go (about) 1 // Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Package webp implements a decoder and encoder for WEBP images. 6 // 7 // WEBP is defined at: 8 // https://developers.google.com/speed/webp/docs/riff_container 9 package webp 10 11 import ( 12 "image" 13 14 image_ext "github.com/chai2010/gopkg/image" 15 ) 16 17 func GetInfo(data []byte) (width, height int, hasAlpha bool, err error) { 18 return webpGetInfo(data) 19 } 20 21 func DecodeGray(data []byte) (m *image.Gray, err error) { 22 pix, w, h, err := webpDecodeGray(data) 23 if err != nil { 24 return 25 } 26 m = &image.Gray{pix, 1 * w, image.Rect(0, 0, w, h)} 27 return 28 } 29 30 func DecodeRGB(data []byte) (m *image_ext.RGB, err error) { 31 pix, w, h, err := webpDecodeRGB(data) 32 if err != nil { 33 return 34 } 35 m = &image_ext.RGB{pix, 3 * w, image.Rect(0, 0, w, h)} 36 return 37 } 38 39 func DecodeRGBA(data []byte) (m *image.RGBA, err error) { 40 pix, w, h, err := webpDecodeRGBA(data) 41 if err != nil { 42 return 43 } 44 m = &image.RGBA{pix, 4 * w, image.Rect(0, 0, w, h)} 45 return 46 } 47 48 func EncodeGray(m *image.Gray, quality float32) (data []byte, err error) { 49 return webpEncodeGray(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride, quality) 50 } 51 52 func EncodeRGB(m *image_ext.RGB, quality float32) (data []byte, err error) { 53 return webpEncodeRGB(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride, quality) 54 } 55 56 func EncodeRGBA(m *image.RGBA, quality float32) (data []byte, err error) { 57 return webpEncodeRGBA(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride, quality) 58 } 59 60 func EncodeLosslessGray(m *image.Gray) (data []byte, err error) { 61 return webpEncodeLosslessGray(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride) 62 } 63 64 func EncodeLosslessRGB(m *image_ext.RGB) (data []byte, err error) { 65 return webpEncodeLosslessRGB(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride) 66 } 67 68 func EncodeLosslessRGBA(m *image.RGBA) (data []byte, err error) { 69 return webpEncodeLosslessRGBA(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride) 70 }