xref: /AOO41X/main/svx/source/xoutdev/_xoutbmp.cxx (revision f6e50924346d0b8c0b07c91832a97665dd718b0c)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <sot/factory.hxx>
28cdf0e10cSrcweir #include <tools/urlobj.hxx>
29cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
30cdf0e10cSrcweir #include <vcl/bmpacc.hxx>
31cdf0e10cSrcweir #include <tools/poly.hxx>
32cdf0e10cSrcweir #include <vcl/virdev.hxx>
33cdf0e10cSrcweir #include <vcl/wrkwin.hxx>
34cdf0e10cSrcweir #include <svl/solar.hrc>
35cdf0e10cSrcweir #include <sfx2/docfile.hxx>
36cdf0e10cSrcweir #include <sfx2/app.hxx>
37cdf0e10cSrcweir #include "svx/xoutbmp.hxx"
38cdf0e10cSrcweir #include <svtools/FilterConfigItem.hxx>
39cdf0e10cSrcweir #include <svtools/filter.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // -----------
42cdf0e10cSrcweir // - Defines -
43cdf0e10cSrcweir // -----------
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #define FORMAT_BMP	String(RTL_CONSTASCII_USTRINGPARAM("bmp"))
46cdf0e10cSrcweir #define FORMAT_GIF	String(RTL_CONSTASCII_USTRINGPARAM("gif"))
47cdf0e10cSrcweir #define FORMAT_JPG	String(RTL_CONSTASCII_USTRINGPARAM("jpg"))
48cdf0e10cSrcweir #define FORMAT_PNG	String(RTL_CONSTASCII_USTRINGPARAM("png"))
49cdf0e10cSrcweir 
50cdf0e10cSrcweir // --------------
51cdf0e10cSrcweir // - XOutBitmap -
52cdf0e10cSrcweir // --------------
53cdf0e10cSrcweir 
54cdf0e10cSrcweir GraphicFilter* XOutBitmap::pGrfFilter = NULL;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir // -----------------------------------------------------------------------------
57cdf0e10cSrcweir 
58cdf0e10cSrcweir BitmapEx XOutBitmap::CreateQuickDrawBitmapEx( const Graphic& rGraphic, const OutputDevice& rCompDev,
59cdf0e10cSrcweir 											  const MapMode& rMapMode, const Size& rLogSize,
60cdf0e10cSrcweir 											  const Point& rPoint, const Size& rSize )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir 	BitmapEx aRetBmp;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	if( rGraphic.IsAlpha() )
65cdf0e10cSrcweir 		aRetBmp = rGraphic.GetBitmapEx();
66cdf0e10cSrcweir 	else
67cdf0e10cSrcweir 	{
68cdf0e10cSrcweir 		VirtualDevice	aVDev( rCompDev );
69cdf0e10cSrcweir 		MapMode			aMap( rMapMode );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 		aMap.SetOrigin( Point() );
72cdf0e10cSrcweir 		aVDev.SetMapMode( aMap );
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 		Point	aPoint( aVDev.LogicToPixel( rPoint ) );
75cdf0e10cSrcweir 		Size	aOldSize( aVDev.LogicToPixel( rSize ) );
76cdf0e10cSrcweir 		Size	aAbsSize( aOldSize );
77cdf0e10cSrcweir 		Size	aQSizePix( aVDev.LogicToPixel( rLogSize ) );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 		aVDev.SetMapMode( MapMode() );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		if( aOldSize.Width() < 0 )
82cdf0e10cSrcweir 			aAbsSize.Width() = -aAbsSize.Width();
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		if( aOldSize.Height() < 0 )
85cdf0e10cSrcweir 			aAbsSize.Height() = -aAbsSize.Height();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		if( aVDev.SetOutputSizePixel( aAbsSize ) )
88cdf0e10cSrcweir 		{
89cdf0e10cSrcweir 			Point		aNewOrg( -aPoint.X(), -aPoint.Y() );
90cdf0e10cSrcweir 			const Point	aNullPoint;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 			// horizontale Spiegelung ggf. beruecksichtigen
93cdf0e10cSrcweir 			if( aOldSize.Width() < 0 )
94cdf0e10cSrcweir 			{
95cdf0e10cSrcweir 				aNewOrg.X() -= aOldSize.Width();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 				// und jetzt noch einen abziehen
98cdf0e10cSrcweir 				aNewOrg.X()--;
99cdf0e10cSrcweir 			}
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 			// vertikale Spiegelung ggf. beruecksichtigen
102cdf0e10cSrcweir 			if( rSize.Height() < 0 )
103cdf0e10cSrcweir 			{
104cdf0e10cSrcweir 				aNewOrg.Y() -= aOldSize.Height();
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 				// und jetzt noch einen abziehen
107cdf0e10cSrcweir 				aNewOrg.Y()--;
108cdf0e10cSrcweir 			}
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 			if( rGraphic.GetType() != GRAPHIC_BITMAP )
111cdf0e10cSrcweir 			{
112cdf0e10cSrcweir 				rGraphic.Draw( &aVDev, aNewOrg, aQSizePix );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 				const Bitmap	aBmp( aVDev.GetBitmap( aNullPoint, aAbsSize ) );
115cdf0e10cSrcweir 				Bitmap			aMask;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 				Graphic( rGraphic.GetGDIMetaFile().GetMonochromeMtf( COL_BLACK ) ).Draw( &aVDev, aNewOrg, aQSizePix );
118cdf0e10cSrcweir 				aMask = aVDev.GetBitmap( aNullPoint, aAbsSize );
119cdf0e10cSrcweir 				aRetBmp = BitmapEx( aBmp, aMask );
120cdf0e10cSrcweir 			}
121cdf0e10cSrcweir 			else
122cdf0e10cSrcweir 			{
123cdf0e10cSrcweir 				Bitmap	aBmp( rGraphic.GetBitmap() );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir // UNX has got problems with 1x1 bitmaps which are transparent (KA 02.11.1998)
126cdf0e10cSrcweir #ifdef UNX
127cdf0e10cSrcweir 				const Size	aBmpSize( aBmp.GetSizePixel() );
128cdf0e10cSrcweir 				sal_Bool		bFullTrans = sal_False;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 				if( aBmpSize.Width() == 1 && aBmpSize.Height() == 1 && rGraphic.IsTransparent() )
131cdf0e10cSrcweir 				{
132cdf0e10cSrcweir 					Bitmap				aTrans( rGraphic.GetBitmapEx().GetMask() );
133cdf0e10cSrcweir 					BitmapReadAccess*	pMAcc = aBmp.AcquireReadAccess();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 					if( pMAcc )
136cdf0e10cSrcweir 					{
137cdf0e10cSrcweir 						if( pMAcc->GetColor( 0, 0 ) == BitmapColor( Color( COL_WHITE ) ) )
138cdf0e10cSrcweir 							bFullTrans = sal_True;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 						aTrans.ReleaseAccess( pMAcc );
141cdf0e10cSrcweir 					}
142cdf0e10cSrcweir 				}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 				if( !bFullTrans )
145cdf0e10cSrcweir #endif // UNX
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 				{
148cdf0e10cSrcweir 					DitherBitmap( aBmp );
149cdf0e10cSrcweir 					aVDev.DrawBitmap( aNewOrg, aQSizePix, aBmp );
150cdf0e10cSrcweir 					aBmp = aVDev.GetBitmap( aNullPoint, aAbsSize );
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 					if( !rGraphic.IsTransparent() )
153cdf0e10cSrcweir 						aRetBmp = BitmapEx( aBmp );
154cdf0e10cSrcweir 					else
155cdf0e10cSrcweir 					{
156cdf0e10cSrcweir 						Bitmap	aTrans( rGraphic.GetBitmapEx().GetMask() );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 						if( !aTrans )
159cdf0e10cSrcweir 							aRetBmp = BitmapEx( aBmp, rGraphic.GetBitmapEx().GetTransparentColor() );
160cdf0e10cSrcweir 						else
161cdf0e10cSrcweir 						{
162cdf0e10cSrcweir 							aVDev.DrawBitmap( aNewOrg, aQSizePix, aTrans );
163cdf0e10cSrcweir 							aRetBmp = BitmapEx( aBmp, aVDev.GetBitmap( Point(), aAbsSize ) );
164cdf0e10cSrcweir 						}
165cdf0e10cSrcweir 					}
166cdf0e10cSrcweir 				}
167cdf0e10cSrcweir 			}
168cdf0e10cSrcweir 		}
169cdf0e10cSrcweir 	}
170cdf0e10cSrcweir 
171cdf0e10cSrcweir 	return aRetBmp;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // ------------------------------------------------------------------------
175cdf0e10cSrcweir 
176cdf0e10cSrcweir void XOutBitmap::DrawQuickDrawBitmapEx( OutputDevice* pOutDev, const Point& rPt,
177cdf0e10cSrcweir 										const Size& rSize, const BitmapEx& rBmpEx )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	const Size		aBmpSizePix( rBmpEx.GetSizePixel() );
180cdf0e10cSrcweir 	const Size		aSizePix( pOutDev->LogicToPixel( rSize ) );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 	if ( ( aSizePix.Width() - aBmpSizePix.Width() ) || ( aSizePix.Height() - aBmpSizePix.Height() ) )
183cdf0e10cSrcweir 		rBmpEx.Draw( pOutDev, rPt, rSize );
184cdf0e10cSrcweir 	else
185cdf0e10cSrcweir 		rBmpEx.Draw( pOutDev, rPt );
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir // ------------------------------------------------------------------------
189cdf0e10cSrcweir 
190cdf0e10cSrcweir void XOutBitmap::DrawTiledBitmapEx( OutputDevice* pOutDev,
191cdf0e10cSrcweir 									const Point& rStartPt, const Size& rGrfSize,
192cdf0e10cSrcweir 									const Rectangle& rTileRect, const BitmapEx& rBmpEx )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir 	Rectangle		aClipRect( pOutDev->LogicToPixel( pOutDev->GetClipRegion().GetBoundRect() ) );
195cdf0e10cSrcweir 	Rectangle		aPixRect( pOutDev->LogicToPixel( rTileRect ) );
196cdf0e10cSrcweir 	const Size		aPixSize( pOutDev->LogicToPixel( rGrfSize ) );
197cdf0e10cSrcweir 	const Point		aPixPoint( pOutDev->LogicToPixel( rStartPt ) );
198cdf0e10cSrcweir 	Point  			aOrg;
199cdf0e10cSrcweir 	const long		nWidth = aPixSize.Width();
200cdf0e10cSrcweir 	const long 		nHeight = aPixSize.Height();
201cdf0e10cSrcweir 	long			nXPos = aPixPoint.X() + ( ( aPixRect.Left() - aPixPoint.X() ) / nWidth ) * nWidth;
202cdf0e10cSrcweir 	long			nYPos = aPixPoint.Y() + ( ( aPixRect.Top() - aPixPoint.Y() ) / nHeight ) * nHeight;
203cdf0e10cSrcweir 	const long		nBottom = aPixRect.Bottom();
204cdf0e10cSrcweir 	const long		nRight = aPixRect.Right();
205cdf0e10cSrcweir 	const long		nLeft = nXPos;
206cdf0e10cSrcweir 	const sal_Bool		bNoSize = ( aPixSize == rBmpEx.GetSizePixel() );
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	pOutDev->Push();
209cdf0e10cSrcweir 	pOutDev->SetMapMode( MapMode() );
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 	// ggf. neue ClipRegion berechnen und setzen
212cdf0e10cSrcweir 	if ( pOutDev->IsClipRegion() )
213cdf0e10cSrcweir 		aPixRect.Intersection( aClipRect );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 	pOutDev->SetClipRegion( aPixRect );
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 	while( nYPos <= nBottom )
218cdf0e10cSrcweir 	{
219cdf0e10cSrcweir 		while( nXPos <= nRight )
220cdf0e10cSrcweir 		{
221cdf0e10cSrcweir 			if ( bNoSize )
222cdf0e10cSrcweir 				rBmpEx.Draw( pOutDev, Point( nXPos, nYPos ) );
223cdf0e10cSrcweir 			else
224cdf0e10cSrcweir 				rBmpEx.Draw( pOutDev, Point( nXPos, nYPos ), aPixSize );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 			nXPos += nWidth;
227cdf0e10cSrcweir 		}
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 		nXPos = nLeft;
230cdf0e10cSrcweir 		nYPos += nHeight;
231cdf0e10cSrcweir 	}
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 	pOutDev->Pop();
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir // ------------------------------------------------------------------------
237cdf0e10cSrcweir 
238cdf0e10cSrcweir Animation XOutBitmap::MirrorAnimation( const Animation& rAnimation, sal_Bool bHMirr, sal_Bool bVMirr )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	Animation aNewAnim( rAnimation );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 	if( bHMirr || bVMirr )
243cdf0e10cSrcweir 	{
244cdf0e10cSrcweir 		const Size&	rGlobalSize = aNewAnim.GetDisplaySizePixel();
245cdf0e10cSrcweir 		sal_uIntPtr		nMirrorFlags = 0L;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 		if( bHMirr )
248cdf0e10cSrcweir 			nMirrorFlags |= BMP_MIRROR_HORZ;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 		if( bVMirr )
251cdf0e10cSrcweir 			nMirrorFlags |= BMP_MIRROR_VERT;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 		for( sal_uInt16 i = 0, nCount = aNewAnim.Count(); i < nCount; i++ )
254cdf0e10cSrcweir 		{
255cdf0e10cSrcweir 			AnimationBitmap	aAnimBmp( aNewAnim.Get( i ) );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 			// BitmapEx spiegeln
258cdf0e10cSrcweir 			aAnimBmp.aBmpEx.Mirror( nMirrorFlags );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 			// Die Positionen innerhalb der Gesamtbitmap
261cdf0e10cSrcweir 			// muessen natuerlich auch angepasst werden
262cdf0e10cSrcweir 			if( bHMirr )
263cdf0e10cSrcweir 				aAnimBmp.aPosPix.X() = rGlobalSize.Width() - aAnimBmp.aPosPix.X() -
264cdf0e10cSrcweir 									   aAnimBmp.aSizePix.Width();
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 			if( bVMirr )
267cdf0e10cSrcweir 				aAnimBmp.aPosPix.Y() = rGlobalSize.Height() - aAnimBmp.aPosPix.Y() -
268cdf0e10cSrcweir 									   aAnimBmp.aSizePix.Height();
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 			aNewAnim.Replace( aAnimBmp, i );
271cdf0e10cSrcweir 		}
272cdf0e10cSrcweir 	}
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 	return aNewAnim;
275cdf0e10cSrcweir }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir // ------------------------------------------------------------------------
278cdf0e10cSrcweir 
279cdf0e10cSrcweir Graphic XOutBitmap::MirrorGraphic( const Graphic& rGraphic, const sal_uIntPtr nMirrorFlags )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir 	Graphic	aRetGraphic;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 	if( nMirrorFlags )
284cdf0e10cSrcweir 	{
285cdf0e10cSrcweir 		if( rGraphic.IsAnimated() )
286cdf0e10cSrcweir 		{
287cdf0e10cSrcweir 			aRetGraphic = MirrorAnimation( rGraphic.GetAnimation(),
288cdf0e10cSrcweir 										   ( nMirrorFlags & BMP_MIRROR_HORZ ) == BMP_MIRROR_HORZ,
289cdf0e10cSrcweir 										   ( nMirrorFlags & BMP_MIRROR_VERT ) == BMP_MIRROR_VERT );
290cdf0e10cSrcweir 		}
291cdf0e10cSrcweir 		else
292cdf0e10cSrcweir 		{
293cdf0e10cSrcweir 			if( rGraphic.IsTransparent() )
294cdf0e10cSrcweir 			{
295cdf0e10cSrcweir 				BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 				aBmpEx.Mirror( nMirrorFlags );
298cdf0e10cSrcweir 				aRetGraphic = aBmpEx;
299cdf0e10cSrcweir 			}
300cdf0e10cSrcweir 			else
301cdf0e10cSrcweir 			{
302cdf0e10cSrcweir 				Bitmap aBmp( rGraphic.GetBitmap() );
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 				aBmp.Mirror( nMirrorFlags );
305cdf0e10cSrcweir 				aRetGraphic = aBmp;
306cdf0e10cSrcweir 			}
307cdf0e10cSrcweir 		}
308cdf0e10cSrcweir 	}
309cdf0e10cSrcweir 	else
310cdf0e10cSrcweir 		aRetGraphic = rGraphic;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 	return aRetGraphic;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir // ------------------------------------------------------------------------
316cdf0e10cSrcweir 
317cdf0e10cSrcweir sal_uInt16 XOutBitmap::WriteGraphic( const Graphic& rGraphic, String& rFileName,
318cdf0e10cSrcweir 								 const String& rFilterName, const sal_uIntPtr nFlags,
319cdf0e10cSrcweir 								 const Size* pMtfSize_100TH_MM )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir 	if( rGraphic.GetType() != GRAPHIC_NONE )
322cdf0e10cSrcweir 	{
323cdf0e10cSrcweir 		INetURLObject	aURL( rFileName );
324cdf0e10cSrcweir 		Graphic			aGraphic;
325cdf0e10cSrcweir 		String			aExt;
326cdf0e10cSrcweir 		GraphicFilter*	pFilter = GraphicFilter::GetGraphicFilter();
327cdf0e10cSrcweir 		sal_uInt16			nErr = GRFILTER_FILTERERROR, nFilter = GRFILTER_FORMAT_NOTFOUND;
328cdf0e10cSrcweir 		sal_Bool			bTransparent = rGraphic.IsTransparent(), bAnimated = rGraphic.IsAnimated();
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 		DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "XOutBitmap::WriteGraphic(...): invalid URL" );
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 		// calculate correct file name
333cdf0e10cSrcweir 		if( !( nFlags & XOUTBMP_DONT_EXPAND_FILENAME ) )
334cdf0e10cSrcweir 		{
335cdf0e10cSrcweir             String aName( aURL.getBase() );
336cdf0e10cSrcweir             aName += '_';
337cdf0e10cSrcweir             aName += String(aURL.getExtension());
338cdf0e10cSrcweir             aName += '_';
339cdf0e10cSrcweir             String aStr( String::CreateFromInt32( rGraphic.GetChecksum(), 16 ) );
340cdf0e10cSrcweir             if ( aStr.GetChar(0) == '-' )
341cdf0e10cSrcweir                 aStr.SetChar(0,'m');
342cdf0e10cSrcweir             aName += aStr;
343cdf0e10cSrcweir             aURL.setBase( aName );
344cdf0e10cSrcweir 		}
345cdf0e10cSrcweir 
346cdf0e10cSrcweir 		if( ( nFlags & XOUTBMP_USE_NATIVE_IF_POSSIBLE ) &&
347cdf0e10cSrcweir 			!( nFlags & XOUTBMP_MIRROR_HORZ ) &&
348cdf0e10cSrcweir 			!( nFlags & XOUTBMP_MIRROR_VERT ) &&
349cdf0e10cSrcweir 			( rGraphic.GetType() != GRAPHIC_GDIMETAFILE ) && rGraphic.IsLink() )
350cdf0e10cSrcweir 		{
351cdf0e10cSrcweir 			// try to write native link
352cdf0e10cSrcweir 			const GfxLink aGfxLink( ( (Graphic&) rGraphic ).GetLink() );
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 			switch( aGfxLink.GetType() )
355cdf0e10cSrcweir 			{
356cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_GIF ): aExt = FORMAT_GIF; break;
357cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_JPG ): aExt = FORMAT_JPG; break;
358cdf0e10cSrcweir 				case( GFX_LINK_TYPE_NATIVE_PNG ): aExt = FORMAT_PNG; break;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 				default:
361cdf0e10cSrcweir 				break;
362cdf0e10cSrcweir 			}
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 			if( aExt.Len() )
365cdf0e10cSrcweir 			{
366cdf0e10cSrcweir                 if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION))
367cdf0e10cSrcweir                     aURL.setExtension( aExt );
368cdf0e10cSrcweir 				rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 				SfxMedium	aMedium( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_SHARE_DENYNONE | STREAM_TRUNC, sal_True );
371cdf0e10cSrcweir 				SvStream*	pOStm = aMedium.GetOutStream();
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 				if( pOStm && aGfxLink.GetDataSize() && aGfxLink.GetData() )
374cdf0e10cSrcweir 				{
375cdf0e10cSrcweir 					pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
376cdf0e10cSrcweir 					aMedium.Commit();
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 					if( !aMedium.GetError() )
379cdf0e10cSrcweir 						nErr = GRFILTER_OK;
380cdf0e10cSrcweir 				}
381cdf0e10cSrcweir 			}
382cdf0e10cSrcweir 		}
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 		if( GRFILTER_OK != nErr )
385cdf0e10cSrcweir 		{
386cdf0e10cSrcweir 			String	aFilter( rFilterName );
387cdf0e10cSrcweir 			sal_Bool	bWriteTransGrf = ( aFilter.EqualsIgnoreCaseAscii( "transgrf" ) ) ||
388cdf0e10cSrcweir 									 ( aFilter.EqualsIgnoreCaseAscii( "gif" ) ) ||
389cdf0e10cSrcweir 									 ( nFlags & XOUTBMP_USE_GIF_IF_POSSIBLE ) ||
390cdf0e10cSrcweir 									 ( ( nFlags & XOUTBMP_USE_GIF_IF_SENSIBLE ) && ( bAnimated || bTransparent ) );
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 			// get filter and extension
393cdf0e10cSrcweir 			if( bWriteTransGrf )
394cdf0e10cSrcweir 				aFilter = FORMAT_GIF;
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 			nFilter = pFilter->GetExportFormatNumberForShortName( aFilter );
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 			if( GRFILTER_FORMAT_NOTFOUND == nFilter )
399cdf0e10cSrcweir 			{
400cdf0e10cSrcweir 				nFilter = pFilter->GetExportFormatNumberForShortName( FORMAT_JPG );
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 				if( GRFILTER_FORMAT_NOTFOUND == nFilter )
403cdf0e10cSrcweir 					nFilter = pFilter->GetExportFormatNumberForShortName( FORMAT_BMP );
404cdf0e10cSrcweir 			}
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 			if( GRFILTER_FORMAT_NOTFOUND != nFilter )
407cdf0e10cSrcweir 			{
408cdf0e10cSrcweir 				aExt = pFilter->GetExportFormatShortName( nFilter ).ToLowerAscii();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 				if( bWriteTransGrf )
411cdf0e10cSrcweir 				{
412cdf0e10cSrcweir 					if( bAnimated  )
413cdf0e10cSrcweir 						aGraphic = rGraphic;
414cdf0e10cSrcweir 					else
415cdf0e10cSrcweir 					{
416cdf0e10cSrcweir 						if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GRAPHIC_BITMAP ) )
417cdf0e10cSrcweir 						{
418cdf0e10cSrcweir 							VirtualDevice aVDev;
419cdf0e10cSrcweir 							const Size    aSize( aVDev.LogicToPixel( *pMtfSize_100TH_MM, MAP_100TH_MM ) );
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 							if( aVDev.SetOutputSizePixel( aSize ) )
422cdf0e10cSrcweir 							{
423cdf0e10cSrcweir 								const Wallpaper aWallpaper( aVDev.GetBackground() );
424cdf0e10cSrcweir 								const Point		aPt;
425cdf0e10cSrcweir 
426cdf0e10cSrcweir 								aVDev.SetBackground( Wallpaper( Color( COL_BLACK ) ) );
427cdf0e10cSrcweir 								aVDev.Erase();
428cdf0e10cSrcweir 								rGraphic.Draw( &aVDev, aPt, aSize );
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 								const Bitmap aBitmap( aVDev.GetBitmap( aPt, aSize ) );
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 								aVDev.SetBackground( aWallpaper );
433cdf0e10cSrcweir 								aVDev.Erase();
434cdf0e10cSrcweir 								rGraphic.Draw( &aVDev, aPt, aSize );
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 								aVDev.SetRasterOp( ROP_XOR );
437cdf0e10cSrcweir 								aVDev.DrawBitmap( aPt, aSize, aBitmap );
438cdf0e10cSrcweir 								aGraphic = BitmapEx( aBitmap, aVDev.GetBitmap( aPt, aSize ) );
439cdf0e10cSrcweir 							}
440cdf0e10cSrcweir 							else
441cdf0e10cSrcweir 								aGraphic = rGraphic.GetBitmapEx();
442cdf0e10cSrcweir 						}
443cdf0e10cSrcweir 						else
444cdf0e10cSrcweir 							aGraphic = rGraphic.GetBitmapEx();
445cdf0e10cSrcweir 					}
446cdf0e10cSrcweir 				}
447cdf0e10cSrcweir 				else
448cdf0e10cSrcweir 				{
449cdf0e10cSrcweir 					if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GRAPHIC_BITMAP ) )
450cdf0e10cSrcweir 					{
451cdf0e10cSrcweir 						VirtualDevice	aVDev;
452cdf0e10cSrcweir 						const Size		aSize( aVDev.LogicToPixel( *pMtfSize_100TH_MM, MAP_100TH_MM ) );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 						if( aVDev.SetOutputSizePixel( aSize ) )
455cdf0e10cSrcweir 						{
456cdf0e10cSrcweir 							rGraphic.Draw( &aVDev, Point(), aSize );
457cdf0e10cSrcweir 							aGraphic =  aVDev.GetBitmap( Point(), aSize );
458cdf0e10cSrcweir 						}
459cdf0e10cSrcweir 						else
460cdf0e10cSrcweir 							aGraphic = rGraphic.GetBitmap();
461cdf0e10cSrcweir 					}
462cdf0e10cSrcweir 					else
463cdf0e10cSrcweir 						aGraphic = rGraphic.GetBitmap();
464cdf0e10cSrcweir 				}
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 				// mirror?
467cdf0e10cSrcweir 				if( ( nFlags & XOUTBMP_MIRROR_HORZ ) || ( nFlags & XOUTBMP_MIRROR_VERT ) )
468cdf0e10cSrcweir 					aGraphic = MirrorGraphic( aGraphic, nFlags );
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 				if( ( GRFILTER_FORMAT_NOTFOUND != nFilter ) && ( aGraphic.GetType() != GRAPHIC_NONE ) )
471cdf0e10cSrcweir 				{
472cdf0e10cSrcweir                     if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION))
473cdf0e10cSrcweir                         aURL.setExtension( aExt );
474cdf0e10cSrcweir 					rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
475cdf0e10cSrcweir 					nErr = ExportGraphic( aGraphic, aURL, *pFilter, nFilter, NULL );
476cdf0e10cSrcweir 				}
477cdf0e10cSrcweir 			}
478cdf0e10cSrcweir 		}
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 		return nErr;
481cdf0e10cSrcweir 	}
482cdf0e10cSrcweir 	else
483cdf0e10cSrcweir 	{
484cdf0e10cSrcweir 		return GRFILTER_OK;
485cdf0e10cSrcweir 	}
486cdf0e10cSrcweir }
487cdf0e10cSrcweir 
488cdf0e10cSrcweir // ------------------------------------------------------------------------
489cdf0e10cSrcweir 
490cdf0e10cSrcweir #ifdef _MSC_VER
491cdf0e10cSrcweir #pragma optimize ( "", off )
492cdf0e10cSrcweir #endif
493cdf0e10cSrcweir 
494cdf0e10cSrcweir sal_uInt16 XOutBitmap::ExportGraphic( const Graphic& rGraphic, const INetURLObject& rURL,
495cdf0e10cSrcweir 								  GraphicFilter& rFilter, const sal_uInt16 nFormat,
496cdf0e10cSrcweir 								  const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir 	DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "XOutBitmap::ExportGraphic(...): invalid URL" );
499cdf0e10cSrcweir 
500cdf0e10cSrcweir 	SfxMedium	aMedium( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_SHARE_DENYNONE | STREAM_TRUNC, sal_True );
501cdf0e10cSrcweir 	SvStream*	pOStm = aMedium.GetOutStream();
502cdf0e10cSrcweir 	sal_uInt16		nRet = GRFILTER_IOERROR;
503cdf0e10cSrcweir 
504cdf0e10cSrcweir 	if( pOStm )
505cdf0e10cSrcweir 	{
506cdf0e10cSrcweir 		pGrfFilter = &rFilter;
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 		nRet = rFilter.ExportGraphic( rGraphic, rURL.GetMainURL( INetURLObject::NO_DECODE ), *pOStm, nFormat, pFilterData );
509cdf0e10cSrcweir 
510cdf0e10cSrcweir 		pGrfFilter = NULL;
511cdf0e10cSrcweir 		aMedium.Commit();
512cdf0e10cSrcweir 
513cdf0e10cSrcweir 		if( aMedium.GetError() && ( GRFILTER_OK == nRet  ) )
514cdf0e10cSrcweir 			nRet = GRFILTER_IOERROR;
515cdf0e10cSrcweir 	}
516cdf0e10cSrcweir 
517cdf0e10cSrcweir 	return nRet;
518cdf0e10cSrcweir }
519cdf0e10cSrcweir 
520cdf0e10cSrcweir #ifdef _MSC_VER
521cdf0e10cSrcweir #pragma optimize ( "", on )
522cdf0e10cSrcweir #endif
523cdf0e10cSrcweir 
524cdf0e10cSrcweir // ------------------------------------------------------------------------
525cdf0e10cSrcweir 
526cdf0e10cSrcweir Bitmap XOutBitmap::DetectEdges( const Bitmap& rBmp, const sal_uInt8 cThreshold )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir 	const Size	aSize( rBmp.GetSizePixel() );
529cdf0e10cSrcweir 	Bitmap		aRetBmp;
530cdf0e10cSrcweir 	sal_Bool		bRet = sal_False;
531cdf0e10cSrcweir 
532cdf0e10cSrcweir 	if( ( aSize.Width() > 2L ) && ( aSize.Height() > 2L ) )
533cdf0e10cSrcweir 	{
534cdf0e10cSrcweir 		Bitmap aWorkBmp( rBmp );
535cdf0e10cSrcweir 
536cdf0e10cSrcweir 		if( aWorkBmp.Convert( BMP_CONVERSION_8BIT_GREYS ) )
537cdf0e10cSrcweir 		{
538cdf0e10cSrcweir 			Bitmap				aDstBmp( aSize, 1 );
539cdf0e10cSrcweir 			BitmapReadAccess*	pReadAcc = aWorkBmp.AcquireReadAccess();
540cdf0e10cSrcweir 			BitmapWriteAccess*	pWriteAcc = aDstBmp.AcquireWriteAccess();
541cdf0e10cSrcweir 
542cdf0e10cSrcweir 			if( pReadAcc && pWriteAcc )
543cdf0e10cSrcweir 			{
544cdf0e10cSrcweir 				const long			nWidth = aSize.Width();
545cdf0e10cSrcweir 				const long			nWidth2 = nWidth - 2L;
546cdf0e10cSrcweir 				const long			nHeight = aSize.Height();
547cdf0e10cSrcweir 				const long			nHeight2 = nHeight - 2L;
548cdf0e10cSrcweir 				const long			lThres2 = (long) cThreshold * cThreshold;
549cdf0e10cSrcweir 				const BitmapColor	aWhite = (sal_uInt8) pWriteAcc->GetBestMatchingColor( Color( COL_WHITE ) );
550cdf0e10cSrcweir 				const BitmapColor	aBlack = (sal_uInt8) pWriteAcc->GetBestMatchingColor( Color( COL_BLACK ) );
551cdf0e10cSrcweir 				long				nSum1;
552cdf0e10cSrcweir 				long				nSum2;
553cdf0e10cSrcweir 				long				lGray;
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 				// Rand mit Weiss init.
556cdf0e10cSrcweir 				pWriteAcc->SetLineColor( Color( COL_WHITE) );
557cdf0e10cSrcweir 				pWriteAcc->DrawLine( Point(), Point( nWidth - 1L, 0L ) );
558cdf0e10cSrcweir 				pWriteAcc->DrawLine( Point( nWidth - 1L, 0L ), Point( nWidth - 1L, nHeight - 1L ) );
559cdf0e10cSrcweir 				pWriteAcc->DrawLine( Point( nWidth - 1L, nHeight - 1L ), Point( 0L, nHeight - 1L ) );
560cdf0e10cSrcweir 				pWriteAcc->DrawLine( Point( 0, nHeight - 1L ), Point() );
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 				for( long nY = 0L, nY1 = 1L, nY2 = 2; nY < nHeight2; nY++, nY1++, nY2++ )
563cdf0e10cSrcweir 				{
564cdf0e10cSrcweir 					for( long nX = 0L, nXDst = 1L, nXTmp; nX < nWidth2; nX++, nXDst++ )
565cdf0e10cSrcweir 					{
566cdf0e10cSrcweir 						nXTmp = nX;
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 						nSum1 = -( nSum2 = lGray = (sal_uInt8) pReadAcc->GetPixel( nY, nXTmp++ ) );
569cdf0e10cSrcweir 						nSum2 += ( (long) (sal_uInt8) pReadAcc->GetPixel( nY, nXTmp++ ) ) << 1;
570cdf0e10cSrcweir 						nSum1 += ( lGray = pReadAcc->GetPixel( nY, nXTmp ) );
571cdf0e10cSrcweir 						nSum2 += lGray;
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 						nSum1 += ( (long) (sal_uInt8) pReadAcc->GetPixel( nY1, nXTmp ) ) << 1;
574cdf0e10cSrcweir 						nSum1 -= ( (long) (sal_uInt8) pReadAcc->GetPixel( nY1, nXTmp -= 2 ) ) << 1;
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 						nSum1 += ( lGray = -(long) (sal_uInt8) pReadAcc->GetPixel( nY2, nXTmp++ ) );
577cdf0e10cSrcweir 						nSum2 += lGray;
578cdf0e10cSrcweir 						nSum2 -= ( (long) (sal_uInt8) pReadAcc->GetPixel( nY2, nXTmp++ ) ) << 1;
579cdf0e10cSrcweir 						nSum1 += ( lGray = (long) (sal_uInt8) pReadAcc->GetPixel( nY2, nXTmp ) );
580cdf0e10cSrcweir 						nSum2 -= lGray;
581cdf0e10cSrcweir 
582cdf0e10cSrcweir 						if( ( nSum1 * nSum1 + nSum2 * nSum2 ) < lThres2 )
583cdf0e10cSrcweir 							pWriteAcc->SetPixel( nY1, nXDst, aWhite );
584cdf0e10cSrcweir 						else
585cdf0e10cSrcweir 							pWriteAcc->SetPixel( nY1, nXDst, aBlack );
586cdf0e10cSrcweir 					}
587cdf0e10cSrcweir 				}
588cdf0e10cSrcweir 
589cdf0e10cSrcweir 				bRet = sal_True;
590cdf0e10cSrcweir 			}
591cdf0e10cSrcweir 
592cdf0e10cSrcweir 			aWorkBmp.ReleaseAccess( pReadAcc );
593cdf0e10cSrcweir 			aDstBmp.ReleaseAccess( pWriteAcc );
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 			if( bRet )
596cdf0e10cSrcweir 				aRetBmp = aDstBmp;
597cdf0e10cSrcweir 		}
598cdf0e10cSrcweir 	}
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 	if( !aRetBmp )
601cdf0e10cSrcweir 		aRetBmp = rBmp;
602cdf0e10cSrcweir 	else
603cdf0e10cSrcweir 	{
604cdf0e10cSrcweir 		aRetBmp.SetPrefMapMode( rBmp.GetPrefMapMode() );
605cdf0e10cSrcweir 		aRetBmp.SetPrefSize( rBmp.GetPrefSize() );
606cdf0e10cSrcweir 	}
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 	return aRetBmp;
609cdf0e10cSrcweir };
610cdf0e10cSrcweir 
611cdf0e10cSrcweir // ------------------------------------------------------------------------
612cdf0e10cSrcweir 
613cdf0e10cSrcweir Polygon XOutBitmap::GetCountour( const Bitmap& rBmp, const sal_uIntPtr nFlags,
614cdf0e10cSrcweir 								 const sal_uInt8 cEdgeDetectThreshold, const Rectangle* pWorkRectPixel )
615cdf0e10cSrcweir {
616cdf0e10cSrcweir 	Bitmap		aWorkBmp;
617cdf0e10cSrcweir 	Polygon		aRetPoly;
618cdf0e10cSrcweir 	Point		aTmpPoint;
619cdf0e10cSrcweir 	Rectangle	aWorkRect( aTmpPoint, rBmp.GetSizePixel() );
620cdf0e10cSrcweir 
621cdf0e10cSrcweir 	if( pWorkRectPixel )
622cdf0e10cSrcweir 		aWorkRect.Intersection( *pWorkRectPixel );
623cdf0e10cSrcweir 
624cdf0e10cSrcweir 	aWorkRect.Justify();
625cdf0e10cSrcweir 
626cdf0e10cSrcweir 	if( ( aWorkRect.GetWidth() > 4 ) && ( aWorkRect.GetHeight() > 4 ) )
627cdf0e10cSrcweir 	{
628cdf0e10cSrcweir 		// falls Flag gesetzt, muessen wir Kanten detektieren
629cdf0e10cSrcweir 		if( nFlags & XOUTBMP_CONTOUR_EDGEDETECT )
630cdf0e10cSrcweir 			aWorkBmp = DetectEdges( rBmp, cEdgeDetectThreshold );
631cdf0e10cSrcweir 		else
632cdf0e10cSrcweir 			aWorkBmp = rBmp;
633cdf0e10cSrcweir 
634cdf0e10cSrcweir 		BitmapReadAccess* pAcc = aWorkBmp.AcquireReadAccess();
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 		if( pAcc )
637cdf0e10cSrcweir 		{
638cdf0e10cSrcweir 			const Size&			rPrefSize = aWorkBmp.GetPrefSize();
639cdf0e10cSrcweir 			const long			nWidth = pAcc->Width();
640cdf0e10cSrcweir 			const long			nHeight = pAcc->Height();
641cdf0e10cSrcweir 			const double		fFactorX = (double) rPrefSize.Width() / nWidth;
642cdf0e10cSrcweir 			const double		fFactorY = (double) rPrefSize.Height() / nHeight;
643cdf0e10cSrcweir 			const long			nStartX1 = aWorkRect.Left() + 1L;
644cdf0e10cSrcweir 			const long			nEndX1 = aWorkRect.Right();
645cdf0e10cSrcweir 			const long			nStartX2 = nEndX1 - 1L;
646cdf0e10cSrcweir //			const long			nEndX2 = nStartX1 - 1L;
647cdf0e10cSrcweir 			const long			nStartY1 = aWorkRect.Top() + 1L;
648cdf0e10cSrcweir 			const long			nEndY1 = aWorkRect.Bottom();
649cdf0e10cSrcweir 			const long			nStartY2 = nEndY1 - 1L;
650cdf0e10cSrcweir //			const long			nEndY2 = nStartY1 - 1L;
651cdf0e10cSrcweir 			Point*				pPoints1 = NULL;
652cdf0e10cSrcweir 			Point*				pPoints2 = NULL;
653cdf0e10cSrcweir 			long				nX, nY;
654cdf0e10cSrcweir 			sal_uInt16				nPolyPos = 0;
655cdf0e10cSrcweir 			const BitmapColor	aBlack = pAcc->GetBestMatchingColor( Color( COL_BLACK ) );
656cdf0e10cSrcweir 
657cdf0e10cSrcweir 			if( nFlags & XOUTBMP_CONTOUR_VERT )
658cdf0e10cSrcweir 			{
659cdf0e10cSrcweir 				pPoints1 = new Point[ nWidth ];
660cdf0e10cSrcweir 				pPoints2 = new Point[ nWidth ];
661cdf0e10cSrcweir 
662cdf0e10cSrcweir 				for( nX = nStartX1; nX < nEndX1; nX++ )
663cdf0e10cSrcweir 				{
664cdf0e10cSrcweir 					nY = nStartY1;
665cdf0e10cSrcweir 
666cdf0e10cSrcweir 					// zunaechst Zeile von Links nach Rechts durchlaufen
667cdf0e10cSrcweir 					while( nY < nEndY1 )
668cdf0e10cSrcweir 					{
669cdf0e10cSrcweir 						if( aBlack == pAcc->GetPixel( nY, nX ) )
670cdf0e10cSrcweir 						{
671cdf0e10cSrcweir 							pPoints1[ nPolyPos ] = Point( nX, nY );
672cdf0e10cSrcweir 							nY = nStartY2;
673cdf0e10cSrcweir 
674cdf0e10cSrcweir 							// diese Schleife wird immer gebreaked da hier ja min. ein Pixel ist
675cdf0e10cSrcweir 							while( sal_True )
676cdf0e10cSrcweir 							{
677cdf0e10cSrcweir 								if( aBlack == pAcc->GetPixel( nY, nX ) )
678cdf0e10cSrcweir 								{
679cdf0e10cSrcweir 									pPoints2[ nPolyPos ] = Point( nX, nY );
680cdf0e10cSrcweir 									break;
681cdf0e10cSrcweir 								}
682cdf0e10cSrcweir 
683cdf0e10cSrcweir 								nY--;
684cdf0e10cSrcweir 							}
685cdf0e10cSrcweir 
686cdf0e10cSrcweir 							nPolyPos++;
687cdf0e10cSrcweir 							break;
688cdf0e10cSrcweir 						}
689cdf0e10cSrcweir 
690cdf0e10cSrcweir 						nY++;
691cdf0e10cSrcweir 					}
692cdf0e10cSrcweir 				}
693cdf0e10cSrcweir 			}
694cdf0e10cSrcweir 			else
695cdf0e10cSrcweir 			{
696cdf0e10cSrcweir 				pPoints1 = new Point[ nHeight ];
697cdf0e10cSrcweir 				pPoints2 = new Point[ nHeight ];
698cdf0e10cSrcweir 
699cdf0e10cSrcweir 				for ( nY = nStartY1; nY < nEndY1; nY++ )
700cdf0e10cSrcweir 				{
701cdf0e10cSrcweir 					nX = nStartX1;
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 					// zunaechst Zeile von Links nach Rechts durchlaufen
704cdf0e10cSrcweir 					while( nX < nEndX1 )
705cdf0e10cSrcweir 					{
706cdf0e10cSrcweir 						if( aBlack == pAcc->GetPixel( nY, nX ) )
707cdf0e10cSrcweir 						{
708cdf0e10cSrcweir 							pPoints1[ nPolyPos ] = Point( nX, nY );
709cdf0e10cSrcweir 							nX = nStartX2;
710cdf0e10cSrcweir 
711cdf0e10cSrcweir 							// diese Schleife wird immer gebreaked da hier ja min. ein Pixel ist
712cdf0e10cSrcweir 							while( sal_True )
713cdf0e10cSrcweir 							{
714cdf0e10cSrcweir 								if( aBlack == pAcc->GetPixel( nY, nX ) )
715cdf0e10cSrcweir 								{
716cdf0e10cSrcweir 									pPoints2[ nPolyPos ] = Point( nX, nY );
717cdf0e10cSrcweir 									break;
718cdf0e10cSrcweir 								}
719cdf0e10cSrcweir 
720cdf0e10cSrcweir 								nX--;
721cdf0e10cSrcweir 							}
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 							nPolyPos++;
724cdf0e10cSrcweir 							break;
725cdf0e10cSrcweir 						}
726cdf0e10cSrcweir 
727cdf0e10cSrcweir 						nX++;
728cdf0e10cSrcweir 					}
729cdf0e10cSrcweir 				}
730cdf0e10cSrcweir 			}
731cdf0e10cSrcweir 
732cdf0e10cSrcweir 			const sal_uInt16 nNewSize1 = nPolyPos << 1;
733cdf0e10cSrcweir 
734cdf0e10cSrcweir 			aRetPoly = Polygon( nPolyPos, pPoints1 );
735cdf0e10cSrcweir 			aRetPoly.SetSize( nNewSize1 + 1 );
736cdf0e10cSrcweir 			aRetPoly[ nNewSize1 ] = aRetPoly[ 0 ];
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 			for( sal_uInt16 j = nPolyPos; nPolyPos < nNewSize1; )
739cdf0e10cSrcweir 				aRetPoly[ nPolyPos++ ] = pPoints2[ --j ];
740cdf0e10cSrcweir 
741cdf0e10cSrcweir 			if( ( fFactorX != 0. ) && ( fFactorY != 0. ) )
742cdf0e10cSrcweir 				aRetPoly.Scale( fFactorX, fFactorY );
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 			delete[] pPoints1;
745cdf0e10cSrcweir 			delete[] pPoints2;
746cdf0e10cSrcweir 		}
747cdf0e10cSrcweir 	}
748cdf0e10cSrcweir 
749cdf0e10cSrcweir 	return aRetPoly;
750cdf0e10cSrcweir };
751cdf0e10cSrcweir 
752cdf0e10cSrcweir // ----------------
753cdf0e10cSrcweir // - DitherBitmap -
754cdf0e10cSrcweir // ----------------
755cdf0e10cSrcweir 
756cdf0e10cSrcweir sal_Bool DitherBitmap( Bitmap& rBitmap )
757cdf0e10cSrcweir {
758cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	if( ( rBitmap.GetBitCount() >= 8 ) && ( Application::GetDefaultDevice()->GetColorCount() < 257 ) )
761cdf0e10cSrcweir 		bRet = rBitmap.Dither( BMP_DITHER_FLOYD );
762cdf0e10cSrcweir 	else
763cdf0e10cSrcweir 		bRet = sal_False;
764cdf0e10cSrcweir 
765cdf0e10cSrcweir 	return bRet;
766cdf0e10cSrcweir }
767