summaryrefslogtreecommitdiffstats
path: root/include/vcl/BitmapWriteAccess.hxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 05:54:39 +0000
commit267c6f2ac71f92999e969232431ba04678e7437e (patch)
tree358c9467650e1d0a1d7227a21dac2e3d08b622b2 /include/vcl/BitmapWriteAccess.hxx
parentInitial commit. (diff)
downloadlibreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz
libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/vcl/BitmapWriteAccess.hxx')
-rw-r--r--include/vcl/BitmapWriteAccess.hxx128
1 files changed, 128 insertions, 0 deletions
diff --git a/include/vcl/BitmapWriteAccess.hxx b/include/vcl/BitmapWriteAccess.hxx
new file mode 100644
index 0000000000..9027210adb
--- /dev/null
+++ b/include/vcl/BitmapWriteAccess.hxx
@@ -0,0 +1,128 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+#pragma once
+
+#include <vcl/alpha.hxx>
+#include <vcl/bitmap.hxx>
+#include <vcl/BitmapReadAccess.hxx>
+#include <optional>
+
+class VCL_DLLPUBLIC BitmapWriteAccess final : public BitmapReadAccess
+{
+public:
+ BitmapWriteAccess(Bitmap& rBitmap);
+ BitmapWriteAccess(AlphaMask& rBitmap);
+ virtual ~BitmapWriteAccess() override;
+
+ void CopyScanline(tools::Long nY, const BitmapReadAccess& rReadAcc);
+ void CopyScanline(tools::Long nY, ConstScanline aSrcScanline, ScanlineFormat nSrcScanlineFormat,
+ sal_uInt32 nSrcScanlineSize);
+
+ void SetPalette(const BitmapPalette& rPalette)
+ {
+ assert(mpBuffer && "Access is not valid!");
+
+ mpBuffer->maPalette = rPalette;
+ }
+
+ void SetPaletteEntryCount(sal_uInt16 nCount)
+ {
+ assert(mpBuffer && "Access is not valid!");
+
+ mpBuffer->maPalette.SetEntryCount(nCount);
+ }
+
+ void SetPaletteColor(sal_uInt16 nColor, const BitmapColor& rBitmapColor)
+ {
+ assert(mpBuffer && "Access is not valid!");
+ assert(HasPalette() && "Bitmap has no palette!");
+
+ mpBuffer->maPalette[nColor] = rBitmapColor;
+ }
+
+ void SetPixel(tools::Long nY, tools::Long nX, const BitmapColor& rBitmapColor)
+ {
+ assert(mpBuffer && "Access is not valid!");
+ assert(nX < mpBuffer->mnWidth && "x-coordinate out of range!");
+ assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
+
+ mFncSetPixel(GetScanline(nY), nX, rBitmapColor, maColorMask);
+ }
+
+ void SetPixelIndex(tools::Long nY, tools::Long nX, sal_uInt8 cIndex)
+ {
+ SetPixel(nY, nX, BitmapColor(cIndex));
+ }
+
+ void SetLineColor(const Color& rColor);
+
+ void SetFillColor();
+ void SetFillColor(const Color& rColor);
+
+ void Erase(const Color& rColor);
+
+ void DrawLine(const Point& rStart, const Point& rEnd);
+
+ void FillRect(const tools::Rectangle& rRect);
+ void DrawRect(const tools::Rectangle& rRect);
+
+private:
+ std::optional<BitmapColor> mpLineColor;
+ std::optional<BitmapColor> mpFillColor;
+
+ BitmapWriteAccess() = delete;
+ BitmapWriteAccess(const BitmapWriteAccess&) = delete;
+ BitmapWriteAccess& operator=(const BitmapWriteAccess&) = delete;
+};
+
+class BitmapScopedWriteAccess
+{
+public:
+ BitmapScopedWriteAccess(Bitmap& rBitmap)
+ : moAccess(rBitmap)
+ {
+ }
+ BitmapScopedWriteAccess(AlphaMask& rBitmap)
+ : moAccess(rBitmap)
+ {
+ }
+ BitmapScopedWriteAccess() {}
+
+ BitmapScopedWriteAccess& operator=(Bitmap& rBitmap)
+ {
+ moAccess.emplace(rBitmap);
+ return *this;
+ }
+
+ BitmapScopedWriteAccess& operator=(AlphaMask& rBitmap)
+ {
+ moAccess.emplace(rBitmap);
+ return *this;
+ }
+
+ bool operator!() const { return !moAccess.has_value() || !*moAccess; }
+ explicit operator bool() const { return moAccess && bool(*moAccess); }
+
+ void reset() { moAccess.reset(); }
+
+ BitmapWriteAccess* get() { return moAccess ? &*moAccess : nullptr; }
+ const BitmapWriteAccess* get() const { return moAccess ? &*moAccess : nullptr; }
+
+ BitmapWriteAccess* operator->() { return &*moAccess; }
+ const BitmapWriteAccess* operator->() const { return &*moAccess; }
+
+ BitmapWriteAccess& operator*() { return *moAccess; }
+ const BitmapWriteAccess& operator*() const { return *moAccess; }
+
+private:
+ std::optional<BitmapWriteAccess> moAccess;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */