数据压缩实验五——JPEG解码器
一、实验目的
掌握JPEG编解码系统的基本原理。初步掌握复杂的数据压缩算法实现,并能根据理论分析需要实现所对应数据的输出。
二、实验内容
1.JPEG编解码原理
JPEG编码的过程如上图所示。解码是编码的逆过程。
- JPEG格式
打开一个JPEG文件:
三、实验步骤
代码实现:
在write_yuv中添加的代码
static void write_yuv(const char *filename, int width, int height, unsigned char **components)
{
FILE *F;
char temp[1024];
snprintf(temp, 1024, "%s.Y", filename);
F = fopen(temp, "wb");
fwrite(components[0], width, height, F);
fclose(F);
snprintf(temp, 1024, "%s.U", filename);
F = fopen(temp, "wb");
fwrite(components[1], width*height/4, 1, F);
fclose(F);
snprintf(temp, 1024, "%s.V", filename);
F = fopen(temp, "wb");
fwrite(components[2], width*height/4, 1, F);
fclose(F);
//添加的代码
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);
}
将JPG转化为yuv打开
三个重要结构:
struct huffman_table用于存储haffman表
struct huffman_table
{
/* Fast look up table, using HUF