156 lines
4.8 KiB
C++
156 lines
4.8 KiB
C++
//#include <mdiwin/main.hpp>
|
|
#include <mdiwin/spacial.hpp>
|
|
#include <mdiwin/string.hpp>
|
|
#include <mdiwin/main.hpp>
|
|
#include <stdio.h>
|
|
|
|
SpacialTransform::SpacialTransform(HPALETTE hPalette,UHUGE *hpImage,WORD width,WORD height,WORD sizeFactor)
|
|
: mSizeFactor(sizeFactor), mSrcWidth(width), mSrcHeight(height),
|
|
mInverseFactor(((float)100.00/(float)sizeFactor)*100.00),
|
|
mSrcExtent(mSrcWidth*mSrcHeight), mhpImage(hpImage),
|
|
mhPalette(hPalette), mIsInThread(TRUE)
|
|
{
|
|
loadPaletteEntries();
|
|
}
|
|
|
|
SpacialTransform::~SpacialTransform()
|
|
{
|
|
}
|
|
|
|
HGLOBAL SpacialTransform::resizeImage(void)
|
|
{
|
|
HGLOBAL hGlobalTemp;
|
|
|
|
DWORD startTime(::GetTickCount());
|
|
DWORD elapsedTime;
|
|
String timeBuffer;
|
|
|
|
mDstWidth=mSrcWidth*((float)mSizeFactor/100.00);
|
|
mDstHeight=mSrcHeight;
|
|
mDstExtent=mDstWidth*mDstHeight;
|
|
mhGlobal=::GlobalAlloc(GMEM_FIXED,mDstExtent);
|
|
if(!mhGlobal)return FALSE;
|
|
mhpDestinationImage=(UHUGE *)::GlobalLock(mhGlobal);
|
|
processTransform();
|
|
if(!mIsInThread)
|
|
{
|
|
::GlobalUnlock(mhGlobal);
|
|
::GlobalFree(mhGlobal);
|
|
return FALSE;
|
|
}
|
|
hGlobalTemp=Main::rotateRight(mhpDestinationImage,(WORD)mDstWidth,(WORD)mDstHeight);
|
|
::GlobalUnlock(mhGlobal);
|
|
::GlobalFree(mhGlobal);
|
|
if(!hGlobalTemp)return FALSE;
|
|
mhpImage=(UHUGE *)::GlobalLock(hGlobalTemp);
|
|
mSrcWidth=mDstHeight;
|
|
mSrcHeight=mDstWidth;
|
|
mSrcExtent=mSrcWidth*mSrcHeight;
|
|
mDstWidth=mSrcWidth*((float)mSizeFactor/100.00);
|
|
mDstHeight=mSrcHeight;
|
|
mDstExtent=mDstWidth*mDstHeight;
|
|
mhGlobal=::GlobalAlloc(GMEM_FIXED,mDstExtent);
|
|
if(!mhGlobal)
|
|
{
|
|
::GlobalUnlock(hGlobalTemp);
|
|
::GlobalFree(hGlobalTemp);
|
|
return FALSE;
|
|
}
|
|
mhpDestinationImage=(UHUGE *)::GlobalLock(mhGlobal);
|
|
processTransform();
|
|
::GlobalUnlock(hGlobalTemp);
|
|
::GlobalFree(hGlobalTemp);
|
|
hGlobalTemp=Main::rotateLeft(mhpDestinationImage,(WORD)mDstWidth,(WORD)mDstHeight);
|
|
::GlobalUnlock(mhGlobal);
|
|
::GlobalFree(mhGlobal);
|
|
Main::smlpStatusBar->setText("");
|
|
elapsedTime=(::GetTickCount()-startTime)/1000L;
|
|
::sprintf(timeBuffer,"Total seconds :%ld , Total minutes :%ld",
|
|
elapsedTime,elapsedTime/60L);
|
|
::MessageBox(::GetFocus(),(LPSTR)timeBuffer,(LPSTR)"TIME",MB_OK);
|
|
return hGlobalTemp;
|
|
}
|
|
|
|
void SpacialTransform::processTransform(void)
|
|
{
|
|
mInSegment=100;
|
|
mOutSegment=mInverseFactor;
|
|
mNextPixelIndex=-1;
|
|
mNextDestinationIndex=0;
|
|
mRedAccumulator=mGreenAccumulator=mBlueAccumulator=0L;
|
|
if(!nextPixel())return;
|
|
while(TRUE)
|
|
{
|
|
if(mOutSegment<=mInSegment)
|
|
{
|
|
mRedAccumulator+=((mInSegment*mCurrentRed)+((100L-mInSegment)*mNextRed))*mOutSegment;
|
|
mGreenAccumulator+=((mInSegment*mCurrentGreen)+((100L-mInSegment)*mNextGreen))*mOutSegment;
|
|
mBlueAccumulator+=((mInSegment*mCurrentBlue)+((100L-mInSegment)*mNextBlue))*mOutSegment;
|
|
mInSegment-=mOutSegment;
|
|
mOutSegment=mInverseFactor;
|
|
mRedAccumulator*=((float)mSizeFactor*.000001);
|
|
mGreenAccumulator*=((float)mSizeFactor*.000001);
|
|
mBlueAccumulator*=((float)mSizeFactor *.000001);
|
|
putPixel();
|
|
mRedAccumulator=mGreenAccumulator=mBlueAccumulator=0L;
|
|
}
|
|
else
|
|
{
|
|
mRedAccumulator+=((mInSegment*mCurrentRed)+((100L-mInSegment)*mNextRed))*mInSegment;
|
|
mGreenAccumulator+=((mInSegment*mCurrentGreen)+((100L-mInSegment)*mNextGreen))*mInSegment;
|
|
mBlueAccumulator+=((mInSegment*mCurrentBlue)+((100L-mInSegment)*mNextBlue))*mInSegment;
|
|
mOutSegment-=mInSegment;
|
|
mInSegment=100;
|
|
if(!nextPixel())break;
|
|
}
|
|
}
|
|
return;
|
|
}
|
|
|
|
UINT SpacialTransform::nextPixel(void)
|
|
{
|
|
UINT paletteIndex;
|
|
UINT nextPaletteIndex;
|
|
char Buffer[50];
|
|
|
|
if(!mIsInThread)return FALSE;
|
|
if(++mNextPixelIndex>=mSrcExtent)return FALSE;
|
|
paletteIndex=*(mhpImage+mNextPixelIndex);
|
|
if(mNextPixelIndex+1L>=mSrcExtent)nextPaletteIndex=paletteIndex;
|
|
else nextPaletteIndex=*(mhpImage+mNextPixelIndex+1L);
|
|
mCurrentRed=mPaletteData[paletteIndex].peRed;
|
|
mCurrentGreen=mPaletteData[paletteIndex].peGreen;
|
|
mCurrentBlue=mPaletteData[paletteIndex].peBlue;
|
|
if(paletteIndex==nextPaletteIndex)
|
|
{
|
|
mNextRed=mCurrentRed;
|
|
mNextGreen=mCurrentGreen;
|
|
mNextBlue=mCurrentBlue;
|
|
}
|
|
else
|
|
{
|
|
mNextRed=mPaletteData[nextPaletteIndex].peRed;
|
|
mNextGreen=mPaletteData[nextPaletteIndex].peGreen;
|
|
mNextBlue=mPaletteData[nextPaletteIndex].peBlue;
|
|
}
|
|
if(!(mNextPixelIndex%1000L))
|
|
{
|
|
::sprintf(Buffer,"Processing Line %ld",mNextPixelIndex);
|
|
Main::smlpStatusBar->setText(Buffer);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void SpacialTransform::putPixel()
|
|
{
|
|
Byte nearestIndex;
|
|
if(mNextDestinationIndex>=mDstExtent)return;
|
|
if(!mSimpleCache.locateItem(RGBStruct((BYTE)mRedAccumulator,(BYTE)mGreenAccumulator,(BYTE)mBlueAccumulator),nearestIndex))
|
|
{
|
|
*(mhpDestinationImage+mNextDestinationIndex)=nearestIndex=::GetNearestPaletteIndex(mhPalette,RGB((BYTE)mRedAccumulator,(BYTE)mGreenAccumulator,(BYTE)mBlueAccumulator));
|
|
mSimpleCache.insertItem(RGBStruct((BYTE)mRedAccumulator,(BYTE)mGreenAccumulator,(BYTE)mBlueAccumulator),nearestIndex);
|
|
}
|
|
else *(mhpDestinationImage+mNextDestinationIndex)=nearestIndex;
|
|
mNextDestinationIndex++;
|
|
}
|