summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-12 17:36:05 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-05-13 17:54:10 +0200
commitd2cb44507708af41e9ee408c4db08c5bc7b13b43 (patch)
treee5c2010672eb760403e0134181568b1471479977 /include
parente8bd027d70d448d8fc5dd90d1a94b4fa6cb937b2 (diff)
vcl: move RawBitmap out of BitmapTools.hxx
Change-Id: I7bb645802718e1beac560bdcf574bf439c48765f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94126 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/vcl/BitmapTools.hxx49
-rw-r--r--include/vcl/RawBitmap.hxx65
2 files changed, 66 insertions, 48 deletions
diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx
index 83cf5ad85844..8c168b64262c 100644
--- a/include/vcl/BitmapTools.hxx
+++ b/include/vcl/BitmapTools.hxx
@@ -20,6 +20,7 @@
#include <basegfx/range/b2drectangle.hxx>
#include <o3tl/safeint.hxx>
#include <array>
+#include <vcl/RawBitmap.hxx>
class SvStream;
namespace basegfx { class B2DHomMatrix; }
@@ -35,54 +36,6 @@ lookup_table VCL_DLLPUBLIC get_unpremultiply_table();
sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a);
sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a);
-/**
- * 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; }
-};
-
BitmapEx VCL_DLLPUBLIC loadFromName(const OUString& rFileName, const ImageLoadFlags eFlags = ImageLoadFlags::NONE);
void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, double fScaleFactor);
diff --git a/include/vcl/RawBitmap.hxx b/include/vcl/RawBitmap.hxx
new file mode 100644
index 000000000000..aeb5dec9f3e1
--- /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: */