Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/drawinglayer/source/primitive2d/GlowSoftEgdeShadowTools.cxx
Line
Count
Source
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 "GlowSoftEgdeShadowTools.hxx"
21
#include <tools/color.hxx>
22
#include <vcl/bitmap/BitmapBasicMorphologyFilter.hxx>
23
#include <vcl/bitmap/BitmapFilterStackBlur.hxx>
24
25
namespace drawinglayer::primitive2d
26
{
27
/* Returns 8-bit alpha mask created from passed mask.
28
29
   Negative fErodeDilateRadius values mean erode, positive - dilate.
30
   nTransparency defines minimal transparency level.
31
*/
32
AlphaMask ProcessAndBlurAlphaMask(const AlphaMask& rMask, double fErodeDilateRadius,
33
                                  double fBlurRadius, sal_uInt8 nTransparency, bool bConvertTo1Bit)
34
0
{
35
    // Invert it to operate in the transparency domain. Trying to update this method to
36
    // work in the alpha domain is fraught with hazards.
37
0
    AlphaMask tmpMask = rMask;
38
0
    tmpMask.Invert();
39
40
    // Only completely white pixels on the initial mask must be considered for transparency. Any
41
    // other color must be treated as black. This creates 1-bit B&W bitmap.
42
0
    Bitmap mask = bConvertTo1Bit ? tmpMask.GetBitmap().CreateMask(COL_WHITE) : tmpMask.GetBitmap();
43
44
    // Scaling down increases performance without noticeable quality loss. Additionally,
45
    // current blur implementation can only handle blur radius between 2 and 254.
46
0
    Size aSize = mask.GetSizePixel();
47
0
    double fScale = 1.0;
48
0
    while (fBlurRadius > 254 || aSize.Height() > 1000 || aSize.Width() > 1000)
49
0
    {
50
0
        fScale /= 2;
51
0
        fBlurRadius /= 2;
52
0
        fErodeDilateRadius /= 2;
53
0
        aSize /= 2;
54
0
    }
55
56
    // BmpScaleFlag::NearestNeighbor is important for following color replacement
57
0
    mask.Scale(fScale, fScale, BmpScaleFlag::NearestNeighbor);
58
59
0
    if (fErodeDilateRadius > 0)
60
0
        BitmapFilter::Filter(mask, BitmapDilateFilter(fErodeDilateRadius));
61
0
    else if (fErodeDilateRadius < 0)
62
0
        BitmapFilter::Filter(mask, BitmapErodeFilter(-fErodeDilateRadius, 0xFF));
63
64
0
    if (nTransparency)
65
0
    {
66
0
        const Color aTransparency(nTransparency, nTransparency, nTransparency);
67
0
        mask.Replace(COL_BLACK, aTransparency);
68
0
    }
69
70
    // We need 8-bit grey mask for blurring
71
0
    mask.Convert(BmpConversion::N8BitGreys);
72
73
    // calculate blurry effect
74
0
    BitmapFilter::Filter(mask, BitmapFilterStackBlur(fBlurRadius));
75
76
0
    mask.Scale(rMask.GetSizePixel());
77
78
    // And switch to the alpha domain.
79
0
    mask.Invert();
80
81
0
    return AlphaMask(mask);
82
0
}
83
84
drawinglayer::geometry::ViewInformation2D
85
expandB2DRangeAtViewInformation2D(const drawinglayer::geometry::ViewInformation2D& rViewInfo,
86
                                  double nAmount)
87
0
{
88
0
    drawinglayer::geometry::ViewInformation2D aRetval(rViewInfo);
89
0
    basegfx::B2DRange viewport(rViewInfo.getViewport());
90
0
    viewport.grow(nAmount);
91
0
    aRetval.setViewport(viewport);
92
0
    return aRetval;
93
0
}
94
95
} // end of namespace drawinglayer::primitive2d
96
97
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */