2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
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.
11 #ifndef VP9_COMMON_VP9_LOOPFILTER_H_
12 #define VP9_COMMON_VP9_LOOPFILTER_H_
14 #include "vpx_ports/mem.h"
15 #include "./vpx_config.h"
17 #include "vp9/common/vp9_blockd.h"
18 #include "vp9/common/vp9_seg_common.h"
24 #define MAX_LOOP_FILTER 63
25 #define MAX_SHARPNESS 7
29 #define MAX_REF_LF_DELTAS 4
30 #define MAX_MODE_LF_DELTAS 2
36 int last_sharpness_level;
38 uint8_t mode_ref_delta_enabled;
39 uint8_t mode_ref_delta_update;
41 // 0 = Intra, Last, GF, ARF
42 signed char ref_deltas[MAX_REF_LF_DELTAS];
43 signed char last_ref_deltas[MAX_REF_LF_DELTAS];
46 signed char mode_deltas[MAX_MODE_LF_DELTAS];
47 signed char last_mode_deltas[MAX_MODE_LF_DELTAS];
50 // Need to align this structure so when it is declared and
51 // passed it can be loaded into vector registers.
53 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
54 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
55 DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
59 loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
60 uint8_t lvl[MAX_SEGMENTS][MAX_REF_FRAMES][MAX_MODE_LF_DELTAS];
63 // This structure holds bit masks for all 8x8 blocks in a 64x64 region.
64 // Each 1 bit represents a position in which we want to apply the loop filter.
65 // Left_ entries refer to whether we apply a filter on the border to the
66 // left of the block. Above_ entries refer to whether or not to apply a
67 // filter on the above border. Int_ entries refer to whether or not to
68 // apply borders on the 4x4 edges within the 8x8 block that each bit
70 // Since each transform is accompanied by a potentially different type of
71 // loop filter there is a different entry in the array for each transform size.
73 uint64_t left_y[TX_SIZES];
74 uint64_t above_y[TX_SIZES];
76 uint16_t left_uv[TX_SIZES];
77 uint16_t above_uv[TX_SIZES];
83 /* assorted loopfilter functions which get used elsewhere */
88 // This function sets up the bit masks for the entire 64x64 region represented
90 void vp9_setup_mask(struct VP9Common *const cm,
91 const int mi_row, const int mi_col,
92 MODE_INFO *mi_8x8, const int mode_info_stride,
93 LOOP_FILTER_MASK *lfm);
95 void vp9_filter_block_plane(struct VP9Common *const cm,
96 struct macroblockd_plane *const plane,
98 LOOP_FILTER_MASK *lfm);
100 void vp9_filter_block_plane_non420(struct VP9Common *cm,
101 struct macroblockd_plane *plane,
103 int mi_row, int mi_col);
105 void vp9_loop_filter_init(struct VP9Common *cm);
107 // Update the loop filter for the current frame.
108 // This should be called before vp9_loop_filter_rows(), vp9_loop_filter_frame()
109 // calls this function directly.
110 void vp9_loop_filter_frame_init(struct VP9Common *cm, int default_filt_lvl);
112 void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame,
113 struct VP9Common *cm,
114 struct macroblockd *mbd,
116 int y_only, int partial_frame);
118 // Apply the loop filter to [start, stop) macro block rows in frame_buffer.
119 void vp9_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer,
120 struct VP9Common *cm,
121 struct macroblockd_plane planes[MAX_MB_PLANE],
122 int start, int stop, int y_only);
124 typedef struct LoopFilterWorkerData {
125 YV12_BUFFER_CONFIG *frame_buffer;
126 struct VP9Common *cm;
127 struct macroblockd_plane planes[MAX_MB_PLANE];
134 void vp9_loop_filter_data_reset(
135 LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
136 struct VP9Common *cm, const struct macroblockd_plane planes[MAX_MB_PLANE]);
138 // Operates on the rows described by 'lf_data'.
139 int vp9_loop_filter_worker(LFWorkerData *const lf_data, void *unused);
144 #endif // VP9_COMMON_VP9_LOOPFILTER_H_