Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/basegfx/pixel/bpixel.hxx
Line
Count
Source (jump to first uncovered line)
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>
23
#include <basegfx/color/bcolor.hxx>
24
25
namespace 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
37
            } maRGBA;
38
39
            struct
40
            {
41
                unsigned                                mnValue : 32;   // all values
42
            } maCombinedRGBA;
43
        } maPixelUnion;
44
45
    public:
46
        BPixel()
47
0
        {
48
0
            maPixelUnion.maCombinedRGBA.mnValue = 0;
49
0
        }
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
0
        {
55
0
            maPixelUnion.maRGBA.mnR = nRed;
56
0
            maPixelUnion.maRGBA.mnG = nGreen;
57
0
            maPixelUnion.maRGBA.mnB = nBlue;
58
0
            maPixelUnion.maRGBA.mnA = nAlpha;
59
0
        }
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
0
        {
65
0
            maPixelUnion.maRGBA.mnR = sal_uInt8((rColor.getRed() * 255.0) + 0.5);
66
0
            maPixelUnion.maRGBA.mnG = sal_uInt8((rColor.getGreen() * 255.0) + 0.5);
67
0
            maPixelUnion.maRGBA.mnB = sal_uInt8((rColor.getBlue() * 255.0) + 0.5);
68
0
            maPixelUnion.maRGBA.mnA = nAlpha;
69
0
        }
70
71
        // data access read
72
0
        sal_uInt8 getRed() const { return maPixelUnion.maRGBA.mnR; }
73
0
        sal_uInt8 getGreen() const { return maPixelUnion.maRGBA.mnG; }
74
0
        sal_uInt8 getBlue() const { return maPixelUnion.maRGBA.mnB; }
75
0
        sal_uInt8 getAlpha() const { return maPixelUnion.maRGBA.mnA; }
76
77
        // data access write
78
0
        void setRed(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnR = nNew; }
79
0
        void setGreen(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnG = nNew; }
80
0
        void setBlue(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnB = nNew; }
81
0
        void setAlpha(sal_uInt8 nNew) { maPixelUnion.maRGBA.mnA = nNew; }
82
83
        // comparators
84
        bool operator==( const BPixel& rPixel ) const
85
0
        {
86
0
            return (rPixel.maPixelUnion.maCombinedRGBA.mnValue == maPixelUnion.maCombinedRGBA.mnValue);
87
0
        }
88
89
        bool operator!=( const BPixel& rPixel ) const
90
0
        {
91
0
            return (rPixel.maPixelUnion.maCombinedRGBA.mnValue != maPixelUnion.maCombinedRGBA.mnValue);
92
0
        }
93
    };
94
95
96
} // end of namespace basegfx
97
98
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */