AOMedia AV1 Codec
av1_loopfilter.h
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 
12 #ifndef AOM_AV1_COMMON_AV1_LOOPFILTER_H_
13 #define AOM_AV1_COMMON_AV1_LOOPFILTER_H_
14 
15 #include "config/aom_config.h"
16 
17 #include "aom_ports/mem.h"
18 #include "av1/common/blockd.h"
19 #include "av1/common/seg_common.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 #define MAX_LOOP_FILTER 63
26 #define MAX_SHARPNESS 7
27 
28 #define SIMD_WIDTH 16
29 
30 enum lf_path {
31  LF_PATH_420,
32  LF_PATH_444,
33  LF_PATH_SLOW,
34 };
35 
37 enum { VERT_EDGE = 0, HORZ_EDGE = 1, NUM_EDGE_DIRS } UENUM1BYTE(EDGE_DIR);
38 typedef struct {
39  uint64_t bits[4];
40 } FilterMask;
41 
42 #if CONFIG_LPF_MASK
43 // This structure holds bit masks for all 4x4 blocks in a 64x64 region.
44 // Each 1 bit represents a position in which we want to apply the loop filter.
45 // For Y plane, 4x4 in 64x64 requires 16x16 = 256 bit, therefore we use 4
46 // uint64_t; For U, V plane, for 420 format, plane size is 32x32, thus we use
47 // a uint64_t to represent bitmask.
48 // Left_ entries refer to whether we apply a filter on the border to the
49 // left of the block. Above_ entries refer to whether or not to apply a
50 // filter on the above border.
51 // Since each transform is accompanied by a potentially different type of
52 // loop filter there is a different entry in the array for each transform size.
53 typedef struct {
54  FilterMask left_y[TX_SIZES];
55  FilterMask above_y[TX_SIZES];
56  FilterMask left_u[TX_SIZES];
57  FilterMask above_u[TX_SIZES];
58  FilterMask left_v[TX_SIZES];
59  FilterMask above_v[TX_SIZES];
60 
61  // Y plane vertical edge and horizontal edge filter level
62  uint8_t lfl_y_hor[MI_SIZE_64X64][MI_SIZE_64X64];
63  uint8_t lfl_y_ver[MI_SIZE_64X64][MI_SIZE_64X64];
64 
65  // U plane filter level
66  uint8_t lfl_u_ver[MI_SIZE_64X64][MI_SIZE_64X64];
67  uint8_t lfl_u_hor[MI_SIZE_64X64][MI_SIZE_64X64];
68 
69  // V plane filter level
70  uint8_t lfl_v_ver[MI_SIZE_64X64][MI_SIZE_64X64];
71  uint8_t lfl_v_hor[MI_SIZE_64X64][MI_SIZE_64X64];
72 
73  // other info
74  FilterMask skip;
75  FilterMask is_vert_border;
76  FilterMask is_horz_border;
77  // Y or UV planes, 5 tx sizes: 4x4, 8x8, 16x16, 32x32, 64x64
78  FilterMask tx_size_ver[2][5];
79  FilterMask tx_size_hor[2][5];
80 } LoopFilterMask;
81 #endif // CONFIG_LPF_MASK
82 
83 struct loopfilter {
84  int filter_level[2];
85  int filter_level_u;
86  int filter_level_v;
87 
88  int sharpness_level;
89 
90  uint8_t mode_ref_delta_enabled;
91  uint8_t mode_ref_delta_update;
92 
93  // 0 = Intra, Last, Last2+Last3,
94  // GF, BRF, ARF2, ARF
95  int8_t ref_deltas[REF_FRAMES];
96 
97  // 0 = ZERO_MV, MV
98  int8_t mode_deltas[MAX_MODE_LF_DELTAS];
99 
100  int combine_vert_horz_lf;
101 
102 #if CONFIG_LPF_MASK
103  LoopFilterMask *lfm;
104  size_t lfm_num;
105  int lfm_stride;
106 #endif // CONFIG_LPF_MASK
107 };
108 
109 // Need to align this structure so when it is declared and
110 // passed it can be loaded into vector registers.
111 typedef struct {
112  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
113  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
114  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
115 } loop_filter_thresh;
116 
117 typedef struct {
118  loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
119  uint8_t lvl[MAX_MB_PLANE][MAX_SEGMENTS][2][REF_FRAMES][MAX_MODE_LF_DELTAS];
120 } loop_filter_info_n;
121 
122 typedef struct LoopFilterWorkerData {
123  YV12_BUFFER_CONFIG *frame_buffer;
124  struct AV1Common *cm;
125  struct macroblockd_plane planes[MAX_MB_PLANE];
126  // TODO(Ranjit): When the filter functions are modified to use xd->lossless
127  // add lossless as a member here.
128  MACROBLOCKD *xd;
129 } LFWorkerData;
132 /* assorted loopfilter functions which get used elsewhere */
133 struct AV1Common;
134 struct macroblockd;
135 struct AV1LfSyncData;
136 
137 void av1_loop_filter_init(struct AV1Common *cm);
138 
139 void av1_loop_filter_frame_init(struct AV1Common *cm, int plane_start,
140  int plane_end);
141 
147 #if CONFIG_LPF_MASK
148 void av1_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
149  struct macroblockd *xd, int is_decoding,
150  int plane_start, int plane_end, int partial_frame);
151 #else
152 void av1_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
153  struct macroblockd *xd, int plane_start,
154  int plane_end, int partial_frame);
155 #endif
156 
157 void av1_filter_block_plane_vert(const struct AV1Common *const cm,
158  const MACROBLOCKD *const xd, const int plane,
159  const MACROBLOCKD_PLANE *const plane_ptr,
160  const uint32_t mi_row, const uint32_t mi_col);
161 
162 void av1_filter_block_plane_horz(const struct AV1Common *const cm,
163  const MACROBLOCKD *const xd, const int plane,
164  const MACROBLOCKD_PLANE *const plane_ptr,
165  const uint32_t mi_row, const uint32_t mi_col);
166 
167 uint8_t av1_get_filter_level(const struct AV1Common *cm,
168  const loop_filter_info_n *lfi_n, const int dir_idx,
169  int plane, const MB_MODE_INFO *mbmi);
170 #if CONFIG_LPF_MASK
171 void av1_filter_block_plane_ver(struct AV1Common *const cm,
172  struct macroblockd_plane *const plane_ptr,
173  int pl, int mi_row, int mi_col);
174 
175 void av1_filter_block_plane_hor(struct AV1Common *const cm,
176  struct macroblockd_plane *const plane, int pl,
177  int mi_row, int mi_col);
178 
179 int get_index_shift(int mi_col, int mi_row, int *index);
180 
181 void av1_build_bitmask_vert_info(
182  struct AV1Common *const cm, const struct macroblockd_plane *const plane_ptr,
183  int plane);
184 
185 void av1_build_bitmask_horz_info(
186  struct AV1Common *const cm, const struct macroblockd_plane *const plane_ptr,
187  int plane);
188 
189 void av1_filter_block_plane_bitmask_vert(
190  struct AV1Common *const cm, struct macroblockd_plane *const plane_ptr,
191  int pl, int mi_row, int mi_col);
192 
193 void av1_filter_block_plane_bitmask_horz(
194  struct AV1Common *const cm, struct macroblockd_plane *const plane_ptr,
195  int pl, int mi_row, int mi_col);
196 
197 void av1_store_bitmask_univariant_tx(struct AV1Common *cm, int mi_row,
198  int mi_col, BLOCK_SIZE bsize,
199  MB_MODE_INFO *mbmi);
200 
201 void av1_store_bitmask_other_info(struct AV1Common *cm, int mi_row, int mi_col,
202  BLOCK_SIZE bsize, MB_MODE_INFO *mbmi,
203  int is_horz_coding_block_border,
204  int is_vert_coding_block_border);
205 
206 void av1_store_bitmask_vartx(struct AV1Common *cm, int mi_row, int mi_col,
207  BLOCK_SIZE bsize, TX_SIZE tx_size,
208  MB_MODE_INFO *mbmi);
209 #endif // CONFIG_LPF_MASK
210 
211 #ifdef __cplusplus
212 } // extern "C"
213 #endif
214 
215 #endif // AOM_AV1_COMMON_AV1_LOOPFILTER_H_
void av1_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm, struct macroblockd *xd, int plane_start, int plane_end, int partial_frame)
Apply AV1 loop filter.
YV12 frame buffer data structure.
Definition: yv12config.h:38
Variables related to current coding block.
Definition: blockd.h:568
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:723
Stores the prediction/txfm mode of the current coding block.
Definition: blockd.h:216