#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aom_dsp/aom_dsp_common.h"
#include "aom_dsp/mathutils.h"
#include "aom_dsp/noise_model.h"
#include "aom_dsp/noise_util.h"
#include "aom_mem/aom_mem.h"
#include "aom_ports/mem.h"
#include "aom_scale/yv12config.h"
#define kLowPolyNumParams …
static const int kMaxLag = …;
#define GET_BLOCK_MEAN(INT_TYPE, suffix) …
GET_BLOCK_MEAN(uint8_t, lowbd)
GET_BLOCK_MEAN(uint16_t, highbd)
static inline double get_block_mean(const uint8_t *data, int w, int h,
int stride, int x_o, int y_o,
int block_size, int use_highbd) { … }
#define GET_NOISE_VAR(INT_TYPE, suffix) …
GET_NOISE_VAR(uint8_t, lowbd)
GET_NOISE_VAR(uint16_t, highbd)
static inline double get_noise_var(const uint8_t *data, const uint8_t *denoised,
int w, int h, int stride, int x_o, int y_o,
int block_size_x, int block_size_y,
int use_highbd) { … }
static void equation_system_clear(aom_equation_system_t *eqns) { … }
static void equation_system_copy(aom_equation_system_t *dst,
const aom_equation_system_t *src) { … }
static int equation_system_init(aom_equation_system_t *eqns, int n) { … }
static int equation_system_solve(aom_equation_system_t *eqns) { … }
static void equation_system_add(aom_equation_system_t *dest,
aom_equation_system_t *src) { … }
static void equation_system_free(aom_equation_system_t *eqns) { … }
static void noise_strength_solver_clear(aom_noise_strength_solver_t *solver) { … }
static void noise_strength_solver_add(aom_noise_strength_solver_t *dest,
aom_noise_strength_solver_t *src) { … }
static int num_coeffs(const aom_noise_model_params_t params) { … }
static int noise_state_init(aom_noise_state_t *state, int n, int bit_depth) { … }
static void set_chroma_coefficient_fallback_soln(aom_equation_system_t *eqns) { … }
int aom_noise_strength_lut_init(aom_noise_strength_lut_t *lut, int num_points) { … }
void aom_noise_strength_lut_free(aom_noise_strength_lut_t *lut) { … }
double aom_noise_strength_lut_eval(const aom_noise_strength_lut_t *lut,
double x) { … }
static double noise_strength_solver_get_bin_index(
const aom_noise_strength_solver_t *solver, double value) { … }
static double noise_strength_solver_get_value(
const aom_noise_strength_solver_t *solver, double x) { … }
void aom_noise_strength_solver_add_measurement(
aom_noise_strength_solver_t *solver, double block_mean, double noise_std) { … }
int aom_noise_strength_solver_solve(aom_noise_strength_solver_t *solver) { … }
int aom_noise_strength_solver_init(aom_noise_strength_solver_t *solver,
int num_bins, int bit_depth) { … }
void aom_noise_strength_solver_free(aom_noise_strength_solver_t *solver) { … }
double aom_noise_strength_solver_get_center(
const aom_noise_strength_solver_t *solver, int i) { … }
static void update_piecewise_linear_residual(
const aom_noise_strength_solver_t *solver,
const aom_noise_strength_lut_t *lut, double *residual, int start, int end) { … }
int aom_noise_strength_solver_fit_piecewise(
const aom_noise_strength_solver_t *solver, int max_output_points,
aom_noise_strength_lut_t *lut) { … }
int aom_flat_block_finder_init(aom_flat_block_finder_t *block_finder,
int block_size, int bit_depth, int use_highbd) { … }
void aom_flat_block_finder_free(aom_flat_block_finder_t *block_finder) { … }
void aom_flat_block_finder_extract_block(
const aom_flat_block_finder_t *block_finder, const uint8_t *const data,
int w, int h, int stride, int offsx, int offsy, double *plane,
double *block) { … }
index_and_score_t;
static int compare_scores(const void *a, const void *b) { … }
int aom_flat_block_finder_run(const aom_flat_block_finder_t *block_finder,
const uint8_t *const data, int w, int h,
int stride, uint8_t *flat_blocks) { … }
int aom_noise_model_init(aom_noise_model_t *model,
const aom_noise_model_params_t params) { … }
void aom_noise_model_free(aom_noise_model_t *model) { … }
#define EXTRACT_AR_ROW(INT_TYPE, suffix) …
EXTRACT_AR_ROW(uint8_t, lowbd)
EXTRACT_AR_ROW(uint16_t, highbd)
static int add_block_observations(
aom_noise_model_t *noise_model, int c, const uint8_t *const data,
const uint8_t *const denoised, int w, int h, int stride, int sub_log2[2],
const uint8_t *const alt_data, const uint8_t *const alt_denoised,
int alt_stride, const uint8_t *const flat_blocks, int block_size,
int num_blocks_w, int num_blocks_h) { … }
static void add_noise_std_observations(
aom_noise_model_t *noise_model, int c, const double *coeffs,
const uint8_t *const data, const uint8_t *const denoised, int w, int h,
int stride, int sub_log2[2], const uint8_t *const alt_data, int alt_stride,
const uint8_t *const flat_blocks, int block_size, int num_blocks_w,
int num_blocks_h) { … }
static int is_noise_model_different(aom_noise_model_t *const noise_model) { … }
static int ar_equation_system_solve(aom_noise_state_t *state, int is_chroma) { … }
aom_noise_status_t aom_noise_model_update(
aom_noise_model_t *const noise_model, const uint8_t *const data[3],
const uint8_t *const denoised[3], int w, int h, int stride[3],
int chroma_sub_log2[2], const uint8_t *const flat_blocks, int block_size) { … }
void aom_noise_model_save_latest(aom_noise_model_t *noise_model) { … }
int aom_noise_model_get_grain_parameters(aom_noise_model_t *const noise_model,
aom_film_grain_t *film_grain) { … }
static void pointwise_multiply(const float *a, float *b, int n) { … }
static float *get_half_cos_window(int block_size) { … }
#define DITHER_AND_QUANTIZE(INT_TYPE, suffix) …
DITHER_AND_QUANTIZE(uint8_t, lowbd)
DITHER_AND_QUANTIZE(uint16_t, highbd)
int aom_wiener_denoise_2d(const uint8_t *const data[3], uint8_t *denoised[3],
int w, int h, int stride[3], int chroma_sub[2],
float *noise_psd[3], int block_size, int bit_depth,
int use_highbd) { … }
struct aom_denoise_and_model_t { … };
struct aom_denoise_and_model_t *aom_denoise_and_model_alloc(int bit_depth,
int block_size,
float noise_level) { … }
void aom_denoise_and_model_free(struct aom_denoise_and_model_t *ctx) { … }
static int denoise_and_model_realloc_if_necessary(
struct aom_denoise_and_model_t *ctx, const YV12_BUFFER_CONFIG *sd) { … }
int aom_denoise_and_model_run(struct aom_denoise_and_model_t *ctx,
const YV12_BUFFER_CONFIG *sd,
aom_film_grain_t *film_grain, int apply_denoise) { … }