Files
Work/browse/dib24.cpp
2024-08-07 09:12:07 -04:00

72 lines
2.5 KiB
C++

#include <browse/dib24.hpp>
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::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;
}
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;
}