• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_COMMON_H_
18 #define LIBGAV1_SRC_DSP_COMMON_H_
19 
20 #include <cstdint>
21 
22 #include "src/dsp/constants.h"
23 #include "src/utils/constants.h"
24 #include "src/utils/memory.h"
25 
26 namespace libgav1 {
27 
28 enum { kSgrStride = kRestorationUnitWidth + 8 };  // anonymous enum
29 
30 // Self guided projection filter.
31 struct SgrProjInfo {
32   int index;
33   int multiplier[2];
34 };
35 
36 struct WienerInfo {
37   static const int kVertical = 0;
38   static const int kHorizontal = 1;
39   int16_t number_leading_zero_coefficients[2];
40   alignas(kMaxAlignment) int16_t filter[2][(kWienerFilterTaps + 1) / 2];
41 };
42 
43 struct RestorationUnitInfo : public MaxAlignedAllocable {
44   LoopRestorationType type;
45   SgrProjInfo sgr_proj_info;
46   WienerInfo wiener_info;
47 };
48 
49 struct SgrBuffer {
50   alignas(kMaxAlignment) uint16_t sum3[4 * kSgrStride];
51   alignas(kMaxAlignment) uint16_t sum5[5 * kSgrStride];
52   alignas(kMaxAlignment) uint32_t square_sum3[4 * kSgrStride];
53   alignas(kMaxAlignment) uint32_t square_sum5[5 * kSgrStride];
54   alignas(kMaxAlignment) uint16_t ma343[4 * kRestorationUnitWidth];
55   alignas(kMaxAlignment) uint16_t ma444[3 * kRestorationUnitWidth];
56   alignas(kMaxAlignment) uint16_t ma565[2 * kRestorationUnitWidth];
57   alignas(kMaxAlignment) uint32_t b343[4 * kRestorationUnitWidth];
58   alignas(kMaxAlignment) uint32_t b444[3 * kRestorationUnitWidth];
59   alignas(kMaxAlignment) uint32_t b565[2 * kRestorationUnitWidth];
60   alignas(kMaxAlignment) uint16_t
61       temp_buffer[12 * (kRestorationUnitHeight + 2)];
62   alignas(kMaxAlignment) uint8_t ma[kSgrStride];  // [0, 255]
63   // b is less than 2^16 for 8-bit. However, making it a template slows down the
64   // C function by 5%. So b is fixed to 32-bit.
65   alignas(kMaxAlignment) uint32_t b[kSgrStride];
66 };
67 
68 union RestorationBuffer {
69   // For self-guided filter.
70   SgrBuffer sgr_buffer;
71   // For wiener filter.
72   // The array |intermediate| in Section 7.17.4, the intermediate results
73   // between the horizontal and vertical filters.
74   alignas(kMaxAlignment) int16_t
75       wiener_buffer[(kRestorationUnitHeight + kWienerFilterTaps - 1) *
76                     kRestorationUnitWidth];
77 };
78 
79 }  // namespace libgav1
80 
81 #endif  // LIBGAV1_SRC_DSP_COMMON_H_
82