1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: texture3d.cxx,v $
9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:34 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/texture/texture3d.hxx>
40 #include <vcl/bmpacc.hxx>
41 #include <drawinglayer/attribute/fillattribute.hxx>
42 #include <drawinglayer/primitive3d/hatchtextureprimitive3d.hxx>
44 //////////////////////////////////////////////////////////////////////////////
46 namespace drawinglayer
50 GeoTexSvxMono::GeoTexSvxMono(const basegfx::BColor
& rSingleColor
, double fOpacity
)
51 : maSingleColor(rSingleColor
),
56 bool GeoTexSvxMono::operator==(const GeoTexSvx
& rGeoTexSvx
) const
58 const GeoTexSvxMono
* pCompare
= dynamic_cast< const GeoTexSvxMono
* >(&rGeoTexSvx
);
60 && maSingleColor
== pCompare
->maSingleColor
61 && mfOpacity
== pCompare
->mfOpacity
);
64 void GeoTexSvxMono::modifyBColor(const basegfx::B2DPoint
& /*rUV*/, basegfx::BColor
& rBColor
, double& /*rfOpacity*/) const
66 rBColor
= maSingleColor
;
69 void GeoTexSvxMono::modifyOpacity(const basegfx::B2DPoint
& /*rUV*/, double& rfOpacity
) const
71 rfOpacity
= mfOpacity
;
73 } // end of namespace texture
74 } // end of namespace drawinglayer
76 //////////////////////////////////////////////////////////////////////////////
78 namespace drawinglayer
82 GeoTexSvxBitmap::GeoTexSvxBitmap(const Bitmap
& rBitmap
, const basegfx::B2DPoint
& rTopLeft
, const basegfx::B2DVector
& rSize
)
90 mpRead
= maBitmap
.AcquireReadAccess();
91 OSL_ENSURE(mpRead
, "GeoTexSvxBitmap: Got no read access to Bitmap (!)");
92 mfMulX
= (double)mpRead
->Width() / maSize
.getX();
93 mfMulY
= (double)mpRead
->Height() / maSize
.getY();
96 GeoTexSvxBitmap::~GeoTexSvxBitmap()
101 bool GeoTexSvxBitmap::impIsValid(const basegfx::B2DPoint
& rUV
, sal_Int32
& rX
, sal_Int32
& rY
) const
105 rX
= (sal_Int32
)((rUV
.getX() - maTopLeft
.getX()) * mfMulX
);
107 if(rX
>= 0L && rX
< mpRead
->Width())
109 rY
= (sal_Int32
)((rUV
.getY() - maTopLeft
.getY()) * mfMulY
);
111 return (rY
>= 0L && rY
< mpRead
->Height());
118 void GeoTexSvxBitmap::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
122 if(impIsValid(rUV
, nX
, nY
))
124 const double fConvertColor(1.0 / 255.0);
125 const BitmapColor
aBMCol(mpRead
->GetColor(nY
, nX
));
126 const basegfx::BColor
aBSource(
127 (double)aBMCol
.GetRed() * fConvertColor
,
128 (double)aBMCol
.GetGreen() * fConvertColor
,
129 (double)aBMCol
.GetBlue() * fConvertColor
);
139 void GeoTexSvxBitmap::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
143 if(impIsValid(rUV
, nX
, nY
))
145 const BitmapColor
aBMCol(mpRead
->GetColor(nY
, nX
));
146 const Color
aColor(aBMCol
.GetRed(), aBMCol
.GetGreen(), aBMCol
.GetBlue());
148 rfOpacity
= ((double)(0xff - aColor
.GetLuminance()) * (1.0 / 255.0));
155 } // end of namespace texture
156 } // end of namespace drawinglayer
158 //////////////////////////////////////////////////////////////////////////////
160 namespace drawinglayer
164 GeoTexSvxBitmapTiled::GeoTexSvxBitmapTiled(const Bitmap
& rBitmap
, const basegfx::B2DPoint
& rTopLeft
, const basegfx::B2DVector
& rSize
)
165 : GeoTexSvxBitmap(rBitmap
, rTopLeft
, rSize
)
169 void GeoTexSvxBitmapTiled::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
173 GeoTexSvxBitmap::modifyBColor(impGetCorrected(rUV
), rBColor
, rfOpacity
);
177 void GeoTexSvxBitmapTiled::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
181 GeoTexSvxBitmap::modifyOpacity(impGetCorrected(rUV
), rfOpacity
);
184 } // end of namespace texture
185 } // end of namespace drawinglayer
187 //////////////////////////////////////////////////////////////////////////////
189 namespace drawinglayer
193 GeoTexSvxMultiHatch::GeoTexSvxMultiHatch(const primitive3d::HatchTexturePrimitive3D
& rPrimitive
, double fLogicPixelSize
)
194 : mfLogicPixelSize(fLogicPixelSize
),
199 const attribute::FillHatchAttribute
& rHatch(rPrimitive
.getHatch());
200 const basegfx::B2DRange
aOutlineRange(0.0, 0.0, rPrimitive
.getTextureSize().getX(), rPrimitive
.getTextureSize().getY());
201 const double fAngleA(-rHatch
.getAngle());
202 maColor
= rHatch
.getColor();
203 mbFillBackground
= rHatch
.isFillBackground();
204 mp0
= new GeoTexSvxHatch(aOutlineRange
, rHatch
.getDistance(), fAngleA
);
206 if(attribute::HATCHSTYLE_DOUBLE
== rHatch
.getStyle() || attribute::HATCHSTYLE_TRIPLE
== rHatch
.getStyle())
208 mp1
= new GeoTexSvxHatch(aOutlineRange
, rHatch
.getDistance(), fAngleA
+ F_PI2
);
211 if(attribute::HATCHSTYLE_TRIPLE
== rHatch
.getStyle())
213 mp2
= new GeoTexSvxHatch(aOutlineRange
, rHatch
.getDistance(), fAngleA
+ F_PI4
);
217 GeoTexSvxMultiHatch::~GeoTexSvxMultiHatch()
224 bool GeoTexSvxMultiHatch::impIsOnHatch(const basegfx::B2DPoint
& rUV
) const
226 if(mp0
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
231 if(mp1
&& mp1
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
236 if(mp2
&& mp2
->getDistanceToHatch(rUV
) < mfLogicPixelSize
)
244 void GeoTexSvxMultiHatch::modifyBColor(const basegfx::B2DPoint
& rUV
, basegfx::BColor
& rBColor
, double& rfOpacity
) const
246 if(impIsOnHatch(rUV
))
250 else if(!mbFillBackground
)
256 void GeoTexSvxMultiHatch::modifyOpacity(const basegfx::B2DPoint
& rUV
, double& rfOpacity
) const
258 if(mbFillBackground
|| impIsOnHatch(rUV
))
267 } // end of namespace texture
268 } // end of namespace drawinglayer
270 //////////////////////////////////////////////////////////////////////////////