GlobalUnlock(hImgData);return TRUE; }BOOL LimbPatternM3(HWND hWnd){DWORD BufSize; LPBITMAPINFOHEADER lpImgData;LPSTR lpPtr;HLOCAL hTempImgData;LPBITMAPINFOHEADER lpTempImgData;LPSTR lpTempPtr;HDC hDc;HFILE hf;LONG x,y;unsigned char num;BufSize=bf.bfSize-sizeof(BITMAPFILEHEADER);if((hTempImgData=LocalAlloc(LHND,BufSize))==NULL) { MessageBox(hWnd,"Error alloc memory!","Error Message",MB_OK|MB_ICONEXCLAMATION); return FALSE; } lpImgData=(LPBITMAPINFOHEADER)GlobalLock(hImgData); lpTempImgData=(LPBITMAPINFOHEADER)LocalLock(hTempImgData);//copy image datamemcpy(lpTempImgData,lpImgData,BufSize);for(y=0;ylpPtr=(char *)lpImgData+(BufSize-LineBytes-y*LineBytes);lpTempPtr=(char *)lpTempImgData+(BufSize-LineBytes-y*LineBytes);for(x=0;xnum=(unsigned char)*lpPtr++;if ( (num>>2) > BayerPattern[y&7][x&7])*(lpTempPtr++)=(unsigned char)255;else *(lpTempPtr++)=(unsigned char)0;}} if(hBitmap!=NULL) DeleteObject(hBitmap);hDc=GetDC(hWnd);hBitmap=CreateDIBitmap(hDc,(LPBITMAPINFOHEADER)lpTempImgData, (LONG)CBM_INIT,(LPSTR)lpTempImgData+sizeof(BITMAPINFOHEADER) +NumColors*sizeof(RGBQUAD), (LPBITMAPINFO)lpTempImgData, DIB_RGB_COLORS); hf=_lcreat("c:\\limbm3.bmp",0);_lwrite(hf,(LPSTR)&bf,sizeof(BITMAPFILEHEADER)); _lwrite(hf,(LPSTR)lpTempImgData,BufSize);_lclose(hf); ReleaseDC(hWnd,hDc);LocalUnlock(hTempImgData);LocalFree(hTempImgData);GlobalUnlock(hImgData);return TRUE;}BOOL LimbPatternM4(HWND hWnd){DWORD BufSize; LPBITMAPINFOHEADER lpImgData;LPSTR lpPtr;HLOCAL hTempImgData;LPBITMAPINFOHEADER lpTempImgData;LPSTR lpTempPtr;HDC hDc;HFILE hf;LONG x,y;DWORD i,j;unsigned char num;BYTE M4Pattern[16][16];for(i=0;ifor(j=0;jM4Pattern[i][j]=4*BayerPattern[i][j];for(i=8;ifor(j=0;jM4Pattern[i][j]=4*BayerPattern[i-8][j]+2;for(i=0;ifor(j=8;jM4Pattern[i][j]=4*BayerPattern[i][j-8]+3;for(i=8;ifor(j=8;jM4Pattern[i][j]=4*BayerPattern[i-8][j-8]+1;BufSize=bf.bfSize-sizeof(BITMAPFILEHEADER);if((hTempImgData=LocalAlloc(LHND,BufSize))==NULL) { MessageBox(hWnd,"Error alloc memory!","Error Message",MB_OK|MB_ICONEXCLAMATION); return FALSE; } lpImgData=(LPBITMAPINFOHEADER)GlobalLock(hImgData); lpTempImgData=(LPBITMAPINFOHEADER)LocalLock(hTempImgData);//copy image datamemcpy(lpTempImgData,lpImgData,BufSize);for(y=0;ylpPtr=(char *)lpImgData+(BufSize-LineBytes-y*LineBytes);lpTempPtr=(char *)lpTempImgData+(BufSize-LineBytes-y*LineBytes);for(x=0;xnum=(unsigned char)*lpPtr++;if ( num > M4Pattern[y&15][x&15])*(lpTempPtr++)=(unsigned char)255;else *(lpTempPtr++)=(unsigned char)0;}} if(hBitmap!=NULL) DeleteObject(hBitmap);hDc=GetDC(hWnd);hBitmap=CreateDIBitmap(hDc,(LPBITMAPINFOHEADER)lpTempImgData, (LONG)CBM_INIT,(LPSTR)lpTempImgData+sizeof(BITMAPINFOHEADER) +NumColors*sizeof(RGBQUAD), (LPBITMAPINFO)lpTempImgData, DIB_RGB_COLORS); hf=_lcreat("c:\\limbm4.bmp",0);_lwrite(hf,(LPSTR)&bf,sizeof(BITMAPFILEHEADER)); _lwrite(hf,(LPSTR)lpTempImgData,BufSize);_lclose(hf); ReleaseDC(hWnd,hDc);LocalUnlock(hTempImgData);LocalFree(hTempImgData);GlobalUnlock(hImgData);return TRUE;}BOOL Steinberg(HWND hWnd){DWORD OffBits,BufSize,IntBufSize; LPBITMAPINFOHEADER lpImgData;HLOCAL hTempImgData;LPBITMAPINFOHEADER lpTempImgData;LPSTR lpPtr;LPSTR lpTempPtr;HDC hDc;HFILE hf;LONG x,y;unsigned char num;float e,f;HLOCAL hIntBuf;int *lpIntBuf,*lpIntPtr;int tempnum;OffBits=bf.bfOffBits-sizeof(BITMAPFILEHEADER);BufSize=bf.bfSize-sizeof(BITMAPFILEHEADER);if((hTempImgData=LocalAlloc(LHND,BufSize))==NULL) { MessageBox(hWnd,"Error alloc memory!","Error Message",MB_OK|MB_ICONEXCLAMATION); return FALSE; }IntBufSize=(DWORD)bi.biHeight*LineBytes*sizeof(int);if((hIntBuf=LocalAlloc(LHND,IntBufSize))==NULL) { MessageBox(hWnd,"Error alloc memory!","Error Message",MB_OK|MB_ICONEXCLAMATION);LocalFree(hTempImgData); return FALSE; } lpImgData=(LPBITMAPINFOHEADER)GlobalLock(hImgData); lpTempImgData=(LPBITMAPINFOHEADER)LocalLock(hTempImgData);lpIntBuf=(int *)LocalLock(hIntBuf);//copy header datamemcpy(lpTempImgData,lpImgData,OffBits);//copy image data to int bufferfor(y=0;ylpPtr=(char *)lpImgData+(BufSize-LineBytes-y*LineBytes);lpIntPtr=(int *)lpIntBuf+(bi.biHeight-1-y)*LineBytes;for(x=0;x*(lpIntPtr++)=(unsigned char)*(lpPtr++);}for(y=0;yfor(x=0;xlpIntPtr=(int *)lpIntBuf+(bi.biHeight-1-y)*LineBytes+x;num=(unsigned char)*lpIntPtr;if ( num > 128 ){*lpIntPtr=255;e=(float)(num-255.0);}else{*lpIntPtr=0;e=(float)num;}if(xf=(float)*(lpIntPtr+1);f+=(float)( (3.0/8.0) * e);*(lpIntPtr+1)=(int)f;}if(yf=(float)*(lpIntPtr-LineBytes);f+=(float)( (3.0/8.0) * e);*(lpIntPtr-LineBytes)=(int)f;f=(float)*(lpIntPtr-LineBytes+1);f+=(float)( (1.0/4.0) * e);*(lpIntPtr-LineBytes+1)=(int)f;}}}//copy new image data from int bufferfor(y=0;ylpTempPtr=(char *)lpTempImgData+(BufSize-LineBytes-y*LineBytes);lpIntPtr=(int *)lpIntBuf+(bi.biHeight-1-y)*LineBytes;for(x=0;xtempnum=*(lpIntPtr++);if(tempnum>255) tempnum=255;else if (tempnum*(lpTempPtr++)=(unsigned char)tempnum;}} if(hBitmap!=NULL) DeleteObject(hBitmap);hDc=GetDC(hWnd);hBitmap=CreateDIBitmap(hDc,(LPBITMAPINFOHEADER)lpTempImgData, (LONG)CBM_INIT,(LPSTR)lpTempImgData+sizeof(BITMAPINFOHEADER) +NumColors*sizeof(RGBQUAD), (LPBITMAPINFO)lpTempImgData, DIB_RGB_COLORS); hf=_lcreat("c:\\steinberg.bmp",0);_lwrite(hf,(LPSTR)&bf,sizeof(BITMAPFILEHEADER)); _lwrite(hf,(LPSTR)lpTempImgData,BufSize);_lclose(hf); ReleaseDC(hWnd,hDc);GlobalUnlock(hImgData);LocalUnlock(hTempImgData);LocalFree(hTempImgData);LocalUnlock(hIntBuf);LocalFree(hIntBuf);return TRUE;}BOOL Bmp2Txt(HWND hWnd){DWORD OffBits,BufSize; LPBITMAPINFOHEADER lpImgData;LPSTR lpPtr;HFILE hf;int i, j, k,h,tint,grayindex;char tchar;int TransHeight, TransWidth;for(i=0;ifor(j=i+1;jif(gr[i]>gr[j]){tchar=ch[i],tint=gr[i];ch[i]=ch[j],gr[i]=gr[j];ch[j]=tchar,gr[j]=tint;}}OffBits=bf.bfOffBits-sizeof(BITMAPFILEHEADER);BufSize=bf.bfSize-sizeof(BITMAPFILEHEADER); lpImgData=(LPBITMAPINFOHEADER)GlobalLock(hImgData);TransWidth = bi.biWidth/8;TransHeight = bi.biHeight/16; hf=_lcreat("c:\\bmp2txt.txt",0);for(i=0;ifor(j=0;jgrayindex=0;for(k=0;kfor(h=0;hlpPtr=(char *)lpImgData+BufSize-LineBytes-(i*16+k)*LineBytes+j*8+h;grayindex+=(unsigned char)*lpPtr;}grayindex/=16*8;grayindex=gr[94]*grayindex/255;k=0;while(gr[k+1]k++;_lwrite(hf,(char *)&ch[k],sizeof(char)); }tchar=(char)13;_lwrite(hf,(char *)&tchar,sizeof(char)); tchar=(char)10;_lwrite(hf,(char *)&tchar,sizeof(char));}_lclose(hf);GlobalUnlock(hImgData);return TRUE;}
c实现 图像dither算法_dither.c
最新推荐文章于 2022-04-20 11:41:47 发布