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  N32Bit,
75  N8BitTrans,
76  N8BitNoConversion // make 8bit without color conversion (e.g. take the red channel)
77 };
78 
79 enum class BmpCombine
80 {
81  Or, And
82 };
83 
84 class BitmapInfoAccess;
85 class BitmapReadAccess;
86 class BitmapWriteAccess;
87 class BitmapPalette;
88 class GDIMetaFile;
89 class AlphaMask;
90 class OutputDevice;
91 class SalBitmap;
92 
94 {
95  #if defined(_WIN32)
96  void* pDIB; // device independent byte buffer
97  #elif defined( MACOSX ) || defined( IOS )
98  // Nothing needed, apparently
99  #else
100  void* aPixmap;
101  #endif
102  int mnWidth;
103  int mnHeight;
104 };
105 
107 {
108 public:
109 
110  Bitmap();
111  Bitmap( const Bitmap& rBitmap );
112  Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = nullptr );
113  explicit Bitmap( std::shared_ptr<SalBitmap> const & xSalBitmap );
114  virtual ~Bitmap();
115 
116  Bitmap& operator=( const Bitmap& rBitmap );
117  Bitmap& operator=( Bitmap&& rBitmap ) noexcept;
118  inline bool operator!() const;
119  bool operator==( const Bitmap& rBitmap ) const;
120  bool operator!=( const Bitmap& rBitmap ) const { return !operator==(rBitmap); }
121 
122  inline bool IsEmpty() const;
123  void SetEmpty();
124 
125  inline const MapMode& GetPrefMapMode() const;
126  inline void SetPrefMapMode( const MapMode& rMapMode );
127 
128  inline const Size& GetPrefSize() const;
129  inline void SetPrefSize( const Size& rSize );
130 
131  Size GetSizePixel() const;
132 
133  sal_uInt16 GetBitCount() const;
134  inline sal_Int64 GetColorCount() const;
135  inline sal_uLong GetSizeBytes() const;
136  bool HasGreyPalette8Bit() const;
137  bool HasGreyPaletteAny() const;
145  bool GetSystemData( BitmapSystemData& rData ) const;
146 
147  BitmapChecksum GetChecksum() const;
148 
149  Bitmap CreateDisplayBitmap( OutputDevice* pDisplay ) const;
150 
151  static const BitmapPalette&
152  GetGreyPalette( int nEntries );
153 
154 public:
155 
163  bool Convert( BmpConversion eConversion );
164 
172  bool Dither();
173 
188  bool Crop( const tools::Rectangle& rRectPixel );
189 
205  bool Expand(
206  sal_uLong nDX, sal_uLong nDY,
207  const Color* pInitColor = nullptr );
208 
231  bool CopyPixel(
232  const tools::Rectangle& rRectDst,
233  const tools::Rectangle& rRectSrc,
234  const Bitmap* pBmpSrc = nullptr );
235 
236  bool CopyPixel_AlphaOptimized(
237  const tools::Rectangle& rRectDst,
238  const tools::Rectangle& rRectSrc,
239  const Bitmap* pBmpSrc );
240 
251  bool CombineSimple(
252  const Bitmap& rMask,
253  BmpCombine eCombine );
254 
271  bool Blend(
272  const AlphaMask& rAlpha,
273  const Color& rBackgroundColor );
274 
282  bool Erase( const Color& rFillColor );
283 
288  bool Invert();
289 
297  bool Mirror( BmpMirrorFlags nMirrorFlags );
298 
309  bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
310 
324  bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
325 
333  static bool HasFastScale();
334 
335  // Adapt the BitCount of rNew to BitCount of total, including grey or color palette
336  // Can be used to create alpha/mask bitmaps after their processing in 24bit
337  void AdaptBitCount(Bitmap& rNew) const;
338 
352  bool Rotate( long nAngle10, const Color& rFillColor );
353 
370  Bitmap CreateMask( const Color& rTransColor, sal_uInt8 nTol = 0 ) const;
371 
383  vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const;
384 
395  bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
396 
407  bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
408 
424  bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 );
425 
444  bool Replace(
445  const Color* pSearchColors,
446  const Color* rReplaceColors,
447  sal_uLong nColorCount,
448  sal_uInt8 const * pTols );
449 
465  void Vectorize(
466  GDIMetaFile& rMtf,
467  sal_uInt8 cReduce,
468  const Link<long,void>* pProgress );
469 
500  bool Adjust(
501  short nLuminancePercent,
502  short nContrastPercent = 0,
503  short nChannelRPercent = 0,
504  short nChannelGPercent = 0,
505  short nChannelBPercent = 0,
506  double fGamma = 1.0,
507  bool bInvert = false,
508  bool msoBrightness = false );
509 
510 public:
517  SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap);
518 
519  SAL_DLLPRIVATE void ImplMakeUnique();
520  const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
521  SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
522 
523  SAL_DLLPRIVATE bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
524 
525 public:
526 
527  BitmapInfoAccess* AcquireInfoAccess();
528  BitmapReadAccess* AcquireReadAccess();
529  BitmapWriteAccess* AcquireWriteAccess();
530  static void ReleaseAccess( BitmapInfoAccess* pAccess );
531 
534 
535 private:
536  SAL_DLLPRIVATE bool ImplConvertUp(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
537  SAL_DLLPRIVATE bool ImplConvertDown(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
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:520
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:120
vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap,&Bitmap::AcquireReadAccess > ScopedReadAccess
Definition: bitmap.hxx:532
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:206
const MapMode & GetPrefMapMode() const
Definition: bitmap.hxx:556
void SetPrefMapMode(const MapMode &rMapMode)
Definition: bitmap.hxx:561
void * aPixmap
Definition: bitmap.hxx:100
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:302
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
short nBitCount
#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:79
Point Rotate(const Point &rPoint, short nOrientation, const Point &rOrigin)
vcl::ScopedBitmapAccess< BitmapInfoAccess, Bitmap,&Bitmap::AcquireInfoAccess > ScopedInfoAccess
Definition: bitmap.hxx:533