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

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: Add helper function for testing Created 4 years, 3 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
23 // Use special testing entry point, so we don't skip the xform, even tho ugh src == dst.
24 return SlowIdentityXform(space);
23 } 25 }
24 }; 26 };
25 27
26 static bool almost_equal(int x, int y) { 28 static bool almost_equal(int x, int y) {
27 return SkTAbs(x - y) <= 1; 29 return SkTAbs(x - y) <= 1;
28 } 30 }
29 31
30 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) { 32 static void test_identity_xform(skiatest::Reporter* r, const sk_sp<SkGammas>& ga mmas) {
31 // Arbitrary set of 10 pixels 33 // Arbitrary set of 10 pixels
32 constexpr int width = 10; 34 constexpr int width = 10;
33 constexpr uint32_t srcPixels[width] = { 35 constexpr uint32_t srcPixels[width] = {
34 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271, 36 0xFFABCDEF, 0xFF146829, 0xFF382759, 0xFF184968, 0xFFDE8271,
35 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, }; 37 0xFF32AB52, 0xFF0383BC, 0xFF000102, 0xFFFFFFFF, 0xFFDDEEFF, };
36 uint32_t dstPixels[width]; 38 uint32_t dstPixels[width];
37 39
38 // Create and perform an identity xform. 40 // Create and perform an identity xform.
39 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti tyXform(gammas); 41 std::unique_ptr<SkColorSpaceXform> xform = ColorSpaceXformTest::CreateIdenti tyXform(gammas);
40 xform->apply(dstPixels, srcPixels, width, kRGBA_8888_SkColorType, kOpaque_Sk AlphaType); 42 xform->apply(dstPixels, srcPixels, width, kN32_SkColorType, kOpaque_SkAlphaT ype);
41 43
42 // Since the src->dst matrix is the identity, and the gamma curves match, 44 // Since the src->dst matrix is the identity, and the gamma curves match,
43 // the pixels should be unchanged. 45 // the pixels should be unchanged.
44 for (int i = 0; i < width; i++) { 46 for (int i = 0; i < width; i++) {
45 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF), 47 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 0) & 0xFF),
46 ((dstPixels[i] >> 0) & 0xFF))); 48 SkGetPackedR32(dstPixels[i])));
47 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF), 49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 8) & 0xFF),
48 ((dstPixels[i] >> 8) & 0xFF))); 50 SkGetPackedG32(dstPixels[i])));
49 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF), 51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 16) & 0xFF),
50 ((dstPixels[i] >> 16) & 0xFF))); 52 SkGetPackedB32(dstPixels[i])));
51 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF), 53 REPORTER_ASSERT(r, almost_equal(((srcPixels[i] >> 24) & 0xFF),
52 ((dstPixels[i] >> 24) & 0xFF))); 54 SkGetPackedA32(dstPixels[i])));
53 } 55 }
54 } 56 }
55 57
56 DEF_TEST(ColorSpaceXform_TableGamma, r) { 58 DEF_TEST(ColorSpaceXform_TableGamma, r) {
57 // Lookup-table based gamma curves 59 // Lookup-table based gamma curves
58 constexpr size_t tableSize = 10; 60 constexpr size_t tableSize = 10;
59 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize) ; 61 void* memory = sk_malloc_throw(sizeof(SkGammas) + sizeof(float) * tableSize) ;
60 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas()); 62 sk_sp<SkGammas> gammas = sk_sp<SkGammas>(new (memory) SkGammas());
61 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kTable_Type; 63 gammas->fRedType = gammas->fGreenType = gammas->fBlueType = SkGammas::Type:: kTable_Type;
62 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize = 64 gammas->fRedData.fTable.fSize = gammas->fGreenData.fTable.fSize =
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 146
145 gammas->fGreenType = SkGammas::Type::kTable_Type; 147 gammas->fGreenType = SkGammas::Type::kTable_Type;
146 gammas->fGreenData.fTable.fSize = tableSize; 148 gammas->fGreenData.fTable.fSize = tableSize;
147 gammas->fGreenData.fTable.fOffset = 0; 149 gammas->fGreenData.fTable.fOffset = 0;
148 150
149 gammas->fBlueType = SkGammas::Type::kParam_Type; 151 gammas->fBlueType = SkGammas::Type::kParam_Type;
150 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize; 152 gammas->fBlueData.fParamOffset = sizeof(float) * tableSize;
151 153
152 test_identity_xform(r, gammas); 154 test_identity_xform(r, gammas);
153 } 155 }
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