LibreOffice Module vcl (master)  1
bitmap.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_BITMAP_HXX
21 #define INCLUDED_VCL_BITMAP_HXX
22 
23 #include <tools/solar.h>
24 #include <vcl/checksum.hxx>
25 #include <vcl/dllapi.h>
26 #include <vcl/mapmod.hxx>
27 #include <vcl/region.hxx>
29 #include <o3tl/typed_flags_set.hxx>
30 #include <memory>
31 
32 class Color;
33 
34 template <typename Arg, typename Ret> class Link;
35 
36 enum class BmpMirrorFlags
37 {
38  NONE = 0x00,
39  Horizontal = 0x01,
40  Vertical = 0x02,
41 };
42 
43 namespace o3tl
44 {
45  template<> struct typed_flags<BmpMirrorFlags> : is_typed_flags<BmpMirrorFlags, 0x03> {};
46 }
47 
48 enum class BmpScaleFlag
49 {
50 // Try to preferably use these.
51  Default,
52  Fast,
54 // Specific algorithms, use only if you really need to (mainly used for tests)
56  Interpolate, // fast, integer bilinear
57  Lanczos,
58  BiCubic,
59  BiLinear,
60  Super // bilinear interpolation when supersampling and averaging when subsampling under certain scale
61 };
62 
63 #define BMP_COL_TRANS Color( 252, 3, 251 )
64 
65 enum class BmpConversion
66 {
67  NNONE,
69  N4BitGreys,
71  N8BitGreys,
73  N24Bit,
74  N8BitTrans,
75  Ghosted
76 };
77 
78 enum class BmpCombine
79 {
80  Or, And
81 };
82 
83 class BitmapInfoAccess;
84 class BitmapReadAccess;
85 class BitmapWriteAccess;
86 class BitmapPalette;
87 class GDIMetaFile;
88 class AlphaMask;
89 class OutputDevice;
90 class SalBitmap;
91 
93 {
94  #if defined(_WIN32)
95  void* pDIB; // device independent byte buffer
96  #elif defined( MACOSX ) || defined( IOS )
97  // Nothing needed, apparently
98  #else
99  void* aPixmap;
100  #endif
101  int mnWidth;
102  int mnHeight;
103 };
104 
106 {
107 public:
108 
109  Bitmap();
110  Bitmap( const Bitmap& rBitmap );
111  Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = nullptr );
112  explicit Bitmap( std::shared_ptr<SalBitmap> const & xSalBitmap );
113  virtual ~Bitmap();
114 
115  Bitmap& operator=( const Bitmap& rBitmap );
116  Bitmap& operator=( Bitmap&& rBitmap ) noexcept;
117  inline bool operator!() const;
118  bool operator==( const Bitmap& rBitmap ) const;
119  bool operator!=( const Bitmap& rBitmap ) const { return !operator==(rBitmap); }
120 
121  inline bool IsEmpty() const;
122  void SetEmpty();
123 
124  inline const MapMode& GetPrefMapMode() const;
125  inline void SetPrefMapMode( const MapMode& rMapMode );
126 
127  inline const Size& GetPrefSize() const;
128  inline void SetPrefSize( const Size& rSize );
129 
130  Size GetSizePixel() const;
131 
132  sal_uInt16 GetBitCount() const;
133  inline sal_Int64 GetColorCount() const;
134  inline sal_uLong GetSizeBytes() const;
135  bool HasGreyPalette() const;
143  bool GetSystemData( BitmapSystemData& rData ) const;
144 
145  BitmapChecksum GetChecksum() const;
146 
147  Bitmap CreateDisplayBitmap( OutputDevice* pDisplay );
148 
149  static const BitmapPalette&
150  GetGreyPalette( int nEntries );
151 
152 public:
153 
161  bool Convert( BmpConversion eConversion );
162 
170  bool Dither();
171 
186  bool Crop( const tools::Rectangle& rRectPixel );
187 
203  bool Expand(
204  sal_uLong nDX, sal_uLong nDY,
205  const Color* pInitColor = nullptr );
206 
229  bool CopyPixel(
230  const tools::Rectangle& rRectDst,
231  const tools::Rectangle& rRectSrc,
232  const Bitmap* pBmpSrc = nullptr );
233 
234  bool CopyPixel_AlphaOptimized(
235  const tools::Rectangle& rRectDst,
236  const tools::Rectangle& rRectSrc,
237  const Bitmap* pBmpSrc );
238 
249  bool CombineSimple(
250  const Bitmap& rMask,
251  BmpCombine eCombine );
252 
269  bool Blend(
270  const AlphaMask& rAlpha,
271  const Color& rBackgroundColor );
272 
280  bool Erase( const Color& rFillColor );
281 
286  bool Invert();
287 
295  bool Mirror( BmpMirrorFlags nMirrorFlags );
296 
307  bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
308 
322  bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
323 
331  static bool HasFastScale();
332 
333  // Adapt the BitCount of rNew to BitCount of total, including grey or color palette
334  // Can be used to create alpha/mask bitmaps after their processing in 24bit
335  void AdaptBitCount(Bitmap& rNew) const;
336 
350  bool Rotate( long nAngle10, const Color& rFillColor );
351 
368  Bitmap CreateMask( const Color& rTransColor, sal_uInt8 nTol = 0 ) const;
369 
381  vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const;
382 
393  bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
394 
405  bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
406 
422  bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 );
423 
442  bool Replace(
443  const Color* pSearchColors,
444  const Color* rReplaceColors,
445  sal_uLong nColorCount,
446  sal_uInt8 const * pTols );
447 
463  void Vectorize(
464  GDIMetaFile& rMtf,
465  sal_uInt8 cReduce,
466  const Link<long,void>* pProgress );
467 
498  bool Adjust(
499  short nLuminancePercent,
500  short nContrastPercent = 0,
501  short nChannelRPercent = 0,
502  short nChannelGPercent = 0,
503  short nChannelBPercent = 0,
504  double fGamma = 1.0,
505  bool bInvert = false,
506  bool msoBrightness = false );
507 
508 public:
515  SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap);
516 
517  SAL_DLLPRIVATE void ImplMakeUnique();
518  const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
519  SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
520 
521  SAL_DLLPRIVATE bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
522 
523 public:
524 
525  BitmapInfoAccess* AcquireInfoAccess();
526  BitmapReadAccess* AcquireReadAccess();
527  BitmapWriteAccess* AcquireWriteAccess();
528  static void ReleaseAccess( BitmapInfoAccess* pAccess );
529 
532 
533 private:
534  SAL_DLLPRIVATE bool ImplConvertUp(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
535  SAL_DLLPRIVATE bool ImplConvertDown(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
536 
537  SAL_DLLPRIVATE bool ImplConvertGhosted();
538 
539 private:
540  std::shared_ptr<SalBitmap> mxSalBmp;
543 
544 };
545 
546 inline bool Bitmap::operator!() const
547 {
548  return( mxSalBmp == nullptr );
549 }
550 
551 inline bool Bitmap::IsEmpty() const
552 {
553  return( mxSalBmp == nullptr );
554 }
555 
556 inline const MapMode& Bitmap::GetPrefMapMode() const
557 {
558  return maPrefMapMode;
559 }
560 
561 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
562 {
563  maPrefMapMode = rMapMode;
564 }
565 
566 inline const Size& Bitmap::GetPrefSize() const
567 {
568  return maPrefSize;
569 }
570 
571 inline void Bitmap::SetPrefSize( const Size& rSize )
572 {
573  maPrefSize = rSize;
574 }
575 
576 inline sal_Int64 Bitmap::GetColorCount() const
577 {
578  return sal_Int64(1) << sal_Int64(GetBitCount());
579 }
580 
582 {
583  const Size aSizePix( GetSizePixel() );
584  return( ( static_cast<sal_uLong>(aSizePix.Width()) * aSizePix.Height() * GetBitCount() ) >> 3 );
585 }
586 
587 #endif // INCLUDED_VCL_BITMAP_HXX
588 
589 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
long Height() const
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
Definition: bitmap.hxx:518
sal_Int64 GetColorCount() const
Definition: bitmap.hxx:576
sal_uIntPtr sal_uLong
Size maPrefSize
Definition: bitmap.hxx:542
Size GetSizePixel() const
const Size & GetPrefSize() const
Definition: bitmap.hxx:566
bool operator!=(const Bitmap &rBitmap) const
Definition: bitmap.hxx:119
vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap,&Bitmap::AcquireReadAccess > ScopedReadAccess
Definition: bitmap.hxx:530
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:203
const MapMode & GetPrefMapMode() const
Definition: bitmap.hxx:556
void SetPrefMapMode(const MapMode &rMapMode)
Definition: bitmap.hxx:561
void * aPixmap
Definition: bitmap.hxx:99
sal_uLong GetSizeBytes() const
Definition: bitmap.hxx:581
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
bool operator!() const
Definition: bitmap.hxx:546
BmpMirrorFlags
Definition: bitmap.hxx:36
void SetPrefSize(const Size &rSize)
Definition: bitmap.hxx:571
BmpScaleFlag
Definition: bitmap.hxx:48
BmpConversion
Definition: bitmap.hxx:65
#define SAL_WARN_UNUSED
unsigned char sal_uInt8
bool IsEmpty() const
Definition: bitmap.hxx:551
sal_uInt16 GetBitCount() const
MapMode maPrefMapMode
Definition: bitmap.hxx:541
std::shared_ptr< SalBitmap > mxSalBmp
Definition: bitmap.hxx:540
BmpCombine
Definition: bitmap.hxx:78
Point Rotate(const Point &rPoint, short nOrientation, const Point &rOrigin)
vcl::ScopedBitmapAccess< BitmapInfoAccess, Bitmap,&Bitmap::AcquireInfoAccess > ScopedInfoAccess
Definition: bitmap.hxx:531