bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / image / Image.cxx
blob0cb7c5d44949af67dd3aa18a0f8b5ab62ee7a2ec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <image.h>
28 #include <BitmapColorizeFilter.hxx>
30 using namespace css;
32 Image::Image()
36 Image::Image(const BitmapEx& rBitmapEx)
38 ImplInit(rBitmapEx);
41 Image::Image(uno::Reference<graphic::XGraphic> const & rxGraphic)
43 if (rxGraphic.is())
45 const Graphic aGraphic(rxGraphic);
47 OUString aPath;
48 if (aGraphic.getOriginURL().startsWith("private:graphicrepository/", &aPath))
49 mpImplData = std::make_shared<ImplImage>(aPath, Size());
50 else
51 ImplInit(aGraphic.GetBitmapEx());
55 Image::Image(const OUString & rFileUrl)
57 OUString sImageName;
58 if (rFileUrl.startsWith("private:graphicrepository/", &sImageName))
59 mpImplData = std::make_shared<ImplImage>(sImageName, Size());
60 else
62 Graphic aGraphic;
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
81 if (mpImplData)
82 return mpImplData->getStock();
83 return OUString();
86 Size Image::GetSizePixel() const
88 if (mpImplData)
89 return mpImplData->getSizePixel();
90 else
91 return Size();
94 BitmapEx Image::GetBitmapEx() const
96 if (mpImplData)
97 return mpImplData->getBitmapEx();
98 else
99 return BitmapEx();
102 bool Image::operator==(const Image& rImage) const
104 bool bRet = false;
106 if (rImage.mpImplData == mpImplData)
107 bRet = true;
108 else if (!rImage.mpImplData || !mpImplData)
109 bRet = false;
110 else
111 bRet = rImage.mpImplData->isEqual(*mpImplData);
113 return bRet;
116 void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize)
118 if (!mpImplData || (!pOutDev->IsDeviceOutputNecessary() && pOutDev->GetConnectMetaFile() == nullptr))
119 return;
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();
134 Color aColor;
135 if (nStyle & DrawImageFlags::Highlight)
136 aColor = rSettings.GetHighlightColor();
137 else
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));
151 else
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: */