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

Unified Diff: src/core/SkColorSpaceXform.cpp

Issue 2413383002: Cache dst LUTs in SkColorSpaceXform (Closed)
Patch Set: Ref the storage on SkColorSpaceXform Created 4 years, 2 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/core/SkColorSpace.cpp ('k') | src/core/SkColorSpaceXform_Base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkColorSpaceXform.cpp
diff --git a/src/core/SkColorSpaceXform.cpp b/src/core/SkColorSpaceXform.cpp
index 50cd9c11e5f0b1ecaf281480d3e57c26148266f7..5e362464b41d5d9470a9795a2eea9e5e23601bf5 100644
--- a/src/core/SkColorSpaceXform.cpp
+++ b/src/core/SkColorSpaceXform.cpp
@@ -138,9 +138,7 @@ static uint8_t clamp_normalized_float_to_byte(float v) {
}
}
-static const int kDstGammaTableSize =
- SkColorSpaceXform_Base<kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch>
- ::kDstGammaTableSize;
+static const int kDstGammaTableSize = SkColorSpaceXform_Base::kDstGammaTableSize;
static void build_table_linear_to_gamma(uint8_t* outTable, float exponent) {
float toGammaExp = 1.0f / exponent;
@@ -256,7 +254,8 @@ static const GammaFns<uint8_t> kFromLinear {
// Build tables to transform src gamma to linear.
template <typename T>
static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage, int gammaTableSize,
- SkColorSpace* space, const GammaFns<T>& fns, bool gammasAreMatching)
+ const SkColorSpace* space, const GammaFns<T>& fns,
+ bool gammasAreMatching)
{
switch (as_CSB(space)->gammaNamed()) {
case kSRGB_SkGammaNamed:
@@ -326,6 +325,13 @@ static void build_gamma_tables(const T* outGammaTables[3], T* gammaTableStorage,
}
}
+void SkColorSpaceXform_Base::BuildDstGammaTables(const uint8_t* dstGammaTables[3],
+ uint8_t* dstStorage, const SkColorSpace* space,
+ bool gammasAreMatching) {
+ build_gamma_tables(dstGammaTables, dstStorage, kDstGammaTableSize, space, kFromLinear,
+ gammasAreMatching);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
static inline bool is_almost_identity(const SkMatrix44& srcToDst) {
@@ -368,41 +374,41 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* srcSpace
switch (as_CSB(dstSpace)->gammaNamed()) {
case kSRGB_SkGammaNamed:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, kSRGB_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kSRGB_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
case k2Dot2Curve_SkGammaNamed:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, k2Dot2_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, k2Dot2_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
case kLinear_SkGammaNamed:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, kLinear_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kLinear_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
default:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
@@ -411,41 +417,41 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* srcSpace
switch (as_CSB(dstSpace)->gammaNamed()) {
case kSRGB_SkGammaNamed:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, kSRGB_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kSRGB_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
case k2Dot2Curve_SkGammaNamed:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, k2Dot2_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, k2Dot2_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
case kLinear_SkGammaNamed:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, kLinear_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kLinear_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
default:
if (srcSpace->gammaIsLinear()) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, kTable_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
} else {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kTable_DstGamma, kGamut_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
@@ -453,19 +459,19 @@ std::unique_ptr<SkColorSpaceXform> SkColorSpaceXform::New(SkColorSpace* srcSpace
case kFull_ColorSpaceMatch:
switch (as_CSB(dstSpace)->gammaNamed()) {
case kSRGB_SkGammaNamed:
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kSRGB_DstGamma, kFull_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
case k2Dot2Curve_SkGammaNamed:
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, k2Dot2_DstGamma, kFull_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
case kLinear_SkGammaNamed:
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kLinear_SrcGamma, kLinear_DstGamma, kFull_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
default:
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kTable_DstGamma, kFull_ColorSpaceMatch>
(srcSpace, srcToDst, dstSpace));
}
@@ -1243,25 +1249,21 @@ static inline int num_tables(SkColorSpace* space) {
}
template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM>
-SkColorSpaceXform_Base<kSrc, kDst, kCSM>
-::SkColorSpaceXform_Base(SkColorSpace* srcSpace, const SkMatrix44& srcToDst, SkColorSpace* dstSpace)
+SkColorSpaceXform_XYZ<kSrc, kDst, kCSM>
+::SkColorSpaceXform_XYZ(SkColorSpace* srcSpace, const SkMatrix44& srcToDst, SkColorSpace* dstSpace)
: fColorLUT(sk_ref_sp((SkColorLookUpTable*) as_CSB(srcSpace)->colorLUT()))
{
srcToDst.asColMajorf(fSrcToDst);
const int numSrcTables = num_tables(srcSpace);
- const int numDstTables = num_tables(dstSpace);
- const size_t srcTableBytes = numSrcTables * 256 * sizeof(float);
- const size_t dstTableBytes = numDstTables * kDstGammaTableSize * sizeof(uint8_t);
- fStorage.reset(srcTableBytes + dstTableBytes);
- float* srcStorage = (float*) fStorage.get();
- uint8_t* dstStorage = SkTAddOffset<uint8_t>(fStorage.get(), srcTableBytes);
-
+ const size_t srcEntries = numSrcTables * 256;
const bool srcGammasAreMatching = (1 >= numSrcTables);
- const bool dstGammasAreMatching = (1 >= numDstTables);
- build_gamma_tables(fSrcGammaTables, srcStorage, 256, srcSpace, kToLinear, srcGammasAreMatching);
- build_gamma_tables(fDstGammaTables, dstStorage, kDstGammaTableSize, dstSpace, kFromLinear,
- dstGammasAreMatching);
+ fSrcStorage.reset(srcEntries);
+ build_gamma_tables(fSrcGammaTables, fSrcStorage.get(), 256, srcSpace, kToLinear,
+ srcGammasAreMatching);
+
+ const int numDstTables = num_tables(dstSpace);
+ as_CSB(dstSpace)->toDstGammaTables(fDstGammaTables, &fDstStorage, numDstTables);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1318,7 +1320,7 @@ static inline bool apply_set_src(void* dst, const void* src, int len, SkAlphaTyp
}
template <SrcGamma kSrc, DstGamma kDst, ColorSpaceMatch kCSM>
-bool SkColorSpaceXform_Base<kSrc, kDst, kCSM>
+bool SkColorSpaceXform_XYZ<kSrc, kDst, kCSM>
::onApply(ColorFormat dstColorFormat, void* dst, ColorFormat srcColorFormat, const void* src,
int len, SkAlphaType alphaType) const
{
@@ -1421,10 +1423,16 @@ bool SkColorSpaceXform_Base<kSrc, kDst, kCSM>
}
}
+bool SkColorSpaceXform::apply(ColorFormat dstColorFormat, void* dst, ColorFormat srcColorFormat,
+ const void* src, int len, SkAlphaType alphaType) const {
+ return ((SkColorSpaceXform_Base*) this)->onApply(dstColorFormat, dst, srcColorFormat, src, len,
+ alphaType);
+}
+
///////////////////////////////////////////////////////////////////////////////////////////////////
std::unique_ptr<SkColorSpaceXform> SlowIdentityXform(SkColorSpace* space) {
- return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_Base
+ return std::unique_ptr<SkColorSpaceXform>(new SkColorSpaceXform_XYZ
<kTable_SrcGamma, kTable_DstGamma, kNone_ColorSpaceMatch>
(space, SkMatrix::I(), space));
}
« no previous file with comments | « src/core/SkColorSpace.cpp ('k') | src/core/SkColorSpaceXform_Base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698