chai2010 / webp

WebP decoder and encoder for Go (Zero Dependencies).
http://godoc.org/github.com/chai2010/webp
BSD 3-Clause "New" or "Revised" License
512 stars 89 forks source link

Alpha channel glitchy when using webp.Decode #31

Open AliFlux opened 4 years ago

AliFlux commented 4 years ago

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