/***************************************************************************************/ /* */ /* Program Name : bmp_nxnoverlapdct_up_resize_1ton_ver**.c */ /* */ /* Date : 09.01.23 New Create */ /* */ /* Author : Takashi Nakajima */ /* */ /* Function : 4x4 DCT Nbai UP RESIZE dct overlaped */ /* */ /* Limitation : bitmap 24bit true color only */ /* */ /***************************************************************************************/ #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 SCALE, int OVERLAP_NUM,int MB_SIZ,int hsize, int vsize, int sizeminus, int smy, unsigned char *vin_buffer , unsigned char *vout); void resize8x8 (double*,double*,double*,double *VINRptr,double *VINIptr,double *VOUTRptr,double *VOUTIptr,int hsize,int vsize,double *kariR,int smy,int sizeminus,unsigned char *vout); void print_help( void ) { fprintf( stderr, "Usage: nxnDCT UP RESIZE [options]\n" ); fprintf( stderr, "\toptions: \n" ); fprintf( stderr, "\t -help : \245\330\245\353\245\327\245\341\245\303\245\273\241\274\245\270\275\320\316\317\n" ); fprintf( stderr, "\t -i : 入力ファイル名(true color BMP画像)\n" ); fprintf( stderr, "\t -o : 出力ファイル名(true color BMP画像)\n" ); // fprintf( stderr, "\t -x : 出力補正スペクトルを何倍にするか指定\n" ); // fprintf( stderr, "\t -orgx : 水平画素サイズ(8の倍数)\n" ); // fprintf( stderr, "\t -orgy : 垂直画素サイズ(8の倍数)\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; int MB_SIZ; int OVERLAP_NUM;//2010.1.3 add int SCALE; org_image_x = ORG_IMAGE_X; org_image_y = ORG_IMAGE_Y; if( argc < 2 ) { print_help(); exit(0); } 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); } /***************************************************/ /* 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 = MB_SIZ*(SCALE-1); resize( SCALE,OVERLAP_NUM,MB_SIZ, hsize, vsize, sizeminus, cnt->smy, RIN , RUPOUT); resize( SCALE,OVERLAP_NUM,MB_SIZ, hsize, vsize, sizeminus, cnt->smy, GIN , GUPOUT); resize( SCALE,OVERLAP_NUM,MB_SIZ, hsize, vsize, sizeminus, cnt->smy, BIN , BUPOUT); free(BIN); free(RIN); free(GIN); sprintf(cnt->OutputFileName,"%s.bmp",outputfile); fpw = fopen(cnt->OutputFileName,"wb"); hsize = hsize*SCALE; vsize = vsize*SCALE; /************************/ /* 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;ivsize-1){ p= 2*vsize-2-p; } if(q<0){ q=-q; } else if(q>hsize-1){ q= 2*hsize-2-q; } *(VINRptr+l*DCT_VSIZE+k)=*(VINRR+q*vsize+p); } } printf("i= %d,j = %d\n",i,j); // while(1); resize8x8(VOUTR,VINR,VINI,VINRptr,VINIptr,VOUTRptr,VOUTIptr,DCT_HSIZE,DCT_VSIZE,kariR,DCT_HSIZE*(SCALE-1),DCT_VSIZE*(SCALE-1),vvv); for(k=0;k= 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++; } } free(fourieR); free(fourieI); } 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