xref: /aosp_15_r20/external/libaom/aom_dsp/ssim.h (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, 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_SSIM_H_
13*77c1e3ccSAndroid Build Coastguard Worker #define AOM_AOM_DSP_SSIM_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
18*77c1e3ccSAndroid Build Coastguard Worker 
19*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
20*77c1e3ccSAndroid Build Coastguard Worker 
21*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_INTERNAL_STATS
22*77c1e3ccSAndroid Build Coastguard Worker #include "aom_scale/yv12config.h"
23*77c1e3ccSAndroid Build Coastguard Worker 
24*77c1e3ccSAndroid Build Coastguard Worker // metrics used for calculating ssim, ssim2, dssim, and ssimc
25*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
26*77c1e3ccSAndroid Build Coastguard Worker   // source sum ( over 8x8 region )
27*77c1e3ccSAndroid Build Coastguard Worker   uint32_t sum_s;
28*77c1e3ccSAndroid Build Coastguard Worker 
29*77c1e3ccSAndroid Build Coastguard Worker   // reference sum (over 8x8 region )
30*77c1e3ccSAndroid Build Coastguard Worker   uint32_t sum_r;
31*77c1e3ccSAndroid Build Coastguard Worker 
32*77c1e3ccSAndroid Build Coastguard Worker   // source sum squared ( over 8x8 region )
33*77c1e3ccSAndroid Build Coastguard Worker   uint32_t sum_sq_s;
34*77c1e3ccSAndroid Build Coastguard Worker 
35*77c1e3ccSAndroid Build Coastguard Worker   // reference sum squared (over 8x8 region )
36*77c1e3ccSAndroid Build Coastguard Worker   uint32_t sum_sq_r;
37*77c1e3ccSAndroid Build Coastguard Worker 
38*77c1e3ccSAndroid Build Coastguard Worker   // sum of source times reference (over 8x8 region)
39*77c1e3ccSAndroid Build Coastguard Worker   uint32_t sum_sxr;
40*77c1e3ccSAndroid Build Coastguard Worker 
41*77c1e3ccSAndroid Build Coastguard Worker   // calculated ssim score between source and reference
42*77c1e3ccSAndroid Build Coastguard Worker   double ssim;
43*77c1e3ccSAndroid Build Coastguard Worker } Ssimv;
44*77c1e3ccSAndroid Build Coastguard Worker 
45*77c1e3ccSAndroid Build Coastguard Worker // metrics collected on a frame basis
46*77c1e3ccSAndroid Build Coastguard Worker typedef struct {
47*77c1e3ccSAndroid Build Coastguard Worker   // ssim consistency error metric ( see code for explanation )
48*77c1e3ccSAndroid Build Coastguard Worker   double ssimc;
49*77c1e3ccSAndroid Build Coastguard Worker 
50*77c1e3ccSAndroid Build Coastguard Worker   // standard ssim
51*77c1e3ccSAndroid Build Coastguard Worker   double ssim;
52*77c1e3ccSAndroid Build Coastguard Worker 
53*77c1e3ccSAndroid Build Coastguard Worker   // revised ssim ( see code for explanation)
54*77c1e3ccSAndroid Build Coastguard Worker   double ssim2;
55*77c1e3ccSAndroid Build Coastguard Worker 
56*77c1e3ccSAndroid Build Coastguard Worker   // ssim restated as an error metric like sse
57*77c1e3ccSAndroid Build Coastguard Worker   double dssim;
58*77c1e3ccSAndroid Build Coastguard Worker 
59*77c1e3ccSAndroid Build Coastguard Worker   // dssim converted to decibels
60*77c1e3ccSAndroid Build Coastguard Worker   double dssimd;
61*77c1e3ccSAndroid Build Coastguard Worker 
62*77c1e3ccSAndroid Build Coastguard Worker   // ssimc converted to decibels
63*77c1e3ccSAndroid Build Coastguard Worker   double ssimcd;
64*77c1e3ccSAndroid Build Coastguard Worker } Metrics;
65*77c1e3ccSAndroid Build Coastguard Worker 
66*77c1e3ccSAndroid Build Coastguard Worker double aom_get_ssim_metrics(uint8_t *img1, int img1_pitch, uint8_t *img2,
67*77c1e3ccSAndroid Build Coastguard Worker                             int img2_pitch, int width, int height, Ssimv *sv2,
68*77c1e3ccSAndroid Build Coastguard Worker                             Metrics *m, int do_inconsistency);
69*77c1e3ccSAndroid Build Coastguard Worker 
70*77c1e3ccSAndroid Build Coastguard Worker void aom_lowbd_calc_ssim(const YV12_BUFFER_CONFIG *source,
71*77c1e3ccSAndroid Build Coastguard Worker                          const YV12_BUFFER_CONFIG *dest, double *weight,
72*77c1e3ccSAndroid Build Coastguard Worker                          double *fast_ssim);
73*77c1e3ccSAndroid Build Coastguard Worker 
74*77c1e3ccSAndroid Build Coastguard Worker double aom_calc_fastssim(const YV12_BUFFER_CONFIG *source,
75*77c1e3ccSAndroid Build Coastguard Worker                          const YV12_BUFFER_CONFIG *dest, double *ssim_y,
76*77c1e3ccSAndroid Build Coastguard Worker                          double *ssim_u, double *ssim_v, uint32_t bd,
77*77c1e3ccSAndroid Build Coastguard Worker                          uint32_t in_bd);
78*77c1e3ccSAndroid Build Coastguard Worker 
79*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
80*77c1e3ccSAndroid Build Coastguard Worker void aom_highbd_calc_ssim(const YV12_BUFFER_CONFIG *source,
81*77c1e3ccSAndroid Build Coastguard Worker                           const YV12_BUFFER_CONFIG *dest, double *weight,
82*77c1e3ccSAndroid Build Coastguard Worker                           uint32_t bd, uint32_t in_bd, double *fast_ssim);
83*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_AV1_HIGHBITDEPTH
84*77c1e3ccSAndroid Build Coastguard Worker 
85*77c1e3ccSAndroid Build Coastguard Worker void aom_calc_ssim(const YV12_BUFFER_CONFIG *orig,
86*77c1e3ccSAndroid Build Coastguard Worker                    const YV12_BUFFER_CONFIG *recon, const uint32_t bit_depth,
87*77c1e3ccSAndroid Build Coastguard Worker                    const uint32_t in_bit_depth, int is_hbd, double *weight,
88*77c1e3ccSAndroid Build Coastguard Worker                    double *frame_ssim2);
89*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_INTERNAL_STATS
90*77c1e3ccSAndroid Build Coastguard Worker 
91*77c1e3ccSAndroid Build Coastguard Worker double aom_ssim2(const uint8_t *img1, const uint8_t *img2, int stride_img1,
92*77c1e3ccSAndroid Build Coastguard Worker                  int stride_img2, int width, int height);
93*77c1e3ccSAndroid Build Coastguard Worker 
94*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
95*77c1e3ccSAndroid Build Coastguard Worker double aom_highbd_ssim2(const uint8_t *img1, const uint8_t *img2,
96*77c1e3ccSAndroid Build Coastguard Worker                         int stride_img1, int stride_img2, int width, int height,
97*77c1e3ccSAndroid Build Coastguard Worker                         uint32_t bd, uint32_t shift);
98*77c1e3ccSAndroid Build Coastguard Worker #endif  // CONFIG_AV1_HIGHBITDEPTH
99*77c1e3ccSAndroid Build Coastguard Worker 
100*77c1e3ccSAndroid Build Coastguard Worker #ifdef __cplusplus
101*77c1e3ccSAndroid Build Coastguard Worker }  // extern "C"
102*77c1e3ccSAndroid Build Coastguard Worker #endif
103*77c1e3ccSAndroid Build Coastguard Worker 
104*77c1e3ccSAndroid Build Coastguard Worker #endif  // AOM_AOM_DSP_SSIM_H_
105