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
16namespace vcl::bitmap
17{
22{
24 std::unique_ptr<sal_uInt8[]> mpData;
27
28public:
30 : maSize(rSize)
31 , mnBitCount(nBitCount)
32 {
33 assert(nBitCount == 24 || nBitCount == 32);
34 if (rSize.getWidth() > std::numeric_limits<sal_Int32>::max() || rSize.getWidth() < 0)
35 throw std::bad_alloc();
36 if (rSize.getHeight() > std::numeric_limits<sal_Int32>::max() || rSize.getHeight() < 0)
37 throw std::bad_alloc();
38 sal_Int32 nRowSize, nDataSize;
39 if (o3tl::checked_multiply<sal_Int32>(rSize.getWidth(), nBitCount / 8, nRowSize)
40 || o3tl::checked_multiply<sal_Int32>(nRowSize, rSize.getHeight(), nDataSize)
41 || nDataSize < 0)
42 {
43 throw std::bad_alloc();
44 }
45 mpData.reset(new sal_uInt8[nDataSize]);
46 }
48 {
49 tools::Long p = (nY * maSize.getWidth() + nX) * (mnBitCount / 8);
50 mpData[p++] = nColor.GetRed();
51 mpData[p++] = nColor.GetGreen();
52 mpData[p++] = nColor.GetBlue();
53 if (mnBitCount == 32)
54 mpData[p] = nColor.GetAlpha();
55 }
57 {
58 assert(mnBitCount == 32);
59 tools::Long p = (nY * maSize.getWidth() + nX) * (mnBitCount / 8) + 3;
60 mpData[p] = nAlpha;
61 }
63 {
64 tools::Long p = (nY * maSize.getWidth() + nX) * mnBitCount / 8;
65 if (mnBitCount == 24)
66 return Color(mpData[p], mpData[p + 1], mpData[p + 2]);
67 else
68 return Color(ColorAlpha, mpData[p + 3], mpData[p], mpData[p + 1], mpData[p + 2]);
69 }
70 // so we don't accidentally leave any code in that uses palette color indexes
71 void SetPixel(tools::Long nY, tools::Long nX, BitmapColor nColor) = delete;
72 tools::Long Height() const { return maSize.Height(); }
73 tools::Long Width() const { return maSize.Width(); }
74 sal_uInt8 GetBitCount() const { return mnBitCount; }
75};
76
77} // end vcl::bitmap
78
79/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 GetBlue() const
sal_uInt8 GetAlpha() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
constexpr tools::Long getHeight() const
constexpr tools::Long getWidth() const
Intended to be used to feed into CreateFromData to create a BitmapEx.
Definition: RawBitmap.hxx:22
void SetAlpha(tools::Long nY, tools::Long nX, sal_uInt8 nAlpha)
Definition: RawBitmap.hxx:56
sal_uInt8 GetBitCount() const
Definition: RawBitmap.hxx:74
void SetPixel(tools::Long nY, tools::Long nX, Color nColor)
Definition: RawBitmap.hxx:47
Color GetPixel(tools::Long nY, tools::Long nX) const
Definition: RawBitmap.hxx:62
tools::Long Height() const
Definition: RawBitmap.hxx:72
std::unique_ptr< sal_uInt8[]> mpData
Definition: RawBitmap.hxx:24
tools::Long Width() const
Definition: RawBitmap.hxx:73
RawBitmap(Size const &rSize, sal_uInt8 nBitCount)
Definition: RawBitmap.hxx:29
void SetPixel(tools::Long nY, tools::Long nX, BitmapColor nColor)=delete
ColorAlpha
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
::basegfx::B2IVector maSize
short nBitCount
Definition: ipict.cxx:80
void * p
long Long
BitmapEx CreateFromData(sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, vcl::PixelFormat ePixelFormat, bool bReversColors, bool bReverseAlpha)
Copy block of image data into the bitmap.
unsigned char sal_uInt8