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 <math.h> | 11 #include <math.h> |
12 #include "./vp9_rtcd.h" | 12 #include "./vpx_dsp_rtcd.h" |
| 13 #include "vpx_dsp/ssim.h" |
13 #include "vpx_ports/mem.h" | 14 #include "vpx_ports/mem.h" |
14 #include "vp9/encoder/vp9_ssim.h" | 15 #include "vpx_ports/system_state.h" |
15 | 16 |
16 void vp9_ssim_parms_16x16_c(uint8_t *s, int sp, uint8_t *r, | 17 void vpx_ssim_parms_16x16_c(const uint8_t *s, int sp, const uint8_t *r, |
17 int rp, unsigned long *sum_s, unsigned long *sum_r, | 18 int rp, uint32_t *sum_s, uint32_t *sum_r, |
18 unsigned long *sum_sq_s, unsigned long *sum_sq_r, | 19 uint32_t *sum_sq_s, uint32_t *sum_sq_r, |
19 unsigned long *sum_sxr) { | 20 uint32_t *sum_sxr) { |
20 int i, j; | 21 int i, j; |
21 for (i = 0; i < 16; i++, s += sp, r += rp) { | 22 for (i = 0; i < 16; i++, s += sp, r += rp) { |
22 for (j = 0; j < 16; j++) { | 23 for (j = 0; j < 16; j++) { |
23 *sum_s += s[j]; | 24 *sum_s += s[j]; |
24 *sum_r += r[j]; | 25 *sum_r += r[j]; |
25 *sum_sq_s += s[j] * s[j]; | 26 *sum_sq_s += s[j] * s[j]; |
26 *sum_sq_r += r[j] * r[j]; | 27 *sum_sq_r += r[j] * r[j]; |
27 *sum_sxr += s[j] * r[j]; | 28 *sum_sxr += s[j] * r[j]; |
28 } | 29 } |
29 } | 30 } |
30 } | 31 } |
31 void vp9_ssim_parms_8x8_c(uint8_t *s, int sp, uint8_t *r, int rp, | 32 void vpx_ssim_parms_8x8_c(const uint8_t *s, int sp, const uint8_t *r, int rp, |
32 unsigned long *sum_s, unsigned long *sum_r, | 33 uint32_t *sum_s, uint32_t *sum_r, |
33 unsigned long *sum_sq_s, unsigned long *sum_sq_r, | 34 uint32_t *sum_sq_s, uint32_t *sum_sq_r, |
34 unsigned long *sum_sxr) { | 35 uint32_t *sum_sxr) { |
35 int i, j; | 36 int i, j; |
36 for (i = 0; i < 8; i++, s += sp, r += rp) { | 37 for (i = 0; i < 8; i++, s += sp, r += rp) { |
37 for (j = 0; j < 8; j++) { | 38 for (j = 0; j < 8; j++) { |
38 *sum_s += s[j]; | 39 *sum_s += s[j]; |
39 *sum_r += r[j]; | 40 *sum_r += r[j]; |
40 *sum_sq_s += s[j] * s[j]; | 41 *sum_sq_s += s[j] * s[j]; |
41 *sum_sq_r += r[j] * r[j]; | 42 *sum_sq_r += r[j] * r[j]; |
42 *sum_sxr += s[j] * r[j]; | 43 *sum_sxr += s[j] * r[j]; |
43 } | 44 } |
44 } | 45 } |
45 } | 46 } |
46 | 47 |
47 #if CONFIG_VP9_HIGHBITDEPTH | 48 #if CONFIG_VP9_HIGHBITDEPTH |
48 void vp9_highbd_ssim_parms_8x8_c(uint16_t *s, int sp, uint16_t *r, int rp, | 49 void vpx_highbd_ssim_parms_8x8_c(const uint16_t *s, int sp, |
| 50 const uint16_t *r, int rp, |
49 uint32_t *sum_s, uint32_t *sum_r, | 51 uint32_t *sum_s, uint32_t *sum_r, |
50 uint32_t *sum_sq_s, uint32_t *sum_sq_r, | 52 uint32_t *sum_sq_s, uint32_t *sum_sq_r, |
51 uint32_t *sum_sxr) { | 53 uint32_t *sum_sxr) { |
52 int i, j; | 54 int i, j; |
53 for (i = 0; i < 8; i++, s += sp, r += rp) { | 55 for (i = 0; i < 8; i++, s += sp, r += rp) { |
54 for (j = 0; j < 8; j++) { | 56 for (j = 0; j < 8; j++) { |
55 *sum_s += s[j]; | 57 *sum_s += s[j]; |
56 *sum_r += r[j]; | 58 *sum_r += r[j]; |
57 *sum_sq_s += s[j] * s[j]; | 59 *sum_sq_s += s[j] * s[j]; |
58 *sum_sq_r += r[j] * r[j]; | 60 *sum_sq_r += r[j] * r[j]; |
59 *sum_sxr += s[j] * r[j]; | 61 *sum_sxr += s[j] * r[j]; |
60 } | 62 } |
61 } | 63 } |
62 } | 64 } |
63 #endif // CONFIG_VP9_HIGHBITDEPTH | 65 #endif // CONFIG_VP9_HIGHBITDEPTH |
64 | 66 |
65 static const int64_t cc1 = 26634; // (64^2*(.01*255)^2 | 67 static const int64_t cc1 = 26634; // (64^2*(.01*255)^2 |
66 static const int64_t cc2 = 239708; // (64^2*(.03*255)^2 | 68 static const int64_t cc2 = 239708; // (64^2*(.03*255)^2 |
67 | 69 |
68 static double similarity(unsigned long sum_s, unsigned long sum_r, | 70 static double similarity(uint32_t sum_s, uint32_t sum_r, |
69 unsigned long sum_sq_s, unsigned long sum_sq_r, | 71 uint32_t sum_sq_s, uint32_t sum_sq_r, |
70 unsigned long sum_sxr, int count) { | 72 uint32_t sum_sxr, int count) { |
71 int64_t ssim_n, ssim_d; | 73 int64_t ssim_n, ssim_d; |
72 int64_t c1, c2; | 74 int64_t c1, c2; |
73 | 75 |
74 // scale the constants by number of pixels | 76 // scale the constants by number of pixels |
75 c1 = (cc1 * count * count) >> 12; | 77 c1 = (cc1 * count * count) >> 12; |
76 c2 = (cc2 * count * count) >> 12; | 78 c2 = (cc2 * count * count) >> 12; |
77 | 79 |
78 ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr - | 80 ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr - |
79 (int64_t) 2 * sum_s * sum_r + c2); | 81 (int64_t) 2 * sum_s * sum_r + c2); |
80 | 82 |
81 ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) * | 83 ssim_d = (sum_s * sum_s + sum_r * sum_r + c1) * |
82 ((int64_t)count * sum_sq_s - (int64_t)sum_s * sum_s + | 84 ((int64_t)count * sum_sq_s - (int64_t)sum_s * sum_s + |
83 (int64_t)count * sum_sq_r - (int64_t) sum_r * sum_r + c2); | 85 (int64_t)count * sum_sq_r - (int64_t) sum_r * sum_r + c2); |
84 | 86 |
85 return ssim_n * 1.0 / ssim_d; | 87 return ssim_n * 1.0 / ssim_d; |
86 } | 88 } |
87 | 89 |
88 static double ssim_8x8(uint8_t *s, int sp, uint8_t *r, int rp) { | 90 static double ssim_8x8(const uint8_t *s, int sp, const uint8_t *r, int rp) { |
89 unsigned long sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; | 91 uint32_t sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; |
90 vp9_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, | 92 vpx_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, |
91 &sum_sxr); | 93 &sum_sxr); |
92 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64); | 94 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64); |
93 } | 95 } |
94 | 96 |
95 #if CONFIG_VP9_HIGHBITDEPTH | 97 #if CONFIG_VP9_HIGHBITDEPTH |
96 static double highbd_ssim_8x8(uint16_t *s, int sp, uint16_t *r, int rp, | 98 static double highbd_ssim_8x8(const uint16_t *s, int sp, const uint16_t *r, |
97 unsigned int bd) { | 99 int rp, unsigned int bd) { |
98 uint32_t sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; | 100 uint32_t sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; |
99 const int oshift = bd - 8; | 101 const int oshift = bd - 8; |
100 vp9_highbd_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, | 102 vpx_highbd_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, |
101 &sum_sxr); | 103 &sum_sxr); |
102 return similarity(sum_s >> oshift, | 104 return similarity(sum_s >> oshift, |
103 sum_r >> oshift, | 105 sum_r >> oshift, |
104 sum_sq_s >> (2 * oshift), | 106 sum_sq_s >> (2 * oshift), |
105 sum_sq_r >> (2 * oshift), | 107 sum_sq_r >> (2 * oshift), |
106 sum_sxr >> (2 * oshift), | 108 sum_sxr >> (2 * oshift), |
107 64); | 109 64); |
108 } | 110 } |
109 #endif // CONFIG_VP9_HIGHBITDEPTH | 111 #endif // CONFIG_VP9_HIGHBITDEPTH |
110 | 112 |
111 // We are using a 8x8 moving window with starting location of each 8x8 window | 113 // We are using a 8x8 moving window with starting location of each 8x8 window |
112 // on the 4x4 pixel grid. Such arrangement allows the windows to overlap | 114 // on the 4x4 pixel grid. Such arrangement allows the windows to overlap |
113 // block boundaries to penalize blocking artifacts. | 115 // block boundaries to penalize blocking artifacts. |
114 double vp9_ssim2(uint8_t *img1, uint8_t *img2, int stride_img1, | 116 static double vpx_ssim2(const uint8_t *img1, const uint8_t *img2, |
115 int stride_img2, int width, int height) { | 117 int stride_img1, int stride_img2, int width, |
| 118 int height) { |
116 int i, j; | 119 int i, j; |
117 int samples = 0; | 120 int samples = 0; |
118 double ssim_total = 0; | 121 double ssim_total = 0; |
119 | 122 |
120 // sample point start with each 4x4 location | 123 // sample point start with each 4x4 location |
121 for (i = 0; i <= height - 8; | 124 for (i = 0; i <= height - 8; |
122 i += 4, img1 += stride_img1 * 4, img2 += stride_img2 * 4) { | 125 i += 4, img1 += stride_img1 * 4, img2 += stride_img2 * 4) { |
123 for (j = 0; j <= width - 8; j += 4) { | 126 for (j = 0; j <= width - 8; j += 4) { |
124 double v = ssim_8x8(img1 + j, stride_img1, img2 + j, stride_img2); | 127 double v = ssim_8x8(img1 + j, stride_img1, img2 + j, stride_img2); |
125 ssim_total += v; | 128 ssim_total += v; |
126 samples++; | 129 samples++; |
127 } | 130 } |
128 } | 131 } |
129 ssim_total /= samples; | 132 ssim_total /= samples; |
130 return ssim_total; | 133 return ssim_total; |
131 } | 134 } |
132 | 135 |
133 #if CONFIG_VP9_HIGHBITDEPTH | 136 #if CONFIG_VP9_HIGHBITDEPTH |
134 double vp9_highbd_ssim2(uint8_t *img1, uint8_t *img2, int stride_img1, | 137 static double vpx_highbd_ssim2(const uint8_t *img1, const uint8_t *img2, |
135 int stride_img2, int width, int height, | 138 int stride_img1, int stride_img2, int width, |
136 unsigned int bd) { | 139 int height, unsigned int bd) { |
137 int i, j; | 140 int i, j; |
138 int samples = 0; | 141 int samples = 0; |
139 double ssim_total = 0; | 142 double ssim_total = 0; |
140 | 143 |
141 // sample point start with each 4x4 location | 144 // sample point start with each 4x4 location |
142 for (i = 0; i <= height - 8; | 145 for (i = 0; i <= height - 8; |
143 i += 4, img1 += stride_img1 * 4, img2 += stride_img2 * 4) { | 146 i += 4, img1 += stride_img1 * 4, img2 += stride_img2 * 4) { |
144 for (j = 0; j <= width - 8; j += 4) { | 147 for (j = 0; j <= width - 8; j += 4) { |
145 double v = highbd_ssim_8x8(CONVERT_TO_SHORTPTR(img1 + j), stride_img1, | 148 double v = highbd_ssim_8x8(CONVERT_TO_SHORTPTR(img1 + j), stride_img1, |
146 CONVERT_TO_SHORTPTR(img2 + j), stride_img2, | 149 CONVERT_TO_SHORTPTR(img2 + j), stride_img2, |
147 bd); | 150 bd); |
148 ssim_total += v; | 151 ssim_total += v; |
149 samples++; | 152 samples++; |
150 } | 153 } |
151 } | 154 } |
152 ssim_total /= samples; | 155 ssim_total /= samples; |
153 return ssim_total; | 156 return ssim_total; |
154 } | 157 } |
155 #endif // CONFIG_VP9_HIGHBITDEPTH | 158 #endif // CONFIG_VP9_HIGHBITDEPTH |
156 | 159 |
157 double vp9_calc_ssim(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, | 160 double vpx_calc_ssim(const YV12_BUFFER_CONFIG *source, |
| 161 const YV12_BUFFER_CONFIG *dest, |
158 double *weight) { | 162 double *weight) { |
159 double a, b, c; | 163 double a, b, c; |
160 double ssimv; | 164 double ssimv; |
161 | 165 |
162 a = vp9_ssim2(source->y_buffer, dest->y_buffer, | 166 a = vpx_ssim2(source->y_buffer, dest->y_buffer, |
163 source->y_stride, dest->y_stride, | 167 source->y_stride, dest->y_stride, |
164 source->y_crop_width, source->y_crop_height); | 168 source->y_crop_width, source->y_crop_height); |
165 | 169 |
166 b = vp9_ssim2(source->u_buffer, dest->u_buffer, | 170 b = vpx_ssim2(source->u_buffer, dest->u_buffer, |
167 source->uv_stride, dest->uv_stride, | 171 source->uv_stride, dest->uv_stride, |
168 source->uv_crop_width, source->uv_crop_height); | 172 source->uv_crop_width, source->uv_crop_height); |
169 | 173 |
170 c = vp9_ssim2(source->v_buffer, dest->v_buffer, | 174 c = vpx_ssim2(source->v_buffer, dest->v_buffer, |
171 source->uv_stride, dest->uv_stride, | 175 source->uv_stride, dest->uv_stride, |
172 source->uv_crop_width, source->uv_crop_height); | 176 source->uv_crop_width, source->uv_crop_height); |
173 | 177 |
174 ssimv = a * .8 + .1 * (b + c); | 178 ssimv = a * .8 + .1 * (b + c); |
175 | 179 |
176 *weight = 1; | 180 *weight = 1; |
177 | 181 |
178 return ssimv; | 182 return ssimv; |
179 } | 183 } |
180 | 184 |
181 double vp9_calc_ssimg(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, | 185 double vpx_calc_ssimg(const YV12_BUFFER_CONFIG *source, |
| 186 const YV12_BUFFER_CONFIG *dest, |
182 double *ssim_y, double *ssim_u, double *ssim_v) { | 187 double *ssim_y, double *ssim_u, double *ssim_v) { |
183 double ssim_all = 0; | 188 double ssim_all = 0; |
184 double a, b, c; | 189 double a, b, c; |
185 | 190 |
186 a = vp9_ssim2(source->y_buffer, dest->y_buffer, | 191 a = vpx_ssim2(source->y_buffer, dest->y_buffer, |
187 source->y_stride, dest->y_stride, | 192 source->y_stride, dest->y_stride, |
188 source->y_crop_width, source->y_crop_height); | 193 source->y_crop_width, source->y_crop_height); |
189 | 194 |
190 b = vp9_ssim2(source->u_buffer, dest->u_buffer, | 195 b = vpx_ssim2(source->u_buffer, dest->u_buffer, |
191 source->uv_stride, dest->uv_stride, | 196 source->uv_stride, dest->uv_stride, |
192 source->uv_crop_width, source->uv_crop_height); | 197 source->uv_crop_width, source->uv_crop_height); |
193 | 198 |
194 c = vp9_ssim2(source->v_buffer, dest->v_buffer, | 199 c = vpx_ssim2(source->v_buffer, dest->v_buffer, |
195 source->uv_stride, dest->uv_stride, | 200 source->uv_stride, dest->uv_stride, |
196 source->uv_crop_width, source->uv_crop_height); | 201 source->uv_crop_width, source->uv_crop_height); |
197 *ssim_y = a; | 202 *ssim_y = a; |
198 *ssim_u = b; | 203 *ssim_u = b; |
199 *ssim_v = c; | 204 *ssim_v = c; |
200 ssim_all = (a * 4 + b + c) / 6; | 205 ssim_all = (a * 4 + b + c) / 6; |
201 | 206 |
202 return ssim_all; | 207 return ssim_all; |
203 } | 208 } |
204 | 209 |
(...skipping 19 matching lines...) Expand all Loading... |
224 // factoring out n*n | 229 // factoring out n*n |
225 // | 230 // |
226 // ssim(x,y) = | 231 // ssim(x,y) = |
227 // (2*sum(x)*sum(y) + n*n*c1)*(2*(n*sum(xi*yi)-sum(x)*sum(y))+n*n*c2) / | 232 // (2*sum(x)*sum(y) + n*n*c1)*(2*(n*sum(xi*yi)-sum(x)*sum(y))+n*n*c2) / |
228 // (((sum(x)*sum(x)+sum(y)*sum(y)) + n*n*c1) * | 233 // (((sum(x)*sum(x)+sum(y)*sum(y)) + n*n*c1) * |
229 // (n*sum(xi*xi)-sum(xi)*sum(xi)+n*sum(yi*yi)-sum(yi)*sum(yi)+n*n*c2)) | 234 // (n*sum(xi*xi)-sum(xi)*sum(xi)+n*sum(yi*yi)-sum(yi)*sum(yi)+n*n*c2)) |
230 // | 235 // |
231 // Replace c1 with n*n * c1 for the final step that leads to this code: | 236 // Replace c1 with n*n * c1 for the final step that leads to this code: |
232 // The final step scales by 12 bits so we don't lose precision in the constants. | 237 // The final step scales by 12 bits so we don't lose precision in the constants. |
233 | 238 |
234 double ssimv_similarity(Ssimv *sv, int64_t n) { | 239 static double ssimv_similarity(const Ssimv *sv, int64_t n) { |
235 // Scale the constants by number of pixels. | 240 // Scale the constants by number of pixels. |
236 const int64_t c1 = (cc1 * n * n) >> 12; | 241 const int64_t c1 = (cc1 * n * n) >> 12; |
237 const int64_t c2 = (cc2 * n * n) >> 12; | 242 const int64_t c2 = (cc2 * n * n) >> 12; |
238 | 243 |
239 const double l = 1.0 * (2 * sv->sum_s * sv->sum_r + c1) / | 244 const double l = 1.0 * (2 * sv->sum_s * sv->sum_r + c1) / |
240 (sv->sum_s * sv->sum_s + sv->sum_r * sv->sum_r + c1); | 245 (sv->sum_s * sv->sum_s + sv->sum_r * sv->sum_r + c1); |
241 | 246 |
242 // Since these variables are unsigned sums, convert to double so | 247 // Since these variables are unsigned sums, convert to double so |
243 // math is done in double arithmetic. | 248 // math is done in double arithmetic. |
244 const double v = (2.0 * n * sv->sum_sxr - 2 * sv->sum_s * sv->sum_r + c2) | 249 const double v = (2.0 * n * sv->sum_sxr - 2 * sv->sum_s * sv->sum_r + c2) |
(...skipping 10 matching lines...) Expand all Loading... |
255 // This luminance factor is super sensitive to the dark side of luminance | 260 // This luminance factor is super sensitive to the dark side of luminance |
256 // values and completely insensitive on the white side. check out 2 sets | 261 // values and completely insensitive on the white side. check out 2 sets |
257 // (1,3) and (250,252) the term gives ( 2*1*3/(1+9) = .60 | 262 // (1,3) and (250,252) the term gives ( 2*1*3/(1+9) = .60 |
258 // 2*250*252/ (250^2+252^2) => .99999997 | 263 // 2*250*252/ (250^2+252^2) => .99999997 |
259 // | 264 // |
260 // As a result in this tweaked version of the calculation in which the | 265 // As a result in this tweaked version of the calculation in which the |
261 // luminance is taken as percentage off from peak possible. | 266 // luminance is taken as percentage off from peak possible. |
262 // | 267 // |
263 // 255 * 255 - (sum_s - sum_r) / count * (sum_s - sum_r) / count | 268 // 255 * 255 - (sum_s - sum_r) / count * (sum_s - sum_r) / count |
264 // | 269 // |
265 double ssimv_similarity2(Ssimv *sv, int64_t n) { | 270 static double ssimv_similarity2(const Ssimv *sv, int64_t n) { |
266 // Scale the constants by number of pixels. | 271 // Scale the constants by number of pixels. |
267 const int64_t c1 = (cc1 * n * n) >> 12; | 272 const int64_t c1 = (cc1 * n * n) >> 12; |
268 const int64_t c2 = (cc2 * n * n) >> 12; | 273 const int64_t c2 = (cc2 * n * n) >> 12; |
269 | 274 |
270 const double mean_diff = (1.0 * sv->sum_s - sv->sum_r) / n; | 275 const double mean_diff = (1.0 * sv->sum_s - sv->sum_r) / n; |
271 const double l = (255 * 255 - mean_diff * mean_diff + c1) / (255 * 255 + c1); | 276 const double l = (255 * 255 - mean_diff * mean_diff + c1) / (255 * 255 + c1); |
272 | 277 |
273 // Since these variables are unsigned, sums convert to double so | 278 // Since these variables are unsigned, sums convert to double so |
274 // math is done in double arithmetic. | 279 // math is done in double arithmetic. |
275 const double v = (2.0 * n * sv->sum_sxr - 2 * sv->sum_s * sv->sum_r + c2) | 280 const double v = (2.0 * n * sv->sum_sxr - 2 * sv->sum_s * sv->sum_r + c2) |
276 / (n * sv->sum_sq_s - sv->sum_s * sv->sum_s + | 281 / (n * sv->sum_sq_s - sv->sum_s * sv->sum_s + |
277 n * sv->sum_sq_r - sv->sum_r * sv->sum_r + c2); | 282 n * sv->sum_sq_r - sv->sum_r * sv->sum_r + c2); |
278 | 283 |
279 return l * v; | 284 return l * v; |
280 } | 285 } |
281 void ssimv_parms(uint8_t *img1, int img1_pitch, uint8_t *img2, int img2_pitch, | 286 static void ssimv_parms(uint8_t *img1, int img1_pitch, uint8_t *img2, |
282 Ssimv *sv) { | 287 int img2_pitch, Ssimv *sv) { |
283 vp9_ssim_parms_8x8(img1, img1_pitch, img2, img2_pitch, | 288 vpx_ssim_parms_8x8(img1, img1_pitch, img2, img2_pitch, |
284 &sv->sum_s, &sv->sum_r, &sv->sum_sq_s, &sv->sum_sq_r, | 289 &sv->sum_s, &sv->sum_r, &sv->sum_sq_s, &sv->sum_sq_r, |
285 &sv->sum_sxr); | 290 &sv->sum_sxr); |
286 } | 291 } |
287 | 292 |
288 double vp9_get_ssim_metrics(uint8_t *img1, int img1_pitch, | 293 double vpx_get_ssim_metrics(uint8_t *img1, int img1_pitch, |
289 uint8_t *img2, int img2_pitch, | 294 uint8_t *img2, int img2_pitch, |
290 int width, int height, | 295 int width, int height, |
291 Ssimv *sv2, Metrics *m, | 296 Ssimv *sv2, Metrics *m, |
292 int do_inconsistency) { | 297 int do_inconsistency) { |
293 double dssim_total = 0; | 298 double dssim_total = 0; |
294 double ssim_total = 0; | 299 double ssim_total = 0; |
295 double ssim2_total = 0; | 300 double ssim2_total = 0; |
296 double inconsistency_total = 0; | 301 double inconsistency_total = 0; |
297 int i, j; | 302 int i, j; |
298 int c = 0; | 303 int c = 0; |
299 double norm; | 304 double norm; |
300 double old_ssim_total = 0; | 305 double old_ssim_total = 0; |
301 vp9_clear_system_state(); | 306 vpx_clear_system_state(); |
302 // We can sample points as frequently as we like start with 1 per 4x4. | 307 // We can sample points as frequently as we like start with 1 per 4x4. |
303 for (i = 0; i < height; i += 4, | 308 for (i = 0; i < height; i += 4, |
304 img1 += img1_pitch * 4, img2 += img2_pitch * 4) { | 309 img1 += img1_pitch * 4, img2 += img2_pitch * 4) { |
305 for (j = 0; j < width; j += 4, ++c) { | 310 for (j = 0; j < width; j += 4, ++c) { |
306 Ssimv sv = {0}; | 311 Ssimv sv = {0}; |
307 double ssim; | 312 double ssim; |
308 double ssim2; | 313 double ssim2; |
309 double dssim; | 314 double dssim; |
310 uint32_t var_new; | 315 uint32_t var_new; |
311 uint32_t var_old; | 316 uint32_t var_old; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 inconsistency_total = 0; | 446 inconsistency_total = 0; |
442 | 447 |
443 m->ssimc = inconsistency_total; | 448 m->ssimc = inconsistency_total; |
444 | 449 |
445 m->dssim = dssim_total; | 450 m->dssim = dssim_total; |
446 return inconsistency_total; | 451 return inconsistency_total; |
447 } | 452 } |
448 | 453 |
449 | 454 |
450 #if CONFIG_VP9_HIGHBITDEPTH | 455 #if CONFIG_VP9_HIGHBITDEPTH |
451 double vp9_highbd_calc_ssim(YV12_BUFFER_CONFIG *source, | 456 double vpx_highbd_calc_ssim(const YV12_BUFFER_CONFIG *source, |
452 YV12_BUFFER_CONFIG *dest, | 457 const YV12_BUFFER_CONFIG *dest, |
453 double *weight, unsigned int bd) { | 458 double *weight, unsigned int bd) { |
454 double a, b, c; | 459 double a, b, c; |
455 double ssimv; | 460 double ssimv; |
456 | 461 |
457 a = vp9_highbd_ssim2(source->y_buffer, dest->y_buffer, | 462 a = vpx_highbd_ssim2(source->y_buffer, dest->y_buffer, |
458 source->y_stride, dest->y_stride, | 463 source->y_stride, dest->y_stride, |
459 source->y_crop_width, source->y_crop_height, bd); | 464 source->y_crop_width, source->y_crop_height, bd); |
460 | 465 |
461 b = vp9_highbd_ssim2(source->u_buffer, dest->u_buffer, | 466 b = vpx_highbd_ssim2(source->u_buffer, dest->u_buffer, |
462 source->uv_stride, dest->uv_stride, | 467 source->uv_stride, dest->uv_stride, |
463 source->uv_crop_width, source->uv_crop_height, bd); | 468 source->uv_crop_width, source->uv_crop_height, bd); |
464 | 469 |
465 c = vp9_highbd_ssim2(source->v_buffer, dest->v_buffer, | 470 c = vpx_highbd_ssim2(source->v_buffer, dest->v_buffer, |
466 source->uv_stride, dest->uv_stride, | 471 source->uv_stride, dest->uv_stride, |
467 source->uv_crop_width, source->uv_crop_height, bd); | 472 source->uv_crop_width, source->uv_crop_height, bd); |
468 | 473 |
469 ssimv = a * .8 + .1 * (b + c); | 474 ssimv = a * .8 + .1 * (b + c); |
470 | 475 |
471 *weight = 1; | 476 *weight = 1; |
472 | 477 |
473 return ssimv; | 478 return ssimv; |
474 } | 479 } |
475 | 480 |
476 double vp9_highbd_calc_ssimg(YV12_BUFFER_CONFIG *source, | 481 double vpx_highbd_calc_ssimg(const YV12_BUFFER_CONFIG *source, |
477 YV12_BUFFER_CONFIG *dest, double *ssim_y, | 482 const YV12_BUFFER_CONFIG *dest, double *ssim_y, |
478 double *ssim_u, double *ssim_v, unsigned int bd) { | 483 double *ssim_u, double *ssim_v, unsigned int bd) { |
479 double ssim_all = 0; | 484 double ssim_all = 0; |
480 double a, b, c; | 485 double a, b, c; |
481 | 486 |
482 a = vp9_highbd_ssim2(source->y_buffer, dest->y_buffer, | 487 a = vpx_highbd_ssim2(source->y_buffer, dest->y_buffer, |
483 source->y_stride, dest->y_stride, | 488 source->y_stride, dest->y_stride, |
484 source->y_crop_width, source->y_crop_height, bd); | 489 source->y_crop_width, source->y_crop_height, bd); |
485 | 490 |
486 b = vp9_highbd_ssim2(source->u_buffer, dest->u_buffer, | 491 b = vpx_highbd_ssim2(source->u_buffer, dest->u_buffer, |
487 source->uv_stride, dest->uv_stride, | 492 source->uv_stride, dest->uv_stride, |
488 source->uv_crop_width, source->uv_crop_height, bd); | 493 source->uv_crop_width, source->uv_crop_height, bd); |
489 | 494 |
490 c = vp9_highbd_ssim2(source->v_buffer, dest->v_buffer, | 495 c = vpx_highbd_ssim2(source->v_buffer, dest->v_buffer, |
491 source->uv_stride, dest->uv_stride, | 496 source->uv_stride, dest->uv_stride, |
492 source->uv_crop_width, source->uv_crop_height, bd); | 497 source->uv_crop_width, source->uv_crop_height, bd); |
493 *ssim_y = a; | 498 *ssim_y = a; |
494 *ssim_u = b; | 499 *ssim_u = b; |
495 *ssim_v = c; | 500 *ssim_v = c; |
496 ssim_all = (a * 4 + b + c) / 6; | 501 ssim_all = (a * 4 + b + c) / 6; |
497 | 502 |
498 return ssim_all; | 503 return ssim_all; |
499 } | 504 } |
500 #endif // CONFIG_VP9_HIGHBITDEPTH | 505 #endif // CONFIG_VP9_HIGHBITDEPTH |
OLD | NEW |