Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/OpenEXR/IlmImf/ImfDwaCompressor.cpp view on Meta::CPAN
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
};
return numBitsSet[src & 0xff] + numBitsSet[src >> 8];
}
//
// Take a DCT coefficient, as well as an acceptable error. Search
// nearby values within the error tolerance, that have fewer
// bits set.
//
// The list of candidates has been pre-computed and sorted
// in order of increasing numbers of bits set. This way, we
// can stop searching as soon as we find a candidate that
// is within the error tolerance.
//
half
DwaCompressor::LossyDctEncoderBase::quantize (half src, float errorTolerance)
{
half tmp;
float srcFloat = (float)src;
int numSetBits = countSetBits(src.bits());
const unsigned short *closest = closestData + closestDataOffset[src.bits()];
for (int targetNumSetBits = numSetBits - 1;
targetNumSetBits >= 0;
--targetNumSetBits)
{
tmp.setBits (*closest);
if (fabs ((float)tmp - srcFloat) < errorTolerance)
return tmp;
closest++;
}
return src;
}
//
// RLE the zig-zag of the AC components + copy over
// into another tmp buffer
//
// Try to do a simple RLE scheme to reduce run's of 0's. This
// differs from the jpeg EOB case, since EOB just indicates that
// the rest of the block is zero. In our case, we have lots of
// NaN symbols, which shouldn't be allowed to occur in DCT
// coefficents - so we'll use them for encoding runs.
//
// If the high byte is 0xff, then we have a run of 0's, of length
// given by the low byte. For example, 0xff03 would be a run
// of 3 0's, starting at the current location.
//
// block is our block of 64 coefficients
// acPtr a pointer to back the RLE'd values into.
//
// This will advance the counter, _numAcComp.
//
void
DwaCompressor::LossyDctEncoderBase::rleAc
(half *block,
unsigned short *&acPtr)
{
int dctComp = 1;
unsigned short rleSymbol = 0x0;
while (dctComp < 64)
{
int runLen = 1;
//
// If we don't have a 0, output verbatim
//
if (block[dctComp].bits() != rleSymbol)
{
*acPtr++ = block[dctComp].bits();
_numAcComp++;
dctComp += runLen;
continue;
}
//
// We're sitting on a 0, so see how big the run is.
//
while ((dctComp+runLen < 64) &&
(block[dctComp+runLen].bits() == rleSymbol))
{
runLen++;
}
//
// If the run len is too small, just output verbatim
// otherwise output our run token
//
// Originally, we wouldn't have a separate symbol for
// "end of block". But in some experimentation, it looks
// like using 0xff00 for "end of block" can save a bit
// of space.
//
if (runLen == 1)
{
runLen = 1;
( run in 0.434 second using v1.01-cache-2.11-cpan-f6376fbd888 )