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/>. */
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"
50 int color_space
; /* used color space. See JPG_ constants */
51 JPG_UINT32 length
; /* length of file/data */
55 int length
; /* length of file/data */
59 typedef struct { /* currently unused */
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 */
80 IMG_TYPE_PDFMEMSTREAM
,
84 typedef enum { IMG_KEEPOPEN
, IMG_CLOSEINBETWEEN
} img_readtype_e
;
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 */
103 int x_orig
; /* origin in sp for PDF files */
105 int x_res
; /* pixel resolution as in JPG/PNG/JBIG2 file */
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 */
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 */
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 */
130 pdf_stream_struct
*pdfstream
;
134 /* jb2_img_struct *jb2; */
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)
210 scaled_whd dimen
; /* requested/actual TeX dimensions */
213 int dict_ref
; /* luaL_ref() reference */
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)