diff options
author | justinlin@chromium.org <justinlin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-02 03:57:47 +0000 |
---|---|---|
committer | justinlin@chromium.org <justinlin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-02 03:57:47 +0000 |
commit | da1b5fa7f8e993286b7f06d2c2b395368cc00fa7 (patch) | |
tree | b9cbbc1dca36fbb3d2a2cdd796c06d82ec48ca21 /media/base/video_util.cc | |
parent | 9ea60544c692133a27049fd52f4420065b46efd6 (diff) | |
download | chromium_src-da1b5fa7f8e993286b7f06d2c2b395368cc00fa7.zip chromium_src-da1b5fa7f8e993286b7f06d2c2b395368cc00fa7.tar.gz chromium_src-da1b5fa7f8e993286b7f06d2c2b395368cc00fa7.tar.bz2 |
Implement CopyFromCompositingSurfaceToVideoFrame for mac.
Move ComputeLetterboxRegion and add ConvertRGBToVideoFrame to VideoUtil class.
Fix intersecting the capture region with unscaled iosurface_size.
BUG=175358
TBR=kbr
Review URL: https://chromiumcodereview.appspot.com/12326085
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185678 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/video_util.cc')
-rw-r--r-- | media/base/video_util.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/media/base/video_util.cc b/media/base/video_util.cc index c40468f..5cb269d 100644 --- a/media/base/video_util.cc +++ b/media/base/video_util.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "media/base/video_frame.h" +#include "media/base/yuv_convert.h" namespace media { @@ -186,4 +187,51 @@ void RotatePlaneByPixels( } } +gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds, + const gfx::Size& content) { + int64 x = static_cast<int64>(content.width()) * bounds.height(); + int64 y = static_cast<int64>(content.height()) * bounds.width(); + + gfx::Size letterbox(bounds.width(), bounds.height()); + if (y < x) + letterbox.set_height(static_cast<int>(y / content.width())); + else + letterbox.set_width(static_cast<int>(x / content.height())); + gfx::Rect result = bounds; + result.ClampToCenteredSize(letterbox); + return result; +} + +void CopyRGBToVideoFrame(const uint8* source, + int stride, + const gfx::Rect& region_in_frame, + VideoFrame* frame) { + const int kY = VideoFrame::kYPlane; + const int kU = VideoFrame::kUPlane; + const int kV = VideoFrame::kVPlane; + CHECK_EQ(frame->stride(kU), frame->stride(kV)); + const int uv_stride = frame->stride(kU); + + if (region_in_frame != gfx::Rect(frame->coded_size())) { + // TODO(justinlin): Optimize this by clearing just the margins. + // http://crbug.com/178789 + FillYUV(frame, 0x00, 0x80, 0x80); + } + + const int y_offset = region_in_frame.x() + + (region_in_frame.y() * frame->stride(kY)); + const int uv_offset = region_in_frame.x() / 2 + + (region_in_frame.y() / 2 * uv_stride); + + ConvertRGB32ToYUV(source, + frame->data(kY) + y_offset, + frame->data(kU) + uv_offset, + frame->data(kV) + uv_offset, + region_in_frame.width(), + region_in_frame.height(), + stride, + frame->stride(kY), + uv_stride); +} + } // namespace media |