📄 jdhuffman.c
字号:
lcode = jpeg_decoder_structure -> lcode;
lsize = jpeg_decoder_structure -> lsize;
start_of_spectral_selection =
jpeg_decoder_structure -> start_of_spectral_selection;
end_of_spectral_selection =
jpeg_decoder_structure -> end_of_spectral_selection;
successive_approximation_bit_position_low =
jpeg_decoder_structure ->
successive_approximation_bit_position_low;
for (coefficient = start_of_spectral_selection; coefficient <= end_of_spectral_selection;
coefficient ++)
{
if (lsize < 16)
{
lcode |= (UINT32) read_16huff_bits (jpeg_decoder_structure) <<
(16 - lsize);
lsize += 16;
}
#if NBITS
huffsize = huffsize_table [lcode >> 32 - NBITS];
if (huffsize)
huffcode = lcode >> (32 - huffsize);
else
#endif
{
huffsize = NBITS + 1;
huffcode = lcode >> 32 - (NBITS + 1);
while ((INT32) huffcode > maxcode_table [huffsize])
{
huffsize ++;
huffcode = lcode >> (32 - huffsize);
}
if (huffsize > 16)
return ERROR_INVALID_HUFFMAN_CODE;
}
index = huffcode + valptr_minus_mincode_table [huffsize];
huffval = huffval_table [index];
lcode <<= huffsize;
lsize -= huffsize;
run_length = huffval >> 4;
size = huffval & 15;
if (size)
{
coefficient += run_length;
if (lsize < size)
{
lcode |= (UINT32) read_16huff_bits (jpeg_decoder_structure)
<< (16 - lsize);
lsize += 16;
}
ac = lcode >> (32 - size);
lcode <<= size;
lsize -= size;
if (ac < (1 << (size - 1)))
ac += (- 1 << size) + 1;
block [coefficient] = ac << successive_approximation_bit_position_low;
}
else
{
if (run_length == 15)
coefficient += 15;
else
{
eobrun = 1 << run_length;
if (run_length)
{
if (lsize < run_length)
{
lcode |= (UINT32) read_16huff_bits
(jpeg_decoder_structure) << (16 - lsize);
lsize += 16;
}
eobrun += lcode >> (32 - run_length);
lcode <<= run_length;
lsize -= run_length;
}
eobrun --;
break;
}
}
}
jpeg_decoder_structure -> lcode = lcode;
jpeg_decoder_structure -> lsize = lsize;
}
jpeg_decoder_structure -> eobrun = eobrun;
return SUCCESS;
}
UINT16 refine_ac_huffman (JPEG_DECODER_STRUCTURE *jpeg_decoder_structure, INT16 *block,
UINT16 component_index)
{
UINT16 lsize, index, coefficient, huffcode, huffsize, huffval;
UINT16 run_length, eobrun;
INT16 pl, ml;
UINT32 lcode;
INT32 size;
UINT16 ac_entropy_coding_table_destination_selector;
UINT16 start_of_spectral_selection, end_of_spectral_selection;
UINT16 *huffsize_table, *huffval_table;
INT32 *maxcode_table, *valptr_minus_mincode_table;
HUFFMAN_STRUCTURE *huffman_structure;
pl = 1 << jpeg_decoder_structure ->
successive_approximation_bit_position_low;
ml = (-1) << jpeg_decoder_structure ->
successive_approximation_bit_position_low;
ac_entropy_coding_table_destination_selector = jpeg_decoder_structure ->
ac_entropy_coding_table_destination_selector [0];
huffman_structure = & jpeg_decoder_structure ->
huffman_structure [1][ac_entropy_coding_table_destination_selector];
huffsize_table = huffman_structure -> huffsize_table;
valptr_minus_mincode_table =
huffman_structure -> valptr_minus_mincode_table;
huffval_table = huffman_structure -> huffval_table;
maxcode_table = huffman_structure -> maxcode_table;
start_of_spectral_selection =
jpeg_decoder_structure -> start_of_spectral_selection;
end_of_spectral_selection =
jpeg_decoder_structure -> end_of_spectral_selection;
eobrun = jpeg_decoder_structure -> eobrun;
coefficient = start_of_spectral_selection;
lcode = jpeg_decoder_structure -> lcode;
lsize = jpeg_decoder_structure -> lsize;
if (eobrun == 0)
{
for (; coefficient <= end_of_spectral_selection; coefficient ++)
{
if (lsize < 16)
{
lcode |= (UINT32) read_16huff_bits (jpeg_decoder_structure) <<
(16 - lsize);
lsize += 16;
}
#if NBITS
huffsize = huffsize_table [lcode >> 32 - NBITS];
if (huffsize)
huffcode = lcode >> (32 - huffsize);
else
#endif
{
huffsize = NBITS + 1;
huffcode = lcode >> 32 - (NBITS + 1);
while ((INT32) huffcode > maxcode_table [huffsize])
{
huffsize ++;
huffcode = lcode >> (32 - huffsize);
}
if (huffsize > 16)
return ERROR_INVALID_HUFFMAN_CODE;
}
index = huffcode + valptr_minus_mincode_table [huffsize];
huffval = huffval_table [index];
lcode <<= huffsize;
lsize -= huffsize;
run_length = huffval >> 4;
size = huffval & 15;
if (size)
{
if (size != 1)
return ERROR_INVALID_HUFFMAN_CODE;
if (lsize == 0)
{
lcode = (UINT32) read_16huff_bits (jpeg_decoder_structure)
<< 16;
lsize = 16;
}
if (lcode >> 31)
size = pl;
else
size = ml;
lcode <<= 1;
lsize -= 1;
}
else
{
if (run_length != 15)
{
eobrun = 1 << run_length;
if (run_length)
{
if (lsize < run_length)
{
lcode |= (UINT32) read_16huff_bits
(jpeg_decoder_structure) << (16 - lsize);
lsize += 16;
}
eobrun += lcode >> (32 - run_length);
lcode <<= run_length;
lsize -= run_length;
}
break;
}
}
do
{
if (block [coefficient] != 0)
{
if (lsize == 0)
{
lcode = (UINT32) read_16huff_bits
(jpeg_decoder_structure) << 16;
lsize = 16;
}
if (lcode >> 31)
{
if ((block[coefficient] & pl) == 0)
{
if (block[coefficient] >= 0)
block[coefficient] += pl;
else
block[coefficient] += ml;
}
}
lcode <<= 1;
lsize -= 1;
}
else
{
if (run_length == 0)
break;
run_length --;
}
coefficient ++;
}
while (coefficient <= end_of_spectral_selection);
if (size)
block [coefficient] = size;
}
}
if (eobrun > 0)
{
for (; coefficient <= end_of_spectral_selection; coefficient ++)
{
if (block [coefficient] != 0)
{
if (lsize == 0)
{
lcode = (UINT32) read_16huff_bits (jpeg_decoder_structure)
<< 16;
lsize = 16;
}
if (lcode >> 31)
{
if ((block[coefficient] & pl) == 0)
{
if (block [coefficient] >= 0)
block [coefficient] += pl;
else
block [coefficient] += ml;
}
}
lcode <<= 1;
lsize -= 1;
}
}
eobrun --;
}
jpeg_decoder_structure -> lcode = lcode;
jpeg_decoder_structure -> lsize = lsize;
jpeg_decoder_structure -> eobrun = eobrun;
return SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -