diff --git a/vp8/encoder/onyx_if.c b/vp8/encoder/onyx_if.c index 7f3964665e4883a484e486a7276c2e93a24b6cfa..849a0ed2a52e54d68a295f2c55122735998ccab4 100644 --- a/vp8/encoder/onyx_if.c +++ b/vp8/encoder/onyx_if.c @@ -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; diff --git a/vp8/encoder/psnr.c b/vp8/encoder/psnr.c deleted file mode 100644 index b3a3d955290f7f04bae413c3ea0a3c417971f3f6..0000000000000000000000000000000000000000 --- a/vp8/encoder/psnr.c +++ /dev/null @@ -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; -} diff --git a/vp8/encoder/psnr.h b/vp8/encoder/psnr.h deleted file mode 100644 index 0c6c088c4f8a45e6f661fcc6956b494d757be592..0000000000000000000000000000000000000000 --- a/vp8/encoder/psnr.h +++ /dev/null @@ -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_ diff --git a/vp8/encoder/temporal_filter.c b/vp8/encoder/temporal_filter.c index 7e3af71ecba8db2fd3bdca43c8cba12e32d92b9b..513b2bfead0c8b100e318b2cb1111af0b26fc617 100644 --- a/vp8/encoder/temporal_filter.c +++ b/vp8/encoder/temporal_filter.c @@ -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" diff --git a/vp8/vp8cx.mk b/vp8/vp8cx.mk index cd091f39ae3bad58598984e4c1405e93850973c9..d7c6dd1e1e6000cea889bbbbafed1c747fa9ab21 100644 --- a/vp8/vp8cx.mk +++ b/vp8/vp8cx.mk @@ -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 diff --git a/vp9/encoder/vp9_onyx_if.c b/vp9/encoder/vp9_onyx_if.c index f86b7a13d0636171c69541aee4540b8853f16ce1..1bf3beffd79abb3083a4903a221170f457ea5e56 100644 --- a/vp9/encoder/vp9_onyx_if.c +++ b/vp9/encoder/vp9_onyx_if.c @@ -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) { diff --git a/vp9/encoder/vp9_psnr.c b/vp9/encoder/vp9_psnr.c deleted file mode 100644 index 58294e15a38f8df7d14cbf93d8004d4c5a4fce1f..0000000000000000000000000000000000000000 --- a/vp9/encoder/vp9_psnr.c +++ /dev/null @@ -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; -} diff --git a/vp9/encoder/vp9_psnr.h b/vp9/encoder/vp9_psnr.h deleted file mode 100644 index ffe00ed2c41313585882f830faafec6ea38884d3..0000000000000000000000000000000000000000 --- a/vp9/encoder/vp9_psnr.h +++ /dev/null @@ -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_ diff --git a/vp9/encoder/vp9_temporal_filter.c b/vp9/encoder/vp9_temporal_filter.c index 004047773ffa85ba02aabdbbdcaf5a58b594f5e9..502e4b678852c84a539b0f1b33d902ca78990128 100644 --- a/vp9/encoder/vp9_temporal_filter.c +++ b/vp9/encoder/vp9_temporal_filter.c @@ -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" diff --git a/vp9/vp9cx.mk b/vp9/vp9cx.mk index 27dd6f62510d1f1f77617415c15d3bd6fff39d1d..6679f89be13cf62c40345a15692e7a0eaef0b7c0 100644 --- a/vp9/vp9cx.mk +++ b/vp9/vp9cx.mk @@ -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 diff --git a/vpx/internal/vpx_psnr.h b/vpx/internal/vpx_psnr.h new file mode 100644 index 0000000000000000000000000000000000000000..07d81bb8d9046466e327fcc79a3c2a7894c1ad28 --- /dev/null +++ b/vpx/internal/vpx_psnr.h @@ -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_ diff --git a/vpx/src/vpx_psnr.c b/vpx/src/vpx_psnr.c new file mode 100644 index 0000000000000000000000000000000000000000..05843acb61f0e9cfec9da01266564da703dd8462 --- /dev/null +++ b/vpx/src/vpx_psnr.c @@ -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; + } +} diff --git a/vpx/vpx_codec.mk b/vpx/vpx_codec.mk index 111c87e53981e918463117e8e7cd4c385cd0727f..98d1d567ce4a986dd5b0f50bc2ce7dbf70b4e423 100644 --- a/vpx/vpx_codec.mk +++ b/vpx/vpx_codec.mk @@ -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