Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DWA Compression #197

Open
johannesvollmer opened this issue Feb 9, 2023 · 1 comment
Open

Add DWA Compression #197

johannesvollmer opened this issue Feb 9, 2023 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@johannesvollmer
Copy link
Owner

johannesvollmer commented Feb 9, 2023

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.

@johannesvollmer johannesvollmer added the enhancement New feature or request label Feb 9, 2023
@johannesvollmer johannesvollmer changed the title DWA Compression Add DWA Compression Feb 9, 2023
@johannesvollmer johannesvollmer added good first issue Good for newcomers help wanted Extra attention is needed labels Jul 10, 2023
@johannesvollmer
Copy link
Owner Author

some work started in a branch, feel free to join

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant