Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/OpenEXR/IlmImf/ImfDwaCompressor.cpp view on Meta::CPAN
//
// 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;
*acPtr++ = block[dctComp].bits();
_numAcComp++;
//
// Using 0xff00 for "end of block"
//
}
else if (runLen + dctComp == 64)
{
//
// Signal EOB
//
*acPtr++ = 0xff00;
_numAcComp++;
}
else
{
//
// Signal normal run
//
*acPtr++ = 0xff00 | runLen;
_numAcComp++;
}
//
// Advance by runLen
//
dctComp += runLen;
}
}
// ==============================================================
//
// DwaCompressor
//
// --------------------------------------------------------------
//
// DwaCompressor()
//
DwaCompressor::DwaCompressor
(const Header &hdr,
int maxScanLineSize,
int numScanLines,
AcCompression acCompression)
:
Compressor(hdr),
_acCompression(acCompression),
( run in 1.408 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )