📄 cfs_tool.c
字号:
*
* *stream Pointer to BIT_FILE structure.
* This structure holds all the
* related to the input file to be
* compressed.
*
* OUTPUTS
*
* None
*
*************************************************************************/
static VOID CFS_Init_Arithmetic_Decoder(WS_BIT_FILE *stream)
{
INT i;
CFS_Code = 0;
for ( i = 0 ; i < 16 ; i++ )
{
CFS_Code <<= 1;
CFS_Code = (UINT16)(CFS_Code + (CFS_Input_Bit(stream)));
}
CFS_Low = 0;
CFS_High = 0xffff;
}
/************************************************************************
*
* FUNCTION
*
* CFS_Remove_Symbol_From_Stream
*
* DESCRIPTION
*
* Just figuring out what the present symbol is
* doesn't remove it from the input bit stream. After
* the character has been decoded, this routine has to
* be called to remove it from the input stream.
*
* INPUTS
*
* *stream Pointer to BIT_FILE structure.
* This structure holds all the
* related to the input file to be
* compressed.
* *s Pointer to the SYMBOL structure
* that contains the converted
* symbol information.
*
* OUTPUTS
*
* None
*
*************************************************************************/
static VOID CFS_Remove_Symbol_From_Stream(WS_BIT_FILE *stream, WS_SYMBOL *s)
{
INT32 range;
/*
* First, the range is expanded to account for the symbol removal.
*/
range = (INT32)( CFS_High - CFS_Low ) + 1;
CFS_High = (UINT16)(CFS_Low + (UINT16)((range * s->high_count) / s->scale - 1));
CFS_Low = (UINT16)(CFS_Low + (UINT16)((range * s->low_count) / s->scale));
/*
* Next, any possible bits are shipped out.
*/
while(1)
{
/*
* If the MSDigits match, the bits will be shifted out.
*/
if ( ( CFS_High & 0x8000 ) == ( CFS_Low & 0x8000 ) )
{
}
/*
* Else, if underflow is threatening, shift out the 2nd MSDigit.
*/
else if ( (CFS_Low & 0x4000) == 0x4000 && (CFS_High & 0x4000) == 0 )
{
CFS_Code ^= 0x4000;
CFS_Low &= 0x3fff;
CFS_High |= 0x4000;
} else
/*
* Otherwise, nothing can be shifted out, so I return.
*/
return;
CFS_Low <<= 1;
CFS_High <<= 1;
CFS_High |= 1;
CFS_Code <<= 1;
CFS_Code = (UINT16)(CFS_Code + CFS_Input_Bit(stream));
}
}
/************************************************************************
*
* FUNCTION
*
* CFS_Open_Output_Bit_File
*
* DESCRIPTION
*
* This function initializes the Output Bit File that is to be
* compressed or decompressed.
*
* INPUTS
*
* *bitfile Pointer to structure that holds all
* information about the file.
* *buf Output Bit Buffer to be opened.
*
* OUTPUTS
*
* None
*
*************************************************************************/
static VOID CFS_Open_Output_Bit_File( WS_BIT_FILE * bit_file, CHAR *buf )
{
bit_file->fstart = buf;
bit_file->cur_pos = buf;
bit_file->length = 0;
bit_file->rack = 0;
bit_file->mask = 0x80;
bit_file->pacifier_counter = 0;
}
/************************************************************************
*
* FUNCTION
*
* CFS_Open_Input_Bit_File
*
* DESCRIPTION
*
* This function initializes the Input Bit File that is to be
* compressed or decompressed.
*
* INPUTS
*
* *bitfile Pointer to structure that
* holds all information about
* the file.
* *buf Input Bit Buffer to be opened.
* length Input Bit Buffer length.
*
* OUTPUTS
*
* NU_SUCCESS
*
*************************************************************************/
static VOID CFS_Open_Input_Bit_File( WS_BIT_FILE *bit_file, CHAR *buf, INT32 length)
{
bit_file->fstart = buf;
bit_file->cur_pos = buf;
bit_file->length = length;
bit_file->rack = 0;
bit_file->mask = 0x80;
bit_file->pacifier_counter = 0;
}
/************************************************************************
*
* FUNCTION
*
* CFS_Close_Output_Bit_File
*
* DESCRIPTION
*
* Function that closes the bit file and then flushes the buffer.
*
* INPUTS
*
* *bitfile Pointer to structure that holds all
* information about the file.
*
* OUTPUTS
*
* None
*
*************************************************************************/
static VOID CFS_Close_Output_Bit_File(WS_BIT_FILE *bit_file)
{
if ( bit_file->mask != 0x80 )
if ( CFS_Buf_Putc( (unsigned int)bit_file->rack, bit_file ) != bit_file->rack )
CFS_Fatal_Error( "Fatal error in CFS_Close_Output_Bit_File!\n" );
}
/************************************************************************
*
* FUNCTION
*
* CFS_Output_Bit
*
* DESCRIPTION
*
* Function to output a specific bit into the file stream.
*
* INPUTS
*
* *bit_file Pointer to structure that holds all
* information about the file.
* bit Bit to be outputted
*
* OUTPUTS
*
* None
*
*************************************************************************/
static VOID CFS_Output_Bit(WS_BIT_FILE *bit_file, INT bit)
{
if ( bit )
bit_file->rack |= bit_file->mask;
bit_file->mask >>= 1;
if ( bit_file->mask == 0 )
{
if ( CFS_Buf_Putc( (unsigned int)bit_file->rack, bit_file ) != bit_file->rack )
CFS_Fatal_Error( "Fatal error in CFS_Output_Bit!\n" );
else
if ( ( bit_file->pacifier_counter++ & CFS_PACIFIER_COUNT ) == 0 );
/*null statement*/
bit_file->rack = 0;
bit_file->mask = 0x80;
}
}
/************************************************************************
*
* FUNCTION
*
* CFS_Output_Bits
*
* DESCRIPTION
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -