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

Side by Side Diff: tests/ColorSpaceXformTest.cpp

Issue 2275563002: Fix generic color space xform, ColorSpaceXformTest (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 4 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/core/SkColorSpaceXform.cpp ('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 std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk Gammas>& gammas) { 18 static std::unique_ptr<SkColorSpaceXform> CreateIdentityXform(const sk_sp<Sk Gammas>& gammas) {
19 // Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut. 19 // Logically we can pass any matrix here. For simplicty, pass I(), i.e. D50 XYZ gamut.
20 sk_sp<SkColorSpace> space(new SkColorSpace_Base( 20 sk_sp<SkColorSpace> space(new SkColorSpace_Base(
21 nullptr, SkColorSpace::kNonStandard_GammaNamed, gammas, SkMatrix ::I(), nullptr)); 21 nullptr, SkColorSpace::kNonStandard_GammaNamed, gammas, SkMatrix ::I(), nullptr));
22 return SkColorSpaceXform::New(space, space); 22
msarett 2016/08/23 14:03:12 This test became useless when we added opts for sp
23 // Use constructor with kNone_ColorSpaceMatch to create SkColorSpaceXfor m. This way,
24 // we bypass the optimizations for when src == dst and actually do the c olor xform.
25 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
26 <SkColorSpace::kNonStandard_GammaNamed, kNone_ColorSpaceMatch>
27 (space, SkMatrix::I(), space));
23 } 28 }
24 }; 29 };
25 30
26 static bool almost_equal(int x, int y) { 31 static bool almost_equal(int x, int y) {
27 return SkTAbs(x - y) <= 1; 32 return SkTAbs(x - y) <= 1;
28 } 33 }
29 34
30 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) { 35 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) {
31 // Arbitrary set of 10 pixels 36 // Arbitrary set of 10 pixels
32 constexpr int width = 10; 37 constexpr int width = 10;
33 constexpr uint32_t srcPixels[width] = { 38 constexpr uint32_t srcPixels[width] = {
34 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, 39 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271,
35 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; 40 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, };
36 uint32_t dstPixels[width]; 41 uint32_t dstPixels[width];
37 42
38 // Create and perform an identity xform. 43 // Create and perform an identity xform.
39 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti tyXform(gammas); 44 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti tyXform(gammas);
40 xform->apply(dstPixels, srcPixels, width, kRGBA_8888_SkColorType, kOpaque_Sk AlphaType); 45 xform->apply(dstPixels, srcPixels, width, kN32_SkColorType, kOpaque_SkAlphaT ype);
msarett 2016/08/23 14:03:12 Turns out only testing RGBA->RGBA is a bad idea...
41 46
42 // Since the src->dst matrix is the identity, and the gamma curves match, 47 // Since the src->dst matrix is the identity, and the gamma curves match,
43 // the pixels should be unchanged. 48 // the pixels should be unchanged.
44 for (int i = 0; i < width; i++) { 49 for (int i = 0; i < width; i++) {
45 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), 50 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
46 ((dstPixels[i] >> 0) & 0xFF))); 51 SkGetPackedR32(dstPixels[i])));
47 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), 52 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
48 ((dstPixels[i] >> 8) & 0xFF))); 53 SkGetPackedG32(dstPixels[i])));
49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), 54 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
50 ((dstPixels[i] >> 16) & 0xFF))); 55 SkGetPackedB32(dstPixels[i])));
51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), 56 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
52 ((dstPixels[i] >> 24) & 0xFF))); 57 SkGetPackedA32(dstPixels[i])));
53 } 58 }
54 } 59 }
55 60
56 DEF_TEST(ColorSpaceXform_TableGamma, r) { 61 DEF_TEST(ColorSpaceXform_TableGamma, r) {
57 // Lookup-table based gamma curves 62 // Lookup-table based gamma curves
58 constexpr size_t tableSize = 10; 63 constexpr size_t tableSize = 10;
59 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize) ; 64 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize) ;
60 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); 65 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
61 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kTable_Type; 66 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kTable_Type;
62 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize = 67 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize =
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 149
145 gammas->fGreenType = SkGammas::Type::kTable_Type; 150 gammas->fGreenType = SkGammas::Type::kTable_Type;
146 gammas->fGreenData.fTable.fSize = tableSize; 151 gammas->fGreenData.fTable.fSize = tableSize;
147 gammas->fGreenData.fTable.fOffset = 0; 152 gammas->fGreenData.fTable.fOffset = 0;
148 153
149 gammas->fBlueType = SkGammas::Type::kParam_Type; 154 gammas->fBlueType = SkGammas::Type::kParam_Type;
150 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; 155 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize;
151 156
152 test_identity_xform(r, gammas); 157 test_identity_xform(r, gammas);
153 } 158 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpaceXform.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698