Skip to content

Commit df16295

Browse files
authored
Adjust the clamping on the dwa compression (#1986)
* Adjust the clamping on the dwa compression The dwa compression is not truly a quality level like other things, so a maximal value is controlling quantization, not quality. A value of 0 is allowed, but negative is not. Signed-off-by: Kimball Thurston <[email protected]> * improve tests for dwa compression level set Signed-off-by: Kimball Thurston <[email protected]> --------- Signed-off-by: Kimball Thurston <[email protected]>
1 parent 97f8571 commit df16295

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/lib/OpenEXRCore/part.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,12 @@ exr_set_dwa_compression_level (exr_context_t ctxt, int part_index, float level)
609609
return EXR_UNLOCK_AND_RETURN (
610610
ctxt->standard_error (ctxt, EXR_ERR_NOT_OPEN_WRITE));
611611

612-
if (level > 0.f && level <= 100.f)
612+
// avoid bad math (fp exceptions or whatever) by clamping here
613+
// there has always been a clamp to 0, but on the upper end, there
614+
// is a limit too, where you only get black images anyway, so that
615+
// is not particularly useful, not that any large value will
616+
// really be crushing the image
617+
if (level >= 0.f && level <= (65504.f*100000.f))
613618
{
614619
part->dwa_compression_level = level;
615620
rv = EXR_ERR_SUCCESS;

src/test/OpenEXRCoreTest/write.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,16 @@ testWriteBaseHeader (const std::string& tempdir)
435435
exr_set_dwa_compression_level (outf, 0, -2.f));
436436
EXRCORE_TEST_RVAL_FAIL (
437437
EXR_ERR_INVALID_ARGUMENT,
438-
exr_set_dwa_compression_level (outf, 0, 420.f));
438+
exr_set_dwa_compression_level (outf, 0, INFINITY));
439+
EXRCORE_TEST_RVAL_FAIL (
440+
EXR_ERR_INVALID_ARGUMENT,
441+
exr_set_dwa_compression_level (outf, 0, NAN));
439442
EXRCORE_TEST_RVAL (exr_set_dwa_compression_level (outf, 0, 42.f));
440443
EXRCORE_TEST_RVAL (exr_get_dwa_compression_level (outf, 0, &dlev));
441444
EXRCORE_TEST (dlev == 42.f);
445+
EXRCORE_TEST_RVAL (exr_set_dwa_compression_level (outf, 0, 420.f));
446+
EXRCORE_TEST_RVAL (exr_get_dwa_compression_level (outf, 0, &dlev));
447+
EXRCORE_TEST (dlev == 420.f);
442448

443449
EXRCORE_TEST_RVAL (exr_finish (&outf));
444450
remove (outfn.c_str ());

0 commit comments

Comments
 (0)