Skip to content

Add DWA Compression #197

Open
Open
@johannesvollmer

Description

@johannesvollmer

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 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):

B44A => b44::compress(&header.channels, &uncompressed_native_endian, pixel_section, true),

and also here for decompression, probably also two times:

B44 | B44A => b44::decompress(&header.channels, compressed, pixel_section, expected_byte_size, pedantic),

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 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions