Doxygen Source Code Documentation
mri_flippo.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
MRI_IMAGE * | mri_flippo (int rot, int mirror, MRI_IMAGE *im) |
Function Documentation
|
Definition at line 19 of file mri_flippo.c. References MRI_IMAGE::dx, MRI_IMAGE::dy, MRI_IMAGE::dz, ENTRY, i1, i2, MRI_IMAGE::kind, MRI_BYTE_PTR, MRI_COMPLEX_PTR, MRI_DOUBLE_PTR, MRI_FLOAT_PTR, MRI_INT_PTR, MRI_IS_2D, mri_new(), MRI_RGB_PTR, MRI_RGBA_PTR, MRI_SHORT_PTR, MRI_IMAGE::nx, MRI_IMAGE::ny, RETURN, and s2. Referenced by AFNI_slice_flip(), ISQ_make_image(), ISQ_manufacture_one(), ISQ_process_mri(), ISQ_saver_CB(), main(), and plot_image_surface().
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 /** sanity check **/ 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 /* set the values to control the copy order: 00041 nxout = x dimen in output 00042 nyout = y dimen in output 00043 d1 = stepsize in original data in the new x direction 00044 d2 = stepsize in original data in the new y direction 00045 s1 = index in original data of new (0,0) point 00046 00047 also, flip the dimensions for the 90 and 270 rotates 00048 */ 00049 00050 fopt = (mirror) ? (rot+MRI_FLMADD) : (rot) ; 00051 switch( fopt ){ 00052 00053 default: RETURN(im); /* should not happen */ 00054 00055 case (MRI_ROT_90): /* ROT_90, no mirror */ 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): /* ROT_180, no mirror */ 00061 nxout = nx ; nyout = ny ; 00062 d1 = -1 ; s1 = nx*ny-1 ; d2 = -nx ; 00063 break ; 00064 00065 case (MRI_ROT_270): /* ROT_270, no mirror */ 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): /* ROT_0, mirror */ 00071 nxout = nx ; nyout = ny ; 00072 d1 = -1 ; s1 = nx-1 ; d2 = nx ; 00073 break ; 00074 00075 case (MRI_ROT_90+MRI_FLMADD): /* ROT_90, mirror */ 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): /* ROT_180, mirror */ 00081 nxout = nx ; nyout = ny ; 00082 d1 = 1 ; s1 = nx*(ny-1) ; d2 = -nx ; 00083 break ; 00084 00085 case (MRI_ROT_270+MRI_FLMADD): /* ROT_270, mirror */ 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:{ /* 11 Feb 1999 */ 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 } |