JPEG原理分析及JPEG解码器的调试
1.JPEG编解码原理
JPEG编码的过程如上图所示。解码是编码的逆过程。
2.JPEG文件格式介绍
实验要求:
1.将输出文件保存为可供YUV Viewer观看的yuv文件
修改loadjpeg.c中的wrire_yuv
static void write_yuv(const char *filename, int width, int height, unsigned char **components)
{
//将输出文件保存为可供YUVViewer观看的YUV文件
FILE *F;
char temp[1024];
snprintf(temp, 1024, "%s.yuv", filename);
F = fopen(temp, "wb");
fwrite(components[0], width, height, F);
fwrite(components[1], width*height/4, 1, F);
fwrite(components[2], width*height/4, 1, F);
fclose(F);
}
输出文件
2.理解程序设计的整体框架,三个结构体的设计目的 、TRACE的目的和含义
在tinyjpeg-internal.h中定义了三个结构体,分别是huffman_table、component 和jdec_private,三个结构体呈现递进关系,component 代表一个块包含huffman_table,jdec_private代表一个MCU包含component
// Huffman码表结构体
struct huffman_table
{
/* Fast look up table, using HUFFMAN_HASH_NBITS bits we can have directly the symbol,
* if the symbol is <0, then we need to look into the tree table */
short int lookup[HUFFMAN_HASH_SIZE];//快速查找权值对应的码字
/* code size: give the number of bits of a symbol is encoded */
unsigned char code_size[HUFFMAN_HASH_SIZE];//码长对应的权值,每个符号编码后的码字