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
29
30using namespace css;
31
33{
34}
35
36Image::Image(const BitmapEx& rBitmapEx)
37{
38 ImplInit(rBitmapEx);
39}
40
41Image::Image(uno::Reference<graphic::XGraphic> const & rxGraphic)
42{
43 if (rxGraphic.is())
44 {
45 const Graphic aGraphic(rxGraphic);
46
47 OUString aPath;
48 if (aGraphic.getOriginURL().startsWith("private:graphicrepository/", &aPath))
49 mpImplData = std::make_shared<ImplImage>(aPath);
50 else if (aGraphic.GetType() == GraphicType::GdiMetafile)
51 mpImplData = std::make_shared<ImplImage>(aGraphic.GetGDIMetaFile());
52 else
53 ImplInit(aGraphic.GetBitmapEx());
54 }
55}
56
57Image::Image(const OUString & rFileUrl)
58{
59 OUString sImageName;
60 if (rFileUrl.startsWith("private:graphicrepository/", &sImageName))
61 mpImplData = std::make_shared<ImplImage>(sImageName);
62 else
63 {
64 Graphic aGraphic;
65 if (ERRCODE_NONE == GraphicFilter::LoadGraphic(rFileUrl, IMP_PNG, aGraphic))
66 ImplInit(aGraphic.GetBitmapEx());
67 }
68}
69
70Image::Image(StockImage, const OUString & rFileUrl)
71 : mpImplData(std::make_shared<ImplImage>(rFileUrl))
72{
73}
74
75void Image::ImplInit(const BitmapEx& rBitmapEx)
76{
77 if (!rBitmapEx.IsEmpty())
78 mpImplData = std::make_shared<ImplImage>(rBitmapEx);
79}
80
81OUString Image::GetStock() const
82{
83 if (mpImplData)
84 return mpImplData->getStock();
85 return OUString();
86}
87
89{
90 if (mpImplData)
91 return mpImplData->getSizePixel();
92 else
93 return Size();
94}
95
97{
98 if (mpImplData)
99 return mpImplData->getBitmapEx();
100 else
101 return BitmapEx();
102}
103
104bool Image::operator==(const Image& rImage) const
105{
106 bool bRet = false;
107
108 if (rImage.mpImplData == mpImplData)
109 bRet = true;
110 else if (!rImage.mpImplData || !mpImplData)
111 bRet = false;
112 else
113 bRet = rImage.mpImplData->isEqual(*mpImplData);
114
115 return bRet;
116}
117
118void Image::Draw(OutputDevice* pOutDev, const Point& rPos, DrawImageFlags nStyle, const Size* pSize)
119{
120 if (!mpImplData || (!pOutDev->IsDeviceOutputNecessary() && pOutDev->GetConnectMetaFile() == nullptr))
121 return;
122
123 Size aOutSize = pSize ? *pSize : pOutDev->PixelToLogic(mpImplData->getSizePixel());
124
125 BitmapEx aRenderBmp = mpImplData->getBitmapExForHiDPI(bool(nStyle & DrawImageFlags::Disable), pOutDev->GetGraphics());
126
127 if (!(nStyle & DrawImageFlags::Disable) &&
130 {
131 BitmapEx aTempBitmapEx(aRenderBmp);
132
134 {
135 const StyleSettings& rSettings = pOutDev->GetSettings().GetStyleSettings();
136 Color aColor;
137 if (nStyle & DrawImageFlags::Highlight)
138 aColor = rSettings.GetHighlightColor();
139 else
140 aColor = rSettings.GetDeactiveColor();
141
142 BitmapFilter::Filter(aTempBitmapEx, BitmapColorizeFilter(aColor));
143 }
144
146 {
147 if (aTempBitmapEx.IsAlpha())
148 {
149 Bitmap aAlphaBmp(aTempBitmapEx.GetAlpha().GetBitmap());
150 aAlphaBmp.Adjust(50);
151 aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aAlphaBmp));
152 }
153 else
154 {
155 sal_uInt8 cErase = 128;
156 aTempBitmapEx = BitmapEx(aTempBitmapEx.GetBitmap(), AlphaMask(aTempBitmapEx.GetSizePixel(), &cErase));
157 }
158 }
159 aRenderBmp = aTempBitmapEx;
160 }
161
162 pOutDev->DrawBitmapEx(rPos, aOutSize, aRenderBmp);
163}
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawImageFlags
const StyleSettings & GetStyleSettings() const
Bitmap const & GetBitmap() const
Definition: alpha.cxx:73
AlphaMask GetAlpha() const
Definition: BitmapEx.cxx:215
bool IsAlpha() const
Definition: BitmapEx.cxx:193
bool IsEmpty() const
Definition: BitmapEx.cxx:177
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:203
const Size & GetSizePixel() const
Definition: bitmapex.hxx:72
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
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.
static ErrCode LoadGraphic(const OUString &rPath, const OUString &rFilter, Graphic &rGraphic, GraphicFilter *pFilter=nullptr, sal_uInt16 *pDeterminedFormat=nullptr)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Definition: graph.cxx:329
Definition: image.hxx:40
OUString GetStock() const
Definition: Image.cxx:81
BitmapEx GetBitmapEx() const
Definition: Image.cxx:96
void Draw(OutputDevice *pOutDev, const Point &rPos, DrawImageFlags nStyle, const Size *pSize=nullptr)
Definition: Image.cxx:118
bool operator==(const Image &rImage) const
Definition: Image.cxx:104
Image()
Definition: Image.cxx:32
std::shared_ptr< ImplImage > mpImplData
Definition: image.hxx:68
SAL_DLLPRIVATE void ImplInit(BitmapEx const &rBmpEx)
Definition: Image.cxx:75
Size GetSizePixel() const
Definition: Image.cxx:88
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:171
SalGraphics const * GetGraphics() const
Get the graphic context that the output device uses to draw on.
Definition: outdev.cxx:201
GDIMetaFile * GetConnectMetaFile() const
Definition: outdev.hxx:286
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
Definition: bitmapex.cxx:33
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1135
bool IsDeviceOutputNecessary() const
Definition: outdev.hxx:482
const AllSettings & GetSettings() const
Definition: outdev.hxx:289
const Color & GetDeactiveColor() const
const Color & GetHighlightColor() const
#define ERRCODE_NONE
#define IMP_PNG
StockImage
Definition: image.hxx:37
std::shared_ptr< T > make_shared(Args &&... args)
unsigned char sal_uInt8