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 struct loopfilter { 33 int filter_level; 34 35 int sharpness_level; 36 int last_sharpness_level; 37 38 uint8_t mode_ref_delta_enabled; 39 uint8_t mode_ref_delta_update; 40 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]; 44 45 // 0 = ZERO_MV, MV 46 signed char mode_deltas[MAX_MODE_LF_DELTAS]; 47 signed char last_mode_deltas[MAX_MODE_LF_DELTAS]; 48 }; 49 50 // Need to align this structure so when it is declared and 51 // passed it can be loaded into vector registers. 52 typedef struct { 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]); 56 } loop_filter_thresh; 57 58 typedef struct { 59 loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1]; 60 uint8_t lvl[MAX_SEGMENTS][MAX_REF_FRAMES][MAX_MODE_LF_DELTAS]; 61 } loop_filter_info_n; 62 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 69 // represents. 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. 72 typedef struct { 73 uint64_t left_y[TX_SIZES]; 74 uint64_t above_y[TX_SIZES]; 75 uint64_t int_4x4_y; 76 uint16_t left_uv[TX_SIZES]; 77 uint16_t above_uv[TX_SIZES]; 78 uint16_t int_4x4_uv; 79 uint8_t lfl_y[64]; 80 uint8_t lfl_uv[16]; 81 } LOOP_FILTER_MASK; 82 83 /* assorted loopfilter functions which get used elsewhere */ 84 struct VP9Common; 85 struct macroblockd; 86 struct VP9LfSyncData; 87 88 // This function sets up the bit masks for the entire 64x64 region represented 89 // by mi_row, mi_col. 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); 94 95 void vp9_filter_block_plane(struct VP9Common *const cm, 96 struct macroblockd_plane *const plane, 97 int mi_row, 98 LOOP_FILTER_MASK *lfm); 99 100 void vp9_loop_filter_init(struct VP9Common *cm); 101 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); 106 107 void vp9_loop_filter_frame(YV12_BUFFER_CONFIG *frame, 108 struct VP9Common *cm, 109 struct macroblockd *mbd, 110 int filter_level, 111 int y_only, int partial_frame); 112 113 // Apply the loop filter to [start, stop) macro block rows in frame_buffer. 114 void vp9_loop_filter_rows(const YV12_BUFFER_CONFIG *frame_buffer, 115 struct VP9Common *cm, 116 struct macroblockd_plane planes[MAX_MB_PLANE], 117 int start, int stop, int y_only); 118 119 typedef struct LoopFilterWorkerData { 120 const YV12_BUFFER_CONFIG *frame_buffer; 121 struct VP9Common *cm; 122 struct macroblockd_plane planes[MAX_MB_PLANE]; 123 124 int start; 125 int stop; 126 int y_only; 127 128 struct VP9LfSyncData *lf_sync; 129 int num_lf_workers; 130 } LFWorkerData; 131 132 // Operates on the rows described by LFWorkerData passed as 'arg1'. 133 int vp9_loop_filter_worker(void *arg1, void *arg2); 134 #ifdef __cplusplus 135 } // extern "C" 136 #endif 137 138 #endif // VP9_COMMON_VP9_LOOPFILTER_H_ 139