xref: /AOO41X/main/drawinglayer/source/texture/texture3d.cxx (revision 464702f4578bd67db020a330afd07883930c5e07)
1*464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*464702f4SAndrew Rist  * distributed with this work for additional information
6*464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*464702f4SAndrew Rist  * software distributed under the License is distributed on an
15*464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*464702f4SAndrew Rist  * specific language governing permissions and limitations
18*464702f4SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*464702f4SAndrew Rist  *************************************************************/
21*464702f4SAndrew Rist 
22*464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/texture/texture3d.hxx>
28cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace drawinglayer
34cdf0e10cSrcweir {
35cdf0e10cSrcweir 	namespace texture
36cdf0e10cSrcweir 	{
37cdf0e10cSrcweir 		GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor& rSingleColor, double fOpacity)
38cdf0e10cSrcweir 		:	maSingleColor(rSingleColor),
39cdf0e10cSrcweir 			mfOpacity(fOpacity)
40cdf0e10cSrcweir 		{
41cdf0e10cSrcweir 		}
42cdf0e10cSrcweir 
43cdf0e10cSrcweir 		bool GeoTexSvxMono::operator==(const GeoTexSvx& rGeoTexSvx) const
44cdf0e10cSrcweir 		{
45cdf0e10cSrcweir 			const GeoTexSvxMono* pCompare = dynamic_cast< const GeoTexSvxMono* >(&rGeoTexSvx);
46cdf0e10cSrcweir 			return (pCompare
47cdf0e10cSrcweir 				&& maSingleColor == pCompare->maSingleColor
48cdf0e10cSrcweir 				&& mfOpacity == pCompare->mfOpacity);
49cdf0e10cSrcweir 		}
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 		void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint& /*rUV*/, basegfx::BColor& rBColor, double& /*rfOpacity*/) const
52cdf0e10cSrcweir 		{
53cdf0e10cSrcweir 			rBColor = maSingleColor;
54cdf0e10cSrcweir 		}
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 		void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint& /*rUV*/, double& rfOpacity) const
57cdf0e10cSrcweir 		{
58cdf0e10cSrcweir 			rfOpacity = mfOpacity;
59cdf0e10cSrcweir 		}
60cdf0e10cSrcweir 	} // end of namespace texture
61cdf0e10cSrcweir } // end of namespace drawinglayer
62cdf0e10cSrcweir 
63cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
64cdf0e10cSrcweir 
65cdf0e10cSrcweir namespace drawinglayer
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 	namespace texture
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
70cdf0e10cSrcweir 		:	maBitmap(rBitmap),
71cdf0e10cSrcweir 			mpRead(0L),
72cdf0e10cSrcweir 			maTopLeft(rTopLeft),
73cdf0e10cSrcweir 			maSize(rSize),
74cdf0e10cSrcweir 			mfMulX(0.0),
75cdf0e10cSrcweir 			mfMulY(0.0)
76cdf0e10cSrcweir 		{
77cdf0e10cSrcweir 			mpRead = maBitmap.AcquireReadAccess();
78cdf0e10cSrcweir 			OSL_ENSURE(mpRead, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
79cdf0e10cSrcweir 			mfMulX = (double)mpRead->Width() / maSize.getX();
80cdf0e10cSrcweir 			mfMulY = (double)mpRead->Height() / maSize.getY();
81cdf0e10cSrcweir 		}
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 		GeoTexSvxBitmap::~GeoTexSvxBitmap()
84cdf0e10cSrcweir 		{
85cdf0e10cSrcweir 			delete mpRead;
86cdf0e10cSrcweir 		}
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 		bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint& rUV, sal_Int32& rX, sal_Int32& rY) const
89cdf0e10cSrcweir 		{
90cdf0e10cSrcweir 			if(mpRead)
91cdf0e10cSrcweir 			{
92cdf0e10cSrcweir 				rX = (sal_Int32)((rUV.getX() - maTopLeft.getX()) * mfMulX);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 				if(rX >= 0L && rX < mpRead->Width())
95cdf0e10cSrcweir 				{
96cdf0e10cSrcweir 					rY = (sal_Int32)((rUV.getY() - maTopLeft.getY()) * mfMulY);
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 					return (rY >= 0L && rY < mpRead->Height());
99cdf0e10cSrcweir 				}
100cdf0e10cSrcweir 			}
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 			return false;
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
106cdf0e10cSrcweir 		{
107cdf0e10cSrcweir 			sal_Int32 nX, nY;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 			if(impIsValid(rUV, nX, nY))
110cdf0e10cSrcweir 			{
111cdf0e10cSrcweir 				const double fConvertColor(1.0 / 255.0);
112cdf0e10cSrcweir 				const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
113cdf0e10cSrcweir 				const basegfx::BColor aBSource(
114cdf0e10cSrcweir 					(double)aBMCol.GetRed() * fConvertColor,
115cdf0e10cSrcweir 					(double)aBMCol.GetGreen() * fConvertColor,
116cdf0e10cSrcweir 					(double)aBMCol.GetBlue() * fConvertColor);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 				rBColor = aBSource;
119cdf0e10cSrcweir 			}
120cdf0e10cSrcweir 			else
121cdf0e10cSrcweir 			{
122cdf0e10cSrcweir 				rfOpacity = 0.0;
123cdf0e10cSrcweir 			}
124cdf0e10cSrcweir 		}
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 		void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
127cdf0e10cSrcweir 		{
128cdf0e10cSrcweir 			sal_Int32 nX, nY;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 			if(impIsValid(rUV, nX, nY))
131cdf0e10cSrcweir 			{
132cdf0e10cSrcweir 				const BitmapColor aBMCol(mpRead->GetColor(nY, nX));
133cdf0e10cSrcweir 				const Color aColor(aBMCol.GetRed(), aBMCol.GetGreen(), aBMCol.GetBlue());
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 				rfOpacity = ((double)(0xff - aColor.GetLuminance()) * (1.0 / 255.0));
136cdf0e10cSrcweir 			}
137cdf0e10cSrcweir 			else
138cdf0e10cSrcweir 			{
139cdf0e10cSrcweir 				rfOpacity = 0.0;
140cdf0e10cSrcweir 			}
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 	} // end of namespace texture
143cdf0e10cSrcweir } // end of namespace drawinglayer
144cdf0e10cSrcweir 
145cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
146cdf0e10cSrcweir 
147cdf0e10cSrcweir namespace drawinglayer
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	namespace texture
150cdf0e10cSrcweir 	{
151cdf0e10cSrcweir 		GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap& rBitmap, const basegfx::B2DPoint& rTopLeft, const basegfx::B2DVector& rSize)
152cdf0e10cSrcweir 		:	GeoTexSvxBitmap(rBitmap, rTopLeft, rSize)
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 		void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
157cdf0e10cSrcweir 		{
158cdf0e10cSrcweir 			if(mpRead)
159cdf0e10cSrcweir 			{
160cdf0e10cSrcweir 				GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV), rBColor, rfOpacity);
161cdf0e10cSrcweir 			}
162cdf0e10cSrcweir 		}
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
165cdf0e10cSrcweir 		{
166cdf0e10cSrcweir 			if(mpRead)
167cdf0e10cSrcweir 			{
168cdf0e10cSrcweir 				GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV), rfOpacity);
169cdf0e10cSrcweir 			}
170cdf0e10cSrcweir 		}
171cdf0e10cSrcweir 	} // end of namespace texture
172cdf0e10cSrcweir } // end of namespace drawinglayer
173cdf0e10cSrcweir 
174cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
175cdf0e10cSrcweir 
176cdf0e10cSrcweir namespace drawinglayer
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	namespace texture
179cdf0e10cSrcweir 	{
180cdf0e10cSrcweir 		GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D& rPrimitive, double fLogicPixelSize)
181cdf0e10cSrcweir 		:	mfLogicPixelSize(fLogicPixelSize),
182cdf0e10cSrcweir 			mp0(0L),
183cdf0e10cSrcweir 			mp1(0L),
184cdf0e10cSrcweir 			mp2(0L)
185cdf0e10cSrcweir 		{
186cdf0e10cSrcweir 			const attribute::FillHatchAttribute& rHatch(rPrimitive.getHatch());
187cdf0e10cSrcweir 			const basegfx::B2DRange aOutlineRange(0.0, 0.0, rPrimitive.getTextureSize().getX(), rPrimitive.getTextureSize().getY());
188cdf0e10cSrcweir 			const double fAngleA(rHatch.getAngle());
189cdf0e10cSrcweir 			maColor = rHatch.getColor();
190cdf0e10cSrcweir 			mbFillBackground = rHatch.isFillBackground();
191cdf0e10cSrcweir 			mp0 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA);
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 			if(attribute::HATCHSTYLE_DOUBLE == rHatch.getStyle() || attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
194cdf0e10cSrcweir 			{
195cdf0e10cSrcweir 				mp1 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI2);
196cdf0e10cSrcweir 			}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 			if(attribute::HATCHSTYLE_TRIPLE == rHatch.getStyle())
199cdf0e10cSrcweir 			{
200cdf0e10cSrcweir 				mp2 = new GeoTexSvxHatch(aOutlineRange, rHatch.getDistance(), fAngleA + F_PI4);
201cdf0e10cSrcweir 			}
202cdf0e10cSrcweir 		}
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 		GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
205cdf0e10cSrcweir 		{
206cdf0e10cSrcweir 			delete mp0;
207cdf0e10cSrcweir 			delete mp1;
208cdf0e10cSrcweir 			delete mp2;
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 		bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint& rUV) const
212cdf0e10cSrcweir 		{
213cdf0e10cSrcweir 			if(mp0->getDistanceToHatch(rUV) < mfLogicPixelSize)
214cdf0e10cSrcweir 			{
215cdf0e10cSrcweir 				return true;
216cdf0e10cSrcweir 			}
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 			if(mp1 && mp1->getDistanceToHatch(rUV) < mfLogicPixelSize)
219cdf0e10cSrcweir 			{
220cdf0e10cSrcweir 				return true;
221cdf0e10cSrcweir 			}
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 			if(mp2 && mp2->getDistanceToHatch(rUV) < mfLogicPixelSize)
224cdf0e10cSrcweir 			{
225cdf0e10cSrcweir 				return true;
226cdf0e10cSrcweir 			}
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 			return false;
229cdf0e10cSrcweir 		}
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 		void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint& rUV, basegfx::BColor& rBColor, double& rfOpacity) const
232cdf0e10cSrcweir 		{
233cdf0e10cSrcweir 			if(impIsOnHatch(rUV))
234cdf0e10cSrcweir 			{
235cdf0e10cSrcweir 				rBColor = maColor;
236cdf0e10cSrcweir 			}
237cdf0e10cSrcweir 			else if(!mbFillBackground)
238cdf0e10cSrcweir 			{
239cdf0e10cSrcweir 				rfOpacity = 0.0;
240cdf0e10cSrcweir 			}
241cdf0e10cSrcweir 		}
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 		void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint& rUV, double& rfOpacity) const
244cdf0e10cSrcweir 		{
245cdf0e10cSrcweir 			if(mbFillBackground || impIsOnHatch(rUV))
246cdf0e10cSrcweir 			{
247cdf0e10cSrcweir 				rfOpacity = 1.0;
248cdf0e10cSrcweir 			}
249cdf0e10cSrcweir 			else
250cdf0e10cSrcweir 			{
251cdf0e10cSrcweir 				rfOpacity = 0.0;
252cdf0e10cSrcweir 			}
253cdf0e10cSrcweir 		}
254cdf0e10cSrcweir 	} // end of namespace texture
255cdf0e10cSrcweir } // end of namespace drawinglayer
256cdf0e10cSrcweir 
257cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
258cdf0e10cSrcweir // eof
259