ref: fc5d16678294a405de44da418474b119965dfb0f
parent: 509ec5945b7c42230dfae96ed6fa03d051a865d0
parent: 6dc612758cac7d4f07e58c020ee2a1422b49a26d
author: Sai Deng <[email protected]>
date: Wed Dec 5 12:55:58 EST 2018
Merge "Fix overflow in calculating highbd SSIM"
--- a/tools/tiny_ssim.c
+++ b/tools/tiny_ssim.c
@@ -237,7 +237,7 @@
static double similarity(uint32_t sum_s, uint32_t sum_r, uint32_t sum_sq_s,
uint32_t sum_sq_r, uint32_t sum_sxr, int count,
uint32_t bd) {
- int64_t ssim_n, ssim_d;
+ double ssim_n, ssim_d;
int64_t c1 = 0, c2 = 0;
if (bd == 8) {
// scale the constants by number of pixels
@@ -253,14 +253,14 @@
assert(0);
}
- ssim_n = (2 * sum_s * sum_r + c1) *
- ((int64_t)2 * count * sum_sxr - (int64_t)2 * sum_s * sum_r + c2);
+ ssim_n = (2.0 * sum_s * sum_r + c1) *
+ (2.0 * count * sum_sxr - 2.0 * sum_s * sum_r + c2);
- ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) *
- ((int64_t)count * sum_sq_s - (int64_t)sum_s * sum_s +
- (int64_t)count * sum_sq_r - (int64_t)sum_r * sum_r + c2);
+ ssim_d = ((double)sum_s * sum_s + (double)sum_r * sum_r + c1) *
+ ((double)count * sum_sq_s - (double)sum_s * sum_s +
+ (double)count * sum_sq_r - (double)sum_r * sum_r + c2);
- return ssim_n * 1.0 / ssim_d;
+ return ssim_n / ssim_d;
}
static double ssim_8x8(const uint8_t *s, int sp, const uint8_t *r, int rp) {
--- a/vpx_dsp/ssim.c
+++ b/vpx_dsp/ssim.c
@@ -73,7 +73,7 @@
static double similarity(uint32_t sum_s, uint32_t sum_r, uint32_t sum_sq_s,
uint32_t sum_sq_r, uint32_t sum_sxr, int count,
uint32_t bd) {
- int64_t ssim_n, ssim_d;
+ double ssim_n, ssim_d;
int64_t c1, c2;
if (bd == 8) {
// scale the constants by number of pixels
@@ -90,14 +90,14 @@
assert(0);
}
- ssim_n = (2 * sum_s * sum_r + c1) *
- ((int64_t)2 * count * sum_sxr - (int64_t)2 * sum_s * sum_r + c2);
+ ssim_n = (2.0 * sum_s * sum_r + c1) *
+ (2.0 * count * sum_sxr - 2.0 * sum_s * sum_r + c2);
- ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) *
- ((int64_t)count * sum_sq_s - (int64_t)sum_s * sum_s +
- (int64_t)count * sum_sq_r - (int64_t)sum_r * sum_r + c2);
+ ssim_d = ((double)sum_s * sum_s + (double)sum_r * sum_r + c1) *
+ ((double)count * sum_sq_s - (double)sum_s * sum_s +
+ (double)count * sum_sq_r - (double)sum_r * sum_r + c2);
- return ssim_n * 1.0 / ssim_d;
+ return ssim_n / ssim_d;
}
static double ssim_8x8(const uint8_t *s, int sp, const uint8_t *r, int rp) {