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
357 Bitmap CreateMask( const Color& rTransColor ) const;
358
375 Bitmap CreateMask( const Color& rTransColor, sal_uInt8 nTol ) const;
376
388 AlphaMask CreateAlphaMask( const Color& rTransColor ) const;
389
406 AlphaMask CreateAlphaMask( const Color& rTransColor, sal_uInt8 nTol ) const;
407
419 vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const;
420
431 bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
432
448 bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 );
449
468 bool Replace(
469 const Color* pSearchColors,
470 const Color* rReplaceColors,
471 size_t nColorCount,
472 sal_uInt8 const * pTols );
473
489 void Vectorize(
490 GDIMetaFile& rMtf,
491 sal_uInt8 cReduce,
492 const Link<tools::Long,void>* pProgress );
493
524 bool Adjust(
525 short nLuminancePercent,
526 short nContrastPercent = 0,
527 short nChannelRPercent = 0,
528 short nChannelGPercent = 0,
529 short nChannelBPercent = 0,
530 double fGamma = 1.0,
531 bool bInvert = false,
532 bool msoBrightness = false );
533
553 void RemoveBlendedStartColor(
554 const Color& rColor,
555 const AlphaMask& rAlphaMask);
556
557 // access to SystemDependentDataHolder, to support overload in derived class(es)
558 const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const;
559
560public:
567 SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap);
568
569 SAL_DLLPRIVATE void ImplMakeUnique();
570 const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
571 SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
572
573 SAL_DLLPRIVATE bool ImplMakeGreyscales();
574
575public:
576
577 BitmapInfoAccess* AcquireInfoAccess();
578 BitmapReadAccess* AcquireReadAccess();
579 BitmapWriteAccess* AcquireWriteAccess();
580 static void ReleaseAccess( BitmapInfoAccess* pAccess );
581
584
585private:
586 SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr);
587 SAL_DLLPRIVATE bool ImplConvertDown8BPP(Color const* pExtColor = nullptr);
588
589private:
590 std::shared_ptr<SalBitmap> mxSalBmp;
593};
594
595inline bool Bitmap::IsEmpty() const
596{
597 return( mxSalBmp == nullptr );
598}
599
600inline const MapMode& Bitmap::GetPrefMapMode() const
601{
602 return maPrefMapMode;
603}
604
605inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
606{
607 maPrefMapMode = rMapMode;
608}
609
610inline const Size& Bitmap::GetPrefSize() const
611{
612 return maPrefSize;
613}
614
615inline void Bitmap::SetPrefSize( const Size& rSize )
616{
617 maPrefSize = rSize;
618}
619
620inline sal_Int64 Bitmap::GetSizeBytes() const
621{
622 const auto aSizePixel = GetSizePixel();
623 const sal_Int64 aBitCount = vcl::pixelFormatBitCount(getPixelFormat());
624 sal_Int64 aSizeInBytes = (aSizePixel.Width() * aSizePixel.Height() * aBitCount) / 8;
625 return aSizeInBytes;
626}
627
628#endif // INCLUDED_VCL_BITMAP_HXX
629
630/* 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:170
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
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:34
unsigned char sal_uInt8
#define SAL_WARN_UNUSED
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:175