Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / vcl / alpha.hxx
blobfb5be9c163888a03b62b332dbc5853f9f1466e40
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_ALPHA_HXX
21 #define INCLUDED_VCL_ALPHA_HXX
23 #include <sal/config.h>
25 #include <utility>
27 #include <vcl/dllapi.h>
28 #include <vcl/bitmap.hxx>
30 class BitmapEx;
32 class VCL_DLLPUBLIC AlphaMask final
34 public:
35 AlphaMask();
36 explicit AlphaMask( const Bitmap& rBitmap );
37 AlphaMask( const AlphaMask& rAlphaMask );
38 AlphaMask( AlphaMask&& rAlphaMask );
39 explicit AlphaMask( const Size& rSizePixel, const sal_uInt8* pEraseTransparency = nullptr );
40 ~AlphaMask();
42 AlphaMask& operator=( const Bitmap& rBitmap );
43 AlphaMask& operator=( const AlphaMask& rAlphaMask ) { maBitmap = rAlphaMask.maBitmap; return *this; }
44 AlphaMask& operator=( AlphaMask&& rAlphaMask ) noexcept { maBitmap = std::move(rAlphaMask.maBitmap); return *this; }
45 bool operator==( const AlphaMask& rAlphaMask ) const { return maBitmap == rAlphaMask.maBitmap; }
46 bool operator!=( const AlphaMask& rAlphaMask ) const { return maBitmap != rAlphaMask.maBitmap; }
48 Bitmap const & GetBitmap() const { return maBitmap; }
50 void Erase( sal_uInt8 cTransparency );
51 void BlendWith(const AlphaMask& rOther);
53 /** Perform boolean OR operation with another alpha-mask
55 @param rMask
56 The mask bitmap in the selected combine operation
58 @return true, if the operation was completed successfully.
60 bool AlphaCombineOr( const AlphaMask& rMask );
62 // check if alpha is used, returns true if at least one pixel has transparence
63 bool hasAlpha() const;
65 bool IsEmpty() const { return maBitmap.IsEmpty(); }
67 void SetEmpty() { maBitmap.SetEmpty(); }
69 vcl::PixelFormat getPixelFormat() const { return maBitmap.getPixelFormat(); }
71 sal_Int64 GetSizeBytes() const { return maBitmap.GetSizeBytes(); }
73 Size GetSizePixel() const { return maBitmap.GetSizePixel(); }
75 void SetPrefSize( const Size& rSize ) { maBitmap.SetPrefSize(rSize); }
77 void SetPrefMapMode( const MapMode& rMapMode ) { maBitmap.SetPrefMapMode(rMapMode); }
79 BitmapChecksum GetChecksum() const { return maBitmap.GetChecksum(); }
81 bool Invert();
83 bool Mirror( BmpMirrorFlags nMirrorFlags ) { return maBitmap.Mirror(nMirrorFlags); }
85 bool Scale( const Size& rNewSize, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default ) { return maBitmap.Scale(rNewSize, nScaleFlag); }
87 bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag = BmpScaleFlag::Default )
88 { return maBitmap.Scale(rScaleX, rScaleY, nScaleFlag); }
90 bool Convert( BmpConversion eConversion ) { return maBitmap.Convert(eConversion); }
92 vcl::Region CreateRegion( const Color& rColor, const tools::Rectangle& rRect ) const { return maBitmap.CreateRegion(rColor, rRect); }
94 bool Rotate( Degree10 nAngle10, const Color& rFillColor ) { return maBitmap.Rotate(nAngle10, rFillColor); }
96 bool Crop( const tools::Rectangle& rRectPixel ) { return maBitmap.Crop(rRectPixel); }
98 bool Expand( sal_Int32 nDX, sal_Int32 nDY, const Color* pInitColor = nullptr ) { return maBitmap.Expand(nDX, nDY, pInitColor); }
100 bool CopyPixel( const tools::Rectangle& rRectDst,
101 const tools::Rectangle& rRectSrc )
102 { return maBitmap.CopyPixel(rRectDst, rRectSrc); }
104 bool CopyPixel( const tools::Rectangle& rRectDst,
105 const tools::Rectangle& rRectSrc,
106 const AlphaMask& rBmpSrc )
107 { return maBitmap.CopyPixel(rRectDst, rRectSrc, rBmpSrc.maBitmap); }
109 bool CopyPixel_AlphaOptimized(
110 const tools::Rectangle& rRectDst,
111 const tools::Rectangle& rRectSrc )
112 { return maBitmap.CopyPixel_AlphaOptimized(rRectDst, rRectSrc); }
114 bool CopyPixel_AlphaOptimized(
115 const tools::Rectangle& rRectDst,
116 const tools::Rectangle& rRectSrc,
117 const AlphaMask& rBmpSrc )
118 { return maBitmap.CopyPixel_AlphaOptimized(rRectDst, rRectSrc, rBmpSrc); }
120 private:
121 friend class BitmapEx;
122 friend class ::OutputDevice;
123 friend bool VCL_DLLPUBLIC ReadDIBBitmapEx(BitmapEx& rTarget, SvStream& rIStm, bool bFileHeader, bool bMSOFormat);
125 Bitmap maBitmap;
128 #endif // INCLUDED_VCL_ALPHA_HXX
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */