diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/BitmapInfoAccess.hxx | 52 | ||||
-rw-r--r-- | include/vcl/BitmapReadAccess.hxx | 51 | ||||
-rw-r--r-- | include/vcl/BitmapWriteAccess.hxx | 128 | ||||
-rw-r--r-- | include/vcl/alpha.hxx | 9 | ||||
-rw-r--r-- | include/vcl/bitmap.hxx | 11 | ||||
-rw-r--r-- | include/vcl/scopedbitmapaccess.hxx | 123 |
6 files changed, 221 insertions, 153 deletions
diff --git a/include/vcl/BitmapInfoAccess.hxx b/include/vcl/BitmapInfoAccess.hxx index 6e255c97e7ec..7ded0c9a95da 100644 --- a/include/vcl/BitmapInfoAccess.hxx +++ b/include/vcl/BitmapInfoAccess.hxx @@ -16,9 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - -#ifndef INCLUDED_VCL_BITMAPINFOACCESS_HXX -#define INCLUDED_VCL_BITMAPINFOACCESS_HXX +#pragma once #include <vcl/dllapi.h> #include <vcl/bitmap.hxx> @@ -38,10 +36,13 @@ class VCL_DLLPUBLIC BitmapInfoAccess friend class BitmapReadAccess; public: - BitmapInfoAccess(Bitmap& rBitmap, BitmapAccessMode nMode = BitmapAccessMode::Info); + BitmapInfoAccess(const Bitmap& rBitmap, BitmapAccessMode nMode = BitmapAccessMode::Info); + BitmapInfoAccess(const AlphaMask& rBitmap, BitmapAccessMode nMode = BitmapAccessMode::Info); + virtual ~BitmapInfoAccess(); bool operator!() const { return mpBuffer == nullptr; } + explicit operator bool() const { return mpBuffer != nullptr; } tools::Long Width() const { return mpBuffer ? mpBuffer->mnWidth : 0L; } @@ -152,6 +153,47 @@ protected: BitmapAccessMode mnAccessMode; }; -#endif // INCLUDED_VCL_BITMAPINFOACCESS_HXX +class BitmapScopedInfoAccess +{ +public: + BitmapScopedInfoAccess(const Bitmap& rBitmap) + : moAccess(rBitmap) + { + } + BitmapScopedInfoAccess(const AlphaMask& rBitmap) + : moAccess(rBitmap) + { + } + BitmapScopedInfoAccess() {} + + BitmapScopedInfoAccess& operator=(const Bitmap& rBitmap) + { + moAccess.emplace(rBitmap); + return *this; + } + + BitmapScopedInfoAccess& operator=(const 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(); } + + BitmapInfoAccess* get() { return moAccess ? &*moAccess : nullptr; } + const BitmapInfoAccess* get() const { return moAccess ? &*moAccess : nullptr; } + + BitmapInfoAccess* operator->() { return &*moAccess; } + const BitmapInfoAccess* operator->() const { return &*moAccess; } + + BitmapInfoAccess& operator*() { return *moAccess; } + const BitmapInfoAccess& operator*() const { return *moAccess; } + +private: + std::optional<BitmapInfoAccess> moAccess; +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/BitmapReadAccess.hxx b/include/vcl/BitmapReadAccess.hxx index 0d12bcae9dd6..5a99adb56bba 100644 --- a/include/vcl/BitmapReadAccess.hxx +++ b/include/vcl/BitmapReadAccess.hxx @@ -16,9 +16,7 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ - -#ifndef INCLUDED_VCL_BITMAPREADACCESS_HXX -#define INCLUDED_VCL_BITMAPREADACCESS_HXX +#pragma once #include <vcl/dllapi.h> #include <vcl/bitmap.hxx> @@ -33,7 +31,9 @@ class SAL_DLLPUBLIC_RTTI BitmapReadAccess : public BitmapInfoAccess friend class BitmapWriteAccess; public: - VCL_DLLPUBLIC BitmapReadAccess(Bitmap& rBitmap, + VCL_DLLPUBLIC BitmapReadAccess(const Bitmap& rBitmap, + BitmapAccessMode nMode = BitmapAccessMode::Read); + VCL_DLLPUBLIC BitmapReadAccess(const AlphaMask& rBitmap, BitmapAccessMode nMode = BitmapAccessMode::Read); VCL_DLLPUBLIC virtual ~BitmapReadAccess() override; @@ -189,6 +189,47 @@ public: static FncSetPixel SetPixelFunction(ScanlineFormat nFormat); }; -#endif // INCLUDED_VCL_BITMAPREADACCESS_HXX +class BitmapScopedReadAccess +{ +public: + BitmapScopedReadAccess(const Bitmap& rBitmap) + : moAccess(rBitmap) + { + } + BitmapScopedReadAccess(const AlphaMask& rBitmap) + : moAccess(rBitmap) + { + } + BitmapScopedReadAccess() {} + + BitmapScopedReadAccess& operator=(const Bitmap& rBitmap) + { + moAccess.emplace(rBitmap); + return *this; + } + + BitmapScopedReadAccess& operator=(const 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(); } + + BitmapReadAccess* get() { return moAccess ? &*moAccess : nullptr; } + const BitmapReadAccess* get() const { return moAccess ? &*moAccess : nullptr; } + + BitmapReadAccess* operator->() { return &*moAccess; } + const BitmapReadAccess* operator->() const { return &*moAccess; } + + BitmapReadAccess& operator*() { return *moAccess; } + const BitmapReadAccess& operator*() const { return *moAccess; } + +private: + std::optional<BitmapReadAccess> moAccess; +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/BitmapWriteAccess.hxx b/include/vcl/BitmapWriteAccess.hxx new file mode 100644 index 000000000000..9027210adb50 --- /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: */ diff --git a/include/vcl/alpha.hxx b/include/vcl/alpha.hxx index 65ad50cfb4ea..fb5be9c16388 100644 --- a/include/vcl/alpha.hxx +++ b/include/vcl/alpha.hxx @@ -62,13 +62,6 @@ public: // check if alpha is used, returns true if at least one pixel has transparence bool hasAlpha() const; - BitmapReadAccess* AcquireAlphaReadAccess() { return maBitmap.AcquireReadAccess(); } - BitmapWriteAccess* AcquireAlphaWriteAccess() { return maBitmap.AcquireWriteAccess(); } - static void ReleaseAccess( BitmapInfoAccess* pBitmapAccess ) { Bitmap::ReleaseAccess(pBitmapAccess); } - - typedef vcl::ScopedBitmapAccess<BitmapReadAccess, AlphaMask, &AlphaMask::AcquireAlphaReadAccess> ScopedReadAccess; - typedef vcl::ScopedBitmapAccess<BitmapWriteAccess, AlphaMask, &AlphaMask::AcquireAlphaWriteAccess> ScopedWriteAccess; - bool IsEmpty() const { return maBitmap.IsEmpty(); } void SetEmpty() { maBitmap.SetEmpty(); } @@ -83,8 +76,6 @@ public: void SetPrefMapMode( const MapMode& rMapMode ) { maBitmap.SetPrefMapMode(rMapMode); } - BitmapReadAccess* AcquireReadAccess() { return maBitmap.AcquireReadAccess(); } - BitmapChecksum GetChecksum() const { return maBitmap.GetChecksum(); } bool Invert(); diff --git a/include/vcl/bitmap.hxx b/include/vcl/bitmap.hxx index 514eefea8f1b..8ce5d9cf74fa 100644 --- a/include/vcl/bitmap.hxx +++ b/include/vcl/bitmap.hxx @@ -26,7 +26,6 @@ #include <vcl/dllapi.h> #include <vcl/mapmod.hxx> #include <vcl/region.hxx> -#include <vcl/scopedbitmapaccess.hxx> #include <vcl/bitmap/BitmapTypes.hxx> #include <o3tl/typed_flags_set.hxx> @@ -605,16 +604,6 @@ public: SAL_DLLPRIVATE bool ImplMakeGreyscales(); -public: - - BitmapInfoAccess* AcquireInfoAccess(); - BitmapReadAccess* AcquireReadAccess(); - BitmapWriteAccess* AcquireWriteAccess(); - static void ReleaseAccess( BitmapInfoAccess* pAccess ); - - typedef vcl::ScopedBitmapAccess<BitmapReadAccess, Bitmap, &Bitmap::AcquireReadAccess> ScopedReadAccess; - typedef vcl::ScopedBitmapAccess<BitmapInfoAccess, Bitmap, &Bitmap::AcquireInfoAccess> ScopedInfoAccess; - private: SAL_DLLPRIVATE bool ImplConvertUp(vcl::PixelFormat ePixelFormat, Color const* pExtColor = nullptr); SAL_DLLPRIVATE bool ImplConvertDown8BPP(Color const* pExtColor = nullptr); diff --git a/include/vcl/scopedbitmapaccess.hxx b/include/vcl/scopedbitmapaccess.hxx deleted file mode 100644 index b06618091529..000000000000 --- a/include/vcl/scopedbitmapaccess.hxx +++ /dev/null @@ -1,123 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX -#define INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX - -#include <sal/types.h> - -namespace vcl -{ - -/** This template handles BitmapAccess the RAII way. - - Please don't use directly, but through the ready-made typedefs - ScopedReadAccess and ScopedWriteAccess in classes Bitmap and - AlphaMask. - - Use as follows: - Bitmap aBitmap; - Bitmap::ScopedReadAccess pReadAccess( aBitmap ); - pReadAccess->SetPixel()... - - Bitmap aBitmap2; - BitmapScopedWriteAccess pWriteAccess( bCond ? aBitmap2.AcquireWriteAccess() : 0, aBitmap2 ); - if ( pWriteAccess )... - - @attention for practical reasons, ScopedBitmapAccess stores a - reference to the provided bitmap, thus, make sure that the bitmap - specified at construction time lives at least as long as the - ScopedBitmapAccess. - */ -template < class Access, class Bitmap, Access* (Bitmap::* Acquire)() > class ScopedBitmapAccess -{ -public: - explicit ScopedBitmapAccess( Bitmap& rBitmap ) : - mpAccess( nullptr ), - mpBitmap( &rBitmap ) - { - mpAccess = (mpBitmap->*Acquire)(); - } - - ScopedBitmapAccess( Access* pAccess, Bitmap& rBitmap ) : - mpAccess( pAccess ), - mpBitmap( &rBitmap ) - { - } - - ScopedBitmapAccess( ) : - mpAccess( nullptr ), - mpBitmap( nullptr ) - { - } - - // Move semantics - ScopedBitmapAccess &operator=(ScopedBitmapAccess&&other) - { - mpAccess=other.mpAccess; - mpBitmap=other.mpBitmap; - other.mpAccess = nullptr; - other.mpBitmap = nullptr; - return *this; - } - - // Disable copy from lvalue. - ScopedBitmapAccess(const ScopedBitmapAccess&) = delete; - ScopedBitmapAccess &operator=(const ScopedBitmapAccess&) = delete; - - ~ScopedBitmapAccess() COVERITY_NOEXCEPT_FALSE - { - if (mpAccess) - mpBitmap->ReleaseAccess( mpAccess ); - } - - void reset() - { - if (mpAccess) - { - mpBitmap->ReleaseAccess( mpAccess ); - mpAccess = nullptr; - } - } - - bool operator!() const { return !mpAccess; } - explicit operator bool() const - { - return mpAccess; - } - - Access* get() { return mpAccess; } - const Access* get() const { return mpAccess; } - - Access* operator->() { return mpAccess; } - const Access* operator->() const { return mpAccess; } - - Access& operator*() { return *mpAccess; } - const Access& operator*() const { return *mpAccess; } - -private: - Access* mpAccess; - Bitmap* mpBitmap; -}; - -} - -#endif // INCLUDED_VCL_SCOPEDBITMAPACCESS_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |