home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
tif2ps
/
part01
/
tif2ps.c
< prev
Wrap
C/C++ Source or Header
|
1989-02-03
|
5KB
|
213 lines
/*
* tif2ps/tifdump -- convert TIFF to PostScript
*
* written by:
* Andreas Lampen, TU-Berlin (andy@coma.UUCP)
* (andy@db0tui62.BITNET)
*
* Copyright (C) 1988 by the author.
* Permission is granted to copy and distribute this program
* without charge, provided this copyright notice is included
* in the copy.
* This Software is distributed on an as-is basis. There will be
* ABSOLUTELY NO WARRANTY for any part of this software to work
* correct. In no case will the author be liable to you for damages
* caused by the usage of this software.
*/
/*
* tif2ps.c -- main program
*
* $Header: tif2ps.c[1.0] Thu Dec 29 20:11:01 1988 andy@coma published $
*/
#include <stdio.h>
#ifdef MSDOS
#include <string.h>
#include <time.h>
#else
#include <strings.h>
#include <sys/time.h>
#endif
#include <setjmp.h>
#include <signal.h>
#include "defs.h"
#include "tif.h"
extern CHAR *optarg;
extern INT optind;
CHAR *progname, *version();
main (ac, av)
INT ac;
CHAR **av;
{
INT getopt(), c, nfiles, i, cleanup();
VOID usage(), logerr(), dodump(), genps();
DOUBLE xoffset = 0., yoffset= 0., scalefactor = 1., height = 0.;
DOUBLE xresfactor, yresfactor, atof();
PICTURE picts[8]; /* maximal 8 pictures */
TIFF tiff;
jmp_buf env;
#ifdef MSDOS
if (!strrchr (av[0], '\\')) progname = av[0];
else progname = strrchr (av[0], '\\') + 1;
#else
if (!rindex (av[0], '/')) progname = av[0];
else progname = rindex (av[0], '/') + 1;
#endif
if (ac < 2)
{
usage ();
exit (-1);
}
while ((c = getopt (ac, av, "h:s:vx:y:")) != EOF)
{
switch (c)
{
case 'h': /* picture height */
if (scalefactor != 1.)
logerr (progname, "only one of 'h' or 's' can be given");
else
height = atof (optarg) * 72;
break;
case 's': /* scale factor */
if (height != 0.)
logerr (progname, "only one of 'h' or 's' can be given");
else
scalefactor = atof (optarg);
break;
case 'v': /* print current version of this program */
printf ("This is %s version %s.\n", av[0], version());
exit (0);
case 'x': /* xposition (in inches) */
xoffset = atof (optarg) * 72;
break;
case 'y': /* yposition (in inches) */
yoffset = atof (optarg) * 72;
break;
default:
usage ();
exit (-1);
}
} /* end of command line parsing */
(VOID) signal (SIGINT, cleanup);
nfiles = ac - optind;
for (i = 0; i < nfiles; i++)
{
/* (VOID) setjmp (env); --- not used */
if (scantif (av[i+optind], picts, &tiff) == ERROR)
{ logerr (progname, "cannot read file"); exit (-1); }
if (!strcmp (progname, "tifdump"))
{
printf ("This is %s version %s.\n\n", progname, version());
dodump (av[i+optind], &tiff);
continue;
}
/* else do initializations */
/* a loop through all pictures should be inserted here */
/* adjust bytecount ???? perhaps not correct */
/* manages only single strip pictures */
if (picts[0].image.strips[0].byteCount == 0)
picts[0].image.strips[0].byteCount =
(picts[0].image.imWidth * picts[0].image.imLength) /
(8 / picts[i].image.bitsPerSample);
switch (picts[0].physWorld.resUnit)
{
case 1: /* special */
xresfactor = 1. / picts[0].physWorld.xRes;
yresfactor = 1. / picts[0].physWorld.yRes;
break;
case 2: /* inches */
xresfactor = 72. / picts[0].physWorld.xRes;
yresfactor = 72. / picts[0].physWorld.yRes;
break;
case 3: /* centimetres */
xresfactor = 28.3465 / picts[0].physWorld.xRes;
yresfactor = 28.3465 / picts[0].physWorld.yRes;
break;
}
if (height != 0.)
scalefactor = (height / (picts[0].image.imLength * yresfactor));
if (xoffset != 0.)
picts[0].context.xPos = xoffset;
if (yoffset != 0.)
picts[0].context.yPos = yoffset;
picts[0].context.xMax =
(picts[0].image.imWidth * xresfactor * scalefactor) +
picts[0].context.xPos;
picts[0].context.yMax =
(picts[0].image.imLength * yresfactor * scalefactor) +
picts[0].context.yPos;
genps (av[i+optind], picts);
}
} /* end of main */
LOCAL INT cleanup ()
{
#ifdef MSDOS
cprintf ("cleanup...\n");
#else
fprintf (stderr, "cleanup...\n");
#endif
exit (-1);
}
LOCAL VOID usage ()
{
printf ("usage: %s [-h <height>] [-s <scalefactor>]\n", progname);
printf ("\t\t[-v] [-x <x-offset>] [-y <y-offset>] file1 ...\n");
}
EXPORT VOID logerr (routine, msg)
CHAR *routine, *msg;
{
#ifdef MSDOS
cprintf ("%s(%s): %s\n", progname, routine, msg);
#else
fprintf (stderr, "%s(%s): %s\n", progname, routine, msg);
#endif
}
EXPORT CHAR *date()
{
LONG seconds, time();
#ifndef MSDOS
CHAR *asctime();
#endif
#ifdef MSDOS
time (&seconds);
return (ctime (&seconds));
#else
seconds = time ((LONG *) 0);
return (asctime (localtime (&seconds)));
#endif
}
EXPORT CHAR *caller()
{
STATIC CHAR name[128];
#ifdef MSDOS
strcpy (name, ""); /* cannot get hostname and login name */
#else
CHAR *getlogin (), host[128];
(VOID) gethostname (host, 128);
(VOID) sprintf (name, "%s@%s\0", getlogin(), host);
#endif
return (name);
}