📄 dib.cpp
字号:
}//end if
for(long j=i;j<GetWidth();j+=nDeta)
pDC->Rectangle (x+j,y,x+j+1,y+GetHeight());
i++;
break;
}//end of case EFFECT_VBLIND
}//end of switch
Delay(dwDelayTime);
}//end of while
MemDC.SelectObject (pOldBmp);
pDC->SelectPalette (pOldPal,TRUE);
CBrush* pBrush=pDC->SelectObject (pOldBrush);
return TRUE;
}
BOOL CDib::DisplayFadeIn(CDC *pDC, int x, int y, int nDeta, DWORD dwDelayTime)
{
//back up DIB
HDIB hDib=CopyHandle(m_hDib);
//get color number
WORD wNumColors=GetColorNumber();
BITMAPINFO *bmi=(BITMAPINFO*)GlobalLock(m_hDib);
BITMAPINFO *bmi0=(BITMAPINFO*)GlobalLock(hDib);
if(!bmi)
return FALSE;
BOOL bDone=FALSE;
int nDetaR,nDetaG,nDetaB;
//fade in
if(wNumColors)//there is a palette
{
//build black image
for(WORD i=0;i<wNumColors;++i)
{
bmi->bmiColors [i].rgbRed =0;
bmi->bmiColors [i].rgbBlue =0;
bmi->bmiColors [i].rgbGreen =0;
}
//display black first
UpdateInternal();
Display(pDC,x,y,SRCCOPY);
while(!bDone)
{
bDone=TRUE;
for(WORD i=0;i<wNumColors;i++)
{
nDetaR=UPVALUE(bmi0->bmiColors[i].rgbRed -
bmi->bmiColors [i].rgbRed ,nDeta);
nDetaG=UPVALUE(bmi0->bmiColors[i].rgbGreen -
bmi->bmiColors [i].rgbGreen ,nDeta);
nDetaB=UPVALUE(bmi0->bmiColors[i].rgbBlue -
bmi->bmiColors [i].rgbBlue ,nDeta);
if(!Fade(nDetaR,nDetaG,nDetaB,
bmi0->bmiColors [i].rgbRed ,
bmi0->bmiColors [i].rgbGreen,
bmi0->bmiColors [i].rgbBlue,
&(bmi->bmiColors [i].rgbRed),
&(bmi->bmiColors [i].rgbGreen),
&(bmi->bmiColors [i].rgbBlue)))
bDone=FALSE;
}
UpdateInternal();
Display(pDC,x,y,SRCCOPY);
Delay(dwDelayTime);
nDeta--;
}
}
else
//no palette
{
//should increase the speed
dwDelayTime/=10;
//bits position
LPBITMAPINFOHEADER lpbi=(LPBITMAPINFOHEADER)bmi;
LPBYTE lpBits=(LPBYTE)lpbi+lpbi->biSize ;
LPBYTE lpBits0=(LPBYTE)bmi0+lpbi->biSize ;
int nDelta=WIDTHBYTES(lpbi->biBitCount *lpbi->biWidth) -
lpbi->biWidth *lpbi->biBitCount /8;
int nx,ny;
//build black image
for(ny=0;ny<lpbi->biHeight ;ny++)
{
for(nx=0;nx<lpbi->biWidth ;nx++)
{
*lpBits++=0;
*lpBits++=0;
*lpBits++=0;
}
lpBits+=nDelta;
}
lpBits=(LPBYTE)lpbi+lpbi->biSize ;
//display black first
UpdateInternal();
Display(pDC,x,y,SRCCOPY);
BYTE r,g,b,r0,g0,b0;
while(!bDone)
{
bDone=TRUE;
for(ny=0;ny<lpbi->biHeight ;ny++)
{
for(nx=0;nx<lpbi->biWidth ;nx++)
{
b0=(BYTE)*lpBits0++;
g0=(BYTE)*lpBits0++;
r0=(BYTE)*lpBits0++;
b=(BYTE)*lpBits;
g=(BYTE)*(lpBits+1);
r=(BYTE)*(lpBits+2);
nDetaR=UPVALUE(r0-r,nDeta);
nDetaG=UPVALUE(g0-g,nDeta);
nDetaB=UPVALUE(b0-b,nDeta);
if(!Fade(nDetaR,nDetaG,nDetaB,r0,g0,b0,
&r,&g,&b))
bDone=FALSE;
*lpBits++=b;
*lpBits++=g;
*lpBits++=r;
}
*lpBits+=nDelta;
*lpBits0+=nDelta;
}
lpBits=(LPBYTE)lpbi+lpbi->biSize ;
lpBits0=(LPBYTE)bmi0+lpbi->biSize ;
UpdateInternal();
Display(pDC,x,y,SRCCOPY);
Delay(dwDelayTime);
nDeta--;
}
}
//clean up
GlobalUnlock(m_hDib);
GlobalUnlock(hDib);
//restore DIB
m_hDib=CopyHandle(hDib);
GlobalFree(hDib);
return TRUE;
}
BOOL CDib::DisplayFadeOut(CDC *pDC, int x, int y, int nDeta, DWORD dwDelayTime)
{
//display first
Display(pDC,x,y,SRCCOPY);
//back up DIB
HDIB hDib=CopyHandle(m_hDib);
//get color number
WORD wNumColors=GetColorNumber();
BITMAPINFO *bmi=(BITMAPINFO*)GlobalLock(m_hDib);
if(!bmi)
return FALSE;
BOOL bDone=FALSE;
int nDetaR,nDetaG,nDetaB;
//fade out
if(wNumColors)//there is a palette
{
while(!bDone)
{
bDone=TRUE;
for(WORD i=0;i<wNumColors;i++)
{
nDetaR=-1*UPVALUE(bmi->bmiColors [i].rgbRed ,nDeta);
nDetaG=-1*UPVALUE(bmi->bmiColors [i].rgbGreen ,nDeta);
nDetaB=-1*UPVALUE(bmi->bmiColors [i].rgbBlue ,nDeta);
if(!Fade(nDetaR,nDetaG,nDetaB,
0,0,0,
&(bmi->bmiColors [i].rgbRed),
&(bmi->bmiColors [i].rgbGreen),
&(bmi->bmiColors [i].rgbBlue)))
bDone=FALSE;
}
UpdateInternal();
Display(pDC,x,y,SRCCOPY);
Delay(dwDelayTime);
nDeta--;
}
}
else
//no palette
{
//should increase the speed
dwDelayTime/=10;
//bits position
LPBITMAPINFOHEADER lpbi=(LPBITMAPINFOHEADER)bmi;
LPBYTE lpBits=(LPBYTE)lpbi+lpbi->biSize ;
int nDelta=WIDTHBYTES(lpbi->biBitCount *lpbi->biWidth) -
lpbi->biWidth *lpbi->biBitCount /8;
int nx,ny;
BYTE r,g,b;
while(!bDone)
{
bDone=TRUE;
for(ny=0;ny<lpbi->biHeight ;ny++)
{
for(nx=0;nx<lpbi->biWidth ;nx++)
{
b=(BYTE)*lpBits;
g=(BYTE)*(lpBits+1);
r=(BYTE)*(lpBits+2);
nDetaR=-1*UPVALUE(r,nDeta);
nDetaG=-1*UPVALUE(g,nDeta);
nDetaB=-1*UPVALUE(b,nDeta);
if(!Fade(nDetaR,nDetaG,nDetaB,0,0,0,
&r,&g,&b))
bDone=FALSE;
*lpBits++=b;
*lpBits++=g;
*lpBits++=r;
}
*lpBits+=nDelta;
}
lpBits=(LPBYTE)lpbi+lpbi->biSize ;
UpdateInternal();
Display(pDC,x,y,SRCCOPY);
Delay(dwDelayTime);
nDeta--;
}
}
//clean up
GlobalUnlock(m_hDib);
GlobalUnlock(hDib);
//restore DIB
m_hDib=CopyHandle(hDib);
GlobalFree(hDib);
return TRUE;
}
BOOL CDib::DisplayMosiacIn(CDC *pDC, int xx, int yy, int nTileSize, DWORD dwDelayTime, DWORD dwRop)
{
//count the number of dwTileNum
DWORD dwTileNum=
(GetWidth()/nTileSize+((GetWidth()%nTileSize)?1:0))*
(GetHeight()/nTileSize+((GetHeight()%nTileSize)?1:0));
//allocate the tile array
POINT *point=new POINT[dwTileNum];
if(point==NULL)
return FALSE;
//initialize the tile array
LONG x=0,y=0;
for(DWORD i=0;i<dwTileNum;++i)
{
point[i].x =x;
point[i].y =y;
x+=nTileSize;
if(x>=GetWidth())
{
x=0;
y+=nTileSize;
}
}
CDC MemDC;
MemDC.CreateCompatibleDC (pDC);
CBitmap* pOldBmp=MemDC.SelectObject (m_pBitmap);
CPalette* pOldPal=pDC->SelectPalette (m_pPalette,TRUE);
pDC->RealizePalette ();
double fMax=RAND_MAX;
BOOL bDone=FALSE;
DWORD n;
while(!bDone)
{
n=(DWORD)((double)dwTileNum*(double)((double)rand()/fMax));
x=point[n].x;
y=point[n].y;
pDC->BitBlt (xx+x,yy+y,nTileSize,nTileSize,&MemDC,x,y,dwRop);
dwTileNum--;
bDone=!dwTileNum;
point[n].x=point[dwTileNum].x;
point[n].y=point[dwTileNum].y;
Delay(dwDelayTime);
}
MemDC.SelectObject (pOldBmp);
pDC->SelectPalette (pOldPal,TRUE);
delete [] point;
return TRUE;
}
BOOL CDib::DisplayMosiacOut(CDC *pDC, int xx, int yy, int nTileSize, DWORD dwDelayTime)
{
//display dib first
CDC MemDC;
MemDC.CreateCompatibleDC (pDC);
CBitmap* pOldBmp=MemDC.SelectObject (m_pBitmap);
CPalette* pOldPal=pDC->SelectPalette (m_pPalette,TRUE);
pDC->RealizePalette ();
pDC->BitBlt (xx,yy,GetWidth(),GetHeight(),&MemDC,0,0,SRCCOPY);
//count the number of dwTileNum
DWORD dwTileNum=
(GetWidth()/nTileSize+((GetWidth()%nTileSize)?1:0))*
(GetHeight()/nTileSize+((GetHeight()%nTileSize)?1:0));
//allocate the tile array
POINT *point=new POINT[dwTileNum];
if(point==NULL)
return FALSE;
//initialize the tile array
LONG x=0,y=0;
for(DWORD i=0;i<dwTileNum;++i)
{
point[i].x =x;
point[i].y =y;
x+=nTileSize;
if(x>=GetWidth())
{
x=0;
y+=nTileSize;
}
}
CBrush brush(GetSysColor(COLOR_WINDOW));
CBrush* pOldBrush=pDC->SelectObject (&brush);
CPen pen(PS_SOLID,1,GetSysColor(COLOR_WINDOW));
CPen *pOldPen=pDC->SelectObject(&pen);
double fMax=RAND_MAX;
BOOL bDone=FALSE;
DWORD n;
while(!bDone)
{
n=(DWORD)((double)dwTileNum*(double)((double)rand()/fMax));
x=point[n].x;
y=point[n].y;
pDC->Rectangle (xx+x,yy+y,xx+x+nTileSize+1,yy+y+nTileSize+1);
dwTileNum--;
bDone=!dwTileNum;
point[n].x=point[dwTileNum].x;
point[n].y=point[dwTileNum].y;
Delay(dwDelayTime);
}
MemDC.SelectObject (pOldBmp);
pDC->SelectPalette (pOldPal,TRUE);
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
delete [] point;
return TRUE;
}
BOOL CDib::Cut(CRect rc)
{
HDIB hNewDIB=CutDIB(m_hDib,&rc);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
BOOL CDib::Crop(CRect rc)
{
HDIB hNewDIB=CropDIB(m_hDib,&rc);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
BOOL CDib::Merge(HDIB hDIB, POINT ptTopLeft)
{
HDIB hNewDIB=MergeDIB(m_hDib,hDIB,ptTopLeft);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
BOOL CDib::Zoom(int nW, int nH)
{
HDIB hNewDIB=ChangeDIBSize(m_hDib,nW,nH);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
BOOL CDib::Canvas(int nWidth, int nHeight, int nPos)
{
HDIB hNewDIB=ChangeDIBCanvasSize(m_hDib,nWidth,
nHeight,nPos);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
BOOL CDib::Rotate()
{
HDIB hNewDIB=RotateDIB(m_hDib);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
BOOL CDib::FlipHorz()
{
HDIB hNewDIB=FlipHorzDIB(m_hDib);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
BOOL CDib::FlipVert()
{
HDIB hNewDIB=FlipVertDIB(m_hDib);
if(!hNewDIB)
return FALSE;
//set to m_hDib
Destroy();
m_hDib=hNewDIB;
//return
return UpdateInternal();
}
IMGMATRIX* CDib::ChangeToMatrix()
{
return ChangDIBToMatrix(m_hDib);
}
BOOL CDib::ChangeFromMatrix(IMGMATRIX *img)
{
if(!ChangeMatrixToDIB(m_hDib,img))
return FALSE;
//return
return UpdateInternal();
}
//Modify Colormap
BOOL CDib::ModifyColorMap()
{
LPBITMAPINFOHEADER lpbi;
lpbi=(LPBITMAPINFOHEADER)GlobalLock(m_hDib);
LPBITMAPINFO lpbmi;//pointer to bitmapinfo structure
int i,wNumColors;//loop index,number of colors in color table
// if handle to DIB is invalid,return NULL
if(!lpbi)
{
return NULL;
}
//get pointer to BITMAPINFO(WIN 30)
lpbmi=(LPBITMAPINFO)lpbi;
//get the number of colors in the DIB
wNumColors=DIBNumColors(lpbi);
for(i=0;i<wNumColors;i++)
{
lpbmi->bmiColors[i].rgbRed-=30;
lpbmi->bmiColors[i].rgbGreen-=30;
lpbmi->bmiColors[i].rgbBlue-=30;
}
GlobalUnlock(m_hDib);
return UpdateInternal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -