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