WebP encoder

2,058 views
Skip to first unread message

canop

unread,
Dec 1, 2011, 9:51:03 AM12/1/11
to golang-nuts
I'm using the PNG encoder/decoder a lot in situations where size and
speed matter and I'd like to try the WebP format.

Is there somewhere a (complete or partial) implementation of a
(lossless) encoder and decoder that could be compatible with weekly
(or forkable) ?

Nigel Tao

unread,
Dec 1, 2011, 7:54:09 PM12/1/11
to canop, golang-nuts
On 2 December 2011 01:51, canop <cano.p...@gmail.com> wrote:
> Is there somewhere a (complete or partial) implementation of a
> (lossless) encoder and decoder that could be compatible with weekly
> (or forkable) ?

http://code.google.com/p/vp8-go/ has a WebP decoder, but only for the
lossy form. I don't think the bitstream for lossless WebP has been
finalized.

Doing an encoder is also is on my TODO list, but I haven't had much
spare time lately.

Kamoliddin Mavlonov

unread,
Jul 26, 2014, 8:39:58 AM7/26/14
to golan...@googlegroups.com, cano.p...@gmail.com
Hi Nigel,

Any news? We need webp encoder :)

chai2010

unread,
Jul 26, 2014, 9:19:30 AM7/26/14
to Kamoliddin Mavlonov, golang-nuts, cano.p...@gmail.com
Hi, i create a webp package with libwebp.
It support lossless and RGB feature.



--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kamol

unread,
Jul 26, 2014, 9:37:21 AM7/26/14
to chai2010, golang-nuts, cano.p...@gmail.com
Thank you Chai2010!

Let me try and be back to you with my feedback :)

Cheers!

Kamol

unread,
Jul 26, 2014, 10:12:08 AM7/26/14
to chai2010, golang-nuts, cano.p...@gmail.com
Hi Chai2010

I am trying to import from "github.com/chai2010/gopkg/image/webp"
And on `go get`
it gives following errors:

../../chai2010/gopkg/image/convert/convert.go:62: m.Gray16At undefined (type *"image".Gray16 has no field or method Gray16At)
../../chai2010/gopkg/image/convert/convert.go:69: m.RGBAAt undefined (type *"image".RGBA has no field or method RGBAAt)
../../chai2010/gopkg/image/convert/convert.go:75: m.RGBA64At undefined (type *"image".RGBA64 has no field or method RGBA64At)
../../chai2010/gopkg/image/convert/convert.go:105: m.GrayAt undefined (type *"image".Gray has no field or method GrayAt)
../../chai2010/gopkg/image/convert/convert.go:113: m.RGBAAt undefined (type *"image".RGBA has no field or method RGBAAt)
../../chai2010/gopkg/image/convert/convert.go:121: m.RGBA64At undefined (type *"image".RGBA64 has no field or method RGBA64At)
../../chai2010/gopkg/image/convert/convert.go:166: m.GrayAt undefined (type *"image".Gray has no field or method GrayAt)
../../chai2010/gopkg/image/convert/convert.go:177: m.Gray16At undefined (type *"image".Gray16 has no field or method Gray16At)
../../chai2010/gopkg/image/convert/convert.go:205: m.GrayAt undefined (type *"image".Gray has no field or method GrayAt)
../../chai2010/gopkg/image/convert/convert.go:216: m.Gray16At undefined (type *"image".Gray16 has no field or method Gray16At)
../../chai2010/gopkg/image/convert/convert.go:216: too many errors

Am I missing anything?

Regards
Kamol

Carlos Castillo

unread,
Jul 26, 2014, 5:45:35 PM7/26/14
to golan...@googlegroups.com, chais...@gmail.com, cano.p...@gmail.com
The <ColorType>At methods of the image types (eg: Gray16At) were added in go 1.3 to speed up image conversions. Which version of go are you using (try command: go version)?

Carlos Castillo

unread,
Jul 26, 2014, 5:49:04 PM7/26/14
to golan...@googlegroups.com, chais...@gmail.com, cano.p...@gmail.com
Sorry, I didn't have my facts straight. The getters like Gray16At don't exist in go 1.3, only the setters like SetGray16, so you will have to be running go at tip to use this code.

Kamol

unread,
Jul 27, 2014, 8:26:25 AM7/27/14
to Carlos Castillo, golang-nuts, Shushan Chai, cano petrole
Hi Carlos,

I have updated my go version into latest one 1.3.
However, still the same:

➜  sushiobrol git:(master) ✗ go get
../../chai2010/gopkg/image/convert/convert.go:62: m.Gray16At undefined (type *"image".Gray16 has no field or method Gray16At)
../../chai2010/gopkg/image/convert/convert.go:69: m.RGBAAt undefined (type *"image".RGBA has no field or method RGBAAt)
../../chai2010/gopkg/image/convert/convert.go:75: m.RGBA64At undefined (type *"image".RGBA64 has no field or method RGBA64At)
../../chai2010/gopkg/image/convert/convert.go:105: m.GrayAt undefined (type *"image".Gray has no field or method GrayAt)
../../chai2010/gopkg/image/convert/convert.go:113: m.RGBAAt undefined (type *"image".RGBA has no field or method RGBAAt)
../../chai2010/gopkg/image/convert/convert.go:121: m.RGBA64At undefined (type *"image".RGBA64 has no field or method RGBA64At)
../../chai2010/gopkg/image/convert/convert.go:166: m.GrayAt undefined (type *"image".Gray has no field or method GrayAt)
../../chai2010/gopkg/image/convert/convert.go:177: m.Gray16At undefined (type *"image".Gray16 has no field or method Gray16At)
../../chai2010/gopkg/image/convert/convert.go:205: m.GrayAt undefined (type *"image".Gray has no field or method GrayAt)
../../chai2010/gopkg/image/convert/convert.go:216: m.Gray16At undefined (type *"image".Gray16 has no field or method Gray16At)
../../chai2010/gopkg/image/convert/convert.go:216: too many errors
➜  sushiobrol git:(master) ✗ go version
go version go1.3 darwin/amd64



--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/gZ-PCUGw7Rk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

Carlos Castillo

unread,
Jul 27, 2014, 9:44:45 AM7/27/14
to Kamol, golang-nuts, Shushan Chai, cano petrole
As I mentioned in my later message, the package requires go at tip, as it uses changes to the image package which will probably appear in go 1.4. This means that you have to build go from the source in the mercurial repository (http://golang.org/doc/install/source + Switch to default branch) to use the package in its current state.

My "go version" which builds successfully: go version devel +fda4c0d14c53 Sat Jul 26 17:46:51 2014 -0400 darwin/amd64

You can either upgrade, wait for 1.4 in several months, or file an issue with the maintainer of the package asking for a version that can compile against go 1.3 (but might be slower). You can file an issue at: https://github.com/chai2010/gopkg/issues
--
Carlos Castillo

Kamol

unread,
Jul 27, 2014, 10:37:26 AM7/27/14
to Carlos Castillo, golang-nuts, Shushan Chai, cano petrole
Hi Carlos,

Thank you for your help.

Btw, I have installed from source code and I am in default branch:

➜  ~GOROOT  hg branches
default                    20469:fda4c0d14c53
release-branch.go1.3       20171:a3a06e67a23a
release-branch.go1.2       18502:9c4fdd8369ca
release-branch.go1.1       16840:414057ac1f1f
release-branch.go1         13681:d5666bad617d
release-branch.r60          9516:c1702f36df03
release-branch.r59          9023:d5785050f61d
release-branch.r58          8741:acaddf1cea75
release-branch.r57          8306:9d7967223815

Which is the same as yours, isn't it?

Am I missing something?

➜  ~GOROOT  go version
go version go1.3 darwin/amd64
➜  ~GOROOT  which go
/Users/kamol/work/go/go/bin/go
➜  ~GOROOT  gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix


Carlos Castillo

unread,
Jul 27, 2014, 3:49:21 PM7/27/14
to Kamol, golang-nuts, Shushan Chai, cano petrole
"hg branches" just lists the branches, to switch you need to run "hg update default" (as shown in the source install document).
 
To see which branch you currently are on use "hg branch".

At the time I posted my version, and since then, no updates to the main go source tree have been made, so yes, I was using the most recent version of go shown in the branches list.

Also remember to re-run ./all.bash in the src dir after switching branches!


--
Carlos Castillo

Kamol

unread,
Jul 27, 2014, 5:45:20 PM7/27/14
to Carlos Castillo, golang-nuts, Shushan Chai, cano petrole
You are right Carlos.

➜  ~GOROOT  hg update default
➜  ~GOROOT  hg update default
597 files updated, 0 files merged, 50 files removed, 0 files unresolved
➜  ~GOROOT  hg branch
default
➜  ~GOROOT  cd src
➜  src  ./all.bash
# Building C bootstrap tool.
cmd/dist
...

However, now I am getting some C error:
➜  sushiobrol git:(master) ✗ go get
In file included from ../../chai2010/gopkg/image/webp/capi.go:10:
./libwebp/include/webp.h:15:23: error: unknown type name 'size_t'
        const uint8_t* data, size_t data_size,
                             ^
./libwebp/include/webp.h:21:23: error: unknown type name 'size_t'
        const uint8_t* data, size_t data_size,
                             ^
./libwebp/include/webp.h:25:23: error: unknown type name 'size_t'
        const uint8_t* data, size_t data_size,
                             ^
./libwebp/include/webp.h:29:23: error: unknown type name 'size_t'
        const uint8_t* data, size_t data_size,
                             ^
./libwebp/include/webp.h:33:1: error: unknown type name 'size_t'
size_t webpEncodeGray(
^
./libwebp/include/webp.h:37:1: error: unknown type name 'size_t'
size_t webpEncodeRGB(
^
./libwebp/include/webp.h:41:1: error: unknown type name 'size_t'
size_t webpEncodeRGBA(
^
./libwebp/include/webp.h:46:1: error: unknown type name 'size_t'
size_t webpEncodeLosslessGray(
^
./libwebp/include/webp.h:50:1: error: unknown type name 'size_t'
size_t webpEncodeLosslessRGB(
^
./libwebp/include/webp.h:54:1: error: unknown type name 'size_t'
size_t webpEncodeLosslessRGBA(
^

It might be my Yosemite gcc version is old...

Carlos Castillo

unread,
Jul 27, 2014, 6:05:26 PM7/27/14
to Kamol, golang-nuts, Shushan Chai, cano petrole
If you are using a recent version of OSX, you probably don't actually have gcc. There is a gcc program installed with the xcode-tools but it just secretly runs clang. 

I was able to fix it by modifying the libwebp/include/webp.h file to have an extra include for stdlib.h (after stdint.h) since it's needed for the definition of size_t.

Honestly though, this package needs fixing, since it only builds at tip, not on any earlier version, including the current release version, and wasn't tested very well.

On Sunday, July 27, 2014, Kamol <kamo...@gmail.com> wrote:


--
Carlos Castillo

Kamol

unread,
Jul 27, 2014, 6:50:21 PM7/27/14
to Carlos Castillo, golang-nuts, Shushan Chai, cano petrole
Carlos,

You are absolutely right! 

//If you are using a recent version of OSX, you probably don't actually have gcc. There is a gcc program installed with the xcode-tools but it just secretly runs clang. 
Yes!

//I was able to fix it by modifying the libwebp/include/webp.h file to have an extra include for stdlib.h (after stdint.h) since it's needed for the definition of size_t.
Yes!

//Honestly though, this package needs fixing, since it only builds at tip, not on any earlier version, including the current release version, and wasn't tested very well.
And yes!

Thank you Carlos!

chai2010

unread,
Jul 27, 2014, 9:35:39 PM7/27/14
to Carlos Castillo, Kamol, golang-nuts, cano petrole
2014-07-28 6:04 GMT+08:00 Carlos Castillo <cook...@gmail.com>:
If you are using a recent version of OSX, you probably don't actually have gcc. There is a gcc program installed with the xcode-tools but it just secretly runs clang. 

I was able to fix it by modifying the libwebp/include/webp.h file to have an extra include for stdlib.h (after stdint.h) since it's needed for the definition of size_t.
fixed. 

Honestly though, this package needs fixing, since it only builds at tip, not on any earlier version, including the current release version, and wasn't tested very well.
This pkg and depends pkg only support tip (need RGBAAt, Gray16At, etc.).

Kamol

unread,
Jul 27, 2014, 10:40:08 PM7/27/14
to chai2010, Carlos Castillo, golang-nuts, cano petrole
Thank you chai2010 for update!

chai2010

unread,
Jul 28, 2014, 10:05:42 PM7/28/14
to Kamol, Carlos Castillo, golang-nuts, cano petrole
Hi Kamol,

This is a standalone pkg for webp:

This pkg don't support decode/encode RGB model.


2014-07-28 10:39 GMT+08:00 Kamol <kamo...@gmail.com>:
Thank you chai2010 for update!

Aarti Parikh

unread,
Sep 22, 2016, 2:27:58 PM9/22/16
to golang-nuts, cano.p...@gmail.com
Is webp encoding in pure go something that may happen in a future release?

Nigel Tao

unread,
Sep 22, 2016, 9:49:37 PM9/22/16
to Aarti Parikh, golang-nuts, cano petrole
On Fri, Sep 23, 2016 at 4:18 AM, Aarti Parikh <aarti....@gmail.com> wrote:
> Is webp encoding in pure go something that may happen in a future release?

I'd like to see that, but I have higher priority things to work on.

Jeffrey

unread,
Dec 28, 2018, 6:58:32 AM12/28/18
to golang-nuts
any update? need pure go implement for webp encoder indeed


Jeffrey

unread,
Dec 30, 2018, 12:08:21 AM12/30/18
to golang-nuts
since the libwebp has released the version 1.0.0, so it's time to port it to pure golang

Mandolyte

unread,
Jan 1, 2019, 9:30:31 AM1/1/19
to golang-nuts
You might consider one of the projects that "transpile" C to Go. Might give you a jump start. For reference, here are two of them:
Reply all
Reply to author
Forward
0 new messages