//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* // Program fraunhofer //=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* #include "cip.h" #include "complex.h" //---- definition of fundermental constants //---- experimental settings const int N = 256; // size of image //---- prototypes of functions void Load( char* fname, Complex h[N][N] ); void Save( char* fname, Complex H[N][N], double amp ); void FFT1( int sign, Complex src[N], Complex dst[N] ); void FFT2( int sign, Complex src[N][N], Complex dst[N][N] ); //---- tables class ExpTable { Complex expo[2*N]; public: ExpTable( void ){ for( int p=-N+1 ; p<=N-1 ; p++ ){ expo[p+N] = Complex( cos(2*M_PI/N*p), sin(2*M_PI/N*p) ); } } inline Complex operator [] ( int p ){ return expo[p+N]; } } Exp; class RevTable { int reve[N]; public: RevTable( void ){ for( int i=0 ; i>=1 ){ if( i&mask1 ) rev|=mask2; } reve[i] = rev; } } inline int operator [] ( int i ){ return reve[i]; } } Rev; //---- main function int main( void ) { static Complex h[N][N], H[N][N]; char buf[32], film[32], screen[32]; printf("The input file name of the film image = "); fgets( buf, 32, stdin ); if( 1 != sscanf( buf, "%s", film ) ) return 1; printf("The output file name of the screen image = "); fgets( buf, 32, stdin ); if( 1 != sscanf( buf, "%s", screen ) ) return 1; printf("Lighting up the film....\n"); Load( film, H ); printf("Propagating wave from the film to the screen....\n"); FFT2( -1, H, h ); printf("Taking this picture to the another film\n"); Save( screen, h, 1.0 ); return 0; } //---- load pgm file(raw) file to the given complex array void Load( char* fname, Complex h[N][N] ) { FILE* fptr = fopen( fname, "rb" ); if( fptr == NULL ){ fprintf( stderr, "File not found!\n" ); exit(1); } char header[64]; for( int significant=0 ; significant<3 ; ){ fgets( header, 64, fptr ); if( header[0] != '#' ) significant++; } u_char buf[N*N]; fread( buf, sizeof(u_char), N*N, fptr ); u_char* ptr = buf; for( int i=0 ; i 1.0 ) bright = 1.0; if( bright < 0.0 ) bright = 0; *ptr++ = (u_char)(255.0*bright); } } fwrite( buf, sizeof(u_char), N*N, fptr ); fclose( fptr ); } //---- 1-Dimensional Fast Fourier Transform (not used in this program) void FFT1( int sign, Complex src[N], Complex dst[N] ) { int k; // copy from source array at reversed index to destination array for( int j=0 ; j>=1 ){ for( k0=0, p=0 ; k0>=1 ){ for( k0=0, p=0 ; k0