tumble_input.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 157
160d624271cc
child 168
ad0b9a8990ac
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  * $Id: tumble_input.h,v 1.3 2003/04/10 00:47:30 eric Exp $
     5  * Copyright 2003 Eric Smith <eric@brouhaha.com>
     6  *
     7  * This program is free software; you can redistribute it and/or modify
     8  * it under the terms of the GNU General Public License version 2 as
     9  * published by the Free Software Foundation.  Note that permission is
    10  * not granted to redistribute this program under the terms of any
    11  * other version of the General Public License.
    12  *
    13  * This program is distributed in the hope that it will be useful,
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  * GNU General Public License for more details.
    17  *
    18  * You should have received a copy of the GNU General Public License
    19  * along with this program; if not, write to the Free Software
    20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
    21  */
    24 typedef struct
    25 {
    26   bool color;
    27   uint32_t width_samples, height_samples;
    28   double width_points, height_points;
    29   double x_resolution, y_resolution;
    30 } image_info_t;
    33 typedef struct
    34 {
    35   bool (*match_suffix) (char *suffix);
    36   bool (*open_input_file) (FILE *f, char *name);
    37   bool (*close_input_file) (void);
    38   bool (*last_input_page) (void);
    39   bool (*get_image_info) (int image,
    40 			 input_attributes_t input_attributes,
    41 			 image_info_t *image_info);
    42   bool (*process_image) (int image,
    43 			 input_attributes_t input_attributes,
    44 			 image_info_t *image_info,
    45 			 pdf_page_handle page);
    46 } input_handler_t;
    49 void install_input_handler (input_handler_t *handler);
    52 bool match_input_suffix (char *suffix);
    53 bool open_input_file (char *name);
    54 bool close_input_file (void);
    55 bool last_input_page (void);
    56 bool get_image_info (int image,
    57 		     input_attributes_t input_attributes,
    58 		     image_info_t *image_info);
    59 bool process_image (int image,
    60 		    input_attributes_t input_attributes,
    61 		    image_info_t *image_info,
    62 		    pdf_page_handle page);
    65 void init_tiff_handler (void);
    66 void init_jpeg_handler (void);
    67 void init_pbm_handler  (void);
    68 void init_png_handler  (void);
    69 void init_jp2_handler  (void);