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

Side by Side 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, 10 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 unified diff | Download patch
« no previous file with comments | « ui/gfx/color_space.cc ('k') | ui/gfx/color_transform.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <cmath>
6
7 #include "base/logging.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/gfx/color_space.h"
10
11 namespace gfx {
12 namespace {
13
14 const float kEpsilon = 1.0e-3f;
15
16 // Returns the L-infty difference of u and v.
17 float Diff(const SkVector4& u, const SkVector4& v) {
18 float result = 0;
19 for (size_t i = 0; i < 4; ++i)
20 result = std::max(result, std::abs(u.fData[i] - v.fData[i]));
21 return result;
22 }
23
24 TEST(ColorSpace, RGBToYUV) {
25 const size_t kNumTestRGBs = 3;
26 SkVector4 test_rgbs[kNumTestRGBs] = {
27 SkVector4(1.f, 0.f, 0.f, 1.f),
28 SkVector4(0.f, 1.f, 0.f, 1.f),
29 SkVector4(0.f, 0.f, 1.f, 1.f),
30 };
31
32 const size_t kNumColorSpaces = 4;
33 gfx::ColorSpace color_spaces[kNumColorSpaces] = {
34 gfx::ColorSpace::CreateREC601(), gfx::ColorSpace::CreateREC709(),
35 gfx::ColorSpace::CreateJpeg(), gfx::ColorSpace::CreateXYZD50(),
36 };
37
38 SkVector4 expected_yuvs[kNumColorSpaces][kNumTestRGBs] = {
39 // REC601
40 {
41 SkVector4(0.3195f, 0.3518f, 0.9392f, 1.0000f),
42 SkVector4(0.5669f, 0.2090f, 0.1322f, 1.0000f),
43 SkVector4(0.1607f, 0.9392f, 0.4286f, 1.0000f),
44 },
45 // REC709
46 {
47 SkVector4(0.2453f, 0.3994f, 0.9392f, 1.0000f),
48 SkVector4(0.6770f, 0.1614f, 0.1011f, 1.0000f),
49 SkVector4(0.1248f, 0.9392f, 0.4597f, 1.0000f),
50 },
51 // Jpeg
52 {
53 SkVector4(0.2990f, 0.3313f, 1.0000f, 1.0000f),
54 SkVector4(0.5870f, 0.1687f, 0.0813f, 1.0000f),
55 SkVector4(0.1140f, 1.0000f, 0.4187f, 1.0000f),
56 },
57 // XYZD50
58 {
59 SkVector4(1.0000f, 0.0000f, 0.0000f, 1.0000f),
60 SkVector4(0.0000f, 1.0000f, 0.0000f, 1.0000f),
61 SkVector4(0.0000f, 0.0000f, 1.0000f, 1.0000f),
62 },
63 };
64
65 for (size_t i = 0; i < kNumColorSpaces; ++i) {
66 SkMatrix44 transfer;
67 color_spaces[i].GetTransferMatrix(&transfer);
68
69 SkMatrix44 range_adjust;
70 color_spaces[i].GetRangeAdjustMatrix(&range_adjust);
71
72 SkMatrix44 range_adjust_inv;
73 range_adjust.invert(&range_adjust_inv);
74
75 for (size_t j = 0; j < kNumTestRGBs; ++j) {
76 SkVector4 yuv = range_adjust_inv * transfer * test_rgbs[j];
77 EXPECT_LT(Diff(yuv, expected_yuvs[i][j]), kEpsilon);
78 }
79 }
80 }
81
82 } // namespace
83 } // namespace gfx
OLDNEW
« 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