1/*---------------------------------------------------------------------------*
2 |              PDFlib - A library for generating PDF on the fly             |
3 +---------------------------------------------------------------------------+
4 | Copyright (c) 1997-2004 Thomas Merz and PDFlib GmbH. All rights reserved. |
5 +---------------------------------------------------------------------------+
6 |                                                                           |
7 |    This software is subject to the PDFlib license. It is NOT in the       |
8 |    public domain. Extended versions and commercial licenses are           |
9 |    available, please check http://www.pdflib.com.                         |
10 |                                                                           |
11 *---------------------------------------------------------------------------*/
12
13/* $Id: p_image.h 14574 2005-10-29 16:27:43Z bonefish $
14 *
15 * Header file for the PDFlib image subsystem
16 *
17 */
18
19#ifndef P_IMAGE_H
20#define P_IMAGE_H
21
22#ifdef HAVE_LIBTIFF
23#include "tiffio.h"
24#endif
25
26#ifdef HAVE_LIBPNG
27#include "png.h"
28#endif
29
30/* Type of image reference */
31typedef enum
32{
33    pdf_img_auto,
34    pdf_img_bmp,
35    pdf_img_ccitt,
36    pdf_img_gif,
37    pdf_img_jpeg,
38    pdf_img_png,
39    pdf_img_raw,
40    pdf_img_tiff
41}
42pdf_image_type;
43
44#ifdef P_IMAGE_C
45const pdc_keyconn pdf_image_keylist[] =
46{
47    {"AUTO",  pdf_img_auto},
48    {"BMP",   pdf_img_bmp},
49    {"CCITT", pdf_img_ccitt},
50    {"GIF",   pdf_img_gif},
51    {"JPEG",  pdf_img_jpeg},
52    {"PNG",   pdf_img_png},
53    {"RAW",   pdf_img_raw},
54    {"TIFF",  pdf_img_tiff},
55    {NULL, 0}
56};
57#endif /* P_IMAGE_C */
58
59/* BMP specific image information */
60typedef struct pdf_bmp_info_t {
61    pdc_ulong           compression;    /* BMP compression */
62    size_t              rowbytes;       /* length of row data */
63    size_t              rowbytes_pad;   /* padded length of row data */
64    size_t              rowbytes_pdf;   /* length of row data for PDF */
65    size_t              skiprows;       /* number of rows to be skipped */
66    pdc_byte           *bitmap;         /* bitmap buffer */
67    pdc_byte           *end;            /* first byte above bitmap buffer */
68    pdc_byte           *pos;            /* current position in bitmap buffer */
69} pdf_bmp_info;
70
71/* JPEG specific image information */
72typedef struct pdf_jpeg_info_t {
73    long                startpos;       /* start of image data in file */
74} pdf_jpeg_info;
75
76/* GIF specific image information */
77typedef struct pdf_gif_info_t {
78    int			c_size;		/* current code size (9..12)	*/
79    int			t_size;		/* current table size (257...)	*/
80    int			i_buff;		/* input buffer			*/
81    int			i_bits;		/* # of bits in i_buff		*/
82    int			o_buff;		/* output buffer		*/
83    int			o_bits;		/* # of bits in o_buff		*/
84} pdf_gif_info;
85
86
87/* PNG specific image information */
88typedef struct pdf_png_info_t {
89    size_t		nbytes;		/* number of bytes left		*/
90    					/* in current IDAT chunk	*/
91#ifdef HAVE_LIBPNG
92    png_structp		png_ptr;
93    png_infop		info_ptr;
94    png_uint_32		rowbytes;
95    pdc_byte		*raster;
96    int			cur_line;
97#endif	/* HAVE_LIBPNG */
98} pdf_png_info;
99
100
101/* TIFF specific image information */
102typedef struct pdf_tiff_info_t {
103#ifdef HAVE_LIBTIFF
104    TIFF		*tif;		/* pointer to TIFF data structure */
105    uint32		*raster;	/* frame buffer */
106#endif	/* HAVE_LIBTIFF */
107
108    int			cur_line;	/* current image row or strip */
109} pdf_tiff_info;
110
111/* CCITT specific image information */
112typedef struct pdf_ccitt_info_t {
113    int			BitReverse;	/* reverse all bits prior to use */
114} pdf_ccitt_info;
115
116/* Type of image reference */
117typedef enum {pdf_ref_direct, pdf_ref_file, pdf_ref_url} pdf_ref_type;
118
119/* must be kept in sync with pdf_filter_names[] in p_image.c */
120typedef enum { none, lzw, runlength, ccitt, dct, flate, jbig2 } pdf_compression;
121
122typedef enum { pred_default = 1, pred_tiff = 2, pred_png = 15 } pdf_predictor;
123
124/* The image descriptor */
125struct pdf_image_s {
126    pdc_file 		*fp;		/* image file pointer */
127    char		*filename;	/* image file name or url */
128    /* width and height in pixels, or in points for PDF pages and templates */
129    float		width;		/* image width */
130    float		height;		/* image height */
131    pdf_compression	compression;	/* image compression type */
132    int	                colorspace;	/* image color space */
133
134    /*************************** option variables *****************************/
135    pdc_bool            verbose;        /* put out warning/error messages */
136    pdc_bool            bitreverse;     /* bitwise reversal of all bytes */
137    int                 bpc;            /* bits per color component */
138    int                 components;     /* number of color components */
139    int                 height_pixel;   /* image height in pixel */
140    pdc_bool            ignoremask;     /* ignore any transparency information*/
141    pdc_bool            doinline;       /* inline image */
142    pdc_bool            interpolate;    /* interpolate image   */
143    pdc_bool		invert;		/* reverse black and white */
144    int                 K;              /* encoding type of CCITT */
145    pdc_bool            imagemask;     	/* create a mask from a 1-bit image */
146    int                 mask;           /* image number of image mask */
147    pdf_renderingintent ri;             /* rendering intent of image */
148    int                 page;           /* page number of TIFF image */
149    pdf_ref_type        reference;      /* kind of image data reference */
150    int                 width_pixel;    /* image width in pixel */
151    /**************************************************************************/
152
153    pdc_bool		transparent;	/* image is transparent */
154    pdc_byte		transval[4];	/* transparent color values */
155    pdf_predictor	predictor;	/* predictor for lzw and flate */
156
157    float		dpi_x;		/* horiz. resolution in dots per inch */
158    float		dpi_y;		/* vert. resolution in dots per inch */
159    					/* dpi is 0 if unknown */
160
161    pdc_bool		in_use;		/* image slot currently in use */
162
163    char		*params;	/* for TIFF */
164    int			strips;		/* number of strips in image */
165    int			rowsperstrip;	/* number of rows per strip */
166    int                 pagehandle;     /* PDI page handle */
167    int			dochandle;	/* PDI document handle */
168    pdc_usebox		usebox;
169    pdc_bool		use_raw;	/* use raw (compressed) image data */
170
171    /* image format specific information */
172    union {
173        pdf_bmp_info    bmp;
174	pdf_jpeg_info	jpeg;
175	pdf_gif_info	gif;
176	pdf_png_info	png;
177	pdf_tiff_info	tiff;
178	pdf_ccitt_info	ccitt;
179    } info;
180
181    int			no;		/* PDF image number */
182    PDF_data_source	src;
183};
184
185/* xobject types */
186typedef enum {
187    image_xobject = 1 << 0,
188    form_xobject = 1 << 1,
189    pdi_xobject = 1 << 2
190} pdf_xobj_type;
191
192typedef enum {
193    xobj_flag_used = 1 << 0,		/* in use */
194    xobj_flag_write = 1 << 1		/* write at end of page */
195} pdf_xobj_flags;
196
197/* A PDF xobject */
198struct pdf_xobject_s {
199    pdc_id		obj_id;		/* object id of this xobject */
200    int			flags;		/* bit mask of pdf_xobj_flags */
201    pdf_xobj_type	type;		/* type of this xobject */
202};
203
204/* p_bmp.c */
205int      pdf_process_BMP_data(PDF *p, int imageslot);
206pdc_bool pdf_is_BMP_file(PDF *p, pdc_file *fp);
207
208/* p_ccitt.c */
209int      pdf_process_CCITT_data(PDF *p, int imageslot);
210int      pdf_process_RAW_data(PDF *p, int imageslot);
211
212/* p_gif.c */
213int      pdf_process_GIF_data(PDF *p, int imageslot);
214pdc_bool pdf_is_GIF_file(PDF *p, pdc_file *fp);
215
216/* p_jpeg.c */
217int      pdf_process_JPEG_data(PDF *p, int imageslot);
218pdc_bool pdf_is_JPEG_file(PDF *p, pdc_file *fp, pdf_jpeg_info *jpeg);
219
220/* p_png.c */
221int	 pdf_process_PNG_data(PDF *p, int imageslot);
222pdc_bool pdf_is_PNG_file(PDF *p, pdc_file *fp);
223
224/* p_tiff.c */
225int      pdf_process_TIFF_data(PDF *p, int imageslot);
226pdc_bool pdf_is_TIFF_file(PDF *p, pdc_file *fp, pdf_tiff_info *tiff,
227                          pdc_bool check);
228
229
230/* p_image.c */
231int	pdf_new_xobject(PDF *p, pdf_xobj_type type, pdc_id obj_id);
232void	pdf_grow_images(PDF *p);
233void	pdf_put_image(PDF *p, int im, pdc_bool firststrip);
234void    pdf_put_inline_image(PDF *p, int im);
235
236void	pdf_init_images(PDF *p);
237void	pdf_cleanup_images(PDF *p);
238void	pdf_cleanup_image(PDF *p, int im);
239void	pdf_init_xobjects(PDF *p);
240void	pdf_write_xobjects(PDF *p);
241void	pdf_cleanup_xobjects(PDF *p);
242void    pdf_place_xobject(PDF *p, int im, float x, float y,
243			const char *optlist);
244void	pdf__fit_image(PDF *p, int im, float x, float y, const char *optlist);
245int	pdf__load_image(PDF *p, const char *type, const char *filename,
246			const char *optlist);
247
248
249#endif /* P_IMAGE_H */
250