| 1 |
/* image.h |
| 2 |
|
| 3 |
Copyright 1996-2006 Han The Thanh <[email protected]> |
| 4 |
Copyright 2006-2010 Taco Hoekwater <[email protected]> |
| 5 |
|
| 6 |
This file is part of LuaTeX. |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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/>. */ |
| 20 |
|
| 21 |
#ifndef IMAGE_H |
| 22 |
# define IMAGE_H |
| 23 |
|
| 24 |
# include <png.h> |
| 25 |
# include "pdf/pdftypes.h" /* for scaled_whd */ |
| 26 |
|
| 27 |
# define JPG_UINT16 unsigned int |
| 28 |
# define JPG_UINT32 unsigned long |
| 29 |
# define JPG_UINT8 unsigned char |
| 30 |
|
| 31 |
extern int do_zround(double r); /* from utils.w */ |
| 32 |
extern scaled one_hundred_bp; /* from pdfgen.w */ |
| 33 |
|
| 34 |
# define bp2sp(p) do_zround(p * (one_hundred_bp / 100.0)) |
| 35 |
# define sp2bp(i) (i * 100.0 / one_hundred_bp) |
| 36 |
|
| 37 |
# define TYPE_IMG "image.meta" |
| 38 |
# define TYPE_IMG_DICT "image.dict" |
| 39 |
|
| 40 |
typedef struct { |
| 41 |
char *stream; |
| 42 |
size_t size; |
| 43 |
} pdf_stream_struct; |
| 44 |
|
| 45 |
typedef struct { |
| 46 |
png_structp png_ptr; |
| 47 |
png_infop info_ptr; |
| 48 |
} png_img_struct; |
| 49 |
|
| 50 |
typedef struct { |
| 51 |
int color_space; /* used color space. See JPG_ constants */ |
| 52 |
JPG_UINT32 length; /* length of file/data */ |
| 53 |
} jpg_img_struct; |
| 54 |
|
| 55 |
typedef struct { |
| 56 |
int length; /* length of file/data */ |
| 57 |
} jp2_img_struct; |
| 58 |
|
| 59 |
# if 0 |
| 60 |
typedef struct { /* currently unused */ |
| 61 |
} jb2_img_struct; |
| 62 |
# endif |
| 63 |
|
| 64 |
typedef enum { |
| 65 |
DICT_NEW, /* fresh dictionary */ |
| 66 |
DICT_FILESCANNED, /* image file scanned */ |
| 67 |
DICT_REFERED, /* pdf_refximage_node in node list --> read-only dict */ |
| 68 |
DICT_OUTIMG, /* /Im* appears in pagestream */ |
| 69 |
DICT_SCHEDULED, /* image dict scheduled for writing (PONR) */ |
| 70 |
DICT_WRITTEN /* image dict written to file */ |
| 71 |
} dict_state; |
| 72 |
|
| 73 |
typedef enum { |
| 74 |
IMG_TYPE_NONE, |
| 75 |
IMG_TYPE_PDF, |
| 76 |
IMG_TYPE_PNG, |
| 77 |
IMG_TYPE_JPG, |
| 78 |
IMG_TYPE_JP2, |
| 79 |
IMG_TYPE_JBIG2, |
| 80 |
IMG_TYPE_PDFSTREAM, |
| 81 |
IMG_TYPE_PDFMEMSTREAM, |
| 82 |
IMG_TYPE_SENTINEL |
| 83 |
} imgtype_e; |
| 84 |
|
| 85 |
typedef enum { IMG_KEEPOPEN, IMG_CLOSEINBETWEEN } img_readtype_e; |
| 86 |
|
| 87 |
typedef enum { |
| 88 |
PDF_BOX_SPEC_NONE, |
| 89 |
PDF_BOX_SPEC_MEDIA, |
| 90 |
PDF_BOX_SPEC_CROP, |
| 91 |
PDF_BOX_SPEC_BLEED, |
| 92 |
PDF_BOX_SPEC_TRIM, |
| 93 |
PDF_BOX_SPEC_ART, |
| 94 |
PDF_BOX_SPEC_SENTINEL |
| 95 |
} pdfboxspec_e; |
| 96 |
|
| 97 |
typedef struct { |
| 98 |
int objnum; |
| 99 |
int index; /* /Im1, /Im2, ... */ |
| 100 |
scaled_whd dimen; /* TeX dimensions given to \pdfximage */ |
| 101 |
int transform; /* transform given to \pdfximage */ |
| 102 |
int x_size; /* dimensions in pixel counts as in JPG/PNG/JBIG2 file */ |
| 103 |
int y_size; |
| 104 |
int x_orig; /* origin in sp for PDF files */ |
| 105 |
int y_orig; |
| 106 |
int x_res; /* pixel resolution as in JPG/PNG/JBIG2 file */ |
| 107 |
int y_res; |
| 108 |
int rotation; /* rotation (multiples of 90 deg.) for PDF files */ |
| 109 |
int orientation; /* jpeg orientation, 0=unset, 1=ul, 2=ur, 3=lr, 4=ll, 5-8 flipped */ |
| 110 |
int colorspace; /* number of /ColorSpace object */ |
| 111 |
int group_ref; /* if it's <=0, the page has no group */ |
| 112 |
int total_pages; |
| 113 |
int page_num; /* requested page (by number) */ |
| 114 |
char *pagename; /* requested page (by name) */ |
| 115 |
char *filename; /* requested raw file name */ |
| 116 |
char *visiblefilename; /* blocks or overwrites filename as it appears in PDF output */ |
| 117 |
char *filepath; /* full file path after kpathsea */ |
| 118 |
char *attr; /* additional image dict entries */ |
| 119 |
FILE *file; |
| 120 |
char *userpassword; |
| 121 |
char *ownerpassword; |
| 122 |
imgtype_e image_type; |
| 123 |
int procset; /* /ProcSet flags */ |
| 124 |
int color_depth; /* color depth */ |
| 125 |
pdfboxspec_e page_box_spec; /* PDF page box spec.: media/crop/bleed/trim/art */ |
| 126 |
int bbox[4]; |
| 127 |
dict_state state; |
| 128 |
int flags; |
| 129 |
int luaref ; |
| 130 |
boolean keepopen; |
| 131 |
boolean nolength; |
| 132 |
boolean notype; |
| 133 |
boolean nobbox; |
| 134 |
int errorlevel; |
| 135 |
int pdfmajorversion; |
| 136 |
int pdfminorversion; |
| 137 |
union { |
| 138 |
pdf_stream_struct *pdfstream; |
| 139 |
png_img_struct *png; |
| 140 |
jpg_img_struct *jpg; |
| 141 |
jp2_img_struct *jp2; |
| 142 |
/* jb2_img_struct *jb2; */ |
| 143 |
} img_struct; |
| 144 |
} image_dict; |
| 145 |
|
| 146 |
# define img_objnum(N) ((N)->objnum) |
| 147 |
# define img_index(N) ((N)->index) |
| 148 |
# define img_dimen(N) ((N)->dimen) |
| 149 |
# define img_width(N) ((N)->dimen.wd) |
| 150 |
# define img_height(N) ((N)->dimen.ht) |
| 151 |
# define img_depth(N) ((N)->dimen.dp) |
| 152 |
# define img_transform(N) ((N)->transform) |
| 153 |
# define img_xsize(N) ((N)->x_size) |
| 154 |
# define img_ysize(N) ((N)->y_size) |
| 155 |
# define img_xorig(N) ((N)->x_orig) |
| 156 |
# define img_yorig(N) ((N)->y_orig) |
| 157 |
# define img_xres(N) ((N)->x_res) |
| 158 |
# define img_yres(N) ((N)->y_res) |
| 159 |
# define img_rotation(N) ((N)->rotation) |
| 160 |
# define img_orientation(N) ((N)->orientation) |
| 161 |
# define img_colorspace(N) ((N)->colorspace) |
| 162 |
# define img_group_ref(N) ((N)->group_ref) |
| 163 |
# define img_totalpages(N) ((N)->total_pages) |
| 164 |
# define img_pagenum(N) ((N)->page_num) |
| 165 |
# define img_pagename(N) ((N)->pagename) |
| 166 |
# define img_filename(N) ((N)->filename) |
| 167 |
# define img_visiblefilename(N) ((N)->visiblefilename) |
| 168 |
# define img_userpassword(N) ((N)->userpassword) |
| 169 |
# define img_ownerpassword(N) ((N)->ownerpassword) |
| 170 |
# define img_filepath(N) ((N)->filepath) |
| 171 |
# define img_attr(N) ((N)->attr) |
| 172 |
# define img_file(N) ((N)->file) |
| 173 |
# define img_type(N) ((N)->image_type) |
| 174 |
# define img_procset(N) ((N)->procset) |
| 175 |
# define img_colordepth(N) ((N)->color_depth) |
| 176 |
# define img_pagebox(N) ((N)->page_box_spec) |
| 177 |
# define img_bbox(N) ((N)->bbox) |
| 178 |
# define img_state(N) ((N)->state) |
| 179 |
# define img_flags(N) ((N)->flags) |
| 180 |
# define img_luaref(N) ((N)->luaref) |
| 181 |
# define img_keepopen(N) ((N)->keepopen) |
| 182 |
# define img_nobbox(N) ((N)->nobbox) |
| 183 |
# define img_nolength(N) ((N)->nolength) |
| 184 |
# define img_notype(N) ((N)->notype) |
| 185 |
# define img_errorlevel(N) ((N)->errorlevel) |
| 186 |
# define img_pdfmajorversion(N) ((N)->pdfmajorversion) |
| 187 |
# define img_pdfminorversion(N) ((N)->pdfminorversion) |
| 188 |
|
| 189 |
# define img_pdfstream_ptr(N) ((N)->img_struct.pdfstream) |
| 190 |
# define img_pdfstream_stream(N) ((N)->img_struct.pdfstream->stream) |
| 191 |
# define img_pdfstream_size(N) ((N)->img_struct.pdfstream->size) |
| 192 |
|
| 193 |
# define img_png_ptr(N) ((N)->img_struct.png) |
| 194 |
# define img_png_png_ptr(N) ((N)->img_struct.png->png_ptr) |
| 195 |
# define img_png_info_ptr(N) ((N)->img_struct.png->info_ptr) |
| 196 |
|
| 197 |
# define img_jpg_ptr(N) ((N)->img_struct.jpg) |
| 198 |
# define img_jpg_color(N) ((N)->img_struct.jpg->color_space) |
| 199 |
|
| 200 |
# define img_jp2_ptr(N) ((N)->img_struct.jp2) |
| 201 |
|
| 202 |
# define img_jb2_ptr(N) ((N)->img_struct.jb2) |
| 203 |
|
| 204 |
# define F_FLAG_BBOX (1 << 0) |
| 205 |
# define F_FLAG_GROUP (1 << 1) |
| 206 |
|
| 207 |
# define img_set_bbox(N) (img_flags(N) |= F_FLAG_BBOX) |
| 208 |
# define img_unset_bbox(N) (img_flags(N) &= ~F_FLAG_BBOX) |
| 209 |
# define img_is_bbox(N) ((img_flags(N) & F_FLAG_BBOX) != 0) |
| 210 |
|
| 211 |
# define img_set_group(N) (img_flags(N) |= F_FLAG_GROUP) |
| 212 |
# define img_unset_group(N) (img_flags(N) &= ~F_FLAG_GROUP) |
| 213 |
# define img_is_group(N) ((img_flags(N) & F_FLAG_GROUP) != 0) |
| 214 |
|
| 215 |
# define epdf_xsize(a) img_xsize(idict_array[a]) |
| 216 |
# define epdf_ysize(a) img_ysize(idict_array[a]) |
| 217 |
# define epdf_orig_x(a) img_xorig(idict_array[a]) |
| 218 |
# define epdf_orig_y(a) img_yorig(idict_array[a]) |
| 219 |
|
| 220 |
# define is_pdf_image(a) ((img_type(idict_array[a]) == IMG_TYPE_PDF) || (img_type(idict_array[a]) == IMG_TYPE_PDFMEMSTREAM)) |
| 221 |
# define is_png_image(a) (img_type(idict_array[a]) == IMG_TYPE_PNG) |
| 222 |
|
| 223 |
# define img_is_refered(N) (img_index(N) != -1) |
| 224 |
|
| 225 |
typedef struct { |
| 226 |
scaled_whd dimen; /* requested/actual TeX dimensions */ |
| 227 |
int transform; |
| 228 |
image_dict *dict; |
| 229 |
int dict_ref; /* luaL_ref() reference */ |
| 230 |
} image; |
| 231 |
|
| 232 |
# define img_dict(N) ((N)->dict) |
| 233 |
# define img_dictref(N) ((N)->dict_ref) |
| 234 |
|
| 235 |
# define set_wd_running(N) (img_width(N) = null_flag) |
| 236 |
# define set_ht_running(N) (img_height(N) = null_flag) |
| 237 |
# define set_dp_running(N) (img_depth(N) = null_flag) |
| 238 |
# define is_wd_running(N) (img_width(N) == null_flag) |
| 239 |
# define is_ht_running(N) (img_height(N) == null_flag) |
| 240 |
# define is_dp_running(N) (img_depth(N) == null_flag) |
| 241 |
|
| 242 |
#endif |