1 // Copyright 2019 The libgav1 Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "src/dsp/constants.h" 16 17 #include <cstdint> 18 19 namespace libgav1 { 20 21 // Each set of 7 taps is padded with a 0 to easily align and pack into the high 22 // and low 8 bytes. This way, we can load 16 at a time to fit mulhi and mullo. 23 alignas(16) const int8_t kFilterIntraTaps[kNumFilterIntraPredictors][8][8] = { 24 {{-6, 10, 0, 0, 0, 12, 0, 0}, 25 {-5, 2, 10, 0, 0, 9, 0, 0}, 26 {-3, 1, 1, 10, 0, 7, 0, 0}, 27 {-3, 1, 1, 2, 10, 5, 0, 0}, 28 {-4, 6, 0, 0, 0, 2, 12, 0}, 29 {-3, 2, 6, 0, 0, 2, 9, 0}, 30 {-3, 2, 2, 6, 0, 2, 7, 0}, 31 {-3, 1, 2, 2, 6, 3, 5, 0}}, 32 {{-10, 16, 0, 0, 0, 10, 0, 0}, 33 {-6, 0, 16, 0, 0, 6, 0, 0}, 34 {-4, 0, 0, 16, 0, 4, 0, 0}, 35 {-2, 0, 0, 0, 16, 2, 0, 0}, 36 {-10, 16, 0, 0, 0, 0, 10, 0}, 37 {-6, 0, 16, 0, 0, 0, 6, 0}, 38 {-4, 0, 0, 16, 0, 0, 4, 0}, 39 {-2, 0, 0, 0, 16, 0, 2, 0}}, 40 {{-8, 8, 0, 0, 0, 16, 0, 0}, 41 {-8, 0, 8, 0, 0, 16, 0, 0}, 42 {-8, 0, 0, 8, 0, 16, 0, 0}, 43 {-8, 0, 0, 0, 8, 16, 0, 0}, 44 {-4, 4, 0, 0, 0, 0, 16, 0}, 45 {-4, 0, 4, 0, 0, 0, 16, 0}, 46 {-4, 0, 0, 4, 0, 0, 16, 0}, 47 {-4, 0, 0, 0, 4, 0, 16, 0}}, 48 {{-2, 8, 0, 0, 0, 10, 0, 0}, 49 {-1, 3, 8, 0, 0, 6, 0, 0}, 50 {-1, 2, 3, 8, 0, 4, 0, 0}, 51 {0, 1, 2, 3, 8, 2, 0, 0}, 52 {-1, 4, 0, 0, 0, 3, 10, 0}, 53 {-1, 3, 4, 0, 0, 4, 6, 0}, 54 {-1, 2, 3, 4, 0, 4, 4, 0}, 55 {-1, 2, 2, 3, 4, 3, 3, 0}}, 56 {{-12, 14, 0, 0, 0, 14, 0, 0}, 57 {-10, 0, 14, 0, 0, 12, 0, 0}, 58 {-9, 0, 0, 14, 0, 11, 0, 0}, 59 {-8, 0, 0, 0, 14, 10, 0, 0}, 60 {-10, 12, 0, 0, 0, 0, 14, 0}, 61 {-9, 1, 12, 0, 0, 0, 12, 0}, 62 {-8, 0, 0, 12, 0, 1, 11, 0}, 63 {-7, 0, 0, 1, 12, 1, 9, 0}}}; 64 65 // A lookup table replacing the calculation of the variable s in Section 7.17.3 66 // (Box filter process). The first index is sgr_proj_index (the lr_sgr_set 67 // syntax element in the Spec, saved in the sgr_proj_info.index field of a 68 // RestorationUnitInfo struct). The second index is pass (0 or 1). 69 // 70 // const uint8_t scale = kSgrProjParams[sgr_proj_index][pass * 2 + 1]; 71 // const uint32_t n2_with_scale = n * n * scale; 72 // const uint32_t s = 73 // ((1 << kSgrProjScaleBits) + (n2_with_scale >> 1)) / n2_with_scale; 74 // 0 is an invalid value, corresponding to radius = 0, where the filter is 75 // skipped. 76 const uint16_t kSgrScaleParameter[16][2] = { 77 {140, 3236}, {112, 2158}, {93, 1618}, {80, 1438}, {70, 1295}, {58, 1177}, 78 {47, 1079}, {37, 996}, {30, 925}, {25, 863}, {0, 2589}, {0, 1618}, 79 {0, 1177}, {0, 925}, {56, 0}, {22, 0}, 80 }; 81 82 const uint8_t kCdefPrimaryTaps[2][2] = {{4, 2}, {3, 3}}; 83 84 // This is Cdef_Directions (section 7.15.3) with 2 padding entries at the 85 // beginning and end of the table. The cdef direction range is [0, 7] and the 86 // first index is offset +/-2. This removes the need to constrain the first 87 // index to the same range using e.g., & 7. 88 const int8_t kCdefDirectionsPadded[12][2][2] = { 89 {{1, 0}, {2, 0}}, // Padding: Cdef_Directions[6] 90 {{1, 0}, {2, -1}}, // Padding: Cdef_Directions[7] 91 {{-1, 1}, {-2, 2}}, // Begin Cdef_Directions 92 {{0, 1}, {-1, 2}}, // 93 {{0, 1}, {0, 2}}, // 94 {{0, 1}, {1, 2}}, // 95 {{1, 1}, {2, 2}}, // 96 {{1, 0}, {2, 1}}, // 97 {{1, 0}, {2, 0}}, // 98 {{1, 0}, {2, -1}}, // End Cdef_Directions 99 {{-1, 1}, {-2, 2}}, // Padding: Cdef_Directions[0] 100 {{0, 1}, {-1, 2}}, // Padding: Cdef_Directions[1] 101 }; 102 103 } // namespace libgav1 104