📄 hi_jpegdecode1.c
字号:
{ for(i = 0;i < rrun;i++) /* 前面的零 */ { BlockBuffer[count++] = 0; } BlockBuffer[count++] = vvalue;/* 解出的值 */ } } return FUNC_OK;}/************************************************************************** Huffman 解码 每个元素 出口 vvalue 入口 读文件ReadByte***************************************************************************/int DecodeElement(void){ int thiscode,tempcode; UINT16 temp,valueex; short codelen; UINT8 hufexbyte,runsize,tempsize,sign; UINT8 newbyte,lastbyte; if(BitPos >= 1) /* BitPos指示当前比特位置 */ { BitPos--; thiscode = (UINT8)CurByte >> BitPos; /* 取一个比特 */ CurByte = CurByte & MyAnd[BitPos]; /* 清除取走的比特位 */ } else /* 取出的一个字节已用完 */ { /* 新取 */ lastbyte = ReadByte(); /* 读出一个字节 */ BitPos--; /* and[]:=0x0,0x1,0x3,0x7,0xf,0x1f,0x2f,0x3f,0x4f */ newbyte = CurByte & MyAnd[BitPos]; // thiscode = lastbyte >> 7; CurByte = newbyte; } codelen = 1;/* 与Huffman表中的码字匹配,直自找到为止 */ while((thiscode < huf_min_value[HufTabIndex][codelen - 1]) || (code_len_table[HufTabIndex][codelen - 1] == 0) || (thiscode > huf_max_value[HufTabIndex][codelen - 1])) { if(BitPos >= 1) /* 取出的一个字节还有 */ { BitPos--; tempcode = (UINT8)CurByte >> BitPos; CurByte = CurByte & MyAnd[BitPos]; } else { lastbyte = ReadByte(); BitPos--; newbyte = CurByte & MyAnd[BitPos]; tempcode = (UINT8)lastbyte >> 7; CurByte = newbyte; } thiscode = (thiscode << 1) + tempcode; codelen++; if(codelen > 16) { return FUNC_FORMAT_ERROR; } } //while temp = thiscode - huf_min_value[HufTabIndex][codelen - 1] + code_pos_table[HufTabIndex][codelen - 1]; hufexbyte = (UINT8)code_value_table[HufTabIndex][temp]; rrun = (short)(hufexbyte >> 4); /* 一个字节中,高四位是其前面的零的个数。*/ runsize = hufexbyte & 0x0f; /* 后四位为后面字的尺寸 */ if(runsize == 0) { vvalue = 0; return FUNC_OK; } tempsize = runsize; if(BitPos >= runsize) { BitPos = BitPos - runsize; valueex = (UINT8)CurByte >> BitPos; CurByte = CurByte & MyAnd[BitPos]; } else { valueex = CurByte; tempsize -= BitPos; while(tempsize > 8) { lastbyte = ReadByte(); valueex = (valueex << 8) + (UINT8)lastbyte; tempsize -= 8; } //while lastbyte = ReadByte(); BitPos -= tempsize; valueex = (valueex << tempsize) + (lastbyte >> BitPos); CurByte = lastbyte & MyAnd[BitPos]; } //else sign = valueex >> (runsize - 1); if(sign != 0) { vvalue = valueex; /* 解出的码值 */ } else { valueex = valueex ^ 0xffff; temp = 0xffff << runsize; vvalue = -(short)(valueex ^ temp); } return FUNC_OK;}/************************************************************************************ 反量化MCU中的每个组件 入口 MCUBuffer 出口 QtZzMCUBuffer*************************************************************************************/void IQtIZzMCUComponent(short flag){ short H,VV; int *pQtZzMCUBuffer,*tempbuf1; short *pMCUBuffer,*tempbuf2; int i,j; switch(flag) { case 0: H = SampRate_Y_H; VV = SampRate_Y_V; pMCUBuffer = MCUBuffer; /* Huffman Decoded */ pQtZzMCUBuffer = QtZzMCUBuffer; break; case 1: H = SampRate_U_H; VV = SampRate_U_V; pMCUBuffer = MCUBuffer; pMCUBuffer += Y_in_MCU << 6; pQtZzMCUBuffer = QtZzMCUBuffer; pQtZzMCUBuffer += Y_in_MCU << 6; break; case 2: H = SampRate_V_H; VV = SampRate_V_V; pMCUBuffer = MCUBuffer; pMCUBuffer += (Y_in_MCU + U_in_MCU) << 6; pQtZzMCUBuffer = QtZzMCUBuffer; pQtZzMCUBuffer += (Y_in_MCU + U_in_MCU) << 6; break; default: H = 0; pQtZzMCUBuffer = NULL; pMCUBuffer = NULL; VV = 0; break; } for(i = 0;i < VV;i++) { for(j = 0;j < H;j++) { tempbuf2 = pMCUBuffer; tempbuf2 += (i * H + j) << 6; tempbuf1 = pQtZzMCUBuffer; tempbuf1 += (i * H + j) << 6; IQtIZzBlock(tempbuf2,tempbuf1,flag); /* 8*8DU */ } }} /* 要量化的字 *//********************************************************************************** 反量化 8*8 DU***********************************************************************************/void IQtIZzBlock(short *s,int *d,short flag){ short tag; short *pQt,*temp1,*temp3; int buffer2[8][8]; int *temp2; short offset; int i,j; switch(flag) { case 0: /* 亮度 */ pQt = YQtTable; /* 量化表地址 */ /* ShowMessage(IntTostr(YQtTable^)); */ offset = 128; break; case 1: /* 红 */ pQt = UQtTable; offset = 0; break; case 2: /* 蓝 */ pQt = VQtTable; offset = 0; break; default: pQt = NULL; offset = 0; break; } for(i = 0;i < 8;i++) { for(j = 0;j < 8;j++) { tag = Zig_Zag[i][j]; temp1 = s; temp1 += tag; temp3 = pQt; temp3 += tag; buffer2[i][j] = (int)((*temp1) * (*temp3)); } } Fast_IDCT(&buffer2[0][0]); /* 反DCT */ for(i = 0;i < 8;i++) { for(j = 0;j < 8;j++) { temp2 = d; temp2 += (i << 3) + j; *temp2 = buffer2[i][j] + offset; } }}void Fast_IDCT(int *block){ short i; for(i = 0;i < 8;i++) { idctrow(block + (i << 3)); } for(i = 0;i < 8;i++) { idctcol(block + i); }}UINT8 ReadByte(void){ UINT8 i; i = *lp; /* lp 为解码的起始位置 */ lp = lp + 1; if(i == 0xff) { lp = lp + 1; } BitPos = 8; CurByte = i; return i;}void Initialize_Fast_IDCT(void){ int i; iclp = iclip + 512; for (i= -512; i < 512; i++) { /* iclp[i] = (i < -256) ? -256 : ((i > 255) ? 255 : i);*/ if(i < -256) { iclp[i] = -256; } if(i > 255) { iclp[i] = 255; } if(( i >= -256) && (i <= 255)) { iclp[i] = i; } }}void idctrow(int *blk){ int x0, x1, x2, x3, x4, x5, x6, x7, x8; //intcut x1 = blk[4] << 11; x2 = blk[6]; x3 = blk[2]; x4 = blk[1]; x5 = blk[7]; x6 = blk[5]; x7 = blk[3]; if ((x1 || x2 || x3 || x4 || x5 || x6 || x7) == 0) { blk[1] = blk[0] << 3; blk[2] = blk[0] << 3; blk[3] = blk[0] << 3; blk[4] = blk[0] << 3; blk[5] = blk[0] << 3; blk[6] = blk[0] << 3; blk[7] = blk[0] << 3; blk[0] = blk[0] << 3; return; } x0 = (blk[0] << 11) + 128; /* for proper rounding in the fourth stage */ /* first stage */ x8 = W7 * (x4 + x5); x4 = x8 + (W1 - W7) * x4; x5 = x8 - (W1 + W7) * x5; x8 = W3 * (x6 + x7); x6 = x8 - (W3 - W5) * x6; x7 = x8 - (W3 + W5) * x7; /* second stage */ x8 = x0 + x1; x0 -= x1; x1 = W6 * (x3 + x2); x2 = x1 - (W2 + W6) * x2; x3 = x1 + (W2 - W6) * x3; x1 = x4 + x6; x4 -= x6; x6 = x5 + x7; x5 -= x7; /* third stage */ x7 = x8 + x3; x8 -= x3; x3 = x0 + x2; x0 -= x2; x2 = (181 * (x4 + x5) + 128) >> 8; x4 = (181 * (x4 - x5) + 128) >> 8; //fourth stage blk[0] = (x7 + x1) >> 8; blk[1] = (x3 + x2) >> 8; blk[2] = (x0 + x4) >> 8; blk[3] = (x8 + x6) >> 8; blk[4] = (x8 - x6) >> 8; blk[5] = (x0 - x4) >> 8; blk[6] = (x3 - x2) >> 8; blk[7] = (x7 - x1) >> 8;}void idctcol(int * blk){ int x0, x1, x2, x3, x4, x5, x6, x7, x8; /* intcut */ x1 = blk[32] << 8; x2 = blk[48]; x3 = blk[16]; x4 = blk[8]; x5 = blk[56]; x6 = blk[40]; x7 = blk[24]; if ((x1 | x2 | x3 | x4 | x5 | x6 | x7) == 0) { blk[8] = iclp[(blk[0] + 32) >> 6]; blk[16] = iclp[(blk[0] + 32) >> 6]; blk[24] = iclp[(blk[0] + 32) >> 6]; blk[32] = iclp[(blk[0] + 32) >> 6]; blk[40] = iclp[(blk[0] + 32) >> 6]; blk[48] = iclp[(blk[0] + 32) >> 6]; blk[56] = iclp[(blk[0] + 32) >> 6]; blk[0] = iclp[(blk[0] + 32) >> 6]; return; } x0 = (blk[0] << 8) + 8192; /* first stage */ x8 = W7 * (x4 + x5) + 4; x4 = (x8 + (W1 - W7) * x4) >> 3; x5 = (x8 - (W1 + W7) * x5) >> 3; x8 = W3 * (x6 + x7) + 4; x6 = (x8 - (W3 - W5) * x6) >> 3; x7 = (x8 - (W3 + W5) * x7) >> 3; //second stage x8 = x0 + x1; x0 -= x1; x1 = W6 * (x3 + x2) + 4; x2 = (x1 - (W2 + W6) * x2) >> 3; x3 = (x1 + (W2 - W6) * x3) >> 3; x1 = x4 + x6; x4 -= x6; x6 = x5 + x7; x5 -= x7; //third stage x7 = x8 + x3; x8 -= x3; x3 = x0 + x2; x0 -= x2; x2 = (181 * (x4 + x5) + 128) >> 8; x4 = (181 * (x4 - x5) + 128) >> 8; /* fourth stage */ blk[0] = iclp[(x7 + x1) >> 14]; blk[8] = iclp[(x3 + x2) >> 14]; blk[16] = iclp[(x0 + x4) >> 14]; blk[24] = iclp[(x8 + x6) >> 14]; blk[32] = iclp[(x8 - x6) >> 14]; blk[40] = iclp[(x0 - x4) >> 14]; blk[48] = iclp[(x3 - x2) >> 14]; blk[56] = iclp[(x7 - x1) >> 14];}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -