home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / libscs / sysenv2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-15  |  5.7 KB  |  236 lines

  1. /*    SYSENV . C
  2. #
  3. %    Image system initial ROUTINE
  4. %
  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, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  31.         g_jin@lbl.gov
  32.  
  33. %
  34. % AUTHOR:    Jin Guojun - LBL    10/1/90
  35. */
  36.  
  37. #include "header.def"
  38. #include "imagedef.h"
  39.  
  40. #ifndef    H_H
  41. #define    H_H    header_handle
  42. #endif
  43. #define    arg_list    job, img, ac, av, assist
  44.  
  45. #ifdef    INCLUDE_MORE_SYS
  46. #include <sys/types.h>
  47. #endif
  48. #include <sys/stat.h>
  49.  
  50. static    struct    stat    statbuf;
  51.  
  52. extern    int    std_interface(), pict_header_handle(), jpeg_header_handle();
  53.  
  54. bridge_header_handle(arg_list)
  55. U_IMAGE    *img;
  56. int    ac;
  57. char    **av;
  58. VType    *assist;
  59. {
  60. register int    status;    /*    Hierarchy :    */
  61.     switch(job) {
  62.     case HEADER_READ:
  63.     status = pull_Itype(img);
  64.     goto    hsw;
  65.     case HEADER_TO:
  66.     status = img->o_type;
  67. hsw:    switch (status)    {
  68.     case HIPS:
  69. #ifdef    HIPS_IMAGE
  70.         if (!(status=hips_header_handle(arg_list)))    break;
  71. #endif
  72.     case FITS:
  73. #ifdef    FITS_IMAGE
  74.         if (!(status=fits_header_handle(arg_list)))    break;
  75. #endif
  76.     case RLE:
  77. #ifdef    RLE_IMAGE
  78.         if (!(status=rle_header_handle(arg_list)) ||
  79.             status != RLE_NOT_RLE)
  80.             break;
  81. #endif
  82. #ifdef    COMMON_TOOL
  83.     case GIF:
  84.         if (!(status=gif_header_handle(arg_list)))    break;
  85.     case ICC:
  86.         if (!(status=icc_header_handle(arg_list)))    break;
  87. /* other cases of first MAGIC character = zero should be below this line */
  88.     case RAS:
  89.         if (!(status=rast_header_handle(arg_list)))    break;
  90.     case PNM:    case PBM:    case PGM:    case PPM:
  91.         if (!(status=pnm_header_handle(arg_list)))    break;
  92.     case JPEG:
  93. #    ifdef    JPEG_IMAGE
  94.         if (!(status=jpeg_header_handle(arg_list)))    break;
  95. #    endif
  96.     case PICT:
  97. #    ifdef    PICT_IMAGE
  98.         if (!(status=pict_header_handle(arg_list)))    break;
  99. #    endif
  100.     case 't':    if (img->table_if &&
  101.         !(status = (*img->table_if)(arg_list)) )    break;
  102.  
  103.     case TiFF:    /*    av===0 for lseek    */
  104.         if (!(status=tiff_header_handle(arg_list)))    break;
  105. #endif
  106.     default:    status = prgmerr(0, "%d Unknown image type", job);
  107.     }
  108.     if (job==HEADER_READ && !status)    {
  109.         select_color_form(img, assist);
  110.         if (img->in_form == IFMT_SCF && img->o_type == HIPS)
  111.             img->in_form = IFMT_BYTE;    /* vague format    */
  112.     }
  113.     break;
  114.     case HEADER_TRANSF:
  115.     img->pxl_out = img->pxl_in;    img->o_form = img->in_form;
  116.     img->color_form = img->in_color;
  117.     break;
  118.     case HEADER_WRITE:
  119.     default:
  120. hhd_bridge:    status =
  121. #ifdef    HIPS_IMAGE
  122.             hips_header_handle(arg_list);
  123. #else
  124.             rle_header_handle(arg_list);
  125. #endif
  126.     }
  127. return    status;
  128. }
  129.  
  130.  
  131. static    /*    EOF routine for macro feof and beof    */
  132. ccs_eof(fp)
  133. FILE*    fp;
  134. {
  135. register BUFFER    *bp = (BUFFER*)fp;
  136. if (bp->flags == BUFFER_MAGIC)
  137.     return    beof(bp);
  138. return    feof(fp);
  139. }
  140.  
  141.  
  142. format_init(img, in_type, mid_type, o_type, pgname, vers)
  143. U_IMAGE    *img;
  144. char    *pgname, *vers;
  145. {
  146. img->in_type = in_type;
  147. img->mid_type = mid_type;
  148. img->o_type = (o_type < 0) ? mid_type : o_type;
  149. img->mag_fact = img->update_header = 1;    /* when output 3D sub-image, set it to False */
  150.  
  151. Progname = pgname;
  152. Mversion = vers;
  153.  
  154. #ifdef    HIPS2_HF
  155. hipserrprt = hipserrlev = HEL_SEVERE;
  156. #endif
  157.  
  158. if (!img->OUT_FP || fstat(fileno(img->OUT_FP), &statbuf))
  159.     img->OUT_FP = stdout;
  160. if (!img->IN_FP || fstat(fileno(img->IN_FP), &statbuf))
  161.     img->IN_FP = stdin;
  162. img->errors = prgmerr;
  163. img->std_swif = std_interface;
  164. img->eof = ccs_eof;
  165. reset_readpipe(img);
  166. img->dpy_channels = img->color_dpy ? 3 : 1;
  167.  
  168. if (in_type > mid_type) in_type = mid_type;
  169.  
  170.     switch (in_type) {
  171. #ifdef    COMMON_TOOL
  172. # ifdef    JPEG_IMAGE
  173.     case JPEG:    img->H_H = jpeg_header_handle;    break;
  174. # endif
  175. # ifdef    PICT_IMAGE
  176.     case PICT:    img->H_H = pict_header_handle;    break;
  177. # endif
  178. #endif
  179.     case HIPS:
  180.     default:/* otherwise use bridge handler, a basic common tool */
  181.         img->H_H = bridge_header_handle;
  182.     }
  183.     if (in_type > ENDITYPE)    {
  184.         message("unknown format %d\n", in_type);
  185.         return    in_type;
  186.     }
  187. return    0;
  188. }
  189.  
  190. usage_n_options(usages, nth, nth_para)
  191. char    *usages, *nth_para;
  192. {
  193. syserr("wrong option[%d] {%s}\n%s", nth, nth_para, usages);
  194. }
  195.  
  196. available_type(name_str)    /* non-case sensitive    */
  197. register char    *name_str;
  198. {
  199. register int    i;
  200.     for (i=0; name_str[i]; i++)
  201.         name_str[i] = toupper(name_str[i]);
  202.     for (i=ENDITYPE; i-- && strcmp(name_str, ITypeName[i]););
  203. return    i;
  204. }
  205.  
  206. pull_Itype(img)    /*    try for piping    */
  207. U_IMAGE    *img;
  208. {
  209. register int    c, t=img->in_type;
  210.     if (t != TiFF)    {    /*    default:    */
  211.     switch (c=(*img->seek)(img->IN_FP, 0, SEEK_PEEK))    {
  212.     case 'H':    t = HIPS;    break;
  213.     case 'S':    t = FITS;    break;
  214.     case 'R':    t = RLE;    break;
  215.     case 'Y':    t = RAS;    break;
  216.     case 'G':    t = GIF;    break;
  217.     case 'P':    t = PNM;    break;
  218.     case 0xFF:    t = JPEG;    break;
  219.     /* try only ICC, other 0s no piping, and must be after ICC    */
  220.     case 0    :    t = ICC;    break;
  221.     default:
  222.         if (isalnum(c) && img->table_if)
  223.             t = 't';    /* use table if    */
  224.     }
  225.     (*img->seek)(img->IN_FP, c, SEEK_UGETB);
  226.     }
  227. return    t;
  228. }
  229.  
  230. bytes_in_colortype(type)
  231. {
  232. if (type < CFM_SCF || type == CFM_BITMAP)
  233.     return    1;
  234. return    3;
  235. }
  236.