LibreOffice Module vcl (master)  1
bitmapex.hxx
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 #ifndef INCLUDED_VCL_BITMAPEX_HXX
21 #define INCLUDED_VCL_BITMAPEX_HXX
22 
23 #include <vcl/dllapi.h>
24 #include <vcl/alpha.hxx>
25 #include <vcl/Scanline.hxx>
26 #include <tools/color.hxx>
27 
28 #include <sal/types.h>
29 
30 namespace com { namespace sun { namespace star { namespace rendering {
31  class XBitmapCanvas;
32 } } } }
33 namespace com { namespace sun { namespace star { namespace uno { template <class interface_type> class Reference; } } } }
34 namespace basegfx { class BColorModifierStack; }
35 
36 enum class TransparentType
37 {
38  NONE,
39  Color,
40  Bitmap
41 };
42 
44 {
45 public:
46 
47  BitmapEx();
48  explicit BitmapEx( const OUString& rIconName );
49  BitmapEx( const BitmapEx& rBitmapEx );
50  BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
51  BitmapEx( Size aSize, sal_uInt16 nBitCount );
52  explicit BitmapEx( const Bitmap& rBmp );
53  BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
54  BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
55  BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
56 
57  BitmapEx& operator=( const BitmapEx& rBitmapEx );
58  BitmapEx& operator=( const Bitmap& rBitmap ) { return operator=(BitmapEx(rBitmap)); }
59  bool operator==( const BitmapEx& rBitmapEx ) const;
60  bool operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
61  bool operator!() const { return !maBitmap; }
62 
63  bool IsEmpty() const;
64  void SetEmpty();
65  void Clear();
66 
67  void Draw( OutputDevice* pOutDev,
68  const Point& rDestPt ) const;
69  void Draw( OutputDevice* pOutDev,
70  const Point& rDestPt, const Size& rDestSize ) const;
71 
72  bool IsTransparent() const;
73  TransparentType GetTransparentType() const { return meTransparent; }
74 
75  Bitmap GetBitmap( const Color* pTransReplaceColor = nullptr ) const;
77  const Bitmap& GetBitmapRef() const;
78  Bitmap GetMask() const;
79 
80  bool IsAlpha() const;
81  AlphaMask GetAlpha() const;
82 
83  const Size& GetSizePixel() const { return maBitmapSize; }
84  void SetSizePixel(const Size& rNewSize);
85 
86  const Size& GetPrefSize() const { return maBitmap.GetPrefSize(); }
87  void SetPrefSize( const Size& rPrefSize ) { maBitmap.SetPrefSize( rPrefSize ); }
88 
89  const MapMode& GetPrefMapMode() const { return maBitmap.GetPrefMapMode(); }
90  void SetPrefMapMode( const MapMode& rPrefMapMode ) { maBitmap.SetPrefMapMode( rPrefMapMode ); }
91 
92  const Color& GetTransparentColor() const { return maTransparentColor; }
93 
94  sal_uInt16 GetBitCount() const { return maBitmap.GetBitCount(); }
95  sal_uLong GetSizeBytes() const;
96  BitmapChecksum GetChecksum() const;
97 
101  void GetSplitData( std::vector<sal_uInt8>& rvColorData, std::vector<sal_uInt8>& rvAlphaData ) const;
102 
110  bool Convert( BmpConversion eConversion );
111 
126  bool Crop( const tools::Rectangle& rRectPixel );
127 
139  void Expand(
140  sal_uLong nDX, sal_uLong nDY,
141  bool bExpandTransparent = false );
142 
165  bool CopyPixel(
166  const tools::Rectangle& rRectDst,
167  const tools::Rectangle& rRectSrc,
168  const BitmapEx* pBmpExSrc );
169 
178  bool Erase( const Color& rFillColor );
179 
184  bool Invert();
185 
193  bool Mirror( BmpMirrorFlags nMirrorFlags );
194 
205  bool Scale(
206  const Size& rNewSize,
207  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
208 
222  bool Scale(
223  const double& rScaleX,
224  const double& rScaleY,
225  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
226 
240  bool Rotate(
241  long nAngle10,
242  const Color& rFillColor );
243 
252  void Replace(
253  const Color& rSearchColor,
254  const Color& rReplaceColor );
255 
269  void Replace(
270  const Color& rSearchColor,
271  const Color& rReplaceColor,
272  sal_uInt8 nTolerance );
273 
290  void Replace(
291  const Color* pSearchColors,
292  const Color* pReplaceColors,
293  sal_uLong nColorCount );
294 
313  void Replace(
314  const Color* pSearchColors,
315  const Color* pReplaceColors,
316  sal_uLong nColorCount,
317  sal_uInt8 const * pTols );
318 
321  void ReplaceTransparency( const Color& rColor );
322 
324  tools::Polygon GetContour( bool bContourEdgeDetect, bool bContourVert,
325  const tools::Rectangle* pWorkRect );
326 
357  bool Adjust(
358  short nLuminancePercent,
359  short nContrastPercent,
360  short nChannelRPercent,
361  short nChannelGPercent,
362  short nChannelBPercent,
363  double fGamma = 1.0,
364  bool bInvert = false,
365  bool msoBrightness = false );
366 
378  sal_uInt8 GetTransparency(
379  sal_Int32 nX,
380  sal_Int32 nY) const;
381 
390  ::Color GetPixelColor(
391  sal_Int32 nX,
392  sal_Int32 nY) const;
393 
406  [[nodiscard]]
407  BitmapEx TransformBitmapEx(
408  double fWidth,
409  double fHeight,
410  const basegfx::B2DHomMatrix& rTransformation) const;
411 
430  [[nodiscard]]
431  BitmapEx getTransformed(
432  const basegfx::B2DHomMatrix& rTransformation,
433  const basegfx::B2DRange& rVisibleRange,
434  double fMaximumArea) const;
435 
441  [[nodiscard]]
442  BitmapEx ModifyBitmapEx( const basegfx::BColorModifierStack& rBColorModifierStack) const;
443 
444  [[nodiscard]]
445  static BitmapEx AutoScaleBitmap( BitmapEx const & aBitmap, const long aStandardSize );
446 
448  bool Create(
449  const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
450  const Size &rSize );
451 
452  void setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
453 
454  void AdjustTransparency( sal_uInt8 cTrans );
455 
456  void CombineMaskOr(Color maskColor, sal_uInt8 nTol);
457 
461  void GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
462  sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex,
463  sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount);
464 
465  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetBitmapSalBitmap() const { return maBitmap.ImplGetSalBitmap(); }
466  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetMaskSalBitmap() const { return maMask.ImplGetSalBitmap(); }
467 
468 
469 private:
470  friend class ImpGraphic;
471  friend class OutputDevice;
472  friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
473  friend bool VCL_DLLPUBLIC ReadRawDIB(BitmapEx& rTarget, const unsigned char* pBuf,
474  const ScanlineFormat nFormat,
475  const int nHeight,
476  const int nStride);
477 
478  void loadFromIconTheme( const OUString& rIconName );
479 
485  bool mbAlpha;
486 
487 };
488 
489 
504  const Size& rSize,
505  sal_uInt8 nAlpha,
506  Color aColorTopLeft,
507  Color aColorBottomRight);
508 
509 
523  const Size& rSize,
524  sal_uInt8 nAlpha,
525  Color aColorTopLeft,
526  Color aColorTopRight,
527  Color aColorBottomRight,
528  Color aColorBottomLeft);
529 
530 #endif // INCLUDED_VCL_BITMAPEX_HXX
531 
532 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BitmapEx & operator=(const Bitmap &rBitmap)
Definition: bitmapex.hxx:58
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
Bitmap maMask
Definition: bitmapex.hxx:481
const MapMode & GetPrefMapMode() const
Definition: bitmapex.hxx:89
signed char sal_Int8
TransparentType
Definition: bitmapex.hxx:36
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
void SetPrefMapMode(const MapMode &rPrefMapMode)
Definition: bitmapex.hxx:90
Reference
Size maBitmapSize
Definition: bitmapex.hxx:482
ScanlineFormat
Definition: Scanline.hxx:28
bool mbAlpha
Definition: bitmapex.hxx:485
const Size & GetPrefSize() const
Definition: bitmapex.hxx:86
bool operator!=(const BitmapEx &rBitmapEx) const
Definition: bitmapex.hxx:60
bool operator!() const
Definition: bitmapex.hxx:61
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:203
Bitmap maBitmap
Definition: bitmapex.hxx:480
bool WriteDIBBitmapEx(const BitmapEx &rSource, SvStream &rOStm)
Definition: dibtools.cxx:1874
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
TransparentType GetTransparentType() const
Definition: bitmapex.hxx:73
BmpMirrorFlags
Definition: bitmap.hxx:36
BmpScaleFlag
Definition: bitmap.hxx:48
BmpConversion
Definition: bitmap.hxx:65
sal_uInt16 GetBitCount() const
Definition: bitmapex.hxx:94
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetMaskSalBitmap() const
Definition: bitmapex.hxx:466
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetBitmapSalBitmap() const
Definition: bitmapex.hxx:465
#define SAL_WARN_UNUSED
const Color & GetTransparentColor() const
Definition: bitmapex.hxx:92
unsigned char sal_uInt8
BitmapEx VCL_DLLPUBLIC createBlendFrame(const Size &rSize, sal_uInt8 nAlpha, Color aColorTopLeft, Color aColorBottomRight)
Create a blend frame as BitmapEx.
Definition: bitmapex.cxx:1137
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
void SetPrefSize(const Size &rPrefSize)
Definition: bitmapex.hxx:87
TransparentType meTransparent
Definition: bitmapex.hxx:484
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
Color maTransparentColor
Definition: bitmapex.hxx:483
bool ReadRawDIB(BitmapEx &rTarget, const unsigned char *pBuf, const ScanlineFormat nFormat, const int nHeight, const int nStride)
Definition: dibtools.cxx:1841
Point Rotate(const Point &rPoint, short nOrientation, const Point &rOrigin)