diff --git a/src/decoder.rs b/src/decoder.rs index 292769d..ad4ba28 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -666,4 +666,38 @@ mod test { expected ); } + + /// Try decoding an image consisting of a single pixel. + #[test] + fn decode_1_pixel_image() { + let input: [u8; 26] = [ + 0x71, 0x6f, 0x69, 0x66, // 'qoif' magic bytes + 0x00, 0x00, 0x00, 0x01, // u32 width + 0x00, 0x00, 0x00, 0x01, // u32 height + 0x03, // u8 channels (3 for RGB mode) + 0x00, // u8 colorspace (0 for sRGB w/ linear alpha) + // One single blue pixel, QOI_OP_RGB + 0xFE, 0x00, 0x00, 0xFF, + // footer + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01 + ]; + + let mut decoder = Decoder::try_new(input.into_iter()) + .expect("Failed to initialize decoder from byte array"); + + // Check the metadata + assert_eq!(decoder.width, 1); + assert_eq!(decoder.height, 1); + assert_eq!(decoder.channels, 3); + assert_eq!(decoder.colorspace, 0); + + // Grab the one single pixel and check that it's solid blue. + let pixel = decoder.next().expect("Couldn't get pixel from decoder"); + assert_eq!(pixel, PixelRGBA::new(0, 0, 255, 255)); + + // Assert that there are no more pixels. + let pixel = decoder.next(); + assert!(pixel.is_none()); + } } \ No newline at end of file