JPEG编解码

实验原理

在这里插入图片描述

可知jpeg编码的步骤如上图所示 下面具体分析每一项
1.rgb到yuv,目的是减少冗余,yuv的关联性较rgb小,电平偏移,减少数据的范围
2.将图像切割分为8*8的块,方便进行dct变化
3.dct变化,将图像放到频域上,左上角是直流分量,向右下角频率增高,此步骤可以去除空间冗余,方面后面用不同的量化步长进行量化
4.量化,采用不同步长的量化
5.熵编码,直流采取哈夫曼编码,交流采取游程编码

重点码表介绍

重点码表包括量化表和哈夫曼表

量化表的表头是FF DB 后面两字节xx xx 表示长度 后面字节xx高四位表示精度 低四位表示表号
注意量化表采用zig-zag排列

哈夫曼码表包括直流码表和交流码表
FF C4 后面两字节 xx xx表示数据长度 再后面1字节为 Huffman Table 的信息 低4位是 HT ID 号 第5位是 HT 表类型标记

代码分析

1存储哈夫曼表

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];

  uint16_t slowtable[16-HUFFMAN_HASH_NBITS][256];
};

2.存储JPEG图像宽高,指针,码表等


struct jdec_private
{
   
  /* Public variables */
  uint8_t *components[COMPONENTS];
  unsigned int width, height;	/* Size of the image */
  unsigned int flags;

  /* Private variables */
  const unsigned char *stream_begin, *stream_end;
  unsigned int stream_length;

  const unsigned char *stream;	/* Pointer to the current stream */
  unsigned int reservoir, nbits_in_reservoir;

  struct component component_infos[COMPONENTS];
  float Q_tables[COMPONENTS
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值