00001 /* 00002 * Copyright (C) 2007 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 SkColorMatrixFilter_DEFINED 00018 #define SkColorMatrixFilter_DEFINED 00019 00020 #include "SkColorFilter.h" 00021 #include "SkColorMatrix.h" 00022 00023 class SkColorMatrixFilter : public SkColorFilter { 00024 public: 00025 SkColorMatrixFilter(); 00026 explicit SkColorMatrixFilter(const SkColorMatrix&); 00027 SkColorMatrixFilter(const SkScalar array[20]); 00028 00029 void setMatrix(const SkColorMatrix&); 00030 void setArray(const SkScalar array[20]); 00031 00032 // overrides from SkColorFilter 00033 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]); 00034 virtual void filterSpan16(const uint16_t src[], int count, uint16_t[]); 00035 virtual uint32_t getFlags(); 00036 00037 // overrides for SkFlattenable 00038 virtual void flatten(SkFlattenableWriteBuffer& buffer); 00039 00040 struct State { 00041 int32_t fArray[20]; 00042 int fShift; 00043 int32_t fResult[4]; 00044 }; 00045 00046 protected: 00047 // overrides for SkFlattenable 00048 virtual Factory getFactory(); 00049 00050 SkColorMatrixFilter(SkFlattenableReadBuffer& buffer); 00051 00052 private: 00053 static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer); 00054 00055 typedef void (*Proc)(State*, unsigned r, unsigned g, unsigned b, 00056 unsigned a); 00057 00058 Proc fProc; 00059 State fState; 00060 uint32_t fFlags; 00061 00062 void setup(const SkScalar array[20]); 00063 00064 typedef SkColorFilter INHERITED; 00065 }; 00066 00067 #endif