xref: /aoo4110/main/cppcanvas/inc/cppcanvas/color.hxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _CPPCANVAS_COLOR_HXX
25 #define _CPPCANVAS_COLOR_HXX
26 
27 #include <com/sun/star/uno/Sequence.hxx>
28 
29 #include <boost/shared_ptr.hpp>
30 
31 
32 /* Definition of Color class */
33 
34 namespace cppcanvas
35 {
36     class Color
37     {
38     public:
39         /** Color in the sRGB color space, plus alpha channel
40 
41         	The four bytes of the sal_uInt32 are allocated as follows
42         	to the color channels and alpha: 0xRRGGBBAA.
43          */
44         typedef sal_uInt32 IntSRGBA;
45 
~Color()46         virtual ~Color() {}
47 
48         virtual IntSRGBA 									getIntSRGBA( ::com::sun::star::uno::Sequence< double >& rDeviceColor ) const = 0;
49         virtual ::com::sun::star::uno::Sequence< double > 	getDeviceColor( IntSRGBA aSRGBA ) const = 0;
50     };
51 
52     typedef ::boost::shared_ptr< ::cppcanvas::Color > ColorSharedPtr;
53 
getRed(Color::IntSRGBA nCol)54     inline sal_uInt8 getRed( Color::IntSRGBA nCol )
55     {
56         return static_cast<sal_uInt8>( (nCol&0xFF000000U) >> 24U );
57     }
58 
getGreen(Color::IntSRGBA nCol)59     inline sal_uInt8 getGreen( Color::IntSRGBA nCol )
60     {
61         return static_cast<sal_uInt8>( (nCol&0x00FF0000U) >> 16U );
62     }
63 
getBlue(Color::IntSRGBA nCol)64     inline sal_uInt8 getBlue( Color::IntSRGBA nCol )
65     {
66         return static_cast<sal_uInt8>( (nCol&0x0000FF00U) >> 8U );
67     }
68 
getAlpha(Color::IntSRGBA nCol)69     inline sal_uInt8 getAlpha( Color::IntSRGBA nCol )
70     {
71         return static_cast<sal_uInt8>( nCol&0x000000FFU );
72     }
73 
makeColor(sal_uInt8 nRed,sal_uInt8 nGreen,sal_uInt8 nBlue,sal_uInt8 nAlpha)74     inline Color::IntSRGBA makeColor( sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue, sal_uInt8 nAlpha )
75     {
76         return (nRed << 24U)|(nGreen << 16U)|(nBlue << 8U)|(nAlpha);
77     }
78 
unMakeColor(sal_uInt8 nAlpha,sal_uInt8 nRed,sal_uInt8 nGreen,sal_uInt8 nBlue)79     inline sal_Int32 unMakeColor( sal_uInt8 nAlpha, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
80     {
81         return (nAlpha << 24U)|(nRed << 16U)|(nGreen << 8U)|(nBlue);
82     }
83 
makeColorARGB(sal_uInt8 nAlpha,sal_uInt8 nRed,sal_uInt8 nGreen,sal_uInt8 nBlue)84     inline sal_Int32 makeColorARGB( sal_uInt8 nAlpha, sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue)
85     {
86         return (nAlpha << 24U)|(nRed << 16U)|(nGreen << 8U)|(nBlue);
87     }
88 
89 }
90 
91 #endif /* _CPPCANVAS_COLOR_HXX */
92