快讯

在BMP文件中隐藏信息

2004-02-14 09:34  出处:PConline  作者:网上收集  责任编辑:zwg 

/****************DATA CODING **********************************/ void encodeData(BITMAP* dest, HEAP* data, LOOKUP* hotspots) { /* encodes data bit by bit into dest */ /* hotspots contains actual data storage locations */ unsigned long int i; unsigned long int heapitem; PIXEL blititem; int bitshift; unsigned char theBool; unsigned char dom; bitshift=0; heapitem=0; for (i=0; i< hotspots- >curitem; i++) { /* get next bit */ theBool=getNextHeapBit(heapitem,bitshift,data); bitshift++; if (bitshift==8) { bitshift=0; heapitem++; if (heapitem >data- >heaplen) break; } blititem=getIndexedPixel(*(hotspots- >dataspace+i),dest); dom=biggest_of_3(blititem.red, blititem.green, blititem.blue); if (dom==blititem.red) { if (theBool==1) { /* R */ if (dom==255) dom--; else dom++; blititem.red=dom; } } else if (dom==blititem.green) { if (theBool==1) { /* G */ if (dom==255) dom--; else dom++; blititem.green=dom; } } else { if (theBool==1) { /* B */ if (dom==255) dom--; else dom++; blititem.blue=dom; } } setIndexedPixel(*(hotspots- >dataspace+i),dest,blititem); } } unsigned char getNextHeapBit (unsigned long int item, int bit, HEAP* data) { unsigned char thisitem; int bitshift; bit=7-bit; /* reverse bit order */ thisitem=*(data- >dataspace+item); bitshift=pow(2,bit); thisitem=thisitem&bitshift; thisitem=thisitem > >bit; return thisitem; } int decodeData(BITMAP* src, HEAP* dest) { unsigned long offset,tmp; unsigned char thisR; unsigned char thisG; unsigned char thisB; unsigned char lookaheadR; unsigned char lookaheadG; unsigned char lookaheadB; int dom,lookaheaddom; int keepflag,keepflag2; unsigned long int hits; PIXEL getdata; PIXEL controlPixel, thisPixel; int theBool; unsigned long int longtmp; int currentBit; int bitshifts; offset=0; currentBit=0; bitshifts=0; while (offset< (src- >x_size*src- >y_size)) { getdata=getIndexedPixel(offset, src); thisR=getdata.red; thisG=getdata.green; thisB=getdata.blue; dom=biggest_of_3(thisR,thisG,thisB); keepflag=FALSE; /* If 1 col varies from others by at least 3 = > candidate */ if (dom==thisG && abs(thisG-thisR) >2 && abs(thisG-thisB) >2) keepflag=TRUE; if (dom==thisB && abs(thisB-thisR) >2 && abs(thisB-thisG) >2) keepflag=TRUE; if (dom==thisR && abs(thisR-thisB) >2 && abs(thisR-thisG) >2) keepflag=TRUE; if (keepflag==FALSE) { offset++; continue; } /* only one of the 3 cols=dom here, and that col is at least 3 points greater than the others */ /* see if dominant col continues on more pixels(+ or - 1) and that other cols dont challenge its dominance */ tmp=offset+1; hits=1; while (tmp< (src- >x_size*src- >y_size)) { getdata=getIndexedPixel(tmp, src); lookaheadR=getdata.red; lookaheadG=getdata.green; lookaheadB=getdata.blue; keepflag=FALSE; if (dom==thisG && abs(lookaheadG-thisG)< 2) keepflag=TRUE; if (dom==thisR && abs(lookaheadR-thisR)< 2) keepflag=TRUE; if (dom==thisB && abs(lookaheadB-thisB)< 2) keepflag=TRUE; /* check dom is still dominant col by at least 3 */ lookaheaddom=biggest_of_3(lookaheadR,lookaheadG,lookaheadB); keepflag2=FALSE; if (thisR==dom && lookaheadR==lookaheaddom && abs(lookaheadR-lookaheadG) >2 && abs(lookaheadR-lookaheadB) >2) keepflag2=TRUE; if (thisG==dom && lookaheadG==lookaheaddom && abs(lookaheadG-lookaheadR) >2 && abs(lookaheadG-lookaheadB) >2) keepflag2=TRUE; if (thisB==dom && lookaheadB==lookaheaddom && abs(lookaheadB-lookaheadR) >2 && abs(lookaheadB-lookaheadG) >2) keepflag2=TRUE; if (keepflag==FALSE || keepflag2==FALSE) break; hits++; tmp++; } if (hits >2) { /* store in lookup table */ for (longtmp=offset+2; longtmp< offset+hits; longtmp++) { controlPixel=getIndexedPixel(offset,src); thisPixel=getIndexedPixel(longtmp,src); dom=biggest_of_3(controlPixel.red, controlPixel.green, controlPixel.blue); if (dom==controlPixel.red) { if (thisPixel.red-dom==0) theBool=0; else theBool=1; } if (dom==controlPixel.green) { if (thisPixel.green-dom==0) theBool=0; else theBool=1; } if (dom==controlPixel.blue) { if (thisPixel.blue-dom==0) theBool=0; else theBool=1; } currentBit=currentBit< < 1; currentBit+=theBool; bitshifts++; if (bitshifts==8) { if (!putToHeap((char)currentBit,dest)) return 2; bitshifts=0; currentBit=0; } } offset+=hits; } else { offset++; } } /* decoded and in heap */ if (dest- >heaplen< 13) return 1; if (!(*(dest- >dataspace)=='B') || (*(dest- >dataspace+1)!='S' && *(dest- >dataspace+1)!='E')) return 1; if (*(dest- >dataspace+6) >THIS_PROTO_VER) return 3; /* set data length by truncation */ longtmp=0; longtmp+=((unsigned long int)(*(dest- >dataspace+2))*1); longtmp+=((unsigned long int)(*(dest- >dataspace+3))*256); longtmp+=((unsigned long int)(*(dest- >dataspace+4))*65536); longtmp+=((unsigned long int)(*(dest- >dataspace+5))*16777216); if (longtmp< =dest- >heaplen) dest- >heaplen=longtmp; else return 1; return 0; }
键盘也能翻页,试试“← →”键
IT热词搜索 来源:360新闻
软件论坛帖子排行
相关文章

相关软件:

腾讯QQ2012
大小:52.93 MB 授权:免费
腾讯QQ2012
立即下载
腾讯QQ2013
大小:49.32 MB 授权:免费
腾讯QQ2013
立即下载