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  Ghosted
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 HasGreyPalette() const;
144  bool GetSystemData( BitmapSystemData& rData ) const;
145 
146  BitmapChecksum GetChecksum() const;
147 
148  Bitmap CreateDisplayBitmap( OutputDevice* pDisplay ) const;
149 
150  static const BitmapPalette&
151  GetGreyPalette( int nEntries );
152 
153 public:
154 
162  bool Convert( BmpConversion eConversion );
163 
171  bool Dither();
172 
187  bool Crop( const tools::Rectangle& rRectPixel );
188 
204  bool Expand(
205  sal_uLong nDX, sal_uLong nDY,
206  const Color* pInitColor = nullptr );
207 
230  bool CopyPixel(
231  const tools::Rectangle& rRectDst,
232  const tools::Rectangle& rRectSrc,
233  const Bitmap* pBmpSrc = nullptr );
234 
235  bool CopyPixel_AlphaOptimized(
236  const tools::Rectangle& rRectDst,
237  const tools::Rectangle& rRectSrc,
238  const Bitmap* pBmpSrc );
239 
250  bool CombineSimple(
251  const Bitmap& rMask,
252  BmpCombine eCombine );
253 
270  bool Blend(
271  const AlphaMask& rAlpha,
272  const Color& rBackgroundColor );
273 
281  bool Erase( const Color& rFillColor );
282 
287  bool Invert();
288 
296  bool Mirror( BmpMirrorFlags nMirrorFlags );
297 
308  bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
309 
323  bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
324 
332  static bool HasFastScale();
333 
334  // Adapt the BitCount of rNew to BitCount of total, including grey or color palette
335  // Can be used to create alpha/mask bitmaps after their processing in 24bit
336  void AdaptBitCount(Bitmap& rNew) const;
337 
351  bool Rotate( long nAngle10, const Color& rFillColor );
352 
369  Bitmap CreateMask( const Color& rTransColor, sal_uInt8 nTol = 0 ) const;
370 
382  vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const;
383 
394  bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
395 
406  bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
407 
423  bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 );
424 
443  bool Replace(
444  const Color* pSearchColors,
445  const Color* rReplaceColors,
446  sal_uLong nColorCount,
447  sal_uInt8 const * pTols );
448 
464  void Vectorize(
465  GDIMetaFile& rMtf,
466  sal_uInt8 cReduce,
467  const Link<long,void>* pProgress );
468 
499  bool Adjust(
500  short nLuminancePercent,
501  short nContrastPercent = 0,
502  short nChannelRPercent = 0,
503  short nChannelGPercent = 0,
504  short nChannelBPercent = 0,
505  double fGamma = 1.0,
506  bool bInvert = false,
507  bool msoBrightness = false );
508 
509 public:
516  SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap);
517 
518  SAL_DLLPRIVATE void ImplMakeUnique();
519  const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
520  SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
521 
522  SAL_DLLPRIVATE bool ImplMakeGreyscales( sal_uInt16 nGreyscales );
523 
524 public:
525 
526  BitmapInfoAccess* AcquireInfoAccess();
527  BitmapReadAccess* AcquireReadAccess();
528  BitmapWriteAccess* AcquireWriteAccess();
529  static void ReleaseAccess( BitmapInfoAccess* pAccess );
530 
533 
534 private:
535  SAL_DLLPRIVATE bool ImplConvertUp(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
536  SAL_DLLPRIVATE bool ImplConvertDown(sal_uInt16 nBitCount, Color const* pExtColor = nullptr);
537 
538  SAL_DLLPRIVATE bool ImplConvertGhosted();
539 
540 private:
541  std::shared_ptr<SalBitmap> mxSalBmp;
544 
545 };
546 
547 inline bool Bitmap::operator!() const
548 {
549  return( mxSalBmp == nullptr );
550 }
551 
552 inline bool Bitmap::IsEmpty() const
553 {
554  return( mxSalBmp == nullptr );
555 }
556 
557 inline const MapMode& Bitmap::GetPrefMapMode() const
558 {
559  return maPrefMapMode;
560 }
561 
562 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
563 {
564  maPrefMapMode = rMapMode;
565 }
566 
567 inline const Size& Bitmap::GetPrefSize() const
568 {
569  return maPrefSize;
570 }
571 
572 inline void Bitmap::SetPrefSize( const Size& rSize )
573 {
574  maPrefSize = rSize;
575 }
576 
577 inline sal_Int64 Bitmap::GetColorCount() const
578 {
579  return sal_Int64(1) << sal_Int64(GetBitCount());
580 }
581 
583 {
584  const Size aSizePix( GetSizePixel() );
585  return( ( static_cast<sal_uLong>(aSizePix.Width()) * aSizePix.Height() * GetBitCount() ) >> 3 );
586 }
587 
588 #endif // INCLUDED_VCL_BITMAP_HXX
589 
590 /* 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:519
sal_Int64 GetColorCount() const
Definition: bitmap.hxx:577
sal_uIntPtr sal_uLong
Size maPrefSize
Definition: bitmap.hxx:543
Size GetSizePixel() const
const Size & GetPrefSize() const
Definition: bitmap.hxx:567
bool operator!=(const Bitmap &rBitmap) const
Definition: bitmap.hxx:120
vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap,&Bitmap::AcquireReadAccess > ScopedReadAccess
Definition: bitmap.hxx:531
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:203
const MapMode & GetPrefMapMode() const
Definition: bitmap.hxx:557
void SetPrefMapMode(const MapMode &rMapMode)
Definition: bitmap.hxx:562
void * aPixmap
Definition: bitmap.hxx:100
sal_uLong GetSizeBytes() const
Definition: bitmap.hxx:582
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:547
BmpMirrorFlags
Definition: bitmap.hxx:36
void SetPrefSize(const Size &rSize)
Definition: bitmap.hxx:572
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:552
sal_uInt16 GetBitCount() const
MapMode maPrefMapMode
Definition: bitmap.hxx:542
std::shared_ptr< SalBitmap > mxSalBmp
Definition: bitmap.hxx:541
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:532