📄 img_fdct_8x8_c.c
字号:
/* */
/* Now, the even-half ends up in Q1.5. On P0 and P1, this */
/* happens because the multiply-by-C4 was canceled with an */
/* upward scaling by sqrt(2). On R0 and R1, this happens */
/* because C2 and C6 are at Q15.5, and we scale r0 and r1 to */
/* Q2 before we multiply. */
/* ------------------------------------------------------------ */
P0 = p0 + p1; /* Results in Q1.5 */
P1 = p0 - p1; /* Results in Q1.5 */
r0_= r0 + r0; /* r0_ is now Q2 */
r1_= r1 + r1; /* r1_ is now Q2 */
R1 = (C6 * r1_+ C2 * r0_+ 0x8000) >> 16; /* Results in Q1.5 */
R0 = (C6 * r0_- C2 * r1_+ 0x8000) >> 16; /* Results in Q1.5 */
Q1 = q1 + q0; Q0 = q1 - q0;
S1 = s1 + s0; S0 = s1 - s0;
/* ------------------------------------------------------------ */
/* Stage 4 */
/* No further changes in Q-point happen here. */
/* ------------------------------------------------------------ */
F0 = P0; F4 = P1;
F2 = R1; F6 = R0;
F1 = (C7 * Q1 + C1 * S1 + 0x8000) >> 16; /* Results in Q1.5 */
F7 = (C7 * S1 - C1 * Q1 + 0x8000) >> 16; /* Results in Q1.5 */
F5 = (C3 * Q0 + C5 * S0 + 0x8000) >> 16; /* Results in Q1.5 */
F3 = (C3 * S0 - C5 * Q0 + 0x8000) >> 16; /* Results in Q1.5 */
/* ------------------------------------------------------------ */
/* Store the frequency domain results. */
/* These values are all at Q1.5 precision. */
/* ------------------------------------------------------------ */
dct[i][0][j] = F0;
dct[i][1][j] = F1;
dct[i][2][j] = F2;
dct[i][3][j] = F3;
dct[i][4][j] = F4;
dct[i][5][j] = F5;
dct[i][6][j] = F6;
dct[i][7][j] = F7;
}
}
/* -------------------------------------------------------------------- */
/* Perform Horizontal 1-D FDCT on each 8x8 block. */
/* -------------------------------------------------------------------- */
for (i = 0; i < num_fdcts; i++)
{
/* ---------------------------------------------------------------- */
/* Perform Vertical 1-D FDCT on columns within each block. */
/* ---------------------------------------------------------------- */
for (j = 0; j < 8; j++)
{
/* ------------------------------------------------------------ */
/* Load the spatial-domain samples. */
/* The incoming terms are at Q1.5 precision from first pass. */
/* ------------------------------------------------------------ */
f0 = dct[i][j][0];
f1 = dct[i][j][1];
f2 = dct[i][j][2];
f3 = dct[i][j][3];
f4 = dct[i][j][4];
f5 = dct[i][j][5];
f6 = dct[i][j][6];
f7 = dct[i][j][7];
/* ------------------------------------------------------------ */
/* Stage 1: Separate into even and odd halves. */
/* */
/* The results of this stage are implicitly in Q2.5, since we */
/* do not explicitly multiply by 0.5. */
/* ------------------------------------------------------------ */
g0 = f0 + f7; g1 = f1 + f6; /* Results in Q2.5 */
h1 = f2 + f5; h0 = f3 + f4; /* Results in Q2.5 */
h2 = f0 - f7; h3 = f1 - f6; /* Results in Q2.5 */
g3 = f2 - f5; g2 = f3 - f4; /* Results in Q2.5 */
/* ------------------------------------------------------------ */
/* Stage 2 */
/* */
/* Note, on the odd-half, the results are in Q3 since those */
/* values are scaled upwards by sqrt(2) at this point. The */
/* order of operations differs in this pass as compared to */
/* the first due to overflow concerns. */
/* */
/* We also inject a rounding term into the DC term which will */
/* also round the Nyquist term, F4. This trick works despite */
/* the fact that we are technically still at Q2.5 here, since */
/* the step from Q2.5 to Q3 later is done implicitly, rather */
/* than with a multiply. (This is due to the sqrt(2) terms */
/* cancelling on the P0/P1 butterfly.) */
/* ------------------------------------------------------------ */
p0 = g0 + h0 + 4; p1 = g1 + h1; /* Results in Q2.5 */
r0 = g0 - h0; r1 = g1 - h1; /* Results in Q2.5 */
q1a= (g2 * C4 + 0x8000) >> 16; /* q1a now in Q2 */
s1a= (h2 * C4 + 0x8000) >> 16; /* s1a now in Q2 */
q1 = q1a + q1a; /* Results in Q3 */
s1 = s1a + s1a; /* Results in Q3 */
s0 = h3 + g3; /* Results in Q3 */
q0 = h3 - g3; /* Results in Q3 */
/* ------------------------------------------------------------ */
/* Stage 3 */
/* */
/* Now, the even-half ends up in Q0. This happens on P0 and */
/* P1 because the multiply-by-c4 was canceled with an upward */
/* scaling by sqrt(2), yielding Q3 intermediate value. The */
/* final >> 3 leaves these at Q0. On R0 and R1, this happens */
/* because c2 and c6 are at Q13.5, giving a Q16 intermediate */
/* value. The final >> 16 then leaves those values at Q0. */
/* ------------------------------------------------------------ */
P0 = ((short)(p0 + p1)) >> 3; /* Results in Q0 */
P1 = ((short)(p0 - p1)) >> 3; /* Results in Q0 */
R1 = (c6 * r1 + c2 * r0 + 0x8000) >> 16; /* Results in Q0 */
R0 = (c6 * r0 - c2 * r1 + 0x8000) >> 16; /* Results in Q0 */
Q1 = q1 + q0; Q0 = q1 - q0; /* Results in Q3 */
S1 = s1 + s0; S0 = s1 - s0; /* Results in Q3 */
/* ------------------------------------------------------------ */
/* Stage 4 */
/* */
/* Next, the odd-half ends up in Q0. This happens because */
/* our values are in Q3 and our cosine terms are in Q13, */
/* giving us Q16 intermediate values. The final >> 16 leaves */
/* us a Q0 result. */
/* ------------------------------------------------------------ */
F0 = P0; F4 = P1;
F2 = R1; F6 = R0;
F1 = (c7 * Q1 + c1 * S1 + 0x8000) >> 16; /* Results in Q0 */
F7 = (c7 * S1 - c1 * Q1 + 0x8000) >> 16; /* Results in Q0 */
F5 = (c3 * Q0 + c5 * S0 + 0x8000) >> 16; /* Results in Q0 */
F3 = (c3 * S0 - c5 * Q0 + 0x8000) >> 16; /* Results in Q0 */
/* ------------------------------------------------------------ */
/* Store the results */
/* ------------------------------------------------------------ */
dct[i][j][0] = F0;
dct[i][j][1] = F1;
dct[i][j][2] = F2;
dct[i][j][3] = F3;
dct[i][j][4] = F4;
dct[i][j][5] = F5;
dct[i][j][6] = F6;
dct[i][j][7] = F7;
}
}
return;
}
/* ======================================================================== */
/* End of file: img_fdct_8x8.c */
/* ------------------------------------------------------------------------ */
/* Copyright (c) 2002 Texas Instruments, Incorporated. */
/* All Rights Reserved. */
/* ======================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -