📄 jfdctint.c
字号:
z3 *= -FIX_1_961570560; /* sqrt(2) * (-c3-c5) */
z4 *= -FIX_0_390180644; /* sqrt(2) * (c5-c3) */
z3 += z5;
z4 += z5;
dataptr[56] = DESCALE(tmp4 + z1 + z3, CONST_BITS + PASS1_BITS);
dataptr[40] = DESCALE(tmp5 + z2 + z4, CONST_BITS + PASS1_BITS);
dataptr[24] = DESCALE(tmp6 + z2 + z3, CONST_BITS + PASS1_BITS);
dataptr[8] = DESCALE(tmp7 + z1 + z4, CONST_BITS + PASS1_BITS);
dataptr++; /* advance pointer to next column */
}
/* descale */
for (i = 0; i < 64; i++)
block[i] = (short) DESCALE(data[i], 3);
}
void jpeg_fdct_islow_ti(short *dct)
{
/* -------------------------------------------------------------------- */
/* Set up the cosine coefficients. */
/* -------------------------------------------------------------------- */
const unsigned short c1 = 0x1F62, c3 = 0x1A9B; /* Q13 coeffs */
const unsigned short c5 = 0x11C7, c7 = 0x063E; /* Q13 coeffs */
const unsigned short c2 = 0x29CF, c6 = 0x1151; /* Q13.5 coeffs */
const unsigned short C1 = 0xFB15, C3 = 0xD4DB; /* Q16 coeffs */
const unsigned short C5 = 0x8E3A, C7 = 0x31F1; /* Q16 coeffs */
const unsigned short C2 = 0xA73D, C6 = 0x4546; /* Q15.5 coeffs */
const unsigned short C4 = 0xB505; /* Q16 coeff */
/* -------------------------------------------------------------------- */
/* Intermediate calculations. */
/* -------------------------------------------------------------------- */
short f0, f1, f2, f3, f4, f5, f6, f7; /* Spatial domain samples. */
short g0, g1, h0, h1, p0, p1; /* Even-half intermediate. */
short r0, r1, r0_,r1_; /* Even-half intermediate. */
short P0, P1, R0, R1; /* Even-half intermediate. */
short g2, g3, h2, h3; /* Odd-half intermediate. */
short q1a,s1a,q0, q1, s0, s1; /* Odd-half intermediate. */
short Q0, Q1, S0, S1; /* Odd-half intermediate. */
short F0, F1, F2, F3, F4, F5, F6, F7; /* Freq. domain results. */
/* -------------------------------------------------------------------- */
/* Input and output pointers, loop control. */
/* -------------------------------------------------------------------- */
unsigned int j;
/* ---------------------------------------------------------------- */
/* Perform Vertical 1-D FDCT on columns within each block. */
/* ---------------------------------------------------------------- */
for (j = 0; j < 8; j++)
{
/* ------------------------------------------------------------ */
/* Load the spatial-domain samples. */
/* The incoming terms start at Q0 precision. */
/* ------------------------------------------------------------ */
f0 = dct[0*8+j];
f1 = dct[1*8+j];
f2 = dct[2*8+j];
f3 = dct[3*8+j];
f4 = dct[4*8+j];
f5 = dct[5*8+j];
f6 = dct[6*8+j];
f7 = dct[7*8+j];
/* ------------------------------------------------------------ */
/* Stage 1: Separate into even and odd halves. */
/* */
/* The results of this stage are implicitly in Q1, since we */
/* do not explicitly multiply by 0.5. */
/* ------------------------------------------------------------ */
g0 = f0 + f7; g1 = f1 + f6; /* Results in Q1 */
h1 = f2 + f5; h0 = f3 + f4; /* Results in Q1 */
g3 = f2 - f5; g2 = f3 - f4; /* Results in Q1 */
h2 = f0 - f7; h3 = f1 - f6; /* Results in Q1 */
/* ------------------------------------------------------------ */
/* Stage 2 */
/* */
/* Note, on the odd-half, the results are in Q1.5 since those */
/* values are scaled upwards by sqrt(2) at this point. */
/* ------------------------------------------------------------ */
p0 = g0 + h0; r0 = g0 - h0; /* Results in Q1 */
p1 = g1 + h1; r1 = g1 - h1; /* Results in Q1 */
q1a = g2 + g2; /* q1a is now Q2 */
s1a = h2 + h2; /* s1a is now Q2 */
q1 = (q1a * C4 + 0x8000) >> 16; /* Results in Q1.5 */
s1 = (s1a * C4 + 0x8000) >> 16; /* Results in Q1.5 */
s0 = h3 + g3; /* Results in Q1.5 */
q0 = h3 - g3; /* Results in Q1.5 */
/* ------------------------------------------------------------ */
/* Stage 3 */
/* */
/* 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[0*8+j] = F0;
dct[1*8+j] = F1;
dct[2*8+j] = F2;
dct[3*8+j] = F3;
dct[4*8+j] = F4;
dct[5*8+j] = F5;
dct[6*8+j] = F6;
dct[7*8+j] = F7;
}
/* ---------------------------------------------------------------- */
/* 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[j*8+0];
f1 = dct[j*8+1];
f2 = dct[j*8+2];
f3 = dct[j*8+3];
f4 = dct[j*8+4];
f5 = dct[j*8+5];
f6 = dct[j*8+6];
f7 = dct[j*8+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[j*8+0] = F0;
dct[j*8+1] = F1;
dct[j*8+2] = F2;
dct[j*8+3] = F3;
dct[j*8+4] = F4;
dct[j*8+5] = F5;
dct[j*8+6] = F6;
dct[j*8+7] = F7;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -