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

Side by Side Diff: src/core/SkColorSpaceXform.cpp

Issue 2323003002: Cache the inverse matrix on SkColorSpace. Rename xyz() to toXYZ(). (Closed)
Patch Set: Remove xyz() again 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/SkColorSpace.cpp ('k') | src/core/SkColorSpace_Base.h » ('j') | 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 "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkColorSpace_Base.h" 9 #include "SkColorSpace_Base.h"
10 #include "SkColorSpacePriv.h" 10 #include "SkColorSpacePriv.h"
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 params.fF); 439 params.fF);
440 outGammaTables[i] = &gammaTableStorage[i * gammaTableSize]; 440 outGammaTables[i] = &gammaTableStorage[i * gammaTableSize];
441 } 441 }
442 } 442 }
443 } 443 }
444 } 444 }
445 } 445 }
446 446
447 //////////////////////////////////////////////////////////////////////////////// /////////////////// 447 //////////////////////////////////////////////////////////////////////////////// ///////////////////
448 448
449 static inline bool compute_gamut_xform(SkMatrix44* srcToDst, const SkMatrix44& s rcToXYZ, 449 static inline void compute_gamut_xform(SkMatrix44* srcToDst, const SkColorSpace* src,
450 const SkMatrix44& dstToXYZ) { 450 const SkColorSpace* dst) {
451 if (!dstToXYZ.invert(srcToDst)) { 451 *srcToDst = as_CSB(dst)->fromXYZD50();
452 return false; 452 srcToDst->postConcat(src->toXYZD50());
453 }
454
455 srcToDst->postConcat(srcToXYZ);
456 return true;
457 } 453 }
458 454
459 static inline bool is_almost_identity(const SkMatrix44& srcToDst) { 455 static inline bool is_almost_identity(const SkMatrix44& srcToDst) {
460 for (int i = 0; i < 4; i++) { 456 for (int i = 0; i < 4; i++) {
461 for (int j = 0; j < 4; j++) { 457 for (int j = 0; j < 4; j++) {
462 float expected = (i == j) ? 1.0f : 0.0f; 458 float expected = (i == j) ? 1.0f : 0.0f;
463 if (!color_space_almost_equal(srcToDst.getFloat(i,j), expected)) { 459 if (!color_space_almost_equal(srcToDst.getFloat(i,j), expected)) {
464 return false; 460 return false;
465 } 461 }
466 } 462 }
467 } 463 }
468 return true; 464 return true;
469 } 465 }
470 466
471 //////////////////////////////////////////////////////////////////////////////// /////////////////// 467 //////////////////////////////////////////////////////////////////////////////// ///////////////////
472 468
473 std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa ce>& srcSpace, 469 std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(const sk_sp<SkColorSpa ce>& srcSpace,
474 const sk_sp<SkColorSpa ce>& dstSpace) { 470 const sk_sp<SkColorSpa ce>& dstSpace) {
475 if (!srcSpace || !dstSpace) { 471 if (!srcSpace || !dstSpace) {
476 // Invalid input 472 // Invalid input
477 return nullptr; 473 return nullptr;
478 } 474 }
479 475
480 ColorSpaceMatch csm = kNone_ColorSpaceMatch; 476 ColorSpaceMatch csm = kNone_ColorSpaceMatch;
481 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor); 477 SkMatrix44 srcToDst(SkMatrix44::kUninitialized_Constructor);
482 if (SkColorSpace::Equals(srcSpace.get(), dstSpace.get())) { 478 if (SkColorSpace::Equals(srcSpace.get(), dstSpace.get())) {
483 srcToDst.setIdentity(); 479 srcToDst.setIdentity();
484 csm = kFull_ColorSpaceMatch; 480 csm = kFull_ColorSpaceMatch;
485 } else if (!compute_gamut_xform(&srcToDst, srcSpace->xyz(), dstSpace->xyz()) ) { 481 } else {
486 return nullptr; 482 compute_gamut_xform(&srcToDst, srcSpace.get(), dstSpace.get());
487 } else if (is_almost_identity(srcToDst)) { 483
488 srcToDst.setIdentity(); 484 if (is_almost_identity(srcToDst)) {
489 csm = kGamut_ColorSpaceMatch; 485 srcToDst.setIdentity();
486 csm = kGamut_ColorSpaceMatch;
487 }
490 } 488 }
491 489
492 switch (csm) { 490 switch (csm) {
493 case kNone_ColorSpaceMatch: 491 case kNone_ColorSpaceMatch:
494 switch (as_CSB(dstSpace)->gammaNamed()) { 492 switch (as_CSB(dstSpace)->gammaNamed()) {
495 case kSRGB_SkGammaNamed: 493 case kSRGB_SkGammaNamed:
496 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXf orm_Base 494 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXf orm_Base
497 <kSRGB_SkGammaNamed, kNone_ColorSpaceMatch> 495 <kSRGB_SkGammaNamed, kNone_ColorSpaceMatch>
498 (srcSpace, srcToDst, dstSpace)); 496 (srcSpace, srcToDst, dstSpace));
499 case k2Dot2Curve_SkGammaNamed: 497 case k2Dot2Curve_SkGammaNamed:
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 SkASSERT(false); 1202 SkASSERT(false);
1205 return; 1203 return;
1206 } 1204 }
1207 } 1205 }
1208 1206
1209 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space) { 1207 std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(const sk_sp<SkColorSpace>& space) {
1210 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base 1208 return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
1211 <kNonStandard_SkGammaNamed, kNone_ColorSpaceMatch> 1209 <kNonStandard_SkGammaNamed, kNone_ColorSpaceMatch>
1212 (space, SkMatrix::I(), space)); 1210 (space, SkMatrix::I(), space));
1213 } 1211 }
OLDNEW
« no previous file with comments | « src/core/SkColorSpace.cpp ('k') | src/core/SkColorSpace_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698