?? main.cpp
字號:
putToHeap('\0',filespace);
putToHeap('\0',filespace);
putToHeap('\0',filespace);
hotspots=(LOOKUP*)calloc(1,sizeof(LOOKUP));
if (hotspots==NULL) {
printf("ERROR\n\nOut of memory\n");
exit(4);
}
hotspots->dataspace=(unsigned long int*)calloc(LOOKUP_INITLEN,sizeof(unsigned long int));
if (hotspots==NULL) {
printf("ERROR\n\nOut of memory\n");
exit (4);
}
hotspots->currentlen=LOOKUP_INITLEN;
maxencode=resolveMaxEncode(BMPworking, hotspots);
if (maxencode< 13)
return FALSE;
longtemp=maxencode;
bit4=(unsigned int)longtemp/16777216;
longtemp=longtemp-(unsigned long)((unsigned long)bit4*16777216);
bit3=(unsigned int)longtemp/65536;
longtemp=longtemp-(unsigned long)((unsigned long)bit3*65536);
bit2=(unsigned int)longtemp/256;
longtemp=longtemp-(unsigned long)((unsigned long)bit2*256);
bit1=(unsigned int)longtemp;
*(filespace->dataspace+2)=bit1;
*(filespace->dataspace+3)=bit2;
*(filespace->dataspace+4)=bit3;
*(filespace->dataspace+5)=bit4;
for (i=filespace->heaplen; i< maxencode; i++)
putToHeap('\0',filespace);
/* encode blank data into bitmap */
encodeData(BMPworking,filespace,hotspots);
return TRUE;
}
void dumpFileDirectory(HEAP* filespace) {
unsigned long int offset,filelen;
unsigned long int filectr,bytectr;
int filenamelen;
offset=9;
filectr=0;
bytectr=0;
printf("\nFilename Size (bytes)\n-------- ------------\n");
for (;;) {
filelen=0;
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*1);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*256);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*65536);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*16777216);
if (filelen==0)
break;
filenamelen=strlen(void(*filespace->dataspace+offset))+1;
printf("%-18s%lu\n",filespace->dataspace+offset,filelen-filenamelen);
offset=offset+filelen;
filectr++;
bytectr+=filelen-filenamelen;
}
if (filectr==0)
printf("No files found in archive!\n");
else
printf("\nTotal %lu byte(s), in %lu file(s)\n",bytectr,filectr);
}
void dumpFileStats(BITMAP* BMPworking, HEAP* filespace) {
unsigned long int offset,filelen,totalsize;
unsigned long int filectr,bytectr;
unsigned long int maxencode;
float perc_used;
LOOKUP* hotspots;
if (filespace->heaplen==0) {
hotspots=(LOOKUP*)calloc(1,sizeof(LOOKUP));
hotspots->dataspace=(unsigned long int*)calloc(LOOKUP_INITLEN,sizeof(unsigned long int));
hotspots->currentlen=LOOKUP_INITLEN;
printf("? Calculating Data Capacity....");
maxencode=resolveMaxEncode(BMPworking, hotspots);
free(hotspots);
printf("OK\n\nThis file does not contain any BlindSide hidden data\n");
printf("The predicted storage capacity for this image is %lu byte(s) [%d Kb]\n",maxencode,(int)((float)maxencode/1024));
}
else {
totalsize=0;
totalsize+=((unsigned long int)(*(filespace->dataspace+2))*1);
totalsize+=((unsigned long int)(*(filespace->dataspace+3))*256);
totalsize+=((unsigned long int)(*(filespace->dataspace+4))*65536);
totalsize+=((unsigned long int)(*(filespace->dataspace+5))*16777216);
offset=9;
filectr=0;
bytectr=0;
for (;;) {
filelen=0;
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*1);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*256);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*65536);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*16777216);
bytectr+=filelen+4;
if (filelen==0)
break;
offset=offset+filelen;
filectr++;
}
bytectr+=9;
perc_used=(float)100/totalsize;
perc_used=perc_used*(float)(totalsize-bytectr);
printf("\nArchive Found - Capacity %lu byte(s) [%lu Kb]\n\n",totalsize,totalsize/1024);
printf("Total files - %lu, using %lu byte(s)\n",filectr,bytectr);
printf("Freespace remaining: %lu byte(s) [%d%%]\n",totalsize-bytectr,(int)perc_used);
}
}
void addFileToArchive(HEAP* filespace, FILE* handle, char* filename) {
HEAP* filedump;
int i;
unsigned long int offset,filelen,freespace,ilong;
unsigned long int lastfile,lastfile2;
unsigned int bit4,bit3,bit2,bit1;
offset=9;
for (;;) {
filelen=0;
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*1);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*256);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*65536);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*16777216);
lastfile=offset-4;
if (filelen==0)
break;
if (stricmp(&filename,filespace->dataspace+offset)==0) {
printf("FATAL: File %s already exists in the archive\n",filename);
exit(4);
}
offset=offset+filelen;
}
freespace=(filespace->heaplen)-(lastfile+4);
filedump=(HEAP*)calloc(1,sizeof(HEAP));
initialiseHeap(filedump);
printf("Adding.... %s\n",filename);
/* Write filename */
for(i=0; i<strlen(filename); i++) {
putToHeap(filename[i],filedump);
}
putToHeap('\0',filedump);
/* Write file */
if (!streamFileToHeap(handle,filedump)) {
printf("\nFATAL: Out of memory, while reading file to encode\n");
exit(4);
}
if (filedump->heaplen==(strlen(filename)+1)) {
printf("\nFATAL: File to encode is empty! (zero length)\n");
exit(4);
}
/* Write next file length (end of chain) */
putToHeap('\0',filedump);
putToHeap('\0',filedump);
putToHeap('\0',filedump);
putToHeap('\0',filedump);
if (freespace< filedump->heaplen) {
printf("\nFATAL: There isn't enough room inside your image to encode that file\n\nYour data coding needs: %ld bytes\nFreespace inside bitmap: %ld bytes\n\n",filedump->heaplen,freespace);
printf("It is possible the image you are trying to encode into is too complex,\nor your file to encode is too large. Maybe try zipping it first?\n");
exit(7);
}
for (ilong=0; ilong< filedump->heaplen; ilong++) {
*(filespace->dataspace+offset+ilong)=*(filedump->dataspace+ilong);
}
lastfile2=filedump->heaplen-4;
bit4=(unsigned int)lastfile2/16777216;
lastfile2=lastfile2-(unsigned long)((unsigned long)bit4*16777216);
bit3=(unsigned int)lastfile2/65536;
lastfile2=lastfile2-(unsigned long)((unsigned long)bit3*65536);
bit2=(unsigned int)lastfile2/256;
lastfile2=lastfile2-(unsigned long)((unsigned long)bit2*256);
bit1=(unsigned int)lastfile2;
*(filespace->dataspace+lastfile)=bit1;
*(filespace->dataspace+lastfile+1)=bit2;
*(filespace->dataspace+lastfile+2)=bit3;
*(filespace->dataspace+lastfile+3)=bit4;
removeHeap(filedump);
free(filedump);
}
int extractFile(HEAP* filespace, char* criteria) {
unsigned long int offset,filelen,filectr;
unsigned long int extractctr,i;
int alwaysoverwrite;
int extractIt;
int wasprompt;
char tmpchar[129];
FILE* outfile;
int filenamelen;
offset=9;
extractctr=0;
filectr=0;
alwaysoverwrite=FALSE;
for (;;) {
filelen=0;
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*1);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*256);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*65536);
filelen+=((unsigned long int)(*(filespace->dataspace+(offset++)))*16777216);
if (filelen==0)
break;
filectr++;
if (criteria==NULL || stricmp(filespace->dataspace+offset,criteria)==0) {
/* extract this file */
printf("Extracting.... %s",filespace->dataspace+offset);
extractIt=TRUE;
if (checkExists(filespace->dataspace+offset) && !alwaysoverwrite) {
wasprompt=TRUE;
printf(" - already exists, Overwrite? (y/N/a)");
fflush(stdin);
fscanf(stdin,"%s",tmpchar);
if (stricmp(tmpchar,"A")==0) {
alwaysoverwrite=TRUE;
printf("\n");
}
else if (stricmp(tmpchar,"Y")==0) {
printf("\n");
}
else {
printf("Skipping file--^\n");
extractIt=FALSE;
}
}
else {
printf("\n");
wasprompt=FALSE;
}
if (extractIt) {
/* Do the actual extraction */
extractctr++;
outfile=fopen(filespace->dataspace+offset,"wb");
filenamelen=strlen(filespace->dataspace+offset)+1;
while ((*(filespace->dataspace+offset))!='\0') {
offset++;
}
offset++;
for (i=0; i< filelen-filenamelen; i++)
fprintf(outfile,"%c",*(filespace->dataspace+offset+i));
fclose(outfile);
offset=offset+(filelen-filenamelen);
}
else {
offset+=filelen;
}
}
else {
offset+=filelen;
}
}
if (filectr==0) {
printf("This BlindSide archive is empty - no files to extract\n");
}
else {
if (!wasprompt)
printf("\n");
if (extractctr==0)
printf("No files in the archive matched your extract request!\n");
else
printf("Extracted %lu file(s) successfully.\n",extractctr);
}
return extractctr;
}
int checkExists(char* filename) {
FILE* tester;
if ((tester=fopen(filename,"rb"))) {
fclose(tester);
return TRUE;
}
return FALSE;
}
void flattenBitmap(BITMAP* src, LOOKUP* store) {
/* passes over data as if reading it - but just flattens all data to '0' bits and
compiles a hotspots list */
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;
unsigned long int longtmp;
unsigned long int longtmp2;
unsigned long int *longptrtmp;
offset=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) {
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) {
thisPixel.red=controlPixel.red;
}
if (dom==controlPixel.green) {
thisPixel.green=controlPixel.green;
}
if (dom==controlPixel.blue) {
thisPixel.blue=controlPixel.blue;
}
setIndexedPixel(longtmp,src,thisPixel);
/* store in lookup table */
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++;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -