diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2014-09-03 03:55:23 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2014-09-03 04:09:38 +0200 |
commit | 5b58d79a99658200ee5562999b16b5a8fa729b22 (patch) | |
tree | bd10ed2708d7485f5156c4e67f8325bcff5bd999 /libavcodec | |
parent | 5db23c07a3f76d31e8e3178f8bacb68289bba62b (diff) | |
parent | 7a1d6ddd2c6b2d66fbc1afa584cf506930a26453 (diff) | |
download | ffmpeg-5b58d79a99658200ee5562999b16b5a8fa729b22.tar.gz |
Merge commit '7a1d6ddd2c6b2d66fbc1afa584cf506930a26453'
* commit '7a1d6ddd2c6b2d66fbc1afa584cf506930a26453':
xvid: Add C IDCT
Conflicts:
libavcodec/dct-test.c
libavcodec/xvididct.c
See: 298b3b6c1f8f66b9bc6de53a7b51d3de745d946b
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/Makefile | 2 | ||||
-rw-r--r-- | libavcodec/dct-test.c | 4 | ||||
-rw-r--r-- | libavcodec/x86/xvididct_init.c | 8 | ||||
-rw-r--r-- | libavcodec/xvid_c_idct.c | 330 | ||||
-rw-r--r-- | libavcodec/xvididct.c | 312 | ||||
-rw-r--r-- | libavcodec/xvididct.h | 9 |
6 files changed, 322 insertions, 343 deletions
diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 8173449c21..b0ce0a6249 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -325,7 +325,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpeg12.o OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpeg12.o -OBJS-$(CONFIG_MPEG4_DECODER) += xvididct.o xvid_c_idct.o +OBJS-$(CONFIG_MPEG4_DECODER) += xvididct.o OBJS-$(CONFIG_MPL2_DECODER) += mpl2dec.o ass.o OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4dec.o msmpeg4.o msmpeg4data.o OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4dec.o msmpeg4.o msmpeg4data.o diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c index bc6b07744a..f4f8abd309 100644 --- a/libavcodec/dct-test.c +++ b/libavcodec/dct-test.c @@ -42,6 +42,7 @@ #include "dct.h" #include "idctdsp.h" #include "simple_idct.h" +#include "xvididct.h" #include "aandcttab.h" #include "faandct.h" #include "faanidct.h" @@ -81,6 +82,9 @@ static const struct algo idct_tab[] = { { "INT", ff_j_rev_dct, FF_IDCT_PERM_LIBMPEG2 }, { "SIMPLE-C", ff_simple_idct_8, FF_IDCT_PERM_NONE }, { "PR-C", ff_prores_idct_wrap, FF_IDCT_PERM_NONE, 0, 1 }, +#if CONFIG_MPEG4_DECODER + { "XVID", ff_xvid_idct, FF_IDCT_PERM_NONE, 0, 1 }, +#endif /* CONFIG_MPEG4_DECODER */ }; #if ARCH_ARM diff --git a/libavcodec/x86/xvididct_init.c b/libavcodec/x86/xvididct_init.c index be0f700766..8c227844b5 100644 --- a/libavcodec/x86/xvididct_init.c +++ b/libavcodec/x86/xvididct_init.c @@ -26,10 +26,16 @@ #include "idctdsp.h" #include "xvididct.h" -av_cold void ff_xvid_idct_init_x86(IDCTDSPContext *c) +av_cold void ff_xvid_idct_init_x86(IDCTDSPContext *c, AVCodecContext *avctx, + unsigned high_bit_depth) { int cpu_flags = av_get_cpu_flags(); + if (high_bit_depth || + !(avctx->idct_algo == FF_IDCT_AUTO || + avctx->idct_algo == FF_IDCT_XVID)) + return; + if (INLINE_MMX(cpu_flags)) { c->idct_put = ff_xvid_idct_mmx_put; c->idct_add = ff_xvid_idct_mmx_add; diff --git a/libavcodec/xvid_c_idct.c b/libavcodec/xvid_c_idct.c deleted file mode 100644 index a2a5b9c693..0000000000 --- a/libavcodec/xvid_c_idct.c +++ /dev/null @@ -1,330 +0,0 @@ -/***************************************************************************** - * - * XVID MPEG-4 VIDEO CODEC - * - Inverse DCT - - * - * Copyright (C) 2006-2011 Xvid Solutions GmbH - * - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * - ****************************************************************************/ - -/** - * @file - * Walken IDCT - * Alternative idct implementations for decoding compatibility - * - * @author Skal - * @note this "C" version is not the original one, but is modified to - * yield the same error profile as the MMX version. - */ - - -#include "xvididct.h" - - -#define ROW_SHIFT 11 -#define COL_SHIFT 6 - -// #define FIX(x) (int)((x) * (1<<ROW_SHIFT)) -#define Rnd0 65536 // 1<<(COL_SHIFT+ROW_SHIFT-1); -#define Rnd1 3597 // FIX (1.75683487303); -#define Rnd2 2260 // FIX (1.10355339059); -#define Rnd3 1203 // FIX (0.587788325588); -#define Rnd4 0 -#define Rnd5 120 // FIX (0.058658283817); -#define Rnd6 512 // FIX (0.25); -#define Rnd7 512 // FIX (0.25); - -static const int Tab04[] = { 22725, 21407, 19266, 16384, 12873, 8867, 4520 }; -static const int Tab17[] = { 31521, 29692, 26722, 22725, 17855, 12299, 6270 }; -static const int Tab26[] = { 29692, 27969, 25172, 21407, 16819, 11585, 5906 }; -static const int Tab35[] = { 26722, 25172, 22654, 19266, 15137, 10426, 5315 }; - -static int Idct_Row(short * In, const int * const Tab, int Rnd) -{ - const int C1 = Tab[0]; - const int C2 = Tab[1]; - const int C3 = Tab[2]; - const int C4 = Tab[3]; - const int C5 = Tab[4]; - const int C6 = Tab[5]; - const int C7 = Tab[6]; - - const int Right = In[5]|In[6]|In[7]; - const int Left = In[1]|In[2]|In[3]; - if (!(Right | In[4])) - { - const int K = C4*In[0] + Rnd; - if (Left) - { - const int a0 = K + C2*In[2]; - const int a1 = K + C6*In[2]; - const int a2 = K - C6*In[2]; - const int a3 = K - C2*In[2]; - - const int b0 = C1*In[1] + C3*In[3]; - const int b1 = C3*In[1] - C7*In[3]; - const int b2 = C5*In[1] - C1*In[3]; - const int b3 = C7*In[1] - C5*In[3]; - - In[0] = (a0 + b0) >> ROW_SHIFT; - In[1] = (a1 + b1) >> ROW_SHIFT; - In[2] = (a2 + b2) >> ROW_SHIFT; - In[3] = (a3 + b3) >> ROW_SHIFT; - In[4] = (a3 - b3) >> ROW_SHIFT; - In[5] = (a2 - b2) >> ROW_SHIFT; - In[6] = (a1 - b1) >> ROW_SHIFT; - In[7] = (a0 - b0) >> ROW_SHIFT; - } - else - { - const int a0 = K >> ROW_SHIFT; - if (a0) { - In[0] = In[1] = In[2] = In[3] = - In[4] = In[5] = In[6] = In[7] = a0; - } - else return 0; - } - } - else if (!(Left|Right)) - { - const int a0 = (Rnd + C4*(In[0]+In[4])) >> ROW_SHIFT; - const int a1 = (Rnd + C4*(In[0]-In[4])) >> ROW_SHIFT; - - In[0] = a0; - In[3] = a0; - In[4] = a0; - In[7] = a0; - In[1] = a1; - In[2] = a1; - In[5] = a1; - In[6] = a1; - } - else - { - const int K = C4*In[0] + Rnd; - const int a0 = K + C2*In[2] + C4*In[4] + C6*In[6]; - const int a1 = K + C6*In[2] - C4*In[4] - C2*In[6]; - const int a2 = K - C6*In[2] - C4*In[4] + C2*In[6]; - const int a3 = K - C2*In[2] + C4*In[4] - C6*In[6]; - - const int b0 = C1*In[1] + C3*In[3] + C5*In[5] + C7*In[7]; - const int b1 = C3*In[1] - C7*In[3] - C1*In[5] - C5*In[7]; - const int b2 = C5*In[1] - C1*In[3] + C7*In[5] + C3*In[7]; - const int b3 = C7*In[1] - C5*In[3] + C3*In[5] - C1*In[7]; - - In[0] = (a0 + b0) >> ROW_SHIFT; - In[1] = (a1 + b1) >> ROW_SHIFT; - In[2] = (a2 + b2) >> ROW_SHIFT; - In[3] = (a3 + b3) >> ROW_SHIFT; - In[4] = (a3 - b3) >> ROW_SHIFT; - In[5] = (a2 - b2) >> ROW_SHIFT; - In[6] = (a1 - b1) >> ROW_SHIFT; - In[7] = (a0 - b0) >> ROW_SHIFT; - } - return 1; -} - -#define Tan1 0x32ec -#define Tan2 0x6a0a -#define Tan3 0xab0e -#define Sqrt2 0x5a82 - -#define MULT(c,x, n) ( ((c) * (x)) >> (n) ) -// 12b version => #define MULT(c,x, n) ( (((c)>>3) * (x)) >> ((n)-3) ) -// 12b zero-testing version: - -#define BUTF(a, b, tmp) \ - (tmp) = (a)+(b); \ - (b) = (a)-(b); \ - (a) = (tmp) - -#define LOAD_BUTF(m1, m2, a, b, tmp, S) \ - (m1) = (S)[(a)] + (S)[(b)]; \ - (m2) = (S)[(a)] - (S)[(b)] - -static void Idct_Col_8(short * const In) -{ - int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, Spill; - - // odd - - mm4 = (int)In[7*8]; - mm5 = (int)In[5*8]; - mm6 = (int)In[3*8]; - mm7 = (int)In[1*8]; - - mm0 = MULT(Tan1, mm4, 16) + mm7; - mm1 = MULT(Tan1, mm7, 16) - mm4; - mm2 = MULT(Tan3, mm5, 16) + mm6; - mm3 = MULT(Tan3, mm6, 16) - mm5; - - mm7 = mm0 + mm2; - mm4 = mm1 - mm3; - mm0 = mm0 - mm2; - mm1 = mm1 + mm3; - mm6 = mm0 + mm1; - mm5 = mm0 - mm1; - mm5 = 2*MULT(Sqrt2, mm5, 16); // 2*sqrt2 - mm6 = 2*MULT(Sqrt2, mm6, 16); // Watch out: precision loss but done to match - // the pmulhw used in mmx/sse versions - - // even - - mm1 = (int)In[2*8]; - mm2 = (int)In[6*8]; - mm3 = MULT(Tan2,mm2, 16) + mm1; - mm2 = MULT(Tan2,mm1, 16) - mm2; - - LOAD_BUTF(mm0, mm1, 0*8, 4*8, Spill, In); - - BUTF(mm0, mm3, Spill); - BUTF(mm0, mm7, Spill); - In[8*0] = (int16_t) (mm0 >> COL_SHIFT); - In[8*7] = (int16_t) (mm7 >> COL_SHIFT); - BUTF(mm3, mm4, mm0); - In[8*3] = (int16_t) (mm3 >> COL_SHIFT); - In[8*4] = (int16_t) (mm4 >> COL_SHIFT); - - BUTF(mm1, mm2, mm0); - BUTF(mm1, mm6, mm0); - In[8*1] = (int16_t) (mm1 >> COL_SHIFT); - In[8*6] = (int16_t) (mm6 >> COL_SHIFT); - BUTF(mm2, mm5, mm0); - In[8*2] = (int16_t) (mm2 >> COL_SHIFT); - In[8*5] = (int16_t) (mm5 >> COL_SHIFT); -} - -static void Idct_Col_4(short * const In) -{ - int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, Spill; - - // odd - - mm0 = (int)In[1*8]; - mm2 = (int)In[3*8]; - - mm1 = MULT(Tan1, mm0, 16); - mm3 = MULT(Tan3, mm2, 16); - - mm7 = mm0 + mm2; - mm4 = mm1 - mm3; - mm0 = mm0 - mm2; - mm1 = mm1 + mm3; - mm6 = mm0 + mm1; - mm5 = mm0 - mm1; - mm6 = 2*MULT(Sqrt2, mm6, 16); // 2*sqrt2 - mm5 = 2*MULT(Sqrt2, mm5, 16); - - // even - - mm0 = mm1 = (int)In[0*8]; - mm3 = (int)In[2*8]; - mm2 = MULT(Tan2,mm3, 16); - - BUTF(mm0, mm3, Spill); - BUTF(mm0, mm7, Spill); - In[8*0] = (int16_t) (mm0 >> COL_SHIFT); - In[8*7] = (int16_t) (mm7 >> COL_SHIFT); - BUTF(mm3, mm4, mm0); - In[8*3] = (int16_t) (mm3 >> COL_SHIFT); - In[8*4] = (int16_t) (mm4 >> COL_SHIFT); - - BUTF(mm1, mm2, mm0); - BUTF(mm1, mm6, mm0); - In[8*1] = (int16_t) (mm1 >> COL_SHIFT); - In[8*6] = (int16_t) (mm6 >> COL_SHIFT); - BUTF(mm2, mm5, mm0); - In[8*2] = (int16_t) (mm2 >> COL_SHIFT); - In[8*5] = (int16_t) (mm5 >> COL_SHIFT); -} - -static void Idct_Col_3(short * const In) -{ - int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, Spill; - - // odd - - mm7 = (int)In[1*8]; - mm4 = MULT(Tan1, mm7, 16); - - mm6 = mm7 + mm4; - mm5 = mm7 - mm4; - mm6 = 2*MULT(Sqrt2, mm6, 16); // 2*sqrt2 - mm5 = 2*MULT(Sqrt2, mm5, 16); - - // even - - mm0 = mm1 = (int)In[0*8]; - mm3 = (int)In[2*8]; - mm2 = MULT(Tan2,mm3, 16); - - BUTF(mm0, mm3, Spill); - BUTF(mm0, mm7, Spill); - In[8*0] = (int16_t) (mm0 >> COL_SHIFT); - In[8*7] = (int16_t) (mm7 >> COL_SHIFT); - BUTF(mm3, mm4, mm0); - In[8*3] = (int16_t) (mm3 >> COL_SHIFT); - In[8*4] = (int16_t) (mm4 >> COL_SHIFT); - - BUTF(mm1, mm2, mm0); - BUTF(mm1, mm6, mm0); - In[8*1] = (int16_t) (mm1 >> COL_SHIFT); - In[8*6] = (int16_t) (mm6 >> COL_SHIFT); - BUTF(mm2, mm5, mm0); - In[8*2] = (int16_t) (mm2 >> COL_SHIFT); - In[8*5] = (int16_t) (mm5 >> COL_SHIFT); -} - -#undef Tan1 -#undef Tan2 -#undef Tan3 -#undef Sqrt2 - -#undef ROW_SHIFT -#undef COL_SHIFT - -////////////////////////////////////////////////////////// - -void ff_idct_xvid(int16_t *const In) -{ - int i, Rows = 0x07; - - Idct_Row(In + 0*8, Tab04, Rnd0); - Idct_Row(In + 1*8, Tab17, Rnd1); - Idct_Row(In + 2*8, Tab26, Rnd2); - if (Idct_Row(In + 3*8, Tab35, Rnd3)) Rows |= 0x08; - if (Idct_Row(In + 4*8, Tab04, Rnd4)) Rows |= 0x10; - if (Idct_Row(In + 5*8, Tab35, Rnd5)) Rows |= 0x20; - if (Idct_Row(In + 6*8, Tab26, Rnd6)) Rows |= 0x40; - if (Idct_Row(In + 7*8, Tab17, Rnd7)) Rows |= 0x80; - - if (Rows&0xf0) { - for(i=0; i<8; i++) - Idct_Col_8(In + i); - } - else if (Rows&0x08) { - for(i=0; i<8; i++) - Idct_Col_4(In + i); - } - else { - for(i=0; i<8; i++) - Idct_Col_3(In + i); - } -} diff --git a/libavcodec/xvididct.c b/libavcodec/xvididct.c index 9f3dab805c..e9fab70cbb 100644 --- a/libavcodec/xvididct.c +++ b/libavcodec/xvididct.c @@ -1,4 +1,8 @@ /* + * Xvid MPEG-4 IDCT + * + * Copyright (C) 2006-2011 Xvid Solutions GmbH + * * This file is part of FFmpeg. * * FFmpeg is free software; you can redistribute it and/or @@ -16,21 +20,313 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/** + * @file + * Walken IDCT + * Alternative IDCT implementation for decoding compatibility. + * + * @author Skal + * @note This C version is not the original IDCT, but a modified one that + * yields the same error profile as the MMX/MMXEXT/SSE2 versions. + */ + #include "config.h" #include "libavutil/attributes.h" #include "avcodec.h" #include "idctdsp.h" #include "xvididct.h" -static void idct_xvid_put(uint8_t *dest, int line_size, int16_t *block) +#define ROW_SHIFT 11 +#define COL_SHIFT 6 + +// #define FIX(x) (int)((x) * (1 << ROW_SHIFT)) +#define RND0 65536 // 1 << (COL_SHIFT + ROW_SHIFT - 1); +#define RND1 3597 // FIX (1.75683487303); +#define RND2 2260 // FIX (1.10355339059); +#define RND3 1203 // FIX (0.587788325588); +#define RND4 0 +#define RND5 120 // FIX (0.058658283817); +#define RND6 512 // FIX (0.25); +#define RND7 512 // FIX (0.25); + +static const int TAB04[] = { 22725, 21407, 19266, 16384, 12873, 8867, 4520 }; +static const int TAB17[] = { 31521, 29692, 26722, 22725, 17855, 12299, 6270 }; +static const int TAB26[] = { 29692, 27969, 25172, 21407, 16819, 11585, 5906 }; +static const int TAB35[] = { 26722, 25172, 22654, 19266, 15137, 10426, 5315 }; + +static int idct_row(short *in, const int *const tab, int rnd) +{ + const int c1 = tab[0]; + const int c2 = tab[1]; + const int c3 = tab[2]; + const int c4 = tab[3]; + const int c5 = tab[4]; + const int c6 = tab[5]; + const int c7 = tab[6]; + + const int right = in[5] | in[6] | in[7]; + const int left = in[1] | in[2] | in[3]; + if (!(right | in[4])) { + const int k = c4 * in[0] + rnd; + if (left) { + const int a0 = k + c2 * in[2]; + const int a1 = k + c6 * in[2]; + const int a2 = k - c6 * in[2]; + const int a3 = k - c2 * in[2]; + + const int b0 = c1 * in[1] + c3 * in[3]; + const int b1 = c3 * in[1] - c7 * in[3]; + const int b2 = c5 * in[1] - c1 * in[3]; + const int b3 = c7 * in[1] - c5 * in[3]; + + in[0] = (a0 + b0) >> ROW_SHIFT; + in[1] = (a1 + b1) >> ROW_SHIFT; + in[2] = (a2 + b2) >> ROW_SHIFT; + in[3] = (a3 + b3) >> ROW_SHIFT; + in[4] = (a3 - b3) >> ROW_SHIFT; + in[5] = (a2 - b2) >> ROW_SHIFT; + in[6] = (a1 - b1) >> ROW_SHIFT; + in[7] = (a0 - b0) >> ROW_SHIFT; + } else { + const int a0 = k >> ROW_SHIFT; + if (a0) { + in[0] = + in[1] = + in[2] = + in[3] = + in[4] = + in[5] = + in[6] = + in[7] = a0; + } else + return 0; + } + } else if (!(left | right)) { + const int a0 = (rnd + c4 * (in[0] + in[4])) >> ROW_SHIFT; + const int a1 = (rnd + c4 * (in[0] - in[4])) >> ROW_SHIFT; + + in[0] = a0; + in[3] = a0; + in[4] = a0; + in[7] = a0; + in[1] = a1; + in[2] = a1; + in[5] = a1; + in[6] = a1; + } else { + const int k = c4 * in[0] + rnd; + const int a0 = k + c2 * in[2] + c4 * in[4] + c6 * in[6]; + const int a1 = k + c6 * in[2] - c4 * in[4] - c2 * in[6]; + const int a2 = k - c6 * in[2] - c4 * in[4] + c2 * in[6]; + const int a3 = k - c2 * in[2] + c4 * in[4] - c6 * in[6]; + + const int b0 = c1 * in[1] + c3 * in[3] + c5 * in[5] + c7 * in[7]; + const int b1 = c3 * in[1] - c7 * in[3] - c1 * in[5] - c5 * in[7]; + const int b2 = c5 * in[1] - c1 * in[3] + c7 * in[5] + c3 * in[7]; + const int b3 = c7 * in[1] - c5 * in[3] + c3 * in[5] - c1 * in[7]; + + in[0] = (a0 + b0) >> ROW_SHIFT; + in[1] = (a1 + b1) >> ROW_SHIFT; + in[2] = (a2 + b2) >> ROW_SHIFT; + in[3] = (a3 + b3) >> ROW_SHIFT; + in[4] = (a3 - b3) >> ROW_SHIFT; + in[5] = (a2 - b2) >> ROW_SHIFT; + in[6] = (a1 - b1) >> ROW_SHIFT; + in[7] = (a0 - b0) >> ROW_SHIFT; + } + return 1; +} + +#define TAN1 0x32EC +#define TAN2 0x6A0A +#define TAN3 0xAB0E +#define SQRT2 0x5A82 + +#define MULT(c, x, n) (((c) * (x)) >> (n)) +// 12b version => #define MULT(c,x, n) ((((c) >> 3) * (x)) >> ((n) - 3)) +// 12b zero-testing version: + +#define BUTTERFLY(a, b, tmp) \ + (tmp) = (a) + (b); \ + (b) = (a) - (b); \ + (a) = (tmp) + +#define LOAD_BUTTERFLY(m1, m2, a, b, tmp, s) \ + (m1) = (s)[(a)] + (s)[(b)]; \ + (m2) = (s)[(a)] - (s)[(b)] + +static void idct_col_8(short *const in) +{ + int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, spill; + + // odd + + mm4 = (int) in[7 * 8]; + mm5 = (int) in[5 * 8]; + mm6 = (int) in[3 * 8]; + mm7 = (int) in[1 * 8]; + + mm0 = MULT(TAN1, mm4, 16) + mm7; + mm1 = MULT(TAN1, mm7, 16) - mm4; + mm2 = MULT(TAN3, mm5, 16) + mm6; + mm3 = MULT(TAN3, mm6, 16) - mm5; + + mm7 = mm0 + mm2; + mm4 = mm1 - mm3; + mm0 = mm0 - mm2; + mm1 = mm1 + mm3; + mm6 = mm0 + mm1; + mm5 = mm0 - mm1; + mm5 = 2 * MULT(SQRT2, mm5, 16); // 2*sqrt2 + mm6 = 2 * MULT(SQRT2, mm6, 16); // Watch out: precision loss but done to match + // the pmulhw used in MMX/MMXEXT/SSE2 versions + + // even + + mm1 = (int) in[2 * 8]; + mm2 = (int) in[6 * 8]; + mm3 = MULT(TAN2, mm2, 16) + mm1; + mm2 = MULT(TAN2, mm1, 16) - mm2; + + LOAD_BUTTERFLY(mm0, mm1, 0 * 8, 4 * 8, spill, in); + + BUTTERFLY(mm0, mm3, spill); + BUTTERFLY(mm0, mm7, spill); + in[8 * 0] = (int16_t) (mm0 >> COL_SHIFT); + in[8 * 7] = (int16_t) (mm7 >> COL_SHIFT); + BUTTERFLY(mm3, mm4, mm0); + in[8 * 3] = (int16_t) (mm3 >> COL_SHIFT); + in[8 * 4] = (int16_t) (mm4 >> COL_SHIFT); + + BUTTERFLY(mm1, mm2, mm0); + BUTTERFLY(mm1, mm6, mm0); + in[8 * 1] = (int16_t) (mm1 >> COL_SHIFT); + in[8 * 6] = (int16_t) (mm6 >> COL_SHIFT); + BUTTERFLY(mm2, mm5, mm0); + in[8 * 2] = (int16_t) (mm2 >> COL_SHIFT); + in[8 * 5] = (int16_t) (mm5 >> COL_SHIFT); +} + +static void idct_col_4(short *const in) +{ + int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, spill; + + // odd + + mm0 = (int) in[1 * 8]; + mm2 = (int) in[3 * 8]; + + mm1 = MULT(TAN1, mm0, 16); + mm3 = MULT(TAN3, mm2, 16); + + mm7 = mm0 + mm2; + mm4 = mm1 - mm3; + mm0 = mm0 - mm2; + mm1 = mm1 + mm3; + mm6 = mm0 + mm1; + mm5 = mm0 - mm1; + mm6 = 2 * MULT(SQRT2, mm6, 16); // 2*sqrt2 + mm5 = 2 * MULT(SQRT2, mm5, 16); + + // even + + mm0 = mm1 = (int) in[0 * 8]; + mm3 = (int) in[2 * 8]; + mm2 = MULT(TAN2, mm3, 16); + + BUTTERFLY(mm0, mm3, spill); + BUTTERFLY(mm0, mm7, spill); + in[8 * 0] = (int16_t) (mm0 >> COL_SHIFT); + in[8 * 7] = (int16_t) (mm7 >> COL_SHIFT); + BUTTERFLY(mm3, mm4, mm0); + in[8 * 3] = (int16_t) (mm3 >> COL_SHIFT); + in[8 * 4] = (int16_t) (mm4 >> COL_SHIFT); + + BUTTERFLY(mm1, mm2, mm0); + BUTTERFLY(mm1, mm6, mm0); + in[8 * 1] = (int16_t) (mm1 >> COL_SHIFT); + in[8 * 6] = (int16_t) (mm6 >> COL_SHIFT); + BUTTERFLY(mm2, mm5, mm0); + in[8 * 2] = (int16_t) (mm2 >> COL_SHIFT); + in[8 * 5] = (int16_t) (mm5 >> COL_SHIFT); +} + +static void idct_col_3(short *const in) +{ + int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, spill; + + // odd + + mm7 = (int) in[1 * 8]; + mm4 = MULT(TAN1, mm7, 16); + + mm6 = mm7 + mm4; + mm5 = mm7 - mm4; + mm6 = 2 * MULT(SQRT2, mm6, 16); // 2*sqrt2 + mm5 = 2 * MULT(SQRT2, mm5, 16); + + // even + + mm0 = mm1 = (int) in[0 * 8]; + mm3 = (int) in[2 * 8]; + mm2 = MULT(TAN2, mm3, 16); + + BUTTERFLY(mm0, mm3, spill); + BUTTERFLY(mm0, mm7, spill); + in[8 * 0] = (int16_t) (mm0 >> COL_SHIFT); + in[8 * 7] = (int16_t) (mm7 >> COL_SHIFT); + BUTTERFLY(mm3, mm4, mm0); + in[8 * 3] = (int16_t) (mm3 >> COL_SHIFT); + in[8 * 4] = (int16_t) (mm4 >> COL_SHIFT); + + BUTTERFLY(mm1, mm2, mm0); + BUTTERFLY(mm1, mm6, mm0); + in[8 * 1] = (int16_t) (mm1 >> COL_SHIFT); + in[8 * 6] = (int16_t) (mm6 >> COL_SHIFT); + BUTTERFLY(mm2, mm5, mm0); + in[8 * 2] = (int16_t) (mm2 >> COL_SHIFT); + in[8 * 5] = (int16_t) (mm5 >> COL_SHIFT); +} + +void ff_xvid_idct(int16_t *const in) +{ + int i, rows = 0x07; + + idct_row(in + 0 * 8, TAB04, RND0); + idct_row(in + 1 * 8, TAB17, RND1); + idct_row(in + 2 * 8, TAB26, RND2); + if (idct_row(in + 3 * 8, TAB35, RND3)) + rows |= 0x08; + if (idct_row(in + 4 * 8, TAB04, RND4)) + rows |= 0x10; + if (idct_row(in + 5 * 8, TAB35, RND5)) + rows |= 0x20; + if (idct_row(in + 6 * 8, TAB26, RND6)) + rows |= 0x40; + if (idct_row(in + 7 * 8, TAB17, RND7)) + rows |= 0x80; + + if (rows & 0xF0) { + for (i = 0; i < 8; i++) + idct_col_8(in + i); + } else if (rows & 0x08) { + for (i = 0; i < 8; i++) + idct_col_4(in + i); + } else { + for (i = 0; i < 8; i++) + idct_col_3(in + i); + } +} + +static void xvid_idct_put(uint8_t *dest, int line_size, int16_t *block) { - ff_idct_xvid(block); + ff_xvid_idct(block); ff_put_pixels_clamped(block, dest, line_size); } -static void idct_xvid_add(uint8_t *dest, int line_size, int16_t *block) +static void xvid_idct_add(uint8_t *dest, int line_size, int16_t *block) { - ff_idct_xvid(block); + ff_xvid_idct(block); ff_add_pixels_clamped(block, dest, line_size); } @@ -44,14 +340,14 @@ av_cold void ff_xvid_idct_init(IDCTDSPContext *c, AVCodecContext *avctx) return; if (avctx->idct_algo == FF_IDCT_XVID) { - c->idct_put = idct_xvid_put; - c->idct_add = idct_xvid_add; - c->idct = ff_idct_xvid; + c->idct_put = xvid_idct_put; + c->idct_add = xvid_idct_add; + c->idct = ff_xvid_idct; c->perm_type = FF_IDCT_PERM_NONE; } if (ARCH_X86) - ff_xvid_idct_init_x86(c); + ff_xvid_idct_init_x86(c, avctx, high_bit_depth); ff_init_scantable_permutation(c->idct_permutation, c->perm_type); } diff --git a/libavcodec/xvididct.h b/libavcodec/xvididct.h index b0233c342c..f7dfba4886 100644 --- a/libavcodec/xvididct.h +++ b/libavcodec/xvididct.h @@ -19,13 +19,16 @@ #ifndef AVCODEC_XVIDIDCT_H #define AVCODEC_XVIDIDCT_H +#include <stdint.h> + #include "avcodec.h" #include "idctdsp.h" -void ff_xvid_idct_init(IDCTDSPContext *c, AVCodecContext *avctx); +void ff_xvid_idct(int16_t *const in); -void ff_xvid_idct_init_x86(IDCTDSPContext *c); +void ff_xvid_idct_init(IDCTDSPContext *c, AVCodecContext *avctx); -void ff_idct_xvid(int16_t *const In); +void ff_xvid_idct_init_x86(IDCTDSPContext *c, AVCodecContext *avctx, + unsigned high_bit_depth); #endif /* AVCODEC_XVIDIDCT_H */ |