home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / hips / sources / lut / logtbl.c next >
Encoding:
C/C++ Source or Header  |  1992-04-04  |  1.7 KB  |  72 lines

  1. /*    Copyright (c) 1989 Michael Landy
  2.  
  3. Disclaimer:  No guarantees of performance accompany this software,
  4. nor is any responsibility assumed on the part of the authors.  All the
  5. software has been tested extensively and every effort has been made to
  6. insure its reliability.   */
  7.  
  8. /*
  9.  * logtbl - takes log of input image.  (Output pixel = log (ipix + 1).)
  10.  * Input image is in byte or short format,
  11.  * output image byte for byte, floating point for short.
  12.  *
  13.  * usage:    logtbl [-a] < iseq > tbl_name
  14.  *            -a parameter indicates op = log (ipix),
  15.  *                with log(0) = -1.
  16.  *
  17.  * to load:    cc -o logtbl logtbl.c -lhips -lm
  18.  *
  19.  * Mike Landy - 5/10/82
  20.  * Mike Landy - 5/17/85 - added float input
  21.  * Charles Carman - 12/11/87 - added short input and -a flag
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <hipl_format.h>
  26. #include <math.h>
  27.  
  28. #define MAXSHORT    32768
  29.  
  30. main(argc, argv)
  31.     int       argc;
  32.     char     *argv[];
  33. {
  34.     int       aflag = 0;
  35.     int       i, pixform, numentries;
  36.     double    num;
  37.     float     entry;
  38.     struct header hd;
  39.  
  40.     Progname = strsave(*argv);
  41.     read_header(&hd);
  42.     pixform = hd.pixel_format;
  43.     if (argc == 2) {
  44.     if (*argv[1] == '-' && argv[1][1] == 'a')
  45.         aflag++;
  46.     else
  47.         perr(HE_MSG, "unknown argument");
  48.     }
  49.     if (pixform == PFBYTE)
  50.     numentries = 256;
  51.     else if (pixform == PFSHORT)
  52.     numentries = MAXSHORT;
  53.     else
  54.     perr(HE_MSG, "pixel format must be byte or short");
  55.  
  56.     pixform = PFFLOAT;
  57.     printf("%d\n", numentries);
  58.     printf("%d\n", pixform);
  59.     if (!aflag)
  60.     printf("-1.0\n");
  61.  
  62.     for (i = 1 - aflag; i < numentries; i++) {
  63.     if (i < 255)
  64.         num = (double) (aflag + i & 0xff);
  65.     else
  66.         num = (double) (aflag + i);
  67.     entry = (float) (log(num));
  68.     printf("%f\n", entry);
  69.     }
  70.     return (0);
  71. }
  72.