X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fjrevdct.c;h=e6846a1d788fc18bba74a0f147162d5167c34544;hb=ea1136baafb1fe271cb56c3f4d7bff0267e3c70f;hp=395eb8c6388918f9c21c772c38429aa3e41525d9;hpb=c8e1b2fbc93eaf102994865d730691f5f16f4129;p=ffmpeg diff --git a/libavcodec/jrevdct.c b/libavcodec/jrevdct.c index 395eb8c6388..e6846a1d788 100644 --- a/libavcodec/jrevdct.c +++ b/libavcodec/jrevdct.c @@ -63,7 +63,7 @@ */ #include "libavutil/common.h" -#include "dsputil.h" +#include "dct.h" #define EIGHT_BIT_SAMPLES @@ -74,7 +74,7 @@ #define RIGHT_SHIFT(x, n) ((x) >> (n)) -typedef DCTELEM DCTBLOCK[DCTSIZE2]; +typedef int16_t DCTBLOCK[DCTSIZE2]; #define CONST_BITS 13 @@ -213,7 +213,7 @@ void ff_j_rev_dct(DCTBLOCK data) int32_t tmp10, tmp11, tmp12, tmp13; int32_t z1, z2, z3, z4, z5; int32_t d0, d1, d2, d3, d4, d5, d6, d7; - register DCTELEM *dataptr; + register int16_t *dataptr; int rowctr; /* Pass 1: process rows. */ @@ -249,7 +249,7 @@ void ff_j_rev_dct(DCTBLOCK data) /* AC terms all zero */ if (d0) { /* Compute a 32 bit value to assign. */ - DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS); + int16_t dcval = (int16_t) (d0 << PASS1_BITS); register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000); idataptr[0] = v; @@ -574,14 +574,14 @@ void ff_j_rev_dct(DCTBLOCK data) } /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataptr[0] = (DCTELEM) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); - dataptr[7] = (DCTELEM) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); - dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); - dataptr[6] = (DCTELEM) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); - dataptr[2] = (DCTELEM) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); - dataptr[5] = (DCTELEM) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); - dataptr[3] = (DCTELEM) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); - dataptr[4] = (DCTELEM) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); + dataptr[0] = (int16_t) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS); + dataptr[7] = (int16_t) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS); + dataptr[1] = (int16_t) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS); + dataptr[6] = (int16_t) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS); + dataptr[2] = (int16_t) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS); + dataptr[5] = (int16_t) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS); + dataptr[3] = (int16_t) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS); + dataptr[4] = (int16_t) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS); dataptr += DCTSIZE; /* advance pointer to next row */ } @@ -920,236 +920,23 @@ void ff_j_rev_dct(DCTBLOCK data) /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp3, + dataptr[DCTSIZE*0] = (int16_t) DESCALE(tmp10 + tmp3, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp10 - tmp3, + dataptr[DCTSIZE*7] = (int16_t) DESCALE(tmp10 - tmp3, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp11 + tmp2, + dataptr[DCTSIZE*1] = (int16_t) DESCALE(tmp11 + tmp2, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(tmp11 - tmp2, + dataptr[DCTSIZE*6] = (int16_t) DESCALE(tmp11 - tmp2, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp12 + tmp1, + dataptr[DCTSIZE*2] = (int16_t) DESCALE(tmp12 + tmp1, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12 - tmp1, + dataptr[DCTSIZE*5] = (int16_t) DESCALE(tmp12 - tmp1, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp13 + tmp0, + dataptr[DCTSIZE*3] = (int16_t) DESCALE(tmp13 + tmp0, CONST_BITS+PASS1_BITS+3); - dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp13 - tmp0, + dataptr[DCTSIZE*4] = (int16_t) DESCALE(tmp13 - tmp0, CONST_BITS+PASS1_BITS+3); dataptr++; /* advance pointer to next column */ } } - -#undef DCTSIZE -#define DCTSIZE 4 -#define DCTSTRIDE 8 - -void ff_j_rev_dct4(DCTBLOCK data) -{ - int32_t tmp0, tmp1, tmp2, tmp3; - int32_t tmp10, tmp11, tmp12, tmp13; - int32_t z1; - int32_t d0, d2, d4, d6; - register DCTELEM *dataptr; - int rowctr; - - /* Pass 1: process rows. */ - /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ - /* furthermore, we scale the results by 2**PASS1_BITS. */ - - data[0] += 4; - - dataptr = data; - - for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { - /* Due to quantization, we will usually find that many of the input - * coefficients are zero, especially the AC terms. We can exploit this - * by short-circuiting the IDCT calculation for any row in which all - * the AC terms are zero. In that case each output is equal to the - * DC coefficient (with scale factor as needed). - * With typical images and quantization tables, half or more of the - * row DCT calculations can be simplified this way. - */ - - register int *idataptr = (int*)dataptr; - - d0 = dataptr[0]; - d2 = dataptr[1]; - d4 = dataptr[2]; - d6 = dataptr[3]; - - if ((d2 | d4 | d6) == 0) { - /* AC terms all zero */ - if (d0) { - /* Compute a 32 bit value to assign. */ - DCTELEM dcval = (DCTELEM) (d0 << PASS1_BITS); - register int v = (dcval & 0xffff) | ((dcval << 16) & 0xffff0000); - - idataptr[0] = v; - idataptr[1] = v; - } - - dataptr += DCTSTRIDE; /* advance pointer to next row */ - continue; - } - - /* Even part: reverse the even part of the forward DCT. */ - /* The rotator is sqrt(2)*c(-6). */ - if (d6) { - if (d2) { - /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */ - z1 = MULTIPLY(d2 + d6, FIX_0_541196100); - tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065); - tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865); - - tmp0 = (d0 + d4) << CONST_BITS; - tmp1 = (d0 - d4) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - } else { - /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */ - tmp2 = MULTIPLY(-d6, FIX_1_306562965); - tmp3 = MULTIPLY(d6, FIX_0_541196100); - - tmp0 = (d0 + d4) << CONST_BITS; - tmp1 = (d0 - d4) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - } - } else { - if (d2) { - /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */ - tmp2 = MULTIPLY(d2, FIX_0_541196100); - tmp3 = MULTIPLY(d2, FIX_1_306562965); - - tmp0 = (d0 + d4) << CONST_BITS; - tmp1 = (d0 - d4) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - } else { - /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */ - tmp10 = tmp13 = (d0 + d4) << CONST_BITS; - tmp11 = tmp12 = (d0 - d4) << CONST_BITS; - } - } - - /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - - dataptr[0] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS); - dataptr[1] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS); - dataptr[2] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS); - dataptr[3] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS); - - dataptr += DCTSTRIDE; /* advance pointer to next row */ - } - - /* Pass 2: process columns. */ - /* Note that we must descale the results by a factor of 8 == 2**3, */ - /* and also undo the PASS1_BITS scaling. */ - - dataptr = data; - for (rowctr = DCTSIZE-1; rowctr >= 0; rowctr--) { - /* Columns of zeroes can be exploited in the same way as we did with rows. - * However, the row calculation has created many nonzero AC terms, so the - * simplification applies less often (typically 5% to 10% of the time). - * On machines with very fast multiplication, it's possible that the - * test takes more time than it's worth. In that case this section - * may be commented out. - */ - - d0 = dataptr[DCTSTRIDE*0]; - d2 = dataptr[DCTSTRIDE*1]; - d4 = dataptr[DCTSTRIDE*2]; - d6 = dataptr[DCTSTRIDE*3]; - - /* Even part: reverse the even part of the forward DCT. */ - /* The rotator is sqrt(2)*c(-6). */ - if (d6) { - if (d2) { - /* d0 != 0, d2 != 0, d4 != 0, d6 != 0 */ - z1 = MULTIPLY(d2 + d6, FIX_0_541196100); - tmp2 = z1 + MULTIPLY(-d6, FIX_1_847759065); - tmp3 = z1 + MULTIPLY(d2, FIX_0_765366865); - - tmp0 = (d0 + d4) << CONST_BITS; - tmp1 = (d0 - d4) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - } else { - /* d0 != 0, d2 == 0, d4 != 0, d6 != 0 */ - tmp2 = MULTIPLY(-d6, FIX_1_306562965); - tmp3 = MULTIPLY(d6, FIX_0_541196100); - - tmp0 = (d0 + d4) << CONST_BITS; - tmp1 = (d0 - d4) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - } - } else { - if (d2) { - /* d0 != 0, d2 != 0, d4 != 0, d6 == 0 */ - tmp2 = MULTIPLY(d2, FIX_0_541196100); - tmp3 = MULTIPLY(d2, FIX_1_306562965); - - tmp0 = (d0 + d4) << CONST_BITS; - tmp1 = (d0 - d4) << CONST_BITS; - - tmp10 = tmp0 + tmp3; - tmp13 = tmp0 - tmp3; - tmp11 = tmp1 + tmp2; - tmp12 = tmp1 - tmp2; - } else { - /* d0 != 0, d2 == 0, d4 != 0, d6 == 0 */ - tmp10 = tmp13 = (d0 + d4) << CONST_BITS; - tmp11 = tmp12 = (d0 - d4) << CONST_BITS; - } - } - - /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */ - - dataptr[DCTSTRIDE*0] = tmp10 >> (CONST_BITS+PASS1_BITS+3); - dataptr[DCTSTRIDE*1] = tmp11 >> (CONST_BITS+PASS1_BITS+3); - dataptr[DCTSTRIDE*2] = tmp12 >> (CONST_BITS+PASS1_BITS+3); - dataptr[DCTSTRIDE*3] = tmp13 >> (CONST_BITS+PASS1_BITS+3); - - dataptr++; /* advance pointer to next column */ - } -} - -void ff_j_rev_dct2(DCTBLOCK data){ - int d00, d01, d10, d11; - - data[0] += 4; - d00 = data[0+0*DCTSTRIDE] + data[1+0*DCTSTRIDE]; - d01 = data[0+0*DCTSTRIDE] - data[1+0*DCTSTRIDE]; - d10 = data[0+1*DCTSTRIDE] + data[1+1*DCTSTRIDE]; - d11 = data[0+1*DCTSTRIDE] - data[1+1*DCTSTRIDE]; - - data[0+0*DCTSTRIDE]= (d00 + d10)>>3; - data[1+0*DCTSTRIDE]= (d01 + d11)>>3; - data[0+1*DCTSTRIDE]= (d00 - d10)>>3; - data[1+1*DCTSTRIDE]= (d01 - d11)>>3; -} - -void ff_j_rev_dct1(DCTBLOCK data){ - data[0] = (data[0] + 4)>>3; -} - -#undef FIX -#undef CONST_BITS