Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(676)

Side by Side Diff: source/libvpx/vp9/encoder/vp9_ssim.c

Issue 668403002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_ssim.h ('k') | source/libvpx/vp9/encoder/vp9_svc_layercontext.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 25 matching lines...) Expand all
36 for (j = 0; j < 8; j++) { 36 for (j = 0; j < 8; j++) {
37 *sum_s += s[j]; 37 *sum_s += s[j];
38 *sum_r += r[j]; 38 *sum_r += r[j];
39 *sum_sq_s += s[j] * s[j]; 39 *sum_sq_s += s[j] * s[j];
40 *sum_sq_r += r[j] * r[j]; 40 *sum_sq_r += r[j] * r[j];
41 *sum_sxr += s[j] * r[j]; 41 *sum_sxr += s[j] * r[j];
42 } 42 }
43 } 43 }
44 } 44 }
45 45
46 #if CONFIG_VP9_HIGHBITDEPTH
47 void vp9_highbd_ssim_parms_8x8_c(uint16_t *s, int sp, uint16_t *r, int rp,
48 uint32_t *sum_s, uint32_t *sum_r,
49 uint32_t *sum_sq_s, uint32_t *sum_sq_r,
50 uint32_t *sum_sxr) {
51 int i, j;
52 for (i = 0; i < 8; i++, s += sp, r += rp) {
53 for (j = 0; j < 8; j++) {
54 *sum_s += s[j];
55 *sum_r += r[j];
56 *sum_sq_s += s[j] * s[j];
57 *sum_sq_r += r[j] * r[j];
58 *sum_sxr += s[j] * r[j];
59 }
60 }
61 }
62 #endif // CONFIG_VP9_HIGHBITDEPTH
63
46 static const int64_t cc1 = 26634; // (64^2*(.01*255)^2 64 static const int64_t cc1 = 26634; // (64^2*(.01*255)^2
47 static const int64_t cc2 = 239708; // (64^2*(.03*255)^2 65 static const int64_t cc2 = 239708; // (64^2*(.03*255)^2
48 66
49 static double similarity(unsigned long sum_s, unsigned long sum_r, 67 static double similarity(unsigned long sum_s, unsigned long sum_r,
50 unsigned long sum_sq_s, unsigned long sum_sq_r, 68 unsigned long sum_sq_s, unsigned long sum_sq_r,
51 unsigned long sum_sxr, int count) { 69 unsigned long sum_sxr, int count) {
52 int64_t ssim_n, ssim_d; 70 int64_t ssim_n, ssim_d;
53 int64_t c1, c2; 71 int64_t c1, c2;
54 72
55 // scale the constants by number of pixels 73 // scale the constants by number of pixels
(...skipping 10 matching lines...) Expand all
66 return ssim_n * 1.0 / ssim_d; 84 return ssim_n * 1.0 / ssim_d;
67 } 85 }
68 86
69 static double ssim_8x8(uint8_t *s, int sp, uint8_t *r, int rp) { 87 static double ssim_8x8(uint8_t *s, int sp, uint8_t *r, int rp) {
70 unsigned long sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0; 88 unsigned long sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0;
71 vp9_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r, 89 vp9_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r,
72 &sum_sxr); 90 &sum_sxr);
73 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64); 91 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64);
74 } 92 }
75 93
94 #if CONFIG_VP9_HIGHBITDEPTH
95 static double highbd_ssim_8x8(uint16_t *s, int sp, uint16_t *r, int rp,
96 unsigned int bd) {
97 uint32_t sum_s = 0, sum_r = 0, sum_sq_s = 0, sum_sq_r = 0, sum_sxr = 0;
98 const int oshift = bd - 8;
99 vp9_highbd_ssim_parms_8x8(s, sp, r, rp, &sum_s, &sum_r, &sum_sq_s, &sum_sq_r,
100 &sum_sxr);
101 return similarity(sum_s >> oshift,
102 sum_r >> oshift,
103 sum_sq_s >> (2 * oshift),
104 sum_sq_r >> (2 * oshift),
105 sum_sxr >> (2 * oshift),
106 64);
107 }
108 #endif // CONFIG_VP9_HIGHBITDEPTH
109
76 // We are using a 8x8 moving window with starting location of each 8x8 window 110 // We are using a 8x8 moving window with starting location of each 8x8 window
77 // on the 4x4 pixel grid. Such arrangement allows the windows to overlap 111 // on the 4x4 pixel grid. Such arrangement allows the windows to overlap
78 // block boundaries to penalize blocking artifacts. 112 // block boundaries to penalize blocking artifacts.
79 double vp9_ssim2(uint8_t *img1, uint8_t *img2, int stride_img1, 113 double vp9_ssim2(uint8_t *img1, uint8_t *img2, int stride_img1,
80 int stride_img2, int width, int height) { 114 int stride_img2, int width, int height) {
81 int i, j; 115 int i, j;
82 int samples = 0; 116 int samples = 0;
83 double ssim_total = 0; 117 double ssim_total = 0;
84 118
85 // sample point start with each 4x4 location 119 // sample point start with each 4x4 location
86 for (i = 0; i <= height - 8; 120 for (i = 0; i <= height - 8;
87 i += 4, img1 += stride_img1 * 4, img2 += stride_img2 * 4) { 121 i += 4, img1 += stride_img1 * 4, img2 += stride_img2 * 4) {
88 for (j = 0; j <= width - 8; j += 4) { 122 for (j = 0; j <= width - 8; j += 4) {
89 double v = ssim_8x8(img1 + j, stride_img1, img2 + j, stride_img2); 123 double v = ssim_8x8(img1 + j, stride_img1, img2 + j, stride_img2);
90 ssim_total += v; 124 ssim_total += v;
91 samples++; 125 samples++;
92 } 126 }
93 } 127 }
94 ssim_total /= samples; 128 ssim_total /= samples;
95 return ssim_total; 129 return ssim_total;
96 } 130 }
131
132 #if CONFIG_VP9_HIGHBITDEPTH
133 double vp9_highbd_ssim2(uint8_t *img1, uint8_t *img2, int stride_img1,
134 int stride_img2, int width, int height,
135 unsigned int bd) {
136 int i, j;
137 int samples = 0;
138 double ssim_total = 0;
139
140 // sample point start with each 4x4 location
141 for (i = 0; i <= height - 8;
142 i += 4, img1 += stride_img1 * 4, img2 += stride_img2 * 4) {
143 for (j = 0; j <= width - 8; j += 4) {
144 double v = highbd_ssim_8x8(CONVERT_TO_SHORTPTR(img1 + j), stride_img1,
145 CONVERT_TO_SHORTPTR(img2 + j), stride_img2,
146 bd);
147 ssim_total += v;
148 samples++;
149 }
150 }
151 ssim_total /= samples;
152 return ssim_total;
153 }
154 #endif // CONFIG_VP9_HIGHBITDEPTH
155
97 double vp9_calc_ssim(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest, 156 double vp9_calc_ssim(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest,
98 double *weight) { 157 double *weight) {
99 double a, b, c; 158 double a, b, c;
100 double ssimv; 159 double ssimv;
101 160
102 a = vp9_ssim2(source->y_buffer, dest->y_buffer, 161 a = vp9_ssim2(source->y_buffer, dest->y_buffer,
103 source->y_stride, dest->y_stride, 162 source->y_stride, dest->y_stride,
104 source->y_crop_width, source->y_crop_height); 163 source->y_crop_width, source->y_crop_height);
105 164
106 b = vp9_ssim2(source->u_buffer, dest->u_buffer, 165 b = vp9_ssim2(source->u_buffer, dest->u_buffer,
(...skipping 27 matching lines...) Expand all
134 c = vp9_ssim2(source->v_buffer, dest->v_buffer, 193 c = vp9_ssim2(source->v_buffer, dest->v_buffer,
135 source->uv_stride, dest->uv_stride, 194 source->uv_stride, dest->uv_stride,
136 source->uv_crop_width, source->uv_crop_height); 195 source->uv_crop_width, source->uv_crop_height);
137 *ssim_y = a; 196 *ssim_y = a;
138 *ssim_u = b; 197 *ssim_u = b;
139 *ssim_v = c; 198 *ssim_v = c;
140 ssim_all = (a * 4 + b + c) / 6; 199 ssim_all = (a * 4 + b + c) / 6;
141 200
142 return ssim_all; 201 return ssim_all;
143 } 202 }
203
204 #if CONFIG_VP9_HIGHBITDEPTH
205 double vp9_highbd_calc_ssim(YV12_BUFFER_CONFIG *source,
206 YV12_BUFFER_CONFIG *dest,
207 double *weight, unsigned int bd) {
208 double a, b, c;
209 double ssimv;
210
211 a = vp9_highbd_ssim2(source->y_buffer, dest->y_buffer,
212 source->y_stride, dest->y_stride,
213 source->y_crop_width, source->y_crop_height, bd);
214
215 b = vp9_highbd_ssim2(source->u_buffer, dest->u_buffer,
216 source->uv_stride, dest->uv_stride,
217 source->uv_crop_width, source->uv_crop_height, bd);
218
219 c = vp9_highbd_ssim2(source->v_buffer, dest->v_buffer,
220 source->uv_stride, dest->uv_stride,
221 source->uv_crop_width, source->uv_crop_height, bd);
222
223 ssimv = a * .8 + .1 * (b + c);
224
225 *weight = 1;
226
227 return ssimv;
228 }
229
230 double vp9_highbd_calc_ssimg(YV12_BUFFER_CONFIG *source,
231 YV12_BUFFER_CONFIG *dest, double *ssim_y,
232 double *ssim_u, double *ssim_v, unsigned int bd) {
233 double ssim_all = 0;
234 double a, b, c;
235
236 a = vp9_highbd_ssim2(source->y_buffer, dest->y_buffer,
237 source->y_stride, dest->y_stride,
238 source->y_crop_width, source->y_crop_height, bd);
239
240 b = vp9_highbd_ssim2(source->u_buffer, dest->u_buffer,
241 source->uv_stride, dest->uv_stride,
242 source->uv_crop_width, source->uv_crop_height, bd);
243
244 c = vp9_highbd_ssim2(source->v_buffer, dest->v_buffer,
245 source->uv_stride, dest->uv_stride,
246 source->uv_crop_width, source->uv_crop_height, bd);
247 *ssim_y = a;
248 *ssim_u = b;
249 *ssim_v = c;
250 ssim_all = (a * 4 + b + c) / 6;
251
252 return ssim_all;
253 }
254 #endif // CONFIG_VP9_HIGHBITDEPTH
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_ssim.h ('k') | source/libvpx/vp9/encoder/vp9_svc_layercontext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698