blob: 94394341d8ea38cc51f6f9853395faae081b7518 [file] [log] [blame]
John Koleszar0ea50ce2010-05-18 11:58:33 -04001/*
John Koleszarc2140b82010-09-09 08:16:39 -04002 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
John Koleszar0ea50ce2010-05-18 11:58:33 -04003 *
John Koleszar94c52e42010-06-18 12:39:21 -04004 * Use of this source code is governed by a BSD-style license
John Koleszar09202d82010-06-04 16:19:40 -04005 * 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
John Koleszar94c52e42010-06-18 12:39:21 -04007 * in the file PATENTS. All contributing project authors may
John Koleszar09202d82010-06-04 16:19:40 -04008 * be found in the AUTHORS file in the root of the source tree.
John Koleszar0ea50ce2010-05-18 11:58:33 -04009 */
10
11
12#include "vpx_scale/yv12config.h"
13#include "math.h"
John Koleszar0ea50ce2010-05-18 11:58:33 -040014
Yaowu Xu39ceef32010-11-18 09:10:30 -080015#define MAX_PSNR 100
John Koleszar0ea50ce2010-05-18 11:58:33 -040016
Dmitry Kovalev5da85342013-02-21 10:34:33 -080017double vp9_mse2psnr(double samples, double peak, double mse) {
John Koleszarc6b90392012-07-13 15:21:29 -070018 double psnr;
John Koleszar0ea50ce2010-05-18 11:58:33 -040019
Dmitry Kovalev5da85342013-02-21 10:34:33 -080020 if (mse > 0.0)
21 psnr = 10.0 * log10(peak * peak * samples / mse);
John Koleszarc6b90392012-07-13 15:21:29 -070022 else
Dmitry Kovalev5da85342013-02-21 10:34:33 -080023 psnr = MAX_PSNR; // Limit to prevent / 0
John Koleszar0ea50ce2010-05-18 11:58:33 -040024
John Koleszarc6b90392012-07-13 15:21:29 -070025 if (psnr > MAX_PSNR)
26 psnr = MAX_PSNR;
John Koleszar0ea50ce2010-05-18 11:58:33 -040027
John Koleszarc6b90392012-07-13 15:21:29 -070028 return psnr;
John Koleszar0ea50ce2010-05-18 11:58:33 -040029}