@@ -99,3 +99,50 @@ func TestMono(t *testing.T) {
9999 })
100100 }
101101}
102+
103+ // Extra test to make sure decoding the image as pixel.Monochrome works as
104+ // expected. (It previously didn't due to
105+ // https://github.com/tinygo-org/drivers/pull/683).
106+ func TestMonoMonochrome (t * testing.T ) {
107+ data , err := os .ReadFile ("testdata/tinygo-logo-monochrome.raw" )
108+ if err != nil {
109+ t .Fatal ("could not read input file:" , err )
110+ }
111+ img , e := image .NewMono [pixel.Monochrome ](true , false , 304 , 255 , string (data ))
112+ if e != nil {
113+ t .Fatal ("could not decode input file:" , e )
114+ }
115+
116+ // Decode the image.
117+ width , height := img .Size ()
118+ buf := pixel .NewImage [pixel.Monochrome ](width , height )
119+ img .Draw (buf , 0 , 0 , 1 )
120+
121+ // Load the reference image.
122+ f , err := os .Open ("testdata/tinygo-logo-monochrome.png" )
123+ if err != nil {
124+ t .Fatal ("could not open reference image:" , err )
125+ }
126+ defer f .Close ()
127+ golden , err := png .Decode (f )
128+ if err != nil {
129+ t .Fatal ("could not decode reference image:" , err )
130+ }
131+
132+ // Check that the decoded image matches the golden image.
133+ fg := color.RGBA {192 , 192 , 192 , 255 }
134+ bg := color.RGBA {32 , 32 , 32 , 255 }
135+ for y := 0 ; y < height ; y ++ {
136+ for x := 0 ; x < width ; x ++ {
137+ c1 := bg
138+ if buf .Get (x , y ) {
139+ c1 = fg
140+ }
141+ r2 , g2 , b2 , _ := golden .At (x , y ).RGBA ()
142+ c2 := color.RGBA {R : uint8 (r2 >> 8 ), G : uint8 (g2 >> 8 ), B : uint8 (b2 >> 8 ), A : 255 }
143+ if c1 != c2 {
144+ t .Fatalf ("mismatch at %dx%d: expected %v got %v" , x , y , c2 , c1 )
145+ }
146+ }
147+ }
148+ }
0 commit comments