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