当前位置: 首页 > news >正文

c jpeg 理论霍夫曼 DC AC表,c程序实现正向逆向转换

此4张表是理论表,不是针对某张图片的特定表。如编码程序不统计生成某图片的专用霍夫曼表,应该也可用理论表代用编码。

1.亮度DC表

a665ef68ef9d4eaa8bde8c83ee5b08e0.jpeg

左边第一列是二进制位数,就是对此位数编码

中间一列是生成比特流的位数,右边是生成的比特流。

2.色度DC表

322bd987a4ce43e890c43ebf8ed9bff2.jpeg

3.亮度AC表

d06b6dd361144075828cdfa9a2028352.jpeg

4.  色度AC表

25c1d9c3df7e4794b7fa5c6cdc0baf02.jpeg

 利用这4张表转换生成亮度,色度的DC,AC比特流

图3图4两张表是用jpeg文件头的形式显示的。

AC 表被编码的数值是两部分组成的,高4比特是0的个数 (a,b)对中的a,低4节为b的二进制位数。

两个AC表中的162个数就是两个输入参数组成的一个字节的值。

对于DC表,直接用if一一例举出现就行了。AC两张表输出都是162个数,这162个数的比特流从1位到16位都有。

  看了AC两张表,最多的是16位的比特流。

AC表的输入为0的个数和二进制位数两个参数,输出为比特流和比特流宽度。

--------------------------------

亮度AC表:

2 位:2个     00(1) ,01(2)

3位:1      010(0),

4位:3      0110(4),0111(11), 1000(5)

5位:3     10010(12) ,10011(21),10100(31)

6位:2     101010(41), 101011(6)

7位:4      1011000(13),1011001(51), 1011010(61),1011011(7)

8位:3        10111000(22),  10111001(71),  10111010(14)

9位:5        101110110(32),  101110111(81), 101111000(91)  ,101111001(A1), 101111010(8)

10位:5      1011110110(23),           1011110111(42),1011111000(b1), 1011111001(c1),1011111010(15)

11位:4     10111110110(52),   10111110111(d1),  10111111000(f0), 10111111001(24)

12位:4     101111110100(33),   101111110101(62), 101111110110(72),101111110111(82)

15位:1     101111111000000(9),

16位 :125     1011111110000010(0a),,,,,,,

共计162个

亮度AC转换:本想用查表法代码太长了,162个if语句。现还不包括16位的数据转换,准备换一种方法。DC可以用这种方法。

​1. 亮度AC编码用正向程序

​
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>  
#include <string.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <math.h>int main(void) {unsigned char i_0=0xf;unsigned char i_len=0xa;unsigned char len;unsigned int o;unsigned char zj=i_0*16+i_len;      //合成一个字节unsigned char  ws[16]={0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d};unsigned char zh[162]={0x1, 0x2, 0x3, 0x0, 0x4, 0x11, 0x5,0x12,0x21,0x31,0x41,0x6, 0x13,0x51,0x61,0x7,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf9,0xfa};int cx_ws,cx_b;unsigned char hfm[17][0x7d]={};int t=0;for(int a=0;a<16;a++){             //把要编码的162个数按位数分为16个数组,二位一组....16位一组if(ws[a]==0){continue;}for(int b=0;b<ws[a];b++){hfm[a+1][b]=zh[t];t++;}}for(int a=0;a<16;a++){               //查询输入数的位数和在所在组的顺序,组内顺序从0开始if(ws[a]==0){continue;}for(int b=0;b<ws[a];b++){if(	hfm[a+1][b]==zj){cx_ws=a+1;         //得到输入数二进制位数,根据此数到相依位数的数组查询cx_b=b;            //输入数在按位数分组的数组中所在的位置,从0开始break;}}}int o_js=0;       //每一组的第一个数的值if(cx_ws==2){o_js=0;}if(cx_ws==3){o_js=0b010;}if(cx_ws==4){o_js=0b0110;}if(cx_ws==5){o_js=0b10010;}if(cx_ws==6){o_js=0b101010;}if(cx_ws==7){o_js=0b1011000;}if(cx_ws==8){o_js=0b10111000;}if(cx_ws==9){o_js=0b101110110;}if(cx_ws==10){o_js=0b1011110110;}if(cx_ws==11){o_js=0b10111110110;}if(cx_ws==12){o_js=0b101111110100;}if(cx_ws==15){o_js=0b101111111000000;}if(cx_ws==16){o_js=0b1011111110000010;}len=cx_ws;o=o_js+cx_b;printf("len:%d o:%d\n",len,o);return 0;	
}​​

2.亮度AC 解码程序


#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>  
#include <string.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <math.h>int main(void) {unsigned int i_bit=0b1011111110000011;unsigned char i_len=16;unsigned char len;unsigned char o;unsigned char  ws[16]={0,2,1,3,3,2,4,3,5,5,4,4,0,0,1,0x7d};unsigned char zh[162]={0x1, 0x2, 0x3, 0x0, 0x4, 0x11, 0x5,0x12,0x21,0x31,0x41,0x6, 0x13,0x51,0x61,0x7,0x22,0x71,0x14,0x32,0x81,0x91,0xa1,0x08,0x23,0x42,0xb1,0xc1,0x15,0x52,0xd1,0xf0,0x24,0x33,0x62,0x72,0x82,0x09,0x0a,0x16,0x17,0x18,0x19,0x1a,0x25,0x26,0x27,0x28,0x29,0x2a,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe6,0xe7,0xe8,0xe9,0xea,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf9,0xfa};unsigned char  cx_ws,cx_b;unsigned char hfm[17][0x7d]={};int t=0;for(int a=0;a<16;a++){             if(ws[a]==0){continue;}for(int b=0;b<ws[a];b++){hfm[a+1][b]=zh[t];t++;}}
//---------------------------------------cx_ws=i_len;int o_js=0;      if(cx_ws==2){o_js=0;cx_b=i_bit-o_js;}if(cx_ws==3){o_js=0b010;cx_b=i_bit-o_js;}if(cx_ws==4){o_js=0b0110;cx_b=i_bit-o_js;}if(cx_ws==5){o_js=0b10010;cx_b=i_bit-o_js;}if(cx_ws==6){o_js=0b101010;cx_b=i_bit-o_js;	}if(cx_ws==7){o_js=0b1011000;cx_b=i_bit-o_js;}if(cx_ws==8){o_js=0b10111000;cx_b=i_bit-o_js;}if(cx_ws==9){o_js=0b101110110;cx_b=i_bit-o_js;}if(cx_ws==10){o_js=0b1011110110;cx_b=i_bit-o_js;}if(cx_ws==11){o_js=0b10111110110;cx_b=i_bit-o_js;}if(cx_ws==12){o_js=0b101111110100;cx_b=i_bit-o_js;}if(cx_ws==15){o_js=0b101111111000000;cx_b=i_bit-o_js;}if(cx_ws==16){o_js=0b1011111110000010;cx_b=i_bit-o_js;}//-----------------------------------------unsigned char o_zj=hfm[cx_ws][cx_b];len=o_zj/16;o=o_zj%16;printf("%x  %x",len,o);return 0;	
}



 

相关文章:

  • Postgresql中PL/pgSQL的游标、自定义函数、存储过程的使用
  • 【UML】第8篇 用例图(3/3)
  • opencv 传统图像识别检测
  • Java 中单例模式的常见实现方式
  • 计算机网络 第五章(运输层)【下】
  • js 字符串功能转换解析
  • ubuntu v2ray
  • JDBC常见的几种连接池使用(C3PO、Druid、HikariCP 、DBCP)
  • 代码随想录第三十六天(一刷C语言)|背包问题理论基础分割等和子集
  • 【稳定检索|投稿优惠】2024年区域经济与经济转型国际学术会议(IACREET 2024)
  • 2023年度佳作:AIGC、AGI、GhatGPT 与人工智能大模型的创新与前景展望
  • Elasticsearch的批量bulk 提交 写入的方式会有顺序问题吗?
  • 设计模式(三)-结构型模式(3)-装饰模式
  • 2023.12.20力扣每日一题
  • 苏宁易购商品详情API:电商实时数据
  • [译] 理解数组在 PHP 内部的实现(给PHP开发者的PHP源码-第四部分)
  • 【刷算法】求1+2+3+...+n
  • CSS 三角实现
  • ES6--对象的扩展
  • ES6语法详解(一)
  • Invalidate和postInvalidate的区别
  • JDK 6和JDK 7中的substring()方法
  • JS数组方法汇总
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • MD5加密原理解析及OC版原理实现
  • Python_网络编程
  • Redis提升并发能力 | 从0开始构建SpringCloud微服务(2)
  • redis学习笔记(三):列表、集合、有序集合
  • XML已死 ?
  • 码农张的Bug人生 - 见面之礼
  • 深入浅出Node.js
  • MPAndroidChart 教程:Y轴 YAxis
  • MyCAT水平分库
  • ​secrets --- 生成管理密码的安全随机数​
  • (2)Java 简介
  • (Redis使用系列) Springboot 在redis中使用BloomFilter布隆过滤器机制 六
  • (免费领源码)Java#Springboot#mysql农产品销售管理系统47627-计算机毕业设计项目选题推荐
  • (三维重建学习)已有位姿放入colmap和3D Gaussian Splatting训练
  • (一)Dubbo快速入门、介绍、使用
  • (一)RocketMQ初步认识
  • (已解决)报错:Could not load the Qt platform plugin “xcb“
  • (转) 深度模型优化性能 调参
  • .NET Core、DNX、DNU、DNVM、MVC6学习资料
  • .NET LINQ 通常分 Syntax Query 和Syntax Method
  • .NET3.5下用Lambda简化跨线程访问窗体控件,避免繁复的delegate,Invoke(转)
  • .NET连接数据库方式
  • .NET轻量级ORM组件Dapper葵花宝典
  • /etc/skel 目录作用
  • @Not - Empty-Null-Blank
  • @Service注解让spring找到你的Service bean
  • [ 英语 ] 马斯克抱水槽“入主”推特总部中那句 Let that sink in 到底是什么梗?
  • [.NET 即时通信SignalR] 认识SignalR (一)
  • [Android] 修改设备访问权限
  • [Angularjs]asp.net mvc+angularjs+web api单页应用之CRUD操作
  • [docker] Docker的私有仓库部署——Harbor