/// Compress the image section of bytes.
Compress the image section of bytes.
Compress the image section of bytes .
pub fn compress_image_section(self, header: &Header, mut uncompressed: ByteVec, pixel_section: IntegerBounds) -> 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()) }
        // convert data if compression method expects native format
        // see https://github.com/AcademySoftwareFoundation/openexr/blob/3bd93f85bcb74c77255f28cdbb913fdbfbb39dfe/OpenEXR/IlmImf/ImfTiledOutputFile.cpp#L750-L842
        if !self.native_format(header) {
            uncompressed = convert_current_to_little_endian(uncompressed, &header.channels, pixel_section);
        }
        use self::Compression::*;
        let compressed = match self {
            Uncompressed => Ok(uncompressed.clone()), // TODO no clone!
            ZIP16 => zip::compress_bytes(&uncompressed),
            ZIP1 => zip::compress_bytes(&uncompressed),
            RLE => rle::compress_bytes(&uncompressed),
            PIZ => piz::compress(&header.channels, &uncompressed, pixel_section),
            PXR24 => pxr24::compress(&header.channels, &uncompressed, pixel_section),
            B44 => b44::compress(&header.channels, &uncompressed, pixel_section, false),
            B44A => b44::compress(&header.channels, &uncompressed, pixel_section, true),
            _ => return Err(Error::unsupported(format!("yet unimplemented compression method: {}", self)))
        };
        let compressed = compressed.map_err(|_|
            Error::invalid(format!("pixels cannot be compressed ({})", self))
        )?;
        if compressed.len() < uncompressed.len() {
            // only write compressed if it actually is smaller than raw
            Ok(compressed)
        }
        else {
            // manually convert uncompressed data
            Ok(convert_current_to_little_endian(uncompressed, &header.channels, pixel_section))
        }
    }
pub fn compress_image_section ( self , header : & Header , mut uncompressed : ByteVec , pixel_section : IntegerBounds ) -> 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 ( ) ) } // convert data if compression method expects native format // see https://github.com/AcademySoftwareFoundation/openexr/blob/3bd93f85bcb74c77255f28cdbb913fdbfbb39dfe/OpenEXR/IlmImf/ImfTiledOutputFile.cpp#L750-L842 if ! self . native_format ( header ) { uncompressed = convert_current_to_little_endian ( uncompressed , & header . channels , pixel_section ) ; } use self :: Compression :: * ; let compressed = match self { Uncompressed => Ok ( uncompressed . clone ( ) ) , // TODO no clone! ZIP16 => zip :: compress_bytes ( & uncompressed ) , ZIP1 => zip :: compress_bytes ( & uncompressed ) , RLE => rle :: compress_bytes ( & uncompressed ) , PIZ => piz :: compress ( & header . channels , & uncompressed , pixel_section ) , PXR24 => pxr24 :: compress ( & header . channels , & uncompressed , pixel_section ) , B44 => b44 :: compress ( & header . channels , & uncompressed , pixel_section , false ) , B44A => b44 :: compress ( & header . channels , & uncompressed , pixel_section , true ) , _ => return Err ( Error :: unsupported ( format ! ( " " self ) ) ) } ; let compressed = compressed . map_err ( | _ | Error :: invalid ( format ! ( " " self ) ) ) ? ; if compressed . len ( ) < uncompressed . len ( ) { // only write compressed if it actually is smaller than raw Ok ( compressed ) } else { // manually convert uncompressed data Ok ( convert_current_to_little_endian ( uncompressed , & header . channels , pixel_section ) ) } }
Compress the image section of bytes.
Compress the image section of bytes .
self
header
&Header
uncompressed
ByteVec
pixel_section
IntegerBounds