Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

arithcodec.cpp File Reference

Definitions of class ArithCodec methods. More...

#include "arithcodec.h"
#include "unroll.h"

Go to the source code of this file.

Defines

#define OUTPUT_BIT(b)
 Output one bit to output device. More...

#define UNGET_BIT(b)
 Return bit to input stream. More...

#define ADD_NEXT_INPUT_BIT(v, garbageBits)
 Read one bit from input device. More...

#define ORIG_BIT_PLUS_FOLLOW(b)
#define BIT_PLUS_FOLLOW(x)
#define ENCODE_RENORMALISE
#define DECODE_RENORMALISE
#define UNROLL_NUM   B_BITS - F_BITS - 1
#define UNROLL_CODE
#define UNROLL_NUM   B_BITS - F_BITS - 1
#define UNROLL_CODE
#define UNROLL_NUM   F_BITS - 1
#define UNROLL_CODE
#define UNROLL_NUM   B_BITS - F_BITS - 1
#define UNROLL_CODE

Functions

 if (high< total) out_R=temp2-temp
 if (outBitsOutstanding > MAX_BITS_OUTSTANDING) FATAL("Bits_outstanding limit reached-File too large!")

Variables

UNROLL_CODE UNROLL_CODE UNROLL_CODE
UNROLL_CODE 
out_L = temp
else out_R = temp
 ENCODE_RENORMALISE
UNROLL_CODE UNROLL_CODE UNROLL_CODE
UNROLL_CODE 
A = in_D
 target = 0
UNROLL_CODE UNROLL_CODE UNROLL_CODE
UNROLL_CODE 
in_D = temp
else in_R = temp
 DECODE_RENORMALISE


Detailed Description

Definitions of class ArithCodec methods.

This file contains definitions of class ArithCodec methods.

Definition in file arithcodec.cpp.


Define Documentation

#define ADD_NEXT_INPUT_BIT v,
garbageBits   
 

Value:

{                                                                       \
  if (inBitPtr == 0)                                                    \
    {                                                                   \
      if (inputDevice->getChar(&inBuffer) == EndOfFile)                 \
        {                                                               \
          inGarbage++;                                                  \
          if ((FreqValue)((inGarbage-1)*8) >= garbageBits)              \
            FATAL("Bad input file - attempted read past end of file."); \
        }                                                               \
      inBitPtr = (1<<(BYTE_SIZE-1));                                    \
    }                                                                   \
    v <<= 1;                                                            \
                                                                        \
  if (inBuffer & inBitPtr)                                              \
    v++;                                                                \
                                                                        \
  inBitPtr >>= 1;                                                       \
}
Read one bit from input device.

Macro shifts \v left and sets its leas significant bit to the value of read bit.

Parameters:
v  Buffer of bits.
garbageBits  Number of bits past end of file.

Definition at line 121 of file arithcodec.cpp.

#define BIT_PLUS_FOLLOW  
 

Value:

{                                               \
     if (ignoreFirstBit)                        \
       ignoreFirstBit = 0;                      \
     else                                       \
       ORIG_BIT_PLUS_FOLLOW(x);                 \
   }
Output one bit and bit based on bitsOutstanding. First bit is ignored.
Parameters:
x  Value of the bit.

Definition at line 166 of file arithcodec.cpp.

#define DECODE_RENORMALISE
 

Value:

{                                               \
     while (in_R <= Quarter)                    \
       {                                        \
         in_R <<= 1;                            \
         in_V <<= 1;                            \
         ADD_NEXT_INPUT_BIT(in_D,B_BITS);       \
         if (in_D & 1)                          \
           in_V++;                              \
       }                                        \
   }
Input code bits until range has been expanded to more than Quarter. Mimics encoder. FRUGAL_BITS option also keeps track of bitstream input so it can work out exactly how many disambiguating bits the encoder put out (1, 2 or 3).

Definition at line 218 of file arithcodec.cpp.

#define ENCODE_RENORMALISE
 

Value:

{                                       \
  while (out_R <= Quarter)              \
    {                                   \
      if (out_L >= Half)                \
        {                               \
          BIT_PLUS_FOLLOW(1);           \
          out_L -= Half;                \
        }                               \
      else                              \
        if (out_L+out_R <= Half)        \
          {                             \
            BIT_PLUS_FOLLOW(0);         \
          }                             \
        else                            \
          {                             \
            outBitsOutstanding++;       \
            out_L -= Quarter;           \
          }                             \
      out_L <<= 1;                      \
      out_R <<= 1;                      \
  }                                     \
}
Output code bits until the range has been expanded to above Quarter. With FRUGAL_BITS option, ignore first zero bit output (a redundant zero will otherwise be emitted every time the encoder is started).

Definition at line 188 of file arithcodec.cpp.

Referenced by ArithCodec::arithmeticEncode.

#define ORIG_BIT_PLUS_FOLLOW  
 

Value:

{                                       \
  OUTPUT_BIT(b);                        \
                                        \
  while (outBitsOutstanding > 0)        \
    {                                   \
      OUTPUT_BIT(!b);                   \
      outBitsOutstanding--;             \
    }                                   \
}
Output given bit and an opposite number of bit equal to the value stored in bitsOutstanding.
Parameters:
b  Value of the but.

Definition at line 148 of file arithcodec.cpp.

#define OUTPUT_BIT  
 

Value:

{                                       \
  outBuffer <<= 1;                      \
  if (b)                                \
    outBuffer |= 1;                     \
  outBitsToGo--;                        \
  if (outBitsToGo == 0)                 \
    {                                   \
      outputDevice->putChar(outBuffer); \
      numberOfBytes++;                  \
      outBitsToGo = BYTE_SIZE;          \
      outBuffer = 0;                    \
    }                                   \
}
Output one bit to output device.

When BYTE_SIZE bits are queued in outBuffer, these are output to the output device.

Parameters:
b  Value of the bit.

Definition at line 73 of file arithcodec.cpp.

#define UNGET_BIT  
 

Value:

{                                       \
  inBitPtr <<= 1;                       \
                                        \
  if (inBitPtr == 0)                    \
    inBitPtr = 1;                       \
                                        \
        \
  inBuffer = inBuffer & (inBitPtr - 1); \
  if (b)                                \
                        \
    inBuffer |= inBitPtr;               \
}
Return bit to input stream.

Only guaranteed to be able to backup by 1 bit.

Parameters:
b  Value of the bit.

Definition at line 97 of file arithcodec.cpp.

#define UNROLL_CODE
 

Value:

M <<= 1; temp <<= 1; temp2 <<= 1;               \
    if (M & Half)                               \
      {                                         \
        temp += low; temp2 += high;             \
      }

#define UNROLL_CODE
 

Value:

A <<= 1; target <<= 1;          \
    if (A >= M)                         \
      {                                 \
        A -= M; target++;               \
      }

#define UNROLL_CODE
 

Value:

A <<= 1; in_r <<= 1;            \
    if (A >= M)                         \
      {                                 \
        A -= M; in_r++;                 \
      }

#define UNROLL_CODE
 

Value:

A <<= 1; temp <<= 1; temp2 <<= 1;               \
    if (A >= M)                                 \
      {                                         \
        A -= M; temp += low; temp2 += high;     \
      }


Generated on Wed Feb 5 10:43:03 2003 for Exalt by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002