| 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" |
| 31 | #include "yuv.h" |
| 32 | |
| 33 | namespace x265 { |
| 34 | // private x265 namespace |
| 35 | |
| 36 | class MotionEstimate : public BitCost |
| 37 | { |
| 38 | protected: |
| 39 | |
| 40 | intptr_t blockOffset; |
| 41 | |
| 42 | int ctuAddr; |
| 43 | int absPartIdx; // part index of PU, including CU offset within CTU |
| 44 | |
| 45 | int searchMethod; |
| 46 | int subpelRefine; |
| 47 | |
| 48 | int blockwidth; |
| 49 | int blockheight; |
| 50 | |
| 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 | |
| 57 | MotionEstimate& operator =(const MotionEstimate&); |
| 58 | |
| 59 | public: |
| 60 | |
| 61 | static const int COST_MAX = 1 << 28; |
| 62 | |
| 63 | Yuv fencPUYuv; |
| 64 | int partEnum; |
| 65 | bool bChromaSATD; |
| 66 | |
| 67 | MotionEstimate(); |
| 68 | ~MotionEstimate(); |
| 69 | |
| 70 | void init(int method, int refine, int csp); |
| 71 | |
| 72 | /* Methods called at slice setup */ |
| 73 | |
| 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); |
| 76 | |
| 77 | /* buf*() and motionEstimate() methods all use cached fenc pixels and thus |
| 78 | * require setSourcePU() to be called prior. */ |
| 79 | |
| 80 | inline int bufSAD(const pixel* fref, intptr_t stride) { return sad(fencPUYuv.m_buf[0], FENC_STRIDE, fref, stride); } |
| 81 | |
| 82 | inline int bufSATD(const pixel* fref, intptr_t stride) { return satd(fencPUYuv.m_buf[0], FENC_STRIDE, fref, stride); } |
| 83 | |
| 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 | } |
| 89 | |
| 90 | int motionEstimate(ReferencePlanes* ref, const MV & mvmin, const MV & mvmax, const MV & qmvp, int numCandidates, const MV * mvc, int merange, MV & outQMv); |
| 91 | |
| 92 | int subpelCompare(ReferencePlanes* ref, const MV &qmv, pixelcmp_t); |
| 93 | |
| 94 | protected: |
| 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 |