home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume6 / tif2ps / part01 / genps.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  4KB  |  126 lines

  1. /*
  2.  * tif2ps/tifdump -- convert TIFF to PostScript
  3.  *
  4.  * written by:
  5.  * Andreas Lampen, TU-Berlin (andy@coma.UUCP)
  6.  *                 (andy@db0tui62.BITNET)
  7.  *
  8.  * Copyright (C) 1988 by the author.
  9.  * Permission is granted to copy and distribute this program
  10.  * without charge, provided this copyright notice is included
  11.  * in the copy.
  12.  * This Software is distributed on an as-is basis. There will be
  13.  * ABSOLUTELY NO WARRANTY for any part of this software to work
  14.  * correct. In no case will the author be liable to you for damages
  15.  * caused by the usage of this software.
  16.  */
  17.  
  18. /*
  19.  * genps.c -- generate PostScript output
  20.  * 
  21.  * $Header: genps.c[1.0] Thu Dec 29 20:10:57 1988 andy@coma published $
  22.  */
  23.  
  24. #include <stdio.h>
  25. #include <math.h>
  26. #include "defs.h"
  27. #include "tif.h"
  28.  
  29. extern CHAR *progname;
  30. extern USHORT pages;
  31.  
  32. EXPORT VOID genps (filename, picts)
  33.      CHAR    *filename;
  34.      PICTURE *picts;
  35. {
  36.   USHORT xsamples, ysamples, c1, c2, noOfGrayVals;
  37.   LONG   i;
  38.   CHAR   *version(), *date(), *caller();
  39.   VOID   logerr();
  40.  
  41.   /* a loop through all pictures should be inserted here */
  42.   
  43.   printf ("%%!PS-Adobe-2.0\n");
  44.   printf ("%%%%Title: %s\n",
  45.        picts[0].context.docName[0] ? picts[0].context.docName : filename);
  46.   printf ("%%%%Creator: %s %s\n", progname, version());
  47.   printf ("%%%%CreationDate: %s", date());
  48.   printf ("%%%%For: %s\n", caller());
  49.   printf ("%%%%Page: %d of %d\n", 
  50.        picts[0].context.pageNo, picts[0].context.noOfPages);
  51.   printf ("%%%%BoundingBox: %.2f %.2f %.2f %.2f\n",
  52.        picts[0].context.xPos, picts[0].context.yPos,
  53.        picts[0].context.xMax, picts[0].context.yMax);
  54.   printf ("%%%%EndComments\n");
  55.  
  56.   /* the calculation of a reasonable number of rows should be inserted here */
  57.   printf ("/DataString 2 string def\n");
  58.   printf ("%%%%EndProlog\n");
  59.  
  60.   printf ("/vmstat save def\n");
  61.   printf ("initgraphics\n");
  62.   printf ("( :: %s/TIFF->PostScript - job starts ::\\n) print flush\n", caller ());
  63.   printf ("( :: printing %s ::\\n) print flush\n", filename);
  64.  
  65.   /* Image */
  66.   printf ("gsave\n");
  67.  
  68.   if (picts[0].image.bitsPerSample > 1)
  69.     {
  70.       /* define new grayscale */
  71.       noOfGrayVals = (SHORT) pow ((DOUBLE)2, 
  72.                   (DOUBLE)picts[0].image.bitsPerSample);
  73.       printf ("{ %d mul round cvi\n[ ", noOfGrayVals-1);
  74.       for (i = 0 ; i < noOfGrayVals; i++)
  75.     printf ("%d ", picts[0].photoMetric.grayResponseCurve[i]);
  76.       printf ("]\nexch get %d div 1.0 exch sub } settransfer\n",
  77.            picts[0].photoMetric.grayResponseCurve[0]);
  78.     }
  79.  
  80.   printf ("%.2f %.2f translate\n",
  81.        picts[0].context.xPos, picts[0].context.yPos);
  82.   printf ("%.2f %.2f scale\n", 
  83.        picts[0].context.xMax - picts[0].context.xPos,
  84.        picts[0].context.yMax - picts[0].context.yPos);
  85.  
  86.   /* adjust transformation matrix */
  87.  
  88.   /* do image data */
  89.   xsamples = (picts[0].image.strips[0].byteCount / picts[0].image.imLength) * 
  90.     (8 / picts[0].image.bitsPerSample);
  91.   ysamples = picts[0].image.imLength;
  92.   printf ("%d %d %d ", 
  93.        xsamples, ysamples, picts[0].image.bitsPerSample);
  94.  
  95.   switch (picts[0].physWorld.orientation)
  96.     {
  97.     case 1:
  98.       printf ("[ %d 0 0 %d 0 %d ]\n", xsamples, -ysamples, ysamples);
  99.       break;
  100.     case 4:
  101.       printf ("[ %d 0 0 %d 0 0 ]\n", xsamples, ysamples);
  102.       break;
  103.     default:
  104.       logerr ("genps", "invalid orientation");
  105.       return;
  106.     }
  107.  
  108.   printf ("{ currentfile DataString readhexstring pop } image \n");
  109.   for (i=0; i < picts[0].image.strips[0].byteCount; i++)
  110.     {
  111.       c1 = (picts[0].image.strips[0].data[i] & 0360) >> 4; /* upper 4 bits */
  112.       c2 = (picts[0].image.strips[0].data[i] & 017); /* lower 4 bits */
  113.       printf ("%c%c", (c1 <= 9) ? (c1+'0') : (c1+'W'),
  114.                            (c2 <= 9) ? (c2+'0') : (c2+'W'));
  115.     }
  116.  
  117.   printf ("\ngrestore\n");
  118.  
  119.   printf ("showpage\n");
  120.   printf ("vmstat restore\n");
  121.   printf ("%%%%Trailer\n");
  122.  
  123.   printf ("( :: Job finished ::\\n) print flush\n");
  124. }
  125.  
  126.