summaryrefslogtreecommitdiffstats
path: root/media/base/yuv_convert_unittest.cc
diff options
context:
space:
mode:
authorfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 02:13:05 +0000
committerfbarchard@chromium.org <fbarchard@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-06 02:13:05 +0000
commit2f9d1c51c1b179c783631d63301c239e797ff0c8 (patch)
tree45cdc54db1dbb618b5770b767882da51fe8ebf51 /media/base/yuv_convert_unittest.cc
parentcfb8c047aae384eb1e6c27c047832ff41a8764b3 (diff)
downloadchromium_src-2f9d1c51c1b179c783631d63301c239e797ff0c8.zip
chromium_src-2f9d1c51c1b179c783631d63301c239e797ff0c8.tar.gz
chromium_src-2f9d1c51c1b179c783631d63301c239e797ff0c8.tar.bz2
YUV conversion code.
This will be used for reference. Its reasonably simple, fast and high quality. Future versions will be optimized and should try to maintain similar quality. Longer term we may move this to Skia or attempt a hardware version. Review URL: http://codereview.chromium.org/40029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11089 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/yuv_convert_unittest.cc')
-rw-r--r--media/base/yuv_convert_unittest.cc62
1 files changed, 62 insertions, 0 deletions
diff --git a/media/base/yuv_convert_unittest.cc b/media/base/yuv_convert_unittest.cc
new file mode 100644
index 0000000..d27bdda6
--- /dev/null
+++ b/media/base/yuv_convert_unittest.cc
@@ -0,0 +1,62 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/base_paths.h"
+#include "base/file_util.h"
+#include "media/base/yuv_convert.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Size of raw image.
+static const int kWidth = 1280;
+static const int kHeight = 720;
+static const int kBpp = 4;
+
+TEST(YuvConvertTest, Basic) {
+ // Read YUV reference data from file.
+ FilePath yuv_url;
+ EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &yuv_url));
+ yuv_url = yuv_url.Append(FILE_PATH_LITERAL("media"))
+ .Append(FILE_PATH_LITERAL("test"))
+ .Append(FILE_PATH_LITERAL("data"))
+ .Append(FILE_PATH_LITERAL("yuv_file"));
+ const size_t size_of_yuv = kWidth * kHeight * 12 / 8;
+ uint8* yuv_bytes = new uint8[size_of_yuv];
+ EXPECT_EQ(size_of_yuv, file_util::ReadFile(yuv_url,
+ reinterpret_cast<char*>(yuv_bytes),
+ static_cast<int>(size_of_yuv)));
+
+ // Read RGB reference data from file.
+ // To keep the file smaller, only the first quarter of the file
+ // is checked into SVN.
+ FilePath rgb_url;
+ EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &rgb_url));
+ rgb_url = rgb_url.Append(FILE_PATH_LITERAL("media"))
+ .Append(FILE_PATH_LITERAL("test"))
+ .Append(FILE_PATH_LITERAL("data"))
+ .Append(FILE_PATH_LITERAL("rgb_file"));
+ const size_t size_of_rgb = kWidth * kHeight * kBpp / 4;
+ uint8* rgb_bytes = new uint8[size_of_rgb];
+ EXPECT_EQ(size_of_rgb, file_util::ReadFile(rgb_url,
+ reinterpret_cast<char*>(rgb_bytes),
+ static_cast<int>(size_of_rgb)));
+
+ // Convert a frame of YUV to 32 bit ARGB.
+ const size_t size_of_rgb_converted = kWidth * kHeight * kBpp;
+ uint8* rgb_converted_bytes = new uint8[size_of_rgb_converted];
+
+ media::ConvertYV12ToRGB32(yuv_bytes, // Y plane
+ yuv_bytes + kWidth * kHeight, // U plane
+ yuv_bytes + kWidth * kHeight * 5 / 4, // V plane
+ rgb_converted_bytes, // Rgb output
+ kWidth, kHeight, // Dimensions
+ kWidth, // YStride
+ kWidth / 2, // UvStride
+ kWidth * kBpp); // RgbStride
+
+ // Compare converted YUV to reference conversion file.
+ int rgb_diff = memcmp(rgb_converted_bytes, rgb_bytes, size_of_rgb);
+
+ EXPECT_EQ(rgb_diff, 0);
+}
+