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 <drawinglayer/texture/texture3d.hxx>
21 #include <vcl/bmpacc.hxx>
22 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
26 namespace drawinglayer
30 GeoTexSvxMono::GeoTexSvxMono(
31 const basegfx::BColor
& rSingleColor
,
33 : maSingleColor(rSingleColor
),
38 bool GeoTexSvxMono::operator==(const GeoTexSvx
& rGeoTexSvx
) const
40 const GeoTexSvxMono
* pCompare
= dynamic_cast< const GeoTexSvxMono
* >(&rGeoTexSvx
);
43 && maSingleColor
== pCompare
->maSingleColor
44 && mfOpacity
== pCompare
->mfOpacity
);
47 void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint
& /*rUV*/, basegfx::BColor
& rBColor
, double& /*rfOpacity*/) const
49 rBColor
= maSingleColor
;
52 void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint
& /*rUV*/, double& rfOpacity
) const
54 rfOpacity
= mfOpacity
;
56 } // end of namespace texture
57 } // end of namespace drawinglayer
61 namespace drawinglayer
65 GeoTexSvxBitmapEx::GeoTexSvxBitmapEx(
66 const BitmapEx
& rBitmapEx
,
67 const basegfx::B2DRange
& rRange
)
68 : maBitmapEx(rBitmapEx
),
71 mpReadTransparence(0),
72 maTopLeft(rRange
.getMinimum()),
73 maSize(rRange
.getRange()),
77 mbIsTransparent(maBitmapEx
.IsTransparent())
79 // #121194# Todo: use alpha channel, too (for 3d)
80 mpReadBitmap
= maBitmapEx
.GetBitmap().AcquireReadAccess();
81 OSL_ENSURE(mpReadBitmap
, "GeoTexSvxBitmapEx: Got no read access to Bitmap (!)");
85 if(maBitmapEx
.IsAlpha())
88 maTransparence
= rBitmapEx
.GetAlpha().GetBitmap();
92 maTransparence
= rBitmapEx
.GetMask();
95 mpReadTransparence
= maTransparence
.AcquireReadAccess();
98 mfMulX
= (double)mpReadBitmap
->Width() / maSize
.getX();
99 mfMulY
= (double)mpReadBitmap
->Height() / maSize
.getY();
101 if(maSize
.getX() <= 1.0)
106 if(maSize
.getY() <= 1.0)
112 GeoTexSvxBitmapEx::~GeoTexSvxBitmapEx()
114 delete mpReadTransparence
;
118 sal_uInt8
GeoTexSvxBitmapEx::impGetTransparence(sal_Int32
& rX
, sal_Int32
& rY
) const
120 switch(maBitmapEx
.GetTransparentType())
122 case TRANSPARENT_NONE
:
126 case TRANSPARENT_COLOR
:
128 const BitmapColor
aBitmapColor(mpReadBitmap
->GetColor(rY
, rX
));
130 if(maBitmapEx
.GetTransparentColor() == aBitmapColor
.operator Color())
137 case TRANSPARENT_BITMAP
:
139 OSL_ENSURE(mpReadTransparence
, "OOps, transparence type Bitmap, but no read access created in the constructor (?)");
140 const BitmapColor
aBitmapColor(mpReadTransparence
->GetPixel(rY
, rX
));
144 return aBitmapColor
.GetIndex();
148 if(0x00 != aBitmapColor
.GetIndex())
160 bool GeoTexSvxBitmapEx::impIsValid(const basegfx::B2DPoint
& rUV
, sal_Int32
& rX
, sal_Int32
& rY
) const
164 rX
= (sal_Int32
)((rUV
.getX() - maTopLeft
.getX()) * mfMulX
);
166 if(rX
>= 0L && rX
< mpReadBitmap
->Width())
168 rY
= (sal_Int32
)((rUV
.getY() - maTopLeft
.getY()) * mfMulY
);
170 return (rY
>= 0L && rY
< mpReadBitmap
->Height());
177 void GeoTexSvxBitmapEx::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
181 if(impIsValid(rUV
, nX
, nY
))
183 const double fConvertColor(1.0 / 255.0);
184 const BitmapColor
aBMCol(mpReadBitmap
->GetColor(nY
, nX
));
185 const basegfx::BColor
aBSource(
186 (double)aBMCol
.GetRed() * fConvertColor
,
187 (double)aBMCol
.GetGreen() * fConvertColor
,
188 (double)aBMCol
.GetBlue() * fConvertColor
);
194 // when we have a transparence, make use of it
195 const sal_uInt8
aLuminance(impGetTransparence(nX
, nY
));
197 rfOpacity
= ((double)(0xff - aLuminance
) * (1.0 / 255.0));
210 void GeoTexSvxBitmapEx::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
214 if(impIsValid(rUV
, nX
, nY
))
218 // this texture has an alpha part, use it
219 const sal_uInt8
aLuminance(impGetTransparence(nX
, nY
));
220 const double fNewOpacity((double)(0xff - aLuminance
) * (1.0 / 255.0));
222 rfOpacity
= 1.0 - ((1.0 - fNewOpacity
) * (1.0 - rfOpacity
));
226 // this texture is a color bitmap used as transparence map
227 const BitmapColor
aBMCol(mpReadBitmap
->GetColor(nY
, nX
));
228 const Color
aColor(aBMCol
.GetRed(), aBMCol
.GetGreen(), aBMCol
.GetBlue());
230 rfOpacity
= ((double)(0xff - aColor
.GetLuminance()) * (1.0 / 255.0));
238 } // end of namespace texture
239 } // end of namespace drawinglayer
243 namespace drawinglayer
247 basegfx::B2DPoint
GeoTexSvxBitmapExTiled::impGetCorrected(const basegfx::B2DPoint
& rUV
) const
249 double fX(rUV
.getX() - maTopLeft
.getX());
250 double fY(rUV
.getY() - maTopLeft
.getY());
254 const sal_Int32
nCol(static_cast< sal_Int32
>((fY
< 0.0 ? maSize
.getY() -fY
: fY
) / maSize
.getY()));
258 fX
+= mfOffsetX
* maSize
.getX();
261 else if(mbUseOffsetY
)
263 const sal_Int32
nRow(static_cast< sal_Int32
>((fX
< 0.0 ? maSize
.getX() -fX
: fX
) / maSize
.getX()));
267 fY
+= mfOffsetY
* maSize
.getY();
271 fX
= fmod(fX
, maSize
.getX());
272 fY
= fmod(fY
, maSize
.getY());
284 return basegfx::B2DPoint(fX
+ maTopLeft
.getX(), fY
+ maTopLeft
.getY());
287 GeoTexSvxBitmapExTiled::GeoTexSvxBitmapExTiled(
288 const BitmapEx
& rBitmapEx
,
289 const basegfx::B2DRange
& rRange
,
292 : GeoTexSvxBitmapEx(rBitmapEx
, rRange
),
293 mfOffsetX(basegfx::clamp(fOffsetX
, 0.0, 1.0)),
294 mfOffsetY(basegfx::clamp(fOffsetY
, 0.0, 1.0)),
295 mbUseOffsetX(!basegfx::fTools::equalZero(mfOffsetX
)),
296 mbUseOffsetY(!mbUseOffsetX
&& !basegfx::fTools::equalZero(mfOffsetY
))
300 void GeoTexSvxBitmapExTiled::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
304 GeoTexSvxBitmapEx::modifyBColor(impGetCorrected(rUV
), rBColor
, rfOpacity
);
308 void GeoTexSvxBitmapExTiled::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
312 GeoTexSvxBitmapEx::modifyOpacity(impGetCorrected(rUV
), rfOpacity
);
315 } // end of namespace texture
316 } // end of namespace drawinglayer
320 namespace drawinglayer
324 GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(
325 const primitive3d::HatchTexturePrimitive3D
& rPrimitive
,
326 double fLogicPixelSize
)
327 : mfLogicPixelSize(fLogicPixelSize
),
332 const attribute::FillHatchAttribute
& rHatch(rPrimitive
.getHatch());
333 const basegfx::B2DRange
aOutlineRange(0.0, 0.0, rPrimitive
.getTextureSize().getX(), rPrimitive
.getTextureSize().getY());
334 const double fAngleA(rHatch
.getAngle());
335 maColor
= rHatch
.getColor();
336 mbFillBackground
= rHatch
.isFillBackground();
337 mp0
= new GeoTexSvxHatch(
340 rHatch
.getDistance(),
343 if(attribute::HATCHSTYLE_DOUBLE
== rHatch
.getStyle() || attribute::HATCHSTYLE_TRIPLE
== rHatch
.getStyle())
345 mp1
= new GeoTexSvxHatch(
348 rHatch
.getDistance(),
352 if(attribute::HATCHSTYLE_TRIPLE
== rHatch
.getStyle())
354 mp2
= new GeoTexSvxHatch(
357 rHatch
.getDistance(),
362 GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
369 bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint
& rUV
) const
371 if(mp0
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
376 if(mp1
&& mp1
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
381 if(mp2
&& mp2
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
389 void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
391 if(impIsOnHatch(rUV
))
395 else if(!mbFillBackground
)
401 void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
403 if(mbFillBackground
|| impIsOnHatch(rUV
))
412 } // end of namespace texture
413 } // end of namespace drawinglayer
415 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */