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
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
37class Color;
38
39template <typename Arg, typename Ret> class Link;
40
42{
43 NONE = 0x00,
44 Horizontal = 0x01,
45 Vertical = 0x02,
46};
47
48namespace o3tl
49{
50 template<> struct typed_flags<BmpMirrorFlags> : is_typed_flags<BmpMirrorFlags, 0x03> {};
51}
52
53enum 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,
65};
66
67#define BMP_COL_TRANS Color( 252, 3, 251 )
68
69enum class BmpConversion
70{
71 NNONE,
75 N24Bit,
76 N32Bit,
78 N8BitNoConversion // make 8bit without color conversion (e.g. take the red channel)
79};
80
84class BitmapPalette;
85class GDIMetaFile;
86class AlphaMask;
87class OutputDevice;
88class SalBitmap;
89
90namespace basegfx { class SystemDependentDataHolder; }
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
103};
104
106{
107public:
108
109 Bitmap();
110 Bitmap( const Bitmap& rBitmap );
111 Bitmap( const Size& rSizePixel, vcl::PixelFormat ePixelFormat, const BitmapPalette* pPal = nullptr );
112 explicit Bitmap( std::shared_ptr<SalBitmap> xSalBitmap );
113 virtual ~Bitmap();
114
115 Bitmap& operator=( const Bitmap& rBitmap );
116 Bitmap& operator=( Bitmap&& rBitmap ) noexcept;
117 bool operator==( const Bitmap& rBitmap ) const;
118 bool operator!=( const Bitmap& rBitmap ) const { return !operator==(rBitmap); }
119
120 inline bool IsEmpty() const;
121 void SetEmpty();
122
123 inline const MapMode& GetPrefMapMode() const;
124 inline void SetPrefMapMode( const MapMode& rMapMode );
125
126 inline const Size& GetPrefSize() const;
127 inline void SetPrefSize( const Size& rSize );
128
129 Size GetSizePixel() const;
130
131 vcl::PixelFormat getPixelFormat() const;
132 inline sal_Int64 GetSizeBytes() const;
133 bool HasGreyPalette8Bit() const;
134 bool HasGreyPaletteAny() const;
142 bool GetSystemData( BitmapSystemData& rData ) const;
143
144 BitmapChecksum GetChecksum() const;
145
146 Bitmap CreateDisplayBitmap( OutputDevice* pDisplay ) const;
147
148 static const BitmapPalette&
149 GetGreyPalette( int nEntries );
150
151public:
152
160 bool Convert( BmpConversion eConversion );
161
169 bool Dither();
170
185 bool Crop( const tools::Rectangle& rRectPixel );
186
202 bool Expand(
203 sal_Int32 nDX, sal_Int32 nDY,
204 const Color* pInitColor = nullptr );
205
228 bool CopyPixel(
229 const tools::Rectangle& rRectDst,
230 const tools::Rectangle& rRectSrc,
231 const Bitmap* pBmpSrc = nullptr );
232
233 bool CopyPixel_AlphaOptimized(
234 const tools::Rectangle& rRectDst,
235 const tools::Rectangle& rRectSrc,
236 const Bitmap* pBmpSrc );
237
245 bool CombineOr( const Bitmap& rMask );
246
263 bool Blend(
264 const AlphaMask& rAlpha,
265 const Color& rBackgroundColor );
266
274 bool Erase( const Color& rFillColor );
275
280 bool Invert();
281
289 bool Mirror( BmpMirrorFlags nMirrorFlags );
290
301 bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
302
316 bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default );
317
325 static bool HasFastScale();
326
327 // Adapt the BitCount of rNew to BitCount of total, including grey or color palette
328 // Can be used to create alpha/mask bitmaps after their processing in 24bit
329 void AdaptBitCount(Bitmap& rNew) const;
330
344 bool Rotate( Degree10 nAngle10, const Color& rFillColor );
345
362 Bitmap CreateMask( const Color& rTransColor, sal_uInt8 nTol = 0 ) const;
363
375 vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const;
376
387 bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
388
399 bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
400
416 bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 );
417
436 bool Replace(
437 const Color* pSearchColors,
438 const Color* rReplaceColors,
439 size_t nColorCount,
440 sal_uInt8 const * pTols );
441
457 void Vectorize(
458 GDIMetaFile& rMtf,
459 sal_uInt8 cReduce,
460 const Link<tools::Long,void>* pProgress );
461
492 bool Adjust(
493 short nLuminancePercent,
494 short nContrastPercent = 0,
495 short nChannelRPercent = 0,
496 short nChannelGPercent = 0,
497 short nChannelBPercent = 0,
498 double fGamma = 1.0,
499 bool bInvert = false,
500 bool msoBrightness = false );
501
521 void RemoveBlendedStartColor(
522 const Color& rColor,
523 const AlphaMask& rAlphaMask);
524
525 // access to SystemDependentDataHolder, to support overload in derived class(es)
526 const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const;
527
528public:
535 SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap);
536
537 SAL_DLLPRIVATE void ImplMakeUnique();
538 const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
539 SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
540
541 SAL_DLLPRIVATE bool ImplMakeGreyscales();
542
543public:
544
545 BitmapInfoAccess* AcquireInfoAccess();
546 BitmapReadAccess* AcquireReadAccess();
547 BitmapWriteAccess* AcquireWriteAccess();
548 static void ReleaseAccess( BitmapInfoAccess* pAccess );
549
552
553private:
554 SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr);
555 SAL_DLLPRIVATE bool ImplConvertDown8BPP(Color const* pExtColor = nullptr);
556
557private:
558 std::shared_ptr<SalBitmap> mxSalBmp;
561};
562
563inline bool Bitmap::IsEmpty() const
564{
565 return( mxSalBmp == nullptr );
566}
567
568inline const MapMode& Bitmap::GetPrefMapMode() const
569{
570 return maPrefMapMode;
571}
572
573inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
574{
575 maPrefMapMode = rMapMode;
576}
577
578inline const Size& Bitmap::GetPrefSize() const
579{
580 return maPrefSize;
581}
582
583inline void Bitmap::SetPrefSize( const Size& rSize )
584{
585 maPrefSize = rSize;
586}
587
588inline sal_Int64 Bitmap::GetSizeBytes() const
589{
590 const auto aSizePixel = GetSizePixel();
591 const sal_Int64 aBitCount = vcl::pixelFormatBitCount(getPixelFormat());
592 sal_Int64 aSizeInBytes = (aSizePixel.Width() * aSizePixel.Height() * aBitCount) / 8;
593 return aSizeInBytes;
594}
595
596#endif // INCLUDED_VCL_BITMAP_HXX
597
598/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
sal_Int64 GetSizeBytes() const
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
void SetPrefMapMode(const MapMode &rMapMode)
const MapMode & GetPrefMapMode() const
Size GetSizePixel() const
bool IsEmpty() const
bool operator!=(const Bitmap &rBitmap) const
vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess > ScopedReadAccess
void SetPrefSize(const Size &rSize)
const Size & GetPrefSize() const
MapMode maPrefMapMode
vcl::ScopedBitmapAccess< BitmapInfoAccess, Bitmap, &Bitmap::AcquireInfoAccess > ScopedInfoAccess
vcl::PixelFormat getPixelFormat() const
std::shared_ptr< SalBitmap > mxSalBmp
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:171
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
Point Rotate(const Point &rPoint, Degree10 nOrientation, const Point &rOrigin)
BmpMirrorFlags
NONE
PixelFormat
Pixel format of the bitmap in bits per pixel.
Definition: BitmapTypes.hxx:20
constexpr sal_uInt16 pixelFormatBitCount(PixelFormat ePixelFormat)
Definition: BitmapTypes.hxx:35
unsigned char sal_uInt8
#define SAL_WARN_UNUSED
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:182