Coverage Report

Created: 2022-08-24 06:15

/src/x265/source/common/mv.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * Copyright (C) 2013-2020 MulticoreWare, Inc
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_MV_H
25
#define X265_MV_H
26
27
#include "common.h"
28
#include "primitives.h"
29
30
namespace X265_NS {
31
// private x265 namespace
32
33
#if _MSC_VER
34
#pragma warning(disable: 4201) // non-standard extension used (nameless struct/union)
35
#endif
36
37
struct MV
38
{
39
public:
40
41
    union {
42
        struct { int32_t x, y; };
43
44
        int64_t word;
45
    };
46
47
106M
    MV()                                       {}
48
45.6k
    MV(int64_t w) : word(w)                    {}
49
98
    MV(int32_t _x, int32_t _y) : x(_x), y(_y)  {}
50
51
0
    MV& operator =(uint64_t w)                 { word = w; return *this; }
52
53
0
    MV& operator +=(const MV& other)           { x += other.x; y += other.y; return *this; }
54
55
0
    MV& operator -=(const MV& other)           { x -= other.x; y -= other.y; return *this; }
56
57
0
    MV& operator >>=(int i)                    { x >>= i; y >>= i; return *this; }
58
59
#if USING_FTRAPV
60
    /* avoid signed left-shifts when -ftrapv is enabled */
61
    MV& operator <<=(int i)                    { x *= (1 << i); y *= (1 << i); return *this; }
62
    MV operator <<(int i) const                { return MV(x * (1 << i), y * (1 << i)); }
63
#else
64
0
    MV& operator <<=(int i)                    { x <<= i; y <<= i; return *this; }
65
0
    MV operator <<(int i) const                { return MV(x << i, y << i); }
66
#endif
67
68
0
    MV operator >>(int i) const                { return MV(x >> i, y >> i); }
69
70
0
    MV operator *(int32_t i) const             { return MV(x * i, y * i); }
71
72
0
    MV operator -(const MV& other) const       { return MV(x - other.x, y - other.y); }
73
74
0
    MV operator +(const MV& other) const       { return MV(x + other.x, y + other.y); }
75
76
0
    bool operator ==(const MV& other) const    { return word == other.word; }
77
78
0
    bool operator !=(const MV& other) const    { return word != other.word; }
79
80
0
    bool operator !() const                    { return !word; }
81
82
    // Scale down a QPEL mv to FPEL mv, rounding up by one HPEL offset
83
0
    MV roundToFPel() const                     { return MV((x + 2) >> 2, (y + 2) >> 2); }
84
85
    // Scale up an FPEL mv to QPEL by shifting up two bits
86
0
    MV toQPel() const                          { return *this << 2; }
87
88
0
    bool inline notZero() const                { return this->word != 0; }
89
90
0
    bool inline isSubpel() const               { return (this->word & 0x0000000300000003ll) != 0; }
91
92
0
    MV mvmin(const MV& m) const                { return MV(x > m.x ? m.x : x, y > m.y ? m.y : y); }
93
94
0
    MV mvmax(const MV& m) const                { return MV(x < m.x ? m.x : x, y < m.y ? m.y : y); }
95
96
    MV clipped(const MV& _min, const MV& _max) const
97
0
    {
98
0
        MV cl = mvmin(_max);
99
100
0
        return cl.mvmax(_min);
101
0
    }
102
103
    // returns true if MV is within range (inclusive)
104
    bool checkRange(const MV& _min, const MV& _max) const
105
0
    {
106
0
        return x >= _min.x && x <= _max.x && y >= _min.y && y <= _max.y;
107
0
    }
108
};
109
}
110
111
#endif // ifndef X265_MV_H