tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / include / basegfx / pixel / bpixel.hxx
blob50209ec2ce47f63c6e3f9c0819a091808bd7f00e
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 #pragma once
22 #include <sal/types.h>
23 #include <basegfx/color/bcolor.hxx>
25 namespace basegfx
27 class BPixel final
29 union
31 struct
33 unsigned mnR : 8; // red intensity
34 unsigned mnG : 8; // green intensity
35 unsigned mnB : 8; // blue intensity
36 unsigned mnA : 8; // opacity, 0 == full transparence
37 } maRGBA;
39 struct
41 unsigned mnValue : 32; // all values
42 } maCombinedRGBA;
43 } maPixelUnion;
45 public:
46 BPixel()
48 maPixelUnion.maCombinedRGBA.mnValue = 0;
51 // use explicit here to make sure everyone knows what he is doing. Values range from
52 // 0..255 integer here.
53 explicit BPixel(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue, sal_uInt8 nAlpha)
55 maPixelUnion.maRGBA.mnR = nRed;
56 maPixelUnion.maRGBA.mnG = nGreen;
57 maPixelUnion.maRGBA.mnB = nBlue;
58 maPixelUnion.maRGBA.mnA = nAlpha;
61 // constructor from BColor which uses double precision color, so change it
62 // to local integer format. It will also be clamped here.
63 BPixel(const BColor& rColor, sal_uInt8 nAlpha)
65 maPixelUnion.maRGBA.mnR = sal_uInt8((rColor.getRed() * 255.0) + 0.5);
66 maPixelUnion.maRGBA.mnG = sal_uInt8((rColor.getGreen() * 255.0) + 0.5);
67 maPixelUnion.maRGBA.mnB = sal_uInt8((rColor.getBlue() * 255.0) + 0.5);
68 maPixelUnion.maRGBA.mnA = nAlpha;
71 // data access read
72 sal_uInt8 getRed() const { return maPixelUnion.maRGBA.mnR; }
73 sal_uInt8 getGreen() const { return maPixelUnion.maRGBA.mnG; }
74 sal_uInt8 getBlue() const { return maPixelUnion.maRGBA.mnB; }
75 sal_uInt8 getAlpha() const { return maPixelUnion.maRGBA.mnA; }
77 // data access write
78 void setRed(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnR = nNew; }
79 void setGreen(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnG = nNew; }
80 void setBlue(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnB = nNew; }
81 void setAlpha(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnA = nNew; }
83 // comparators
84 bool operator==( const BPixel& rPixel ) const
86 return (rPixel.maPixelUnion.maCombinedRGBA.mnValue == maPixelUnion.maCombinedRGBA.mnValue);
89 bool operator!=( const BPixel& rPixel ) const
91 return (rPixel.maPixelUnion.maCombinedRGBA.mnValue != maPixelUnion.maCombinedRGBA.mnValue);
96 } // end of namespace basegfx
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */