gonum/plot

cmpimg: invalid handling of images that are not image.RGBA

sbinet opened this issue · 3 comments

in cmpimg, one sees:

func cmpImg(v1, v2 image.Image, delta float64) bool {
        img1, ok := v1.(*image.RGBA)
        if !ok {
                img1 = newRGBAFrom(v1)
        }

        img2, ok := v2.(*image.RGBA)
        if !ok {
                img2 = newRGBAFrom(v2)
        }

        if len(img1.Pix) != len(img2.Pix) {
                return false
        }

        max := delta * delta
        bnd := img1.Bounds()
        for x := bnd.Min.X; x < bnd.Max.X; x++ {
                for y := bnd.Min.Y; y < bnd.Max.Y; y++ {
                        c1 := img1.RGBAAt(x, y)
                        c2 := img2.RGBAAt(x, y)
                        if !yiqEqApprox(c1, c2, max) {
                                return false
                        }
                }
        }

        return ok
}

it may happen that v2 isn't a *image.RGBA.
in that case, ok==false and we convert v2 into img2 going through the necessary steps.

and if no pixel differed too much between img1 and img2, we return ok... which is still false.

ooops

yeah... silly mistake, heh?

looking at the coverage of cmpimg.go, it would perhaps stand to reason to improve it a little bit.
WDYT?

SGTM