1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_basegfx.hxx" 26 27 #include <basegfx/color/bcolormodifier.hxx> 28 29 ////////////////////////////////////////////////////////////////////////////// 30 31 namespace basegfx 32 { 33 ::basegfx::BColor BColorModifier::getModifiedColor(const ::basegfx::BColor& aSourceColor) const 34 { 35 switch(meMode) 36 { 37 case BCOLORMODIFYMODE_INTERPOLATE : 38 { 39 return interpolate(maBColor, aSourceColor, mfValue); 40 } 41 case BCOLORMODIFYMODE_GRAY : 42 { 43 const double fLuminance(aSourceColor.luminance()); 44 return ::basegfx::BColor(fLuminance, fLuminance, fLuminance); 45 } 46 case BCOLORMODIFYMODE_BLACKANDWHITE : 47 { 48 const double fLuminance(aSourceColor.luminance()); 49 50 if(fLuminance < mfValue) 51 { 52 return ::basegfx::BColor::getEmptyBColor(); 53 } 54 else 55 { 56 return ::basegfx::BColor(1.0, 1.0, 1.0); 57 } 58 } 59 case BCOLORMODIFYMODE_INVERT : 60 { 61 return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue()); 62 } 63 case BCOLORMODIFYMODE_LUMINANCE_TO_ALPHA: 64 { 65 const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721))); 66 return ::basegfx::BColor(fAlpha, fAlpha, fAlpha); 67 } 68 default : // BCOLORMODIFYMODE_REPLACE 69 { 70 return maBColor; 71 } 72 } 73 } 74 } // end of namespace basegfx 75 76 ////////////////////////////////////////////////////////////////////////////// 77 // eof 78