home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / tools / convert / headers.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-02  |  4.8 KB  |  165 lines

  1. /*
  2. %    HEADERS . C
  3. %
  4. % Display image header for HIPS, FIST, GIF, PNM, RLE, SUN-RASter, and TIFF
  5. %
  6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  7.  
  8. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  9. Permission is granted to reproduce this software for non-commercial
  10. purposes provided that this notice is left intact.
  11.  
  12. It is acknowledged that the U.S. Government has rights to this software
  13. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  14. and the University of California.
  15.  
  16. This software is provided as a professional and academic contribution
  17. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  18. with no warranties of any kind whatsoever, no support, no promise of
  19. updates, or printed documentation. By using this software, you
  20. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  21. University of California shall have no liability with respect to the
  22. infringement of other copyrights by any part of this software.
  23.  
  24. For further information about this notice, contact William Johnston,
  25. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  26. (wejohnston@lbl.gov)
  27.  
  28. For further information about this software, contact:
  29.     Jin Guojun
  30.     Bld. 50B, Rm. 2275,
  31.     Lawrence Berkeley Laboratory, Berkeley, CA, 94720
  32.     g_jin@lbl.gov
  33. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  34. %
  35. % compile:    cc -O -o headers headers.c -lscs5 -lccs -lhips -lrle -ltiff ...
  36. %
  37. % AUTHOR:    Jin Guojun - LBL    12/10/91
  38. */
  39.  
  40. #include <string.h>
  41. #include "header.def"
  42. #include "imagedef.h"
  43. #include <math.h>
  44.  
  45. #ifndef    SBUF_LEN
  46. #define    SBUF_LEN    256
  47. #endif
  48.  
  49. U_IMAGE    uimg;
  50. char    usage[]="headers image_files ... ",
  51.     *color_or_grayscale(),    /* returns    color format */
  52.     *format_string();    /* returns    format desciption */
  53.  
  54.  
  55. main(argc, argv)
  56. int    argc;
  57. char*    argv[];
  58. {
  59. int    f = 0;
  60.  
  61. format_init(&uimg, IMAGE_INIT_TYPE, COLOR_PS, -1, *argv, "D12-1");
  62.  
  63. if (argc==1) {    /* for single file using `<' redirction input */
  64.     f--;
  65.     io_test(fileno(in_fp), usage_n_options(usage, argc, argv[argc]));
  66. }
  67. while (++f < argc) {
  68.     if (argc != 1 && (in_fp=freopen(uimg.name=argv[f], "rb", stdin))==NULL) {
  69.     prgmerr(0, "can not open %s for input", argv[f]);
  70.     continue;
  71.     }
  72.     uimg.in_type = IMAGE_INIT_TYPE;    /* important for multi-handling    */
  73.     if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0) < 0) {
  74.     msg("%s is not in type of HIPS, FITS, GIF, ICC, PNM, RLE, SUN, and TIFF\n",
  75.         argv[f]);
  76.     continue;
  77.     }
  78.     fprintf(out_fp, "\nNAME =>    %s\n", argv[f]);
  79.     fprintf(out_fp, "Type :    %s\n", ITypeName[uimg.in_type]);
  80.     fprintf(out_fp, "color :    %s\n", color_or_grayscale(uimg.in_color));
  81.     fprintf(out_fp, "format :    %s\n", format_string(uimg.in_form));
  82.     fprintf(out_fp, "frames :    %d\n", uimg.frames ? uimg.frames : 1);
  83.     fprintf(out_fp, "size   :    %d(w) x %d(h)\n", uimg.width, uimg.height);
  84.     fprintf(out_fp, "sub-image :    %d(w) x %d(h) <%d:%d>\n",
  85.     uimg.sub_img_w, uimg.sub_img_h, uimg.sub_img_x, uimg.sub_img_y);
  86.     fprintf(out_fp, "pixel bytes :    %d\n", uimg.pxl_in);
  87.     if (print_string(out_fp, "History", uimg.history))
  88.     free(uimg.history);
  89.     if (print_string(out_fp, "Desciption", uimg.desc))
  90.     free(uimg.desc);
  91.     uimg.history = uimg.desc = NULL;
  92. }
  93. exit(0);
  94. }
  95.  
  96. char    *color_or_grayscale(type)
  97. {
  98.     switch (type) {
  99.     case CFM_SGF:
  100.         return    "GrayScale";
  101.     case CFM_SCF:
  102.         return    "8-bit Color witch color_map";
  103.     case CFM_ILL:
  104.         return    "24-bit Color, scan line";
  105.     case CFM_ILC:
  106.         return    "24-bit Color, interleaf";
  107.     case CFM_BITMAP:
  108.         return    "Bit-Map";
  109.     case CFM_ALPHA:
  110.         return    "32-bit Color (alpha channel)";
  111.     case CFM_SEPLANE:
  112.         return    "24-bit Color, separate planes";
  113.     default:    return    "Unknown color format";
  114.     }
  115. }
  116.  
  117. char*    format_string(form)
  118. {
  119.     switch (form) {
  120.     case IFMT_VFFT3D:    return    "3D VFFT";
  121.     case IFMT_VFFT2D:    return    "2D VFFT";
  122.     case IFMT_DVFFT3D:    return    "3D Double VFFT";
  123.     case IFMT_DVFFT2D:    return    "2D Double VFFT";
  124.     case IFMT_VVFFT3D:    return    "3D VFFT in separated plane";
  125.     case IFMT_DVVFFT3D:    return    "3D Double VFFT in separated plane";
  126.     case IFMT_SCF:    return    "1 byte color";
  127.     case IFMT_SEPLANE:
  128.     case IFMT_ILC:
  129.     case IFMT_ILL:    return    "3 byte color";
  130.     case IFMT_ALPHA:    return    "4 byte color";
  131.     case IFMT_BITMAP:    return    "bitmap";
  132.     case IFMT_BYTE:    return    "byte";
  133.     case IFMT_SHORT:    return    "short";
  134.     case IFMT_LONG:    return    "long";
  135.     case IFMT_FLOAT:    return    "float";
  136.     default    :    return    "no library linked";
  137.     }
  138. }
  139.  
  140. print_string(fp, phd, s)
  141. FILE    *fp;
  142. char    *phd, *s;
  143. {
  144. char    buffer[SBUF_LEN];    /* 256 is save for most case */
  145. register int    i;
  146.     if (s) {
  147.     fprintf(fp, "%s\n", phd);
  148.     do {
  149.         for (i=0; *s && *s != '\n' && i<SBUF_LEN-1; i++)
  150.             if (*s == '|' && *(s+1) == '\\')
  151.             {    s+=2;    i--;    }
  152.             else    buffer[i] = *s++;
  153.         if (!*s)
  154.             buffer[i++] = '\n';
  155.         buffer[i]=0;
  156.         i ^= i;
  157.         while(buffer[i] == ' ')    i++;
  158.         if (strlen(buffer+i))
  159.             fprintf(fp, "%s\n", buffer+i);
  160.     } while(*++s);
  161.     return    1;
  162.     } else    fprintf(fp, "No %s\n", phd);
  163. return    0;
  164. }
  165.