1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #ifndef AOM_AOM_DSP_SSIM_H_
13 #define AOM_AOM_DSP_SSIM_H_
14 
15 #define MAX_SSIM_DB 100.0;
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 #include "config/aom_config.h"
22 
23 #include "aom_scale/yv12config.h"
24 
25 // metrics used for calculating ssim, ssim2, dssim, and ssimc
26 typedef struct {
27   // source sum ( over 8x8 region )
28   uint32_t sum_s;
29 
30   // reference sum (over 8x8 region )
31   uint32_t sum_r;
32 
33   // source sum squared ( over 8x8 region )
34   uint32_t sum_sq_s;
35 
36   // reference sum squared (over 8x8 region )
37   uint32_t sum_sq_r;
38 
39   // sum of source times reference (over 8x8 region)
40   uint32_t sum_sxr;
41 
42   // calculated ssim score between source and reference
43   double ssim;
44 } Ssimv;
45 
46 // metrics collected on a frame basis
47 typedef struct {
48   // ssim consistency error metric ( see code for explanation )
49   double ssimc;
50 
51   // standard ssim
52   double ssim;
53 
54   // revised ssim ( see code for explanation)
55   double ssim2;
56 
57   // ssim restated as an error metric like sse
58   double dssim;
59 
60   // dssim converted to decibels
61   double dssimd;
62 
63   // ssimc converted to decibels
64   double ssimcd;
65 } Metrics;
66 
67 double aom_get_ssim_metrics(uint8_t *img1, int img1_pitch, uint8_t *img2,
68                             int img2_pitch, int width, int height, Ssimv *sv2,
69                             Metrics *m, int do_inconsistency);
70 
71 double aom_calc_ssim(const YV12_BUFFER_CONFIG *source,
72                      const YV12_BUFFER_CONFIG *dest, double *weight);
73 
74 double aom_calc_fastssim(const YV12_BUFFER_CONFIG *source,
75                          const YV12_BUFFER_CONFIG *dest, double *ssim_y,
76                          double *ssim_u, double *ssim_v, uint32_t bd,
77                          uint32_t in_bd);
78 
79 double aom_highbd_calc_ssim(const YV12_BUFFER_CONFIG *source,
80                             const YV12_BUFFER_CONFIG *dest, double *weight,
81                             uint32_t bd, uint32_t in_bd);
82 
83 #ifdef __cplusplus
84 }  // extern "C"
85 #endif
86 
87 #endif  // AOM_AOM_DSP_SSIM_H_
88