LCOV - code coverage report
Current view: top level - basegfx/source/color - bcolormodifier.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 19 117 16.2 %
Date: 2014-04-11 Functions: 8 37 21.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <basegfx/color/bcolormodifier.hxx>
      21             : 
      22             : 
      23             : 
      24             : namespace basegfx
      25             : {
      26         807 :     BColorModifier::~BColorModifier()
      27             :     {
      28         807 :     }
      29             : } // end of namespace basegfx
      30             : 
      31             : 
      32             : 
      33             : namespace basegfx
      34             : {
      35           0 :     BColorModifier_gray::~BColorModifier_gray()
      36             :     {
      37           0 :     }
      38             : 
      39           0 :     bool BColorModifier_gray::operator==(const BColorModifier& rCompare) const
      40             :     {
      41           0 :         return 0 != dynamic_cast< const BColorModifier_gray* >(&rCompare);
      42             :     }
      43             : 
      44           0 :     ::basegfx::BColor BColorModifier_gray::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
      45             :     {
      46           0 :         const double fLuminance(aSourceColor.luminance());
      47             : 
      48           0 :         return ::basegfx::BColor(fLuminance, fLuminance, fLuminance);
      49             :     }
      50             : } // end of namespace basegfx
      51             : 
      52             : 
      53             : 
      54             : namespace basegfx
      55             : {
      56           0 :     BColorModifier_invert::~BColorModifier_invert()
      57             :     {
      58           0 :     }
      59             : 
      60           0 :     bool BColorModifier_invert::operator==(const BColorModifier& rCompare) const
      61             :     {
      62           0 :         return 0 != dynamic_cast< const BColorModifier_invert* >(&rCompare);
      63             :     }
      64             : 
      65           0 :     ::basegfx::BColor BColorModifier_invert::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
      66             :     {
      67           0 :         return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue());
      68             :     }
      69             : } // end of namespace basegfx
      70             : 
      71             : 
      72             : 
      73             : namespace basegfx
      74             : {
      75         308 :     BColorModifier_luminance_to_alpha::~BColorModifier_luminance_to_alpha()
      76             :     {
      77         308 :     }
      78             : 
      79           0 :     bool BColorModifier_luminance_to_alpha::operator==(const BColorModifier& rCompare) const
      80             :     {
      81           0 :         return 0 != dynamic_cast< const BColorModifier_luminance_to_alpha* >(&rCompare);
      82             :     }
      83             : 
      84      185748 :     ::basegfx::BColor BColorModifier_luminance_to_alpha::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
      85             :     {
      86      185748 :         const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721)));
      87             : 
      88      185748 :         return ::basegfx::BColor(fAlpha, fAlpha, fAlpha);
      89             :     }
      90             : } // end of namespace basegfx
      91             : 
      92             : 
      93             : 
      94             : namespace basegfx
      95             : {
      96        1306 :     BColorModifier_replace::~BColorModifier_replace()
      97             :     {
      98        1306 :     }
      99             : 
     100           0 :     bool BColorModifier_replace::operator==(const BColorModifier& rCompare) const
     101             :     {
     102           0 :         const BColorModifier_replace* pCompare = dynamic_cast< const BColorModifier_replace* >(&rCompare);
     103             : 
     104           0 :         if(!pCompare)
     105             :         {
     106           0 :             return false;
     107             :         }
     108             : 
     109           0 :         return getBColor() == pCompare->getBColor();
     110             :     }
     111             : 
     112       22746 :     ::basegfx::BColor BColorModifier_replace::getModifiedColor(const ::basegfx::BColor& /*aSourceColor*/) const
     113             :     {
     114       22746 :         return maBColor;
     115             :     }
     116             : } // end of namespace basegfx
     117             : 
     118             : 
     119             : 
     120             : namespace basegfx
     121             : {
     122           0 :     BColorModifier_interpolate::~BColorModifier_interpolate()
     123             :     {
     124           0 :     }
     125             : 
     126           0 :     bool BColorModifier_interpolate::operator==(const BColorModifier& rCompare) const
     127             :     {
     128           0 :         const BColorModifier_interpolate* pCompare = dynamic_cast< const BColorModifier_interpolate* >(&rCompare);
     129             : 
     130           0 :         if(!pCompare)
     131             :         {
     132           0 :             return false;
     133             :         }
     134             : 
     135           0 :         return getBColor() == pCompare->getBColor() && getValue() == pCompare->getValue();
     136             :     }
     137             : 
     138           0 :     ::basegfx::BColor BColorModifier_interpolate::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     139             :     {
     140           0 :         return interpolate(maBColor, aSourceColor, mfValue);
     141             :     }
     142             : } // end of namespace basegfx
     143             : 
     144             : 
     145             : 
     146             : namespace basegfx
     147             : {
     148           0 :     BColorModifier_black_and_white::~BColorModifier_black_and_white()
     149             :     {
     150           0 :     }
     151             : 
     152           0 :     bool BColorModifier_black_and_white::operator==(const BColorModifier& rCompare) const
     153             :     {
     154           0 :         const BColorModifier_black_and_white* pCompare = dynamic_cast< const BColorModifier_black_and_white* >(&rCompare);
     155             : 
     156           0 :         if(!pCompare)
     157             :         {
     158           0 :             return false;
     159             :         }
     160             : 
     161           0 :         return getValue() == pCompare->getValue();
     162             :     }
     163             : 
     164           0 :     ::basegfx::BColor BColorModifier_black_and_white::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     165             :     {
     166           0 :         const double fLuminance(aSourceColor.luminance());
     167             : 
     168           0 :         if(fLuminance < mfValue)
     169             :         {
     170           0 :             return ::basegfx::BColor::getEmptyBColor();
     171             :         }
     172             :         else
     173             :         {
     174           0 :             return ::basegfx::BColor(1.0, 1.0, 1.0);
     175             :         }
     176             :     }
     177             : } // end of namespace basegfx
     178             : 
     179             : 
     180             : 
     181             : namespace basegfx
     182             : {
     183           0 :     BColorModifier_gamma::BColorModifier_gamma(double fValue)
     184             :     :   BColorModifier(),
     185             :         mfValue(fValue),
     186             :         mfInvValue(fValue),
     187           0 :         mbUseIt(!basegfx::fTools::equal(fValue, 1.0) && basegfx::fTools::more(fValue, 0.0) && basegfx::fTools::lessOrEqual(fValue, 10.0))
     188             :     {
     189           0 :         if(mbUseIt)
     190             :         {
     191           0 :             mfInvValue = 1.0 / mfValue;
     192             :         }
     193           0 :     }
     194             : 
     195           0 :     BColorModifier_gamma::~BColorModifier_gamma()
     196             :     {
     197           0 :     }
     198             : 
     199           0 :     bool BColorModifier_gamma::operator==(const BColorModifier& rCompare) const
     200             :     {
     201           0 :         const BColorModifier_gamma* pCompare = dynamic_cast< const BColorModifier_gamma* >(&rCompare);
     202             : 
     203           0 :         if(!pCompare)
     204             :         {
     205           0 :             return false;
     206             :         }
     207             : 
     208             :         // getValue is sufficient, mfInvValue and mbUseIt are only helper values
     209           0 :         return getValue() == pCompare->getValue();
     210             :     }
     211             : 
     212           0 :     ::basegfx::BColor BColorModifier_gamma::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     213             :     {
     214           0 :         if(mbUseIt)
     215             :         {
     216             :             ::basegfx::BColor aRetval(
     217             :                 pow(aSourceColor.getRed(), mfInvValue),
     218             :                 pow(aSourceColor.getGreen(), mfInvValue),
     219           0 :                 pow(aSourceColor.getBlue(), mfInvValue));
     220             : 
     221           0 :             aRetval.clamp();
     222           0 :             return aRetval;
     223             :         }
     224             :         else
     225             :         {
     226           0 :             return aSourceColor;
     227             :         }
     228             :     }
     229             : } // end of namespace basegfx
     230             : 
     231             : 
     232             : 
     233             : namespace basegfx
     234             : {
     235           0 :     BColorModifier_RGBLuminanceContrast::BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast)
     236             :     :   BColorModifier(),
     237           0 :         mfRed(basegfx::clamp(fRed, -1.0, 1.0)),
     238           0 :         mfGreen(basegfx::clamp(fGreen, -1.0, 1.0)),
     239           0 :         mfBlue(basegfx::clamp(fBlue, -1.0, 1.0)),
     240           0 :         mfLuminance(basegfx::clamp(fLuminance, -1.0, 1.0)),
     241           0 :         mfContrast(basegfx::clamp(fContrast, -1.0, 1.0)),
     242             :         mfContrastOff(1.0),
     243             :         mfRedOff(0.0),
     244             :         mfGreenOff(0.0),
     245             :         mfBlueOff(0.0),
     246           0 :         mbUseIt(false)
     247             :     {
     248           0 :         if(!basegfx::fTools::equalZero(mfRed)
     249           0 :             || !basegfx::fTools::equalZero(mfGreen)
     250           0 :             || !basegfx::fTools::equalZero(mfBlue)
     251           0 :             || !basegfx::fTools::equalZero(mfLuminance)
     252           0 :             || !basegfx::fTools::equalZero(mfContrast))
     253             :         {
     254             :             // calculate slope
     255           0 :             if(mfContrast >= 0.0)
     256             :             {
     257           0 :                 mfContrastOff = 128.0 / (128.0 - (mfContrast * 127.0));
     258             :             }
     259             :             else
     260             :             {
     261           0 :                 mfContrastOff = ( 128.0 + (mfContrast * 127.0)) / 128.0;
     262             :             }
     263             : 
     264             :             // calculate unified contrast offset
     265           0 :             const double fPreparedContrastOff((128.0 - mfContrastOff * 128.0) / 255.0);
     266           0 :             const double fCombinedOffset(mfLuminance + fPreparedContrastOff);
     267             : 
     268             :             // set full offsets
     269           0 :             mfRedOff = mfRed + fCombinedOffset;
     270           0 :             mfGreenOff = mfGreen + fCombinedOffset;
     271           0 :             mfBlueOff = mfBlue + fCombinedOffset;
     272             : 
     273           0 :             mbUseIt = true;
     274             :         }
     275           0 :     }
     276             : 
     277           0 :     BColorModifier_RGBLuminanceContrast::~BColorModifier_RGBLuminanceContrast()
     278             :     {
     279           0 :     }
     280             : 
     281           0 :     bool BColorModifier_RGBLuminanceContrast::operator==(const BColorModifier& rCompare) const
     282             :     {
     283           0 :         const BColorModifier_RGBLuminanceContrast* pCompare = dynamic_cast< const BColorModifier_RGBLuminanceContrast* >(&rCompare);
     284             : 
     285           0 :         if(!pCompare)
     286             :         {
     287           0 :             return false;
     288             :         }
     289             : 
     290             :         // no need to compare other values, these are just helpers
     291           0 :         return getRed() == pCompare->getRed()
     292           0 :             && getGreen() == pCompare->getGreen()
     293           0 :             && getBlue() == pCompare->getBlue()
     294           0 :             && getLuminance() == pCompare->getLuminance()
     295           0 :             && getContrast() == pCompare->getContrast();
     296             :     }
     297             : 
     298           0 :     ::basegfx::BColor BColorModifier_RGBLuminanceContrast::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     299             :     {
     300           0 :         if(mbUseIt)
     301             :         {
     302             :             return basegfx::BColor(
     303           0 :                 basegfx::clamp(aSourceColor.getRed() * mfContrastOff + mfRedOff, 0.0, 1.0),
     304           0 :                 basegfx::clamp(aSourceColor.getGreen() * mfContrastOff + mfGreenOff, 0.0, 1.0),
     305           0 :                 basegfx::clamp(aSourceColor.getBlue() * mfContrastOff + mfBlueOff, 0.0, 1.0));
     306             :         }
     307             :         else
     308             :         {
     309           0 :             return aSourceColor;
     310             :         }
     311             :     }
     312             : } // end of namespace basegfx
     313             : 
     314             : 
     315             : 
     316             : namespace basegfx
     317             : {
     318      360764 :     ::basegfx::BColor BColorModifierStack::getModifiedColor(const ::basegfx::BColor& rSource) const
     319             :     {
     320      360764 :         if(maBColorModifiers.empty())
     321             :         {
     322      336646 :             return rSource;
     323             :         }
     324             : 
     325       24118 :         ::basegfx::BColor aRetval(rSource);
     326             : 
     327       72434 :         for(sal_uInt32 a(maBColorModifiers.size()); a;)
     328             :         {
     329       24198 :             a--;
     330       24198 :             aRetval = maBColorModifiers[a]->getModifiedColor(aRetval);
     331             :         }
     332             : 
     333       24118 :         return aRetval;
     334             :     }
     335             : } // end of namespace basegfx
     336             : 
     337             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10