• 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 + 32 };  // 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   // The following 2 buffers are only used by the C functions. Since SgrBuffer
61   // is smaller than |wiener_buffer| in RestorationBuffer which is an union,
62   // it's OK to always keep the following 2 buffers.
63   alignas(kMaxAlignment) uint8_t ma[kSgrStride];  // [0, 255]
64   // b is less than 2^16 for 8-bit. However, making it a template slows down the
65   // C function by 5%. So b is fixed to 32-bit.
66   alignas(kMaxAlignment) uint32_t b[kSgrStride];
67 };
68 
69 union RestorationBuffer {
70   // For self-guided filter.
71   SgrBuffer sgr_buffer;
72   // For wiener filter.
73   // The array |intermediate| in Section 7.17.4, the intermediate results
74   // between the horizontal and vertical filters.
75   alignas(kMaxAlignment) int16_t
76       wiener_buffer[(kRestorationUnitHeight + kWienerFilterTaps - 1) *
77                     kRestorationUnitWidth];
78 };
79 
80 }  // namespace libgav1
81 
82 #endif  // LIBGAV1_SRC_DSP_COMMON_H_
83