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.
5 #ifndef MEDIA_BASE_VIDEO_UTIL_H_
6 #define MEDIA_BASE_VIDEO_UTIL_H_
8 #include "base/basictypes.h"
9 #include "media/base/media_export.h"
10 #include "ui/gfx/geometry/rect.h"
11 #include "ui/gfx/geometry/size.h"
17 // Computes the size of |visible_size| for a given aspect ratio.
18 MEDIA_EXPORT
gfx::Size
GetNaturalSize(const gfx::Size
& visible_size
,
19 int aspect_ratio_numerator
,
20 int aspect_ratio_denominator
);
22 // Copies a plane of YUV(A) source into a VideoFrame object, taking into account
23 // source and destinations dimensions.
25 // NOTE: rows is *not* the same as height!
26 MEDIA_EXPORT
void CopyYPlane(const uint8
* source
, int stride
, int rows
,
28 MEDIA_EXPORT
void CopyUPlane(const uint8
* source
, int stride
, int rows
,
30 MEDIA_EXPORT
void CopyVPlane(const uint8
* source
, int stride
, int rows
,
32 MEDIA_EXPORT
void CopyAPlane(const uint8
* source
, int stride
, int rows
,
35 // Sets alpha plane values to be completely opaque (all 255's).
36 MEDIA_EXPORT
void MakeOpaqueAPlane(int stride
, int rows
, VideoFrame
* frame
);
38 // |plane| is one of VideoFrame::kYPlane, VideoFrame::kUPlane,
39 // VideoFrame::kVPlane or VideoFrame::kAPlane
40 MEDIA_EXPORT
void CopyPlane(size_t plane
, const uint8
* source
, int stride
,
41 int rows
, VideoFrame
* frame
);
44 // Fills |frame| containing YUV data to the given color values.
45 MEDIA_EXPORT
void FillYUV(VideoFrame
* frame
, uint8 y
, uint8 u
, uint8 v
);
47 // Fills |frame| containing YUVA data with the given color values.
48 MEDIA_EXPORT
void FillYUVA(VideoFrame
* frame
,
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.
58 MEDIA_EXPORT
void LetterboxYUV(VideoFrame
* frame
,
59 const gfx::Rect
& view_area
);
61 // Rotates |src| plane by |rotation| degree with possible flipping vertically
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.
72 MEDIA_EXPORT
void RotatePlaneByPixels(
77 int rotation
, // Clockwise.
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.
84 MEDIA_EXPORT
gfx::Rect
ComputeLetterboxRegion(const gfx::Rect
& bounds
,
85 const gfx::Size
& content
);
87 // Return a scaled |size| whose area is less than or equal to |target|, where
88 // one of its dimensions is equal to |target|'s. The aspect ratio of |size| is
89 // preserved as closely as possible. If |size| is empty, the result will be
91 MEDIA_EXPORT
gfx::Size
ScaleSizeToFitWithinTarget(const gfx::Size
& size
,
92 const gfx::Size
& target
);
94 // Return a scaled |size| whose area is greater than or equal to |target|, where
95 // one of its dimensions is equal to |target|'s. The aspect ratio of |size| is
96 // preserved as closely as possible. If |size| is empty, the result will be
98 MEDIA_EXPORT
gfx::Size
ScaleSizeToEncompassTarget(const gfx::Size
& size
,
99 const gfx::Size
& target
);
101 // Returns |size| with only one of its dimensions increased such that the result
102 // matches the aspect ratio of |target|. This is different from
103 // ScaleSizeToEncompassTarget() in two ways: 1) The goal is to match the aspect
104 // ratio of |target| rather than that of |size|. 2) Only one of the dimensions
105 // of |size| may change, and it may only be increased (padded). If either
106 // |size| or |target| is empty, the result will be empty.
107 MEDIA_EXPORT
gfx::Size
PadToMatchAspectRatio(const gfx::Size
& size
,
108 const gfx::Size
& target
);
110 // Copy an RGB bitmap into the specified |region_in_frame| of a YUV video frame.
111 // Fills the regions outside |region_in_frame| with black.
112 MEDIA_EXPORT
void CopyRGBToVideoFrame(const uint8
* source
,
114 const gfx::Rect
& region_in_frame
,
119 #endif // MEDIA_BASE_VIDEO_UTIL_H_