]> git.sesse.net Git - x264/blob - common/dct.h
Update file headers throughout x264
[x264] / common / dct.h
1 /*****************************************************************************
2  * dct.h: h264 encoder library
3  *****************************************************************************
4  * Copyright (C) 2004-2008 Loren Merritt <lorenm@u.washington.edu>
5  *
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.
10  *
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.
15  *
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  *****************************************************************************/
20
21 #ifndef X264_DCT_H
22 #define X264_DCT_H
23
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),
36
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)
41 };
42 #undef W
43
44 /* inverse squared */
45 #define W(i) (i==0 ? FIX8(3.125) :\
46               i==1 ? FIX8(1.25) :\
47               i==2 ? FIX8(0.5) :0)
48 static const uint16_t x264_dct4_weight2_tab[16] = {
49     W(0), W(1), W(0), W(1),
50     W(1), W(2), W(1), W(2),
51     W(0), W(1), W(0), W(1),
52     W(1), W(2), W(1), W(2)
53 };
54 #undef W
55
56 #define W(i) (i==0 ? FIX8(1.00000) :\
57               i==1 ? FIX8(0.78487) :\
58               i==2 ? FIX8(2.56132) :\
59               i==3 ? FIX8(0.88637) :\
60               i==4 ? FIX8(1.60040) :\
61               i==5 ? FIX8(1.41850) :0)
62 static const uint16_t x264_dct8_weight2_tab[64] = {
63     W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
64     W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
65     W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
66     W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
67
68     W(0), W(3), W(4), W(3),  W(0), W(3), W(4), W(3),
69     W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1),
70     W(4), W(5), W(2), W(5),  W(4), W(5), W(2), W(5),
71     W(3), W(1), W(5), W(1),  W(3), W(1), W(5), W(1)
72 };
73 #undef W
74
75 extern int x264_dct4_weight2_zigzag[2][16]; // [2] = {frame, field}
76 extern int x264_dct8_weight2_zigzag[2][64];
77
78 typedef struct
79 {
80     // pix1  stride = FENC_STRIDE
81     // pix2  stride = FDEC_STRIDE
82     // p_dst stride = FDEC_STRIDE
83     void (*sub4x4_dct)   ( int16_t dct[4][4], uint8_t *pix1, uint8_t *pix2 );
84     void (*add4x4_idct)  ( uint8_t *p_dst, int16_t dct[4][4] );
85
86     void (*sub8x8_dct)   ( int16_t dct[4][4][4], uint8_t *pix1, uint8_t *pix2 );
87     void (*add8x8_idct)  ( uint8_t *p_dst, int16_t dct[4][4][4] );
88
89     void (*sub16x16_dct) ( int16_t dct[16][4][4], uint8_t *pix1, uint8_t *pix2 );
90     void (*add16x16_idct)( uint8_t *p_dst, int16_t dct[16][4][4] );
91
92     void (*sub8x8_dct8)  ( int16_t dct[8][8], uint8_t *pix1, uint8_t *pix2 );
93     void (*add8x8_idct8) ( uint8_t *p_dst, int16_t dct[8][8] );
94
95     void (*sub16x16_dct8) ( int16_t dct[4][8][8], uint8_t *pix1, uint8_t *pix2 );
96     void (*add16x16_idct8)( uint8_t *p_dst, int16_t dct[4][8][8] );
97
98     void (*dct4x4dc) ( int16_t d[4][4] );
99     void (*idct4x4dc)( int16_t d[4][4] );
100
101     void (*dct2x2dc) ( int16_t d[2][2] );
102     void (*idct2x2dc)( int16_t d[2][2] );
103
104 } x264_dct_function_t;
105
106 typedef struct
107 {
108     void (*scan_8x8)( int16_t level[64], int16_t dct[8][8] );
109     void (*scan_4x4)( int16_t level[16], int16_t dct[4][4] );
110     void (*sub_4x4)( int16_t level[16], const uint8_t *p_src, uint8_t *p_dst );
111
112 } x264_zigzag_function_t;
113
114 void x264_dct_init( int cpu, x264_dct_function_t *dctf );
115 void x264_dct_init_weights( void );
116 void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf, int b_interlaced );
117
118 #endif