]> git.sesse.net Git - x264/blob - common/mc.h
cbdf1a631c0ae39562d5d3e95cbff8abb569d034
[x264] / common / mc.h
1 /*****************************************************************************
2  * mc.h: h264 encoder library (Motion Compensation)
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_MC_H
22 #define X264_MC_H
23
24 struct x264_weight_t;
25 typedef void (* weight_fn_t)( pixel *, int, pixel *,int, const struct x264_weight_t *, int );
26 typedef struct x264_weight_t
27 {
28     /* aligning the first member is a gcc hack to force the struct to be
29      * 16 byte aligned, as well as force sizeof(struct) to be a multiple of 16 */
30     ALIGNED_16( int16_t cachea[8] );
31     int16_t cacheb[8];
32     int32_t i_denom;
33     int32_t i_scale;
34     int32_t i_offset;
35     weight_fn_t *weightfn;
36 } ALIGNED_16( x264_weight_t );
37
38 extern const x264_weight_t weight_none[3];
39
40 #define SET_WEIGHT( w, b, s, d, o )\
41 {\
42     (w).i_scale = (s);\
43     (w).i_denom = (d);\
44     (w).i_offset = (o);\
45     if( b )\
46         h->mc.weight_cache( h, &w );\
47     else\
48         w.weightfn = NULL;\
49 }
50
51 /* Do the MC
52  * XXX: Only width = 4, 8 or 16 are valid
53  * width == 4 -> height == 4 or 8
54  * width == 8 -> height == 4 or 8 or 16
55  * width == 16-> height == 8 or 16
56  * */
57
58 typedef struct
59 {
60     void (*mc_luma)(pixel *dst, int i_dst, pixel **src, int i_src,
61                     int mvx, int mvy,
62                     int i_width, int i_height, const x264_weight_t *weight );
63
64     /* may round up the dimensions if they're not a power of 2 */
65     pixel* (*get_ref)(pixel *dst, int *i_dst, pixel **src, int i_src,
66                       int mvx, int mvy,
67                       int i_width, int i_height, const x264_weight_t *weight );
68
69     /* mc_chroma may write up to 2 bytes of garbage to the right of dst,
70      * so it must be run from left to right. */
71     void (*mc_chroma)(pixel *dst, int i_dst, pixel *src, int i_src,
72                       int mvx, int mvy,
73                       int i_width, int i_height );
74
75     void (*avg[10])( pixel *dst, int, pixel *src1, int, pixel *src2, int, int i_weight );
76
77     /* only 16x16, 8x8, and 4x4 defined */
78     void (*copy[7])( pixel *dst, int, pixel *src, int, int i_height );
79     void (*copy_16x16_unaligned)( pixel *dst, int, pixel *src, int, int i_height );
80
81     void (*plane_copy)( pixel *dst, int i_dst,
82                         uint8_t *src, int i_src, int w, int h);
83
84     void (*hpel_filter)( pixel *dsth, pixel *dstv, pixel *dstc, pixel *src,
85                          int i_stride, int i_width, int i_height, dctcoef *buf );
86
87     /* prefetch the next few macroblocks of fenc or fdec */
88     void (*prefetch_fenc)( pixel *pix_y, int stride_y,
89                            pixel *pix_uv, int stride_uv, int mb_x );
90     /* prefetch the next few macroblocks of a hpel reference frame */
91     void (*prefetch_ref)( pixel *pix, int stride, int parity );
92
93     void *(*memcpy_aligned)( void *dst, const void *src, size_t n );
94     void (*memzero_aligned)( void *dst, int n );
95
96     /* successive elimination prefilter */
97     void (*integral_init4h)( uint16_t *sum, pixel *pix, int stride );
98     void (*integral_init8h)( uint16_t *sum, pixel *pix, int stride );
99     void (*integral_init4v)( uint16_t *sum8, uint16_t *sum4, int stride );
100     void (*integral_init8v)( uint16_t *sum8, int stride );
101
102     void (*frame_init_lowres_core)( pixel *src0, pixel *dst0, pixel *dsth, pixel *dstv, pixel *dstc,
103                                     int src_stride, int dst_stride, int width, int height );
104     weight_fn_t *weight;
105     weight_fn_t *offsetadd;
106     weight_fn_t *offsetsub;
107     void (*weight_cache)( x264_t *, x264_weight_t * );
108
109     void (*mbtree_propagate_cost)( int *dst, uint16_t *propagate_in, uint16_t *intra_costs,
110                                    uint16_t *inter_costs, uint16_t *inv_qscales, int len );
111 } x264_mc_functions_t;
112
113 void x264_mc_init( int cpu, x264_mc_functions_t *pf );
114
115 #endif