Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2008 The Android Open Source Project
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkKernel33MaskFilter_DEFINED
      9 #define SkKernel33MaskFilter_DEFINED
     10 
     11 #include "SkMaskFilter.h"
     12 
     13 class SK_API SkKernel33ProcMaskFilter : public SkMaskFilter {
     14 public:
     15     SkKernel33ProcMaskFilter(unsigned percent256 = 256)
     16         : fPercent256(percent256) {}
     17 
     18     virtual uint8_t computeValue(uint8_t* const* srcRows) const = 0;
     19 
     20     virtual SkMask::Format getFormat() const SK_OVERRIDE;
     21     virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&,
     22                             SkIPoint*) const SK_OVERRIDE;
     23 
     24     SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     25 
     26 protected:
     27     SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb);
     28     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
     29 
     30 private:
     31     int fPercent256;
     32 
     33     typedef SkMaskFilter INHERITED;
     34 };
     35 
     36 ///////////////////////////////////////////////////////////////////////////////
     37 
     38 class SK_API SkKernel33MaskFilter : public SkKernel33ProcMaskFilter {
     39 public:
     40     SkKernel33MaskFilter(const int coeff[3][3], int shift, int percent256 = 256)
     41             : SkKernel33ProcMaskFilter(percent256) {
     42         memcpy(fKernel, coeff, 9 * sizeof(int));
     43         fShift = shift;
     44     }
     45 
     46     // override from SkKernel33ProcMaskFilter
     47     virtual uint8_t computeValue(uint8_t* const* srcRows) const SK_OVERRIDE;
     48 
     49     SkDEVCODE(virtual void toString(SkString* str) const SK_OVERRIDE;)
     50     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkKernel33MaskFilter)
     51 
     52 private:
     53     int fKernel[3][3];
     54     int fShift;
     55 
     56     SkKernel33MaskFilter(SkFlattenableReadBuffer& rb);
     57     virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
     58 
     59     typedef SkKernel33ProcMaskFilter INHERITED;
     60 };
     61 
     62 #endif
     63