beta-0.89.2
[luatex.git] / source / texk / web2c / luatexdir / image / image.h
blob49996947e26adc86b162410540fe72189c410f75
1 /* image.h
3 Copyright 1996-2006 Han The Thanh <thanh@pdftex.org>
4 Copyright 2006-2010 Taco Hoekwater <taco@luatex.org>
6 This file is part of LuaTeX.
8 LuaTeX is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 2 of the License, or (at your
11 option) any later version.
13 LuaTeX is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16 License for more details.
18 You should have received a copy of the GNU General Public License along
19 with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
21 #ifndef IMAGE_H
22 # define IMAGE_H
24 # include <png.h>
25 # include "pdf/pdftypes.h" /* for scaled_whd */
27 # define JPG_UINT16 unsigned int
28 # define JPG_UINT32 unsigned long
29 # define JPG_UINT8 unsigned char
31 extern int do_zround(double r); /* from utils.w */
32 extern scaled one_hundred_bp; /* from pdfgen.w */
34 # define bp2sp(p) do_zround(p * (one_hundred_bp / 100.0))
35 # define sp2bp(i) (i * 100.0 / one_hundred_bp)
37 # define TYPE_IMG "image.meta"
38 # define TYPE_IMG_DICT "image.dict"
40 typedef struct {
41 char *stream;
42 } pdf_stream_struct;
44 typedef struct {
45 png_structp png_ptr;
46 png_infop info_ptr;
47 } png_img_struct;
49 typedef struct {
50 int color_space; /* used color space. See JPG_ constants */
51 JPG_UINT32 length; /* length of file/data */
52 } jpg_img_struct;
54 typedef struct {
55 int length; /* length of file/data */
56 } jp2_img_struct;
58 # if 0
59 typedef struct { /* currently unused */
60 } jb2_img_struct;
61 # endif
63 typedef enum {
64 DICT_NEW, /* fresh dictionary */
65 DICT_FILESCANNED, /* image file scanned */
66 DICT_REFERED, /* pdf_refximage_node in node list --> read-only dict */
67 DICT_OUTIMG, /* /Im* appears in pagestream */
68 DICT_SCHEDULED, /* image dict scheduled for writing (PONR) */
69 DICT_WRITTEN /* image dict written to file */
70 } dict_state;
72 typedef enum {
73 IMG_TYPE_NONE,
74 IMG_TYPE_PDF,
75 IMG_TYPE_PNG,
76 IMG_TYPE_JPG,
77 IMG_TYPE_JP2,
78 IMG_TYPE_JBIG2,
79 IMG_TYPE_PDFSTREAM,
80 IMG_TYPE_PDFMEMSTREAM,
81 IMG_TYPE_SENTINEL
82 } imgtype_e;
84 typedef enum { IMG_KEEPOPEN, IMG_CLOSEINBETWEEN } img_readtype_e;
86 typedef enum {
87 PDF_BOX_SPEC_NONE,
88 PDF_BOX_SPEC_MEDIA,
89 PDF_BOX_SPEC_CROP,
90 PDF_BOX_SPEC_BLEED,
91 PDF_BOX_SPEC_TRIM,
92 PDF_BOX_SPEC_ART,
93 PDF_BOX_SPEC_SENTINEL
94 } pdfboxspec_e;
96 typedef struct {
97 int objnum;
98 int index; /* /Im1, /Im2, ... */
99 scaled_whd dimen; /* TeX dimensions given to \pdfximage */
100 int transform; /* transform given to \pdfximage */
101 int x_size; /* dimensions in pixel counts as in JPG/PNG/JBIG2 file */
102 int y_size;
103 int x_orig; /* origin in sp for PDF files */
104 int y_orig;
105 int x_res; /* pixel resolution as in JPG/PNG/JBIG2 file */
106 int y_res;
107 int rotation; /* rotation (multiples of 90 deg.) for PDF files */
108 int colorspace; /* number of /ColorSpace object */
109 int group_ref; /* if it's <=0, the page has no group */
110 int total_pages;
111 int page_num; /* requested page (by number) */
112 char *pagename; /* requested page (by name) */
113 char *filename; /* requested raw file name */
114 char *visiblefilename; /* blocks or overwrites filename as it appears in PDF output */
115 char *filepath; /* full file path after kpathsea */
116 char *attr; /* additional image dict entries */
117 FILE *file;
118 imgtype_e image_type;
119 int procset; /* /ProcSet flags */
120 int color_depth; /* color depth */
121 pdfboxspec_e page_box_spec; /* PDF page box spec.: media/crop/bleed/trim/art */
122 int bbox[4];
123 dict_state state;
124 int flags;
125 int luaref ;
126 boolean keepopen;
127 int errorlevel;
128 int pdfminorversion;
129 union {
130 pdf_stream_struct *pdfstream;
131 png_img_struct *png;
132 jpg_img_struct *jpg;
133 jp2_img_struct *jp2;
134 /* jb2_img_struct *jb2; */
135 } img_struct;
136 } image_dict;
138 # define img_objnum(N) ((N)->objnum)
139 # define img_index(N) ((N)->index)
140 # define img_dimen(N) ((N)->dimen)
141 # define img_width(N) ((N)->dimen.wd)
142 # define img_height(N) ((N)->dimen.ht)
143 # define img_depth(N) ((N)->dimen.dp)
144 # define img_transform(N) ((N)->transform)
145 # define img_xsize(N) ((N)->x_size)
146 # define img_ysize(N) ((N)->y_size)
147 # define img_xorig(N) ((N)->x_orig)
148 # define img_yorig(N) ((N)->y_orig)
149 # define img_xres(N) ((N)->x_res)
150 # define img_yres(N) ((N)->y_res)
151 # define img_rotation(N) ((N)->rotation)
152 # define img_colorspace(N) ((N)->colorspace)
153 # define img_group_ref(N) ((N)->group_ref)
154 # define img_totalpages(N) ((N)->total_pages)
155 # define img_pagenum(N) ((N)->page_num)
156 # define img_pagename(N) ((N)->pagename)
157 # define img_filename(N) ((N)->filename)
158 # define img_visiblefilename(N) ((N)->visiblefilename)
159 # define img_filepath(N) ((N)->filepath)
160 # define img_attr(N) ((N)->attr)
161 # define img_file(N) ((N)->file)
162 # define img_type(N) ((N)->image_type)
163 # define img_procset(N) ((N)->procset)
164 # define img_colordepth(N) ((N)->color_depth)
165 # define img_pagebox(N) ((N)->page_box_spec)
166 # define img_bbox(N) ((N)->bbox)
167 # define img_state(N) ((N)->state)
168 # define img_flags(N) ((N)->flags)
169 # define img_luaref(N) ((N)->luaref)
170 # define img_keepopen(N) ((N)->keepopen)
171 # define img_errorlevel(N) ((N)->errorlevel)
172 # define img_pdfminorversion(N) ((N)->pdfminorversion)
174 # define img_pdfstream_ptr(N) ((N)->img_struct.pdfstream)
175 # define img_pdfstream_stream(N) ((N)->img_struct.pdfstream->stream)
177 # define img_png_ptr(N) ((N)->img_struct.png)
178 # define img_png_png_ptr(N) ((N)->img_struct.png->png_ptr)
179 # define img_png_info_ptr(N) ((N)->img_struct.png->info_ptr)
181 # define img_jpg_ptr(N) ((N)->img_struct.jpg)
182 # define img_jpg_color(N) ((N)->img_struct.jpg->color_space)
184 # define img_jp2_ptr(N) ((N)->img_struct.jp2)
186 # define img_jb2_ptr(N) ((N)->img_struct.jb2)
188 # define F_FLAG_BBOX (1 << 0)
189 # define F_FLAG_GROUP (1 << 1)
191 # define img_set_bbox(N) (img_flags(N) |= F_FLAG_BBOX)
192 # define img_unset_bbox(N) (img_flags(N) &= ~F_FLAG_BBOX)
193 # define img_is_bbox(N) ((img_flags(N) & F_FLAG_BBOX) != 0)
195 # define img_set_group(N) (img_flags(N) |= F_FLAG_GROUP)
196 # define img_unset_group(N) (img_flags(N) &= ~F_FLAG_GROUP)
197 # define img_is_group(N) ((img_flags(N) & F_FLAG_GROUP) != 0)
199 # define epdf_xsize(a) img_xsize(idict_array[a])
200 # define epdf_ysize(a) img_ysize(idict_array[a])
201 # define epdf_orig_x(a) img_xorig(idict_array[a])
202 # define epdf_orig_y(a) img_yorig(idict_array[a])
204 # define is_pdf_image(a) ((img_type(idict_array[a]) == IMG_TYPE_PDF) || (img_type(idict_array[a]) == IMG_TYPE_PDFMEMSTREAM))
205 # define is_png_image(a) (img_type(idict_array[a]) == IMG_TYPE_PNG)
207 # define img_is_refered(N) (img_index(N) != -1)
209 typedef struct {
210 scaled_whd dimen; /* requested/actual TeX dimensions */
211 int transform;
212 image_dict *dict;
213 int dict_ref; /* luaL_ref() reference */
214 } image;
216 # define img_dict(N) ((N)->dict)
217 # define img_dictref(N) ((N)->dict_ref)
219 # define set_wd_running(N) (img_width(N) = null_flag)
220 # define set_ht_running(N) (img_height(N) = null_flag)
221 # define set_dp_running(N) (img_depth(N) = null_flag)
222 # define is_wd_running(N) (img_width(N) == null_flag)
223 # define is_ht_running(N) (img_height(N) == null_flag)
224 # define is_dp_running(N) (img_depth(N) == null_flag)
226 #endif