\hypertarget{HDD_8c}{
\section{HDD.c File Reference}
\label{HDD_8c}\index{HDD.c@{HDD.c}}
}
Implementation ofthe routines to decode a distribution of symbols previously encoded using HDE\_\-encode\-SS. 

{\tt \#include \char`\"{}LDT/HDD.h\char`\"{}}\par
{\tt \#include \char`\"{}LDT/HUFF.h\char`\"{}}\par
{\tt \#include \char`\"{}LDT/BFU.h\char`\"{}}\par
{\tt \#include \char`\"{}ffs.h\char`\"{}}\par
{\tt \#include \char`\"{}PBI/Endianness.h\char`\"{}}\par
{\tt \#include \char`\"{}dprintf.h\char`\"{}}\par


Include dependency graph for HDD.c:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=228pt]{HDD_8c__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct {\bf \_\-HDD}
\item 
union \hyperlink{struct__DeltaInfo__bf}{\_\-Delta\-Info\_\-bf}
\begin{CompactList}\small\item\em Union of the delta information word as (signed) bit fields. \item\end{CompactList}\item 
union \hyperlink{union__DeltaInfo}{\_\-Delta\-Info}
\begin{CompactList}\small\item\em Union of the delta information word as an interpretted 32-bit integer and its (signed) bit fields. \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{HDD_8c_a0}{
\#define {\bf \_\-CV\_\-TO\_\-CODETREE}(\_\-0, \_\-1, \_\-2)~((\_\-2  $<$$<$ 4) $|$ (\_\-1  $<$$<$ 2) $|$ (\_\-0  $<$$<$ 0))}
\label{HDD_8c_a0}

\item 
\hypertarget{HDD_8c_a1}{
\#define {\bf \_\-CODES}(\_\-c0, \_\-c1, \_\-c2)~((\_\-c2 $<$$<$ 4) $|$ (\_\-c1 $<$$<$ 2) $|$ (\_\-c0 $<$$<$ 0))}
\label{HDD_8c_a1}

\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{HDD_8c_a2}{
typedef \_\-HDD {\bf HDD}}
\label{HDD_8c_a2}

\item 
typedef \hyperlink{struct__DeltaInfo__bf}{\_\-Delta\-Info\_\-bf} \hyperlink{HDD_8c_a3}{Delta\-Info\_\-bf}
\begin{CompactList}\small\item\em Typedef for union \hyperlink{struct__DeltaInfo__bf}{\_\-Delta\-Info\_\-bf}. \item\end{CompactList}\item 
\hypertarget{HDD_8c_a4}{
typedef \hyperlink{union__DeltaInfo}{\_\-Delta\-Info} \hyperlink{HDD_8c_a4}{Delta\-Info}}
\label{HDD_8c_a4}

\begin{CompactList}\small\item\em Typedef for union \hyperlink{union__DeltaInfo}{\_\-Delta\-Info}. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} \hyperlink{HDD_8c_a5}{unpack\_\-code\_\-lens} (unsigned char $\ast$lens, int nlens, const unsigned int $\ast$src, unsigned int max, \hyperlink{struct__BFU}{BFU} bfu)
\begin{CompactList}\small\item\em Dispatch routine to unpack the deltas and form the code length array when the deltas are themselves encoded as a Huffman table. \item\end{CompactList}\item 
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} \hyperlink{HDD_8c_a6}{unpack\_\-code\_\-lens1} (unsigned char $\ast$lens, int nlens, unsigned int seed, int min, const unsigned int $\ast$src, unsigned int max, \hyperlink{struct__BFU}{BFU} bfu)
\begin{CompactList}\small\item\em Optimized routine to unpack the deltas and form the code length array when the deltas are all 0s or 1s. \item\end{CompactList}\item 
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} \hyperlink{HDD_8c_a7}{unpack\_\-code\_\-lens2} (unsigned char $\ast$lens, int nlens, unsigned int seed, int min, const unsigned int $\ast$src, unsigned int max, \hyperlink{struct__BFU}{BFU} bfu)
\begin{CompactList}\small\item\em Optimized routine to unpack the deltas and form the code length array when the deltas ranges is 2 (0,1,2). \item\end{CompactList}\item 
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} \hyperlink{HDD_8c_a8}{unpack\_\-code\_\-lens\-N} (unsigned char $\ast$lens, int nlens, unsigned int seed, int delta\_\-min, int delta\_\-max, const unsigned int $\ast$src, unsigned int max, \hyperlink{struct__BFU}{BFU} bfu)
\begin{CompactList}\small\item\em Generic routine to unpack the deltas and form the code length array when the deltas are themselves encoded as a Huffman table The routines unpack\_\-deltas1 and deltas2 are used when the range of the huffman encoding table is only 1 (2 symbols) or 2 (3 symbols) In these cases, a more optimal scheme, tailored to these small tables is used. \item\end{CompactList}\item 
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} \hyperlink{HDD_8c_a9}{unpack\_\-syms} (signed short int $\ast$syms, int nsyms, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$dtable, int nlens, int min, unsigned int nunderflow, unsigned int noverflow, const unsigned int $\ast$src, unsigned int max, \hyperlink{struct__BFU}{BFU} bfu)
\begin{CompactList}\small\item\em Restores the differences between the original PHA value and its pedestal. \item\end{CompactList}\item 
\hypertarget{HDD_8c_a10}{
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} {\bf unpack\_\-short} (\hyperlink{struct__BFU}{BFU} bfu, const unsigned int $\ast$src, int $\ast$val)}
\label{HDD_8c_a10}

\item 
\hypertarget{HDD_8c_a11}{
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} {\bf unpack\_\-nshort} (\hyperlink{struct__BFU}{BFU} bfu, const unsigned int $\ast$src, int $\ast$val)}
\label{HDD_8c_a11}

\item 
\hypertarget{HDD_8c_a12}{
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} {\bf unpack\_\-ushort} (\hyperlink{struct__BFU}{BFU} bfu, const unsigned int $\ast$src, unsigned int $\ast$val)}
\label{HDD_8c_a12}

\item 
\hypertarget{HDD_8c_a13}{
static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} {\bf unpack\_\-delta\_\-min\_\-max\_\-seed} (\hyperlink{struct__BFU}{BFU} bfu, const unsigned int $\ast$src, int $\ast$delta\_\-min, int $\ast$delta\_\-max, unsigned int $\ast$seed)}
\label{HDD_8c_a13}

\item 
unsigned int \hyperlink{HDD_8c_a14}{HDD\_\-sizeof} (unsigned int nhuff)
\begin{CompactList}\small\item\em Returns the size, in bytes, for a handle to hold a Huffman distribution of {\em huffman\_\-bins\/}. \item\end{CompactList}\item 
void $\ast$ \hyperlink{HDD_8c_a15}{HDD\_\-construct} (HDD $\ast$hdd, unsigned int nhuff)
\begin{CompactList}\small\item\em Constructs (initializes) the specified HDD structure. \item\end{CompactList}\item 
unsigned int \hyperlink{HDD_8c_a16}{HDD\_\-decode\-S} (HDD $\ast$hdd, const unsigned int $\ast$src, unsigned int pos, unsigned int max\_\-pos, unsigned short int $\ast$syms, unsigned int nsyms)
\begin{CompactList}\small\item\em Unpacks the distribution encoded with HDD\_\-encode\-SS. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Implementation ofthe routines to decode a distribution of symbols previously encoded using HDE\_\-encode\-SS. 

\begin{Desc}
\item[Author:]JJRussell - \href{mailto:russell@slac.stanford.edu}{\tt russell@slac.stanford.edu}\end{Desc}


\footnotesize\begin{verbatim}   CVS $Id: HDD.c,v 1.4 2006/11/19 14:34:06 russell Exp $
\end{verbatim}
\normalsize


\subsection{Typedef Documentation}
\hypertarget{HDD_8c_a3}{
\index{HDD.c@{HDD.c}!DeltaInfo_bf@{DeltaInfo\_\-bf}}
\index{DeltaInfo_bf@{DeltaInfo\_\-bf}!HDD.c@{HDD.c}}
\subsubsection[DeltaInfo\_\-bf]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{struct__DeltaInfo__bf}{Delta\-Info\_\-bf}}}
\label{HDD_8c_a3}


Typedef for union \hyperlink{struct__DeltaInfo__bf}{\_\-Delta\-Info\_\-bf}. 

The advantage of defining these structures is that it allows the compiler to sign-extend the bit fields where needed.

\subsection{Function Documentation}
\hypertarget{HDD_8c_a15}{
\index{HDD.c@{HDD.c}!HDD_construct@{HDD\_\-construct}}
\index{HDD_construct@{HDD\_\-construct}!HDD.c@{HDD.c}}
\subsubsection[HDD\_\-construct]{\setlength{\rightskip}{0pt plus 5cm}void$\ast$ HDD\_\-construct (HDD $\ast$ {\em hdd}, unsigned int {\em nhuff})}}
\label{HDD_8c_a15}


Constructs (initializes) the specified HDD structure. 

\begin{Desc}
\item[Returns:]The next address after this structure.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hdd}]The HDD control structure to construct \item[{\em nhuff}]The maximum number of Huffman encoding bins that this control structure is meant to support.\end{description}
\end{Desc}
The size of this structure should be acquired by a call to HDD\_\-sizeof. The parameter {\em huffman\_\-nbins\/} must be the same in the call to HDD\_\-sizeof and HDD\_\-construct.\hypertarget{HDD_8c_a16}{
\index{HDD.c@{HDD.c}!HDD_decodeS@{HDD\_\-decodeS}}
\index{HDD_decodeS@{HDD\_\-decodeS}!HDD.c@{HDD.c}}
\subsubsection[HDD\_\-decodeS]{\setlength{\rightskip}{0pt plus 5cm}unsigned int HDD\_\-decode\-S (HDD $\ast$ {\em hdd}, const unsigned int $\ast$ {\em src}, unsigned int {\em pos}, unsigned int {\em max\_\-pos}, unsigned short int $\ast$ {\em syms}, unsigned int {\em nsyms})}}
\label{HDD_8c_a16}


Unpacks the distribution encoded with HDD\_\-encode\-SS. 

\begin{Desc}
\item[Returns:]The next bit position to read.\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em hdd}]The decode handle \item[{\em src}]The source stream \item[{\em pos}]The current bit read position \item[{\em max\_\-pos}]The maximum bit position, {\em i.e\/}. do not read past this point \item[{\em syms}]The array to receive the decoded symbols \item[{\em nsyms}]The number of symbols to decode\end{description}
\end{Desc}
\hypertarget{HDD_8c_a14}{
\index{HDD.c@{HDD.c}!HDD_sizeof@{HDD\_\-sizeof}}
\index{HDD_sizeof@{HDD\_\-sizeof}!HDD.c@{HDD.c}}
\subsubsection[HDD\_\-sizeof]{\setlength{\rightskip}{0pt plus 5cm}unsigned int HDD\_\-sizeof (unsigned int {\em nhuff})}}
\label{HDD_8c_a14}


Returns the size, in bytes, for a handle to hold a Huffman distribution of {\em huffman\_\-bins\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em nhuff}]The maximum number of Huffman codes\end{description}
\end{Desc}
For the most part, this only provides a working area. On host-based workstations with expandable stacks, this memory would go on the stack, except for the fact that it is variable length.\hypertarget{HDD_8c_a5}{
\index{HDD.c@{HDD.c}!unpack_code_lens@{unpack\_\-code\_\-lens}}
\index{unpack_code_lens@{unpack\_\-code\_\-lens}!HDD.c@{HDD.c}}
\subsubsection[unpack\_\-code\_\-lens]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} unpack\_\-code\_\-lens (unsigned char $\ast$ {\em lens}, int {\em nlens}, const unsigned int $\ast$ {\em src}, unsigned int {\em max}, \hyperlink{struct__BFU}{BFU} {\em bfu})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HDD_8c_a5}


Dispatch routine to unpack the deltas and form the code length array when the deltas are themselves encoded as a Huffman table. 

\begin{Desc}
\item[Returns:]The updated bit position and current deblocked 32-bit buffer\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em lens}]The array of code lengths to fill in \item[{\em nlens}]The number of lengths to fill in \item[{\em src}]The data source, i.e. the bit stream \item[{\em max}]The maximum bit position \item[{\em bfu}]The current bit position and temporary buffer\end{description}
\end{Desc}
\hypertarget{HDD_8c_a6}{
\index{HDD.c@{HDD.c}!unpack_code_lens1@{unpack\_\-code\_\-lens1}}
\index{unpack_code_lens1@{unpack\_\-code\_\-lens1}!HDD.c@{HDD.c}}
\subsubsection[unpack\_\-code\_\-lens1]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} unpack\_\-code\_\-lens1 (unsigned char $\ast$ {\em lens}, int {\em nlens}, unsigned int {\em seed}, int {\em min}, const unsigned int $\ast$ {\em src}, unsigned int {\em max}, \hyperlink{struct__BFU}{BFU} {\em bfu})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HDD_8c_a6}


Optimized routine to unpack the deltas and form the code length array when the deltas are all 0s or 1s. 

\begin{Desc}
\item[Returns:]The updated bit position and current deblocked 32-bit buffer\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em lens}]The array of code lengths to fill in \item[{\em nlens}]The number of lengths to fill in \item[{\em seed}]The starting value to integrate the deltas from \item[{\em min}]The minimum delta, this is almost certainly 0, but.. \item[{\em src}]The data source, i.e. the bit stream \item[{\em max}]The maximum bit position \item[{\em bfu}]The current bit position and temporary buffer\end{description}
\end{Desc}
This routine starts at the mid point and works its way first down to the code length 0, then restarts and works its way up to the last code length. In each case the deltas are integrated starting with the seed value\hypertarget{HDD_8c_a7}{
\index{HDD.c@{HDD.c}!unpack_code_lens2@{unpack\_\-code\_\-lens2}}
\index{unpack_code_lens2@{unpack\_\-code\_\-lens2}!HDD.c@{HDD.c}}
\subsubsection[unpack\_\-code\_\-lens2]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} unpack\_\-code\_\-lens2 (unsigned char $\ast$ {\em lens}, int {\em nlens}, unsigned int {\em seed}, int {\em min}, const unsigned int $\ast$ {\em src}, unsigned int {\em max}, \hyperlink{struct__BFU}{BFU} {\em bfu})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HDD_8c_a7}


Optimized routine to unpack the deltas and form the code length array when the deltas ranges is 2 (0,1,2). 

\begin{Desc}
\item[Returns:]The updated bit position and current deblocked 32-bit buffer\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em lens}]The array of code lengths to fill in \item[{\em nlens}]The number of lengths to fill in \item[{\em seed}]The starting value to integrate the deltas from \item[{\em min}]The minimum delta, this is almost certainly -1 or 0 \item[{\em src}]The data source, i.e. the bit stream \item[{\em max}]The maximum bit position \item[{\em bfu}]The current bit position and temporary buffer\end{description}
\end{Desc}
This routine starts at the mid point and works its way first down to the code length 0, then restarts and works its way up to the last code length. In each case the deltas are integrated starting with the seed value\hypertarget{HDD_8c_a8}{
\index{HDD.c@{HDD.c}!unpack_code_lensN@{unpack\_\-code\_\-lensN}}
\index{unpack_code_lensN@{unpack\_\-code\_\-lensN}!HDD.c@{HDD.c}}
\subsubsection[unpack\_\-code\_\-lensN]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} unpack\_\-code\_\-lens\-N (unsigned char $\ast$ {\em lens}, int {\em nlens}, unsigned int {\em seed}, int {\em delta\_\-min}, int {\em delta\_\-max}, const unsigned int $\ast$ {\em src}, unsigned int {\em max}, \hyperlink{struct__BFU}{BFU} {\em bfu})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HDD_8c_a8}


Generic routine to unpack the deltas and form the code length array when the deltas are themselves encoded as a Huffman table The routines unpack\_\-deltas1 and deltas2 are used when the range of the huffman encoding table is only 1 (2 symbols) or 2 (3 symbols) In these cases, a more optimal scheme, tailored to these small tables is used. 

\begin{Desc}
\item[Returns:]The updated bit position and current deblocked 32-bit buffer\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em lens}]The array of code lengths to fill in \item[{\em nlens}]The number of lengths to fill in \item[{\em delta\_\-min}]The minimum delta value \item[{\em delta\_\-max}]The maximum delta value \item[{\em seed}]The starting value to integrate the deltas from \item[{\em src}]The data source, i.e. the bit stream \item[{\em max}]The maximum bit position \item[{\em bfu}]The current bit position and temporary buffer\end{description}
\end{Desc}
\hypertarget{HDD_8c_a9}{
\index{HDD.c@{HDD.c}!unpack_syms@{unpack\_\-syms}}
\index{unpack_syms@{unpack\_\-syms}!HDD.c@{HDD.c}}
\subsubsection[unpack\_\-syms]{\setlength{\rightskip}{0pt plus 5cm}static \_\-\_\-inline \hyperlink{struct__BFU}{BFU} unpack\_\-syms (signed short int $\ast$ {\em syms}, int {\em nsyms}, const \hyperlink{struct__HUFF__dtable}{HUFF\_\-dtable} $\ast$ {\em dtable}, int {\em nlens}, int {\em min}, unsigned int {\em nunderflow}, unsigned int {\em noverflow}, const unsigned int $\ast$ {\em src}, unsigned int {\em max\_\-pos}, \hyperlink{struct__BFU}{BFU} {\em bfu})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{HDD_8c_a9}


Restores the differences between the original PHA value and its pedestal. 

\begin{Desc}
\item[Returns:]The updated bit position and current deblocked 32-bit buffer\end{Desc}
\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em syms}]The array of symbol values, corresponding to the difference between the PHA value and its pedestal to be filled in \item[{\em nsyms}]The number of symbols to decode \item[{\em dtable}]The decoding table \item[{\em nlens}]The number of code lengths \item[{\em min}]The minimum symbol value. This is the biase that most be added to all symbols when they are decoded. It restores the symbol to its original value. \item[{\em nunderflow}]The number of bins below the first HUFFman bin to be decoded \item[{\em noverflow}]The number of bins above the last HUFFman bin to be decoded \item[{\em src}]The data source, i.e. the bit stream \item[{\em max\_\-pos}]The maximum bit position \item[{\em bfu}]The current bit position and temporary buffer\end{description}
\end{Desc}
