1411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org/*
2411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org *
4411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org *  Use of this source code is governed by a BSD-style license
5411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org *  that can be found in the LICENSE file in the root of the source
6411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org *  tree. An additional intellectual property rights grant can be found
7411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org *  in the file PATENTS.  All contributing project authors may
8411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org *  be found in the AUTHORS file in the root of the source tree.
9411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org */
10411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org
11411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org#include <math.h>
12411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org
13411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org#include "vpx/internal/vpx_psnr.h"
14411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org
15411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org#define MAX_PSNR 100.0
16411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org
17411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.orgdouble vpx_sse_to_psnr(double samples, double peak, double sse) {
18411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org  if (sse > 0.0) {
19411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org    const double psnr = 10.0 * log10(samples * peak * peak / sse);
20411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org    return psnr > MAX_PSNR ? MAX_PSNR : psnr;
21411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org  } else {
22411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org    return MAX_PSNR;
23411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org  }
24411971f94253c85e1866c281860d6344f6aa0c78fgalligan@chromium.org}
25