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  N1BitMatrix, // aka Dithered, used in export to bitmap
70  N4BitGreys,
72  N8BitGreys,
74  N24Bit,
75  N32Bit,
76  N8BitTrans,
77  Ghosted
78 };
79 
80 enum class BmpCombine
81 {
82  Or, And
83 };
84 
85 class BitmapInfoAccess;
86 class BitmapReadAccess;
87 class BitmapWriteAccess;
88 class BitmapPalette;
89 class GDIMetaFile;
90 class AlphaMask;
91 class OutputDevice;
92 class SalBitmap;
93 
95 {
96  #if defined(_WIN32)
97  void* pDIB; // device independent byte buffer
98  #elif defined( MACOSX ) || defined( IOS )
99  // Nothing needed, apparently
100  #else
101  void* aPixmap;
102  #endif
103  int mnWidth;
104  int mnHeight;
105 };
106 
108 {
109 public:
110 
111  Bitmap();
112  Bitmap( const Bitmap& rBitmap );
113  Bitmap( const Size& rSizePixel, sal_uInt16 nBitCount, const BitmapPalette* pPal = nullptr );
114  explicit Bitmap( std::shared_ptr<SalBitmap> const & xSalBitmap );
115  virtual ~Bitmap();
116 
117  Bitmap& operator=( const Bitmap& rBitmap );
118  Bitmap& operator=( Bitmap&& rBitmap ) noexcept;
119  inline bool operator!() const;
120  bool operator==( const Bitmap& rBitmap ) const;
121  bool operator!=( const Bitmap& rBitmap ) const { return !operator==(rBitmap); }
122 
123  inline bool IsEmpty() const;
124  void SetEmpty();
125 
126  inline const MapMode& GetPrefMapMode() const;
127  inline void SetPrefMapMode( const MapMode& rMapMode );
128 
129  inline const Size& GetPrefSize() const;
130  inline void SetPrefSize( const Size& rSize );
131 
132  Size GetSizePixel() const;
133 
134  sal_uInt16 GetBitCount() const;
135  inline sal_Int64 GetColorCount() const;
136  inline sal_uLong GetSizeBytes() const;
137  bool HasGreyPalette() 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  SAL_DLLPRIVATE bool ImplConvertGhosted();
540 
541 private:
542  std::shared_ptr<SalBitmap> mxSalBmp;
545 
546 };
547 
548 inline bool Bitmap::operator!() const
549 {
550  return( mxSalBmp == nullptr );
551 }
552 
553 inline bool Bitmap::IsEmpty() const
554 {
555  return( mxSalBmp == nullptr );
556 }
557 
558 inline const MapMode& Bitmap::GetPrefMapMode() const
559 {
560  return maPrefMapMode;
561 }
562 
563 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
564 {
565  maPrefMapMode = rMapMode;
566 }
567 
568 inline const Size& Bitmap::GetPrefSize() const
569 {
570  return maPrefSize;
571 }
572 
573 inline void Bitmap::SetPrefSize( const Size& rSize )
574 {
575  maPrefSize = rSize;
576 }
577 
578 inline sal_Int64 Bitmap::GetColorCount() const
579 {
580  return sal_Int64(1) << sal_Int64(GetBitCount());
581 }
582 
584 {
585  const Size aSizePix( GetSizePixel() );
586  return( ( static_cast<sal_uLong>(aSizePix.Width()) * aSizePix.Height() * GetBitCount() ) >> 3 );
587 }
588 
589 #endif // INCLUDED_VCL_BITMAP_HXX
590 
591 /* 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:578
sal_uIntPtr sal_uLong
Size maPrefSize
Definition: bitmap.hxx:544
Size GetSizePixel() const
const Size & GetPrefSize() const
Definition: bitmap.hxx:568
bool operator!=(const Bitmap &rBitmap) const
Definition: bitmap.hxx:121
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:558
void SetPrefMapMode(const MapMode &rMapMode)
Definition: bitmap.hxx:563
void * aPixmap
Definition: bitmap.hxx:101
sal_uLong GetSizeBytes() const
Definition: bitmap.hxx:583
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:548
BmpMirrorFlags
Definition: bitmap.hxx:36
void SetPrefSize(const Size &rSize)
Definition: bitmap.hxx:573
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:553
sal_uInt16 GetBitCount() const
MapMode maPrefMapMode
Definition: bitmap.hxx:543
std::shared_ptr< SalBitmap > mxSalBmp
Definition: bitmap.hxx:542
BmpCombine
Definition: bitmap.hxx:80
Point Rotate(const Point &rPoint, short nOrientation, const Point &rOrigin)
vcl::ScopedBitmapAccess< BitmapInfoAccess, Bitmap,&Bitmap::AcquireInfoAccess > ScopedInfoAccess
Definition: bitmap.hxx:533