Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
mri_swapbytes.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "mrilib.h"
00008
00009
00010
00011 #define SWAB16(x) ( ( ((x)&0x00ffU)<<8 ) | ( ((x)&0xff00U)>>8 ) )
00012
00013 void mri_swapbytes( MRI_IMAGE *im )
00014 {
00015 register int ii , npix ;
00016
00017 ENTRY("mri_swapbytes") ;
00018
00019 if( im->kind != MRI_short ){
00020 fprintf( stderr , "mri_swapbytes called with non-short image kind\n" ) ;
00021 EXRETURN ;
00022 }
00023
00024 npix = im->nvox ;
00025
00026 for( ii=0 ; ii < npix ; ii++ )
00027 im->im.short_data[ii] = SWAB16( im->im.short_data[ii] ) ;
00028
00029 EXRETURN ;
00030 }
00031
00032
00033
00034
00035
00036 typedef struct { unsigned char a,b ; } twobytes ;
00037
00038 void swap_twobytes( int n , void * ar )
00039 {
00040 register int ii ;
00041 register twobytes * tb = (twobytes *) ar ;
00042 register unsigned char tt ;
00043
00044 for( ii=0 ; ii < n ; ii++ ){
00045 tt = tb[ii].a ;
00046 tb[ii].a = tb[ii].b ;
00047 tb[ii].b = tt ;
00048 }
00049 }
00050
00051 typedef struct { unsigned char a,b,c,d ; } fourbytes ;
00052
00053 void swap_fourbytes( int n , void * ar )
00054 {
00055 register int ii ;
00056 register fourbytes * tb = (fourbytes *) ar ;
00057 register unsigned char tt ;
00058
00059 for( ii=0 ; ii < n ; ii++ ){
00060 tt = tb[ii].a ;
00061 tb[ii].a = tb[ii].d ;
00062 tb[ii].d = tt ;
00063 tt = tb[ii].b ;
00064 tb[ii].b = tb[ii].c ;
00065 tb[ii].c = tt ;
00066 }
00067 }
00068
00069 typedef struct { unsigned char a,b,c,d , D,C,B,A ; } eightbytes ;
00070
00071 void swap_eightbytes( int n , void * ar )
00072 {
00073 register int ii ;
00074 register eightbytes * tb = (eightbytes *) ar ;
00075 register unsigned char tt ;
00076
00077 for( ii=0 ; ii < n ; ii++ ){
00078 tt = tb[ii].a ; tb[ii].a = tb[ii].A ; tb[ii].A = tt ;
00079 tt = tb[ii].b ; tb[ii].b = tb[ii].B ; tb[ii].B = tt ;
00080 tt = tb[ii].c ; tb[ii].c = tb[ii].C ; tb[ii].C = tt ;
00081 tt = tb[ii].d ; tb[ii].d = tb[ii].D ; tb[ii].D = tt ;
00082 }
00083 }