Main Page   Data Structures   File List   Data Fields   Globals  

sadie_short.c

Go to the documentation of this file.
00001 #include        <stdio.h>
00002 #include        <malloc.h>
00003 #include        <tcl.h>
00004 #include        "sadie.h"
00005 #include        "sadie_short.h"
00006 
00007 
00008 /*----------------------------------------------------------------------------*/
00009 /*-General Information--------------------------------------------------------*/
00010 /*                                                                            */
00011 /*   This low-level function allocates memory for a new image, short and      */
00012 /*   initializes its data structure.  It is based on the SADIE function       */
00013 /*   GETMEM.                                                                  */
00014 /*                                                                            */
00015 /*----------------------------------------------------------------------------*/
00016 /*-Interface Information------------------------------------------------------*/
00017 void GETMEM_SHORT(
00018 short   nbnd,     /*  I   Number of bands.                                      */
00019 short   nlin,     /*  I   Number of lines.                                      */
00020 short   npix,     /*  I   Number of pixels/line.                                */
00021 IMAGE_SHORT **out    /*  O   Address of a pointer to the image being allocated.    */
00022 )
00023 /*----------------------------------------------------------------------------*/
00024 {   register short i, j;
00025     long total;
00026     BYTE *ptr=NULL;
00027 
00028     /* allocate space for image data structure, image data and list_byte entry */
00029     total = sizeof(IMAGE_SHORT) + nbnd*sizeof(PIXEL_SHORT **) + nbnd*nlin*sizeof(PIXEL_SHORT *) + nbnd*nlin*npix*sizeof(PIXEL_SHORT);
00030     if (total < 0L) {
00031         MESSAGE('E'," Memory request failed.");
00032         goto the_end;
00033     }
00034     if (!(ptr=(BYTE *)malloc(total*sizeof(BYTE)))) {
00035         MESSAGE('E'," Memory request failed.");
00036         goto the_end;
00037     }
00038 
00039     /* assign (DEFAULT) values */
00040     *out = (IMAGE_SHORT *)ptr;
00041     (*out)->nbnd = nbnd;
00042     (*out)->nlin = nlin;
00043     (*out)->npix = npix;
00044     (*out)->nbit = (short)(sizeof(PIXEL_SHORT)*8);
00045     for (i=0; i<TLEN; (*out)->text[i++]='\0');
00046     (*out)->data = (PIXEL_SHORT ***)(ptr + sizeof(IMAGE_SHORT));
00047 
00048     /* initialize pointers */
00049     for (i=0; i<nbnd; i++) {
00050         (*out)->data[i] = (PIXEL_SHORT **)(ptr + sizeof(IMAGE_SHORT) + nbnd*sizeof(PIXEL_SHORT **) + i*nlin*sizeof(PIXEL_SHORT *));
00051         for (j=0; j<nlin; j++) {
00052             (*out)->data[i][j] = (PIXEL_SHORT *)(ptr + sizeof(IMAGE_SHORT) + nbnd*sizeof(PIXEL_SHORT **) + nbnd*nlin*sizeof(PIXEL_SHORT *) + (j*nbnd+i)*npix*sizeof(PIXEL_SHORT));
00053         }
00054     }
00055     
00056     the_end:
00057     return;
00058     /* if (TIMES) TIMING(T_EXIT); */
00059 }
00060 
00061 /*----------------------------------------------------------------------------*/
00062 /*-General Information--------------------------------------------------------*/
00063 /*                                                                            */
00064 /*   This function releases a short image to free memory space.               */
00065 /*   It is based on the SADIE function RELIMG.                                */
00066 /*                                                                            */
00067 /*----------------------------------------------------------------------------*/
00068 /*-Interface Information------------------------------------------------------*/
00069 void RELIMG_SHORT(
00070 IMAGE_SHORT **out    /* I/O  Address of the pointer to the image to be released.   */
00071 )
00072 /*----------------------------------------------------------------------------*/
00073 {
00074     if (NAMES) {
00075         MESSAGE('I',"");
00076         MESSAGE('I',"RELIMG_SHORT");
00077     }
00078 
00079     /* check input */
00080     if (!CHECKIMG_SHORT(*out)) {
00081         MESSAGE('E'," Can't identify image.");
00082         goto the_end;
00083     }
00084 
00085     /* release image */
00086     RELMEM_SHORT(*out);
00087     *out = NULL;
00088 
00089     the_end:
00090     return;
00091     /* if (TIMES) TIMING(T_EXIT); */
00092 }
00093  
00094 /*-General Information--------------------------------------------------------*/
00095 /*                                                                            */
00096 /*   This low-level function releases a short image and frees its data        */
00097 /*   structure.  It is based on the SADIE function RELMEM.                    */
00098 /*                                                                            */
00099 /*----------------------------------------------------------------------------*/
00100 /*-Interface Information------------------------------------------------------*/
00101 void RELMEM_SHORT(
00102 IMAGE_SHORT *in      /*  I   Pointer to the image to be released.                  */
00103 )
00104 /*----------------------------------------------------------------------------*/
00105 {
00106 
00107      /* free allocated space */
00108     free(in);
00109 
00110     return;
00111     /* if (TIMES) TIMING(T_EXIT); */
00112 }
00113  
00114 /*----------------------------------------------------------------------------*/
00115 /*-General Information--------------------------------------------------------*/
00116 /*                                                                            */
00117 /*   This low-level function determines whether or not an IMAGE_SHORT pointer */
00118 /*   points to an image that was properly created by SADIE.                   */
00119 /*   It is based on the SADIE routine CHECKIMG.                               */
00120 /*                                                                            */
00121 /*----------------------------------------------------------------------------*/
00122 /*-Interface Information------------------------------------------------------*/
00123 short CHECKIMG_SHORT(
00124 IMAGE_SHORT *in      /*  I   Pointer to the image to be checked.                   */
00125 )
00126 /*----------------------------------------------------------------------------*/
00127 {
00128     return(in!=NULL);
00129 }
00130 
00131 /*----------------------------------------------------------------------------*/
00132 /*-General Information--------------------------------------------------------*/
00133 /*                                                                            */
00134 /*   This low-level function finds the maximum and minimum graylevels         */
00135 /*   in a short image.  It is based on the SADIE function RANGE.              */
00136 /*                                                                            */
00137 /*----------------------------------------------------------------------------*/
00138 /*-Interface Information------------------------------------------------------*/
00139 void RANGE_SHORT(
00140 IMAGE_SHORT *in      /*  I   Pointer to the input image.                           */
00141 )
00142 /*----------------------------------------------------------------------------*/
00143 {   register PIXEL_SHORT *p1, *p2, *p3, *gmin, *gmax;
00144 
00145     /* find minimum and maximum */
00146     if (((long)in->nbnd*(long)in->nlin*(long)in->npix)%2L == 0) {
00147         p1 = &in->data[0][0][0];
00148         p2 = &in->data[0][0][1];
00149     } else {
00150         p1 = &in->data[0][0][1];
00151         p2 = &in->data[0][0][2];
00152     }
00153     p3 = &(in->data[in->nbnd-1][in->nlin-1][in->npix-1]);
00154     for (gmin=gmax=(&in->data[0][0][0]); p1<p3; p1+=2,p2+=2) {
00155         if (*p1 < *p2) {
00156             if (*p1 < *gmin) gmin = p1;
00157             if (*p2 > *gmax) gmax = p2;
00158         } else {
00159             if (*p2 < *gmin) gmin = p2;
00160             if (*p1 > *gmax) gmax = p1;
00161         }
00162     }
00163     in->gmin = *gmin;
00164     in->gmax = *gmax;
00165 
00166     /* if (TIMES) TIMING(T_EXIT); */
00167 }

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