#include #include #include /*#define DEBUG*/ #define VERSION "0.01" #define AUTHOR "Mishiki Sakana" #define MYMAIL "osakana@ofo.jp" void showUsage(char *filename){ fprintf (stderr, "\"%s\" Ver. %s by %s <%s>\nUsage: %s FILE(.sue)\n\t(if you omit FILE, assumes \"_THUMBNL.SUE\" is specified)\n\n",filename, VERSION, AUTHOR, MYMAIL, filename); return; } int getFileSize(FILE *fp){ long filesize; fseek(fp,0L,SEEK_END); filesize=ftell(fp); rewind(fp); return(filesize); } void padnullbyte(FILE *fp, int padlong){ int i=0; while (i++ ftell(fp)+10){ #ifdef DEBUG printf("getting each icon chunk length...\n"); #endif fpstartat = ftell(fp); fread (&chunklong,4,1,fp); #ifdef DEBUG printf("\tchunklength : %d(fp : %d)\n",chunklong,ftell(fp)); #endif fread (&icontype,1,1,fp); #ifdef DEBUG printf ("\ticontype : %d (fp : %d)\n",icontype,ftell(fp)); #endif if (icontype!=1){ fseek(fp,(fpstartat+chunklong),SEEK_SET); } else { #ifdef DEBUG printf("OK, icontype is :%d!!\nNow Reading headers...(fp : %d)\n",icontype,ftell(fp)); #endif fread (&bitdepth,1,1,fp); fread (&imgwidth,2,1,fp); fread (&imgheight,2,1,fp); fread (×tamp,4,1,fp); fread (&filenamelong,1,1,fp); char filename[filenamelong+16]; fgets (filename,filenamelong+1,fp); #ifdef DEBUG printf("Done.\n\tchunklong : %d\n\tbitdepth : %d\n\twidth : %d\n\theight : %d\n\ttimestamp : %d\n\tnamelong : %d\n\tfilename : %s\n",chunklong, bitdepth, imgwidth,imgheight,timestamp, filenamelong, filename); #endif fseek(fp,(ftell(fp)),SEEK_SET); #ifdef DEBUG printf("\t\t(fp is : %d)\n",ftell(fp)); #endif char ext[8]; strcpy (ext, ".bmp"); strcat (filename,ext); long padbitwidth=0; long realbitwidth=0; int diff=0; realbitwidth = imgwidth*bitdepth/8; if (realbitwidth%4){ padbitwidth = (realbitwidth/4+1)*4; diff = padbitwidth - realbitwidth; } #ifdef DEBUG printf ("\trealwidth : %d\n\tpadded to : %d\n\tdiff : %d\n\n\n",realbitwidth,padbitwidth,diff); printf ("Writing a new BMP file...\n"); #endif //fb = fopen (filename,"wb"); if ((fb = fopen (filename, "wb")) == NULL){ fprintf (stderr, "Cannot open file : %s.\n",filename); exit (1); } fputc ('B',fb);fputc ('M',fb); long headeroffset = 54; long filelong = 0; long realfilelong = 0; filelong = realbitwidth*imgheight; realfilelong = (padbitwidth)?(padbitwidth*imgheight):(filelong); realfilelong +=headeroffset; #ifdef DEBUG printf ("\tdatalong : %d\n\trealfilelong : %d\n",filelong, realfilelong); #endif fwrite (&realfilelong,4,1,fb); #ifdef DEBUG printf("\nchunklong is : %d\nnow, fp is : %d\nfilelong is : %d\n",chunklong,ftell(fp),filelong); #endif padnullbyte(fb,4); fwrite (&headeroffset,4,1,fb); long headersize = 40; fwrite (&headersize,4,1,fb); fwrite (&imgwidth,4,1,fb); fwrite (&imgheight,4,1,fb); fputc (1,fb); fputc (0,fb); fwrite (&bitdepth,2,1,fb); padnullbyte(fb,4); fwrite (&filelong,4,1,fb); padnullbyte(fb,16); //printf("\nnow, fp is : %d\nfilelong is : %d\n",ftell(fp),filelong); unsigned short filebit; unsigned short rval=0; unsigned short gval=0; unsigned short bval=0; int i=0; int j=realbitwidth; int k=0; while ((ftell(fp))<(fpstartat+chunklong)){ i++; if (padbitwidth){ if (i>j){ k=0; while(k++> 11; gval = filebit << 5; gval = gval >> 11; gval = gval << 5; rval = filebit << 11; rval = rval >> 1; filebit = gval + bval + rval; fwrite (&filebit,2,1,fb); i++; } } fclose (fb); } fseek(fp,(fpstartat+chunklong),SEEK_SET); } fclose (fp); }