/////////////////////////////////////////////////////////////////////////////
// Copyright (c) Winnov L.P., 1996.  All rights reserved.
// codecmsg.c
/////////////////////////////////////////////////////////////////////////////



///////////////////////////////////////////////////////////////////////

LONG
BuildHuffmanTables(PCODEC	pCodec,
		   BOOL		fdex)
{
	WORD	wHufftab	= fdex ? pCodec->wHufftabDex : pCodec->wHufftabDe;
	LPSTR	lp;
	int	i;

	for (i = 1; (i < 4); i++)
	    {
		lp = (fdex) ? pCodec->lpHuffmanDex[i] : pCodec->lpHuffmanDe[i];
		if (lp == NULL)
			lp = CreateDehuffLut(i + 4, wHufftab);
		else
			FillDehuffLut(lp, i + 4, wHufftab);
		if (!lp)
			return ICERR_MEMORY;
		if (fdex)
			pCodec->lpHuffmanDex[i] = lp;
		else
			pCodec->lpHuffmanDe[i] = lp;
	    }
	return ICERR_OK;
}


LONG
DecompressDH(LPDHDECOMP	lpDHProc,
	     LPSTR	lpOut,
	     LPSTR	lpIn,
	     DWORD	bIn,
	     DWORD	dwWidth,
	     DWORD	dwHeight,
	     LONG	lNextLine,
	     LPSTR	lpHuffLut,
	     LPSTR	lpColorLut,
	     DWORD	dwBitDepth,
	     BOOL	fBothFields)
{
	DWORD	dwResidual = 0;	// First/Last YUV value
	DWORD	dwLength;

	if (fBothFields)
	{//	Do half the lines at a time, and skip every other line
		dwHeight /= 2;
		lNextLine *= 2;
	}

	dwLength = lpDHProc(lpOut, lpIn, bIn, dwWidth, dwHeight, lNextLine,
			    lpHuffLut, lpColorLut, dwBitDepth, &dwResidual);
	if (fBothFields)
	{
		dwLength += bIn;
		lpIn += dwLength / 8;
		bIn = dwLength % 8;
		lpOut += lNextLine / 2;
		lpDHProc(lpOut, lpIn, bIn, dwWidth, dwHeight, lNextLine,
			 lpHuffLut, lpColorLut, dwBitDepth, &dwResidual);
	}
	return ICERR_OK;
}


