/src/x265/source/encoder/bitcost.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_BITCOST_H |
25 | | #define X265_BITCOST_H |
26 | | |
27 | | #include "common.h" |
28 | | #include "threading.h" |
29 | | #include "mv.h" |
30 | | |
31 | | namespace X265_NS { |
32 | | // private x265 namespace |
33 | | |
34 | | class BitCost |
35 | | { |
36 | | public: |
37 | | |
38 | | BitCost() |
39 | 0 | : m_cost_mvx(0) |
40 | 0 | , m_cost_mvy(0) |
41 | 0 | , m_cost(0) |
42 | 0 | , m_mvp(0) |
43 | | , s_bitsizes(NULL) |
44 | 0 | { |
45 | 0 | memset(m_fpelMvCosts, 0, sizeof(m_fpelMvCosts)); |
46 | 0 | memset(s_costs, 0, sizeof(s_costs)); |
47 | 0 | memset(s_fpelMvCosts, 0, sizeof(s_fpelMvCosts)); |
48 | 0 | } |
49 | 0 | ~BitCost() { destroy(); } |
50 | | |
51 | | void setQP(unsigned int qp); |
52 | | |
53 | 0 | void setMVP(const MV& mvp) { m_mvp = mvp; m_cost_mvx = m_cost - mvp.x; m_cost_mvy = m_cost - mvp.y; } |
54 | | |
55 | | // return bit cost of motion vector difference, multiplied by lambda |
56 | 0 | inline uint16_t mvcost(const MV& mv) const { return m_cost_mvx[mv.x] + m_cost_mvy[mv.y]; } |
57 | | |
58 | | // return bit cost of motion vector difference, without lambda |
59 | | inline uint32_t bitcost(const MV& mv) const |
60 | 0 | { |
61 | 0 | return (uint32_t)(s_bitsizes[mv.x - m_mvp.x] + |
62 | 0 | s_bitsizes[mv.y - m_mvp.y] + 0.5f); |
63 | 0 | } |
64 | | |
65 | | inline uint32_t bitcost(const MV& mv, const MV& mvp) const |
66 | 0 | { |
67 | 0 | return (uint32_t)(s_bitsizes[mv.x - mvp.x] + |
68 | 0 | s_bitsizes[mv.y - mvp.y] + 0.5f); |
69 | 0 | } |
70 | | |
71 | | void destroy(); |
72 | | |
73 | | protected: |
74 | | |
75 | | uint16_t *m_cost_mvx; |
76 | | |
77 | | uint16_t *m_cost_mvy; |
78 | | |
79 | | uint16_t *m_cost; |
80 | | |
81 | | uint16_t *m_fpelMvCosts[4]; |
82 | | |
83 | | MV m_mvp; |
84 | | |
85 | | BitCost& operator =(const BitCost&); |
86 | | |
87 | | private: |
88 | | |
89 | | /* default log2_max_mv_length_horizontal and log2_max_mv_length_horizontal |
90 | | * are 15, specified in quarter-pel luma sample units. making the maximum |
91 | | * signaled ful-pel motion distance 4096, max qpel is 32768 */ |
92 | | enum { BC_MAX_MV = (1 << 15) }; |
93 | | |
94 | | enum { BC_MAX_QP = 82 }; |
95 | | |
96 | | float *s_bitsizes; |
97 | | |
98 | | uint16_t *s_costs[BC_MAX_QP]; |
99 | | |
100 | | uint16_t *s_fpelMvCosts[BC_MAX_QP][4]; |
101 | | |
102 | | Lock s_costCalcLock; |
103 | | |
104 | | void CalculateLogs(); |
105 | | }; |
106 | | } |
107 | | |
108 | | #endif // ifndef X265_BITCOST_H |