fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / drawinglayer / source / texture / texture3d.cxx
blob88fa8bb6a6be746c90d5e922609b18b7e554ca13
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 <drawinglayer/texture/texture3d.hxx>
21 #include <vcl/bmpacc.hxx>
22 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
24 //////////////////////////////////////////////////////////////////////////////
26 namespace drawinglayer
28 namespace texture
30 GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity)
31 : maSingleColor(rSingleColor),
32 mfOpacity(fOpacity)
36 bool GeoTexSvxMono::operator==(const GeoTexSvx& rGeoTexSvx) const
38 const GeoTexSvxMono* pCompare = dynamic_cast< const GeoTexSvxMono* >(&rGeoTexSvx);
39 return (pCompare
40 && maSingleColor == pCompare->maSingleColor
41 && mfOpacity == pCompare->mfOpacity);
44 void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
46 rBColor = maSingleColor;
49 void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint& /*rUV*/, double& rfOpacity) const
51 rfOpacity = mfOpacity;
53 } // end of namespace texture
54 } // end of namespace drawinglayer
56 //////////////////////////////////////////////////////////////////////////////
58 namespace drawinglayer
60 namespace texture
62 GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
63 : maBitmap(rBitmap),
64 mpRead(0L),
65 maTopLeft(rTopLeft),
66 maSize(rSize),
67 mfMulX(0.0),
68 mfMulY(0.0)
70 mpRead = maBitmap.AcquireReadAccess();
71 OSL_ENSURE(mpRead, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
72 mfMulX = (double)mpRead->Width() / maSize.getX();
73 mfMulY = (double)mpRead->Height() / maSize.getY();
76 GeoTexSvxBitmap::~GeoTexSvxBitmap()
78 delete mpRead;
81 bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
83 if(mpRead)
85 rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);
87 if(rX >= 0L && rX < mpRead->Width())
89 rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);
91 return (rY >= 0L && rY < mpRead->Height());
95 return false;
98 void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
100 sal_Int32 nX, nY;
102 if(impIsValid(rUV, nX, nY))
104 const double fConvertColor(1.0 / 255.0);
105 const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
106 const basegfx::BColor aBSource(
107 (double)aBMCol.GetRed() * fConvertColor,
108 (double)aBMCol.GetGreen() * fConvertColor,
109 (double)aBMCol.GetBlue() * fConvertColor);
111 rBColor = aBSource;
113 else
115 rfOpacity = 0.0;
119 void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
121 sal_Int32 nX, nY;
123 if(impIsValid(rUV, nX, nY))
125 const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
126 const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
128 rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
130 else
132 rfOpacity = 0.0;
135 } // end of namespace texture
136 } // end of namespace drawinglayer
138 //////////////////////////////////////////////////////////////////////////////
140 namespace drawinglayer
142 namespace texture
144 GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
145 : GeoTexSvxBitmap(rBitmap, rTopLeft, rSize)
149 void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
151 if(mpRead)
153 GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
157 void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
159 if(mpRead)
161 GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV), rfOpacity);
164 } // end of namespace texture
165 } // end of namespace drawinglayer
167 //////////////////////////////////////////////////////////////////////////////
169 namespace drawinglayer
171 namespace texture
173 GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize)
174 : mfLogicPixelSize(fLogicPixelSize),
175 mp0(0L),
176 mp1(0L),
177 mp2(0L)
179 const attribute::FillHatchAttribute& rHatch(rPrimitive.getHatch());
180 const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
181 const double fAngleA(rHatch.getAngle());
182 maColor = rHatch.getColor();
183 mbFillBackground = rHatch.isFillBackground();
184 mp0 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA);
186 if(attribute::HATCHSTYLE_DOUBLE == rHatch.getStyle() || attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
188 mp1 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI2);
191 if(attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
193 mp2 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI4);
197 GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
199 delete mp0;
200 delete mp1;
201 delete mp2;
204 bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const
206 if(mp0->getDistanceToHatch(rUV) < mfLogicPixelSize)
208 return true;
211 if(mp1 && mp1->getDistanceToHatch(rUV) < mfLogicPixelSize)
213 return true;
216 if(mp2 && mp2->getDistanceToHatch(rUV) < mfLogicPixelSize)
218 return true;
221 return false;
224 void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
226 if(impIsOnHatch(rUV))
228 rBColor = maColor;
230 else if(!mbFillBackground)
232 rfOpacity = 0.0;
236 void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
238 if(mbFillBackground || impIsOnHatch(rUV))
240 rfOpacity = 1.0;
242 else
244 rfOpacity = 0.0;
247 } // end of namespace texture
248 } // end of namespace drawinglayer
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */