go-libwebp

Experimental translation from libwebp to Go source.
Log | Files | Refs | README | LICENSE

commit b2fb224c1f9613d70f27c7ac28a185acabc7901c
parent 6be5ab5f797e71adea62b6aec71b9bad343b7cf0
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Sat, 29 Jan 2022 19:27:42 +0800

webp: wrap x/image/webp for decoding

I attempted to decode with the translated code
but C was using inline instructions which is
not supported.

However, we can still offer a convenient decoding
interface by wrapping x/image/webp thus creating
a single unified package that can encode and decode.

Signed-off-by: Jack Mordaunt <jackmordaunt.dev@gmail.com>

Diffstat:
Mgo.mod | 2++
Mgo.sum | 3+++
Mwebp/decode.go | 11+++++++----
3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/go.mod b/go.mod @@ -4,6 +4,8 @@ go 1.17 require modernc.org/libc v1.14.5 +require golang.org/x/image v0.0.0-20211028202545-6944b10bf410 // indirect + require ( github.com/google/uuid v1.3.0 // indirect github.com/mattn/go-isatty v0.0.14 // indirect diff --git a/go.sum b/go.sum @@ -14,6 +14,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= +golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -33,6 +35,7 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8 golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= diff --git a/webp/decode.go b/webp/decode.go @@ -1,16 +1,19 @@ package webp import ( - "fmt" "image" "io" + + stdwebp "golang.org/x/image/webp" ) -// Decode a webp into an image. +// Decode reads a WEBP image from r and returns it as an image.Image. func Decode(r io.Reader) (image.Image, error) { - return nil, fmt.Errorf("unimplemented") + return stdwebp.Decode(r) } +// DecodeConfig returns the color model and dimensions of a WEBP image without +// decoding the entire image. func DecodeConfig(r io.Reader) (image.Config, error) { - return image.Config{}, fmt.Errorf("unimplemented") + return stdwebp.DecodeConfig(r) }