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::sun::star::rendering {
31  class XBitmapCanvas;
32 }
33 namespace com::sun::star::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( Color aTransparentReplaceColor ) const;
77  const Bitmap& GetBitmap() 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 
105  bool Convert( BmpConversion eConversion );
106 
121  bool Crop( const tools::Rectangle& rRectPixel );
122 
134  void Expand(
135  sal_uLong nDX, sal_uLong nDY,
136  bool bExpandTransparent = false );
137 
160  bool CopyPixel(
161  const tools::Rectangle& rRectDst,
162  const tools::Rectangle& rRectSrc,
163  const BitmapEx* pBmpExSrc );
164 
173  bool Erase( const Color& rFillColor );
174 
179  bool Invert();
180 
188  bool Mirror( BmpMirrorFlags nMirrorFlags );
189 
200  bool Scale(
201  const Size& rNewSize,
202  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
203 
217  bool Scale(
218  const double& rScaleX,
219  const double& rScaleY,
220  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
221 
235  bool Rotate(
236  long nAngle10,
237  const Color& rFillColor );
238 
247  void Replace(
248  const Color& rSearchColor,
249  const Color& rReplaceColor );
250 
264  void Replace(
265  const Color& rSearchColor,
266  const Color& rReplaceColor,
267  sal_uInt8 nTolerance );
268 
285  void Replace(
286  const Color* pSearchColors,
287  const Color* pReplaceColors,
288  sal_uLong nColorCount );
289 
308  void Replace(
309  const Color* pSearchColors,
310  const Color* pReplaceColors,
311  sal_uLong nColorCount,
312  sal_uInt8 const * pTols );
313 
316  void ReplaceTransparency( const Color& rColor );
317 
319  tools::Polygon GetContour( bool bContourEdgeDetect, const tools::Rectangle* pWorkRect );
320 
351  bool Adjust(
352  short nLuminancePercent,
353  short nContrastPercent,
354  short nChannelRPercent,
355  short nChannelGPercent,
356  short nChannelBPercent,
357  double fGamma = 1.0,
358  bool bInvert = false,
359  bool msoBrightness = false );
360 
372  sal_uInt8 GetTransparency(
373  sal_Int32 nX,
374  sal_Int32 nY) const;
375 
384  ::Color GetPixelColor(
385  sal_Int32 nX,
386  sal_Int32 nY) const;
387 
400  [[nodiscard]]
401  BitmapEx TransformBitmapEx(
402  double fWidth,
403  double fHeight,
404  const basegfx::B2DHomMatrix& rTransformation) const;
405 
424  [[nodiscard]]
425  BitmapEx getTransformed(
426  const basegfx::B2DHomMatrix& rTransformation,
427  const basegfx::B2DRange& rVisibleRange,
428  double fMaximumArea) const;
429 
435  [[nodiscard]]
436  BitmapEx ModifyBitmapEx( const basegfx::BColorModifierStack& rBColorModifierStack) const;
437 
438  [[nodiscard]]
439  static BitmapEx AutoScaleBitmap( BitmapEx const & aBitmap, const long aStandardSize );
440 
442  bool Create(
443  const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
444  const Size &rSize );
445 
446  void setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
447 
448  void AdjustTransparency( sal_uInt8 cTrans );
449 
450  void CombineMaskOr(Color maskColor, sal_uInt8 nTol);
451 
455  void GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
456  sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex,
457  sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount);
458 
459  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetBitmapSalBitmap() const { return maBitmap.ImplGetSalBitmap(); }
460  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetMaskSalBitmap() const { return maMask.ImplGetSalBitmap(); }
461 
462 
463 private:
464  friend class ImpGraphic;
465  friend class OutputDevice;
466  friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
467  friend bool VCL_DLLPUBLIC ReadRawDIB(BitmapEx& rTarget, const unsigned char* pBuf,
468  const ScanlineFormat nFormat,
469  const int nHeight,
470  const int nStride);
471 
472  void loadFromIconTheme( const OUString& rIconName );
473 
479  bool mbAlpha;
480 
481 };
482 
483 
498  const Size& rSize,
499  sal_uInt8 nAlpha,
500  Color aColorTopLeft,
501  Color aColorBottomRight);
502 
503 
517  const Size& rSize,
518  sal_uInt8 nAlpha,
519  Color aColorTopLeft,
520  Color aColorTopRight,
521  Color aColorBottomRight,
522  Color aColorBottomLeft);
523 
524 #endif // INCLUDED_VCL_BITMAPEX_HXX
525 
526 /* 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:475
const MapMode & GetPrefMapMode() const
Definition: bitmapex.hxx:89
signed char sal_Int8
TransparentType
Definition: bitmapex.hxx:36
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
#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:476
ScanlineFormat
Definition: Scanline.hxx:28
bool mbAlpha
Definition: bitmapex.hxx:479
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:206
Bitmap maBitmap
Definition: bitmapex.hxx:474
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:73
BmpMirrorFlags
Definition: bitmap.hxx:36
BmpScaleFlag
Definition: bitmap.hxx:48
BmpConversion
Definition: bitmap.hxx:65
short nBitCount
sal_uInt16 GetBitCount() const
Definition: bitmapex.hxx:94
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetMaskSalBitmap() const
Definition: bitmapex.hxx:460
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetBitmapSalBitmap() const
Definition: bitmapex.hxx:459
#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:1166
void SetPrefSize(const Size &rPrefSize)
Definition: bitmapex.hxx:87
TransparentType meTransparent
Definition: bitmapex.hxx:478
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
Color maTransparentColor
Definition: bitmapex.hxx:477
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)