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

Alpha channel glitchy when using webp.Decode #31

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

Alpha channel glitchy when using webp.Decode #31

AliFlux opened this issue Jul 12, 2020 · 0 comments

Comments

@AliFlux
Copy link

AliFlux commented Jul 12, 2020

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

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

No branches or pull requests

1 participant