LibreOffice Module vcl (master)  1
RawBitmap.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  */
9 
10 #pragma once
11 
12 #include <o3tl/safeint.hxx>
13 #include <vcl/BitmapColor.hxx>
14 #include <vcl/bitmapex.hxx>
15 
16 namespace vcl::bitmap
17 {
22 {
23  friend BitmapEx VCL_DLLPUBLIC CreateFromData(RawBitmap&& rawBitmap);
24  std::unique_ptr<sal_uInt8[]> mpData;
27 
28 public:
29  RawBitmap(Size const& rSize, sal_uInt8 nBitCount)
30  : maSize(rSize)
31  , mnBitCount(nBitCount)
32  {
33  assert(nBitCount == 24 || nBitCount == 32);
34  sal_Int32 nRowSize, nDataSize;
35  if (o3tl::checked_multiply<sal_Int32>(rSize.getWidth(), nBitCount / 8, nRowSize)
36  || o3tl::checked_multiply<sal_Int32>(nRowSize, rSize.getHeight(), nDataSize)
37  || nDataSize < 0)
38  {
39  throw std::bad_alloc();
40  }
41  mpData.reset(new sal_uInt8[nDataSize]);
42  }
43  void SetPixel(tools::Long nY, tools::Long nX, Color nColor)
44  {
45  tools::Long p = (nY * maSize.getWidth() + nX) * (mnBitCount / 8);
46  mpData[p++] = nColor.GetRed();
47  mpData[p++] = nColor.GetGreen();
48  mpData[p++] = nColor.GetBlue();
49  if (mnBitCount == 32)
50  mpData[p] = nColor.GetTransparency();
51  }
53  {
54  tools::Long p = (nY * maSize.getWidth() + nX) * mnBitCount / 8;
55  if (mnBitCount == 24)
56  return Color(mpData[p], mpData[p + 1], mpData[p + 2]);
57  else
58  return Color(mpData[p + 3], mpData[p], mpData[p + 1], mpData[p + 2]);
59  }
60  // so we don't accidentally leave any code in that uses palette color indexes
61  void SetPixel(tools::Long nY, tools::Long nX, BitmapColor nColor) = delete;
62  tools::Long Height() { return maSize.Height(); }
63  tools::Long Width() { return maSize.Width(); }
64  sal_uInt8 GetBitCount() const { return mnBitCount; }
65 };
66 
67 } // end vcl::bitmap
68 
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tools::Long Height()
Definition: RawBitmap.hxx:62
sal_uInt8 GetBitCount() const
Definition: RawBitmap.hxx:64
sal_uInt8 GetRed() const
tools::Long getWidth() const
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
sal_uInt8 GetTransparency() const
long Long
Color GetPixel(tools::Long nY, tools::Long nX) const
Definition: RawBitmap.hxx:52
RawBitmap(Size const &rSize, sal_uInt8 nBitCount)
Definition: RawBitmap.hxx:29
BitmapEx CreateFromData(sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_uInt16 nBitCount)
Copy block of image data into the bitmap.
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
sal_uInt8 GetBlue() const
tools::Long getHeight() const
tools::Long Width()
Definition: RawBitmap.hxx:63
tools::Long Width() const
Intended to be used to feed into CreateFromData to create a BitmapEx.
Definition: RawBitmap.hxx:21
sal_uInt8 GetGreen() const
std::unique_ptr< sal_uInt8[]> mpData
Definition: RawBitmap.hxx:24
unsigned char sal_uInt8
tools::Long Height() const
void * p
void SetPixel(tools::Long nY, tools::Long nX, Color nColor)
Definition: RawBitmap.hxx:43