SkMorphologyImageFilter.h revision cac5fd597f6e2495f50aaa6bcbe3dadc56f0b977
1/* 2 * Copyright 2012 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 9#ifndef SkMorphologyImageFilter_DEFINED 10#define SkMorphologyImageFilter_DEFINED 11 12#include "SkColor.h" 13#include "SkImageFilter.h" 14#include "SkSize.h" 15 16class SK_API SkMorphologyImageFilter : public SkImageFilter { 17public: 18 virtual void computeFastBounds(const SkRect& src, SkRect* dst) const SK_OVERRIDE; 19 virtual bool onFilterBounds(const SkIRect& src, const SkMatrix& ctm, SkIRect* dst) const SK_OVERRIDE; 20 21 /** 22 * All morphology procs have the same signature: src is the source buffer, dst the 23 * destination buffer, radius is the morphology radius, width and height are the bounds 24 * of the destination buffer (in pixels), and srcStride and dstStride are the 25 * number of pixels per row in each buffer. All buffers are 8888. 26 */ 27 28 typedef void (*Proc)(const SkPMColor* src, SkPMColor* dst, int radius, 29 int width, int height, int srcStride, int dstStride); 30 31protected: 32 SkMorphologyImageFilter(int radiusX, int radiusY, SkImageFilter* input, 33 const CropRect* cropRect); 34 bool filterImageGeneric(Proc procX, Proc procY, 35 Proxy*, const SkBitmap& src, const SkMatrix&, 36 SkBitmap* result, SkIPoint* offset) const; 37 SkMorphologyImageFilter(SkReadBuffer& buffer); 38 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; 39#if SK_SUPPORT_GPU 40 virtual bool canFilterImageGPU() const SK_OVERRIDE { return true; } 41 bool filterImageGPUGeneric(bool dilate, Proxy* proxy, const SkBitmap& src, 42 const SkMatrix& ctm, SkBitmap* result, 43 SkIPoint* offset) const; 44#endif 45 46 SkISize radius() const { return fRadius; } 47 48private: 49 SkISize fRadius; 50 typedef SkImageFilter INHERITED; 51}; 52 53class SK_API SkDilateImageFilter : public SkMorphologyImageFilter { 54public: 55 static SkDilateImageFilter* Create(int radiusX, int radiusY, 56 SkImageFilter* input = NULL, 57 const CropRect* cropRect = NULL) { 58 return SkNEW_ARGS(SkDilateImageFilter, (radiusX, radiusY, input, cropRect)); 59 } 60 61 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, 62 SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE; 63#if SK_SUPPORT_GPU 64 virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, 65 SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE; 66#endif 67 68 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDilateImageFilter) 69 70protected: 71 SkDilateImageFilter(SkReadBuffer& buffer) : INHERITED(buffer) {} 72 73#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS 74public: 75#endif 76 SkDilateImageFilter(int radiusX, int radiusY, 77 SkImageFilter* input = NULL, 78 const CropRect* cropRect = NULL) 79 : INHERITED(radiusX, radiusY, input, cropRect) {} 80 81private: 82 typedef SkMorphologyImageFilter INHERITED; 83}; 84 85class SK_API SkErodeImageFilter : public SkMorphologyImageFilter { 86public: 87 static SkErodeImageFilter* Create(int radiusX, int radiusY, 88 SkImageFilter* input = NULL, 89 const CropRect* cropRect = NULL) { 90 return SkNEW_ARGS(SkErodeImageFilter, (radiusX, radiusY, input, cropRect)); 91 } 92 93 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const SkMatrix&, 94 SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE; 95#if SK_SUPPORT_GPU 96 virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, 97 SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE; 98#endif 99 100 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkErodeImageFilter) 101 102protected: 103 SkErodeImageFilter(SkReadBuffer& buffer) : INHERITED(buffer) {} 104 105#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS 106public: 107#endif 108 SkErodeImageFilter(int radiusX, int radiusY, 109 SkImageFilter* input = NULL, 110 const CropRect* cropRect = NULL) 111 : INHERITED(radiusX, radiusY, input, cropRect) {} 112 113private: 114 typedef SkMorphologyImageFilter INHERITED; 115}; 116 117#endif 118