home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / tools / convert / torle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-04-06  |  3.2 KB  |  98 lines

  1. /*
  2. %
  3. %    TORLE . C
  4. %
  5. %    The format for the input file is any image.
  6. %    The format for the output file is a RLE image.
  7. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8.  
  9. This software is copyright (C) by the Lawrence Berkeley Laboratory.
  10. Permission is granted to reproduce this software for non-commercial
  11. purposes provided that this notice is left intact.
  12.  
  13. It is acknowledged that the U.S. Government has rights to this software
  14. under Contract DE-AC03-765F00098 between the U.S.  Department of Energy
  15. and the University of California.
  16.  
  17. This software is provided as a professional and academic contribution
  18. for joint exchange. Thus, it is experimental, and is provided ``as is'',
  19. with no warranties of any kind whatsoever, no support, no promise of
  20. updates, or printed documentation. By using this software, you
  21. acknowledge that the Lawrence Berkeley Laboratory and Regents of the
  22. University of California shall have no liability with respect to the
  23. infringement of other copyrights by any part of this software.
  24.  
  25. For further information about this notice, contact William Johnston,
  26. Bld. 50B, Rm. 2239, Lawrence Berkeley Laboratory, Berkeley, CA, 94720.
  27. (wejohnston@lbl.gov)
  28.  
  29. For further information about this software, contact:
  30.     Jin Guojun
  31.     Bld. 50B, Rm. 2275,
  32.     Lawrence Berkeley Laboratory, Berkeley, CA, 94720
  33.     g_jin@lbl.gov
  34. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  35. %
  36. % AUTHOR:    Jin Guojun - LBL    12/10/1991
  37. */
  38.  
  39. #include "imagedef.h"
  40.  
  41. arg_fmt_list_string    arg_fmt[] =    {
  42.     {"-d", "%-", No, 1, 0,    "dither to 8-bit"},
  43.     {"-k", "%b", True, 1, 0, "keep going when errors hanppen"},
  44.     {"-l", "%-", No, 1, 0,    "rotate left 90"},
  45.     {"-r", "%+", No, 1, 0,    "rotate right 90"},
  46.     {"-s", "%f", 1.0, 1, 1, "scale"},
  47.     {"-t", "%s", No, 1, 1,    "title"},
  48.     {"-TIFF", "%N", TiFF, 1, 0, "-image_type    using for pipe"},
  49.  {"    [<] input [[> |] output]", "0", 0, 0, 0, "end of usage"},
  50.     NULL    };
  51. U_IMAGE    uimg;
  52. bool    nostop, rot, to8, init_type=IMAGE_INIT_TYPE;
  53. float    scale;
  54. #define    rows    uimg.height
  55. #define    cols    uimg.width
  56.  
  57. main(ac, av)
  58. int    ac;
  59. char*    av[];
  60. {
  61. char    *title, **fl;
  62. int    row, state;
  63.  
  64.     if ((state=parse_argus(&fl, ac, av, arg_fmt,
  65.         &to8, &nostop, &rot, &rot, &scale, &title, &init_type)) < 0)
  66.         exit(state);
  67.     if (state && !freopen(uimg.name=fl[0], "rb", stdin))
  68.         syserr("input file -- %s", fl[0]);
  69.  
  70. uimg.color_dpy = True;
  71. format_init(&uimg, init_type, RLE, -1, *av, "D20-1");
  72. io_test(fileno(in_fp), {parse_usage(arg_fmt); exit(0);});
  73.  
  74.     if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0, True) < 0)
  75.         syserr("unknown image type");
  76.  
  77.     (*uimg.std_swif)(FI_LOAD_FILE, &uimg, nostop ? NULL : uimg.name, True);
  78.     rle_dflt_hdr.comments = zalloc(2, sizeof(char*), "comment");
  79.     if (uimg.desc)
  80.         rle_dflt_hdr.comments[0] = str_save(uimg.desc);
  81.     if (title)
  82.         rle_dflt_hdr.comments[1] = str_save(title);
  83.     if (to8 && uimg.channels > 1)
  84.         To_8(&uimg, reg_cmap, to8==1, 256),
  85.         uimg.dpy_channels = uimg.channels;
  86.     if (rot++)    {
  87.         uimg.dest = uimg.src;
  88.         uimg.src = nzalloc(uimg.channels*uimg.width, uimg.height, "rot");
  89.         row = uimg.width;
  90.         uimg.width = uimg.height;
  91.         uimg.height = row;
  92.         color_rotate_90(uimg.dest, uimg.src, row, uimg.width,
  93.             uimg.color_form, rot);
  94.         free(uimg.dest);
  95.     }
  96.     state = (*uimg.std_swif)(FI_SAVE_FILE, &uimg, No, NULL);
  97. }
  98.