]> git.sesse.net Git - x264/blob - common/pixel.h
Fix SSIM calculation with sliced threads
[x264] / common / pixel.h
1 /*****************************************************************************
2  * pixel.c: pixel metrics
3  *****************************************************************************
4  * Copyright (C) 2004-2011 x264 project
5  *
6  * Authors: Loren Merritt <lorenm@u.washington.edu>
7  *          Fiona Glaser <fiona@x264.com>
8  *
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.
13  *
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.
18  *
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., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
22  *
23  * This program is also available under a commercial proprietary license.
24  * For more information, contact us at licensing@x264.com.
25  *****************************************************************************/
26
27 #ifndef X264_PIXEL_H
28 #define X264_PIXEL_H
29
30 // SSD assumes all args aligned
31 // other cmp functions assume first arg aligned
32 typedef int  (*x264_pixel_cmp_t) ( pixel *, int, pixel *, int );
33 typedef void (*x264_pixel_cmp_x3_t) ( pixel *, pixel *, pixel *, pixel *, int, int[3] );
34 typedef void (*x264_pixel_cmp_x4_t) ( pixel *, pixel *, pixel *, pixel *, pixel *, int, int[4] );
35
36 enum
37 {
38     PIXEL_16x16 = 0,
39     PIXEL_16x8  = 1,
40     PIXEL_8x16  = 2,
41     PIXEL_8x8   = 3,
42     PIXEL_8x4   = 4,
43     PIXEL_4x8   = 5,
44     PIXEL_4x4   = 6,
45     PIXEL_4x2   = 7,
46     PIXEL_2x4   = 8,
47     PIXEL_2x2   = 9,
48 };
49
50 static const struct
51 {
52     int w;
53     int h;
54 } x264_pixel_size[7] =
55 {
56     { 16, 16 },
57     { 16,  8 }, {  8, 16 },
58     {  8,  8 },
59     {  8,  4 }, {  4,  8 },
60     {  4,  4 }
61 };
62
63 static const uint8_t x264_size2pixel[5][5] =
64 {
65     { 0, },
66     { 0, PIXEL_4x4, PIXEL_8x4, 0, 0 },
67     { 0, PIXEL_4x8, PIXEL_8x8, 0, PIXEL_16x8 },
68     { 0, },
69     { 0, 0,        PIXEL_8x16, 0, PIXEL_16x16 }
70 };
71
72 typedef struct
73 {
74     x264_pixel_cmp_t  sad[7];
75     x264_pixel_cmp_t  ssd[7];
76     x264_pixel_cmp_t satd[7];
77     x264_pixel_cmp_t ssim[7];
78     x264_pixel_cmp_t sa8d[4];
79     x264_pixel_cmp_t mbcmp[7]; /* either satd or sad for subpel refine and mode decision */
80     x264_pixel_cmp_t mbcmp_unaligned[7]; /* unaligned mbcmp for subpel */
81     x264_pixel_cmp_t fpelcmp[7]; /* either satd or sad for fullpel motion search */
82     x264_pixel_cmp_x3_t fpelcmp_x3[7];
83     x264_pixel_cmp_x4_t fpelcmp_x4[7];
84     x264_pixel_cmp_t sad_aligned[7]; /* Aligned SAD for mbcmp */
85     int (*vsad)( pixel *, int, int );
86     int (*var2_8x8)( pixel *, int, pixel *, int, int * );
87
88     uint64_t (*var[4])( pixel *pix, int stride );
89     uint64_t (*hadamard_ac[4])( pixel *pix, int stride );
90
91     void (*ssd_nv12_core)( pixel *pixuv1, int stride1,
92                            pixel *pixuv2, int stride2, int width, int height,
93                            uint64_t *ssd_u, uint64_t *ssd_v );
94     void (*ssim_4x4x2_core)( const pixel *pix1, int stride1,
95                              const pixel *pix2, int stride2, int sums[2][4] );
96     float (*ssim_end4)( int sum0[5][4], int sum1[5][4], int width );
97
98     /* multiple parallel calls to cmp. */
99     x264_pixel_cmp_x3_t sad_x3[7];
100     x264_pixel_cmp_x4_t sad_x4[7];
101     x264_pixel_cmp_x3_t satd_x3[7];
102     x264_pixel_cmp_x4_t satd_x4[7];
103
104     /* abs-diff-sum for successive elimination.
105      * may round width up to a multiple of 16. */
106     int (*ads[7])( int enc_dc[4], uint16_t *sums, int delta,
107                    uint16_t *cost_mvx, int16_t *mvs, int width, int thresh );
108
109     /* calculate satd or sad of V, H, and DC modes.
110      * may be NULL, in which case just use pred+satd instead. */
111     void (*intra_mbcmp_x3_16x16)( pixel *fenc, pixel *fdec  , int res[3] );
112     void (*intra_satd_x3_16x16) ( pixel *fenc, pixel *fdec  , int res[3] );
113     void (*intra_sad_x3_16x16)  ( pixel *fenc, pixel *fdec  , int res[3] );
114     void (*intra_mbcmp_x3_8x8c) ( pixel *fenc, pixel *fdec  , int res[3] );
115     void (*intra_satd_x3_8x8c)  ( pixel *fenc, pixel *fdec  , int res[3] );
116     void (*intra_sad_x3_8x8c)   ( pixel *fenc, pixel *fdec  , int res[3] );
117     void (*intra_mbcmp_x3_4x4)  ( pixel *fenc, pixel *fdec  , int res[3] );
118     void (*intra_satd_x3_4x4)   ( pixel *fenc, pixel *fdec  , int res[3] );
119     void (*intra_sad_x3_4x4)    ( pixel *fenc, pixel *fdec  , int res[3] );
120     void (*intra_mbcmp_x3_8x8)  ( pixel *fenc, pixel edge[33], int res[3] );
121     void (*intra_sa8d_x3_8x8)   ( pixel *fenc, pixel edge[33], int res[3] );
122     void (*intra_sad_x3_8x8)    ( pixel *fenc, pixel edge[33], int res[3] );
123 } x264_pixel_function_t;
124
125 void x264_pixel_init( int cpu, x264_pixel_function_t *pixf );
126 void x264_pixel_ssd_nv12( x264_pixel_function_t *pf, pixel *pix1, int i_pix1, pixel *pix2, int i_pix2, int i_width, int i_height, uint64_t *ssd_u, uint64_t *ssd_v );
127 uint64_t x264_pixel_ssd_wxh( x264_pixel_function_t *pf, pixel *pix1, int i_pix1, pixel *pix2, int i_pix2, int i_width, int i_height );
128 float x264_pixel_ssim_wxh( x264_pixel_function_t *pf, pixel *pix1, int i_pix1, pixel *pix2, int i_pix2, int i_width, int i_height, void *buf, int *cnt );
129 int x264_field_vsad( x264_t *h, int mb_x, int mb_y );
130
131 #endif