| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/base_paths.h" | 5 #include "base/base_paths.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "media/base/djb2.h" | 8 #include "media/base/djb2.h" |
| 9 #include "media/base/simd/convert_row.h" |
| 9 #include "media/base/yuv_convert.h" | 10 #include "media/base/yuv_convert.h" |
| 10 #include "media/base/yuv_row.h" | 11 #include "media/base/yuv_row.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 // Size of raw image. | 14 // Size of raw image. |
| 14 static const int kSourceWidth = 640; | 15 static const int kSourceWidth = 640; |
| 15 static const int kSourceHeight = 360; | 16 static const int kSourceHeight = 360; |
| 16 static const int kSourceYSize = kSourceWidth * kSourceHeight; | 17 static const int kSourceYSize = kSourceWidth * kSourceHeight; |
| 17 static const int kScaledWidth = 1024; | 18 static const int kScaledWidth = 1024; |
| 18 static const int kScaledHeight = 768; | 19 static const int kScaledHeight = 768; |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 media::ConvertYUY2ToYUV(yuy_bytes.get(), | 327 media::ConvertYUY2ToYUV(yuy_bytes.get(), |
| 327 yuv_converted_bytes.get(), | 328 yuv_converted_bytes.get(), |
| 328 yuv_converted_bytes.get() + kSourceYSize, | 329 yuv_converted_bytes.get() + kSourceYSize, |
| 329 yuv_converted_bytes.get() + kSourceYSize * 5 / 4, | 330 yuv_converted_bytes.get() + kSourceYSize * 5 / 4, |
| 330 kSourceWidth, kSourceHeight); | 331 kSourceWidth, kSourceHeight); |
| 331 | 332 |
| 332 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, | 333 uint32 yuy_hash = DJB2Hash(yuv_converted_bytes.get(), kYUV12Size, |
| 333 kDJB2HashSeed); | 334 kDJB2HashSeed); |
| 334 EXPECT_EQ(666823187u, yuy_hash); | 335 EXPECT_EQ(666823187u, yuy_hash); |
| 335 } | 336 } |
| 337 |
| 338 // A loop-back test that converts RGB pixels to YV12 pixels, converts the |
| 339 // converted YV12 pixels back to RGB pixels, and compare the converted RGB |
| 340 // pixels with the source RGB pixels. RGB-to-YV12 conversion discards the U and |
| 341 // V values of src[2 * k + 1] (k >= 0). We repeat the same RGB pixel twice so |
| 342 // the U and V values of src[2 * k + 1] become the same as the ones of |
| 343 // src[2 * k + 1], respectively. |
| 344 TEST(YUVConvertTest, LoopbackRGB) { |
| 345 const int kStep = 4; |
| 346 const int kElements = 256 / kStep; |
| 347 const int kRowSize = kElements * kElements * kElements * 2; |
| 348 static uint8 src[kElements][kElements][kElements][6]; |
| 349 static uint8 dst[kElements][kElements][kElements][6]; |
| 350 static uint8 y[kRowSize]; |
| 351 static uint8 u[(kRowSize + 1) / 2]; |
| 352 static uint8 v[(kRowSize + 1) / 2]; |
| 353 |
| 354 for (int r = 0; r < kElements; ++r) { |
| 355 for (int g = 0; g < kElements; ++g) { |
| 356 for (int b = 0; b < kElements; ++b) { |
| 357 src[r][g][b][0] = b * kStep; |
| 358 src[r][g][b][1] = g * kStep; |
| 359 src[r][g][b][2] = r * kStep; |
| 360 src[r][g][b][3] = b * kStep; |
| 361 src[r][g][b][4] = g * kStep; |
| 362 src[r][g][b][5] = r * kStep; |
| 363 } |
| 364 } |
| 365 } |
| 366 |
| 367 media::simd::ConvertRGBtoYUVRow(&src[0][0][0][0], y, u, v, kRowSize); |
| 368 media::simd::ConvertYUVtoRGBRow(y, u, v, &dst[0][0][0][0], kRowSize); |
| 369 |
| 370 for (int r = 0; r < kElements; ++r) { |
| 371 for (int g = 0; g < kElements; ++g) { |
| 372 for (int b = 0; b < kElements; ++b) { |
| 373 int error = abs(src[r][g][b][0] - dst[r][g][b][0]); |
| 374 error += abs(src[r][g][b][1] - dst[r][g][b][1]); |
| 375 error += abs(src[r][g][b][2] - dst[r][g][b][2]); |
| 376 EXPECT_LE(error, 4); |
| 377 } |
| 378 } |
| 379 } |
| 380 } |
| 381 |
| 382 TEST(YUVConvertTest, LoopbackRGBA) { |
| 383 const int kStep = 4; |
| 384 const int kElements = 256 / kStep; |
| 385 const int kRowSize = kElements * kElements * kElements * 2; |
| 386 static uint8 src[kElements][kElements][kElements][8]; |
| 387 static uint8 dst[kElements][kElements][kElements][8]; |
| 388 static uint8 y[kRowSize]; |
| 389 static uint8 u[(kRowSize + 1) / 2]; |
| 390 static uint8 v[(kRowSize + 1) / 2]; |
| 391 |
| 392 for (int r = 0; r < kElements; ++r) { |
| 393 for (int g = 0; g < kElements; ++g) { |
| 394 for (int b = 0; b < kElements; ++b) { |
| 395 src[r][g][b][0] = b * kStep; |
| 396 src[r][g][b][1] = g * kStep; |
| 397 src[r][g][b][2] = r * kStep; |
| 398 src[r][g][b][3] = 255; |
| 399 src[r][g][b][4] = b * kStep; |
| 400 src[r][g][b][5] = g * kStep; |
| 401 src[r][g][b][6] = r * kStep; |
| 402 src[r][g][b][7] = 255; |
| 403 } |
| 404 } |
| 405 } |
| 406 |
| 407 media::simd::ConvertRGBAtoYUVRow(&src[0][0][0][0], y, u, v, kRowSize); |
| 408 media::simd::ConvertYUVtoRGBARow(y, u, v, &dst[0][0][0][0], kRowSize); |
| 409 |
| 410 for (int r = 0; r < kElements; ++r) { |
| 411 for (int g = 0; g < kElements; ++g) { |
| 412 for (int b = 0; b < kElements; ++b) { |
| 413 int error = abs(src[r][g][b][0] - dst[r][g][b][0]); |
| 414 error += abs(src[r][g][b][1] - dst[r][g][b][1]); |
| 415 error += abs(src[r][g][b][2] - dst[r][g][b][2]); |
| 416 EXPECT_LE(error, 4); |
| 417 } |
| 418 } |
| 419 } |
| 420 } |
| OLD | NEW |