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 SkPorterDuff_DEFINED 18 #define SkPorterDuff_DEFINED 19 20 #include "SkColor.h" 21 #include "SkXfermode.h" 22 23 class SkXfermode; 24 25 /** DEPRECATED - use SkXfermode::Mode instead 26 */ 27 class SkPorterDuff { 28 public: 29 /** List of predefined xfermodes. In general, the algebra for the modes 30 uses the following symbols: 31 Sa, Sc - source alpha and color 32 Da, Dc - destination alpha and color (before compositing) 33 [a, c] - Resulting (alpha, color) values 34 For these equations, the colors are in premultiplied state. 35 If no xfermode is specified, kSrcOver is assumed. 36 */ 37 enum Mode { 38 kClear_Mode, //!< [0, 0] 39 kSrc_Mode, //!< [Sa, Sc] 40 kDst_Mode, //!< [Da, Dc] 41 kSrcOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Sc + (1 - Sa)*Dc] 42 kDstOver_Mode, //!< [Sa + Da - Sa*Da, Rc = Dc + (1 - Da)*Sc] 43 kSrcIn_Mode, //!< [Sa * Da, Sc * Da] 44 kDstIn_Mode, //!< [Sa * Da, Sa * Dc] 45 kSrcOut_Mode, //!< [Sa * (1 - Da), Sc * (1 - Da)] 46 kDstOut_Mode, //!< [Da * (1 - Sa), Dc * (1 - Sa)] 47 kSrcATop_Mode, //!< [Da, Sc * Da + (1 - Sa) * Dc] 48 kDstATop_Mode, //!< [Sa, Sa * Dc + Sc * (1 - Da)] 49 kXor_Mode, //!< [Sa + Da - 2 * Sa * Da, Sc * (1 - Da) + (1 - Sa) * Dc] 50 kDarken_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + min(Sc, Dc)] 51 kLighten_Mode, //!< [Sa + Da - Sa*Da, Sc*(1 - Da) + Dc*(1 - Sa) + max(Sc, Dc)] 52 kMultiply_Mode, //!< [Sa * Da, Sc * Dc] 53 kScreen_Mode, //!< [Sa + Da - Sa * Da, Sc + Dc - Sc * Dc] 54 kAdd_Mode, //!< Saturate(S + D) 55 #ifdef ANDROID 56 kOverlay_Mode, 57 #endif 58 59 kModeCount 60 }; 61 62 /** Return an SkXfermode object for the specified mode. 63 */ 64 static SkXfermode* CreateXfermode(Mode mode); 65 66 /** Return a function pointer to a routine that applies the specified 67 porter-duff transfer mode. 68 */ 69 static SkXfermodeProc GetXfermodeProc(Mode mode); 70 71 /** Return a function pointer to a routine that applies the specified 72 porter-duff transfer mode and srcColor to a 16bit device color. Note, 73 if the mode+srcColor might return a non-opaque color, then there is not 74 16bit proc, and this will return NULL. 75 */ 76 static SkXfermodeProc16 GetXfermodeProc16(Mode mode, SkColor srcColor); 77 78 /** If the specified xfermode advertises itself as one of the porterduff 79 modes (via SkXfermode::Coeff), return true and if not null, set mode 80 to the corresponding porterduff mode. If it is not recognized as a one, 81 return false and ignore the mode parameter. 82 */ 83 static bool IsMode(SkXfermode*, Mode* mode); 84 85 /** Return the corersponding SkXfermode::Mode 86 */ 87 static SkXfermode::Mode ToXfermodeMode(Mode); 88 }; 89 90 #endif 91 92