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
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
101};
102
104{
105public:
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
149public:
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
500public:
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
515public:
516
517 BitmapInfoAccess* AcquireInfoAccess();
518 BitmapReadAccess* AcquireReadAccess();
519 BitmapWriteAccess* AcquireWriteAccess();
520 static void ReleaseAccess( BitmapInfoAccess* pAccess );
521
524
525private:
526 SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr);
527 SAL_DLLPRIVATE bool ImplConvertDown8BPP(Color const* pExtColor = nullptr);
528
529private:
530 std::shared_ptr<SalBitmap> mxSalBmp;
533};
534
535inline bool Bitmap::IsEmpty() const
536{
537 return( mxSalBmp == nullptr );
538}
539
540inline const MapMode& Bitmap::GetPrefMapMode() const
541{
542 return maPrefMapMode;
543}
544
545inline void Bitmap::SetPrefMapMode( const MapMode& rMapMode )
546{
547 maPrefMapMode = rMapMode;
548}
549
550inline const Size& Bitmap::GetPrefSize() const
551{
552 return maPrefSize;
553}
554
555inline void Bitmap::SetPrefSize( const Size& rSize )
556{
557 maPrefSize = rSize;
558}
559
560inline 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: */
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:176
#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