HylaFAX The world's
most advanced open source fax server
|
|
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
tiff2ps patch for better output
Last week I asked about fixing tiff2ps so that short pages would be put at
the top of the page instead of the bottom. I didn't get any responses,
but I have fixed it myself, so others who are sending their faxes to a
printer may find the changes useful as well.
Previously, tiff2ps had 2 modes. If no page height and width were
specified (via -h and -w), the tiff image is simply bottom-left justified
at the resolution specified in the tiff file. If a page size is given via
-h and -w the tiff image is shrunk or expanded to exactly fill the page.
This is nice for oversize pages, but results in terribly elongated
stretching if the page is short.
To fix this behavior, I have modified the behavior when -h and -w are used
to specify the page size. Short (or narrow) images are no longer
stretched, instead they are simply positioned at the top-left on the page
(previous behavior put it at the bottom-left). Long (or wide) images are
shrunk to fit the page.
The new behavior only applies to Postscript level-1 output so far. (But I
think level-2 output was already broken anyway.)
A patch for tiff2ps.c (against tiff-v3.4beta035) is attached. Feedback is
appreciated, positive or negative. I would like to get this included in
the tiff distribution, so if anyone is maintaining it, feel free to
contact me.
~ John Williams
--- tiff2ps.c 1998/09/29 15:42:13 1.1
+++ tiff2ps.c 1998/10/08 16:56:50
@@ -56,9 +56,9 @@
int ascii85breaklen;
int TIFF2PS(FILE*, TIFF*, float, float);
-void PSpage(FILE*, TIFF*, uint32, uint32);
-void PSColorContigPreamble(FILE*, uint32, uint32, int);
-void PSColorSeparatePreamble(FILE*, uint32, uint32, int);
+void PSpage(FILE*, TIFF*, uint32, uint32, uint32);
+void PSColorContigPreamble(FILE*, uint32, uint32, uint32, int);
+void PSColorSeparatePreamble(FILE*, uint32, uint32, uint32, int);
void PSDataColorContig(FILE*, TIFF*, uint32, uint32, int);
void PSDataColorSeparate(FILE*, TIFF*, uint32, uint32, int);
void PSDataPalette(FILE*, TIFF*, uint32, uint32);
@@ -71,6 +71,8 @@
void PSTail(FILE*, int);
static void usage(int);
+#define MIN(a,b) ((a)<(b)?(a):(b))
+#define MAX(a,b) ((a)>(b)?(a):(b))
int
main(int argc, char* argv[])
@@ -263,10 +265,10 @@
}
static void
-setupPageState(TIFF* tif, uint32* pw, uint32* ph, float* pprw, float* pprh)
+setupPageState(TIFF* tif, uint32* pw, uint32* ph, float* pprw, float* pprh, float *xres, float *yres)
{
uint16 res_unit;
- float xres, yres;
+ /*float xres, yres;*/
TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, pw);
TIFFGetField(tif, TIFFTAG_IMAGELENGTH, ph);
@@ -274,20 +276,20 @@
/*
* Calculate printable area.
*/
- if (!TIFFGetField(tif, TIFFTAG_XRESOLUTION, &xres))
- xres = PS_UNIT_SIZE;
- if (!TIFFGetField(tif, TIFFTAG_YRESOLUTION, &yres))
- yres = PS_UNIT_SIZE;
+ if (!TIFFGetField(tif, TIFFTAG_XRESOLUTION, xres))
+ *xres = PS_UNIT_SIZE;
+ if (!TIFFGetField(tif, TIFFTAG_YRESOLUTION, yres))
+ *yres = PS_UNIT_SIZE;
switch (res_unit) {
case RESUNIT_CENTIMETER:
- xres /= 2.54, yres /= 2.54;
+ *xres /= 2.54, *yres /= 2.54;
break;
case RESUNIT_NONE:
- xres *= PS_UNIT_SIZE, yres *= PS_UNIT_SIZE;
+ *xres *= PS_UNIT_SIZE, *yres *= PS_UNIT_SIZE;
break;
}
- *pprh = PSUNITS(*ph, yres);
- *pprw = PSUNITS(*pw, xres);
+ *pprh = PSUNITS(*ph, *yres);
+ *pprw = PSUNITS(*pw, *xres);
}
static int
@@ -317,18 +319,19 @@
uint32 subfiletype;
uint16* sampleinfo;
static int npages = 0;
+ float xres,yres;
if (!TIFFGetField(tif, TIFFTAG_XPOSITION, &ox))
ox = 0;
if (!TIFFGetField(tif, TIFFTAG_YPOSITION, &oy))
oy = 0;
- setupPageState(tif, &w, &h, &prw, &prh);
+ setupPageState(tif, &w, &h, &prw, &prh, &xres, &yres);
do {
tf_numberstrips = TIFFNumberOfStrips(tif);
TIFFGetFieldDefaulted(tif, TIFFTAG_ROWSPERSTRIP,
&tf_rowsperstrip);
- setupPageState(tif, &w, &h, &prw, &prh);
+ setupPageState(tif, &w, &h, &prw, &prh, &xres, &yres);
if (!npages)
PSHead(fd, tif, w, h, prw, prh, ox, oy);
tf_bytesperrow = TIFFScanlineSize(tif);
@@ -361,12 +364,22 @@
fprintf(fd, "%%%%Page: %d %d\n", npages, npages);
fprintf(fd, "gsave\n");
fprintf(fd, "100 dict begin\n");
- if (pw != 0 && ph != 0)
- fprintf(fd, "%f %f scale\n",
- pw*PS_UNIT_SIZE, ph*PS_UNIT_SIZE);
- else
+ if (pw != 0 && ph != 0) {
+ if (ph*PS_UNIT_SIZE < prh) {
+ fprintf(fd, "%f %f scale\n",
+ MIN(pw*PS_UNIT_SIZE,prw),
+ ph*PS_UNIT_SIZE );
+ PSpage(fd, tif, w, h, h);
+ } else {
+ fprintf(fd, "%f %f scale\n",
+ MIN(pw*PS_UNIT_SIZE,prw),
+ prh );
+ PSpage(fd, tif, w, h, (unsigned long)(ph*yres));
+ }
+ } else {
fprintf(fd, "%f %f scale\n", prw, prh);
- PSpage(fd, tif, w, h);
+ PSpage(fd, tif, w, h, h);
+ }
fprintf(fd, "end\n");
fprintf(fd, "grestore\n");
fprintf(fd, "showpage\n");
@@ -901,7 +914,7 @@
}
void
-PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h)
+PSpage(FILE* fd, TIFF* tif, uint32 w, uint32 h, uint32 ph)
{
if (level2 && PS_Lvl2page(fd, tif, w, h))
return;
@@ -910,20 +923,20 @@
case PHOTOMETRIC_RGB:
if (planarconfiguration == PLANARCONFIG_CONTIG) {
fprintf(fd, "%s", RGBcolorimage);
- PSColorContigPreamble(fd, w, h, 3);
+ PSColorContigPreamble(fd, w, h, ph, 3);
PSDataColorContig(fd, tif, w, h, 3);
} else {
- PSColorSeparatePreamble(fd, w, h, 3);
+ PSColorSeparatePreamble(fd, w, h, ph, 3);
PSDataColorSeparate(fd, tif, w, h, 3);
}
break;
case PHOTOMETRIC_SEPARATED:
/* XXX should emit CMYKcolorimage */
if (planarconfiguration == PLANARCONFIG_CONTIG) {
- PSColorContigPreamble(fd, w, h, 4);
+ PSColorContigPreamble(fd, w, h, ph, 4);
PSDataColorContig(fd, tif, w, h, 4);
} else {
- PSColorSeparatePreamble(fd, w, h, 4);
+ PSColorSeparatePreamble(fd, w, h, ph, 4);
PSDataColorSeparate(fd, tif, w, h, 4);
}
break;
@@ -935,7 +948,7 @@
fprintf(fd, "%lu %lu 8\n",
(unsigned long) w, (unsigned long) h);
fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n",
- (unsigned long) w, (unsigned long) h, (unsigned long) h);
+ (unsigned long) w, (unsigned long) h, (unsigned long) ph);
fprintf(fd, "{currentfile scanLine readhexstring pop} bind\n");
fprintf(fd, "false 3 colorimage\n");
PSDataPalette(fd, tif, w, h);
@@ -948,7 +961,7 @@
fprintf(fd, "%lu %lu %d\n",
(unsigned long) w, (unsigned long) h, bitspersample);
fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n",
- (unsigned long) w, (unsigned long) h, (unsigned long) h);
+ (unsigned long) w, (unsigned long) h, (unsigned long) ph);
fprintf(fd,
"{currentfile scanLine readhexstring pop} bind\n");
fprintf(fd, "image\n");
@@ -959,7 +972,7 @@
}
void
-PSColorContigPreamble(FILE* fd, uint32 w, uint32 h, int nc)
+PSColorContigPreamble(FILE* fd, uint32 w, uint32 h, uint32 ph, int nc)
{
ps_bytesperrow = nc * (tf_bytesperrow / samplesperpixel);
PhotoshopBanner(fd, w, h, 1, nc, "false %d colorimage");
@@ -967,13 +980,13 @@
fprintf(fd, "%lu %lu %d\n",
(unsigned long) w, (unsigned long) h, bitspersample);
fprintf(fd, "[%lu 0 0 -%lu 0 %lu]\n",
- (unsigned long) w, (unsigned long) h, (unsigned long) h);
+ (unsigned long) w, (unsigned long) h, (unsigned long) ph);
fprintf(fd, "{currentfile line readhexstring pop} bind\n");
fprintf(fd, "false %d colorimage\n", nc);
}
void
-PSColorSeparatePreamble(FILE* fd, uint32 w, uint32 h, int nc)
+PSColorSeparatePreamble(FILE* fd, uint32 w, uint32 h, uint32 ph, int nc)
{
int i;
@@ -984,7 +997,7 @@
fprintf(fd, "%lu %lu %d\n",
(unsigned long) w, (unsigned long) h, bitspersample);
fprintf(fd, "[%lu 0 0 -%lu 0 %lu] \n",
- (unsigned long) w, (unsigned long) h, (unsigned long) h);
+ (unsigned long) w, (unsigned long) h, (unsigned long) ph);
for (i = 0; i < nc; i++)
fprintf(fd, "{currentfile line%d readhexstring pop}bind\n", i);
fprintf(fd, "true %d colorimage\n", nc);
Date: Thu, 08 Oct 1998 15:56:38 -0700
From: Aaron Seelye <akharon@3-cities.com>
X-Mailer: Mozilla 4.5b2 [en] (X11; I; Linux 2.0.35 i586)
X-Accept-Language: en
To: flexfax@sgi.com
Subject: flexfax: paging gateway
Sender: owner-flexfax@celestial.com
Hello,
I've finally got hylafax installed, and now i want to setup a method of
getting paged whenever a server goes down, receiving mail, etc. The
problem i'm having is that the pager service my company uses is
Kelley's (if that factors into anything), and the way they're set up for
alpha-numeric pages is that you dial a phone number, input an id and a
pass (they are the same), and then send it along. I was wondering if
anyone else has this config set up, and would be willing to share how
they did it. also, should the config be setup to use ppp0 or cua0 as
the modem?
any help would be greatly appreciated
--
Aaron Seelye
Systems Administrator
BOSS Internet Group