169 lines
5.1 KiB
C++
169 lines
5.1 KiB
C++
#include <mdiwin/pwarp.hpp>
|
|
|
|
PerspectiveWarp::PerspectiveWarp(WORD width,WORD height,UHUGE *hpImageInvert,double wRow,double wCol)
|
|
: mWidth(width), mHeight(height),mwRow(wRow), mwCol(wCol),
|
|
mhpImageInvert(hpImageInvert), mWarpType(None),
|
|
mIsInThread(TRUE)
|
|
{
|
|
}
|
|
|
|
PerspectiveWarp::PerspectiveWarp(WORD width,WORD height,double wRow,double wCol,Operation colOp,double colIncr,Operation rowOp,double rowIncr,UHUGE *hpImageInvert)
|
|
: mWidth(width), mHeight(height), mwRow(wRow), mwCol(wCol),
|
|
mColOp(colOp), mColIncr(colIncr), mRowOp(rowOp), mRowIncr(rowIncr),
|
|
mhpImageInvert(hpImageInvert), mWarpType(Incremental),
|
|
mIsInThread(TRUE)
|
|
{
|
|
}
|
|
|
|
PerspectiveWarp::~PerspectiveWarp()
|
|
{
|
|
}
|
|
|
|
HGLOBAL PerspectiveWarp::performPerspectiveWarp(void)
|
|
{
|
|
if(Incremental==mWarpType)return incrementalWarp();
|
|
return nonIncrementalWarp();
|
|
}
|
|
|
|
HGLOBAL PerspectiveWarp::incrementalWarp(void)
|
|
{
|
|
int maxCol, maxRow;
|
|
double newRow, newCol, tempColFactor, tempRowFactor;
|
|
LONG rowMult, colMult, row, col;
|
|
HGLOBAL hGlobal, hGlobalTemp, hGlobalSource;
|
|
UHUGE *ptr;
|
|
UHUGE *ptrSource;
|
|
|
|
maxCol=maxRow=0L;
|
|
hGlobalSource=Main::upsideDown(mWidth,mHeight,mhpImageInvert);
|
|
ptrSource=(UHUGE*)::GlobalLock(hGlobalSource);
|
|
hGlobal=::GlobalAlloc(GMEM_FIXED,(LONG)mHeight*(LONG)mWidth);
|
|
ptr=(UHUGE*)::GlobalLock(hGlobal);
|
|
Main::hmemset(ptr,0,(LONG)mHeight*(LONG)mWidth);
|
|
tempRowFactor=mwRow;
|
|
for(row=0;row<mHeight;row++)
|
|
{
|
|
tempColFactor=mwCol;
|
|
for(col=0;col<mWidth;col++)
|
|
{
|
|
newCol=(col/((mwCol*col)+(mwRow*row)+1))+.5;
|
|
newRow=(row/((mwCol*col)+(mwRow*row)+1))+.5;
|
|
if(newRow>maxRow)maxRow=(int)newRow;
|
|
if(newCol>maxCol)maxCol=(int)newCol;
|
|
if(Add==mColOp)mwCol+=mColIncr;
|
|
else if(Subtract==mColOp)mwCol=(mwCol-mColIncr<0?0:mwCol-mColIncr);
|
|
else if(Multiply==mColOp)mwCol*=mColIncr;
|
|
else mwCol/=(mColIncr?mColIncr:1);
|
|
if(!yieldTask())return (HGLOBAL)emergencyCleanup(hGlobalSource,hGlobal);
|
|
}
|
|
mwCol=tempColFactor;
|
|
if(Add==mRowOp)mwRow+=mRowIncr;
|
|
else if(Subtract==mRowOp)mwRow=(mwRow-mRowIncr<0?0:mwRow-mRowIncr);
|
|
else if(Multiply==mRowOp)mwRow*=mRowIncr;
|
|
else mwRow/=(mRowIncr?mRowIncr:1);
|
|
}
|
|
rowMult=(mHeight/(maxRow?maxRow:1));
|
|
colMult=(mWidth/(maxCol?maxCol:1));
|
|
mwRow=tempRowFactor;
|
|
for(row=0;row<mHeight;row++)
|
|
{
|
|
tempColFactor=mwCol;
|
|
for(col=0;col<mWidth;col++)
|
|
{
|
|
newCol=((col/((mwCol*col)+(mwRow*row)+1)))*rowMult;
|
|
newRow=((row/((mwCol*col)+(mwRow*row)+1)))*colMult;
|
|
if(((LONG)newRow*(LONG)mWidth)+(LONG)newCol>=(LONG)mWidth*(LONG)mHeight)
|
|
continue;
|
|
*(ptr+((LONG)newRow*(LONG)mWidth)+(LONG)newCol)=
|
|
*(ptrSource+(row*(LONG)mWidth)+col);
|
|
if(Add==mColOp)mwCol+=mColIncr;
|
|
else if(Subtract==mColOp)mwCol=(mwCol-mColIncr<0?0:mwCol-mColIncr);
|
|
else if(Multiply==mColOp)mwCol*=mColIncr;
|
|
else mwCol/=(mColIncr?mColIncr:1);
|
|
if(!yieldTask())return (HGLOBAL)emergencyCleanup(hGlobalSource,hGlobal);
|
|
}
|
|
mwCol=tempColFactor;
|
|
if(Add==mRowOp)mwRow+=mRowIncr;
|
|
else if(Subtract==mRowOp)mwRow=(mwRow-mRowIncr<0?0:mwRow-mRowIncr);
|
|
else if(Multiply==mRowOp)mwRow*=mRowIncr;
|
|
else mwRow/=(mRowIncr?mRowIncr:1);
|
|
}
|
|
::GlobalUnlock(hGlobalSource);
|
|
::GlobalFree(hGlobalSource);
|
|
hGlobalTemp=Main::upsideDown(mWidth,mHeight,ptr);
|
|
::GlobalUnlock(hGlobal);
|
|
::GlobalFree(hGlobal);
|
|
return hGlobalTemp;
|
|
}
|
|
|
|
HGLOBAL PerspectiveWarp::nonIncrementalWarp(void)
|
|
{
|
|
int maxCol, maxRow;
|
|
double newRow, newCol;
|
|
LONG rowMult, colMult, row, col;
|
|
HGLOBAL hGlobal, hGlobalTemp, hGlobalSource;
|
|
UHUGE *ptr;
|
|
UHUGE *ptrSource;
|
|
|
|
maxCol=maxRow=0L;
|
|
hGlobalSource=Main::upsideDown(mWidth,mHeight,mhpImageInvert);
|
|
ptrSource=(UHUGE*)::GlobalLock(hGlobalSource);
|
|
hGlobal=::GlobalAlloc(GMEM_FIXED,(LONG)mHeight*(LONG)mWidth);
|
|
ptr=(UHUGE*)::GlobalLock(hGlobal);
|
|
Main::hmemset(ptr,0,(LONG)mHeight*(LONG)mWidth);
|
|
for(row=0;row<mHeight;row++)
|
|
{
|
|
for(col=0;col<mWidth;col++)
|
|
{
|
|
newCol=(col/((mwCol*col)+(mwRow*row)+1))+.5;
|
|
newRow=(row/((mwCol*col)+(mwRow*row)+1))+.5;
|
|
if(newRow>maxRow)maxRow=(int)newRow;
|
|
if(newCol>maxCol)maxCol=(int)newCol;
|
|
if(!yieldTask())return (HGLOBAL)emergencyCleanup(hGlobalSource,hGlobal);
|
|
}
|
|
}
|
|
rowMult=(mHeight/(maxRow?maxRow:1));
|
|
colMult=(mWidth/(maxCol?maxCol:1));
|
|
for(row=0;row<mHeight;row++)
|
|
{
|
|
for(col=0;col<mWidth;col++)
|
|
{
|
|
newCol=((col/((mwCol*col)+(mwRow*row)+1)))*rowMult;
|
|
newRow=((row/((mwCol*col)+(mwRow*row)+1)))*colMult;
|
|
if(((LONG)newRow*(LONG)mWidth)+(LONG)newCol>=(LONG)mWidth*(LONG)mHeight)
|
|
continue;
|
|
*(ptr+((LONG)newRow*(LONG)mWidth)+(LONG)newCol)=
|
|
*(ptrSource+(row*(LONG)mWidth)+col);
|
|
if(!yieldTask())return (HGLOBAL)emergencyCleanup(hGlobalSource,hGlobal);
|
|
}
|
|
}
|
|
::GlobalUnlock(hGlobalSource);
|
|
::GlobalFree(hGlobalSource);
|
|
hGlobalTemp=Main::upsideDown(mWidth,mHeight,ptr);
|
|
::GlobalUnlock(hGlobal);
|
|
::GlobalFree(hGlobal);
|
|
return hGlobalTemp;
|
|
}
|
|
|
|
WORD PerspectiveWarp::yieldTask(void)const
|
|
{
|
|
MSG msg;
|
|
|
|
while(::PeekMessage((MSG far *)&msg,0,0,0,PM_REMOVE))
|
|
{
|
|
::TranslateMessage(&msg);
|
|
::DispatchMessage(&msg);
|
|
}
|
|
return mIsInThread;
|
|
}
|
|
|
|
WORD PerspectiveWarp::emergencyCleanup(HGLOBAL hGlobalSource,HGLOBAL hGlobal)const
|
|
{
|
|
::GlobalUnlock(hGlobalSource);
|
|
::GlobalFree(hGlobalSource);
|
|
::GlobalUnlock(hGlobal);
|
|
::GlobalFree(hGlobal);
|
|
return FALSE;
|
|
}
|
|
|