/***************************************************************************************/ /* */ /* Program Name : bmp_grey_area_add.c */ /* */ /* Date : 06.07.31 New Create */ /* */ /* Author : zuruneko */ /* */ /* Function : pre rotation disposal */ /* */ /* ver01 06.07.31 New Create */ /* */ /* */ /***************************************************************************************/ #include #include #include #include #include #define uchar unsigned char #define ushort unsigned short #define uint unsigned int #define ulong unsigned long #define rchar register char #define rshort register short #define rint register int #define rlong register long #define ruchar register uchar #define rushort register ushort #define ruint register uint #define rulong register ulong #define schar static char #define sshhort static short #define sint static int #define slong static long #define suchar static uchar #define sushort static ushort #define suint static uint #define sulong static ulong #define ORG_IMAGE_X 720 #define ORG_IMAGE_Y 480 #define BUNBOMAX 32 #define BUNSHIMAX 31 #define TAPMAXY 50 #define TAPMAXC 50 typedef struct control_data { uint sizex; uint sizey; uint startx; uint starty; char InputFileName[128]; char InputFileName2[128]; char OutputFileName[128]; uint hv; uint sm; uint smy; uint bunshi; uint bunbo; uint norm; uint mado; uint tapnum_y; uint tapnum_c; double Fs; } CNTL; char inputfile[50]; char inputfile2[50]; char outputfile[50]; int hsize; int vsize; int org_image_x; int org_image_y; void coeffhairetsuculc(uint , uint, uint , uint, uint, uint, uint, uint, double, double, double, double, double *,double *, uint,double); double INITPHASECULC(uint , uint , uint , uint , uint ); uint FILPATCULC(uint , uint , uint , double , double *); void COEFCULC( uint , uint , uint , uint , uint , uint , uint, double ); void normarize(uint ,uint ,uint ,uint , double *, uint ); void DFT1DV(int , double *, double *, double *, double *); void DFT1DH(int , int , double *, double*, double *, double *); void IDFT1DV(int , double *, double *, double *, double *); void IDFT1DH(int , int , double *, double*, double *, double *); void resize( int hsize, int vsize, int sizeminus, int smy, unsigned char *vin_buffer , unsigned char *vout); void print_help( void ) { fprintf( stderr, "Usage: bmp_grey_area_add [options]\n" ); fprintf( stderr, "\toptions: \n" ); fprintf( stderr, "\t -help : help\n" ); fprintf( stderr, "\t -i : input bitmap filename(BMP24bittruecolor)\n" ); fprintf( stderr, "\t -o : output bitmap file name(BMP24bittruecolor .bmp extension auto add\n" ); // fprintf( stderr, "\t -x : 出力補正スペクトルを何倍にするか指定\n" ); // fprintf( stderr, "\t -orgx : 水平画素サイズ(任意の自然数)\n" ); // fprintf( stderr, "\t -orgy : 垂直画素サイズ(任意の自然数)\n" ); // fprintf( stderr, "\t -sizexminus : 原画像水平方向サイズと水平方向縮小後サイズとの差分(任意の自然数)\n" ); // fprintf( stderr, "\t -sizexminusy : 原画像垂直方向サイズと垂直方向縮小後サイズとの差分(任意の自然数)\n" ); // fprintf( stderr, "\t -hv : 1:水平 2:プログレッシブ垂直 3:インタレース垂直\n" ); // fprintf( stderr, "\t -bunshi : 縮小率分子 max31\n" ); // fprintf( stderr, "\t -bunbo : 縮小率分母 max32\n" ); // fprintf( stderr, "\t -tapnum_y : 輝度フィルタタップ数 推奨 21 max50\n" ); // fprintf( stderr, "\t -tapnum_c : 色差フィルタタップ数 推奨 11 max50\n" ); // fprintf( stderr, "\t -norm : 総係数合計 推奨4096 サブサンプルプログラムで使う場合\n" ); // fprintf( stderr, "\t -mado : 1:矩形 2:Lanczos 3:hanning(両端が0) 4:hamming\n" ); // fprintf( stderr, "\t -Fsc : サブサンプル後のサンプリング周波数を1としたときカットオフ周波数を指定(推奨0.5)\n" ); } void option_set(short argc,char *argv[], CNTL *ptr) { short i; for(i=1;i < argc;i++) { if(argv[i][0] != '-') continue; if ( !strcmp( &argv[i][1], "h" ) ){ /* \245\330\245\353\245\327\311\275\274\250 */ print_help(); exit(0); } else if ( !strcmp( &argv[i][1], "o" ) ){ /* \275\320\316\317\245\325\245\241\245\244\245\353\314\276 */ strcpy(ptr->OutputFileName, argv[++i]); } else if ( !strcmp( &argv[i][1], "i" ) ){ strcpy(ptr->InputFileName, argv[++i]); } else if ( !strcmp( &argv[i][1], "i2" ) ){ strcpy(ptr->InputFileName2, argv[++i]); } else if ( !strcmp( &argv[i][1], "x" ) ){ ptr->sizex = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "y" ) ){ ptr->sizey = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "startx" ) ){ ptr->startx = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "starty" ) ){ ptr->starty = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "hv" ) ){ ptr->hv = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "bunshi" ) ){ ptr->bunshi = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "bunbo" ) ){ ptr->bunbo = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "norm" ) ){ ptr->norm = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "mado" ) ){ ptr->mado = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "tapnum_y" ) ){ ptr->tapnum_y = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "tapnum_c" ) ){ ptr->tapnum_c = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "Fsc" ) ){ ptr->Fs = atof(argv[++i]); } else if ( !strcmp( &argv[i][1], "sizexminus" ) ){ ptr->sm = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "sizexminusy" ) ){ ptr->smy = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "orgx" ) ){ /* \277\345\312\277\312\375\270\376\306\376\316\317\262\350\301\374\245\265\245\244\245\272 */ org_image_x = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "orgy" ) ){ /* \277\342\304\276\312\375\270\376\306\376\316\317\262\350\301\374\245\265\245\244\245\272 */ org_image_y = atoi(argv[++i]); } else { print_help(); exit(0); } } } int main(int argc, char *argv[]){ FILE *fpr1; FILE *fpr2; FILE *fpw; unsigned char *vin; unsigned char *vout; unsigned char *vin_buffer; //#define HSIZE 360 //#define VSIZE 288 //#define tmp HSIZE*VSIZE int i,j,k,l,m,n,o ; CNTL *cnt; int center0; int sizeminus; int filesizebyte; unsigned char *B; unsigned char *G; unsigned char *R; unsigned char *BIN; unsigned char *GIN; unsigned char *RIN; unsigned char *RUPOUT; unsigned char *GUPOUT; unsigned char *BUPOUT; unsigned char temp; unsigned char temp2; unsigned int filesize; double DiagonalLength; int NewHsize; int NewVsize; org_image_x = ORG_IMAGE_X; org_image_y = ORG_IMAGE_Y; if( argc < 2 ) { print_help(); exit(0); } //-----debug----- //for(;;); //---------------- cnt = (CNTL *)malloc( sizeof(CNTL)*sizeof(uchar) ); /* \245\307\245\325\245\251\245\353\245\310\303\315\300\337\304\352 */ cnt->sizex = ORG_IMAGE_X; cnt->sizey = ORG_IMAGE_Y; cnt->startx = 0; cnt->starty = 0; /* \245\252\245\327\245\267\245\347\245\363\245\301\245\247\245\303\245\257 */ option_set(argc, argv, cnt); hsize = org_image_x; vsize = org_image_y; strcpy(inputfile,cnt->InputFileName); strcpy(inputfile2,cnt->InputFileName2); strcpy(outputfile,cnt->OutputFileName); sizeminus = cnt->sm; /********************************/ /* */ /* MAIN ROUTINE */ /* */ /********************************/ // vin_buffer = (unsigned char *)malloc(sizeof(unsigned char)*hsize*vsize); // vout = (unsigned char *)malloc(sizeof(unsigned char)*(hsize+sizeminus)*(vsize+smy)*2); if((fpr1 = fopen(inputfile,"rb"))==NULL){ exit(0); } //debug start //for(;;); //debug end /***************************************************/ /* picture size & file size get from bitmap header */ /***************************************************/ fseek(fpr1,18,SEEK_SET); fread(&hsize,sizeof(int),1,fpr1); //debug start //printf ("%d\n",hsize); //for(;;); //debug end fread(&vsize,sizeof(int),1,fpr1); fseek(fpr1,2,SEEK_SET); fread(&filesizebyte,sizeof(int),1,fpr1); //debug start //printf ("%d\n",filesizebyte); //for(;;); //debug end /***************/ /* picture get */ /***************/ vin = (unsigned char *)malloc(sizeof(unsigned char)*(filesizebyte-54)); B = (unsigned char *)malloc(sizeof(unsigned char)*hsize*vsize); G = (unsigned char *)malloc(sizeof(unsigned char)*hsize*vsize); R = (unsigned char *)malloc(sizeof(unsigned char)*hsize*vsize); fseek(fpr1,54,SEEK_SET); if(fread(vin,sizeof(unsigned char),filesizebyte - 54,fpr1) != filesizebyte -54 ){ printf("input file size err!!\n"); exit(1); } fclose(fpr1); //debug start //for(;;); //debug end /***************************************/ /* set to B,G,R array with RGB PICTURE */ /***************************************/ for(i=0,k=0;ismy, RIN , RUPOUT); // resize( hsize, vsize, sizeminus, cnt->smy, GIN , GUPOUT); // resize( hsize, vsize, sizeminus, cnt->smy, BIN , BUPOUT); // sprintf(cnt->OutputFileName,"%s.bmp",outputfile); // fpw = fopen(cnt->OutputFileName,"wb"); /************************/ /* */ /* 対角線の長さ計算 */ /* */ /************************/ DiagonalLength = sqrt(((double)(hsize-1)*(double)(hsize-1)) + ((double)(vsize-1) * (double)(vsize-1))); DiagonalLength += 0.5; NewHsize = (int)(DiagonalLength) + 6; if(NewHsize % 2 == 1){ NewHsize += 1; } NewVsize = NewHsize; RUPOUT = (unsigned char *)malloc(sizeof(unsigned char)*(NewHsize)*(NewVsize)); GUPOUT = (unsigned char *)malloc(sizeof(unsigned char)*(NewHsize)*(NewVsize)); BUPOUT = (unsigned char *)malloc(sizeof(unsigned char)*(NewHsize)*(NewVsize)); /***************/ /* */ /* 上段処理 */ /* */ /***************/ for(i=0;i<((NewVsize - vsize)/2);i++){ for(j=0;jOutputFileName,"%dx%d_%s.bmp",NewHsize,NewVsize,outputfile); fpw = fopen(cnt->OutputFileName,"wb"); /************************/ /* HEADER 54 byte write */ /************************/ if(((hsize*3)%4) == 0){ filesize = 0x36 + hsize*vsize*3; } else { filesize = 0x36 + hsize*vsize*3+(4-(hsize*3)%4)*vsize; } temp = 0x42; //'B' fwrite(&temp,sizeof(unsigned char),1,fpw); temp = 0x4D; //'M' fwrite(&temp,sizeof(unsigned char),1,fpw); fwrite(&filesize,sizeof(unsigned int),1,fpw); filesize = 0; fwrite(&filesize,sizeof(unsigned int),1,fpw); filesize = 0x00000036; fwrite(&filesize,sizeof(unsigned int),1,fpw); filesize = 0x28; fwrite(&filesize,sizeof(unsigned int),1,fpw); fwrite(&hsize,sizeof(int),1,fpw); fwrite(&vsize,sizeof(int),1,fpw); filesize = 0x00180001; fwrite(&filesize,sizeof(unsigned int),1,fpw); filesize = 0; fwrite(&filesize,sizeof(unsigned int),1,fpw); fwrite(&filesize,sizeof(unsigned int),1,fpw); filesize = 0x00000EC4; fwrite(&filesize,sizeof(unsigned int),1,fpw); fwrite(&filesize,sizeof(unsigned int),1,fpw); filesize = 0; fwrite(&filesize,sizeof(unsigned int),1,fpw); fwrite(&filesize,sizeof(unsigned int),1,fpw); temp2 =0; for(i=0;i= 255.0){ *(vout+j*(vsize-smy)+i) = 255; } else if((*(fourieR+j*(vsize-smy)+i)/(((double)(hsize*vsize)))*4.0) <= 0.0){ *(vout+j*(vsize-smy)+i) = 0; } else { *(vout+j*(vsize-smy)+i) = (unsigned char)(*(fourieR+j*(vsize-smy)+i)/(((double)(hsize*vsize)))*4.0); // *(vout+k) = (unsigned char)(*(fourieR+j*(vsize-smy)+i)/(double)(hsize*vsize)/((double)(vsize-smy) * (double)(hsize-sizeminus))); // *(vout+k) = (unsigned char)(*(fourieR+j*(vsize-smy)+i)/(double)(hsize*vsize)/(double)(hsize*vsize)*((double)(vsize-smy) * (double)(hsize-sizeminus))); // *(vout+k) = (unsigned char)((*(fourieR+j*(vsize-smy)+i))/(sqrt((double)(hsize*vsize)*((double)(vsize-smy) * (double)(hsize-sizeminus))))); // *(vout+k) = (unsigned char)((*(fourieR+j*(vsize-smy)+i))*((double)(hsize*vsize))); } //debug //printf("%f\n",((*(fourieR+j*2*(vsize-smy)+i))/(double)(hsize*vsize*4))); // k++; } } }// resize kansuu end void DFT1DV(int size, double *VINR, double *VINI, double *VOUTR, double *VOUTI) { int i,j; double PI = atan(1)*4.0; for(i=0;i