Main Page   Data Structures   File List   Data Fields   Globals  

mosaic_index.c

Go to the documentation of this file.
00001 #include        <stdio.h>
00002 #include        <malloc.h>
00003 #include        "sadie.h"
00004 #include        "mosaic.h"
00005 
00006 
00007 
00008 
00009 
00010 
00011 /*----------------------------------------------------------------------------*/
00012 /*-General Information--------------------------------------------------------*/
00013 /*                                                                            */
00014 /*   This low-level function allocates memory for a new mosaic index and      */
00015 /*   initializes its data structure.  It is based on the SADIE function       */
00016 /*   GETMEM.                                                                  */
00017 /*                                                                            */
00018 /*----------------------------------------------------------------------------*/
00019 /*-Interface Information------------------------------------------------------*/
00020 void GETMEM_MOSAIC_INDEX(
00021 int nlin,         /*  I   Number of lines in mosaic.                            */
00022 int npix,         /*  I   Number of pixels/line.                                */
00023 short   nframe,   /*  I   Number of frames.                             */
00024 MOSAIC_INDEX **out    /*  O   Address of a pointer to the mosaic index being allocated.    */
00025 )
00026 /*----------------------------------------------------------------------------*/
00027 {   register int i;
00028     long total;
00029     BYTE *ptr=NULL;
00030 
00031     /* allocate space for image data structure, image data and list entry */
00032     total = sizeof(MOSAIC_INDEX) + 2*npix*sizeof(short) + 2*npix*sizeof(short) + (nframe*4)*sizeof(short) + sizeof(REGION_OF_INTEREST);
00033     if (total < 0L) {
00034         MESSAGE('E'," Memory request failed.");
00035         goto the_end;
00036     }
00037     if (!(ptr=(BYTE *)malloc(total*sizeof(BYTE)))) {
00038         MESSAGE('E'," Memory request failed.");
00039         goto the_end;
00040     }
00041 
00042     /* assign (DEFAULT) values */
00043     *out = (MOSAIC_INDEX *)ptr;
00044     (*out)->nlin = nlin;
00045     (*out)->npix = npix;
00046     (*out)->height_max = 0;
00047     (*out)->nframe = nframe;
00048     (*out)->voffset = (short *)(ptr + sizeof(MOSAIC_INDEX));
00049     (*out)->vheight = (short *)(ptr + sizeof(MOSAIC_INDEX) + npix*sizeof(short));
00050     (*out)->hstart = 0;
00051     (*out)->hend = npix - 1;
00052     (*out)->vstart = (short *)(ptr + sizeof(MOSAIC_INDEX) + 2*npix*sizeof(short));
00053     (*out)->vend = (short *)(ptr + sizeof(MOSAIC_INDEX) + 3*npix*sizeof(short));
00054     (*out)->roi = (REGION_OF_INTEREST *)(ptr + sizeof(MOSAIC_INDEX) + 4*npix*sizeof(short));
00055     (*out)->frame = (MOSAIC_FRAME *)(ptr + sizeof(MOSAIC_INDEX) + 4*npix*sizeof(short) + sizeof(REGION_OF_INTEREST));
00056 
00057     
00058     /* initialize arrays */
00059     for (i=0; i<npix; i++) {
00060         (*out)->voffset[i] = 0;
00061         (*out)->vheight[i] = 0;
00062         (*out)->vstart[i] = 0;
00063         (*out)->vend[i] = 0;
00064     }
00065     for (i=0; i<nframe; i++) {
00066         (*out)->frame[i].startx = 0;
00067         (*out)->frame[i].endx = 0;
00068         (*out)->frame[i].starty = 0;
00069         (*out)->frame[i].endy = 0;
00070     }
00071 
00072 
00073     the_end:
00074     return;
00075     /* if (TIMES) TIMING(T_EXIT); */
00076 }
00077 
00078 /*----------------------------------------------------------------------------*/
00079 /*-General Information--------------------------------------------------------*/
00080 /*                                                                            */
00081 /*   This function releases a mosaic_index to free memory space.              */
00082 /*   It is based on the SADIE function RELIMG.                                */
00083 /*                                                                            */
00084 /*----------------------------------------------------------------------------*/
00085 /*-Interface Information------------------------------------------------------*/
00086 void RELIMG_MOSAIC_INDEX(
00087 MOSAIC_INDEX **out    /* I/O  Address of the pointer to the mosaic index to be released.   */
00088 )
00089 /*----------------------------------------------------------------------------*/
00090 {
00091     if (NAMES) {
00092         MESSAGE('I',"");
00093         MESSAGE('I',"RELIMG_MOSAIC_INDEX");
00094     }
00095 
00096     /* check input */
00097     if (!CHECKIMG_MOSAIC_INDEX(*out)) {
00098         MESSAGE('E'," Can't identify mosaic index.");
00099         goto the_end;
00100     }
00101 
00102     /* release image */
00103     RELMEM_MOSAIC_INDEX(*out);
00104     *out = NULL;
00105 
00106     the_end:
00107     return;
00108     /* if (TIMES) TIMING(T_EXIT); */
00109 }
00110  
00111 /*-General Information--------------------------------------------------------*/
00112 /*                                                                            */
00113 /*   This low-level function releases a mosaic index and frees its data        */
00114 /*   structure.  It is based on the SADIE function RELMEM.                    */
00115 /*                                                                            */
00116 /*----------------------------------------------------------------------------*/
00117 /*-Interface Information------------------------------------------------------*/
00118 void RELMEM_MOSAIC_INDEX(
00119 MOSAIC_INDEX *in      /*  I   Pointer to the mosaic index to be released.     */
00120 )
00121 /*----------------------------------------------------------------------------*/
00122 {   
00123 
00124     /* free allocated space */
00125     free(in);
00126 
00127     return;
00128     /* if (TIMES) TIMING(T_EXIT); */
00129 }
00130  
00131 /*----------------------------------------------------------------------------*/
00132 /*-General Information--------------------------------------------------------*/
00133 /*                                                                            */
00134 /*   This low-level function determines whether or not a MOSAIC_INDEX pointer */
00135 /*   points to an mosaic index that was properly created by SADIE.            */
00136 /*   It is based on the SADIE routine CHECKIMG.                               */
00137 /*                                                                            */
00138 /*----------------------------------------------------------------------------*/
00139 /*-Interface Information------------------------------------------------------*/
00140 short CHECKIMG_MOSAIC_INDEX(
00141 MOSAIC_INDEX *in      /*  I   Pointer to the mosaic index to be checked.      */
00142 )
00143 /*----------------------------------------------------------------------------*/
00144 {   
00145 
00146     return(in!=NULL);
00147 }
00148 
00149 
00150 /*----------------------------------------------------------------------------*/
00151 /*-General Information--------------------------------------------------------*/
00152 /*                                                                            */
00153 /*   This function computes the scaled version of actual mosaic index.        */
00154 /*                                                                            */
00155 /*----------------------------------------------------------------------------*/
00156 /*-Interface Information------------------------------------------------------*/
00157 void INDEX_RESAMPL(
00158 MOSAIC_INDEX *index,
00159 int scale,
00160 MOSAIC_INDEX ** outindex
00161 )
00162 /*----------------------------------------------------------------------------*/
00163 {
00164     register int i, npix, nlin, nframe;
00165     long total;
00166     BYTE *ptr=NULL;
00167 
00168     nlin = index->nlin/scale;
00169     npix = index->npix/scale;
00170     nframe = index->nframe;
00171     
00172     /* allocate space for image data structure, image data and list entry */
00173     total = sizeof(MOSAIC_INDEX) + 2*npix*sizeof(short) + 2*npix*sizeof(short) + (nframe*4)*sizeof(short) + sizeof(REGION_OF_INTEREST);
00174     if (total < 0L) {
00175         MESSAGE('E'," Memory request failed.");
00176         goto the_end;
00177     }
00178     if (!(ptr=(BYTE *)malloc(total*sizeof(BYTE)))) {
00179         MESSAGE('E'," Memory request failed.");
00180         goto the_end;
00181     }
00182 
00183     /* assign (DEFAULT) values */
00184     *outindex = (MOSAIC_INDEX *)ptr;
00185     (*outindex)->nlin = nlin;
00186     (*outindex)->npix = npix;
00187     (*outindex)->height_max = index->height_max/scale;
00188     (*outindex)->nframe = nframe;
00189     (*outindex)->voffset = (short *)(ptr + sizeof(MOSAIC_INDEX));
00190     (*outindex)->vheight = (short *)(ptr + sizeof(MOSAIC_INDEX) + npix*sizeof(short));
00191     (*outindex)->hstart = index->hstart/scale + 1;
00192     (*outindex)->hend = index->hend/scale - 1;
00193     (*outindex)->vstart = (short *)(ptr + sizeof(MOSAIC_INDEX) + 2*npix*sizeof(short));
00194     (*outindex)->vend = (short *)(ptr + sizeof(MOSAIC_INDEX) + 3*npix*sizeof(short));
00195     (*outindex)->roi = (REGION_OF_INTEREST *)(ptr + sizeof(MOSAIC_INDEX) + 4*npix*sizeof(short));
00196     (*outindex)->frame = (MOSAIC_FRAME *)(ptr + sizeof(MOSAIC_INDEX) + 4*npix*sizeof(short) + sizeof(REGION_OF_INTEREST));
00197 
00198     
00199     /* initialize arrays */
00200     for (i=0; i<npix; i++) {
00201         if (i*scale >= index->npix)
00202             break;
00203         (*outindex)->voffset[i] = index->voffset[i*scale]/scale;
00204         (*outindex)->vheight[i] = index->vheight[i*scale]/scale;
00205         (*outindex)->vstart[i] = index->vstart[i*scale]/scale + 1;
00206         (*outindex)->vend[i] = index->vend[i*scale]/scale - 1;
00207     }
00208     for (i=0; i<nframe; i++) {
00209         (*outindex)->frame[i].startx = index->frame[i].startx/scale;
00210         (*outindex)->frame[i].endx = index->frame[i].endx/scale;
00211         (*outindex)->frame[i].starty = index->frame[i].starty/scale;
00212         (*outindex)->frame[i].endy = index->frame[i].endy/scale;
00213     }
00214     for (i=0; i<2; i++) {
00215         (*outindex)->roi->top[i] = index->roi->top[i]/scale;
00216         (*outindex)->roi->bottom[i] = index->roi->bottom[i]/scale;
00217         (*outindex)->roi->left[i] = index->roi->left[i]/scale;
00218         (*outindex)->roi->right[i] = index->roi->right[i]/scale;
00219     }
00220     
00221     the_end:
00222     
00223 }

Generated on Wed Apr 9 08:56:09 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002