📄 jdloop.c
字号:
#include "jdconfig.h"
#include "jderror.h"
#include "jdmarker.h"
#include "jddatatype.h"
#include "jdprototype.h"
UINT16 decode_interleaved_scan (JPEG_DECODER_STRUCTURE *jpeg_decoder_structure, UINT16 flag)
{
UINT16 i, j, k, l, m, tmp;
UINT16 sof, successive_approximation_bit_position_high;
UINT16 horizontal_mcus, vertical_mcus;
UINT16 mcu_size, number_of_image_components_in_frame;
UINT16 last_mcu_row, last_mcu_column;
UINT16 horizontal_sampling_factor, vertical_sampling_factor;
UINT16 quantization_table_destination_selector, *quantization_table;
INT16 *coefficient_buffer, *mcu_buffer, temporary_buffer [64];
UINT32 *image_buffer, *external_image_buffer;
UINT16 (* huffman) (JPEG_DECODER_STRUCTURE *, INT16 *, UINT16);
UINT16 restart_interval;
sof = jpeg_decoder_structure -> sof;
successive_approximation_bit_position_high = jpeg_decoder_structure->successive_approximation_bit_position_high;
if (sof != SOF2)
huffman = sequential_huffman;
else if (successive_approximation_bit_position_high == 0)
huffman = first_dc_huffman;
else
huffman = refine_dc_huffman;
horizontal_mcus = jpeg_decoder_structure->horizontal_mcus;
vertical_mcus = jpeg_decoder_structure->vertical_mcus;
mcu_size = jpeg_decoder_structure->mcu_size;
number_of_image_components_in_frame = jpeg_decoder_structure->number_of_image_components_in_frame;
coefficient_buffer = jpeg_decoder_structure -> coefficient_buffer;
mcu_buffer = jpeg_decoder_structure -> mcu_buffer;
image_buffer = jpeg_decoder_structure -> image_buffer;
external_image_buffer = jpeg_decoder_structure -> external_image_buffer;
for (i=1; i<=vertical_mcus; i++)
{
for (j=1; j<=horizontal_mcus;j++)
{
last_mcu_row = (i == vertical_mcus) ? 1 : 0;
last_mcu_column = (j == horizontal_mcus) ? 1 : 0;
if ((flag == 1) && (successive_approximation_bit_position_high == 0))
clear_buffer (mcu_buffer, mcu_size);
else
copy_data (coefficient_buffer, mcu_buffer, mcu_size);
for (k=0; k<number_of_image_components_in_frame; k ++)
{
vertical_sampling_factor = jpeg_decoder_structure->vertical_sampling_factor [k];
horizontal_sampling_factor = jpeg_decoder_structure->horizontal_sampling_factor [k];
quantization_table_destination_selector = jpeg_decoder_structure ->
quantization_table_destination_selector [k];
quantization_table = jpeg_decoder_structure ->
quantization_table [quantization_table_destination_selector];
for (l=0; l<vertical_sampling_factor; l++)
{
for (m=0; m<horizontal_sampling_factor; m++)
{
if (flag)
{
tmp = (* huffman) (jpeg_decoder_structure, mcu_buffer, k);
if (tmp != SUCCESS)
return tmp;
if (sof == SOF2)
copy_data (mcu_buffer, coefficient_buffer, 64);
}
inverse_quantize_inverse_zigzag (mcu_buffer, temporary_buffer, quantization_table);
idct (temporary_buffer);
level_shift (temporary_buffer, mcu_buffer);
mcu_buffer += 64;
coefficient_buffer += 64;
}
}
}
mcu_buffer = jpeg_decoder_structure -> mcu_buffer;
(* jpeg_decoder_structure->write_format) (mcu_buffer, image_buffer);
copy_output (jpeg_decoder_structure -> image_buffer, external_image_buffer,
jpeg_decoder_structure ->number_of_samples_per_line,
jpeg_decoder_structure -> number_of_rows [last_mcu_row],
jpeg_decoder_structure -> number_of_columns [last_mcu_column],
jpeg_decoder_structure -> image_format);
jpeg_decoder_structure -> restarts_to_go --;
restart_interval = jpeg_decoder_structure -> restart_interval;
if (!(last_mcu_row & last_mcu_column))
{
if (restart_interval)
{
if (jpeg_decoder_structure -> restarts_to_go == 0)
{
tmp = read_restart_marker (jpeg_decoder_structure);
if (tmp != SUCCESS)
return tmp;
}
}
}
external_image_buffer += jpeg_decoder_structure -> increment1;
}
external_image_buffer += jpeg_decoder_structure -> increment2;
}
return SUCCESS;
}
UINT16 decode_noninterleaved_scan (JPEG_DECODER_STRUCTURE *jpeg_decoder_structure)
{
UINT16 sof, successive_approximation_bit_position_high;
UINT16 component_index_in_frame, mcu_size;
UINT16 number_of_lines, number_of_samples_per_line, image_format;
UINT16 number_of_vertical_blocks, number_of_horizontal_blocks;
UINT16 horizontal_mcus;
UINT16 i, j, tmp;
INT16 * coefficient_buffer, * mcu_buffer;
UINT16 (* huffman) (JPEG_DECODER_STRUCTURE * jpeg_decoder_structure,
INT16 * block, UINT16 component_index_in_scan);
UINT32 offset;
sof = jpeg_decoder_structure -> sof;
successive_approximation_bit_position_high = jpeg_decoder_structure ->
successive_approximation_bit_position_high;
if (sof != SOF2)
huffman = sequential_huffman;
else
{
if (successive_approximation_bit_position_high == 0)
huffman = first_ac_huffman;
else
huffman = refine_ac_huffman;
jpeg_decoder_structure -> eobrun = 0;
}
component_index_in_frame = jpeg_decoder_structure -> component_index_in_frame [0];
mcu_size = jpeg_decoder_structure -> mcu_size;
if (component_index_in_frame == 0)
offset = 0;
else if (component_index_in_frame == 1)
offset = mcu_size - 128;
else
offset = mcu_size - 64;
number_of_lines = jpeg_decoder_structure -> number_of_lines;
number_of_samples_per_line =
jpeg_decoder_structure -> number_of_samples_per_line;
number_of_vertical_blocks = (number_of_lines + 7) >> 3;
number_of_horizontal_blocks = (number_of_samples_per_line + 7) >> 3;
image_format = jpeg_decoder_structure -> image_format;
if (component_index_in_frame != 0)
{
if (image_format == FOUR_TWO_ZERO)
{
number_of_vertical_blocks = (number_of_lines + 15) >> 4;
number_of_horizontal_blocks = (number_of_samples_per_line + 15) >> 4;
}
else if (image_format == FOUR_TWO_TWO)
number_of_horizontal_blocks = (number_of_samples_per_line + 15) >> 4;
}
coefficient_buffer = jpeg_decoder_structure -> coefficient_buffer;
mcu_buffer = jpeg_decoder_structure -> mcu_buffer;
horizontal_mcus = jpeg_decoder_structure -> horizontal_mcus;
for (i=0; i<number_of_vertical_blocks; i++)
{
for (j=0; j<number_of_horizontal_blocks; j++)
{
if (sof == SOF2)
copy_data (coefficient_buffer + offset, mcu_buffer, 64);
else
clear_buffer (mcu_buffer, 64);
tmp = (* huffman) (jpeg_decoder_structure, mcu_buffer, 0);
if (tmp != SUCCESS)
return tmp;
copy_data (mcu_buffer, coefficient_buffer + offset, 64);
offset += mcu_size;
if (component_index_in_frame == 0)
{
if ((image_format == FOUR_TWO_ZERO) || (image_format == FOUR_TWO_TWO))
{
if (j & 1)
offset -= 64;
else
offset -= (mcu_size - 64);
}
}
}
if (component_index_in_frame == 0)
{
if (image_format == FOUR_TWO_ZERO)
{
if (i & 1)
{
if (number_of_horizontal_blocks & 1)
offset += 320;
offset -= 128;
}
else
{
if (number_of_horizontal_blocks & 1)
offset += 320;
offset -= 384 * horizontal_mcus;
offset += 128;
}
}
}
}
return SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -