]> git.sesse.net Git - x264/blob - common/dct.h
Correct X header path usage in configure
[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 #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)
52 };
53 #undef W
54
55 /* inverse squared */
56 #define W(i) (i==0 ? FIX8(3.125) :\
57               i==1 ? FIX8(1.25) :\
58               i==2 ? FIX8(0.5) :0)
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)
64 };
65 #undef W
66
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),
78
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)
83 };
84 #undef W
85
86 extern int x264_dct4_weight2_zigzag[2][16]; // [2] = {frame, field}
87 extern int x264_dct8_weight2_zigzag[2][64];
88
89 typedef struct
90 {
91     // pix1  stride = FENC_STRIDE
92     // pix2  stride = FDEC_STRIDE
93     // p_dst stride = FDEC_STRIDE
94     void (*sub4x4_dct)   ( dctcoef dct[16], pixel *pix1, pixel *pix2 );
95     void (*add4x4_idct)  ( pixel *p_dst, dctcoef dct[16] );
96
97     void (*sub8x8_dct)   ( dctcoef dct[4][16], pixel *pix1, pixel *pix2 );
98     void (*sub8x8_dct_dc)( dctcoef dct[4], pixel *pix1, pixel *pix2 );
99     void (*add8x8_idct)  ( pixel *p_dst, dctcoef dct[4][16] );
100     void (*add8x8_idct_dc) ( pixel *p_dst, dctcoef dct[4] );
101
102     void (*sub16x16_dct) ( dctcoef dct[16][16], pixel *pix1, pixel *pix2 );
103     void (*add16x16_idct)( pixel *p_dst, dctcoef dct[16][16] );
104     void (*add16x16_idct_dc) ( pixel *p_dst, dctcoef dct[16] );
105
106     void (*sub8x8_dct8)  ( dctcoef dct[64], pixel *pix1, pixel *pix2 );
107     void (*add8x8_idct8) ( pixel *p_dst, dctcoef dct[64] );
108
109     void (*sub16x16_dct8) ( dctcoef dct[4][64], pixel *pix1, pixel *pix2 );
110     void (*add16x16_idct8)( pixel *p_dst, dctcoef dct[4][64] );
111
112     void (*dct4x4dc) ( dctcoef d[16] );
113     void (*idct4x4dc)( dctcoef d[16] );
114
115 } x264_dct_function_t;
116
117 typedef struct
118 {
119     void (*scan_8x8)( dctcoef level[64], dctcoef dct[64] );
120     void (*scan_4x4)( dctcoef level[16], dctcoef dct[16] );
121     int  (*sub_8x8)  ( dctcoef level[64], const pixel *p_src, pixel *p_dst );
122     int  (*sub_4x4)  ( dctcoef level[16], const pixel *p_src, pixel *p_dst );
123     int  (*sub_4x4ac)( dctcoef level[16], const pixel *p_src, pixel *p_dst, dctcoef *dc );
124     void (*interleave_8x8_cavlc)( dctcoef *dst, dctcoef *src, uint8_t *nnz );
125
126 } x264_zigzag_function_t;
127
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 );
131
132 #endif