Commit 5acccbf9 authored by Yi Luo's avatar Yi Luo

Loopfilter bitmask buildup

Change-Id: Icf7902e6f34380ea8f74662260c134e45e14f407
parent 34f94985
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 2 Clause License and
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
* was not distributed with this source code in the LICENSE file, you can
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
* Media Patent License 1.0 was not distributed with this source code in the
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
*/
#ifndef AV1_COMMON_LOOPFILTER_H_
#define AV1_COMMON_LOOPFILTER_H_
#include "aom_ports/mem.h"
#include "./aom_config.h"
#include "av1/common/blockd.h"
#include "av1/common/seg_common.h"
#ifdef __cplusplus
extern "C" {
#endif
#define MAX_LOOP_FILTER 63
#define MAX_SHARPNESS 7
#define SIMD_WIDTH 16
#define MAX_MODE_LF_DELTAS 2
enum lf_path {
LF_PATH_420,
LF_PATH_444,
LF_PATH_SLOW,
};
typedef struct { uint64_t bits[4]; } FilterMaskY;
typedef uint64_t FilterMaskUV;
// This structure holds bit masks for all 8x8 blocks in a 64x64 region.
// Each 1 bit represents a position in which we want to apply the loop filter.
// Left_ entries refer to whether we apply a filter on the border to the
// left of the block. Above_ entries refer to whether or not to apply a
// filter on the above border. Int_ entries refer to whether or not to
// apply borders on the 4x4 edges within the 8x8 block that each bit
// represents.
// Since each transform is accompanied by a potentially different type of
// loop filter there is a different entry in the array for each transform size.
typedef struct {
FilterMaskY left_y[TX_SIZES];
FilterMaskY above_y[TX_SIZES];
FilterMaskUV left_u[TX_SIZES];
FilterMaskUV above_u[TX_SIZES];
FilterMaskUV left_v[TX_SIZES];
FilterMaskUV above_v[TX_SIZES];
// Y plane vertical edge and horizontal edge filter level
uint8_t lfl_y_hor[MAX_MIB_SIZE / 2][MAX_MIB_SIZE / 2];
uint8_t lfl_y_ver[MAX_MIB_SIZE / 2][MAX_MIB_SIZE / 2];
// UV plane vertical edge and horizontal edge shares the same level
uint8_t lfl_u[MAX_MIB_SIZE / 4][MAX_MIB_SIZE / 4];
uint8_t lfl_v[MAX_MIB_SIZE / 4][MAX_MIB_SIZE / 4];
} LoopFilterMask;
// Loopfilter bit mask per super block
#define LOOP_FILTER_MASK_NUM 4
typedef struct {
LoopFilterMask lfm[LOOP_FILTER_MASK_NUM];
int is_setup;
} LpfMask;
struct loopfilter {
LpfMask *lfm;
// Neighbor block information for loopfilter bit mask setup
uint8_t *neighbor;
size_t lfm_num;
int lfm_stride;
unsigned int curr_frame_offset;
unsigned int neighbor_width;
unsigned int neighbor_height;
#if CONFIG_LOOPFILTER_LEVEL
int filter_level[2];
int filter_level_u;
int filter_level_v;
#else
int filter_level;
#endif
int sharpness_level;
int last_sharpness_level;
uint8_t mode_ref_delta_enabled;
uint8_t mode_ref_delta_update;
// 0 = Intra, Last, Last2+Last3,
// GF, BRF, ARF2, ARF
int8_t ref_deltas[TOTAL_REFS_PER_FRAME];
int8_t last_ref_deltas[TOTAL_REFS_PER_FRAME];
// 0 = ZERO_MV, MV
int8_t mode_deltas[MAX_MODE_LF_DELTAS];
int8_t last_mode_deltas[MAX_MODE_LF_DELTAS];
};
// Need to align this structure so when it is declared and
// passed it can be loaded into vector registers.
typedef struct {
DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, mblim[SIMD_WIDTH]);
DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, lim[SIMD_WIDTH]);
DECLARE_ALIGNED(SIMD_WIDTH, uint8_t, hev_thr[SIMD_WIDTH]);
} loop_filter_thresh;
typedef struct {
loop_filter_thresh lfthr[MAX_LOOP_FILTER + 1];
#if CONFIG_LOOPFILTER_LEVEL
uint8_t lvl[MAX_SEGMENTS][2][TOTAL_REFS_PER_FRAME][MAX_MODE_LF_DELTAS];
#else
uint8_t lvl[MAX_SEGMENTS][TOTAL_REFS_PER_FRAME][MAX_MODE_LF_DELTAS];
#endif
} loop_filter_info_n;
/* assorted loopfilter functions which get used elsewhere */
struct AV1Common;
struct macroblockd;
struct AV1LfSyncData;
// This function sets up the bit masks for the entire 64x64 region represented
// by mi_row, mi_col.
void av1_setup_mask(struct AV1Common *const cm, const int mi_row,
const int mi_col, MODE_INFO **mi_4x4,
const int mode_info_stride, LpfMask *lfm);
void av1_filter_block_plane_ss00_ver(struct AV1Common *const cm,
struct macroblockd_plane *const plane,
int mi_row, LoopFilterMask *lfm);
void av1_filter_block_plane_ss00_hor(struct AV1Common *const cm,
struct macroblockd_plane *const plane,
int mi_row, LoopFilterMask *lfm);
void av1_filter_block_plane_ss11_u_ver(struct AV1Common *const cm,
struct macroblockd_plane *const plane,
int mi_row, LoopFilterMask *lfm);
void av1_filter_block_plane_ss11_u_hor(struct AV1Common *const cm,
struct macroblockd_plane *const plane,
int mi_row, LoopFilterMask *lfm);
void av1_filter_block_plane_ss11_v_ver(struct AV1Common *const cm,
struct macroblockd_plane *const plane,
int mi_row, LoopFilterMask *lfm);
void av1_filter_block_plane_ss11_v_hor(struct AV1Common *const cm,
struct macroblockd_plane *const plane,
int mi_row, LoopFilterMask *lfm);
void av1_filter_block_plane_non420_ver(struct AV1Common *const cm,
struct macroblockd_plane *plane,
MODE_INFO **mi_8x8, int mi_row,
int mi_col, int pl);
void av1_filter_block_plane_non420_hor(struct AV1Common *const cm,
struct macroblockd_plane *plane,
MODE_INFO **mi_8x8, int mi_row,
int mi_col, int pl);
void av1_loop_filter_init(struct AV1Common *cm);
// Update the loop filter for the current frame.
// This should be called before av1_loop_filter_rows(),
// av1_loop_filter_frame()
// calls this function directly.
void av1_loop_filter_frame_init(struct AV1Common *cm, int default_filt_lvl,
int default_filt_lvl_r
#if CONFIG_LOOPFILTER_LEVEL
,
int plane
#endif
);
void av1_loop_filter_frame(YV12_BUFFER_CONFIG *frame, struct AV1Common *cm,
struct macroblockd *mbd, int filter_level,
#if CONFIG_LOOPFILTER_LEVEL
int filter_level_r,
#endif
int y_only, int partial_frame);
// Apply the loop filter to [start, stop) macro block rows in frame_buffer.
void av1_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer,
struct AV1Common *cm,
struct macroblockd_plane *planes, int start, int stop,
int y_only);
typedef struct LoopFilterWorkerData {
YV12_BUFFER_CONFIG *frame_buffer;
struct AV1Common *cm;
struct macroblockd_plane planes[MAX_MB_PLANE];
int start;
int stop;
int y_only;
} LFWorkerData;
void av1_loop_filter_data_reset(LFWorkerData *lf_data,
YV12_BUFFER_CONFIG *frame_buffer,
struct AV1Common *cm,
const struct macroblockd_plane *planes);
// Operates on the rows described by 'lf_data'.
int av1_loop_filter_worker(LFWorkerData *const lf_data, void *unused);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // AV1_COMMON_LOOPFILTER_H_
#include <stdio.h>
#include <stdint.h>
//----------------------------------------------------------------------------
// Note:
// Establish 64x64 block, contructed by 256 (16x16) 4x4 sub-block.
// Every 4 rows would be represented by one uint64_t mask. Hence,
// there are 4 uint64_t bitmask[4] to represent the whole 64x64.
//
// Given a location by (idx, idy), This function returns the index
// 0, 1, 2, 3 to select which bitmask[] to use.
// Then the pointer y_shift contains the shift value in the bit mask.
// Function returns y_shift; y_index contains the index.
//
int get_y_index_shift(int idx, int idy, int *y_index) {
*y_index = idy >> 4;
const int y_idy = (idy >> 2) % 4;
return (y_idy << 4) + (idx >> 2);
}
// Note:
// For 4:2:0 format sampling, establish 32x32 block, constructed by
// 64 (8x8), 4x4 sub-block. We need one uint64_t bitmask to present
// all edge information
// Function returns uv_shift.
//
int get_uv_index_shift(int idx, int idy) {
return ((idy >> 3) << 3) + (idx >> 3);
}
//----------------------------------------------------------------------------
// AV1 has 4x4 coding block
// I use 4 uint64_t integer to describe block edge information by a bit mask
//
void get_y_shift_value(int size) {
int x, y;
for (y = 0; y < size; y += 4) {
for (x = 0; x < size; x += 4) {
printf("[%02d,%02d] ", x, y);
}
printf("\n");
}
printf("\n");
int v_index;
int y_shift;
for (y = 0; y < size; y += 4) {
for (x = 0; x < size; x += 4) {
// cb8x8
//int shift = ((y >> 3) << 3) + (x >> 3);
//printf("%02d ", shift);
// cb4x4
y_shift = get_y_index_shift(x, y, &v_index);
printf("%02d ", y_shift);
}
printf("Index %d\n", v_index);
}
}
void get_uv_shift_value(int size) {
int x, y;
int uv_shift = 0;
const int step = 4;
for (y = 0; y < size; y += step) {
for (x = 0; x < size; x += step) {
// cb8x8
// int uv_shift = ((y >> 3) << 2) + (x >> 3);
// cb4x4
uv_shift = get_uv_index_shift(x, y);
printf("%02d ", uv_shift);
}
printf("\n");
}
}
//---------------------------------------------------------------------------
int get_uv_shift(int idx, int idy) {
return (((idy - 2) >> 2) << 3) + (idx >> 2);
}
//---------------------------------------------------------------------------
// AV1: AV1=1
// VP9: AV1=0
#define AV1 1
#if AV1
#define MAX_MIB_SIZE_LOG2 (4)
const int num = 16;
typedef struct {
uint64_t bits[4];
} FilterMaskY;
#else
#define MAX_MIB_SIZE_LOG2 (3)
const int num = 8;
#endif
int main() {
get_y_shift_value(64);
printf("\n");
get_uv_shift_value(64);
printf("\n");
int y_index = 0;
const int x = 0;
int y;
int i;
// Remaining rows are 1, 2, ..., num - 1
// VP9 : 1-7
// AV1 : 1-15
for (i = 1; i < num; ++i) {
#if AV1
y = i << 2;
int y_shift = get_y_index_shift(x, y, &y_index);
int uv_shift = get_uv_shift(x >> 1, y >> 1);
printf("[%02d,%02d] index=%d y_shift=%02d uv_shift=%02d mask_y ",
x, y, y_index, y_shift, uv_shift);
FilterMaskY mask = {0, 0, 0, 0};
int j;
for (j = 0; j < y_index; ++j) {
mask.bits[j] = 0xffffffffffffffffULL;
}
mask.bits[y_index] = ((uint64_t)1 << y_shift) - 1;
for (j = 0; j < 4; ++j) {
printf("0x%016llx ", (unsigned long long int)mask.bits[j]);
}
uint64_t mask_uv = (((uint64_t)1 << (uv_shift + 8)) - 1);
if (uv_shift + 8 == 64) mask_uv = 0xffffffffffffffffULL;
printf("mask_uv 0x%016llx", (unsigned long long int)mask_uv);
printf("\n");
#else
const uint64_t mask_y = (((uint64_t)1 << (i << MAX_MIB_SIZE_LOG2)) - 1);
const uint16_t mask_uv =
(((uint16_t)1 << (((i + 1) >> 1) << (MAX_MIB_SIZE_LOG2 - 1))) - 1);
printf("mask_y=%016llx, mask_uv=%04x\n", (long long unsigned int)mask_y, mask_uv);
#endif
}
return 0;
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment