From 3f1c802c9cc65dcf5ebcc5ea8007acab2ef3b1a8 Mon Sep 17 00:00:00 2001 From: Eric Smith Date: Thu, 20 Feb 2003 12:44:17 +0000 Subject: [PATCH] my own PDF routines to replace Panda. --- Makefile | 8 ++-- bitblt_g4.c | 70 ++++++++++++++++++---------- pdf.c | 29 ++++++++++++ pdf.h | 34 +++++++++++--- pdf_g4.c | 70 ++++++++++++++++++---------- pdf_prim.c | 37 +++++++++++++-- pdf_prim.h | 28 +++++++++++- pdf_private.h | 26 +++++++++++ pdf_util.c | 29 ++++++++++++ pdf_util.h | 26 +++++++++++ t2p.c | 124 +++++++++++++++++--------------------------------- tumble.c | 124 +++++++++++++++++--------------------------------- 12 files changed, 378 insertions(+), 227 deletions(-) diff --git a/Makefile b/Makefile index 25f3e4b..bc5477d 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 # Makefile -# $Id: Makefile,v 1.13 2003/02/20 04:21:10 eric Exp $ +# $Id: Makefile,v 1.14 2003/02/20 04:44:17 eric Exp $ # Copyright 2001 Eric Smith # # This program is free software; you can redistribute it and/or modify @@ -19,13 +19,13 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA -CFLAGS = -Wall -g -I/usr/local/include/panda +CFLAGS = -Wall -g # Panda is not all that common, so we'll statically link it in order to # make the t2p binary more portable. LDFLAGS = -g -LDLIBS = -Wl,-static -lpanda -Wl,-dy -lpng -ltiff -ljpeg -lz -lm -L/usr/local/lib/panda +LDLIBS = -ltiff -lm YACC = bison YFLAGS = -d -v @@ -61,7 +61,7 @@ all: $(TARGETS) t2p: t2p.o scanner.o semantics.o parser.tab.o bitblt.o \ - pdf_util.o pdf_prim.o pdf_g4.o + pdf.o pdf_util.o pdf_prim.o pdf_g4.o bitblt_tables.h: bitblt_table_gen ./bitblt_table_gen >bitblt_tables.h diff --git a/bitblt_g4.c b/bitblt_g4.c index ea71065..be18ecc 100644 --- a/bitblt_g4.c +++ b/bitblt_g4.c @@ -1,7 +1,36 @@ +/* + * 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. + * + * PDF routines + * $Id: bitblt_g4.c,v 1.3 2003/02/20 04:44:17 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 "bitblt.h" #include "pdf.h" #include "pdf_util.h" #include "pdf_prim.h" @@ -12,10 +41,8 @@ struct pdf_g4_image { unsigned long Columns; unsigned long Rows; - unsigned long rowbytes; int BlackIs1; - unsigned char *data; - unsigned long len; + Bitmap *bitmap; char XObject_name [4]; }; @@ -69,23 +96,24 @@ void pdf_write_g4_fax_image_callback (pdf_file_handle pdf_file, { struct pdf_g4_image *image = app_data; -#if 1 +#if 0 pdf_stream_write_data (pdf_file, stream, image->data, image->len); #else unsigned long row = 0; - unsigned char *ref; - unsigned char *raw; + word_type *ref; + word_type *raw; ref = NULL; - raw = image->data; + raw = image->bitmap->bits; while (row < image->Rows) { - pdf_stream_write_data (pdf_file, stream, raw, image->rowbytes); + pdf_stream_write_data (pdf_file, stream, raw, + image->bitmap->row_words * sizeof (word_type)); row++; ref = raw; - raw += image->rowbytes; + raw += image->bitmap->row_words; } /* $$$ generate and write EOFB code */ /* $$$ flush any remaining buffered bits */ @@ -94,13 +122,9 @@ void pdf_write_g4_fax_image_callback (pdf_file_handle pdf_file, void pdf_write_g4_fax_image (pdf_page_handle pdf_page, - unsigned long Columns, - unsigned long Rows, - unsigned long rowbytes, + Bitmap *bitmap, int ImageMask, - int BlackIs1, /* boolean, typ. false */ - unsigned char *data, - unsigned long len) + int BlackIs1) /* boolean, typ. false */ { struct pdf_g4_image *image; @@ -112,12 +136,10 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, image = pdf_calloc (sizeof (struct pdf_g4_image)); - image->Columns = Columns; - image->Rows = Rows; - image->rowbytes = rowbytes; + image->bitmap = bitmap; + image->Columns = bitmap->rect.max.x - bitmap->rect.min.x; + image->Rows = bitmap->rect.max.y - bitmap->rect.min.y; image->BlackIs1 = BlackIs1; - image->data = data; - image->len = len; stream_dict = pdf_new_obj (PT_DICTIONARY); @@ -133,8 +155,8 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, pdf_set_dict_entry (stream_dict, "Type", pdf_new_name ("XObject")); pdf_set_dict_entry (stream_dict, "Subtype", pdf_new_name ("Image")); pdf_set_dict_entry (stream_dict, "Name", pdf_new_name (& image->XObject_name [0])); - pdf_set_dict_entry (stream_dict, "Width", pdf_new_integer (Columns)); - pdf_set_dict_entry (stream_dict, "Height", pdf_new_integer (Rows)); + pdf_set_dict_entry (stream_dict, "Width", pdf_new_integer (image->Columns)); + pdf_set_dict_entry (stream_dict, "Height", pdf_new_integer (image->Rows)); pdf_set_dict_entry (stream_dict, "BitsPerComponent", pdf_new_integer (1)); if (ImageMask) pdf_set_dict_entry (stream_dict, "ImageMask", pdf_new_bool (ImageMask)); @@ -149,11 +171,11 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, pdf_set_dict_entry (decode_parms, "Columns", - pdf_new_integer (Columns)); + pdf_new_integer (image->Columns)); pdf_set_dict_entry (decode_parms, "Rows", - pdf_new_integer (Rows)); + pdf_new_integer (image->Rows)); if (BlackIs1) pdf_set_dict_entry (decode_parms, diff --git a/pdf.c b/pdf.c index f89c711..4033c82 100644 --- a/pdf.c +++ b/pdf.c @@ -1,7 +1,36 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf.c,v 1.3 2003/02/20 04:44:17 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 "bitblt.h" #include "pdf.h" #include "pdf_util.h" #include "pdf_prim.h" diff --git a/pdf.h b/pdf.h index 42fc2db..68b6611 100644 --- a/pdf.h +++ b/pdf.h @@ -1,3 +1,29 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf.h,v 1.2 2003/02/20 04:44:17 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 + */ + + typedef struct pdf_file *pdf_file_handle; typedef struct pdf_page *pdf_page_handle; @@ -28,13 +54,9 @@ void pdf_close_page (pdf_page_handle pdf_page); Note that rowbytes must be at least (Columns+7)/8, but may be arbitrarily large. */ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, - unsigned long Columns, - unsigned long Rows, - unsigned long rowbytes, + Bitmap *bitmap, int ImageMask, - int BlackIs1, /* boolean, typ. false */ - unsigned char *data, - unsigned long len); + int BlackIs1); /* boolean, typ. false */ void pdf_set_page_number (pdf_page_handle pdf_page, char *page_number); diff --git a/pdf_g4.c b/pdf_g4.c index ea71065..2e7ffde 100644 --- a/pdf_g4.c +++ b/pdf_g4.c @@ -1,7 +1,36 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf_g4.c,v 1.3 2003/02/20 04:44:17 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 "bitblt.h" #include "pdf.h" #include "pdf_util.h" #include "pdf_prim.h" @@ -12,10 +41,8 @@ struct pdf_g4_image { unsigned long Columns; unsigned long Rows; - unsigned long rowbytes; int BlackIs1; - unsigned char *data; - unsigned long len; + Bitmap *bitmap; char XObject_name [4]; }; @@ -69,23 +96,24 @@ void pdf_write_g4_fax_image_callback (pdf_file_handle pdf_file, { struct pdf_g4_image *image = app_data; -#if 1 +#if 0 pdf_stream_write_data (pdf_file, stream, image->data, image->len); #else unsigned long row = 0; - unsigned char *ref; - unsigned char *raw; + word_type *ref; + word_type *raw; ref = NULL; - raw = image->data; + raw = image->bitmap->bits; while (row < image->Rows) { - pdf_stream_write_data (pdf_file, stream, raw, image->rowbytes); + pdf_stream_write_data (pdf_file, stream, raw, + image->bitmap->row_words * sizeof (word_type)); row++; ref = raw; - raw += image->rowbytes; + raw += image->bitmap->row_words; } /* $$$ generate and write EOFB code */ /* $$$ flush any remaining buffered bits */ @@ -94,13 +122,9 @@ void pdf_write_g4_fax_image_callback (pdf_file_handle pdf_file, void pdf_write_g4_fax_image (pdf_page_handle pdf_page, - unsigned long Columns, - unsigned long Rows, - unsigned long rowbytes, + Bitmap *bitmap, int ImageMask, - int BlackIs1, /* boolean, typ. false */ - unsigned char *data, - unsigned long len) + int BlackIs1) /* boolean, typ. false */ { struct pdf_g4_image *image; @@ -112,12 +136,10 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, image = pdf_calloc (sizeof (struct pdf_g4_image)); - image->Columns = Columns; - image->Rows = Rows; - image->rowbytes = rowbytes; + image->bitmap = bitmap; + image->Columns = bitmap->rect.max.x - bitmap->rect.min.x; + image->Rows = bitmap->rect.max.y - bitmap->rect.min.y; image->BlackIs1 = BlackIs1; - image->data = data; - image->len = len; stream_dict = pdf_new_obj (PT_DICTIONARY); @@ -133,8 +155,8 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, pdf_set_dict_entry (stream_dict, "Type", pdf_new_name ("XObject")); pdf_set_dict_entry (stream_dict, "Subtype", pdf_new_name ("Image")); pdf_set_dict_entry (stream_dict, "Name", pdf_new_name (& image->XObject_name [0])); - pdf_set_dict_entry (stream_dict, "Width", pdf_new_integer (Columns)); - pdf_set_dict_entry (stream_dict, "Height", pdf_new_integer (Rows)); + pdf_set_dict_entry (stream_dict, "Width", pdf_new_integer (image->Columns)); + pdf_set_dict_entry (stream_dict, "Height", pdf_new_integer (image->Rows)); pdf_set_dict_entry (stream_dict, "BitsPerComponent", pdf_new_integer (1)); if (ImageMask) pdf_set_dict_entry (stream_dict, "ImageMask", pdf_new_bool (ImageMask)); @@ -149,11 +171,11 @@ void pdf_write_g4_fax_image (pdf_page_handle pdf_page, pdf_set_dict_entry (decode_parms, "Columns", - pdf_new_integer (Columns)); + pdf_new_integer (image->Columns)); pdf_set_dict_entry (decode_parms, "Rows", - pdf_new_integer (Rows)); + pdf_new_integer (image->Rows)); if (BlackIs1) pdf_set_dict_entry (decode_parms, diff --git a/pdf_prim.c b/pdf_prim.c index fb469ca..a068a51 100644 --- a/pdf_prim.c +++ b/pdf_prim.c @@ -1,7 +1,36 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf_prim.c,v 1.3 2003/02/20 04:44:17 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 "bitblt.h" #include "pdf.h" #include "pdf_util.h" #include "pdf_prim.h" @@ -60,7 +89,7 @@ struct pdf_obj unsigned long ref_count; pdf_obj_type type; union { - int bool; + bool boolean; char *name; char *string; unsigned long integer; @@ -170,10 +199,10 @@ struct pdf_obj *pdf_new_obj (pdf_obj_type type) } -struct pdf_obj *pdf_new_bool (int bool) +struct pdf_obj *pdf_new_bool (bool val) { struct pdf_obj *obj = pdf_new_obj (PT_BOOL); - obj->val.bool = bool; + obj->val.boolean = val; return (obj); } @@ -450,7 +479,7 @@ void pdf_write_obj (pdf_file_handle pdf_file, struct pdf_obj *obj) fprintf (pdf_file->f, "null "); break; case PT_BOOL: - if (obj->val.bool) + if (obj->val.boolean) fprintf (pdf_file->f, "true "); else fprintf (pdf_file->f, "false "); diff --git a/pdf_prim.h b/pdf_prim.h index fc86e00..6d40e54 100644 --- a/pdf_prim.h +++ b/pdf_prim.h @@ -1,3 +1,29 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf_prim.h,v 1.2 2003/02/20 04:44:17 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 + */ + + typedef enum { PT_BAD, @@ -36,7 +62,7 @@ void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val); /* Create a new object that will NOT be used indirectly */ struct pdf_obj *pdf_new_obj (pdf_obj_type type); -struct pdf_obj *pdf_new_bool (int bool); +struct pdf_obj *pdf_new_bool (bool val); struct pdf_obj *pdf_new_name (char *name); diff --git a/pdf_private.h b/pdf_private.h index d4467e4..e316771 100644 --- a/pdf_private.h +++ b/pdf_private.h @@ -1,3 +1,29 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf_private.h,v 1.2 2003/02/20 04:44:17 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 + */ + + struct pdf_page { pdf_file_handle pdf_file; diff --git a/pdf_util.c b/pdf_util.c index 7c4b020..47e683c 100644 --- a/pdf_util.c +++ b/pdf_util.c @@ -1,8 +1,37 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf_util.c,v 1.3 2003/02/20 04:44:17 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 "bitblt.h" #include "pdf.h" #include "pdf_util.h" diff --git a/pdf_util.h b/pdf_util.h index 2045cd6..2dcbc5e 100644 --- a/pdf_util.h +++ b/pdf_util.h @@ -1,3 +1,29 @@ +/* + * 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. + * + * PDF routines + * $Id: pdf_util.h,v 1.2 2003/02/20 04:44:17 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 + */ + + void pdf_fatal (char *fmt, ...); void *pdf_calloc (long int size); diff --git a/t2p.c b/t2p.c index d1b2835..afe29eb 100644 --- a/t2p.c +++ b/t2p.c @@ -4,7 +4,7 @@ * will be compressed using ITU-T T.6 (G4) fax encoding. * * Main program - * $Id: t2p.c,v 1.21 2003/01/21 10:39:55 eric Exp $ + * $Id: t2p.c,v 1.22 2003/02/20 04:44:17 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -20,7 +20,8 @@ * * 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 */ + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA + */ #include @@ -28,18 +29,17 @@ #include #include #include +#include #include #include #define TIFF_REVERSE_BITS -#include -#include - #include "bitblt.h" #include "semantics.h" #include "parser.tab.h" #include "t2p.h" +#include "pdf.h" #define MAX_INPUT_FILES 5000 @@ -55,7 +55,7 @@ typedef struct output_file_t { struct output_file_t *next; char *name; - panda_pdf *pdf; + pdf_file_handle pdf; } output_file_t; @@ -66,7 +66,6 @@ char *in_filename; TIFF *in; output_file_t *output_files; output_file_t *out; -/* panda_pdf *out; */ char *progname; @@ -87,6 +86,10 @@ void usage (void) 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\n"); + fprintf (stderr, " %%p page number\n"); } @@ -158,7 +161,7 @@ bool close_pdf_output_files (void) for (o = output_files; o; o = n) { n = o->next; - panda_close (o->pdf); + pdf_close (o->pdf); free (o->name); free (o); } @@ -195,7 +198,7 @@ bool open_pdf_output_file (char *name, return (0); } - o->pdf = panda_open (name, "w"); + o->pdf = pdf_create (name); if (! o->pdf) { fprintf (stderr, "can't open output file '%s'\n", name); @@ -205,15 +208,15 @@ bool open_pdf_output_file (char *name, } if (attributes->author) - panda_setauthor (o->pdf, attributes->author); + pdf_set_author (o->pdf, attributes->author); if (attributes->creator) - panda_setcreator (o->pdf, attributes->creator); + pdf_set_creator (o->pdf, attributes->creator); if (attributes->title) - panda_settitle (o->pdf, attributes->title); + pdf_set_title (o->pdf, attributes->title); if (attributes->subject) - panda_setsubject (o->pdf, attributes->subject); + pdf_set_subject (o->pdf, attributes->subject); if (attributes->keywords) - panda_setkeywords (o->pdf, attributes->keywords); + pdf_set_keywords (o->pdf, attributes->keywords); /* prepend new output file onto list */ o->next = output_files; @@ -304,23 +307,15 @@ bool process_page (int image, /* range 1 .. n */ float x_resolution, y_resolution; float dest_x_resolution, dest_y_resolution; - int width_points, height_points; /* really 1/72 inch units rather than - points */ + double width_points, height_points; /* really 1/72 inch units rather than + points */ Rect rect; Bitmap *bitmap; int row; - panda_page *page; - - int tiff_temp_fd; - char tiff_temp_fn [] = "/var/tmp/t2p-XXXXXX\0"; - TIFF *tiff_temp; - - char pagesize [26]; /* Needs to hold two ints of four characters (0..3420), - two zeros, three spaces, two brackets, and a NULL. - Added an extra ten characters just in case. */ + pdf_page_handle page; if (! TIFFSetDirectory (in, image - 1)) { @@ -406,7 +401,7 @@ bool process_page (int image, /* range 1 .. n */ dest_image_length = image_width; dest_x_resolution = y_resolution; dest_y_resolution = x_resolution; - SWAP (int, width_points, height_points); + SWAP (double, width_points, height_points); /* $$$ not yet set!!! */ } else { @@ -453,80 +448,32 @@ bool process_page (int image, /* range 1 .. n */ rotate_bitmap (bitmap, input_attributes); - tiff_temp_fd = mkstemp (tiff_temp_fn); - if (tiff_temp_fd < 0) - { - fprintf (stderr, "can't create temporary TIFF file\n"); - goto fail; - } - - tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); - if (! out) - { - fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); - goto fail; - } - - TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, rect_height (& bitmap->rect)); - TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, rect_width (& bitmap->rect)); - TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); - - TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, rect_height (& bitmap->rect)); - - TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); - TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); - TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); - - TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); - TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); - TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); - TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); - #ifdef TIFF_REVERSE_BITS reverse_bits ((uint8_t *) bitmap->bits, image_length * bitmap->row_words * sizeof (word_type)); #endif /* TIFF_REVERSE_BITS */ - for (row = 0; row < rect_height (& bitmap->rect); row++) - if (1 != TIFFWriteScanline (tiff_temp, - bitmap->bits + row * bitmap->row_words, - row, - 0)) - { - fprintf (stderr, "can't write TIFF scanline\n"); - goto fail; - } - - TIFFClose (tiff_temp); - width_points = (rect_width (& bitmap->rect) / dest_x_resolution) * POINTS_PER_INCH; height_points = (rect_height (& bitmap->rect) / dest_y_resolution) * POINTS_PER_INCH; - free_bitmap (bitmap); - 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; } - sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); + page = pdf_new_page (out->pdf, width_points, height_points); - page = panda_newpage (out->pdf, pagesize); - panda_imagebox (out->pdf, - page, - 0, /* top */ - 0, /* left */ - height_points, /* bottom */ - width_points, /* right */ - tiff_temp_fn, - panda_image_tiff); + pdf_write_g4_fax_image (page, + bitmap, + 0, /* ImageMask */ + 0); /* BlackIs1 */ + + free_bitmap (bitmap); result = 1; fail: - if (tiff_temp_fd) - unlink (tiff_temp_fn); return (result); } @@ -548,6 +495,7 @@ void main_args (char *out_fn, int inf_count, char **in_fn) 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 (! process_page (ip, input_attributes, NULL)) fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]); if (last_tiff_page ()) @@ -576,12 +524,13 @@ 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]; - panda_init (); + pdf_init (); while (--argc) { @@ -611,6 +560,17 @@ int main (int argc, char *argv[]) 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]); } diff --git a/tumble.c b/tumble.c index 228f043..8c8e820 100644 --- a/tumble.c +++ b/tumble.c @@ -4,7 +4,7 @@ * will be compressed using ITU-T T.6 (G4) fax encoding. * * Main program - * $Id: tumble.c,v 1.21 2003/01/21 10:39:55 eric Exp $ + * $Id: tumble.c,v 1.22 2003/02/20 04:44:17 eric Exp $ * Copyright 2001, 2002, 2003 Eric Smith * * This program is free software; you can redistribute it and/or modify @@ -20,7 +20,8 @@ * * 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 */ + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA + */ #include @@ -28,18 +29,17 @@ #include #include #include +#include #include #include #define TIFF_REVERSE_BITS -#include -#include - #include "bitblt.h" #include "semantics.h" #include "parser.tab.h" #include "t2p.h" +#include "pdf.h" #define MAX_INPUT_FILES 5000 @@ -55,7 +55,7 @@ typedef struct output_file_t { struct output_file_t *next; char *name; - panda_pdf *pdf; + pdf_file_handle pdf; } output_file_t; @@ -66,7 +66,6 @@ char *in_filename; TIFF *in; output_file_t *output_files; output_file_t *out; -/* panda_pdf *out; */ char *progname; @@ -87,6 +86,10 @@ void usage (void) 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\n"); + fprintf (stderr, " %%p page number\n"); } @@ -158,7 +161,7 @@ bool close_pdf_output_files (void) for (o = output_files; o; o = n) { n = o->next; - panda_close (o->pdf); + pdf_close (o->pdf); free (o->name); free (o); } @@ -195,7 +198,7 @@ bool open_pdf_output_file (char *name, return (0); } - o->pdf = panda_open (name, "w"); + o->pdf = pdf_create (name); if (! o->pdf) { fprintf (stderr, "can't open output file '%s'\n", name); @@ -205,15 +208,15 @@ bool open_pdf_output_file (char *name, } if (attributes->author) - panda_setauthor (o->pdf, attributes->author); + pdf_set_author (o->pdf, attributes->author); if (attributes->creator) - panda_setcreator (o->pdf, attributes->creator); + pdf_set_creator (o->pdf, attributes->creator); if (attributes->title) - panda_settitle (o->pdf, attributes->title); + pdf_set_title (o->pdf, attributes->title); if (attributes->subject) - panda_setsubject (o->pdf, attributes->subject); + pdf_set_subject (o->pdf, attributes->subject); if (attributes->keywords) - panda_setkeywords (o->pdf, attributes->keywords); + pdf_set_keywords (o->pdf, attributes->keywords); /* prepend new output file onto list */ o->next = output_files; @@ -304,23 +307,15 @@ bool process_page (int image, /* range 1 .. n */ float x_resolution, y_resolution; float dest_x_resolution, dest_y_resolution; - int width_points, height_points; /* really 1/72 inch units rather than - points */ + double width_points, height_points; /* really 1/72 inch units rather than + points */ Rect rect; Bitmap *bitmap; int row; - panda_page *page; - - int tiff_temp_fd; - char tiff_temp_fn [] = "/var/tmp/t2p-XXXXXX\0"; - TIFF *tiff_temp; - - char pagesize [26]; /* Needs to hold two ints of four characters (0..3420), - two zeros, three spaces, two brackets, and a NULL. - Added an extra ten characters just in case. */ + pdf_page_handle page; if (! TIFFSetDirectory (in, image - 1)) { @@ -406,7 +401,7 @@ bool process_page (int image, /* range 1 .. n */ dest_image_length = image_width; dest_x_resolution = y_resolution; dest_y_resolution = x_resolution; - SWAP (int, width_points, height_points); + SWAP (double, width_points, height_points); /* $$$ not yet set!!! */ } else { @@ -453,80 +448,32 @@ bool process_page (int image, /* range 1 .. n */ rotate_bitmap (bitmap, input_attributes); - tiff_temp_fd = mkstemp (tiff_temp_fn); - if (tiff_temp_fd < 0) - { - fprintf (stderr, "can't create temporary TIFF file\n"); - goto fail; - } - - tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); - if (! out) - { - fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); - goto fail; - } - - TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, rect_height (& bitmap->rect)); - TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, rect_width (& bitmap->rect)); - TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); - - TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, rect_height (& bitmap->rect)); - - TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); - TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); - TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); - - TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); - TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); - TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); - TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); - #ifdef TIFF_REVERSE_BITS reverse_bits ((uint8_t *) bitmap->bits, image_length * bitmap->row_words * sizeof (word_type)); #endif /* TIFF_REVERSE_BITS */ - for (row = 0; row < rect_height (& bitmap->rect); row++) - if (1 != TIFFWriteScanline (tiff_temp, - bitmap->bits + row * bitmap->row_words, - row, - 0)) - { - fprintf (stderr, "can't write TIFF scanline\n"); - goto fail; - } - - TIFFClose (tiff_temp); - width_points = (rect_width (& bitmap->rect) / dest_x_resolution) * POINTS_PER_INCH; height_points = (rect_height (& bitmap->rect) / dest_y_resolution) * POINTS_PER_INCH; - free_bitmap (bitmap); - 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; } - sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); + page = pdf_new_page (out->pdf, width_points, height_points); - page = panda_newpage (out->pdf, pagesize); - panda_imagebox (out->pdf, - page, - 0, /* top */ - 0, /* left */ - height_points, /* bottom */ - width_points, /* right */ - tiff_temp_fn, - panda_image_tiff); + pdf_write_g4_fax_image (page, + bitmap, + 0, /* ImageMask */ + 0); /* BlackIs1 */ + + free_bitmap (bitmap); result = 1; fail: - if (tiff_temp_fd) - unlink (tiff_temp_fn); return (result); } @@ -548,6 +495,7 @@ void main_args (char *out_fn, int inf_count, char **in_fn) 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 (! process_page (ip, input_attributes, NULL)) fatal (3, "error processing page %d of input file \"%s\"\n", ip, in_fn [i]); if (last_tiff_page ()) @@ -576,12 +524,13 @@ 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]; - panda_init (); + pdf_init (); while (--argc) { @@ -611,6 +560,17 @@ int main (int argc, char *argv[]) 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]); }