mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 16:54:45 +00:00
fix(exr): expose internal ordinal helpers to regression tests
This commit is contained in:
@@ -245,7 +245,7 @@ fn window_size(size: exr::math::Vec2<usize>) -> (u32, u32) {
|
||||
|
||||
/// Reads the headers and checks every part's declared size, alone and together, before any pixel
|
||||
/// allocation. Headers are read without the crate's validation, which refuses deep parts.
|
||||
fn read_meta(bytes: &[u8], limits: &Limits) -> Result<MetaData> {
|
||||
pub(super) fn read_meta(bytes: &[u8], limits: &Limits) -> Result<MetaData> {
|
||||
check_previews(bytes)?;
|
||||
let meta = MetaData::read_from_buffered(Cursor::new(bytes), false).map_err(map_exr)?;
|
||||
let (mut total, mut flat, mut dwa) = (0u64, 0u64, 0u64);
|
||||
@@ -758,7 +758,7 @@ fn tables_start(bytes: &[u8]) -> Result<u64> {
|
||||
|
||||
/// Stable dense ordinal without materializing every tile. The library's block iterator
|
||||
/// internally allocates a Vec of all coordinates, which is unsuitable for cropped reads.
|
||||
fn flat_block_ordinal(header: &Header, tile: TileCoordinates) -> Result<usize> {
|
||||
pub(super) fn flat_block_ordinal(header: &Header, tile: TileCoordinates) -> Result<usize> {
|
||||
use exr::math::Vec2;
|
||||
use exr::meta::attribute::LevelMode;
|
||||
let mut start = 0usize;
|
||||
|
||||
@@ -574,13 +574,13 @@ fn mixed_one_tile(channels: &[&str], tile: u32, size: i32) -> Vec<u8> {
|
||||
|
||||
#[test]
|
||||
fn a_chunk_beside_a_deep_part_must_fit_the_rest_of_the_file() {
|
||||
// 2^15 × 2^15 tiles of three floats let a chunk hold up to 12 GiB, so the crate would
|
||||
// 2^14 × 2^14 tiles of three floats let a chunk hold up to 3 GiB (also on 32-bit), so the crate would
|
||||
// allocate the 2 GiB this chunk declares before it found the file too short.
|
||||
let limits = Limits::default();
|
||||
let channels = ["B", "G", "R"];
|
||||
let good = mixed_one_tile(&channels, 1 << 15, 12);
|
||||
let good = mixed_one_tile(&channels, 1 << 14, 12);
|
||||
assert_eq!(decode_part(&good, 0, &all, &limits).unwrap().channel("R").unwrap().samples, Samples::F32(vec![1.0]));
|
||||
let b = mixed_one_tile(&channels, 1 << 15, i32::MAX);
|
||||
let b = mixed_one_tile(&channels, 1 << 14, i32::MAX);
|
||||
for r in [decode_part(&b, 0, &all, &limits).map(|_| ()), decode_display_part(&b, 0, &all, &|_| 0.0, &limits).map(|_| ())] {
|
||||
assert!(matches!(&r, Err(Error::Malformed(m)) if m.contains("remain in the file")), "{r:?}");
|
||||
}
|
||||
@@ -689,6 +689,7 @@ fn cropped_mixed_display_bounds_block_tracking() {
|
||||
|
||||
#[test]
|
||||
fn dense_block_ordinals_cover_scan_lines_and_all_tile_levels() {
|
||||
use exr::block::chunk::TileCoordinates;
|
||||
use exr::meta::attribute::LevelMode;
|
||||
for tiled in [false, true] {
|
||||
let bytes = file(vec![layer(None, 9, 7, &["R"], tiled, exr::prelude::Compression::ZIP1)], (9, 7));
|
||||
|
||||
Reference in New Issue
Block a user