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> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 263 } |
264 } | 264 } |
265 | 265 |
266 // Helper function to return |a| divided by |b|, rounded to the nearest integer. | 266 // Helper function to return |a| divided by |b|, rounded to the nearest integer. |
267 static int RoundedDivision(int64_t a, int b) { | 267 static int RoundedDivision(int64_t a, int b) { |
268 DCHECK_GE(a, 0); | 268 DCHECK_GE(a, 0); |
269 DCHECK_GT(b, 0); | 269 DCHECK_GT(b, 0); |
270 base::CheckedNumeric<uint64_t> result(a); | 270 base::CheckedNumeric<uint64_t> result(a); |
271 result += b / 2; | 271 result += b / 2; |
272 result /= b; | 272 result /= b; |
273 return base::checked_cast<int>(result.ValueOrDie()); | 273 return base::ValueOrDieForType<int>(result); |
274 } | 274 } |
275 | 275 |
276 // Common logic for the letterboxing and scale-within/scale-encompassing | 276 // Common logic for the letterboxing and scale-within/scale-encompassing |
277 // functions. Scales |size| to either fit within or encompass |target|, | 277 // functions. Scales |size| to either fit within or encompass |target|, |
278 // depending on whether |fit_within_target| is true. | 278 // depending on whether |fit_within_target| is true. |
279 static gfx::Size ScaleSizeToTarget(const gfx::Size& size, | 279 static gfx::Size ScaleSizeToTarget(const gfx::Size& size, |
280 const gfx::Size& target, | 280 const gfx::Size& target, |
281 bool fit_within_target) { | 281 bool fit_within_target) { |
282 if (size.IsEmpty()) | 282 if (size.IsEmpty()) |
283 return gfx::Size(); // Corner case: Aspect ratio is undefined. | 283 return gfx::Size(); // Corner case: Aspect ratio is undefined. |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 dst_frame->stride(VideoFrame::kVPlane), | 413 dst_frame->stride(VideoFrame::kVPlane), |
414 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, | 414 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, |
415 dst_frame->coded_size()), | 415 dst_frame->coded_size()), |
416 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, | 416 VideoFrame::PlaneSize(PIXEL_FORMAT_I420, VideoFrame::kVPlane, |
417 src_frame.visible_rect().size())); | 417 src_frame.visible_rect().size())); |
418 | 418 |
419 return true; | 419 return true; |
420 } | 420 } |
421 | 421 |
422 } // namespace media | 422 } // namespace media |
OLD | NEW |