OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 | 11 |
12 #include "vp9/encoder/vp9_onyx_int.h" | 12 #include "vp9/encoder/vp9_onyx_int.h" |
13 | 13 |
14 void vp9_ssim_parms_16x16_c(unsigned char *s, int sp, unsigned char *r, | 14 void vp9_ssim_parms_16x16_c(uint8_t *s, int sp, uint8_t *r, |
15 int rp, unsigned long *sum_s, unsigned long *sum_r, | 15 int rp, unsigned long *sum_s, unsigned long *sum_r, |
16 unsigned long *sum_sq_s, unsigned long *sum_sq_r, | 16 unsigned long *sum_sq_s, unsigned long *sum_sq_r, |
17 unsigned long *sum_sxr) { | 17 unsigned long *sum_sxr) { |
18 int i, j; | 18 int i, j; |
19 for (i = 0; i < 16; i++, s += sp, r += rp) { | 19 for (i = 0; i < 16; i++, s += sp, r += rp) { |
20 for (j = 0; j < 16; j++) { | 20 for (j = 0; j < 16; j++) { |
21 *sum_s += s[j]; | 21 *sum_s += s[j]; |
22 *sum_r += r[j]; | 22 *sum_r += r[j]; |
23 *sum_sq_s += s[j] * s[j]; | 23 *sum_sq_s += s[j] * s[j]; |
24 *sum_sq_r += r[j] * r[j]; | 24 *sum_sq_r += r[j] * r[j]; |
25 *sum_sxr += s[j] * r[j]; | 25 *sum_sxr += s[j] * r[j]; |
26 } | 26 } |
27 } | 27 } |
28 } | 28 } |
29 void vp9_ssim_parms_8x8_c(unsigned char *s, int sp, unsigned char *r, int rp, | 29 void vp9_ssim_parms_8x8_c(uint8_t *s, int sp, uint8_t *r, int rp, |
30 unsigned long *sum_s, unsigned long *sum_r, | 30 unsigned long *sum_s, unsigned long *sum_r, |
31 unsigned long *sum_sq_s, unsigned long *sum_sq_r, | 31 unsigned long *sum_sq_s, unsigned long *sum_sq_r, |
32 unsigned long *sum_sxr) { | 32 unsigned long *sum_sxr) { |
33 int i, j; | 33 int i, j; |
34 for (i = 0; i < 8; i++, s += sp, r += rp) { | 34 for (i = 0; i < 8; i++, s += sp, r += rp) { |
35 for (j = 0; j < 8; j++) { | 35 for (j = 0; j < 8; j++) { |
36 *sum_s += s[j]; | 36 *sum_s += s[j]; |
37 *sum_r += r[j]; | 37 *sum_r += r[j]; |
38 *sum_sq_s += s[j] * s[j]; | 38 *sum_sq_s += s[j] * s[j]; |
39 *sum_sq_r += r[j] * r[j]; | 39 *sum_sq_r += r[j] * r[j]; |
(...skipping 18 matching lines...) Expand all Loading... |
58 ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr - | 58 ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr - |
59 (int64_t) 2 * sum_s * sum_r + c2); | 59 (int64_t) 2 * sum_s * sum_r + c2); |
60 | 60 |
61 ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) * | 61 ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) * |
62 ((int64_t)count * sum_sq_s - (int64_t)sum_s * sum_s + | 62 ((int64_t)count * sum_sq_s - (int64_t)sum_s * sum_s + |
63 (int64_t)count * sum_sq_r - (int64_t) sum_r * sum_r + c2); | 63 (int64_t)count * sum_sq_r - (int64_t) sum_r * sum_r + c2); |
64 | 64 |
65 return ssim_n * 1.0 / ssim_d; | 65 return ssim_n * 1.0 / ssim_d; |
66 } | 66 } |
67 | 67 |
68 static double ssim_16x16(unsigned char *s, int sp, unsigned char *r, int rp) { | 68 static double ssim_16x16(uint8_t *s, int sp, uint8_t *r, int rp) { |
69 unsigned long sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; | 69 unsigned long sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; |
70 vp9_ssim_parms_16x16(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, | 70 vp9_ssim_parms_16x16(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, |
71 &sum_sxr); | 71 &sum_sxr); |
72 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 256); | 72 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 256); |
73 } | 73 } |
74 static double ssim_8x8(unsigned char *s, int sp, unsigned char *r, int rp) { | 74 static double ssim_8x8(uint8_t *s, int sp, uint8_t *r, int rp) { |
75 unsigned long sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; | 75 unsigned long sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; |
76 vp9_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, | 76 vp9_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, |
77 &sum_sxr); | 77 &sum_sxr); |
78 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64); | 78 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64); |
79 } | 79 } |
80 | 80 |
81 // We are using a 8x8 moving window with starting location of each 8x8 window | 81 // We are using a 8x8 moving window with starting location of each 8x8 window |
82 // on the 4x4 pixel grid. Such arrangement allows the windows to overlap | 82 // on the 4x4 pixel grid. Such arrangement allows the windows to overlap |
83 // block boundaries to penalize blocking artifacts. | 83 // block boundaries to penalize blocking artifacts. |
84 double vp9_ssim2(unsigned char *img1, unsigned char *img2, int stride_img1, | 84 double vp9_ssim2(uint8_t *img1, uint8_t *img2, int stride_img1, |
85 int stride_img2, int width, int height) { | 85 int stride_img2, int width, int height) { |
86 int i, j; | 86 int i, j; |
87 int samples = 0; | 87 int samples = 0; |
88 double ssim_total = 0; | 88 double ssim_total = 0; |
89 | 89 |
90 // sample point start with each 4x4 location | 90 // sample point start with each 4x4 location |
91 for (i = 0; i < height - 8; i += 4, img1 += stride_img1 * 4, img2 += stride_im
g2 * 4) { | 91 for (i = 0; i < height - 8; i += 4, img1 += stride_img1 * 4, img2 += stride_im
g2 * 4) { |
92 for (j = 0; j < width - 8; j += 4) { | 92 for (j = 0; j < width - 8; j += 4) { |
93 double v = ssim_8x8(img1 + j, stride_img1, img2 + j, stride_img2); | 93 double v = ssim_8x8(img1 + j, stride_img1, img2 + j, stride_img2); |
94 ssim_total += v; | 94 ssim_total += v; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 c = vp9_ssim2(source->v_buffer, dest->v_buffer, | 138 c = vp9_ssim2(source->v_buffer, dest->v_buffer, |
139 source->uv_stride, dest->uv_stride, source->uv_width, | 139 source->uv_stride, dest->uv_stride, source->uv_width, |
140 source->uv_height); | 140 source->uv_height); |
141 *ssim_y = a; | 141 *ssim_y = a; |
142 *ssim_u = b; | 142 *ssim_u = b; |
143 *ssim_v = c; | 143 *ssim_v = c; |
144 ssim_all = (a * 4 + b + c) / 6; | 144 ssim_all = (a * 4 + b + c) / 6; |
145 | 145 |
146 return ssim_all; | 146 return ssim_all; |
147 } | 147 } |
OLD | NEW |