• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/obmc.h"
16 
17 #include <cassert>
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "src/dsp/dsp.h"
22 #include "src/utils/common.h"
23 #include "src/utils/constants.h"
24 
25 namespace libgav1 {
26 namespace dsp {
27 namespace {
28 
29 #include "src/dsp/obmc.inc"
30 
31 // 7.11.3.10 (from top samples).
32 template <typename Pixel>
OverlapBlendVertical_C(void * const prediction,const ptrdiff_t prediction_stride,const int width,const int height,const void * const obmc_prediction,const ptrdiff_t obmc_prediction_stride)33 void OverlapBlendVertical_C(void* const prediction,
34                             const ptrdiff_t prediction_stride, const int width,
35                             const int height, const void* const obmc_prediction,
36                             const ptrdiff_t obmc_prediction_stride) {
37   auto* pred = static_cast<Pixel*>(prediction);
38   const ptrdiff_t pred_stride = prediction_stride / sizeof(Pixel);
39   const auto* obmc_pred = static_cast<const Pixel*>(obmc_prediction);
40   const ptrdiff_t obmc_pred_stride = obmc_prediction_stride / sizeof(Pixel);
41   const uint8_t* const mask = kObmcMask + height - 2;
42 
43   for (int y = 0; y < height; ++y) {
44     const uint8_t mask_value = mask[y];
45     for (int x = 0; x < width; ++x) {
46       pred[x] = static_cast<Pixel>(RightShiftWithRounding(
47           mask_value * pred[x] + (64 - mask_value) * obmc_pred[x], 6));
48     }
49     pred += pred_stride;
50     obmc_pred += obmc_pred_stride;
51   }
52 }
53 
54 // 7.11.3.10 (from left samples).
55 template <typename Pixel>
OverlapBlendHorizontal_C(void * const prediction,const ptrdiff_t prediction_stride,const int width,const int height,const void * const obmc_prediction,const ptrdiff_t obmc_prediction_stride)56 void OverlapBlendHorizontal_C(void* const prediction,
57                               const ptrdiff_t prediction_stride,
58                               const int width, const int height,
59                               const void* const obmc_prediction,
60                               const ptrdiff_t obmc_prediction_stride) {
61   auto* pred = static_cast<Pixel*>(prediction);
62   const ptrdiff_t pred_stride = prediction_stride / sizeof(Pixel);
63   const auto* obmc_pred = static_cast<const Pixel*>(obmc_prediction);
64   const ptrdiff_t obmc_pred_stride = obmc_prediction_stride / sizeof(Pixel);
65   const uint8_t* const mask = kObmcMask + width - 2;
66   for (int y = 0; y < height; ++y) {
67     for (int x = 0; x < width; ++x) {
68       const uint8_t mask_value = mask[x];
69       pred[x] = static_cast<Pixel>(RightShiftWithRounding(
70           mask_value * pred[x] + (64 - mask_value) * obmc_pred[x], 6));
71     }
72     pred += pred_stride;
73     obmc_pred += obmc_pred_stride;
74   }
75 }
76 
Init8bpp()77 void Init8bpp() {
78   Dsp* const dsp = dsp_internal::GetWritableDspTable(8);
79   assert(dsp != nullptr);
80 #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
81   dsp->obmc_blend[kObmcDirectionVertical] = OverlapBlendVertical_C<uint8_t>;
82   dsp->obmc_blend[kObmcDirectionHorizontal] = OverlapBlendHorizontal_C<uint8_t>;
83 #else  // !LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
84   static_cast<void>(dsp);
85 #ifndef LIBGAV1_Dsp8bpp_ObmcVertical
86   dsp->obmc_blend[kObmcDirectionVertical] = OverlapBlendVertical_C<uint8_t>;
87 #endif
88 #ifndef LIBGAV1_Dsp8bpp_ObmcHorizontal
89   dsp->obmc_blend[kObmcDirectionHorizontal] = OverlapBlendHorizontal_C<uint8_t>;
90 #endif
91 #endif  // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
92 }
93 
94 #if LIBGAV1_MAX_BITDEPTH >= 10
Init10bpp()95 void Init10bpp() {
96   Dsp* const dsp = dsp_internal::GetWritableDspTable(10);
97   assert(dsp != nullptr);
98 #if LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
99   dsp->obmc_blend[kObmcDirectionVertical] = OverlapBlendVertical_C<uint16_t>;
100   dsp->obmc_blend[kObmcDirectionHorizontal] =
101       OverlapBlendHorizontal_C<uint16_t>;
102 #else  // !LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
103   static_cast<void>(dsp);
104 #ifndef LIBGAV1_Dsp10bpp_ObmcVertical
105   dsp->obmc_blend[kObmcDirectionVertical] = OverlapBlendVertical_C<uint16_t>;
106 #endif
107 #ifndef LIBGAV1_Dsp10bpp_ObmcHorizontal
108   dsp->obmc_blend[kObmcDirectionHorizontal] =
109       OverlapBlendHorizontal_C<uint16_t>;
110 #endif
111 #endif  // LIBGAV1_ENABLE_ALL_DSP_FUNCTIONS
112 }
113 #endif
114 
115 }  // namespace
116 
ObmcInit_C()117 void ObmcInit_C() {
118   Init8bpp();
119 #if LIBGAV1_MAX_BITDEPTH >= 10
120   Init10bpp();
121 #endif
122 }
123 
124 }  // namespace dsp
125 }  // namespace libgav1
126