| Index: webrtc/common_video/video_frame_buffer.cc
|
| diff --git a/webrtc/common_video/video_frame_buffer.cc b/webrtc/common_video/video_frame_buffer.cc
|
| index 700dcaf02b7af098798eb51e344f065b232a8700..e6d8c527f6409c01cd803b3331b6ac80cbe3de0d 100644
|
| --- a/webrtc/common_video/video_frame_buffer.cc
|
| +++ b/webrtc/common_video/video_frame_buffer.cc
|
| @@ -13,6 +13,7 @@
|
| #include "webrtc/base/checks.h"
|
| #include "webrtc/base/keep_ref_until_done.h"
|
| #include "libyuv/convert.h"
|
| +#include "libyuv/scale.h"
|
|
|
| // Aligning pointer to 64 bytes for improved performance, e.g. use SIMD.
|
| static const int kBufferAlignment = 64;
|
| @@ -207,6 +208,49 @@ rtc::scoped_refptr<I420Buffer> I420Buffer::Copy(
|
| return copy;
|
| }
|
|
|
| +rtc::scoped_refptr<I420Buffer> I420Buffer::CropAndScale(
|
| + const rtc::scoped_refptr<VideoFrameBuffer>& buffer,
|
| + int offset_x,
|
| + int offset_y,
|
| + int crop_width,
|
| + int crop_height,
|
| + int dst_width,
|
| + int dst_height) {
|
| + RTC_CHECK_LE(crop_width, buffer->width());
|
| + RTC_CHECK_LE(crop_height, buffer->height());
|
| + RTC_CHECK_LE(crop_width + offset_x, buffer->width());
|
| + RTC_CHECK_LE(crop_height + offset_y, buffer->height());
|
| + RTC_CHECK_GE(offset_x, 0);
|
| + RTC_CHECK_GE(offset_y, 0);
|
| +
|
| + rtc::scoped_refptr<I420Buffer> scaled =
|
| + new rtc::RefCountedObject<I420Buffer>(dst_width, dst_height);
|
| +
|
| + // Make sure offset is even so that u/v plane becomes aligned.
|
| + const int uv_offset_x = offset_x / 2;
|
| + const int uv_offset_y = offset_y / 2;
|
| + offset_x = uv_offset_x * 2;
|
| + offset_y = uv_offset_y * 2;
|
| +
|
| + const uint8_t* y_plane =
|
| + buffer->DataY() + buffer->StrideY() * offset_y + offset_x;
|
| + const uint8_t* u_plane =
|
| + buffer->DataU() + buffer->StrideU() * uv_offset_y + uv_offset_x;
|
| + const uint8_t* v_plane =
|
| + buffer->DataV() + buffer->StrideV() * uv_offset_y + uv_offset_x;
|
| + if (libyuv::I420Scale(y_plane, buffer->StrideY(),
|
| + u_plane, buffer->StrideU(),
|
| + v_plane, buffer->StrideV(),
|
| + crop_width, crop_height,
|
| + scaled->MutableDataY(), scaled->StrideY(),
|
| + scaled->MutableDataU(), scaled->StrideU(),
|
| + scaled->MutableDataV(), scaled->StrideV(),
|
| + dst_width, dst_height, libyuv::kFilterBox) < 0) {
|
| + return nullptr;
|
| + }
|
| + return scaled;
|
| +}
|
| +
|
| NativeHandleBuffer::NativeHandleBuffer(void* native_handle,
|
| int width,
|
| int height)
|
|
|