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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "media/base/video_frame.h" | 6 #include "media/base/video_frame.h" |
7 #include "media/base/video_util.h" | 7 #include "media/base/video_util.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 RotatePlaneByPixels(GetParam().src, dest, GetParam().width, | 321 RotatePlaneByPixels(GetParam().src, dest, GetParam().width, |
322 GetParam().height, rotation, | 322 GetParam().height, rotation, |
323 GetParam().flip_vert, GetParam().flip_horiz); | 323 GetParam().flip_vert, GetParam().flip_horiz); |
324 | 324 |
325 EXPECT_EQ(memcmp(dest, GetParam().target, size), 0); | 325 EXPECT_EQ(memcmp(dest, GetParam().target, size), 0); |
326 } | 326 } |
327 | 327 |
328 INSTANTIATE_TEST_CASE_P(, VideoUtilRotationTest, | 328 INSTANTIATE_TEST_CASE_P(, VideoUtilRotationTest, |
329 testing::ValuesIn(kVideoRotationTestData)); | 329 testing::ValuesIn(kVideoRotationTestData)); |
330 | 330 |
| 331 // Tests the ComputeLetterboxRegion function. Also, because of shared code |
| 332 // internally, this also tests ScaleSizeToFitWithinTarget(). |
331 TEST_F(VideoUtilTest, ComputeLetterboxRegion) { | 333 TEST_F(VideoUtilTest, ComputeLetterboxRegion) { |
332 EXPECT_EQ(gfx::Rect(167, 0, 666, 500), | 334 EXPECT_EQ(gfx::Rect(167, 0, 666, 500), |
333 ComputeLetterboxRegion(gfx::Rect(0, 0, 1000, 500), | 335 ComputeLetterboxRegion(gfx::Rect(0, 0, 1000, 500), |
334 gfx::Size(640, 480))); | 336 gfx::Size(640, 480))); |
335 EXPECT_EQ(gfx::Rect(0, 312, 500, 375), | 337 EXPECT_EQ(gfx::Rect(0, 312, 500, 375), |
336 ComputeLetterboxRegion(gfx::Rect(0, 0, 500, 1000), | 338 ComputeLetterboxRegion(gfx::Rect(0, 0, 500, 1000), |
337 gfx::Size(640, 480))); | 339 gfx::Size(640, 480))); |
338 EXPECT_EQ(gfx::Rect(56, 0, 888, 500), | 340 EXPECT_EQ(gfx::Rect(56, 0, 888, 500), |
339 ComputeLetterboxRegion(gfx::Rect(0, 0, 1000, 500), | 341 ComputeLetterboxRegion(gfx::Rect(0, 0, 1000, 500), |
340 gfx::Size(1920, 1080))); | 342 gfx::Size(1920, 1080))); |
341 EXPECT_EQ(gfx::Rect(0, 12, 100, 75), | 343 EXPECT_EQ(gfx::Rect(0, 12, 100, 75), |
342 ComputeLetterboxRegion(gfx::Rect(0, 0, 100, 100), | 344 ComputeLetterboxRegion(gfx::Rect(0, 0, 100, 100), |
343 gfx::Size(400, 300))); | 345 gfx::Size(400, 300))); |
344 EXPECT_EQ(gfx::Rect(0, 250000000, 2000000000, 1500000000), | 346 EXPECT_EQ(gfx::Rect(0, 250000000, 2000000000, 1500000000), |
345 ComputeLetterboxRegion(gfx::Rect(0, 0, 2000000000, 2000000000), | 347 ComputeLetterboxRegion(gfx::Rect(0, 0, 2000000000, 2000000000), |
346 gfx::Size(40000, 30000))); | 348 gfx::Size(40000, 30000))); |
347 EXPECT_TRUE(ComputeLetterboxRegion(gfx::Rect(0, 0, 2000000000, 2000000000), | 349 EXPECT_TRUE(ComputeLetterboxRegion(gfx::Rect(0, 0, 2000000000, 2000000000), |
348 gfx::Size(0, 0)).IsEmpty()); | 350 gfx::Size(0, 0)).IsEmpty()); |
349 } | 351 } |
350 | 352 |
| 353 TEST_F(VideoUtilTest, ScaleSizeToEncompassTarget) { |
| 354 EXPECT_EQ(gfx::Size(1000, 750), |
| 355 ScaleSizeToEncompassTarget(gfx::Size(640, 480), |
| 356 gfx::Size(1000, 500))); |
| 357 EXPECT_EQ(gfx::Size(1333, 1000), |
| 358 ScaleSizeToEncompassTarget(gfx::Size(640, 480), |
| 359 gfx::Size(500, 1000))); |
| 360 EXPECT_EQ(gfx::Size(1000, 562), |
| 361 ScaleSizeToEncompassTarget(gfx::Size(1920, 1080), |
| 362 gfx::Size(1000, 500))); |
| 363 EXPECT_EQ(gfx::Size(133, 100), |
| 364 ScaleSizeToEncompassTarget(gfx::Size(400, 300), |
| 365 gfx::Size(100, 100))); |
| 366 EXPECT_EQ(gfx::Size(2666666666, 2000000000), |
| 367 ScaleSizeToEncompassTarget(gfx::Size(40000, 30000), |
| 368 gfx::Size(2000000000, 2000000000))); |
| 369 EXPECT_TRUE(ScaleSizeToEncompassTarget( |
| 370 gfx::Size(0, 0), gfx::Size(2000000000, 2000000000)).IsEmpty()); |
| 371 } |
| 372 |
| 373 TEST_F(VideoUtilTest, PadToMatchAspectRatio) { |
| 374 EXPECT_EQ(gfx::Size(640, 480), |
| 375 PadToMatchAspectRatio(gfx::Size(640, 480), gfx::Size(640, 480))); |
| 376 EXPECT_EQ(gfx::Size(640, 480), |
| 377 PadToMatchAspectRatio(gfx::Size(640, 480), gfx::Size(4, 3))); |
| 378 EXPECT_EQ(gfx::Size(960, 480), |
| 379 PadToMatchAspectRatio(gfx::Size(640, 480), gfx::Size(1000, 500))); |
| 380 EXPECT_EQ(gfx::Size(640, 1280), |
| 381 PadToMatchAspectRatio(gfx::Size(640, 480), gfx::Size(500, 1000))); |
| 382 EXPECT_EQ(gfx::Size(2160, 1080), |
| 383 PadToMatchAspectRatio(gfx::Size(1920, 1080), gfx::Size(1000, 500))); |
| 384 EXPECT_EQ(gfx::Size(400, 400), |
| 385 PadToMatchAspectRatio(gfx::Size(400, 300), gfx::Size(100, 100))); |
| 386 EXPECT_EQ(gfx::Size(400, 400), |
| 387 PadToMatchAspectRatio(gfx::Size(300, 400), gfx::Size(100, 100))); |
| 388 EXPECT_EQ(gfx::Size(40000, 40000), |
| 389 PadToMatchAspectRatio(gfx::Size(40000, 30000), |
| 390 gfx::Size(2000000000, 2000000000))); |
| 391 EXPECT_TRUE(PadToMatchAspectRatio( |
| 392 gfx::Size(40000, 30000), gfx::Size(0, 0)).IsEmpty()); |
| 393 } |
| 394 |
351 TEST_F(VideoUtilTest, LetterboxYUV) { | 395 TEST_F(VideoUtilTest, LetterboxYUV) { |
352 int width = 40; | 396 int width = 40; |
353 int height = 30; | 397 int height = 30; |
354 gfx::Size size(width, height); | 398 gfx::Size size(width, height); |
355 scoped_refptr<VideoFrame> frame( | 399 scoped_refptr<VideoFrame> frame( |
356 VideoFrame::CreateFrame(VideoFrame::YV12, size, gfx::Rect(size), size, | 400 VideoFrame::CreateFrame(VideoFrame::YV12, size, gfx::Rect(size), size, |
357 base::TimeDelta())); | 401 base::TimeDelta())); |
358 | 402 |
359 for (int left_margin = 0; left_margin <= 10; left_margin += 10) { | 403 for (int left_margin = 0; left_margin <= 10; left_margin += 10) { |
360 for (int right_margin = 0; right_margin <= 10; right_margin += 10) { | 404 for (int right_margin = 0; right_margin <= 10; right_margin += 10) { |
(...skipping 21 matching lines...) Expand all Loading... |
382 inside ? 0x03 : 0x80); | 426 inside ? 0x03 : 0x80); |
383 } | 427 } |
384 } | 428 } |
385 } | 429 } |
386 } | 430 } |
387 } | 431 } |
388 } | 432 } |
389 } | 433 } |
390 | 434 |
391 } // namespace media | 435 } // namespace media |
OLD | NEW |