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

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

Issue 11555023: libvpx: Add VP9 decoder. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 8 years 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11
12 #include "vp9/encoder/vp9_onyx_int.h"
13
14 void vp9_ssim_parms_16x16_c(unsigned char *s, int sp, unsigned char *r,
15 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_sxr) {
18 int i, j;
19 for (i = 0; i < 16; i++, s += sp, r += rp) {
20 for (j = 0; j < 16; j++) {
21 *sum_s += s[j];
22 *sum_r += r[j];
23 *sum_sq_s += s[j] * s[j];
24 *sum_sq_r += r[j] * r[j];
25 *sum_sxr += s[j] * r[j];
26 }
27 }
28 }
29 void vp9_ssim_parms_8x8_c(unsigned char *s, int sp, unsigned char *r, int rp,
30 unsigned long *sum_s, unsigned long *sum_r,
31 unsigned long *sum_sq_s, unsigned long *sum_sq_r,
32 unsigned long *sum_sxr) {
33 int i, j;
34 for (i = 0; i < 8; i++, s += sp, r += rp) {
35 for (j = 0; j < 8; j++) {
36 *sum_s += s[j];
37 *sum_r += r[j];
38 *sum_sq_s += s[j] * s[j];
39 *sum_sq_r += r[j] * r[j];
40 *sum_sxr += s[j] * r[j];
41 }
42 }
43 }
44
45 const static int64_t cc1 = 26634; // (64^2*(.01*255)^2
46 const static int64_t cc2 = 239708; // (64^2*(.03*255)^2
47
48 static double similarity(unsigned long sum_s, unsigned long sum_r,
49 unsigned long sum_sq_s, unsigned long sum_sq_r,
50 unsigned long sum_sxr, int count) {
51 int64_t ssim_n, ssim_d;
52 int64_t c1, c2;
53
54 // scale the constants by number of pixels
55 c1 = (cc1 * count * count) >> 12;
56 c2 = (cc2 * count * count) >> 12;
57
58 ssim_n = (2 * sum_s * sum_r + c1) * ((int64_t) 2 * count * sum_sxr -
59 (int64_t) 2 * sum_s * sum_r + c2);
60
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 +
63 (int64_t)count * sum_sq_r - (int64_t) sum_r * sum_r + c2);
64
65 return ssim_n * 1.0 / ssim_d;
66 }
67
68 static double ssim_16x16(unsigned char *s, int sp, unsigned char *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(unsigned char *s, int sp, unsigned char *r, int rp) {
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,
77 &sum_sxr);
78 return similarity(sum_s, sum_r, sum_sq_s, sum_sq_r, sum_sxr, 64);
79 }
80
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
83 // block boundaries to penalize blocking artifacts.
84 double vp9_ssim2(unsigned char *img1, unsigned char *img2, int stride_img1,
85 int stride_img2, int width, int height) {
86 int i, j;
87 int samples = 0;
88 double ssim_total = 0;
89
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) {
92 for (j = 0; j < width - 8; j += 4) {
93 double v = ssim_8x8(img1 + j, stride_img1, img2 + j, stride_img2);
94 ssim_total += v;
95 samples++;
96 }
97 }
98 ssim_total /= samples;
99 return ssim_total;
100 }
101 double vp9_calc_ssim(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest,
102 int lumamask, double *weight) {
103 double a, b, c;
104 double ssimv;
105
106 a = vp9_ssim2(source->y_buffer, dest->y_buffer,
107 source->y_stride, dest->y_stride, source->y_width,
108 source->y_height);
109
110 b = vp9_ssim2(source->u_buffer, dest->u_buffer,
111 source->uv_stride, dest->uv_stride, source->uv_width,
112 source->uv_height);
113
114 c = vp9_ssim2(source->v_buffer, dest->v_buffer,
115 source->uv_stride, dest->uv_stride, source->uv_width,
116 source->uv_height);
117
118 ssimv = a * .8 + .1 * (b + c);
119
120 *weight = 1;
121
122 return ssimv;
123 }
124
125 double vp9_calc_ssimg(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest,
126 double *ssim_y, double *ssim_u, double *ssim_v) {
127 double ssim_all = 0;
128 double a, b, c;
129
130 a = vp9_ssim2(source->y_buffer, dest->y_buffer,
131 source->y_stride, dest->y_stride, source->y_width,
132 source->y_height);
133
134 b = vp9_ssim2(source->u_buffer, dest->u_buffer,
135 source->uv_stride, dest->uv_stride, source->uv_width,
136 source->uv_height);
137
138 c = vp9_ssim2(source->v_buffer, dest->v_buffer,
139 source->uv_stride, dest->uv_stride, source->uv_width,
140 source->uv_height);
141 *ssim_y = a;
142 *ssim_u = b;
143 *ssim_v = c;
144 ssim_all = (a * 4 + b + c) / 6;
145
146 return ssim_all;
147 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698