1 /*
2 * Copyright 2019 The libgav1 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef LIBGAV1_SRC_DSP_WARP_H_
18 #define LIBGAV1_SRC_DSP_WARP_H_
19
20 // Pull in LIBGAV1_DspXXX defines representing the implementation status
21 // of each function. The resulting value of each can be used by each module to
22 // determine whether an implementation is needed at compile time.
23 // IWYU pragma: begin_exports
24
25 // ARM:
26 #include "src/dsp/arm/warp_neon.h"
27
28 // x86:
29 // Note includes should be sorted in logical order avx2/avx/sse4, etc.
30 // The order of includes is important as each tests for a superior version
31 // before setting the base.
32 // clang-format off
33 #include "src/dsp/x86/warp_sse4.h"
34 // clang-format on
35
36 // IWYU pragma: end_exports
37
38 namespace libgav1 {
39 namespace dsp {
40
41 // Section 7.11.3.5.
42 struct WarpFilterParams {
43 int64_t x4;
44 int64_t y4;
45 int ix4;
46 int iy4;
47 };
48
49 // Initializes Dsp::warp. This function is not thread-safe.
50 void WarpInit_C();
51
52 // Section 7.11.3.5.
GetWarpFilterParams(int src_x,int src_y,int subsampling_x,int subsampling_y,const int * warp_params)53 inline WarpFilterParams GetWarpFilterParams(int src_x, int src_y,
54 int subsampling_x,
55 int subsampling_y,
56 const int* warp_params) {
57 WarpFilterParams filter_params;
58 // warp_params[2]/[5] require 17 bits (the others 14). With large resolutions
59 // the result of the multiplication will require 33.
60 const int64_t dst_x = static_cast<int64_t>(src_x) * warp_params[2] +
61 src_y * warp_params[3] + warp_params[0];
62 const int64_t dst_y = src_x * warp_params[4] +
63 static_cast<int64_t>(src_y) * warp_params[5] +
64 warp_params[1];
65 filter_params.x4 = dst_x >> subsampling_x;
66 filter_params.y4 = dst_y >> subsampling_y;
67 filter_params.ix4 =
68 static_cast<int>(filter_params.x4 >> kWarpedModelPrecisionBits);
69 filter_params.iy4 =
70 static_cast<int>(filter_params.y4 >> kWarpedModelPrecisionBits);
71 return filter_params;
72 }
73
74 } // namespace dsp
75 } // namespace libgav1
76
77 #endif // LIBGAV1_SRC_DSP_WARP_H_
78