diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /include/vcl/RawBitmap.hxx | |
parent | Initial commit. (diff) | |
download | libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'include/vcl/RawBitmap.hxx')
-rw-r--r-- | include/vcl/RawBitmap.hxx | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/include/vcl/RawBitmap.hxx b/include/vcl/RawBitmap.hxx new file mode 100644 index 000000000..aeb5dec9f --- /dev/null +++ b/include/vcl/RawBitmap.hxx @@ -0,0 +1,65 @@ +/* -*- 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 + +namespace vcl::bitmap +{ +/** + * Intended to be used to feed into CreateFromData to create a BitmapEx. RGB data format. + */ +class VCL_DLLPUBLIC RawBitmap +{ + friend BitmapEx VCL_DLLPUBLIC CreateFromData(RawBitmap&& rawBitmap); + std::unique_ptr<sal_uInt8[]> mpData; + Size maSize; + sal_uInt8 mnBitCount; + +public: + RawBitmap(Size const& rSize, sal_uInt8 nBitCount) + : maSize(rSize) + , mnBitCount(nBitCount) + { + assert(nBitCount == 24 || nBitCount == 32); + sal_Int32 nRowSize, nDataSize; + if (o3tl::checked_multiply<sal_Int32>(rSize.getWidth(), nBitCount / 8, nRowSize) + || o3tl::checked_multiply<sal_Int32>(nRowSize, rSize.getHeight(), nDataSize) + || nDataSize < 0) + { + throw std::bad_alloc(); + } + mpData.reset(new sal_uInt8[nDataSize]); + } + void SetPixel(long nY, long nX, Color nColor) + { + long p = (nY * maSize.getWidth() + nX) * (mnBitCount / 8); + mpData[p++] = nColor.GetRed(); + mpData[p++] = nColor.GetGreen(); + mpData[p++] = nColor.GetBlue(); + if (mnBitCount == 32) + mpData[p] = nColor.GetTransparency(); + } + Color GetPixel(long nY, long nX) const + { + long p = (nY * maSize.getWidth() + nX) * mnBitCount / 8; + if (mnBitCount == 24) + return Color(mpData[p], mpData[p + 1], mpData[p + 2]); + else + return Color(mpData[p + 3], mpData[p], mpData[p + 1], mpData[p + 2]); + } + // so we don't accidentally leave any code in that uses palette color indexes + void SetPixel(long nY, long nX, BitmapColor nColor) = delete; + long Height() { return maSize.Height(); } + long Width() { return maSize.Width(); } + sal_uInt8 GetBitCount() const { return mnBitCount; } +}; + +} // end vcl::bitmap + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |