📄 dibapi.cpp
字号:
************************************************************/
DWORD DIBLockSize(LPBYTE lpDIB)
{
if(((LPBITMAPINFOHEADER)lpDIB)->biSizeImage ==0)
((LPBITMAPINFOHEADER)lpDIB)->biSizeImage =
BytesPerLine(lpDIB)*((LPBITMAPINFOHEADER)lpDIB)->biHeight ;
return ((LPBITMAPINFOHEADER)lpDIB)->biSize +PaletteSize(lpDIB)+
((LPBITMAPINFOHEADER)lpDIB)->biSizeImage ;
}
/************************************************************
*
* Function Name:
*
* DIBLockSize()
*
* Parameters :
*
* HANDLE hDIB: -handle of the DIB
*
* Return Value:
*
* DWORD -DIB block size
*
* Description:
*
* This function calculates the block size of image bit
*
************************************************************/
DWORD DIBLockSize(HDIB hDIB)
{
LPBITMAPINFOHEADER lpDIB;
lpDIB=(LPBITMAPINFOHEADER)GlobalLock(hDIB);
if(((LPBITMAPINFOHEADER)lpDIB)->biSizeImage ==0)
((LPBITMAPINFOHEADER)lpDIB)->biSizeImage =
BytesPerLine(lpDIB)*((LPBITMAPINFOHEADER)lpDIB)->biHeight ;
DWORD dwBlockSize= ((LPBITMAPINFOHEADER)lpDIB)->biSize +PaletteSize(lpDIB)+
((LPBITMAPINFOHEADER)lpDIB)->biSizeImage ;
GlobalUnlock(hDIB);
return dwBlockSize;
}
/************************************************************
*
* Function Name:
*
* DIBHeight()
*
* Parameters :
*
* LPBYTE lpDIB: -pointer to packed -DIB memory block
*
* Return Value:
*
* DWORD -Height of the DIB
*
* Description:
*
* This function calculates the Height of the DIB
*
************************************************************/
DWORD DIBHeight(LPBYTE lpDIB)
{
DWORD dwHeight;
dwHeight=((LPBITMAPINFOHEADER)lpDIB)->biHeight ;
return dwHeight;
}
/************************************************************
*
* Function Name:
*
* DIBHeight()
*
* Parameters :
*
* HDIB hDIB: -handle of DIB
*
* Return Value:
*
* DWORD -Height of the DIB
*
* Description:
*
* This function calculates the Height of the DIB
*
************************************************************/
DWORD DIBHeight(HDIB hDIB)
{
LPBITMAPINFOHEADER lpDIB;
lpDIB=(LPBITMAPINFOHEADER)GlobalLock(hDIB);
DWORD dwHeight;
dwHeight=((LPBITMAPINFOHEADER)lpDIB)->biHeight ;
GlobalUnlock(hDIB);
return dwHeight;
}
/************************************************************
*
* Function Name:
*
* DIBWidth()
*
* Parameters :
*
* LPBYTE lpDIB: -pointer to packed -DIB memory block
*
* Return Value:
*
* DWORD -Width of the DIB
*
* Description:
*
* This function calculates the width of the DIB
*
************************************************************/
DWORD DIBWidth(LPBYTE lpDIB)
{
DWORD dwWidth;
dwWidth=((LPBITMAPINFOHEADER)lpDIB)->biWidth ;
return dwWidth;
}
/************************************************************
*
* Function Name:
*
* DIBWidth()
*
* Parameters :
*
* HDIB hDIB: -handle of DIB
*
* Return Value:
*
* DWORD -width of the DIB
*
* Description:
*
* This function calculates the width of the DIB
*
************************************************************/
DWORD DIBWidth(HDIB hDIB)
{
LPBITMAPINFOHEADER lpDIB;
lpDIB=(LPBITMAPINFOHEADER)GlobalLock(hDIB);
DWORD dwWidth;
dwWidth=((LPBITMAPINFOHEADER)lpDIB)->biWidth ;
GlobalUnlock(hDIB);
return dwWidth;
}
/************************************************************
*
* Function Name:
*
* DIBNumColors()
*
* Parameters :
*
* LPBYTE lpDIB: -pointer to packed -DIB memory block
*
* Return Value:
*
* WORD -number of colors in the color table
*
* Description:
*
* This function calculates the number of colors in the DIB's
* color table by finding the bits per pixel for the DIB.If
* bits per pixel 1:colors=2,if 4: colors=16,if 8:256
* if 24 no colors in color table
*
************************************************************/
WORD DIBNumColors(LPBYTE lpDIB)
{
WORD wBitCount;//DIB bit count
// the number of colors
// in the color table can be less than the number of
//bits per pixel
//allow for. if this is the case ,return the appropriate
//value
DWORD dwClrUsed;
dwClrUsed=((LPBITMAPINFOHEADER)lpDIB)->biClrUsed ;
if (dwClrUsed)
return(WORD) dwClrUsed;
//calculate the number of colors in the color table based on
//the number of bits per pixel for the DIB
wBitCount=((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
//return number of colors based on bits per pixel
switch(wBitCount)
{
case 1:
return 2;
case 4:
return 16;
case 8:
return 256;
default:
return 0;
}
}
/************************************************************
*
* Function Name:
*
* DIBNumColors()
*
* Parameters :
*
* HANDLE hDIB: -handle of the DIB
*
* Return Value:
*
* WORD -number of colors in the color table
*
* Description:
*
* This function calculates the number of colors in the DIB's
* color table by finding the bits per pixel for the DIB.If
* bits per pixel 1:colors=2,if 4: colors=16,if 8:256
* if 24 no colors in color table
*
************************************************************/
WORD DIBNumColors(HDIB hDIB)
{
LPBITMAPINFOHEADER lpDIB;
lpDIB=(LPBITMAPINFOHEADER)GlobalLock(hDIB);
WORD wNumColors;
WORD wBitCount;//DIB bit count
// the number of colors
// in the color table can be less than the number of
//bits per pixel
//allow for. if this is the case ,return the appropriate
//value
//访问相关字段,读出图像位数信息
DWORD dwClrUsed;
dwClrUsed=((LPBITMAPINFOHEADER)lpDIB)->biClrUsed ;
if (dwClrUsed)
return(WORD) dwClrUsed;
//calculate the number of colors in the color table based on
//the number of bits per pixel for the DIB
//根据图像位数,计算该图像用到的颜色数目
wBitCount=((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
//return number of colors based on bits per pixel
switch(wBitCount)
{
case 1:
wNumColors= 2;
case 4:
wNumColors= 16;
case 8:
wNumColors= 256;
default:
wNumColors= 0;
}
GlobalUnlock(hDIB);
//返回颜色数目
return wNumColors;
}
/************************************************************
*
* Function Name:
*
* DIBBitCount()
*
* Parameters :
*
* LPBYTE lpDIB: -pointer to packed -DIB memory block
*
* Return Value:
*
* WORD -number of bits in the DIB
*
* Description:
*
* This function calculates the number of bits in the DIB
*
************************************************************/
WORD DIBBitCount(LPBYTE lpDIB)
{
WORD wBitCount;//DIB bit count
wBitCount=((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
return wBitCount;
}
/************************************************************
*
* Function Name:
*
* DIBBitCount()
*
* Parameters :
*
* HDIB hDIB: -handle of DIB
*
* Return Value:
*
* WORD -number of bits in the DIB
*
* Description:
*
* This function calculates the number of bits in the DIB
*
************************************************************/
WORD DIBBitCount(HDIB hDIB)
{
LPBITMAPINFOHEADER lpDIB;
lpDIB=(LPBITMAPINFOHEADER)GlobalLock(hDIB);
WORD wBitCount;//DIB bit count
wBitCount=((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
GlobalUnlock(hDIB);
return wBitCount;
}
/************************************************************
*
* Function Name:
*
* FindDIBBit()
*
* Parameters :
*
* LPBYTE lpDIB: -pointer to packed -DIB memory block
*
* Return Value:
*
* WORD -pointer of the DIB data block
*
* Description:
*
* This function calculates the pointer of the DIB
* data block
*
************************************************************/
LPBYTE FindDIBBits(LPBYTE lpDIB)
{
//返回实际位图数据的起始指针位置
WORD nNumColors;
nNumColors=DIBNumColors(lpDIB);
DWORD offsits;
offsits=sizeof(BITMAPINFOHEADER)+
nNumColors*sizeof(RGBQUAD);
return (lpDIB+offsits);
}
/************************************************************
*
* Function Name:
*
* PaletteSize()
*
* Parameters :
*
* LPBYTE lpDIB: -pointer to packed -DIB memory block
*
* Return Value:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -