1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _BGFX_RASTER_BPIXELRASTER_HXX
25 #define _BGFX_RASTER_BPIXELRASTER_HXX
26 
27 #include <algorithm>
28 #include <sal/types.h>
29 #include <basegfx/pixel/bpixel.hxx>
30 #include <rtl/memory.h>
31 #include <basegfx/basegfxdllapi.h>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 // predeclarations
35 
36 //////////////////////////////////////////////////////////////////////////////
37 
38 namespace basegfx
39 {
40 	class BASEGFX_DLLPUBLIC BPixelRaster
41 	{
42 	private:
43 		// do not allow copy constructor and assignment operator
44 		BPixelRaster(const BPixelRaster&);
45 		BPixelRaster& operator=(const BPixelRaster&);
46 
47 	protected:
48 		sal_uInt32					mnWidth;
49 		sal_uInt32					mnHeight;
50 		sal_uInt32					mnCount;
51 		BPixel*						mpContent;
52 
53 	public:
54 		// reset
reset()55 		void reset()
56 		{
57             rtl_zeroMemory(mpContent, sizeof(BPixel) * mnCount);
58 		}
59 
60 		// constructor/destructor
BPixelRaster(sal_uInt32 nWidth,sal_uInt32 nHeight)61 		BPixelRaster(sal_uInt32 nWidth, sal_uInt32 nHeight)
62 		:	mnWidth(nWidth),
63 			mnHeight(nHeight),
64 			mnCount(nWidth * nHeight),
65 			mpContent(new BPixel[mnCount])
66 		{
67 			reset();
68 		}
69 
~BPixelRaster()70 		~BPixelRaster()
71 		{
72 			delete [] mpContent;
73 		}
74 
75 		// coordinate calcs between X/Y and span
getIndexFromXY(sal_uInt32 nX,sal_uInt32 nY) const76 		sal_uInt32 getIndexFromXY(sal_uInt32 nX, sal_uInt32 nY) const { return (nX + (nY * mnWidth)); }
getXFromIndex(sal_uInt32 nIndex) const77 		sal_uInt32 getXFromIndex(sal_uInt32 nIndex) const { return (nIndex % mnWidth); }
getYFromIndex(sal_uInt32 nIndex) const78 		sal_uInt32 getYFromIndex(sal_uInt32 nIndex) const { return (nIndex / mnWidth); }
79 
80 		// data access read
getWidth() const81 		sal_uInt32 getWidth() const { return mnWidth; }
getHeight() const82 		sal_uInt32 getHeight() const { return mnHeight; }
getCount() const83 		sal_uInt32 getCount() const { return mnCount; }
84 
85 		// data access read only
getBPixel(sal_uInt32 nIndex) const86 		const BPixel& getBPixel(sal_uInt32 nIndex) const
87 		{
88 #ifdef DBG_UTIL
89 			if(nIndex >= mnCount)
90 			{
91 				OSL_ENSURE(false, "getBPixel: Access out of range (!)");
92 				return BPixel::getEmptyBPixel();
93 			}
94 #endif
95 			return mpContent[nIndex];
96 		}
97 
98 		// data access read/write
getBPixel(sal_uInt32 nIndex)99 		BPixel& getBPixel(sal_uInt32 nIndex)
100 		{
101 #ifdef DBG_UTIL
102 			if(nIndex >= mnCount)
103 			{
104 				OSL_ENSURE(false, "getBPixel: Access out of range (!)");
105 				return mpContent[0L];
106 			}
107 #endif
108 			return mpContent[nIndex];
109 		}
110 	};
111 } // end of namespace basegfx
112 
113 #endif /* _BGFX_RASTER_BPIXELRASTER_HXX */
114