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_loop_filter_init(struct VP9Common *cm);
102 // Update the loop filter for the current frame.
103 // This should be called before vp9_loop_filter_rows(), vp9_loop_filter_frame()
104 // calls this function directly.
105 void vp9_loop_filter_frame_init(struct VP9Common *cm, int default_filt_lvl);
107 void vp9_loop_filter_frame(struct VP9Common *cm,
108 struct macroblockd *mbd,
110 int y_only, int partial_frame);
112 // Apply the loop filter to [start, stop) macro block rows in frame_buffer.
113 void vp9_loop_filter_rows(const YV12_BUFFER_CONFIG *frame_buffer,
114 struct VP9Common *cm, struct macroblockd *xd,
115 int start, int stop, int y_only);
117 typedef struct LoopFilterWorkerData {
118 const YV12_BUFFER_CONFIG *frame_buffer;
119 struct VP9Common *cm;
120 struct macroblockd xd; // TODO(jzern): most of this is unnecessary to the
121 // loopfilter. the planes are necessary as their state
122 // is changed during decode.
127 struct VP9LfSyncData *lf_sync;
131 // Operates on the rows described by LFWorkerData passed as 'arg1'.
132 int vp9_loop_filter_worker(void *arg1, void *arg2);
137 #endif // VP9_COMMON_VP9_LOOPFILTER_H_