Skip to content

Commit

Permalink
Clamp incoming float values to half, instead of simply casting, on
Browse files Browse the repository at this point in the history
encode.

Casting can introduce Infs, which are zero'ed later on, prior to the
forward DCT step. This can have the nasty side effect of forcing
bright values to zero, instead of clamping them to 65k.
  • Loading branch information
Karl Rasche committed Nov 24, 2014
1 parent f4a6d3b commit cb172ee
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions OpenEXR/IlmImf/ImfDwaCompressor.cpp
Expand Up @@ -149,6 +149,7 @@
#include "ImathBox.h"
#include "ImathVec.h"
#include "half.h"
#include "halfLimits.h"

#include "dwaLookups.h"

Expand Down Expand Up @@ -1408,6 +1409,15 @@ DwaCompressor::LossyDctEncoderBase::execute ()
{

Xdr::read<CharPtrIO> (srcXdr, src);

//
// Clamp to half ranges, instead of just casting. This
// avoids introducing Infs which end up getting zeroed later
//
src = std::max (
std::min ((float) std::numeric_limits<half>::max(), src),
(float)-std::numeric_limits<half>::max());

Xdr::write<CharPtrIO> (dstXdr, ((half)src).bits());

//
Expand Down

0 comments on commit cb172ee

Please sign in to comment.