Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/drawinglayer/source/primitive2d/BitmapAlphaPrimitive2D.cxx
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
#include <drawinglayer/primitive2d/BitmapAlphaPrimitive2D.hxx>
21
#include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
22
#include <drawinglayer/primitive2d/unifiedtransparenceprimitive2d.hxx>
23
#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
24
#include <com/sun/star/awt/XBitmap.hpp>
25
#include <utility>
26
27
using namespace com::sun::star;
28
29
namespace drawinglayer::primitive2d
30
{
31
Primitive2DReference BitmapAlphaPrimitive2D::create2DDecomposition(
32
    const geometry::ViewInformation2D& /*rViewInformation*/) const
33
0
{
34
0
    if (basegfx::fTools::equal(getTransparency(), 1.0))
35
0
    {
36
        // completely transparent, done
37
0
        return nullptr;
38
0
    }
39
40
0
    if (getBitmap().IsEmpty())
41
0
    {
42
        // no geometry, done
43
0
        return nullptr;
44
0
    }
45
46
0
    if (basegfx::fTools::equalZero(getTransparency()))
47
0
    {
48
        // no transparency, use simple BitmapPrimitive2D
49
0
        return Primitive2DReference{ new BitmapPrimitive2D(getBitmap(), getTransform()) };
50
0
    }
51
52
    // default: embed to UnifiedTransparencePrimitive2D
53
0
    Primitive2DContainer aContent{ new BitmapPrimitive2D(getBitmap(), getTransform()) };
54
0
    return Primitive2DReference{ new UnifiedTransparencePrimitive2D(std::move(aContent),
55
0
                                                                    getTransparency()) };
56
0
}
57
58
BitmapAlphaPrimitive2D::BitmapAlphaPrimitive2D(BitmapEx xXBitmap, basegfx::B2DHomMatrix aTransform,
59
                                               double fTransparency)
60
0
    : maBitmap(std::move(xXBitmap))
61
0
    , maTransform(std::move(aTransform))
62
0
    , mfTransparency(std::max(0.0, std::min(1.0, fTransparency)))
63
0
{
64
0
}
65
66
bool BitmapAlphaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
67
0
{
68
0
    if (BasePrimitive2D::operator==(rPrimitive))
69
0
    {
70
0
        const BitmapAlphaPrimitive2D& rCompare
71
0
            = static_cast<const BitmapAlphaPrimitive2D&>(rPrimitive);
72
73
0
        return (getBitmap() == rCompare.getBitmap() && getTransform() == rCompare.getTransform()
74
0
                && basegfx::fTools::equal(getTransparency(), rCompare.getTransparency()));
75
0
    }
76
77
0
    return false;
78
0
}
79
80
basegfx::B2DRange
81
BitmapAlphaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const
82
0
{
83
0
    basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
84
0
    aRetval.transform(maTransform);
85
0
    return aRetval;
86
0
}
87
88
sal_Int64 BitmapAlphaPrimitive2D::estimateUsage()
89
0
{
90
0
    if (getBitmap().IsEmpty())
91
0
    {
92
0
        return 0;
93
0
    }
94
0
    return getBitmap().GetSizeBytes();
95
0
}
96
97
// provide unique ID
98
sal_uInt32 BitmapAlphaPrimitive2D::getPrimitive2DID() const
99
0
{
100
0
    return PRIMITIVE2D_ID_BITMAPALPHAPRIMITIVE2D;
101
0
}
102
103
} // end of namespace
104
105
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */