#include <assert.h>
#include <limits.h>
#include <math.h>
#include "config/aom_dsp_rtcd.h"
#include "aom_dsp/aom_dsp_common.h"
#include "aom_scale/yv12config.h"
#include "aom/aom_integer.h"
#include "av1/common/reconinter.h"
#include "av1/encoder/reconinter_enc.h"
#include "av1/encoder/context_tree.h"
#include "av1/encoder/av1_temporal_denoiser.h"
#include "av1/encoder/encoder.h"
#ifdef OUTPUT_YUV_DENOISED
static void make_grayscale(YV12_BUFFER_CONFIG *yuv);
#endif
static int absdiff_thresh(BLOCK_SIZE bs, int increase_denoising) { … }
static int delta_thresh(BLOCK_SIZE bs, int increase_denoising) { … }
static int noise_motion_thresh(BLOCK_SIZE bs, int increase_denoising) { … }
static unsigned int sse_thresh(BLOCK_SIZE bs, int increase_denoising) { … }
static int sse_diff_thresh(BLOCK_SIZE bs, int increase_denoising,
int motion_magnitude) { … }
static int total_adj_weak_thresh(BLOCK_SIZE bs, int increase_denoising) { … }
int av1_denoiser_filter_c(const uint8_t *sig, int sig_stride,
const uint8_t *mc_avg, int mc_avg_stride,
uint8_t *avg, int avg_stride, int increase_denoising,
BLOCK_SIZE bs, int motion_magnitude) { … }
static uint8_t *block_start(uint8_t *framebuf, int stride, int mi_row,
int mi_col) { … }
static AV1_DENOISER_DECISION perform_motion_compensation(
AV1_COMMON *const cm, AV1_DENOISER *denoiser, MACROBLOCK *mb, BLOCK_SIZE bs,
int increase_denoising, int mi_row, int mi_col, PICK_MODE_CONTEXT *ctx,
int motion_magnitude, int *zeromv_filter, int num_spatial_layers, int width,
int lst_fb_idx, int gld_fb_idx, int use_svc, int spatial_layer,
int use_gf_temporal_ref) { … }
void av1_denoiser_denoise(AV1_COMP *cpi, MACROBLOCK *mb, int mi_row, int mi_col,
BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx,
AV1_DENOISER_DECISION *denoiser_decision,
int use_gf_temporal_ref) { … }
static void copy_frame(YV12_BUFFER_CONFIG *const dest,
const YV12_BUFFER_CONFIG *const src) { … }
static void swap_frame_buffer(YV12_BUFFER_CONFIG *const dest,
YV12_BUFFER_CONFIG *const src) { … }
void av1_denoiser_update_frame_info(
AV1_DENOISER *denoiser, YV12_BUFFER_CONFIG src, struct RTC_REF *rtc_ref,
struct SVC *svc, FRAME_TYPE frame_type, int refresh_alt_ref_frame,
int refresh_golden_frame, int refresh_last_frame, int alt_fb_idx,
int gld_fb_idx, int lst_fb_idx, int resized,
int svc_refresh_denoiser_buffers, int second_spatial_layer) { … }
void av1_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx) { … }
void av1_denoiser_update_frame_stats(MB_MODE_INFO *mi, int64_t sse,
PREDICTION_MODE mode,
PICK_MODE_CONTEXT *ctx) { … }
static int av1_denoiser_realloc_svc_helper(AV1_COMMON *cm,
AV1_DENOISER *denoiser, int fb_idx) { … }
int av1_denoiser_realloc_svc(AV1_COMMON *cm, AV1_DENOISER *denoiser,
struct RTC_REF *rtc_ref, struct SVC *svc,
int svc_buf_shift, int refresh_alt,
int refresh_gld, int refresh_lst, int alt_fb_idx,
int gld_fb_idx, int lst_fb_idx) { … }
int av1_denoiser_alloc(AV1_COMMON *cm, struct SVC *svc, AV1_DENOISER *denoiser,
int use_svc, int noise_sen, int width, int height,
int ssx, int ssy, int use_highbitdepth, int border) { … }
void av1_denoiser_free(AV1_DENOISER *denoiser) { … }
#if 0
static void force_refresh_longterm_ref(AV1_COMP *const cpi) {
SVC *const svc = &cpi->svc;
if (svc->use_gf_temporal_ref_current_layer) {
int index = svc->spatial_layer_id;
if (svc->number_spatial_layers == 3) index = svc->spatial_layer_id - 1;
assert(index >= 0);
cpi->alt_fb_idx = svc->buffer_gf_temporal_ref[index].idx;
cpi->refresh_alt_ref_frame = 1;
}
}
#endif
void av1_denoiser_set_noise_level(AV1_COMP *const cpi, int noise_level) { … }
int64_t av1_scale_part_thresh(int64_t threshold, AV1_DENOISER_LEVEL noise_level,
CONTENT_STATE_SB content_state,
int temporal_layer_id) { … }
int64_t av1_scale_acskip_thresh(int64_t threshold,
AV1_DENOISER_LEVEL noise_level, int abs_sumdiff,
int temporal_layer_id) { … }
void av1_denoiser_reset_on_first_frame(AV1_COMP *const cpi) { … }
void av1_denoiser_update_ref_frame(AV1_COMP *const cpi) { … }
#ifdef OUTPUT_YUV_DENOISED
static void make_grayscale(YV12_BUFFER_CONFIG *yuv) {
int r, c;
uint8_t *u = yuv->u_buffer;
uint8_t *v = yuv->v_buffer;
for (r = 0; r < yuv->uv_height; ++r) {
for (c = 0; c < yuv->uv_width; ++c) {
u[c] = UINT8_MAX / 2;
v[c] = UINT8_MAX / 2;
}
u += yuv->uv_stride;
v += yuv->uv_stride;
}
}
void aom_write_yuv_frame(FILE *yuv_file, YV12_BUFFER_CONFIG *s) {
unsigned char *src = s->y_buffer;
int h = s->y_crop_height;
do {
fwrite(src, s->y_width, 1, yuv_file);
src += s->y_stride;
} while (--h);
src = s->u_buffer;
h = s->uv_crop_height;
do {
fwrite(src, s->uv_width, 1, yuv_file);
src += s->uv_stride;
} while (--h);
src = s->v_buffer;
h = s->uv_crop_height;
do {
fwrite(src, s->uv_width, 1, yuv_file);
src += s->uv_stride;
} while (--h);
}
#endif