This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
forked from chai2010/webp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebp.go
78 lines (66 loc) · 1.88 KB
/
webp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2014 <chaishushan{AT}gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package webp
import (
"image"
)
func GetInfo(data []byte) (width, height int, hasAlpha bool, err error) {
return webpGetInfo(data)
}
func DecodeGray(data []byte) (m *image.Gray, err error) {
pix, w, h, err := webpDecodeGray(data)
if err != nil {
return
}
m = &image.Gray{
Pix: pix,
Stride: 1 * w,
Rect: image.Rect(0, 0, w, h),
}
return
}
func DecodeRGB(data []byte) (m image.Image, err error) {
pix, w, h, err := webpDecodeRGB(data)
if err != nil {
return
}
m = &_RGB{
_Pix: pix,
_Stride: 3 * w,
_Rect: image.Rect(0, 0, w, h),
}
return
}
func DecodeRGBA(data []byte) (m *image.RGBA, err error) {
pix, w, h, err := webpDecodeRGBA(data)
if err != nil {
return
}
m = &image.RGBA{
Pix: pix,
Stride: 4 * w,
Rect: image.Rect(0, 0, w, h),
}
return
}
func EncodeGray(m *image.Gray, quality float32) (data []byte, err error) {
return webpEncodeGray(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride, quality)
}
func EncodeRGB(m image.Image, quality float32) (data []byte, err error) {
p := newRGBFromImage(m)
return webpEncodeRGB(p._Pix, p._Rect.Dx(), p._Rect.Dy(), p._Stride, quality)
}
func EncodeRGBA(m *image.RGBA, quality float32) (data []byte, err error) {
return webpEncodeRGBA(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride, quality)
}
func EncodeLosslessGray(m *image.Gray) (data []byte, err error) {
return webpEncodeLosslessGray(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride)
}
func EncodeLosslessRGB(m image.Image) (data []byte, err error) {
p := newRGBFromImage(m)
return webpEncodeLosslessRGB(p._Pix, p._Rect.Dx(), p._Rect.Dy(), p._Stride)
}
func EncodeLosslessRGBA(m *image.RGBA) (data []byte, err error) {
return webpEncodeLosslessRGBA(m.Pix, m.Rect.Dx(), m.Rect.Dy(), m.Stride)
}