LibreOffice Module basegfx (master) 1
bpixel.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/types.h>
24
25namespace basegfx
26{
27 class BPixel final
28 {
29 union
30 {
31 struct
32 {
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
38
39 struct
40 {
41 unsigned mnValue : 32; // all values
44
45 public:
47 {
48 maPixelUnion.maCombinedRGBA.mnValue = 0;
49 }
50
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)
54 {
55 maPixelUnion.maRGBA.mnR = nRed;
56 maPixelUnion.maRGBA.mnG = nGreen;
57 maPixelUnion.maRGBA.mnB = nBlue;
58 maPixelUnion.maRGBA.mnA = nAlpha;
59 }
60
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)
64 {
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;
69 }
70
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; }
76
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; }
82
83 // comparators
84 bool operator==( const BPixel& rPixel ) const
85 {
86 return (rPixel.maPixelUnion.maCombinedRGBA.mnValue == maPixelUnion.maCombinedRGBA.mnValue);
87 }
88
89 bool operator!=( const BPixel& rPixel ) const
90 {
91 return (rPixel.maPixelUnion.maCombinedRGBA.mnValue != maPixelUnion.maCombinedRGBA.mnValue);
92 }
93 };
94
95
96} // end of namespace basegfx
97
98/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base Color class with three double values.
Definition: bcolor.hxx:41
double getBlue() const
Definition: bcolor.hxx:80
double getRed() const
Definition: bcolor.hxx:78
double getGreen() const
Definition: bcolor.hxx:79
sal_uInt8 getAlpha() const
Definition: bpixel.hxx:75
struct basegfx::BPixel::@1::@3 maCombinedRGBA
bool operator==(const BPixel &rPixel) const
Definition: bpixel.hxx:84
void setAlpha(sal_uInt8 nNew)
Definition: bpixel.hxx:81
unsigned mnG
Definition: bpixel.hxx:34
sal_uInt8 getBlue() const
Definition: bpixel.hxx:74
BPixel(const BColor &rColor, sal_uInt8 nAlpha)
Definition: bpixel.hxx:63
sal_uInt8 getGreen() const
Definition: bpixel.hxx:73
void setRed(sal_uInt8 nNew)
Definition: bpixel.hxx:78
unsigned mnA
Definition: bpixel.hxx:36
sal_uInt8 getRed() const
Definition: bpixel.hxx:72
BPixel(sal_uInt8 nRed, sal_uInt8 nGreen, sal_uInt8 nBlue, sal_uInt8 nAlpha)
Definition: bpixel.hxx:53
void setBlue(sal_uInt8 nNew)
Definition: bpixel.hxx:80
void setGreen(sal_uInt8 nNew)
Definition: bpixel.hxx:79
bool operator!=(const BPixel &rPixel) const
Definition: bpixel.hxx:89
union basegfx::BPixel::@1 maPixelUnion
unsigned mnR
Definition: bpixel.hxx:33
struct basegfx::BPixel::@1::@2 maRGBA
unsigned mnB
Definition: bpixel.hxx:35
unsigned mnValue
Definition: bpixel.hxx:41
unsigned char sal_uInt8