//对比度拉伸
void CMyDIPView::OnMenuitem32777()
{
// 获取文档
CMyDIPDoc* pDoc = GetDocument();
int i,j;
int r1=60,r2=200;
double k=1.5;
unsigned char *lpSrc;
ASSERT_VALID(pDoc);
if(pDoc->m_hDIB == NULL)
return ;
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->m_hDIB);
LPSTR lpDIBBits=::FindDIBBits (lpDIB);
int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y
long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数
// 每行
for(i = 0; i < cyDIB; i++)
{
// 每列
for(j = 0; j < cxDIB; j++)
{
// 指向DIB第i行,第j个象素的指针
lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB - 1 - i) + j;
// 计算新的灰度值
if(*lpSrc else if(*lpSrc else *lpSrc=BYTE((*lpSrc-r2)/k+255-(255-r2)/k);
}
}
::GlobalUnlock((HGLOBAL) pDoc->m_hDIB);
Invalidate(TRUE);
}
阅读(700) | 评论(0) | 转发(0) |