/// Validates this meta data. Returns the minimal possible requirements.
Validates this meta data. Returns the minimal possible requirements.
Validates this meta data . Returns the minimal possible requirements .
pub fn validate(headers: &[Header], pedantic: bool) -> Result<Requirements> {
        if headers.len() == 0 {
            return Err(Error::invalid("at least one layer is required"));
        }
        let deep = false; // TODO deep data
        let is_multilayer = headers.len() > 1;
        let first_header_has_tiles = headers.iter().next()
            .map_or(false, |header| header.blocks.has_tiles());
        let mut minimal_requirements = Requirements {
            // according to the spec, version 2  should only be necessary if `is_multilayer || deep`.
            // but the current open exr library does not support images with version 1, so always use version 2.
            file_format_version: 2,
            // start as low as possible, later increasing if required
            has_long_names: false,
            is_single_layer_and_tiled: !is_multilayer && first_header_has_tiles,
            has_multiple_layers: is_multilayer,
            has_deep_data: deep,
        };
        for header in headers {
            if header.deep { // TODO deep data (and then remove this check)
                return Err(Error::unsupported("deep data not supported yet"));
            }
            header.validate(is_multilayer, &mut minimal_requirements.has_long_names, pedantic)?;
        }
        // TODO validation fn!
        /*if let Some(max) = max_pixel_bytes {
            let byte_size: usize = headers.iter()
                .map(|header| header.total_pixel_bytes())
                .sum();
            if byte_size > max {
                return Err(Error::invalid("image larger than specified maximum"));
            }
        }*/
        if pedantic { // check for duplicate header names
            let mut header_names = HashSet::with_capacity(headers.len());
            for header in headers {
                if !header_names.insert(&header.own_attributes.layer_name) {
                    return Err(Error::invalid(format!(
                        "duplicate layer name: `{}`",
                        header.own_attributes.layer_name.as_ref().expect("header validation bug")
                    )));
                }
            }
        }
        if pedantic {
            let must_share = headers.iter().flat_map(|header| header.own_attributes.other.iter())
                .any(|(_, value)| value.to_chromaticities().is_ok() || value.to_time_code().is_ok());
            if must_share {
                return Err(Error::invalid("chromaticities and time code attributes must must not exist in own attributes but shared instead"));
            }
        }
        if pedantic && headers.len() > 1 { // check for attributes that should not differ in between headers
            let first_header = headers.first().expect("header count validation bug");
            let first_header_attributes = &first_header.shared_attributes;
            for header in &headers[1..] {
                if &header.shared_attributes != first_header_attributes {
                    return Err(Error::invalid("display window, pixel aspect, chromaticities, and time code attributes must be equal for all headers"))
                }
            }
        }
        debug_assert!(minimal_requirements.validate().is_ok(), "inferred requirements are invalid");
        Ok(minimal_requirements)
    }
pub fn validate ( headers : & [ Header ] , pedantic : bool ) -> Result < Requirements > { if headers . len ( ) == 0 { return Err ( Error :: invalid ( " " ) ) ; } let deep = false ; // TODO deep data let is_multilayer = headers . len ( ) > 1 ; let first_header_has_tiles = headers . iter ( ) . next ( ) . map_or ( false , | header | header . blocks . has_tiles ( ) ) ; let mut minimal_requirements = Requirements { // according to the spec, version 2  should only be necessary if `is_multilayer || deep`. // but the current open exr library does not support images with version 1, so always use version 2. file_format_version : 2 , // start as low as possible, later increasing if required has_long_names : false , is_single_layer_and_tiled : ! is_multilayer && first_header_has_tiles , has_multiple_layers : is_multilayer , has_deep_data : deep , } ; for header in headers { if header . deep { // TODO deep data (and then remove this check) return Err ( Error :: unsupported ( " " ) ) ; } header . validate ( is_multilayer , & mut minimal_requirements . has_long_names , pedantic ) ? ; } // TODO validation fn! /*if let Some(max) = max_pixel_bytes {
            let byte_size: usize = headers.iter()
                .map(|header| header.total_pixel_bytes())
                .sum();

            if byte_size > max {
                return Err(Error::invalid("image larger than specified maximum"));
            }
        }*/ if pedantic { // check for duplicate header names let mut header_names = HashSet :: with_capacity ( headers . len ( ) ) ; for header in headers { if ! header_names . insert ( & header . own_attributes . layer_name ) { return Err ( Error :: invalid ( format ! ( " " header own_attributes layer_name as_ref ( ) expect ( " " ) ) ) ) ; } } } if pedantic { let must_share = headers . iter ( ) . flat_map ( | header | header . own_attributes . other . iter ( ) ) . any ( | ( _ , value ) | value . to_chromaticities ( ) . is_ok ( ) || value . to_time_code ( ) . is_ok ( ) ) ; if must_share { return Err ( Error :: invalid ( " " ) ) ; } } if pedantic && headers . len ( ) > 1 { // check for attributes that should not differ in between headers let first_header = headers . first ( ) . expect ( " " ) ; let first_header_attributes = & first_header . shared_attributes ; for header in & headers [ 1 .. ] { if & header . shared_attributes != first_header_attributes { return Err ( Error :: invalid ( " " ) ) } } } debug_assert ! ( minimal_requirements validate ( ) is_ok ( ) " " ) ; Ok ( minimal_requirements ) }
Validates this meta data.
Validates this meta data .
headers
&[Header]
pedantic
bool