Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/image: WebP decode contrast issue #40173

Open
AliFlux opened this issue Jul 12, 2020 · 3 comments
Open

x/image: WebP decode contrast issue #40173

AliFlux opened this issue Jul 12, 2020 · 3 comments

Comments

@AliFlux
Copy link

@AliFlux AliFlux commented Jul 12, 2020

What version of Go are you using (go version)?

go version go1.13.7 windows/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GO111MODULE=off
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Alpha\AppData\Local\go-build
set GOENV=C:\Users\Alpha\AppData\Roaming\go\env
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\Alpha\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=c:\go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Alpha\AppData\Local\Temp\go-build034800510=/tmp/go-build -gno-record-gcc-switches

What did you do?

I opened up a webp using go, and saved it back to png, The output was different from the source. Other golang webp decoding packages parsed it correctly.

package main

import (
	"image"
	"image/png"
	"os"

	// you can swap between these two libs, chai2010 is okay
	"golang.org/x/image/webp"
	//"github.com/chai2010/webp"
)

func main() {

	tileStream, _ := os.Open("full.webp")
	tile, _ := webp.Decode(tileStream)
	defer tileStream.Close()

	outputStream, _ := os.Create("full.png")
	png.Encode(outputStream, tile)

	defer outputStream.Close()
}

What did you expect to see?

b(1)

This is the source image, notice the details and the clarity.

What did you see instead?

full

This is the converted, the details are dimmed, the contrast is lower. Other webp decoding libs maintain the contrast.

@gopherbot gopherbot added this to the Unreleased milestone Jul 12, 2020
@agnivade
Copy link
Contributor

@agnivade agnivade commented Jul 12, 2020

/cc @nigeltao

Loading

@dwbuiten
Copy link
Contributor

@dwbuiten dwbuiten commented Jul 22, 2020

I'm almost certain this is due to x/image's VP8 decoder (which WebP lossy is internally) not handling the full/limited range flag:

https://github.com/golang/image/blob/69cc3646b96e61de0b417f4815b86c36e65783ee/vp8/decode.go#L332-L336

I'm also not sure if image.YCbCr can even handle full range vs limited range YCbCr content. It certainly can't handle any colorspace but BT.601 (which is fine for WebP, which is always BT.601, but won't hold true for newer formats.)

Loading

@AliFlux
Copy link
Author

@AliFlux AliFlux commented Aug 3, 2020

Is there any temporary hack that can fix this? I'm using python webp library to write the images.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants