?? discrete cosine transform.txt
字號:
* ========================================================================= *
* *
* TEXAS INSTRUMENTS, INC. *
* *
* NAME *
* fdct_8x8 -- 8x8 Block FDCT With Rounding, Endian Neutral *
* *
* REVISION HISTORY *
* 20-May-1999 Initial handcode version *
* *
* USAGE *
* This routine is C callable, and has the following C prototype: *
* *
* void fdct_8x8(short fdct_data[], unsigned num_fdcts) *
* *
* The fdct routine accepts a list of 8x8 pixel blocks and performs *
* FDCTs on each. The array should be laid out identically to *
* "fdct_data[num_fdcts+1][8][8]". All operations in this array are *
* performed entirely in-place. *
* *
* Input values are stored in shorts, and may be in the range *
* [-512,511]. Larger input values may result in overflow, *
* although the 12-bit JPEG range [-1024,1023] overflows rarely. *
* *
* This code requires '48 + 160 * num_fdcts' cycles to process *
* 'num_fdcts' blocks, including function call overhead. When *
* 'num_fdcts' is zero, an early exit is taken and the function *
* runs for only 13 cycles (again, including call overhead). *
* *
* DESCRIPTION *
* The fdct_8x8 function implements a Chen FDCT. Output values are *
* rounded, providing improved accuracy. Input terms are expected *
* to be signed 11Q0 values, producing signed 15Q0 results. (A *
* smaller dynamic range may be used on the input, producing a *
* correspondingly smaller output range. Typical applications *
* include processing signed 9Q0 and unsigned 8Q0 pixel data, *
* producing signed 13Q0 or 12Q0 outputs, respectively.) No *
* saturation is performed. *
* *
* void fdct_8x8(short *dct_data, unsigned num_fdcts) *
* { *
* /* -------------------------------------------------------- */ *
* /* Set up the cosine coefficients c0..c7. */ *
* /* -------------------------------------------------------- */ *
* const unsigned short c1 = 0x2C62, c3 = 0x25A0; *
* const unsigned short c5 = 0x1924, c7 = 0x08D4; *
* const unsigned short c0 = 0xB505, c2 = 0x29CF; *
* const unsigned short c6 = 0x1151; *
* *
* /* -------------------------------------------------------- */ *
* /* Intermediate calculations. */ *
* /* -------------------------------------------------------- */ *
* short f0, f1, f2, f3, *
* f4, f5, f6, f7; /* Spatial domain samples. */ *
* int g0, g1, h0, h1, *
* p0, p1; /* Even-half intermediate. */ *
* short r0, r1; /* Even-half intermediate. */ *
* int P0, P1, R0, R1; /* Even-half intermediate. */ *
* short g2, g3, h2, h3; /* Odd-half intermediate. */ *
* short q0a,s0a,q0, q1, *
* s0, s1; /* Odd-half intermediate. */ *
* short Q0, Q1, S0, S1; /* Odd-half intermediate. */ *
* int F0, F1, F2, F3, *
* F4, F5, F6, F7; /* Freq. domain results. */ *
* int F0r,F1r,F2r,F3r, *
* F4r,F5r,F6r,F7r; /* Rounded, truncated results. */ *
* *
* /* -------------------------------------------------------- */ *
* /* Input and output pointers, loop control. */ *
* /* -------------------------------------------------------- */ *
* unsigned i, j; *
* short *dct_io_ptr; *
* *
* /* -------------------------------------------------------- */ *
* /* Outer vertical loop -- Process each 8x8 block. */ *
* /* -------------------------------------------------------- */ *
* dct_io_ptr = dct_data; *
* for (i = 0; i < num_fdcts; i++) *
* { *
* /* ---------------------------------------------------- */ *
* /* Perform Vert 1-D FDCT on columns within each block. */ *
* /* ---------------------------------------------------- */ *
* for (j = 0; j < 8; j++) *
* { *
* /* ------------------------------------------------ */ *
* /* Load the spatial-domain samples. */ *
* /* ------------------------------------------------ */ *
* f0 = dct_io_ptr[ 0]; *
* f1 = dct_io_ptr[ 8]; *
* f2 = dct_io_ptr[16]; *
* f3 = dct_io_ptr[24]; *
* f4 = dct_io_ptr[32]; *
* f5 = dct_io_ptr[40]; *
* f6 = dct_io_ptr[48]; *
* f7 = dct_io_ptr[56]; *
* *
* /* ------------------------------------------------ */ *
* /* Stage 1: Separate into even and odd halves. */ *
* /* ------------------------------------------------ */ *
* g0 = f0 + f7; h2 = f0 - f7; *
* g1 = f1 + f6; h3 = f1 - f6; *
* h1 = f2 + f5; g3 = f2 - f5; *
* h0 = f3 + f4; g2 = f3 - f4; *
* *
* /* ------------------------------------------------ */ *
* /* Stage 2 */ *
* /* ------------------------------------------------ */ *
* p0 = g0 + h0; r0 = g0 - h0; *
* p1 = g1 + h1; r1 = g1 - h1; *
* q1 = g2; s1 = h2; *
* *
* s0a= h3 + g3; q0a= h3 - g3; *
* s0 = (s0a * c0 + 0x7FFF) >> 16; *
* q0 = (q0a * c0 + 0x7FFF) >> 16; *
* *
* /* ------------------------------------------------ */ *
* /* Stage 3 */ *
* /* ------------------------------------------------ */ *
* P0 = p0 + p1; P1 = p0 - p1; *
* R1 = c6 * r1 + c2 * r0; R0 = c6 * r0 - c2 * r1; *
* *
* Q1 = q1 + q0; Q0 = q1 - q0; *
* S1 = s1 + s0; S0 = s1 - s0; *
* *
* /* ------------------------------------------------ */ *
* /* Stage 4 */ *
* /* ------------------------------------------------ */ *
* F0 = P0; F4 = P1; *
* F2 = R1; F6 = R0; *
* *
* F1 = c7 * Q1 + c1 * S1; F7 = c7 * S1 - c1 * Q1; *
* F5 = c3 * Q0 + c5 * S0; F3 = c3 * S0 - c5 * Q0; *
* *
* /* ------------------------------------------------ */ *
* /* Store the frequency domain results. */ *
* /* ------------------------------------------------ */ *
* dct_io_ptr[ 0] = F0; *
* dct_io_ptr[ 8] = F1 >> 13; *
* dct_io_ptr[16] = F2 >> 13; *
* dct_io_ptr[24] = F3 >> 13; *
* dct_io_ptr[32] = F4; *
* dct_io_ptr[40] = F5 >> 13; *
* dct_io_ptr[48] = F6 >> 13; *
* dct_io_ptr[56] = F7 >> 13; *
* *
* dct_io_ptr++; *
* } *
* /* ---------------------------------------------------- */ *
* /* Update pointer to next 8x8 FDCT block. */ *
* /* ---------------------------------------------------- */ *
* dct_io_ptr += 56; *
* } *
* *
* /* -------------------------------------------------------- */ *
* /* Perform Horizontal 1-D FDCT on each 8x8 block. */ *
* /* -------------------------------------------------------- */ *
* dct_io_ptr = dct_data; *
* for (i = 0; i < 8 * num_fdcts; i++) *
* { *
* /* ---------------------------------------------------- */ *
* /* Load the spatial-domain samples. */ *
* /* ---------------------------------------------------- */ *
* f0 = dct_io_ptr[0]; *
* f1 = dct_io_ptr[1]; *
* f2 = dct_io_ptr[2]; *
* f3 = dct_io_ptr[3]; *
* f4 = dct_io_ptr[4]; *
* f5 = dct_io_ptr[5]; *
* f6 = dct_io_ptr[6]; *
* f7 = dct_io_ptr[7]; *
* *
* /* ---------------------------------------------------- */ *
* /* Stage 1: Separate into even and odd halves. */ *
* /* ---------------------------------------------------- */ *
* g0 = f0 + f7; h2 = f0 - f7; *
* g1 = f1 + f6; h3 = f1 - f6; *
* h1 = f2 + f5; g3 = f2 - f5; *
* h0 = f3 + f4; g2 = f3 - f4; *
* *
* /* ---------------------------------------------------- */ *
* /* Stage 2 */ *
* /* ---------------------------------------------------- */ *
* p0 = g0 + h0; r0 = g0 - h0; *
* p1 = g1 + h1; r1 = g1 - h1; *
* q1 = g2; s1 = h2; *
* *
* s0a= h3 + g3; q0a= h3 - g3; *
* q0 = (q0a * c0 + 0x7FFF) >> 16; *
* s0 = (s0a * c0 + 0x7FFF) >> 16; *
* *
* /* ---------------------------------------------------- */ *
* /* Stage 3 */ *
* /* ---------------------------------------------------- */ *
* P0 = p0 + p1; P1 = p0 - p1; *
* R1 = c6 * r1 + c2 * r0; R0 = c6 * r0 - c2 * r1; *
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -