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[4][4], uint8_t *pix1, uint8_t *pix2 );
95 void (*add4x4_idct) ( uint8_t *p_dst, int16_t dct[4][4] );
97 void (*sub8x8_dct) ( int16_t dct[4][4][4], uint8_t *pix1, uint8_t *pix2 );
98 void (*add8x8_idct) ( uint8_t *p_dst, int16_t dct[4][4][4] );
100 void (*sub16x16_dct) ( int16_t dct[16][4][4], uint8_t *pix1, uint8_t *pix2 );
101 void (*add16x16_idct)( uint8_t *p_dst, int16_t dct[16][4][4] );
103 void (*sub8x8_dct8) ( int16_t dct[8][8], uint8_t *pix1, uint8_t *pix2 );
104 void (*add8x8_idct8) ( uint8_t *p_dst, int16_t dct[8][8] );
106 void (*sub16x16_dct8) ( int16_t dct[4][8][8], uint8_t *pix1, uint8_t *pix2 );
107 void (*add16x16_idct8)( uint8_t *p_dst, int16_t dct[4][8][8] );
109 void (*dct4x4dc) ( int16_t d[4][4] );
110 void (*idct4x4dc)( int16_t d[4][4] );
112 } x264_dct_function_t;
116 void (*scan_8x8)( int16_t level[64], int16_t dct[8][8] );
117 void (*scan_4x4)( int16_t level[16], int16_t dct[4][4] );
118 void (*sub_8x8)( int16_t level[64], const uint8_t *p_src, uint8_t *p_dst );
119 void (*sub_4x4)( int16_t level[16], const uint8_t *p_src, uint8_t *p_dst );
120 void (*interleave_8x8_cavlc)( int16_t *dst, int16_t *src );
122 } x264_zigzag_function_t;
124 void x264_dct_init( int cpu, x264_dct_function_t *dctf );
125 void x264_dct_init_weights( void );
126 void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf, int b_interlaced );