Main Page   Data Structures   File List   Data Fields   Globals  

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

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