LibreOffice Module vcl (master)  1
Image.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 
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>
27 
28 #include <BitmapColorizeFilter.hxx>
29 
30 using namespace css;
31 
33 {
34 }
35 
36 Image::Image(const BitmapEx& rBitmapEx)
37 {
38  ImplInit(rBitmapEx);
39 }
40 
41 Image::Image(uno::Reference<graphic::XGraphic> const & rxGraphic)
42 {
43  const Graphic aGraphic(rxGraphic);
44  ImplInit(aGraphic.GetBitmapEx());
45 }
46 
47 Image::Image(const OUString & rFileUrl)
48 {
49  OUString sImageName;
50  if (rFileUrl.startsWith("private:graphicrepository/", &sImageName))
51  {
52  mpImplData = std::make_shared<ImplImage>(sImageName, Size());
53  }
54  else
55  {
56  Graphic aGraphic;
57  if (ERRCODE_NONE == GraphicFilter::LoadGraphic(rFileUrl, IMP_PNG, aGraphic))
58  {
59  ImplInit(aGraphic.GetBitmapEx());
60  }
61  }
62 }
63 
64 Image::Image(StockImage, const OUString & rFileUrl, Size aSpecificSize)
65  : mpImplData(std::make_shared<ImplImage>(rFileUrl, aSpecificSize))
66 {
67 }
68 
69 void Image::ImplInit(const BitmapEx& rBitmapEx)
70 {
71  if (!rBitmapEx.IsEmpty())
72  mpImplData = std::make_shared<ImplImage>(rBitmapEx);
73 }
74 
76 {
77  if (mpImplData)
78  return mpImplData->getSizePixel();
79  else
80  return Size();
81 }
82 
84 {
85  if (mpImplData)
86  return mpImplData->getBitmapEx();
87  else
88  return BitmapEx();
89 }
90 
91 bool Image::operator==(const Image& rImage) const
92 {
93  bool bRet = false;
94 
95  if (rImage.mpImplData == mpImplData)
96  bRet = true;
97  else if (!rImage.mpImplData || !mpImplData)
98  bRet = false;
99  else
100  bRet = rImage.mpImplData->isEqual(*mpImplData);
101 
102  return bRet;
103 }
104 
105 void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize)
106 {
107  if (!mpImplData || (!pOutDev->IsDeviceOutputNecessary() && pOutDev->GetConnectMetaFile() == nullptr))
108  return;
109 
110  Size aOutSize = pSize ? *pSize : pOutDev->PixelToLogic(mpImplData->getSizePixel());
111 
112  BitmapEx aRenderBmp = mpImplData->getBitmapExForHiDPI(bool(nStyle & DrawImageFlags::Disable));
113 
114  if (!(nStyle & DrawImageFlags::Disable) &&
117  {
118  BitmapEx aTempBitmapEx(aRenderBmp);
119 
121  {
122  const StyleSettings& rSettings = pOutDev->GetSettings().GetStyleSettings();
123  Color aColor;
124  if (nStyle & DrawImageFlags::Highlight)
125  aColor = rSettings.GetHighlightColor();
126  else
127  aColor = rSettings.GetDeactiveColor();
128 
129  BitmapFilter::Filter(aTempBitmapEx, BitmapColorizeFilter(aColor));
130  }
131 
132  if (nStyle & DrawImageFlags::SemiTransparent)
133  {
134  if (aTempBitmapEx.IsTransparent())
135  {
136  Bitmap aAlphaBmp(aTempBitmapEx.GetAlpha().GetBitmap());
137  aAlphaBmp.Adjust(50);
138  aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aAlphaBmp));
139  }
140  else
141  {
142  sal_uInt8 cErase = 128;
143  aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aTempBitmapEx.GetSizePixel(), &cErase));
144  }
145  }
146  aRenderBmp = aTempBitmapEx;
147  }
148 
149  pOutDev->DrawBitmapEx(rPos, aOutSize, aRenderBmp);
150 }
151 
152 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Size GetSizePixel() const
Definition: Image.cxx:75
bool Adjust(short nLuminancePercent, short nContrastPercent=0, short nChannelRPercent=0, short nChannelGPercent=0, short nChannelBPercent=0, double fGamma=1.0, bool bInvert=false, bool msoBrightness=false)
Change various global color characteristics.
Definition: bitmap3.cxx:1044
bool operator==(const Image &rImage) const
Definition: Image.cxx:91
const Color & GetDeactiveColor() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Bitmap const & GetBitmap() const
Definition: alpha.cxx:70
const StyleSettings & GetStyleSettings() const
GDIMetaFile * GetConnectMetaFile() const
Definition: outdev.hxx:417
const Color & GetHighlightColor() const
void Draw(OutputDevice *pOutDev, const Point &rPos, DrawImageFlags nStyle, const Size *pSize=nullptr)
Definition: Image.cxx:105
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
Bitmap GetBitmap(const Color *pTransReplaceColor=nullptr) const
Definition: bitmapex.cxx:236
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
bool IsEmpty() const
Definition: bitmapex.cxx:203
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Definition: graph.cxx:341
bool IsTransparent() const
Definition: bitmapex.cxx:221
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1185
StockImage
Definition: image.hxx:49
AlphaMask GetAlpha() const
Definition: bitmapex.cxx:268
#define ERRCODE_NONE
Definition: errcode.hxx:198
unsigned char sal_uInt8
#define IMP_PNG
Definition: image.hxx:51
Image()
Definition: Image.cxx:32
BitmapEx GetBitmapEx() const
Definition: Image.cxx:83
std::shared_ptr< ImplImage > mpImplData
Definition: image.hxx:79
SAL_DLLPRIVATE void ImplInit(BitmapEx const &rBmpEx)
Definition: Image.cxx:69
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
bool IsDeviceOutputNecessary() const
Definition: outdev.hxx:589
DrawImageFlags
Definition: outdev.hxx:172