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_overlay.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 /*----------------------------------------------------------------------------*/
00010 /*! Overlay a smaller 2D image into a larger 2D image.
00011     - 06 Aug 1999: Overlay imover into imbase at position ix,jy.
00012                    - Input images must contain the same kind of data!
00013                    - ix >= 0 is offset from left; ix < 0 is from right
00014                    - jy >= 0 is offset from top ; jy < 0 is from bottom
00015     - 08 Jun 2000: Modified to allow for imover being too big to fit.
00016     - 13 Nov 2002: Modified to allow some type conversion from imover to imbase.
00017     - 15 Apr 2003: Fixed use of imover to imov to get 'ov' pointer (oopsie).
00018 ------------------------------------------------------------------------------*/
00019 
00020 void mri_overlay_2D( MRI_IMAGE *imbase , MRI_IMAGE *imover , int ix , int jy )
00021 {
00022    byte *ba , *ov ;
00023    int nxba,nyba , nxov,nyov , jj , nxxov,nyyov , psiz ;
00024    MRI_IMAGE *imov ;
00025 
00026 ENTRY("mri_overlay_2D") ;
00027 
00028    if( imbase == NULL || imover == NULL ){
00029 STATUS("bad inputs") ;
00030      EXRETURN ;  /* bad inputs */
00031    }
00032 
00033    /* 13 Nov 2002: possibly do type conversion on imover to match imbase */
00034 
00035    if( imbase->kind == imover->kind ){
00036      STATUS("direct overlay possible") ;
00037      imov = imover ;
00038    } else if( imbase->kind == MRI_byte && imover->kind == MRI_rgb ){
00039      STATUS("conversion to byte needed") ;
00040      imov = mri_to_byte( imover ) ;
00041    } else if( imbase->kind == MRI_rgb  && imover->kind == MRI_byte ){
00042      STATUS("conversion to RGB needed") ;
00043      imov = mri_to_rgb( imover ) ;
00044    } else {
00045      if(PRINT_TRACING){
00046        char str[256] ;
00047        sprintf(str,"incompatible inputs: imbase=%s imover=%s",
00048                MRI_TYPE_NAME(imbase) , MRI_TYPE_NAME(imover) ) ;
00049        STATUS(str);
00050      }
00051      EXRETURN ;   /* bad inputs */
00052    }
00053 
00054    /* get dimensions and pointers of images */
00055 
00056    nxba = imbase->nx ; nyba = imbase->ny ; ba = mri_data_pointer(imbase) ;
00057    nxov = imov  ->nx ; nyov = imov  ->ny ; ov = mri_data_pointer(imov  ) ;
00058    psiz = imbase->pixel_size ;
00059 
00060    if( ix >= nxba || jy >= nyba ){          /* bad placement */
00061 STATUS("overlay oompossible") ;
00062      if( imov != imover ) mri_free(imov) ;
00063      EXRETURN ;
00064    }
00065 
00066    /* negative offsets are from right & bottom */
00067 
00068    if( ix < 0 ){
00069      ix = nxba + ix ;
00070      if( ix < 0 ){ /* bad */
00071       STATUS("ix < 0"); if( imov != imover ) mri_free(imov); EXRETURN;
00072      }
00073    }
00074    if( jy < 0 ){
00075      jy = nyba + jy ;
00076      if( jy < 0 ){ /* bad */
00077       STATUS("jy < 0"); if( imov != imover ) mri_free(imov); EXRETURN;
00078      }
00079    }
00080 
00081    nxxov = nxov ;                           /* length of overlay row */
00082    if( ix+nxov > nxba ) nxxov = nxba - ix ; /* row too long for base? */
00083 
00084    nyyov = nyov ;                           /* number of overlay rows */
00085    if( jy+nyov > nyba ) nyyov = nyba - jy ; /* too many rows for base? */
00086 
00087    /* actually overlay each row */
00088 STATUS("overlaying now") ;
00089 
00090    for( jj=0 ; jj < nyyov ; jj++ )
00091      memcpy( ba + ((jy+jj)*nxba + ix)*psiz , ov + jj*nxov*psiz , nxxov*psiz ) ;
00092 
00093    if( imov != imover ) mri_free(imov) ;  /* throw away converted overlay? */
00094    EXRETURN ;
00095 }
 

Powered by Plone

This site conforms to the following standards: