📄 jfdctint.c
字号:
tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[4]);
tmp3 = GETJSAMPLE(elemptr[3]);
tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[6]);
tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[5]);
tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[4]);
z1 = tmp0 + tmp2;
/* Apply unsigned->signed conversion */
dataptr[0] = (DCTELEM)
((z1 + tmp1 + tmp3 - 7 * CENTERJSAMPLE) << PASS1_BITS);
tmp3 += tmp3;
z1 -= tmp3;
z1 -= tmp3;
z1 = MULTIPLY(z1, FIX(0.353553391)); /* (c2+c6-c4)/2 */
z2 = MULTIPLY(tmp0 - tmp2, FIX(0.920609002)); /* (c2+c4-c6)/2 */
z3 = MULTIPLY(tmp1 - tmp2, FIX(0.314692123)); /* c6 */
dataptr[2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS-PASS1_BITS);
z1 -= z2;
z2 = MULTIPLY(tmp0 - tmp1, FIX(0.881747734)); /* c4 */
dataptr[4] = (DCTELEM)
DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.707106781)), /* c2+c6-c4 */
CONST_BITS-PASS1_BITS);
dataptr[6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS-PASS1_BITS);
/* Odd part */
tmp1 = MULTIPLY(tmp10 + tmp11, FIX(0.935414347)); /* (c3+c1-c5)/2 */
tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.170262339)); /* (c3+c5-c1)/2 */
tmp0 = tmp1 - tmp2;
tmp1 += tmp2;
tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.378756276)); /* -c1 */
tmp1 += tmp2;
tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.613604268)); /* c5 */
tmp0 += tmp3;
tmp2 += tmp3 + MULTIPLY(tmp12, FIX(1.870828693)); /* c3+c1-c5 */
dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);
dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);
dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);
dataptr += DCTSIZE; /* advance pointer to next row */
}
/* Pass 2: process columns.
* We remove the PASS1_BITS scaling, but leave the results scaled up
* by an overall factor of 8.
* We must also scale the output by (8/7)**2 = 64/49, which we fold
* into the constant multipliers:
* cK now represents sqrt(2) * cos(K*pi/14) * 64/49.
*/
dataptr = data;
for (ctr = 0; ctr < 7; ctr++) {
/* Even part */
tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*6];
tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*5];
tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*4];
tmp3 = dataptr[DCTSIZE*3];
tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*6];
tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*5];
tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*4];
z1 = tmp0 + tmp2;
dataptr[DCTSIZE*0] = (DCTELEM)
DESCALE(MULTIPLY(z1 + tmp1 + tmp3, FIX(1.306122449)), /* 64/49 */
CONST_BITS+PASS1_BITS);
tmp3 += tmp3;
z1 -= tmp3;
z1 -= tmp3;
z1 = MULTIPLY(z1, FIX(0.461784020)); /* (c2+c6-c4)/2 */
z2 = MULTIPLY(tmp0 - tmp2, FIX(1.202428084)); /* (c2+c4-c6)/2 */
z3 = MULTIPLY(tmp1 - tmp2, FIX(0.411026446)); /* c6 */
dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS+PASS1_BITS);
z1 -= z2;
z2 = MULTIPLY(tmp0 - tmp1, FIX(1.151670509)); /* c4 */
dataptr[DCTSIZE*4] = (DCTELEM)
DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.923568041)), /* c2+c6-c4 */
CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+PASS1_BITS);
/* Odd part */
tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.221765677)); /* (c3+c1-c5)/2 */
tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.222383464)); /* (c3+c5-c1)/2 */
tmp0 = tmp1 - tmp2;
tmp1 += tmp2;
tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.800824523)); /* -c1 */
tmp1 += tmp2;
tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.801442310)); /* c5 */
tmp0 += tmp3;
tmp2 += tmp3 + MULTIPLY(tmp12, FIX(2.443531355)); /* c3+c1-c5 */
dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS);
dataptr++; /* advance pointer to next column */
}
}
/*
* Perform the forward DCT on a 6x6 sample block.
*/
GLOBAL(void)
jpeg_fdct_6x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
{
INT32 tmp0, tmp1, tmp2;
INT32 tmp10, tmp11, tmp12;
DCTELEM *dataptr;
JSAMPROW elemptr;
int ctr;
SHIFT_TEMPS
/* Pre-zero output coefficient block. */
MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
/* Pass 1: process rows. */
/* Note results are scaled up by sqrt(8) compared to a true DCT; */
/* furthermore, we scale the results by 2**PASS1_BITS. */
/* cK represents sqrt(2) * cos(K*pi/12). */
dataptr = data;
for (ctr = 0; ctr < 6; ctr++) {
elemptr = sample_data[ctr] + start_col;
/* Even part */
tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);
tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);
tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);
tmp10 = tmp0 + tmp2;
tmp12 = tmp0 - tmp2;
tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);
tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);
tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);
/* Apply unsigned->signed conversion */
dataptr[0] = (DCTELEM)
((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << PASS1_BITS);
dataptr[2] = (DCTELEM)
DESCALE(MULTIPLY(tmp12, FIX(1.224744871)), /* c2 */
CONST_BITS-PASS1_BITS);
dataptr[4] = (DCTELEM)
DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */
CONST_BITS-PASS1_BITS);
/* Odd part */
tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)), /* c5 */
CONST_BITS-PASS1_BITS);
dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << PASS1_BITS));
dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << PASS1_BITS);
dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << PASS1_BITS));
dataptr += DCTSIZE; /* advance pointer to next row */
}
/* Pass 2: process columns.
* We remove the PASS1_BITS scaling, but leave the results scaled up
* by an overall factor of 8.
* We must also scale the output by (8/6)**2 = 16/9, which we fold
* into the constant multipliers:
* cK now represents sqrt(2) * cos(K*pi/12) * 16/9.
*/
dataptr = data;
for (ctr = 0; ctr < 6; ctr++) {
/* Even part */
tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];
tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];
tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];
tmp10 = tmp0 + tmp2;
tmp12 = tmp0 - tmp2;
tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];
tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];
tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];
dataptr[DCTSIZE*0] = (DCTELEM)
DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)), /* 16/9 */
CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*2] = (DCTELEM)
DESCALE(MULTIPLY(tmp12, FIX(2.177324216)), /* c2 */
CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*4] = (DCTELEM)
DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */
CONST_BITS+PASS1_BITS);
/* Odd part */
tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829)); /* c5 */
dataptr[DCTSIZE*1] = (DCTELEM)
DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)), /* 16/9 */
CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*3] = (DCTELEM)
DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)), /* 16/9 */
CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*5] = (DCTELEM)
DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)), /* 16/9 */
CONST_BITS+PASS1_BITS);
dataptr++; /* advance pointer to next column */
}
}
/*
* Perform the forward DCT on a 5x5 sample block.
*/
GLOBAL(void)
jpeg_fdct_5x5 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
{
INT32 tmp0, tmp1, tmp2;
INT32 tmp10, tmp11;
DCTELEM *dataptr;
JSAMPROW elemptr;
int ctr;
SHIFT_TEMPS
/* Pre-zero output coefficient block. */
MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
/* Pass 1: process rows. */
/* Note results are scaled up by sqrt(8) compared to a true DCT; */
/* furthermore, we scale the results by 2**PASS1_BITS. */
/* We scale the results further by 2 as part of output adaption */
/* scaling for different DCT size. */
/* cK represents sqrt(2) * cos(K*pi/10). */
dataptr = data;
for (ctr = 0; ctr < 5; ctr++) {
elemptr = sample_data[ctr] + start_col;
/* Even part */
tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[4]);
tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[3]);
tmp2 = GETJSAMPLE(elemptr[2]);
tmp10 = tmp0 + tmp1;
tmp11 = tmp0 - tmp1;
tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[4]);
tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[3]);
/* Apply unsigned->signed conversion */
dataptr[0] = (DCTELEM)
((tmp10 + tmp2 - 5 * CENTERJSAMPLE) << (PASS1_BITS+1));
tmp11 = MULTIPLY(tmp11, FIX(0.790569415)); /* (c2+c4)/2 */
tmp10 -= tmp2 << 2;
tmp10 = MULTIPLY(tmp10, FIX(0.353553391)); /* (c2-c4)/2 */
dataptr[2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS-PASS1_BITS-1);
dataptr[4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS-PASS1_BITS-1);
/* Odd part */
tmp10 = MULTIPLY(tmp0 + tmp1, FIX(0.831253876)); /* c3 */
dataptr[1] = (DCTELEM)
DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.513743148)), /* c1-c3 */
CONST_BITS-PASS1_BITS-1);
dataptr[3] = (DCTELEM)
DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.176250899)), /* c1+c3 */
CONST_BITS-PASS1_BITS-1);
dataptr += DCTSIZE; /* advance pointer to next row */
}
/* Pass 2: process columns.
* We remove the PASS1_BITS scaling, but leave the results scaled up
* by an overall factor of 8.
* We must also scale the output by (8/5)**2 = 64/25, which we partially
* fold into the constant multipliers (other part was done in pass 1):
* cK now represents sqrt(2) * cos(K*pi/10) * 32/25.
*/
dataptr = data;
for (ctr = 0; ctr < 5; ctr++) {
/* Even part */
tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*4];
tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*3];
tmp2 = dataptr[DCTSIZE*2];
tmp10 = tmp0 + tmp1;
tmp11 = tmp0 - tmp1;
tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*4];
tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*3];
dataptr[DCTSIZE*0] = (DCTELEM)
DESCALE(MULTIPLY(tmp10 + tmp2, FIX(1.28)), /* 32/25 */
CONST_BITS+PASS1_BITS);
tmp11 = MULTIPLY(tmp11, FIX(1.011928851)); /* (c2+c4)/2 */
tmp10 -= tmp2 << 2;
tmp10 = MULTIPLY(tmp10, FIX(0.452548340)); /* (c2-c4)/2 */
dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS+PASS1_BITS);
/* Odd part */
tmp10 = MULTIPLY(tmp0 + tmp1, FIX(1.064004961)); /* c3 */
dataptr[DCTSIZE*1] = (DCTELEM)
DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.657591230)), /* c1-c3 */
CONST_BITS+PASS1_BITS);
dataptr[DCTSIZE*3] = (DCTELEM)
DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.785601151)), /* c1+c3 */
CONST_BITS+PASS1_BITS);
dataptr++; /* advance pointer to next column */
}
}
/*
* Perform the forward DCT on a 4x4 sample block.
*/
GLOBAL(void)
jpeg_fdct_4x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)
{
INT32 tmp0, tmp1;
INT32 tmp10, tmp11;
DCTELEM *dataptr;
JSAMPROW elemptr;
int ctr;
SHIFT_TEMPS
/* Pre-zero output coefficient block. */
MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);
/* Pass 1: process rows. */
/* Note results are scaled up by sqrt(8) compared to a true DCT; */
/* furthermore, we scale the results by 2**PASS1_BITS. */
/* We must also scale the output by (8/4)**2 = 2**2, which we add here. */
/* cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT]. */
dataptr = data;
for (ctr = 0; ctr < 4; ctr++) {
elemptr = sample_data[ctr] + start_col;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -