1 /*****************************************************************************
2 * dct.h: transform and zigzag
3 *****************************************************************************
4 * Copyright (C) 2004-2011 x264 project
6 * Authors: Loren Merritt <lorenm@u.washington.edu>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.
22 * This program is also available under a commercial proprietary license.
23 * For more information, contact us at licensing@x264.com.
24 *****************************************************************************/
29 /* the inverse of the scaling factors introduced by 8x8 fdct */
30 #define W(i) (i==0 ? FIX8(1.0000) :\
31 i==1 ? FIX8(0.8859) :\
32 i==2 ? FIX8(1.6000) :\
33 i==3 ? FIX8(0.9415) :\
34 i==4 ? FIX8(1.2651) :\
35 i==5 ? FIX8(1.1910) :0)
36 static const uint16_t x264_dct8_weight_tab[64] = {
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),
42 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
43 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
44 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
45 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1)
49 #define W(i) (i==0 ? FIX8(1.76777) :\
50 i==1 ? FIX8(1.11803) :\
51 i==2 ? FIX8(0.70711) :0)
52 static const uint16_t x264_dct4_weight_tab[16] = {
53 W(0), W(1), W(0), W(1),
54 W(1), W(2), W(1), W(2),
55 W(0), W(1), W(0), W(1),
56 W(1), W(2), W(1), W(2)
61 #define W(i) (i==0 ? FIX8(3.125) :\
64 static const uint16_t x264_dct4_weight2_tab[16] = {
65 W(0), W(1), W(0), W(1),
66 W(1), W(2), W(1), W(2),
67 W(0), W(1), W(0), W(1),
68 W(1), W(2), W(1), W(2)
72 #define W(i) (i==0 ? FIX8(1.00000) :\
73 i==1 ? FIX8(0.78487) :\
74 i==2 ? FIX8(2.56132) :\
75 i==3 ? FIX8(0.88637) :\
76 i==4 ? FIX8(1.60040) :\
77 i==5 ? FIX8(1.41850) :0)
78 static const uint16_t x264_dct8_weight2_tab[64] = {
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),
84 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
85 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
86 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
87 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1)
91 extern int x264_dct4_weight2_zigzag[2][16]; // [2] = {frame, field}
92 extern int x264_dct8_weight2_zigzag[2][64];
96 // pix1 stride = FENC_STRIDE
97 // pix2 stride = FDEC_STRIDE
98 // p_dst stride = FDEC_STRIDE
99 void (*sub4x4_dct) ( dctcoef dct[16], pixel *pix1, pixel *pix2 );
100 void (*add4x4_idct) ( pixel *p_dst, dctcoef dct[16] );
102 void (*sub8x8_dct) ( dctcoef dct[4][16], pixel *pix1, pixel *pix2 );
103 void (*sub8x8_dct_dc)( dctcoef dct[4], pixel *pix1, pixel *pix2 );
104 void (*add8x8_idct) ( pixel *p_dst, dctcoef dct[4][16] );
105 void (*add8x8_idct_dc) ( pixel *p_dst, dctcoef dct[4] );
107 void (*sub16x16_dct) ( dctcoef dct[16][16], pixel *pix1, pixel *pix2 );
108 void (*add16x16_idct)( pixel *p_dst, dctcoef dct[16][16] );
109 void (*add16x16_idct_dc) ( pixel *p_dst, dctcoef dct[16] );
111 void (*sub8x8_dct8) ( dctcoef dct[64], pixel *pix1, pixel *pix2 );
112 void (*add8x8_idct8) ( pixel *p_dst, dctcoef dct[64] );
114 void (*sub16x16_dct8) ( dctcoef dct[4][64], pixel *pix1, pixel *pix2 );
115 void (*add16x16_idct8)( pixel *p_dst, dctcoef dct[4][64] );
117 void (*dct4x4dc) ( dctcoef d[16] );
118 void (*idct4x4dc)( dctcoef d[16] );
120 } x264_dct_function_t;
124 void (*scan_8x8)( dctcoef level[64], dctcoef dct[64] );
125 void (*scan_4x4)( dctcoef level[16], dctcoef dct[16] );
126 int (*sub_8x8) ( dctcoef level[64], const pixel *p_src, pixel *p_dst );
127 int (*sub_4x4) ( dctcoef level[16], const pixel *p_src, pixel *p_dst );
128 int (*sub_4x4ac)( dctcoef level[16], const pixel *p_src, pixel *p_dst, dctcoef *dc );
129 void (*interleave_8x8_cavlc)( dctcoef *dst, dctcoef *src, uint8_t *nnz );
131 } x264_zigzag_function_t;
133 void x264_dct_init( int cpu, x264_dct_function_t *dctf );
134 void x264_dct_init_weights( void );
135 void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf_progressive, x264_zigzag_function_t *pf_interlaced );