• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2020 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_FILM_GRAIN_COMMON_H_
18 #define LIBGAV1_SRC_DSP_FILM_GRAIN_COMMON_H_
19 
20 #include <cstddef>
21 #include <cstdint>
22 #include <memory>
23 #include <type_traits>
24 
25 #include "src/dsp/common.h"
26 #include "src/utils/array_2d.h"
27 #include "src/utils/constants.h"
28 #include "src/utils/cpu.h"
29 
30 namespace libgav1 {
31 
32 template <int bitdepth>
GetGrainMax()33 int GetGrainMax() {
34   return (1 << (bitdepth - 1)) - 1;
35 }
36 
37 template <int bitdepth>
GetGrainMin()38 int GetGrainMin() {
39   return -(1 << (bitdepth - 1));
40 }
41 
GetFilmGrainRandomNumber(int bits,uint16_t * seed)42 inline int GetFilmGrainRandomNumber(int bits, uint16_t* seed) {
43   uint16_t s = *seed;
44   uint16_t bit = (s ^ (s >> 1) ^ (s >> 3) ^ (s >> 12)) & 1;
45   s = (s >> 1) | (bit << 15);
46   *seed = s;
47   return s >> (16 - bits);
48 }
49 
50 enum {
51   kAutoRegressionBorder = 3,
52   // The width of the luma noise array.
53   kLumaWidth = 82,
54   // The height of the luma noise array.
55   kLumaHeight = 73,
56   // The two possible widths of the chroma noise array.
57   kMinChromaWidth = 44,
58   kMaxChromaWidth = 82,
59   // The two possible heights of the chroma noise array.
60   kMinChromaHeight = 38,
61   kMaxChromaHeight = 73,
62   // The scaling lookup table maps bytes to bytes, so only uses 256 elements,
63   // plus one for overflow in 10bit lookups.
64   kScalingLookupTableSize = 257,
65   // Padding is added to the scaling lookup table to permit overwrites by
66   // InitializeScalingLookupTable_NEON.
67   kScalingLookupTablePadding = 6,
68   // Padding is added to each row of the noise image to permit overreads by
69   // BlendNoiseWithImageLuma_NEON and overwrites by WriteOverlapLine8bpp_NEON.
70   kNoiseImagePadding = 7,
71   // Padding is added to the end of the |noise_stripes_| buffer to permit
72   // overreads by WriteOverlapLine8bpp_NEON.
73   kNoiseStripePadding = 7,
74 };  // anonymous enum
75 
76 }  // namespace libgav1
77 
78 #endif  // LIBGAV1_SRC_DSP_FILM_GRAIN_COMMON_H_
79