#include #include #include WINGBlt::WINGBlt(WORD width,WORD height,PurePalette &somePurePalette) : mhWINGDC(0), mDisposition(InvalidDC), mhWINGBitmap(0), mIsOkay(FALSE), mhLibrary(0), mlpfnWINGCreateDC(0), mlpfnWINGCreateBitmap(0), mlpWINGData(0), mlpfnWINGBitBlt(0), mlpfnWINGStretchBlt(0), mOrientation(BottomUp), mWINGBitmapExtent(0L), mhOldBitmap(0) { if(!initWING())return; getDIBFormat(); mWINGPalette=somePurePalette; mWINGPalette.identityPalette(); mWINGBitmapInfo=mWINGPalette; createWINGBitmap(width,height); } WINGBlt::~WINGBlt() { destroyBitmap(); destroyDevice(); freeLibrary(); } WORD WINGBlt::size(WORD width,WORD height) { if(!isOkay())return FALSE; return createWINGBitmap(width,height); } void WINGBlt::getDIBFormat(void) { BitmapInfo bitmapInfo; (*mlpfnWINGRecommendDIBFormat)(bitmapInfo); mOrientation=(Orientation)bitmapInfo.height(); } WORD WINGBlt::createWINGBitmap(WORD width,WORD height) { destroyBitmap(); createDevice(); getRequiredWidth(width,height); mWINGBitmapExtent=(DWORD)width*(DWORD)height; mWINGBitmapInfo.width(width); mWINGBitmapInfo.height(height*(int)mOrientation); mhWINGBitmap=(*mlpfnWINGCreateBitmap)(mhWINGDC,mWINGBitmapInfo,(void**)&mlpWINGData); if(!mhWINGBitmap)return mIsOkay=FALSE; setBits(mlpWINGData,mWINGBitmapExtent,0); mhOldBitmap=(HBITMAP)::SelectObject(mhWINGDC,mhWINGBitmap); return mIsOkay=TRUE; } WINGBlt &WINGBlt::operator+=(BitmapOverlay &someBitmapOverlay) { Point placementPoint; DWORD newSrcY; DWORD newDstY; DWORD srcIndex; DWORD dstIndex; UINT srcRow; UINT srcCol; if(!isOkay())return *this; placementPoint=someBitmapOverlay.placementPoint(); switch(mOrientation) { case TopDown : for(srcRow=0;srcRow=mWINGBitmapInfo.height()||col>=mWINGBitmapInfo.width())return; if(TopDown==mOrientation)setByteTopDown(row,col,byteValue); else setByteBottomUp(row,col,byteValue); } BYTE WINGBlt::getByte(WORD row,WORD col)const { if(!isOkay())return (BYTE)FALSE; if(row>=mWINGBitmapInfo.height()||col>=mWINGBitmapInfo.width())return (BYTE)FALSE; if(TopDown==mOrientation)return getByteTopDown(row,col); else return getByteBottomUp(row,col); } void WINGBlt::line(const Point &firstPoint,const Point &secondPoint,BYTE byteValue) { LONG xRunning((LONG)firstPoint.x()<<0x10); LONG yRunning((LONG)firstPoint.y()<<0x10); LONG xDelta; LONG yDelta; short xDir(1); short yDir(1); short steps; if(secondPoint.x()>0x10,xRunning>>0x10,byteValue); xRunning-=xDelta; yRunning-=yDelta; } } else if(-1==xDir&&1==yDir) { for(short stepIndex=0;stepIndex>0x10,xRunning>>0x10,byteValue); xRunning-=xDelta; yRunning+=yDelta; } } else if(1==xDir&&-1==yDir) { for(short itemIndex=0;itemIndex>0x10,xRunning>>0x10,byteValue); xRunning+=xDelta; yRunning-=yDelta; } } else if(1==xDir&&1==yDir) { for(short itemIndex=0;itemIndex>0x10,xRunning>>0x10,byteValue); xRunning+=xDelta; yRunning+=yDelta; } } } void WINGBlt::setColTopDown(WORD col,WORD row,char FAR *lpColData,WORD wDataLength) { UHUGE *lpImage=mlpWINGData+(LONG)col; lpImage+=((LONG)row*mWINGBitmapInfo.width()); for(;(short)row>=0&&wDataLength;row--) { *lpImage=*lpColData; lpImage-=mWINGBitmapInfo.width(); lpColData--; wDataLength--; } return; } void WINGBlt::setColBottomUp(WORD col,WORD row,char FAR *lpColData,WORD wDataLength) { UHUGE *lpImage=mlpWINGData+(LONG)col; lpImage+=(mWINGBitmapInfo.width()*((mWINGBitmapInfo.height()-1L)-(LONG)row)); for(;(short)row>=0&&wDataLength;row--) { *lpImage=*lpColData; lpImage+=mWINGBitmapInfo.width(); lpColData--; wDataLength--; } } void WINGBlt::setColBottomUp(WORD col,char FAR *lpColData) { UHUGE *lpImage=mlpWINGData+mWINGBitmapInfo.width()*mWINGBitmapInfo.height(); lpImage=(lpImage-mWINGBitmapInfo.width())+(LONG)col; for(short rowIndex=0;rowIndex>3)*(LONG)desiredHeight; if(imageExtent==(LONG)desiredWidth*(LONG)desiredHeight)return; desiredWidth=(WORD)(imageExtent/(LONG)desiredHeight); } #if defined(__FLAT__) WORD WINGBlt::initWING(void) { String wingDLLFileName("WING32.DLL"); String wingDLLPathFileName; DWORD wingBitBltOrdinal(1L); DWORD wingStretchBltOrdinal(10L); DWORD wingCreateBitmapOrdinal(2L); DWORD wingCreateDCOrdinal(3L); DWORD wingRecommendDIBFormatOrdinal(8); PathFind pathFind; if(!pathFind.findFile(wingDLLFileName,wingDLLPathFileName))return FALSE; if((mhLibrary=::LoadLibrary(wingDLLPathFileName))<(HINSTANCE)HINSTANCE_ERROR)return FALSE; mlpfnWINGCreateDC=(LPFNWINGCREATEDC)::GetProcAddress(mhLibrary,(LPCSTR)wingCreateDCOrdinal); mlpfnWINGCreateBitmap=(LPFNWINGCREATEBITMAP)::GetProcAddress(mhLibrary,(LPCSTR)wingCreateBitmapOrdinal); mlpfnWINGBitBlt=(LPFNWINGBITBLT)::GetProcAddress(mhLibrary,(LPCSTR)wingBitBltOrdinal); mlpfnWINGStretchBlt=(LPFNWINGSTRETCHBLT)::GetProcAddress(mhLibrary,(LPCSTR)wingStretchBltOrdinal); mlpfnWINGRecommendDIBFormat=(LPFNWINGRECOMMENDDIBFORMAT)::GetProcAddress(mhLibrary,(LPCSTR)wingRecommendDIBFormatOrdinal); if(!mlpfnWINGCreateDC)throw(NullError()); if(!mlpfnWINGCreateBitmap)throw(NullError()); if(!mlpfnWINGBitBlt)throw(NullError()); if(!mlpfnWINGStretchBlt)throw(NullError()); if(!mlpfnWINGRecommendDIBFormat)throw(NullError()); return TRUE; } #else WORD WINGBlt::initWING(void) { String wingDLLFileName("WING.DLL"); String wingDLLPathFileName; DWORD wingBitBltOrdinal(1010L); DWORD wingStretchBltOrdinal(1009L); DWORD wingCreateBitmapOrdinal(1003L); DWORD wingCreateDCOrdinal(1001L); DWORD wingRecommendDIBFormatOrdinal(1002); PathFind pathFind; if(!pathFind.findFile(wingDLLFileName,wingDLLPathFileName))return FALSE; if((mhLibrary=::LoadLibrary(wingDLLPathFileName))