workaround segfault in compiler on macos-clang-intel
[LibreOffice.git] / include / vcl / BitmapWriteAccess.hxx
blob631b097438bf00ca7996d3b8496464f9871d3ef8
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 */
10 #pragma once
12 #include <vcl/alpha.hxx>
13 #include <vcl/bitmap.hxx>
14 #include <vcl/BitmapReadAccess.hxx>
15 #include <optional>
17 class VCL_DLLPUBLIC BitmapWriteAccess final : public BitmapReadAccess
19 public:
20 BitmapWriteAccess(Bitmap& rBitmap);
21 BitmapWriteAccess(AlphaMask& rBitmap);
22 virtual ~BitmapWriteAccess() override;
24 SAL_DLLPRIVATE void CopyScanline(tools::Long nY, const BitmapReadAccess& rReadAcc);
25 SAL_DLLPRIVATE void CopyScanline(tools::Long nY, ConstScanline aSrcScanline,
26 ScanlineFormat nSrcScanlineFormat,
27 sal_uInt32 nSrcScanlineSize);
29 void SetPalette(const BitmapPalette& rPalette)
31 assert(mpBuffer && "Access is not valid!");
33 mpBuffer->maPalette = rPalette;
36 void SetPaletteEntryCount(sal_uInt16 nCount)
38 assert(mpBuffer && "Access is not valid!");
40 mpBuffer->maPalette.SetEntryCount(nCount);
43 void SetPaletteColor(sal_uInt16 nColor, const BitmapColor& rBitmapColor)
45 assert(mpBuffer && "Access is not valid!");
46 assert(HasPalette() && "Bitmap has no palette!");
48 mpBuffer->maPalette[nColor] = rBitmapColor;
51 void SetPixel(tools::Long nY, tools::Long nX, const BitmapColor& rBitmapColor)
53 assert(mpBuffer && "Access is not valid!");
54 assert(nX < mpBuffer->mnWidth && "x-coordinate out of range!");
55 assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
57 mFncSetPixel(GetScanline(nY), nX, rBitmapColor, maColorMask);
60 void SetPixelIndex(tools::Long nY, tools::Long nX, sal_uInt8 cIndex)
62 SetPixel(nY, nX, BitmapColor(cIndex));
65 void SetLineColor(const Color& rColor);
67 void SetFillColor();
68 void SetFillColor(const Color& rColor);
70 void Erase(const Color& rColor);
72 SAL_DLLPRIVATE void DrawLine(const Point& rStart, const Point& rEnd);
74 void FillRect(const tools::Rectangle& rRect);
75 void DrawRect(const tools::Rectangle& rRect);
77 private:
78 std::optional<BitmapColor> mpLineColor;
79 std::optional<BitmapColor> mpFillColor;
81 BitmapWriteAccess() = delete;
82 BitmapWriteAccess(const BitmapWriteAccess&) = delete;
83 BitmapWriteAccess& operator=(const BitmapWriteAccess&) = delete;
86 class BitmapScopedWriteAccess
88 public:
89 BitmapScopedWriteAccess(Bitmap& rBitmap)
90 : moAccess(rBitmap)
93 BitmapScopedWriteAccess(AlphaMask& rBitmap)
94 : moAccess(rBitmap)
97 BitmapScopedWriteAccess() {}
99 BitmapScopedWriteAccess& operator=(Bitmap& rBitmap)
101 moAccess.emplace(rBitmap);
102 return *this;
105 BitmapScopedWriteAccess& operator=(AlphaMask& rBitmap)
107 moAccess.emplace(rBitmap);
108 return *this;
111 bool operator!() const { return !moAccess.has_value() || !*moAccess; }
112 explicit operator bool() const { return moAccess && bool(*moAccess); }
114 void reset() { moAccess.reset(); }
116 BitmapWriteAccess* get() { return moAccess ? &*moAccess : nullptr; }
117 const BitmapWriteAccess* get() const { return moAccess ? &*moAccess : nullptr; }
119 BitmapWriteAccess* operator->() { return &*moAccess; }
120 const BitmapWriteAccess* operator->() const { return &*moAccess; }
122 BitmapWriteAccess& operator*() { return *moAccess; }
123 const BitmapWriteAccess& operator*() const { return *moAccess; }
125 private:
126 std::optional<BitmapWriteAccess> moAccess;
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */