00001
00002
00003
00004
00005
00006
00007 #include "mrilib.h"
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 MRI_IMAGE * mri_cat2D( int mx , int my , int gap , void * gapval , MRI_IMARR * imar )
00020 {
00021 int nx , ny , ii , jj , kind , ij , nxout , nyout , ijoff , jout,iout ;
00022 MRI_IMAGE * imout , * imin ;
00023 void * vout ;
00024
00025 ENTRY("mri_cat2D") ;
00026
00027
00028
00029 if( mx < 1 || my < 1 || imar == NULL || imar->num < mx*my ) RETURN( NULL );
00030 if( gap < 0 || (gap > 0 && gapval == NULL) ) RETURN( NULL );
00031
00032 for( ij=0 ; ij < mx*my ; ij++ ){
00033 imin = IMARR_SUBIMAGE(imar,ij) ;
00034 if( imin != NULL ) break ;
00035 }
00036 if( ij == mx*my ) RETURN( NULL );
00037
00038 kind = imin->kind ;
00039 nx = imin->nx ;
00040 ny = imin->ny ;
00041
00042 if( mx==1 && my==1 ){
00043 imout = mri_to_mri( kind , imin ) ;
00044 RETURN( imout );
00045 }
00046
00047 for( ij=0 ; ij < mx*my ; ij++ ){
00048 imin = IMARR_SUBIMAGE(imar,ij) ;
00049 if( imin != NULL &&
00050 (imin->kind != kind || imin->nx != nx || imin->ny != ny) )
00051 RETURN( NULL );
00052 }
00053
00054 nxout = mx * nx + (mx-1) * gap ;
00055 nyout = my * ny + (my-1) * gap ;
00056 imout = mri_new( nxout , nyout , kind ) ;
00057 vout = mri_data_pointer( imout ) ;
00058
00059 ij = 0 ;
00060 for( jj=0 ; jj < my ; jj++ ){
00061 for( ii=0 ; ii < mx ; ii++ , ij++ ){
00062
00063 imin = IMARR_SUBIMAGE(imar,ij) ;
00064 ijoff = ii * (nx+gap) + jj * (ny+gap) * nxout ;
00065
00066
00067
00068 if( imin == NULL || mri_data_pointer(imin) == NULL ){
00069 switch( kind ){
00070 case MRI_byte:{
00071 byte * pout = ((byte *) vout);
00072 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00073 (void) memset( pout+ijoff , 0 , sizeof(byte)*nx ) ;
00074 } break ;
00075
00076 case MRI_rgb:{
00077 byte * pout = ((byte *) vout);
00078 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00079 (void) memset( pout+(3*ijoff) , 0 , sizeof(byte)*(3*nx) ) ;
00080 } break ;
00081
00082 case MRI_short:{
00083 short * pout = ((short *) vout);
00084 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00085 (void) memset( pout+ijoff , 0 , sizeof(short)*nx ) ;
00086 } break ;
00087
00088 case MRI_int:{
00089 int * pout = ((int *) vout);
00090 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00091 (void) memset( pout+ijoff , 0 , sizeof(int)*nx ) ;
00092 } break ;
00093
00094 case MRI_float:{
00095 float * pout = ((float *) vout);
00096 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00097 for( iout=0 ; iout < nx ; iout++ )
00098 pout[iout+ijoff] = 0 ;
00099 } break ;
00100
00101 case MRI_double:{
00102 double * pout = ((double *) vout);
00103 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00104 for( iout=0 ; iout < nx ; iout++ )
00105 pout[iout+ijoff] = 0 ;
00106 } break ;
00107
00108 case MRI_complex:{
00109 complex * pout = ((complex *) vout);
00110 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00111 for( iout=0 ; iout < nx ; iout++ )
00112 pout[iout+ijoff].r = pout[iout+ijoff].i = 0 ;
00113 } break ;
00114 }
00115
00116
00117
00118 } else {
00119 switch( kind ){
00120 case MRI_byte:{
00121 byte * pout = ((byte *) vout) ,
00122 * pin = (byte *) MRI_BYTE_PTR(imin) ;
00123 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00124 memcpy( pout+ijoff , pin , sizeof(byte)*nx ) , pin += nx ;
00125 } break ;
00126
00127 case MRI_rgb:{
00128 byte * pout = ((byte *) vout) ,
00129 * pin = (byte *) MRI_RGB_PTR(imin) ;
00130 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00131 memcpy( pout+(3*ijoff) , pin , sizeof(byte)*(3*nx) ) , pin += 3*nx ;
00132 } break ;
00133
00134 case MRI_short:{
00135 short * pout = ((short *) vout) ,
00136 * pin = (short *) MRI_SHORT_PTR(imin) ;
00137 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00138 memcpy( pout+ijoff , pin , sizeof(short)*nx ) , pin += nx ;
00139 } break ;
00140
00141 case MRI_int:{
00142 int * pout = ((int *) vout) ,
00143 * pin = (int *) MRI_INT_PTR(imin) ;
00144 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00145 memcpy( pout+ijoff , pin , sizeof(int)*nx ) , pin += nx ;
00146 } break ;
00147
00148 case MRI_float:{
00149 float * pout = ((float *) vout) ,
00150 * pin = (float *) MRI_FLOAT_PTR(imin) ;
00151 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00152 memcpy( pout+ijoff , pin , sizeof(float)*nx ) , pin += nx ;
00153 } break ;
00154
00155 case MRI_double:{
00156 double * pout = ((double *) vout) ,
00157 * pin = (double *) MRI_DOUBLE_PTR(imin) ;
00158 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00159 memcpy( pout+ijoff , pin , sizeof(double)*nx ) , pin += nx ;
00160 } break ;
00161
00162 case MRI_complex:{
00163 complex * pout = ((complex *) vout) ,
00164 * pin = (complex *) MRI_COMPLEX_PTR(imin) ;
00165 for( jout=0 ; jout < ny ; jout++ , ijoff+=nxout )
00166 memcpy( pout+ijoff , pin , sizeof(complex)*nx ) , pin += nx ;
00167 } break ;
00168 }
00169 }
00170 }
00171 }
00172
00173
00174
00175 if( gap > 0 ){
00176
00177
00178
00179 ii = nxout * gap ;
00180 for( jj=0 ; jj < my-1 ; jj++ ){
00181 ijoff = (ny + jj * (ny+gap)) * nxout ;
00182 switch( kind ){
00183 case MRI_byte:{
00184 byte gval = *((byte *)gapval) , * pout = ((byte *) vout) ;
00185 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ;
00186 } break ;
00187
00188 case MRI_rgb:{
00189 byte rval = *(((byte *)gapval) ) ,
00190 gval = *(((byte *)gapval)+1) ,
00191 bval = *(((byte *)gapval)+2) , * pout = ((byte *) vout) ;
00192
00193 for( ij=0 ; ij < ii ; ij++ ){
00194 pout[3*(ij+ijoff) ] = rval ;
00195 pout[3*(ij+ijoff)+1] = gval ;
00196 pout[3*(ij+ijoff)+2] = bval ;
00197 }
00198 } break ;
00199
00200 case MRI_short:{
00201 short gval = *((short *)gapval) , * pout = ((short *) vout) ;
00202 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ;
00203 } break ;
00204
00205 case MRI_float:{
00206 float gval = *((float *)gapval) , * pout = ((float *) vout) ;
00207 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ;
00208 } break ;
00209
00210 case MRI_int:{
00211 int gval = *((int *)gapval) , * pout = ((int *) vout) ;
00212 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ;
00213 } break ;
00214
00215 case MRI_double:{
00216 double gval = *((double *)gapval) , * pout = ((double *) vout) ;
00217 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ;
00218 } break ;
00219
00220 case MRI_complex:{
00221 complex gval = *((complex *)gapval) , * pout = ((complex *) vout) ;
00222 for( ij=0 ; ij < ii ; ij++ ) pout[ij+ijoff] = gval ;
00223 } break ;
00224 }
00225 }
00226
00227
00228
00229 for( ii=0 ; ii < mx-1 ; ii++ ){
00230 ijoff = nx + ii*(nx+gap) ;
00231 switch( kind ){
00232 case MRI_byte:{
00233 byte gval = *((byte *)gapval) , * pout = ((byte *) vout) ;
00234 for( ij=0 ; ij < gap ; ij++ , ijoff++ )
00235 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ;
00236 } break ;
00237
00238 case MRI_rgb:{
00239 byte rval = *(((byte *)gapval) ) ,
00240 gval = *(((byte *)gapval)+1) ,
00241 bval = *(((byte *)gapval)+2) , * pout = ((byte *) vout) ;
00242
00243 for( ij=0 ; ij < gap ; ij++ , ijoff++ )
00244 for( jj=0 ; jj < nyout ; jj++ ){
00245 pout[3*(jj*nxout+ijoff) ] = rval ;
00246 pout[3*(jj*nxout+ijoff)+1] = gval ;
00247 pout[3*(jj*nxout+ijoff)+2] = bval ;
00248 }
00249 } break ;
00250
00251 case MRI_short:{
00252 short gval = *((short *)gapval) , * pout = ((short *) vout) ;
00253 for( ij=0 ; ij < gap ; ij++ , ijoff++ )
00254 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ;
00255 } break ;
00256
00257 case MRI_float:{
00258 float gval = *((float *)gapval) , * pout = ((float *) vout) ;
00259 for( ij=0 ; ij < gap ; ij++ , ijoff++ )
00260 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ;
00261 } break ;
00262
00263 case MRI_int:{
00264 int gval = *((int *)gapval) , * pout = ((int *) vout) ;
00265 for( ij=0 ; ij < gap ; ij++ , ijoff++ )
00266 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ;
00267 } break ;
00268
00269 case MRI_double:{
00270 double gval = *((double *)gapval) , * pout = ((double *) vout) ;
00271 for( ij=0 ; ij < gap ; ij++ , ijoff++ )
00272 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ;
00273 } break ;
00274
00275 case MRI_complex:{
00276 complex gval = *((complex *)gapval) , * pout = ((complex *) vout) ;
00277 for( ij=0 ; ij < gap ; ij++ , ijoff++ )
00278 for( jj=0 ; jj < nyout ; jj++ ) pout[jj*nxout+ijoff] = gval ;
00279 } break ;
00280 }
00281 }
00282 }
00283
00284 RETURN( imout );
00285 }