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