Home | History | Annotate | Download | only in effects
      1 
      2 /*
      3  * Copyright 2006 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkTableMaskFilter_DEFINED
     11 #define SkTableMaskFilter_DEFINED
     12 
     13 #include "SkMaskFilter.h"
     14 #include "SkScalar.h"
     15 
     16 /** \class SkTableMaskFilter
     17 
     18     Applies a table lookup on each of the alpha values in the mask.
     19     Helper methods create some common tables (e.g. gamma, clipping)
     20  */
     21 class SkTableMaskFilter : public SkMaskFilter {
     22 public:
     23     SkTableMaskFilter();
     24     SkTableMaskFilter(const uint8_t table[256]);
     25     virtual ~SkTableMaskFilter();
     26 
     27     void setTable(const uint8_t table[256]);
     28 
     29     /** Utility that sets the gamma table
     30      */
     31     static void MakeGammaTable(uint8_t table[256], SkScalar gamma);
     32 
     33     /** Utility that creates a clipping table: clamps values below min to 0
     34         and above max to 255, and rescales the remaining into 0..255
     35      */
     36     static void MakeClipTable(uint8_t table[256], uint8_t min, uint8_t max);
     37 
     38     static SkTableMaskFilter* CreateGamma(SkScalar gamma) {
     39         uint8_t table[256];
     40         MakeGammaTable(table, gamma);
     41         return SkNEW_ARGS(SkTableMaskFilter, (table));
     42     }
     43 
     44     static SkTableMaskFilter* CreateClip(uint8_t min, uint8_t max) {
     45         uint8_t table[256];
     46         MakeClipTable(table, min, max);
     47         return SkNEW_ARGS(SkTableMaskFilter, (table));
     48     }
     49 
     50     // overrides from SkMaskFilter
     51     virtual SkMask::Format getFormat();
     52     virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*);
     53 
     54     // overrides from SkFlattenable
     55     virtual void flatten(SkFlattenableWriteBuffer& wb);
     56     virtual Factory getFactory();
     57 
     58 protected:
     59     SkTableMaskFilter(SkFlattenableReadBuffer& rb);
     60     static SkFlattenable* Factory(SkFlattenableReadBuffer&);
     61 
     62 private:
     63     uint8_t fTable[256];
     64 
     65     typedef SkMaskFilter INHERITED;
     66 };
     67 
     68 #endif
     69 
     70