Git Product home page Git Product logo

webp's Introduction


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 [email protected].

Thanks!

webp's People

Contributors

chai2010 avatar coldnight avatar jjkoh95 avatar kamoljan avatar milosgagovic avatar pijushgupta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webp's Issues

Works on MacOS, but doesn't work on CoreOS

Error when run go build:

 # github.com/chai2010/webp/tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc.o: In function `GetPSNR':
/home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/./enc/picture_psnr.c:60: undefined reference to `log'
 /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc.o: In function `WebPPictureDistortion':
/home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/./enc/picture_psnr.c:137: undefined reference to `log10'
/tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_dsp_lossless.o: In function `FastSLog2Slow':
 /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/dsp/lossless.c:358: undefined reference to `log'
/tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_dsp_lossless.o: In function `FastLog2Slow':
/home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/dsp/lossless.c:383: undefined reference to `log'
/tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_frame.o: In function `GetPSNR':
/home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/frame.c:521: undefined reference to `log10'
/home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/frame.c:521: undefined reference to `log10'
/tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_picture_csp.o: In function `InitGammaTables':
/home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/picture_csp.c:110: undefined reference to `pow'
/home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/picture_csp.c:114: undefined reference to `pow'
/tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_quant.o: In function `QualityToCompression':
 /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/quant.c:297: undefined reference to `pow'
 /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_quant.o: In function `VP8SetSegmentParams':
 /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/quant.c:373: undefined reference to `pow'
 /tmp/go-build901091022/github.com/chai2010/webp/_obj/webp_enc_webpenc.o: In function `GetPSNR':
 /home/kamol/go/gocode/src/github.com/chai2010/webp/./libwebp/src/enc/webpenc.c:254: undefined reference to `log10'

OS(CoreOS) Version

 $ cat /etc/issue
 Fedora release 20 (Heisenbug)

Go Version

 $ go version
 go version devel +6acc2dd545b2 Thu Jul 31 12:55:40 2014 +0400 linux/amd64

Libwebp Version 0.4.0

Warning in picture_csp_enc.c related to XOR operation

Description:
When building my Go Fyne project which uses the github.com/chai2010/webp library, I encountered the following warning:

In file included from z_libwebp_src_enc_picture_csp_enc.c:9:
../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' (8)? [-Wxor-used-as-pow]
../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: note: replace expression with '0x2 ^ ALPHA_OFFSET' to silence this warning.

Steps to reproduce:

  1. Running the app or even building it with go build .
  2. fyne package and then run the executable

Environment:

  • Go version: 1.20.1
  • OS: MacOS 13.5.1

RGBA vs NRGBA

The webp libraries return non-premultiplied alpha values. This library wraps those values in RGBA structs which represent premultiplied values.

Everywhere RGBA{} is created with data returned by the webp decoder, it should be NRGBA{}.

e.g. this fixes one of them: https://github.com/chai2010/webp/compare/master...jamesshoebox:nrgba?expand=1

Here's a (very) simple program that illustrates the problem. If you pass in a webp with alpha, you'll see that it doesn't blend correctly with the white background.
https://gist.github.com/jamesshoebox/30ca5beada606842f98328481bf17f8d

对比cwebp命令行,带透明度png图片转换失真明显

使用下面代码进行png转webp

func ImgTowebp(imgData []byte) ([]byte, error) {
	//jpeg.Decode()
	img, err := jpeg.Decode(bytes.NewBuffer(imgData))
	if err != nil {
		//log.Println("decode error from jpg",err)
		img, err = png.Decode(bytes.NewBuffer(imgData))
		if err != nil {
			log.Println("decode error from png or jpg", err)
			return nil, err
		}
	}
	//log.Println(fname)
	webImgBytes, err := webp.EncodeRGBA(img, 80)
	if err == nil {
		webpLength := len(webImgBytes)
		imgLength := len(imgData)
		if webpLength > imgLength {
			log.Println("webp bigger than img")
		}
		log.Println("img2webp <webp size>:<img size>", webpLength, ":", imgLength)
		return webImgBytes, nil
	} else {
		log.Println("webp encode jpg file", err)
		return nil, err
	}

}

对比用cwebp命令行

cwebp -q 80 test.png -o test.png.webp

发现图片的颜色变化明显,排查源代码没有发现明显错误

测试图片:

test

memory leak

I create a simple http server do convert a jpg to webp

here is the sample code:

func ImgTowebp(imgData []byte) ([]byte, error) {
	//jpeg.Decode()
	img, err := jpeg.Decode(bytes.NewBuffer(imgData))
	if err != nil {
		//log.Println("decode error from jpg",err)
		img, err = png.Decode(bytes.NewBuffer(imgData))
		if err != nil {
			log.Println("decode error from png or jpg", err)
			return nil, err
		}
	}
	//log.Println(fname)
	webImgBytes, err := webp.EncodeRGBA(img, 80)
	if err == nil {
		webpLength := len(webImgBytes)
		imgLength := len(imgData)
		if webpLength > imgLength {
			log.Println("webp bigger than img")
		}
		log.Println("img2webp <webp size>:<img size>", webpLength, ":", imgLength)
		return webImgBytes, nil
	} else {
		log.Println("webp encode jpg file", err)
		return nil, err
	}

}


main.go

webImgBytes, err := ImgTowebp(bodybuffer)
			if err == nil {
				w.WriteHeader(http.StatusOK)
				w.Header().Set("Content-Type", "image/webp")
				w.Write(webImgBytes)
				return
			} 

运行一段时间后, 内存分析图:

20191217141007

查看 相关源代码:

func EncodeRGBA(m image.Image, quality float32) (data []byte, err error) {
	p := toRGBAImage(m)
	data, err = webpEncodeRGBA(p.Pix, p.Rect.Dx(), p.Rect.Dy(), p.Stride, quality)
	return
}

func toRGBAImage(m image.Image) *image.RGBA {
	if m, ok := m.(*image.RGBA); ok {
		return m
	}
	b := m.Bounds()
	rgba := image.NewRGBA(b)
	dstColorRGBA64 := &color.RGBA64{}
	dstColor := color.Color(dstColorRGBA64)
	for y := b.Min.Y; y < b.Max.Y; y++ {
		for x := b.Min.X; x < b.Max.X; x++ {
			pr, pg, pb, pa := m.At(x, y).RGBA()
			dstColorRGBA64.R = uint16(pr)
			dstColorRGBA64.G = uint16(pg)
			dstColorRGBA64.B = uint16(pb)
			dstColorRGBA64.A = uint16(pa)
			rgba.Set(x, y, dstColor)
		}
	}
	return rgba
}

func webpEncodeRGB(pix []byte, width, height, stride int, quality float32) (output []byte, err error) {
	if len(pix) == 0 || width <= 0 || height <= 0 || stride <= 0 || quality < 0.0 {
		err = errors.New("webpEncodeRGB: bad arguments")
		return
	}
	if stride < width*3 && len(pix) < height*stride {
		err = errors.New("webpEncodeRGB: bad arguments")
		return
	}

     //主要怀疑 (*C.uint8_t)(unsafe.Pointer(&pix[0])) 这个是golang分配的图片pix数组, 传递到CGO后,没有进行释放,就一直持有。
///
	var cptr_size C.size_t
	var cptr = C.webpEncodeRGB(
		(*C.uint8_t)(unsafe.Pointer(&pix[0])), C.int(width), C.int(height),
		C.int(stride), C.float(quality),
		&cptr_size,
	)
	if cptr == nil || cptr_size == 0 {
		err = errors.New("webpEncodeRGB: failed")
		return
	}
	defer C.free(unsafe.Pointer(cptr))

	output = make([]byte, int(cptr_size))
	copy(output, ((*[1 << 30]byte)(unsafe.Pointer(cptr)))[0:len(output):len(output)])
	return
}

Linux go mod vendor 后,编译出错

go mod vendor 后,编译出错,提示无法找到 webp.h 文件

# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

# go version
go version go1.15.5 linux/amd64

# go build
# github.com/chai2010/webp
vendor/github.com/chai2010/webp/capi.go:24:18: fatal error: webp.h: No such file or directory
 #include "webp.h"
                  ^
compilation terminated.

Add a license

Hi,

I'm considering using your package for a project but I can't even consider it due to the lack of a license. Could you add one? Maybe Apache 2.0?

Thanks

Getting compilation issues on linux

Installing my package github.paytm.com/paytm/resizer via go get is causing this issue, and then it fails to build.

github.com/chai2010/webp

src/github.com/chai2010/webp/writer.go:91: unknown _RGB field 'Pix' in struct literal
src/github.com/chai2010/webp/writer.go:92: unknown _RGB field 'Stride' in struct literal
src/github.com/chai2010/webp/writer.go:93: unknown _RGB field 'Rect' in struct literal

Error for Linux Build

Hi! My params for Linux release.

set GOARCH=amd64
set GOOS=linux
go build -ldflags "-s -w"

Output:

C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:22:9: undefined: webpGetInfo
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:26:20: undefined: webpDecodeGray
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:39:20: undefined: webpDecodeRGB
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:52:20: undefined: webpDecodeRGBA
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:68:14: undefined: webpDecodeGrayToSize
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:82:14: undefined: webpDecodeRGBToSize
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:96:14: undefined: webpDecodeRGBAToSize
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:109:7: undefined: toGrayImage
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:110:14: undefined: webpEncodeGray
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:119:14: undefined: webpEncodeRGB
C:\Users\admin\go\pkg\mod\github.com\chai2010\[email protected]\webp.go:119:14: too many errors

Installed TDM-GCC
OS Windows 10.
Golang version 1.18.4

How can I compile for Linux? When building for Windows, there are no errors. Thanks!

Resize function?

is there going to be plan to add resizing function?
like the one from the cwebp
cwebp -resize <width> <height>
apparently resizing using cwebp give a clearer image compared to Lanczos3

Mac下编译不了linux的binary?

$ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./main.go

# command-line-arguments
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /var/folders/m2/nwyl7pg57j378_k7qqfghmpw0000gn/T/go-link-956317668/go.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
"__cgo_topofstack", referenced from:
__cgo_26061493d47f_C2func_getnameinfo in 000002.o
__cgo_26061493d47f_Cfunc_getnameinfo in 000002.o
__cgo_26061493d47f_C2func_getaddrinfo in 000004.o
__cgo_26061493d47f_Cfunc_gai_strerror in 000004.o
__cgo_26061493d47f_Cfunc_getaddrinfo in 000004.o
__cgo_9b69751600cf_Cfunc_WebPGetFeatures in 000018.o
__cgo_9b69751600cf_Cfunc_webpDecodeGray in 000018.o
...
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Alpha channel glitchy when using webp.Decode

Hi.

I'm trying to read some webp files and creating an alpha composite using Draw method with Over as a parameter (code below).
The output shows glitchy lines where the alpha channel is merged:

result

This code was used:

package main

import (
	"fmt"
	"image"
	"image/draw"
	"image/png"
	"log"
	"os"
	"time"

	// swap between these two. The glitch is only in this lib
	//"golang.org/x/image/webp"
	"github.com/chai2010/webp"
)

func getTile(path string) image.Image {
	tileStream, _ := os.Open(path)
	tile, _ := webp.Decode(tileStream)
	defer tileStream.Close()
	return tile
}

func main() {
	tileA := getTile("a.webp")
	tileB := getTile("b.webp")

	canvas := image.NewRGBA(image.Rect(0, 0, 500, 500))

	draw.Draw(canvas, image.Rect(0, 0, tileA.Bounds().Max.X, tileA.Bounds().Max.Y), tileA, image.ZP, draw.Src)
	draw.Draw(canvas, image.Rect(0, 75, tileB.Bounds().Max.X, 75+tileB.Bounds().Max.Y), tileB, image.ZP, draw.Over)

	outputStream, _ := os.Create("result.png")
	png.Encode(outputStream, canvas)

	defer outputStream.Close()
}

Using golang.org/x/image/webp fixes the issue, but it has a couple other problems therefore I can't use it.

result

The source files are in the following zip:
experiments.zip

webp package problem

there is this error: # github.com/chai2010/webp
cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in %PATH%
I need help, please. I use windows. And I install libvips and TDM-GCC-64 and add their bin folder in to PATH but there is same error :(

memory leak problem

I am using Go v1.13.6, here is my sample code:
I was trying to convert a webp file into jpeg file, when I use 10000+ webp files to test program stability, the momery keeps rising......
image

是不是不支持在windows平台编译成linux?

go\pkg\mod\github.com\chai2010\[email protected]\webp.go:17:9: undefined: webpGetInfo
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:21:20: undefined: webpDecodeGray
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:34:20: undefined: webpDecodeRGB
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:47:20: undefined: webpDecodeRGBA
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:63:14: undefined: webpDecodeGrayToSize
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:77:14: undefined: webpDecodeRGBToSize
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:91:14: undefined: webpDecodeRGBAToSize
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:104:7: undefined: toGrayImage
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:105:14: undefined: webpEncodeGray
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:114:14: undefined: webpEncodeRGB
go\pkg\mod\github.com\chai2010\[email protected]\webp.go:114:14: too many errors

webp.h: No such file or directory

github.com/chai2010/webp

./capi.go:26:10: fatal error: webp.h: No such file or directory
#include "webp.h"
^~~~~~~~
compilation terminated.

Question: webp lossless compression?

Cant find the option in the code to enable a degree of compression. I'm not webp expert, just found it a couple of days ago, but I do it offers lossless compression as PNG does.

Thanks!

Exif Metadata getting set incorrectly

I have a service where I am able to convert jpeg images into webp and render them. The jpeg image that I get has exif information which I extract using goexif library.

In order to preserve the metadata in the webp image as well, I encode my image with webp encoder and try to set the EXIF data that I extracted earlier, in the encoded image data using the method SetMetadata. This executes successfully and if I try to call GetMetadata after the previous step, I get the correct response i.e all the EXIF tags that were supposed to be set.

The issue that I face here is, when I try to extract the metadata of the returned webp image using any other online tool, like exif viewer extension on chrome, it errors out with failure to decode exif metadata

Can someone help here?

trying to compile a project for linux from osx

i get this error

$ GOOS=linux GOARCH=amd64 go build main.go                                                                          
# github.com/chai2010/webp
../../github.com/chai2010/webp/webp.go:24: undefined: CBuffer

did i miss anything? thank you (:

Problem with macos build

I try to build application which use webp library and can't build it with enabled CGO:
GOOS=darwin GOARCH=amd64 CGO_ENABLED=1 go build -ldflags "-X main.Version=2.1.29 -X main.Build=`git rev-parse HEAD` -X main.BuildTime=`date +%FT%T%z`" -o bin
I have gcc installed.
image

macos 编译出错

macos 12.4
go 1.18.1
提示如下
github.com/sizeofint/webp-animation

github.com/sizeofint/webp-animation
In file included from ../../repository/go/pkg/mod/github.com/sizeofint/[email protected]/gifdec.go:6:
./webp.hpp:4:10: fatal error: 'webp/encode.h' file not found
#include <webp/encode.h>
^~~~~~~~~~~~~~~

使用make 或者手动命令build
提示均如上所示

arm64 build error

Getting Build errors when I try to build my project for arm64

CGO_ENABLED is enabled. The Build Command:

env GOOS=linux GOARCH=arm64 go build -o build/app-arm64

The Error:

$ env GOOS=linux GOARCH=arm64 go build -o build/app-arm64 90# runtime/cgo 91gcc_arm64.S: Assembler messages: 92gcc_arm64.S:30: Error: no such instruction: stp x29,x30,[sp,' 93gcc_arm64.S:34: Error: too many memory references for mov'
94gcc_arm64.S:36: Error: no such instruction: stp x19,x20,[sp,'
95gcc_arm64.S:39: Error: no such instruction: stp x21,x22,[sp,'
96gcc_arm64.S:42: Error: no such instruction: stp x23,x24,[sp,'
97gcc_arm64.S:45: Error: no such instruction: stp x25,x26,[sp,'
98gcc_arm64.S:48: Error: no such instruction: stp x27,x28,[sp,'
99gcc_arm64.S:52: Error: too many memory references for mov'
100gcc_arm64.S:53: Error: too many memory references for mov'
101gcc_arm64.S:54: Error: too many memory references for mov'
102gcc_arm64.S:56: Error: no such instruction: blr x20'
103gcc_arm64.S:57: Error: no such instruction: blr x19'
104gcc_arm64.S:59: Error: no such instruction: ldp x27,x28,[sp,'
105gcc_arm64.S:62: Error: no such instruction: ldp x25,x26,[sp,'
106gcc_arm64.S:65: Error: no such instruction: ldp x23,x24,[sp,'
107gcc_arm64.S:68: Error: no such instruction: ldp x21,x22,[sp,'
108gcc_arm64.S:71: Error: no such instruction: ldp x19,x20,[sp,'
109gcc_arm64.S:74: Error: no such instruction: ldp x29,x30,[sp],'`

Clang build warning

When building with Clang I get this warning.

# github.com/chai2010/webp
In file included from z_libwebp_src_enc_picture_csp_enc.c:9:
../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' (8)? [-Wxor-used-as-pow]
../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: note: replace expression with '0x2 ^ ALPHA_OFFSET' to silence this warning

clang version 10.0.0-4ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

Not enough return values on GetInfo function

There are not enough return values for the GetInfo function and I am receiving an build error when using the package. How is this function being used with an invalid/missing return types

Location: /github.com/chai2010/webp/webp.go:22:10

func GetInfo(data []byte) (width, height int, hasAlpha bool, err error) { return (data) }

Error compiling: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET'

Hi there,

Thanks for the great package.
When installing/building I am receiving an error:

../../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: warning: result of '2 ^ ALPHA_OFFSET' is 1; did you mean '1 << ALPHA_OFFSET' (8)? [-Wxor-used-as-pow]
../../../../go/pkg/mod/github.com/chai2010/[email protected]/internal/libwebp-1.0.2/src/enc/picture_csp_enc.c:1002:40: note: replace expression with '0x2 ^ ALPHA_OFFSET' to silence this warning

Not sure how to go about this?

Many thanks.

Strange compiler errors when CGO_ENABLED=0

I'm trying to compile my Go project to one static binary file, without linking to external libraries.

I am doing so by using this command:

CGO_ENABLED=0 go get -a -u -ldflags '-s'

This however produces the following errors:

# github.com/chai2010/webp
../github.com/chai2010/webp/reader.go:17: undefined: maxWebpHeaderSize
../github.com/chai2010/webp/webp.go:13: undefined: webpGetInfo
../github.com/chai2010/webp/webp.go:17: undefined: webpDecodeGray
../github.com/chai2010/webp/webp.go:30: undefined: webpDecodeRGB
../github.com/chai2010/webp/webp.go:39: undefined: webpDecodeRGBA
../github.com/chai2010/webp/webp.go:52: undefined: webpEncodeGray
../github.com/chai2010/webp/webp.go:57: undefined: webpEncodeRGB
../github.com/chai2010/webp/webp.go:61: undefined: webpEncodeRGBA
../github.com/chai2010/webp/webp.go:65: undefined: webpEncodeLosslessGray
../github.com/chai2010/webp/webp.go:70: undefined: webpEncodeLosslessRGB
../github.com/chai2010/webp/webp.go:70: too many errors

Which is strange, because (for instance) maxWebpHeaderSize is declared in capi.go

Extra info:

OS: Debian Jessie
Kernel 3.2.0-4-amd64
go version go1.3.2 linux/amd64

Any thoughts?

Thanks in advance.

cross-compiling and linking on macOS fails with undefined webp*

Hello! 👋 I am currently unable to release twtxt v0.2.0 because of the following build/link errors when running through my release process with goreleaser:

   ⨯ release failed after 42.26s error=failed to build for darwin_amd64: # github.com/chai2010/webp
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:17:9: undefined: webpGetInfo
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:21:20: undefined: webpDecodeGray
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:34:20: undefined: webpDecodeRGB
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:47:20: undefined: webpDecodeRGBA
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:63:14: undefined: webpDecodeGrayToSize
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:77:14: undefined: webpDecodeRGBToSize
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:91:14: undefined: webpDecodeRGBAToSize
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:104:7: undefined: toGrayImage
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:105:14: undefined: webpEncodeGray
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:114:14: undefined: webpEncodeRGB
../../../go/pkg/mod/github.com/chai2010/[email protected]/webp.go:114:14: too many errors

The funny thing about this is that I actually develop on macOS and the binary otherwise builds just fine:

prologic@Jamess-iMac
Mon Aug 31 09:05:41
~/Projects/jointwt/twtxt
 (master) 0
$ make clean && make build && ./twtd -v
twtxt v0.1.0@1bbc215

Can someone please help? I'm not really sure what's going on 😢 and this is #blocking my release.

undefined: webp.Encode

func Encode(w io.Writer, m image.Image, opt *Options) (err error)

In the docks, this function is present, in fact it is not!

Status of v1.2-alpha

Has anyone been using 1.2-alpha1 on live systems so far? We are particularly interested in memory leak and heap corruption fixes that were introduced in the newer versions of libwebp. Is it ready for production systems?

Is there some sort of a roadmap or plans to promote 1.2-alpha1 to stable? Are there any blockers preventing this, anything we could help with?

hello.go doesn't work

hi @chai2010

hello.go does not work any longer:

 ➜  src  cd github.com/chai2010/webp
 ➜  webp git:(master) go run hello.go
 width = 400, height = 301
 Metadata: err = webpGetMetadata: not found

Before it was generating output.webp?
But it works in my fork

webp.Decode(buf) returns imagewebpDecodeRGBA: bad arguments

@chai2010 I am having a strange issue.
the webp.Decode(buf) returns imagewebpDecodeRGBA: bad arguments

Here is the code, where I use the webp:

func Put(w http.ResponseWriter, r *http.Request) {
    if r.Method != "PUT" {
    w.Write(json.Message("ERROR", "Not supported Method"))
    return
}
reader, err := r.MultipartReader()
if err != nil {
    w.Write(json.Message("ERROR", "Client should support multipart/form-data"))
    return
}
buf := bytes.NewBufferString("")
for {
    part, err := reader.NextPart()
    if err == io.EOF {
        break
    }
    if part.FileName() == "" { // if empty skip this iteration
        continue
    }
    _, err = io.Copy(buf, part)
    if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
    }
}
defer r.Body.Close()
var result json.Result
var ic iconf
ic.machine = conf.Image.Machine
if ic.image, err = webp.Decode(buf); err != nil { // FIXME imagewebpDecodeRGBA: bad arguments
    w.Write(json.Message("ERROR", "Unable to decode your image"+err))
    return
}
ic.hash = fmt.Sprintf("%x", sha1.Sum(buf.Bytes()))
setColor(&ic)
for _, format := range conf.Image.Format { // jpeg, webp, ...
    for _, screen := range conf.Image.Screen {
        ic.format = format
        ic.ui = screen.Ui
        ic.density = screen.Density
        ic.width = screen.Width
        if ic.fid, err = imgToFile(&ic); err != nil {
            w.Write(json.Message("ERROR", "Unable to create a file"))
            return
        }
        fid := json.Fid{fmt.Sprintf("%s_%s", screen.Density, screen.Ui), ic.fid}
        result.Image = append(result.Image, fid)
    }
}
w.Write(json.Message("OK", &result))
}

I might be messed up with Multipart/form-data.
However the same code above works if I send by curl:

curl -v -XPOST -include --form asdfasdf=@Photo_20140806_000942.jpg http://obrol.shopafter.com:9090/

Is it bug?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.