av1_loopfilter.h 7.33 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

Yaowu Xu's avatar
Yaowu Xu committed
12 13
#ifndef AV1_COMMON_LOOPFILTER_H_
#define AV1_COMMON_LOOPFILTER_H_
Jingning Han's avatar
Jingning Han committed
14

15
#include "aom_ports/mem.h"
Yaowu Xu's avatar
Yaowu Xu committed
16
#include "./aom_config.h"
Jingning Han's avatar
Jingning Han committed
17

18 19
#include "av1/common/blockd.h"
#include "av1/common/seg_common.h"
Jingning Han's avatar
Jingning Han committed
20 21 22 23 24 25 26 27 28 29

#ifdef __cplusplus
extern "C" {
#endif

#define MAX_LOOP_FILTER 63
#define MAX_SHARPNESS 7

#define SIMD_WIDTH 16

clang-format's avatar
clang-format committed
30
#define MAX_MODE_LF_DELTAS 2
Jingning Han's avatar
Jingning Han committed
31 32 33 34 35 36 37 38

enum lf_path {
  LF_PATH_420,
  LF_PATH_444,
  LF_PATH_SLOW,
};

struct loopfilter {
Cheng Chen's avatar
Cheng Chen committed
39
#if CONFIG_LOOPFILTER_LEVEL
40
  int filter_level[2];
41 42
  int filter_level_u;
  int filter_level_v;
43 44
#else
  int filter_level;
45
#endif
Jingning Han's avatar
Jingning Han committed
46 47 48 49 50 51 52

  int sharpness_level;
  int last_sharpness_level;

  uint8_t mode_ref_delta_enabled;
  uint8_t mode_ref_delta_update;

53 54
  // 0 = Intra, Last, Last2+Last3,
  // GF, BRF, ARF2, ARF
55 56
  int8_t ref_deltas[TOTAL_REFS_PER_FRAME];
  int8_t last_ref_deltas[TOTAL_REFS_PER_FRAME];
Jingning Han's avatar
Jingning Han committed
57 58

  // 0 = ZERO_MV, MV
59 60
  int8_t mode_deltas[MAX_MODE_LF_DELTAS];
  int8_t last_mode_deltas[MAX_MODE_LF_DELTAS];
Jingning Han's avatar
Jingning Han committed
61 62 63 64 65 66 67 68 69 70 71 72
};

// Need to align this structure so when it is declared and
// passed it can be loaded into vector registers.
typedef struct {
  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
  DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
} loop_filter_thresh;

typedef struct {
  loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
Cheng Chen's avatar
Cheng Chen committed
73
#if CONFIG_LOOPFILTER_LEVEL
74 75
  uint8_t lvl[MAX_SEGMENTS][2][TOTAL_REFS_PER_FRAME][MAX_MODE_LF_DELTAS];
#else
76
  uint8_t lvl[MAX_SEGMENTS][TOTAL_REFS_PER_FRAME][MAX_MODE_LF_DELTAS];
77
#endif
Jingning Han's avatar
Jingning Han committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
} loop_filter_info_n;

// This structure holds bit masks for all 8x8 blocks in a 64x64 region.
// Each 1 bit represents a position in which we want to apply the loop filter.
// Left_ entries refer to whether we apply a filter on the border to the
// left of the block.   Above_ entries refer to whether or not to apply a
// filter on the above border.   Int_ entries refer to whether or not to
// apply borders on the 4x4 edges within the 8x8 block that each bit
// represents.
// Since each transform is accompanied by a potentially different type of
// loop filter there is a different entry in the array for each transform size.
typedef struct {
  uint64_t left_y[TX_SIZES];
  uint64_t above_y[TX_SIZES];
  uint64_t int_4x4_y;
  uint16_t left_uv[TX_SIZES];
  uint16_t above_uv[TX_SIZES];
95 96
  uint16_t left_int_4x4_uv;
  uint16_t above_int_4x4_uv;
97 98
  uint8_t lfl_y[MAX_MIB_SIZE][MAX_MIB_SIZE];
  uint8_t lfl_uv[MAX_MIB_SIZE / 2][MAX_MIB_SIZE / 2];
Jingning Han's avatar
Jingning Han committed
99 100 101
} LOOP_FILTER_MASK;

/* assorted loopfilter functions which get used elsewhere */
Yaowu Xu's avatar
Yaowu Xu committed
102
struct AV1Common;
Jingning Han's avatar
Jingning Han committed
103
struct macroblockd;
Yaowu Xu's avatar
Yaowu Xu committed
104
struct AV1LfSyncData;
Jingning Han's avatar
Jingning Han committed
105 106 107

// This function sets up the bit masks for the entire 64x64 region represented
// by mi_row, mi_col.
Yaowu Xu's avatar
Yaowu Xu committed
108 109 110
void av1_setup_mask(struct AV1Common *const cm, const int mi_row,
                    const int mi_col, MODE_INFO **mi_8x8,
                    const int mode_info_stride, LOOP_FILTER_MASK *lfm);
Jingning Han's avatar
Jingning Han committed
111

Ryan Lei's avatar
Ryan Lei committed
112 113 114 115 116 117 118 119 120 121 122 123 124
void av1_filter_block_plane_ss00_ver(struct AV1Common *const cm,
                                     struct macroblockd_plane *const plane,
                                     int mi_row, LOOP_FILTER_MASK *lfm);
void av1_filter_block_plane_ss00_hor(struct AV1Common *const cm,
                                     struct macroblockd_plane *const plane,
                                     int mi_row, LOOP_FILTER_MASK *lfm);
void av1_filter_block_plane_ss11_ver(struct AV1Common *const cm,
                                     struct macroblockd_plane *const plane,
                                     int mi_row, LOOP_FILTER_MASK *lfm);
void av1_filter_block_plane_ss11_hor(struct AV1Common *const cm,
                                     struct macroblockd_plane *const plane,
                                     int mi_row, LOOP_FILTER_MASK *lfm);

125
void av1_filter_block_plane_non420_ver(struct AV1Common *const cm,
Ryan Lei's avatar
Ryan Lei committed
126 127
                                       struct macroblockd_plane *plane,
                                       MODE_INFO **mi_8x8, int mi_row,
128
                                       int mi_col, int pl);
129
void av1_filter_block_plane_non420_hor(struct AV1Common *const cm,
Ryan Lei's avatar
Ryan Lei committed
130
                                       struct macroblockd_plane *plane,
131
                                       MODE_INFO **mi_8x8, int mi_row,
132
                                       int mi_col, int pl);
Jingning Han's avatar
Jingning Han committed
133

Yaowu Xu's avatar
Yaowu Xu committed
134
void av1_loop_filter_init(struct AV1Common *cm);
Jingning Han's avatar
Jingning Han committed
135 136

// Update the loop filter for the current frame.
Yaowu Xu's avatar
Yaowu Xu committed
137 138
// This should be called before av1_loop_filter_rows(),
// av1_loop_filter_frame()
Jingning Han's avatar
Jingning Han committed
139
// calls this function directly.
140
void av1_loop_filter_frame_init(struct AV1Common *cm, int default_filt_lvl,
141 142 143 144 145 146
                                int default_filt_lvl_r
#if CONFIG_LOOPFILTER_LEVEL
                                ,
                                int plane
#endif
                                );
Jingning Han's avatar
Jingning Han committed
147

148 149 150
#if CONFIG_LPF_SB
void av1_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
                           struct macroblockd *mbd, int filter_level,
151 152 153
#if CONFIG_LOOPFILTER_LEVEL
                           int frame_filter_level_r,
#endif
154 155 156 157 158 159
                           int y_only, int partial_frame, int mi_row,
                           int mi_col);

// Apply the loop filter to [start, stop) macro block rows in frame_buffer.
void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer,
                          struct AV1Common *cm,
160 161
                          struct macroblockd_plane *planes, int start, int stop,
                          int col_start, int col_end, int y_only);
162 163

void av1_loop_filter_sb_level_init(struct AV1Common *cm, int mi_row, int mi_col,
164 165 166
#if CONFIG_LOOPFILTER_LEVEL
                                   int plane, int dir,
#endif
167
                                   int lvl);
168
#else
Yaowu Xu's avatar
Yaowu Xu committed
169 170
void av1_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
                           struct macroblockd *mbd, int filter_level,
Cheng Chen's avatar
Cheng Chen committed
171
#if CONFIG_LOOPFILTER_LEVEL
172 173
                           int filter_level_r,
#endif
Yaowu Xu's avatar
Yaowu Xu committed
174
                           int y_only, int partial_frame);
Jingning Han's avatar
Jingning Han committed
175 176

// Apply the loop filter to [start, stop) macro block rows in frame_buffer.
Yaowu Xu's avatar
Yaowu Xu committed
177 178
void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer,
                          struct AV1Common *cm,
179 180
                          struct macroblockd_plane *planes, int start, int stop,
                          int y_only);
181
#endif  // CONFIG_LPF_SB
Jingning Han's avatar
Jingning Han committed
182 183 184

typedef struct LoopFilterWorkerData {
  YV12_BUFFER_CONFIG *frame_buffer;
Yaowu Xu's avatar
Yaowu Xu committed
185
  struct AV1Common *cm;
Jingning Han's avatar
Jingning Han committed
186 187 188 189 190 191 192
  struct macroblockd_plane planes[MAX_MB_PLANE];

  int start;
  int stop;
  int y_only;
} LFWorkerData;

193 194 195 196
void av1_loop_filter_data_reset(LFWorkerData *lf_data,
                                YV12_BUFFER_CONFIG *frame_buffer,
                                struct AV1Common *cm,
                                const struct macroblockd_plane *planes);
Jingning Han's avatar
Jingning Han committed
197 198

// Operates on the rows described by 'lf_data'.
Yaowu Xu's avatar
Yaowu Xu committed
199
int av1_loop_filter_worker(LFWorkerData *const lf_data, void *unused);
Jingning Han's avatar
Jingning Han committed
200 201 202 203
#ifdef __cplusplus
}  // extern "C"
#endif

Yaowu Xu's avatar
Yaowu Xu committed
204
#endif  // AV1_COMMON_LOOPFILTER_H_