lugre_bitmask.cpp
Go to the documentation of this file.00001 #include "lugre_prefix.h"
00002 #include "lugre_bitmask.h"
00003 #include <stdlib.h>
00004 #include <Ogre.h>
00005
00006 namespace Lugre {
00007
00008 cBitMask::cBitMask () : mpData(0), mbWrap(false) {}
00009 cBitMask::~cBitMask () { Reset(); }
00010
00011 void cBitMask::SetDataFromOgreImage (Ogre::Image& pImage,float fMinAlpha) {
00012 int w = pImage.getWidth();
00013 int h = pImage.getHeight();
00014 BlankData(w,h);
00015 for (int y=0;y<h;++y) for (int x=0;x<w;++x) {
00016 int iPixelOffset = y*w+x;
00017 if (pImage.getColourAt(x,y,0).a >= fMinAlpha) mpData[iPixelOffset/8] |= (1<<(iPixelOffset%8));
00018 }
00019 }
00020
00021 void cBitMask::SetDataFrom16BitImage (const short *pImageData16Bit,const int w,const int h) {
00022 BlankData(w,h);
00023 for (int y=0;y<h;++y) for (int x=0;x<w;++x) {
00024 int iPixelOffset = y*w+x;
00025 if (pImageData16Bit[iPixelOffset]) mpData[iPixelOffset/8] |= (1<<(iPixelOffset%8));
00026 }
00027 }
00028
00029 void cBitMask::BlankData (const int w,const int h) {
00030 Reset();
00031 miW = w;
00032 miH = h;
00033 int iDataSize = (w*h+7)/8;
00034 mpData = (char*)malloc(iDataSize);
00035 memset(mpData,0,iDataSize);
00036 }
00037
00038 void cBitMask::Reset () {
00039 if (mpData) free(mpData); mpData = 0;
00040 miW = 0;
00041 miH = 0;
00042 }
00043
00044 };