home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume6
/
tif2ps
/
part01
/
genps.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-02-03
|
4KB
|
126 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.
*/
/*
* genps.c -- generate PostScript output
*
* $Header: genps.c[1.0] Thu Dec 29 20:10:57 1988 andy@coma published $
*/
#include <stdio.h>
#include <math.h>
#include "defs.h"
#include "tif.h"
extern CHAR *progname;
extern USHORT pages;
EXPORT VOID genps (filename, picts)
CHAR *filename;
PICTURE *picts;
{
USHORT xsamples, ysamples, c1, c2, noOfGrayVals;
LONG i;
CHAR *version(), *date(), *caller();
VOID logerr();
/* a loop through all pictures should be inserted here */
printf ("%%!PS-Adobe-2.0\n");
printf ("%%%%Title: %s\n",
picts[0].context.docName[0] ? picts[0].context.docName : filename);
printf ("%%%%Creator: %s %s\n", progname, version());
printf ("%%%%CreationDate: %s", date());
printf ("%%%%For: %s\n", caller());
printf ("%%%%Page: %d of %d\n",
picts[0].context.pageNo, picts[0].context.noOfPages);
printf ("%%%%BoundingBox: %.2f %.2f %.2f %.2f\n",
picts[0].context.xPos, picts[0].context.yPos,
picts[0].context.xMax, picts[0].context.yMax);
printf ("%%%%EndComments\n");
/* the calculation of a reasonable number of rows should be inserted here */
printf ("/DataString 2 string def\n");
printf ("%%%%EndProlog\n");
printf ("/vmstat save def\n");
printf ("initgraphics\n");
printf ("( :: %s/TIFF->PostScript - job starts ::\\n) print flush\n", caller ());
printf ("( :: printing %s ::\\n) print flush\n", filename);
/* Image */
printf ("gsave\n");
if (picts[0].image.bitsPerSample > 1)
{
/* define new grayscale */
noOfGrayVals = (SHORT) pow ((DOUBLE)2,
(DOUBLE)picts[0].image.bitsPerSample);
printf ("{ %d mul round cvi\n[ ", noOfGrayVals-1);
for (i = 0 ; i < noOfGrayVals; i++)
printf ("%d ", picts[0].photoMetric.grayResponseCurve[i]);
printf ("]\nexch get %d div 1.0 exch sub } settransfer\n",
picts[0].photoMetric.grayResponseCurve[0]);
}
printf ("%.2f %.2f translate\n",
picts[0].context.xPos, picts[0].context.yPos);
printf ("%.2f %.2f scale\n",
picts[0].context.xMax - picts[0].context.xPos,
picts[0].context.yMax - picts[0].context.yPos);
/* adjust transformation matrix */
/* do image data */
xsamples = (picts[0].image.strips[0].byteCount / picts[0].image.imLength) *
(8 / picts[0].image.bitsPerSample);
ysamples = picts[0].image.imLength;
printf ("%d %d %d ",
xsamples, ysamples, picts[0].image.bitsPerSample);
switch (picts[0].physWorld.orientation)
{
case 1:
printf ("[ %d 0 0 %d 0 %d ]\n", xsamples, -ysamples, ysamples);
break;
case 4:
printf ("[ %d 0 0 %d 0 0 ]\n", xsamples, ysamples);
break;
default:
logerr ("genps", "invalid orientation");
return;
}
printf ("{ currentfile DataString readhexstring pop } image \n");
for (i=0; i < picts[0].image.strips[0].byteCount; i++)
{
c1 = (picts[0].image.strips[0].data[i] & 0360) >> 4; /* upper 4 bits */
c2 = (picts[0].image.strips[0].data[i] & 017); /* lower 4 bits */
printf ("%c%c", (c1 <= 9) ? (c1+'0') : (c1+'W'),
(c2 <= 9) ? (c2+'0') : (c2+'W'));
}
printf ("\ngrestore\n");
printf ("showpage\n");
printf ("vmstat restore\n");
printf ("%%%%Trailer\n");
printf ("( :: Job finished ::\\n) print flush\n");
}