| OLD | NEW |
| 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 "SkAtomics.h" | 8 #include "SkAtomics.h" |
| 9 #include "SkColorSpace.h" | 9 #include "SkColorSpace.h" |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 , fNamed(named) | 95 , fNamed(named) |
| 96 { | 96 { |
| 97 for (int i = 0; i < 3; ++i) { | 97 for (int i = 0; i < 3; ++i) { |
| 98 SkASSERT(SkFloatIsFinite(gamma.fVec[i])); | 98 SkASSERT(SkFloatIsFinite(gamma.fVec[i])); |
| 99 for (int j = 0; j < 3; ++j) { | 99 for (int j = 0; j < 3; ++j) { |
| 100 SkASSERT(SkFloatIsFinite(toXYZD50.fMat[3*i + j])); | 100 SkASSERT(SkFloatIsFinite(toXYZD50.fMat[3*i + j])); |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 } | 103 } |
| 104 | 104 |
| 105 SkColorSpace* SkColorSpace::NewRGB(const SkFloat3x3& toXYZD50, const SkFloat3& g
amma) { | 105 sk_sp<SkColorSpace> SkColorSpace::NewRGB(const SkFloat3x3& toXYZD50, const SkFlo
at3& gamma) { |
| 106 for (int i = 0; i < 3; ++i) { | 106 for (int i = 0; i < 3; ++i) { |
| 107 if (!SkFloatIsFinite(gamma.fVec[i]) || gamma.fVec[i] < 0) { | 107 if (!SkFloatIsFinite(gamma.fVec[i]) || gamma.fVec[i] < 0) { |
| 108 return nullptr; | 108 return nullptr; |
| 109 } | 109 } |
| 110 for (int j = 0; j < 3; ++j) { | 110 for (int j = 0; j < 3; ++j) { |
| 111 if (!SkFloatIsFinite(toXYZD50.fMat[3*i + j])) { | 111 if (!SkFloatIsFinite(toXYZD50.fMat[3*i + j])) { |
| 112 return nullptr; | 112 return nullptr; |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 // check the matrix for invertibility | 117 // check the matrix for invertibility |
| 118 float d = det(toXYZD50); | 118 float d = det(toXYZD50); |
| 119 if (!SkFloatIsFinite(d) || !SkFloatIsFinite(1 / d)) { | 119 if (!SkFloatIsFinite(d) || !SkFloatIsFinite(1 / d)) { |
| 120 return nullptr; | 120 return nullptr; |
| 121 } | 121 } |
| 122 | 122 |
| 123 return new SkColorSpace(toXYZD50, gamma, kUnknown_Named); | 123 return sk_sp<SkColorSpace>(new SkColorSpace(toXYZD50, gamma, kUnknown_Named)
); |
| 124 } | 124 } |
| 125 | 125 |
| 126 void SkColorSpace::dump() const { | 126 void SkColorSpace::dump() const { |
| 127 fToXYZD50.dump(); | 127 fToXYZD50.dump(); |
| 128 fGamma.dump(); | 128 fGamma.dump(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 ////////////////////////////////////////////////////////////////////////////////
////////////////// | 131 ////////////////////////////////////////////////////////////////////////////////
////////////////// |
| 132 | 132 |
| 133 const SkFloat3 gDevice_gamma {{ 0, 0, 0 }}; | 133 const SkFloat3 gDevice_gamma {{ 0, 0, 0 }}; |
| 134 const SkFloat3x3 gDevice_toXYZD50 {{ | 134 const SkFloat3x3 gDevice_toXYZD50 {{ |
| 135 1, 0, 0, | 135 1, 0, 0, |
| 136 0, 1, 0, | 136 0, 1, 0, |
| 137 0, 0, 1 | 137 0, 0, 1 |
| 138 }}; | 138 }}; |
| 139 | 139 |
| 140 const SkFloat3 gSRGB_gamma {{ 2.2f, 2.2f, 2.2f }}; | 140 const SkFloat3 gSRGB_gamma {{ 2.2f, 2.2f, 2.2f }}; |
| 141 const SkFloat3x3 gSRGB_toXYZD50 {{ | 141 const SkFloat3x3 gSRGB_toXYZD50 {{ |
| 142 0.4358f, 0.2224f, 0.0139f, // * R | 142 0.4358f, 0.2224f, 0.0139f, // * R |
| 143 0.3853f, 0.7170f, 0.0971f, // * G | 143 0.3853f, 0.7170f, 0.0971f, // * G |
| 144 0.1430f, 0.0606f, 0.7139f, // * B | 144 0.1430f, 0.0606f, 0.7139f, // * B |
| 145 }}; | 145 }}; |
| 146 | 146 |
| 147 SkColorSpace* SkColorSpace::NewNamed(Named named) { | 147 sk_sp<SkColorSpace> SkColorSpace::NewNamed(Named named) { |
| 148 switch (named) { | 148 switch (named) { |
| 149 case kDevice_Named: | 149 case kDevice_Named: |
| 150 return new SkColorSpace(gDevice_toXYZD50, gDevice_gamma, kDevice_Nam
ed); | 150 return sk_sp<SkColorSpace>(new SkColorSpace(gDevice_toXYZD50, gDevic
e_gamma, |
| 151 kDevice_Named)); |
| 151 case kSRGB_Named: | 152 case kSRGB_Named: |
| 152 return new SkColorSpace(gSRGB_toXYZD50, gSRGB_gamma, kSRGB_Named); | 153 return sk_sp<SkColorSpace>(new SkColorSpace(gSRGB_toXYZD50, gSRGB_ga
mma, kSRGB_Named)); |
| 153 default: | 154 default: |
| 154 break; | 155 break; |
| 155 } | 156 } |
| 156 return nullptr; | 157 return nullptr; |
| 157 } | 158 } |
| 158 | 159 |
| 159 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 160 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 160 | 161 |
| 161 #include "SkFixed.h" | 162 #include "SkFixed.h" |
| 162 #include "SkTemplates.h" | 163 #include "SkTemplates.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Guess 2.2f. | 371 // Guess 2.2f. |
| 371 SkColorSpacePrintf("parametric curve\n"); | 372 SkColorSpacePrintf("parametric curve\n"); |
| 372 *gamma = 2.2f; | 373 *gamma = 2.2f; |
| 373 return true; | 374 return true; |
| 374 default: | 375 default: |
| 375 SkColorSpacePrintf("Unsupported gamma tag type %d\n", type); | 376 SkColorSpacePrintf("Unsupported gamma tag type %d\n", type); |
| 376 return false; | 377 return false; |
| 377 } | 378 } |
| 378 } | 379 } |
| 379 | 380 |
| 380 SkColorSpace* SkColorSpace::NewICC(const void* base, size_t len) { | 381 sk_sp<SkColorSpace> SkColorSpace::NewICC(const void* base, size_t len) { |
| 381 const uint8_t* ptr = (const uint8_t*) base; | 382 const uint8_t* ptr = (const uint8_t*) base; |
| 382 | 383 |
| 383 if (len < kICCHeaderSize) { | 384 if (len < kICCHeaderSize) { |
| 384 return_null("Data is not large enough to contain an ICC profile"); | 385 return_null("Data is not large enough to contain an ICC profile"); |
| 385 } | 386 } |
| 386 | 387 |
| 387 // Read the ICC profile header and check to make sure that it is valid. | 388 // Read the ICC profile header and check to make sure that it is valid. |
| 388 ICCProfileHeader header; | 389 ICCProfileHeader header; |
| 389 header.init(ptr, len); | 390 header.init(ptr, len); |
| 390 if (!header.valid()) { | 391 if (!header.valid()) { |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 SkDebugf("\n"); | 522 SkDebugf("\n"); |
| 522 | 523 |
| 523 mat = gSRGB_toXYZD50; | 524 mat = gSRGB_toXYZD50; |
| 524 inv = invert(mat); | 525 inv = invert(mat); |
| 525 mat.dump(); | 526 mat.dump(); |
| 526 inv.dump(); | 527 inv.dump(); |
| 527 concat(mat, inv).dump(); | 528 concat(mat, inv).dump(); |
| 528 concat(inv, mat).dump(); | 529 concat(inv, mat).dump(); |
| 529 SkDebugf("\n"); | 530 SkDebugf("\n"); |
| 530 | 531 |
| 531 SkAutoTUnref<SkColorSpace> cs0(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
med)); | 532 sk_sp<SkColorSpace> cs0(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); |
| 532 SkAutoTUnref<SkColorSpace> cs1(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Na
med)); | 533 sk_sp<SkColorSpace> cs1(SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named)); |
| 533 | 534 |
| 534 cs0->dump(); | 535 cs0->dump(); |
| 535 cs1->dump(); | 536 cs1->dump(); |
| 536 SkFloat3x3 xform; | 537 SkFloat3x3 xform; |
| 537 (void)SkColorSpace::Concat(cs0, cs1, &xform); | 538 (void)SkColorSpace::Concat(cs0.get(), cs1.get(), &xform); |
| 538 xform.dump(); | 539 xform.dump(); |
| 539 SkDebugf("\n"); | 540 SkDebugf("\n"); |
| 540 } | 541 } |
| 541 | 542 |
| 542 // D65 white point of Rec. 709 [8] are: | 543 // D65 white point of Rec. 709 [8] are: |
| 543 // | 544 // |
| 544 // D65 white-point in unit luminance XYZ = 0.9505, 1.0000, 1.0890 | 545 // D65 white-point in unit luminance XYZ = 0.9505, 1.0000, 1.0890 |
| 545 // | 546 // |
| 546 // R G B white | 547 // R G B white |
| 547 // x 0.640 0.300 0.150 0.3127 | 548 // x 0.640 0.300 0.150 0.3127 |
| 548 // y 0.330 0.600 0.060 0.3290 | 549 // y 0.330 0.600 0.060 0.3290 |
| 549 // z 0.030 0.100 0.790 0.3582 | 550 // z 0.030 0.100 0.790 0.3582 |
| OLD | NEW |