Doxygen Source Code Documentation
mri_overlay.c File Reference
#include "mrilib.h"Go to the source code of this file.
Functions | |
| void | mri_overlay_2D (MRI_IMAGE *imbase, MRI_IMAGE *imover, int ix, int jy) |
Function Documentation
|
||||||||||||||||||||
|
Overlay a smaller 2D image into a larger 2D image.
Definition at line 20 of file mri_overlay.c. References ENTRY, imbase, MRI_IMAGE::kind, mri_data_pointer(), mri_free(), mri_to_byte(), mri_to_rgb(), MRI_TYPE_NAME, MRI_IMAGE::nx, MRI_IMAGE::ny, MRI_IMAGE::pixel_size, and STATUS. Referenced by AFNI_splashup().
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 }
|