LibreOffice Module vcl (master)  1
include/vcl/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/degree.hxx>
24 #include <vcl/checksum.hxx>
25 #include <vcl/dllapi.h>
26 #include <vcl/mapmod.hxx>
27 #include <vcl/region.hxx>
30 
31 #include <o3tl/typed_flags_set.hxx>
32 
33 #include <memory>
34 
35 #define GAMMA( _def_cVal, _def_InvGamma ) (static_cast<sal_uInt8>(MinMax(FRound(pow( _def_cVal/255.0,_def_InvGamma)*255.0),0,255)))
36 
37 class Color;
38 
39 template <typename Arg, typename Ret> class Link;
40 
41 enum class BmpMirrorFlags
42 {
43  NONE = 0x00,
44  Horizontal = 0x01,
45  Vertical = 0x02,
46 };
47 
48 namespace o3tl
49 {
50  template<> struct typed_flags<BmpMirrorFlags> : is_typed_flags<BmpMirrorFlags, 0x03> {};
51 }
52 
53 enum class BmpScaleFlag
54 {
55 // Try to preferably use these.
56  Default,
57  Fast,
59 // Specific algorithms, use only if you really need to (mainly used for tests)
61  Interpolate, // fast, integer bilinear
62  Lanczos,
63  BiCubic,
64  BiLinear
65 };
66 
67 #define BMP_COL_TRANS Color( 252, 3, 251 )
68 
69 enum class BmpConversion
70 {
71  NNONE,
73  N8BitGreys,
75  N24Bit,
76  N32Bit,
77  N8BitTrans,
78  N8BitNoConversion // make 8bit without color conversion (e.g. take the red channel)
79 };
80 
81 class BitmapInfoAccess;
82 class BitmapReadAccess;
83 class BitmapWriteAccess;
84 class BitmapPalette;
85 class GDIMetaFile;
86 class AlphaMask;
87 class OutputDevice;
88 class SalBitmap;
89 
91 {
92  #if defined(_WIN32)
93  void* pDIB; // device independent byte buffer
94  #elif defined( MACOSX ) || defined( IOS )
95  // Nothing needed, apparently
96  #else
97  void* aPixmap;
98  #endif
99  int mnWidth;
100  int mnHeight;
101 };
102 
104 {
105 public:
106 
107  Bitmap();
108  Bitmap( const Bitmap& rBitmap );
109  Bitmap( const Size& rSizePixel, vcl::PixelFormat ePixelFormat, const BitmapPalette* pPal = nullptr );
110  explicit Bitmap( std::shared_ptr<SalBitmap> const & xSalBitmap );
111  virtual ~Bitmap();
112 
113  Bitmap& operator=( const Bitmap& rBitmap );
114  Bitmap& operator=( Bitmap&& rBitmap ) noexcept;
115  bool operator==( const Bitmap& rBitmap ) const;
116  bool operator!=( const Bitmap& rBitmap ) const { return !operator==(rBitmap); }
117 
118  inline bool IsEmpty() const;
119  void SetEmpty();
120 
121  inline const MapMode& GetPrefMapMode() const;
122  inline void SetPrefMapMode( const MapMode& rMapMode );
123 
124  inline const Size& GetPrefSize() const;
125  inline void SetPrefSize( const Size& rSize );
126 
127  Size GetSizePixel() const;
128 
129  vcl::PixelFormat getPixelFormat() const;
130  inline sal_Int64 GetSizeBytes() const;
131  bool HasGreyPalette8Bit() const;
132  bool HasGreyPaletteAny() const;
140  bool GetSystemData( BitmapSystemData& rData ) const;
141 
142  BitmapChecksum GetChecksum() const;
143 
144  Bitmap CreateDisplayBitmap( OutputDevice* pDisplay ) const;
145 
146  static const BitmapPalette&
147  GetGreyPalette( int nEntries );
148 
149 public:
150 
158  bool Convert( BmpConversion eConversion );
159 
167  bool Dither();
168 
183  bool Crop( const tools::Rectangle& rRectPixel );
184 
200  bool Expand(
201  sal_Int32 nDX, sal_Int32 nDY,
202  const Color* pInitColor = nullptr );
203 
226  bool CopyPixel(
227  const tools::Rectangle& rRectDst,
228  const tools::Rectangle& rRectSrc,
229  const Bitmap* pBmpSrc = nullptr );
230 
231  bool CopyPixel_AlphaOptimized(
232  const tools::Rectangle& rRectDst,
233  const tools::Rectangle& rRectSrc,
234  const Bitmap* pBmpSrc );
235 
243  bool CombineOr( const Bitmap& rMask );
244 
261  bool Blend(
262  const AlphaMask& rAlpha,
263  const Color& rBackgroundColor );
264 
272  bool Erase( const Color& rFillColor );
273 
278  bool Invert();
279 
287  bool Mirror( BmpMirrorFlags nMirrorFlags );
288 
299  bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
300 
314  bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
315 
323  static bool HasFastScale();
324 
325  // Adapt the BitCount of rNew to BitCount of total, including grey or color palette
326  // Can be used to create alpha/mask bitmaps after their processing in 24bit
327  void AdaptBitCount(Bitmap& rNew) const;
328 
342  bool Rotate( Degree10 nAngle10, const Color& rFillColor );
343 
360  Bitmap CreateMask( const Color& rTransColor, sal_uInt8 nTol = 0 ) const;
361 
373  vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const;
374 
385  bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
386 
397  bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
398 
414  bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 );
415 
434  bool Replace(
435  const Color* pSearchColors,
436  const Color* rReplaceColors,
437  size_t nColorCount,
438  sal_uInt8 const * pTols );
439 
455  void Vectorize(
456  GDIMetaFile& rMtf,
457  sal_uInt8 cReduce,
458  const Link<tools::Long,void>* pProgress );
459 
490  bool Adjust(
491  short nLuminancePercent,
492  short nContrastPercent = 0,
493  short nChannelRPercent = 0,
494  short nChannelGPercent = 0,
495  short nChannelBPercent = 0,
496  double fGamma = 1.0,
497  bool bInvert = false,
498  bool msoBrightness = false );
499 
500 public:
507  SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap);
508 
509  SAL_DLLPRIVATE void ImplMakeUnique();
510  const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
511  SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
512 
513  SAL_DLLPRIVATE bool ImplMakeGreyscales();
514 
515 public:
516 
517  BitmapInfoAccess* AcquireInfoAccess();
518  BitmapReadAccess* AcquireReadAccess();
519  BitmapWriteAccess* AcquireWriteAccess();
520  static void ReleaseAccess( BitmapInfoAccess* pAccess );
521 
524 
525 private:
526  SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr);
527  SAL_DLLPRIVATE bool ImplConvertDown8BPP(Color const* pExtColor = nullptr);
528 
529 private:
530  std::shared_ptr<SalBitmap> mxSalBmp;
533 };
534 
535 inline bool Bitmap::IsEmpty() const
536 {
537  return( mxSalBmp == nullptr );
538 }
539 
540 inline const MapMode& Bitmap::GetPrefMapMode() const
541 {
542  return maPrefMapMode;
543 }
544 
545 inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
546 {
547  maPrefMapMode = rMapMode;
548 }
549 
550 inline const Size& Bitmap::GetPrefSize() const
551 {
552  return maPrefSize;
553 }
554 
555 inline void Bitmap::SetPrefSize( const Size& rSize )
556 {
557  maPrefSize = rSize;
558 }
559 
560 inline sal_Int64 Bitmap::GetSizeBytes() const
561 {
562  const auto aSizePixel = GetSizePixel();
563  const sal_Int64 aBitCount = vcl::pixelFormatBitCount(getPixelFormat());
564  sal_Int64 aSizeInBytes = (aSizePixel.Width() * aSizePixel.Height() * aBitCount) / 8;
565  return aSizeInBytes;
566 }
567 
568 #endif // INCLUDED_VCL_BITMAP_HXX
569 
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PixelFormat
Pixel format of the bitmap in bits per pixel.
Definition: BitmapTypes.hxx:19
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
Size GetSizePixel() const
const Size & GetPrefSize() const
bool operator!=(const Bitmap &rBitmap) const
Point Rotate(const Point &rPoint, Degree10 nOrientation, const Point &rOrigin)
vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap,&Bitmap::AcquireReadAccess > ScopedReadAccess
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:202
const MapMode & GetPrefMapMode() const
void SetPrefMapMode(const MapMode &rMapMode)
vcl::PixelFormat getPixelFormat() const
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
void SetPrefSize(const Size &rSize)
#define SAL_WARN_UNUSED
sal_Int64 GetSizeBytes() const
unsigned char sal_uInt8
bool IsEmpty() const
constexpr sal_uInt16 pixelFormatBitCount(PixelFormat ePixelFormat)
Definition: BitmapTypes.hxx:35
MapMode maPrefMapMode
std::shared_ptr< SalBitmap > mxSalBmp
BmpMirrorFlags
vcl::ScopedBitmapAccess< BitmapInfoAccess, Bitmap,&Bitmap::AcquireInfoAccess > ScopedInfoAccess