1 /*****************************************************************************
2 * dct.h: h264 encoder library
3 *****************************************************************************
4 * Copyright (C) 2004-2008 Loren Merritt <lorenm@u.washington.edu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
19 *****************************************************************************/
24 /* the inverse of the scaling factors introduced by 8x8 fdct */
25 #define W(i) (i==0 ? FIX8(1.0000) :\
26 i==1 ? FIX8(0.8859) :\
27 i==2 ? FIX8(1.6000) :\
28 i==3 ? FIX8(0.9415) :\
29 i==4 ? FIX8(1.2651) :\
30 i==5 ? FIX8(1.1910) :0)
31 static const uint16_t x264_dct8_weight_tab[64] = {
32 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
33 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
34 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
35 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
37 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
38 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
39 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
40 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1)
44 #define W(i) (i==0 ? FIX8(1.76777) :\
45 i==1 ? FIX8(1.11803) :\
46 i==2 ? FIX8(0.70711) :0)
47 static const uint16_t x264_dct4_weight_tab[16] = {
48 W(0), W(1), W(0), W(1),
49 W(1), W(2), W(1), W(2),
50 W(0), W(1), W(0), W(1),
51 W(1), W(2), W(1), W(2)
56 #define W(i) (i==0 ? FIX8(3.125) :\
59 static const uint16_t x264_dct4_weight2_tab[16] = {
60 W(0), W(1), W(0), W(1),
61 W(1), W(2), W(1), W(2),
62 W(0), W(1), W(0), W(1),
63 W(1), W(2), W(1), W(2)
67 #define W(i) (i==0 ? FIX8(1.00000) :\
68 i==1 ? FIX8(0.78487) :\
69 i==2 ? FIX8(2.56132) :\
70 i==3 ? FIX8(0.88637) :\
71 i==4 ? FIX8(1.60040) :\
72 i==5 ? FIX8(1.41850) :0)
73 static const uint16_t x264_dct8_weight2_tab[64] = {
74 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
75 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
76 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
77 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
79 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
80 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
81 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
82 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1)
86 extern int x264_dct4_weight2_zigzag[2][16]; // [2] = {frame, field}
87 extern int x264_dct8_weight2_zigzag[2][64];
91 // pix1 stride = FENC_STRIDE
92 // pix2 stride = FDEC_STRIDE
93 // p_dst stride = FDEC_STRIDE
94 void (*sub4x4_dct) ( int16_t dct[16], pixel *pix1, pixel *pix2 );
95 void (*add4x4_idct) ( pixel *p_dst, int16_t dct[16] );
97 void (*sub8x8_dct) ( int16_t dct[4][16], pixel *pix1, pixel *pix2 );
98 void (*sub8x8_dct_dc)( int16_t dct[4], pixel *pix1, pixel *pix2 );
99 void (*add8x8_idct) ( pixel *p_dst, int16_t dct[4][16] );
100 void (*add8x8_idct_dc) ( pixel *p_dst, int16_t dct[4] );
102 void (*sub16x16_dct) ( int16_t dct[16][16], pixel *pix1, pixel *pix2 );
103 void (*add16x16_idct)( pixel *p_dst, int16_t dct[16][16] );
104 void (*add16x16_idct_dc) ( pixel *p_dst, int16_t dct[16] );
106 void (*sub8x8_dct8) ( int16_t dct[64], pixel *pix1, pixel *pix2 );
107 void (*add8x8_idct8) ( pixel *p_dst, int16_t dct[64] );
109 void (*sub16x16_dct8) ( int16_t dct[4][64], pixel *pix1, pixel *pix2 );
110 void (*add16x16_idct8)( pixel *p_dst, int16_t dct[4][64] );
112 void (*dct4x4dc) ( int16_t d[16] );
113 void (*idct4x4dc)( int16_t d[16] );
115 } x264_dct_function_t;
119 void (*scan_8x8)( int16_t level[64], int16_t dct[64] );
120 void (*scan_4x4)( int16_t level[16], int16_t dct[16] );
121 int (*sub_8x8) ( int16_t level[64], const pixel *p_src, pixel *p_dst );
122 int (*sub_4x4) ( int16_t level[16], const pixel *p_src, pixel *p_dst );
123 int (*sub_4x4ac)( int16_t level[16], const pixel *p_src, pixel *p_dst, int16_t *dc );
124 void (*interleave_8x8_cavlc)( int16_t *dst, int16_t *src, uint8_t *nnz );
126 } x264_zigzag_function_t;
128 void x264_dct_init( int cpu, x264_dct_function_t *dctf );
129 void x264_dct_init_weights( void );
130 void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf, int b_interlaced );