LibreOffice Module vcl (master) 1
UnoGraphic.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
22#include <tools/stream.hxx>
23#include <vcl/svapp.hxx>
24#include <com/sun/star/graphic/GraphicType.hpp>
25#include <com/sun/star/graphic/XGraphicTransformer.hpp>
26#include <vcl/dibtools.hxx>
27#include <vcl/graph.hxx>
28#include <vcl/BitmapColor.hxx>
34
35using namespace com::sun::star;
36
37namespace unographic {
38
40{
41}
42
44{
45}
46
47void Graphic::init(const ::Graphic& rGraphic)
48{
49 maGraphic = rGraphic;
51}
52
54{
55 uno::Any aAny;
57 aAny <<= uno::Reference< graphic::XGraphic >( this );
58 else if( rType == cppu::UnoType<awt::XBitmap>::get())
59 aAny <<= uno::Reference< awt::XBitmap >( this );
61 aAny <<= uno::Reference< graphic::XGraphicTransformer >(this);
62 else
64
65 return aAny;
66}
67
68void SAL_CALL Graphic::acquire()
69 noexcept
70{
72}
73
74void SAL_CALL Graphic::release() noexcept
75{
77}
78
80{
81 return "com.sun.star.comp.graphic.Graphic";
82}
83
84sal_Bool SAL_CALL Graphic::supportsService( const OUString& rServiceName )
85{
86 return cppu::supportsService( this, rServiceName );
87}
88
89uno::Sequence< OUString > SAL_CALL Graphic::getSupportedServiceNames()
90{
91 uno::Sequence< OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() );
92 const uno::Sequence< OUString > aNew { "com.sun.star.graphic.Graphic" };
93 sal_Int32 nOldCount = aRet.getLength();
94
95 aRet.realloc( nOldCount + aNew.getLength() );
96
97 std::copy(aNew.begin(), aNew.end(), std::next(aRet.getArray(), nOldCount));
98
99 return aRet;
100}
101
102uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes()
103{
108 ).getTypes();
109}
110
111uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId()
112{
113 return css::uno::Sequence<sal_Int8>();
114}
115
117{
118 sal_Int8 cRet = graphic::GraphicType::EMPTY;
119
120 if (!maGraphic.IsNone())
121 {
122 cRet = (maGraphic.GetType() == ::GraphicType::Bitmap) ? graphic::GraphicType::PIXEL
123 : graphic::GraphicType::VECTOR;
124 }
125
126 return cRet;
127}
128
129// XBitmap
130
131awt::Size SAL_CALL Graphic::getSize()
132{
133 SolarMutexGuard aGuard;
134
135 Size aVclSize;
136 if (!maGraphic.IsNone())
137 {
138 aVclSize = maGraphic.GetSizePixel();
139 }
140 return awt::Size(aVclSize.Width(), aVclSize.Height());
141}
142
143uno::Sequence<sal_Int8> SAL_CALL Graphic::getDIB()
144{
145 SolarMutexGuard aGuard;
146
147 if (!maGraphic.IsNone())
148 {
149 SvMemoryStream aMemoryStream;
150
151 WriteDIB(maGraphic.GetBitmapEx().GetBitmap(), aMemoryStream, false, true);
152 return css::uno::Sequence<sal_Int8>(static_cast<sal_Int8 const *>(aMemoryStream.GetData()), aMemoryStream.Tell());
153 }
154 else
155 {
156 return uno::Sequence<sal_Int8>();
157 }
158}
159
160uno::Sequence<sal_Int8> SAL_CALL Graphic::getMaskDIB()
161{
162 SolarMutexGuard aGuard;
163
164 if (!maGraphic.IsNone())
165 {
166 SvMemoryStream aMemoryStream;
167
168 WriteDIB(maGraphic.GetBitmapEx().GetAlphaMask(), aMemoryStream, false, true);
169 return css::uno::Sequence<sal_Int8>( static_cast<sal_Int8 const *>(aMemoryStream.GetData()), aMemoryStream.Tell() );
170 }
171 else
172 {
173 return uno::Sequence<sal_Int8>();
174 }
175}
176
177// XGraphicTransformer
178uno::Reference< graphic::XGraphic > SAL_CALL Graphic::colorChange(
179 const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nColorFrom, sal_Int8 nTolerance, sal_Int32 nColorTo, sal_Int8 nAlphaTo )
180{
181 ::Graphic aGraphic(rxGraphic);
182 ::Graphic aReturnGraphic;
183
184 BitmapColor aBmpColorFrom(Color(ColorTransparency, static_cast<sal_uInt32>(nColorFrom)));
185 BitmapColor aBmpColorTo(Color(ColorTransparency, static_cast<sal_uInt32>(nColorTo)));
186
187 Color aColorFrom(aBmpColorFrom);
188 Color aColorTo(aBmpColorTo);
189
190 const sal_uInt8 cIndexFrom = aBmpColorFrom.GetIndex();
191
192 //TODO This code convert GdiMetafile(vector graphic) to Bitmap, which cause to information lost
193 if (aGraphic.GetType() == GraphicType::Bitmap ||
194 aGraphic.GetType() == GraphicType::GdiMetafile)
195 {
196 BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
197
198 if (aBitmapEx.IsAlpha())
199 {
200 aBitmapEx.ChangeColorAlpha( cIndexFrom, nAlphaTo );
201 aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance);
202 aReturnGraphic = ::Graphic(aBitmapEx);
203 }
204 else
205 {
206 if ((nAlphaTo == 0) || (nAlphaTo == sal::static_int_cast< sal_Int8 >(0xff)))
207 {
208 Bitmap aBitmap(aBitmapEx.GetBitmap());
209 AlphaMask aMask(aBitmap.CreateAlphaMask(aColorFrom, nTolerance));
210 aBitmap.Replace(aColorFrom, aColorTo, nTolerance);
211 aReturnGraphic = ::Graphic(BitmapEx(aBitmap, aMask));
212 }
213 else
214 {
215 aBitmapEx.Replace(aColorFrom, aColorTo, nTolerance);
216 aReturnGraphic = ::Graphic(aBitmapEx);
217 }
218 }
219 }
220
221 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
222 return aReturnGraphic.GetXGraphic();
223}
224
225uno::Reference< graphic::XGraphic > SAL_CALL Graphic::applyDuotone(
226 const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nColorOne, sal_Int32 nColorTwo )
227{
228 ::Graphic aGraphic(rxGraphic);
229 ::Graphic aReturnGraphic;
230
231 BitmapEx aBitmapEx( aGraphic.GetBitmapEx() );
232 AlphaMask aMask( aBitmapEx.GetAlphaMask() );
233
234 BitmapEx aTmpBmpEx(aBitmapEx.GetBitmap());
235 BitmapFilter::Filter(aTmpBmpEx,
237 Color(ColorTransparency, nColorOne),
238 Color(ColorTransparency, nColorTwo)));
239
240 aReturnGraphic = ::Graphic( BitmapEx( aTmpBmpEx.GetBitmap(), aMask ) );
241 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
242 return aReturnGraphic.GetXGraphic();
243}
244
245uno::Reference< graphic::XGraphic > SAL_CALL Graphic::applyBrightnessContrast(
246 const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nBrightness, sal_Int32 nContrast, sal_Bool mso )
247{
248 ::Graphic aGraphic(rxGraphic);
249 ::Graphic aReturnGraphic;
250
251 BitmapEx aBitmapEx(aGraphic.GetBitmapEx());
252 aBitmapEx.Adjust(nBrightness, nContrast, 0, 0, 0, 0, false, mso);
253 aReturnGraphic = ::Graphic(aBitmapEx);
254 aReturnGraphic.setOriginURL(aGraphic.getOriginURL());
255 return aReturnGraphic.GetXGraphic();
256}
257
258
259}
260
261/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 GetIndex() const
Definition: BitmapColor.hxx:70
const AlphaMask & GetAlphaMask() const
Definition: bitmapex.hxx:71
void ChangeColorAlpha(sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo)
Definition: BitmapEx.cxx:1365
bool IsAlpha() const
Definition: BitmapEx.cxx:207
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
void Replace(const Color &rSearchColor, const Color &rReplaceColor)
Replace all pixel having the search color with the specified color.
Definition: BitmapEx.cxx:482
bool Adjust(short nLuminancePercent, short nContrastPercent, short nChannelRPercent, short nChannelGPercent, short nChannelBPercent, double fGamma=1.0, bool bInvert=false, bool msoBrightness=false)
Change various global color characteristics.
Definition: BitmapEx.cxx:494
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
bool Replace(const AlphaMask &rAlpha, const Color &rMergeColor)
Merge bitmap with given background color according to specified alpha mask.
AlphaMask CreateAlphaMask(const Color &rTransColor) const
Create on-off alpha mask from bitmap.
css::uno::Reference< css::graphic::XGraphic > GetXGraphic() const
Definition: graph.cxx:350
OUString getOriginURL() const
Definition: graph.cxx:535
GraphicType GetType() const
Definition: graph.cxx:294
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
Definition: graph.cxx:330
void setOriginURL(OUString const &rOriginURL)
Definition: graph.cxx:544
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const void * GetData()
sal_uInt64 Tell() const
css::uno::Sequence< css::uno::Type > SAL_CALL getTypes()
virtual void SAL_CALL release() noexcept override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
void init(const ::Graphic &rGraphic)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual void SAL_CALL acquire() noexcept override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
Definition: UnoGraphic.cxx:79
virtual css::awt::Size SAL_CALL getSize() override
Definition: UnoGraphic.cxx:131
virtual void SAL_CALL acquire() noexcept override
Definition: UnoGraphic.cxx:68
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: UnoGraphic.cxx:89
virtual ::sal_Int8 SAL_CALL getType() override
Definition: UnoGraphic.cxx:116
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: UnoGraphic.cxx:53
virtual ~Graphic() noexcept override
Definition: UnoGraphic.cxx:43
void init(const ::Graphic &rGraphic)
Definition: UnoGraphic.cxx:47
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: UnoGraphic.cxx:111
virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getMaskDIB() override
Definition: UnoGraphic.cxx:160
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: UnoGraphic.cxx:102
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL applyBrightnessContrast(const css::uno::Reference< css::graphic::XGraphic > &rxGraphic, sal_Int32 nBrightness, sal_Int32 nContrast, sal_Bool mso) override
Definition: UnoGraphic.cxx:245
virtual css::uno::Sequence< ::sal_Int8 > SAL_CALL getDIB() override
Definition: UnoGraphic.cxx:143
virtual void SAL_CALL release() noexcept override
Definition: UnoGraphic.cxx:74
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL colorChange(const css::uno::Reference< css::graphic::XGraphic > &rGraphic, sal_Int32 nColorFrom, sal_Int8 nTolerance, sal_Int32 nColorTo, sal_Int8 nAlphaTo) override
Definition: UnoGraphic.cxx:178
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: UnoGraphic.cxx:84
virtual css::uno::Reference< css::graphic::XGraphic > SAL_CALL applyDuotone(const css::uno::Reference< css::graphic::XGraphic > &rGraphic, sal_Int32 nColorOne, sal_Int32 nColorTwo) override
Definition: UnoGraphic.cxx:225
ColorTransparency
bool WriteDIB(const Bitmap &rSource, SvStream &rOStm, bool bCompressed, bool bFileHeader)
Definition: dibtools.cxx:1725
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_uInt8
unsigned char sal_Bool
signed char sal_Int8