📄 bdi.cpp
字号:
{
for(register int j=0;j<nLine;j++)
{
if(*pSourAddr != m_byColorKeyIndex)
{
*pDestAddr=GBDI::BDI_GrayTable[*pSourAddr];
}
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreenGrayDestColorKey(unsigned char*pBufDest,int nDestWidth,unsigned char*pBufSour,int nLine,int nRow,unsigned char byDestColorKey)
{
unsigned char*pDestAddr=pBufDest;
unsigned char*pSourAddr=pBufSour;
for(register int i=0;i<nRow;i++)
{
for(register int j=0;j<nLine;j++)
{
if(*pDestAddr != byDestColorKey)
{
*pDestAddr=GBDI::BDI_GrayTable[*pSourAddr];
}
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreenAdditiveNoColorKey(unsigned char*pBufDest,int nDestWidth,unsigned char*pBufSour,int nLine,int nRow)
{
unsigned char*pDestAddr=pBufDest;
unsigned char*pSourAddr=pBufSour;
for(register int i=0;i<nRow;i++)
{
for(register int j=0;j<nLine;j++)
{
*pDestAddr=GBDI::BDI_AdditiveTable[*pSourAddr][*pDestAddr];
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreenAdditiveSrcColorKey(unsigned char*pBufDest,int nDestWidth,unsigned char*pBufSour,int nLine,int nRow)
{
unsigned char*pDestAddr=pBufDest;
unsigned char*pSourAddr=pBufSour;
for(register int i=0;i<nRow;i++)
{
for(register int j=0;j<nLine;j++)
{
if(*pSourAddr != m_byColorKeyIndex)
{
*pDestAddr=GBDI::BDI_AdditiveTable[*pSourAddr][*pDestAddr];
}
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreenAdditiveDestColorKey(unsigned char*pBufDest,int nDestWidth,unsigned char*pBufSour,int nLine,int nRow,unsigned char byDestColorKey)
{
unsigned char*pDestAddr=pBufDest;
unsigned char*pSourAddr=pBufSour;
for(register int i=0;i<nRow;i++)
{
for(register int j=0;j<nLine;j++)
{
if(*pDestAddr != byDestColorKey)
{
*pDestAddr=GBDI::BDI_AdditiveTable[*pSourAddr][*pDestAddr];
}
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreenSubNoColorKey(unsigned char*pBufDest,int nDestWidth,unsigned char*pBufSour,int nLine,int nRow)
{
unsigned char*pDestAddr=pBufDest;
unsigned char*pSourAddr=pBufSour;
for(register int i=0;i<nRow;i++)
{
for(register int j=0;j<nLine;j++)
{
*pDestAddr=GBDI::BDI_SubTable[*pSourAddr][*pDestAddr];
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreenSubSrcColorKey(unsigned char*pBufDest,int nDestWidth,unsigned char*pBufSour,int nLine,int nRow)
{
unsigned char*pDestAddr=pBufDest;
unsigned char*pSourAddr=pBufSour;
for(register int i=0;i<nRow;i++)
{
for(register int j=0;j<nLine;j++)
{
if(*pSourAddr != m_byColorKeyIndex)
{
*pDestAddr=GBDI::BDI_SubTable[*pSourAddr][*pDestAddr];
}
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreenSubDestColorKey(unsigned char*pBufDest,int nDestWidth,unsigned char*pBufSour,int nLine,int nRow,unsigned char byDestColorKey)
{
unsigned char*pDestAddr=pBufDest;
unsigned char*pSourAddr=pBufSour;
for(register int i=0;i<nRow;i++)
{
for(register int j=0;j<nLine;j++)
{
if(*pDestAddr != byDestColorKey)
{
*pDestAddr=GBDI::BDI_SubTable[*pSourAddr][*pSourAddr];
}
pDestAddr++;
pSourAddr++;
}
pBufDest+=nDestWidth;
pBufSour+=m_nWidth;
pDestAddr=pBufDest;
pSourAddr=pBufSour;
}
}
void GBDI::DrawToScreen(GScreen*pScreen)
{
assert(pScreen!=NULL);
RECT rtDest={m_position.x,m_position.y,m_position.x+pScreen->GetWidth(),m_position.y+pScreen->GetHeight()};
RECT rtSour=m_rtShowArea;
if(rtDest.top<0)
{
rtSour.top-=rtDest.top;
rtDest.top=0;
}
if(rtDest.left<0)
{
rtSour.left-=rtDest.left;
rtDest.left=0;
}
if(rtDest.left+rtSour.right-rtSour.left>pScreen->GetWidth())
{
rtSour.right=rtSour.left+pScreen->GetWidth()-rtDest.left;
}
if(rtDest.top+rtSour.bottom-rtSour.top>pScreen->GetHeight())
{
rtSour.bottom=rtSour.top+pScreen->GetHeight()-rtDest.top;
}
unsigned char*pBufDest=pScreen->GetBuffer()+pScreen->GetWidth()*rtDest.top+rtDest.left;//目标地址
unsigned char*pBufSour=m_pData+m_nWidth*rtSour.top+rtSour.left;//源地址
int nLine=rtSour.right-rtSour.left;
int nRow=rtSour.bottom-rtSour.top;
switch(m_nShowMethod)
{
case BDI_NOCOLORKEY:
{
DrawToScreenNoColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_SRCCOLORKEY:
{
DrawToScreenSrcColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_DESTCOLORKEY:
{
DrawToScreenDestColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow,m_nArg>>8);
}
break;
case BDI_ALPHA:
{
DrawToScreenAlphaNoColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow,m_nArg & 0xF);
}
break;
case BDI_SRCCKALPHA:
{
DrawToScreenAlphaSrcColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow,m_nArg & 0xF);
}
break;
case BDI_DESTCKALPHA:
{
DrawToScreenAlphaDestColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow,m_nArg & 0xF,m_nArg>>8);
}
break;
case BDI_ADDITIVE:
{
DrawToScreenAdditiveNoColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_SRCCKADDITIVE:
{
DrawToScreenAdditiveSrcColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_DESTCKADDITIVE:
{
DrawToScreenAdditiveDestColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow,m_nArg>>8);
}
break;
case BDI_SUB:
{
DrawToScreenSubNoColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_SRCCKSUB:
{
DrawToScreenSubSrcColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_DESTCKSUB:
{
DrawToScreenSubDestColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow,m_nArg>>8);
}
break;
case BDI_GRAY:
{
DrawToScreenGrayNoColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_SRCCKGRAY:
{
DrawToScreenGraySrcColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow);
}
break;
case BDI_DESTCKGRAY:
{
DrawToScreenGrayDestColorKey(pBufDest,pScreen->GetWidth(),pBufSour,nLine,nRow,m_nArg>>8);
}
break;
default:
return;
}
}
GBDI::GBDI()
{
m_pData=NULL;
m_byColorKeyIndex=255;
m_bEnableTrans=false;
}
GBDI::~GBDI()
{
if(m_pData)
{
delete [] m_pData;
m_pData=NULL;
}
}
void GBDI::SetColorKeyRGB(unsigned r,unsigned g,unsigned b)
{
m_byColorKeyIndex=FindBestMatch(RGBTo16Bit565(r,g,b));
}
bool GBDI::LoadBDI(GFileLoader*pFileLoader,const string & strFileName)
{
GFileData fd;
if(!pFileLoader->LoadFile(strFileName,fd))
return false;
memcpy(&m_bdi,fd.GetData(),sizeof(m_bdi));
if(m_bdi.wID !=D_BDIID)
{
return false;
}
if(m_bdi.dwCompressedImageDataSize!=fd.GetSize()-sizeof(m_bdi))
{
return false;
}
m_nWidth=m_bdi.wWidth;
m_nHeight=m_bdi.wHeight;
if(m_pData)
delete [] m_pData;
m_pData=new unsigned char[m_bdi.dwOrgDataSize];
if(!m_pData)
{
return false;
}
long lCompressRet;
if(1==m_bdi.byCompress)//rle
{
lCompressRet=GTDecompress<GCompress8BitRLE>()(fd.GetData()+sizeof(m_bdi),fd.GetSize()-sizeof(m_bdi),m_pData);
}
else if(2==m_bdi.byCompress)//lzss
{
lCompressRet=GTDecompress<GCompressLZSS>()(fd.GetData()+sizeof(m_bdi),fd.GetSize()-sizeof(m_bdi),m_pData);
}
else if(0==m_bdi.byCompress)//none
{
lCompressRet=GTDecompress<GCompressNone>()(fd.GetData()+sizeof(m_bdi),fd.GetSize()-sizeof(m_bdi),m_pData);
}
else
{
lCompressRet=false;
}
if(!lCompressRet)
{
return false;
}
SetShowArea();
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -