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

Unified Diff: ui/gfx/color_space_unittest.cc

Issue 2670773002: Towards deleting YUV to RGB computation redundancy (Closed)
Patch Set: Explicitly mark constants as float Created 3 years, 11 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
« no previous file with comments | « ui/gfx/color_space.cc ('k') | ui/gfx/color_transform.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/color_space_unittest.cc
diff --git a/ui/gfx/color_space_unittest.cc b/ui/gfx/color_space_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1c652fa535ab7aea6ccd27934cc111ee4f348964
--- /dev/null
+++ b/ui/gfx/color_space_unittest.cc
@@ -0,0 +1,83 @@
+// Copyright 2017 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 <cmath>
+
+#include "base/logging.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/gfx/color_space.h"
+
+namespace gfx {
+namespace {
+
+const float kEpsilon = 1.0e-3f;
+
+// Returns the L-infty difference of u and v.
+float Diff(const SkVector4& u, const SkVector4& v) {
+ float result = 0;
+ for (size_t i = 0; i < 4; ++i)
+ result = std::max(result, std::abs(u.fData[i] - v.fData[i]));
+ return result;
+}
+
+TEST(ColorSpace, RGBToYUV) {
+ const size_t kNumTestRGBs = 3;
+ SkVector4 test_rgbs[kNumTestRGBs] = {
+ SkVector4(1.f, 0.f, 0.f, 1.f),
+ SkVector4(0.f, 1.f, 0.f, 1.f),
+ SkVector4(0.f, 0.f, 1.f, 1.f),
+ };
+
+ const size_t kNumColorSpaces = 4;
+ gfx::ColorSpace color_spaces[kNumColorSpaces] = {
+ gfx::ColorSpace::CreateREC601(), gfx::ColorSpace::CreateREC709(),
+ gfx::ColorSpace::CreateJpeg(), gfx::ColorSpace::CreateXYZD50(),
+ };
+
+ SkVector4 expected_yuvs[kNumColorSpaces][kNumTestRGBs] = {
+ // REC601
+ {
+ SkVector4(0.3195f, 0.3518f, 0.9392f, 1.0000f),
+ SkVector4(0.5669f, 0.2090f, 0.1322f, 1.0000f),
+ SkVector4(0.1607f, 0.9392f, 0.4286f, 1.0000f),
+ },
+ // REC709
+ {
+ SkVector4(0.2453f, 0.3994f, 0.9392f, 1.0000f),
+ SkVector4(0.6770f, 0.1614f, 0.1011f, 1.0000f),
+ SkVector4(0.1248f, 0.9392f, 0.4597f, 1.0000f),
+ },
+ // Jpeg
+ {
+ SkVector4(0.2990f, 0.3313f, 1.0000f, 1.0000f),
+ SkVector4(0.5870f, 0.1687f, 0.0813f, 1.0000f),
+ SkVector4(0.1140f, 1.0000f, 0.4187f, 1.0000f),
+ },
+ // XYZD50
+ {
+ SkVector4(1.0000f, 0.0000f, 0.0000f, 1.0000f),
+ SkVector4(0.0000f, 1.0000f, 0.0000f, 1.0000f),
+ SkVector4(0.0000f, 0.0000f, 1.0000f, 1.0000f),
+ },
+ };
+
+ for (size_t i = 0; i < kNumColorSpaces; ++i) {
+ SkMatrix44 transfer;
+ color_spaces[i].GetTransferMatrix(&transfer);
+
+ SkMatrix44 range_adjust;
+ color_spaces[i].GetRangeAdjustMatrix(&range_adjust);
+
+ SkMatrix44 range_adjust_inv;
+ range_adjust.invert(&range_adjust_inv);
+
+ for (size_t j = 0; j < kNumTestRGBs; ++j) {
+ SkVector4 yuv = range_adjust_inv * transfer * test_rgbs[j];
+ EXPECT_LT(Diff(yuv, expected_yuvs[i][j]), kEpsilon);
+ }
+ }
+}
+
+} // namespace
+} // namespace gfx
« no previous file with comments | « ui/gfx/color_space.cc ('k') | ui/gfx/color_transform.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698