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

Unified Diff: src/effects/SkLumaColorFilter.cpp

Issue 26467003: Align SkLumaColorFilter with the spec. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Use kRGB_GrColorComponentFlags. Created 7 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 | « include/effects/SkLumaColorFilter.h ('k') | tests/ColorFilterTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkLumaColorFilter.cpp
diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp
index c9f1fb02c3a17d49c841ee69dcf38a6f29d75541..82089ba6bf8189634f3ab3ae9112d23906779f3e 100644
--- a/src/effects/SkLumaColorFilter.cpp
+++ b/src/effects/SkLumaColorFilter.cpp
@@ -9,7 +9,6 @@
#include "SkColorPriv.h"
#include "SkString.h"
-#include "SkUnPreMultiply.h"
#if SK_SUPPORT_GPU
#include "gl/GrGLEffect.h"
@@ -19,44 +18,21 @@
void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count,
SkPMColor dst[]) const {
- const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();
-
for (int i = 0; i < count; ++i) {
SkPMColor c = src[i];
- unsigned r = SkGetPackedR32(c);
- unsigned g = SkGetPackedG32(c);
- unsigned b = SkGetPackedB32(c);
- unsigned a = SkGetPackedA32(c);
-
- // No need to do anything for white (luminance == 1.0)
- if (a != r || a != g || a != b) {
- /*
- * To avoid un-premultiplying multiple components, we can start
- * with the luminance computed in PM space:
- *
- * Lum = i * (r / a) + j * (g / a) + k * (b / a)
- * Lum = (i * r + j * g + k * b) / a
- * Lum = Lum'(PM) / a
- *
- * Then the filter function is:
- *
- * C' = [ Lum * a, Lum * r, Lum * g, Lum * b ]
- *
- * which is equivalent to:
- *
- * C' = [ Lum'(PM), Lum * r, Lum * g, Lum * b ]
- */
- unsigned pm_lum = SkComputeLuminance(r, g, b);
- unsigned lum = SkUnPreMultiply::ApplyScale(table[a], pm_lum);
-
- c = SkPackARGB32(pm_lum,
- SkMulDiv255Round(r, lum),
- SkMulDiv255Round(g, lum),
- SkMulDiv255Round(b, lum));
- }
-
- dst[i] = c;
+ /*
+ * While LuminanceToAlpha is defined to operate on un-premultiplied
+ * inputs, due to the final alpha scaling it can be computed based on
+ * premultipled components:
+ *
+ * LumA = (k1 * r / a + k2 * g / a + k3 * b / a) * a
+ * LumA = (k1 * r + k2 * g + k3 * b)
+ */
+ unsigned luma = SkComputeLuminance(SkGetPackedR32(c),
+ SkGetPackedG32(c),
+ SkGetPackedB32(c));
+ dst[i] = SkPackARGB32(luma, 0, 0, 0);
}
}
@@ -97,7 +73,9 @@ public:
virtual void getConstantColorComponents(GrColor* color,
uint32_t* validFlags) const SK_OVERRIDE {
- *validFlags = 0;
+ // The output is always black.
+ *color = GrColorPackRGBA(0, 0, 0, GrColorUnpackA(*color));
+ *validFlags = kRGB_GrColorComponentFlags;
}
class GLEffect : public GrGLEffect {
@@ -123,16 +101,13 @@ public:
inputColor = GrGLSLOnesVecf(4);
}
- // The max() is to guard against 0 / 0 during unpremul when the incoming color is
- // transparent black.
- builder->fsCodeAppendf("\tfloat nonZeroAlpha = max(%s.a, 0.00001);\n", inputColor);
builder->fsCodeAppendf("\tfloat luma = dot(vec3(%f, %f, %f), %s.rgb);\n",
SK_ITU_BT709_LUM_COEFF_R,
SK_ITU_BT709_LUM_COEFF_G,
SK_ITU_BT709_LUM_COEFF_B,
inputColor);
- builder->fsCodeAppendf("\t%s = vec4(%s.rgb * luma / nonZeroAlpha, luma);\n",
- outputColor, inputColor);
+ builder->fsCodeAppendf("\t%s = vec4(0, 0, 0, luma);\n",
+ outputColor);
}
« no previous file with comments | « include/effects/SkLumaColorFilter.h ('k') | tests/ColorFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698