| 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 #include "./vp9_rtcd.h" |
| 11 | 12 |
| 12 #include "vp9/encoder/vp9_onyx_int.h" | 13 #include "vp9/encoder/vp9_ssim.h" |
| 13 | 14 |
| 14 void vp9_ssim_parms_16x16_c(uint8_t *s, int sp, uint8_t *r, | 15 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, | 16 int rp, unsigned long *sum_s, unsigned long *sum_r, |
| 16 unsigned long *sum_sq_s, unsigned long *sum_sq_r, | 17 unsigned long *sum_sq_s, unsigned long *sum_sq_r, |
| 17 unsigned long *sum_sxr) { | 18 unsigned long *sum_sxr) { |
| 18 int i, j; | 19 int i, j; |
| 19 for (i = 0; i < 16; i++, s += sp, r += rp) { | 20 for (i = 0; i < 16; i++, s += sp, r += rp) { |
| 20 for (j = 0; j < 16; j++) { | 21 for (j = 0; j < 16; j++) { |
| 21 *sum_s += s[j]; | 22 *sum_s += s[j]; |
| 22 *sum_r += r[j]; | 23 *sum_r += r[j]; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr - | 59 ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr - |
| 59 (int64_t) 2 * sum_s * sum_r + c2); | 60 (int64_t) 2 * sum_s * sum_r + c2); |
| 60 | 61 |
| 61 ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) * | 62 ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) * |
| 62 ((int64_t)count * sum_sq_s - (int64_t)sum_s * sum_s + | 63 ((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); | 64 (int64_t)count * sum_sq_r - (int64_t) sum_r * sum_r + c2); |
| 64 | 65 |
| 65 return ssim_n * 1.0 / ssim_d; | 66 return ssim_n * 1.0 / ssim_d; |
| 66 } | 67 } |
| 67 | 68 |
| 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; | |
| 70 vp9_ssim_parms_16x16(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, | |
| 71 &sum_sxr); | |
| 72 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 256); | |
| 73 } | |
| 74 static double ssim_8x8(uint8_t *s, int sp, uint8_t *r, int rp) { | 69 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; | 70 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, | 71 vp9_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, |
| 77 &sum_sxr); | 72 &sum_sxr); |
| 78 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64); | 73 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64); |
| 79 } | 74 } |
| 80 | 75 |
| 81 // We are using a 8x8 moving window with starting location of each 8x8 window | 76 // 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 | 77 // on the 4x4 pixel grid. Such arrangement allows the windows to overlap |
| 83 // block boundaries to penalize blocking artifacts. | 78 // block boundaries to penalize blocking artifacts. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 c = vp9_ssim2(source->v_buffer, dest->v_buffer, | 134 c = vp9_ssim2(source->v_buffer, dest->v_buffer, |
| 140 source->uv_stride, dest->uv_stride, | 135 source->uv_stride, dest->uv_stride, |
| 141 source->uv_crop_width, source->uv_crop_height); | 136 source->uv_crop_width, source->uv_crop_height); |
| 142 *ssim_y = a; | 137 *ssim_y = a; |
| 143 *ssim_u = b; | 138 *ssim_u = b; |
| 144 *ssim_v = c; | 139 *ssim_v = c; |
| 145 ssim_all = (a * 4 + b + c) / 6; | 140 ssim_all = (a * 4 + b + c) / 6; |
| 146 | 141 |
| 147 return ssim_all; | 142 return ssim_all; |
| 148 } | 143 } |
| OLD | NEW |