Skip to content

image/png: nearly black pixels under certain conditions with alpha channels #10191

@nfnt

Description

@nfnt

I'm writing a small package for image resizing. While I've had my share of issues with images that have an alpha channel, this time I think that there may be an issue in the image/png package. I'm using Go 1.4.2 with OS X and under certain conditions there will be nearly black pixels in images created by png.Encode. The following code will produce an output that shows the problem:

package main

import (
    "bytes"
    "fmt"
    "image"
    "image/color"
    "image/png"
)

func main() {
    expected := image.NewRGBA64(image.Rect(0, 0, 7, 1))

    expected.SetRGBA64(0, 0, color.RGBA64{64561, 64547, 64541, 64566})
    expected.SetRGBA64(1, 0, color.RGBA64{65535, 65535, 65529, 65535})
    expected.SetRGBA64(2, 0, color.RGBA64{65118, 65535, 65535, 64688})
    expected.SetRGBA64(3, 0, color.RGBA64{42253, 29639, 24962, 46946})
    expected.SetRGBA64(4, 0, color.RGBA64{36967, 14176, 5958, 45390})
    expected.SetRGBA64(5, 0, color.RGBA64{38060, 17046, 9449, 45831})
    expected.SetRGBA64(6, 0, color.RGBA64{37852, 16504, 8790, 45746})

    var buffer bytes.Buffer
    png.Encode(&buffer, expected)

    actual, err := png.Decode(&buffer)
    if err != nil {
        panic(err)
    }

    for i := 0; i < 7; i++ {
        fmt.Printf("\n(%v,0):\n", i)
        fmt.Println(actual.At(i, 0).RGBA())
        fmt.Println(expected.At(i, 0).RGBA())
    }
}

While most color values of actual are about the same as in expected, pixel (2,0) of actual is very different from the one in expected and would show as nearly black in the output image. I didn't test if this is only happening with image.RGBA64 input.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions