chai2010 / chai2010/webp

Alpha channel glitchy when using webp.Decode

Open
#31 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
723
Forks
113
PR merge metrics
No merged PRs in 30d

Description

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](https://user-images.githubusercontent.com/8333794/87240448-27e64500-c433-11ea-9064-9cccedf1d249.png)

This code was used:

```go
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](https://user-images.githubusercontent.com/8333794/87240508-95927100-c433-11ea-8269-d18f785f06c9.png)

The source files are in the following zip:
[experiments.zip](https://github.com/chai2010/webp/files/4908117/experiments.zip)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Go reproducer in the issue and the a.webp, b.webp files from experiments.zip. Compare the output from this package with golang.org/x/image/webp, focusing on the alpha data used by draw.Draw with draw.Over. Done means decoding the supplied files produces correct alpha compositing without the visible glitch lines.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.