Be able to extract the first page (#0). As per bug

http://bugzilla.remotesensing.org/show_bug.cgi?id=690
This commit is contained in:
Andrey Kiselev 2004-11-29 16:20:30 +00:00
parent 9013d3b16c
commit d9845f725c

View File

@ -1,4 +1,4 @@
/* $Id: fax2ps.c,v 1.17 2004-09-09 18:02:13 fwarmerdam Exp $" */ /* $Id: fax2ps.c,v 1.18 2004-11-29 16:20:30 dron Exp $" */
/* /*
* Copyright (c) 1991-1997 Sam Leffler * Copyright (c) 1991-1997 Sam Leffler
@ -187,7 +187,7 @@ emitFont(FILE* fd)
} }
void void
printTIF(TIFF* tif, int pageNumber) printTIF(TIFF* tif, uint16 pageNumber)
{ {
uint32 w, h; uint32 w, h;
uint16 unit; uint16 unit;
@ -236,7 +236,7 @@ printTIF(TIFF* tif, int pageNumber)
printf("/s{show}d\n"); printf("/s{show}d\n");
printf("/p{showpage}d \n"); /* end page */ printf("/p{showpage}d \n"); /* end page */
printf("%%%%EndProlog\n"); printf("%%%%EndProlog\n");
printf("%%%%Page: \"%d\" %d\n", pageNumber, pageNumber); printf("%%%%Page: \"%u\" %u\n", pageNumber, pageNumber);
printf("/$pageTop save def gsave\n"); printf("/$pageTop save def gsave\n");
if (scaleToPage) if (scaleToPage)
scale = pageHeight / (h/yres) < pageWidth / (w/xres) ? scale = pageHeight / (h/yres) < pageWidth / (w/xres) ?
@ -260,7 +260,7 @@ printTIF(TIFF* tif, int pageNumber)
TIFFGetField(tif, TIFFTAG_PAGENUMBER, &pn, &ptotal) TIFFGetField(tif, TIFFTAG_PAGENUMBER, &pn, &ptotal)
int int
findPage(TIFF* tif, int pageNumber) findPage(TIFF* tif, uint16 pageNumber)
{ {
uint16 pn = (uint16) -1; uint16 pn = (uint16) -1;
uint16 ptotal = (uint16) -1; uint16 ptotal = (uint16) -1;
@ -273,7 +273,7 @@ findPage(TIFF* tif, int pageNumber)
} }
void void
fax2ps(TIFF* tif, int npages, int* pages, char* filename) fax2ps(TIFF* tif, uint16 npages, uint16* pages, char* filename)
{ {
if (npages > 0) { if (npages > 0) {
uint16 pn, ptotal; uint16 pn, ptotal;
@ -289,7 +289,7 @@ fax2ps(TIFF* tif, int npages, int* pages, char* filename)
fprintf(stderr, "%s: No page number %d\n", filename, pages[i]); fprintf(stderr, "%s: No page number %d\n", filename, pages[i]);
} }
} else { } else {
int pageNumber = 1; uint16 pageNumber = 0;
do do
printTIF(tif, pageNumber++); printTIF(tif, pageNumber++);
while (TIFFReadDirectory(tif)); while (TIFFReadDirectory(tif));
@ -313,9 +313,8 @@ main(int argc, char** argv)
{ {
extern int optind; extern int optind;
extern char* optarg; extern char* optarg;
int c, pageNumber; uint16 *pages = NULL, npages = 0, pageNumber;
int* pages = 0, npages = 0; int c, dowarnings = 0; /* if 1, enable library warnings */
int dowarnings = 0; /* if 1, enable library warnings */
TIFF* tif; TIFF* tif;
while ((c = getopt(argc, argv, "l:p:x:y:W:H:wS")) != -1) while ((c = getopt(argc, argv, "l:p:x:y:W:H:wS")) != -1)
@ -330,16 +329,11 @@ main(int argc, char** argv)
pageWidth = (float)atof(optarg); pageWidth = (float)atof(optarg);
break; break;
case 'p': /* print specific page */ case 'p': /* print specific page */
pageNumber = atoi(optarg); pageNumber = (uint16)atoi(optarg);
if (pageNumber < 1) {
fprintf(stderr, "%s: Invalid page number (must be > 0).\n",
optarg);
usage(-1);
}
if (pages) if (pages)
pages = (int*) realloc((char*)pages, (npages+1)*sizeof(int)); pages = (uint16*) realloc(pages, (npages+1)*sizeof(uint16));
else else
pages = (int*) malloc(sizeof(int)); pages = (uint16*) malloc(sizeof(uint16));
pages[npages++] = pageNumber; pages[npages++] = pageNumber;
break; break;
case 'w': case 'w':
@ -358,7 +352,7 @@ main(int argc, char** argv)
usage(-1); usage(-1);
} }
if (npages > 0) if (npages > 0)
qsort(pages, npages, sizeof (int), pcompar); qsort(pages, npages, sizeof(uint16), pcompar);
if (!dowarnings) if (!dowarnings)
TIFFSetWarningHandler(0); TIFFSetWarningHandler(0);
if (optind < argc) { if (optind < argc) {