Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: webrtc/common_video/libyuv/webrtc_libyuv.cc

Issue 2332213011: Reland of Optimize Android NV12 capture (Closed)
Patch Set: Fix dst vs src width/height bug Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/common_video/libyuv/include/webrtc_libyuv.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/common_video/libyuv/webrtc_libyuv.cc
diff --git a/webrtc/common_video/libyuv/webrtc_libyuv.cc b/webrtc/common_video/libyuv/webrtc_libyuv.cc
index 44577e9ac8e6beac40001a87af737422d92da624..40fcf9bff6592a911b040f86c042387c81460626 100644
--- a/webrtc/common_video/libyuv/webrtc_libyuv.cc
+++ b/webrtc/common_video/libyuv/webrtc_libyuv.cc
@@ -341,4 +341,54 @@ double I420SSIM(const VideoFrame* ref_frame, const VideoFrame* test_frame) {
test_frame->video_frame_buffer()->StrideV(),
test_frame->width(), test_frame->height());
}
+
+void NV12ToI420Scaler::NV12ToI420Scale(
+ const uint8_t* src_y, int src_stride_y,
+ const uint8_t* src_uv, int src_stride_uv,
+ int src_width, int src_height,
+ uint8_t* dst_y, int dst_stride_y,
+ uint8_t* dst_u, int dst_stride_u,
+ uint8_t* dst_v, int dst_stride_v,
+ int dst_width, int dst_height) {
+ if (src_width == dst_width && src_height == dst_height) {
+ // No scaling.
+ tmp_uv_planes_.clear();
+ tmp_uv_planes_.shrink_to_fit();
+ libyuv::NV12ToI420(
+ src_y, src_stride_y,
+ src_uv, src_stride_uv,
+ dst_y, dst_stride_y,
+ dst_u, dst_stride_u,
+ dst_v, dst_stride_v,
+ src_width, src_height);
+ return;
+ }
+
+ // Scaling.
+ // Allocate temporary memory for spitting UV planes.
+ const int src_uv_width = (src_width + 1) / 2;
+ const int src_uv_height = (src_height + 1) / 2;
+ tmp_uv_planes_.resize(src_uv_width * src_uv_height * 2);
+ tmp_uv_planes_.shrink_to_fit();
+
+ // Split source UV plane into separate U and V plane using the temporary data.
+ uint8_t* const src_u = tmp_uv_planes_.data();
+ uint8_t* const src_v = tmp_uv_planes_.data() + src_uv_width * src_uv_height;
+ libyuv::SplitUVPlane(src_uv, src_stride_uv,
+ src_u, src_uv_width,
+ src_v, src_uv_width,
+ src_uv_width, src_uv_height);
+
+ // Scale the planes into the destination.
+ libyuv::I420Scale(src_y, src_stride_y,
+ src_u, src_uv_width,
+ src_v, src_uv_width,
+ src_width, src_height,
+ dst_y, dst_stride_y,
+ dst_u, dst_stride_u,
+ dst_v, dst_stride_v,
+ dst_width, dst_height,
+ libyuv::kFilterBox);
+}
+
} // namespace webrtc
« no previous file with comments | « webrtc/common_video/libyuv/include/webrtc_libyuv.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698