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 = 0,
40  // Color = 1, Never actually used in BitmapEx, only present for backwards compat with existing SVM files
41  Bitmap = 2
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, vcl::PixelFormat ePixelFormat);
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 
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 
93  {
94  return maBitmap.getPixelFormat();
95  }
96 
97  sal_uLong GetSizeBytes() const;
98  BitmapChecksum GetChecksum() const;
99 
107  bool Convert( BmpConversion eConversion );
108 
123  bool Crop( const tools::Rectangle& rRectPixel );
124 
136  void Expand(
137  sal_uLong nDX, sal_uLong nDY,
138  bool bExpandTransparent = false );
139 
162  bool CopyPixel(
163  const tools::Rectangle& rRectDst,
164  const tools::Rectangle& rRectSrc,
165  const BitmapEx* pBmpExSrc );
166 
175  bool Erase( const Color& rFillColor );
176 
181  bool Invert();
182 
190  bool Mirror( BmpMirrorFlags nMirrorFlags );
191 
202  bool Scale(
203  const Size& rNewSize,
204  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
205 
219  bool Scale(
220  const double& rScaleX,
221  const double& rScaleY,
222  BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
223 
237  bool Rotate(
238  Degree10 nAngle10,
239  const Color& rFillColor );
240 
249  void Replace(
250  const Color& rSearchColor,
251  const Color& rReplaceColor );
252 
266  void Replace(
267  const Color& rSearchColor,
268  const Color& rReplaceColor,
269  sal_uInt8 nTolerance );
270 
287  void Replace(
288  const Color* pSearchColors,
289  const Color* pReplaceColors,
290  size_t nColorCount );
291 
310  void Replace(
311  const Color* pSearchColors,
312  const Color* pReplaceColors,
313  size_t nColorCount,
314  sal_uInt8 const * pTols );
315 
318  void ReplaceTransparency( const Color& rColor );
319 
321  tools::Polygon GetContour( bool bContourEdgeDetect, const tools::Rectangle* pWorkRect );
322 
353  bool Adjust(
354  short nLuminancePercent,
355  short nContrastPercent,
356  short nChannelRPercent,
357  short nChannelGPercent,
358  short nChannelBPercent,
359  double fGamma = 1.0,
360  bool bInvert = false,
361  bool msoBrightness = false );
362 
374  sal_uInt8 GetAlpha(
375  sal_Int32 nX,
376  sal_Int32 nY) const;
377 
386  ::Color GetPixelColor(
387  sal_Int32 nX,
388  sal_Int32 nY) const;
389 
402  [[nodiscard]]
403  BitmapEx TransformBitmapEx(
404  double fWidth,
405  double fHeight,
406  const basegfx::B2DHomMatrix& rTransformation) const;
407 
426  [[nodiscard]]
427  BitmapEx getTransformed(
428  const basegfx::B2DHomMatrix& rTransformation,
429  const basegfx::B2DRange& rVisibleRange,
430  double fMaximumArea) const;
431 
437  [[nodiscard]]
438  BitmapEx ModifyBitmapEx( const basegfx::BColorModifierStack& rBColorModifierStack) const;
439 
440  [[nodiscard]]
441  static BitmapEx AutoScaleBitmap( BitmapEx const & aBitmap, const tools::Long aStandardSize );
442 
444  bool Create(
445  const css::uno::Reference< css::rendering::XBitmapCanvas > &xBitmapCanvas,
446  const Size &rSize );
447 
448  void setAlphaFrom( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo );
449 
450  void AdjustTransparency( sal_uInt8 cTrans );
451 
452  void CombineMaskOr(Color maskColor, sal_uInt8 nTol);
453 
457  void GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
458  sal_uInt32& rnRedMask, sal_uInt32& rnGreenMask, sal_uInt32& rnBlueMask, sal_uInt32& rnAlphaMask, sal_uInt32& rnTransparencyIndex,
459  sal_uInt32& rnWidth, sal_uInt32& rnHeight, sal_uInt8& rnBitCount);
460 
461  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetBitmapSalBitmap() const { return maBitmap.ImplGetSalBitmap(); }
462  SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetMaskSalBitmap() const { return maMask.ImplGetSalBitmap(); }
463 
464 
465 private:
466  friend class ImpGraphic;
467  friend class OutputDevice;
468  friend bool VCL_DLLPUBLIC WriteDIBBitmapEx(const BitmapEx& rSource, SvStream& rOStm);
469  friend bool VCL_DLLPUBLIC ReadRawDIB(BitmapEx& rTarget, const unsigned char* pBuf,
470  const ScanlineFormat nFormat,
471  const int nHeight,
472  const int nStride);
473 
474  void loadFromIconTheme( const OUString& rIconName );
475 
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: */
PixelFormat
Pixel format of the bitmap in bits per pixel.
Definition: BitmapTypes.hxx:19
BitmapEx & operator=(const Bitmap &rBitmap)
Definition: bitmapex.hxx:59
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
Bitmap maMask
Definition: bitmapex.hxx:477
const MapMode & GetPrefMapMode() const
Definition: bitmapex.hxx:89
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:90
Reference
Size maBitmapSize
Definition: bitmapex.hxx:478
ScanlineFormat
Definition: Scanline.hxx:29
bool mbAlpha
Definition: bitmapex.hxx:480
const Size & GetPrefSize() const
Definition: bitmapex.hxx:86
bool operator!=(const BitmapEx &rBitmapEx) const
Definition: bitmapex.hxx:61
Point Rotate(const Point &rPoint, Degree10 nOrientation, const Point &rOrigin)
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:204
Bitmap maBitmap
Definition: bitmapex.hxx:476
bool WriteDIBBitmapEx(const BitmapEx &rSource, SvStream &rOStm)
Definition: dibtools.cxx:1840
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:303
TransparentType GetTransparentType() const
Definition: bitmapex.hxx:73
BmpMirrorFlags
Definition: bitmap.hxx:42
BmpScaleFlag
Definition: bitmap.hxx:54
BmpConversion
Definition: bitmap.hxx:71
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetMaskSalBitmap() const
Definition: bitmapex.hxx:462
SAL_DLLPRIVATE std::shared_ptr< SalBitmap > const & ImplGetBitmapSalBitmap() const
Definition: bitmapex.hxx:461
#define SAL_WARN_UNUSED
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:1131
void SetPrefSize(const Size &rPrefSize)
Definition: bitmapex.hxx:87
TransparentType meTransparent
Definition: bitmapex.hxx:479
const Size & GetSizePixel() const
Definition: bitmapex.hxx:83
vcl::PixelFormat getPixelFormat() const
Definition: bitmapex.hxx:92
bool ReadRawDIB(BitmapEx &rTarget, const unsigned char *pBuf, const ScanlineFormat nFormat, const int nHeight, const int nStride)
Definition: dibtools.cxx:1807