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

Unified Diff: src/effects/SkColorFilters.cpp

Issue 151353005: remove legacy LightingColorFilter impl (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 | « no previous file | no next file » | 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 d947bbc1ad80b11f550a515b242f94710366716a..ab32bc66363b7da18593df772958c940c2bfc978 100644
--- a/src/effects/SkColorFilters.cpp
+++ b/src/effects/SkColorFilters.cpp
@@ -15,9 +15,6 @@
#include "SkValidationUtils.h"
#include "SkColorMatrixFilter.h"
-#define SK_MAP_LIGHTINGCOLORFILTER_TO_COLORMATRIX
-
-
#define ILLEGAL_XFERMODE_MODE ((SkXfermode::Mode)-1)
// baseclass for filters that store a color and mode
@@ -541,8 +538,6 @@ 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
@@ -552,279 +547,7 @@ static SkScalar byte_to_scale(U8CPU byte) {
}
}
-#else
-
-static inline unsigned pin(unsigned value, unsigned max) {
- if (value > max) {
- value = max;
- }
- return value;
-}
-
-class SkLightingColorFilter : public SkColorFilter {
-public:
- SkLightingColorFilter(SkColor mul, SkColor add) : fMul(mul), fAdd(add) {}
-
- virtual void filterSpan(const SkPMColor shader[], int count,
- SkPMColor result[]) const SK_OVERRIDE {
- unsigned scaleR = SkAlpha255To256(SkColorGetR(fMul));
- unsigned scaleG = SkAlpha255To256(SkColorGetG(fMul));
- unsigned scaleB = SkAlpha255To256(SkColorGetB(fMul));
-
- unsigned addR = SkColorGetR(fAdd);
- unsigned addG = SkColorGetG(fAdd);
- unsigned addB = SkColorGetB(fAdd);
-
- for (int i = 0; i < count; i++) {
- SkPMColor c = shader[i];
- if (c) {
- unsigned a = SkGetPackedA32(c);
- unsigned scaleA = SkAlpha255To256(a);
- unsigned r = pin(SkAlphaMul(SkGetPackedR32(c), scaleR) + SkAlphaMul(addR, scaleA), a);
- unsigned g = pin(SkAlphaMul(SkGetPackedG32(c), scaleG) + SkAlphaMul(addG, scaleA), a);
- unsigned b = pin(SkAlphaMul(SkGetPackedB32(c), scaleB) + SkAlphaMul(addB, scaleA), a);
- c = SkPackARGB32(a, r, g, b);
- }
- result[i] = c;
- }
- }
-
-#ifdef SK_DEVELOPER
- virtual void toString(SkString* str) const SK_OVERRIDE {
- str->append("SkLightingColorFilter: mul: 0x");
- str->appendHex(fMul);
- str->append(" add: 0x");
- str->appendHex(fAdd);
- }
-#endif
-
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingColorFilter)
-
-protected:
- virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE {
- this->INHERITED::flatten(buffer);
- buffer.writeColor(fMul);
- buffer.writeColor(fAdd);
- }
-
- SkLightingColorFilter(SkReadBuffer& buffer) {
- fMul = buffer.readColor();
- fAdd = buffer.readColor();
- }
-
- SkColor fMul, fAdd;
-
-private:
- typedef SkColorFilter INHERITED;
-};
-
-class SkLightingColorFilter_JustAdd : public SkLightingColorFilter {
-public:
- SkLightingColorFilter_JustAdd(SkColor mul, SkColor add)
- : INHERITED(mul, add) {}
-
- virtual void filterSpan(const SkPMColor shader[], int count,
- SkPMColor result[]) const SK_OVERRIDE {
- unsigned addR = SkColorGetR(fAdd);
- unsigned addG = SkColorGetG(fAdd);
- unsigned addB = SkColorGetB(fAdd);
-
- for (int i = 0; i < count; i++) {
- SkPMColor c = shader[i];
- if (c) {
- unsigned a = SkGetPackedA32(c);
- unsigned scaleA = SkAlpha255To256(a);
- unsigned r = pin(SkGetPackedR32(c) + SkAlphaMul(addR, scaleA), a);
- unsigned g = pin(SkGetPackedG32(c) + SkAlphaMul(addG, scaleA), a);
- unsigned b = pin(SkGetPackedB32(c) + SkAlphaMul(addB, scaleA), a);
- c = SkPackARGB32(a, r, g, b);
- }
- result[i] = c;
- }
- }
-
-#ifdef SK_DEVELOPER
- virtual void toString(SkString* str) const SK_OVERRIDE {
- str->append("SkLightingColorFilter_JustAdd: add: 0x");
- str->appendHex(fAdd);
- }
-#endif
-
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingColorFilter_JustAdd)
-
-protected:
- SkLightingColorFilter_JustAdd(SkReadBuffer& buffer)
- : INHERITED(buffer) {}
-
-private:
- typedef SkLightingColorFilter INHERITED;
-};
-
-class SkLightingColorFilter_JustMul : public SkLightingColorFilter {
-public:
- SkLightingColorFilter_JustMul(SkColor mul, SkColor add)
- : INHERITED(mul, add) {}
-
- virtual void filterSpan(const SkPMColor shader[], int count,
- SkPMColor result[]) const SK_OVERRIDE {
- unsigned scaleR = SkAlpha255To256(SkColorGetR(fMul));
- unsigned scaleG = SkAlpha255To256(SkColorGetG(fMul));
- unsigned scaleB = SkAlpha255To256(SkColorGetB(fMul));
-
- for (int i = 0; i < count; i++) {
- SkPMColor c = shader[i];
- if (c) {
- unsigned a = SkGetPackedA32(c);
- unsigned r = SkAlphaMul(SkGetPackedR32(c), scaleR);
- unsigned g = SkAlphaMul(SkGetPackedG32(c), scaleG);
- unsigned b = SkAlphaMul(SkGetPackedB32(c), scaleB);
- c = SkPackARGB32(a, r, g, b);
- }
- result[i] = c;
- }
- }
-
-#ifdef SK_DEVELOPER
- virtual void toString(SkString* str) const SK_OVERRIDE {
- str->append("SkLightingColorFilter_JustMul: mul: 0x");
- str->appendHex(fMul);
- }
-#endif
-
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingColorFilter_JustMul)
-
-protected:
- SkLightingColorFilter_JustMul(SkReadBuffer& buffer)
- : INHERITED(buffer) {}
-
-private:
- typedef SkLightingColorFilter INHERITED;
-};
-
-class SkLightingColorFilter_SingleMul : public SkLightingColorFilter {
-public:
- SkLightingColorFilter_SingleMul(SkColor mul, SkColor add)
- : INHERITED(mul, add) {
- SkASSERT(SkColorGetR(add) == 0);
- SkASSERT(SkColorGetG(add) == 0);
- SkASSERT(SkColorGetB(add) == 0);
- SkASSERT(SkColorGetR(mul) == SkColorGetG(mul));
- SkASSERT(SkColorGetR(mul) == SkColorGetB(mul));
- }
-
- virtual uint32_t getFlags() const SK_OVERRIDE {
- return this->INHERITED::getFlags() | (kAlphaUnchanged_Flag | kHasFilter16_Flag);
- }
-
- virtual void filterSpan16(const uint16_t shader[], int count,
- uint16_t result[]) const SK_OVERRIDE {
- // all mul components are the same
- unsigned scale = SkAlpha255To256(SkColorGetR(fMul));
-
- if (count > 0) {
- do {
- *result++ = SkAlphaMulRGB16(*shader++, scale);
- } while (--count > 0);
- }
- }
-
-#ifdef SK_DEVELOPER
- virtual void toString(SkString* str) const SK_OVERRIDE {
- str->append("SkLightingColorFilter_SingleMul: mul: 0x");
- str->appendHex(fMul);
- }
-#endif
-
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingColorFilter_SingleMul)
-
-protected:
- SkLightingColorFilter_SingleMul(SkReadBuffer& buffer)
- : INHERITED(buffer) {}
-
-private:
- typedef SkLightingColorFilter INHERITED;
-};
-
-class SkLightingColorFilter_NoPin : public SkLightingColorFilter {
-public:
- SkLightingColorFilter_NoPin(SkColor mul, SkColor add)
- : INHERITED(mul, add) {}
-
- virtual void filterSpan(const SkPMColor shader[], int count,
- SkPMColor result[]) const SK_OVERRIDE {
- unsigned scaleR = SkAlpha255To256(SkColorGetR(fMul));
- unsigned scaleG = SkAlpha255To256(SkColorGetG(fMul));
- unsigned scaleB = SkAlpha255To256(SkColorGetB(fMul));
-
- unsigned addR = SkColorGetR(fAdd);
- unsigned addG = SkColorGetG(fAdd);
- unsigned addB = SkColorGetB(fAdd);
-
- for (int i = 0; i < count; i++) {
- SkPMColor c = shader[i];
- if (c) {
- unsigned a = SkGetPackedA32(c);
- unsigned scaleA = SkAlpha255To256(a);
- unsigned r = SkAlphaMul(SkGetPackedR32(c), scaleR) + SkAlphaMul(addR, scaleA);
- unsigned g = SkAlphaMul(SkGetPackedG32(c), scaleG) + SkAlphaMul(addG, scaleA);
- unsigned b = SkAlphaMul(SkGetPackedB32(c), scaleB) + SkAlphaMul(addB, scaleA);
- c = SkPackARGB32(a, r, g, b);
- }
- result[i] = c;
- }
- }
-
-#ifdef SK_DEVELOPER
- virtual void toString(SkString* str) const SK_OVERRIDE {
- str->append("SkLightingColorFilter_NoPin: mul: 0x");
- str->appendHex(fMul);
- str->append(" add: 0x");
- str->appendHex(fAdd);
- }
-#endif
-
- SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLightingColorFilter_NoPin)
-
-protected:
- SkLightingColorFilter_NoPin(SkReadBuffer& buffer)
- : INHERITED(buffer) {}
-
-private:
- typedef SkLightingColorFilter INHERITED;
-};
-
-class SkSimpleColorFilter : public SkColorFilter {
-public:
- static SkFlattenable* CreateProc(SkReadBuffer& buffer) {
- return SkNEW(SkSimpleColorFilter);
- }
-
-#ifdef SK_DEVELOPER
- virtual void toString(SkString* str) const SK_OVERRIDE {
- str->append("SkSimpleColorFilter");
- }
-#endif
-
-protected:
- void filterSpan(const SkPMColor src[], int count, SkPMColor
- result[]) const SK_OVERRIDE {
- if (result != src) {
- memcpy(result, src, count * sizeof(SkPMColor));
- }
- }
-
- virtual void flatten(SkWriteBuffer& buffer) const SK_OVERRIDE {}
-
- virtual Factory getFactory() const {
- return CreateProc;
- }
-
-};
-
-#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)),
@@ -835,47 +558,10 @@ SkColorFilter* SkColorFilter::CreateLightingFilter(SkColor mul, SkColor add) {
SkIntToScalar(SkColorGetB(add)),
0);
return SkNEW_ARGS(SkColorMatrixFilter, (matrix));
-#else
- mul &= 0x00FFFFFF;
- add &= 0x00FFFFFF;
-
- if (0xFFFFFF == mul) {
- if (0 == add) {
- return SkNEW(SkSimpleColorFilter); // no change to the colors
- } else {
- return SkNEW_ARGS(SkLightingColorFilter_JustAdd, (mul, add));
- }
- }
-
- if (0 == add) {
- if (SkColorGetR(mul) == SkColorGetG(mul) &&
- SkColorGetR(mul) == SkColorGetB(mul)) {
- return SkNEW_ARGS(SkLightingColorFilter_SingleMul, (mul, add));
- } else {
- return SkNEW_ARGS(SkLightingColorFilter_JustMul, (mul, add));
- }
- }
-
- if (SkColorGetR(mul) + SkColorGetR(add) <= 255 &&
- SkColorGetG(mul) + SkColorGetG(add) <= 255 &&
- SkColorGetB(mul) + SkColorGetB(add) <= 255) {
- return SkNEW_ARGS(SkLightingColorFilter_NoPin, (mul, 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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698