reed@android.com | 3f2025f | 2009-10-29 17:37:56 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2006 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef SkTableMaskFilter_DEFINED |
| 18 | #define SkTableMaskFilter_DEFINED |
| 19 | |
| 20 | #include "SkMaskFilter.h" |
| 21 | #include "SkScalar.h" |
| 22 | |
| 23 | /** \class SkTableMaskFilter |
| 24 | |
| 25 | Applies a table lookup on each of the alpha values in the mask. |
| 26 | Helper methods create some common tables (e.g. gamma, clipping) |
| 27 | */ |
| 28 | class SkTableMaskFilter : public SkMaskFilter { |
| 29 | public: |
| 30 | SkTableMaskFilter(); |
| 31 | SkTableMaskFilter(const uint8_t table[256]); |
| 32 | virtual ~SkTableMaskFilter(); |
| 33 | |
| 34 | void setTable(const uint8_t table[256]); |
| 35 | |
| 36 | /** Utility that sets the gamma table |
| 37 | */ |
| 38 | static void MakeGammaTable(uint8_t table[256], SkScalar gamma); |
| 39 | |
| 40 | /** Utility that creates a clipping table: clamps values below min to 0 |
| 41 | and above max to 255, and rescales the remaining into 0..255 |
| 42 | */ |
| 43 | static void MakeClipTable(uint8_t table[256], uint8_t min, uint8_t max); |
| 44 | |
| 45 | static SkTableMaskFilter* CreateGamma(SkScalar gamma) { |
| 46 | uint8_t table[256]; |
| 47 | MakeGammaTable(table, gamma); |
| 48 | return SkNEW_ARGS(SkTableMaskFilter, (table)); |
| 49 | } |
| 50 | |
| 51 | static SkTableMaskFilter* CreateClip(uint8_t min, uint8_t max) { |
| 52 | uint8_t table[256]; |
| 53 | MakeClipTable(table, min, max); |
| 54 | return SkNEW_ARGS(SkTableMaskFilter, (table)); |
| 55 | } |
| 56 | |
| 57 | // overrides from SkMaskFilter |
| 58 | virtual SkMask::Format getFormat(); |
| 59 | virtual bool filterMask(SkMask*, const SkMask&, const SkMatrix&, SkIPoint*); |
| 60 | |
| 61 | // overrides from SkFlattenable |
| 62 | virtual void flatten(SkFlattenableWriteBuffer& wb); |
| 63 | virtual Factory getFactory(); |
| 64 | |
| 65 | protected: |
| 66 | SkTableMaskFilter(SkFlattenableReadBuffer& rb); |
| 67 | static SkFlattenable* Factory(SkFlattenableReadBuffer&); |
| 68 | |
| 69 | private: |
| 70 | uint8_t fTable[256]; |
| 71 | |
| 72 | typedef SkMaskFilter INHERITED; |
| 73 | }; |
| 74 | |
| 75 | #endif |
| 76 | |