pdf_prim.h

Mon, 14 Dec 2009 15:51:53 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Mon, 14 Dec 2009 15:51:53 +0000
changeset 166
301f6f17c364
parent 125
e2ef1c2f9eca
permissions
-rw-r--r--

Patched to add PNG and JP2 support.

Created-By: Daniel Gl?ckner <daniel-gl at gmx.net>


The attached patch adds PNG and JP2 support to tumble.

PNG:
As the deflated data is directly copied into the PDF, there are some
limitations to the list of supported images:
- bit depth <= 8
- no alpha channel
- no interlace

JP2:
The PDF Reference says JP2 is just a subset of the allowed JPX
format. I don't have a copy of the official standard, so I don't know
what to change to cover JPXes as well.
You'll need the Adobe Acrobat Reader 6 to display those images.
Xpdf and Ghostscript are missing the ColorSpace key in the image
dictionary, which is optional for JPXDecode and IMHO not just a matter
of a few lines of code.
One thing left to do is to change the PDF version to 1.5 if a JP2 file
has been given to tumble - maybe using the Version key in the Catalog
if seeking is not possible.
Using the resolution info in a JP2 (resc/resd boxes) is implemented but
untested. Jasper doesn't write those boxes.

I had to change the string handling to allow black in PNG palettes.
And there was a double free in tumble_input.c which happens when not
using control files.

Daniel

     1 /*
     2  * tumble: build a PDF file from image files
     3  *
     4  * PDF routines
     5  * $Id: pdf_prim.h,v 1.10 2003/03/13 00:57:05 eric Exp $
     6  * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
     7  *
     8  * This program is free software; you can redistribute it and/or modify
     9  * it under the terms of the GNU General Public License version 2 as
    10  * published by the Free Software Foundation.  Note that permission is
    11  * not granted to redistribute this program under the terms of any
    12  * other version of the General Public License.
    13  *
    14  * This program is distributed in the hope that it will be useful,
    15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    17  * GNU General Public License for more details.
    18  *
    19  * You should have received a copy of the GNU General Public License
    20  * along with this program; if not, write to the Free Software
    21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
    22  */
    25 typedef enum
    26 {
    27   PT_BAD,
    29   /* scalar */
    30   PT_NULL,
    31   PT_BOOL,
    32   PT_NAME,
    33   PT_STRING,
    34   PT_INTEGER,
    35   PT_REAL,
    36   PT_IND_REF,
    38   /* composite */
    39   PT_DICTIONARY,
    40   PT_ARRAY,
    41   PT_STREAM
    42 } pdf_obj_type;
    45 struct pdf_obj;
    48 typedef void (*pdf_stream_write_callback)(pdf_file_handle pdf_file,
    49 					  struct pdf_obj *stream,
    50 					  void *app_data);
    53 /* returns -1 if o1 < 02, 0 if o1 == o2, 1 if o1 > o2 */
    54 /* only works for integer, real, string, and name objects */
    55 int pdf_compare_obj (struct pdf_obj *o1, struct pdf_obj *o2);
    58 void pdf_set_dict_entry (struct pdf_obj *dict_obj, char *key, struct pdf_obj *val);
    59 struct pdf_obj *pdf_get_dict_entry (struct pdf_obj *dict_obj, char *key);
    62 void pdf_add_array_elem (struct pdf_obj *array_obj, struct pdf_obj *val);
    65 /* Following is intended for things like ProcSet in which an array object
    66    is used to represent a set.  Only works if all objects in array, and
    67    the element to be added are of scalar types (types that are supported
    68    by pdf_compare_obj.  Not efficient for large arrays as it does a
    69    comaprison to every element. */
    70 void pdf_add_array_elem_unique (struct pdf_obj *array_obj, struct pdf_obj *val);
    73 /* Create a new object that will NOT be used indirectly */
    74 struct pdf_obj *pdf_new_obj (pdf_obj_type type);
    76 struct pdf_obj *pdf_new_bool (bool val);
    78 struct pdf_obj *pdf_new_name (char *name);
    80 struct pdf_obj *pdf_new_string (char *str);
    82 struct pdf_obj *pdf_new_string_n (char *str, int n);
    84 struct pdf_obj *pdf_new_integer (long val);
    86 struct pdf_obj *pdf_new_real (double val);
    89 /* Create a new indirect object */
    90 struct pdf_obj *pdf_new_ind_ref (pdf_file_handle pdf_file, struct pdf_obj *obj);
    92 /* get the object referenced by an indirect reference */
    93 struct pdf_obj *pdf_deref_ind_obj (struct pdf_obj *ind_obj);
    96 long pdf_get_integer (struct pdf_obj *obj);
    97 void pdf_set_integer (struct pdf_obj *obj, long val);
   100 double pdf_get_real (struct pdf_obj *obj);
   101 void pdf_set_real (struct pdf_obj *obj, double val);
   104 /* The callback will be called when the stream data is to be written to the
   105    file.  app_data will be passed as an argument to the callback. */
   106 struct pdf_obj *pdf_new_stream (pdf_file_handle pdf_file,
   107 				struct pdf_obj *stream_dict,
   108 				pdf_stream_write_callback callback,
   109 				void *app_data);
   111 /* The callback should call pdf_stream_write_data() or pdf_stream_printf()
   112    to write the actual stream data. */
   114 void pdf_stream_flush_bits (pdf_file_handle pdf_file,
   115 			    struct pdf_obj *stream);
   117 void pdf_stream_write_data (pdf_file_handle pdf_file,
   118 			    struct pdf_obj *stream,
   119 			    char *data,
   120 			    unsigned long len);
   122 void pdf_stream_printf (pdf_file_handle pdf_file,
   123 			struct pdf_obj *stream,
   124 			char *fmt, ...);
   127 void pdf_stream_add_filter (struct pdf_obj *stream,
   128 			    char *filter_name,
   129 			    struct pdf_obj *decode_parms);
   132 /* Write the object to the file */
   133 void pdf_write_obj (pdf_file_handle pdf_file, struct pdf_obj *obj);
   136 /* Write the indirect object to the file.  For most objects this should
   137    be done by pdf_write_all_ind_obj() when the file is being closed, but for
   138    large objects such as streams, it's probably better to do it as soon as the
   139    object is complete. */
   140 void pdf_write_ind_obj (pdf_file_handle pdf_file, struct pdf_obj *ind_obj);
   143 /* Write all indirect objects that haven't already been written to the file. */
   144 void pdf_write_all_ind_obj (pdf_file_handle pdf_file);
   147 /* Write the cross reference table, and return the maximum object number */
   148 unsigned long pdf_write_xref (pdf_file_handle pdf_file);
   151 /* this isn't really a PDF primitive data type */
   152 char pdf_new_XObject (pdf_page_handle pdf_page, struct pdf_obj *ind_ref);