| 1 |
|
| 2 | // see https://github.com/openexr/openexr/blob/master/OpenEXR/IlmImf/ImfCompressor.cpp
|
| 3 |
|
| 4 |
|
| 5 | use super::*;
|
| 6 | use super::optimize_bytes::*;
|
| 7 | use crate::error::Result;
|
| 8 |
|
| 9 | // scanline decompression routine, see https://github.com/openexr/openexr/blob/master/OpenEXR/IlmImf/ImfScanLineInputFile.cpp
|
| 10 | // 1. Uncompress the data, if necessary (If the line is uncompressed, it's in XDR format, regardless of the compressor's output format.)
|
| 11 | // 3. Convert one scan line's worth of pixel data back from the machine-independent representation
|
| 12 | // 4. Fill the frame buffer with pixel data, respective to sampling and whatnot
|
| 13 |
|
| 14 |
|
| 15 | pub fn decompress_bytes(
|
| 16 | channels: &ChannelList,
|
| 17 | data: ByteVec,
|
| 18 | rectangle: IntegerBounds,
|
| 19 | expected_byte_size: usize,
|
| 20 | _pedantic: bool,
|
| 21 | ) -> Result<ByteVec> {
|
| 22 | let options: DeflateOptions = zune_inflate::DeflateOptions::default().set_limit(expected_byte_size).set_size_hint(expected_byte_size);
|
| 23 | let mut decoder: DeflateDecoder<'_> = zune_inflate::DeflateDecoder::new_with_options(&data, options);
|
| 24 | let mut decompressed: Vec = decoder.decode_zlib()
|
| 25 | .map_err(|_| Error::invalid(message:"zlib-compressed data malformed" ))?;
|
| 26 |
|
| 27 | differences_to_samples(&mut decompressed);
|
| 28 | interleave_byte_blocks(&mut decompressed);
|
| 29 |
|
| 30 | Ok(super::convert_little_endian_to_current(bytes:decompressed, channels, rectangle))// TODO no alloc
|
| 31 | }
|
| 32 |
|
| 33 | pub fn compress_bytes(channels: &ChannelList, uncompressed: ByteVec, rectangle: IntegerBounds) -> Result<ByteVec> {
|
| 34 | // see https://github.com/AcademySoftwareFoundation/openexr/blob/3bd93f85bcb74c77255f28cdbb913fdbfbb39dfe/OpenEXR/IlmImf/ImfTiledOutputFile.cpp#L750-L842
|
| 35 | let mut packed: Vec = convert_current_to_little_endian(bytes:uncompressed, channels, rectangle);
|
| 36 |
|
| 37 | separate_bytes_fragments(&mut packed);
|
| 38 | samples_to_differences(&mut packed);
|
| 39 |
|
| 40 | Ok(miniz_oxide::deflate::compress_to_vec_zlib(input:packed.as_slice(), level:4))
|
| 41 | }
|
| 42 | |