LibreOffice Module drawinglayer (master) 1
GlowSoftEgdeShadowTools.cxx
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
21#include <vcl/bitmapex.hxx>
22#include <vcl/BitmapFilter.hxx>
25
27{
28/* Returns 8-bit alpha mask created from passed mask.
29
30 Negative fErodeDilateRadius values mean erode, positive - dilate.
31 nTransparency defines minimal transparency level.
32*/
33AlphaMask ProcessAndBlurAlphaMask(const Bitmap& rMask, double fErodeDilateRadius,
34 double fBlurRadius, sal_uInt8 nTransparency, bool bConvertTo1Bit)
35{
36 // Only completely white pixels on the initial mask must be considered for transparency. Any
37 // other color must be treated as black. This creates 1-bit B&W bitmap.
38 BitmapEx mask(bConvertTo1Bit ? rMask.CreateMask(COL_WHITE) : rMask);
39
40 // Scaling down increases performance without noticeable quality loss. Additionally,
41 // current blur implementation can only handle blur radius between 2 and 254.
42 Size aSize = mask.GetSizePixel();
43 double fScale = 1.0;
44 while (fBlurRadius > 254 || aSize.Height() > 1000 || aSize.Width() > 1000)
45 {
46 fScale /= 2;
47 fBlurRadius /= 2;
48 fErodeDilateRadius /= 2;
49 aSize.setHeight(aSize.Height() / 2);
50 aSize.setWidth(aSize.Width() / 2);
51 }
52
53 // BmpScaleFlag::NearestNeighbor is important for following color replacement
54 mask.Scale(fScale, fScale, BmpScaleFlag::NearestNeighbor);
55
56 if (fErodeDilateRadius > 0)
57 BitmapFilter::Filter(mask, BitmapDilateFilter(fErodeDilateRadius));
58 else if (fErodeDilateRadius < 0)
59 BitmapFilter::Filter(mask, BitmapErodeFilter(-fErodeDilateRadius, 0xFF));
60
61 if (nTransparency != 255)
62 {
63 const Color aTransparency(nTransparency, nTransparency, nTransparency);
64 mask.Replace(COL_WHITE, aTransparency);
65 }
66
67 // We need 8-bit grey mask for blurring
68 mask.Convert(BmpConversion::N8BitGreys);
69
70 // calculate blurry effect
72
73 mask.Scale(rMask.GetSizePixel());
74
75 mask.Invert(); // convert transparency to alpha
76
77 return AlphaMask(mask.GetBitmap());
78}
79
82 double nAmount)
83{
85 basegfx::B2DRange viewport(rViewInfo.getViewport());
86 viewport.grow(nAmount);
87 aRetval.setViewport(viewport);
88 return aRetval;
89}
90
91} // end of namespace drawinglayer::primitive2d
92
93/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool Invert()
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
bool Convert(BmpConversion eConversion)
Bitmap GetBitmap(Color aTransparentReplaceColor) const
void Replace(const Color &rSearchColor, const Color &rReplaceColor)
const Size & GetSizePixel() const
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
Bitmap CreateMask(const Color &rTransColor) const
Size GetSizePixel() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
void grow(TYPE fValue)
const basegfx::B2DRange & getViewport() const
Empty viewport means everything is visible.
void setViewport(const basegfx::B2DRange &rNew)
constexpr ::Color COL_WHITE(0xFF, 0xFF, 0xFF)
AlphaMask ProcessAndBlurAlphaMask(const Bitmap &rMask, double fErodeDilateRadius, double fBlurRadius, sal_uInt8 nTransparency, bool bConvertTo1Bit)
drawinglayer::geometry::ViewInformation2D expandB2DRangeAtViewInformation2D(const drawinglayer::geometry::ViewInformation2D &rViewInfo, double nAmount)
unsigned char sal_uInt8