ftp.nice.ch/pub/next/unix/developer/plplot.3.0.s.tar.gz#/plplot/drivers/iff.c

This is iff.c in view mode; [Download] [Up]

/* IFF file driver. Supplied by Tomas Rokicki (Radical Eye Software) */

#include "plplot.h"
#include <stdio.h>

static FILE *OutFile=NULL;
static int orient=0, setup=0, curwid;
static int fileopen;
static char line[80];
static int xwidth, ywidth, xsubw, ysubw;
static int vxwidth, vywidth;
static double xdotspi, ydotspi;

void iffsetup(xdpi, ydpi, xwid, ywid)
int xwid, ywid;
double xdpi, ydpi;
{
   xdotspi = xdpi;
   ydotspi = ydpi;
   xwidth = xwid;
   ywidth = ywid;
   setup = 1;
}

void ifforient(ori)
int ori;
{
   orient = ori;
}

void iffselect(file)
FILE *file;
{
   OutFile = file;
   fileopen = 0;
}

static int getint(s)
char *s;
{
   int 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 double getflt(s)
char *s;
{
   double 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()
{
   while(!OutFile) {
      printf("Enter graphics file name. ");
      fgets(line,sizeof(line),stdin);
      line[strlen(line)-1] = '\0';

      if (!(OutFile = fopen(line,"w")))
         fprintf(stderr,"Can't open %s.\n",line);
      else
         fileopen=1;
   }
}

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(orient) {
      setpxl((double)(ydotspi*25/25.4), (double)(xdotspi*25/25.4));
      setphy(0,vywidth,0,vxwidth);
   }
   else {
      setpxl((double)(xdotspi*25./25.4), (double)(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("");
   }
   iffopenfile();
}

/* 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((int)xdotspi,(int)ydotspi,OutFile);
}

void iffpage()
{
   void mapclear();

   mapclear();
}

void iffeop()
{
}

void iffwidth(width)
int width;
{
   if(width < 1)
      curwid = 1;
   else if(width > 3)
      curwid = 3;
   else
      curwid = width;
}

/* Change color */
void iffcolor(colour)
int colour;
{
}

void iffline(x1,y1,x2,y2)
int 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((int)xdotspi,(int)ydotspi,OutFile);
  if(fileopen)
     fclose(OutFile) ;
  mapfree();
  OutFile = NULL;
  orient = 0;
}

void iffcwin()
{
}

void iffgwin()
{
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.