Supporting the last missing compression format will increase reliability of the library. Currently, you can never be sure if an arbitrary image can be opened.
Implementation Approach
All code will go into a new dwa module that has to be created inside the src/compression/ folder. Look at ./piz/mod.rs and ./b44/mod.rs as a starting point.
The functions in the new module will be called from src/compression/mod.rs. To be exact, it's called here for compression (probably two times, because DWA has two variants, DWAA and DWAB):
Note that the original implementation uses a Compressor class with mutable state. In the current Rust compression implementations, we only have two simple stateless functions instead: pub fn decompress(bytes, ...) -> bytes and pub fn compress(bytes, ...) -> bytes.
What the code should look like
There's some functionality in the compression::optimize_bytes module that you might be able to re-use, especially convert_little_endian_to_current and friends. Note that the C++ implementation has a lot of code duplication, as each compression method implements this algorithm again, look out for that part.
Of course, don't use unsafe code. For byte manipulations, have a look at the exr::io::Data trait. Also be sure to check out the existing piz and b44 Rust implementations if you are stuck. You can add unit tests in your new module. But even without any, you can still check your code simply by running cargo test. Big-endian support is not of high priority, so having little-endian alone would be great.
Why
Supporting the last missing compression format will increase reliability of the library. Currently, you can never be sure if an arbitrary image can be opened.
Implementation Approach
All code will go into a new
dwa
module that has to be created inside thesrc/compression/
folder. Look at./piz/mod.rs
and./b44/mod.rs
as a starting point.The functions in the new module will be called from
src/compression/mod.rs
. To be exact, it's called here for compression (probably two times, because DWA has two variants, DWAA and DWAB):https://github.com/johannesvollmer/exrs/blob/66a247789004d974043300daf7bfc57c7d52a459/src/compression/mod.rs#L175
and also here for decompression, probably also two times: https://github.com/johannesvollmer/exrs/blob/66a247789004d974043300daf7bfc57c7d52a459/src/compression/mod.rs#L216
Here's the reference implementation, in C++: https://github.com/AcademySoftwareFoundation/openexr/blob/main/src/lib/OpenEXR/ImfDwaCompressor.cpp
Note that the original implementation uses a
Compressor
class with mutable state. In the current Rust compression implementations, we only have two simple stateless functions instead:pub fn decompress(bytes, ...) -> bytes
andpub fn compress(bytes, ...) -> bytes
.What the code should look like
There's some functionality in the
compression::optimize_bytes
module that you might be able to re-use, especiallyconvert_little_endian_to_current
and friends. Note that the C++ implementation has a lot of code duplication, as each compression method implements this algorithm again, look out for that part.Of course, don't use unsafe code. For byte manipulations, have a look at the
exr::io::Data
trait. Also be sure to check out the existingpiz
andb44
Rust implementations if you are stuck. You can add unit tests in your new module. But even without any, you can still check your code simply by runningcargo test
. Big-endian support is not of high priority, so having little-endian alone would be great.