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 32 ////////////////////////////////////////////////////////////////////////////// 33 // predeclarations 34 35 ////////////////////////////////////////////////////////////////////////////// 36 37 namespace basegfx 38 { 39 class BPixelRaster 40 { 41 private: 42 // do not allow copy constructor and assignment operator 43 BPixelRaster(const BPixelRaster&); 44 BPixelRaster& operator=(const BPixelRaster&); 45 46 protected: 47 sal_uInt32 mnWidth; 48 sal_uInt32 mnHeight; 49 sal_uInt32 mnCount; 50 BPixel* mpContent; 51 52 public: 53 // reset reset()54 void reset() 55 { 56 rtl_zeroMemory(mpContent, sizeof(BPixel) * mnCount); 57 } 58 59 // constructor/destructor BPixelRaster(sal_uInt32 nWidth,sal_uInt32 nHeight)60 BPixelRaster(sal_uInt32 nWidth, sal_uInt32 nHeight) 61 : mnWidth(nWidth), 62 mnHeight(nHeight), 63 mnCount(nWidth * nHeight), 64 mpContent(new BPixel[mnCount]) 65 { 66 reset(); 67 } 68 ~BPixelRaster()69 ~BPixelRaster() 70 { 71 delete [] mpContent; 72 } 73 74 // coordinate calcs between X/Y and span getIndexFromXY(sal_uInt32 nX,sal_uInt32 nY) const75 sal_uInt32 getIndexFromXY(sal_uInt32 nX, sal_uInt32 nY) const { return (nX + (nY * mnWidth)); } getXFromIndex(sal_uInt32 nIndex) const76 sal_uInt32 getXFromIndex(sal_uInt32 nIndex) const { return (nIndex % mnWidth); } getYFromIndex(sal_uInt32 nIndex) const77 sal_uInt32 getYFromIndex(sal_uInt32 nIndex) const { return (nIndex / mnWidth); } 78 79 // data access read getWidth() const80 sal_uInt32 getWidth() const { return mnWidth; } getHeight() const81 sal_uInt32 getHeight() const { return mnHeight; } getCount() const82 sal_uInt32 getCount() const { return mnCount; } 83 84 // data access read only getBPixel(sal_uInt32 nIndex) const85 const BPixel& getBPixel(sal_uInt32 nIndex) const 86 { 87 #ifdef DBG_UTIL 88 if(nIndex >= mnCount) 89 { 90 OSL_ENSURE(false, "getBPixel: Access out of range (!)"); 91 return BPixel::getEmptyBPixel(); 92 } 93 #endif 94 return mpContent[nIndex]; 95 } 96 97 // data access read/write getBPixel(sal_uInt32 nIndex)98 BPixel& getBPixel(sal_uInt32 nIndex) 99 { 100 #ifdef DBG_UTIL 101 if(nIndex >= mnCount) 102 { 103 OSL_ENSURE(false, "getBPixel: Access out of range (!)"); 104 return mpContent[0L]; 105 } 106 #endif 107 return mpContent[nIndex]; 108 } 109 }; 110 } // end of namespace basegfx 111 112 #endif /* _BGFX_RASTER_BPIXELRASTER_HXX */ 113