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 13 namespace media { 14 15 class VideoFrame; 16 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); 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! 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); 34 35 // Sets alpha plane values to be completely opaque (all 255's). 36 MEDIA_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 40 MEDIA_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. 45 MEDIA_EXPORT void FillYUV(VideoFrame* frame, uint8 y, uint8 u, uint8 v); 46 47 // Creates a border in |frame| such that all pixels outside of 48 // |view_area| are black. The size and position of |view_area| 49 // must be even to align correctly with the color planes. 50 // Only YV12 format video frames are currently supported. 51 MEDIA_EXPORT void LetterboxYUV(VideoFrame* frame, 52 const gfx::Rect& view_area); 53 54 // Rotates |src| plane by |rotation| degree with possible flipping vertically 55 // and horizontally. 56 // |rotation| is limited to {0, 90, 180, 270}. 57 // |width| and |height| are expected to be even numbers. 58 // Both |src| and |dest| planes are packed and have same |width| and |height|. 59 // When |width| != |height| and rotated by 90/270, only the maximum square 60 // portion located in the center is rotated. For example, for width=640 and 61 // height=480, the rotated area is 480x480 located from row 0 through 479 and 62 // from column 80 through 559. The leftmost and rightmost 80 columns are 63 // ignored for both |src| and |dest|. 64 // The caller is responsible for blanking out the margin area. 65 MEDIA_EXPORT void RotatePlaneByPixels( 66 const uint8* src, 67 uint8* dest, 68 int width, 69 int height, 70 int rotation, // Clockwise. 71 bool flip_vert, 72 bool flip_horiz); 73 74 // Return the largest centered rectangle with the same aspect ratio of |content| 75 // that fits entirely inside of |bounds|. If |content| is empty, its aspect 76 // ratio would be undefined; and in this case an empty Rect would be returned. 77 MEDIA_EXPORT gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds, 78 const gfx::Size& content); 79 80 // Copy an RGB bitmap into the specified |region_in_frame| of a YUV video frame. 81 // Fills the regions outside |region_in_frame| with black. 82 MEDIA_EXPORT void CopyRGBToVideoFrame(const uint8* source, 83 int stride, 84 const gfx::Rect& region_in_frame, 85 VideoFrame* frame); 86 87 } // namespace media 88 89 #endif // MEDIA_BASE_VIDEO_UTIL_H_ 90