From 22dcb1616ba3e38eb3f24531f13b4623e0a6bab0 Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Thu, 13 Mar 2003 08:57:05 +0000 Subject: [PATCH] changed program name from t2p to tumble. --- Makefile | 16 +- bitblt.c | 6 +- bitblt.h | 6 +- bitblt_g4.c | 6 +- bitblt_table_gen.c | 6 +- g4_table_gen.c | 6 +- parser.y | 6 +- pdf.c | 6 +- pdf.h | 6 +- pdf_bookmark.c | 6 +- pdf_g4.c | 6 +- pdf_jpeg.c | 6 +- pdf_name_tree.c | 6 +- pdf_name_tree.h | 6 +- pdf_prim.c | 6 +- pdf_prim.h | 6 +- pdf_private.h | 6 +- pdf_text.c | 6 +- pdf_util.c | 6 +- pdf_util.h | 6 +- scanner.l | 6 +- semantics.c | 8 +- semantics.h | 6 +- t2p.c | 732 --------------------------------------------- t2p.h | 71 ----- tumble.c | 12 +- tumble.h | 6 +- 27 files changed, 60 insertions(+), 911 deletions(-) delete mode 100644 t2p.c delete mode 100644 t2p.h diff --git a/Makefile b/Makefile index 70de498..3b82a7e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -# t2p: build a PDF file out of one or more TIFF Class F Group 4 files +# tumble: build a PDF file from image files # Makefile -# $Id: Makefile,v 1.28 2003/03/12 23:57:21 eric Exp $ +# $Id: Makefile,v 1.29 2003/03/13 00:57:05 eric Exp $ # Copyright 2001, 2002, 2003 Eric Smith # # This program is free software; you can redistribute it and/or modify @@ -55,18 +55,18 @@ YFLAGS = -d -v # let me know why so I can improve this Makefile. # ----------------------------------------------------------------------------- -VERSION = 0.23 +VERSION = 0.24 -PACKAGE = t2p +PACKAGE = tumble -TARGETS = t2p +TARGETS = tumble -CSRCS = t2p.c semantics.c \ +CSRCS = tumble.c semantics.c \ bitblt.c bitblt_table_gen.c bitblt_g4.c g4_table_gen.c \ pdf.c pdf_util.c pdf_prim.c pdf_bookmark.c pdf_name_tree.c \ pdf_text.c pdf_g4.c pdf_jpeg.c OSRCS = scanner.l parser.y -HDRS = t2p.h semantics.h bitblt.h bitblt_tables.h \ +HDRS = tumble.h semantics.h bitblt.h bitblt_tables.h \ pdf.h pdf_private.h pdf_util.h pdf_prim.h pdf_name_tree.h MISC = COPYING Makefile @@ -85,7 +85,7 @@ AUTO_MISC = parser.output all: $(TARGETS) $(TEST_TARGETS) -t2p: t2p.o scanner.o semantics.o parser.tab.o \ +tumble: tumble.o scanner.o semantics.o parser.tab.o \ bitblt.o bitblt_g4.o bitblt_tables.o g4_tables.o \ pdf.o pdf_util.o pdf_prim.o pdf_bookmark.o pdf_name_tree.o \ pdf_text.o pdf_g4.o pdf_jpeg.o diff --git a/bitblt.c b/bitblt.c index 1cd205a..3ad48c7 100644 --- a/bitblt.c +++ b/bitblt.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * bitblt routines - * $Id: bitblt.c,v 1.15 2003/03/12 02:59:09 eric Exp $ + * $Id: bitblt.c,v 1.16 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/bitblt.h b/bitblt.h index e904514..a0fd668 100644 --- a/bitblt.h +++ b/bitblt.h @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * bitblt routines - * $Id: bitblt.h,v 1.16 2003/03/12 02:59:09 eric Exp $ + * $Id: bitblt.h,v 1.17 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/bitblt_g4.c b/bitblt_g4.c index 1656fa5..b709ca0 100644 --- a/bitblt_g4.c +++ b/bitblt_g4.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * G4 compression - * $Id: bitblt_g4.c,v 1.13 2003/03/12 19:30:44 eric Exp $ + * $Id: bitblt_g4.c,v 1.14 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/bitblt_table_gen.c b/bitblt_table_gen.c index 1ddb968..a7e9158 100644 --- a/bitblt_table_gen.c +++ b/bitblt_table_gen.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * bitblt table generator - * $Id: bitblt_table_gen.c,v 1.6 2003/03/11 22:40:34 eric Exp $ + * $Id: bitblt_table_gen.c,v 1.7 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/g4_table_gen.c b/g4_table_gen.c index 68db2ea..e3390f9 100644 --- a/g4_table_gen.c +++ b/g4_table_gen.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * G4 table generator - * $Id: g4_table_gen.c,v 1.3 2003/03/11 22:57:46 eric Exp $ + * $Id: g4_table_gen.c,v 1.4 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/parser.y b/parser.y index 99daf73..d87bb1b 100644 --- a/parser.y +++ b/parser.y @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * Parser - * $Id: parser.y,v 1.17 2003/02/21 00:49:11 eric Exp $ + * $Id: parser.y,v 1.18 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf.c b/pdf.c index 372e690..3b31e7e 100644 --- a/pdf.c +++ b/pdf.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf.c,v 1.9 2003/03/13 00:03:11 eric Exp $ + * $Id: pdf.c,v 1.10 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf.h b/pdf.h index e46332f..1aa94e4 100644 --- a/pdf.h +++ b/pdf.h @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf.h,v 1.8 2003/03/12 23:57:21 eric Exp $ + * $Id: pdf.h,v 1.9 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_bookmark.c b/pdf_bookmark.c index 5a2e9e7..f375d22 100644 --- a/pdf_bookmark.c +++ b/pdf_bookmark.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_bookmark.c,v 1.5 2003/03/05 12:56:25 eric Exp $ + * $Id: pdf_bookmark.c,v 1.6 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_g4.c b/pdf_g4.c index e91fec8..067bd60 100644 --- a/pdf_g4.c +++ b/pdf_g4.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_g4.c,v 1.14 2003/03/12 23:59:35 eric Exp $ + * $Id: pdf_g4.c,v 1.15 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_jpeg.c b/pdf_jpeg.c index bc7474d..1f74411 100644 --- a/pdf_jpeg.c +++ b/pdf_jpeg.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_jpeg.c,v 1.1 2003/03/12 02:57:06 eric Exp $ + * $Id: pdf_jpeg.c,v 1.2 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_name_tree.c b/pdf_name_tree.c index 953b4e6..7f65d79 100644 --- a/pdf_name_tree.c +++ b/pdf_name_tree.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_name_tree.c,v 1.8 2003/03/12 03:13:28 eric Exp $ + * $Id: pdf_name_tree.c,v 1.9 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_name_tree.h b/pdf_name_tree.h index 981cb7a..0187c73 100644 --- a/pdf_name_tree.h +++ b/pdf_name_tree.h @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_name_tree.h,v 1.2 2003/03/07 22:52:09 eric Exp $ + * $Id: pdf_name_tree.h,v 1.3 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_prim.c b/pdf_prim.c index d49b0bc..e762a9c 100644 --- a/pdf_prim.c +++ b/pdf_prim.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_prim.c,v 1.11 2003/03/13 00:00:21 eric Exp $ + * $Id: pdf_prim.c,v 1.12 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_prim.h b/pdf_prim.h index 15d56e1..a40116f 100644 --- a/pdf_prim.h +++ b/pdf_prim.h @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_prim.h,v 1.9 2003/03/12 22:56:57 eric Exp $ + * $Id: pdf_prim.h,v 1.10 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_private.h b/pdf_private.h index 1530e46..37f97a2 100644 --- a/pdf_private.h +++ b/pdf_private.h @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_private.h,v 1.6 2003/03/07 22:52:09 eric Exp $ + * $Id: pdf_private.h,v 1.7 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_text.c b/pdf_text.c index a898d61..c5b58a2 100644 --- a/pdf_text.c +++ b/pdf_text.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_text.c,v 1.1 2003/03/12 23:57:21 eric Exp $ + * $Id: pdf_text.c,v 1.2 2003/03/13 00:57:05 eric Exp $ * Copyright 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_util.c b/pdf_util.c index b89c0d3..bcf7479 100644 --- a/pdf_util.c +++ b/pdf_util.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_util.c,v 1.5 2003/03/10 05:08:25 eric Exp $ + * $Id: pdf_util.c,v 1.6 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/pdf_util.h b/pdf_util.h index f004b27..f3d741c 100644 --- a/pdf_util.h +++ b/pdf_util.h @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * PDF routines - * $Id: pdf_util.h,v 1.5 2003/03/07 03:02:12 eric Exp $ + * $Id: pdf_util.h,v 1.6 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/scanner.l b/scanner.l index f65a7d8..7b4b255 100644 --- a/scanner.l +++ b/scanner.l @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * Lexical analyzer - * $Id: scanner.l,v 1.17 2003/02/21 00:49:11 eric Exp $ + * $Id: scanner.l,v 1.18 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/semantics.c b/semantics.c index 2d9bbc4..9a7803d 100644 --- a/semantics.c +++ b/semantics.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * Semantic routines for spec file parser - * $Id: semantics.c,v 1.18 2003/03/12 00:38:04 eric Exp $ + * $Id: semantics.c,v 1.19 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -32,7 +30,7 @@ #include "semantics.h" #include "parser.tab.h" -#include "t2p.h" +#include "tumble.h" typedef struct diff --git a/semantics.h b/semantics.h index c9ee43f..05e77b4 100644 --- a/semantics.h +++ b/semantics.h @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * Semantic routines for spec file parser - * $Id: semantics.h,v 1.12 2003/03/12 00:38:04 eric Exp $ + * $Id: semantics.h,v 1.13 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify diff --git a/t2p.c b/t2p.c deleted file mode 100644 index 6aa2243..0000000 --- a/t2p.c +++ /dev/null @@ -1,732 +0,0 @@ -/* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. - * - * Main program - * $Id: t2p.c,v 1.31 2003/03/12 23:59:10 eric Exp $ - * Copyright 2001, 2002, 2003 Eric Smith - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. Note that permission is - * not granted to redistribute this program under the terms of any - * other version of the General Public License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA - */ - - -#include -#include -#include -#include -#include -#include -#include - -#include -#define TIFF_REVERSE_BITS - -#include "bitblt.h" -#include "semantics.h" -#include "parser.tab.h" -#include "t2p.h" -#include "pdf.h" - - -#define MAX_INPUT_FILES 5000 - -#define POINTS_PER_INCH 72 - -/* page size limited by Acrobat Reader to 45 inches on a side */ -#define PAGE_MAX_INCHES 45 -#define PAGE_MAX_POINTS (PAGE_MAX_INCHES * POINTS_PER_INCH) - - -typedef struct output_file_t -{ - struct output_file_t *next; - char *name; - pdf_file_handle pdf; -} output_file_t; - - -int verbose; - - -char *in_filename; -TIFF *in; -output_file_t *output_files; -output_file_t *out; - - -char *progname; - - -bool close_tiff_input_file (void); -bool close_pdf_output_files (void); - - -void usage (void) -{ - fprintf (stderr, "\n"); - fprintf (stderr, "t2p - Copyright 2001-2003 Eric Smith \n"); - fprintf (stderr, "http://www.brouhaha.com/~eric/software/t2p/\n"); - fprintf (stderr, "\n"); - fprintf (stderr, "usage:\n"); - fprintf (stderr, " %s [options] -s spec\n", progname); - fprintf (stderr, " %s [options] ... -o \n", progname); - fprintf (stderr, "options:\n"); - fprintf (stderr, " -v verbose\n"); - fprintf (stderr, " -b fmt create bookmarks\n"); - fprintf (stderr, "bookmark format:\n"); - fprintf (stderr, " %%F file name (sans suffix)\n"); - fprintf (stderr, " %%p page number\n"); -} - - -/* generate fatal error message to stderr, doesn't return */ -void fatal (int ret, char *format, ...) -{ - va_list ap; - - fprintf (stderr, "fatal error"); - if (format) - { - fprintf (stderr, ": "); - va_start (ap, format); - vfprintf (stderr, format, ap); - va_end (ap); - } - else - fprintf (stderr, "\n"); - if (ret == 1) - usage (); - close_tiff_input_file (); - close_pdf_output_files (); - exit (ret); -} - - -bool close_tiff_input_file (void) -{ - if (in) - { - free (in_filename); - TIFFClose (in); - } - in = NULL; - in_filename = NULL; - return (1); -} - - -bool open_tiff_input_file (char *name) -{ - if (in) - { - if (strcmp (name, in_filename) == 0) - return (1); - close_tiff_input_file (); - } - in_filename = strdup (name); - if (! in_filename) - { - fprintf (stderr, "can't strdup input filename '%s'\n", name); - return (0); - } - in = TIFFOpen (name, "r"); - if (! in) - { - fprintf (stderr, "can't open input file '%s'\n", name); - free (in_filename); - return (0); - } - return (1); -} - - -bool close_pdf_output_files (void) -{ - output_file_t *o, *n; - - for (o = output_files; o; o = n) - { - n = o->next; - pdf_close (o->pdf); - free (o->name); - free (o); - } - out = NULL; - output_files = NULL; - return (1); -} - -bool open_pdf_output_file (char *name, - pdf_file_attributes_t *attributes) -{ - output_file_t *o; - - if (out && (strcmp (name, out->name) == 0)) - return (1); - for (o = output_files; o; o = o->next) - if (strcmp (name, o->name) == 0) - { - out = o; - return (1); - } - o = calloc (1, sizeof (output_file_t)); - if (! o) - { - fprintf (stderr, "can't calloc output file struct for '%s'\n", name); - return (0); - } - - o->name = strdup (name); - if (! o->name) - { - fprintf (stderr, "can't strdup output filename '%s'\n", name); - free (o); - return (0); - } - - o->pdf = pdf_create (name, (attributes->has_bookmarks ? - PDF_PAGE_MODE_USE_OUTLINES : - PDF_PAGE_MODE_USE_NONE)); - if (! o->pdf) - { - fprintf (stderr, "can't open output file '%s'\n", name); - free (o->name); - free (o); - return (0); - } - - if (attributes->author) - pdf_set_author (o->pdf, attributes->author); - if (attributes->creator) - pdf_set_creator (o->pdf, attributes->creator); - if (attributes->title) - pdf_set_title (o->pdf, attributes->title); - if (attributes->subject) - pdf_set_subject (o->pdf, attributes->subject); - if (attributes->keywords) - pdf_set_keywords (o->pdf, attributes->keywords); - - /* prepend new output file onto list */ - o->next = output_files; - output_files = o; - - out = o; - return (1); -} - - -void process_page_numbers (int page_index, - int count, - int base, - page_label_t *page_label) -{ -} - - -/* frees original! */ -static Bitmap *resize_bitmap (Bitmap *src, - double x_resolution, - double y_resolution, - input_attributes_t input_attributes) -{ - Rect src_rect; - Point dest_min; - Bitmap *dest; - - int width_pixels = input_attributes.page_size.width * x_resolution; - int height_pixels = input_attributes.page_size.height * y_resolution; - - src_rect.min.x = (rect_width (& src->rect) - width_pixels) / 2; - src_rect.min.y = (rect_height (& src->rect) - height_pixels) / 2; - src_rect.max.x = src_rect.min.x + width_pixels; - src_rect.max.y = src_rect.min.y + height_pixels; - - dest_min.x = 0; - dest_min.y = 0; - - dest = bitblt (src, & src_rect, NULL, & dest_min, TF_SRC, 0); - free_bitmap (src); - return (dest); -} - - -/* "in place" rotation */ -static void rotate_bitmap (Bitmap *src, - input_attributes_t input_attributes) -{ - switch (input_attributes.rotation) - { - case 0: break; - case 90: rot_90 (src); break; - case 180: rot_180 (src); break; - case 270: rot_270 (src); break; - default: - fprintf (stderr, "rotation must be 0, 90, 180, or 270\n"); - } -} - - -#define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0) - - -bool last_tiff_page (void) -{ - return (TIFFLastDirectory (in)); -} - - -bool process_tiff_page (int image, /* range 1 .. n */ - input_attributes_t input_attributes, - bookmark_t *bookmarks) -{ - int result = 0; - - uint32_t image_length, image_width; - uint32_t dest_image_length, dest_image_width; -#ifdef CHECK_DEPTH - uint32_t image_depth; -#endif - - uint16_t samples_per_pixel; - uint16_t bits_per_sample; - uint16_t planar_config; - - uint16_t resolution_unit; - float x_resolution, y_resolution; - double dest_x_resolution, dest_y_resolution; - - double width_points, height_points; /* really 1/72 inch units rather than - points */ - - Rect rect; - Bitmap *bitmap = NULL; - - int row; - - pdf_page_handle page; - - if (! TIFFSetDirectory (in, image - 1)) - { - fprintf (stderr, "can't find page %d of input file\n", image); - goto fail; - } - if (1 != TIFFGetField (in, TIFFTAG_IMAGELENGTH, & image_length)) - { - fprintf (stderr, "can't get image length\n"); - goto fail; - } - if (1 != TIFFGetField (in, TIFFTAG_IMAGEWIDTH, & image_width)) - { - fprintf (stderr, "can't get image width\n"); - goto fail; - } - - if (1 != TIFFGetField (in, TIFFTAG_SAMPLESPERPIXEL, & samples_per_pixel)) - { - fprintf (stderr, "can't get samples per pixel\n"); - goto fail; - } - -#ifdef CHECK_DEPTH - if (1 != TIFFGetField (in, TIFFTAG_IMAGEDEPTH, & image_depth)) - { - fprintf (stderr, "can't get image depth\n"); - goto fail; - } -#endif - - if (1 != TIFFGetField (in, TIFFTAG_BITSPERSAMPLE, & bits_per_sample)) - { - fprintf (stderr, "can't get bits per sample\n"); - goto fail; - } - - if (1 != TIFFGetField (in, TIFFTAG_PLANARCONFIG, & planar_config)) - planar_config = 1; - - if (1 != TIFFGetField (in, TIFFTAG_RESOLUTIONUNIT, & resolution_unit)) - resolution_unit = 2; - if (1 != TIFFGetField (in, TIFFTAG_XRESOLUTION, & x_resolution)) - x_resolution = 300; - if (1 != TIFFGetField (in, TIFFTAG_YRESOLUTION, & y_resolution)) - y_resolution = 300; - - if (samples_per_pixel != 1) - { - fprintf (stderr, "samples per pixel %u, must be 1\n", samples_per_pixel); - goto fail; - } - -#ifdef CHECK_DEPTH - if (image_depth != 1) - { - fprintf (stderr, "image depth %u, must be 1\n", image_depth); - goto fail; - } -#endif - - if (bits_per_sample != 1) - { - fprintf (stderr, "bits per sample %u, must be 1\n", bits_per_sample); - goto fail; - } - - if (planar_config != 1) - { - fprintf (stderr, "planar config %u, must be 1\n", planar_config); - goto fail; - } - - if (input_attributes.has_resolution) - { - x_resolution = input_attributes.x_resolution; - y_resolution = input_attributes.y_resolution; - } - - if ((input_attributes.rotation == 90) || (input_attributes.rotation == 270)) - { - dest_image_width = image_length; - dest_image_length = image_width; - dest_x_resolution = y_resolution; - dest_y_resolution = x_resolution; - SWAP (double, width_points, height_points); /* $$$ not yet set!!! */ - } - else - { - dest_image_width = image_width; - dest_image_length = image_length; - dest_x_resolution = x_resolution; - dest_y_resolution = y_resolution; - } - - rect.min.x = 0; - rect.min.y = 0; - rect.max.x = image_width; - rect.max.y = image_length; - - bitmap = create_bitmap (& rect); - - if (! bitmap) - { - fprintf (stderr, "can't allocate bitmap\n"); - goto fail; - } - - for (row = 0; row < image_length; row++) - if (1 != TIFFReadScanline (in, - bitmap->bits + row * bitmap->row_words, - row, - 0)) - { - fprintf (stderr, "can't read TIFF scanline\n"); - goto fail; - } - -#ifdef TIFF_REVERSE_BITS - reverse_bits ((uint8_t *) bitmap->bits, - image_length * bitmap->row_words * sizeof (word_t)); -#endif /* TIFF_REVERSE_BITS */ - -#if 0 - if (input_attributes.has_page_size) - bitmap = resize_bitmap (bitmap, - x_resolution, - y_resolution, - input_attributes); -#endif - - rotate_bitmap (bitmap, - input_attributes); - - width_points = (rect_width (& bitmap->rect) / dest_x_resolution) * POINTS_PER_INCH; - height_points = (rect_height (& bitmap->rect) / dest_y_resolution) * POINTS_PER_INCH; - - if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) - { - fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); - goto fail; - } - - page = pdf_new_page (out->pdf, width_points, height_points); - -#if 0 - pdf_write_text (page); -#else - pdf_write_g4_fax_image (page, - 0, 0, /* x, y */ - width_points, height_points, - bitmap, - 0, /* ImageMask */ - 0, 0, 0, /* r, g, b */ - 0); /* BlackIs1 */ -#endif - - while (bookmarks) - { - /* $$$ need to handle level here */ - pdf_new_bookmark (NULL, bookmarks->name, 0, page); - bookmarks = bookmarks->next; - } - - result = 1; - - fail: - if (bitmap) - free_bitmap (bitmap); - - return (result); -} - - -#if 0 -bool process_jpeg_page (int image, /* range 1 .. n */ - input_attributes_t input_attributes, - bookmark_t *bookmarks) -{ - int result = 0; - FILE *f; - pdf_page_handle page; - - f = fopen (filename, "rb"); - if (! f) - fatal ("error opening input file '%s'\n", filename); - - page = pdf_new_page (out->pdf, width_points, height_points); - - pdf_write_jpeg_image (page, - 0, 0, /* x, y */ - width_points, height_points, - f); - - return (result); -} -#endif - - -bool process_page (int image, /* range 1 .. n */ - input_attributes_t input_attributes, - bookmark_t *bookmarks) -{ - int result = 0; - - result = process_tiff_page (image, input_attributes, bookmarks); - - return (result); -} - - -#define MAX_BOOKMARK_NAME_LEN 500 - - -static int filename_length_without_suffix (char *in_fn) -{ - char *p; - int len = strlen (in_fn); - - p = strrchr (in_fn, '.'); - if (p && ((strcasecmp (p, ".tif") == 0) || - (strcasecmp (p, ".tiff") == 0))) - return (p - in_fn); - return (len); -} - - -/* $$$ this function should ensure that it doesn't overflow the name string! */ -static void generate_bookmark_name (char *name, - char *bookmark_fmt, - char *in_fn, - int page) -{ - bool meta = 0; - int len; - - while (*bookmark_fmt) - { - if (meta) - { - meta = 0; - switch (*bookmark_fmt) - { - case '%': - *(name++) = '%'; - break; - case 'F': - len = filename_length_without_suffix (in_fn); - strncpy (name, in_fn, len); - name += len; - break; - case 'p': - sprintf (name, "%d", page); - name += strlen (name); - break; - default: - break; - } - } - else - switch (*bookmark_fmt) - { - case '%': - meta = 1; - break; - default: - *(name++) = *bookmark_fmt; - } - bookmark_fmt++; - } - *name = '\0'; -} - - -void main_args (char *out_fn, - int inf_count, - char **in_fn, - char *bookmark_fmt) -{ - int i, ip; - input_attributes_t input_attributes; - pdf_file_attributes_t output_attributes; - bookmark_t bookmark; - char bookmark_name [MAX_BOOKMARK_NAME_LEN]; - - bookmark.next = NULL; - bookmark.level = 1; - bookmark.name = & bookmark_name [0]; - - memset (& input_attributes, 0, sizeof (input_attributes)); - memset (& output_attributes, 0, sizeof (output_attributes)); - - output_attributes.has_bookmarks = (bookmark_fmt != NULL); - - if (! open_pdf_output_file (out_fn, & output_attributes)) - fatal (3, "error opening output file \"%s\"\n", out_fn); - for (i = 0; i < inf_count; i++) - { - if (! open_tiff_input_file (in_fn [i])) - fatal (3, "error opening input file \"%s\"\n", in_fn [i]); - for (ip = 1;; ip++) - { - fprintf (stderr, "processing page %d of file \"%s\"\r", ip, in_fn [i]); - if (bookmark_fmt) - generate_bookmark_name (& bookmark_name [0], - bookmark_fmt, - in_fn [i], - ip); - if (! process_page (ip, input_attributes, - bookmark_fmt ? & bookmark : NULL)) - fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]); - if (last_tiff_page ()) - break; - } - if (verbose) - fprintf (stderr, "processed %d pages of input file \"%s\"\n", ip, in_fn [i]); - if (! close_tiff_input_file ()) - fatal (3, "error closing input file \"%s\"\n", in_fn [i]); - } - if (! close_pdf_output_files ()) - fatal (3, "error closing output file \"%s\"\n", out_fn); -} - - -void main_spec (char *spec_fn) -{ - if (! parse_spec_file (spec_fn)) - fatal (2, "error parsing spec file\n"); - if (! process_specs ()) - fatal (3, "error processing spec file\n"); -} - - -int main (int argc, char *argv[]) -{ - char *spec_fn = NULL; - char *out_fn = NULL; - char *bookmark_fmt = NULL; - int inf_count = 0; - char *in_fn [MAX_INPUT_FILES]; - - progname = argv [0]; - - pdf_init (); - - while (--argc) - { - if (argv [1][0] == '-') - { - if (strcmp (argv [1], "-v") == 0) - verbose++; - else if (strcmp (argv [1], "-o") == 0) - { - if (argc) - { - argc--; - argv++; - out_fn = argv [1]; - } - else - fatal (1, "missing filename after \"-o\" option\n"); - } - else if (strcmp (argv [1], "-s") == 0) - { - if (argc) - { - argc--; - argv++; - spec_fn = argv [1]; - } - else - fatal (1, "missing filename after \"-s\" option\n"); - } - else if (strcmp (argv [1], "-b") == 0) - { - if (argc) - { - argc--; - argv++; - bookmark_fmt = argv [1]; - } - else - fatal (1, "missing format string after \"-b\" option\n"); - } - else - fatal (1, "unrecognized option \"%s\"\n", argv [1]); - } - else if (inf_count < MAX_INPUT_FILES) - in_fn [inf_count++] = argv [1]; - else - fatal (1, "exceeded maximum of %d input files\n", MAX_INPUT_FILES); - argv++; - } - - if (! ((! out_fn) ^ (! spec_fn))) - fatal (1, "either a spec file or an output file (but not both) must be specified\n"); - - if (out_fn && ! inf_count) - fatal (1, "no input files specified\n"); - - if (spec_fn && inf_count) - fatal (1, "if spec file is provided, input files can't be specified as arguments\n"); - - if (spec_fn) - main_spec (spec_fn); - else - main_args (out_fn, inf_count, in_fn, bookmark_fmt); - - close_tiff_input_file (); - close_pdf_output_files (); - exit (0); -} diff --git a/t2p.h b/t2p.h deleted file mode 100644 index ffe91d7..0000000 --- a/t2p.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. - * - * $Id: t2p.h,v 1.12 2003/03/12 23:59:10 eric Exp $ - * Copyright 2001, 2002, 2003 Eric Smith - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. Note that permission is - * not granted to redistribute this program under the terms of any - * other version of the General Public License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA */ - - -extern int verbose; - - -typedef struct -{ - bool has_resolution; - double x_resolution; - double y_resolution; - - bool has_page_size; - page_size_t page_size; - - bool has_rotation; - int rotation; - - bool has_crop; - crop_t crop; -} input_attributes_t; - -bool open_tiff_input_file (char *name); -bool close_tiff_input_file (void); - - -typedef struct -{ - char *author; - char *creator; - char *title; - char *subject; - char *keywords; - bool has_bookmarks; -} pdf_file_attributes_t; - -bool open_pdf_output_file (char *name, - pdf_file_attributes_t *attributes); - - -void process_page_numbers (int page_index, - int count, - int base, - page_label_t *page_label); - - - -bool process_page (int image, /* range 1 .. n */ - input_attributes_t input_attributes, - bookmark_t *bookmarks); diff --git a/tumble.c b/tumble.c index 48f5d9c..856c695 100644 --- a/tumble.c +++ b/tumble.c @@ -1,10 +1,8 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * * Main program - * $Id: tumble.c,v 1.31 2003/03/12 23:59:10 eric Exp $ + * $Id: tumble.c,v 1.32 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -38,7 +36,7 @@ #include "bitblt.h" #include "semantics.h" #include "parser.tab.h" -#include "t2p.h" +#include "tumble.h" #include "pdf.h" @@ -78,8 +76,8 @@ bool close_pdf_output_files (void); void usage (void) { fprintf (stderr, "\n"); - fprintf (stderr, "t2p - Copyright 2001-2003 Eric Smith \n"); - fprintf (stderr, "http://www.brouhaha.com/~eric/software/t2p/\n"); + fprintf (stderr, "tumble - Copyright 2001-2003 Eric Smith \n"); + fprintf (stderr, "http://www.brouhaha.com/~eric/software/tumble/\n"); fprintf (stderr, "\n"); fprintf (stderr, "usage:\n"); fprintf (stderr, " %s [options] -s spec\n", progname); diff --git a/tumble.h b/tumble.h index 35a30a4..9976e29 100644 --- a/tumble.h +++ b/tumble.h @@ -1,9 +1,7 @@ /* - * t2p: Create a PDF file from the contents of one or more TIFF - * bilevel image files. The images in the resulting PDF file - * will be compressed using ITU-T T.6 (G4) fax encoding. + * tumble: build a PDF file from image files * - * $Id: tumble.h,v 1.12 2003/03/12 23:59:10 eric Exp $ + * $Id: tumble.h,v 1.13 2003/03/13 00:57:05 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify