1 /*****************************************************************************
2 * dct.h: h264 encoder library
3 *****************************************************************************
4 * Copyright (C) 2003 Laurent Aimar
5 * $Id: dct.h,v 1.1 2004/06/03 19:27:06 fenrir Exp $
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
27 /* the inverse of the scaling factors introduced by 8x8 fdct */
28 #define W(i) (i==0 ? FIX8(1.0000) :\
29 i==1 ? FIX8(0.8859) :\
30 i==2 ? FIX8(1.6000) :\
31 i==3 ? FIX8(0.9415) :\
32 i==4 ? FIX8(1.2651) :\
33 i==5 ? FIX8(1.1910) :0)
34 static const uint16_t x264_dct8_weight_tab[64] = {
35 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
36 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
37 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
38 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
40 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
41 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
42 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
43 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1)
48 #define W(i) (i==0 ? FIX8(3.125) :\
51 static const uint16_t x264_dct4_weight2_tab[16] = {
52 W(0), W(1), W(0), W(1),
53 W(1), W(2), W(1), W(2),
54 W(0), W(1), W(0), W(1),
55 W(1), W(2), W(1), W(2)
59 #define W(i) (i==0 ? FIX8(1.00000) :\
60 i==1 ? FIX8(0.78487) :\
61 i==2 ? FIX8(2.56132) :\
62 i==3 ? FIX8(0.88637) :\
63 i==4 ? FIX8(1.60040) :\
64 i==5 ? FIX8(1.41850) :0)
65 static const uint16_t x264_dct8_weight2_tab[64] = {
66 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
67 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
68 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
69 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
71 W(0), W(3), W(4), W(3), W(0), W(3), W(4), W(3),
72 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1),
73 W(4), W(5), W(2), W(5), W(4), W(5), W(2), W(5),
74 W(3), W(1), W(5), W(1), W(3), W(1), W(5), W(1)
78 extern int x264_dct4_weight2_zigzag[2][16]; // [2] = {frame, field}
79 extern int x264_dct8_weight2_zigzag[2][64];
83 // pix1 stride = FENC_STRIDE
84 // pix2 stride = FDEC_STRIDE
85 // p_dst stride = FDEC_STRIDE
86 void (*sub4x4_dct) ( int16_t dct[4][4], uint8_t *pix1, uint8_t *pix2 );
87 void (*add4x4_idct) ( uint8_t *p_dst, int16_t dct[4][4] );
89 void (*sub8x8_dct) ( int16_t dct[4][4][4], uint8_t *pix1, uint8_t *pix2 );
90 void (*add8x8_idct) ( uint8_t *p_dst, int16_t dct[4][4][4] );
92 void (*sub16x16_dct) ( int16_t dct[16][4][4], uint8_t *pix1, uint8_t *pix2 );
93 void (*add16x16_idct)( uint8_t *p_dst, int16_t dct[16][4][4] );
95 void (*sub8x8_dct8) ( int16_t dct[8][8], uint8_t *pix1, uint8_t *pix2 );
96 void (*add8x8_idct8) ( uint8_t *p_dst, int16_t dct[8][8] );
98 void (*sub16x16_dct8) ( int16_t dct[4][8][8], uint8_t *pix1, uint8_t *pix2 );
99 void (*add16x16_idct8)( uint8_t *p_dst, int16_t dct[4][8][8] );
101 void (*dct4x4dc) ( int16_t d[4][4] );
102 void (*idct4x4dc)( int16_t d[4][4] );
104 void (*dct2x2dc) ( int16_t d[2][2] );
105 void (*idct2x2dc)( int16_t d[2][2] );
107 } x264_dct_function_t;
111 void (*scan_8x8)( int level[64], int16_t dct[8][8] );
112 void (*scan_4x4)( int level[16], int16_t dct[4][4] );
113 void (*scan_4x4ac)( int level[15], int16_t dct[4][4] );
114 void (*sub_4x4)( int level[16], const uint8_t *p_src, uint8_t *p_dst );
115 void (*sub_4x4ac)( int level[15], const uint8_t *p_src, uint8_t *p_dst );
117 } x264_zigzag_function_t;
119 void x264_dct_init( int cpu, x264_dct_function_t *dctf );
120 void x264_dct_init_weights( void );
121 void x264_zigzag_init( int cpu, x264_zigzag_function_t *pf, int b_interlaced );