cc: Remove tile and scale specific code from raster source
[chromium-blink-merge.git] / media / base / video_util.h
blob7798ebe016e1a996bf1d0b022fe98ebbc702d53f
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"
13 namespace media {
15 class VideoFrame;
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,
27 VideoFrame* frame);
28 MEDIA_EXPORT void CopyUPlane(const uint8* source, int stride, int rows,
29 VideoFrame* frame);
30 MEDIA_EXPORT void CopyVPlane(const uint8* source, int stride, int rows,
31 VideoFrame* frame);
32 MEDIA_EXPORT void CopyAPlane(const uint8* source, int stride, int rows,
33 VideoFrame* frame);
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,
49 uint8 y,
50 uint8 u,
51 uint8 v,
52 uint8 a);
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
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.
72 MEDIA_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);
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 // 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.
89 MEDIA_EXPORT void CopyRGBToVideoFrame(const uint8* source,
90 int stride,
91 const gfx::Rect& region_in_frame,
92 VideoFrame* frame);
94 } // namespace media
96 #endif // MEDIA_BASE_VIDEO_UTIL_H_