Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / basegfx / pixel / bpixel.hxx
blob5ac2e22b2e81a4aa20ac6cbcddd527453906b995
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_BASEGFX_PIXEL_BPIXEL_HXX
21 #define INCLUDED_BASEGFX_PIXEL_BPIXEL_HXX
23 #include <sal/types.h>
24 #include <basegfx/numeric/ftools.hxx>
25 #include <basegfx/color/bcolor.hxx>
26 #include <basegfx/basegfxdllapi.h>
28 namespace basegfx
30 class BASEGFX_DLLPUBLIC BPixel
32 protected:
33 union
35 struct
37 unsigned mnR : 8; // red intensity
38 unsigned mnG : 8; // green intensity
39 unsigned mnB : 8; // blue intensity
40 unsigned mnO : 8; // opacity, 0 == full transparence
41 } maRGBO;
43 struct
45 unsigned mnValue : 32; // all values
46 } maCombinedRGBO;
47 } maPixelUnion;
49 public:
50 BPixel()
52 maPixelUnion.maCombinedRGBO.mnValue = 0L;
55 // use explicit here to make sure everyone knows what he is doing. Values range from
56 // 0..255 integer here.
57 explicit BPixel(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue, sal_uInt8 nOpacity)
59 maPixelUnion.maRGBO.mnR = nRed;
60 maPixelUnion.maRGBO.mnG = nGreen;
61 maPixelUnion.maRGBO.mnB = nBlue;
62 maPixelUnion.maRGBO.mnO = nOpacity;
65 // constructor from BColor which uses double precision color, so change it
66 // to local integer format. It will also be clamped here.
67 BPixel(const BColor& rColor, sal_uInt8 nOpacity)
69 maPixelUnion.maRGBO.mnR = sal_uInt8((rColor.getRed() * 255.0) + 0.5);
70 maPixelUnion.maRGBO.mnG = sal_uInt8((rColor.getGreen() * 255.0) + 0.5);
71 maPixelUnion.maRGBO.mnB = sal_uInt8((rColor.getBlue() * 255.0) + 0.5);
72 maPixelUnion.maRGBO.mnO = nOpacity;
75 // data access read
76 sal_uInt8 getRed() const { return maPixelUnion.maRGBO.mnR; }
77 sal_uInt8 getGreen() const { return maPixelUnion.maRGBO.mnG; }
78 sal_uInt8 getBlue() const { return maPixelUnion.maRGBO.mnB; }
79 sal_uInt8 getOpacity() const { return maPixelUnion.maRGBO.mnO; }
81 // data access write
82 void setRed(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnR = nNew; }
83 void setGreen(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnG = nNew; }
84 void setBlue(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnB = nNew; }
85 void setOpacity(sal_uInt8 nNew) { maPixelUnion.maRGBO.mnO = nNew; }
87 // comparators
88 bool operator==( const BPixel& rPixel ) const
90 return (rPixel.maPixelUnion.maCombinedRGBO.mnValue == maPixelUnion.maCombinedRGBO.mnValue);
93 bool operator!=( const BPixel& rPixel ) const
95 return (rPixel.maPixelUnion.maCombinedRGBO.mnValue != maPixelUnion.maCombinedRGBO.mnValue);
100 } // end of namespace basegfx
102 #endif // INCLUDED_BASEGFX_PIXEL_BPIXEL_HXX
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */