home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / drivers / iff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  4.2 KB  |  217 lines

  1. /* IFF file driver. Supplied by Tomas Rokicki (Radical Eye Software) */
  2.  
  3. #include "plplot.h"
  4. #include <stdio.h>
  5.  
  6. static FILE *OutFile;
  7. static PLINT orient, setup=0, select=0, curwid;
  8. static char FileName[80];
  9. static char line[80];
  10. static PLINT xwidth, ywidth, xsubw, ysubw;
  11. static PLINT vxwidth, vywidth;
  12. static PLFLT xdotspi, ydotspi;
  13.  
  14. void iffsetup(xdpi, ydpi, xwid, ywid)
  15. PLINT xwid, ywid;
  16. PLFLT xdpi, ydpi;
  17. {
  18.    xdotspi = xdpi;
  19.    ydotspi = ydpi;
  20.    xwidth = xwid;
  21.    ywidth = ywid;
  22.    setup = 1;
  23. }
  24.  
  25. void iffselect(ori, name)
  26. PLINT ori;
  27. char *name;
  28. {
  29.    orient = ori;
  30.    strncpy(FileName,name,sizeof(FileName)-1);
  31.    FileName[sizeof(FileName)-1] = '\0';
  32.    select = 1;
  33. }
  34.  
  35. static PLINT getint(s)
  36. char *s;
  37. {
  38.    PLINT m;
  39.  
  40.    while(1) {
  41.       printf(s);
  42.       fgets(line,sizeof(line),stdin);
  43.       if(sscanf(line,"%d",&m) == 1)
  44.          return(m);
  45.       printf("No value or value out of range; please try again\n");
  46.    }
  47. }
  48.  
  49. static PLFLT getflt(s)
  50. char *s;
  51. {
  52.    PLFLT m;
  53.  
  54.    while(1) {
  55.       printf(s);
  56.       fgets(line,sizeof(line),stdin);
  57.       if(sscanf(line,"%f",&m) == 1)
  58.          return(m);
  59.       printf("No value or value out of range; please try again\n");
  60.    }
  61. }
  62.  
  63. void iffopenfile()
  64. {
  65.    for(;;) {
  66.       if(!select) {
  67.          printf("Enter graphics file name. ");
  68.          fgets(line,sizeof(line),stdin);
  69.          if(sscanf(line,"%s",FileName)!=1)
  70.             continue;
  71.       }
  72.  
  73.       if (!(OutFile = fopen(FileName,"w"))) {
  74.          fprintf(stderr,"Can't open %s.\n",FileName);
  75.          select = 0;
  76.       }
  77.       else
  78.          break;
  79.    }
  80.    select = 0;
  81. }
  82.  
  83. void iffinit()
  84. {
  85.    int mapinit();
  86.  
  87.    if(!setup) {
  88.       xdotspi = getflt("Enter desired horizontal IFF resolution (dpi): ");
  89.       ydotspi = getflt("Enter desired vertical   IFF resolution (dpi): ");
  90.       xwidth  = getint("Enter desired horizontal IFF size in pixels  : ");
  91.       ywidth  = getint("Enter desired vertical   IFF size in pixels  : ");
  92.    }
  93.    setup = 0;
  94.  
  95.    vxwidth = xwidth*25;
  96.    vywidth = ywidth*25;
  97.  
  98.    if(!select)
  99.       orient = getint("Landscape or portrait orientation? (0 or 1) ");
  100.  
  101.    if(orient) {
  102.       setpxl((PLFLT)(ydotspi*25/25.4), (PLFLT)(xdotspi*25/25.4));
  103.       setphy(0,vywidth,0,vxwidth);
  104.    }
  105.    else {
  106.       setpxl((PLFLT)(xdotspi*25./25.4), (PLFLT)(ydotspi*25/25.4));
  107.       setphy(0,vxwidth,0,vywidth);
  108.    }
  109.  
  110.    xsubw = xwidth - 2;
  111.    ysubw = ywidth - 2;
  112.  
  113.    scol(1);   /* set pen color (ignored for this driver) */
  114.    swid(1);   /* set default pen width */
  115.    smod(0);   /* set mode (not an interactive device) */
  116.  
  117.    /* Allocate bitmap and initialize for line drawing */
  118.    if(mapinit(xwidth, ywidth)) {
  119.       plexit("");
  120.    }
  121. }
  122.  
  123. /* Set IFF to test mode */
  124. void ifftext()
  125. {
  126.   /* do nothing here */
  127. }
  128.  
  129. /* Set IFF to graphics mode */
  130. void iffgraph()
  131. {
  132.   /* Do nothing here */
  133. }
  134.  
  135. /* Print out page */
  136. void iffclear()
  137. {
  138.   void iffwritefile();
  139.  
  140.   iffwritefile((PLINT)xdotspi,(PLINT)ydotspi,OutFile);
  141.   fclose(OutFile) ;
  142. }
  143.  
  144. void iffpage()
  145. {
  146.    void mapclear();
  147.  
  148.    mapclear();
  149.    iffopenfile();
  150. }
  151.  
  152. void iffwidth(width)
  153. PLINT width;
  154. {
  155.    if(width < 1)
  156.       curwid = 1;
  157.    else if(width > 3)
  158.       curwid = 3;
  159.    else
  160.       curwid = width;
  161. }
  162.  
  163. /* Change color */
  164. void iffcolor(colour)
  165. PLINT colour;
  166. {
  167. }
  168.  
  169. void iffline(x1,y1,x2,y2)
  170. PLINT x1, y1, x2, y2;
  171. {
  172.    long xn1, yn1, xn2, yn2;
  173.    void mapline();
  174.  
  175.    if(orient) {
  176.       xn1 = (x1*ysubw)/vywidth;
  177.       yn1 = (y1*xsubw)/vxwidth;
  178.       xn2 = (x2*ysubw)/vywidth;
  179.       yn2 = (y2*xsubw)/vxwidth;
  180.       switch(curwid) {
  181.          case 3:
  182.             mapline(yn1,xn1,yn2,xn2);
  183.          case 2:
  184.             mapline(yn1+2,xn1+2,yn2+2,xn2+2);
  185.          case 1:
  186.          default:
  187.             mapline(yn1+1,xn1+1,yn2+1,xn2+1);
  188.       }
  189.    }
  190.    else {
  191.       xn1 = (x1*xsubw)/vxwidth;
  192.       yn1 = (y1*ysubw)/vywidth;
  193.       xn2 = (x2*xsubw)/vxwidth;
  194.       yn2 = (y2*ysubw)/vywidth;
  195.       switch(curwid) {
  196.          case 3:
  197.             mapline(xn1,ysubw-yn1,xn2,ysubw-yn2);
  198.          case 2:
  199.             mapline(xn1+2,ysubw-yn1+2,xn2+2,ysubw-yn2+2);
  200.          case 1:
  201.          default:
  202.             mapline(xn1+1,ysubw-yn1+1,xn2+1,ysubw-yn2+1);
  203.       }
  204.    }
  205. }
  206.  
  207. /* Reset printer and close file */
  208. void ifftidy()
  209. {
  210.   void iffwritefile(), mapfree();
  211.  
  212.   iffwritefile((PLINT)xdotspi,(PLINT)ydotspi,OutFile);
  213.   fclose(OutFile) ;
  214.   mapfree();
  215. }
  216.  
  217.