Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / basegfx / raster / bpixelraster.hxx
blob42620c7c01d7fd64dfbc985853b0f165feb46ce3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_BASEGFX_RASTER_BPIXELRASTER_HXX
21 #define INCLUDED_BASEGFX_RASTER_BPIXELRASTER_HXX
23 #include <memory>
24 #include <algorithm>
25 #include <string.h>
26 #include <sal/types.h>
27 #include <basegfx/pixel/bpixel.hxx>
28 #include <basegfx/basegfxdllapi.h>
30 namespace basegfx
32 class BPixelRaster
34 private:
35 BPixelRaster(const BPixelRaster&) = delete;
36 BPixelRaster& operator=(const BPixelRaster&) = delete;
38 protected:
39 sal_uInt32 mnWidth;
40 sal_uInt32 mnHeight;
41 sal_uInt32 mnCount;
42 std::unique_ptr<BPixel[]> mpContent;
44 public:
45 // reset
46 void reset()
48 memset(mpContent.get(), 0, sizeof(BPixel) * mnCount);
51 // constructor/destructor
52 BPixelRaster(sal_uInt32 nWidth, sal_uInt32 nHeight)
53 : mnWidth(nWidth),
54 mnHeight(nHeight),
55 mnCount(nWidth * nHeight),
56 mpContent(new BPixel[mnCount])
58 reset();
61 // coordinate calcs between X/Y and span
62 sal_uInt32 getIndexFromXY(sal_uInt32 nX, sal_uInt32 nY) const { return (nX + (nY * mnWidth)); }
64 // data access read
65 sal_uInt32 getWidth() const { return mnWidth; }
66 sal_uInt32 getHeight() const { return mnHeight; }
68 // data access read only
69 const BPixel& getBPixel(sal_uInt32 nIndex) const
71 assert(nIndex < mnCount && "Access out of range");
72 return mpContent[nIndex];
75 // data access read/write
76 BPixel& getBPixel(sal_uInt32 nIndex)
78 assert(nIndex < mnCount && "Access out of range");
79 return mpContent[nIndex];
82 } // end of namespace basegfx
84 #endif // INCLUDED_BASEGFX_RASTER_BPIXELRASTER_HXX
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */