LCOV - code coverage report
Current view: top level - basegfx/source/color - bcolormodifier.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 19 117 16.2 %
Date: 2014-11-03 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             : namespace basegfx
      23             : {
      24         633 :     BColorModifier::~BColorModifier()
      25             :     {
      26         633 :     }
      27             : } // end of namespace basegfx
      28             : 
      29             : namespace basegfx
      30             : {
      31           0 :     BColorModifier_gray::~BColorModifier_gray()
      32             :     {
      33           0 :     }
      34             : 
      35           0 :     bool BColorModifier_gray::operator==(const BColorModifier& rCompare) const
      36             :     {
      37           0 :         return 0 != dynamic_cast< const BColorModifier_gray* >(&rCompare);
      38             :     }
      39             : 
      40           0 :     ::basegfx::BColor BColorModifier_gray::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
      41             :     {
      42           0 :         const double fLuminance(aSourceColor.luminance());
      43             : 
      44           0 :         return ::basegfx::BColor(fLuminance, fLuminance, fLuminance);
      45             :     }
      46             : } // end of namespace basegfx
      47             : 
      48             : namespace basegfx
      49             : {
      50           0 :     BColorModifier_invert::~BColorModifier_invert()
      51             :     {
      52           0 :     }
      53             : 
      54           0 :     bool BColorModifier_invert::operator==(const BColorModifier& rCompare) const
      55             :     {
      56           0 :         return 0 != dynamic_cast< const BColorModifier_invert* >(&rCompare);
      57             :     }
      58             : 
      59           0 :     ::basegfx::BColor BColorModifier_invert::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
      60             :     {
      61           0 :         return ::basegfx::BColor(1.0 - aSourceColor.getRed(), 1.0 - aSourceColor.getGreen(), 1.0 - aSourceColor.getBlue());
      62             :     }
      63             : } // end of namespace basegfx
      64             : 
      65             : namespace basegfx
      66             : {
      67         302 :     BColorModifier_luminance_to_alpha::~BColorModifier_luminance_to_alpha()
      68             :     {
      69         302 :     }
      70             : 
      71           0 :     bool BColorModifier_luminance_to_alpha::operator==(const BColorModifier& rCompare) const
      72             :     {
      73           0 :         return 0 != dynamic_cast< const BColorModifier_luminance_to_alpha* >(&rCompare);
      74             :     }
      75             : 
      76      185732 :     ::basegfx::BColor BColorModifier_luminance_to_alpha::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
      77             :     {
      78      185732 :         const double fAlpha(1.0 - ((aSourceColor.getRed() * 0.2125) + (aSourceColor.getGreen() * 0.7154) + (aSourceColor.getBlue() * 0.0721)));
      79             : 
      80      185732 :         return ::basegfx::BColor(fAlpha, fAlpha, fAlpha);
      81             :     }
      82             : } // end of namespace basegfx
      83             : 
      84             : namespace basegfx
      85             : {
      86         964 :     BColorModifier_replace::~BColorModifier_replace()
      87             :     {
      88         964 :     }
      89             : 
      90           0 :     bool BColorModifier_replace::operator==(const BColorModifier& rCompare) const
      91             :     {
      92           0 :         const BColorModifier_replace* pCompare = dynamic_cast< const BColorModifier_replace* >(&rCompare);
      93             : 
      94           0 :         if(!pCompare)
      95             :         {
      96           0 :             return false;
      97             :         }
      98             : 
      99           0 :         return getBColor() == pCompare->getBColor();
     100             :     }
     101             : 
     102       13610 :     ::basegfx::BColor BColorModifier_replace::getModifiedColor(const ::basegfx::BColor& /*aSourceColor*/) const
     103             :     {
     104       13610 :         return maBColor;
     105             :     }
     106             : } // end of namespace basegfx
     107             : 
     108             : namespace basegfx
     109             : {
     110           0 :     BColorModifier_interpolate::~BColorModifier_interpolate()
     111             :     {
     112           0 :     }
     113             : 
     114           0 :     bool BColorModifier_interpolate::operator==(const BColorModifier& rCompare) const
     115             :     {
     116           0 :         const BColorModifier_interpolate* pCompare = dynamic_cast< const BColorModifier_interpolate* >(&rCompare);
     117             : 
     118           0 :         if(!pCompare)
     119             :         {
     120           0 :             return false;
     121             :         }
     122             : 
     123           0 :         return getBColor() == pCompare->getBColor() && getValue() == pCompare->getValue();
     124             :     }
     125             : 
     126           0 :     ::basegfx::BColor BColorModifier_interpolate::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     127             :     {
     128           0 :         return interpolate(maBColor, aSourceColor, mfValue);
     129             :     }
     130             : } // end of namespace basegfx
     131             : 
     132             : namespace basegfx
     133             : {
     134           0 :     BColorModifier_black_and_white::~BColorModifier_black_and_white()
     135             :     {
     136           0 :     }
     137             : 
     138           0 :     bool BColorModifier_black_and_white::operator==(const BColorModifier& rCompare) const
     139             :     {
     140           0 :         const BColorModifier_black_and_white* pCompare = dynamic_cast< const BColorModifier_black_and_white* >(&rCompare);
     141             : 
     142           0 :         if(!pCompare)
     143             :         {
     144           0 :             return false;
     145             :         }
     146             : 
     147           0 :         return getValue() == pCompare->getValue();
     148             :     }
     149             : 
     150           0 :     ::basegfx::BColor BColorModifier_black_and_white::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     151             :     {
     152           0 :         const double fLuminance(aSourceColor.luminance());
     153             : 
     154           0 :         if(fLuminance < mfValue)
     155             :         {
     156           0 :             return ::basegfx::BColor::getEmptyBColor();
     157             :         }
     158             :         else
     159             :         {
     160           0 :             return ::basegfx::BColor(1.0, 1.0, 1.0);
     161             :         }
     162             :     }
     163             : } // end of namespace basegfx
     164             : 
     165             : namespace basegfx
     166             : {
     167           0 :     BColorModifier_gamma::BColorModifier_gamma(double fValue)
     168             :     :   BColorModifier(),
     169             :         mfValue(fValue),
     170             :         mfInvValue(fValue),
     171           0 :         mbUseIt(!basegfx::fTools::equal(fValue, 1.0) && basegfx::fTools::more(fValue, 0.0) && basegfx::fTools::lessOrEqual(fValue, 10.0))
     172             :     {
     173           0 :         if(mbUseIt)
     174             :         {
     175           0 :             mfInvValue = 1.0 / mfValue;
     176             :         }
     177           0 :     }
     178             : 
     179           0 :     BColorModifier_gamma::~BColorModifier_gamma()
     180             :     {
     181           0 :     }
     182             : 
     183           0 :     bool BColorModifier_gamma::operator==(const BColorModifier& rCompare) const
     184             :     {
     185           0 :         const BColorModifier_gamma* pCompare = dynamic_cast< const BColorModifier_gamma* >(&rCompare);
     186             : 
     187           0 :         if(!pCompare)
     188             :         {
     189           0 :             return false;
     190             :         }
     191             : 
     192             :         // getValue is sufficient, mfInvValue and mbUseIt are only helper values
     193           0 :         return getValue() == pCompare->getValue();
     194             :     }
     195             : 
     196           0 :     ::basegfx::BColor BColorModifier_gamma::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     197             :     {
     198           0 :         if(mbUseIt)
     199             :         {
     200             :             ::basegfx::BColor aRetval(
     201             :                 pow(aSourceColor.getRed(), mfInvValue),
     202             :                 pow(aSourceColor.getGreen(), mfInvValue),
     203           0 :                 pow(aSourceColor.getBlue(), mfInvValue));
     204             : 
     205           0 :             aRetval.clamp();
     206           0 :             return aRetval;
     207             :         }
     208             :         else
     209             :         {
     210           0 :             return aSourceColor;
     211             :         }
     212             :     }
     213             : } // end of namespace basegfx
     214             : 
     215             : namespace basegfx
     216             : {
     217           0 :     BColorModifier_RGBLuminanceContrast::BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast)
     218             :     :   BColorModifier(),
     219           0 :         mfRed(basegfx::clamp(fRed, -1.0, 1.0)),
     220           0 :         mfGreen(basegfx::clamp(fGreen, -1.0, 1.0)),
     221           0 :         mfBlue(basegfx::clamp(fBlue, -1.0, 1.0)),
     222           0 :         mfLuminance(basegfx::clamp(fLuminance, -1.0, 1.0)),
     223           0 :         mfContrast(basegfx::clamp(fContrast, -1.0, 1.0)),
     224             :         mfContrastOff(1.0),
     225             :         mfRedOff(0.0),
     226             :         mfGreenOff(0.0),
     227             :         mfBlueOff(0.0),
     228           0 :         mbUseIt(false)
     229             :     {
     230           0 :         if(!basegfx::fTools::equalZero(mfRed)
     231           0 :             || !basegfx::fTools::equalZero(mfGreen)
     232           0 :             || !basegfx::fTools::equalZero(mfBlue)
     233           0 :             || !basegfx::fTools::equalZero(mfLuminance)
     234           0 :             || !basegfx::fTools::equalZero(mfContrast))
     235             :         {
     236             :             // calculate slope
     237           0 :             if(mfContrast >= 0.0)
     238             :             {
     239           0 :                 mfContrastOff = 128.0 / (128.0 - (mfContrast * 127.0));
     240             :             }
     241             :             else
     242             :             {
     243           0 :                 mfContrastOff = ( 128.0 + (mfContrast * 127.0)) / 128.0;
     244             :             }
     245             : 
     246             :             // calculate unified contrast offset
     247           0 :             const double fPreparedContrastOff((128.0 - mfContrastOff * 128.0) / 255.0);
     248           0 :             const double fCombinedOffset(mfLuminance + fPreparedContrastOff);
     249             : 
     250             :             // set full offsets
     251           0 :             mfRedOff = mfRed + fCombinedOffset;
     252           0 :             mfGreenOff = mfGreen + fCombinedOffset;
     253           0 :             mfBlueOff = mfBlue + fCombinedOffset;
     254             : 
     255           0 :             mbUseIt = true;
     256             :         }
     257           0 :     }
     258             : 
     259           0 :     BColorModifier_RGBLuminanceContrast::~BColorModifier_RGBLuminanceContrast()
     260             :     {
     261           0 :     }
     262             : 
     263           0 :     bool BColorModifier_RGBLuminanceContrast::operator==(const BColorModifier& rCompare) const
     264             :     {
     265           0 :         const BColorModifier_RGBLuminanceContrast* pCompare = dynamic_cast< const BColorModifier_RGBLuminanceContrast* >(&rCompare);
     266             : 
     267           0 :         if(!pCompare)
     268             :         {
     269           0 :             return false;
     270             :         }
     271             : 
     272             :         // no need to compare other values, these are just helpers
     273           0 :         return getRed() == pCompare->getRed()
     274           0 :             && getGreen() == pCompare->getGreen()
     275           0 :             && getBlue() == pCompare->getBlue()
     276           0 :             && getLuminance() == pCompare->getLuminance()
     277           0 :             && getContrast() == pCompare->getContrast();
     278             :     }
     279             : 
     280           0 :     ::basegfx::BColor BColorModifier_RGBLuminanceContrast::getModifiedColor(const ::basegfx::BColor& aSourceColor) const
     281             :     {
     282           0 :         if(mbUseIt)
     283             :         {
     284             :             return basegfx::BColor(
     285           0 :                 basegfx::clamp(aSourceColor.getRed() * mfContrastOff + mfRedOff, 0.0, 1.0),
     286           0 :                 basegfx::clamp(aSourceColor.getGreen() * mfContrastOff + mfGreenOff, 0.0, 1.0),
     287           0 :                 basegfx::clamp(aSourceColor.getBlue() * mfContrastOff + mfBlueOff, 0.0, 1.0));
     288             :         }
     289             :         else
     290             :         {
     291           0 :             return aSourceColor;
     292             :         }
     293             :     }
     294             : } // end of namespace basegfx
     295             : 
     296             : namespace basegfx
     297             : {
     298      433843 :     ::basegfx::BColor BColorModifierStack::getModifiedColor(const ::basegfx::BColor& rSource) const
     299             :     {
     300      433843 :         if(maBColorModifiers.empty())
     301             :         {
     302      418837 :             return rSource;
     303             :         }
     304             : 
     305       15006 :         ::basegfx::BColor aRetval(rSource);
     306             : 
     307       45058 :         for(sal_uInt32 a(maBColorModifiers.size()); a;)
     308             :         {
     309       15046 :             a--;
     310       15046 :             aRetval = maBColorModifiers[a]->getModifiedColor(aRetval);
     311             :         }
     312             : 
     313       15006 :         return aRetval;
     314             :     }
     315             : } // end of namespace basegfx
     316             : 
     317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10