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_copy.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   Copy an image.
00013 -------------------------------------------------------*/
00014 
00015 MRI_IMAGE * mri_copy( MRI_IMAGE * oldim )
00016 {
00017    MRI_IMAGE * newim ;
00018    void * oar , * nar ;
00019 
00020 ENTRY("mri_copy") ;
00021 
00022    if( oldim == NULL ) RETURN(NULL);
00023 
00024    newim = mri_new_conforming( oldim , oldim->kind ) ;
00025    oar   = mri_data_pointer( oldim ) ;
00026    nar   = mri_data_pointer( newim ) ;
00027    if( oar == NULL ){
00028      free(nar); mri_fix_data_pointer(NULL,newim);
00029    } else {
00030      memcpy( nar , oar , newim->nvox * newim->pixel_size ) ;
00031    }
00032    MRI_COPY_AUX( newim , oldim ) ;
00033    RETURN( newim );
00034 }
00035 
00036 /*---------------------------------------------------------------------*/
00037 /* Copy a 2D image, expanding it nup times in x and y.
00038 -----------------------------------------------------------------------*/
00039 
00040 MRI_IMAGE * mri_expand_2D( int nup , MRI_IMAGE *imin )  /* 22 Feb 2004 */
00041 {
00042    MRI_IMAGE *newim ;
00043    int nx,ny , nxup,nyup , ii,jj, pp,qq , ds ;
00044    char *nar , *iar ;
00045 
00046 ENTRY("mri_expand") ;
00047 
00048    /*-- sanity checks --*/
00049 
00050    if( nup < 1 || imin == NULL || imin->nz > 1 ) RETURN(NULL);
00051 
00052    if( nup == 1 ){ newim = mri_copy(imin); RETURN(newim); }
00053 
00054    iar = (char *)mri_data_pointer(imin) ; if( iar == NULL ) RETURN(NULL);
00055 
00056    nx = imin->nx ; nxup = nx*nup ;
00057    ny = imin->ny ; nyup = ny*nup ;
00058 
00059    newim = mri_new( nxup,nyup , imin->kind ) ;
00060    nar   = (char *)mri_data_pointer(newim) ;
00061    ds    = imin->pixel_size ;
00062 
00063    for( jj=0 ; jj < nyup ; jj++ ){
00064      qq = jj / nup ;
00065      for( ii=0 ; ii < nxup ; ii++ ){
00066        pp = ii / nup ;
00067        memcpy( nar + (ii+jj*nxup)*ds , iar + (pp+qq*nx)*ds , ds ) ;
00068      }
00069    }
00070 
00071    MRI_COPY_AUX( newim , imin ) ;
00072    RETURN(newim) ;
00073 }
 

Powered by Plone

This site conforms to the following standards: