快讯

在BMP文件中隐藏信息

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

/*********************************************************************/ /**************************** ENCODE FUNCTIONS ***********************/ unsigned long int resolveMaxEncode(BITMAP* bmp, LOOKUP* store) { /* return maximum possible storage space in BMP */ unsigned long storage; 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, corrupta; unsigned long int longtmp; unsigned long int longtmp2; unsigned long int *longptrtmp; offset=0; storage=0; /* running total */ while (offset< (bmp- >x_size*bmp- >y_size)) { getdata=getIndexedPixel(offset, bmp); 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 + that other cols dont challenge its dominance */ tmp=offset+1; hits=1; while (tmp< (bmp- >x_size*bmp- >y_size)) { getdata=getIndexedPixel(tmp, bmp); lookaheadR=getdata.red; lookaheadG=getdata.green; lookaheadB=getdata.blue; keepflag=FALSE; if (dom==thisG && lookaheadG==thisG) keepflag=TRUE; if (dom==thisR && lookaheadR==thisR) keepflag=TRUE; if (dom==thisB && lookaheadB==thisB) keepflag=TRUE; /* check dom is still dominant col by at least 4 */ 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) { /* make this byte (that broke chain) much different to running colour byte to prevent decode confusion */ if (thisR==dom && lookaheadR!=thisR && abs(thisR-lookaheadR)< 3) { /* chain was red, and broke with a minor difference*/ corrupta.blue=lookaheadB; corrupta.green=lookaheadG; if (lookaheadR >thisR) { if (lookaheadR< 253) corrupta.red=lookaheadR+3; else corrupta.red=lookaheadR-6; } else { if (lookaheadR< 253) corrupta.red=lookaheadR-3; else corrupta.red=lookaheadR-6; } setIndexedPixel(tmp,bmp,corrupta); } else if (thisG==dom && lookaheadG!=thisG && abs(thisG-lookaheadG)< 3) { /* chain was green and broke with minor diff*/ corrupta.red=lookaheadR; corrupta.blue=lookaheadB; if (lookaheadG >thisG) { if (lookaheadG< 253) corrupta.green=lookaheadG+3; else corrupta.green=lookaheadG-6; } else { if (lookaheadG< 253) corrupta.green=lookaheadG-3; else corrupta.green=lookaheadG-6; } setIndexedPixel(tmp,bmp,corrupta); } else if (thisB==dom && lookaheadB!=thisB && abs(thisB-lookaheadB)< 3) { /* chain was blue and broke with minor diff */ corrupta.green=lookaheadG; corrupta.red=lookaheadR; if (lookaheadB >thisB) { if (lookaheadB< 253) corrupta.blue=lookaheadB+3; else corrupta.blue=lookaheadB-6; } else { if (lookaheadB< 253) corrupta.blue=lookaheadB-3; else corrupta.blue=lookaheadB-6; } setIndexedPixel(tmp,bmp,corrupta); } break; } hits++; tmp++; } if (hits >2) { storage+=(hits-2); /* store in lookup table */ for (longtmp=offset+2; longtmp< offset+hits; longtmp++) { if (store- >curitem >=store- >currentlen) { longptrtmp=store- >dataspace; store- >dataspace=(unsigned long int*)calloc(2*store- >currentlen,sizeof(unsigned long int)); for (longtmp2=0; longtmp2< store- >currentlen; longtmp2++) { *(store- >dataspace+longtmp2)=*(longptrtmp+longtmp2); } free (longptrtmp); longptrtmp=NULL; store- >currentlen*=2; } *(store- >dataspace+(store- >curitem++))=longtmp; } offset+=hits; } else { offset++; } } return (unsigned long)(storage/8); } unsigned int biggest_of_3 (unsigned int a, unsigned int b, unsigned int c) { int pr1,pr2; if (a >b) pr1=a; else pr1=b; if (b >c) pr2=b; else pr2=c; if (pr1 >pr2) return pr1; else return pr2; }
键盘也能翻页,试试“← →”键
IT热词搜索 来源:360新闻
软件论坛帖子排行
相关文章

相关软件:

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