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

Side by Side Diff: tests/ColorSpaceXformTest.cpp

Issue 2084673002: Use a table-based implementation of SkDefaultXform (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: quickEquals() Created 4 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 unified diff | Download patch
« no previous file with comments | « src/opts/SkColorXform_opts.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 Google Inc. 2 * Copyright 2016 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "Resources.h" 8 #include "Resources.h"
9 #include "SkCodec.h" 9 #include "SkCodec.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
11 #include "SkColorSpace.h" 11 #include "SkColorSpace.h"
12 #include "SkColorSpace_Base.h" 12 #include "SkColorSpace_Base.h"
13 #include "SkColorSpaceXform.h" 13 #include "SkColorSpaceXform.h"
14 #include "Test.h" 14 #include "Test.h"
15 15
16 class ColorSpaceXformTest { 16 class ColorSpaceXformTest {
17 public: 17 public:
18 static SkDefaultXform* CreateDefaultXform(const sk_sp<SkGammas>& srcGamma, 18 static std::unique_ptr<SkColorSpaceXform> CreateDefaultXform(const sk_sp<SkG ammas>& srcGamma,
19 const SkMatrix44& srcToDst, const sk_sp<SkGammas>& dstGamma) { 19 const SkMatrix44& srcToDst, const sk_sp<SkGammas>& dstGamma) {
20 return new SkDefaultXform(srcGamma, srcToDst, dstGamma); 20
21 sk_sp<SkColorSpace> srcSpace(
22 new SkColorSpace_Base(nullptr, srcGamma, SkMatrix::I(), nullptr) );
23 sk_sp<SkColorSpace> dstSpace(
24 new SkColorSpace_Base(nullptr, dstGamma, SkMatrix::I(), nullptr) );
25
26 return SkColorSpaceXform::New(srcSpace, dstSpace);
21 } 27 }
22 }; 28 };
23 29
30 static bool almost_equal(int x, int y) {
31 return SkTAbs(x - y) <= 1;
32 }
33
24 static void test_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& gammas) { 34 static void test_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& gammas) {
25 // Arbitrary set of 10 pixels 35 // Arbitrary set of 10 pixels
26 constexpr int width = 10; 36 constexpr int width = 10;
27 constexpr uint32_t srcPixels[width] = { 37 constexpr uint32_t srcPixels[width] = {
28 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, 38 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271,
29 0xFF32AB52, 0xFF0383BC, 0xFF000000, 0xFFFFFFFF, 0xFFDDEEFF, }; 39 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, };
30 uint32_t dstPixels[width]; 40 uint32_t dstPixels[width];
31 41
32 // Identity matrix 42 // Identity matrix
33 SkMatrix44 srcToDst = SkMatrix44::I(); 43 SkMatrix44 srcToDst = SkMatrix44::I();
34 44
35 // Create and perform xform 45 // Create and perform xform
36 std::unique_ptr<SkColorSpaceXform> xform( 46 std::unique_ptr<SkColorSpaceXform> xform =
37 ColorSpaceXformTest::CreateDefaultXform(gammas, srcToDst, gammas)); 47 ColorSpaceXformTest::CreateDefaultXform(gammas, srcToDst, gammas);
38 xform->xform_RGB1_8888(dstPixels, srcPixels, width); 48 xform->xform_RGB1_8888(dstPixels, srcPixels, width);
39 49
40 // Since the matrix is the identity, and the gamma curves match, the pixels 50 // Since the matrix is the identity, and the gamma curves match, the pixels
41 // should be unchanged. 51 // should be unchanged.
42 for (int i = 0; i < width; i++) { 52 for (int i = 0; i < width; i++) {
43 // TODO (msarett): 53 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
44 // As the implementation changes, we may want to use a tolerance here. 54 SkGetPackedR32(dstPixels[i])));
45 REPORTER_ASSERT(r, ((srcPixels[i] >> 0) & 0xFF) == SkGetPackedR32(dstPi xels[i])); 55 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
46 REPORTER_ASSERT(r, ((srcPixels[i] >> 8) & 0xFF) == SkGetPackedG32(dstPi xels[i])); 56 SkGetPackedG32(dstPixels[i])));
47 REPORTER_ASSERT(r, ((srcPixels[i] >> 16) & 0xFF) == SkGetPackedB32(dstPi xels[i])); 57 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
48 REPORTER_ASSERT(r, ((srcPixels[i] >> 24) & 0xFF) == SkGetPackedA32(dstPi xels[i])); 58 SkGetPackedB32(dstPixels[i])));
59 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
60 SkGetPackedA32(dstPixels[i])));
49 } 61 }
50 } 62 }
51 63
52 DEF_TEST(ColorSpaceXform_TableGamma, r) { 64 DEF_TEST(ColorSpaceXform_TableGamma, r) {
53 // Lookup-table based gamma curves 65 // Lookup-table based gamma curves
54 SkGammaCurve red, green, blue; 66 SkGammaCurve red, green, blue;
55 constexpr size_t tableSize = 10; 67 constexpr size_t tableSize = 10;
56 red.fTable = std::unique_ptr<float[]>(new float[tableSize]); 68 red.fTable = std::unique_ptr<float[]>(new float[tableSize]);
57 green.fTable = std::unique_ptr<float[]>(new float[tableSize]); 69 green.fTable = std::unique_ptr<float[]>(new float[tableSize]);
58 blue.fTable = std::unique_ptr<float[]>(new float[tableSize]); 70 blue.fTable = std::unique_ptr<float[]>(new float[tableSize]);
(...skipping 10 matching lines...) Expand all
69 red.fTable[9] = green.fTable[9] = blue.fTable[9] = 1.00f; 81 red.fTable[9] = green.fTable[9] = blue.fTable[9] = 1.00f;
70 sk_sp<SkGammas> gammas = 82 sk_sp<SkGammas> gammas =
71 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e)); 83 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
72 test_xform(r, gammas); 84 test_xform(r, gammas);
73 } 85 }
74 86
75 DEF_TEST(ColorSpaceXform_ParametricGamma, r) { 87 DEF_TEST(ColorSpaceXform_ParametricGamma, r) {
76 // Parametric gamma curves 88 // Parametric gamma curves
77 SkGammaCurve red, green, blue; 89 SkGammaCurve red, green, blue;
78 90
79 // Interval, switch xforms at 0.5f 91 // Interval, switch xforms at 0.0031308f
80 red.fD = green.fD = blue.fD = 0.5f; 92 red.fD = green.fD = blue.fD = 0.04045f;
81 93
82 // First equation, Y = 0.5f * X 94 // First equation:
83 red.fE = green.fE = blue.fE = 0.5f; 95 red.fE = green.fE = blue.fE = 1.0f / 12.92f;
84 96
85 // Second equation, Y = ((1.0f * X) + 0.0f) ^ 3.0f + 0.125f 97 // Second equation:
86 // Note that the function is continuous: 98 // Note that the function is continuous (it's actually sRGB).
87 // 0.5f * 0.5f = ((1.0f * 0.5f) + 0.0f) ^ 3.0f + 0.125f = 0.25f 99 red.fA = green.fA = blue.fA = 1.0f / 1.055f;
88 red.fA = green.fA = blue.fA = 1.0f; 100 red.fB = green.fB = blue.fB = 0.055f / 1.055f;
89 red.fB = green.fB = blue.fB = 0.0f; 101 red.fC = green.fC = blue.fC = 0.0f;
90 red.fC = green.fC = blue.fC = 0.125f; 102 red.fG = green.fG = blue.fG = 2.4f;
91 red.fG = green.fG = blue.fG = 3.0f; 103 sk_sp<SkGammas> gammas =
92 sk_sp<SkGammas> gammas = sk_make_sp<SkGammas>(std::move(red), std::move(gree n), std::move(blue)); 104 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
93 test_xform(r, gammas); 105 test_xform(r, gammas);
94 } 106 }
95 107
96 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) { 108 DEF_TEST(ColorSpaceXform_ExponentialGamma, r) {
97 // Exponential gamma curves 109 // Exponential gamma curves
98 SkGammaCurve red, green, blue; 110 SkGammaCurve red, green, blue;
99 red.fValue = green.fValue = blue.fValue = 4.0f; 111 red.fValue = green.fValue = blue.fValue = 1.4f;
100 sk_sp<SkGammas> gammas = 112 sk_sp<SkGammas> gammas =
101 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e)); 113 sk_make_sp<SkGammas>(std::move(red), std::move(green), std::move(blu e));
102 test_xform(r, gammas); 114 test_xform(r, gammas);
103 } 115 }
OLDNEW
« no previous file with comments | « src/opts/SkColorXform_opts.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698