Main Page   Data Structures   File List   Data Fields   Globals  

control.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 
00006 /*
00007 ##########################################
00008 # control.c -
00009 #   File from the SADIE library.  Updated for use on UNIX and
00010 #   in tclSadie.
00011 #
00012 # RCS: $Id: control.c,v 2.4 2000/08/08 22:54:32 giri Exp $ 
00013 # 
00014 # Digital Image Analysis Lab
00015 # Dept. of Electrical and Computer Engineering
00016 # University of Arizona
00017 ##########################################
00018 */
00019 
00020 /* RCS Indentification information */
00021 static char rcsid[] = "$Id: control.c,v 2.4 2000/08/08 22:54:32 giri Exp $";
00022 
00023 /* Added 4/2/97 by S.Conner */
00024 extern char *msg_ptr;
00025 extern Tcl_Interp *MainTclInterp;
00026 
00027 char *functions[T_END][2] = { {"", ""},
00028 {"BILTOBSQ", "biltobsq.c"},
00029 {"BSQTOBIL", "bsqtobil.c"},
00030 {"CHECKER", "checker.c"},
00031 {"CHECKIMG", "control.c"},
00032 {"CHIRP", "chirp.c"},
00033 {"CLUSTER", "cluster.c"},
00034 {"COM2REAL", "com2real.c"},
00035 {"COMBINE", "combine.c"},
00036 {"COMPARE", "compare.c"},
00037 {"CONTNORM", "contnorm.c"},
00038 {"CONTOUR", "contour.c"},
00039 {"COVAR", "covar.c"},
00040 {"CSPLINE", "geomwarp.c"},
00041 {"DECORSTR", "decorstr.c"},
00042 {"DESTRIPE", "destripe.c"},
00043 {"DISK2IMG", "disk2img.c"},
00044 {"DSPL2IMG", "dspl2img.c"},
00045 {"DUPL", "dupl.c"},
00046 {"EDGE", "edge.c"},
00047 {"EIGEN", "eigen.c"},
00048 {"EXPAND", "expand.c"},
00049 {"FCONVL", "fconvl.c"},
00050 {"FFT1D", "fft2d.c"},
00051 {"FFT2D", "fft2d.c"},
00052 {"FHT1D", "fht2d.c"},
00053 {"FHT2D", "fht2d.c"},
00054 {"FILTER", "filter.c"},
00055 {"FINI", "control.c"},
00056 {"FLTBOX", "filter.c"},
00057 {"FLTCONE", "filter.c"},
00058 {"FLTCYL", "filter.c"},
00059 {"FLTEXP", "filter.c"},
00060 {"FLTGAUSS", "filter.c"},
00061 {"FUNCTION", "function.c"},
00062 {"GEOMCOEF", "geomcoef.c"},
00063 {"GEOMWARP", "geomwarp.c"},
00064 {"GETMEM", "control.c"},
00065 {"GRADIENT", "gradient.c"},
00066 {"GRAYSCAL", "grayscal.c"},
00067 {"GRID", "grid.c"},
00068 {"HELP", "control.c"},
00069 {"HISTEQ", "histeq.c"},
00070 {"HISTOGRM", "histogrm.c"},
00071 {"HMOSAIC", "hmosaic.c"},
00072 {"HSVTORGB", "hsvtorgb.c"},
00073 {"IMG2DISK", "img2disk.c"},
00074 {"IMG2DSPL", "img2dspl.c"},
00075 {"IMG2EPSF", "img2epsf.c"},
00076 {"IMG2PICT", "img2pict.c"},
00077 {"IMG2TAPE", "img2tape.c"},
00078 {"IMG2TEXT", "img2text.c"},
00079 {"IMG2TIFF", "img2tiff.c"},
00080 {"IMG2VECT", "img2vect.c"},
00081 {"INFO", "info.c"},
00082 {"INIT", "control.c"},
00083 {"INSERT", "insert.c"},
00084 {"MATRIX_INVERT", "matrix_invert.c"},
00085 {"LABEL", "label.c"},
00086 {"LVLSLICE", "lvlslice.c"},
00087 {"MAIN", ""},
00088 {"MATCH", "match.c"},
00089 {"MAXLIKE", "maxlike.c"},
00090 {"MEDIAN", "median.c"},
00091 {"MESSAGE", "control.c"},
00092 {"MOSAIC", "mosaic.c"},
00093 {"MINDIST", "mindist.c"},
00094 {"PACK", "control.c"},
00095 {"PCT", "pct.c"},
00096 {"PICT2IMG", "pict2img.c"},
00097 {"PIXLDUMP", "pixldump.c"},
00098 {"PLOT", "plot.c"},
00099 {"PROGRESS", "control.c"},
00100 {"PSPECT", "pspect.c"},
00101 {"PSPECT1D", "pspect.c"},
00102 {"RANDOM", "random.c"},
00103 {"RANGE", "control.c"},
00104 {"REAL2COM", "real2com.c"},
00105 {"REFINE", "refine.c"},
00106 {"RELIEF", "relief.c"},
00107 {"RELIMG", "control.c"},
00108 {"RELMEM", "control.c"},
00109 {"RESAMPL", "resampl.c"},
00110 {"RGBTOHSV", "rgbtohsv.c"},
00111 {"RMSDIFF", "rmsdiff.c"},
00112 {"ROISTATS", "roistats.c"},
00113 {"ROTATE", "rotate.c"},
00114 {"SCATTER", "scatter.c"},
00115 {"SCONVL", "sconvl.c"},
00116 {"SEGMENT", "segment.c"},
00117 {"SIGMAP", "sigmap.c"},
00118 {"SINESTAR", "sinestar.c"},
00119 {"SINEWAVE", "sinewave.c"},
00120 {"STATS", "stats.c"},
00121 {"STRETCH", "stretch.c"},
00122 {"SUBSAMPL", "subsampl.c"},
00123 {"SWAP", "control.c"},
00124 {"TAPE2IMG", "tape2img.c"},
00125 {"TEST", ""},
00126 {"TFINVERT", "stretch.c"},
00127 {"TFLINEAR", "stretch.c"},
00128 {"TFLOG", "stretch.c"},
00129 {"TFPLT", "stretch.c"},
00130 {"TFQUANT", "stretch.c"},
00131 {"TFROOT", "stretch.c"},
00132 {"TFSAT", "stretch.c"},
00133 {"TFSCALE", "stretch.c"},
00134 {"TFSQUARE", "stretch.c"},
00135 {"TFTABLE", "stretch.c"},
00136 {"TFTHRESH", "stretch.c"},
00137 {"TIFF2IMG", "tiff2img.c"},
00138 {"TIMING", "control.c"},
00139 {"TRNSFORM", "trnsform.c"},
00140 {"UNPACK", "control.c"},
00141 {"VECT2IMG", "vect2img.c"},
00142 {"VMOSAIC", "vmosaic.c"},
00143 {"VSTRETCH", "vstretch.c"},
00144 {"WINDOW", "window.c"},
00145 {"WTFCAVG", "window.c"},
00146 {"WTFDIVER", "window.c"},
00147 {"WTFMAJ", "window.c"},
00148 {"WTFMAX", "window.c"},
00149 {"WTFMIN", "window.c"},
00150 {"WTFVAR", "window.c"}
00151 };
00152 
00153 typedef struct _list
00154 {                               /* Data structure for tracking images */
00155   IMAGE *image;
00156   struct _list *next;
00157 } list;
00158 
00159 short ABORT = FALSE;            /* Added by SBA, 11-02-90 */
00160 
00161 static short i = 0, w = 0, e = 0;       /* Message counts */
00162 
00163 static short top = 0;           /* Number of functions on the stack */
00164 
00165 static short stack[T_END];      /* Stack of function calls */
00166 
00167 static long calls[T_END];       /* Number of calls per function */
00168 
00169 static long actms[T_END];       /* Accumulated times per function */
00170 
00171 static FILE *sys = NULL;        /* Pointer to system log-file */
00172 
00173 static list *img = NULL;        /* List of allocated images */
00174 
00175 #ifdef WINNT
00176 int
00177 rint (double value)
00178 {
00179   int result;
00180 
00181   if (value > 0.0)
00182     {
00183       result = (int) (value + 0.5);
00184     }
00185   else
00186     {
00187       result = (int) (value - 0.5);
00188     }
00189 }
00190 #endif
00191 
00192 /*-Copyright Information------------------------------------------------------*/
00193 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00194 /*----------------------------------------------------------------------------*/
00195 /*-General Information--------------------------------------------------------*/
00196 /*                                                                            */
00197 /*   This function initializes a SADIE program and must be called before      */
00198 /*   any other SADIE function. If desired, global system variables must       */
00199 /*   be set before this function is called.                                   */
00200 /*                                                                            */
00201 /*----------------------------------------------------------------------------*/
00202 /*-Interface Information------------------------------------------------------*/
00203 char *SLOG = NULL;              /*  I   Name of the system log-file.                  */
00204 short NAMES = ON;               /*  I   Switch, giving amount of log-file output:     */
00205                         /*      ON    -   function names are listed.          */
00206                         /*      OFF   -   function names are suppressed.      */
00207 short TIMES = OFF;              /*  I   Switch, giving status of timing facility:     */
00208                         /*      ON    -   timing enabled.                     */
00209                         /*      OFF   -   timing disabled.                    */
00210 short LINES = OFF;              /*  I   Switch, giving status of progress indicator:  */
00211                         /*      ON    -   progress indicator enabled.         */
00212                         /*      OFF   -   progress indicator disabled.        */
00213 void
00214 INIT ()
00215 /*----------------------------------------------------------------------------*/
00216 {
00217   char msg[SLEN];
00218 
00219   /* open log-file */
00220   if (SLOG == NULL || (sys = fopen (SLOG, "w+")) == NULL)
00221     {
00222       sys = stdout;
00223     }
00224 
00225   TIMING (T_MAIN);
00226   if (TIMES)
00227     TIMING (T_INIT);
00228 
00229   if (NAMES)
00230     {
00231       MESSAGE ('I', "INIT");
00232       MESSAGE ('I', "");
00233     }
00234   MESSAGE ('I', LOCALE);
00235   MESSAGE ('I', SYSTEM);
00236   MESSAGE ('I', "");
00237   sprintf (msg, " %.*s", strlen (ctime (actms)) - 1, ctime (actms));
00238   MESSAGE ('I', msg);
00239 
00240 the_end:
00241   if (TIMES)
00242     TIMING (T_EXIT);
00243 }
00244 
00245 /*-Copyright Information------------------------------------------------------*/
00246 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00247 /*----------------------------------------------------------------------------*/
00248 /*-General Information--------------------------------------------------------*/
00249 /*                                                                            */
00250 /*   This function terminates a SADIE program.                                */
00251 /*                                                                            */
00252 /*----------------------------------------------------------------------------*/
00253 /*-Interface Information------------------------------------------------------*/
00254 void
00255 FINI ()
00256 /*----------------------------------------------------------------------------*/
00257 {
00258   char msg[SLEN];
00259 
00260   if (TIMES)
00261     TIMING (T_FINI);
00262   if (NAMES)
00263     {
00264       MESSAGE ('I', "");
00265       MESSAGE ('I', "FINI");
00266     }
00267 
00268   /* release all remaining images */
00269   while (img)
00270     RELMEM (img->image);
00271 
00272   /* output termination status */
00273   if (e || w)
00274     {
00275       sprintf (msg, " SADIE terminated with %d warning(s) and %d error(s).",
00276                w, e);
00277     }
00278   else
00279     {
00280       sprintf (msg, " SADIE completed successfully.");
00281     }
00282   MESSAGE ('I', "");
00283   MESSAGE ('I', msg);
00284 
00285 the_end:
00286   if (TIMES)
00287     TIMING (T_EXIT);
00288   TIMING (T_EXIT);
00289 
00290   if (sys != NULL && sys != stdout)
00291     {
00292       fclose (sys);
00293     }
00294 }
00295 
00296 /*-Copyright Information------------------------------------------------------*/
00297 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00298 /*----------------------------------------------------------------------------*/
00299 /*-General Information--------------------------------------------------------*/
00300 /*                                                                            */
00301 /*   This low-level function handles the output for all SADIE functions,      */
00302 /*   with the exception of image display.                                     */
00303 /*                                                                            */
00304 /*----------------------------------------------------------------------------*/
00305 /*-Interface Information------------------------------------------------------*/
00306 void
00307 MESSAGE (char option,           /*  I   Switch, indicating the type of output:                */
00308          /*      'I'   -   Informational message.                      */
00309          /*      'W'   -   Warning.                                    */
00310          /*      'E'   -   Error.                                      */
00311          char *msg              /*  I   Pointer to an array[*] of characters, containing      */
00312          /*      one line of output (without terminating '\n').        */
00313 /*----------------------------------------------------------------------------*/
00314   )
00315 {
00316 
00317 /* Modified 4/2/97 by S.Conner */
00318 
00319   if (TIMES)
00320     TIMING (T_MESSAGE);
00321 
00322   /* update error counts and output message to log-file */
00323   switch (option)
00324     {
00325     case 'E':
00326       e += 1;
00327       /* fprintf(sys,"%c:   %s\n",option,msg); */
00328       sprintf (msg_ptr, "tk_dialog .dlg \"Warning\" \"%s\" warning 0 OK",
00329                msg);
00330       Tcl_GlobalEval (MainTclInterp, msg_ptr);
00331 
00332       sprintf (msg_ptr, "set SadieVar(message) \"%c:   %s\"", option, msg);
00333       break;
00334     case 'W':
00335       w += 1;
00336       /* fprintf(sys,"%c:   %s\n",option,msg); */
00337       sprintf (msg_ptr, "set SadieVar(message) \"%c:   %s\"", option, msg);
00338       break;
00339     case 'I':
00340       i += 1;
00341       /* fprintf(sys,"%c:   %s\n",option,msg); */
00342       sprintf (msg_ptr, "set SadieVar(message) \"%c:   %s\"", option, msg);
00343       break;
00344     default:
00345       /* fprintf(sys,"%s",msg); */
00346       sprintf (msg_ptr, "set SadieVar(message) \"%s\"", msg);
00347       break;
00348     }
00349 
00350 the_end:
00351 
00352   Tcl_GlobalEval (MainTclInterp, msg_ptr);
00353 
00354   if (TIMES)
00355     TIMING (T_EXIT);
00356 }
00357 
00358 /*-Copyright Information------------------------------------------------------*/
00359 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00360 /*----------------------------------------------------------------------------*/
00361 /*-General Information--------------------------------------------------------*/
00362 /*                                                                            */
00363 /*   This low-level function provides a timing facility for SADIE.            */
00364 /*                                                                            */
00365 /*----------------------------------------------------------------------------*/
00366 /*-Interface Information------------------------------------------------------*/
00367 void
00368 TIMING (option)
00369      T_TIME option;             /*  I   Switch, indicating the calling function.              */
00370 /*----------------------------------------------------------------------------*/
00371 {
00372   register short i;
00373   char msg[SLEN];
00374   long cur_time = time (NULL);
00375 
00376   /* update time-keeping */
00377   actms[stack[top]] += cur_time;
00378   stack[option ? calls[option]++, ++top : top--] = option;
00379   actms[stack[top]] -= cur_time;
00380 
00381   /* output statistics */
00382   if (top == 0 && TIMES == ON)
00383     {
00384       TIMES = OFF;
00385       if (NAMES)
00386         {
00387           MESSAGE ('I', "");
00388           MESSAGE ('I', "TIMING");
00389         }
00390       MESSAGE ('I', "");
00391       MESSAGE ('I', " Function  # of calls      Elapsed time    Time in %");
00392       MESSAGE ('I', "");
00393       for (i = 1; i < T_END; i++)
00394         {
00395           if (calls[i])
00396             {
00397               sprintf (msg, " %-8s%8ld            %02ld:%02ld:%02ld%13.1f",
00398                        functions[i][0], calls[i], actms[i] / 3600L,
00399                        actms[i] / 60L - 60L * (actms[i] / 3600L),
00400                        actms[i] % 60L,
00401                        (actms[0] ? -(double) actms[i] / (double) actms[0] *
00402                         100.0 : 0.0));
00403               MESSAGE ('I', msg);
00404             }
00405         }
00406     }
00407 }
00408 
00409 /*-Copyright Information------------------------------------------------------*/
00410 /* Copyright (c) 1989 by the University of Arizona Digital Image Analysis Lab */
00411 /*----------------------------------------------------------------------------*/
00412 /*-General Information--------------------------------------------------------*/
00413 /*                                                                            */
00414 /*   This low-level function provides a progress indicator for SADIE.         */
00415 /*                                                                            */
00416 /*----------------------------------------------------------------------------*/
00417 /*-Interface Information------------------------------------------------------*/
00418 short
00419 PROGRESS (pct)
00420      double pct;                /*  I   Percentage of work completed (0.0 <= pct <= 1.0).     */
00421 /*----------------------------------------------------------------------------*/
00422 {
00423   if (TIMES)
00424     TIMING (T_PROGRESS);
00425 
00426   /* output percentage */
00427   fprintf (stderr, "%3d%%\b\b\b\b", (int) (100.0 * pct));
00428   fflush (stderr);
00429 
00430 the_end:
00431   if (TIMES)
00432     TIMING (T_EXIT);
00433   return (TRUE);
00434 }
00435 
00436 /*-Copyright Information------------------------------------------------------*/
00437 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00438 /*----------------------------------------------------------------------------*/
00439 /*-Programmer Information-----------------------------------------------------*/
00440 /*                                                                            */
00441 /*   The number and size of images that may be allocated from a program is    */
00442 /*   system-dependent. However, this code will work on any system without     */
00443 /*   modifications.                                                           */
00444 /*                                                                            */
00445 /*----------------------------------------------------------------------------*/
00446 /*-General Information--------------------------------------------------------*/
00447 /*                                                                            */
00448 /*   This low-level function allocates memory for a new image, and            */
00449 /*   initializes its data structure.                                          */
00450 /*                                                                            */
00451 /*----------------------------------------------------------------------------*/
00452 /*-Interface Information------------------------------------------------------*/
00453 void
00454 GETMEM (short nbnd,             /*  I   Number of bands.                                      */
00455         short nlin,             /*  I   Number of lines.                                      */
00456         short npix,             /*  I   Number of pixels/line.                                */
00457         IMAGE ** out            /*  O   Address of a pointer to the image being allocated.    */
00458 /*----------------------------------------------------------------------------*/
00459   )
00460 {
00461   register short i, j;
00462   long total;
00463   BYTE *ptr = NULL;
00464   list *link = NULL;
00465 
00466   if (TIMES)
00467     TIMING (T_GETMEM);
00468 
00469   /* allocate space for image data structure, image data and list entry */
00470   total =
00471     sizeof (IMAGE) + nbnd * sizeof (PIXEL **) +
00472     nbnd * nlin * sizeof (PIXEL *) + nbnd * nlin * npix * sizeof (PIXEL) +
00473     sizeof (list);
00474   if (total < 0L)
00475     {
00476       MESSAGE ('E', " Memory request failed.");
00477       goto the_end;
00478     }
00479   if (!(ptr = (BYTE *) malloc (total * sizeof (BYTE))))
00480     {
00481       MESSAGE ('E', " Memory request failed.");
00482       goto the_end;
00483     }
00484 
00485   /* assign (DEFAULT) values */
00486   *out = (IMAGE *) ptr;
00487   (*out)->nbnd = nbnd;
00488   (*out)->nlin = nlin;
00489   (*out)->npix = npix;
00490   (*out)->nbit = SBIT;
00491 /*  (*out)->gmin = undefined;  */
00492 /*  (*out)->gmax = undefined;  */
00493   for (i = 0; i < TLEN; (*out)->text[i++] = '\0');
00494   (*out)->regions = NULL;
00495   (*out)->data = (PIXEL ***) (ptr + sizeof (IMAGE));
00496 
00497   /* initialize pointers */
00498   for (i = 0; i < nbnd; i++)
00499     {
00500       (*out)->data[i] =
00501         (PIXEL **) (ptr + sizeof (IMAGE) + nbnd * sizeof (PIXEL **) +
00502                     i * nlin * sizeof (PIXEL *));
00503       for (j = 0; j < nlin; j++)
00504         {
00505           (*out)->data[i][j] =
00506             (PIXEL *) (ptr + sizeof (IMAGE) + nbnd * sizeof (PIXEL **) +
00507                        nbnd * nlin * sizeof (PIXEL *) + (j * nbnd +
00508                                                          i) * npix *
00509                        sizeof (PIXEL));
00510         }
00511     }
00512 
00513   /* put new entry on the list */
00514   link = (list *) (ptr + total - sizeof (list));
00515   link->image = *out;
00516   link->next = img;
00517   img = link;
00518 
00519 the_end:
00520   if (TIMES)
00521     TIMING (T_EXIT);
00522 }
00523 
00524 /*-Copyright Information------------------------------------------------------*/
00525 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00526 /*----------------------------------------------------------------------------*/
00527 /*-General Information--------------------------------------------------------*/
00528 /*                                                                            */
00529 /*   This function releases an image to free memory space.                    */
00530 /*                                                                            */
00531 /*----------------------------------------------------------------------------*/
00532 /*-Interface Information------------------------------------------------------*/
00533 void
00534 RELIMG (out)
00535      IMAGE **out;               /* I/O  Address of the pointer to the image to be released.   */
00536 /*----------------------------------------------------------------------------*/
00537 {
00538   if (TIMES)
00539     TIMING (T_RELIMG);
00540   if (NAMES)
00541     {
00542       MESSAGE ('I', "");
00543       MESSAGE ('I', "RELIMG");
00544     }
00545 
00546   /* check input */
00547   if (!CHECKIMG (*out))
00548     {
00549       MESSAGE ('E', " RELIMG: Can't identify image.");
00550       goto the_end;
00551     }
00552 
00553   /* release image */
00554   RELMEM (*out);
00555   *out = NULL;
00556 
00557 the_end:
00558   if (TIMES)
00559     TIMING (T_EXIT);
00560 }
00561 
00562 /*-Copyright Information------------------------------------------------------*/
00563 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00564 /*----------------------------------------------------------------------------*/
00565 /*-General Information--------------------------------------------------------*/
00566 /*                                                                            */
00567 /*   This low-level function releases an image and frees its data structure.  */
00568 /*                                                                            */
00569 /*----------------------------------------------------------------------------*/
00570 /*-Interface Information------------------------------------------------------*/
00571 void
00572 RELMEM (in)
00573      IMAGE *in;                 /*  I   Pointer to the image to be released.                  */
00574 /*----------------------------------------------------------------------------*/
00575 {
00576   register list *ptr;
00577   ROIPtr r;
00578 
00579   if (TIMES)
00580     TIMING (T_RELMEM);
00581 
00582   /* take image off the list */
00583   if (img->image == in)
00584     {
00585       img = img->next;
00586     }
00587   else
00588     {
00589       for (ptr = img; ptr->next->image != in; ptr = ptr->next);
00590       ptr->next = ptr->next->next;
00591     }
00592 
00593   /* free allocated space */
00594   while ((r = in->regions) != NULL)
00595     {
00596       in->regions = r->next;
00597       free (r->name);
00598       r->name = NULL;
00599 
00600       free (r->zero);
00601       r->zero = NULL;
00602 
00603       free (r->gmin);
00604       r->gmin = NULL;
00605 
00606       free (r->gmax);
00607       r->gmax = NULL;
00608 
00609       free (r->mean);
00610       r->mean = NULL;
00611 
00612       free (r->dev);
00613       r->dev = NULL;
00614 
00615       free (r->cov);
00616       r->cov = NULL;
00617 
00618       free (r->cor);
00619       r->cor = NULL;
00620 
00621       free (r);
00622       r = NULL;
00623     }
00624   free (in);
00625   in = NULL;
00626 
00627 the_end:
00628   if (TIMES)
00629     TIMING (T_EXIT);
00630 }
00631 
00632 /*-Copyright Information------------------------------------------------------*/
00633 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00634 /*----------------------------------------------------------------------------*/
00635 /*-General Information--------------------------------------------------------*/
00636 /*                                                                            */
00637 /*   This low-level function determines whether or not an IMAGE pointer       */
00638 /*   points to an image that was properly created by SADIE.                   */
00639 /*                                                                            */
00640 /*----------------------------------------------------------------------------*/
00641 /*-Interface Information------------------------------------------------------*/
00642 short
00643 CHECKIMG (in)
00644      IMAGE *in;                 /*  I   Pointer to the image to be checked.                   */
00645 /*----------------------------------------------------------------------------*/
00646 {
00647   list *ptr;
00648 
00649   if (TIMES)
00650     TIMING (T_CHECKIMG);
00651 
00652   /* check to see if image is on the list */
00653   for (ptr = img; ptr != NULL && ptr->image != in; ptr = ptr->next);
00654 
00655 the_end:
00656   if (TIMES)
00657     TIMING (T_EXIT);
00658   return (ptr != NULL);
00659 }
00660 
00661 /*-Copyright Information------------------------------------------------------*/
00662 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00663 /*----------------------------------------------------------------------------*/
00664 /*-General Information--------------------------------------------------------*/
00665 /*                                                                            */
00666 /*   This low-level function finds the maximum and minimum graylevels         */
00667 /*   in an image.                                                             */
00668 /*                                                                            */
00669 /*----------------------------------------------------------------------------*/
00670 /*-Interface Information------------------------------------------------------*/
00671 void
00672 RANGE (in)
00673      IMAGE *in;                 /*  I   Pointer to the input image.                           */
00674 /*----------------------------------------------------------------------------*/
00675 {
00676   register PIXEL *p1, *p2, *p3, *gmin, *gmax;
00677 
00678   if (TIMES)
00679     TIMING (T_RANGE);
00680 
00681   /* find minimum and maximum */
00682   if (((long) in->nbnd * (long) in->nlin * (long) in->npix) % 2L == 0)
00683     {
00684       p1 = &in->data[0][0][0];
00685       p2 = &in->data[0][0][1];
00686     }
00687   else
00688     {
00689       p1 = &in->data[0][0][1];
00690       p2 = &in->data[0][0][2];
00691     }
00692   p3 = &(in->data[in->nbnd - 1][in->nlin - 1][in->npix - 1]);
00693   for (gmin = gmax = (&in->data[0][0][0]); p1 < p3; p1 += 2, p2 += 2)
00694     {
00695       if (*p1 < *p2)
00696         {
00697           if (*p1 < *gmin)
00698             gmin = p1;
00699           if (*p2 > *gmax)
00700             gmax = p2;
00701         }
00702       else
00703         {
00704           if (*p2 < *gmin)
00705             gmin = p2;
00706           if (*p1 > *gmax)
00707             gmax = p1;
00708         }
00709     }
00710   in->gmin = *gmin;
00711   in->gmax = *gmax;
00712 
00713   if (TIMES)
00714     TIMING (T_EXIT);
00715 }
00716 
00717 /*-Copyright Information------------------------------------------------------*/
00718 /* Copyright (c) 1995 by the University of Arizona Digital Image Analysis Lab */
00719 /*----------------------------------------------------------------------------*/
00720 /*-General Information--------------------------------------------------------*/
00721 /*                                                                            */
00722 /*   This low-level function swaps the bytes in a 2-byte word.                */
00723 /*                                                                            */
00724 /*----------------------------------------------------------------------------*/
00725 /*-Interface Information------------------------------------------------------*/
00726 short
00727 SWAP (unsigned char *cptr       /*  I  Pointer to the first byte of a 2-byte word.       */
00728 /*----------------------------------------------------------------------------*/
00729   )
00730 {
00731   unsigned char cval[2];
00732 
00733   if (TIMES)
00734     TIMING (T_SWAP);
00735 
00736   cval[0] = cptr[1];
00737   cval[1] = cptr[0];
00738 
00739 the_end:
00740   if (TIMES)
00741     TIMING (T_EXIT);
00742 
00743   return (*(short *) cval);
00744 }
00745 
00746 /*-Copyright Information------------------------------------------------------*/
00747 /* Copyright (c) 1989 by the University of Arizona Digital Image Analysis Lab */
00748 /*----------------------------------------------------------------------------*/
00749 /*-General Information--------------------------------------------------------*/
00750 /*                                                                            */
00751 /*   This low-level function packs an array of pixels from PIXEL              */
00752 /*   representation to "nbit" bits per pixel.                                 */
00753 /*                                                                            */
00754 /*----------------------------------------------------------------------------*/
00755 /*-Interface Information------------------------------------------------------*/
00756 void
00757 PACK (short nbit,               /*  I   Number of bits/pixel.                                 */
00758       long npix,                /*  I   Number of pixels in the array.                        */
00759       PIXEL * line              /* I/O  Pointer to an array[npix] of pixels.                  */
00760 /*----------------------------------------------------------------------------*/
00761   )
00762 {
00763   register BYTE *pckd = (BYTE *) line;
00764   register long i, j, k, l, m;
00765   unsigned long lpix;
00766 
00767   if (TIMES)
00768     TIMING (T_PACK);
00769 
00770   /* pack to nbit bits per pixel, in place */
00771   for (i = 0, j = (-1), l = m = SBPB; i < npix; i++)
00772     {
00773       for (lpix = (unsigned long) line[i], k = nbit; k > 0; m = k, k -= l)
00774         {
00775           l = m < l ? l - m : ((pckd[++j] = 0), SBPB);
00776           pckd[j] |=
00777             lpix << SBPB * sizeof (lpix) - k >> SBPB * sizeof (lpix) - l;
00778         }
00779     }
00780 
00781 the_end:
00782   if (TIMES)
00783     TIMING (T_EXIT);
00784 }
00785 
00786 /*-Copyright Information------------------------------------------------------*/
00787 /* Copyright (c) 1989 by the University of Arizona Digital Image Analysis Lab */
00788 /*----------------------------------------------------------------------------*/
00789 /*-General Information--------------------------------------------------------*/
00790 /*                                                                            */
00791 /*   This low-level function unpacks an array of pixels from "nbit"           */
00792 /*   bits per pixel to PIXEL representation.                                  */
00793 /*                                                                            */
00794 /*----------------------------------------------------------------------------*/
00795 /*-Interface Information------------------------------------------------------*/
00796 void
00797 UNPACK (short nbit,             /*  I   Number of bits/pixel.                                 */
00798         long npix,              /*  I   Number of pixels in the array.                        */
00799         PIXEL * line            /* I/O  Pointer to an array[npix] of pixels.                  */
00800 /*----------------------------------------------------------------------------*/
00801   )
00802 {
00803   register BYTE *pckd = (BYTE *) line;
00804   register long i, j, k, l, m;
00805   unsigned long lpix, mask =
00806     (unsigned long) ~0 >> sizeof (lpix) * SBPB - nbit;
00807 
00808   if (TIMES)
00809     TIMING (T_UNPACK);
00810 
00811   /* unpack from nbit bits per pixel, in place */
00812   for (i = npix - 1, j =
00813        (long) ceil ((double) (npix * nbit) / (double) SBPB) - 1, l =
00814        (npix * nbit) % SBPB ? (npix * nbit) % SBPB : SBPB, m = 0; i >= 0;
00815        line[i--] = (PIXEL) (lpix & mask))
00816     {
00817       for (lpix = 0, k = nbit; k > 0; m = k, k -= l)
00818         {
00819           l = m < l ? l - m : (--j, SBPB);
00820           lpix |= (unsigned long) pckd[j] >> SBPB - l << nbit - k;
00821         }
00822     }
00823 
00824 the_end:
00825   if (TIMES)
00826     TIMING (T_EXIT);
00827 }
00828 
00829 /*-Copyright Information------------------------------------------------------*/
00830 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00831 /*----------------------------------------------------------------------------*/
00832 /*-General Information--------------------------------------------------------*/
00833 /*                                                                            */
00834 /*   This low-level function extracts documentation from SADIE source code.   */
00835 /*                                                                            */
00836 /*----------------------------------------------------------------------------*/
00837 /*-Interface Information------------------------------------------------------*/
00838 void
00839 HELP (function, options)
00840      T_TIME function;           /*  I   Switch, indicating the desired function.              */
00841      char *options;             /*  I   is any combination of the following (as a string):    */
00842                 /*      'B'     Background Information will be listed.        */
00843                 /*      'C'     Copyright Information will be listed.         */
00844                 /*      'G'     General Information will be listed.           */
00845                 /*      'I'     Interface Information will be listed.         */
00846                 /*      'P'     Programmer Information will be listed.        */
00847 /*----------------------------------------------------------------------------*/
00848 {
00849   register short i, j, k;
00850   char msg[SLEN], fname[SLEN];
00851   long last[SLEN], temp;
00852   FILE *fp;
00853 
00854   if (TIMES)
00855     TIMING (T_HELP);
00856 
00857   /* check input */
00858   if (T_EXIT > function || strlen (functions[function][1]) == 0
00859       || function > T_END)
00860     {
00861       MESSAGE ('E', " Can't find documentation.");
00862       goto the_end;
00863     }
00864 
00865   /* open documentation file */
00866   sprintf (fname, "%s%s", DIR, functions[function][1]);
00867   if (!(fp = fopen (fname, "r")))
00868     {
00869       sprintf (msg, " Can't open file %s.", fname);
00870       MESSAGE ('E', msg);
00871       goto the_end;
00872     }
00873 
00874   /* search file for requested documentation */
00875   for (i = 0; i < strlen (options); i++)
00876     {
00877       last[i] = -1L;
00878     }
00879   for (i = 1; fgets (msg, SLEN, fp); i++)
00880     {
00881       if (strncmp (msg, BEGIN, strlen (BEGIN)) == 0)
00882         {
00883           for (j = 0; j < strlen (options); j++)
00884             {
00885               if (msg[CODE] == options[j])
00886                 {
00887                   if (last[j] > -1L)
00888                     {
00889                       for (k = 0; k < strlen (options); k++)
00890                         {
00891                           last[k] = -1L;
00892                         }
00893                     }
00894                   last[j] = ftell (fp) - (long) strlen (msg);
00895                 }
00896             }
00897         }
00898       for (j = 0; j <= strlen (msg) - strlen (functions[function][0]); j++)
00899         {
00900           if (strncmp
00901               (msg + j, functions[function][0],
00902                strlen (functions[function][0])) == 0
00903               && msg[j + strlen (functions[function][0])] == ' ')
00904             goto sort;
00905         }
00906     }
00907 
00908 sort:                          /* output */
00909   for (i = 0; i < strlen (options); i++)
00910     {
00911       for (j = i + 1; j < strlen (options); j++)
00912         {
00913           if (last[i] > last[j])
00914             {
00915               temp = last[i];
00916               last[i] = last[j];
00917               last[j] = temp;
00918             }
00919         }
00920     }
00921 
00922   /* output documentation */
00923   for (i = 0; i < strlen (options); i++)
00924     {
00925       if (last[i] > -1L)
00926         {
00927           fseek (fp, last[i], 0);
00928           fgets (msg, SLEN, fp);
00929           do
00930             {
00931               MESSAGE (' ', msg);
00932               fgets (msg, SLEN, fp);
00933             }
00934           while (strncmp (msg, END, strlen (END)));
00935           MESSAGE (' ', msg);
00936         }
00937     }
00938 
00939   /* close documentation file */
00940   if (fclose (fp))
00941     {
00942       sprintf (msg, " Can't close file %s.", fname);
00943       MESSAGE ('W', msg);
00944     }
00945 
00946 the_end:
00947   if (TIMES)
00948     TIMING (T_EXIT);
00949 }

Generated on Sun May 18 15:36:08 2003 for tclSadie by doxygen1.3