Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
to26.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #include "mrilib.h"
00008 #include <string.h>
00009
00010 static byte map[26] =
00011 { 30, 50, 70, 90, 106, 118, 130, 140, 146, 152, 158, 164, 170,
00012 176, 182, 190, 198, 206, 212, 218, 224, 230, 236, 242, 248, 254 } ;
00013
00014 static byte bk[26] ;
00015
00016 static char * alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
00017 static char * num = "0123456789" ;
00018
00019 #define NOUT 61
00020
00021 int main( int argc , char * argv[] )
00022 {
00023 MRI_IMAGE * im ;
00024 byte * bp , bb ;
00025 int ii , jj , nn , rr , kk , nlin=0 ;
00026 char out[NOUT+1] , zout[NOUT+1] , cc,nc , *nam ;
00027
00028 if( argc < 2 ){ fprintf(stderr,"Usage: to26 NAME input.pgm > output.26\n"); exit(0); }
00029
00030 nam = argv[1] ;
00031 im = mri_read( argv[2] ) ; if( im == NULL ) exit(1) ;
00032 bp = MRI_BYTE_PTR(im) ;
00033
00034 for( ii=0 ; ii < 25 ; ii++ ) bk[ii] = (map[ii]+map[ii+1])/2 ;
00035 bk[25] = 255 ;
00036
00037 fprintf(stderr,"image dimensions = %d %d\n",im->nx,im->ny) ;
00038
00039 nn = 0 ; rr = 0 ;
00040 printf( "#undef NX_%s\n",nam) ;
00041 printf( "#undef NY_%s\n",nam) ;
00042 printf( "#define NX_%s %d\n",nam,im->nx) ;
00043 printf( "#define NY_%s %d\n",nam,im->ny) ;
00044 printf( "static char * BAR_%s[] = {\n" , nam ) ;
00045 for( ii=0 ; ii < im->nvox ; ii++ ){
00046 bb = bp[ii] ;
00047 for( jj=0 ; jj < 26 ; jj++ ) if( bb <= bk[jj] ) break ;
00048
00049 out[nn++] = (jj<26) ? alpha[jj] : 'Z' ;
00050
00051 if( nn == NOUT && ii < im->nvox-1 ){
00052 out[nn] = '\0' ;
00053 cc = out[0] ; rr = 1 ; kk = 0 ;
00054 for( jj=1 ; jj <= nn ; jj++ ){
00055 nc = out[jj] ;
00056 if( nc == cc ){
00057 if( rr == 9 ){ zout[kk++] = num[rr] ; zout[kk++] = cc ; rr = 0 ; }
00058 rr++ ;
00059 } else {
00060 if( rr == 1 ){
00061 zout[kk++] = cc ; rr = 1 ;
00062 } else if( rr == 2 ){
00063 zout[kk++] = cc ; zout[kk++] = cc ; rr = 1 ;
00064 } else {
00065 zout[kk++] = num[rr] ; zout[kk++] = cc ; rr = 1 ;
00066 }
00067 }
00068 cc = nc ;
00069 }
00070 zout[kk] = '\0' ;
00071 printf(" \"%s\",\n",zout) ; nlin++ ; nn = 0 ;
00072 }
00073 }
00074
00075 out[nn] = '\0' ;
00076 printf(" \"%s\"\n};\n",out) ; nlin++ ;
00077 printf("#undef NLINE_%s\n",nam) ;
00078 printf("#define NLINE_%s %d\n",nam,nlin) ;
00079 exit(0) ;
00080 }