Skip to content

Commit

Permalink
Adopt new compression API
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Leprince <[email protected]>
  • Loading branch information
pleprince committed Mar 13, 2024
1 parent 48fa372 commit ccac098
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/lib/OpenEXR/ImfCRgbaFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ typedef struct ImfRgba ImfRgba;
#define IMF_B44A_COMPRESSION 7
#define IMF_DWAA_COMPRESSION 8
#define IMF_DWAB_COMPRESSION 9
#define IMF_NUM_COMPRESSION_METHODS 10
#define IMF_ZSTD_COMPRESSION 10
#define IMF_NUM_COMPRESSION_METHODS 11

/*
** Channels; values must be the same as in Imf::RgbaChannels.
Expand Down
7 changes: 7 additions & 0 deletions src/lib/OpenEXR/ImfCompression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ static const CompressionDesc IdToDesc[] = {
256,
true,
false),
CompressionDesc (
"zstd",
"blosc zstd lossless compression, one scan line at a time.",
1,
false,
true),
};
// clang-format on

Expand All @@ -114,6 +120,7 @@ static const std::map<std::string, Compression> CompressionNameToId = {
{"b44a", Compression::B44A_COMPRESSION},
{"dwaa", Compression::DWAA_COMPRESSION},
{"dwab", Compression::DWAB_COMPRESSION},
{"zstd", Compression::ZSTD_COMPRESSION},
};

#define UNKNOWN_COMPRESSION_ID_MSG "INVALID COMPRESSION ID"
Expand Down
3 changes: 2 additions & 1 deletion src/lib/OpenEXR/ImfCompression.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ enum IMF_EXPORT_ENUM Compression
// wise and faster to decode full frames
// than DWAA_COMPRESSION.

ZSTD_COMPRESSION = 10,
ZSTD_COMPRESSION = 10, // blosc zstd lossless compression, one scan line
// at a time.

NUM_COMPRESSION_METHODS // number of different compression methods.
};
Expand Down
9 changes: 6 additions & 3 deletions src/lib/OpenEXR/ImfCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ newCompressor (Compression c, size_t maxScanLineSize, const Header& hdr)
DwaCompressor::STATIC_HUFFMAN);

case ZSTD_COMPRESSION:

return new ZstdCompressor (hdr);

default: return 0;
}
// clang-format on
Expand Down Expand Up @@ -135,9 +137,6 @@ newTileCompressor (
case ZIP_COMPRESSION:

return new ZipCompressor (hdr, tileLineSize, numTileLines);
case ZSTD_COMPRESSION:

return new ZstdCompressor (hdr);

case PIZ_COMPRESSION:

Expand Down Expand Up @@ -171,6 +170,10 @@ newTileCompressor (
static_cast<int> (numTileLines),
DwaCompressor::STATIC_HUFFMAN);

case ZSTD_COMPRESSION:

return new ZstdCompressor (hdr);

default: return 0;
}
// clang-format on
Expand Down
5 changes: 3 additions & 2 deletions src/lib/OpenEXR/ImfZstdCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace
{
std::mutex g_mutex;
}

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER

ZstdCompressor::ZstdCompressor (const Header& hdr)
Expand All @@ -26,7 +26,8 @@ ZstdCompressor::ZstdCompressor (const Header& hdr)
int
ZstdCompressor::numScanLines () const
{
return (int)exr_get_zstd_lines_per_chunk(); // Needs to be in sync with ImfCompressor::numLinesInBuffer
// Needs to be in sync with ImfCompressor::numLinesInBuffer
return (int) exr_get_zstd_lines_per_chunk ();
}

int
Expand Down
10 changes: 6 additions & 4 deletions src/lib/OpenEXR/ImfZstdCompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@
#include "vector"

OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER

class ZstdCompressor : public Compressor
{
public:
explicit ZstdCompressor (const Header& hdr);

private:
using raw_ptr = std::unique_ptr<char, decltype (&free)>;
std::vector<raw_ptr> _outBuffer;
int numScanLines () const override; // max
int compress (
const char* inPtr, int inSize, int minY, const char*& outPtr) override;
std::vector<raw_ptr> _outBuffer;
int numScanLines () const override; // max
int compress (
const char* inPtr, int inSize, int minY, const char*& outPtr) override;
int uncompress (
const char* inPtr, int inSize, int minY, const char*& outPtr) override;
};
Expand Down

0 comments on commit ccac098

Please sign in to comment.