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, const tools::Rectangle* pWorkRect );
325 
356  bool Adjust(
357  short nLuminancePercent,
358  short nContrastPercent,
359  short nChannelRPercent,
360  short nChannelGPercent,
361  short nChannelBPercent,
362  double fGamma = 1.0,
363  bool bInvert = false,
364  bool msoBrightness = false );
365 
377  sal_uInt8 GetTransparency(
378  sal_Int32 nX,
379  sal_Int32 nY) const;
380 
389  ::Color GetPixelColor(
390  sal_Int32 nX,
391  sal_Int32 nY) const;
392 
405  [[nodiscard]]
406  BitmapEx TransformBitmapEx(
407  double fWidth,
408  double fHeight,
409  const basegfx::B2DHomMatrix& rTransformation) const;
410 
429  [[nodiscard]]
430  BitmapEx getTransformed(
431  const basegfx::B2DHomMatrix& rTransformation,
432  const basegfx::B2DRange& rVisibleRange,
433  double fMaximumArea) const;
434 
440  [[nodiscard]]
441  BitmapEx ModifyBitmapEx( const basegfx::BColorModifierStack& rBColorModifierStack) const;
442 
443  [[nodiscard]]
444  static BitmapEx AutoScaleBitmap( BitmapEx const & aBitmap, const long aStandardSize );
445 
447  bool Create(
448  const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
449  const Size &rSize );
450 
451  void setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
452 
453  void AdjustTransparency( sal_uInt8 cTrans );
454 
455  void CombineMaskOr(Color maskColor, sal_uInt8 nTol);
456 
460  void GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
461  sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex,
462  sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount);
463 
464  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetBitmapSalBitmap() const { return maBitmap.ImplGetSalBitmap(); }
465  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetMaskSalBitmap() const { return maMask.ImplGetSalBitmap(); }
466 
467 
468 private:
469  friend class ImpGraphic;
470  friend class OutputDevice;
471  friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
472  friend bool VCL_DLLPUBLIC ReadRawDIB(BitmapEx& rTarget, const unsigned char* pBuf,
473  const ScanlineFormat nFormat,
474  const int nHeight,
475  const int nStride);
476 
477  void loadFromIconTheme( const OUString& rIconName );
478 
484  bool mbAlpha;
485 
486 };
487 
488 
503  const Size& rSize,
504  sal_uInt8 nAlpha,
505  Color aColorTopLeft,
506  Color aColorBottomRight);
507 
508 
522  const Size& rSize,
523  sal_uInt8 nAlpha,
524  Color aColorTopLeft,
525  Color aColorTopRight,
526  Color aColorBottomRight,
527  Color aColorBottomLeft);
528 
529 #endif // INCLUDED_VCL_BITMAPEX_HXX
530 
531 /* 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:480
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:481
ScanlineFormat
Definition: Scanline.hxx:28
bool mbAlpha
Definition: bitmapex.hxx:484
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:479
bool WriteDIBBitmapEx(const BitmapEx &rSource, SvStream &rOStm)
Definition: dibtools.cxx:1871
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:465
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetBitmapSalBitmap() const
Definition: bitmapex.hxx:464
#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:1170
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
void SetPrefSize(const Size &rPrefSize)
Definition: bitmapex.hxx:87
TransparentType meTransparent
Definition: bitmapex.hxx:483
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
Color maTransparentColor
Definition: bitmapex.hxx:482
bool ReadRawDIB(BitmapEx &rTarget, const unsigned char *pBuf, const ScanlineFormat nFormat, const int nHeight, const int nStride)
Definition: dibtools.cxx:1838
Point Rotate(const Point &rPoint, short nOrientation, const Point &rOrigin)