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