1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef MEDIA_BASE_VIDEO_UTIL_H_ 6#define MEDIA_BASE_VIDEO_UTIL_H_ 7 8#include "base/basictypes.h" 9#include "media/base/media_export.h" 10#include "ui/gfx/rect.h" 11#include "ui/gfx/size.h" 12 13namespace media { 14 15class VideoFrame; 16 17// Computes the size of |visible_size| for a given aspect ratio. 18MEDIA_EXPORT gfx::Size GetNaturalSize(const gfx::Size& visible_size, 19 int aspect_ratio_numerator, 20 int aspect_ratio_denominator); 21 22// Copies a plane of YUV(A) source into a VideoFrame object, taking into account 23// source and destinations dimensions. 24// 25// NOTE: rows is *not* the same as height! 26MEDIA_EXPORT void CopyYPlane(const uint8* source, int stride, int rows, 27 VideoFrame* frame); 28MEDIA_EXPORT void CopyUPlane(const uint8* source, int stride, int rows, 29 VideoFrame* frame); 30MEDIA_EXPORT void CopyVPlane(const uint8* source, int stride, int rows, 31 VideoFrame* frame); 32MEDIA_EXPORT void CopyAPlane(const uint8* source, int stride, int rows, 33 VideoFrame* frame); 34 35// Sets alpha plane values to be completely opaque (all 255's). 36MEDIA_EXPORT void MakeOpaqueAPlane(int stride, int rows, VideoFrame* frame); 37 38// |plane| is one of VideoFrame::kYPlane, VideoFrame::kUPlane, 39// VideoFrame::kVPlane or VideoFrame::kAPlane 40MEDIA_EXPORT void CopyPlane(size_t plane, const uint8* source, int stride, 41 int rows, VideoFrame* frame); 42 43 44// Fills |frame| containing YUV data to the given color values. 45MEDIA_EXPORT void FillYUV(VideoFrame* frame, uint8 y, uint8 u, uint8 v); 46 47// Fills |frame| containing YUVA data with the given color values. 48MEDIA_EXPORT void FillYUVA(VideoFrame* frame, 49 uint8 y, 50 uint8 u, 51 uint8 v, 52 uint8 a); 53 54// Creates a border in |frame| such that all pixels outside of 55// |view_area| are black. The size and position of |view_area| 56// must be even to align correctly with the color planes. 57// Only YV12 format video frames are currently supported. 58MEDIA_EXPORT void LetterboxYUV(VideoFrame* frame, 59 const gfx::Rect& view_area); 60 61// Rotates |src| plane by |rotation| degree with possible flipping vertically 62// and horizontally. 63// |rotation| is limited to {0, 90, 180, 270}. 64// |width| and |height| are expected to be even numbers. 65// Both |src| and |dest| planes are packed and have same |width| and |height|. 66// When |width| != |height| and rotated by 90/270, only the maximum square 67// portion located in the center is rotated. For example, for width=640 and 68// height=480, the rotated area is 480x480 located from row 0 through 479 and 69// from column 80 through 559. The leftmost and rightmost 80 columns are 70// ignored for both |src| and |dest|. 71// The caller is responsible for blanking out the margin area. 72MEDIA_EXPORT void RotatePlaneByPixels( 73 const uint8* src, 74 uint8* dest, 75 int width, 76 int height, 77 int rotation, // Clockwise. 78 bool flip_vert, 79 bool flip_horiz); 80 81// Return the largest centered rectangle with the same aspect ratio of |content| 82// that fits entirely inside of |bounds|. If |content| is empty, its aspect 83// ratio would be undefined; and in this case an empty Rect would be returned. 84MEDIA_EXPORT gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds, 85 const gfx::Size& content); 86 87// Copy an RGB bitmap into the specified |region_in_frame| of a YUV video frame. 88// Fills the regions outside |region_in_frame| with black. 89MEDIA_EXPORT void CopyRGBToVideoFrame(const uint8* source, 90 int stride, 91 const gfx::Rect& region_in_frame, 92 VideoFrame* frame); 93 94} // namespace media 95 96#endif // MEDIA_BASE_VIDEO_UTIL_H_ 97