c 编码(进行中)

发布时间:2024年01月03日

编码出来的jpeg图片只有红,绿色。排查中

???????



#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>  //v4l2 头文件
#include <string.h>
#include <sys/mman.h>
#include <linux/fb.h>
#include <math.h>
#define PI 3.1415926


#define  pic_width   16     //1280*720  640*360  960*540   320*240   424*240  848*480 640*480
#define  pic_heigth  16


#define filename  "/home/wzpc/Pictures/16*16.yuv"
#define file1  "/home/wzpc/Pictures/4.jpeg"        //借用成品图片的量化表

static unsigned char o_bit[1000000]={};
static int to=0;

int  main(void) {
	//------ali--------------------------------------
	int ali(int i,int out[2]){        //out[1]=len  out[0]=int
		//	int i=-5;
		int o=-1;      //如果输出负数无意义
		char len=-1;   //如果输出负数无意义
		
		if(i==0){
			len=0;
			o=0;
		}
		if(i==-1){
			len=1;
			o=0;
		}
		if(i==1){
			len=1;
			o=1;
		}
		
		if((i>=2)&&(i<=32767)){             //二进制位数0-16位
			for(int a=0;a<16;a++){
				if((i>=pow(2,a))&&(i<pow(2,(a+1)))){
					len=a+1;
					o=i;
				}
			}
		}
		if((i>=-32767)&&(i<=-2)){
			for(int a=0;a<16;a++){
				if((i<=-pow(2,a))&&(i>-pow(2,(a+1)))){
					len=a+1;
					o=i+pow(2,(a+1))-1;
				}
			}
		}
		
		//	printf("len:%d  o:%d\n",len,o);
		out[1]=len;
		out[0]=o;
		return 0;
	}
	//-------------Y_DC--------------------------------
	int hfm_ydc(unsigned char  i,int out[2]){  //out[1]=len  out[0]=int
		
		if(i==0){
			out[1]=2;
			out[0]=0b00;
		}
		if(i==1){
			out[1]=3;
			out[0]=0b010;
		}
		if(i==2){
			out[1]=3;
			out[0]=0b011;
		}
		if(i==3){
			out[1]=3;
			out[0]=0b100;
		}
		if(i==4){
			out[1]=3;
			out[0]=0b101;
		}
		if(i==5){
			out[1]=3;
			out[0]=0b110;
		}
		if(i==6){
			out[1]=4;
			out[0]=0b1110;
		}
		if(i==7){
			out[1]=5;
			out[0]=0b11110;
		}
		if(i==8){
			out[1]=6;
			out[0]=0b111110;
		}
		if(i==9){
			out[1]=7;
			out[0]=0b1111110;
		}
		if(i==10){
			out[1]=8;
			out[0]=0b11111110;
		}
		if(i==11){
			out[1]=9;
			out[0]=0b111111110;
		}
		return 0;
	}
	//-------------UV_DC-----------------------------------
	int hfm_uvdc(unsigned char i,int out[2]){   //out[1]=len  out[0]=int
		if(i==0){
			out[1]=2;
			out[0]=0;
		}
		if(i==1){
			out[1]=2;
			out[0]=0b01;
		}
		if(i==2){
			out[1]=2;
			out[0]=0b10;
		}
		if(i==3){
			out[1]=3;
			out[0]=0b110;
		}
		if(i==4){
			out[1]=4;
			out[0]=0b1110;
		}
		if(i==5){
			out[1]=5;
			out[0]=0b11110;
		}
		if(i==6){
			out[1]=6;
			out[0]=0b111110;
		}
		if(i==7){
			out[1]=7;
			out[0]=0b1111110;
		}
		if(i==8){
			out[1]=8;
			out[0]=0b11111110;
		}
		if(i==9){
			out[1]=9;
			out[0]=0b111111110;
		}
		if(i==10){
			out[1]=10;
			out[0]=0b1111111110;
		}
		if(i==11){
			out[1]=11;
			out[0]=0b11111111110;
		}
		return 0;
	}
	//---------霍夫曼编码Y_AC-----------------------------------
	int hfm_yac(unsigned char i_0,unsigned char i_len,unsigned int out[2]){
		
		//	unsigned char i_0=0xf;                      //out[1]=len  out[0]=int
		//	unsigned char i_len=0xa;
		
		unsigned int 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=0b00;
		}
		if(cx_ws==3){
			o_js=0b100;
		}
		if(cx_ws==4){
			o_js=0b1010;
		}
		if(cx_ws==5){
			o_js=0b11010;
		}
		if(cx_ws==6){
			o_js=0b111010;
		}
		if(cx_ws==7){
			o_js=0b1111000;
		}
		if(cx_ws==8){
			o_js=0b11111000;
		}
		if(cx_ws==9){
			o_js=0b111110110;
		}
		if(cx_ws==10){
			o_js=0b1111110110;
		}
		if(cx_ws==11){
			o_js=0b11111110110;
		}
		if(cx_ws==12){
			o_js=0b111111110100;
		}
		if(cx_ws==15){
			o_js=0b111111111000000;
		}
		if(cx_ws==16){
			o_js=0b1111111110000010;
		}
		len=cx_ws;
		o=o_js+cx_b;
		out[1]=len;
		out[0]=o;
		return 0;
	}
	
	//---------UV_AC---------------------------------
	
	int hfm_uvac(unsigned char i_0,unsigned char i_len,unsigned int out[2]){
		
		//	unsigned char i_0=0xf;                         //out[1]=len  out[0]=int
		//	unsigned char i_len=0xa;
		
		unsigned int len;
		unsigned int o;
		
		unsigned char zj=i_0*16+i_len;      //合成一个字节
		
		unsigned char  ws[16]={0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77};
		unsigned char zh[162]={
		    0x00, 0x1, 0x2, 0x3, 0x11, 0x4, 0x5, 0x21, 0x31, 0x6, 0x12, 0x41, 0x51, 0x7, 0x61, 0x71,
			0x13, 0x22, 0x32, 0x81, 0x8, 0x14,  0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x9, 0x23, 0x33, 0x52, 0xf0,
			0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
			0x27, 0x28, 0x29, 0x2a, 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, 0x82, 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,
			0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
			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=0b00;
		}
		if(cx_ws==3){
			o_js=0b100;
		}
		if(cx_ws==4){
			o_js=0b1010;
		}
		if(cx_ws==5){
			o_js=0b11000;
		}
		if(cx_ws==6){
			o_js=0b111000;
		}
		if(cx_ws==7){
			o_js=0b1111000;
		}
		if(cx_ws==8){
			o_js=0b11110110;
		}
		if(cx_ws==9){
			o_js=0b111110100;
		}
		if(cx_ws==10){
			o_js=0b1111110110;
		}
		if(cx_ws==11){
			o_js=0b11111110110;
		}
		if(cx_ws==12){
			o_js=0b111111110100;
		}
		if(cx_ws==14){
			o_js=0b11111111100000;
		}
		if(cx_ws==15){
			o_js=0b111111111000010;
		}
		if(cx_ws==16){
			o_js=0b1111111110001000;
		}
		len=cx_ws;
		o=o_js+cx_b;
		out[1]=len;
		out[0]=o;
		return 0;
	}
	
	
//-----------FDCT()函数------------------------------------
	int fdct( char (*i)[8], int(*o)[8] ) {  //i 为输入   o 为参数传入的输出转换后的数据
		
		
		double s;
		double au;
		double av;
		
		for (int u = 0; u < 8; u++) {
			for (int v = 0; v < 8; v++) {
				for (int y = 0; y < 8; y++) {
					for (int x = 0; x < 8; x++) {
						s = s + (1.0 / 4) * i[y][x] * cos((2 * y + 1) * u * PI / 16) * cos((2 * x + 1) * v * PI / 16);
					}
				}
				
				if (u == 0) {
					au = 1.0 / sqrt(2);
				} else {
					au = 1.0;
				}
				if (v == 0) {
					av = 1.0 / sqrt(2);
				} else {
					av = 1.0;
				}
				
				s = s * au * av;   //-30.1856
				int s1 = round(s * 100); //-3019
				s = s1 / 100.0;    //-30.19
				
				o[u][v] = s;       //double 转为char 类型
				s = 0;
			}
		}
		
		return 0;
	}
//-----------规范RLC格式---------------------
	int zl(int len,int (*i)[2],int (*o)[2]){
		int t=0;                        //如果中间有一次超过15个0,o的下标要加一,因为增加了(15,0)
		for(int a=0;a<len;a++){
			
			if((a<len)&&(i[a][1]>=16)&&(i[a][0]!=0)){
				o[a+t][0]=0;
				o[a+t][1]=15;
				o[a+1+t][0]=i[a][0];
				o[a+1+t][1]=i[a][1]-15;
				t++;
			}
			if((a<len)&&(i[a][1]<16)){        
				memcpy(&(o[a+t][0]),&(i[a][0]),8);  //一行为单位复制
			}
			if((a==len)&&(i[a][0]==0)){
				o[a+t][0]=0;
				o[a+t][1]=0;
				break;
			}
			
		}
		
		return len+t;
	}
	
//-----------去0-----------------------------
	int q0(int i[64], int (*o)[2]) {
		
		int t = 0;         //输出数组序号
		int z = 0;         //计算连续的0
		for (int a = 0; a < 64; a++) {                               //  a
			if ((i[a] == 0) && (i[a + 1] == 0) && ((a + 1) < 63)) { //000001
				z++;
				
			}                                                        // a
			if ((i[a] == 0) && (i[a + 1] == 0) && ((a + 1) == 63)){ //0000结束
				z++;             //本次的0
				o[t][0] =0;
				o[t][1] = z+1;   //加a+1的0
				break;           //判断完成
				
			}                                               //  a
			if ((i[a] == 0) && (i[a + 1] != 0)) {           //000100
				z++;                  //加上本次的一个0
				o[t][0] = i[a + 1]; 
				o[t][1] = z;
				z = 0;           //清0,计算下次的连续0
				t++;
				a = a + 1;   
				
			}                  
			if ((i[a] != 0)&&(a==0)) {   //第一个数非0
				o[t][0] = i[a];
				o[t][1] = 0;
				t++;
				
			}
			if ((a>0)&&(i[a] != 0)&&(i[a-1]!=0)) {   //防止第3种重复读取,这种是读取连续的非0
				o[t][0] = i[a];
				o[t][1] = 0;
				t++;
				
			}
			
		}
		
		return t+1;
	}
	
//--------Z 排序--------------------------------
	
	int zz(int (*i)[8], int o[64]) {
		int zb[64] = {0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,12,19,26,33,40,48,41,34,27,20,13,6,
			7,14,21,28,35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,58,59,52,45,38,31,39,46,53,60,61,54,47,
			55,62,63
		};
		int *p = (int *)i;
		for (int a = 0; a < 64; a++) {
			int c = zb[a];
			o[a] = p[c];
			
		}
		
		return 0;
	}
// -----量化函数---------------
	int lh(int (*i)[8], char (*lhb)[8], int (*o)[8]) {
		for (int a = 0; a < 8; a++) {
			for (int b = 0; b < 8; b++) {
				o[a][b] = round((i[a][b]) / (lhb[a][b]));
			}
		}
		
		return 0;
	}
	
	
//---------start-------------------------------------
	
	FILE *f1 = fopen(file1, "rb");  //如用mmap 必须以读写方式打开文件
	if (f1 == NULL) {
		puts("filename error");
		exit(-1);
	}
	fseek(f1, 0, SEEK_END);
	int len1 = ftell(f1);
	fseek(f1, 0, SEEK_SET);
	
	int fd1 = fileno(f1);
	unsigned char *mp1 = mmap(NULL, len1, PROT_READ, MAP_SHARED, fd1, 0); //必须要读,写
	
	
//---------读量化表-------------------------------
	char lh00[64] = {};                 //提取量化表
	char lh10[64] = {};
	for (int a = 0; a < len1; a++) {
		if ((mp1[a] == 0xff) && (mp1[a + 1] == 0xdb) && (mp1[a + 2] == 0)) {
			for (int b = 0; b < 65; b++) {
				
				if (mp1[a + b + 4] == 0) {
					memcpy(lh00, &(mp1[a + b + 5]), 64);
				}
				if (mp1[a + b + 4] == 1) {
					memcpy(lh10, &(mp1[a + b + 5]), 64);
				}
			}
			//	printf("\n");
			
		}
	}
	
//---------------------------------------------------------------------------
	FILE *f = fopen(filename, "rb");  //如用mmap 必须以读写方式打开文件
	if (f == NULL) {
		puts("filename error");
		exit(-1);
	}
	fseek(f, 0, SEEK_END);
	int len_file = ftell(f);
	fseek(f, 0, SEEK_SET);
	
	int fd = fileno(f);
	unsigned char *mp = mmap(NULL, len_file, PROT_READ, MAP_SHARED, fd, 0); //必须要读,写
	

	 char yfl[pic_heigth*pic_width]={};
	 char ufl[pic_heigth*pic_width/4]={};
	 char vfl[pic_heigth*pic_width/4]={};
	
	for(int a=0;a<256;a++){
		yfl[a]=mp[a];
	}
	for(int a=0;a<64;a++){
		ufl[a]=mp[a+256];
	}
	for(int a=0;a<64;a++){
		vfl[a]=mp[a+256+64];
	}
	
	//-------Y 分割8×8----------------------------
	
	
	int p=0;                //输出数组序号
	 char y64[4][64]={};         //输出数组
	
	for(int y=0;y<16;y=y+8){          //提取左上角点的垂直数据
		for(int x=0;x<16;x=x+8){      //提取左上角点的水平数据
			int n=0;             //每一个数组下标取值 0-15
			
			for(int a=0;a<8;a++){
				for(int b=0;b<8;b++){
					y64[p][n]=yfl[16*(a+y)+(b+x)];
					n++;
				}
			}
			p++;
		}
	}
	
/*	
//--------------FDCY Y- U  V----------------------------
	unsigned char y[8][8]={};
	memcpy(y,&(y64[0][0]),64);    //4个Y 0-3 :y64[0][0] ,y64[1][0] ,y64[2][0], y64[3][0]
	
	
	unsigned char u[8][8]={};
	memcpy(u,&ufl,64);
	unsigned char v[8][8]={};
	memcpy(v,&vfl,64);
	
	int y_fdct[8][8] = {};
	fdct(y,y_fdct);
	int u_fdct[8][8] = {};
	fdct(u, u_fdct);
	int v_fdct[8][8] = {};
	fdct(v, v_fdct);
	
	
//----------------量化 Y U  V  -----------------------------------
	//借用成品jpg图片量化表,lh0,lh1
	char (*lh0)[8] = (char (*)[8])lh00;
	char (*lh1)[8] = (char (*)[8])lh10;
	
	int y_lh[8][8] = {};
	int u_lh[8][8] = {};
	int v_lh[8][8] = {};
	
	lh(y_fdct, lh0, y_lh);
	lh(u_fdct, lh1, u_lh);
	lh(v_fdct, lh1, v_lh);
	
//---------Z排序--------------------------
	int y_z[64] = {};
	int u_z[64] = {};
	int v_z[64] = {};
	zz(y_lh, y_z);
	zz(u_lh, u_z);
	zz(v_lh, v_z);
//--------去0-------------------------
	
	int y_0[64][2] = {};
	int u_0[64][2] = {};
	int v_0[64][2] = {};
	int len_y_0 = q0(y_z, y_0);
	int len_u_0 = q0(u_z, u_0);
	int len_v_0 = q0(v_z, v_0);
	
//-----整理规范------------------------
	int y_zl[64][2]={};         //定义是必须指定数组内存大小,下标不能用变量,64是此数组的最大值
	int u_zl[64][2]={};         //zl[1]=0的个数  zl[0]=int 系数
	int v_zl[64][2]={};
	
	int len_y_zl=zl(len_y_0,y_0,y_zl);
	int len_u_zl=zl(len_u_0,u_0,u_zl);
	int len_v_zl=zl(len_v_0,v_0,v_zl);
	
  */
	

	//------Y处理函数---------------------------------

	
    int yy(int ysc,char y[8][8]){
	
	int y_fdct[8][8] = {};
	fdct(y,y_fdct);
	char (*lh0)[8] = (char (*)[8])lh00;
	int y_lh[8][8] = {};
	lh(y_fdct, lh0, y_lh);
	int y_z[64] = {};
	zz(y_lh, y_z);
	int y_0[64][2] = {};
	int len_y_0 = q0(y_z, y_0);
	int y_zl[64][2]={}; 
	int len_y_zl=zl(len_y_0,y_0,y_zl);
	//--------Y-DC----------------------------------
	int ydc[2]={};         //ydc[1]=len  ydc[0]=int
	int q=y_zl[0][0]-ysc;
	ali(q,ydc);   //处理Y_DC
	int ydc_hfm[2]={};     //ydc_hfm[1]=len
	hfm_ydc(ydc[1],ydc_hfm);
	
	int ls=(ydc_hfm[0]<<ydc[1])|ydc[0];  //组合成一int(12位)
	
	for(int a=(ydc[1]+ydc_hfm[1]);a>0;a--){
	   o_bit[to]=(ls&(int)pow(2,(a-1)))>>(a-1);    //取ls 每一位数
		to++;
	}	
	//-------Y-AC-------------------------------
	 for(int a=1;a<len_y_zl;a++){
		 int yac[2]={};
		 ali(y_zl[a][0],yac);
		 unsigned int yac_h[2]={};
		 hfm_yac(y_zl[a][1],yac[1],yac_h);
		 int ls=(yac_h[0]<<yac[1])|yac[0];
		 for(int a=(yac[1]+yac_h[1]);a>0;a--){
			 o_bit[to]=(ls&(int)pow(2,(a-1)))>>(a-1);    //取ls 每一位数
			 to++;
		 }	 
	 }
		return y_zl[0][0];
	}
	
    int ydiff=0;
	for(int a=0;a<4;a++){
	    char y[8][8]={};
      	memcpy(y,&(y64[a][0]),64);   //4个Y8×8
		ydiff=yy(ydiff,y);
	}
	
	char (*lh1)[8] = (char (*)[8])lh10;
	

	//-----处理U--------------------------------
	 char u[8][8]={};
	memcpy(u,&ufl,64);
	int u_fdct[8][8] = {};
	fdct(u, u_fdct);
	
	int u_lh[8][8] = {};
	lh(u_fdct, lh1, u_lh);
	int u_z[64] = {};
	zz(u_lh, u_z);
	int u_0[64][2] = {};
	int len_u_0 = q0(u_z, u_0);
	int u_zl[64][2]={};
	int len_u_zl=zl(len_u_0,u_0,u_zl);
	
	//--------U-DC----------------------------------
	int udc[2]={};         //ydc[1]=len  ydc[0]=int
	int q=u_zl[0][0];
	ali(q,udc);   //处理Y_DC
	int udc_hfm[2]={};     //ydc_hfm[1]=len
	hfm_uvdc(udc[1],udc_hfm);
	
	int ls=(udc_hfm[0]<<udc[1])|udc[0];  //组合成一int(12位)
	
	for(int a=(udc[1]+udc_hfm[1]);a>0;a--){
		o_bit[to]=(ls&(int)pow(2,(a-1)))>>(a-1);    //取ls 每一位数
		to++;
	}	
	//-------U-AC-------------------------------
	for(int a=1;a<len_u_zl;a++){
		int uac[2]={};
		ali(u_zl[a][0],uac);
		unsigned int uac_h[2]={};
		hfm_uvac(u_zl[a][1],uac[1],uac_h);
		int ls2=(uac_h[0]<<uac[1])|uac[0];
		for(int a=(uac[1]+uac_h[1]);a>0;a--){
			o_bit[to]=(ls2&(int)pow(2,(a-1)))>>(a-1);    //取ls 每一位数
			to++;
		}	 
	}

	//-------V 处理--------------------------------
	char  v[8][8]={};
	memcpy(v,&vfl,64);
	int v_fdct[8][8] = {};
	fdct(v, v_fdct);
//	char (*lh1)[8] = (char (*)[8])lh10;
	int v_lh[8][8] = {};
	lh(v_fdct, lh1, v_lh);
	int v_z[64] = {};
	zz(v_lh, v_z);
	int v_0[64][2] = {};
	int len_v_0 = q0(v_z, v_0);
	int v_zl[64][2]={};
	int len_v_zl=zl(len_v_0,v_0,v_zl);
	
	//--------V-DC----------------------------------
	int vdc[2]={};         //ydc[1]=len  ydc[0]=int
	int qv=v_zl[0][0];
	ali(qv,vdc);   //处理Y_DC
	int vdc_hfm[2]={};     //ydc_hfm[1]=len
	hfm_uvdc(vdc[1],vdc_hfm);
	
	int lsv=(vdc_hfm[0]<<vdc[1])|vdc[0];  //组合成一int(12位)
	
	for(int a=(vdc[1]+vdc_hfm[1]);a>0;a--){
		o_bit[to]=(lsv&(int)pow(2,(a-1)))>>(a-1);    //取ls 每一位数
		to++;
	}	
	//-------V-AC-------------------------------
	for(int a=1;a<len_v_zl;a++){
		int vac[2]={};
		ali(v_zl[a][0],vac);
		unsigned int vac_h[2]={};
		hfm_uvac(v_zl[a][1],vac[1],vac_h);
		int ls=(vac_h[0]<<vac[1])|vac[0];
		for(int a=(vac[1]+vac_h[1]);a>0;a--){
			o_bit[to]=(ls&(int)pow(2,(a-1)))>>(a-1);    //取ls 每一位数
			to++;
		}	 
	}
	
	for(int a=0;a<to;a++){
//		printf("%d ,",o_bit[a]);
	}
//	printf("to:%d\n",to);  //419
//-------生成jpeg文件-----------------------------
   for(int a=0;a<len1;a++){
	   if((mp1[a]==0xff)){
//		   printf("%x\n",mp1[a+1]);             //670  211
	   }
   }
	
	unsigned char jp[1000]={};
	memcpy(jp,mp1,671);
	jp[211]=0;
	jp[212]=16;
	jp[213]=0;
	jp[214]=16;
	for(int a=0;a<5;a++){
		o_bit[to+a]=1;
	}
	to=to+5;            //419+5=424
	int k=0;
	for(int a=0;a<424;a=a+8){
		unsigned char zz=o_bit[a]*128+o_bit[a+1]*64+o_bit[a+2]*32+o_bit[a+3]*16+o_bit[a+4]*8+o_bit[a+5]*4+o_bit[a+6]*4+o_bit[a+7];
		if(zz==0xff){
			jp[671+k]=zz;
			jp[671+k+1]=0;
		}else{
			jp[671+k]=zz;
		}
		k++;
	}
	jp[671+k+1]=0xff;
	jp[671+k+2]=0xd9;
	
	FILE *fz=fopen("/home/wzpc/Pictures/zz.jpg","w+b");
	fwrite(jp,671+k+2,1,fz);
	fclose(fz);
//	printf("%x\n",jp[671]);
//---------------------------------------------------
	return 0;
}




文章来源:https://blog.csdn.net/m0_59802969/article/details/135349688
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。