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