]> git.sesse.net Git - x264/blob - common/pixel.h
Fix RD early-skip
[x264] / common / pixel.h
1 /*****************************************************************************
2  * pixel.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_PIXEL_H
22 #define X264_PIXEL_H
23
24 // SSD assumes all args aligned
25 // other cmp functions assume first arg aligned
26 typedef int  (*x264_pixel_cmp_t) ( uint8_t *, int, uint8_t *, int );
27 typedef void (*x264_pixel_cmp_x3_t) ( uint8_t *, uint8_t *, uint8_t *, uint8_t *, int, int[3] );
28 typedef void (*x264_pixel_cmp_x4_t) ( uint8_t *, uint8_t *, uint8_t *, uint8_t *, uint8_t *, int, int[4] );
29
30 enum
31 {
32     PIXEL_16x16 = 0,
33     PIXEL_16x8  = 1,
34     PIXEL_8x16  = 2,
35     PIXEL_8x8   = 3,
36     PIXEL_8x4   = 4,
37     PIXEL_4x8   = 5,
38     PIXEL_4x4   = 6,
39     PIXEL_4x2   = 7,
40     PIXEL_2x4   = 8,
41     PIXEL_2x2   = 9,
42 };
43
44 static const struct {
45     int w;
46     int h;
47 } x264_pixel_size[7] = {
48     { 16, 16 },
49     { 16,  8 }, {  8, 16 },
50     {  8,  8 },
51     {  8,  4 }, {  4,  8 },
52     {  4,  4 }
53 };
54
55 static const uint8_t x264_size2pixel[5][5] = {
56     { 0, },
57     { 0, PIXEL_4x4, PIXEL_8x4, 0, 0 },
58     { 0, PIXEL_4x8, PIXEL_8x8, 0, PIXEL_16x8 },
59     { 0, },
60     { 0, 0,        PIXEL_8x16, 0, PIXEL_16x16 }
61 };
62
63 typedef struct
64 {
65     x264_pixel_cmp_t  sad[7];
66     x264_pixel_cmp_t  ssd[7];
67     x264_pixel_cmp_t satd[7];
68     x264_pixel_cmp_t ssim[7];
69     x264_pixel_cmp_t sa8d[4];
70     x264_pixel_cmp_t mbcmp[7]; /* either satd or sad for subpel refine and mode decision */
71     x264_pixel_cmp_t mbcmp_unaligned[7]; /* unaligned mbcmp for subpel */
72     x264_pixel_cmp_t fpelcmp[7]; /* either satd or sad for fullpel motion search */
73     x264_pixel_cmp_x3_t fpelcmp_x3[7];
74     x264_pixel_cmp_x4_t fpelcmp_x4[7];
75     x264_pixel_cmp_t sad_aligned[7]; /* Aligned SAD for mbcmp */
76     int (*var2_8x8)( uint8_t *, int, uint8_t *, int, int * );
77
78     int (*var[4])( uint8_t *pix, int stride );
79     uint64_t (*hadamard_ac[4])( uint8_t *pix, int stride );
80
81     void (*ssim_4x4x2_core)( const uint8_t *pix1, int stride1,
82                              const uint8_t *pix2, int stride2, int sums[2][4] );
83     float (*ssim_end4)( int sum0[5][4], int sum1[5][4], int width );
84
85     /* multiple parallel calls to cmp. */
86     x264_pixel_cmp_x3_t sad_x3[7];
87     x264_pixel_cmp_x4_t sad_x4[7];
88     x264_pixel_cmp_x3_t satd_x3[7];
89     x264_pixel_cmp_x4_t satd_x4[7];
90
91     /* abs-diff-sum for successive elimination.
92      * may round width up to a multiple of 16. */
93     int (*ads[7])( int enc_dc[4], uint16_t *sums, int delta,
94                    uint16_t *cost_mvx, int16_t *mvs, int width, int thresh );
95
96     /* calculate satd or sad of V, H, and DC modes.
97      * may be NULL, in which case just use pred+satd instead. */
98     void (*intra_mbcmp_x3_16x16)( uint8_t *fenc, uint8_t *fdec  , int res[3] );
99     void (*intra_satd_x3_16x16) ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
100     void (*intra_sad_x3_16x16)  ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
101     void (*intra_mbcmp_x3_8x8c) ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
102     void (*intra_satd_x3_8x8c)  ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
103     void (*intra_sad_x3_8x8c)   ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
104     void (*intra_mbcmp_x3_4x4)  ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
105     void (*intra_satd_x3_4x4)   ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
106     void (*intra_sad_x3_4x4)    ( uint8_t *fenc, uint8_t *fdec  , int res[3] );
107     void (*intra_mbcmp_x3_8x8)  ( uint8_t *fenc, uint8_t edge[33], int res[3] );
108     void (*intra_sa8d_x3_8x8)   ( uint8_t *fenc, uint8_t edge[33], int res[3] );
109     void (*intra_sad_x3_8x8)    ( uint8_t *fenc, uint8_t edge[33], int res[3] );
110 } x264_pixel_function_t;
111
112 void x264_pixel_init( int cpu, x264_pixel_function_t *pixf );
113 int64_t x264_pixel_ssd_wxh( x264_pixel_function_t *pf, uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2, int i_width, int i_height );
114 float x264_pixel_ssim_wxh( x264_pixel_function_t *pf, uint8_t *pix1, int i_pix1, uint8_t *pix2, int i_pix2, int i_width, int i_height, void *buf );
115
116 #endif