Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

mri_write_angif.c File Reference

#include "mrilib.h"

Go to the source code of this file.


Functions

int setup_mri_write_angif (void)
int mri_write_angif (char *fname, MRI_IMARR *imar)

Variables

char * gfilt = NULL
char * ganim = NULL
int setup = -1

Function Documentation

int mri_write_angif char *    fname,
MRI_IMARR   imar
 

Definition at line 50 of file mri_write_angif.c.

References ganim, gfilt, IMARR_COUNT, IMARR_SUBIMAGE, MRI_IMAGE::kind, mri_free(), MRI_RGB_PTR, mri_to_rgb(), MRI_IMAGE::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, pclose, popen, setup, and setup_mri_write_angif().

00051 {
00052    char gnam[32] , gt[16] , filt[512] ;
00053    MRI_IMAGE *tim , *qim ;
00054    int ii , nim ;
00055    FILE *fp ;
00056 
00057    /*-- sanity check --*/
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    /*-- make individual gifs from each file --*/
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    /*-- make the animated gif output --*/
00093 
00094    sprintf( filt , "%s Elvis.%s.*.gif > %s" , ganim , gt , fname ) ;
00095    system( filt ) ;
00096 
00097    /*-- remove individual gif files --*/
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 ; /* indicate success */
00105 }

int setup_mri_write_angif void   
 

Definition at line 13 of file mri_write_angif.c.

References AFMALL, ganim, gfilt, setup, and THD_find_executable().

Referenced by mri_write_angif().

00014 {
00015    char *pq,*pg,*pgs,*pwg ;
00016 
00017    if( setup >= 0 ) return setup ;
00018 
00019    /*-- make the commands: gfilt to produce 1 gif
00020                            ganim to animate a bunch of them --*/
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 }

Variable Documentation

char* ganim = NULL [static]
 

Definition at line 4 of file mri_write_angif.c.

Referenced by mri_write_angif(), and setup_mri_write_angif().

char* gfilt = NULL [static]
 

Definition at line 3 of file mri_write_angif.c.

Referenced by mri_write_angif(), and setup_mri_write_angif().

int setup = -1 [static]
 

Definition at line 5 of file mri_write_angif.c.

Referenced by mri_write_angif(), and setup_mri_write_angif().

 

Powered by Plone

This site conforms to the following standards: