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

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

Issue 1124333011: libvpx: Pull from upstream (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libvpx.git@master
Patch Set: only update to last nights LKGR Created 5 years, 7 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
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_pickmode.c ('k') | source/libvpx/vp9/encoder/vp9_quantize.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * This code was originally written by: Gregory Maxwell, at the Daala
11 * project.
12 */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <math.h>
16
17 #include "./vpx_config.h"
18 #include "./vp9_rtcd.h"
19 #include "vp9/encoder/vp9_ssim.h"
20
21 #if !defined(M_PI)
22 # define M_PI (3.141592653589793238462643)
23 #endif
24 #include <string.h>
25
26 void od_bin_fdct8x8(tran_low_t *y, int ystride, const int16_t *x, int xstride) {
27 (void) xstride;
28 vp9_fdct8x8_c(x, y, ystride);
29 }
30
31 /* Normalized inverse quantization matrix for 8x8 DCT at the point of
32 * transparency. This is not the JPEG based matrix from the paper,
33 this one gives a slightly higher MOS agreement.*/
34 float csf_y[8][8] = {{1.6193873005, 2.2901594831, 2.08509755623, 1.48366094411,
35 1.00227514334, 0.678296995242, 0.466224900598, 0.3265091542}, {2.2901594831,
36 1.94321815382, 2.04793073064, 1.68731108984, 1.2305666963, 0.868920337363,
37 0.61280991668, 0.436405793551}, {2.08509755623, 2.04793073064,
38 1.34329019223, 1.09205635862, 0.875748795257, 0.670882927016,
39 0.501731932449, 0.372504254596}, {1.48366094411, 1.68731108984,
40 1.09205635862, 0.772819797575, 0.605636379554, 0.48309405692,
41 0.380429446972, 0.295774038565}, {1.00227514334, 1.2305666963,
42 0.875748795257, 0.605636379554, 0.448996256676, 0.352889268808,
43 0.283006984131, 0.226951348204}, {0.678296995242, 0.868920337363,
44 0.670882927016, 0.48309405692, 0.352889268808, 0.27032073436,
45 0.215017739696, 0.17408067321}, {0.466224900598, 0.61280991668,
46 0.501731932449, 0.380429446972, 0.283006984131, 0.215017739696,
47 0.168869545842, 0.136153931001}, {0.3265091542, 0.436405793551,
48 0.372504254596, 0.295774038565, 0.226951348204, 0.17408067321,
49 0.136153931001, 0.109083846276}};
50 float csf_cb420[8][8] = {
51 {1.91113096927, 2.46074210438, 1.18284184739, 1.14982565193, 1.05017074788,
52 0.898018824055, 0.74725392039, 0.615105596242}, {2.46074210438,
53 1.58529308355, 1.21363250036, 1.38190029285, 1.33100189972,
54 1.17428548929, 0.996404342439, 0.830890433625}, {1.18284184739,
55 1.21363250036, 0.978712413627, 1.02624506078, 1.03145147362,
56 0.960060382087, 0.849823426169, 0.731221236837}, {1.14982565193,
57 1.38190029285, 1.02624506078, 0.861317501629, 0.801821139099,
58 0.751437590932, 0.685398513368, 0.608694761374}, {1.05017074788,
59 1.33100189972, 1.03145147362, 0.801821139099, 0.676555426187,
60 0.605503172737, 0.55002013668, 0.495804539034}, {0.898018824055,
61 1.17428548929, 0.960060382087, 0.751437590932, 0.605503172737,
62 0.514674450957, 0.454353482512, 0.407050308965}, {0.74725392039,
63 0.996404342439, 0.849823426169, 0.685398513368, 0.55002013668,
64 0.454353482512, 0.389234902883, 0.342353999733}, {0.615105596242,
65 0.830890433625, 0.731221236837, 0.608694761374, 0.495804539034,
66 0.407050308965, 0.342353999733, 0.295530605237}};
67 float csf_cr420[8][8] = {
68 {2.03871978502, 2.62502345193, 1.26180942886, 1.11019789803, 1.01397751469,
69 0.867069376285, 0.721500455585, 0.593906509971}, {2.62502345193,
70 1.69112867013, 1.17180569821, 1.3342742857, 1.28513006198,
71 1.13381474809, 0.962064122248, 0.802254508198}, {1.26180942886,
72 1.17180569821, 0.944981930573, 0.990876405848, 0.995903384143,
73 0.926972725286, 0.820534991409, 0.706020324706}, {1.11019789803,
74 1.3342742857, 0.990876405848, 0.831632933426, 0.77418706195,
75 0.725539939514, 0.661776842059, 0.587716619023}, {1.01397751469,
76 1.28513006198, 0.995903384143, 0.77418706195, 0.653238524286,
77 0.584635025748, 0.531064164893, 0.478717061273}, {0.867069376285,
78 1.13381474809, 0.926972725286, 0.725539939514, 0.584635025748,
79 0.496936637883, 0.438694579826, 0.393021669543}, {0.721500455585,
80 0.962064122248, 0.820534991409, 0.661776842059, 0.531064164893,
81 0.438694579826, 0.375820256136, 0.330555063063}, {0.593906509971,
82 0.802254508198, 0.706020324706, 0.587716619023, 0.478717061273,
83 0.393021669543, 0.330555063063, 0.285345396658}};
84
85 static double convert_score_db(double _score, double _weight) {
86 return 10 * (log10(255 * 255) - log10(_weight * _score));
87 }
88
89 static double calc_psnrhvs(const unsigned char *_src, int _systride,
90 const unsigned char *_dst, int _dystride,
91 double _par, int _w, int _h, int _step,
92 float _csf[8][8]) {
93 float ret;
94 int16_t dct_s[8 * 8], dct_d[8 * 8];
95 tran_low_t dct_s_coef[8 * 8], dct_d_coef[8 * 8];
96 float mask[8][8];
97 int pixels;
98 int x;
99 int y;
100 (void) _par;
101 ret = pixels = 0;
102 /*In the PSNR-HVS-M paper[1] the authors describe the construction of
103 their masking table as "we have used the quantization table for the
104 color component Y of JPEG [6] that has been also obtained on the
105 basis of CSF. Note that the values in quantization table JPEG have
106 been normalized and then squared." Their CSF matrix (from PSNR-HVS)
107 was also constructed from the JPEG matrices. I can not find any obvious
108 scheme of normalizing to produce their table, but if I multiply their
109 CSF by 0.38857 and square the result I get their masking table.
110 I have no idea where this constant comes from, but deviating from it
111 too greatly hurts MOS agreement.
112
113 [1] Nikolay Ponomarenko, Flavia Silvestri, Karen Egiazarian, Marco Carli,
114 Jaakko Astola, Vladimir Lukin, "On between-coefficient contrast masking
115 of DCT basis functions", CD-ROM Proceedings of the Third
116 International Workshop on Video Processing and Quality Metrics for Consumer
117 Electronics VPQM-07, Scottsdale, Arizona, USA, 25-26 January, 2007, 4 p.*/
118 for (x = 0; x < 8; x++)
119 for (y = 0; y < 8; y++)
120 mask[x][y] = (_csf[x][y] * 0.3885746225901003)
121 * (_csf[x][y] * 0.3885746225901003);
122 for (y = 0; y < _h - 7; y += _step) {
123 for (x = 0; x < _w - 7; x += _step) {
124 int i;
125 int j;
126 float s_means[4];
127 float d_means[4];
128 float s_vars[4];
129 float d_vars[4];
130 float s_gmean = 0;
131 float d_gmean = 0;
132 float s_gvar = 0;
133 float d_gvar = 0;
134 float s_mask = 0;
135 float d_mask = 0;
136 for (i = 0; i < 4; i++)
137 s_means[i] = d_means[i] = s_vars[i] = d_vars[i] = 0;
138 for (i = 0; i < 8; i++) {
139 for (j = 0; j < 8; j++) {
140 int sub = ((i & 12) >> 2) + ((j & 12) >> 1);
141 dct_s[i * 8 + j] = _src[(y + i) * _systride + (j + x)];
142 dct_d[i * 8 + j] = _dst[(y + i) * _dystride + (j + x)];
143 s_gmean += dct_s[i * 8 + j];
144 d_gmean += dct_d[i * 8 + j];
145 s_means[sub] += dct_s[i * 8 + j];
146 d_means[sub] += dct_d[i * 8 + j];
147 }
148 }
149 s_gmean /= 64.f;
150 d_gmean /= 64.f;
151 for (i = 0; i < 4; i++)
152 s_means[i] /= 16.f;
153 for (i = 0; i < 4; i++)
154 d_means[i] /= 16.f;
155 for (i = 0; i < 8; i++) {
156 for (j = 0; j < 8; j++) {
157 int sub = ((i & 12) >> 2) + ((j & 12) >> 1);
158 s_gvar += (dct_s[i * 8 + j] - s_gmean) * (dct_s[i * 8 + j] - s_gmean);
159 d_gvar += (dct_d[i * 8 + j] - d_gmean) * (dct_d[i * 8 + j] - d_gmean);
160 s_vars[sub] += (dct_s[i * 8 + j] - s_means[sub])
161 * (dct_s[i * 8 + j] - s_means[sub]);
162 d_vars[sub] += (dct_d[i * 8 + j] - d_means[sub])
163 * (dct_d[i * 8 + j] - d_means[sub]);
164 }
165 }
166 s_gvar *= 1 / 63.f * 64;
167 d_gvar *= 1 / 63.f * 64;
168 for (i = 0; i < 4; i++)
169 s_vars[i] *= 1 / 15.f * 16;
170 for (i = 0; i < 4; i++)
171 d_vars[i] *= 1 / 15.f * 16;
172 if (s_gvar > 0)
173 s_gvar = (s_vars[0] + s_vars[1] + s_vars[2] + s_vars[3]) / s_gvar;
174 if (d_gvar > 0)
175 d_gvar = (d_vars[0] + d_vars[1] + d_vars[2] + d_vars[3]) / d_gvar;
176 od_bin_fdct8x8(dct_s_coef, 8, dct_s, 8);
177 od_bin_fdct8x8(dct_d_coef, 8, dct_d, 8);
178 for (i = 0; i < 8; i++)
179 for (j = (i == 0); j < 8; j++)
180 s_mask += dct_s_coef[i * 8 + j] * dct_s_coef[i * 8 + j] * mask[i][j];
181 for (i = 0; i < 8; i++)
182 for (j = (i == 0); j < 8; j++)
183 d_mask += dct_d_coef[i * 8 + j] * dct_d_coef[i * 8 + j] * mask[i][j];
184 s_mask = sqrt(s_mask * s_gvar) / 32.f;
185 d_mask = sqrt(d_mask * d_gvar) / 32.f;
186 if (d_mask > s_mask)
187 s_mask = d_mask;
188 for (i = 0; i < 8; i++) {
189 for (j = 0; j < 8; j++) {
190 float err;
191 err = fabs(dct_s_coef[i * 8 + j] - dct_d_coef[i * 8 + j]);
192 if (i != 0 || j != 0)
193 err = err < s_mask / mask[i][j] ? 0 : err - s_mask / mask[i][j];
194 ret += (err * _csf[i][j]) * (err * _csf[i][j]);
195 pixels++;
196 }
197 }
198 }
199 }
200 ret /= pixels;
201 return ret;
202 }
203 double vp9_psnrhvs(YV12_BUFFER_CONFIG *source, YV12_BUFFER_CONFIG *dest,
204 double *y_psnrhvs, double *u_psnrhvs, double *v_psnrhvs) {
205 double psnrhvs;
206 double par = 1.0;
207 int step = 7;
208 vp9_clear_system_state();
209 *y_psnrhvs = calc_psnrhvs(source->y_buffer, source->y_stride, dest->y_buffer,
210 dest->y_stride, par, source->y_crop_width,
211 source->y_crop_height, step, csf_y);
212
213 *u_psnrhvs = calc_psnrhvs(source->u_buffer, source->uv_stride, dest->u_buffer,
214 dest->uv_stride, par, source->uv_crop_width,
215 source->uv_crop_height, step, csf_cb420);
216
217 *v_psnrhvs = calc_psnrhvs(source->v_buffer, source->uv_stride, dest->v_buffer,
218 dest->uv_stride, par, source->uv_crop_width,
219 source->uv_crop_height, step, csf_cr420);
220 psnrhvs = (*y_psnrhvs) * .8 + .1 * ((*u_psnrhvs) + (*v_psnrhvs));
221
222 return convert_score_db(psnrhvs, 1.0);
223 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_pickmode.c ('k') | source/libvpx/vp9/encoder/vp9_quantize.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698