michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #ifndef MEDIA_BASE_VIDEO_UTIL_H_ michael@0: #define MEDIA_BASE_VIDEO_UTIL_H_ michael@0: michael@0: #include "mp4_demuxer/basictypes.h" michael@0: michael@0: namespace mp4_demuxer { michael@0: michael@0: class VideoFrame; michael@0: michael@0: // Computes the size of |visible_size| for a given aspect ratio. michael@0: IntSize GetNaturalSize(const IntSize& visible_size, michael@0: int aspect_ratio_numerator, michael@0: int aspect_ratio_denominator); michael@0: /* michael@0: // Copies a plane of YUV(A) source into a VideoFrame object, taking into account michael@0: // source and destinations dimensions. michael@0: // michael@0: // NOTE: rows is *not* the same as height! michael@0: void CopyYPlane(const uint8_t* source, int stride, int rows, michael@0: VideoFrame* frame); michael@0: void CopyUPlane(const uint8_t* source, int stride, int rows, michael@0: VideoFrame* frame); michael@0: void CopyVPlane(const uint8_t* source, int stride, int rows, michael@0: VideoFrame* frame); michael@0: void CopyAPlane(const uint8_t* source, int stride, int rows, michael@0: VideoFrame* frame); michael@0: michael@0: // Sets alpha plane values to be completely opaque (all 255's). michael@0: void MakeOpaqueAPlane(int stride, int rows, VideoFrame* frame); michael@0: michael@0: // |plane| is one of VideoFrame::kYPlane, VideoFrame::kUPlane, michael@0: // VideoFrame::kVPlane or VideoFrame::kAPlane michael@0: void CopyPlane(size_t plane, const uint8_t* source, int stride, michael@0: int rows, VideoFrame* frame); michael@0: michael@0: michael@0: // Fills |frame| containing YUV data to the given color values. michael@0: void FillYUV(VideoFrame* frame, uint8_t y, uint8_t u, uint8_t v); michael@0: michael@0: // Creates a border in |frame| such that all pixels outside of michael@0: // |view_area| are black. The size and position of |view_area| michael@0: // must be even to align correctly with the color planes. michael@0: // Only YV12 format video frames are currently supported. michael@0: void LetterboxYUV(VideoFrame* frame, michael@0: const gfx::Rect& view_area); michael@0: michael@0: // Rotates |src| plane by |rotation| degree with possible flipping vertically michael@0: // and horizontally. michael@0: // |rotation| is limited to {0, 90, 180, 270}. michael@0: // |width| and |height| are expected to be even numbers. michael@0: // Both |src| and |dest| planes are packed and have same |width| and |height|. michael@0: // When |width| != |height| and rotated by 90/270, only the maximum square michael@0: // portion located in the center is rotated. For example, for width=640 and michael@0: // height=480, the rotated area is 480x480 located from row 0 through 479 and michael@0: // from column 80 through 559. The leftmost and rightmost 80 columns are michael@0: // ignored for both |src| and |dest|. michael@0: // The caller is responsible for blanking out the margin area. michael@0: void RotatePlaneByPixels( michael@0: const uint8_t* src, michael@0: uint8_t* dest, michael@0: int width, michael@0: int height, michael@0: int rotation, // Clockwise. michael@0: bool flip_vert, michael@0: bool flip_horiz); michael@0: michael@0: // Return the largest centered rectangle with the same aspect ratio of |content| michael@0: // that fits entirely inside of |bounds|. michael@0: gfx::Rect ComputeLetterboxRegion(const gfx::Rect& bounds, michael@0: const IntSize& content); michael@0: michael@0: // Copy an RGB bitmap into the specified |region_in_frame| of a YUV video frame. michael@0: // Fills the regions outside |region_in_frame| with black. michael@0: void CopyRGBToVideoFrame(const uint8_t* source, michael@0: int stride, michael@0: const gfx::Rect& region_in_frame, michael@0: VideoFrame* frame); michael@0: */ michael@0: michael@0: } // namespace mp4_demuxer michael@0: michael@0: #endif // MEDIA_BASE_VIDEO_UTIL_H_