home *** CD-ROM | disk | FTP | other *** search
- /*
- % HEADERS . C
- %
- % Display image header for HIPS, FIST, GIF, PNM, RLE, SUN-RASter, and TIFF
- %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- This software is copyright (C) by the Lawrence Berkeley Laboratory.
- Permission is granted to reproduce this software for non-commercial
- purposes provided that this notice is left intact.
-
- It is acknowledged that the U.S. Government has rights to this software
- under Contract DE-AC03-765F00098 between the U.S. Department of Energy
- and the University of California.
-
- This software is provided as a professional and academic contribution
- for joint exchange. Thus, it is experimental, and is provided ``as is'',
- with no warranties of any kind whatsoever, no support, no promise of
- updates, or printed documentation. By using this software, you
- acknowledge that the Lawrence Berkeley Laboratory and Regents of the
- University of California shall have no liability with respect to the
- infringement of other copyrights by any part of this software.
-
- For further information about this notice, contact William Johnston,
- Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
- (wejohnston@lbl.gov)
-
- For further information about this software, contact:
- Jin Guojun
- Bld. 50B, Rm. 2275,
- Lawrence Berkeley Laboratory, Berkeley, CA, 94720
- g_jin@lbl.gov
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %
- % compile: cc -O -o headers headers.c -lscs5 -lccs -lhips -lrle -ltiff ...
- %
- % AUTHOR: Jin Guojun - LBL 12/10/91
- */
-
- #include <string.h>
- #include "header.def"
- #include "imagedef.h"
- #include <math.h>
-
- #ifndef SBUF_LEN
- #define SBUF_LEN 256
- #endif
-
- U_IMAGE uimg;
- char usage[]="headers image_files ... ",
- *color_or_grayscale(), /* returns color format */
- *format_string(); /* returns format desciption */
-
-
- main(argc, argv)
- int argc;
- char* argv[];
- {
- int f = 0;
-
- format_init(&uimg, IMAGE_INIT_TYPE, COLOR_PS, -1, *argv, "D12-1");
-
- if (argc==1) { /* for single file using `<' redirction input */
- f--;
- io_test(fileno(in_fp), usage_n_options(usage, argc, argv[argc]));
- }
- while (++f < argc) {
- if (argc != 1 && (in_fp=freopen(uimg.name=argv[f], "rb", stdin))==NULL) {
- prgmerr(0, "can not open %s for input", argv[f]);
- continue;
- }
- uimg.in_type = IMAGE_INIT_TYPE; /* important for multi-handling */
- if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0) < 0) {
- msg("%s is not in type of HIPS, FITS, GIF, ICC, PNM, RLE, SUN, and TIFF\n",
- argv[f]);
- continue;
- }
- fprintf(out_fp, "\nNAME => %s\n", argv[f]);
- fprintf(out_fp, "Type : %s\n", ITypeName[uimg.in_type]);
- fprintf(out_fp, "color : %s\n", color_or_grayscale(uimg.in_color));
- fprintf(out_fp, "format : %s\n", format_string(uimg.in_form));
- fprintf(out_fp, "frames : %d\n", uimg.frames ? uimg.frames : 1);
- fprintf(out_fp, "size : %d(w) x %d(h)\n", uimg.width, uimg.height);
- fprintf(out_fp, "sub-image : %d(w) x %d(h) <%d:%d>\n",
- uimg.sub_img_w, uimg.sub_img_h, uimg.sub_img_x, uimg.sub_img_y);
- fprintf(out_fp, "pixel bytes : %d\n", uimg.pxl_in);
- if (print_string(out_fp, "History", uimg.history))
- free(uimg.history);
- if (print_string(out_fp, "Desciption", uimg.desc))
- free(uimg.desc);
- uimg.history = uimg.desc = NULL;
- }
- exit(0);
- }
-
- char *color_or_grayscale(type)
- {
- switch (type) {
- case CFM_SGF:
- return "GrayScale";
- case CFM_SCF:
- return "8-bit Color witch color_map";
- case CFM_ILL:
- return "24-bit Color, scan line";
- case CFM_ILC:
- return "24-bit Color, interleaf";
- case CFM_BITMAP:
- return "Bit-Map";
- case CFM_ALPHA:
- return "32-bit Color (alpha channel)";
- case CFM_SEPLANE:
- return "24-bit Color, separate planes";
- default: return "Unknown color format";
- }
- }
-
- char* format_string(form)
- {
- switch (form) {
- case IFMT_VFFT3D: return "3D VFFT";
- case IFMT_VFFT2D: return "2D VFFT";
- case IFMT_DVFFT3D: return "3D Double VFFT";
- case IFMT_DVFFT2D: return "2D Double VFFT";
- case IFMT_VVFFT3D: return "3D VFFT in separated plane";
- case IFMT_DVVFFT3D: return "3D Double VFFT in separated plane";
- case IFMT_SCF: return "1 byte color";
- case IFMT_SEPLANE:
- case IFMT_ILC:
- case IFMT_ILL: return "3 byte color";
- case IFMT_ALPHA: return "4 byte color";
- case IFMT_BITMAP: return "bitmap";
- case IFMT_BYTE: return "byte";
- case IFMT_SHORT: return "short";
- case IFMT_LONG: return "long";
- case IFMT_FLOAT: return "float";
- default : return "no library linked";
- }
- }
-
- print_string(fp, phd, s)
- FILE *fp;
- char *phd, *s;
- {
- char buffer[SBUF_LEN]; /* 256 is save for most case */
- register int i;
- if (s) {
- fprintf(fp, "%s\n", phd);
- do {
- for (i=0; *s && *s != '\n' && i<SBUF_LEN-1; i++)
- if (*s == '|' && *(s+1) == '\\')
- { s+=2; i--; }
- else buffer[i] = *s++;
- if (!*s)
- buffer[i++] = '\n';
- buffer[i]=0;
- i ^= i;
- while(buffer[i] == ' ') i++;
- if (strlen(buffer+i))
- fprintf(fp, "%s\n", buffer+i);
- } while(*++s);
- return 1;
- } else fprintf(fp, "No %s\n", phd);
- return 0;
- }
-