home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11.lha / ccs-lib / tools / convert / to3dplot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-04  |  3.5 KB  |  118 lines

  1. /*
  2. %    TO3DPLOT . C
  3. %
  4. %    input any image, and output 3D GNUPLOT data.
  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. % AUTHOR:    Jin Guojun - LBL    3/10/1992
  36. */
  37.  
  38. #include "header.def"
  39. #include "imagedef.h"
  40.  
  41. arg_fmt_list_string    arg_fmt[] = {
  42.     {"-k", "%b", True, 1, 0, "keep going when errors hanppen"},
  43.     {"-r", "%b", True, 1, 0, "rotate right 90"},
  44.     {"-s[x][y]", "%f", 1., 1, 1,
  45.         "scale for X or Y or both (-s #) coordinate in float"},
  46.     {"-t", "%s", No, 1, 1, "title"},
  47.     {"I/O:    [<] input [>] output\n", "0", 0, 0, 0, "END"}, NULL    };
  48.  
  49. U_IMAGE    uimg;
  50. bool    nostop, rot;
  51. float    scale, xscale=1., yscale=1.;
  52.  
  53. main(ac, av)
  54. int    ac;
  55. char*    av[];
  56. {
  57. char    *title = *av, **fl;
  58. int    frm, nf;
  59.  
  60. format_init(&uimg, IMAGE_INIT_TYPE, HIPS, -1, *av, "Mar15-2");
  61.  
  62.     if ((nf=parse_argus(&fl, ac, av, arg_fmt,
  63.         &nostop, &rot, &scale, &xscale, &yscale, &title)) < 0)
  64.         exit(nf);
  65.     if (nf && freopen(uimg.name = *fl, "rb", stdin) != stdin)
  66.         syserr("input file -- %s", av[frm]);
  67.     if (scale != 1.)
  68.         xscale = yscale = scale;
  69.  
  70.     io_test(fileno(in_fp), exit(0));
  71.  
  72.     if ((*uimg.header_handle)(HEADER_READ, &uimg, 0, 0, True) < 0)
  73.         syserr("unknown image type");
  74.  
  75.     fprintf(out_fp, "# %s\n", title);
  76.  
  77.     {    register int    col, row;
  78.     for (frm=uimg.frames; frm--;)    {
  79.  
  80.     (*uimg.std_swif)(FI_LOAD_FILE, &uimg, nostop ? NULL : uimg.name, True);
  81.  
  82.         fprintf(out_fp, "# 3D gnuplot %s frame %d\n", uimg.name, frm);
  83.         switch (uimg.in_form)    {
  84.         case IFMT_BYTE:    {
  85.         register byte    *bp = uimg.src;
  86.             for (row=0; row<uimg.height; row++)
  87.                 for (col=0; col<uimg.width; col++)
  88.                 fprintf(out_fp, "%f %f %d\n",
  89.                     col*xscale, row*yscale, *bp++);
  90.         }    break;
  91.         case IFMT_SHORT:    {
  92.         register byte    *sp = uimg.src;
  93.             for (row=0; row<uimg.height; row++)
  94.                 for (col=0; col<uimg.width; col++)
  95.                 fprintf(out_fp, "%f %f %d\n",
  96.                     col*xscale, row*yscale, *sp++);
  97.         }    break;
  98.         case IFMT_LONG:    {
  99.         register long    *ip = uimg.src;
  100.             for (row=0; row<uimg.height; row++)
  101.                 for (col=0; col<uimg.width; col++)
  102.                 fprintf(out_fp, "%f %f %d\n",
  103.                     col*xscale, row*yscale, *ip++);
  104.         }    break;
  105.         case IFMT_FLOAT:    {
  106.         register byte    *fp = uimg.src;
  107.             for (row=0; row<uimg.height; row++)
  108.                 for (col=0; col<uimg.width; col++)
  109.                 fprintf(out_fp, "%f %f %f\n",
  110.                     col*xscale, row*yscale, *fp++);
  111.         }    break;
  112.         default:
  113.             prgmerr('f', "only handle byte to float format");
  114.         }
  115.     }
  116.     }
  117. }
  118.