/// Decompress the image section of bytes.
Decompress the image section of bytes.
Decompress the image section of bytes .
pub fn decompress_image_section(self, header: &Header, compressed: ByteVec, pixel_section: IntegerBounds, pedantic: bool) -> Result<ByteVec> {
        let max_tile_size = header.max_block_pixel_size();
        assert!(pixel_section.validate(Some(max_tile_size)).is_ok(), "decompress tile coordinate bug");
        if header.deep { assert!(self.supports_deep_data()) }
        let expected_byte_size = pixel_section.size.area() * header.channels.bytes_per_pixel; // FIXME this needs to account for subsampling anywhere
        if compressed.len() == expected_byte_size {
            // the compressed data was larger than the raw data, so the small raw data has been written
            Ok(convert_little_endian_to_current(compressed, &header.channels, pixel_section))
        }
        else {
            use self::Compression::*;
            let bytes = match self {
                Uncompressed => Ok(compressed),
                ZIP16 => zip::decompress_bytes(&compressed),
                ZIP1 => zip::decompress_bytes(&compressed),
                RLE => rle::decompress_bytes(&compressed, expected_byte_size, pedantic),
                PIZ => piz::decompress(&header.channels, compressed, pixel_section, expected_byte_size, pedantic),
                PXR24 => pxr24::decompress(&header.channels, &compressed, pixel_section, expected_byte_size, pedantic),
                B44 | B44A => b44::decompress(&header.channels, &compressed, pixel_section, expected_byte_size, pedantic),
                _ => return Err(Error::unsupported(format!("yet unimplemented compression method: {}", self)))
            };
            // map all errors to compression errors
            let bytes = bytes
                .map_err(|_| Error::invalid(format!("compressed data ({:?})", self)))?;
            if bytes.len() != expected_byte_size {
                Err(Error::invalid("decompressed data"))
            }
            else {
                // convert data if compression method has output native format
                if !self.native_format(header) {
                    Ok(convert_little_endian_to_current(bytes, &header.channels, pixel_section))
                }
                else { Ok(bytes) }
            }
        }
    }
pub fn decompress_image_section ( self , header : & Header , compressed : ByteVec , pixel_section : IntegerBounds , pedantic : bool ) -> Result < ByteVec > { let max_tile_size = header . max_block_pixel_size ( ) ; assert ! ( pixel_section validate ( Some ( max_tile_size ) ) is_ok ( ) " " ) ; if header . deep { assert ! ( self supports_deep_data ( ) ) } let expected_byte_size = pixel_section . size . area ( ) * header . channels . bytes_per_pixel ; // FIXME this needs to account for subsampling anywhere if compressed . len ( ) == expected_byte_size { // the compressed data was larger than the raw data, so the small raw data has been written Ok ( convert_little_endian_to_current ( compressed , & header . channels , pixel_section ) ) } else { use self :: Compression :: * ; let bytes = match self { Uncompressed => Ok ( compressed ) , ZIP16 => zip :: decompress_bytes ( & compressed ) , ZIP1 => zip :: decompress_bytes ( & compressed ) , RLE => rle :: decompress_bytes ( & compressed , expected_byte_size , pedantic ) , PIZ => piz :: decompress ( & header . channels , compressed , pixel_section , expected_byte_size , pedantic ) , PXR24 => pxr24 :: decompress ( & header . channels , & compressed , pixel_section , expected_byte_size , pedantic ) , B44 | B44A => b44 :: decompress ( & header . channels , & compressed , pixel_section , expected_byte_size , pedantic ) , _ => return Err ( Error :: unsupported ( format ! ( " " self ) ) ) } ; // map all errors to compression errors let bytes = bytes . map_err ( | _ | Error :: invalid ( format ! ( " " self ) ) ) ? ; if bytes . len ( ) != expected_byte_size { Err ( Error :: invalid ( " " ) ) } else { // convert data if compression method has output native format if ! self . native_format ( header ) { Ok ( convert_little_endian_to_current ( bytes , & header . channels , pixel_section ) ) } else { Ok ( bytes ) } } } }
Decompress the image section of bytes.
Decompress the image section of bytes .
self
header
&Header
compressed
ByteVec
pixel_section
IntegerBounds
pedantic
bool