• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 #ifndef AOM_AV1_ENCODER_PICKRST_H_
12 #define AOM_AV1_ENCODER_PICKRST_H_
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #include "av1/encoder/encoder.h"
19 
20 struct yv12_buffer_config;
21 struct AV1_COMP;
22 
23 static const uint8_t g_shuffle_stats_data[16] = {
24   0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8,
25 };
26 
27 static const uint8_t g_shuffle_stats_highbd_data[32] = {
28   0, 1, 2, 3, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9,
29   0, 1, 2, 3, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9,
30 };
31 
find_average(const uint8_t * src,int h_start,int h_end,int v_start,int v_end,int stride)32 static INLINE uint8_t find_average(const uint8_t *src, int h_start, int h_end,
33                                    int v_start, int v_end, int stride) {
34   uint64_t sum = 0;
35   for (int i = v_start; i < v_end; i++) {
36     for (int j = h_start; j < h_end; j++) {
37       sum += src[i * stride + j];
38     }
39   }
40   uint64_t avg = sum / ((v_end - v_start) * (h_end - h_start));
41   return (uint8_t)avg;
42 }
43 
44 #if CONFIG_AV1_HIGHBITDEPTH
find_average_highbd(const uint16_t * src,int h_start,int h_end,int v_start,int v_end,int stride)45 static INLINE uint16_t find_average_highbd(const uint16_t *src, int h_start,
46                                            int h_end, int v_start, int v_end,
47                                            int stride) {
48   uint64_t sum = 0;
49   for (int i = v_start; i < v_end; i++) {
50     for (int j = h_start; j < h_end; j++) {
51       sum += src[i * stride + j];
52     }
53   }
54   uint64_t avg = sum / ((v_end - v_start) * (h_end - h_start));
55   return (uint16_t)avg;
56 }
57 #endif
58 
59 /*!\brief Algorithm for AV1 loop restoration search and estimation.
60  *
61  * \ingroup in_loop_restoration
62  * This function determines proper restoration filter types and
63  * associated parameters for each restoration unit in a frame.
64  *
65  * \param[in]       sd           Source frame buffer
66  * \param[in,out]   cpi          Top-level encoder structure
67  *
68  * \remark Nothing is returned. Instead, chosen restoration filter
69  * types and parameters are stored per plane in the \c rst_info structure
70  * of type \ref RestorationInfo inside \c cpi->common:
71  * \arg \c rst_info[ \c 0 ]: Chosen parameters for Y plane
72  * \arg \c rst_info[ \c 1 ]: Chosen parameters for U plane if it exists
73  * \arg \c rst_info[ \c 2 ]: Chosen parameters for V plane if it exists
74  * \par
75  * The following fields in each \c rst_info[ \c p], \c p = 0, 1, 2
76  * are populated:
77  * \arg \c rst_info[ \c p ].\c frame_restoration_type
78  * \arg \c rst_info[ \c p ].\c unit_info[ \c u ],
79  * for each \c u in 0, 1, ..., \c n( \c p ) - 1,
80  * where \c n( \c p ) is the number of restoration units in plane \c p.
81  * \par
82  * The following fields in each \c rst_info[ \c p ].\c unit_info[ \c u ],
83  * \c p = 0, 1, 2 and \c u = 0, 1, ..., \c n( \c p ) - 1, of type
84  * \ref RestorationUnitInfo are populated:
85  * \arg \c rst_info[ \c p ].\c unit_info[ \c u ].\c restoration_type
86  * \arg \c rst_info[ \c p ].\c unit_info[ \c u ].\c wiener_info OR
87  *      \c rst_info[ \c p ].\c unit_info[ \c u ].\c sgrproj_info OR
88  *      neither, depending on
89  *      \c rst_info[ \c p ].\c unit_info[ \c u ].\c restoration_type
90  *
91  */
92 void av1_pick_filter_restoration(const YV12_BUFFER_CONFIG *sd, AV1_COMP *cpi);
93 
94 #ifdef __cplusplus
95 }  // extern "C"
96 #endif
97 
98 #endif  // AOM_AV1_ENCODER_PICKRST_H_
99