Imported Upstream version 1.4+222+hg5f9f7194267b
[deb_x265.git] / source / encoder / motion.h
CommitLineData
72b9787e
JB
1/*****************************************************************************
2 * Copyright (C) 2013 x265 project
3 *
4 * Authors: Steve Borho <steve@borho.org>
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 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
23
24#ifndef X265_MOTIONESTIMATE_H
25#define X265_MOTIONESTIMATE_H
26
27#include "primitives.h"
28#include "reference.h"
29#include "mv.h"
30#include "bitcost.h"
b53f7c52 31#include "yuv.h"
72b9787e
JB
32
33namespace x265 {
34// private x265 namespace
35
36class MotionEstimate : public BitCost
37{
38protected:
39
72b9787e 40 intptr_t blockOffset;
b53f7c52
JB
41
42 int ctuAddr;
43 int absPartIdx; // part index of PU, including CU offset within CTU
44
72b9787e
JB
45 int searchMethod;
46 int subpelRefine;
47
72b9787e
JB
48 int blockwidth;
49 int blockheight;
50
b53f7c52
JB
51 pixelcmp_t sad;
52 pixelcmp_x3_t sad_x3;
53 pixelcmp_x4_t sad_x4;
54 pixelcmp_t satd;
55 pixelcmp_t chromaSatd;
56
72b9787e
JB
57 MotionEstimate& operator =(const MotionEstimate&);
58
59public:
60
61 static const int COST_MAX = 1 << 28;
62
b53f7c52
JB
63 Yuv fencPUYuv;
64 int partEnum;
65 bool bChromaSATD;
72b9787e
JB
66
67 MotionEstimate();
72b9787e
JB
68 ~MotionEstimate();
69
b53f7c52 70 void init(int method, int refine, int csp);
72b9787e
JB
71
72 /* Methods called at slice setup */
73
b53f7c52
JB
74 void setSourcePU(pixel *fencY, intptr_t stride, intptr_t offset, int pwidth, int pheight);
75 void setSourcePU(const Yuv& srcFencYuv, int ctuAddr, int cuPartIdx, int puPartIdx, int pwidth, int pheight);
72b9787e
JB
76
77 /* buf*() and motionEstimate() methods all use cached fenc pixels and thus
78 * require setSourcePU() to be called prior. */
79
b53f7c52 80 inline int bufSAD(const pixel* fref, intptr_t stride) { return sad(fencPUYuv.m_buf[0], FENC_STRIDE, fref, stride); }
72b9787e 81
b53f7c52 82 inline int bufSATD(const pixel* fref, intptr_t stride) { return satd(fencPUYuv.m_buf[0], FENC_STRIDE, fref, stride); }
72b9787e 83
b53f7c52
JB
84 inline int bufChromaSATD(const Yuv& refYuv, int puPartIdx)
85 {
86 return chromaSatd(refYuv.getCbAddr(puPartIdx), refYuv.m_csize, fencPUYuv.m_buf[1], fencPUYuv.m_csize) +
87 chromaSatd(refYuv.getCrAddr(puPartIdx), refYuv.m_csize, fencPUYuv.m_buf[2], fencPUYuv.m_csize);
88 }
72b9787e 89
b53f7c52 90 int motionEstimate(ReferencePlanes* ref, const MV & mvmin, const MV & mvmax, const MV & qmvp, int numCandidates, const MV * mvc, int merange, MV & outQMv);
72b9787e 91
b53f7c52 92 int subpelCompare(ReferencePlanes* ref, const MV &qmv, pixelcmp_t);
72b9787e
JB
93
94protected:
95
96 inline void StarPatternSearch(ReferencePlanes *ref,
97 const MV & mvmin,
98 const MV & mvmax,
99 MV & bmv,
100 int & bcost,
101 int & bPointNr,
102 int & bDistance,
103 int earlyExitIters,
104 int merange);
105};
106}
107
108#endif // ifndef X265_MOTIONESTIMATE_H