1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/color/bcolor.hxx>
25 #include <basegfx/basegfxdllapi.h>
35 unsigned mnR
: 8; // red intensity
36 unsigned mnG
: 8; // green intensity
37 unsigned mnB
: 8; // blue intensity
38 unsigned mnO
: 8; // opacity, 0 == full transparence
43 unsigned mnValue
: 32; // all values
50 maPixelUnion
.maCombinedRGBO
.mnValue
= 0;
53 // use explicit here to make sure everyone knows what he is doing. Values range from
54 // 0..255 integer here.
55 explicit BPixel(sal_uInt8 nRed
, sal_uInt8 nGreen
, sal_uInt8 nBlue
, sal_uInt8 nOpacity
)
57 maPixelUnion
.maRGBO
.mnR
= nRed
;
58 maPixelUnion
.maRGBO
.mnG
= nGreen
;
59 maPixelUnion
.maRGBO
.mnB
= nBlue
;
60 maPixelUnion
.maRGBO
.mnO
= nOpacity
;
63 // constructor from BColor which uses double precision color, so change it
64 // to local integer format. It will also be clamped here.
65 BPixel(const BColor
& rColor
, sal_uInt8 nOpacity
)
67 maPixelUnion
.maRGBO
.mnR
= sal_uInt8((rColor
.getRed() * 255.0) + 0.5);
68 maPixelUnion
.maRGBO
.mnG
= sal_uInt8((rColor
.getGreen() * 255.0) + 0.5);
69 maPixelUnion
.maRGBO
.mnB
= sal_uInt8((rColor
.getBlue() * 255.0) + 0.5);
70 maPixelUnion
.maRGBO
.mnO
= nOpacity
;
74 sal_uInt8
getRed() const { return maPixelUnion
.maRGBO
.mnR
; }
75 sal_uInt8
getGreen() const { return maPixelUnion
.maRGBO
.mnG
; }
76 sal_uInt8
getBlue() const { return maPixelUnion
.maRGBO
.mnB
; }
77 sal_uInt8
getOpacity() const { return maPixelUnion
.maRGBO
.mnO
; }
80 void setRed(sal_uInt8 nNew
) { maPixelUnion
.maRGBO
.mnR
= nNew
; }
81 void setGreen(sal_uInt8 nNew
) { maPixelUnion
.maRGBO
.mnG
= nNew
; }
82 void setBlue(sal_uInt8 nNew
) { maPixelUnion
.maRGBO
.mnB
= nNew
; }
83 void setOpacity(sal_uInt8 nNew
) { maPixelUnion
.maRGBO
.mnO
= nNew
; }
86 bool operator==( const BPixel
& rPixel
) const
88 return (rPixel
.maPixelUnion
.maCombinedRGBO
.mnValue
== maPixelUnion
.maCombinedRGBO
.mnValue
);
91 bool operator!=( const BPixel
& rPixel
) const
93 return (rPixel
.maPixelUnion
.maCombinedRGBO
.mnValue
!= maPixelUnion
.maCombinedRGBO
.mnValue
);
98 } // end of namespace basegfx
100 #endif // INCLUDED_BASEGFX_PIXEL_BPIXEL_HXX
102 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */