117 lines
3.3 KiB
C++
117 lines
3.3 KiB
C++
#include <stdio.h>
|
|
#include <math.h>
|
|
#include <mdiwin/main.hpp>
|
|
#include <mdiwin/shear.hpp>
|
|
|
|
HGLOBAL Shear::performShear(WORD &width,WORD &height,double hFraction,double gFraction,UHUGE *lpImage)
|
|
{
|
|
POINT workPoint;
|
|
HGLOBAL hGlobalImage;
|
|
HGLOBAL hGlobalSource;
|
|
UHUGE *ptrSource;
|
|
UHUGE *ptrImage;
|
|
double tempxPoint;
|
|
double tempyPoint;
|
|
double tempFraction;
|
|
|
|
mSourceWidth=width;
|
|
mSourceHeight=height;
|
|
mxSourceHalf=mSourceWidth/2;
|
|
mySourceHalf=mSourceHeight/2;
|
|
calculateDimensions(width,height,hFraction,gFraction);
|
|
hGlobalSource=Main::upsideDown(width,height,lpImage);
|
|
ptrSource=(UHUGE*)::GlobalLock(hGlobalSource);
|
|
hGlobalImage=::GlobalAlloc(GMEM_FIXED,(LONG)mDestWidth*(LONG)mDestHeight);
|
|
ptrImage=(UHUGE *)::GlobalLock(hGlobalImage);
|
|
Main::hmemset(ptrImage,0,(LONG)mDestWidth*(LONG)mDestHeight);
|
|
for(int row=0;row<mSourceHeight;row++)
|
|
{
|
|
for(int col=0;col<mSourceWidth;col++)
|
|
{
|
|
setPoint(col,row,workPoint);
|
|
cartesianPoint(workPoint);
|
|
tempFraction=hFraction*(double)workPoint.y;
|
|
if(tempFraction)tempFraction+=(tempFraction<0.00?-0.50:0.459);
|
|
tempxPoint=((double)workPoint.x+tempFraction);
|
|
if(tempxPoint)tempxPoint+=(tempxPoint<0.00?-0.50:0.459);
|
|
tempFraction=gFraction*(double)workPoint.x;
|
|
if(tempFraction)tempFraction+=(tempFraction<0.00?-0.50:0.459);
|
|
tempyPoint=(tempFraction+(double)workPoint.y);
|
|
if(tempyPoint)tempyPoint+=(tempyPoint<0.00?-0.50:0.459);
|
|
setPoint(tempxPoint,tempyPoint,workPoint);
|
|
imagePoint(workPoint);
|
|
*(ptrImage+((LONG)workPoint.y*(LONG)mDestWidth)+(LONG)workPoint.x)=
|
|
*(ptrSource+((LONG)row*(LONG)mSourceWidth)+(LONG)col);
|
|
}
|
|
}
|
|
|
|
|
|
::GlobalUnlock(hGlobalSource);
|
|
::GlobalFree(hGlobalSource);
|
|
hGlobalSource=Main::upsideDown(mDestWidth,mDestHeight,ptrImage);
|
|
::GlobalUnlock(hGlobalImage);
|
|
::GlobalFree(hGlobalImage);
|
|
width=mDestWidth;
|
|
height=mDestHeight;
|
|
return hGlobalSource;
|
|
}
|
|
|
|
void Shear::calculateDimensions(WORD width,WORD height,double xFactor,double yFactor)
|
|
{
|
|
POINT maxPoint;
|
|
POINT minPoint;
|
|
double tempPoint;
|
|
int maxx;
|
|
int minx;
|
|
int maxy;
|
|
int miny;
|
|
|
|
if(xFactor<0)
|
|
{
|
|
setPoint(0,0,minPoint);
|
|
setPoint(width-1,height-1,maxPoint);
|
|
}
|
|
else
|
|
{
|
|
setPoint(0,width-1,minPoint);
|
|
setPoint(width-1,0,maxPoint);
|
|
}
|
|
cartesianPoint(minPoint);
|
|
cartesianPoint(maxPoint);
|
|
tempPoint=xFactor*(double)maxPoint.y;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
tempPoint+=(double)maxPoint.x;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
maxx=tempPoint;
|
|
tempPoint=xFactor*(double)minPoint.y;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
tempPoint+=(double)minPoint.x;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
minx=tempPoint;
|
|
if(yFactor<0)
|
|
{
|
|
setPoint(width-1,height-1,minPoint);
|
|
setPoint(0,0,maxPoint);
|
|
}
|
|
else
|
|
{
|
|
setPoint(0,height-1,minPoint);
|
|
setPoint(width-1,0,maxPoint);
|
|
}
|
|
cartesianPoint(minPoint);
|
|
cartesianPoint(maxPoint);
|
|
tempPoint=yFactor*(double)minPoint.x;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
tempPoint+=(double)minPoint.y;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
miny=tempPoint;
|
|
tempPoint=yFactor*(double)maxPoint.x;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
tempPoint+=(double)maxPoint.y;
|
|
if(tempPoint)tempPoint+=(tempPoint<0?-.5:.459);
|
|
maxy=tempPoint;
|
|
mDestWidth=::abs(maxx)+::abs(minx)+1;
|
|
mDestHeight=::abs(maxy)+::abs(miny)+1;
|
|
mxDestHalf=::abs(minx);
|
|
}
|