LCOV - code coverage report
Current view: top level - libreoffice/solver/unxlngi6.pro/inc/basegfx/color - bcolormodifier.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 27 22.2 %
Date: 2012-12-17 Functions: 4 17 23.5 %
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             : #ifndef _BGFX_COLOR_BCOLORMODIFIER_HXX
      21             : #define _BGFX_COLOR_BCOLORMODIFIER_HXX
      22             : 
      23             : #include <basegfx/color/bcolor.hxx>
      24             : #include <vector>
      25             : #include <basegfx/basegfxdllapi.h>
      26             : 
      27             : //////////////////////////////////////////////////////////////////////////////
      28             : 
      29             : namespace basegfx
      30             : {
      31             :     /** Descriptor for type of color modification
      32             :     */
      33             :     enum BColorModifyMode
      34             :     {
      35             :         BCOLORMODIFYMODE_REPLACE,               // replace all color with local color
      36             :         BCOLORMODIFYMODE_INTERPOLATE,           // interpolate color between given and local with local value
      37             :         BCOLORMODIFYMODE_GRAY,                  // convert color to gray
      38             :         BCOLORMODIFYMODE_BLACKANDWHITE,         // convert color to B&W, local value is treshhold
      39             :         BCOLORMODIFYMODE_INVERT,                // invert color
      40             :         BCOLORMODIFYMODE_LUMINANCE_TO_ALPHA     // convert color to alpha value (used for Svg Mask)
      41             :     };
      42             : 
      43             :     /** Class to hold a color, value and mode for a color modification. Color modification is
      44             :         done calling the getModifiedColor() method
      45             :     */
      46           0 :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier
      47             :     {
      48             :     protected:
      49             :         ::basegfx::BColor                           maBColor;
      50             :         double                                      mfValue;
      51             :         BColorModifyMode                            meMode;
      52             : 
      53             :     public:
      54           0 :         BColorModifier(
      55             :             const ::basegfx::BColor& rBColor,
      56             :             double fValue = 0.5,
      57             :             BColorModifyMode eMode = BCOLORMODIFYMODE_REPLACE)
      58             :         :   maBColor(rBColor),
      59             :             mfValue(fValue),
      60           0 :             meMode(eMode)
      61           0 :         {}
      62             : 
      63             :         // compare operator(s)
      64           0 :         bool operator==(const BColorModifier& rCompare) const
      65             :         {
      66           0 :             return (maBColor == rCompare.maBColor && mfValue == rCompare.mfValue && meMode == rCompare.meMode);
      67             :         }
      68             : 
      69             :         bool operator!=(const BColorModifier& rCompare) const
      70             :         {
      71             :             return !(operator==(rCompare));
      72             :         }
      73             : 
      74             :         // data access
      75           0 :         const ::basegfx::BColor& getBColor() const { return maBColor; }
      76             :         double getValue() const { return mfValue; }
      77           0 :         BColorModifyMode getMode() const { return meMode; }
      78             : 
      79             :         // compute modified color
      80             :         ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const;
      81             :     };
      82             : 
      83             :     /** Class to hold a stack of BColorModifiers and to get the modified color with
      84             :         applying all existing entry changes
      85             :     */
      86        5400 :     class BASEGFX_DLLPUBLIC BColorModifierStack
      87             :     {
      88             :     protected:
      89             :         ::std::vector< BColorModifier >             maBColorModifiers;
      90             : 
      91             :     public:
      92        5910 :         sal_uInt32 count() const
      93             :         {
      94        5910 :             return maBColorModifiers.size();
      95             :         }
      96             : 
      97           0 :         const BColorModifier& getBColorModifier(sal_uInt32 nIndex) const
      98             :         {
      99             :             OSL_ENSURE(nIndex < count(), "BColorModifierStack: Access out of range (!)");
     100           0 :             return maBColorModifiers[nIndex];
     101             :         }
     102             : 
     103        5898 :         ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& rSource) const
     104             :         {
     105        5898 :             if(count())
     106             :             {
     107           0 :                 ::basegfx::BColor aRetval(rSource);
     108           0 :                 ::std::vector< BColorModifier >::const_iterator aEnd(maBColorModifiers.end());
     109             : 
     110           0 :                 while(aEnd != maBColorModifiers.begin())
     111             :                 {
     112           0 :                     aRetval = (--aEnd)->getModifiedColor(aRetval);
     113             :                 }
     114             : 
     115           0 :                 return aRetval;
     116             :             }
     117             :             else
     118             :             {
     119        5898 :                 return rSource;
     120             :             }
     121             :         }
     122             : 
     123           0 :         void push(const BColorModifier& rNew)
     124             :         {
     125           0 :             maBColorModifiers.push_back(rNew);
     126           0 :         }
     127             : 
     128           0 :         void pop()
     129             :         {
     130           0 :             maBColorModifiers.pop_back();
     131           0 :         }
     132             :     };
     133             : } // end of namespace basegfx
     134             : 
     135             : #endif // _BGFX_COLOR_BCOLORMODIFIER_HXX
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10