Commit db81017f authored by fbarchard@google.com's avatar fbarchard@google.com

Test color space against a reference function.

BUG=none
TESTED=TestYUV
R=tpsiaki@google.com

Review URL: https://webrtc-codereview.appspot.com/35789004

git-svn-id: http://libyuv.googlecode.com/svn/trunk@1229 16f28f9a-4ce2-e073-06de-1de4eb20be90
parent a5a15198
......@@ -114,4 +114,77 @@ TESTCS(TestI422, I422ToARGB, ARGBToI422, 0, 1, 0, 7)
TESTCS(TestJ420, J420ToARGB, ARGBToJ420, 1, 2, benchmark_width_, 3)
TESTCS(TestJ422, J422ToARGB, ARGBToJ422, 0, 1, 0, 3)
int Clamp(double f) {
int i = static_cast<int>(round(f));
if (i < 0) {
i = 0;
}
if (i > 255) {
i = 255;
}
return i;
}
void TestYUVToRGBReference(int y, int u, int v, int &r, int &g, int &b) {
r = Clamp((y - 16) * 1.164 + (v - 128) * 1.596);
g = Clamp((y - 16) * 1.164 + (u - 128) * -0.391 + (v - 128) * -0.813);
b = Clamp((y - 16) * 1.164 + (u - 128) * 2.018);
}
void TestYUVToRGB(int y, int u, int v, int &r, int &g, int &b,
int benchmark_width_, int benchmark_height_) {
const int kPixels = benchmark_width_ * benchmark_height_;
const int kHalfPixels = ((benchmark_width_ + 1) / 2) *
((benchmark_height_ + 1) / 2);
align_buffer_64(orig_y, kPixels);
align_buffer_64(orig_u, kHalfPixels);
align_buffer_64(orig_v, kHalfPixels);
align_buffer_64(orig_pixels, kPixels * 4);
memset(orig_y, y, kPixels);
memset(orig_u, u, kHalfPixels);
memset(orig_v, v, kHalfPixels);
MemRandomize(orig_pixels, kPixels * 4);
/* YUV converted to ARGB. */
I420ToARGB(orig_y, benchmark_width_,
orig_u, (benchmark_width_ + 1) / 2,
orig_v, (benchmark_width_ + 1) / 2,
orig_pixels, benchmark_width_ * 4,
benchmark_width_, benchmark_height_);
b = orig_pixels[0];
g = orig_pixels[1];
r = orig_pixels[2];
free_aligned_buffer_64(orig_pixels);
free_aligned_buffer_64(orig_y);
free_aligned_buffer_64(orig_u);
free_aligned_buffer_64(orig_v);
}
TEST_F(libyuvTest, TestYUV) {
int r0, g0, b0;
TestYUVToRGBReference(16, 128, 128, r0, g0, b0);
EXPECT_EQ(0, r0);
EXPECT_EQ(0, g0);
EXPECT_EQ(0, b0);
int r1, g1, b1;
TestYUVToRGB(16, 128, 128, r1, g1, b1, benchmark_width_, benchmark_height_);
EXPECT_EQ(0, r1);
EXPECT_EQ(0, g1);
EXPECT_EQ(0, b1);
TestYUVToRGBReference(240, 128, 128, r0, g0, b0);
EXPECT_EQ(255, r0);
EXPECT_EQ(255, g0);
EXPECT_EQ(255, b0);
TestYUVToRGB(240, 128, 128, r1, g1, b1, benchmark_width_, benchmark_height_);
EXPECT_EQ(255, r1);
EXPECT_EQ(254, g1);
EXPECT_EQ(255, b1);
}
} // namespace libyuv
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment