xref: /aosp_15_r20/external/libgav1/src/motion_vector.h (revision 095378508e87ed692bf8dfeb34008b65b3735891)
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_MOTION_VECTOR_H_
18 #define LIBGAV1_SRC_MOTION_VECTOR_H_
19 
20 #include <algorithm>
21 #include <array>
22 #include <cstdint>
23 
24 #include "src/buffer_pool.h"
25 #include "src/obu_parser.h"
26 #include "src/tile.h"
27 #include "src/utils/array_2d.h"
28 #include "src/utils/constants.h"
29 #include "src/utils/types.h"
30 
31 namespace libgav1 {
32 
IsGlobalMvBlock(const BlockParameters & bp,GlobalMotionTransformationType type)33 constexpr bool IsGlobalMvBlock(const BlockParameters& bp,
34                                GlobalMotionTransformationType type) {
35   return (bp.y_mode == kPredictionModeGlobalMv ||
36           bp.y_mode == kPredictionModeGlobalGlobalMv) &&
37          !IsBlockDimension4(bp.size) &&
38          type > kGlobalMotionTransformationTypeTranslation;
39 }
40 
41 // The |contexts| output parameter may be null. If the caller does not need
42 // the |contexts| output, pass nullptr as the argument.
43 void FindMvStack(const Tile::Block& block, bool is_compound,
44                  MvContexts* contexts);  // 7.10.2
45 
46 void FindWarpSamples(const Tile::Block& block, int* num_warp_samples,
47                      int* num_samples_scanned,
48                      int candidates[kMaxLeastSquaresSamples][4]);  // 7.10.4.
49 
50 // Section 7.9.1 in the spec. But this is done per tile instead of for the whole
51 // frame.
52 void SetupMotionField(
53     const ObuFrameHeader& frame_header, const RefCountedBuffer& current_frame,
54     const std::array<RefCountedBufferPtr, kNumReferenceFrameTypes>&
55         reference_frames,
56     int row4x4_start, int row4x4_end, int column4x4_start, int column4x4_end,
57     TemporalMotionField* motion_field);
58 
59 }  // namespace libgav1
60 
61 #endif  // LIBGAV1_SRC_MOTION_VECTOR_H_
62