1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _BGFX_RASTER_BPIXELRASTER_HXX
29 #define _BGFX_RASTER_BPIXELRASTER_HXX
30 
31 #include <algorithm>
32 #include <sal/types.h>
33 #include <basegfx/pixel/bpixel.hxx>
34 #include <rtl/memory.h>
35 
36 //////////////////////////////////////////////////////////////////////////////
37 // predeclarations
38 
39 //////////////////////////////////////////////////////////////////////////////
40 
41 namespace basegfx
42 {
43 	class BPixelRaster
44 	{
45 	private:
46 		// do not allow copy constructor and assignment operator
47 		BPixelRaster(const BPixelRaster&);
48 		BPixelRaster& operator=(const BPixelRaster&);
49 
50 	protected:
51 		sal_uInt32					mnWidth;
52 		sal_uInt32					mnHeight;
53 		sal_uInt32					mnCount;
54 		BPixel*						mpContent;
55 
56 	public:
57 		// reset
58 		void reset()
59 		{
60             rtl_zeroMemory(mpContent, sizeof(BPixel) * mnCount);
61 		}
62 
63 		// constructor/destructor
64 		BPixelRaster(sal_uInt32 nWidth, sal_uInt32 nHeight)
65 		:	mnWidth(nWidth),
66 			mnHeight(nHeight),
67 			mnCount(nWidth * nHeight),
68 			mpContent(new BPixel[mnCount])
69 		{
70 			reset();
71 		}
72 
73 		~BPixelRaster()
74 		{
75 			delete [] mpContent;
76 		}
77 
78 		// coordinate calcs between X/Y and span
79 		sal_uInt32 getIndexFromXY(sal_uInt32 nX, sal_uInt32 nY) const { return (nX + (nY * mnWidth)); }
80 		sal_uInt32 getXFromIndex(sal_uInt32 nIndex) const { return (nIndex % mnWidth); }
81 		sal_uInt32 getYFromIndex(sal_uInt32 nIndex) const { return (nIndex / mnWidth); }
82 
83 		// data access read
84 		sal_uInt32 getWidth() const { return mnWidth; }
85 		sal_uInt32 getHeight() const { return mnHeight; }
86 		sal_uInt32 getCount() const { return mnCount; }
87 
88 		// data access read only
89 		const BPixel& getBPixel(sal_uInt32 nIndex) const
90 		{
91 #ifdef DBG_UTIL
92 			if(nIndex >= mnCount)
93 			{
94 				OSL_ENSURE(false, "getBPixel: Access out of range (!)");
95 				return BPixel::getEmptyBPixel();
96 			}
97 #endif
98 			return mpContent[nIndex];
99 		}
100 
101 		// data access read/write
102 		BPixel& getBPixel(sal_uInt32 nIndex)
103 		{
104 #ifdef DBG_UTIL
105 			if(nIndex >= mnCount)
106 			{
107 				OSL_ENSURE(false, "getBPixel: Access out of range (!)");
108 				return mpContent[0L];
109 			}
110 #endif
111 			return mpContent[nIndex];
112 		}
113 	};
114 } // end of namespace basegfx
115 
116 #endif /* _BGFX_RASTER_BPIXELRASTER_HXX */
117