1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #ifndef VP9_COMMON_VP9_LOOPFILTER_H_
12 #define VP9_COMMON_VP9_LOOPFILTER_H_
13
14 #include "vpx_ports/mem.h"
15 #include "./vpx_config.h"
16
17 #include "vp9/common/vp9_blockd.h"
18 #include "vp9/common/vp9_seg_common.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #define MAX_LOOP_FILTER 63
25 #define MAX_SHARPNESS 7
26
27 #define SIMD_WIDTH 16
28
29 #define MAX_REF_LF_DELTAS 4
30 #define MAX_MODE_LF_DELTAS 2
31
32 enum lf_path {
33 LF_PATH_420,
34 LF_PATH_444,
35 LF_PATH_SLOW,
36 };
37
38 // Need to align this structure so when it is declared and
39 // passed it can be loaded into vector registers.
40 typedef struct {
41 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
42 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
43 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
44 } loop_filter_thresh;
45
46 typedef struct {
47 loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
48 uint8_t lvl[MAX_SEGMENTS][MAX_REF_FRAMES][MAX_MODE_LF_DELTAS];
49 } loop_filter_info_n;
50
51 // This structure holds bit masks for all 8x8 blocks in a 64x64 region.
52 // Each 1 bit represents a position in which we want to apply the loop filter.
53 // Left_ entries refer to whether we apply a filter on the border to the
54 // left of the block. Above_ entries refer to whether or not to apply a
55 // filter on the above border. Int_ entries refer to whether or not to
56 // apply borders on the 4x4 edges within the 8x8 block that each bit
57 // represents.
58 // Since each transform is accompanied by a potentially different type of
59 // loop filter there is a different entry in the array for each transform size.
60 typedef struct {
61 uint64_t left_y[TX_SIZES];
62 uint64_t above_y[TX_SIZES];
63 uint64_t int_4x4_y;
64 uint16_t left_uv[TX_SIZES];
65 uint16_t above_uv[TX_SIZES];
66 uint16_t int_4x4_uv;
67 uint8_t lfl_y[64];
68 } LOOP_FILTER_MASK;
69
70 struct loopfilter {
71 int filter_level;
72
73 int sharpness_level;
74 int last_sharpness_level;
75
76 uint8_t mode_ref_delta_enabled;
77 uint8_t mode_ref_delta_update;
78
79 // 0 = Intra, Last, GF, ARF
80 signed char ref_deltas[MAX_REF_LF_DELTAS];
81 signed char last_ref_deltas[MAX_REF_LF_DELTAS];
82
83 // 0 = ZERO_MV, MV
84 signed char mode_deltas[MAX_MODE_LF_DELTAS];
85 signed char last_mode_deltas[MAX_MODE_LF_DELTAS];
86
87 LOOP_FILTER_MASK *lfm;
88 int lfm_stride;
89 };
90
91 /* assorted loopfilter functions which get used elsewhere */
92 struct VP9Common;
93 struct macroblockd;
94 struct VP9LfSyncData;
95
96 // This function sets up the bit masks for the entire 64x64 region represented
97 // by mi_row, mi_col.
98 void vp9_setup_mask(struct VP9Common *const cm,
99 const int mi_row, const int mi_col,
100 MODE_INFO **mi_8x8, const int mode_info_stride,
101 LOOP_FILTER_MASK *lfm);
102
103 void vp9_filter_block_plane_ss00(struct VP9Common *const cm,
104 struct macroblockd_plane *const plane,
105 int mi_row,
106 LOOP_FILTER_MASK *lfm);
107
108 void vp9_filter_block_plane_ss11(struct VP9Common *const cm,
109 struct macroblockd_plane *const plane,
110 int mi_row,
111 LOOP_FILTER_MASK *lfm);
112
113 void vp9_filter_block_plane_non420(struct VP9Common *cm,
114 struct macroblockd_plane *plane,
115 MODE_INFO **mi_8x8,
116 int mi_row, int mi_col);
117
118 void vp9_loop_filter_init(struct VP9Common *cm);
119
120 // Update the loop filter for the current frame.
121 // This should be called before vp9_loop_filter_frame(), vp9_build_mask_frame()
122 // calls this function directly.
123 void vp9_loop_filter_frame_init(struct VP9Common *cm, int default_filt_lvl);
124
125 void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame,
126 struct VP9Common *cm,
127 struct macroblockd *mbd,
128 int filter_level,
129 int y_only, int partial_frame);
130
131 // Get the superblock lfm for a given mi_row, mi_col.
get_lfm(const struct loopfilter * lf,const int mi_row,const int mi_col)132 static INLINE LOOP_FILTER_MASK *get_lfm(const struct loopfilter *lf,
133 const int mi_row, const int mi_col) {
134 return &lf->lfm[(mi_col >> 3) + ((mi_row >> 3) * lf->lfm_stride)];
135 }
136
137 void vp9_build_mask(struct VP9Common *cm, const MB_MODE_INFO *mbmi, int mi_row,
138 int mi_col, int bw, int bh);
139 void vp9_adjust_mask(struct VP9Common *const cm, const int mi_row,
140 const int mi_col, LOOP_FILTER_MASK *lfm);
141 void vp9_build_mask_frame(struct VP9Common *cm, int frame_filter_level,
142 int partial_frame);
143 void vp9_reset_lfm(struct VP9Common *const cm);
144
145 typedef struct LoopFilterWorkerData {
146 YV12_BUFFER_CONFIG *frame_buffer;
147 struct VP9Common *cm;
148 struct macroblockd_plane planes[MAX_MB_PLANE];
149
150 int start;
151 int stop;
152 int y_only;
153 } LFWorkerData;
154
155 void vp9_loop_filter_data_reset(
156 LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
157 struct VP9Common *cm, const struct macroblockd_plane planes[MAX_MB_PLANE]);
158
159 // Operates on the rows described by 'lf_data'.
160 int vp9_loop_filter_worker(LFWorkerData *const lf_data, void *unused);
161 #ifdef __cplusplus
162 } // extern "C"
163 #endif
164
165 #endif // VP9_COMMON_VP9_LOOPFILTER_H_
166