|
1 | 1 | use grim_rs::{Box as GrimBox, CaptureParameters, CaptureResult, Error, Grim}; |
2 | 2 | use std::collections::HashMap; |
| 3 | +use wayland_client::protocol::wl_shm::Format as ShmFormat; |
| 4 | + |
| 5 | +fn convert_shm_to_rgba_for_test(buffer_data: &mut [u8], format: ShmFormat) { |
| 6 | + match format { |
| 7 | + ShmFormat::Xrgb8888 => { |
| 8 | + for chunk in buffer_data.chunks_exact_mut(4) { |
| 9 | + chunk.swap(0, 2); |
| 10 | + chunk[3] = 255; |
| 11 | + } |
| 12 | + } |
| 13 | + ShmFormat::Argb8888 => { |
| 14 | + for chunk in buffer_data.chunks_exact_mut(4) { |
| 15 | + chunk.swap(0, 2); |
| 16 | + } |
| 17 | + } |
| 18 | + ShmFormat::Xbgr8888 => { |
| 19 | + for chunk in buffer_data.chunks_exact_mut(4) { |
| 20 | + chunk[3] = 255; |
| 21 | + } |
| 22 | + } |
| 23 | + ShmFormat::Abgr8888 => {} |
| 24 | + _ => {} |
| 25 | + } |
| 26 | +} |
3 | 27 |
|
4 | 28 | #[test] |
5 | 29 | fn test_box_struct_creation() { |
@@ -115,6 +139,20 @@ fn test_image_data_format() { |
115 | 139 | assert_eq!(data[3], 255); // A |
116 | 140 | } |
117 | 141 |
|
| 142 | +#[test] |
| 143 | +fn test_convert_xrgb8888_to_rgba() { |
| 144 | + let mut pixel_data = vec![10, 20, 30, 99]; |
| 145 | + convert_shm_to_rgba_for_test(&mut pixel_data, ShmFormat::Xrgb8888); |
| 146 | + assert_eq!(pixel_data, vec![30, 20, 10, 255]); |
| 147 | +} |
| 148 | + |
| 149 | +#[test] |
| 150 | +fn test_convert_argb8888_to_rgba_preserves_alpha() { |
| 151 | + let mut pixel_data = vec![10, 20, 30, 40]; |
| 152 | + convert_shm_to_rgba_for_test(&mut pixel_data, ShmFormat::Argb8888); |
| 153 | + assert_eq!(pixel_data, vec![30, 20, 10, 40]); |
| 154 | +} |
| 155 | + |
118 | 156 | #[test] |
119 | 157 | fn test_png_compression_levels() { |
120 | 158 | let test_data = vec![255u8; 100 * 100 * 4]; // 100x100 image |
|
0 commit comments