xref: /aoo42x/main/svx/source/xoutdev/_xoutbmp.cxx (revision 72583341)
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 
MirrorAnimation(const Animation & rAnimation,sal_Bool bHMirr,sal_Bool bVMirr)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 
MirrorGraphic(const Graphic & rGraphic,const sal_uIntPtr nMirrorFlags)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 
WriteGraphic(const Graphic & rGraphic,String & rFileName,const String & rFilterName,const sal_uIntPtr nFlags,const Size * pMtfSize_100TH_MM)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 
207                     // #15508# added BMP type for better exports (no call/trigger found, prob used in HTML export)
208                     case( GFX_LINK_TYPE_NATIVE_BMP ): aExt = FORMAT_BMP; break;
209 
210 				    case( GFX_LINK_TYPE_NATIVE_JPG ): aExt = FORMAT_JPG; break;
211 				    case( GFX_LINK_TYPE_NATIVE_PNG ): aExt = FORMAT_PNG; break;
212 
213 				    default:
214 				    break;
215 			    }
216 
217 			    if( aExt.Len() )
218 			    {
219                     if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION))
220                         aURL.setExtension( aExt );
221 				    rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
222 
223 				    SfxMedium	aMedium( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_SHARE_DENYNONE | STREAM_TRUNC, sal_True );
224 				    SvStream*	pOStm = aMedium.GetOutStream();
225 
226 				    if( pOStm && aGfxLink.GetDataSize() && aGfxLink.GetData() )
227 				    {
228 					    pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
229 					    aMedium.Commit();
230 
231 					    if( !aMedium.GetError() )
232 						    nErr = GRFILTER_OK;
233 				    }
234 			    }
235 		    }
236         }
237 
238 		if( GRFILTER_OK != nErr )
239 		{
240 			String	aFilter( rFilterName );
241 			sal_Bool	bWriteTransGrf = ( aFilter.EqualsIgnoreCaseAscii( "transgrf" ) ) ||
242 									 ( aFilter.EqualsIgnoreCaseAscii( "gif" ) ) ||
243 									 ( nFlags & XOUTBMP_USE_GIF_IF_POSSIBLE ) ||
244 									 ( ( nFlags & XOUTBMP_USE_GIF_IF_SENSIBLE ) && ( bAnimated || bTransparent ) );
245 
246 			// get filter and extension
247 			if( bWriteTransGrf )
248 				aFilter = FORMAT_GIF;
249 
250 			nFilter = pFilter->GetExportFormatNumberForShortName( aFilter );
251 
252 			if( GRFILTER_FORMAT_NOTFOUND == nFilter )
253 			{
254 				nFilter = pFilter->GetExportFormatNumberForShortName( FORMAT_JPG );
255 
256 				if( GRFILTER_FORMAT_NOTFOUND == nFilter )
257 					nFilter = pFilter->GetExportFormatNumberForShortName( FORMAT_BMP );
258 			}
259 
260 			if( GRFILTER_FORMAT_NOTFOUND != nFilter )
261 			{
262 				aExt = pFilter->GetExportFormatShortName( nFilter ).ToLowerAscii();
263 
264 				if( bWriteTransGrf )
265 				{
266 					if( bAnimated  )
267 						aGraphic = rGraphic;
268 					else
269 					{
270 						if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GRAPHIC_BITMAP ) )
271 						{
272 							VirtualDevice aVDev;
273 							const Size    aSize( aVDev.LogicToPixel( *pMtfSize_100TH_MM, MAP_100TH_MM ) );
274 
275 							if( aVDev.SetOutputSizePixel( aSize ) )
276 							{
277 								const Wallpaper aWallpaper( aVDev.GetBackground() );
278 								const Point		aPt;
279 
280 								aVDev.SetBackground( Wallpaper( Color( COL_BLACK ) ) );
281 								aVDev.Erase();
282 								rGraphic.Draw( &aVDev, aPt, aSize );
283 
284 								const Bitmap aBitmap( aVDev.GetBitmap( aPt, aSize ) );
285 
286 								aVDev.SetBackground( aWallpaper );
287 								aVDev.Erase();
288 								rGraphic.Draw( &aVDev, aPt, aSize );
289 
290 								aVDev.SetRasterOp( ROP_XOR );
291 								aVDev.DrawBitmap( aPt, aSize, aBitmap );
292 								aGraphic = BitmapEx( aBitmap, aVDev.GetBitmap( aPt, aSize ) );
293 							}
294 							else
295 								aGraphic = rGraphic.GetBitmapEx();
296 						}
297 						else
298 							aGraphic = rGraphic.GetBitmapEx();
299 					}
300 				}
301 				else
302 				{
303 					if( pMtfSize_100TH_MM && ( rGraphic.GetType() != GRAPHIC_BITMAP ) )
304 					{
305 						VirtualDevice	aVDev;
306 						const Size		aSize( aVDev.LogicToPixel( *pMtfSize_100TH_MM, MAP_100TH_MM ) );
307 
308 						if( aVDev.SetOutputSizePixel( aSize ) )
309 						{
310 							rGraphic.Draw( &aVDev, Point(), aSize );
311 							aGraphic =  aVDev.GetBitmap( Point(), aSize );
312 						}
313 						else
314 							aGraphic = rGraphic.GetBitmap();
315 					}
316 					else
317 						aGraphic = rGraphic.GetBitmap();
318 				}
319 
320 				// mirror?
321 				if( ( nFlags & XOUTBMP_MIRROR_HORZ ) || ( nFlags & XOUTBMP_MIRROR_VERT ) )
322 					aGraphic = MirrorGraphic( aGraphic, nFlags );
323 
324 				if( ( GRFILTER_FORMAT_NOTFOUND != nFilter ) && ( aGraphic.GetType() != GRAPHIC_NONE ) )
325 				{
326                     if( 0 == (nFlags & XOUTBMP_DONT_ADD_EXTENSION))
327                         aURL.setExtension( aExt );
328 					rFileName = aURL.GetMainURL( INetURLObject::NO_DECODE );
329 					nErr = ExportGraphic( aGraphic, aURL, *pFilter, nFilter, NULL );
330 				}
331 			}
332 		}
333 
334 		return nErr;
335 	}
336 	else
337 	{
338 		return GRFILTER_OK;
339 	}
340 }
341 
342 // ------------------------------------------------------------------------
343 
344 #ifdef _MSC_VER
345 #pragma optimize ( "", off )
346 #endif
347 
ExportGraphic(const Graphic & rGraphic,const INetURLObject & rURL,GraphicFilter & rFilter,const sal_uInt16 nFormat,const com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> * pFilterData)348 sal_uInt16 XOutBitmap::ExportGraphic( const Graphic& rGraphic, const INetURLObject& rURL,
349 								  GraphicFilter& rFilter, const sal_uInt16 nFormat,
350 								  const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >* pFilterData )
351 {
352 	DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "XOutBitmap::ExportGraphic(...): invalid URL" );
353 
354 	SfxMedium	aMedium( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_SHARE_DENYNONE | STREAM_TRUNC, sal_True );
355 	SvStream*	pOStm = aMedium.GetOutStream();
356 	sal_uInt16		nRet = GRFILTER_IOERROR;
357 
358 	if( pOStm )
359 	{
360 		pGrfFilter = &rFilter;
361 
362 		nRet = rFilter.ExportGraphic( rGraphic, rURL.GetMainURL( INetURLObject::NO_DECODE ), *pOStm, nFormat, pFilterData );
363 
364 		pGrfFilter = NULL;
365 		aMedium.Commit();
366 
367 		if( aMedium.GetError() && ( GRFILTER_OK == nRet  ) )
368 			nRet = GRFILTER_IOERROR;
369 	}
370 
371 	return nRet;
372 }
373 
374 #ifdef _MSC_VER
375 #pragma optimize ( "", on )
376 #endif
377 
378 // ------------------------------------------------------------------------
379 
DetectEdges(const Bitmap & rBmp,const sal_uInt8 cThreshold)380 Bitmap XOutBitmap::DetectEdges( const Bitmap& rBmp, const sal_uInt8 cThreshold )
381 {
382 	const Size	aSize( rBmp.GetSizePixel() );
383 	Bitmap		aRetBmp;
384 	sal_Bool		bRet = sal_False;
385 
386 	if( ( aSize.Width() > 2L ) && ( aSize.Height() > 2L ) )
387 	{
388 		Bitmap aWorkBmp( rBmp );
389 
390 		if( aWorkBmp.Convert( BMP_CONVERSION_8BIT_GREYS ) )
391 		{
392 			Bitmap				aDstBmp( aSize, 1 );
393 			BitmapReadAccess*	pReadAcc = aWorkBmp.AcquireReadAccess();
394 			BitmapWriteAccess*	pWriteAcc = aDstBmp.AcquireWriteAccess();
395 
396 			if( pReadAcc && pWriteAcc )
397 			{
398 				const long			nWidth = aSize.Width();
399 				const long			nWidth2 = nWidth - 2L;
400 				const long			nHeight = aSize.Height();
401 				const long			nHeight2 = nHeight - 2L;
402 				const long			lThres2 = (long) cThreshold * cThreshold;
403 				const sal_uInt8 nWhitePalIdx(static_cast< sal_uInt8 >(pWriteAcc->GetBestPaletteIndex(Color(COL_WHITE))));
404 				const sal_uInt8 nBlackPalIdx(static_cast< sal_uInt8 >(pWriteAcc->GetBestPaletteIndex(Color(COL_BLACK))));
405 				long				nSum1;
406 				long				nSum2;
407 				long				lGray;
408 
409 				// initialize border with white pixels
410 				pWriteAcc->SetLineColor( Color( COL_WHITE) );
411 				pWriteAcc->DrawLine( Point(), Point( nWidth - 1L, 0L ) );
412 				pWriteAcc->DrawLine( Point( nWidth - 1L, 0L ), Point( nWidth - 1L, nHeight - 1L ) );
413 				pWriteAcc->DrawLine( Point( nWidth - 1L, nHeight - 1L ), Point( 0L, nHeight - 1L ) );
414 				pWriteAcc->DrawLine( Point( 0, nHeight - 1L ), Point() );
415 
416 				for( long nY = 0L, nY1 = 1L, nY2 = 2; nY < nHeight2; nY++, nY1++, nY2++ )
417 				{
418 					for( long nX = 0L, nXDst = 1L, nXTmp; nX < nWidth2; nX++, nXDst++ )
419 					{
420 						nXTmp = nX;
421 
422 						nSum1 = -( nSum2 = lGray = pReadAcc->GetPixelIndex( nY, nXTmp++ ) );
423 						nSum2 += ( (long) pReadAcc->GetPixelIndex( nY, nXTmp++ ) ) << 1;
424 						nSum1 += ( lGray = pReadAcc->GetPixelIndex( nY, nXTmp ) );
425 						nSum2 += lGray;
426 
427 						nSum1 += ( (long) pReadAcc->GetPixelIndex( nY1, nXTmp ) ) << 1;
428 						nSum1 -= ( (long) pReadAcc->GetPixelIndex( nY1, nXTmp -= 2 ) ) << 1;
429 
430 						nSum1 += ( lGray = -(long) pReadAcc->GetPixelIndex( nY2, nXTmp++ ) );
431 						nSum2 += lGray;
432 						nSum2 -= ( (long) pReadAcc->GetPixelIndex( nY2, nXTmp++ ) ) << 1;
433 						nSum1 += ( lGray = (long) pReadAcc->GetPixelIndex( nY2, nXTmp ) );
434 						nSum2 -= lGray;
435 
436 						if( ( nSum1 * nSum1 + nSum2 * nSum2 ) < lThres2 )
437 							pWriteAcc->SetPixelIndex( nY1, nXDst, nWhitePalIdx );
438 						else
439 							pWriteAcc->SetPixelIndex( nY1, nXDst, nBlackPalIdx );
440 					}
441 				}
442 
443 				bRet = sal_True;
444 			}
445 
446 			aWorkBmp.ReleaseAccess( pReadAcc );
447 			aDstBmp.ReleaseAccess( pWriteAcc );
448 
449 			if( bRet )
450 				aRetBmp = aDstBmp;
451 		}
452 	}
453 
454 	if( !aRetBmp )
455 		aRetBmp = rBmp;
456 	else
457 	{
458 		aRetBmp.SetPrefMapMode( rBmp.GetPrefMapMode() );
459 		aRetBmp.SetPrefSize( rBmp.GetPrefSize() );
460 	}
461 
462 	return aRetBmp;
463 };
464 
465 // ------------------------------------------------------------------------
466 
GetCountour(const Bitmap & rBmp,const sal_uIntPtr nFlags,const sal_uInt8 cEdgeDetectThreshold,const Rectangle * pWorkRectPixel)467 Polygon XOutBitmap::GetCountour( const Bitmap& rBmp, const sal_uIntPtr nFlags,
468 								 const sal_uInt8 cEdgeDetectThreshold, const Rectangle* pWorkRectPixel )
469 {
470 	Bitmap		aWorkBmp;
471 	Polygon		aRetPoly;
472 	Point		aTmpPoint;
473 	Rectangle	aWorkRect( aTmpPoint, rBmp.GetSizePixel() );
474 
475 	if( pWorkRectPixel )
476 		aWorkRect.Intersection( *pWorkRectPixel );
477 
478 	aWorkRect.Justify();
479 
480 	if( ( aWorkRect.GetWidth() > 4 ) && ( aWorkRect.GetHeight() > 4 ) )
481 	{
482 		// falls Flag gesetzt, muessen wir Kanten detektieren
483 		if( nFlags & XOUTBMP_CONTOUR_EDGEDETECT )
484 			aWorkBmp = DetectEdges( rBmp, cEdgeDetectThreshold );
485 		else
486 			aWorkBmp = rBmp;
487 
488 		BitmapReadAccess* pAcc = aWorkBmp.AcquireReadAccess();
489 
490 		if( pAcc )
491 		{
492 			const Size&			rPrefSize = aWorkBmp.GetPrefSize();
493 			const long			nWidth = pAcc->Width();
494 			const long			nHeight = pAcc->Height();
495 			const double		fFactorX = (double) rPrefSize.Width() / nWidth;
496 			const double		fFactorY = (double) rPrefSize.Height() / nHeight;
497 			const long			nStartX1 = aWorkRect.Left() + 1L;
498 			const long			nEndX1 = aWorkRect.Right();
499 			const long			nStartX2 = nEndX1 - 1L;
500 //			const long			nEndX2 = nStartX1 - 1L;
501 			const long			nStartY1 = aWorkRect.Top() + 1L;
502 			const long			nEndY1 = aWorkRect.Bottom();
503 			const long			nStartY2 = nEndY1 - 1L;
504 //			const long			nEndY2 = nStartY1 - 1L;
505 			Point*				pPoints1 = NULL;
506 			Point*				pPoints2 = NULL;
507 			long				nX, nY;
508 			sal_uInt16				nPolyPos = 0;
509 			const BitmapColor	aBlack = pAcc->GetBestMatchingColor( Color( COL_BLACK ) );
510 
511 			if( nFlags & XOUTBMP_CONTOUR_VERT )
512 			{
513 				pPoints1 = new Point[ nWidth ];
514 				pPoints2 = new Point[ nWidth ];
515 
516 				for( nX = nStartX1; nX < nEndX1; nX++ )
517 				{
518 					nY = nStartY1;
519 
520 					// zunaechst Zeile von Links nach Rechts durchlaufen
521 					while( nY < nEndY1 )
522 					{
523 						if( aBlack == pAcc->GetPixel( nY, nX ) )
524 						{
525 							pPoints1[ nPolyPos ] = Point( nX, nY );
526 							nY = nStartY2;
527 
528 							// diese Schleife wird immer gebreaked da hier ja min. ein Pixel ist
529 							while( sal_True )
530 							{
531 								if( aBlack == pAcc->GetPixel( nY, nX ) )
532 								{
533 									pPoints2[ nPolyPos ] = Point( nX, nY );
534 									break;
535 								}
536 
537 								nY--;
538 							}
539 
540 							nPolyPos++;
541 							break;
542 						}
543 
544 						nY++;
545 					}
546 				}
547 			}
548 			else
549 			{
550 				pPoints1 = new Point[ nHeight ];
551 				pPoints2 = new Point[ nHeight ];
552 
553 				for ( nY = nStartY1; nY < nEndY1; nY++ )
554 				{
555 					nX = nStartX1;
556 
557 					// zunaechst Zeile von Links nach Rechts durchlaufen
558 					while( nX < nEndX1 )
559 					{
560 						if( aBlack == pAcc->GetPixel( nY, nX ) )
561 						{
562 							pPoints1[ nPolyPos ] = Point( nX, nY );
563 							nX = nStartX2;
564 
565 							// diese Schleife wird immer gebreaked da hier ja min. ein Pixel ist
566 							while( sal_True )
567 							{
568 								if( aBlack == pAcc->GetPixel( nY, nX ) )
569 								{
570 									pPoints2[ nPolyPos ] = Point( nX, nY );
571 									break;
572 								}
573 
574 								nX--;
575 							}
576 
577 							nPolyPos++;
578 							break;
579 						}
580 
581 						nX++;
582 					}
583 				}
584 			}
585 
586 			const sal_uInt16 nNewSize1 = nPolyPos << 1;
587 
588 			aRetPoly = Polygon( nPolyPos, pPoints1 );
589 			aRetPoly.SetSize( nNewSize1 + 1 );
590 			aRetPoly[ nNewSize1 ] = aRetPoly[ 0 ];
591 
592 			for( sal_uInt16 j = nPolyPos; nPolyPos < nNewSize1; )
593 				aRetPoly[ nPolyPos++ ] = pPoints2[ --j ];
594 
595 			if( ( fFactorX != 0. ) && ( fFactorY != 0. ) )
596 				aRetPoly.Scale( fFactorX, fFactorY );
597 
598 			delete[] pPoints1;
599 			delete[] pPoints2;
600 		}
601 	}
602 
603 	return aRetPoly;
604 };
605 
606 // ----------------
607 // - DitherBitmap -
608 // ----------------
609 
DitherBitmap(Bitmap & rBitmap)610 sal_Bool DitherBitmap( Bitmap& rBitmap )
611 {
612 	sal_Bool bRet = sal_False;
613 
614 	if( ( rBitmap.GetBitCount() >= 8 ) && ( Application::GetDefaultDevice()->GetColorCount() < 257 ) )
615 		bRet = rBitmap.Dither( BMP_DITHER_FLOYD );
616 	else
617 		bRet = sal_False;
618 
619 	return bRet;
620 }
621