/src/vvenc/source/Lib/CommonLib/AffineGradientSearch.cpp
Line | Count | Source |
1 | | /* ----------------------------------------------------------------------------- |
2 | | The copyright in this software is being made available under the Clear BSD |
3 | | License, included below. No patent rights, trademark rights and/or |
4 | | other Intellectual Property Rights other than the copyrights concerning |
5 | | the Software are granted under this license. |
6 | | |
7 | | The Clear BSD License |
8 | | |
9 | | Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors. |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use in source and binary forms, with or without modification, |
13 | | are permitted (subject to the limitations in the disclaimer below) provided that |
14 | | the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the copyright holder nor the names of its |
24 | | contributors may be used to endorse or promote products derived from this |
25 | | software without specific prior written permission. |
26 | | |
27 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY |
28 | | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
29 | | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
31 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
33 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
34 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
35 | | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
36 | | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | | POSSIBILITY OF SUCH DAMAGE. |
39 | | |
40 | | |
41 | | ------------------------------------------------------------------------------------------- */ |
42 | | |
43 | | |
44 | | /** |
45 | | * \file |
46 | | * \brief Implementation of AffineGradientSearch class |
47 | | */ |
48 | | |
49 | | // ==================================================================================================================== |
50 | | // Includes |
51 | | // ==================================================================================================================== |
52 | | |
53 | | #include "AffineGradientSearch.h" |
54 | | |
55 | | namespace vvenc { |
56 | | |
57 | | //! \ingroup CommonLib |
58 | | //! \{ |
59 | | |
60 | | // ==================================================================================================================== |
61 | | // Private member functions |
62 | | // ==================================================================================================================== |
63 | | |
64 | | AffineGradientSearch::AffineGradientSearch( bool enableOpt ) |
65 | 0 | { |
66 | 0 | m_HorizontalSobelFilter = xHorizontalSobelFilter; |
67 | 0 | m_VerticalSobelFilter = xVerticalSobelFilter; |
68 | 0 | m_EqualCoeffComputer[0] = xEqualCoeffComputer<false>; |
69 | 0 | m_EqualCoeffComputer[1] = xEqualCoeffComputer<true>; |
70 | |
|
71 | 0 | #if ENABLE_SIMD_OPT_AFFINE_ME |
72 | 0 | if( enableOpt ) |
73 | 0 | { |
74 | 0 | #ifdef TARGET_SIMD_X86 |
75 | 0 | initAffineGradientSearchX86(); |
76 | 0 | #endif |
77 | | #ifdef TARGET_SIMD_ARM |
78 | | initAffineGradientSearchARM(); |
79 | | #endif |
80 | 0 | } |
81 | 0 | #endif // ENABLE_SIMD_OPT_AFFINE_ME |
82 | 0 | } |
83 | | |
84 | | void AffineGradientSearch::xHorizontalSobelFilter(Pel* const pPred, const int predStride, Pel *const pDerivate, const int derivateBufStride, const int width, const int height) |
85 | 0 | { |
86 | 0 | for (int j = 1; j < height - 1; j++) |
87 | 0 | { |
88 | 0 | for (int k = 1; k < width - 1; k++) |
89 | 0 | { |
90 | 0 | int iCenter = j * predStride + k; |
91 | |
|
92 | 0 | pDerivate[j * derivateBufStride + k] = |
93 | 0 | (pPred[iCenter + 1 - predStride] - |
94 | 0 | pPred[iCenter - 1 - predStride] + |
95 | 0 | (pPred[iCenter + 1] << 1) - |
96 | 0 | (pPred[iCenter - 1] << 1) + |
97 | 0 | pPred[iCenter + 1 + predStride] - |
98 | 0 | pPred[iCenter - 1 + predStride]); |
99 | 0 | } |
100 | 0 | pDerivate[j * derivateBufStride] = pDerivate[j * derivateBufStride + 1]; |
101 | 0 | pDerivate[j * derivateBufStride + width - 1] = pDerivate[j * derivateBufStride + width - 2]; |
102 | 0 | } |
103 | |
|
104 | 0 | pDerivate[0] = pDerivate[derivateBufStride + 1]; |
105 | 0 | pDerivate[width - 1] = pDerivate[derivateBufStride + width - 2]; |
106 | 0 | pDerivate[(height - 1) * derivateBufStride] = pDerivate[(height - 2) * derivateBufStride + 1]; |
107 | 0 | pDerivate[(height - 1) * derivateBufStride + width - 1] = pDerivate[(height - 2) * derivateBufStride + (width - 2)]; |
108 | |
|
109 | 0 | for (int j = 1; j < width - 1; j++) |
110 | 0 | { |
111 | 0 | pDerivate[j] = pDerivate[derivateBufStride + j]; |
112 | 0 | pDerivate[(height - 1) * derivateBufStride + j] = pDerivate[(height - 2) * derivateBufStride + j]; |
113 | 0 | } |
114 | 0 | } |
115 | | |
116 | | void AffineGradientSearch::xVerticalSobelFilter(Pel* const pPred, const int predStride, Pel *const pDerivate, const int derivateBufStride, const int width, const int height) |
117 | 0 | { |
118 | 0 | for (int k = 1; k < width - 1; k++) |
119 | 0 | { |
120 | 0 | for (int j = 1; j < height - 1; j++) |
121 | 0 | { |
122 | 0 | int iCenter = j * predStride + k; |
123 | |
|
124 | 0 | pDerivate[j * derivateBufStride + k] = |
125 | 0 | (pPred[iCenter + predStride - 1] - |
126 | 0 | pPred[iCenter - predStride - 1] + |
127 | 0 | (pPred[iCenter + predStride] << 1) - |
128 | 0 | (pPred[iCenter - predStride] << 1) + |
129 | 0 | pPred[iCenter + predStride + 1] - |
130 | 0 | pPred[iCenter - predStride + 1]); |
131 | 0 | } |
132 | |
|
133 | 0 | pDerivate[k] = pDerivate[derivateBufStride + k]; |
134 | 0 | pDerivate[(height - 1) * derivateBufStride + k] = pDerivate[(height - 2) * derivateBufStride + k]; |
135 | 0 | } |
136 | |
|
137 | 0 | pDerivate[0] = pDerivate[derivateBufStride + 1]; |
138 | 0 | pDerivate[width - 1] = pDerivate[derivateBufStride + width - 2]; |
139 | 0 | pDerivate[(height - 1) * derivateBufStride] = pDerivate[(height - 2) * derivateBufStride + 1]; |
140 | 0 | pDerivate[(height - 1) * derivateBufStride + width - 1] = pDerivate[(height - 2) * derivateBufStride + (width - 2)]; |
141 | |
|
142 | 0 | for (int j = 1; j < height - 1; j++) |
143 | 0 | { |
144 | 0 | pDerivate[j * derivateBufStride] = pDerivate[j * derivateBufStride + 1]; |
145 | 0 | pDerivate[j * derivateBufStride + width - 1] = pDerivate[j * derivateBufStride + width - 2]; |
146 | 0 | } |
147 | 0 | } |
148 | | |
149 | | template<bool b6Param> |
150 | | void AffineGradientSearch::xEqualCoeffComputer(Pel* const pResidue, const int residueStride, Pel **const ppDerivate, const int derivateBufStride, const int width, const int height, int64_t(*pEqualCoeff)[7]) |
151 | 0 | { |
152 | 0 | int affineParamNum = b6Param ? 6 : 4; |
153 | |
|
154 | 0 | for (int j = 0; j != height; j++) |
155 | 0 | { |
156 | 0 | int cy = ((j >> 2) << 2) + 2; |
157 | 0 | for (int k = 0; k != width; k++) |
158 | 0 | { |
159 | 0 | int iC[6]; |
160 | |
|
161 | 0 | int drvIdx = j * derivateBufStride + k; |
162 | 0 | int resIdx = j * residueStride + k; |
163 | 0 | int cx = ((k >> 2) << 2) + 2; |
164 | 0 | if (!b6Param) |
165 | 0 | { |
166 | 0 | iC[0] = ppDerivate[0][drvIdx]; |
167 | 0 | iC[1] = cx * ppDerivate[0][drvIdx] + cy * ppDerivate[1][drvIdx]; |
168 | 0 | iC[2] = ppDerivate[1][drvIdx]; |
169 | 0 | iC[3] = cy * ppDerivate[0][drvIdx] - cx * ppDerivate[1][drvIdx]; |
170 | 0 | } |
171 | 0 | else |
172 | 0 | { |
173 | 0 | iC[0] = ppDerivate[0][drvIdx]; |
174 | 0 | iC[1] = cx * ppDerivate[0][drvIdx]; |
175 | 0 | iC[2] = ppDerivate[1][drvIdx]; |
176 | 0 | iC[3] = cx * ppDerivate[1][drvIdx]; |
177 | 0 | iC[4] = cy * ppDerivate[0][drvIdx]; |
178 | 0 | iC[5] = cy * ppDerivate[1][drvIdx]; |
179 | 0 | } |
180 | 0 | for (int col = 0; col < affineParamNum; col++) |
181 | 0 | { |
182 | 0 | for (int row = 0; row < affineParamNum; row++) |
183 | 0 | { |
184 | 0 | pEqualCoeff[col + 1][row] += (int64_t)iC[col] * iC[row]; |
185 | 0 | } |
186 | 0 | pEqualCoeff[col + 1][affineParamNum] += ((int64_t)iC[col] * pResidue[resIdx]) *(1<< 3); |
187 | 0 | } |
188 | 0 | } |
189 | 0 | } |
190 | 0 | } Unexecuted instantiation: void vvenc::AffineGradientSearch::xEqualCoeffComputer<false>(short*, int, short**, int, int, int, long (*) [7]) Unexecuted instantiation: void vvenc::AffineGradientSearch::xEqualCoeffComputer<true>(short*, int, short**, int, int, int, long (*) [7]) |
191 | | |
192 | | } |
193 | | |
194 | | //! \} |