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

Unified Diff: src/effects/SkColorFilters.cpp

Issue 135123008: replace impl of SkLightingColorFilter with SkColorMatrixFilter (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 10 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 | « include/effects/SkColorMatrix.h ('k') | src/effects/SkColorMatrix.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkColorFilters.cpp
diff --git a/src/effects/SkColorFilters.cpp b/src/effects/SkColorFilters.cpp
index f9fa1fd82bfa16f53053cbeaf9f7759bd8012060..d947bbc1ad80b11f550a515b242f94710366716a 100644
--- a/src/effects/SkColorFilters.cpp
+++ b/src/effects/SkColorFilters.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -6,7 +5,6 @@
* found in the LICENSE file.
*/
-
#include "SkBlitRow.h"
#include "SkColorFilter.h"
#include "SkColorPriv.h"
@@ -15,6 +13,10 @@
#include "SkUtils.h"
#include "SkString.h"
#include "SkValidationUtils.h"
+#include "SkColorMatrixFilter.h"
+
+#define SK_MAP_LIGHTINGCOLORFILTER_TO_COLORMATRIX
+
#define ILLEGAL_XFERMODE_MODE ((SkXfermode::Mode)-1)
@@ -539,6 +541,19 @@ SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color,
///////////////////////////////////////////////////////////////////////////////
+#ifdef SK_MAP_LIGHTINGCOLORFILTER_TO_COLORMATRIX
+
+static SkScalar byte_to_scale(U8CPU byte) {
+ if (0xFF == byte) {
+ // want to get this exact
+ return 1;
+ } else {
+ return byte * 0.00392156862745f;
+ }
+}
+
+#else
+
static inline unsigned pin(unsigned value, unsigned max) {
if (value > max) {
value = max;
@@ -778,8 +793,6 @@ private:
typedef SkLightingColorFilter INHERITED;
};
-///////////////////////////////////////////////////////////////////////////////
-
class SkSimpleColorFilter : public SkColorFilter {
public:
static SkFlattenable* CreateProc(SkReadBuffer& buffer) {
@@ -808,7 +821,21 @@ protected:
};
+#endif // SK_MAP_LIGHTINGCOLORFILTER_TO_COLORMATRIX
+
SkColorFilter* SkColorFilter::CreateLightingFilter(SkColor mul, SkColor add) {
+#ifdef SK_MAP_LIGHTINGCOLORFILTER_TO_COLORMATRIX
+ SkColorMatrix matrix;
+ matrix.setScale(byte_to_scale(SkColorGetR(mul)),
+ byte_to_scale(SkColorGetG(mul)),
+ byte_to_scale(SkColorGetB(mul)),
+ 1);
+ matrix.postTranslate(SkIntToScalar(SkColorGetR(add)),
+ SkIntToScalar(SkColorGetG(add)),
+ SkIntToScalar(SkColorGetB(add)),
+ 0);
+ return SkNEW_ARGS(SkColorMatrixFilter, (matrix));
+#else
mul &= 0x00FFFFFF;
add &= 0x00FFFFFF;
@@ -836,16 +863,19 @@ SkColorFilter* SkColorFilter::CreateLightingFilter(SkColor mul, SkColor add) {
}
return SkNEW_ARGS(SkLightingColorFilter, (mul, add));
+#endif
}
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkColorFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkModeColorFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(Src_SkModeColorFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SrcOver_SkModeColorFilter)
+#ifndef SK_MAP_LIGHTINGCOLORFILTER_TO_COLORMATRIX
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingColorFilter)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingColorFilter_JustAdd)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingColorFilter_JustMul)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingColorFilter_SingleMul)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkLightingColorFilter_NoPin)
SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkSimpleColorFilter)
+#endif
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
« no previous file with comments | « include/effects/SkColorMatrix.h ('k') | src/effects/SkColorMatrix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698