1 /*****************************************************************************
2 * Copyright (C) 2013 x265 project
4 * Authors: Steve Borho <steve@borho.org>
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.
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.
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.
20 * This program is also available under a commercial proprietary license.
21 * For more information, contact us at license @ x265.com.
22 *****************************************************************************/
28 #include "primitives.h"
31 // private x265 namespace
34 #pragma warning(disable: 4201) // non-standard extension used (nameless struct/union)
42 struct { int16_t x
, y
; };
49 MV(int16_t _x
, int16_t _y
) : x(_x
), y(_y
) {}
51 const MV
& operator =(uint32_t w
) { word
= w
; return *this; }
53 const MV
& operator +=(const MV
& other
) { x
+= other
.x
; y
+= other
.y
; return *this; }
55 const MV
& operator -=(const MV
& other
) { x
-= other
.x
; y
-= other
.y
; return *this; }
57 const MV
& operator >>=(int i
) { x
>>= i
; y
>>= i
; return *this; }
59 const MV
& operator <<=(int i
) { x
<<= i
; y
<<= i
; return *this; }
61 MV
operator >>(int i
) const { return MV(x
>> i
, y
>> i
); }
63 MV
operator <<(int i
) const { return MV(x
<< i
, y
<< i
); }
65 MV
operator *(int16_t i
) const { return MV(x
* i
, y
* i
); }
67 const MV
operator -(const MV
& other
) const { return MV(x
- other
.x
, y
- other
.y
); }
69 const MV
operator +(const MV
& other
) const { return MV(x
+ other
.x
, y
+ other
.y
); }
71 bool operator ==(const MV
& other
) const { return word
== other
.word
; }
73 bool operator !=(const MV
& other
) const { return word
!= other
.word
; }
75 // Scale down a QPEL mv to FPEL mv, rounding up by one HPEL offset
76 MV
roundToFPel() const { return MV(x
+ 2, y
+ 2) >> 2; }
78 // Scale up an FPEL mv to QPEL by shifting up two bits
79 MV
toQPel() const { return *this << 2; }
81 bool inline notZero() const { return this->word
!= 0; }
83 bool inline isSubpel() const { return (this->word
& 0x00030003) != 0; }
85 MV
mvmin(const MV
& m
) const { return MV(x
> m
.x
? m
.x
: x
, y
> m
.y
? m
.y
: y
); }
87 MV
mvmax(const MV
& m
) const { return MV(x
< m
.x
? m
.x
: x
, y
< m
.y
? m
.y
: y
); }
89 MV
clipped(const MV
& _min
, const MV
& _max
) const
93 return cl
.mvmax(_min
);
96 // returns true if MV is within range (inclusive)
97 bool checkRange(const MV
& _min
, const MV
& _max
) const
99 return x
>= _min
.x
&& x
<= _max
.x
&& y
>= _min
.y
&& y
<= _max
.y
;
104 #endif // ifndef X265_MV_H