00001 /* 00002 * Copyright (C) 2008 The Android Open Source Project 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef SkKernel33MaskFilter_DEFINED 00018 #define SkKernel33MaskFilter_DEFINED 00019 00020 #include "SkMaskFilter.h" 00021 00022 class SkKernel33ProcMaskFilter : public SkMaskFilter { 00023 public: 00024 SkKernel33ProcMaskFilter(unsigned percent256 = 256) 00025 : fPercent256(percent256) {} 00026 00027 virtual uint8_t computeValue(uint8_t* const* srcRows) = 0; 00028 00029 // overrides from SkMaskFilter 00030 virtual SkMask::Format getFormat(); 00031 virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*); 00032 00033 // overrides from SkFlattenable 00034 virtual void flatten(SkFlattenableWriteBuffer& wb); 00035 00036 protected: 00037 SkKernel33ProcMaskFilter(SkFlattenableReadBuffer& rb); 00038 00039 private: 00040 int fPercent256; 00041 00042 typedef SkMaskFilter INHERITED; 00043 }; 00044 00046 00047 class SkKernel33MaskFilter : public SkKernel33ProcMaskFilter { 00048 public: 00049 SkKernel33MaskFilter(const int coeff[3][3], int shift, int percent256 = 256) 00050 : SkKernel33ProcMaskFilter(percent256) 00051 { 00052 memcpy(fKernel, coeff, 9 * sizeof(int)); 00053 fShift = shift; 00054 } 00055 00056 // override from SkKernel33ProcMaskFilter 00057 virtual uint8_t computeValue(uint8_t* const* srcRows); 00058 00059 // overrides from SkFlattenable 00060 virtual void flatten(SkFlattenableWriteBuffer& wb); 00061 virtual Factory getFactory(); 00062 00063 private: 00064 int fKernel[3][3]; 00065 int fShift; 00066 00067 SkKernel33MaskFilter(SkFlattenableReadBuffer& rb); 00068 static SkFlattenable* Create(SkFlattenableReadBuffer& rb); 00069 00070 typedef SkKernel33ProcMaskFilter INHERITED; 00071 }; 00072 00073 #endif