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_free.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #include "mrilib.h"
00008 
00009 /*** 7D SAFE ***/
00010 
00011 /*-------------------------------------------------------------------------*/
00012 /*! Return the pointer to the data array in an MRI_IMAGE struct.
00013 ---------------------------------------------------------------------------*/
00014 
00015 void *mri_data_pointer( MRI_IMAGE *im )
00016 {
00017    void *data ;
00018 
00019 #ifdef USE_MRI_DELAY
00020    if( im->fname != NULL && (im->fondisk & INPUT_DELAY) )
00021       mri_input_delay( im ) ;
00022 #endif
00023 
00024    if( im == NULL ) return NULL ;  /* 27 Jul 2004 */
00025 
00026    switch( im->kind ){
00027       case MRI_byte:   data = im->im.byte_data   ; break ;
00028       case MRI_short:  data = im->im.short_data  ; break ;
00029       case MRI_int:    data = im->im.int_data    ; break ;
00030       case MRI_float:  data = im->im.float_data  ; break ;
00031       case MRI_double: data = im->im.double_data ; break ;
00032       case MRI_complex:data = im->im.complex_data; break ;
00033       case MRI_rgb:    data = im->im.rgb_data    ; break ;
00034       case MRI_rgba:   data = im->im.rgba_data   ; break ;
00035       default:         data = NULL               ; break ;
00036    }
00037    return data ;
00038 }
00039 
00040 /*-------------------------------------------------------------------------*/
00041 /*! Modify the data pointer in an MRI_IMAGE struct.
00042 ---------------------------------------------------------------------------*/
00043 
00044 void mri_fix_data_pointer( void *ptr , MRI_IMAGE *im )
00045 {
00046    if( im == NULL ) return ;
00047    switch( im->kind ){
00048       case MRI_byte:   im->im.byte_data   = (byte *)    ptr; break ;
00049       case MRI_short:  im->im.short_data  = (short *)   ptr; break ;
00050       case MRI_int:    im->im.int_data    = (int   *)   ptr; break ;
00051       case MRI_float:  im->im.float_data  = (float *)   ptr; break ;
00052       case MRI_double: im->im.double_data = (double *)  ptr; break ;
00053       case MRI_complex:im->im.complex_data= (complex *) ptr; break ;
00054       case MRI_rgb:    im->im.byte_data   = (byte *)    ptr; break ;
00055       case MRI_rgba:   im->im.rgba_data   = (rgba *)    ptr; break ;
00056    }
00057    return ;
00058 }
00059 
00060 /*-------------------------------------------------------------------------*/
00061 /*! Get rid of an MRI_IMAGE struct and all its contents.
00062 ---------------------------------------------------------------------------*/
00063 
00064 void mri_free( MRI_IMAGE *im )
00065 {
00066    void *ptr ;
00067 
00068 ENTRY("mri_free") ;
00069    if( im == NULL ) EXRETURN ;
00070 #ifdef USE_MRI_DELAY
00071    if( im->fname != NULL ){ free(im->fname) ; im->fname = NULL ; }
00072    im->fondisk = 0 ;
00073 #endif
00074    if( im->name != NULL ){ free(im->name) ; im->name = NULL ; }
00075    ptr = mri_data_pointer(im) ;
00076    if( ptr != NULL ) free(ptr) ;
00077    free(im) ;
00078    EXRETURN ;
00079 }
00080 
00081 /*-------------------------------------------------------------------------*/
00082 /*! Return the size (bytes) of one data element of the given type.
00083 ---------------------------------------------------------------------------*/
00084 
00085 int mri_datum_size( MRI_TYPE typ )
00086 {
00087    switch( typ ){
00088       case MRI_byte:    return sizeof(byte) ;
00089       case MRI_short:   return sizeof(short) ;
00090       case MRI_int:     return sizeof(int) ;
00091       case MRI_float:   return sizeof(float) ;
00092       case MRI_double:  return sizeof(double) ;
00093       case MRI_complex: return sizeof(complex) ;
00094       case MRI_rgb:     return 3*sizeof(byte) ;
00095       case MRI_rgba:    return sizeof(rgba) ;
00096       default:          return 0 ;
00097    }
00098 }
00099 
00100 /*-------------------------------------------------------------------------*/
00101 /*! Replace the guts of MRI_IMAGE struct qim with those of zim.
00102     Afterwards, what's left of zim is mri_free()-ed, so don't ever refer
00103     to it again. If you want a copy of an image, use mri_copy() instead.
00104 ---------------------------------------------------------------------------*/
00105 
00106 void mri_move_guts( MRI_IMAGE *qim , MRI_IMAGE *zim )
00107 {
00108    void *ptr ;
00109 
00110 ENTRY("mri_move_guts") ;
00111 
00112    if( qim == NULL || zim == NULL ) EXRETURN ;  /* stupid caller */
00113 
00114    /* destroy the contents inside qim, if any */
00115 
00116 #ifdef USE_MRI_DELAY
00117    if( qim->fname != NULL ) free(qim->fname) ;
00118 #endif
00119    if( qim->name != NULL ) free(qim->name) ;
00120    ptr = mri_data_pointer(qim) ;
00121    if( ptr != NULL ) free(ptr) ;
00122 
00123    /* put the contents of zim in their place */
00124 
00125    *qim = *zim ;
00126 
00127    /* NULL out the contents of zim, then free() it */
00128 
00129    mri_fix_data_pointer( NULL , zim ) ;
00130    zim->name = NULL ;
00131 #ifdef USE_MRI_DELAY
00132    zim->fname = NULL ;
00133 #endif
00134    free(zim) ; EXRETURN ;
00135 }
00136 
00137 /*---------------- added fake rint() 12 Feb 2001 ---------------*/
00138 
00139 #ifdef NO_RINT
00140 double rint( double x )
00141 {
00142    int nn ;
00143 
00144    if( x >= 0.0 ) nn = (int)(x+0.49999999) ;
00145    else           nn = (int)(x-0.49999999) ;
00146    return (double)nn ;
00147 }
00148 #endif
 

Powered by Plone

This site conforms to the following standards: