/********************************************************************/ /* */ /* Program Name : bmp_lanczos3_up_resize_ver**.c */ /* */ /* Author : Takashi Nakajima */ /* */ /* Revision: : Ver03 2011.01.17 拡大率のバグ修正 */ /* */ /********************************************************************/ #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 vbunshi; uint vbunbo; 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 bunshi, int bunbo, int vbunshi, int vbunbo, unsigned char *vin_buffer , unsigned char *vout); void hresize( int hsize , int vsize, int bunshi , int bunbo , double *in , double *out); void vresize( int hsize , int vsize, int bunshi , int bunbo , double *in , double *out); void print_help( void ) { fprintf( stderr, "Usage: SINC UP RESIZE [options]\n" ); fprintf( stderr, "\toptions: \n" ); fprintf( stderr, "\t -help\n" ); fprintf( stderr, "\t -i : Input File Name(BMP 24bit truecolor)\n" ); fprintf( stderr, "\t -o : Output File Name(BMP 24bit truecolor .bmp extension is automatically added.\n" ); fprintf( stderr, "\t -bunshi : kakudaigo no suihei gazou size(mataha suihei kakudairitu bunshi ,seisuu wo irete kudasai )\n" ); fprintf( stderr, "\t -bunbo : kakudai mae no suihei gazou size(mataha suihei kakudairitu bunbo ,seisuu wo irete kudasai )\n" ); fprintf( stderr, "\t -vbunshi : kakudaigo no suityoku gazou size(mataha suityoku kakudairitu bunshi ,seisuu wo irete kudasai )\n" ); fprintf( stderr, "\t -vbunbo : kakudai mae no suityoku gazou size(mataha suityoku kakudairitu bunbo ,seisuu wo irete kudasai )\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], "bunshi" ) ){ ptr->bunshi = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "bunbo" ) ){ ptr->bunbo = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "vbunshi" ) ){ ptr->vbunshi = atoi(argv[++i]); } else if ( !strcmp( &argv[i][1], "vbunbo" ) ){ ptr->vbunbo = atoi(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 { 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; 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; //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 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 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 for(i=0,k=0;ibunbo*(double)cnt->bunshi+0.5)*(int)((double)(vsize)/(double)cnt->vbunbo*(double)cnt->vbunshi)+0.5); GUPOUT = (unsigned char *)malloc(sizeof(unsigned char)*(int)((double)(hsize)/(double)cnt->bunbo*(double)cnt->bunshi+0.5)*(int)((double)(vsize)/(double)cnt->vbunbo*(double)cnt->vbunshi)+0.5); BUPOUT = (unsigned char *)malloc(sizeof(unsigned char)*(int)((double)(hsize)/(double)cnt->bunbo*(double)cnt->bunshi+0.5)*(int)((double)(vsize)/(double)cnt->vbunbo*(double)cnt->vbunshi)+0.5); int hsizekakudai,vsizekakudai; hsizekakudai = (int)((double)(hsize)/(double)cnt->bunbo*(double)cnt->bunshi+0.5); vsizekakudai = (int)((double)(vsize)/(double)cnt->vbunbo*(double)cnt->vbunshi+0.5); resize( hsize, vsize, hsizekakudai, hsize, vsizekakudai, vsize, RIN , RUPOUT); // while(1); resize( hsize, vsize, hsizekakudai, hsize, vsizekakudai, vsize, GIN , GUPOUT); resize( hsize, vsize, hsizekakudai, hsize, vsizekakudai, vsize, BIN , BUPOUT); sprintf(cnt->OutputFileName,"%s.bmp",outputfile); fpw = fopen(cnt->OutputFileName,"wb"); hsize = hsizekakudai ; vsize = vsizekakudai ; 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){ *(VOUTI+j*vsizekakudai+i) = 255.0; } *(vout+j*vsizekakudai+i) = (unsigned char)(*(VOUTI+j*vsizekakudai+i)); } } }// resize kansuu end void hresize( int hsize , int vsize, int bunshi , int bunbo , double *in , double *out) { int TAPNUM = 8;//フィルタタップ数 偶数を設定 int i,j,k,l,m,n; double center_left_iti; double center_right_iti; double temp; double iti; double x; int temp2; double *KEISUU; double KEISUU_GOUKEI; double PI = atan(1)*4.0; int hsizekakudai; hsizekakudai = (int)((double)hsize/(double)bunbo*(double)bunshi+0.5); KEISUU = (double *)malloc(sizeof(double)*TAPNUM); for(i=0;i= -3.0) && (iti <= 3.0)){ *(KEISUU+TAPNUM/2-1-k) = sin(x/3.0)/x*3.0*sin(x)/x; } else { *(KEISUU+TAPNUM/2-1-k) = 0.0; } } for(k=0;k= -3.0) && (iti <= 3.0)){ *(KEISUU+k+TAPNUM/2) = sin(x/3.0)/x*3.0*sin(x)/x; } else { *(KEISUU+k+TAPNUM/2) = 0.0; } } KEISUU_GOUKEI = 0.0; for(k=0;k=hsize){ l= 2*(hsize-1) - l; } *(out+j*vsize+i) += (*(KEISUU+k))*(*(in+l*vsize+i)); } } } } void vresize( int hsize , int vsize, int bunshi , int bunbo , double *in , double *out) { int i,j,k,l,m,n; int TAPNUM = 8;//フィルタタップ数 偶数を設定 double center_left_iti; double center_right_iti; double temp; double iti; double x; int temp2; double *KEISUU; double KEISUU_GOUKEI; double PI = atan(1)*4.0; int vsizekakudai; vsizekakudai =(int)((double)vsize/(double)bunbo*(double)bunshi+0.5); KEISUU = (double *)malloc(sizeof(double)*TAPNUM); for(i=0;i= -3.0) && (iti <= 3.0)){ *(KEISUU+TAPNUM/2-1-k) = sin(x/3.0)/x*3.0*sin(x)/x; } else { *(KEISUU+TAPNUM/2-1-k) = 0.0; } } // if(i == 1133){while(1);} for(k=0;k= -3.0) && (iti <= 3.0)){ *(KEISUU+k+TAPNUM/2) = sin(x/3.0)/x*3.0*sin(x)/x; } else { *(KEISUU+k+TAPNUM/2) = 0.0; } } KEISUU_GOUKEI = 0.0; for(k=0;k=vsize){ l= 2*(vsize-1) - l; } *(out+i*vsizekakudai+j) += (*(KEISUU+k))*(*(in+i*vsize+l)); } //if(i == 1133){while(1);} } } }