xref: /AOO41X/main/drawinglayer/source/texture/texture3d.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/texture/texture3d.hxx>
32*cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
33*cdf0e10cSrcweir #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir namespace drawinglayer
38*cdf0e10cSrcweir {
39*cdf0e10cSrcweir 	namespace texture
40*cdf0e10cSrcweir 	{
41*cdf0e10cSrcweir 		GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity)
42*cdf0e10cSrcweir 		:	maSingleColor(rSingleColor),
43*cdf0e10cSrcweir 			mfOpacity(fOpacity)
44*cdf0e10cSrcweir 		{
45*cdf0e10cSrcweir 		}
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 		bool GeoTexSvxMono::operator==(const GeoTexSvx& rGeoTexSvx) const
48*cdf0e10cSrcweir 		{
49*cdf0e10cSrcweir 			const GeoTexSvxMono* pCompare = dynamic_cast< const GeoTexSvxMono* >(&rGeoTexSvx);
50*cdf0e10cSrcweir 			return (pCompare
51*cdf0e10cSrcweir 				&& maSingleColor == pCompare->maSingleColor
52*cdf0e10cSrcweir 				&& mfOpacity == pCompare->mfOpacity);
53*cdf0e10cSrcweir 		}
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 		void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
56*cdf0e10cSrcweir 		{
57*cdf0e10cSrcweir 			rBColor = maSingleColor;
58*cdf0e10cSrcweir 		}
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir 		void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint& /*rUV*/, double& rfOpacity) const
61*cdf0e10cSrcweir 		{
62*cdf0e10cSrcweir 			rfOpacity = mfOpacity;
63*cdf0e10cSrcweir 		}
64*cdf0e10cSrcweir 	} // end of namespace texture
65*cdf0e10cSrcweir } // end of namespace drawinglayer
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir namespace drawinglayer
70*cdf0e10cSrcweir {
71*cdf0e10cSrcweir 	namespace texture
72*cdf0e10cSrcweir 	{
73*cdf0e10cSrcweir 		GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
74*cdf0e10cSrcweir 		:	maBitmap(rBitmap),
75*cdf0e10cSrcweir 			mpRead(0L),
76*cdf0e10cSrcweir 			maTopLeft(rTopLeft),
77*cdf0e10cSrcweir 			maSize(rSize),
78*cdf0e10cSrcweir 			mfMulX(0.0),
79*cdf0e10cSrcweir 			mfMulY(0.0)
80*cdf0e10cSrcweir 		{
81*cdf0e10cSrcweir 			mpRead = maBitmap.AcquireReadAccess();
82*cdf0e10cSrcweir 			OSL_ENSURE(mpRead, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
83*cdf0e10cSrcweir 			mfMulX = (double)mpRead->Width() / maSize.getX();
84*cdf0e10cSrcweir 			mfMulY = (double)mpRead->Height() / maSize.getY();
85*cdf0e10cSrcweir 		}
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 		GeoTexSvxBitmap::~GeoTexSvxBitmap()
88*cdf0e10cSrcweir 		{
89*cdf0e10cSrcweir 			delete mpRead;
90*cdf0e10cSrcweir 		}
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 		bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
93*cdf0e10cSrcweir 		{
94*cdf0e10cSrcweir 			if(mpRead)
95*cdf0e10cSrcweir 			{
96*cdf0e10cSrcweir 				rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 				if(rX >= 0L && rX < mpRead->Width())
99*cdf0e10cSrcweir 				{
100*cdf0e10cSrcweir 					rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 					return (rY >= 0L && rY < mpRead->Height());
103*cdf0e10cSrcweir 				}
104*cdf0e10cSrcweir 			}
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 			return false;
107*cdf0e10cSrcweir 		}
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 		void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir 			sal_Int32 nX, nY;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 			if(impIsValid(rUV, nX, nY))
114*cdf0e10cSrcweir 			{
115*cdf0e10cSrcweir 				const double fConvertColor(1.0 / 255.0);
116*cdf0e10cSrcweir 				const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
117*cdf0e10cSrcweir 				const basegfx::BColor aBSource(
118*cdf0e10cSrcweir 					(double)aBMCol.GetRed() * fConvertColor,
119*cdf0e10cSrcweir 					(double)aBMCol.GetGreen() * fConvertColor,
120*cdf0e10cSrcweir 					(double)aBMCol.GetBlue() * fConvertColor);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 				rBColor = aBSource;
123*cdf0e10cSrcweir 			}
124*cdf0e10cSrcweir 			else
125*cdf0e10cSrcweir 			{
126*cdf0e10cSrcweir 				rfOpacity = 0.0;
127*cdf0e10cSrcweir 			}
128*cdf0e10cSrcweir 		}
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 		void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
131*cdf0e10cSrcweir 		{
132*cdf0e10cSrcweir 			sal_Int32 nX, nY;
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 			if(impIsValid(rUV, nX, nY))
135*cdf0e10cSrcweir 			{
136*cdf0e10cSrcweir 				const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
137*cdf0e10cSrcweir 				const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 				rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
140*cdf0e10cSrcweir 			}
141*cdf0e10cSrcweir 			else
142*cdf0e10cSrcweir 			{
143*cdf0e10cSrcweir 				rfOpacity = 0.0;
144*cdf0e10cSrcweir 			}
145*cdf0e10cSrcweir 		}
146*cdf0e10cSrcweir 	} // end of namespace texture
147*cdf0e10cSrcweir } // end of namespace drawinglayer
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir namespace drawinglayer
152*cdf0e10cSrcweir {
153*cdf0e10cSrcweir 	namespace texture
154*cdf0e10cSrcweir 	{
155*cdf0e10cSrcweir 		GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
156*cdf0e10cSrcweir 		:	GeoTexSvxBitmap(rBitmap, rTopLeft, rSize)
157*cdf0e10cSrcweir 		{
158*cdf0e10cSrcweir 		}
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 		void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
161*cdf0e10cSrcweir 		{
162*cdf0e10cSrcweir 			if(mpRead)
163*cdf0e10cSrcweir 			{
164*cdf0e10cSrcweir 				GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
165*cdf0e10cSrcweir 			}
166*cdf0e10cSrcweir 		}
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 		void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
169*cdf0e10cSrcweir 		{
170*cdf0e10cSrcweir 			if(mpRead)
171*cdf0e10cSrcweir 			{
172*cdf0e10cSrcweir 				GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV), rfOpacity);
173*cdf0e10cSrcweir 			}
174*cdf0e10cSrcweir 		}
175*cdf0e10cSrcweir 	} // end of namespace texture
176*cdf0e10cSrcweir } // end of namespace drawinglayer
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir namespace drawinglayer
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir 	namespace texture
183*cdf0e10cSrcweir 	{
184*cdf0e10cSrcweir 		GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize)
185*cdf0e10cSrcweir 		:	mfLogicPixelSize(fLogicPixelSize),
186*cdf0e10cSrcweir 			mp0(0L),
187*cdf0e10cSrcweir 			mp1(0L),
188*cdf0e10cSrcweir 			mp2(0L)
189*cdf0e10cSrcweir 		{
190*cdf0e10cSrcweir 			const attribute::FillHatchAttribute& rHatch(rPrimitive.getHatch());
191*cdf0e10cSrcweir 			const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
192*cdf0e10cSrcweir 			const double fAngleA(rHatch.getAngle());
193*cdf0e10cSrcweir 			maColor = rHatch.getColor();
194*cdf0e10cSrcweir 			mbFillBackground = rHatch.isFillBackground();
195*cdf0e10cSrcweir 			mp0 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA);
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 			if(attribute::HATCHSTYLE_DOUBLE == rHatch.getStyle() || attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
198*cdf0e10cSrcweir 			{
199*cdf0e10cSrcweir 				mp1 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI2);
200*cdf0e10cSrcweir 			}
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 			if(attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
203*cdf0e10cSrcweir 			{
204*cdf0e10cSrcweir 				mp2 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI4);
205*cdf0e10cSrcweir 			}
206*cdf0e10cSrcweir 		}
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 		GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
209*cdf0e10cSrcweir 		{
210*cdf0e10cSrcweir 			delete mp0;
211*cdf0e10cSrcweir 			delete mp1;
212*cdf0e10cSrcweir 			delete mp2;
213*cdf0e10cSrcweir 		}
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 		bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const
216*cdf0e10cSrcweir 		{
217*cdf0e10cSrcweir 			if(mp0->getDistanceToHatch(rUV) < mfLogicPixelSize)
218*cdf0e10cSrcweir 			{
219*cdf0e10cSrcweir 				return true;
220*cdf0e10cSrcweir 			}
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 			if(mp1 && mp1->getDistanceToHatch(rUV) < mfLogicPixelSize)
223*cdf0e10cSrcweir 			{
224*cdf0e10cSrcweir 				return true;
225*cdf0e10cSrcweir 			}
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 			if(mp2 && mp2->getDistanceToHatch(rUV) < mfLogicPixelSize)
228*cdf0e10cSrcweir 			{
229*cdf0e10cSrcweir 				return true;
230*cdf0e10cSrcweir 			}
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 			return false;
233*cdf0e10cSrcweir 		}
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir 		void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
236*cdf0e10cSrcweir 		{
237*cdf0e10cSrcweir 			if(impIsOnHatch(rUV))
238*cdf0e10cSrcweir 			{
239*cdf0e10cSrcweir 				rBColor = maColor;
240*cdf0e10cSrcweir 			}
241*cdf0e10cSrcweir 			else if(!mbFillBackground)
242*cdf0e10cSrcweir 			{
243*cdf0e10cSrcweir 				rfOpacity = 0.0;
244*cdf0e10cSrcweir 			}
245*cdf0e10cSrcweir 		}
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 		void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
248*cdf0e10cSrcweir 		{
249*cdf0e10cSrcweir 			if(mbFillBackground || impIsOnHatch(rUV))
250*cdf0e10cSrcweir 			{
251*cdf0e10cSrcweir 				rfOpacity = 1.0;
252*cdf0e10cSrcweir 			}
253*cdf0e10cSrcweir 			else
254*cdf0e10cSrcweir 			{
255*cdf0e10cSrcweir 				rfOpacity = 0.0;
256*cdf0e10cSrcweir 			}
257*cdf0e10cSrcweir 		}
258*cdf0e10cSrcweir 	} // end of namespace texture
259*cdf0e10cSrcweir } // end of namespace drawinglayer
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
262*cdf0e10cSrcweir // eof
263