From eaa77979908d1b9fff00b73d02c4576901448933 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Fri, 23 Aug 2013 13:13:12 +0000 Subject: Add luminance mask transfer modes. This adds kSrcInLum_Mode and kDstInLum_Mode, to support CSS and SVG luminance masks (http://www.w3.org/TR/css-masking/#MaskValues , http://www.w3.org/TR/SVG/masking.html#Masking ). The transfer coefficient is computed according to http://www.w3.org/TR/2011/REC-SVG11-20110816/filters.html#feColorMatrixElement "luminance-to-alpha": luma = 0.2125 * r + 0.7154 * g + 0.0721 * b R=bsalomon@google.com, reed@google.com, robertphillips@google.com, vandebo@chromium.org Author: fmalita@chromium.org Review URL: https://chromiumcodereview.appspot.com/22918012 git-svn-id: http://skia.googlecode.com/svn/trunk@10887 2bbb7eff-a529-9590-31e7-b0007b416f81 --- include/effects/SkLumaXfermode.h | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 include/effects/SkLumaXfermode.h (limited to 'include/effects') diff --git a/include/effects/SkLumaXfermode.h b/include/effects/SkLumaXfermode.h new file mode 100644 index 0000000000..5bcd10eff1 --- /dev/null +++ b/include/effects/SkLumaXfermode.h @@ -0,0 +1,58 @@ +/* + * Copyright 2013 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkLumaXfermode_DEFINED +#define SkLumaXfermode_DEFINED + +#include "SkXfermode.h" + +/** + * Luminance mask transfer, as defined in + * http://www.w3.org/TR/SVG/masking.html#Masking + * http://www.w3.org/TR/css-masking/#MaskValues + * + * The luminance-to-alpha function is applied before performing a standard + * SrcIn/DstIn xfer: + * + * luma(C) = (0.2125 * C.r + 0.7154 * C.g + 0.0721 * C.b) * C.a + * + * (where C is un-premultiplied) + */ +class SK_API SkLumaMaskXfermode : public SkXfermode { +public: + /** Return an SkLumaMaskXfermode object for the specified submode. + * + * Only kSrcIn_Mode and kDstIn_Mode are supported - for everything else, + * the factory returns NULL. + */ + static SkXfermode* Create(SkXfermode::Mode); + + virtual SkPMColor xferColor(SkPMColor, SkPMColor) const SK_OVERRIDE; + virtual void xfer32(SkPMColor dst[], const SkPMColor src[], int count, + const SkAlpha aa[]) const SK_OVERRIDE; + + SK_DEVELOPER_TO_STRING() + SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLumaMaskXfermode) + +#if SK_SUPPORT_GPU + virtual bool asNewEffectOrCoeff(GrContext*, GrEffectRef**, Coeff*, Coeff*, + GrTexture*) const SK_OVERRIDE; +#endif + +protected: + SkLumaMaskXfermode(SkFlattenableReadBuffer&); + virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE; + +private: + SkLumaMaskXfermode(SkXfermode::Mode); + + const SkXfermode::Mode fMode; + + typedef SkXfermode INHERITED; +}; + +#endif -- cgit v1.2.3