1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/settings.hxx>
21 #include <vcl/outdev.hxx>
22 #include <vcl/graph.hxx>
23 #include <vcl/graphicfilter.hxx>
24 #include <vcl/image.hxx>
25 #include <sal/types.h>
28 #include <BitmapColorizeFilter.hxx>
36 Image::Image(const BitmapEx
& rBitmapEx
)
41 Image::Image(uno::Reference
<graphic::XGraphic
> const & rxGraphic
)
45 const Graphic
aGraphic(rxGraphic
);
48 if (aGraphic
.getOriginURL().startsWith("private:graphicrepository/", &aPath
))
49 mpImplData
= std::make_shared
<ImplImage
>(aPath
, Size());
51 ImplInit(aGraphic
.GetBitmapEx());
55 Image::Image(const OUString
& rFileUrl
)
58 if (rFileUrl
.startsWith("private:graphicrepository/", &sImageName
))
59 mpImplData
= std::make_shared
<ImplImage
>(sImageName
, Size());
63 if (ERRCODE_NONE
== GraphicFilter::LoadGraphic(rFileUrl
, IMP_PNG
, aGraphic
))
64 ImplInit(aGraphic
.GetBitmapEx());
68 Image::Image(StockImage
, const OUString
& rFileUrl
, Size aSpecificSize
)
69 : mpImplData(std::make_shared
<ImplImage
>(rFileUrl
, aSpecificSize
))
73 void Image::ImplInit(const BitmapEx
& rBitmapEx
)
75 if (!rBitmapEx
.IsEmpty())
76 mpImplData
= std::make_shared
<ImplImage
>(rBitmapEx
);
79 OUString
Image::GetStock() const
82 return mpImplData
->getStock();
86 Size
Image::GetSizePixel() const
89 return mpImplData
->getSizePixel();
94 BitmapEx
Image::GetBitmapEx() const
97 return mpImplData
->getBitmapEx();
102 bool Image::operator==(const Image
& rImage
) const
106 if (rImage
.mpImplData
== mpImplData
)
108 else if (!rImage
.mpImplData
|| !mpImplData
)
111 bRet
= rImage
.mpImplData
->isEqual(*mpImplData
);
116 void Image::Draw(OutputDevice
* pOutDev
, const Point
& rPos
, DrawImageFlags nStyle
, const Size
* pSize
)
118 if (!mpImplData
|| (!pOutDev
->IsDeviceOutputNecessary() && pOutDev
->GetConnectMetaFile() == nullptr))
121 Size aOutSize
= pSize
? *pSize
: pOutDev
->PixelToLogic(mpImplData
->getSizePixel());
123 BitmapEx aRenderBmp
= mpImplData
->getBitmapExForHiDPI(bool(nStyle
& DrawImageFlags::Disable
));
125 if (!(nStyle
& DrawImageFlags::Disable
) &&
126 (nStyle
& (DrawImageFlags::ColorTransform
| DrawImageFlags::Highlight
|
127 DrawImageFlags::Deactive
| DrawImageFlags::SemiTransparent
)))
129 BitmapEx
aTempBitmapEx(aRenderBmp
);
131 if (nStyle
& (DrawImageFlags::Highlight
| DrawImageFlags::Deactive
))
133 const StyleSettings
& rSettings
= pOutDev
->GetSettings().GetStyleSettings();
135 if (nStyle
& DrawImageFlags::Highlight
)
136 aColor
= rSettings
.GetHighlightColor();
138 aColor
= rSettings
.GetDeactiveColor();
140 BitmapFilter::Filter(aTempBitmapEx
, BitmapColorizeFilter(aColor
));
143 if (nStyle
& DrawImageFlags::SemiTransparent
)
145 if (aTempBitmapEx
.IsTransparent())
147 Bitmap
aAlphaBmp(aTempBitmapEx
.GetAlpha().GetBitmap());
148 aAlphaBmp
.Adjust(50);
149 aTempBitmapEx
= BitmapEx(aTempBitmapEx
.GetBitmap(), AlphaMask(aAlphaBmp
));
153 sal_uInt8 cErase
= 128;
154 aTempBitmapEx
= BitmapEx(aTempBitmapEx
.GetBitmap(), AlphaMask(aTempBitmapEx
.GetSizePixel(), &cErase
));
157 aRenderBmp
= aTempBitmapEx
;
160 pOutDev
->DrawBitmapEx(rPos
, aOutSize
, aRenderBmp
);
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */