60 lines
2.1 KiB
C++
60 lines
2.1 KiB
C++
#include <mdiwin/resize.hpp>
|
|
#include <mdiwin/main.hpp>
|
|
|
|
Resize::Resize(int width,int height, const RECT ©Rect,HGLOBAL hGlobalImage)
|
|
: mIsCopyRect(TRUE), mCopyRect(copyRect), mhGlobalImage(hGlobalImage),
|
|
mOldWidth(width), mOldHeight(height), mNewWidth((copyRect.right-copyRect.left)+1),
|
|
mNewHeight((copyRect.bottom-copyRect.top)+1)
|
|
{
|
|
}
|
|
|
|
Resize::Resize(int width,int height,int newWidth, int newHeight, HGLOBAL hGlobalImage)
|
|
: mIsCopyRect(FALSE), mhGlobalImage(hGlobalImage), mOldWidth(width),
|
|
mOldHeight(height), mNewWidth(newWidth), mNewHeight(newHeight)
|
|
{
|
|
}
|
|
|
|
Resize::~Resize()
|
|
{
|
|
}
|
|
|
|
HGLOBAL Resize::resizeImage(void)
|
|
{
|
|
HGLOBAL hGlobalTemp;
|
|
HGLOBAL hGlobalCopy;
|
|
HGLOBAL hGlobalRegion;
|
|
UHUGE *ptrCopy;
|
|
UHUGE *ptrImage;
|
|
UHUGE *ptrRegion;
|
|
UHUGE *ptrTemp;
|
|
int destRow;
|
|
int srcRow;
|
|
Index i;
|
|
|
|
if(!mhGlobalImage)return mhGlobalImage;
|
|
if(!mIsCopyRect)::SetRect(&mCopyRect,0,0,mNewWidth-1,mNewHeight-1);
|
|
if(mCopyRect.right>=mOldWidth || mCopyRect.bottom>=mOldHeight)return FALSE;
|
|
hGlobalCopy=::GlobalAlloc(GMEM_FIXED,(LONG)mOldWidth*(LONG)mOldHeight);
|
|
if(!hGlobalCopy)return hGlobalCopy;
|
|
ptrCopy=(UHUGE *)::GlobalLock(hGlobalCopy);
|
|
ptrImage=(UHUGE *)::GlobalLock(mhGlobalImage);
|
|
for(i=0;i<mOldHeight;i++)
|
|
Main::hmemcpy(ptrCopy+(i*(LONG)mOldWidth),(ptrImage+((LONG)mOldHeight-i)*(LONG)mOldWidth)-(LONG)mOldWidth,mOldWidth);
|
|
::GlobalUnlock(mhGlobalImage);
|
|
hGlobalRegion=::GlobalAlloc(GMEM_FIXED,((LONG)mNewWidth*(LONG)mNewHeight));
|
|
ptrRegion=(UHUGE *)::GlobalLock(hGlobalRegion);
|
|
for(destRow=0,srcRow=mCopyRect.top;srcRow<=mCopyRect.bottom;srcRow++,destRow++)
|
|
Main::hmemcpy(ptrRegion+((LONG)destRow*(LONG)mNewWidth),
|
|
ptrCopy+((LONG)srcRow*(LONG)mOldWidth)+(LONG)mCopyRect.left,(LONG)mNewWidth);
|
|
::GlobalUnlock(hGlobalCopy);
|
|
::GlobalFree(hGlobalCopy);
|
|
hGlobalTemp=::GlobalAlloc(GMEM_FIXED,(LONG)mNewWidth*(LONG)mNewHeight);
|
|
ptrTemp=(UHUGE *)::GlobalLock(hGlobalTemp);
|
|
for(i=0;i<(LONG)mNewHeight;i++)
|
|
Main::hmemcpy(ptrTemp+(i*(LONG)mNewWidth),(ptrRegion+((LONG)mNewHeight-i)*(LONG)mNewWidth)-(LONG)mNewWidth,(LONG)mNewWidth);
|
|
::GlobalUnlock(hGlobalRegion);
|
|
::GlobalFree(hGlobalRegion);
|
|
::GlobalUnlock(hGlobalTemp);
|
|
return hGlobalTemp;
|
|
}
|