• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 VPX_VP9_COMMON_VP9_LOOPFILTER_H_
12 #define VPX_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   int last_filt_level;
73 
74   int sharpness_level;
75   int last_sharpness_level;
76 
77   uint8_t mode_ref_delta_enabled;
78   uint8_t mode_ref_delta_update;
79 
80   // 0 = Intra, Last, GF, ARF
81   signed char ref_deltas[MAX_REF_LF_DELTAS];
82   signed char last_ref_deltas[MAX_REF_LF_DELTAS];
83 
84   // 0 = ZERO_MV, MV
85   signed char mode_deltas[MAX_MODE_LF_DELTAS];
86   signed char last_mode_deltas[MAX_MODE_LF_DELTAS];
87 
88   LOOP_FILTER_MASK *lfm;
89   int lfm_stride;
90 };
91 
92 /* assorted loopfilter functions which get used elsewhere */
93 struct VP9Common;
94 struct macroblockd;
95 struct VP9LfSyncData;
96 
97 // This function sets up the bit masks for the entire 64x64 region represented
98 // by mi_row, mi_col.
99 void vp9_setup_mask(struct VP9Common *const cm, const int mi_row,
100                     const int mi_col, MODE_INFO **mi8x8,
101                     const int mode_info_stride, 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, LOOP_FILTER_MASK *lfm);
106 
107 void vp9_filter_block_plane_ss11(struct VP9Common *const cm,
108                                  struct macroblockd_plane *const plane,
109                                  int mi_row, LOOP_FILTER_MASK *lfm);
110 
111 void vp9_filter_block_plane_non420(struct VP9Common *cm,
112                                    struct macroblockd_plane *plane,
113                                    MODE_INFO **mi_8x8, int mi_row, int mi_col);
114 
115 void vp9_loop_filter_init(struct VP9Common *cm);
116 
117 // Update the loop filter for the current frame.
118 // This should be called before vp9_loop_filter_frame(), vp9_build_mask_frame()
119 // calls this function directly.
120 void vp9_loop_filter_frame_init(struct VP9Common *cm, int default_filt_lvl);
121 
122 void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct VP9Common *cm,
123                            struct macroblockd *xd, int frame_filter_level,
124                            int y_only, int partial_frame);
125 
126 // 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)127 static INLINE LOOP_FILTER_MASK *get_lfm(const struct loopfilter *lf,
128                                         const int mi_row, const int mi_col) {
129   return &lf->lfm[(mi_col >> 3) + ((mi_row >> 3) * lf->lfm_stride)];
130 }
131 
132 void vp9_build_mask(struct VP9Common *cm, const MODE_INFO *mi, int mi_row,
133                     int mi_col, int bw, int bh);
134 void vp9_adjust_mask(struct VP9Common *const cm, const int mi_row,
135                      const int mi_col, LOOP_FILTER_MASK *lfm);
136 void vp9_build_mask_frame(struct VP9Common *cm, int frame_filter_level,
137                           int partial_frame);
138 void vp9_reset_lfm(struct VP9Common *const cm);
139 
140 typedef struct LoopFilterWorkerData {
141   YV12_BUFFER_CONFIG *frame_buffer;
142   struct VP9Common *cm;
143   struct macroblockd_plane planes[MAX_MB_PLANE];
144 
145   int start;
146   int stop;
147   int y_only;
148 } LFWorkerData;
149 
150 void vp9_loop_filter_data_reset(
151     LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
152     struct VP9Common *cm, const struct macroblockd_plane planes[MAX_MB_PLANE]);
153 
154 // Operates on the rows described by 'arg1' (cast to LFWorkerData *).
155 int vp9_loop_filter_worker(void *arg1, void *unused);
156 #ifdef __cplusplus
157 }  // extern "C"
158 #endif
159 
160 #endif  // VPX_VP9_COMMON_VP9_LOOPFILTER_H_
161