blob: 4d7f3d41ed57b696e958760609cf87e969359664 [file] [log] [blame]
Yunqing Wange61573c2012-06-28 10:37:53 -07001/*
2 * Copyright (c) 2012 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#ifndef TEST_UTIL_H_
12#define TEST_UTIL_H_
13
Deb Mukherjee01cafaa2013-01-15 06:43:35 -080014#include <stdio.h>
15#include <math.h>
16#include "third_party/googletest/src/include/gtest/gtest.h"
17#include "vpx/vpx_image.h"
18
Yunqing Wange61573c2012-06-28 10:37:53 -070019// Macros
20#define PARAMS(...) ::testing::TestWithParam< std::tr1::tuple< __VA_ARGS__ > >
21#define GET_PARAM(k) std::tr1::get< k >(GetParam())
22
Deb Mukherjee01cafaa2013-01-15 06:43:35 -080023static double compute_psnr(const vpx_image_t *img1,
24 const vpx_image_t *img2) {
25 assert((img1->fmt == img2->fmt) &&
26 (img1->d_w == img2->d_w) &&
27 (img1->d_h == img2->d_h));
28
29 const unsigned int width_y = img1->d_w;
30 const unsigned int height_y = img1->d_h;
31 unsigned int i, j;
32
33 int64_t sqrerr = 0;
34 for (i = 0; i < height_y; ++i)
35 for (j = 0; j < width_y; ++j) {
36 int64_t d = img1->planes[VPX_PLANE_Y][i * img1->stride[VPX_PLANE_Y] + j] -
37 img2->planes[VPX_PLANE_Y][i * img2->stride[VPX_PLANE_Y] + j];
38 sqrerr += d * d;
39 }
James Zern104dbbb2013-07-18 16:13:39 -070040 double mse = static_cast<double>(sqrerr) / (width_y * height_y);
Deb Mukherjee01cafaa2013-01-15 06:43:35 -080041 double psnr = 100.0;
42 if (mse > 0.0) {
43 psnr = 10 * log10(255.0 * 255.0 / mse);
44 }
45 return psnr;
46}
47
Yunqing Wange61573c2012-06-28 10:37:53 -070048#endif // TEST_UTIL_H_