uint16 Physics::GetMaskBits(std::vector<std::string> layerNames,GLboolean isColliding) { uint16 mask=0; for(int i =0 ;i<layerNames.size();++i) { mask |=GetMaskBits(layerNames[i],isColliding); } if(isColliding) return mask; return ~mask; }
HRESULT CImgBitsDIB::ComputeTransMask(LONG yFirst, LONG cLines, LONG lTrans, LONG lReplace) { DWORD* pdw; DWORD dwBits; BYTE* pb; int cb; int cbPad; int x, y, b; BYTE bTrans; Assert(_iBitCount == 8); if(lTrans < 0) { Assert(!_pvMaskBits); return S_OK; } // negate coordinate system for DIBs yFirst = _yHeight - cLines - yFirst; // Step 1: scan for transparent bits: if none, there's nothing to do (yet) bTrans = lTrans; if(!_pvMaskBits) { pb = (BYTE*)GetBits() + CbLine()*yFirst; cbPad = CbLine() - _xWidth; for(y=cLines; y-->0; pb+=cbPad) { for(x=_xWidth; x-->0; ) { if(*pb++ == bTrans) { HRESULT hr = AllocMask(); if(hr) { RRETURN(hr); } goto trans; } } } return S_OK; } trans: // Step 2: allocate and fill in the one-bit mask pdw = (DWORD*)((BYTE*)GetBits() + CbLine()*yFirst); pb = (BYTE*)GetMaskBits() + CbLineMask()*yFirst; cbPad = CbLineMask() - (_xWidth+7)/8; for(y=cLines; y-->0; pb+=cbPad) { for(x=_xWidth; x>0; x-=8) { dwBits = *pdw++; b = 0; b |= ((BYTE)dwBits != bTrans); b <<= 1; dwBits >>= 8; b |= ((BYTE)dwBits != bTrans); b <<= 1; dwBits >>= 8; b |= ((BYTE)dwBits != bTrans); b <<= 1; dwBits >>= 8; b |= ((BYTE)dwBits != bTrans); b <<= 1; if(x <= 4) { b = (b << 3) | 0xF; } else { dwBits = *pdw++; b |= ((BYTE)dwBits != bTrans); b <<= 1; dwBits >>= 8; b |= ((BYTE)dwBits != bTrans); b <<= 1; dwBits >>= 8; b |= ((BYTE)dwBits != bTrans); b <<= 1; dwBits >>= 8; b |= ((BYTE)dwBits != bTrans); } *pb++ = (BYTE)b; } } // Step 3: replace the transparent color if(lTrans != lReplace) { for(pb=(BYTE*)GetBits()+CbLine()*yFirst,cb=CbLine()*cLines; cb; pb+=1,cb-=1) { if(*pb == bTrans) { *pb = lReplace; } } } return S_OK; }