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