Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
mri_flippo.c
Go to the documentation of this file.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_flippo( int rot , int mirror , MRI_IMAGE * im )
00020 {
00021 MRI_IMAGE * flim ;
00022 int nx,ny , fopt , nxout,nyout ;
00023 register int d1,d2,s1,s2,e1,e2,jb , i1,i2 ;
00024 float new_dx , new_dy ;
00025
00026 ENTRY("mri_flippo") ;
00027
00028
00029 if( im == NULL ) RETURN( NULL );
00030 if( rot == MRI_ROT_0 && mirror == FALSE ) RETURN( im );
00031
00032 if( ! MRI_IS_2D(im) ){
00033 fprintf(stderr,"\n*** mri_flippo only works with 2D images!\n") ;
00034 RETURN( im );
00035 }
00036
00037 nx = im->nx ; ny = im->ny ;
00038 new_dx = im->dx ; new_dy = im->dy ;
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 fopt = (mirror) ? (rot+MRI_FLMADD) : (rot) ;
00051 switch( fopt ){
00052
00053 default: RETURN(im);
00054
00055 case (MRI_ROT_90):
00056 nxout = ny ; nyout = nx ;
00057 d1 = nx ; s1 = nx-1 ; d2 = -1 ; new_dx = im->dy ; new_dy = im->dx ;
00058 break ;
00059
00060 case (MRI_ROT_180):
00061 nxout = nx ; nyout = ny ;
00062 d1 = -1 ; s1 = nx*ny-1 ; d2 = -nx ;
00063 break ;
00064
00065 case (MRI_ROT_270):
00066 nxout = ny ; nyout = nx ;
00067 d1 = -nx ; s1 = nx*(ny-1) ; d2 = 1 ; new_dx = im->dy ; new_dy = im->dx ;
00068 break ;
00069
00070 case (MRI_ROT_0+MRI_FLMADD):
00071 nxout = nx ; nyout = ny ;
00072 d1 = -1 ; s1 = nx-1 ; d2 = nx ;
00073 break ;
00074
00075 case (MRI_ROT_90+MRI_FLMADD):
00076 nxout = ny ; nyout = nx ;
00077 d1 = -nx ; s1 = nx*ny-1 ; d2 = -1 ; new_dx = im->dy ; new_dy = im->dx ;
00078 break ;
00079
00080 case (MRI_ROT_180+MRI_FLMADD):
00081 nxout = nx ; nyout = ny ;
00082 d1 = 1 ; s1 = nx*(ny-1) ; d2 = -nx ;
00083 break ;
00084
00085 case (MRI_ROT_270+MRI_FLMADD):
00086 nxout = ny ; nyout = nx ;
00087 d1 = nx ; s1 = 0 ; d2 = 1 ; new_dx = im->dy ; new_dy = im->dx ;
00088 break ;
00089
00090 }
00091
00092 flim = mri_new( nxout , nyout , im->kind ) ;
00093
00094 jb = 0 ;
00095 s2 = 0 ;
00096 e1 = s1 + nxout * d1 ;
00097 e2 = s2 + nyout * d2 ;
00098
00099 switch( im->kind ){
00100
00101 case MRI_byte:{
00102 register byte * inar = MRI_BYTE_PTR(im) ;
00103 register byte * flar = MRI_BYTE_PTR(flim) ;
00104 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00105 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ;
00106 }
00107 break ;
00108
00109 case MRI_rgb:{
00110 register byte * inar = MRI_RGB_PTR(im) ;
00111 register byte * flar = MRI_RGB_PTR(flim) ;
00112 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00113 for( i1=s1 ; i1 != e1 ; i1 += d1 ){
00114 flar[jb++] = inar[3*(i2+i1) ] ;
00115 flar[jb++] = inar[3*(i2+i1)+1] ;
00116 flar[jb++] = inar[3*(i2+i1)+2] ;
00117 }
00118 }
00119 break ;
00120
00121 case MRI_short:{
00122 register short * inar = MRI_SHORT_PTR(im) ;
00123 register short * flar = MRI_SHORT_PTR(flim) ;
00124 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00125 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ;
00126 }
00127 break ;
00128
00129 case MRI_int:{
00130 register int * inar = MRI_INT_PTR(im) ;
00131 register int * flar = MRI_INT_PTR(flim) ;
00132 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00133 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ;
00134 }
00135 break ;
00136
00137 case MRI_rgba:{
00138 register rgba * inar = MRI_RGBA_PTR(im) ;
00139 register rgba * flar = MRI_RGBA_PTR(flim) ;
00140 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00141 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ;
00142 }
00143 break ;
00144
00145 case MRI_float:{
00146 register float * inar = MRI_FLOAT_PTR(im) ;
00147 register float * flar = MRI_FLOAT_PTR(flim) ;
00148 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00149 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ;
00150 }
00151 break ;
00152
00153 case MRI_double:{
00154 register double * inar = MRI_DOUBLE_PTR(im) ;
00155 register double * flar = MRI_DOUBLE_PTR(flim) ;
00156 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00157 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ;
00158 }
00159 break ;
00160
00161 case MRI_complex:{
00162 register complex * inar = MRI_COMPLEX_PTR(im) ;
00163 register complex * flar = MRI_COMPLEX_PTR(flim) ;
00164 for( i2=s2 ; i2 != e2 ; i2 += d2 )
00165 for( i1=s1 ; i1 != e1 ; i1 += d1 ) flar[jb++] = inar[i2+i1] ;
00166 }
00167 break ;
00168
00169 }
00170
00171 flim->dx = new_dx ; flim->dy = new_dy ; flim->dz = im->dz ;
00172 RETURN( flim ) ;
00173 }