| 1 | use base64::{Engine as _, engine::general_purpose::STANDARD}; |
| 2 | |
| 3 | /// A 1x1 PNG, as bytes rather than a fixture file so the encoding tests |
| 4 | /// have no filesystem dependency. |
| 5 | pub const PNG_1X1: &[u8] = &[ |
| 6 | 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52, |
| 7 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06, 0x00, 0x00, 0x00, 0x1f, 0x15, 0xc4, |
| 8 | 0x89, 0x00, 0x00, 0x00, 0x0a, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0x00, 0x01, 0x00, 0x00, |
| 9 | 0x05, 0x00, 0x01, 0x0d, 0x0a, 0x2d, 0xb4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, |
| 10 | 0x42, 0x60, 0x82, |
| 11 | ]; |
| 12 | |
| 13 | pub fn runtime_image_fixture( |
| 14 | color: u8, |
| 15 | ) -> codewhale_app_server_protocol::runtime::RuntimeImageInput { |
| 16 | let image = image::DynamicImage::ImageRgba8(image::RgbaImage::from_pixel( |
| 17 | 2, |
| 18 | 2, |
| 19 | image::Rgba([color, 31, 99, 255]), |
| 20 | )); |
| 21 | let mut bytes = std::io::Cursor::new(Vec::new()); |
| 22 | image.write_to(&mut bytes, image::ImageFormat::Png).unwrap(); |
| 23 | codewhale_app_server_protocol::runtime::RuntimeImageInput { |
| 24 | mime: "image/png".into(), |
| 25 | data_base64: STANDARD.encode(bytes.into_inner()), |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | pub fn runtime_image_fixture_bytes( |
| 30 | size: usize, |
| 31 | ) -> codewhale_app_server_protocol::runtime::RuntimeImageInput { |
| 32 | let mut image = runtime_image_fixture(42); |
| 33 | let mut bytes = STANDARD.decode(&image.data_base64).unwrap(); |
| 34 | bytes.resize(size, 0); |
| 35 | image.data_base64 = STANDARD.encode(bytes); |
| 36 | image |
| 37 | } |
| 38 |