blob: ae0ef8a34aa220d664b92df9d0b1ff41b0c13831 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_COMMON_LOOPFILTER_H_
13#define AV1_COMMON_LOOPFILTER_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include "aom_ports/mem.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "./aom_config.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070017
18#include "av1/common/blockd.h"
19#include "av1/common/restoration.h"
20#include "av1/common/seg_common.h"
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#define MAX_LOOP_FILTER 63
27#define MAX_SHARPNESS 7
28
29#define SIMD_WIDTH 16
30
31#define MAX_MODE_LF_DELTAS 2
32
33enum lf_path {
34 LF_PATH_420,
35 LF_PATH_444,
36 LF_PATH_SLOW,
37};
38
39struct loopfilter {
40 int filter_level;
41
42 int sharpness_level;
43 int last_sharpness_level;
44
45 uint8_t mode_ref_delta_enabled;
46 uint8_t mode_ref_delta_update;
47
48 // 0 = Intra, Last, Last2+Last3(CONFIG_EXT_REFS),
49 // GF, BRF(CONFIG_EXT_REFS), ARF
50 signed char ref_deltas[TOTAL_REFS_PER_FRAME];
51 signed char last_ref_deltas[TOTAL_REFS_PER_FRAME];
52
53 // 0 = ZERO_MV, MV
54 signed char mode_deltas[MAX_MODE_LF_DELTAS];
55 signed char last_mode_deltas[MAX_MODE_LF_DELTAS];
56};
57
58// Need to align this structure so when it is declared and
59// passed it can be loaded into vector registers.
60typedef struct {
61 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
62 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
63 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
64} loop_filter_thresh;
65
66typedef struct {
67 loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
68 uint8_t lvl[MAX_SEGMENTS][TOTAL_REFS_PER_FRAME][MAX_MODE_LF_DELTAS];
69} loop_filter_info_n;
70
71// This structure holds bit masks for all 8x8 blocks in a 64x64 region.
72// Each 1 bit represents a position in which we want to apply the loop filter.
73// Left_ entries refer to whether we apply a filter on the border to the
74// left of the block. Above_ entries refer to whether or not to apply a
75// filter on the above border. Int_ entries refer to whether or not to
76// apply borders on the 4x4 edges within the 8x8 block that each bit
77// represents.
78// Since each transform is accompanied by a potentially different type of
79// loop filter there is a different entry in the array for each transform size.
80typedef struct {
81 uint64_t left_y[TX_SIZES];
82 uint64_t above_y[TX_SIZES];
83 uint64_t int_4x4_y;
84 uint16_t left_uv[TX_SIZES];
85 uint16_t above_uv[TX_SIZES];
86 uint16_t left_int_4x4_uv;
87 uint16_t above_int_4x4_uv;
88 uint8_t lfl_y[MAX_MIB_SIZE][MAX_MIB_SIZE];
89 uint8_t lfl_uv[MAX_MIB_SIZE / 2][MAX_MIB_SIZE / 2];
90} LOOP_FILTER_MASK;
91
92/* assorted loopfilter functions which get used elsewhere */
Yaowu Xuf883b422016-08-30 14:01:10 -070093struct AV1Common;
Yaowu Xuc27fc142016-08-22 16:08:15 -070094struct macroblockd;
Yaowu Xuf883b422016-08-30 14:01:10 -070095struct AV1LfSyncData;
Yaowu Xuc27fc142016-08-22 16:08:15 -070096
97// This function sets up the bit masks for the entire 64x64 region represented
98// by mi_row, mi_col.
Yaowu Xuf883b422016-08-30 14:01:10 -070099void av1_setup_mask(struct AV1Common *const cm, const int mi_row,
100 const int mi_col, MODE_INFO **mi_8x8,
101 const int mode_info_stride, LOOP_FILTER_MASK *lfm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700102
Yaowu Xuf883b422016-08-30 14:01:10 -0700103void av1_filter_block_plane_ss00(struct AV1Common *const cm,
104 struct macroblockd_plane *const plane,
105 int mi_row, LOOP_FILTER_MASK *lfm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700106
Yaowu Xuf883b422016-08-30 14:01:10 -0700107void av1_filter_block_plane_ss11(struct AV1Common *const cm,
108 struct macroblockd_plane *const plane,
109 int mi_row, LOOP_FILTER_MASK *lfm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700110
Yaowu Xuf883b422016-08-30 14:01:10 -0700111void av1_filter_block_plane_non420(struct AV1Common *cm,
112 struct macroblockd_plane *plane,
113 MODE_INFO **mi_8x8, int mi_row, int mi_col);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700114
Yaowu Xuf883b422016-08-30 14:01:10 -0700115void av1_loop_filter_init(struct AV1Common *cm);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700116
117// Update the loop filter for the current frame.
Yaowu Xuf883b422016-08-30 14:01:10 -0700118// This should be called before av1_loop_filter_rows(),
119// av1_loop_filter_frame()
Yaowu Xuc27fc142016-08-22 16:08:15 -0700120// calls this function directly.
Yaowu Xuf883b422016-08-30 14:01:10 -0700121void av1_loop_filter_frame_init(struct AV1Common *cm, int default_filt_lvl);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700122
Yaowu Xuf883b422016-08-30 14:01:10 -0700123void av1_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
124 struct macroblockd *mbd, int filter_level,
125 int y_only, int partial_frame);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700126
127// Apply the loop filter to [start, stop) macro block rows in frame_buffer.
Yaowu Xuf883b422016-08-30 14:01:10 -0700128void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer,
129 struct AV1Common *cm,
130 struct macroblockd_plane planes[MAX_MB_PLANE],
131 int start, int stop, int y_only);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700132
133typedef struct LoopFilterWorkerData {
134 YV12_BUFFER_CONFIG *frame_buffer;
Yaowu Xuf883b422016-08-30 14:01:10 -0700135 struct AV1Common *cm;
Yaowu Xuc27fc142016-08-22 16:08:15 -0700136 struct macroblockd_plane planes[MAX_MB_PLANE];
137
138 int start;
139 int stop;
140 int y_only;
141} LFWorkerData;
142
Yaowu Xuf883b422016-08-30 14:01:10 -0700143void av1_loop_filter_data_reset(
Yaowu Xuc27fc142016-08-22 16:08:15 -0700144 LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
Yaowu Xuf883b422016-08-30 14:01:10 -0700145 struct AV1Common *cm, const struct macroblockd_plane planes[MAX_MB_PLANE]);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700146
147// Operates on the rows described by 'lf_data'.
Yaowu Xuf883b422016-08-30 14:01:10 -0700148int av1_loop_filter_worker(LFWorkerData *const lf_data, void *unused);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700149#ifdef __cplusplus
150} // extern "C"
151#endif
152
Yaowu Xuf883b422016-08-30 14:01:10 -0700153#endif // AV1_COMMON_LOOPFILTER_H_