Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Unified Diff: media/base/yuv_convert_unittest.cc

Issue 7003082: Implements RGB to YV12 conversion in YASM. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/base/yuv_convert_unittest.cc
===================================================================
--- media/base/yuv_convert_unittest.cc (revision 88621)
+++ media/base/yuv_convert_unittest.cc (working copy)
@@ -6,6 +6,7 @@
#include "base/file_util.h"
#include "base/path_service.h"
#include "media/base/djb2.h"
+#include "media/base/simd/convert_row.h"
#include "media/base/yuv_convert.h"
#include "media/base/yuv_row.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -333,3 +334,87 @@
kDJB2HashSeed);
EXPECT_EQ(666823187u, yuy_hash);
}
+
+// A loop-back test that converts RGB pixels to YV12 pixels, converts the
+// converted YV12 pixels back to RGB pixels, and compare the converted RGB
+// pixels with the source RGB pixels. RGB-to-YV12 conversion discards the U and
+// V values of src[2 * k + 1] (k >= 0). We repeat the same RGB pixel twice so
+// the U and V values of src[2 * k + 1] become the same as the ones of
+// src[2 * k + 1], respectively.
+TEST(YUVConvertTest, LoopbackRGB) {
+ const int kStep = 4;
+ const int kElements = 256 / kStep;
+ const int kRowSize = kElements * kElements * kElements * 2;
+ static uint8 src[kElements][kElements][kElements][6];
+ static uint8 dst[kElements][kElements][kElements][6];
+ static uint8 y[kRowSize];
+ static uint8 u[(kRowSize + 1) / 2];
+ static uint8 v[(kRowSize + 1) / 2];
+
+ for (int r = 0; r < kElements; ++r) {
+ for (int g = 0; g < kElements; ++g) {
+ for (int b = 0; b < kElements; ++b) {
+ src[r][g][b][0] = b * kStep;
+ src[r][g][b][1] = g * kStep;
+ src[r][g][b][2] = r * kStep;
+ src[r][g][b][3] = b * kStep;
+ src[r][g][b][4] = g * kStep;
+ src[r][g][b][5] = r * kStep;
+ }
+ }
+ }
+
+ media::simd::ConvertRGBtoYUVRow(&src[0][0][0][0], y, u, v, kRowSize);
+ media::simd::ConvertYUVtoRGBRow(y, u, v, &dst[0][0][0][0], kRowSize);
+
+ for (int r = 0; r < kElements; ++r) {
+ for (int g = 0; g < kElements; ++g) {
+ for (int b = 0; b < kElements; ++b) {
+ int error = abs(src[r][g][b][0] - dst[r][g][b][0]);
+ error += abs(src[r][g][b][1] - dst[r][g][b][1]);
+ error += abs(src[r][g][b][2] - dst[r][g][b][2]);
+ EXPECT_LE(error, 4);
+ }
+ }
+ }
+}
+
+TEST(YUVConvertTest, LoopbackRGBA) {
+ const int kStep = 4;
+ const int kElements = 256 / kStep;
+ const int kRowSize = kElements * kElements * kElements * 2;
+ static uint8 src[kElements][kElements][kElements][8];
+ static uint8 dst[kElements][kElements][kElements][8];
+ static uint8 y[kRowSize];
+ static uint8 u[(kRowSize + 1) / 2];
+ static uint8 v[(kRowSize + 1) / 2];
+
+ for (int r = 0; r < kElements; ++r) {
+ for (int g = 0; g < kElements; ++g) {
+ for (int b = 0; b < kElements; ++b) {
+ src[r][g][b][0] = b * kStep;
+ src[r][g][b][1] = g * kStep;
+ src[r][g][b][2] = r * kStep;
+ src[r][g][b][3] = 255;
+ src[r][g][b][4] = b * kStep;
+ src[r][g][b][5] = g * kStep;
+ src[r][g][b][6] = r * kStep;
+ src[r][g][b][7] = 255;
+ }
+ }
+ }
+
+ media::simd::ConvertRGBAtoYUVRow(&src[0][0][0][0], y, u, v, kRowSize);
+ media::simd::ConvertYUVtoRGBARow(y, u, v, &dst[0][0][0][0], kRowSize);
+
+ for (int r = 0; r < kElements; ++r) {
+ for (int g = 0; g < kElements; ++g) {
+ for (int b = 0; b < kElements; ++b) {
+ int error = abs(src[r][g][b][0] - dst[r][g][b][0]);
+ error += abs(src[r][g][b][1] - dst[r][g][b][1]);
+ error += abs(src[r][g][b][2] - dst[r][g][b][2]);
+ EXPECT_LE(error, 4);
+ }
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698