U20: ec-image drop open_info, to_rgb16, to_rgba16 (edith uses none; differential test gets its own 16-bit RGBA helper, same mapping)
Browse files at this commit58f8d8f6acfc57dbcf59b4deb772e30194e4ae95Parent: 4e4fcb82 changed files +13 -41
crates/ec-image/src/lib.rsmodified+1 -40
| @@ -333,11 +333,6 @@ fn narrow(v: u16) -> u8 { | |||
| 333 | ((u32::from(v) + 128) / 257) as u8 | 333 | ((u32::from(v) + 128) / 257) as u8 |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | -/// 8-bit sample widened to 16: `v * 65535 / 255`, exact. | ||
| 337 | -fn widen(v: u8) -> u16 { | ||
| 338 | - u16::from(v) * 257 | ||
| 339 | -} | ||
| 340 | - | ||
| 341 | impl Image { | 336 | impl Image { |
| 342 | /// `(width, height)`. | 337 | /// `(width, height)`. |
| 343 | pub fn dimensions(&self) -> (u32, u32) { | 338 | pub fn dimensions(&self) -> (u32, u32) { |
| @@ -404,34 +399,6 @@ impl Image { | |||
| 404 | out | 399 | out |
| 405 | } | 400 | } |
| 406 | 401 | ||
| 407 | - /// Packed 16-bit R,G,B — 8-bit sources widened exactly (`v * 257`). | ||
| 408 | - pub fn to_rgb16(&self) -> Vec<u16> { | ||
| 409 | - match &self.pixels { | ||
| 410 | - Pixels::Rgb16(d) => d.clone(), | ||
| 411 | - Pixels::Rgba16(d) => d.as_chunks::<4>().0.iter().flat_map(|p| p[..3].to_vec()).collect(), | ||
| 412 | - Pixels::L16(d) => d.iter().flat_map(|&l| [l, l, l]).collect(), | ||
| 413 | - Pixels::La16(d) => d.as_chunks::<2>().0.iter().flat_map(|p| [p[0], p[0], p[0]]).collect(), | ||
| 414 | - _ => self.to_rgb8().into_iter().map(widen).collect(), | ||
| 415 | - } | ||
| 416 | - } | ||
| 417 | - | ||
| 418 | - /// Packed 16-bit R,G,B,A; opaque where the source had no alpha. | ||
| 419 | - pub fn to_rgba16(&self) -> Vec<u16> { | ||
| 420 | - match &self.pixels { | ||
| 421 | - Pixels::Rgba16(d) => d.clone(), | ||
| 422 | - Pixels::Rgb16(d) => d | ||
| 423 | - .as_chunks::<3>().0.iter() | ||
| 424 | - .flat_map(|p| [p[0], p[1], p[2], u16::MAX]) | ||
| 425 | - .collect(), | ||
| 426 | - Pixels::L16(d) => d.iter().flat_map(|&l| [l, l, l, u16::MAX]).collect(), | ||
| 427 | - Pixels::La16(d) => d | ||
| 428 | - .as_chunks::<2>().0.iter() | ||
| 429 | - .flat_map(|p| [p[0], p[0], p[0], p[1]]) | ||
| 430 | - .collect(), | ||
| 431 | - _ => self.to_rgba8().into_iter().map(widen).collect(), | ||
| 432 | - } | ||
| 433 | - } | ||
| 434 | - | ||
| 435 | /// The image as an [`ec_core::VideoFrame`], packed RGB8 or RGBA8. | 402 | /// The image as an [`ec_core::VideoFrame`], packed RGB8 or RGBA8. |
| 436 | /// | 403 | /// |
| 437 | /// The natural bridge for a caller that composes stills and decoded video | 404 | /// The natural bridge for a caller that composes stills and decoded video |
| @@ -552,12 +519,6 @@ pub fn open(path: impl AsRef<std::path::Path>) -> Result<Image> { | |||
| 552 | decode(&data) | 519 | decode(&data) |
| 553 | } | 520 | } |
| 554 | 521 | ||
| 555 | -/// Read the file at `path` and report its header dimensions. | ||
| 556 | -pub fn open_info(path: impl AsRef<std::path::Path>) -> Result<Info> { | ||
| 557 | - let data = std::fs::read(path).map_err(Error::Io)?; | ||
| 558 | - info(&data) | ||
| 559 | -} | ||
| 560 | - | ||
| 561 | #[cfg(test)] | 522 | #[cfg(test)] |
| 562 | mod tests { | 523 | mod tests { |
| 563 | use super::*; | 524 | use super::*; |
| @@ -582,7 +543,7 @@ mod tests { | |||
| 582 | #[test] | 543 | #[test] |
| 583 | fn sample_conversion_round_trips_through_eight_bits() { | 544 | fn sample_conversion_round_trips_through_eight_bits() { |
| 584 | for v in 0..=255u8 { | 545 | for v in 0..=255u8 { |
| 585 | - assert_eq!(narrow(widen(v)), v, "{v}"); | 546 | + assert_eq!(narrow(u16::from(v) * 257), v, "{v}"); |
| 586 | } | 547 | } |
| 587 | assert_eq!(narrow(0), 0); | 548 | assert_eq!(narrow(0), 0); |
| 588 | assert_eq!(narrow(u16::MAX), 255); | 549 | assert_eq!(narrow(u16::MAX), 255); |
crates/ec-image/tests/it/differential.rsmodified+12 -1
| @@ -85,6 +85,17 @@ fn psnr(a: &[u8], b: &[u8]) -> f64 { | |||
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | +fn rgba16(img: &ec_image::Image) -> Vec<u16> { | ||
| 89 | + use ec_image::Pixels; | ||
| 90 | + match &img.pixels { | ||
| 91 | + Pixels::L16(d) => d.iter().flat_map(|&l| [l, l, l, u16::MAX]).collect(), | ||
| 92 | + Pixels::La16(d) => d.as_chunks::<2>().0.iter().flat_map(|p| [p[0], p[0], p[0], p[1]]).collect(), | ||
| 93 | + Pixels::Rgb16(d) => d.as_chunks::<3>().0.iter().flat_map(|p| [p[0], p[1], p[2], u16::MAX]).collect(), | ||
| 94 | + Pixels::Rgba16(d) => d.clone(), | ||
| 95 | + _ => unreachable!("only called for 16-bit pictures"), | ||
| 96 | + } | ||
| 97 | +} | ||
| 98 | + | ||
| 88 | #[test] | 99 | #[test] |
| 89 | fn png_decodes_pixel_exactly() { | 100 | fn png_decodes_pixel_exactly() { |
| 90 | let files = corpus("png"); | 101 | let files = corpus("png"); |
| @@ -102,7 +113,7 @@ fn png_decodes_pixel_exactly() { | |||
| 102 | if ours.pixels.bit_depth() == 16 { | 113 | if ours.pixels.bit_depth() == 16 { |
| 103 | // Compared at 16 bits so the comparison is not laundered through | 114 | // Compared at 16 bits so the comparison is not laundered through |
| 104 | // two different 16-to-8 rounding conventions. | 115 | // two different 16-to-8 rounding conventions. |
| 105 | - let a = ours.to_rgba16(); | 116 | + let a = rgba16(&ours); |
| 106 | let b = theirs.to_rgba16().into_raw(); | 117 | let b = theirs.to_rgba16().into_raw(); |
| 107 | assert_eq!(a, b, "{} (16-bit samples)", path.display()); | 118 | assert_eq!(a, b, "{} (16-bit samples)", path.display()); |
| 108 | } else { | 119 | } else { |