Line data Source code
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 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _BGFX_RASTER_BPIXELRASTER_HXX
21 : #define _BGFX_RASTER_BPIXELRASTER_HXX
22 :
23 : #include <algorithm>
24 : #include <string.h>
25 : #include <sal/types.h>
26 : #include <basegfx/pixel/bpixel.hxx>
27 : #include <basegfx/basegfxdllapi.h>
28 :
29 : //////////////////////////////////////////////////////////////////////////////
30 : // predeclarations
31 :
32 : //////////////////////////////////////////////////////////////////////////////
33 :
34 : namespace basegfx
35 : {
36 : class BPixelRaster
37 : {
38 : private:
39 : // do not allow copy constructor and assignment operator
40 : BPixelRaster(const BPixelRaster&);
41 : BPixelRaster& operator=(const BPixelRaster&);
42 :
43 : protected:
44 : sal_uInt32 mnWidth;
45 : sal_uInt32 mnHeight;
46 : sal_uInt32 mnCount;
47 : BPixel* mpContent;
48 :
49 : public:
50 : // reset
51 0 : void reset()
52 : {
53 0 : memset(mpContent, 0, sizeof(BPixel) * mnCount);
54 0 : }
55 :
56 : // constructor/destructor
57 0 : BPixelRaster(sal_uInt32 nWidth, sal_uInt32 nHeight)
58 : : mnWidth(nWidth),
59 : mnHeight(nHeight),
60 : mnCount(nWidth * nHeight),
61 0 : mpContent(new BPixel[mnCount])
62 : {
63 0 : reset();
64 0 : }
65 :
66 0 : ~BPixelRaster()
67 : {
68 0 : delete [] mpContent;
69 0 : }
70 :
71 : // coordinate calcs between X/Y and span
72 0 : sal_uInt32 getIndexFromXY(sal_uInt32 nX, sal_uInt32 nY) const { return (nX + (nY * mnWidth)); }
73 : sal_uInt32 getXFromIndex(sal_uInt32 nIndex) const { return (nIndex % mnWidth); }
74 : sal_uInt32 getYFromIndex(sal_uInt32 nIndex) const { return (nIndex / mnWidth); }
75 :
76 : // data access read
77 0 : sal_uInt32 getWidth() const { return mnWidth; }
78 0 : sal_uInt32 getHeight() const { return mnHeight; }
79 : sal_uInt32 getCount() const { return mnCount; }
80 :
81 : // data access read only
82 0 : const BPixel& getBPixel(sal_uInt32 nIndex) const
83 : {
84 : #ifdef DBG_UTIL
85 : if(nIndex >= mnCount)
86 : {
87 : OSL_FAIL("getBPixel: Access out of range (!)");
88 : return BPixel::getEmptyBPixel();
89 : }
90 : #endif
91 0 : return mpContent[nIndex];
92 : }
93 :
94 : // data access read/write
95 0 : BPixel& getBPixel(sal_uInt32 nIndex)
96 : {
97 : #ifdef DBG_UTIL
98 : if(nIndex >= mnCount)
99 : {
100 : OSL_FAIL("getBPixel: Access out of range (!)");
101 : return mpContent[0L];
102 : }
103 : #endif
104 0 : return mpContent[nIndex];
105 : }
106 : };
107 : } // end of namespace basegfx
108 :
109 : #endif /* _BGFX_RASTER_BPIXELRASTER_HXX */
110 :
111 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|