home *** CD-ROM | disk | FTP | other *** search
- /* SYSENV . C
- #
- % Image system initial ROUTINE
- %
- #
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- 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
-
- %
- % AUTHOR: Jin Guojun - LBL 10/1/90
- */
-
- #include "header.def"
- #include "imagedef.h"
-
- #ifndef H_H
- #define H_H header_handle
- #endif
- #define arg_list job, img, ac, av, assist
-
- #ifdef INCLUDE_MORE_SYS
- #include <sys/types.h>
- #endif
- #include <sys/stat.h>
-
- static struct stat statbuf;
-
- extern int std_interface(), pict_header_handle(), jpeg_header_handle();
-
- bridge_header_handle(arg_list)
- U_IMAGE *img;
- int ac;
- char **av;
- VType *assist;
- {
- register int status; /* Hierarchy : */
- switch(job) {
- case HEADER_READ:
- status = pull_Itype(img);
- goto hsw;
- case HEADER_TO:
- status = img->o_type;
- hsw: switch (status) {
- case HIPS:
- #ifdef HIPS_IMAGE
- if (!(status=hips_header_handle(arg_list))) break;
- #endif
- case FITS:
- #ifdef FITS_IMAGE
- if (!(status=fits_header_handle(arg_list))) break;
- #endif
- case RLE:
- #ifdef RLE_IMAGE
- if (!(status=rle_header_handle(arg_list)) ||
- status != RLE_NOT_RLE)
- break;
- #endif
- #ifdef COMMON_TOOL
- case GIF:
- if (!(status=gif_header_handle(arg_list))) break;
- case ICC:
- if (!(status=icc_header_handle(arg_list))) break;
- /* other cases of first MAGIC character = zero should be below this line */
- case RAS:
- if (!(status=rast_header_handle(arg_list))) break;
- case PNM: case PBM: case PGM: case PPM:
- if (!(status=pnm_header_handle(arg_list))) break;
- case JPEG:
- # ifdef JPEG_IMAGE
- if (!(status=jpeg_header_handle(arg_list))) break;
- # endif
- case PICT:
- # ifdef PICT_IMAGE
- if (!(status=pict_header_handle(arg_list))) break;
- # endif
- case 't': if (img->table_if &&
- !(status = (*img->table_if)(arg_list)) ) break;
-
- case TiFF: /* av===0 for lseek */
- if (!(status=tiff_header_handle(arg_list))) break;
- #endif
- default: status = prgmerr(0, "%d Unknown image type", job);
- }
- if (job==HEADER_READ && !status) {
- select_color_form(img, assist);
- if (img->in_form == IFMT_SCF && img->o_type == HIPS)
- img->in_form = IFMT_BYTE; /* vague format */
- }
- break;
- case HEADER_TRANSF:
- img->pxl_out = img->pxl_in; img->o_form = img->in_form;
- img->color_form = img->in_color;
- break;
- case HEADER_WRITE:
- default:
- hhd_bridge: status =
- #ifdef HIPS_IMAGE
- hips_header_handle(arg_list);
- #else
- rle_header_handle(arg_list);
- #endif
- }
- return status;
- }
-
-
- static /* EOF routine for macro feof and beof */
- ccs_eof(fp)
- FILE* fp;
- {
- register BUFFER *bp = (BUFFER*)fp;
- if (bp->flags == BUFFER_MAGIC)
- return beof(bp);
- return feof(fp);
- }
-
-
- format_init(img, in_type, mid_type, o_type, pgname, vers)
- U_IMAGE *img;
- char *pgname, *vers;
- {
- img->in_type = in_type;
- img->mid_type = mid_type;
- img->o_type = (o_type < 0) ? mid_type : o_type;
- img->mag_fact = img->update_header = 1; /* when output 3D sub-image, set it to False */
-
- Progname = pgname;
- Mversion = vers;
-
- #ifdef HIPS2_HF
- hipserrprt = hipserrlev = HEL_SEVERE;
- #endif
-
- if (!img->OUT_FP || fstat(fileno(img->OUT_FP), &statbuf))
- img->OUT_FP = stdout;
- if (!img->IN_FP || fstat(fileno(img->IN_FP), &statbuf))
- img->IN_FP = stdin;
- img->errors = prgmerr;
- img->std_swif = std_interface;
- img->eof = ccs_eof;
- reset_readpipe(img);
- img->dpy_channels = img->color_dpy ? 3 : 1;
-
- if (in_type > mid_type) in_type = mid_type;
-
- switch (in_type) {
- #ifdef COMMON_TOOL
- # ifdef JPEG_IMAGE
- case JPEG: img->H_H = jpeg_header_handle; break;
- # endif
- # ifdef PICT_IMAGE
- case PICT: img->H_H = pict_header_handle; break;
- # endif
- #endif
- case HIPS:
- default:/* otherwise use bridge handler, a basic common tool */
- img->H_H = bridge_header_handle;
- }
- if (in_type > ENDITYPE) {
- message("unknown format %d\n", in_type);
- return in_type;
- }
- return 0;
- }
-
- usage_n_options(usages, nth, nth_para)
- char *usages, *nth_para;
- {
- syserr("wrong option[%d] {%s}\n%s", nth, nth_para, usages);
- }
-
- available_type(name_str) /* non-case sensitive */
- register char *name_str;
- {
- register int i;
- for (i=0; name_str[i]; i++)
- name_str[i] = toupper(name_str[i]);
- for (i=ENDITYPE; i-- && strcmp(name_str, ITypeName[i]););
- return i;
- }
-
- pull_Itype(img) /* try for piping */
- U_IMAGE *img;
- {
- register int c, t=img->in_type;
- if (t != TiFF) { /* default: */
- switch (c=(*img->seek)(img->IN_FP, 0, SEEK_PEEK)) {
- case 'H': t = HIPS; break;
- case 'S': t = FITS; break;
- case 'R': t = RLE; break;
- case 'Y': t = RAS; break;
- case 'G': t = GIF; break;
- case 'P': t = PNM; break;
- case 0xFF: t = JPEG; break;
- /* try only ICC, other 0s no piping, and must be after ICC */
- case 0 : t = ICC; break;
- default:
- if (isalnum(c) && img->table_if)
- t = 't'; /* use table if */
- }
- (*img->seek)(img->IN_FP, c, SEEK_UGETB);
- }
- return t;
- }
-
- bytes_in_colortype(type)
- {
- if (type < CFM_SCF || type == CFM_BITMAP)
- return 1;
- return 3;
- }
-