Merge "Fix high bit depth in vp10 codebase"
[platform/upstream/libvpx.git] / vp10 / common / loopfilter.h
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 "vp10/common/blockd.h"
18 #include "vp10/common/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 struct loopfilter {
39   int filter_level;
40
41   int sharpness_level;
42   int last_sharpness_level;
43
44   uint8_t mode_ref_delta_enabled;
45   uint8_t mode_ref_delta_update;
46
47   // 0 = Intra, Last, GF, ARF
48   signed char ref_deltas[MAX_REF_LF_DELTAS];
49   signed char last_ref_deltas[MAX_REF_LF_DELTAS];
50
51   // 0 = ZERO_MV, MV
52   signed char mode_deltas[MAX_MODE_LF_DELTAS];
53   signed char last_mode_deltas[MAX_MODE_LF_DELTAS];
54 };
55
56 // Need to align this structure so when it is declared and
57 // passed it can be loaded into vector registers.
58 typedef struct {
59   DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
60   DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
61   DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
62 } loop_filter_thresh;
63
64 typedef struct {
65   loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
66   uint8_t lvl[MAX_SEGMENTS][MAX_REF_FRAMES][MAX_MODE_LF_DELTAS];
67 } loop_filter_info_n;
68
69 // This structure holds bit masks for all 8x8 blocks in a 64x64 region.
70 // Each 1 bit represents a position in which we want to apply the loop filter.
71 // Left_ entries refer to whether we apply a filter on the border to the
72 // left of the block.   Above_ entries refer to whether or not to apply a
73 // filter on the above border.   Int_ entries refer to whether or not to
74 // apply borders on the 4x4 edges within the 8x8 block that each bit
75 // represents.
76 // Since each transform is accompanied by a potentially different type of
77 // loop filter there is a different entry in the array for each transform size.
78 typedef struct {
79   uint64_t left_y[TX_SIZES];
80   uint64_t above_y[TX_SIZES];
81   uint64_t int_4x4_y;
82   uint16_t left_uv[TX_SIZES];
83   uint16_t above_uv[TX_SIZES];
84   uint16_t int_4x4_uv;
85   uint8_t lfl_y[64];
86   uint8_t lfl_uv[16];
87 } LOOP_FILTER_MASK;
88
89 /* assorted loopfilter functions which get used elsewhere */
90 struct VP9Common;
91 struct macroblockd;
92 struct VP9LfSyncData;
93
94 // This function sets up the bit masks for the entire 64x64 region represented
95 // by mi_row, mi_col.
96 void vp10_setup_mask(struct VP9Common *const cm,
97                     const int mi_row, const int mi_col,
98                     MODE_INFO **mi_8x8, const int mode_info_stride,
99                     LOOP_FILTER_MASK *lfm);
100
101 void vp10_filter_block_plane_ss00(struct VP9Common *const cm,
102                                  struct macroblockd_plane *const plane,
103                                  int mi_row,
104                                  LOOP_FILTER_MASK *lfm);
105
106 void vp10_filter_block_plane_ss11(struct VP9Common *const cm,
107                                  struct macroblockd_plane *const plane,
108                                  int mi_row,
109                                  LOOP_FILTER_MASK *lfm);
110
111 void vp10_filter_block_plane_non420(struct VP9Common *cm,
112                                    struct macroblockd_plane *plane,
113                                    MODE_INFO **mi_8x8,
114                                    int mi_row, int mi_col);
115
116 void vp10_loop_filter_init(struct VP9Common *cm);
117
118 // Update the loop filter for the current frame.
119 // This should be called before vp10_loop_filter_rows(), vp10_loop_filter_frame()
120 // calls this function directly.
121 void vp10_loop_filter_frame_init(struct VP9Common *cm, int default_filt_lvl);
122
123 void vp10_loop_filter_frame(YV12_BUFFER_CONFIG *frame,
124                            struct VP9Common *cm,
125                            struct macroblockd *mbd,
126                            int filter_level,
127                            int y_only, int partial_frame);
128
129 // Apply the loop filter to [start, stop) macro block rows in frame_buffer.
130 void vp10_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer,
131                           struct VP9Common *cm,
132                           struct macroblockd_plane planes[MAX_MB_PLANE],
133                           int start, int stop, int y_only);
134
135 typedef struct LoopFilterWorkerData {
136   YV12_BUFFER_CONFIG *frame_buffer;
137   struct VP9Common *cm;
138   struct macroblockd_plane planes[MAX_MB_PLANE];
139
140   int start;
141   int stop;
142   int y_only;
143 } LFWorkerData;
144
145 void vp10_loop_filter_data_reset(
146     LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
147     struct VP9Common *cm, const struct macroblockd_plane planes[MAX_MB_PLANE]);
148
149 // Operates on the rows described by 'lf_data'.
150 int vp10_loop_filter_worker(LFWorkerData *const lf_data, void *unused);
151 #ifdef __cplusplus
152 }  // extern "C"
153 #endif
154
155 #endif  // VP9_COMMON_VP9_LOOPFILTER_H_