📄 idct_arai.cc
字号:
a6 = tmp[v][1]-tmp[v][7]; a7 = tmp1 + tmp2; tmp4 = MUL32(C6,(a4+a6)); b2 = IDESCALE(MUL32(C4 , a2) , IDCT_PostM1_Shift); b4 = IDESCALE(MUL32(Q , a4) -tmp4 , IDCT_PostM1_Shift); b5 = IDESCALE(MUL32(C4 , a5) , IDCT_PostM1_Shift); b6 = IDESCALE(MUL32(R , a6) -tmp4 , IDCT_PostM1_Shift); a0 >>= -(IDCT_M1Scale - IDCT_PostM1_Shift); a1 >>= -(IDCT_M1Scale - IDCT_PostM1_Shift); a3 >>= -(IDCT_M1Scale - IDCT_PostM1_Shift); a7 >>= -(IDCT_M1Scale - IDCT_PostM1_Shift); tmp3 = b6-a7; n0 = tmp3-b5; n1 = a0-a1; n2 = b2-a3; n3 = a0+a1; m3 = n1+n2; m4 = n3+a3; m5 = n1-n2; m6 = n3-a3; m7 = b4-n0; out[v][0] = IDESCALE( (m4+a7) , IDCT_PostM1_NK); out[v][1] = IDESCALE( (m3+tmp3) , IDCT_PostM1_NK); out[v][2] = IDESCALE( (m5-n0) , IDCT_PostM1_NK); out[v][3] = IDESCALE( (m6-m7) , IDCT_PostM1_NK); out[v][4] = IDESCALE( (m6+m7) , IDCT_PostM1_NK); out[v][5] = IDESCALE( (m5+n0) , IDCT_PostM1_NK); out[v][6] = IDESCALE( (m3-tmp3) , IDCT_PostM1_NK); out[v][7] = IDESCALE( (m4-a7) , IDCT_PostM1_NK); }}}//// --------------- The following IDCT-code originates from libJPEG ! -----------------/**********************************************************//* inverse two dimensional DCT, Chen-Wang algorithm *//* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) *//* 32-bit integer arithmetic (8 bit coefficients) *//* 11 mults, 29 adds per DCT *//* sE, 18.8.91 *//**********************************************************//* coefficients extended to 12 bit for IEEE1180-1990 *//* compliance sE, 2.1.94 *//**********************************************************//* this code assumes >> to be a two's-complement arithmetic *//* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */// #include "config.h"#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) *//* global declarations *///void Initialize_Fast_IDCT _ANSI_ARGS_((void));//void Fast_IDCT _ANSI_ARGS_((short *block));/* private prototypes *///static void idctrow _ANSI_ARGS_((short *blk));//static void idctcol _ANSI_ARGS_((short *blk));/* row (horizontal) IDCT * * 7 pi 1 * dst[k] = sum c[l] * src[l] * cos( -- * ( k + - ) * l ) * l=0 8 2 * * where: c[0] = 128 * c[1..7] = 128*sqrt(2) */inline void idctrow(short *blk){ int x0, x1, x2, x3, x4, x5, x6, x7, x8; /* shortcut */ if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) | (x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3]))) { blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=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;}/* column (vertical) IDCT * * 7 pi 1 * dst[8*k] = sum c[l] * src[8*l] * cos( -- * ( k + - ) * l ) * l=0 8 2 * * where: c[0] = 1/1024 * c[1..7] = (1/1024)*sqrt(2) */inline void idctcol2(short **in,int i,short** out){ int x0, x1, x2, x3, x4, x5, x6, x7, x8; /* shortcut */ if (!((x1 = (in[4][i]<<8)) | (x2 = in[6][i]) | (x3 = in[2][i]) | (x4 = in[1][i]) | (x5 = in[7][i]) | (x6 = in[5][i]) | (x7 = in[3][i]))) { out[0][i] = out[1][i] = out[2][i] = out[3][i] = out[4][i] = out[5][i] = out[6][i] = out[7][i] = (in[0][i]+32)>>6; //iclp return; } x0 = (in[0][i]<<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 */ out[0][i] = (x7+x1)>>14; out[1][i] = (x3+x2)>>14; out[2][i] = (x0+x4)>>14; out[3][i] = (x8+x6)>>14; out[4][i] = (x8-x6)>>14; out[5][i] = (x0-x4)>>14; out[6][i] = (x3-x2)>>14; out[7][i] = (x7-x1)>>14;}inline void idctcol2b(short *in,int i,Pixel** out,bool add){ int x0, x1, x2, x3, x4, x5, x6, x7, x8; /* shortcut */ if (!((x1 = (in[4*8]<<8)) | (x2 = in[6*8]) | (x3 = in[2*8]) | (x4 = in[1*8]) | (x5 = in[7*8]) | (x6 = in[5*8]) | (x7 = in[3*8]))) { if (add) {#if 0 out[0][i] = clip2_0_255[ out[0][i] + ((in[0][i]+32)>>6)]; out[1][i] = clip2_0_255[ out[1][i] + ((in[1][i]+32)>>6)]; out[2][i] = clip2_0_255[ out[2][i] + ((in[2][i]+32)>>6)]; out[3][i] = clip2_0_255[ out[3][i] + ((in[3][i]+32)>>6)]; out[4][i] = clip2_0_255[ out[4][i] + ((in[4][i]+32)>>6)]; out[5][i] = clip2_0_255[ out[5][i] + ((in[5][i]+32)>>6)]; out[6][i] = clip2_0_255[ out[6][i] + ((in[6][i]+32)>>6)]; out[7][i] = clip2_0_255[ out[7][i] + ((in[7][i]+32)>>6)]; return;#endif } else {#if 1 out[0][i] = out[1][i] = out[2][i] = out[3][i] = out[4][i] = out[5][i] = out[6][i] = out[7][i] = clip2_0_255[(in[0*8]+32)>>6]; //iclp return;#endif } } x0 = (in[0*8]<<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 */ if (add) { out[0][i] = clip2_0_255[ out[0][i] + ((x7+x1)>>14) ]; out[7][i] = clip2_0_255[ out[7][i] + ((x7-x1)>>14) ]; out[1][i] = clip2_0_255[ out[1][i] + ((x3+x2)>>14) ]; out[6][i] = clip2_0_255[ out[6][i] + ((x3-x2)>>14) ]; out[2][i] = clip2_0_255[ out[2][i] + ((x0+x4)>>14) ]; out[5][i] = clip2_0_255[ out[5][i] + ((x0-x4)>>14) ]; out[3][i] = clip2_0_255[ out[3][i] + ((x8+x6)>>14) ]; out[4][i] = clip2_0_255[ out[4][i] + ((x8-x6)>>14) ]; } else { out[0][i] = clip2_0_255[ ((x7+x1)>>14) ]; out[7][i] = clip2_0_255[ ((x7-x1)>>14) ]; out[1][i] = clip2_0_255[ ((x3+x2)>>14) ]; out[6][i] = clip2_0_255[ ((x3-x2)>>14) ]; out[2][i] = clip2_0_255[ ((x0+x4)>>14) ]; out[5][i] = clip2_0_255[ ((x0-x4)>>14) ]; out[3][i] = clip2_0_255[ ((x8+x6)>>14) ]; out[4][i] = clip2_0_255[ ((x8-x6)>>14) ]; }}/* two dimensional inverse discrete cosine transform */void IDCT_Int2(short* in[8], short* out[8]){ int i; for (i=0; i<8; i++) idctrow(in[i]); for (i=0; i<8; i++) idctcol2(in,i,out);}void IDCT_Int2b(short* in, Pixel* out[8],bool add){ int i; for (i=0; i<8; i++) idctrow(in+8*i); for (i=0; i<8; i++) idctcol2b(in+i,i,out,add);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -