Merge "Adding vpx_sse_to_psnr() function."

This commit is contained in:
Dmitry Kovalev 2014-02-26 18:38:26 -08:00 committed by Gerrit Code Review
commit e4118e253a
13 changed files with 92 additions and 146 deletions

View File

@ -19,7 +19,7 @@
#include "vp8/common/alloccommon.h"
#include "mcomp.h"
#include "firstpass.h"
#include "psnr.h"
#include "vpx/internal/vpx_psnr.h"
#include "vpx_scale/vpx_scale.h"
#include "vp8/common/extend.h"
#include "ratectrl.h"
@ -2170,10 +2170,12 @@ void vp8_remove_compressor(VP8_COMP **ptr)
8.0 / 1000.0 / time_encoded;
double samples = 3.0 / 2 * cpi->frames_in_layer[i] *
lst_yv12->y_width * lst_yv12->y_height;
double total_psnr = vp8_mse2psnr(samples, 255.0,
cpi->total_error2[i]);
double total_psnr2 = vp8_mse2psnr(samples, 255.0,
cpi->total_error2_p[i]);
double total_psnr =
vpx_sse_to_psnr(samples, 255.0,
cpi->total_error2[i]);
double total_psnr2 =
vpx_sse_to_psnr(samples, 255.0,
cpi->total_error2_p[i]);
double total_ssim = 100 * pow(cpi->sum_ssim[i] /
cpi->sum_weights[i], 8.0);
@ -2190,9 +2192,9 @@ void vp8_remove_compressor(VP8_COMP **ptr)
{
double samples = 3.0 / 2 * cpi->count *
lst_yv12->y_width * lst_yv12->y_height;
double total_psnr = vp8_mse2psnr(samples, 255.0,
cpi->total_sq_error);
double total_psnr2 = vp8_mse2psnr(samples, 255.0,
double total_psnr = vpx_sse_to_psnr(samples, 255.0,
cpi->total_sq_error);
double total_psnr2 = vpx_sse_to_psnr(samples, 255.0,
cpi->total_sq_error2);
double total_ssim = 100 * pow(cpi->summed_quality /
cpi->summed_weights, 8.0);
@ -2522,8 +2524,8 @@ static void generate_psnr_packet(VP8_COMP *cpi)
pkt.data.psnr.samples[3] = width * height;
for (i = 0; i < 4; i++)
pkt.data.psnr.psnr[i] = vp8_mse2psnr(pkt.data.psnr.samples[i], 255.0,
(double)(pkt.data.psnr.sse[i]));
pkt.data.psnr.psnr[i] = vpx_sse_to_psnr(pkt.data.psnr.samples[i], 255.0,
(double)(pkt.data.psnr.sse[i]));
vpx_codec_pkt_list_add(cpi->output_pkt_list, &pkt);
}
@ -5284,11 +5286,11 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
sq_error = (double)(ye + ue + ve);
frame_psnr = vp8_mse2psnr(t_samples, 255.0, sq_error);
frame_psnr = vpx_sse_to_psnr(t_samples, 255.0, sq_error);
cpi->total_y += vp8_mse2psnr(y_samples, 255.0, (double)ye);
cpi->total_u += vp8_mse2psnr(uv_samples, 255.0, (double)ue);
cpi->total_v += vp8_mse2psnr(uv_samples, 255.0, (double)ve);
cpi->total_y += vpx_sse_to_psnr(y_samples, 255.0, (double)ye);
cpi->total_u += vpx_sse_to_psnr(uv_samples, 255.0, (double)ue);
cpi->total_v += vpx_sse_to_psnr(uv_samples, 255.0, (double)ve);
cpi->total_sq_error += sq_error;
cpi->total += frame_psnr;
#if CONFIG_POSTPROC
@ -5311,14 +5313,14 @@ int vp8_get_compressed_data(VP8_COMP *cpi, unsigned int *frame_flags, unsigned l
sq_error2 = (double)(ye + ue + ve);
frame_psnr2 = vp8_mse2psnr(t_samples, 255.0, sq_error2);
frame_psnr2 = vpx_sse_to_psnr(t_samples, 255.0, sq_error2);
cpi->totalp_y += vp8_mse2psnr(y_samples,
255.0, (double)ye);
cpi->totalp_u += vp8_mse2psnr(uv_samples,
255.0, (double)ue);
cpi->totalp_v += vp8_mse2psnr(uv_samples,
255.0, (double)ve);
cpi->totalp_y += vpx_sse_to_psnr(y_samples,
255.0, (double)ye);
cpi->totalp_u += vpx_sse_to_psnr(uv_samples,
255.0, (double)ue);
cpi->totalp_v += vpx_sse_to_psnr(uv_samples,
255.0, (double)ve);
cpi->total_sq_error2 += sq_error2;
cpi->totalp += frame_psnr2;

View File

@ -1,31 +0,0 @@
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "vpx_scale/yv12config.h"
#include "math.h"
#include "vp8/common/systemdependent.h" /* for vp8_clear_system_state() */
#define MAX_PSNR 100
double vp8_mse2psnr(double Samples, double Peak, double Mse)
{
double psnr;
if ((double)Mse > 0.0)
psnr = 10.0 * log10(Peak * Peak * Samples / Mse);
else
psnr = MAX_PSNR; /* Limit to prevent / 0 */
if (psnr > MAX_PSNR)
psnr = MAX_PSNR;
return psnr;
}

View File

@ -1,25 +0,0 @@
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VP8_ENCODER_PSNR_H_
#define VP8_ENCODER_PSNR_H_
#ifdef __cplusplus
extern "C" {
#endif
extern double vp8_mse2psnr(double Samples, double Peak, double Mse);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // VP8_ENCODER_PSNR_H_

View File

@ -16,7 +16,6 @@
#include "vp8/common/alloccommon.h"
#include "mcomp.h"
#include "firstpass.h"
#include "psnr.h"
#include "vpx_scale/vpx_scale.h"
#include "vp8/common/extend.h"
#include "ratectrl.h"

View File

@ -50,7 +50,6 @@ VP8_CX_SRCS-yes += encoder/mcomp.h
VP8_CX_SRCS-yes += encoder/modecosts.h
VP8_CX_SRCS-yes += encoder/onyx_int.h
VP8_CX_SRCS-yes += encoder/pickinter.h
VP8_CX_SRCS-yes += encoder/psnr.h
VP8_CX_SRCS-yes += encoder/quantize.h
VP8_CX_SRCS-yes += encoder/ratectrl.h
VP8_CX_SRCS-yes += encoder/rdopt.h
@ -61,7 +60,6 @@ VP8_CX_SRCS-yes += encoder/modecosts.c
VP8_CX_SRCS-yes += encoder/onyx_if.c
VP8_CX_SRCS-yes += encoder/pickinter.c
VP8_CX_SRCS-yes += encoder/picklpf.c
VP8_CX_SRCS-yes += encoder/psnr.c
VP8_CX_SRCS-yes += encoder/quantize.c
VP8_CX_SRCS-yes += encoder/ratectrl.c
VP8_CX_SRCS-yes += encoder/rdopt.c

View File

@ -14,6 +14,8 @@
#include "./vpx_config.h"
#include "./vpx_scale_rtcd.h"
#include "vpx/internal/vpx_psnr.h"
#include "vpx_ports/vpx_timer.h"
#include "vp9/common/vp9_alloccommon.h"
#include "vp9/common/vp9_filter.h"
@ -30,7 +32,6 @@
#include "vp9/encoder/vp9_mbgraph.h"
#include "vp9/encoder/vp9_onyx_int.h"
#include "vp9/encoder/vp9_picklpf.h"
#include "vp9/encoder/vp9_psnr.h"
#include "vp9/encoder/vp9_ratectrl.h"
#include "vp9/encoder/vp9_rdopt.h"
#include "vp9/encoder/vp9_segmentation.h"
@ -38,8 +39,6 @@
#include "vp9/encoder/vp9_vaq.h"
#include "vp9/encoder/vp9_resize.h"
#include "vpx_ports/vpx_timer.h"
void vp9_entropy_mode_init();
void vp9_coef_tree_initialize();
@ -2045,11 +2044,11 @@ void vp9_remove_compressor(VP9_PTR *ptr) {
if (cpi->b_calculate_psnr) {
const double total_psnr =
vp9_mse2psnr((double)cpi->total_samples, 255.0,
(double)cpi->total_sq_error);
vpx_sse_to_psnr((double)cpi->total_samples, 255.0,
(double)cpi->total_sq_error);
const double totalp_psnr =
vp9_mse2psnr((double)cpi->totalp_samples, 255.0,
(double)cpi->totalp_sq_error);
vpx_sse_to_psnr((double)cpi->totalp_samples, 255.0,
(double)cpi->totalp_sq_error);
const double total_ssim = 100 * pow(cpi->summed_quality /
cpi->summed_weights, 8.0);
const double totalp_ssim = 100 * pow(cpi->summedp_quality /
@ -2230,7 +2229,7 @@ static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b,
w, h);
psnr->sse[1 + i] = sse;
psnr->samples[1 + i] = samples;
psnr->psnr[1 + i] = vp9_mse2psnr(samples, 255.0, (double) sse);
psnr->psnr[1 + i] = vpx_sse_to_psnr(samples, 255.0, (double)sse);
total_sse += sse;
total_samples += samples;
@ -2238,7 +2237,8 @@ static void calc_psnr(const YV12_BUFFER_CONFIG *a, const YV12_BUFFER_CONFIG *b,
psnr->sse[0] = total_sse;
psnr->samples[0] = total_samples;
psnr->psnr[0] = vp9_mse2psnr((double)total_samples, 255.0, (double)total_sse);
psnr->psnr[0] = vpx_sse_to_psnr((double)total_samples, 255.0,
(double)total_sse);
}
static void generate_psnr_packet(VP9_COMP *cpi) {

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include "vpx_scale/yv12config.h"
#define MAX_PSNR 100
double vp9_mse2psnr(double samples, double peak, double mse) {
double psnr;
if (mse > 0.0)
psnr = 10.0 * log10(peak * peak * samples / mse);
else
psnr = MAX_PSNR; // Limit to prevent / 0
if (psnr > MAX_PSNR)
psnr = MAX_PSNR;
return psnr;
}

View File

@ -1,25 +0,0 @@
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VP9_ENCODER_VP9_PSNR_H_
#define VP9_ENCODER_VP9_PSNR_H_
#ifdef __cplusplus
extern "C" {
#endif
double vp9_mse2psnr(double samples, double peak, double mse);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // VP9_ENCODER_VP9_PSNR_H_

View File

@ -20,7 +20,6 @@
#include "vp9/encoder/vp9_firstpass.h"
#include "vp9/encoder/vp9_mcomp.h"
#include "vp9/encoder/vp9_onyx_int.h"
#include "vp9/encoder/vp9_psnr.h"
#include "vp9/encoder/vp9_quantize.h"
#include "vp9/encoder/vp9_ratectrl.h"
#include "vp9/encoder/vp9_segmentation.h"

View File

@ -38,7 +38,6 @@ VP9_CX_SRCS-yes += encoder/vp9_lookahead.c
VP9_CX_SRCS-yes += encoder/vp9_lookahead.h
VP9_CX_SRCS-yes += encoder/vp9_mcomp.h
VP9_CX_SRCS-yes += encoder/vp9_onyx_int.h
VP9_CX_SRCS-yes += encoder/vp9_psnr.h
VP9_CX_SRCS-yes += encoder/vp9_quantize.h
VP9_CX_SRCS-yes += encoder/vp9_ratectrl.h
VP9_CX_SRCS-yes += encoder/vp9_rdopt.h
@ -50,7 +49,6 @@ VP9_CX_SRCS-yes += encoder/vp9_mcomp.c
VP9_CX_SRCS-yes += encoder/vp9_onyx_if.c
VP9_CX_SRCS-yes += encoder/vp9_picklpf.c
VP9_CX_SRCS-yes += encoder/vp9_picklpf.h
VP9_CX_SRCS-yes += encoder/vp9_psnr.c
VP9_CX_SRCS-yes += encoder/vp9_quantize.c
VP9_CX_SRCS-yes += encoder/vp9_ratectrl.c
VP9_CX_SRCS-yes += encoder/vp9_rdopt.c

34
vpx/internal/vpx_psnr.h Normal file
View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef VPX_INTERNAL_VPX_PSNR_H_
#define VPX_INTERNAL_VPX_PSNR_H_
#ifdef __cplusplus
extern "C" {
#endif
// TODO(dkovalev) change vpx_sse_to_psnr signature: double -> int64_t
/*!\brief Converts SSE to PSNR
*
* Converts sum of squared errros (SSE) to peak signal-to-noise ratio (PNSR).
*
* \param[in] samples Number of samples
* \param[in] peak Max sample value
* \param[in] sse Sum of squared errors
*/
double vpx_sse_to_psnr(double samples, double peak, double sse);
#ifdef __cplusplus
} // extern "C"
#endif
#endif // VPX_INTERNAL_VPX_PSNR_H_

24
vpx/src/vpx_psnr.c Normal file
View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <math.h>
#include "vpx/internal/vpx_psnr.h"
#define MAX_PSNR 100.0
double vpx_sse_to_psnr(double samples, double peak, double sse) {
if (sse > 0.0) {
const double psnr = 10.0 * log10(samples * peak * peak / sse);
return psnr > MAX_PSNR ? MAX_PSNR : psnr;
} else {
return MAX_PSNR;
}
}

View File

@ -34,8 +34,10 @@ API_SRCS-yes += vpx_decoder.h
API_SRCS-yes += src/vpx_encoder.c
API_SRCS-yes += vpx_encoder.h
API_SRCS-yes += internal/vpx_codec_internal.h
API_SRCS-yes += internal/vpx_psnr.h
API_SRCS-yes += src/vpx_codec.c
API_SRCS-yes += src/vpx_image.c
API_SRCS-yes += src/vpx_psnr.c
API_SRCS-yes += vpx_codec.h
API_SRCS-yes += vpx_codec.mk
API_SRCS-yes += vpx_frame_buffer.h