home *** CD-ROM | disk | FTP | other *** search
- /* IFF file driver. Supplied by Tomas Rokicki (Radical Eye Software) */
-
- #include "plplot.h"
- #include <stdio.h>
-
- static FILE *OutFile;
- static PLINT orient, setup=0, select=0, curwid;
- static char FileName[80];
- static char line[80];
- static PLINT xwidth, ywidth, xsubw, ysubw;
- static PLINT vxwidth, vywidth;
- static PLFLT xdotspi, ydotspi;
-
- void iffsetup(xdpi, ydpi, xwid, ywid)
- PLINT xwid, ywid;
- PLFLT xdpi, ydpi;
- {
- xdotspi = xdpi;
- ydotspi = ydpi;
- xwidth = xwid;
- ywidth = ywid;
- setup = 1;
- }
-
- void iffselect(ori, name)
- PLINT ori;
- char *name;
- {
- orient = ori;
- strncpy(FileName,name,sizeof(FileName)-1);
- FileName[sizeof(FileName)-1] = '\0';
- select = 1;
- }
-
- static PLINT getint(s)
- char *s;
- {
- PLINT m;
-
- while(1) {
- printf(s);
- fgets(line,sizeof(line),stdin);
- if(sscanf(line,"%d",&m) == 1)
- return(m);
- printf("No value or value out of range; please try again\n");
- }
- }
-
- static PLFLT getflt(s)
- char *s;
- {
- PLFLT m;
-
- while(1) {
- printf(s);
- fgets(line,sizeof(line),stdin);
- if(sscanf(line,"%f",&m) == 1)
- return(m);
- printf("No value or value out of range; please try again\n");
- }
- }
-
- void iffopenfile()
- {
- for(;;) {
- if(!select) {
- printf("Enter graphics file name. ");
- fgets(line,sizeof(line),stdin);
- if(sscanf(line,"%s",FileName)!=1)
- continue;
- }
-
- if (!(OutFile = fopen(FileName,"w"))) {
- fprintf(stderr,"Can't open %s.\n",FileName);
- select = 0;
- }
- else
- break;
- }
- select = 0;
- }
-
- void iffinit()
- {
- int mapinit();
-
- if(!setup) {
- xdotspi = getflt("Enter desired horizontal IFF resolution (dpi): ");
- ydotspi = getflt("Enter desired vertical IFF resolution (dpi): ");
- xwidth = getint("Enter desired horizontal IFF size in pixels : ");
- ywidth = getint("Enter desired vertical IFF size in pixels : ");
- }
- setup = 0;
-
- vxwidth = xwidth*25;
- vywidth = ywidth*25;
-
- if(!select)
- orient = getint("Landscape or portrait orientation? (0 or 1) ");
-
- if(orient) {
- setpxl((PLFLT)(ydotspi*25/25.4), (PLFLT)(xdotspi*25/25.4));
- setphy(0,vywidth,0,vxwidth);
- }
- else {
- setpxl((PLFLT)(xdotspi*25./25.4), (PLFLT)(ydotspi*25/25.4));
- setphy(0,vxwidth,0,vywidth);
- }
-
- xsubw = xwidth - 2;
- ysubw = ywidth - 2;
-
- scol(1); /* set pen color (ignored for this driver) */
- swid(1); /* set default pen width */
- smod(0); /* set mode (not an interactive device) */
-
- /* Allocate bitmap and initialize for line drawing */
- if(mapinit(xwidth, ywidth)) {
- plexit("");
- }
- }
-
- /* Set IFF to test mode */
- void ifftext()
- {
- /* do nothing here */
- }
-
- /* Set IFF to graphics mode */
- void iffgraph()
- {
- /* Do nothing here */
- }
-
- /* Print out page */
- void iffclear()
- {
- void iffwritefile();
-
- iffwritefile((PLINT)xdotspi,(PLINT)ydotspi,OutFile);
- fclose(OutFile) ;
- }
-
- void iffpage()
- {
- void mapclear();
-
- mapclear();
- iffopenfile();
- }
-
- void iffwidth(width)
- PLINT width;
- {
- if(width < 1)
- curwid = 1;
- else if(width > 3)
- curwid = 3;
- else
- curwid = width;
- }
-
- /* Change color */
- void iffcolor(colour)
- PLINT colour;
- {
- }
-
- void iffline(x1,y1,x2,y2)
- PLINT x1, y1, x2, y2;
- {
- long xn1, yn1, xn2, yn2;
- void mapline();
-
- if(orient) {
- xn1 = (x1*ysubw)/vywidth;
- yn1 = (y1*xsubw)/vxwidth;
- xn2 = (x2*ysubw)/vywidth;
- yn2 = (y2*xsubw)/vxwidth;
- switch(curwid) {
- case 3:
- mapline(yn1,xn1,yn2,xn2);
- case 2:
- mapline(yn1+2,xn1+2,yn2+2,xn2+2);
- case 1:
- default:
- mapline(yn1+1,xn1+1,yn2+1,xn2+1);
- }
- }
- else {
- xn1 = (x1*xsubw)/vxwidth;
- yn1 = (y1*ysubw)/vywidth;
- xn2 = (x2*xsubw)/vxwidth;
- yn2 = (y2*ysubw)/vywidth;
- switch(curwid) {
- case 3:
- mapline(xn1,ysubw-yn1,xn2,ysubw-yn2);
- case 2:
- mapline(xn1+2,ysubw-yn1+2,xn2+2,ysubw-yn2+2);
- case 1:
- default:
- mapline(xn1+1,ysubw-yn1+1,xn2+1,ysubw-yn2+1);
- }
- }
- }
-
- /* Reset printer and close file */
- void ifftidy()
- {
- void iffwritefile(), mapfree();
-
- iffwritefile((PLINT)xdotspi,(PLINT)ydotspi,OutFile);
- fclose(OutFile) ;
- mapfree();
- }
-
-