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 #include <tools/degree.hxx>
28 
29 #include <sal/types.h>
30 
31 namespace com::sun::star::rendering {
32  class XBitmapCanvas;
33 }
34 namespace com::sun::star::uno { template <class interface_type> class Reference; }
35 namespace basegfx { class BColorModifierStack; }
36 
37 enum class TransparentType
38 {
39  NONE,
40  Color,
41  Bitmap
42 };
43 
45 {
46 public:
47 
48  BitmapEx();
49  explicit BitmapEx( const OUString& rIconName );
50  BitmapEx( const BitmapEx& rBitmapEx );
51  BitmapEx( const BitmapEx& rBitmapEx, Point aSrc, Size aSize );
52  BitmapEx( Size aSize, sal_uInt16 nBitCount );
53  explicit BitmapEx( const Bitmap& rBmp );
54  BitmapEx( const Bitmap& rBmp, const Bitmap& rMask );
55  BitmapEx( const Bitmap& rBmp, const AlphaMask& rAlphaMask );
56  BitmapEx( const Bitmap& rBmp, const Color& rTransparentColor );
57 
58  BitmapEx& operator=( const BitmapEx& rBitmapEx );
59  BitmapEx& operator=( const Bitmap& rBitmap ) { return operator=(BitmapEx(rBitmap)); }
60  bool operator==( const BitmapEx& rBitmapEx ) const;
61  bool operator!=( const BitmapEx& rBitmapEx ) const { return !(*this==rBitmapEx); }
62  bool operator!() const { return !maBitmap; }
63 
64  bool IsEmpty() const;
65  void SetEmpty();
66  void Clear();
67 
68  void Draw( OutputDevice* pOutDev,
69  const Point& rDestPt ) const;
70  void Draw( OutputDevice* pOutDev,
71  const Point& rDestPt, const Size& rDestSize ) const;
72 
73  bool IsTransparent() const;
74  TransparentType GetTransparentType() const { return meTransparent; }
75 
76  Bitmap GetBitmap( Color aTransparentReplaceColor ) const;
78  const Bitmap& GetBitmap() const;
79  Bitmap GetMask() const;
80 
81  bool IsAlpha() const;
82  AlphaMask GetAlpha() const;
83 
84  const Size& GetSizePixel() const { return maBitmapSize; }
85  void SetSizePixel(const Size& rNewSize);
86 
87  const Size& GetPrefSize() const { return maBitmap.GetPrefSize(); }
88  void SetPrefSize( const Size& rPrefSize ) { maBitmap.SetPrefSize( rPrefSize ); }
89 
90  const MapMode& GetPrefMapMode() const { return maBitmap.GetPrefMapMode(); }
91  void SetPrefMapMode( const MapMode& rPrefMapMode ) { maBitmap.SetPrefMapMode( rPrefMapMode ); }
92 
93  const Color& GetTransparentColor() const { return maTransparentColor; }
94 
95  sal_uInt16 GetBitCount() const { return maBitmap.GetBitCount(); }
96  sal_uLong GetSizeBytes() const;
97  BitmapChecksum GetChecksum() const;
98 
106  bool Convert( BmpConversion eConversion );
107 
122  bool Crop( const tools::Rectangle& rRectPixel );
123 
135  void Expand(
136  sal_uLong nDX, sal_uLong nDY,
137  bool bExpandTransparent = false );
138 
161  bool CopyPixel(
162  const tools::Rectangle& rRectDst,
163  const tools::Rectangle& rRectSrc,
164  const BitmapEx* pBmpExSrc );
165 
174  bool Erase( const Color& rFillColor );
175 
180  bool Invert();
181 
189  bool Mirror( BmpMirrorFlags nMirrorFlags );
190 
201  bool Scale(
202  const Size& rNewSize,
203  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
204 
218  bool Scale(
219  const double& rScaleX,
220  const double& rScaleY,
221  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
222 
236  bool Rotate(
237  Degree10 nAngle10,
238  const Color& rFillColor );
239 
248  void Replace(
249  const Color& rSearchColor,
250  const Color& rReplaceColor );
251 
265  void Replace(
266  const Color& rSearchColor,
267  const Color& rReplaceColor,
268  sal_uInt8 nTolerance );
269 
286  void Replace(
287  const Color* pSearchColors,
288  const Color* pReplaceColors,
289  sal_uLong nColorCount );
290 
309  void Replace(
310  const Color* pSearchColors,
311  const Color* pReplaceColors,
312  sal_uLong nColorCount,
313  sal_uInt8 const * pTols );
314 
317  void ReplaceTransparency( const Color& rColor );
318 
320  tools::Polygon GetContour( bool bContourEdgeDetect, const tools::Rectangle* pWorkRect );
321 
352  bool Adjust(
353  short nLuminancePercent,
354  short nContrastPercent,
355  short nChannelRPercent,
356  short nChannelGPercent,
357  short nChannelBPercent,
358  double fGamma = 1.0,
359  bool bInvert = false,
360  bool msoBrightness = false );
361 
373  sal_uInt8 GetTransparency(
374  sal_Int32 nX,
375  sal_Int32 nY) const;
376 
385  ::Color GetPixelColor(
386  sal_Int32 nX,
387  sal_Int32 nY) const;
388 
401  [[nodiscard]]
402  BitmapEx TransformBitmapEx(
403  double fWidth,
404  double fHeight,
405  const basegfx::B2DHomMatrix& rTransformation) const;
406 
425  [[nodiscard]]
426  BitmapEx getTransformed(
427  const basegfx::B2DHomMatrix& rTransformation,
428  const basegfx::B2DRange& rVisibleRange,
429  double fMaximumArea) const;
430 
436  [[nodiscard]]
437  BitmapEx ModifyBitmapEx( const basegfx::BColorModifierStack& rBColorModifierStack) const;
438 
439  [[nodiscard]]
440  static BitmapEx AutoScaleBitmap( BitmapEx const & aBitmap, const tools::Long aStandardSize );
441 
443  bool Create(
444  const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
445  const Size &rSize );
446 
447  void setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
448 
449  void AdjustTransparency( sal_uInt8 cTrans );
450 
451  void CombineMaskOr(Color maskColor, sal_uInt8 nTol);
452 
456  void GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
457  sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex,
458  sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount);
459 
460  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetBitmapSalBitmap() const { return maBitmap.ImplGetSalBitmap(); }
461  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetMaskSalBitmap() const { return maMask.ImplGetSalBitmap(); }
462 
463 
464 private:
465  friend class ImpGraphic;
466  friend class OutputDevice;
467  friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
468  friend bool VCL_DLLPUBLIC ReadRawDIB(BitmapEx& rTarget, const unsigned char* pBuf,
469  const ScanlineFormat nFormat,
470  const int nHeight,
471  const int nStride);
472 
473  void loadFromIconTheme( const OUString& rIconName );
474 
480  bool mbAlpha;
481 
482 };
483 
484 
499  const Size& rSize,
500  sal_uInt8 nAlpha,
501  Color aColorTopLeft,
502  Color aColorBottomRight);
503 
504 
518  const Size& rSize,
519  sal_uInt8 nAlpha,
520  Color aColorTopLeft,
521  Color aColorTopRight,
522  Color aColorBottomRight,
523  Color aColorBottomLeft);
524 
525 #endif // INCLUDED_VCL_BITMAPEX_HXX
526 
527 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BitmapEx & operator=(const Bitmap &rBitmap)
Definition: bitmapex.hxx:59
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
Bitmap maMask
Definition: bitmapex.hxx:476
const MapMode & GetPrefMapMode() const
Definition: bitmapex.hxx:90
signed char sal_Int8
TransparentType
Definition: bitmapex.hxx:37
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uIntPtr sal_uLong
long Long
void SetPrefMapMode(const MapMode &rPrefMapMode)
Definition: bitmapex.hxx:91
Reference
Size maBitmapSize
Definition: bitmapex.hxx:477
ScanlineFormat
Definition: Scanline.hxx:28
bool mbAlpha
Definition: bitmapex.hxx:480
const Size & GetPrefSize() const
Definition: bitmapex.hxx:87
bool operator!=(const BitmapEx &rBitmapEx) const
Definition: bitmapex.hxx:61
bool operator!() const
Definition: bitmapex.hxx:62
Point Rotate(const Point &rPoint, Degree10 nOrientation, const Point &rOrigin)
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:206
Bitmap maBitmap
Definition: bitmapex.hxx:475
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:302
TransparentType GetTransparentType() const
Definition: bitmapex.hxx:74
BmpMirrorFlags
Definition: bitmap.hxx:37
BmpScaleFlag
Definition: bitmap.hxx:49
BmpConversion
Definition: bitmap.hxx:66
short nBitCount
sal_uInt16 GetBitCount() const
Definition: bitmapex.hxx:95
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetMaskSalBitmap() const
Definition: bitmapex.hxx:461
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetBitmapSalBitmap() const
Definition: bitmapex.hxx:460
#define SAL_WARN_UNUSED
const Color & GetTransparentColor() const
Definition: bitmapex.hxx:93
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:1165
void SetPrefSize(const Size &rPrefSize)
Definition: bitmapex.hxx:88
TransparentType meTransparent
Definition: bitmapex.hxx:479
const Size & GetSizePixel() const
Definition: bitmapex.hxx:84
Color maTransparentColor
Definition: bitmapex.hxx:478
bool ReadRawDIB(BitmapEx &rTarget, const unsigned char *pBuf, const ScanlineFormat nFormat, const int nHeight, const int nStride)
Definition: dibtools.cxx:1841