OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/base/video_util.h" | 5 #include "media/base/video_util.h" |
6 | 6 |
| 7 #include <cmath> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "media/base/video_frame.h" | 10 #include "media/base/video_frame.h" |
9 | 11 |
10 namespace media { | 12 namespace media { |
11 | 13 |
| 14 gfx::Size GetNaturalSize(const gfx::Rect& visible_rect, |
| 15 int aspect_ratio_numerator, |
| 16 int aspect_ratio_denominator) { |
| 17 if (aspect_ratio_denominator == 0) |
| 18 return gfx::Size(); |
| 19 |
| 20 // Calculate the natural size given the aspect ratio and visible rect. |
| 21 double aspect_ratio = aspect_ratio_numerator / |
| 22 static_cast<double>(aspect_ratio_denominator); |
| 23 |
| 24 int width = floor(visible_rect.width() * aspect_ratio + 0.5); |
| 25 int height = visible_rect.height(); |
| 26 |
| 27 // An even width makes things easier for YV12 and appears to be the behavior |
| 28 // expected by WebKit layout tests. |
| 29 return gfx::Size(width & ~1, height); |
| 30 } |
| 31 |
12 static void CopyPlane(size_t plane, const uint8* source, int stride, int rows, | 32 static void CopyPlane(size_t plane, const uint8* source, int stride, int rows, |
13 VideoFrame* frame) { | 33 VideoFrame* frame) { |
14 uint8* dest = frame->data(plane); | 34 uint8* dest = frame->data(plane); |
15 int dest_stride = frame->stride(plane); | 35 int dest_stride = frame->stride(plane); |
16 | 36 |
17 // Clamp in case source frame has smaller stride. | 37 // Clamp in case source frame has smaller stride. |
18 int bytes_to_copy_per_row = std::min(frame->row_bytes(plane), stride); | 38 int bytes_to_copy_per_row = std::min(frame->row_bytes(plane), stride); |
19 | 39 |
20 // Clamp in case source frame has smaller height. | 40 // Clamp in case source frame has smaller height. |
21 int rows_to_copy = std::min(frame->rows(plane), rows); | 41 int rows_to_copy = std::min(frame->rows(plane), rows); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 int v_row_bytes = frame->row_bytes(VideoFrame::kVPlane); | 78 int v_row_bytes = frame->row_bytes(VideoFrame::kVPlane); |
59 for (int i = 0; i < uv_rows; ++i) { | 79 for (int i = 0; i < uv_rows; ++i) { |
60 memset(u_plane, u, u_row_bytes); | 80 memset(u_plane, u, u_row_bytes); |
61 memset(v_plane, v, v_row_bytes); | 81 memset(v_plane, v, v_row_bytes); |
62 u_plane += frame->stride(VideoFrame::kUPlane); | 82 u_plane += frame->stride(VideoFrame::kUPlane); |
63 v_plane += frame->stride(VideoFrame::kVPlane); | 83 v_plane += frame->stride(VideoFrame::kVPlane); |
64 } | 84 } |
65 } | 85 } |
66 | 86 |
67 } // namespace media | 87 } // namespace media |
OLD | NEW |