LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/basebmp - color.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 7 8 87.5 %
Date: 2012-08-25 Functions: 5 6 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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_BASEBMP_COLOR_HXX
      21                 :            : #define INCLUDED_BASEBMP_COLOR_HXX
      22                 :            : 
      23                 :            : #include <sal/types.h>
      24                 :            : #include <rtl/math.hxx>
      25                 :            : 
      26                 :            : namespace basebmp
      27                 :            : {
      28                 :            : 
      29                 :            : class Color
      30                 :            : {
      31                 :            : private:
      32                 :            :     sal_uInt32          mnColor;
      33                 :            : 
      34                 :            : public:
      35                 :            :     typedef sal_uInt32  value_type;
      36                 :            :     typedef sal_uInt8   component_type;
      37                 :            : 
      38                 :            :     Color() : mnColor(0) {}
      39                 :    4840221 :     explicit Color( sal_uInt32 nVal ) : mnColor(nVal) {}
      40                 :   62228937 :     Color( sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue ) :
      41                 :   62228937 :         mnColor( ((sal_uInt32)nRed << 16) | ((sal_uInt32)nGreen << 8) | nBlue )
      42                 :   62228937 :     {}
      43                 :            : 
      44                 :            :     void setRed( sal_uInt8 nRed ) { mnColor &= ~0x00FF0000UL; mnColor |= (sal_uInt32)nRed << 16; }
      45                 :            :     void setGreen( sal_uInt8 nGreen ) { mnColor &= ~0x0000FF00UL; mnColor |= (sal_uInt32)nGreen << 8; }
      46                 :            :     void setBlue( sal_uInt8 nBlue ) { mnColor &= ~0x000000FFUL; mnColor |= nBlue; }
      47                 :            : 
      48                 :            :     void setGrey( sal_uInt8 nGreyVal ) { mnColor = (sal_uInt32)nGreyVal << 16 | (sal_uInt32)nGreyVal << 8 | nGreyVal; }
      49                 :            : 
      50                 :  167042630 :     sal_uInt8 getRed() const   { return 0xFF & (sal_uInt8)(mnColor >> 16); }
      51                 :  167042630 :     sal_uInt8 getGreen() const { return 0xFF & (sal_uInt8)(mnColor >> 8); }
      52                 :  167042630 :     sal_uInt8 getBlue() const  { return 0xFF & (sal_uInt8)mnColor; }
      53                 :            : 
      54                 :            :     sal_uInt8 getGreyscale() const { return (sal_uInt8)((getBlue()*28UL +
      55                 :            :                                                          getGreen()*151 +
      56                 :            :                                                          getRed()*77) / 256); }
      57                 :            : 
      58                 :          0 :     sal_uInt32 toInt32() const { return mnColor; }
      59                 :            : 
      60                 :            :     bool  operator!() const { return mnColor == 0; }
      61                 :            :     Color operator&( sal_uInt32 nMask ) const { return Color(mnColor & nMask); }
      62                 :            :     Color operator^( Color col ) const { return Color(col.getRed()^getRed(),
      63                 :            :                                                       col.getGreen()^getGreen(),
      64                 :            :                                                       col.getBlue()^getBlue()); }
      65                 :            :     Color operator-( Color col ) const { return Color((sal_uInt8)abs((int)getRed()-col.getRed()),
      66                 :            :                                                       (sal_uInt8)abs((int)getGreen()-col.getGreen()),
      67                 :            :                                                       (sal_uInt8)abs((int)getBlue()-col.getBlue())); }
      68                 :            :     Color operator+( Color col ) const { return Color(getRed()+col.getRed(),
      69                 :            :                                                       getGreen()+col.getGreen(),
      70                 :            :                                                       getBlue()+col.getBlue()); }
      71                 :            :     Color operator*( Color col ) const { return Color((sal_uInt8)((sal_uInt32)col.getRed()*getRed()/SAL_MAX_UINT8),
      72                 :            :                                                       (sal_uInt8)((sal_uInt32)col.getGreen()*getGreen()/SAL_MAX_UINT8),
      73                 :            :                                                       (sal_uInt8)((sal_uInt32)col.getBlue()*getBlue()/SAL_MAX_UINT8)); }
      74                 :            :     Color operator*( sal_uInt8 n ) const { return Color((sal_uInt8)((sal_uInt32)n*getRed()/SAL_MAX_UINT8),
      75                 :            :                                                         (sal_uInt8)((sal_uInt32)n*getGreen()/SAL_MAX_UINT8),
      76                 :            :                                                         (sal_uInt8)((sal_uInt32)n*getBlue()/SAL_MAX_UINT8)); }
      77                 :            :     Color operator*( double n ) const { return Color((sal_uInt8)(n*getRed()+.5),
      78                 :            :                                                      (sal_uInt8)(n*getGreen()+.5),
      79                 :            :                                                      (sal_uInt8)(n*getBlue()+.5)); }
      80                 :            :     bool operator==( const Color& rhs ) const { return (getRed()==rhs.getRed() &&
      81                 :            :                                                         getGreen()==rhs.getGreen() &&
      82                 :            :                                                         getBlue()==rhs.getBlue()); }
      83                 :            :     bool operator!=( const Color& rhs ) const { return !(*this==rhs); }
      84                 :            :     double magnitude() const { return sqrt((double)getRed()*getRed()
      85                 :            :                                            + getGreen()*getGreen()
      86                 :            :                                            + getBlue()*getBlue()); }
      87                 :            : };
      88                 :            : 
      89                 :            : } // namespace vigra
      90                 :            : 
      91                 :            : #endif /* INCLUDED_BASEBMP_COLOR_HXX */
      92                 :            : 
      93                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10