LCOV - code coverage report
Current view: top level - include/basegfx/color - bcolormodifier.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 40 0.0 %
Date: 2014-04-14 Functions: 0 26 0.0 %
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 INCLUDED_BASEGFX_COLOR_BCOLORMODIFIER_HXX
      21             : #define INCLUDED_BASEGFX_COLOR_BCOLORMODIFIER_HXX
      22             : 
      23             : #include <basegfx/basegfxdllapi.h>
      24             : #include <basegfx/color/bcolor.hxx>
      25             : #include <boost/shared_ptr.hpp>
      26             : #include <boost/utility.hpp>
      27             : #include <vector>
      28             : 
      29             : 
      30             : 
      31             : namespace basegfx
      32             : {
      33             :     /** base class to define color modifications
      34             : 
      35             :         The basic idea is to have instances of color modifiers where each
      36             :         of these can be asked to get a modified version of a color. This
      37             :         can be as easy as to return a fixed color, but may also do any
      38             :         other computation based on the given source color and the local
      39             :         algorithm to apply.
      40             : 
      41             :         This base implementation defines the abstract base class. Every
      42             :         derivation offers another color blending effect, when needed with
      43             :         parameters for that blending defined as members.
      44             : 
      45             :         As long as aw080 is not applied, an operator== is needed to implement
      46             :         the operator== of the primitive based on this instances.
      47             : 
      48             :         For the exact definitions of the color blending applied refer to the
      49             :         implementation of the method getModifiedColor
      50             : 
      51             :         BColorModifier is not copyable (no copy constructor, no assigment
      52             :         operator); local values cannot be changed after construction. The
      53             :         instances are cheap and the idea is to create them on demand. To
      54             :         be able to reuse these as much as possible, a define for a
      55             :         ::boost::shared_ptr named BColorModifierSharedPtr exists below.
      56             :         All usages should handle instances of BColorModifier encapsulated
      57             :         into these shared pointers.
      58             :     */
      59             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier : private boost::noncopyable
      60             :     {
      61             :     private:
      62             :     protected:
      63             :         // noone is allowed to incarnate the abstract base class
      64             :         // except derivations
      65           0 :         BColorModifier() {}
      66             : 
      67             :     public:
      68             :         // noone should directly destroy it; all incarnations should be
      69             :         // handled in a boost::shared_ptr of type BColorModifierSharedPtr
      70             :         virtual ~BColorModifier();
      71             : 
      72             :         // compare operator
      73             :         virtual bool operator==(const BColorModifier& rCompare) const = 0;
      74             :         bool operator!=(const BColorModifier& rCompare) const
      75             :         {
      76             :             return !(operator==(rCompare));
      77             :         }
      78             : 
      79             :         // compute modified color
      80             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const = 0;
      81             :     };
      82             : } // end of namespace basegfx
      83             : 
      84             : 
      85             : 
      86             : namespace basegfx
      87             : {
      88             :     /** convert color to gray
      89             :     */
      90             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_gray : public BColorModifier
      91             :     {
      92             :     private:
      93             :     protected:
      94             :     public:
      95           0 :         BColorModifier_gray()
      96           0 :         :   BColorModifier()
      97             :         {
      98           0 :         }
      99             : 
     100             :         virtual ~BColorModifier_gray();
     101             : 
     102             :         // compare operator
     103             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     104             : 
     105             :         // compute modified color
     106             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     107             :     };
     108             : } // end of namespace basegfx
     109             : 
     110             : 
     111             : 
     112             : namespace basegfx
     113             : {
     114             :     /** invert color
     115             : 
     116             :         returns a color where red green and blue are inverted using 1.0 - n
     117             :     */
     118             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_invert : public BColorModifier
     119             :     {
     120             :     private:
     121             :     protected:
     122             :     public:
     123           0 :         BColorModifier_invert()
     124           0 :         :   BColorModifier()
     125             :         {
     126           0 :         }
     127             : 
     128             :         virtual ~BColorModifier_invert();
     129             : 
     130             :         // compare operator
     131             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     132             : 
     133             :         // compute modified color
     134             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     135             :     };
     136             : } // end of namespace basegfx
     137             : 
     138             : 
     139             : 
     140             : namespace basegfx
     141             : {
     142             :     /** convert to alpha based on luminance
     143             : 
     144             :         returns a color where red green and blue are first weighted and added
     145             :         to build a luminance value which is then inverted and used for red,
     146             :         green and blue. The weights are  r * 0.2125 + g * 0.7154 + b * 0.0721.
     147             :         This derivation is used for the svg importer and does exactly what SVG
     148             :         defines for this needed case.
     149             :     */
     150             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_luminance_to_alpha : public BColorModifier
     151             :     {
     152             :     private:
     153             :     protected:
     154             :     public:
     155           0 :         BColorModifier_luminance_to_alpha()
     156           0 :         :   BColorModifier()
     157             :         {
     158           0 :         }
     159             : 
     160             :         virtual ~BColorModifier_luminance_to_alpha();
     161             : 
     162             :         // compare operator
     163             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     164             : 
     165             :         // compute modified color
     166             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     167             :     };
     168             : } // end of namespace basegfx
     169             : 
     170             : 
     171             : 
     172             : namespace basegfx
     173             : {
     174             :     /** replace color
     175             : 
     176             :         does not use the source color at all, but always returns the
     177             :         given color, replacing everything. Useful e.g. for unified shadow
     178             :         creation
     179             :     */
     180             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_replace : public BColorModifier
     181             :     {
     182             :     private:
     183             :         ::basegfx::BColor           maBColor;
     184             : 
     185             :     protected:
     186             :     public:
     187           0 :         BColorModifier_replace(const ::basegfx::BColor& rBColor)
     188             :         :   BColorModifier(),
     189           0 :             maBColor(rBColor)
     190             :         {
     191           0 :         }
     192             : 
     193             :         virtual ~BColorModifier_replace();
     194             : 
     195             :         // data access
     196           0 :         const ::basegfx::BColor& getBColor() const { return maBColor; }
     197             : 
     198             :         // compare operator
     199             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     200             : 
     201             :         // compute modified color
     202             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     203             :     };
     204             : } // end of namespace basegfx
     205             : 
     206             : 
     207             : 
     208             : namespace basegfx
     209             : {
     210             :     /** interpolate color
     211             : 
     212             :         returns an interpolated color mixed by the given value (f) in the range
     213             :         [0.0 .. 1.0] and the given color (col) as follows:
     214             : 
     215             :         col * (1 - f) + aSourceColor * f
     216             :     */
     217             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_interpolate : public BColorModifier
     218             :     {
     219             :     private:
     220             :         ::basegfx::BColor           maBColor;
     221             :         double                      mfValue;
     222             : 
     223             :     protected:
     224             :     public:
     225           0 :         BColorModifier_interpolate(const ::basegfx::BColor& rBColor, double fValue)
     226             :         :   BColorModifier(),
     227             :             maBColor(rBColor),
     228           0 :             mfValue(fValue)
     229             :         {
     230           0 :         }
     231             : 
     232             :         virtual ~BColorModifier_interpolate();
     233             : 
     234             :         // data access
     235           0 :         const ::basegfx::BColor& getBColor() const { return maBColor; }
     236           0 :         double getValue() const { return mfValue; }
     237             : 
     238             :         // compare operator
     239             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     240             : 
     241             :         // compute modified color
     242             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     243             :     };
     244             : } // end of namespace basegfx
     245             : 
     246             : 
     247             : 
     248             : namespace basegfx
     249             : {
     250             :     /** convert color to black and white
     251             : 
     252             :         returns black when the luminance of the given color is less than
     253             :         the given treshhold value in the range [0.0 .. 1.0], else white
     254             :     */
     255             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_black_and_white : public BColorModifier
     256             :     {
     257             :     private:
     258             :         double                      mfValue;
     259             : 
     260             :     protected:
     261             :     public:
     262           0 :         BColorModifier_black_and_white(double fValue)
     263             :         :   BColorModifier(),
     264           0 :             mfValue(fValue)
     265             :         {
     266           0 :         }
     267             : 
     268             :         virtual ~BColorModifier_black_and_white();
     269             : 
     270             :         // data access
     271           0 :         double getValue() const { return mfValue; }
     272             : 
     273             :         // compare operator
     274             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     275             : 
     276             :         // compute modified color
     277             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     278             :     };
     279             : } // end of namespace basegfx
     280             : 
     281             : 
     282             : 
     283             : namespace basegfx
     284             : {
     285             :     /** gamma correction
     286             : 
     287             :         Input is a gamma correction value in the range ]0.0 .. 10.0]; the
     288             :         color values get correted using
     289             : 
     290             :         col(r,g,b) = clamp(pow(col(r,g,b), 1.0 / gamma), 0.0, 1.0)
     291             :     */
     292             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_gamma : public BColorModifier
     293             :     {
     294             :     private:
     295             :         double                      mfValue;
     296             :         double                      mfInvValue;
     297             : 
     298             :         /// bitfield
     299             :         bool                        mbUseIt : 1;
     300             : 
     301             :     protected:
     302             :     public:
     303             :         BColorModifier_gamma(double fValue);
     304             : 
     305             :         virtual ~BColorModifier_gamma();
     306             : 
     307             :         // data access
     308           0 :         double getValue() const { return mfValue; }
     309             : 
     310             :         // compare operator
     311             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     312             : 
     313             :         // compute modified color
     314             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     315             :     };
     316             : } // end of namespace basegfx
     317             : 
     318             : 
     319             : 
     320             : namespace basegfx
     321             : {
     322             :     /** Red, Green, Blue, Luminance and Contrast correction
     323             : 
     324             :         Input are percent values from [-1.0 .. 1-0] which correspond to -100% to 100%
     325             :         correction of Red, Green, Blue, Luminance or Contrast. 0.0 means no change of
     326             :         the corresponding channel. All these are combined (but can be used single) to
     327             :         - be able to cover a bigger change range utilizing the cmobination
     328             :         - allow execution by a small, common, precalculated table
     329             :     */
     330             :     class BASEGFX_DLLPUBLIC SAL_WARN_UNUSED BColorModifier_RGBLuminanceContrast : public BColorModifier
     331             :     {
     332             :     private:
     333             :         double                      mfRed;
     334             :         double                      mfGreen;
     335             :         double                      mfBlue;
     336             :         double                      mfLuminance;
     337             :         double                      mfContrast;
     338             : 
     339             :         double                      mfContrastOff;
     340             :         double                      mfRedOff;
     341             :         double                      mfGreenOff;
     342             :         double                      mfBlueOff;
     343             : 
     344             :         /// bitfield
     345             :         bool                        mbUseIt : 1;
     346             : 
     347             :     protected:
     348             :     public:
     349             :         BColorModifier_RGBLuminanceContrast(double fRed, double fGreen, double fBlue, double fLuminance, double fContrast);
     350             : 
     351             :         virtual ~BColorModifier_RGBLuminanceContrast();
     352             : 
     353             :         // data access
     354           0 :         double getRed() const { return mfRed; }
     355           0 :         double getGreen() const { return mfGreen; }
     356           0 :         double getBlue() const { return mfBlue; }
     357           0 :         double getLuminance() const { return mfLuminance; }
     358           0 :         double getContrast() const { return mfContrast; }
     359             : 
     360             :         // compare operator
     361             :         virtual bool operator==(const BColorModifier& rCompare) const SAL_OVERRIDE;
     362             : 
     363             :         // compute modified color
     364             :         virtual ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& aSourceColor) const SAL_OVERRIDE;
     365             :     };
     366             : } // end of namespace basegfx
     367             : 
     368             : 
     369             : 
     370             : namespace basegfx
     371             : {
     372             :     /// typedef to allow working with shared instances of BColorModifier
     373             :     /// for the whole mechanism
     374             :     typedef ::boost::shared_ptr< BColorModifier > BColorModifierSharedPtr;
     375             : 
     376             :     /** Class to hold a stack of BColorModifierSharedPtrs and to get the modified color with
     377             :         applying all existing entry changes as defined in the stack. Instances of BColorModifier
     378             :         can be pushed and popped to change the stack.
     379             : 
     380             :         All references to BColorModifier members use shared pointers, thus instances of
     381             :         BColorModifierStack can be copied by the default mechanisms if needed.
     382             :     */
     383           0 :     class BASEGFX_DLLPUBLIC BColorModifierStack
     384             :     {
     385             :     protected:
     386             :         ::std::vector< BColorModifierSharedPtr >        maBColorModifiers;
     387             : 
     388             :     public:
     389           0 :         sal_uInt32 count() const
     390             :         {
     391           0 :             return maBColorModifiers.size();
     392             :         }
     393             : 
     394           0 :         const BColorModifierSharedPtr& getBColorModifier(sal_uInt32 nIndex) const
     395             :         {
     396             :             OSL_ENSURE(nIndex < count(), "BColorModifierStack: Access out of range (!)");
     397           0 :             return maBColorModifiers[nIndex];
     398             :         }
     399             : 
     400             :         // get the color in it's modified form by applying all existing BColorModifiers,
     401             :         // from back to front (the newest first)
     402             :         ::basegfx::BColor getModifiedColor(const ::basegfx::BColor& rSource) const;
     403             : 
     404           0 :         void push(const BColorModifierSharedPtr& rNew)
     405             :         {
     406           0 :             maBColorModifiers.push_back(rNew);
     407           0 :         }
     408             : 
     409           0 :         void pop()
     410             :         {
     411           0 :             maBColorModifiers.pop_back();
     412           0 :         }
     413             :     };
     414             : } // end of namespace basegfx
     415             : 
     416             : 
     417             : 
     418             : #endif // INCLUDED_BASEGFX_COLOR_BCOLORMODIFIER_HXX
     419             : 
     420             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10