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

Unified Diff: src/core/SkColorSpace.cpp

Issue 2196743002: Add SkColorSpace::Equals() API (Closed) Base URL: https://skia.googlesource.com/skia.git@cscleanup
Patch Set: Fix logic Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/codec/SkJpegCodec.cpp ('k') | tests/ColorSpaceTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpace.cpp
diff --git a/src/core/SkColorSpace.cpp b/src/core/SkColorSpace.cpp
index 3874f0e7d0d139b5204c77bcb568307f1a7e372d..e7bd4e8111e9f1c727dc2964354349003beb3d72 100644
--- a/src/core/SkColorSpace.cpp
+++ b/src/core/SkColorSpace.cpp
@@ -316,6 +316,51 @@ sk_sp<SkColorSpace> SkColorSpace::Deserialize(const void* data, size_t length) {
return NewICC(data, profileSize);
}
+bool SkColorSpace::Equals(const SkColorSpace* src, const SkColorSpace* dst) {
+ if (src == dst) {
+ return true;
+ }
+
+ if (!src || !dst) {
+ return false;
+ }
+
+ switch (src->fNamed) {
+ case kSRGB_Named:
+ case kAdobeRGB_Named:
+ return src->fNamed == dst->fNamed;
+ case kUnknown_Named:
+ if (kUnknown_Named != dst->fNamed) {
+ return false;
+ }
+ break;
+ }
+
+ SkData* srcData = as_CSB(src)->fProfileData.get();
+ SkData* dstData = as_CSB(dst)->fProfileData.get();
+ if (srcData || dstData) {
+ if (srcData && dstData) {
+ return srcData->size() == dstData->size() &&
+ 0 == memcmp(srcData->data(), dstData->data(), srcData->size());
+ }
+
+ return false;
+ }
+
+ // It's important to check fProfileData before named gammas. Some profiles may have named
+ // gammas, but also include other wacky features that cause us to save the data.
+ switch (src->fGammaNamed) {
+ case kSRGB_GammaNamed:
+ case k2Dot2Curve_GammaNamed:
+ case kLinear_GammaNamed:
+ return (src->fGammaNamed == dst->fGammaNamed) && (src->fToXYZD50 == dst->fToXYZD50);
+ default:
+ // If |src| does not have a named gamma, fProfileData should be non-null.
+ SkASSERT(false);
+ return false;
+ }
+}
+
bool SkColorSpace::gammasAreMatching() const {
const SkGammas* gammas = as_CSB(this)->gammas();
SkASSERT(gammas);
« no previous file with comments | « src/codec/SkJpegCodec.cpp ('k') | tests/ColorSpaceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698