x264-dsp
pixel.h
1 /*****************************************************************************
2  * pixel.h: pixel metrics
3  *****************************************************************************/
4 
5 #ifndef X264_PIXEL_H
6 #define X264_PIXEL_H
7 
8 // SSD assumes all args aligned
9 // other cmp functions assume first arg aligned
10 typedef int (*x264_pixel_cmp_t)(pixel *, intptr_t, pixel *, intptr_t);
11 typedef void (*x264_pixel_cmp_x3_t)(pixel *, pixel *, pixel *, pixel *, intptr_t, int[3]);
12 typedef void (*x264_pixel_cmp_x4_t)(pixel *, pixel *, pixel *, pixel *, pixel *, intptr_t, int[4]);
13 
14 enum {
15  PIXEL_16x16 = 0,
16  PIXEL_16x8 = 1,
17  PIXEL_8x16 = 2,
18  PIXEL_8x8 = 3,
19  PIXEL_8x4 = 4,
20  PIXEL_4x8 = 5,
21  PIXEL_4x4 = 6,
22 
23  /* Subsampled chroma only */
24  PIXEL_4x16 = 7, /* 4:2:2 */
25  PIXEL_4x2 = 8,
26  PIXEL_2x8 = 9, /* 4:2:2 */
27  PIXEL_2x4 = 10,
28  PIXEL_2x2 = 11,
29 };
30 
31 static const struct {
32  uint8_t w, h;
33 } x264_pixel_size[12] =
34  {
35  {16, 16},
36  {16, 8},
37  {8, 16},
38  {8, 8},
39  {8, 4},
40  {4, 8},
41  {4, 4},
42  {4, 16},
43  {4, 2},
44  {2, 8},
45  {2, 4},
46  {2, 2},
47 };
48 
49 static const uint8_t x264_size2pixel[5][5] =
50  {
51  {
52  0,
53  },
54  {0, PIXEL_4x4, PIXEL_8x4, 0, 0},
55  {0, PIXEL_4x8, PIXEL_8x8, 0, PIXEL_16x8},
56  {
57  0,
58  },
59  {0, 0, PIXEL_8x16, 0, PIXEL_16x16}};
60 
61 static const uint8_t x264_luma2chroma_pixel[4][7] =
62  {
63  {0},
64  {PIXEL_8x8, PIXEL_8x4, PIXEL_4x8, PIXEL_4x4, PIXEL_4x2, PIXEL_2x4, PIXEL_2x2}, /* 4:2:0 */
65  {PIXEL_8x16, PIXEL_8x8, PIXEL_4x16, PIXEL_4x8, PIXEL_4x4, PIXEL_2x8, PIXEL_2x4}, /* 4:2:2 */
66  {PIXEL_16x16, PIXEL_16x8, PIXEL_8x16, PIXEL_8x8, PIXEL_8x4, PIXEL_4x8, PIXEL_4x4}, /* 4:4:4 */
67 };
68 
69 typedef struct
70 {
71  x264_pixel_cmp_t sad[8];
72  x264_pixel_cmp_t ssd[8];
73  x264_pixel_cmp_t satd[8];
74  x264_pixel_cmp_t mbcmp[8]; /* either satd or sad for subpel refine and mode decision */
75  x264_pixel_cmp_t mbcmp_unaligned[8]; /* unaligned mbcmp for subpel */
76  x264_pixel_cmp_t fpelcmp[8]; /* either satd or sad for fullpel motion search */
77  x264_pixel_cmp_x3_t fpelcmp_x3[7];
78  x264_pixel_cmp_x4_t fpelcmp_x4[7];
79  x264_pixel_cmp_t sad_aligned[8]; /* Aligned SAD for mbcmp */
80 
81  uint64_t (*var[4])(pixel *pix, intptr_t stride);
82  int (*var2[4])(pixel *pix1, intptr_t stride1, pixel *pix2, intptr_t stride2, int *ssd);
83 
84 #ifdef _DEBUG
85  void (*ssd_nv12_core)(pixel *pixuv1, intptr_t stride1,
86  pixel *pixuv2, intptr_t stride2, int width, int height,
87  uint64_t *ssd_u, uint64_t *ssd_v);
88  void (*ssim_4x4x2_core)(const pixel *pix1, intptr_t stride1,
89  const pixel *pix2, intptr_t stride2, int sums[2][4]);
90  float (*ssim_end4)(int sum0[5][4], int sum1[5][4], int width);
91 #endif
92 
93  /* multiple parallel calls to cmp. */
94  x264_pixel_cmp_x3_t sad_x3[7];
95  x264_pixel_cmp_x4_t sad_x4[7];
96  x264_pixel_cmp_x3_t satd_x3[7];
97  x264_pixel_cmp_x4_t satd_x4[7];
98 
99  /* calculate satd or sad of V, H, and DC modes. */
100  void (*intra_mbcmp_x3_16x16)(pixel *fenc, pixel *fdec, int res[3]);
101  void (*intra_satd_x3_16x16)(pixel *fenc, pixel *fdec, int res[3]);
102  void (*intra_sad_x3_16x16)(pixel *fenc, pixel *fdec, int res[3]);
103 
104  void (*intra_mbcmp_x3_4x4)(pixel *fenc, pixel *fdec, int res[3]);
105  void (*intra_satd_x3_4x4)(pixel *fenc, pixel *fdec, int res[3]);
106  void (*intra_sad_x3_4x4)(pixel *fenc, pixel *fdec, int res[3]);
107 
108  void (*intra_mbcmp_x4_4x4_h)(pixel *fenc, pixel *fdec, int res[9]);
109  void (*intra_satd_x4_4x4_h)(pixel *fenc, pixel *fdec, int res[9]);
110  void (*intra_sad_x4_4x4_h)(pixel *fenc, pixel *fdec, int res[9]);
111 
112  void (*intra_mbcmp_x4_4x4_v)(pixel *fenc, pixel *fdec, int res[9]);
113  void (*intra_satd_x4_4x4_v)(pixel *fenc, pixel *fdec, int res[9]);
114  void (*intra_sad_x4_4x4_v)(pixel *fenc, pixel *fdec, int res[9]);
115 
116  void (*intra_mbcmp_x3_chroma)(pixel *fenc, pixel *fdec, int res[3]);
117  void (*intra_satd_x3_chroma)(pixel *fenc, pixel *fdec, int res[3]);
118  void (*intra_sad_x3_chroma)(pixel *fenc, pixel *fdec, int res[3]);
119 
120  void (*intra_mbcmp_x3_8x8c)(pixel *fenc, pixel *fdec, int res[3]);
121  void (*intra_satd_x3_8x8c)(pixel *fenc, pixel *fdec, int res[3]);
122  void (*intra_sad_x3_8x8c)(pixel *fenc, pixel *fdec, int res[3]);
123 
124  /* find minimum satd or sad of all modes, and set fdec.
125  * may be NULL, in which case just use pred+satd instead. */
126  int (*intra_mbcmp_x9_4x4)(pixel *fenc, pixel *fdec, uint16_t *bitcosts);
127  int (*intra_satd_x9_4x4)(pixel *fenc, pixel *fdec, uint16_t *bitcosts);
128  int (*intra_sad_x9_4x4)(pixel *fenc, pixel *fdec, uint16_t *bitcosts);
129 
131 
132 void x264_pixel_init(int cpu, x264_pixel_function_t *pixf);
133 
134 #ifdef _DEBUG
135 void x264_pixel_ssd_nv12(x264_pixel_function_t *pf, pixel *pix1, intptr_t i_pix1, pixel *pix2, intptr_t i_pix2,
136  int i_width, int i_height, uint64_t *ssd_u, uint64_t *ssd_v);
137 uint64_t x264_pixel_ssd_wxh(x264_pixel_function_t *pf, pixel *pix1, intptr_t i_pix1, pixel *pix2, intptr_t i_pix2,
138  int i_width, int i_height);
139 float x264_pixel_ssim_wxh(x264_pixel_function_t *pf, pixel *pix1, intptr_t i_pix1, pixel *pix2, intptr_t i_pix2,
140  int i_width, int i_height, void *buf, int *cnt);
141 #endif
142 
143 #endif
Definition: pixel.h:70