Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
overfim.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include <math.h>
00009 #include <stdlib.h>
00010
00011 #include "overfim.h"
00012
00013
00014
00015
00016
00017 short * RWC_create_overlay( nxover , nyover )
00018 int nxover , nyover ;
00019 {
00020 short * ov ;
00021 register int ii , npix = nxover * nyover ;
00022
00023 ov = (short *) malloc( sizeof(short) * npix ) ;
00024
00025 for( ii=0 ; ii < npix ; ii++ ) ov[ii] = RWC_OVFLAG ;
00026 return ov ;
00027 }
00028
00029
00030
00031
00032
00033
00034 int RWC_short_overlay( nxim,nyim,image , nxover,nyover ,
00035 flag,dont_overlay,checker , overlay )
00036 short * image ;
00037 int nxim,nyim , nxover,nyover , checker ;
00038 short flag , dont_overlay ;
00039 short * overlay ;
00040 {
00041 int rowsize = nxim ;
00042 static int old_rowsize = -1 ;
00043
00044 int nxdup , nydup ;
00045 static int old_nxdup = -1 ,
00046 old_nydup = -1 ;
00047
00048 static int old_checker = -1 ;
00049
00050 int ir , jc , xx,yy ;
00051 register int jj ;
00052
00053 static int * jump = NULL ;
00054 static int jump_size = -1 ;
00055 static int jump_count ;
00056
00057 short * ovp = overlay ;
00058
00059 register short * imbase ;
00060 int xfac , yfac ;
00061
00062 #ifdef OV_DEBUG1
00063 int nov = 0 ;
00064 #endif
00065
00066
00067
00068 #ifdef OV_DEBUG1
00069 if( jump_size == -1 )
00070 fprintf(stderr,"RWC: overlay called nxim=%d nxover=%d\n",nxim,nxover) ;
00071 #endif
00072
00073 if( overlay == NULL || image == NULL ||
00074 nxover == 0 || nyover == 0 ) return 1 ;
00075
00076
00077
00078
00079 if( (nxim % nxover) !=0 || (nyim % nyover) != 0 ) return 2 ;
00080
00081 nxdup = nxim / nxover ;
00082 nydup = nyim / nyover ;
00083
00084 #ifdef OV_DEBUG1
00085 if( nxdup != old_nxdup || nydup != old_nydup )
00086 fprintf(stderr,"RWC: overlay nxdup=%d nydup=%d\n",nxdup,nydup) ;
00087 #endif
00088
00089
00090
00091 if( nxdup * nydup > jump_size ){
00092 if( jump != NULL ) free(jump) ;
00093 jump_size = nxdup * nydup ;
00094 jump = (int *) malloc( sizeof(int) * jump_size ) ;
00095 if( jump == NULL ){
00096 jump_size = -1 ;
00097 return 3 ;
00098 }
00099 }
00100
00101 if( rowsize != old_rowsize ||
00102 nxdup != old_nxdup || nydup != old_nydup ||
00103 checker != old_checker ){
00104
00105 jj = 0 ;
00106 for( yy=0 ; yy < nydup ; yy++ ){
00107 for( xx=0 ; xx < nxdup ; xx++ ){
00108 if( !checker || (xx+yy)%2 == 0 )
00109 jump[jj++] = ( xx + yy * rowsize ) ;
00110 }
00111 }
00112 jump_count = jj ;
00113 old_rowsize = rowsize ;
00114 old_nxdup = nxdup ;
00115 old_nydup = nydup ;
00116 old_checker = checker ;
00117
00118 #ifdef OV_DEBUG1
00119 fprintf(stderr,"RWC_short_overlay: new jump array:\n") ;
00120 for( jj=0 ; jj < jump_size ; jj++ ) fprintf(stderr,"%d ",jump[jj]) ;
00121 fprintf(stderr,"\ncomputed from nxdup=%d nydup=%d rowsize=%d \n",
00122 nxdup,nydup,rowsize ) ;
00123 #endif
00124 }
00125
00126
00127
00128 xfac = nxdup ;
00129 yfac = rowsize * nydup ;
00130
00131 for( jc=0 ; jc < nyover ; jc++ ){
00132 for( ir=0 ; ir < nxover ; ir++,ovp++ ){
00133
00134 if( *ovp != flag ){
00135
00136 imbase = &image[ir * xfac + jc * yfac] ;
00137 for( jj=0 ; jj < jump_count ; jj++ ){
00138 if( imbase[jump[jj]] != dont_overlay ){
00139
00140 imbase[jump[jj]] = *ovp ;
00141 #ifdef OV_DEBUG1
00142 nov++ ;
00143 #endif
00144 }
00145 }
00146 }
00147 }
00148 }
00149
00150 #ifdef OV_DEBUG1
00151 fprintf(stderr,"RWC: number points overlaid = %d\n",nov);
00152 #endif
00153 return 0 ;
00154 }