152 lines
5.7 KiB
C++
152 lines
5.7 KiB
C++
#include <remotepsapp/pureimg.hpp>
|
|
#include <remotepsapp/rgb888.hpp>
|
|
#include <common/purehdc.hpp>
|
|
#include <remotepsapp/asmutil.hpp>
|
|
|
|
bool PureImage::draw(PureDevice &pureDevice)
|
|
{
|
|
PureDevice compatibleDevice;
|
|
if(!isOkay())return FALSE;
|
|
compatibleDevice.compatibleDevice(pureDevice);
|
|
compatibleDevice.select((GDIObj)mhBitmap,TRUE);
|
|
pureDevice.bitBlt(Rect(0,0,width(),height()),compatibleDevice,Point(0,0));
|
|
compatibleDevice.select((GDIObj)mhBitmap,FALSE);
|
|
return TRUE;
|
|
}
|
|
|
|
bool PureImage::draw(PureDevice &pureDevice,int xSrc,int ySrc)
|
|
{
|
|
PureDevice compatibleDevice;
|
|
if(!isOkay())return FALSE;
|
|
compatibleDevice.compatibleDevice(pureDevice);
|
|
compatibleDevice.select((GDIObj)mhBitmap,TRUE);
|
|
pureDevice.bitBlt(Rect(xSrc,ySrc,width(),height()),compatibleDevice,Point(0,0));
|
|
compatibleDevice.select((GDIObj)mhBitmap,FALSE);
|
|
return TRUE;
|
|
}
|
|
|
|
bool PureImage::draw(PureDevice &pureDevice,const Rect &dstRect,const Point &srcPoint)
|
|
{
|
|
PureDevice compatibleDevice;
|
|
if(!isOkay())return FALSE;
|
|
compatibleDevice.compatibleDevice(pureDevice);
|
|
compatibleDevice.select((GDIObj)mhBitmap,TRUE);
|
|
pureDevice.bitBlt(dstRect,compatibleDevice,srcPoint);
|
|
compatibleDevice.select((GDIObj)mhBitmap,FALSE);
|
|
return TRUE;
|
|
}
|
|
|
|
bool PureImage::stretch(PureDevice &pureDevice,const Point &xyPoint,int strwidth,int strheight)
|
|
{
|
|
PureDevice compatibleDevice;
|
|
if(!isOkay())return FALSE;
|
|
compatibleDevice.compatibleDevice(pureDevice);
|
|
compatibleDevice.select((GDIObj)mhBitmap,TRUE);
|
|
pureDevice.stretchBlt(Rect(xyPoint.x(),xyPoint.y(),strwidth,strheight),compatibleDevice,Rect(0,0,width(),height()));
|
|
compatibleDevice.select((GDIObj)mhBitmap,FALSE);
|
|
return FALSE;
|
|
}
|
|
|
|
bool PureImage::resample(PureDevice &pureDevice,int newWidth)
|
|
{
|
|
Array<RGB888> rgbArray;
|
|
Array<RGB888> tmpArray;
|
|
BitmapInfo bitmapInfo;
|
|
float heightFactor;
|
|
float aspectRatio;
|
|
int newHeight;
|
|
|
|
newWidth-=(newWidth%4); // align the width on DWORD boundary
|
|
if(!isOkay())return false;
|
|
aspectRatio=(float)width()/(float)height();
|
|
newHeight=(float)newWidth/aspectRatio;
|
|
heightFactor=(float)newHeight/height();
|
|
bitmapInfo.rgbColors(0);
|
|
bitmapInfo.bitCount(BitmapInfo::Bit24);
|
|
bitmapInfo.width(newWidth);
|
|
bitmapInfo.height(int((float)getBitmapInfo().height()*heightFactor));
|
|
bitmapInfo.planes(1);
|
|
bitmapInfo.compression(BI_RGB);
|
|
bitmapInfo.sizeImage(0);
|
|
bitmapInfo.colorUsed(0);
|
|
bitmapInfo.colorImportant(0);
|
|
tmpArray.size(bitmapInfo.width()*height());
|
|
for(int row=0;row<height();row++)::resampleClipRow(&getRGBArray()[(row*width())],&tmpArray[(row*newWidth)],width(),newWidth);
|
|
rgbArray.size(bitmapInfo.width()*(bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height()));
|
|
for(int col=0;col<bitmapInfo.width();col++)::resampleClipCol(&tmpArray[col],&rgbArray[col],height(),bitmapInfo.width(),bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height(),bitmapInfo.width());
|
|
destroy();
|
|
getBitmapInfo()=bitmapInfo;
|
|
getRGBArray()=rgbArray;
|
|
mhBitmap=::CreateDIBitmap((HDC)pureDevice,(BITMAPINFOHEADER*)getBitmapInfo(),CBM_INIT,&getRGBArray()[0],(BITMAPINFO*)getBitmapInfo(),DIB_RGB_COLORS);
|
|
return true;
|
|
}
|
|
|
|
bool PureImage::resample(PureDevice &pureDevice,int newWidth,int newHeight)
|
|
{
|
|
Array<RGB888> rgbArray;
|
|
Array<RGB888> tmpArray;
|
|
BitmapInfo bitmapInfo;
|
|
|
|
if(!isOkay())return false;
|
|
bitmapInfo.rgbColors(0);
|
|
bitmapInfo.bitCount(BitmapInfo::Bit24);
|
|
bitmapInfo.width(newWidth);
|
|
bitmapInfo.height(-newHeight);
|
|
bitmapInfo.planes(1);
|
|
bitmapInfo.compression(BI_RGB);
|
|
bitmapInfo.sizeImage(0);
|
|
bitmapInfo.colorUsed(0);
|
|
bitmapInfo.colorImportant(0);
|
|
bitmapInfo.verifyDimensions();
|
|
tmpArray.size(bitmapInfo.width()*(height()<0?-height():height()));
|
|
for(int row=0;row<height();row++)::resampleClipRow(&getRGBArray()[(row*width())],&tmpArray[(row*newWidth)],width()+1,newWidth);
|
|
rgbArray.size(bitmapInfo.width()*(bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height()));
|
|
for(int col=0;col<bitmapInfo.width();col++)::resampleClipCol(&tmpArray[col],&rgbArray[col],height(),bitmapInfo.width(),bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height(),bitmapInfo.width());
|
|
destroy();
|
|
getBitmapInfo()=bitmapInfo;
|
|
getRGBArray()=rgbArray;
|
|
mhBitmap=::CreateDIBitmap((HDC)pureDevice,(BITMAPINFOHEADER*)getBitmapInfo(),CBM_INIT,&getRGBArray()[0],(BITMAPINFO*)getBitmapInfo(),DIB_RGB_COLORS);
|
|
return true;
|
|
}
|
|
|
|
bool PureImage::resample(int newWidth,int newHeight)
|
|
{
|
|
Array<RGB888> rgbArray;
|
|
Array<RGB888> tmpArray;
|
|
BitmapInfo bitmapInfo;
|
|
|
|
if(!getRGBArray().size())return false;
|
|
bitmapInfo.rgbColors(0);
|
|
bitmapInfo.bitCount(BitmapInfo::Bit24);
|
|
bitmapInfo.width(newWidth);
|
|
bitmapInfo.height(-newHeight);
|
|
bitmapInfo.planes(1);
|
|
bitmapInfo.compression(BI_RGB);
|
|
bitmapInfo.sizeImage(0);
|
|
bitmapInfo.colorUsed(0);
|
|
bitmapInfo.colorImportant(0);
|
|
bitmapInfo.verifyDimensions();
|
|
tmpArray.size(bitmapInfo.width()*(height()<0?-height():height()));
|
|
for(int row=0;row<height();row++)::resampleClipRow(&getRGBArray()[(row*width())],&tmpArray[(row*newWidth)],width()+1,newWidth);
|
|
rgbArray.size(bitmapInfo.width()*(bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height()));
|
|
for(int col=0;col<bitmapInfo.width();col++)::resampleClipCol(&tmpArray[col],&rgbArray[col],height(),bitmapInfo.width(),bitmapInfo.height()<0?-bitmapInfo.height():bitmapInfo.height(),bitmapInfo.width());
|
|
destroy();
|
|
getBitmapInfo()=bitmapInfo;
|
|
getRGBArray()=rgbArray;
|
|
return true;
|
|
}
|
|
|
|
bool PureImage::getRawData(GlobalData<BYTE> &rawData)
|
|
{
|
|
return RawImage::getRawData(rawData);
|
|
}
|
|
|
|
bool PureImage::setRawData(GlobalData<BYTE> &rawData,PureDevice &pureDevice)
|
|
{
|
|
destroy();
|
|
if(!RawImage::setRawData(rawData))return false;
|
|
mhBitmap=::CreateDIBitmap((HDC)pureDevice,(BITMAPINFOHEADER*)getBitmapInfo(),CBM_INIT,&getRGBArray()[0],(BITMAPINFO*)getBitmapInfo(),DIB_RGB_COLORS);
|
|
return true;
|
|
}
|
|
|