me.h 2.88 KB
Newer Older
Laurent Aimar's avatar
Laurent Aimar committed
1 2 3
/*****************************************************************************
 * me.h: h264 encoder library (Motion Estimation)
 *****************************************************************************
4
 * Copyright (C) 2003-2008 x264 project
Laurent Aimar's avatar
Laurent Aimar committed
5
 *
6 7
 * Authors: Loren Merritt <lorenm@u.washington.edu>
 *          Laurent Aimar <fenrir@via.ecp.fr>
Laurent Aimar's avatar
Laurent Aimar committed
8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111, USA.
Laurent Aimar's avatar
Laurent Aimar committed
22 23
 *****************************************************************************/

24 25
#ifndef X264_ME_H
#define X264_ME_H
Laurent Aimar's avatar
Laurent Aimar committed
26

27
#define COST_MAX (1<<28)
28
#define COST_MAX64 (1ULL<<60)
29

Laurent Aimar's avatar
Laurent Aimar committed
30 31 32 33
typedef struct
{
    /* input */
    int      i_pixel;   /* PIXEL_WxH */
34
    uint16_t *p_cost_mv; /* lambda * nbits for each possible mv */
Loren Merritt's avatar
Loren Merritt committed
35 36
    int      i_ref_cost;
    int      i_ref;
Laurent Aimar's avatar
Laurent Aimar committed
37

Loren Merritt's avatar
Loren Merritt committed
38 39
    uint8_t *p_fref[6];
    uint8_t *p_fenc[3];
40
    uint16_t *integral;
Loren Merritt's avatar
Loren Merritt committed
41
    int      i_stride[2];
Laurent Aimar's avatar
Laurent Aimar committed
42

43
    ALIGNED_4( int16_t mvp[2] );
Laurent Aimar's avatar
Laurent Aimar committed
44 45

    /* output */
46 47
    int cost_mv;        /* lambda * nbits for the chosen mv */
    int cost;           /* satd + lambda * nbits */
48 49
    ALIGNED_4( int16_t mv[2] );
} ALIGNED_16( x264_me_t );
Laurent Aimar's avatar
Laurent Aimar committed
50

51 52 53 54 55
typedef struct {
    int sad;
    int16_t mx, my;
} mvsad_t;

56 57
void x264_me_search_ref( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc, int *p_fullpel_thresh );
static inline void x264_me_search( x264_t *h, x264_me_t *m, int16_t (*mvc)[2], int i_mvc )
58 59
    { x264_me_search_ref( h, m, mvc, i_mvc, NULL ); }

Laurent Aimar's avatar
Laurent Aimar committed
60
void x264_me_refine_qpel( x264_t *h, x264_me_t *m );
Fiona Glaser's avatar
Fiona Glaser committed
61
void x264_me_refine_qpel_rd( x264_t *h, x264_me_t *m, int i_lambda2, int i4, int i_list );
62 63
void x264_me_refine_bidir_rd( x264_t *h, x264_me_t *m0, x264_me_t *m1, int i_weight, int i8, int i_lambda2 );
void x264_me_refine_bidir_satd( x264_t *h, x264_me_t *m0, x264_me_t *m1, int i_weight );
64
uint64_t x264_rd_cost_part( x264_t *h, int i_lambda2, int i8, int i_pixel );
Laurent Aimar's avatar
Laurent Aimar committed
65

66
extern uint16_t *x264_cost_mv_fpel[92][4];
67

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#define COPY1_IF_LT(x,y)\
if((y)<(x))\
    (x)=(y);

#define COPY2_IF_LT(x,y,a,b)\
if((y)<(x))\
{\
    (x)=(y);\
    (a)=(b);\
}

#define COPY3_IF_LT(x,y,a,b,c,d)\
if((y)<(x))\
{\
    (x)=(y);\
    (a)=(b);\
    (c)=(d);\
}

87 88 89 90 91 92 93 94 95
#define COPY4_IF_LT(x,y,a,b,c,d,f,e)\
if((y)<(x))\
{\
    (x)=(y);\
    (a)=(b);\
    (c)=(d);\
    (f)=(e);\
}

Loren Merritt's avatar
Loren Merritt committed
96 97 98 99 100 101 102
#define COPY2_IF_GT(x,y,a,b)\
if((y)>(x))\
{\
    (x)=(y);\
    (a)=(b);\
}

Laurent Aimar's avatar
Laurent Aimar committed
103
#endif