WebP decoder and encoder for Go (Zero Dependencies).
Clone or download
Latest commit 76ae9d0 Nov 6, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bench bench: add build tag for go1.6+, (depends on Go1.6 image.NYCbCrA) Apr 27, 2016
fuzz add fuzz Feb 12, 2016
internal Updates for PR feedback. Apr 26, 2016
testdata Adding large lossy photo and additional benchmarks. Apr 26, 2016
.gitattributes Update .gitattributes Nov 6, 2018
.gitignore add RGBImage and RGBColor Jul 22, 2015
.travis.yml try fix travis-ci for Go1.5 test Apr 27, 2016
LICENSE add LICENSE Oct 1, 2014
README.md revert hello.go Feb 11, 2016
bench_test.go Updates for PR feedback. Apr 26, 2016
capi.c simplify CGO code Feb 23, 2016
capi.go Updates for PR feedback. Apr 26, 2016
cgo.go export c api Jul 28, 2016
doc.go update doc Aug 9, 2015
gen.go support go generate Oct 13, 2014
gen_helper.go fix build if cgo is disabled (go test will fail). Nov 26, 2014
go.mod add go.mod for vgo Mar 1, 2018
hello.go revert hello.go Feb 11, 2016
image.go fix typo Apr 27, 2016
image_color.go add ColorModelInterface Feb 24, 2017
image_example_test.go fix typo Apr 27, 2016
image_pix_slice.go fix typo Apr 27, 2016
reader.go simplify webpDecodeRGBA and fix test Feb 11, 2016
reader_example_test.go simplify webpDecodeRGBA and fix test Feb 11, 2016
reader_test.go Avoid pass Go pointers from crossing the boundary into C in Go1.3. Aug 6, 2014
rgb.go sync MemPImage Aug 5, 2015
rgb48.go sync RGB48Image Aug 5, 2015
testing_test.go add testing helper Feb 11, 2016
webp.go Updates for PR feedback. Apr 26, 2016
webp_decode.go hide new CGO func Feb 12, 2016
webp_decode_test.go hide new CGO func Feb 12, 2016
webp_example_test.go remove CBuffer Feb 12, 2016
webp_test.go reduce maxWebpHeaderSize, and add test for webpGetInfo Oct 15, 2014
writer.go simplify CGO code and fix test Feb 12, 2016
writer_example_test.go simplify CGO code and fix test Feb 12, 2016
writer_test.go fix test Oct 10, 2014
z_libwebp_src_dec_alpha.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_buffer.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_frame.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_idec.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_io.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_quant.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_tree.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_vp8.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_vp8l.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dec_webp.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_demux_demux.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_alpha_processing.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_cpu.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_dec.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_dec_clip_tables.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_dec_mips32.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_dec_neon.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_dec_sse2.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_enc.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_enc_avx2.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_enc_mips32.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_enc_neon.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_enc_sse2.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_lossless.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_lossless_mips32.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_lossless_neon.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_lossless_sse2.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_upsampling.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_upsampling_neon.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_upsampling_sse2.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_yuv.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_yuv_mips32.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_dsp_yuv_sse2.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_alpha.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_analysis.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_backward_references.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_config.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_cost.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_filter.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_frame.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_histogram.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_iterator.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_picture.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_picture_csp.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_picture_psnr.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_picture_rescale.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_picture_tools.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_quant.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_syntax.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_token.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_tree.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_vp8l.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_enc_webpenc.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_mux_muxedit.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_mux_muxinternal.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_mux_muxread.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_bit_reader.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_bit_writer.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_color_cache.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_filters.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_huffman.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_huffman_encode.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_quant_levels.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_quant_levels_dec.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_random.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_rescaler.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_thread.c fix build if cgo is disabled (go test will fail). Nov 26, 2014
z_libwebp_src_utils_utils.c fix build if cgo is disabled (go test will fail). Nov 26, 2014

README.md

webp

██╗    ██╗███████╗██████╗ ██████╗
██║    ██║██╔════╝██╔══██╗██╔══██╗
██║ █╗ ██║█████╗  ██████╔╝██████╔╝
██║███╗██║██╔══╝  ██╔══██╗██╔═══╝
╚███╔███╔╝███████╗██████╔╝██║
 ╚══╝╚══╝ ╚══════╝╚═════╝ ╚═╝

Build Status GoDoc

Benchmark

Install

Install GCC or MinGW (download here) at first, and then run these commands:

  1. go get github.com/chai2010/webp
  2. go run hello.go

Example

This is a simple example:

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"log"

	"github.com/chai2010/webp"
)

func main() {
	var buf bytes.Buffer
	var width, height int
	var data []byte
	var err error

	// Load file data
	if data, err = ioutil.ReadFile("./testdata/1_webp_ll.webp"); err != nil {
		log.Println(err)
	}

	// GetInfo
	if width, height, _, err = webp.GetInfo(data); err != nil {
		log.Println(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))
	if err != nil {
		log.Println(err)
	}

	// Encode lossless webp
	if err = webp.Encode(&buf, m, &webp.Options{Lossless: true}); err != nil {
		log.Println(err)
	}
	if err = ioutil.WriteFile("output.webp", buf.Bytes(), 0666); err != nil {
		log.Println(err)
	}
    
    fmt.Println("Save output.webp ok")
}

Decode and Encode as RGB format:

m, err := webp.DecodeRGB(data)
if err != nil {
	log.Fatal(err)
}

data, err := webp.EncodeRGB(m)
if err != nil {
	log.Fatal(err)
}

Notes

Change the libwebp to fast method:

internal/libwebp/src/enc/config.c
WebPConfigInitInternal
config->method = 0; // 4;

BUGS

Report bugs to chaishushan@gmail.com.

Thanks!