LibreOffice Module vcl (master)  1
bitmapex.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <sal/log.hxx>
22 #include <osl/diagnose.h>
25 
26 #include <vcl/ImageTree.hxx>
27 #include <vcl/outdev.hxx>
28 #include <vcl/alpha.hxx>
29 #include <vcl/bitmapex.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/bitmapaccess.hxx>
32 #include <vcl/virdev.hxx>
33 #include <vcl/settings.hxx>
35 
36 // BitmapEx::Create
37 #include <salbmp.hxx>
38 #include <salinst.hxx>
39 #include <svdata.hxx>
40 #include <bitmapwriteaccess.hxx>
41 
42 #include <o3tl/any.hxx>
43 
44 #include <com/sun/star/beans/XFastPropertySet.hpp>
45 
46 #include <memory>
47 
48 using namespace ::com::sun::star;
49 
51  : meTransparent(TransparentType::NONE)
52  , mbAlpha(false)
53 {
54 }
55 
56 BitmapEx::BitmapEx( const BitmapEx& ) = default;
57 
58 BitmapEx::BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize )
59  : meTransparent(TransparentType::NONE)
60  , mbAlpha(false)
61 {
62  if( rBitmapEx.IsEmpty() )
63  return;
64 
65  maBitmap = Bitmap( aSize, rBitmapEx.maBitmap.GetBitCount() );
66  SetSizePixel(aSize);
67  if( rBitmapEx.IsAlpha() )
68  {
69  mbAlpha = true;
70  maMask = AlphaMask( aSize ).ImplGetBitmap();
71  }
72  else if( rBitmapEx.IsTransparent() )
73  maMask = Bitmap( aSize, rBitmapEx.maMask.GetBitCount() );
74 
75  tools::Rectangle aDestRect( Point( 0, 0 ), aSize );
76  tools::Rectangle aSrcRect( aSrc, aSize );
77  CopyPixel( aDestRect, aSrcRect, &rBitmapEx );
78 }
79 
80 BitmapEx::BitmapEx( Size aSize, sal_uInt16 nBitCount )
81  : meTransparent(TransparentType::NONE)
82  , mbAlpha(false)
83 {
84  maBitmap = Bitmap( aSize, nBitCount );
85  SetSizePixel(aSize);
86 }
87 
88 BitmapEx::BitmapEx( const OUString& rIconName )
89  : meTransparent(TransparentType::NONE)
90  , mbAlpha(false)
91 {
92  loadFromIconTheme( rIconName );
93 }
94 
95 void BitmapEx::loadFromIconTheme( const OUString& rIconName )
96 {
97  bool bSuccess;
98  OUString aIconTheme;
99 
100  try
101  {
103  bSuccess = ImageTree::get().loadImage(rIconName, aIconTheme, *this, true);
104  }
105  catch (...)
106  {
107  bSuccess = false;
108  }
109 
110  SAL_WARN_IF( !bSuccess, "vcl", "BitmapEx::BitmapEx(): could not load image " << rIconName << " via icon theme " << aIconTheme);
111 }
112 
113 BitmapEx::BitmapEx( const Bitmap& rBmp ) :
114  maBitmap ( rBmp ),
115  maBitmapSize ( maBitmap.GetSizePixel() ),
116  meTransparent( TransparentType::NONE ),
117  mbAlpha ( false )
118 {
119 }
120 
121 BitmapEx::BitmapEx( const Bitmap& rBmp, const Bitmap& rMask ) :
122  maBitmap ( rBmp ),
123  maMask ( rMask ),
124  maBitmapSize ( maBitmap.GetSizePixel() ),
125  meTransparent ( !rMask ? TransparentType::NONE : TransparentType::Bitmap ),
126  mbAlpha ( false )
127 {
128  // Ensure a mask is exactly one bit deep
129  if( !!maMask && maMask.GetBitCount() != 1 )
130  {
131  SAL_WARN( "vcl", "BitmapEx: forced mask to monochrome");
132  BitmapEx aMaskEx(maMask);
134  maMask = aMaskEx.GetBitmap();
135  }
136 
138  {
139  OSL_ENSURE(false, "Mask size differs from Bitmap size, corrected Mask (!)");
141  }
142 }
143 
144 BitmapEx::BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask ) :
145  maBitmap ( rBmp ),
146  maMask ( rAlphaMask.ImplGetBitmap() ),
147  maBitmapSize ( maBitmap.GetSizePixel() ),
148  meTransparent ( !rAlphaMask ? TransparentType::NONE : TransparentType::Bitmap ),
149  mbAlpha ( !rAlphaMask.IsEmpty() )
150 {
152  {
153  OSL_ENSURE(false, "Alpha size differs from Bitmap size, corrected Mask (!)");
154  maMask.Scale(rBmp.GetSizePixel());
155  }
156 
157  // #i75531# the workaround below can go when
158  // X11SalGraphics::drawAlphaBitmap()'s render acceleration
159  // can handle the bitmap depth mismatch directly
162 }
163 
164 BitmapEx::BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor ) :
165  maBitmap ( rBmp ),
166  maBitmapSize ( maBitmap.GetSizePixel() ),
167  maTransparentColor ( rTransparentColor ),
168  meTransparent ( TransparentType::Bitmap ),
169  mbAlpha ( false )
170 {
172 
173  SAL_WARN_IF(rBmp.GetSizePixel() != maMask.GetSizePixel(), "vcl",
174  "BitmapEx::BitmapEx(): size mismatch for bitmap and alpha mask.");
175 }
176 
177 BitmapEx& BitmapEx::operator=( const BitmapEx& ) = default;
178 
179 bool BitmapEx::operator==( const BitmapEx& rBitmapEx ) const
180 {
181  if (meTransparent != rBitmapEx.meTransparent)
182  return false;
183 
184  if (GetSizePixel() != rBitmapEx.GetSizePixel())
185  return false;
186 
187  if (meTransparent != rBitmapEx.meTransparent)
188  return false;
189 
191  && maTransparentColor != rBitmapEx.maTransparentColor)
192  return false;
193 
194  if (mbAlpha != rBitmapEx.mbAlpha)
195  return false;
196 
197  if (maBitmap != rBitmapEx.maBitmap)
198  return false;
199 
200  return maMask == rBitmapEx.maMask;
201 }
202 
203 bool BitmapEx::IsEmpty() const
204 {
205  return( maBitmap.IsEmpty() && maMask.IsEmpty() );
206 }
207 
209 {
210  maBitmap.SetEmpty();
211  maMask.SetEmpty();
213  mbAlpha = false;
214 }
215 
217 {
218  SetEmpty();
219 }
220 
222 {
224 }
225 
226 bool BitmapEx::IsAlpha() const
227 {
228  return( IsTransparent() && mbAlpha );
229 }
230 
232 {
233  return maBitmap;
234 }
235 
236 Bitmap BitmapEx::GetBitmap( const Color* pTransReplaceColor ) const
237 {
238  Bitmap aRetBmp( maBitmap );
239 
240  if( pTransReplaceColor && ( meTransparent != TransparentType::NONE ) )
241  {
242  Bitmap aTempMask;
243 
245  aTempMask = maBitmap.CreateMask( maTransparentColor );
246  else
247  aTempMask = maMask;
248 
249  if( !IsAlpha() )
250  aRetBmp.Replace( aTempMask, *pTransReplaceColor );
251  else
252  aRetBmp.Replace( GetAlpha(), *pTransReplaceColor );
253  }
254 
255  return aRetBmp;
256 }
257 
259 {
260  if (!IsAlpha())
261  return maMask;
262 
263  BitmapEx aMaskEx(maMask);
265  return aMaskEx.GetBitmap();
266 }
267 
269 {
270  if( IsAlpha() )
271  {
272  AlphaMask aAlpha;
273  aAlpha.ImplSetBitmap( maMask );
274  return aAlpha;
275  }
276  else
277  {
278  return AlphaMask(maMask);
279  }
280 }
281 
283 {
284  sal_uLong nSizeBytes = maBitmap.GetSizeBytes();
285 
287  nSizeBytes += maMask.GetSizeBytes();
288 
289  return nSizeBytes;
290 }
291 
293 {
295  SVBT32 aBT32;
297 
298  UInt32ToSVBT32( o3tl::underlyingEnumValue(meTransparent), aBT32 );
299  nCrc = vcl_get_checksum( nCrc, aBT32, 4 );
300 
301  UInt32ToSVBT32( sal_uInt32(mbAlpha), aBT32 );
302  nCrc = vcl_get_checksum( nCrc, aBT32, 4 );
303 
305  {
306  BCToBCOA( maMask.GetChecksum(), aBCOA );
307  nCrc = vcl_get_checksum( nCrc, aBCOA, BITMAP_CHECKSUM_SIZE );
308  }
309 
310  return nCrc;
311 }
312 
313 void BitmapEx::SetSizePixel(const Size& rNewSize)
314 {
315  maBitmapSize = rNewSize;
316 }
317 
319 {
320  bool bRet = false;
321 
322  if (!!maBitmap)
323  {
324  bRet = maBitmap.Invert();
325 
326  if (bRet && (meTransparent == TransparentType::Color))
328  }
329 
330  return bRet;
331 }
332 
333 bool BitmapEx::Mirror( BmpMirrorFlags nMirrorFlags )
334 {
335  bool bRet = false;
336 
337  if( !!maBitmap )
338  {
339  bRet = maBitmap.Mirror( nMirrorFlags );
340 
341  if( bRet && ( meTransparent == TransparentType::Bitmap ) && !!maMask )
342  maMask.Mirror( nMirrorFlags );
343  }
344 
345  return bRet;
346 }
347 
348 bool BitmapEx::Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag )
349 {
350  bool bRet = false;
351 
352  if( !!maBitmap )
353  {
354  bRet = maBitmap.Scale( rScaleX, rScaleY, nScaleFlag );
355 
356  if( bRet && ( meTransparent == TransparentType::Bitmap ) && !!maMask )
357  {
358  maMask.Scale( rScaleX, rScaleY, nScaleFlag );
359  }
360 
362 
364  "BitmapEx::Scale(): size mismatch for bitmap and alpha mask." );
365  }
366 
367  return bRet;
368 }
369 
370 bool BitmapEx::Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag )
371 {
372  bool bRet;
373 
374  if (GetSizePixel().Width() && GetSizePixel().Height()
375  && (rNewSize.Width() != GetSizePixel().Width()
376  || rNewSize.Height() != GetSizePixel().Height() ) )
377  {
378  bRet = Scale( static_cast<double>(rNewSize.Width()) / GetSizePixel().Width(),
379  static_cast<double>(rNewSize.Height()) / GetSizePixel().Height(),
380  nScaleFlag );
381  }
382  else
383  {
384  bRet = true;
385  }
386 
387  return bRet;
388 }
389 
390 bool BitmapEx::Rotate( long nAngle10, const Color& rFillColor )
391 {
392  bool bRet = false;
393 
394  if( !!maBitmap )
395  {
396  const bool bTransRotate = ( COL_TRANSPARENT == rFillColor );
397 
398  if( bTransRotate )
399  {
401  bRet = maBitmap.Rotate( nAngle10, maTransparentColor );
402  else
403  {
404  bRet = maBitmap.Rotate( nAngle10, COL_BLACK );
405 
407  {
408  maMask = Bitmap(GetSizePixel(), 1);
411  }
412 
413  if( bRet && !!maMask )
414  maMask.Rotate( nAngle10, COL_WHITE );
415  }
416  }
417  else
418  {
419  bRet = maBitmap.Rotate( nAngle10, rFillColor );
420 
421  if( bRet && ( meTransparent == TransparentType::Bitmap ) && !!maMask )
422  maMask.Rotate( nAngle10, COL_WHITE );
423  }
424 
426 
428  "BitmapEx::Rotate(): size mismatch for bitmap and alpha mask.");
429  }
430 
431  return bRet;
432 }
433 
434 bool BitmapEx::Crop( const tools::Rectangle& rRectPixel )
435 {
436  bool bRet = false;
437 
438  if( !!maBitmap )
439  {
440  bRet = maBitmap.Crop( rRectPixel );
441 
442  if( bRet && ( meTransparent == TransparentType::Bitmap ) && !!maMask )
443  maMask.Crop( rRectPixel );
444 
446 
448  "BitmapEx::Crop(): size mismatch for bitmap and alpha mask.");
449  }
450 
451  return bRet;
452 }
453 
454 bool BitmapEx::Convert( BmpConversion eConversion )
455 {
456  return !!maBitmap && maBitmap.Convert( eConversion );
457 }
458 
459 void BitmapEx::Expand( sal_uLong nDX, sal_uLong nDY, bool bExpandTransparent )
460 {
461  bool bRet = false;
462 
463  if( !!maBitmap )
464  {
465  bRet = maBitmap.Expand( nDX, nDY );
466 
467  if( bRet && ( meTransparent == TransparentType::Bitmap ) && !!maMask )
468  {
469  Color aColor( bExpandTransparent ? COL_WHITE : COL_BLACK );
470  maMask.Expand( nDX, nDY, &aColor );
471  }
472 
474 
476  "BitmapEx::Expand(): size mismatch for bitmap and alpha mask.");
477  }
478 }
479 
480 bool BitmapEx::CopyPixel( const tools::Rectangle& rRectDst, const tools::Rectangle& rRectSrc,
481  const BitmapEx* pBmpExSrc )
482 {
483  bool bRet = false;
484 
485  if( !pBmpExSrc || pBmpExSrc->IsEmpty() )
486  {
487  if( !maBitmap.IsEmpty() )
488  {
489  bRet = maBitmap.CopyPixel( rRectDst, rRectSrc );
490 
491  if( bRet && ( meTransparent == TransparentType::Bitmap ) && !!maMask )
492  maMask.CopyPixel( rRectDst, rRectSrc );
493  }
494  }
495  else
496  {
497  if( !maBitmap.IsEmpty() )
498  {
499  bRet = maBitmap.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->maBitmap );
500 
501  if( bRet )
502  {
503  if( pBmpExSrc->IsAlpha() )
504  {
505  if( IsAlpha() )
506  // cast to use the optimized AlphaMask::CopyPixel
507  maMask.CopyPixel_AlphaOptimized( rRectDst, rRectSrc, &pBmpExSrc->maMask );
508  else if( IsTransparent() )
509  {
510  std::unique_ptr<AlphaMask> pAlpha(new AlphaMask( maMask ));
511 
512  maMask = pAlpha->ImplGetBitmap();
513  pAlpha.reset();
514  mbAlpha = true;
515  maMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->maMask );
516  }
517  else
518  {
519  sal_uInt8 cBlack = 0;
520  std::unique_ptr<AlphaMask> pAlpha(new AlphaMask(GetSizePixel(), &cBlack));
521 
522  maMask = pAlpha->ImplGetBitmap();
523  pAlpha.reset();
525  mbAlpha = true;
526  maMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->maMask );
527  }
528  }
529  else if( pBmpExSrc->IsTransparent() )
530  {
531  if (IsAlpha())
532  {
533  AlphaMask aAlpha( pBmpExSrc->maMask );
534  maMask.CopyPixel( rRectDst, rRectSrc, &aAlpha.ImplGetBitmap() );
535  }
536  else if (IsTransparent())
537  {
538  maMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->maMask );
539  }
540  else
541  {
542  maMask = Bitmap(GetSizePixel(), 1);
545  maMask.CopyPixel( rRectDst, rRectSrc, &pBmpExSrc->maMask );
546  }
547  }
548  else if (IsAlpha())
549  {
550  sal_uInt8 cBlack = 0;
551  const AlphaMask aAlphaSrc(pBmpExSrc->GetSizePixel(), &cBlack);
552 
553  maMask.CopyPixel( rRectDst, rRectSrc, &aAlphaSrc.ImplGetBitmap() );
554  }
555  else if (IsTransparent())
556  {
557  Bitmap aMaskSrc(pBmpExSrc->GetSizePixel(), 1);
558 
559  aMaskSrc.Erase( COL_BLACK );
560  maMask.CopyPixel( rRectDst, rRectSrc, &aMaskSrc );
561  }
562  }
563  }
564  }
565 
566  return bRet;
567 }
568 
569 bool BitmapEx::Erase( const Color& rFillColor )
570 {
571  bool bRet = false;
572 
573  if( !!maBitmap )
574  {
575  bRet = maBitmap.Erase( rFillColor );
576 
577  if( bRet && ( meTransparent == TransparentType::Bitmap ) && !!maMask )
578  {
579  // Respect transparency on fill color
580  if( rFillColor.GetTransparency() )
581  {
582  const Color aFill( rFillColor.GetTransparency(), rFillColor.GetTransparency(), rFillColor.GetTransparency() );
583  maMask.Erase( aFill );
584  }
585  else
586  {
587  const Color aBlack( COL_BLACK );
588  maMask.Erase( aBlack );
589  }
590  }
591  }
592 
593  return bRet;
594 }
595 
596 void BitmapEx::Replace( const Color& rSearchColor, const Color& rReplaceColor )
597 {
598  if (!!maBitmap)
599  maBitmap.Replace( rSearchColor, rReplaceColor );
600 }
601 
602 void BitmapEx::Replace( const Color* pSearchColors, const Color* pReplaceColors, sal_uLong nColorCount )
603 {
604  if (!!maBitmap)
605  maBitmap.Replace( pSearchColors, pReplaceColors, nColorCount, /*pTols*/nullptr );
606 }
607 
608 bool BitmapEx::Adjust( short nLuminancePercent, short nContrastPercent,
609  short nChannelRPercent, short nChannelGPercent, short nChannelBPercent,
610  double fGamma, bool bInvert, bool msoBrightness )
611 {
612  return !!maBitmap && maBitmap.Adjust( nLuminancePercent, nContrastPercent,
613  nChannelRPercent, nChannelGPercent, nChannelBPercent,
614  fGamma, bInvert, msoBrightness );
615 }
616 
617 void BitmapEx::Draw( OutputDevice* pOutDev, const Point& rDestPt ) const
618 {
619  pOutDev->DrawBitmapEx( rDestPt, *this );
620 }
621 
623  const Point& rDestPt, const Size& rDestSize ) const
624 {
625  pOutDev->DrawBitmapEx( rDestPt, rDestSize, *this );
626 }
627 
628 BitmapEx BitmapEx:: AutoScaleBitmap(BitmapEx const & aBitmap, const long aStandardSize)
629 {
630  Point aEmptyPoint(0,0);
631  double imgposX = 0;
632  double imgposY = 0;
633  BitmapEx aRet = aBitmap;
634  double imgOldWidth = aRet.GetSizePixel().Width();
635  double imgOldHeight = aRet.GetSizePixel().Height();
636 
637  Size aScaledSize;
638  if (imgOldWidth >= aStandardSize || imgOldHeight >= aStandardSize)
639  {
640  sal_Int32 imgNewWidth = 0;
641  sal_Int32 imgNewHeight = 0;
642  if (imgOldWidth >= imgOldHeight)
643  {
644  imgNewWidth = aStandardSize;
645  imgNewHeight = sal_Int32(imgOldHeight / (imgOldWidth / aStandardSize) + 0.5);
646  imgposX = 0;
647  imgposY = (aStandardSize - (imgOldHeight / (imgOldWidth / aStandardSize) + 0.5)) / 2 + 0.5;
648  }
649  else
650  {
651  imgNewHeight = aStandardSize;
652  imgNewWidth = sal_Int32(imgOldWidth / (imgOldHeight / aStandardSize) + 0.5);
653  imgposY = 0;
654  imgposX = (aStandardSize - (imgOldWidth / (imgOldHeight / aStandardSize) + 0.5)) / 2 + 0.5;
655  }
656 
657  aScaledSize = Size( imgNewWidth, imgNewHeight );
658  aRet.Scale( aScaledSize, BmpScaleFlag::BestQuality );
659  }
660  else
661  {
662  imgposX = (aStandardSize - imgOldWidth) / 2 + 0.5;
663  imgposY = (aStandardSize - imgOldHeight) / 2 + 0.5;
664  }
665 
666  Size aStdSize( aStandardSize, aStandardSize );
667  tools::Rectangle aRect(aEmptyPoint, aStdSize );
668 
671  aVirDevice->SetOutputSizePixel( aStdSize );
672  aVirDevice->SetFillColor( COL_TRANSPARENT );
673  aVirDevice->SetLineColor( COL_TRANSPARENT );
674 
675  // Draw a rect into virDevice
676  aVirDevice->DrawRect( aRect );
677  Point aPointPixel( static_cast<long>(imgposX), static_cast<long>(imgposY) );
678  aVirDevice->DrawBitmapEx( aPointPixel, aRet );
679  aRet = aVirDevice->GetBitmapEx( aEmptyPoint, aStdSize );
680 
681  return aRet;
682 }
683 
684 sal_uInt8 BitmapEx::GetTransparency(sal_Int32 nX, sal_Int32 nY) const
685 {
686  sal_uInt8 nTransparency(0xff);
687 
688  if(!maBitmap.IsEmpty())
689  {
690  if (nX >= 0 && nX < GetSizePixel().Width() && nY >= 0 && nY < GetSizePixel().Height())
691  {
692  switch(meTransparent)
693  {
695  {
696  // Not transparent, ergo all covered
697  nTransparency = 0x00;
698  break;
699  }
701  {
702  Bitmap aTestBitmap(maBitmap);
703  Bitmap::ScopedReadAccess pRead(aTestBitmap);
704 
705  if(pRead)
706  {
707  const BitmapColor aBmpColor = pRead->GetColor(nY, nX);
708 
709  // If color is not equal to TransparentColor, we are not transparent
710  if (aBmpColor != maTransparentColor)
711  nTransparency = 0x00;
712 
713  }
714  break;
715  }
717  {
718  if(!maMask.IsEmpty())
719  {
720  Bitmap aTestBitmap(maMask);
721  Bitmap::ScopedReadAccess pRead(aTestBitmap);
722 
723  if(pRead)
724  {
725  const BitmapColor aBitmapColor(pRead->GetPixel(nY, nX));
726 
727  if(mbAlpha)
728  {
729  nTransparency = aBitmapColor.GetIndex();
730  }
731  else
732  {
733  if(0x00 == aBitmapColor.GetIndex())
734  {
735  nTransparency = 0x00;
736  }
737  }
738  }
739  }
740  break;
741  }
742  }
743  }
744  }
745 
746  return nTransparency;
747 }
748 
749 
750 Color BitmapEx::GetPixelColor(sal_Int32 nX, sal_Int32 nY) const
751 {
752  Bitmap::ScopedReadAccess pReadAccess( const_cast<Bitmap&>(maBitmap) );
753  assert(pReadAccess);
754 
755  BitmapColor aColor = pReadAccess->GetColor(nY, nX);
756 
757  if (IsAlpha())
758  {
759  AlphaMask aAlpha = GetAlpha();
760  AlphaMask::ScopedReadAccess pAlphaReadAccess(aAlpha);
761  aColor.SetTransparency(pAlphaReadAccess->GetPixel(nY, nX).GetIndex());
762  }
763  else if (maBitmap.GetBitCount() != 32)
764  {
765  aColor.SetTransparency(0);
766  }
767  return aColor;
768 }
769 
770 // Shift alpha transparent pixels between cppcanvas/ implementations
771 // and vcl in a generally grotesque and under-performing fashion
772 bool BitmapEx::Create( const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
773  const Size &rSize )
774 {
775  uno::Reference< beans::XFastPropertySet > xFastPropertySet( xBitmapCanvas, uno::UNO_QUERY );
776  if( xFastPropertySet.get() )
777  {
778  // 0 means get BitmapEx
779  uno::Any aAny = xFastPropertySet->getFastPropertyValue( 0 );
780  std::unique_ptr<BitmapEx> xBitmapEx(reinterpret_cast<BitmapEx*>(*o3tl::doAccess<sal_Int64>(aAny)));
781  if( xBitmapEx )
782  {
783  *this = *xBitmapEx;
784  return true;
785  }
786  }
787 
788  std::shared_ptr<SalBitmap> pSalBmp;
789  std::shared_ptr<SalBitmap> pSalMask;
790 
791  pSalBmp = ImplGetSVData()->mpDefInst->CreateSalBitmap();
792 
793  Size aLocalSize(rSize);
794  if( pSalBmp->Create( xBitmapCanvas, aLocalSize ) )
795  {
796  pSalMask = ImplGetSVData()->mpDefInst->CreateSalBitmap();
797  if ( pSalMask->Create( xBitmapCanvas, aLocalSize, true ) )
798  {
799  *this = BitmapEx(Bitmap(pSalBmp), Bitmap(pSalMask) );
800  return true;
801  }
802  else
803  {
804  *this = BitmapEx(Bitmap(pSalBmp));
805  return true;
806  }
807  }
808 
809  return false;
810 }
811 
812 namespace
813 {
814  Bitmap impTransformBitmap(
815  const Bitmap& rSource,
816  const Size& rDestinationSize,
817  const basegfx::B2DHomMatrix& rTransform,
818  bool bSmooth)
819  {
820  Bitmap aDestination(rDestinationSize, 24);
821  BitmapScopedWriteAccess xWrite(aDestination);
822 
823  if(xWrite)
824  {
825  Bitmap::ScopedReadAccess xRead(const_cast< Bitmap& >(rSource));
826 
827  if (xRead)
828  {
829  const Size aDestinationSizePixel(aDestination.GetSizePixel());
830  const BitmapColor aOutside(BitmapColor(0xff, 0xff, 0xff));
831 
832  for(long y(0); y < aDestinationSizePixel.getHeight(); y++)
833  {
834  Scanline pScanline = xWrite->GetScanline( y );
835  for(long x(0); x < aDestinationSizePixel.getWidth(); x++)
836  {
837  const basegfx::B2DPoint aSourceCoor(rTransform * basegfx::B2DPoint(x, y));
838 
839  if(bSmooth)
840  {
841  xWrite->SetPixelOnData(
842  pScanline,
843  x,
844  xRead->GetInterpolatedColorWithFallback(
845  aSourceCoor.getY(),
846  aSourceCoor.getX(),
847  aOutside));
848  }
849  else
850  {
851  // this version does the correct <= 0.0 checks, so no need
852  // to do the static_cast< sal_Int32 > self and make an error
853  xWrite->SetPixelOnData(
854  pScanline,
855  x,
856  xRead->GetColorWithFallback(
857  aSourceCoor.getY(),
858  aSourceCoor.getX(),
859  aOutside));
860  }
861  }
862  }
863  }
864  }
865 
866  rSource.AdaptBitCount(aDestination);
867 
868  return aDestination;
869  }
870 } // end of anonymous namespace
871 
873  double fWidth,
874  double fHeight,
875  const basegfx::B2DHomMatrix& rTransformation) const
876 {
877  if(fWidth <= 1 || fHeight <= 1)
878  return BitmapEx();
879 
880  // force destination to 24 bit, we want to smooth output
881  const Size aDestinationSize(basegfx::fround(fWidth), basegfx::fround(fHeight));
882  const Bitmap aDestination(impTransformBitmap(GetBitmapRef(), aDestinationSize, rTransformation, /*bSmooth*/true));
883 
884  // create mask
885  if(IsTransparent())
886  {
887  if(IsAlpha())
888  {
889  const Bitmap aAlpha(impTransformBitmap(GetAlpha().GetBitmap(), aDestinationSize, rTransformation, /*bSmooth*/true));
890  return BitmapEx(aDestination, AlphaMask(aAlpha));
891  }
892  else
893  {
894  const Bitmap aLclMask(impTransformBitmap(GetMask(), aDestinationSize, rTransformation, false));
895  return BitmapEx(aDestination, aLclMask);
896  }
897  }
898 
899  return BitmapEx(aDestination);
900 }
901 
903  const basegfx::B2DHomMatrix& rTransformation,
904  const basegfx::B2DRange& rVisibleRange,
905  double fMaximumArea) const
906 {
907  BitmapEx aRetval;
908 
909  if(IsEmpty())
910  return aRetval;
911 
912  const sal_uInt32 nSourceWidth(GetSizePixel().Width());
913  const sal_uInt32 nSourceHeight(GetSizePixel().Height());
914 
915  if(!nSourceWidth || !nSourceHeight)
916  return aRetval;
917 
918  // Get aOutlineRange
919  basegfx::B2DRange aOutlineRange(0.0, 0.0, 1.0, 1.0);
920 
921  aOutlineRange.transform(rTransformation);
922 
923  // create visible range from it by moving from relative to absolute
924  basegfx::B2DRange aVisibleRange(rVisibleRange);
925 
926  aVisibleRange.transform(
928  aOutlineRange.getRange(),
929  aOutlineRange.getMinimum()));
930 
931  // get target size (which is visible range's size)
932  double fWidth(aVisibleRange.getWidth());
933  double fHeight(aVisibleRange.getHeight());
934 
935  if(fWidth < 1.0 || fHeight < 1.0)
936  {
937  return aRetval;
938  }
939 
940  // test if discrete size (pixel) maybe too big and limit it
941  const double fArea(fWidth * fHeight);
942  const bool bNeedToReduce(basegfx::fTools::more(fArea, fMaximumArea));
943  double fReduceFactor(1.0);
944 
945  if(bNeedToReduce)
946  {
947  fReduceFactor = sqrt(fMaximumArea / fArea);
948  fWidth *= fReduceFactor;
949  fHeight *= fReduceFactor;
950  }
951 
952  // Build complete transform from source pixels to target pixels.
953  // Start by scaling from source pixel size to unit coordinates
954  basegfx::B2DHomMatrix aTransform(
956  1.0 / nSourceWidth,
957  1.0 / nSourceHeight));
958 
959  // multiply with given transform which leads from unit coordinates inside
960  // aOutlineRange
961  aTransform = rTransformation * aTransform;
962 
963  // subtract top-left of absolute VisibleRange
964  aTransform.translate(
965  -aVisibleRange.getMinX(),
966  -aVisibleRange.getMinY());
967 
968  // scale to target pixels (if needed)
969  if(bNeedToReduce)
970  {
971  aTransform.scale(fReduceFactor, fReduceFactor);
972  }
973 
974  // invert to get transformation from target pixel coordinates to source pixels
975  aTransform.invert();
976 
977  // create bitmap using source, destination and linear back-transformation
978  aRetval = TransformBitmapEx(fWidth, fHeight, aTransform);
979 
980  return aRetval;
981 }
982 
984 {
985  Bitmap aChangedBitmap(GetBitmapRef());
986  bool bDone(false);
987 
988  for(sal_uInt32 a(rBColorModifierStack.count()); a && !bDone; )
989  {
990  const basegfx::BColorModifierSharedPtr& rModifier = rBColorModifierStack.getBColorModifier(--a);
991  const basegfx::BColorModifier_replace* pReplace = dynamic_cast< const basegfx::BColorModifier_replace* >(rModifier.get());
992 
993  if(pReplace)
994  {
995  // complete replace
996  if(IsTransparent())
997  {
998  // clear bitmap with dest color
999  if(aChangedBitmap.GetBitCount() <= 8)
1000  {
1001  // do NOT use erase; for e.g. 8bit Bitmaps, the nearest color to the given
1002  // erase color is determined and used -> this may be different from what is
1003  // wanted here. Better create a new bitmap with the needed color explicitly
1004  Bitmap::ScopedReadAccess xReadAccess(aChangedBitmap);
1005  OSL_ENSURE(xReadAccess, "Got no Bitmap ReadAccess ?!?");
1006 
1007  if(xReadAccess)
1008  {
1009  BitmapPalette aNewPalette(xReadAccess->GetPalette());
1010  aNewPalette[0] = BitmapColor(Color(pReplace->getBColor()));
1011  aChangedBitmap = Bitmap(
1012  aChangedBitmap.GetSizePixel(),
1013  aChangedBitmap.GetBitCount(),
1014  &aNewPalette);
1015  }
1016  }
1017  else
1018  {
1019  aChangedBitmap.Erase(Color(pReplace->getBColor()));
1020  }
1021  }
1022  else
1023  {
1024  // erase bitmap, caller will know to paint direct
1025  aChangedBitmap.SetEmpty();
1026  }
1027 
1028  bDone = true;
1029  }
1030  else
1031  {
1032  BitmapScopedWriteAccess xContent(aChangedBitmap);
1033 
1034  if(xContent)
1035  {
1036  const double fConvertColor(1.0 / 255.0);
1037 
1038  if(xContent->HasPalette())
1039  {
1040  const sal_uInt16 nCount(xContent->GetPaletteEntryCount());
1041 
1042  for(sal_uInt16 b(0); b < nCount; b++)
1043  {
1044  const BitmapColor& rCol = xContent->GetPaletteColor(b);
1045  const basegfx::BColor aBSource(
1046  rCol.GetRed() * fConvertColor,
1047  rCol.GetGreen() * fConvertColor,
1048  rCol.GetBlue() * fConvertColor);
1049  const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1050  xContent->SetPaletteColor(b, BitmapColor(Color(aBDest)));
1051  }
1052  }
1053  else if(ScanlineFormat::N24BitTcBgr == xContent->GetScanlineFormat())
1054  {
1055  for(sal_uInt32 y(0); y < static_cast<sal_uInt32>(xContent->Height()); y++)
1056  {
1057  Scanline pScan = xContent->GetScanline(y);
1058 
1059  for(sal_uInt32 x(0); x < static_cast<sal_uInt32>(xContent->Width()); x++)
1060  {
1061  const basegfx::BColor aBSource(
1062  *(pScan + 2)* fConvertColor,
1063  *(pScan + 1) * fConvertColor,
1064  *pScan * fConvertColor);
1065  const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1066  *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0);
1067  *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0);
1068  *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0);
1069  }
1070  }
1071  }
1072  else if(ScanlineFormat::N24BitTcRgb == xContent->GetScanlineFormat())
1073  {
1074  for(sal_uInt32 y(0); y < static_cast<sal_uInt32>(xContent->Height()); y++)
1075  {
1076  Scanline pScan = xContent->GetScanline(y);
1077 
1078  for(sal_uInt32 x(0); x < static_cast<sal_uInt32>(xContent->Width()); x++)
1079  {
1080  const basegfx::BColor aBSource(
1081  *pScan * fConvertColor,
1082  *(pScan + 1) * fConvertColor,
1083  *(pScan + 2) * fConvertColor);
1084  const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1085  *pScan++ = static_cast< sal_uInt8 >(aBDest.getRed() * 255.0);
1086  *pScan++ = static_cast< sal_uInt8 >(aBDest.getGreen() * 255.0);
1087  *pScan++ = static_cast< sal_uInt8 >(aBDest.getBlue() * 255.0);
1088  }
1089  }
1090  }
1091  else
1092  {
1093  for(sal_uInt32 y(0); y < static_cast<sal_uInt32>(xContent->Height()); y++)
1094  {
1095  Scanline pScanline = xContent->GetScanline( y );
1096  for(sal_uInt32 x(0); x < static_cast<sal_uInt32>(xContent->Width()); x++)
1097  {
1098  const BitmapColor aBMCol(xContent->GetColor(y, x));
1099  const basegfx::BColor aBSource(
1100  static_cast<double>(aBMCol.GetRed()) * fConvertColor,
1101  static_cast<double>(aBMCol.GetGreen()) * fConvertColor,
1102  static_cast<double>(aBMCol.GetBlue()) * fConvertColor);
1103  const basegfx::BColor aBDest(rModifier->getModifiedColor(aBSource));
1104 
1105  xContent->SetPixelOnData(pScanline, x, BitmapColor(Color(aBDest)));
1106  }
1107  }
1108  }
1109  }
1110  }
1111  }
1112 
1113  if(aChangedBitmap.IsEmpty())
1114  {
1115  return BitmapEx();
1116  }
1117  else
1118  {
1119  if(IsTransparent())
1120  {
1121  if(IsAlpha())
1122  {
1123  return BitmapEx(aChangedBitmap, GetAlpha());
1124  }
1125  else
1126  {
1127  return BitmapEx(aChangedBitmap, GetMask());
1128  }
1129  }
1130  else
1131  {
1132  return BitmapEx(aChangedBitmap);
1133  }
1134  }
1135 }
1136 
1138  const Size& rSize,
1139  sal_uInt8 nAlpha,
1140  Color aColorTopLeft,
1141  Color aColorBottomRight)
1142 {
1143  const sal_uInt32 nW(rSize.Width());
1144  const sal_uInt32 nH(rSize.Height());
1145 
1146  if(nW || nH)
1147  {
1148  Color aColTopRight(aColorTopLeft);
1149  Color aColBottomLeft(aColorTopLeft);
1150  const sal_uInt32 nDE(nW + nH);
1151 
1152  aColTopRight.Merge(aColorBottomRight, 255 - sal_uInt8((nW * 255) / nDE));
1153  aColBottomLeft.Merge(aColorBottomRight, 255 - sal_uInt8((nH * 255) / nDE));
1154 
1155  return createBlendFrame(rSize, nAlpha, aColorTopLeft, aColTopRight, aColorBottomRight, aColBottomLeft);
1156  }
1157 
1158  return BitmapEx();
1159 }
1160 
1162  const Size& rSize,
1163  sal_uInt8 nAlpha,
1164  Color aColorTopLeft,
1165  Color aColorTopRight,
1166  Color aColorBottomRight,
1167  Color aColorBottomLeft)
1168 {
1169  BlendFrameCache* pBlendFrameCache = ImplGetBlendFrameCache();
1170 
1171  if(pBlendFrameCache->m_aLastSize == rSize
1172  && pBlendFrameCache->m_nLastAlpha == nAlpha
1173  && pBlendFrameCache->m_aLastColorTopLeft == aColorTopLeft
1174  && pBlendFrameCache->m_aLastColorTopRight == aColorTopRight
1175  && pBlendFrameCache->m_aLastColorBottomRight == aColorBottomRight
1176  && pBlendFrameCache->m_aLastColorBottomLeft == aColorBottomLeft)
1177  {
1178  return pBlendFrameCache->m_aLastResult;
1179  }
1180 
1181  pBlendFrameCache->m_aLastSize = rSize;
1182  pBlendFrameCache->m_nLastAlpha = nAlpha;
1183  pBlendFrameCache->m_aLastColorTopLeft = aColorTopLeft;
1184  pBlendFrameCache->m_aLastColorTopRight = aColorTopRight;
1185  pBlendFrameCache->m_aLastColorBottomRight = aColorBottomRight;
1186  pBlendFrameCache->m_aLastColorBottomLeft = aColorBottomLeft;
1187  pBlendFrameCache->m_aLastResult.Clear();
1188 
1189  const long nW(rSize.Width());
1190  const long nH(rSize.Height());
1191 
1192  if(nW > 1 && nH > 1)
1193  {
1194  sal_uInt8 aEraseTrans(0xff);
1195  Bitmap aContent(rSize, 24);
1196  AlphaMask aAlpha(rSize, &aEraseTrans);
1197 
1198  aContent.Erase(COL_BLACK);
1199 
1200  BitmapScopedWriteAccess pContent(aContent);
1201  AlphaScopedWriteAccess pAlpha(aAlpha);
1202 
1203  if(pContent && pAlpha)
1204  {
1205  long x(0);
1206  long y(0);
1207  Scanline pScanContent = pContent->GetScanline( 0 );
1208  Scanline pScanAlpha = pContent->GetScanline( 0 );
1209 
1210  // x == 0, y == 0, top-left corner
1211  pContent->SetPixelOnData(pScanContent, 0, aColorTopLeft);
1212  pAlpha->SetPixelOnData(pScanAlpha, 0, BitmapColor(nAlpha));
1213 
1214  // y == 0, top line left to right
1215  for(x = 1; x < nW - 1; x++)
1216  {
1217  Color aMix(aColorTopLeft);
1218 
1219  aMix.Merge(aColorTopRight, 255 - sal_uInt8((x * 255) / nW));
1220  pContent->SetPixelOnData(pScanContent, x, aMix);
1221  pAlpha->SetPixelOnData(pScanAlpha, x, BitmapColor(nAlpha));
1222  }
1223 
1224  // x == nW - 1, y == 0, top-right corner
1225  // #i123690# Caution! When nW is 1, x == nW is possible (!)
1226  if(x < nW)
1227  {
1228  pContent->SetPixelOnData(pScanContent, x, aColorTopRight);
1229  pAlpha->SetPixelOnData(pScanAlpha, x, BitmapColor(nAlpha));
1230  }
1231 
1232  // x == 0 and nW - 1, left and right line top-down
1233  for(y = 1; y < nH - 1; y++)
1234  {
1235  pScanContent = pContent->GetScanline( y );
1236  pScanAlpha = pContent->GetScanline( y );
1237  Color aMixA(aColorTopLeft);
1238 
1239  aMixA.Merge(aColorBottomLeft, 255 - sal_uInt8((y * 255) / nH));
1240  pContent->SetPixelOnData(pScanContent, 0, aMixA);
1241  pAlpha->SetPixelOnData(pScanAlpha, 0, BitmapColor(nAlpha));
1242 
1243  // #i123690# Caution! When nW is 1, x == nW is possible (!)
1244  if(x < nW)
1245  {
1246  Color aMixB(aColorTopRight);
1247 
1248  aMixB.Merge(aColorBottomRight, 255 - sal_uInt8((y * 255) / nH));
1249  pContent->SetPixelOnData(pScanContent, x, aMixB);
1250  pAlpha->SetPixelOnData(pScanAlpha, x, BitmapColor(nAlpha));
1251  }
1252  }
1253 
1254  // #i123690# Caution! When nH is 1, y == nH is possible (!)
1255  if(y < nH)
1256  {
1257  // x == 0, y == nH - 1, bottom-left corner
1258  pContent->SetPixelOnData(pScanContent, 0, aColorBottomLeft);
1259  pAlpha->SetPixelOnData(pScanAlpha, 0, BitmapColor(nAlpha));
1260 
1261  // y == nH - 1, bottom line left to right
1262  for(x = 1; x < nW - 1; x++)
1263  {
1264  Color aMix(aColorBottomLeft);
1265 
1266  aMix.Merge(aColorBottomRight, 255 - sal_uInt8(((x - 0)* 255) / nW));
1267  pContent->SetPixelOnData(pScanContent, x, aMix);
1268  pAlpha->SetPixelOnData(pScanAlpha, x, BitmapColor(nAlpha));
1269  }
1270 
1271  // x == nW - 1, y == nH - 1, bottom-right corner
1272  // #i123690# Caution! When nW is 1, x == nW is possible (!)
1273  if(x < nW)
1274  {
1275  pContent->SetPixelOnData(pScanContent, x, aColorBottomRight);
1276  pAlpha->SetPixelOnData(pScanAlpha, x, BitmapColor(nAlpha));
1277  }
1278  }
1279 
1280  pContent.reset();
1281  pAlpha.reset();
1282 
1283  pBlendFrameCache->m_aLastResult = BitmapEx(aContent, aAlpha);
1284  }
1285  }
1286 
1287  return pBlendFrameCache->m_aLastResult;
1288 }
1289 
1290 void BitmapEx::Replace(const Color& rSearchColor,
1291  const Color& rReplaceColor,
1292  sal_uInt8 nTolerance)
1293 {
1294  maBitmap.Replace(rSearchColor, rReplaceColor, nTolerance);
1295 }
1296 
1297 void BitmapEx::Replace( const Color* pSearchColors,
1298  const Color* pReplaceColors,
1299  sal_uLong nColorCount,
1300  sal_uInt8 const * pTols )
1301 {
1302  maBitmap.Replace( pSearchColors, pReplaceColors, nColorCount, pTols );
1303 }
1304 
1306 {
1307  if( IsTransparent() )
1308  {
1309  maBitmap.Replace( GetMask(), rColor );
1310  maMask = Bitmap();
1314  mbAlpha = false;
1315  }
1316 }
1317 
1318 static Bitmap DetectEdges( const Bitmap& rBmp )
1319 {
1320  constexpr sal_uInt8 cEdgeDetectThreshold = 128;
1321  const Size aSize( rBmp.GetSizePixel() );
1322  Bitmap aRetBmp;
1323 
1324  if( ( aSize.Width() > 2 ) && ( aSize.Height() > 2 ) )
1325  {
1326  Bitmap aWorkBmp( rBmp );
1327 
1328  if( aWorkBmp.Convert( BmpConversion::N8BitGreys ) )
1329  {
1330  bool bRet = false;
1331 
1333  pVirDev->SetOutputSizePixel(aSize);
1334  Bitmap::ScopedReadAccess pReadAcc(aWorkBmp);
1335 
1336  if( pReadAcc )
1337  {
1338  const long nWidth = aSize.Width();
1339  const long nWidth2 = nWidth - 2;
1340  const long nHeight = aSize.Height();
1341  const long nHeight2 = nHeight - 2;
1342  const long lThres2 = static_cast<long>(cEdgeDetectThreshold) * cEdgeDetectThreshold;
1343  long nSum1;
1344  long nSum2;
1345  long lGray;
1346 
1347  // initialize border with white pixels
1348  pVirDev->SetLineColor( COL_WHITE );
1349  pVirDev->DrawLine( Point(), Point( nWidth - 1, 0L ) );
1350  pVirDev->DrawLine( Point( nWidth - 1, 0L ), Point( nWidth - 1, nHeight - 1 ) );
1351  pVirDev->DrawLine( Point( nWidth - 1, nHeight - 1 ), Point( 0L, nHeight - 1 ) );
1352  pVirDev->DrawLine( Point( 0, nHeight - 1 ), Point() );
1353 
1354  for( long nY = 0, nY1 = 1, nY2 = 2; nY < nHeight2; nY++, nY1++, nY2++ )
1355  {
1356  Scanline pScanlineRead = pReadAcc->GetScanline( nY );
1357  Scanline pScanlineRead1 = pReadAcc->GetScanline( nY1 );
1358  Scanline pScanlineRead2 = pReadAcc->GetScanline( nY2 );
1359  for( long nX = 0, nXDst = 1, nXTmp; nX < nWidth2; nX++, nXDst++ )
1360  {
1361  nXTmp = nX;
1362 
1363  nSum2 = lGray = pReadAcc->GetIndexFromData( pScanlineRead, nXTmp++ );
1364  nSum1 = -nSum2;
1365  nSum2 += static_cast<long>(pReadAcc->GetIndexFromData( pScanlineRead, nXTmp++ )) << 1;
1366  lGray = pReadAcc->GetIndexFromData( pScanlineRead, nXTmp );
1367  nSum1 += lGray;
1368  nSum2 += lGray;
1369 
1370  nSum1 += static_cast<long>(pReadAcc->GetIndexFromData( pScanlineRead1, nXTmp )) << 1;
1371  nXTmp -= 2;
1372  nSum1 -= static_cast<long>(pReadAcc->GetIndexFromData( pScanlineRead1, nXTmp )) << 1;
1373 
1374  lGray = -static_cast<long>(pReadAcc->GetIndexFromData( pScanlineRead2, nXTmp++ ));
1375  nSum1 += lGray;
1376  nSum2 += lGray;
1377  nSum2 -= static_cast<long>(pReadAcc->GetIndexFromData( pScanlineRead2, nXTmp++ )) << 1;
1378  lGray = static_cast<long>(pReadAcc->GetIndexFromData( pScanlineRead2, nXTmp ));
1379  nSum1 += lGray;
1380  nSum2 -= lGray;
1381 
1382  if( ( nSum1 * nSum1 + nSum2 * nSum2 ) < lThres2 )
1383  pVirDev->DrawPixel( Point(nXDst, nY), COL_WHITE );
1384  else
1385  pVirDev->DrawPixel( Point(nXDst, nY), COL_BLACK );
1386  }
1387  }
1388 
1389  bRet = true;
1390  }
1391 
1392  pReadAcc.reset();
1393 
1394  if( bRet )
1395  aRetBmp = pVirDev->GetBitmap(Point(0,0), aSize);
1396  }
1397  }
1398 
1399  if( !aRetBmp )
1400  aRetBmp = rBmp;
1401  else
1402  {
1403  aRetBmp.SetPrefMapMode( rBmp.GetPrefMapMode() );
1404  aRetBmp.SetPrefSize( rBmp.GetPrefSize() );
1405  }
1406 
1407  return aRetBmp;
1408 }
1409 
1411 tools::Polygon BitmapEx::GetContour( bool bContourEdgeDetect, bool bContourVert,
1412  const tools::Rectangle* pWorkRectPixel )
1413 {
1414  Bitmap aWorkBmp;
1415  tools::Polygon aRetPoly;
1416  tools::Rectangle aWorkRect( Point(), maBitmap.GetSizePixel() );
1417 
1418  if( pWorkRectPixel )
1419  aWorkRect.Intersection( *pWorkRectPixel );
1420 
1421  aWorkRect.Justify();
1422 
1423  if( ( aWorkRect.GetWidth() > 4 ) && ( aWorkRect.GetHeight() > 4 ) )
1424  {
1425  // if the flag is set, we need to detect edges
1426  if( bContourEdgeDetect )
1427  aWorkBmp = DetectEdges( maBitmap );
1428  else
1429  aWorkBmp = maBitmap;
1430 
1431  BitmapReadAccess* pAcc = aWorkBmp.AcquireReadAccess();
1432 
1433  const long nWidth = pAcc ? pAcc->Width() : 0;
1434  const long nHeight = pAcc ? pAcc->Height() : 0;
1435 
1436  if (pAcc && nWidth && nHeight)
1437  {
1438  const Size& rPrefSize = aWorkBmp.GetPrefSize();
1439  const double fFactorX = static_cast<double>(rPrefSize.Width()) / nWidth;
1440  const double fFactorY = static_cast<double>(rPrefSize.Height()) / nHeight;
1441  const long nStartX1 = aWorkRect.Left() + 1;
1442  const long nEndX1 = aWorkRect.Right();
1443  const long nStartX2 = nEndX1 - 1;
1444  const long nStartY1 = aWorkRect.Top() + 1;
1445  const long nEndY1 = aWorkRect.Bottom();
1446  const long nStartY2 = nEndY1 - 1;
1447  std::unique_ptr<Point[]> pPoints1;
1448  std::unique_ptr<Point[]> pPoints2;
1449  long nX, nY;
1450  sal_uInt16 nPolyPos = 0;
1451  const BitmapColor aBlack = pAcc->GetBestMatchingColor( COL_BLACK );
1452 
1453  if( bContourVert )
1454  {
1455  pPoints1.reset(new Point[ nWidth ]);
1456  pPoints2.reset(new Point[ nWidth ]);
1457 
1458  for( nX = nStartX1; nX < nEndX1; nX++ )
1459  {
1460  nY = nStartY1;
1461 
1462  // scan row from left to right
1463  while( nY < nEndY1 )
1464  {
1465  Scanline pScanline = pAcc->GetScanline( nY );
1466  if( aBlack == pAcc->GetPixelFromData( pScanline, nX ) )
1467  {
1468  pPoints1[ nPolyPos ] = Point( nX, nY );
1469  nY = nStartY2;
1470 
1471  // this loop always breaks eventually as there is at least one pixel
1472  while( true )
1473  {
1474  // coverity[copy_paste_error : FALSE] - this is correct nX, not nY
1475  if( aBlack == pAcc->GetPixelFromData( pScanline, nX ) )
1476  {
1477  pPoints2[ nPolyPos ] = Point( nX, nY );
1478  break;
1479  }
1480 
1481  nY--;
1482  }
1483 
1484  nPolyPos++;
1485  break;
1486  }
1487 
1488  nY++;
1489  }
1490  }
1491  }
1492  else
1493  {
1494  pPoints1.reset(new Point[ nHeight ]);
1495  pPoints2.reset(new Point[ nHeight ]);
1496 
1497  for ( nY = nStartY1; nY < nEndY1; nY++ )
1498  {
1499  nX = nStartX1;
1500  Scanline pScanline = pAcc->GetScanline( nY );
1501 
1502  // scan row from left to right
1503  while( nX < nEndX1 )
1504  {
1505  if( aBlack == pAcc->GetPixelFromData( pScanline, nX ) )
1506  {
1507  pPoints1[ nPolyPos ] = Point( nX, nY );
1508  nX = nStartX2;
1509 
1510  // this loop always breaks eventually as there is at least one pixel
1511  while( true )
1512  {
1513  if( aBlack == pAcc->GetPixelFromData( pScanline, nX ) )
1514  {
1515  pPoints2[ nPolyPos ] = Point( nX, nY );
1516  break;
1517  }
1518 
1519  nX--;
1520  }
1521 
1522  nPolyPos++;
1523  break;
1524  }
1525 
1526  nX++;
1527  }
1528  }
1529  }
1530 
1531  const sal_uInt16 nNewSize1 = nPolyPos << 1;
1532 
1533  aRetPoly = tools::Polygon( nPolyPos, pPoints1.get() );
1534  aRetPoly.SetSize( nNewSize1 + 1 );
1535  aRetPoly[ nNewSize1 ] = aRetPoly[ 0 ];
1536 
1537  for( sal_uInt16 j = nPolyPos; nPolyPos < nNewSize1; )
1538  aRetPoly[ nPolyPos++ ] = pPoints2[ --j ];
1539 
1540  if( ( fFactorX != 0. ) && ( fFactorY != 0. ) )
1541  aRetPoly.Scale( fFactorX, fFactorY );
1542  }
1543 
1544  Bitmap::ReleaseAccess(pAcc);
1545  }
1546 
1547  return aRetPoly;
1548 }
1549 
1550 void BitmapEx::setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo )
1551 {
1552  AlphaMask aAlphaMask(GetAlpha());
1553  BitmapScopedWriteAccess pWriteAccess(aAlphaMask);
1554  Bitmap::ScopedReadAccess pReadAccess(maBitmap);
1555  assert( pReadAccess.get() && pWriteAccess.get() );
1556  if ( pReadAccess.get() && pWriteAccess.get() )
1557  {
1558  for ( long nY = 0; nY < pReadAccess->Height(); nY++ )
1559  {
1560  Scanline pScanline = pWriteAccess->GetScanline( nY );
1561  Scanline pScanlineRead = pReadAccess->GetScanline( nY );
1562  for ( long nX = 0; nX < pReadAccess->Width(); nX++ )
1563  {
1564  const sal_uInt8 cIndex = pReadAccess->GetPixelFromData( pScanlineRead, nX ).GetIndex();
1565  if ( cIndex == cIndexFrom )
1566  pWriteAccess->SetPixelOnData( pScanline, nX, BitmapColor(nAlphaTo) );
1567  }
1568  }
1569  }
1570 }
1571 
1573 {
1574  AlphaMask aAlpha;
1575 
1576  if (!IsTransparent())
1577  {
1578  aAlpha = AlphaMask(GetSizePixel(), &cTrans);
1579  }
1580  else if( !IsAlpha() )
1581  {
1582  aAlpha = GetMask();
1583  aAlpha.Replace( 0, cTrans );
1584  }
1585  else
1586  {
1587  aAlpha = GetAlpha();
1588  BitmapScopedWriteAccess pA(aAlpha);
1589  assert(pA);
1590 
1591  if( !pA )
1592  return;
1593 
1594  sal_uLong nTrans = cTrans, nNewTrans;
1595  const long nWidth = pA->Width(), nHeight = pA->Height();
1596 
1598  {
1599  for( long nY = 0; nY < nHeight; nY++ )
1600  {
1601  Scanline pAScan = pA->GetScanline( nY );
1602 
1603  for( long nX = 0; nX < nWidth; nX++ )
1604  {
1605  nNewTrans = nTrans + *pAScan;
1606  *pAScan++ = static_cast<sal_uInt8>( ( nNewTrans & 0xffffff00 ) ? 255 : nNewTrans );
1607  }
1608  }
1609  }
1610  else
1611  {
1612  BitmapColor aAlphaValue( 0 );
1613 
1614  for( long nY = 0; nY < nHeight; nY++ )
1615  {
1616  Scanline pScanline = pA->GetScanline( nY );
1617  for( long nX = 0; nX < nWidth; nX++ )
1618  {
1619  nNewTrans = nTrans + pA->GetIndexFromData( pScanline, nX );
1620  aAlphaValue.SetIndex( static_cast<sal_uInt8>( ( nNewTrans & 0xffffff00 ) ? 255 : nNewTrans ) );
1621  pA->SetPixelOnData( pScanline, nX, aAlphaValue );
1622  }
1623  }
1624  }
1625  }
1626  *this = BitmapEx( GetBitmapRef(), aAlpha );
1627 }
1628 
1629 // AS: Because JPEGs require the alpha channel provided separately (JPEG does not
1630 // natively support alpha channel, but SWF lets you provide it separately), we
1631 // extract the alpha channel into a separate array here.
1632 void BitmapEx::GetSplitData( std::vector<sal_uInt8>& rvColorData, std::vector<sal_uInt8>& rvAlphaData ) const
1633 {
1634  if( IsEmpty() )
1635  return;
1636 
1637  Bitmap::ScopedReadAccess pRAcc(const_cast<Bitmap&>(maBitmap));
1638 
1639  assert( pRAcc );
1640 
1641  AlphaMask aAlpha;
1642  sal_uInt32 nWidth = pRAcc->Width();
1643  sal_uInt32 nHeight = pRAcc->Height();
1644  rvColorData.resize(nWidth*nHeight*4);
1645  rvAlphaData.resize(nWidth*nHeight);
1646  sal_uInt8* p = rvColorData.data(), *pAlpha = rvAlphaData.data();
1647 
1648 
1649  if (IsAlpha())
1650  {
1651  aAlpha = GetAlpha();
1652  }
1653  else if (IsTransparent())
1654  {
1655  aAlpha = GetMask();
1656  }
1657  else
1658  {
1659  sal_uInt8 cAlphaVal = 0;
1660  aAlpha = AlphaMask(maBitmap.GetSizePixel(), &cAlphaVal);
1661  }
1662 
1663  AlphaMask::ScopedReadAccess pAAcc(aAlpha);
1664 
1665  assert( pAAcc );
1666 
1667  for( sal_uInt32 nY = 0; nY < nHeight; nY++ )
1668  {
1669  Scanline pScanlineAA = pAAcc->GetScanline( nY );
1670  for( sal_uInt32 nX = 0; nX < nWidth; nX++ )
1671  {
1672  const sal_uInt8 nAlpha = pAAcc->GetIndexFromData( pScanlineAA, nX );
1673  const BitmapColor aPixelColor( pRAcc->GetColor( nY, nX ) );
1674 
1675  if( nAlpha == 0xff )
1676  {
1677  *p++ = 0;
1678  *p++ = 0;
1679  *p++ = 0;
1680  *p++ = 0;
1681  }
1682  else
1683  {
1684  *p++ = 0xff-nAlpha;
1685  *p++ = aPixelColor.GetRed();
1686  *p++ = aPixelColor.GetGreen();
1687  *p++ = aPixelColor.GetBlue();
1688  }
1689  *pAlpha++ = 0xff - nAlpha;
1690  }
1691  }
1692 }
1693 
1695 {
1696  Bitmap aNewMask = maBitmap.CreateMask( maskColor, nTol );
1697  if ( IsTransparent() )
1698  aNewMask.CombineSimple( maMask, BmpCombine::Or );
1699  maMask = aNewMask;
1701 }
1702 
1706 void BitmapEx::GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
1707  sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex,
1708  sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount)
1709 {
1710  Bitmap::ScopedReadAccess pReadAccess( maBitmap );
1711  assert( pReadAccess );
1712 
1713  if( pReadAccess->HasPalette() )
1714  {
1715  sal_uInt16 nPalCount = pReadAccess->GetPaletteEntryCount();
1716 
1717  if( nPalCount )
1718  {
1719  rRGBPalette = css::uno::Sequence< sal_Int32 >( nPalCount + 1 );
1720 
1721  sal_Int32* pTmp = rRGBPalette.getArray();
1722 
1723  for( sal_uInt32 i = 0; i < nPalCount; i++, pTmp++ )
1724  {
1725  const BitmapColor& rCol = pReadAccess->GetPaletteColor( static_cast<sal_uInt16>(i) );
1726 
1727  *pTmp = static_cast<sal_Int32>(rCol.GetRed()) << sal_Int32(24);
1728  *pTmp |= static_cast<sal_Int32>(rCol.GetGreen()) << sal_Int32(16);
1729  *pTmp |= static_cast<sal_Int32>(rCol.GetBlue()) << sal_Int32(8);
1730  *pTmp |= sal_Int32(0x000000ffL);
1731  }
1732 
1733  if( IsTransparent() )
1734  {
1735  // append transparent entry
1736  *pTmp = sal_Int32(0xffffff00L);
1737  rnTransparencyIndex = nPalCount;
1738  nPalCount++;
1739  }
1740  else
1741  rnTransparencyIndex = 0;
1742  }
1743  }
1744  else
1745  {
1746  rnRedMask = 0xff000000UL;
1747  rnGreenMask = 0x00ff0000UL;
1748  rnBlueMask = 0x0000ff00UL;
1749  rnAlphaMask = 0x000000ffUL;
1750  rnTransparencyIndex = 0;
1751  }
1752 
1753  rnWidth = pReadAccess->Width();
1754  rnHeight = pReadAccess->Height();
1755  rnBitCount = pReadAccess->GetBitCount();
1756 }
1757 
1758 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const BitmapEx &rBitmapEx) const
Definition: bitmapex.cxx:179
long Width() const
Color m_aLastColorBottomLeft
Definition: svdata.hxx:310
void Replace(const Bitmap &rMask, sal_uInt8 rReplaceTransparency)
Definition: alpha.cxx:80
bool Erase(const Color &rFillColor)
Fill the entire bitmap with the given color.
Definition: bitmapex.cxx:569
Bitmap GetMask() const
Definition: bitmapex.cxx:258
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
bool Adjust(short nLuminancePercent, short nContrastPercent=0, short nChannelRPercent=0, short nChannelGPercent=0, short nChannelBPercent=0, double fGamma=1.0, bool bInvert=false, bool msoBrightness=false)
Change various global color characteristics.
Definition: bitmap3.cxx:1044
sal_uInt8 GetIndex() const
Definition: BitmapColor.hxx:61
BitmapEx TransformBitmapEx(double fWidth, double fHeight, const basegfx::B2DHomMatrix &rTransformation) const
Create transformed Bitmap.
Definition: bitmapex.cxx:872
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
sal_uInt8 GetRed() const
void SetTransparency(sal_uInt8 nTransparency)
void SetSizePixel(const Size &rNewSize)
Definition: bitmapex.cxx:313
double getHeight() const
tools::Rectangle & Intersection(const tools::Rectangle &rRect)
Scanline GetScanline(long nY) const
OUString DetermineIconTheme() const
Determine which icon theme should be used.
bool Adjust(short nLuminancePercent, short nContrastPercent, short nChannelRPercent, short nChannelGPercent, short nChannelBPercent, double fGamma=1.0, bool bInvert=false, bool msoBrightness=false)
Change various global color characteristics.
Definition: bitmapex.cxx:608
void Replace(const Color &rSearchColor, const Color &rReplaceColor)
Replace all pixel having the search color with the specified color.
Definition: bitmapex.cxx:596
Bitmap maMask
Definition: bitmapex.hxx:481
void Merge(const Color &rMergeColor, sal_uInt8 cTransparency)
BitmapEx createBlendFrame(const Size &rSize, sal_uInt8 nAlpha, Color aColorTopLeft, Color aColorBottomRight)
Create a blend frame as BitmapEx.
Definition: bitmapex.cxx:1137
static bool more(const double &rfValA, const double &rfValB)
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:32
long Height() const
signed char sal_Int8
TransparentType
Definition: bitmapex.hxx:36
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
BitmapEx m_aLastResult
Definition: svdata.hxx:311
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
Scale the bitmap.
Definition: bitmapex.cxx:370
sal_uInt8 GetTransparency() const
sal_uIntPtr sal_uLong
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:705
void Expand(sal_uLong nDX, sal_uLong nDY, bool bExpandTransparent=false)
Expand the bitmap by pixel padding.
Definition: bitmapex.cxx:459
BitmapEx getTransformed(const basegfx::B2DHomMatrix &rTransformation, const basegfx::B2DRange &rVisibleRange, double fMaximumArea) const
Create transformed Bitmap.
Definition: bitmapex.cxx:902
constexpr std::underlying_type_t< T > underlyingEnumValue(T e)
sal_uInt16 GetBitCount() const
B2DVector getRange() const
void SetSize(sal_uInt16 nNewSize)
BitmapChecksum vcl_get_checksum(BitmapChecksum Checksum, const void *Data, sal_uInt32 DatLen)
Definition: checksum.hxx:72
BitmapReadAccess * AcquireReadAccess()
SAL_DLLPRIVATE void ImplSetBitmap(const Bitmap &rBitmap)
Definition: alpha.cxx:63
Size GetSizePixel() const
Size m_aLastSize
Definition: svdata.hxx:305
long Width() const
bool Expand(sal_uLong nDX, sal_uLong nDY, const Color *pInitColor=nullptr)
Expand the bitmap by pixel padding.
float x
BlendFrameCache * ImplGetBlendFrameCache()
Definition: svdata.cxx:307
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Definition: bitmapex.cxx:454
BitmapChecksum GetChecksum() const
Definition: bitmapex.cxx:292
static Bitmap DetectEdges(const Bitmap &rBmp)
Definition: bitmapex.cxx:1318
Size maBitmapSize
Definition: bitmapex.hxx:482
void Scale(double fScaleX, double fScaleY)
sal_uInt8 SVBT32[4]
static BitmapEx AutoScaleBitmap(BitmapEx const &aBitmap, const long aStandardSize)
Definition: bitmapex.cxx:628
const Size & GetPrefSize() const
Definition: bitmap.hxx:566
static OutputDevice * GetDefaultDevice()
Get the default "device" (in this case the default window).
Definition: svapp.cxx:1055
bool Crop(const tools::Rectangle &rRectPixel)
Crop the bitmap.
static VCL_DLLPUBLIC ImageTree & get()
Definition: ImageTree.cxx:16
constexpr::Color COL_TRANSPARENT(0xFF, 0xFF, 0xFF, 0xFF)
bool IsAlpha() const
Definition: bitmapex.cxx:226
bool CombineSimple(const Bitmap &rMask, BmpCombine eCombine)
Perform boolean operations with another bitmap.
bool Mirror(BmpMirrorFlags nMirrorFlags)
Mirror the bitmap.
double getWidth() const
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
std::shared_ptr< BColorModifier > BColorModifierSharedPtr
BitmapEx & operator=(const BitmapEx &rBitmapEx)
B2DHomMatrix createScaleB2DHomMatrix(double fScaleX, double fScaleY)
bool mbAlpha
Definition: bitmapex.hxx:485
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
B2DHomMatrix createScaleTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fTranslateX, double fTranslateY)
void SetPixelOnData(sal_uInt8 *pData, long nX, const BitmapColor &rBitmapColor)
void loadFromIconTheme(const OUString &rIconName)
Definition: bitmapex.cxx:95
sal_uInt8 m_nLastAlpha
Definition: svdata.hxx:306
sal_uInt8 GetBlue() const
B2IRange fround(const B2DRange &rRange)
void Clear()
Definition: bitmapex.cxx:216
float y
bool Mirror(BmpMirrorFlags nMirrorFlags)
Mirror the bitmap.
Definition: bitmapex.cxx:333
void CombineMaskOr(Color maskColor, sal_uInt8 nTol)
Definition: bitmapex.cxx:1694
BitmapEx ModifyBitmapEx(const basegfx::BColorModifierStack &rBColorModifierStack) const
Create ColorStack-modified version of this BitmapEx.
Definition: bitmapex.cxx:983
Color m_aLastColorTopRight
Definition: svdata.hxx:308
Bitmap GetBitmap(const Color *pTransReplaceColor=nullptr) const
Definition: bitmapex.cxx:236
void AdjustTransparency(sal_uInt8 cTrans)
Definition: bitmapex.cxx:1572
void Invert()
void SetEmpty()
Definition: bitmapex.cxx:208
bool IsEmpty() const
Definition: bitmapex.cxx:203
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:66
const MapMode & GetPrefMapMode() const
Definition: bitmap.hxx:556
VCL_DLLPUBLIC bool loadImage(OUString const &name, OUString const &style, BitmapEx &bitmap, bool localized, const ImageLoadFlags eFlags=ImageLoadFlags::NONE)
Definition: ImageTree.cxx:45
NONE
void SetPrefMapMode(const MapMode &rMapMode)
Definition: bitmap.hxx:561
bool Create(const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas, const Size &rSize)
populate from a canvas implementation
Definition: bitmapex.cxx:772
#define BITMAP_CHECKSUM_SIZE
Definition: checksum.hxx:28
Bitmap maBitmap
Definition: bitmapex.hxx:480
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
void GetSplitData(std::vector< sal_uInt8 > &rvColorData, std::vector< sal_uInt8 > &rvAlphaData) const
extract the bitmap and alpha data separately.
Definition: bitmapex.cxx:1632
Color m_aLastColorTopLeft
Definition: svdata.hxx:307
bool HasPalette() const
ScanlineFormat GetScanlineFormat() const
Color m_aLastColorBottomRight
Definition: svdata.hxx:309
BitmapChecksum GetChecksum() const
bool Invert()
Perform the Invert operation on every pixel.
Definition: bitmapex.cxx:318
const ::basegfx::BColor & getBColor() const
int i
sal_uLong GetSizeBytes() const
Definition: bitmap.hxx:581
const BColorModifierSharedPtr & getBColorModifier(sal_uInt32 nIndex) const
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
sal_uLong GetSizeBytes() const
Definition: bitmapex.cxx:282
BmpMirrorFlags
Definition: bitmap.hxx:36
bool Invert()
Perform the Invert operation on every pixel.
BmpScaleFlag
Definition: bitmap.hxx:48
static void ReleaseAccess(BitmapInfoAccess *pAccess)
::Color GetPixelColor(sal_Int32 nX, sal_Int32 nY) const
Get pixel color (including alpha) at given position.
Definition: bitmapex.cxx:750
bool CopyPixel(const tools::Rectangle &rRectDst, const tools::Rectangle &rRectSrc, const BitmapEx *pBmpExSrc)
Copy a rectangular area from another bitmap.
Definition: bitmapex.cxx:480
BmpConversion
Definition: bitmap.hxx:65
bool IsTransparent() const
Definition: bitmapex.cxx:221
bool CopyPixel_AlphaOptimized(const tools::Rectangle &rRectDst, const tools::Rectangle &rRectSrc, const Bitmap *pBmpSrc)
void Draw(OutputDevice *pOutDev, const Point &rDestPt) const
Definition: bitmapex.cxx:617
BitmapColor GetPixel(long nY, long nX) const
sal_uInt16 GetPaletteEntryCount() const
void SetIndex(sal_uInt8 cIndex)
Definition: BitmapColor.hxx:66
void SetEmpty()
sal_uInt8 GetGreen() const
SAL_DLLPRIVATE const Bitmap & ImplGetBitmap() const
Definition: alpha.cxx:58
double getMinY() const
bool Rotate(long nAngle10, const Color &rFillColor)
Rotate bitmap by the specified angle.
virtual std::shared_ptr< SalBitmap > CreateSalBitmap()=0
AlphaMask GetAlpha() const
Definition: bitmapex.cxx:268
const Bitmap & GetBitmapRef() const
Gives direct access to the contained bitmap.
Definition: bitmapex.cxx:231
long Height() const
#define SAL_WARN_IF(condition, area, stream)
unsigned char sal_uInt8
bool Scale(const Size &rNewSize, BmpScaleFlag nScaleFlag=BmpScaleFlag::Default)
Scale the bitmap.
Definition: bitmap3.cxx:818
void BCToBCOA(BitmapChecksum n, BitmapChecksumOctetArray p)
Definition: checksum.hxx:34
bool Convert(BmpConversion eConversion)
Convert bitmap format.
Definition: bitmap3.cxx:226
BitmapColor GetColor(long nY, long nX) const
const BitmapPalette & GetPalette() const
B2DPoint getMinimum() const
bool IsEmpty() const
Definition: bitmap.hxx:551
void GetColorModel(css::uno::Sequence< sal_Int32 > &rRGBPalette, sal_uInt32 &rnRedMask, sal_uInt32 &rnGreenMask, sal_uInt32 &rnBlueMask, sal_uInt32 &rnAlphaMask, sal_uInt32 &rnTransparencyIndex, sal_uInt32 &rnWidth, sal_uInt32 &rnHeight, sal_uInt8 &rnBitCount)
Retrieves the color model data we need for the XImageConsumer stuff.
Definition: bitmapex.cxx:1706
BitmapEx()
Definition: bitmapex.cxx:50
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
void translate(double fX, double fY)
BitmapColor GetPixelFromData(const sal_uInt8 *pData, long nX) const
void AdaptBitCount(Bitmap &rNew) const
Definition: bitmap3.cxx:844
TransparentType meTransparent
Definition: bitmapex.hxx:484
bool Erase(const Color &rFillColor)
Fill the entire bitmap with the given color.
Definition: bitmappaint.cxx:34
void setAlphaFrom(sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo)
Definition: bitmapex.cxx:1550
#define SAL_WARN(area, stream)
sal_uInt8 BitmapChecksumOctetArray[BITMAP_CHECKSUM_SIZE]
Definition: checksum.hxx:31
double getMinX() const
const BitmapColor & GetPaletteColor(sal_uInt16 nColor) const
void ReplaceTransparency(const Color &rColor)
Replace transparency with given color.
Definition: bitmapex.cxx:1305
sal_uInt16 GetBitCount() const
sal_uInt32 count() const
bool CopyPixel(const tools::Rectangle &rRectDst, const tools::Rectangle &rRectSrc, const Bitmap *pBmpSrc=nullptr)
Copy a rectangular area from another bitmap.
bool Replace(const Bitmap &rMask, const Color &rReplaceColor)
Replace all pixel where the given mask is on with the specified color.
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
tools::Polygon GetContour(bool bContourEdgeDetect, bool bContourVert, const tools::Rectangle *pWorkRect)
Get contours in image.
Definition: bitmapex.cxx:1411
Color maTransparentColor
Definition: bitmapex.hxx:483
sal_uInt8 GetTransparency(sal_Int32 nX, sal_Int32 nY) const
Get transparency at given position.
Definition: bitmapex.cxx:684
BitmapColor GetBestMatchingColor(const BitmapColor &rBitmapColor)
bool Crop(const tools::Rectangle &rRectPixel)
Crop the bitmap.
Definition: bitmapex.cxx:434
Bitmap CreateMask(const Color &rTransColor, sal_uInt8 nTol=0) const
Create on-off mask from bitmap.
void SetPaletteColor(sal_uInt16 nColor, const BitmapColor &rBitmapColor)
SalInstance * mpDefInst
Definition: svdata.hxx:341
sal_uInt8 GetIndexFromData(const sal_uInt8 *pData, long nX) const
bool Rotate(long nAngle10, const Color &rFillColor)
Rotate bitmap by the specified angle.
Definition: bitmapex.cxx:390