Skip to content

Commit

Permalink
image: fix TestMono test
Browse files Browse the repository at this point in the history
I wanted to fix the TODO (whether the decoded image was actually valid)
but found that it wasn't:

  - The size wasn't correct. The TinyGo logo was actually 304x255 in
    size, not 299x255 (it looks like it was created with a tool that
    assumes every row starts at a byte aligned line, which image.Mono
    doesn't).
  - There seems to be a problem when the image is decoded as a
    pixel.Monochrome, but I haven't yet figured out why.
  • Loading branch information
aykevl committed May 25, 2024
1 parent 23da4bb commit 0d8f650
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,24 @@ func testImage(t *testing.T, img image.Image[pixel.RGB888], reference string) {
}

func TestMono(t *testing.T) {
for _, name := range []string{"tinygo-logo-noalpha"} {
for _, name := range []string{"tinygo-logo-monochrome"} {
t.Run(name, func(t *testing.T) {
data, err := os.ReadFile("testdata/" + name + ".raw")
if err != nil {
t.Fatal("could not read input file:", err)
}
img, e := image.NewMono[pixel.Monochrome](true, false, 299, 255, string(data))
fg := pixel.NewRGB888(192, 192, 192)
bg := pixel.NewRGB888(32, 32, 32)
img, e := image.NewMono(fg, bg, 304, 255, string(data))
if e != nil {
t.Fatal("could not decode input file:", e)
}
if x, y := img.Size(); x != 299 || y != 255 {
if x, y := img.Size(); x != 304 || y != 255 {
t.Fatalf("unexpected size: %d, %d", x, y)
}

// Decode the image.
buf := pixel.NewImage[pixel.Monochrome](299, 255)
img.Draw(buf, 0, 0, 1)

// TODO: check for data validity
// Test whether the decoded image matches the reference image.
testImage(t, img, "testdata/"+name+".png")
})
}
}
Binary file added image/testdata/tinygo-logo-monochrome.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.

0 comments on commit 0d8f650

Please sign in to comment.