1 /*
2 Copyright 1996-2014 Han The Thanh, <thanh@pdftex.org>
3 
4 This file is part of pdfTeX.
5 
6 pdfTeX is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 pdfTeX is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License along
17 with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include <png.h>
21 
22 /* JPG_IMAGE_INFO is main structure for interchange of image data */
23 
24 #define JPG_UINT16      unsigned int
25 #define JPG_UINT32      unsigned long
26 #define JPG_UINT8       unsigned char
27 
28 typedef struct {
29     int color_space;            /* used color space. See JPG_ constants */
30     JPG_UINT8 bits_per_component;       /* bits per component                         */
31     JPG_UINT32 length;          /* length of file/data                        */
32     FILE *file;                 /* jpg file                                   */
33 } JPG_IMAGE_INFO;
34 
35 typedef struct {
36     png_structp png_ptr;
37     png_infop info_ptr;
38 } png_image_struct;
39 
40 typedef struct {
41     integer orig_x;
42     integer orig_y;
43     integer selected_page;
44     integer page_box;
45     void *doc;
46 } pdf_image_struct;
47 
48 typedef struct {
49     integer selected_page;
50     FILE *file;
51 } JBIG2_IMAGE_INFO;
52 
53 typedef struct {
54     char *image_name;
55     int image_type;
56     int color_type;
57     integer width;
58     integer height;
59     integer rotate;
60     integer x_res;
61     integer y_res;
62     integer num_pages;
63     integer colorspace_ref;
64     integer group_ref;          // if it's <=0, the page has no group
65     union {
66         pdf_image_struct *pdf;
67         png_image_struct png;
68         JPG_IMAGE_INFO *jpg;
69         JBIG2_IMAGE_INFO *jbig2;
70     } image_struct;
71 } image_entry;
72 
73 extern image_entry *image_ptr, *image_array;
74 extern integer image_max;
75 
76 #define IMAGE_TYPE_NONE 0
77 #define IMAGE_TYPE_PDF  1
78 #define IMAGE_TYPE_PNG  2
79 #define IMAGE_TYPE_JPG  3
80 #define IMAGE_TYPE_TIF  4
81 #define IMAGE_TYPE_JBIG2 5
82 
83 #define IMAGE_COLOR_B   1
84 #define IMAGE_COLOR_C   2
85 #define IMAGE_COLOR_I   4
86 
87 #define img_ptr(N)      (image_array + (N))
88 #define img_name(N)     (img_ptr(N)->image_name)
89 #define img_type(N)     (img_ptr(N)->image_type)
90 #define img_color(N)    (img_ptr(N)->color_type)
91 #define img_colorspace_ref(N) (img_ptr(N)->colorspace_ref)
92 #define img_group_ref(N) (img_ptr(N)->group_ref)
93 #define img_pages(N)    (img_ptr(N)->num_pages)
94 #define img_width(N)    (img_ptr(N)->width)
95 #define img_height(N)   (img_ptr(N)->height)
96 #define img_rotate(N)   (img_ptr(N)->rotate)
97 #define img_xres(N)     (img_ptr(N)->x_res)
98 #define img_yres(N)     (img_ptr(N)->y_res)
99 #define png_ptr(N)      (img_ptr(N)->image_struct.png.png_ptr)
100 #define png_info(N)     (img_ptr(N)->image_struct.png.info_ptr)
101 #define pdf_ptr(N)      (img_ptr(N)->image_struct.pdf)
102 #define jpg_ptr(N)      (img_ptr(N)->image_struct.jpg)
103 #define jbig2_ptr(N)    (img_ptr(N)->image_struct.jbig2)
104 #define tif_ptr(N)      (img_ptr(N)->image_struct.tif)
105 
106 extern void read_png_info(integer);
107 extern void write_png(integer);
108 extern void read_jpg_info(integer);
109 extern void write_jpg(integer);
110 extern void read_jbig2_info(integer);
111 extern void write_jbig2(integer);
112