216 lines
5.7 KiB
C++
216 lines
5.7 KiB
C++
#include <jpgimg/dib24.hpp>
|
|
#include <jpgimg/imginfo.hpp>
|
|
#include <jpgimg/asmutil.hpp>
|
|
#include <common/resbmp.hpp>
|
|
|
|
DIB24 &DIB24::operator=(const DIB24 &image)
|
|
{
|
|
PureDevice pureDevice;
|
|
RGB888 rgb888;
|
|
|
|
pureDevice.screenDevice();
|
|
create(image.width(),image.height(),pureDevice);
|
|
for(int row=0;row<height();row++)
|
|
{
|
|
for(int col=0;col<width();col++)
|
|
{
|
|
image.getAt(row,col,rgb888);
|
|
setAt(row,col,rgb888);
|
|
}
|
|
}
|
|
return *this;
|
|
}
|
|
|
|
bool DIB24::create(int width,int height,PureDevice &pureDevice)
|
|
{
|
|
destroy();
|
|
if(!width||!height||!pureDevice.isOkay())return false;
|
|
mBitmapInfo.rgbColors(0);
|
|
mBitmapInfo.bitCount(BitmapInfo::Bit24);
|
|
mBitmapInfo.width(width);
|
|
mBitmapInfo.height(height);
|
|
mBitmapInfo.planes(1);
|
|
mBitmapInfo.compression(BI_RGB);
|
|
mBitmapInfo.sizeImage(0);
|
|
mBitmapInfo.colorUsed(0);
|
|
mBitmapInfo.colorImportant(0);
|
|
verifyDimensions(mBitmapInfo);
|
|
mExtent=mBitmapInfo.width()*(mBitmapInfo.height()<0?-mBitmapInfo.height():mBitmapInfo.height());
|
|
mhBitmap=::CreateDIBSection((HDC)pureDevice,(BITMAPINFO*)mBitmapInfo,DIB_RGB_COLORS,(void**)&mpRGBArray,0,0);
|
|
return isOkay();
|
|
}
|
|
|
|
bool DIB24::bitBlt(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 DIB24::draw(PureDevice &pureDevice,const Rect &dstRect,const Point &srcPoint)
|
|
{
|
|
return bitBlt(pureDevice,dstRect,srcPoint);
|
|
}
|
|
|
|
void DIB24::verifyDimensions(BitmapInfo &someBitmapInfo)
|
|
{
|
|
DWORD desiredHeight(someBitmapInfo.height()<0?-someBitmapInfo.height():someBitmapInfo.height());
|
|
DWORD desiredWidth(someBitmapInfo.width());
|
|
DWORD imageExtent;
|
|
|
|
imageExtent=(((((LONG)desiredWidth*8)+31)&~31)>>3)*(LONG)desiredHeight;
|
|
if(imageExtent==(LONG)desiredWidth*(LONG)desiredHeight)return;
|
|
else desiredWidth=(WORD)(imageExtent/(LONG)desiredHeight);
|
|
someBitmapInfo.width(desiredWidth);
|
|
}
|
|
|
|
bool DIB24::setAt(DWORD row,DWORD col,JPGImage &jpgImage)
|
|
{
|
|
DWORD srcWidth;
|
|
DWORD srcHeight;
|
|
DWORD dstWidth;
|
|
DWORD dstHeight;
|
|
RGB888 *ptrSrcCol;
|
|
RGB888 *ptrDstCol;
|
|
|
|
if(!isOkay())return false;
|
|
srcWidth=jpgImage.width();
|
|
srcHeight=jpgImage.height();
|
|
dstWidth=mBitmapInfo.width();
|
|
dstHeight=mBitmapInfo.height()<0?-mBitmapInfo.height():mBitmapInfo.height();
|
|
for(int srcRow=0,dstRow=row;srcRow<srcHeight;srcRow++,dstRow++)
|
|
{
|
|
if(jpgImage.getBitmapInfo().height()<0)ptrSrcCol=&jpgImage.getRGBArray()[srcRow*jpgImage.width()];
|
|
else ptrSrcCol=&jpgImage.getRGBArray()[(jpgImage.getBitmapInfo().width()*(-jpgImage.getBitmapInfo().height()))-(((srcRow*jpgImage.getBitmapInfo().width())+jpgImage.getBitmapInfo().width()))];
|
|
if(mBitmapInfo.height()<0)ptrDstCol=&mpRGBArray[dstRow*width()+col];
|
|
else ptrDstCol=&mpRGBArray[(mBitmapInfo.width()*(-mBitmapInfo.height()))-(((dstRow*mBitmapInfo.width())+mBitmapInfo.width()))+col];
|
|
::memcpy(ptrDstCol,ptrSrcCol,srcWidth*sizeof(RGB888));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool DIB24::setAtAsm(DWORD row,DWORD col,JPGImage &jpgImage)
|
|
{
|
|
ImageInfo imageInfo;
|
|
|
|
if(!isOkay())return false;
|
|
imageInfo.setSrcParams(jpgImage.width(),jpgImage.height(),&jpgImage.getRGBArray()[0]);
|
|
imageInfo.setDstParams(width(),height(),&mpRGBArray[0]);
|
|
imageInfo.dstRow(row);
|
|
imageInfo.dstCol(col);
|
|
::setAt(&imageInfo);
|
|
return true;
|
|
}
|
|
|
|
bool DIB24::line(Point firstPoint,Point secondPoint,const RGB888 &rgb888)
|
|
{
|
|
int xRunning;
|
|
int yRunning;
|
|
int xDelta;
|
|
int yDelta;
|
|
short xDir(1);
|
|
short yDir(1);
|
|
short steps;
|
|
|
|
if(!isOkay())return false;
|
|
if(firstPoint.y()>height())firstPoint.y(height());
|
|
if(firstPoint.x()>width())firstPoint.x(width());
|
|
if(secondPoint.y()>height())secondPoint.y(height());
|
|
if(secondPoint.x()>width())secondPoint.x(width());
|
|
xRunning=(LONG)firstPoint.x()<<0x10;
|
|
yRunning=(LONG)firstPoint.y()<<0x10;
|
|
if(secondPoint.x()<firstPoint.x())xDir=-1;
|
|
if(secondPoint.y()<firstPoint.y())yDir=-1;
|
|
xDelta=(int)secondPoint.x()-(int)firstPoint.x();
|
|
yDelta=(int)secondPoint.y()-(int)firstPoint.y();
|
|
if(xDelta<0)xDelta=-xDelta;
|
|
if(yDelta<0)yDelta=-yDelta;
|
|
if(xDelta<yDelta)
|
|
{
|
|
xDelta<<=0x10;
|
|
if(yDelta)xDelta/=yDelta;
|
|
else xDelta=1L;
|
|
steps=yDelta;
|
|
yDelta=0x10000;
|
|
}
|
|
else
|
|
{
|
|
yDelta<<=0x10;
|
|
if(xDelta)yDelta/=xDelta;
|
|
else yDelta=1L;
|
|
steps=xDelta;
|
|
xDelta=0x10000;
|
|
}
|
|
if(-1==xDir&&-1==yDir)
|
|
{
|
|
for(short stepIndex=0;stepIndex<steps;stepIndex++)
|
|
{
|
|
setAt(yRunning>>0x10,xRunning>>0x10,rgb888);
|
|
xRunning-=xDelta;
|
|
yRunning-=yDelta;
|
|
}
|
|
}
|
|
else if(-1==xDir&&1==yDir)
|
|
{
|
|
for(short stepIndex=0;stepIndex<steps;stepIndex++)
|
|
{
|
|
setAt(yRunning>>0x10,xRunning>>0x10,rgb888);
|
|
xRunning-=xDelta;
|
|
yRunning+=yDelta;
|
|
}
|
|
}
|
|
else if(1==xDir&&-1==yDir)
|
|
{
|
|
for(short itemIndex=0;itemIndex<steps;itemIndex++)
|
|
{
|
|
setAt(yRunning>>0x10,xRunning>>0x10,rgb888);
|
|
xRunning+=xDelta;
|
|
yRunning-=yDelta;
|
|
}
|
|
}
|
|
else if(1==xDir&&1==yDir)
|
|
{
|
|
for(short itemIndex=0;itemIndex<steps;itemIndex++)
|
|
{
|
|
setAt(yRunning>>0x10,xRunning>>0x10,rgb888);
|
|
xRunning+=xDelta;
|
|
yRunning+=yDelta;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool DIB24::copyBits(ResBitmap &resBitmap)
|
|
{
|
|
if(BitmapInfo::Bit8!=resBitmap.bitCount())return false; // add code to handle other bitCounts
|
|
BYTE *pData=resBitmap.ptrData();
|
|
int srcWidth=resBitmap.width();
|
|
int srcHeight=resBitmap.height();
|
|
int dstWidth=width();
|
|
int dstHeight=height();
|
|
|
|
for(int col=0;col<dstWidth;col++)
|
|
{
|
|
for(int row=0;row<dstHeight;row++)
|
|
{
|
|
if(row>=srcHeight)continue;
|
|
if(col>=srcWidth)continue;
|
|
RGBColor color=resBitmap.paletteEntry(pData[row*dstWidth+col]);
|
|
RGB888 dibColor(color.red(),color.green(),color.blue());
|
|
setAt(row,col,dibColor);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|