Skip to content

Commit 437f5cd

Browse files
committed
Add lossy HTJ2K
Signed-off-by: Pierre-Anthony Lemieux <pal@palemieux.com>
1 parent 830bfb5 commit 437f5cd

38 files changed

Lines changed: 555 additions & 101 deletions

cmake/OpenEXRSetup.cmake

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -432,18 +432,11 @@ if(TARGET Imath AND TARGET ImathConfig)
432432
"${_openexr_imath_cfg_compat}/Imath/ImathConfig.h" COPYONLY)
433433
endif()
434434

435-
# Add the build interface include directory, but only do it once;
436-
# if the cache key exists, it's already been added by a previous
437-
# configuration run.
438-
set(_openexr_imath_inc_patch_key "${Imath_SOURCE_DIR}|${Imath_BINARY_DIR}")
439-
if(NOT OPENEXR_IMATH_SUBDIR_INCLUDE_PATCH STREQUAL _openexr_imath_inc_patch_key)
440-
target_include_directories(Imath INTERFACE
441-
"$<BUILD_INTERFACE:${Imath_SOURCE_DIR}/src>")
442-
if(EXISTS "${_openexr_imath_gen_cfg}")
443-
target_include_directories(ImathConfig INTERFACE
444-
"$<BUILD_INTERFACE:${_openexr_imath_cfg_compat}>")
445-
endif()
446-
set(OPENEXR_IMATH_SUBDIR_INCLUDE_PATCH "${_openexr_imath_inc_patch_key}" CACHE INTERNAL "")
435+
target_include_directories(Imath INTERFACE
436+
"$<BUILD_INTERFACE:${Imath_SOURCE_DIR}/src>")
437+
if(EXISTS "${_openexr_imath_gen_cfg}")
438+
target_include_directories(ImathConfig INTERFACE
439+
"$<BUILD_INTERFACE:${_openexr_imath_cfg_compat}>")
447440
endif()
448441
endif()
449442
endif()

src/bin/exrmetrics/exrmetrics.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,10 @@ exrmetrics (
10221022
outHeaders[p].zipCompressionLevel () = level;
10231023
compressionSet = true;
10241024
break;
1025+
case HTJ2KL256_COMPRESSION:
1026+
outHeaders[p].lossyHTJ2KQuality () = level;
1027+
compressionSet = true;
1028+
break;
10251029
// case ZSTD_COMPRESSION :
10261030
// outHeader.zstdCompressionLevel()=level;
10271031
// break;
@@ -1061,7 +1065,7 @@ exrmetrics (
10611065
if (!isinf (level) && level >= -1 && !compressionSet)
10621066
{
10631067
throw runtime_error (
1064-
"-l option only works for DWAA/DWAB,ZIP/ZIPS or ZSTD compression");
1068+
"-l option only works for DWAA/DWAB, HTJ2KL256,ZIP/ZIPS or ZSTD compression");
10651069
}
10661070

10671071
vector<partData> parts (part == -1 ? in.parts () : 1);

src/bin/exrmetrics/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ usageMessage (ostream& stream, const char* program_name, bool verbose = false)
6464
" -t n Use a pool of n worker threads for processing files.\n"
6565
" Default is single threaded (no thread pool)\n"
6666
"\n"
67-
" -l level set DWA or ZIP compression level\n"
67+
" -l level set compression level for DWA, ZIP and lossy HTJ2K\n"
6868
"\n"
6969
" -z,--compression list list of compression methods to test\n"
7070
" ("

src/lib/OpenEXR/ImfCRgbaFile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ typedef struct ImfRgba ImfRgba;
8787
#define IMF_DWAB_COMPRESSION 9
8888
#define IMF_HTJ2K256_COMPRESSION 10
8989
#define IMF_HTJ2K32_COMPRESSION 11
90-
#define IMF_NUM_COMPRESSION_METHODS 12
90+
#define IMF_HTJ2KL256_COMPRESSION 12
91+
#define IMF_NUM_COMPRESSION_METHODS 13
9192

9293
/*
9394
** Channels; values must be the same as in Imf::RgbaChannels.

src/lib/OpenEXR/ImfCompression.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,22 @@ static const CompressionDesc IdToDesc[] = {
178178
false),
179179
CompressionDesc (
180180
"htj2k256",
181-
"High-Throughput JPEG 2000 (256 lines)",
181+
"High-Throughput JPEG 2000, lossless (256 lines)",
182182
256,
183183
false,
184184
false),
185185
CompressionDesc (
186186
"htj2k32",
187-
"High-Throughput JPEG 2000 (32 lines)",
187+
"High-Throughput JPEG 2000, lossless (32 lines)",
188188
32,
189189
false,
190190
false),
191+
CompressionDesc (
192+
"htj2kl256",
193+
"High-Throughput JPEG 2000, lossy (256 lines)",
194+
256,
195+
true,
196+
false),
191197
};
192198
// clang-format on
193199

@@ -206,6 +212,7 @@ static const std::map<std::string, Compression> CompressionNameToId = {
206212
{"dwab", Compression::DWAB_COMPRESSION},
207213
{"htj2k256", Compression::HTJ2K256_COMPRESSION},
208214
{"htj2k32", Compression::HTJ2K32_COMPRESSION},
215+
{"htj2kl256", Compression::HTJ2KL256_COMPRESSION},
209216
};
210217

211218
#define UNKNOWN_COMPRESSION_ID_MSG "INVALID COMPRESSION ID"

src/lib/OpenEXR/ImfCompression.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ enum IMF_EXPORT_ENUM Compression
5151
// wise and faster to decode full frames
5252
// than DWAA_COMPRESSION.
5353

54-
HTJ2K256_COMPRESSION = 10, // High-Throughput JPEG2000 (HTJ2K), 256 scanlines
54+
HTJ2K256_COMPRESSION = 10, // High-Throughput JPEG2000 (HTJ2K), lossless, 256 scanlines
5555

56-
HTJ2K32_COMPRESSION = 11, // High-Throughput JPEG2000 (HTJ2K), 32 scanlines
56+
HTJ2K32_COMPRESSION = 11, // High-Throughput JPEG2000 (HTJ2K), lossless, 32 scanlines
57+
58+
HTJ2KL256_COMPRESSION = 12, // High-Throughput JPEG2000 (HTJ2K), lossy, 256 scanlines
5759

5860
NUM_COMPRESSION_METHODS // number of different compression methods
5961
};

src/lib/OpenEXR/ImfCompressor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Compressor::Compressor (
5454

5555
exr_set_zip_compression_level (_ctxt, 0, hdr.zipCompressionLevel ());
5656
exr_set_dwa_compression_level (_ctxt, 0, hdr.dwaCompressionLevel ());
57+
exr_set_lossy_htj2k_quality (_ctxt, 0, hdr.lossyHTJ2KQuality ());
5758

5859
exr_compression_t hdrcomp;
5960
if (EXR_ERR_SUCCESS != exr_get_compression (_ctxt, 0, &hdrcomp))
@@ -337,6 +338,7 @@ newCompressor (Compression c, size_t maxScanLineSize, const Header& hdr)
337338
break;
338339

339340
case HTJ2K256_COMPRESSION:
341+
case HTJ2KL256_COMPRESSION:
340342

341343
return new HTCompressor (hdr, static_cast<int> (maxScanLineSize), 256);
342344

@@ -427,6 +429,7 @@ newTileCompressor (
427429

428430
case HTJ2K256_COMPRESSION:
429431
case HTJ2K32_COMPRESSION:
432+
case HTJ2KL256_COMPRESSION:
430433

431434
return new HTCompressor (
432435
hdr,

src/lib/OpenEXR/ImfContextInit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ class IMF_EXPORT_TYPE ContextInitializer
105105
return *this;
106106
}
107107

108+
ContextInitializer& setLossyHTJ2KQuality (float jq) noexcept
109+
{
110+
_initializer.lossy_htj2k_quality = jq;
111+
return *this;
112+
}
113+
108114
ContextInitializer& strictHeaderValidation (bool onoff) noexcept
109115
{
110116
setFlag (EXR_CONTEXT_FLAG_STRICT_HEADER, onoff);

src/lib/OpenEXR/ImfHeader.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ struct CompressionRecord
7171
{
7272
exr_get_default_zip_compression_level (&zip_level);
7373
exr_get_default_dwa_compression_quality (&dwa_level);
74+
exr_get_default_lossy_htj2k_quality (&lossy_htj2k_quality);
7475
}
7576
int zip_level;
7677
float dwa_level;
78+
float lossy_htj2k_quality;
7779
};
7880
// NB: This is extra complicated than one would normally write to
7981
// handle scenario that seems to happen on MacOS/Windows (probably
@@ -705,6 +707,18 @@ Header::dwaCompressionLevel () const
705707
return retrieveCompressionRecord (this).dwa_level;
706708
}
707709

710+
float&
711+
Header::lossyHTJ2KQuality ()
712+
{
713+
return retrieveCompressionRecord (this).lossy_htj2k_quality;
714+
}
715+
716+
float
717+
Header::lossyHTJ2KQuality () const
718+
{
719+
return retrieveCompressionRecord (this).lossy_htj2k_quality;
720+
}
721+
708722
void
709723
Header::setName (const string& name)
710724
{

src/lib/OpenEXR/ImfHeader.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,10 @@ class IMF_EXPORT_TYPE Header
286286
float& dwaCompressionLevel ();
287287
IMF_EXPORT
288288
float dwaCompressionLevel () const;
289+
IMF_EXPORT
290+
float& lossyHTJ2KQuality ();
291+
IMF_EXPORT
292+
float lossyHTJ2KQuality () const;
289293

290294
//-----------------------------------------------------
291295
// Access to required attributes for multipart files

0 commit comments

Comments
 (0)