diff options
author | Sebastian Jansson <srte@webrtc.org> | 2019-04-01 14:12:08 +0200 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-04-01 15:08:21 +0000 |
commit | 8ce89ba820281e87a989e8e4f6f7c9e7953d8b37 (patch) | |
tree | 44922cdc223c655b2a39329cf224365a44f7cc92 /common_video | |
parent | de83d0c81a4fa29e32a7e62b37a673cdb386458e (diff) | |
download | webrtc-8ce89ba820281e87a989e8e4f6f7c9e7953d8b37.tar.gz |
Adds function to calculate squared error sum to libyuv.
This will be used for frame matching in a follow up CL.
Bug: webrtc:10365
Change-Id: I57bb743dd10a3327a5befceb98b3539e1138448b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/130510
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27398}
Diffstat (limited to 'common_video')
-rw-r--r-- | common_video/libyuv/include/webrtc_libyuv.h | 3 | ||||
-rw-r--r-- | common_video/libyuv/webrtc_libyuv.cc | 22 |
2 files changed, 25 insertions, 0 deletions
diff --git a/common_video/libyuv/include/webrtc_libyuv.h b/common_video/libyuv/include/webrtc_libyuv.h index 340fd3d4a7..c748d86f09 100644 --- a/common_video/libyuv/include/webrtc_libyuv.h +++ b/common_video/libyuv/include/webrtc_libyuv.h @@ -77,6 +77,9 @@ int ConvertFromI420(const VideoFrame& src_frame, int dst_sample_size, uint8_t* dst_frame); +double I420SSE(const I420BufferInterface& ref_buffer, + const I420BufferInterface& test_buffer); + // Compute PSNR for an I420 frame (all planes). // Returns the PSNR in decibel, to a maximum of kInfinitePSNR. double I420PSNR(const VideoFrame* ref_frame, const VideoFrame* test_frame); diff --git a/common_video/libyuv/webrtc_libyuv.cc b/common_video/libyuv/webrtc_libyuv.cc index 10b32b8bcb..eee8cd17cf 100644 --- a/common_video/libyuv/webrtc_libyuv.cc +++ b/common_video/libyuv/webrtc_libyuv.cc @@ -201,6 +201,28 @@ rtc::scoped_refptr<I420ABufferInterface> ScaleI420ABuffer( return merged_buffer; } +double I420SSE(const I420BufferInterface& ref_buffer, + const I420BufferInterface& test_buffer) { + RTC_DCHECK_EQ(ref_buffer.width(), test_buffer.width()); + RTC_DCHECK_EQ(ref_buffer.height(), test_buffer.height()); + const uint64_t width = test_buffer.width(); + const uint64_t height = test_buffer.height(); + const uint64_t sse_y = libyuv::ComputeSumSquareErrorPlane( + ref_buffer.DataY(), ref_buffer.StrideY(), test_buffer.DataY(), + test_buffer.StrideY(), width, height); + const int width_uv = (width + 1) >> 1; + const int height_uv = (height + 1) >> 1; + const uint64_t sse_u = libyuv::ComputeSumSquareErrorPlane( + ref_buffer.DataU(), ref_buffer.StrideU(), test_buffer.DataU(), + test_buffer.StrideU(), width_uv, height_uv); + const uint64_t sse_v = libyuv::ComputeSumSquareErrorPlane( + ref_buffer.DataV(), ref_buffer.StrideV(), test_buffer.DataV(), + test_buffer.StrideV(), width_uv, height_uv); + const double samples = width * height + 2 * (width_uv * height_uv); + const double sse = sse_y + sse_u + sse_v; + return sse / (samples * 255.0 * 255.0); +} + // Compute PSNR for an I420A frame (all planes). Can upscale test frame. double I420APSNR(const I420ABufferInterface& ref_buffer, const I420ABufferInterface& test_buffer) { |