Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
mri_write_angif.c
Go to the documentation of this file.00001 #include "mrilib.h"
00002
00003 static char *gfilt=NULL ;
00004 static char *ganim=NULL ;
00005 static int setup=-1 ;
00006
00007
00008
00009
00010
00011
00012
00013 int setup_mri_write_angif( void )
00014 {
00015 char *pq,*pg,*pgs,*pwg ;
00016
00017 if( setup >= 0 ) return setup ;
00018
00019
00020
00021
00022 pg = THD_find_executable( "ppmtogif" ) ;
00023 if( pg == NULL ){ setup = 0; return setup; }
00024 pq = THD_find_executable( "ppmquant" ) ;
00025 if( pq == NULL ){ setup = 0; return setup; }
00026 pgs = THD_find_executable( "gifsicle" ) ;
00027 if( pgs == NULL ){
00028 pwg = THD_find_executable( "whirlgif" ) ;
00029 if( pwg == NULL ){ setup = 0; return setup; }
00030 }
00031
00032 gfilt = AFMALL(char, strlen(pg)+strlen(pq)+32) ;
00033 sprintf( gfilt , "%s 127 | %s > %%s" , pq,pg ) ;
00034
00035 if( pgs != NULL ){
00036 ganim = AFMALL(char, strlen(pgs)+64) ;
00037 sprintf(ganim,"%s -d 10 -l -O1 -k 127 --method median-cut",pgs) ;
00038 } else {
00039 ganim = AFMALL(char, strlen(pwg)+64) ;
00040 sprintf(ganim,"%s -loop -time 10",pwg) ;
00041 }
00042
00043 setup = 1; return setup;
00044 }
00045
00046
00047
00048
00049
00050 int mri_write_angif( char *fname , MRI_IMARR *imar )
00051 {
00052 char gnam[32] , gt[16] , filt[512] ;
00053 MRI_IMAGE *tim , *qim ;
00054 int ii , nim ;
00055 FILE *fp ;
00056
00057
00058
00059 if( fname == NULL || fname[0] == '\0' ||
00060 imar == NULL || IMARR_COUNT(imar) < 2 ) return 0 ;
00061
00062 if( setup < 0 ) setup_mri_write_angif() ;
00063 if( setup == 0 ) return 0 ;
00064
00065
00066
00067 nim = IMARR_COUNT(imar) ;
00068
00069 sprintf(gt,"%x",(unsigned int)imar) ; gt[5] = '\0' ;
00070
00071 for( ii=0 ; ii < nim ; ii++ ){
00072 sprintf(gnam,"Elvis%s.%05d.gif",gt,ii) ;
00073
00074 tim = IMARR_SUBIMAGE(imar,ii) ; if( tim == NULL ) continue ;
00075 qim = tim ;
00076 if( tim->kind != MRI_rgb ) qim = mri_to_rgb( tim ) ;
00077
00078 sprintf( filt , gfilt , gnam ) ;
00079 fp = popen( filt , "w" ) ;
00080 if( fp == NULL ){
00081 fprintf(stderr,"** Can't open output filter %s\n",filt) ;
00082 return 0 ;
00083 }
00084
00085 fprintf(fp,"P6\n%d %d\n255\n" , qim->nx,qim->ny ) ;
00086 fwrite( MRI_RGB_PTR(qim), sizeof(byte), 3*qim->nvox, fp ) ;
00087 pclose(fp) ;
00088
00089 if( qim != tim ) mri_free(qim) ;
00090 }
00091
00092
00093
00094 sprintf( filt , "%s Elvis.%s.*.gif > %s" , ganim , gt , fname ) ;
00095 system( filt ) ;
00096
00097
00098
00099 for( ii=0 ; ii < nim ; ii++ ){
00100 sprintf(gnam,"Elvis%s.%05d.gif",gt,ii) ;
00101 remove(gnam) ;
00102 }
00103
00104 return 1 ;
00105 }