xref: /aosp_15_r20/external/libaom/aom_dsp/noise_util.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2017, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #ifndef AOM_AOM_DSP_NOISE_UTIL_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AOM_DSP_NOISE_UTIL_H_
14*77c1e3ccSAndroid Build Coastguard Worker 
15*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
16*77c1e3ccSAndroid Build Coastguard Worker extern "C" {
17*77c1e3ccSAndroid Build Coastguard Worker #endif  // __cplusplus
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker // aom_noise_tx_t is an abstraction of a transform that is used for denoising.
20*77c1e3ccSAndroid Build Coastguard Worker // It is meant to be lightweight and does hold the transformed data (as
21*77c1e3ccSAndroid Build Coastguard Worker // the user should not be manipulating the transformed data directly).
22*77c1e3ccSAndroid Build Coastguard Worker struct aom_noise_tx_t;
23*77c1e3ccSAndroid Build Coastguard Worker 
24*77c1e3ccSAndroid Build Coastguard Worker // Allocates and returns a aom_noise_tx_t useful for denoising the given
25*77c1e3ccSAndroid Build Coastguard Worker // block_size. The resulting aom_noise_tx_t should be free'd with
26*77c1e3ccSAndroid Build Coastguard Worker // aom_noise_tx_free.
27*77c1e3ccSAndroid Build Coastguard Worker struct aom_noise_tx_t *aom_noise_tx_malloc(int block_size);
28*77c1e3ccSAndroid Build Coastguard Worker void aom_noise_tx_free(struct aom_noise_tx_t *aom_noise_tx);
29*77c1e3ccSAndroid Build Coastguard Worker 
30*77c1e3ccSAndroid Build Coastguard Worker // Transforms the internal data and holds it in the aom_noise_tx's internal
31*77c1e3ccSAndroid Build Coastguard Worker // buffer. For compatibility with existing SIMD implementations, "data" must
32*77c1e3ccSAndroid Build Coastguard Worker // be 32-byte aligned.
33*77c1e3ccSAndroid Build Coastguard Worker void aom_noise_tx_forward(struct aom_noise_tx_t *aom_noise_tx,
34*77c1e3ccSAndroid Build Coastguard Worker                           const float *data);
35*77c1e3ccSAndroid Build Coastguard Worker 
36*77c1e3ccSAndroid Build Coastguard Worker // Filters aom_noise_tx's internal data using the provided noise power spectral
37*77c1e3ccSAndroid Build Coastguard Worker // density. The PSD must be at least block_size * block_size and should be
38*77c1e3ccSAndroid Build Coastguard Worker // populated with a constant or via estimates taken from
39*77c1e3ccSAndroid Build Coastguard Worker // aom_noise_tx_add_energy.
40*77c1e3ccSAndroid Build Coastguard Worker void aom_noise_tx_filter(struct aom_noise_tx_t *aom_noise_tx, const float *psd);
41*77c1e3ccSAndroid Build Coastguard Worker 
42*77c1e3ccSAndroid Build Coastguard Worker // Performs an inverse transform using the internal transform data.
43*77c1e3ccSAndroid Build Coastguard Worker // For compatibility with existing SIMD implementations, "data" must be 32-byte
44*77c1e3ccSAndroid Build Coastguard Worker // aligned.
45*77c1e3ccSAndroid Build Coastguard Worker void aom_noise_tx_inverse(struct aom_noise_tx_t *aom_noise_tx, float *data);
46*77c1e3ccSAndroid Build Coastguard Worker 
47*77c1e3ccSAndroid Build Coastguard Worker // Aggregates the power of the buffered transform data into the psd buffer.
48*77c1e3ccSAndroid Build Coastguard Worker void aom_noise_tx_add_energy(const struct aom_noise_tx_t *aom_noise_tx,
49*77c1e3ccSAndroid Build Coastguard Worker                              float *psd);
50*77c1e3ccSAndroid Build Coastguard Worker 
51*77c1e3ccSAndroid Build Coastguard Worker // Returns a default value suitable for denosing a transform of the given
52*77c1e3ccSAndroid Build Coastguard Worker // block_size. The noise "factor" determines the strength of the noise to
53*77c1e3ccSAndroid Build Coastguard Worker // be removed. A value of about 2.5 can be used for moderate denoising,
54*77c1e3ccSAndroid Build Coastguard Worker // where a value of 5.0 can be used for a high level of denoising.
55*77c1e3ccSAndroid Build Coastguard Worker float aom_noise_psd_get_default_value(int block_size, float factor);
56*77c1e3ccSAndroid Build Coastguard Worker 
57*77c1e3ccSAndroid Build Coastguard Worker // Computes normalized cross correlation of two vectors a and b of length n.
58*77c1e3ccSAndroid Build Coastguard Worker double aom_normalized_cross_correlation(const double *a, const double *b,
59*77c1e3ccSAndroid Build Coastguard Worker                                         int n);
60*77c1e3ccSAndroid Build Coastguard Worker 
61*77c1e3ccSAndroid Build Coastguard Worker // Validates the correlated noise in the data buffer of size (w, h).
62*77c1e3ccSAndroid Build Coastguard Worker int aom_noise_data_validate(const double *data, int w, int h);
63*77c1e3ccSAndroid Build Coastguard Worker 
64*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
65*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
66*77c1e3ccSAndroid Build Coastguard Worker #endif  // __cplusplus
67*77c1e3ccSAndroid Build Coastguard Worker 
68*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AOM_DSP_NOISE_UTIL_H_
69