Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
| 3 | * |
| 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 11 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 12 | #include <assert.h> |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 13 | #include <math.h> |
| 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_dsp_rtcd.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | #include "aom_dsp/psnr.h" |
| 17 | #include "aom_scale/yv12config.h" |
| 18 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 19 | double aom_sse_to_psnr(double samples, double peak, double sse) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | if (sse > 0.0) { |
| 21 | const double psnr = 10.0 * log10(samples * peak * peak / sse); |
| 22 | return psnr > MAX_PSNR ? MAX_PSNR : psnr; |
| 23 | } else { |
| 24 | return MAX_PSNR; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /* TODO(yaowu): The block_variance calls the unoptimized versions of variance() |
| 29 | * and highbd_8_variance(). It should not. |
| 30 | */ |
| 31 | static void encoder_variance(const uint8_t *a, int a_stride, const uint8_t *b, |
| 32 | int b_stride, int w, int h, unsigned int *sse, |
| 33 | int *sum) { |
| 34 | int i, j; |
| 35 | |
| 36 | *sum = 0; |
| 37 | *sse = 0; |
| 38 | |
| 39 | for (i = 0; i < h; i++) { |
| 40 | for (j = 0; j < w; j++) { |
| 41 | const int diff = a[j] - b[j]; |
| 42 | *sum += diff; |
| 43 | *sse += diff * diff; |
| 44 | } |
| 45 | |
| 46 | a += a_stride; |
| 47 | b += b_stride; |
| 48 | } |
| 49 | } |
| 50 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 51 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 52 | static void encoder_highbd_variance64(const uint8_t *a8, int a_stride, |
| 53 | const uint8_t *b8, int b_stride, int w, |
| 54 | int h, uint64_t *sse, int64_t *sum) { |
| 55 | int i, j; |
| 56 | |
| 57 | uint16_t *a = CONVERT_TO_SHORTPTR(a8); |
| 58 | uint16_t *b = CONVERT_TO_SHORTPTR(b8); |
| 59 | *sum = 0; |
| 60 | *sse = 0; |
| 61 | |
| 62 | for (i = 0; i < h; i++) { |
| 63 | for (j = 0; j < w; j++) { |
| 64 | const int diff = a[j] - b[j]; |
| 65 | *sum += diff; |
| 66 | *sse += diff * diff; |
| 67 | } |
| 68 | a += a_stride; |
| 69 | b += b_stride; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | static void encoder_highbd_8_variance(const uint8_t *a8, int a_stride, |
| 74 | const uint8_t *b8, int b_stride, int w, |
| 75 | int h, unsigned int *sse, int *sum) { |
| 76 | uint64_t sse_long = 0; |
| 77 | int64_t sum_long = 0; |
| 78 | encoder_highbd_variance64(a8, a_stride, b8, b_stride, w, h, &sse_long, |
| 79 | &sum_long); |
| 80 | *sse = (unsigned int)sse_long; |
| 81 | *sum = (int)sum_long; |
| 82 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 83 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 84 | |
| 85 | static int64_t get_sse(const uint8_t *a, int a_stride, const uint8_t *b, |
| 86 | int b_stride, int width, int height) { |
| 87 | const int dw = width % 16; |
| 88 | const int dh = height % 16; |
| 89 | int64_t total_sse = 0; |
| 90 | unsigned int sse = 0; |
| 91 | int sum = 0; |
| 92 | int x, y; |
| 93 | |
| 94 | if (dw > 0) { |
| 95 | encoder_variance(&a[width - dw], a_stride, &b[width - dw], b_stride, dw, |
| 96 | height, &sse, &sum); |
| 97 | total_sse += sse; |
| 98 | } |
| 99 | |
| 100 | if (dh > 0) { |
| 101 | encoder_variance(&a[(height - dh) * a_stride], a_stride, |
| 102 | &b[(height - dh) * b_stride], b_stride, width - dw, dh, |
| 103 | &sse, &sum); |
| 104 | total_sse += sse; |
| 105 | } |
| 106 | |
| 107 | for (y = 0; y < height / 16; ++y) { |
| 108 | const uint8_t *pa = a; |
| 109 | const uint8_t *pb = b; |
| 110 | for (x = 0; x < width / 16; ++x) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 111 | aom_mse16x16(pa, a_stride, pb, b_stride, &sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 112 | total_sse += sse; |
| 113 | |
| 114 | pa += 16; |
| 115 | pb += 16; |
| 116 | } |
| 117 | |
| 118 | a += 16 * a_stride; |
| 119 | b += 16 * b_stride; |
| 120 | } |
| 121 | |
| 122 | return total_sse; |
| 123 | } |
| 124 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 125 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 126 | static int64_t highbd_get_sse_shift(const uint8_t *a8, int a_stride, |
| 127 | const uint8_t *b8, int b_stride, int width, |
| 128 | int height, unsigned int input_shift) { |
| 129 | const uint16_t *a = CONVERT_TO_SHORTPTR(a8); |
| 130 | const uint16_t *b = CONVERT_TO_SHORTPTR(b8); |
| 131 | int64_t total_sse = 0; |
| 132 | int x, y; |
| 133 | for (y = 0; y < height; ++y) { |
| 134 | for (x = 0; x < width; ++x) { |
| 135 | int64_t diff; |
| 136 | diff = (a[x] >> input_shift) - (b[x] >> input_shift); |
| 137 | total_sse += diff * diff; |
| 138 | } |
| 139 | a += a_stride; |
| 140 | b += b_stride; |
| 141 | } |
| 142 | return total_sse; |
| 143 | } |
| 144 | |
| 145 | static int64_t highbd_get_sse(const uint8_t *a, int a_stride, const uint8_t *b, |
| 146 | int b_stride, int width, int height) { |
| 147 | int64_t total_sse = 0; |
| 148 | int x, y; |
| 149 | const int dw = width % 16; |
| 150 | const int dh = height % 16; |
| 151 | unsigned int sse = 0; |
| 152 | int sum = 0; |
| 153 | if (dw > 0) { |
| 154 | encoder_highbd_8_variance(&a[width - dw], a_stride, &b[width - dw], |
| 155 | b_stride, dw, height, &sse, &sum); |
| 156 | total_sse += sse; |
| 157 | } |
| 158 | if (dh > 0) { |
| 159 | encoder_highbd_8_variance(&a[(height - dh) * a_stride], a_stride, |
| 160 | &b[(height - dh) * b_stride], b_stride, |
| 161 | width - dw, dh, &sse, &sum); |
| 162 | total_sse += sse; |
| 163 | } |
| 164 | for (y = 0; y < height / 16; ++y) { |
| 165 | const uint8_t *pa = a; |
| 166 | const uint8_t *pb = b; |
| 167 | for (x = 0; x < width / 16; ++x) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 168 | aom_highbd_8_mse16x16(pa, a_stride, pb, b_stride, &sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 169 | total_sse += sse; |
| 170 | pa += 16; |
| 171 | pb += 16; |
| 172 | } |
| 173 | a += 16 * a_stride; |
| 174 | b += 16 * b_stride; |
| 175 | } |
| 176 | return total_sse; |
| 177 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 178 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 179 | |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 180 | int64_t aom_get_y_sse_part(const YV12_BUFFER_CONFIG *a, |
clang-format | bda8d61 | 2016-09-19 15:55:46 -0700 | [diff] [blame] | 181 | const YV12_BUFFER_CONFIG *b, int hstart, int width, |
| 182 | int vstart, int height) { |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 183 | return get_sse(a->y_buffer + vstart * a->y_stride + hstart, a->y_stride, |
| 184 | b->y_buffer + vstart * b->y_stride + hstart, b->y_stride, |
| 185 | width, height); |
| 186 | } |
| 187 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 188 | int64_t aom_get_y_sse(const YV12_BUFFER_CONFIG *a, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 189 | const YV12_BUFFER_CONFIG *b) { |
| 190 | assert(a->y_crop_width == b->y_crop_width); |
| 191 | assert(a->y_crop_height == b->y_crop_height); |
| 192 | |
| 193 | return get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, |
| 194 | a->y_crop_width, a->y_crop_height); |
| 195 | } |
| 196 | |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 197 | int64_t aom_get_u_sse_part(const YV12_BUFFER_CONFIG *a, |
| 198 | const YV12_BUFFER_CONFIG *b, int hstart, int width, |
| 199 | int vstart, int height) { |
| 200 | return get_sse(a->u_buffer + vstart * a->uv_stride + hstart, a->uv_stride, |
| 201 | b->u_buffer + vstart * b->uv_stride + hstart, b->uv_stride, |
| 202 | width, height); |
| 203 | } |
| 204 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 205 | int64_t aom_get_u_sse(const YV12_BUFFER_CONFIG *a, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 206 | const YV12_BUFFER_CONFIG *b) { |
| 207 | assert(a->uv_crop_width == b->uv_crop_width); |
| 208 | assert(a->uv_crop_height == b->uv_crop_height); |
| 209 | |
| 210 | return get_sse(a->u_buffer, a->uv_stride, b->u_buffer, b->uv_stride, |
| 211 | a->uv_crop_width, a->uv_crop_height); |
| 212 | } |
| 213 | |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 214 | int64_t aom_get_v_sse_part(const YV12_BUFFER_CONFIG *a, |
| 215 | const YV12_BUFFER_CONFIG *b, int hstart, int width, |
| 216 | int vstart, int height) { |
| 217 | return get_sse(a->v_buffer + vstart * a->uv_stride + hstart, a->uv_stride, |
| 218 | b->v_buffer + vstart * b->uv_stride + hstart, b->uv_stride, |
| 219 | width, height); |
| 220 | } |
| 221 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 222 | int64_t aom_get_v_sse(const YV12_BUFFER_CONFIG *a, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 223 | const YV12_BUFFER_CONFIG *b) { |
| 224 | assert(a->uv_crop_width == b->uv_crop_width); |
| 225 | assert(a->uv_crop_height == b->uv_crop_height); |
| 226 | |
| 227 | return get_sse(a->v_buffer, a->uv_stride, b->v_buffer, b->uv_stride, |
| 228 | a->uv_crop_width, a->uv_crop_height); |
| 229 | } |
| 230 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 231 | #if CONFIG_HIGHBITDEPTH |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 232 | int64_t aom_highbd_get_y_sse_part(const YV12_BUFFER_CONFIG *a, |
clang-format | bda8d61 | 2016-09-19 15:55:46 -0700 | [diff] [blame] | 233 | const YV12_BUFFER_CONFIG *b, int hstart, |
| 234 | int width, int vstart, int height) { |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 235 | return highbd_get_sse( |
| 236 | a->y_buffer + vstart * a->y_stride + hstart, a->y_stride, |
clang-format | bda8d61 | 2016-09-19 15:55:46 -0700 | [diff] [blame] | 237 | b->y_buffer + vstart * b->y_stride + hstart, b->y_stride, width, height); |
Debargha Mukherjee | 5cd2ab9 | 2016-09-08 15:15:17 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 240 | int64_t aom_highbd_get_y_sse(const YV12_BUFFER_CONFIG *a, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 241 | const YV12_BUFFER_CONFIG *b) { |
| 242 | assert(a->y_crop_width == b->y_crop_width); |
| 243 | assert(a->y_crop_height == b->y_crop_height); |
| 244 | assert((a->flags & YV12_FLAG_HIGHBITDEPTH) != 0); |
| 245 | assert((b->flags & YV12_FLAG_HIGHBITDEPTH) != 0); |
| 246 | |
| 247 | return highbd_get_sse(a->y_buffer, a->y_stride, b->y_buffer, b->y_stride, |
| 248 | a->y_crop_width, a->y_crop_height); |
| 249 | } |
| 250 | |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 251 | int64_t aom_highbd_get_u_sse_part(const YV12_BUFFER_CONFIG *a, |
| 252 | const YV12_BUFFER_CONFIG *b, int hstart, |
| 253 | int width, int vstart, int height) { |
| 254 | return highbd_get_sse(a->u_buffer + vstart * a->uv_stride + hstart, |
| 255 | a->uv_stride, |
| 256 | b->u_buffer + vstart * b->uv_stride + hstart, |
| 257 | b->uv_stride, width, height); |
| 258 | } |
| 259 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 260 | int64_t aom_highbd_get_u_sse(const YV12_BUFFER_CONFIG *a, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 261 | const YV12_BUFFER_CONFIG *b) { |
| 262 | assert(a->uv_crop_width == b->uv_crop_width); |
| 263 | assert(a->uv_crop_height == b->uv_crop_height); |
| 264 | assert((a->flags & YV12_FLAG_HIGHBITDEPTH) != 0); |
| 265 | assert((b->flags & YV12_FLAG_HIGHBITDEPTH) != 0); |
| 266 | |
| 267 | return highbd_get_sse(a->u_buffer, a->uv_stride, b->u_buffer, b->uv_stride, |
| 268 | a->uv_crop_width, a->uv_crop_height); |
| 269 | } |
| 270 | |
Debargha Mukherjee | 874d36d | 2016-12-14 16:53:17 -0800 | [diff] [blame] | 271 | int64_t aom_highbd_get_v_sse_part(const YV12_BUFFER_CONFIG *a, |
| 272 | const YV12_BUFFER_CONFIG *b, int hstart, |
| 273 | int width, int vstart, int height) { |
| 274 | return highbd_get_sse(a->v_buffer + vstart * a->uv_stride + hstart, |
| 275 | a->uv_stride, |
| 276 | b->v_buffer + vstart * b->uv_stride + hstart, |
| 277 | b->uv_stride, width, height); |
| 278 | } |
| 279 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 280 | int64_t aom_highbd_get_v_sse(const YV12_BUFFER_CONFIG *a, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 281 | const YV12_BUFFER_CONFIG *b) { |
| 282 | assert(a->uv_crop_width == b->uv_crop_width); |
| 283 | assert(a->uv_crop_height == b->uv_crop_height); |
| 284 | assert((a->flags & YV12_FLAG_HIGHBITDEPTH) != 0); |
| 285 | assert((b->flags & YV12_FLAG_HIGHBITDEPTH) != 0); |
| 286 | |
| 287 | return highbd_get_sse(a->v_buffer, a->uv_stride, b->v_buffer, b->uv_stride, |
| 288 | a->uv_crop_width, a->uv_crop_height); |
| 289 | } |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 290 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 291 | |
Cheng Chen | 9efbaf9 | 2017-07-27 14:09:59 -0700 | [diff] [blame] | 292 | int64_t aom_get_sse_plane(const YV12_BUFFER_CONFIG *a, |
| 293 | const YV12_BUFFER_CONFIG *b, int plane, int highbd) { |
| 294 | #if CONFIG_HIGHBITDEPTH |
| 295 | if (highbd) { |
| 296 | switch (plane) { |
| 297 | case 0: return aom_highbd_get_y_sse(a, b); |
| 298 | case 1: return aom_highbd_get_u_sse(a, b); |
| 299 | case 2: return aom_highbd_get_v_sse(a, b); |
| 300 | default: assert(plane >= 0 && plane <= 2); return 0; |
| 301 | } |
| 302 | } |
| 303 | #endif |
| 304 | (void)highbd; |
| 305 | switch (plane) { |
| 306 | case 0: return aom_get_y_sse(a, b); |
| 307 | case 1: return aom_get_u_sse(a, b); |
| 308 | case 2: return aom_get_v_sse(a, b); |
| 309 | default: assert(plane >= 0 && plane <= 2); return 0; |
| 310 | } |
| 311 | } |
| 312 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 313 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 314 | void aom_calc_highbd_psnr(const YV12_BUFFER_CONFIG *a, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 315 | const YV12_BUFFER_CONFIG *b, PSNR_STATS *psnr, |
| 316 | uint32_t bit_depth, uint32_t in_bit_depth) { |
| 317 | const int widths[3] = { a->y_crop_width, a->uv_crop_width, a->uv_crop_width }; |
| 318 | const int heights[3] = { a->y_crop_height, a->uv_crop_height, |
| 319 | a->uv_crop_height }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 320 | const int a_strides[3] = { a->y_stride, a->uv_stride, a->uv_stride }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 321 | const int b_strides[3] = { b->y_stride, b->uv_stride, b->uv_stride }; |
| 322 | int i; |
| 323 | uint64_t total_sse = 0; |
| 324 | uint32_t total_samples = 0; |
| 325 | const double peak = (double)((1 << in_bit_depth) - 1); |
| 326 | const unsigned int input_shift = bit_depth - in_bit_depth; |
| 327 | |
| 328 | for (i = 0; i < 3; ++i) { |
| 329 | const int w = widths[i]; |
| 330 | const int h = heights[i]; |
| 331 | const uint32_t samples = w * h; |
| 332 | uint64_t sse; |
| 333 | if (a->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 334 | if (input_shift) { |
Rupert Swarbrick | 82529d2 | 2017-09-20 13:36:39 +0100 | [diff] [blame] | 335 | sse = highbd_get_sse_shift(a->buffers[i], a_strides[i], b->buffers[i], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 336 | b_strides[i], w, h, input_shift); |
| 337 | } else { |
Rupert Swarbrick | 82529d2 | 2017-09-20 13:36:39 +0100 | [diff] [blame] | 338 | sse = highbd_get_sse(a->buffers[i], a_strides[i], b->buffers[i], |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 339 | b_strides[i], w, h); |
| 340 | } |
| 341 | } else { |
Rupert Swarbrick | 82529d2 | 2017-09-20 13:36:39 +0100 | [diff] [blame] | 342 | sse = get_sse(a->buffers[i], a_strides[i], b->buffers[i], b_strides[i], w, |
| 343 | h); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 344 | } |
| 345 | psnr->sse[1 + i] = sse; |
| 346 | psnr->samples[1 + i] = samples; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 347 | psnr->psnr[1 + i] = aom_sse_to_psnr(samples, peak, (double)sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 348 | |
| 349 | total_sse += sse; |
| 350 | total_samples += samples; |
| 351 | } |
| 352 | |
| 353 | psnr->sse[0] = total_sse; |
| 354 | psnr->samples[0] = total_samples; |
| 355 | psnr->psnr[0] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 356 | aom_sse_to_psnr((double)total_samples, peak, (double)total_sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 359 | #endif // !CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 360 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 361 | void aom_calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 362 | PSNR_STATS *psnr) { |
| 363 | static const double peak = 255.0; |
| 364 | const int widths[3] = { a->y_crop_width, a->uv_crop_width, a->uv_crop_width }; |
| 365 | const int heights[3] = { a->y_crop_height, a->uv_crop_height, |
| 366 | a->uv_crop_height }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 367 | const int a_strides[3] = { a->y_stride, a->uv_stride, a->uv_stride }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 368 | const int b_strides[3] = { b->y_stride, b->uv_stride, b->uv_stride }; |
| 369 | int i; |
| 370 | uint64_t total_sse = 0; |
| 371 | uint32_t total_samples = 0; |
| 372 | |
| 373 | for (i = 0; i < 3; ++i) { |
| 374 | const int w = widths[i]; |
| 375 | const int h = heights[i]; |
| 376 | const uint32_t samples = w * h; |
| 377 | const uint64_t sse = |
Rupert Swarbrick | 82529d2 | 2017-09-20 13:36:39 +0100 | [diff] [blame] | 378 | get_sse(a->buffers[i], a_strides[i], b->buffers[i], b_strides[i], w, h); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 379 | psnr->sse[1 + i] = sse; |
| 380 | psnr->samples[1 + i] = samples; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 381 | psnr->psnr[1 + i] = aom_sse_to_psnr(samples, peak, (double)sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 382 | |
| 383 | total_sse += sse; |
| 384 | total_samples += samples; |
| 385 | } |
| 386 | |
| 387 | psnr->sse[0] = total_sse; |
| 388 | psnr->samples[0] = total_samples; |
| 389 | psnr->psnr[0] = |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 390 | aom_sse_to_psnr((double)total_samples, peak, (double)total_sse); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 391 | } |