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 vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const;
389
400 bool Replace( const Bitmap& rMask, const Color& rReplaceColor );
401
412 bool Replace( const AlphaMask& rAlpha, const Color& rMergeColor );
413
429 bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol = 0 );
430
449 bool Replace(
450 const Color* pSearchColors,
451 const Color* rReplaceColors,
452 size_t nColorCount,
453 sal_uInt8 const * pTols );
454
470 void Vectorize(
471 GDIMetaFile& rMtf,
472 sal_uInt8 cReduce,
473 const Link<tools::Long,void>* pProgress );
474
505 bool Adjust(
506 short nLuminancePercent,
507 short nContrastPercent = 0,
508 short nChannelRPercent = 0,
509 short nChannelGPercent = 0,
510 short nChannelBPercent = 0,
511 double fGamma = 1.0,
512 bool bInvert = false,
513 bool msoBrightness = false );
514
534 void RemoveBlendedStartColor(
535 const Color& rColor,
536 const AlphaMask& rAlphaMask);
537
538 // access to SystemDependentDataHolder, to support overload in derived class(es)
539 const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const;
540
541public:
548 SAL_DLLPRIVATE void ReassignWithSize(const Bitmap& rBitmap);
549
550 SAL_DLLPRIVATE void ImplMakeUnique();
551 const std::shared_ptr<SalBitmap>& ImplGetSalBitmap() const { return mxSalBmp; }
552 SAL_DLLPRIVATE void ImplSetSalBitmap( const std::shared_ptr<SalBitmap>& xImpBmp );
553
554 SAL_DLLPRIVATE bool ImplMakeGreyscales();
555
556public:
557
558 BitmapInfoAccess* AcquireInfoAccess();
559 BitmapReadAccess* AcquireReadAccess();
560 BitmapWriteAccess* AcquireWriteAccess();
561 static void ReleaseAccess( BitmapInfoAccess* pAccess );
562
565
566private:
567 SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr);
568 SAL_DLLPRIVATE bool ImplConvertDown8BPP(Color const* pExtColor = nullptr);
569
570private:
571 std::shared_ptr<SalBitmap> mxSalBmp;
574};
575
576inline bool Bitmap::IsEmpty() const
577{
578 return( mxSalBmp == nullptr );
579}
580
581inline const MapMode& Bitmap::GetPrefMapMode() const
582{
583 return maPrefMapMode;
584}
585
586inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
587{
588 maPrefMapMode = rMapMode;
589}
590
591inline const Size& Bitmap::GetPrefSize() const
592{
593 return maPrefSize;
594}
595
596inline void Bitmap::SetPrefSize( const Size& rSize )
597{
598 maPrefSize = rSize;
599}
600
601inline sal_Int64 Bitmap::GetSizeBytes() const
602{
603 const auto aSizePixel = GetSizePixel();
604 const sal_Int64 aBitCount = vcl::pixelFormatBitCount(getPixelFormat());
605 sal_Int64 aSizeInBytes = (aSizePixel.Width() * aSizePixel.Height() * aBitCount) / 8;
606 return aSizeInBytes;
607}
608
609#endif // INCLUDED_VCL_BITMAP_HXX
610
611/* 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
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:34
unsigned char sal_uInt8
#define SAL_WARN_UNUSED
bool operator==(const ItalicMatrix &a, const ItalicMatrix &b)
Definition: vclenum.hxx:182