static void write_image_or_node(lua_State * L, wrtype_e writetype) { image *a, **aa; image_dict *ad; halfword n; if (lua_gettop(L) != 1) luaL_error(L, "%s expects an argument", wrtype_s[writetype]); if (lua_istable(L, 1)) (void) l_new_image(L); aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); a = *aa; ad = img_dict(a); setup_image(static_pdf, a, writetype); switch (writetype) { case WR_WRITE: n = img_to_node(L, a); tail_append(n); break; case WR_IMMEDIATEWRITE: write_img(static_pdf, ad); break; case WR_NODE: lua_pop(L, 1); /* - */ n = img_to_node(L, a); lua_nodelib_push_fast(L, n); break; default: luaL_error(L, "%s expects an valid image", wrtype_s[writetype]); } if (img_state(ad) < DICT_REFERED) img_state(ad) = DICT_REFERED; }
static void write_image_or_node(lua_State * L, wrtype_e writetype) { image *a, **aa; image_dict *ad; halfword n; if (lua_gettop(L) != 1) luaL_error(L, "%s needs exactly 1 argument", wrtype_s[writetype]); if (lua_istable(L, 1)) (void) l_new_image(L); /* image --- if everything worked well */ aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* image */ a = *aa; ad = img_dict(a); setup_image(static_pdf, a, writetype); switch (writetype) { case WR_WRITE: n = img_to_node(a); tail_append(n); break; /* image */ case WR_IMMEDIATEWRITE: write_img(static_pdf, ad); break; /* image */ case WR_NODE: /* image */ lua_pop(L, 1); /* - */ n = img_to_node(a); lua_nodelib_push_fast(L, n); break; /* node */ default: assert(0); } if (img_state(ad) < DICT_REFERED) img_state(ad) = DICT_REFERED; }
void write_img(PDF pdf, image_dict * idict) { if (img_state(idict) < DICT_WRITTEN) { report_start_file(filetype_image, img_filepath(idict)); switch (img_type(idict)) { case IMG_TYPE_PNG: write_png(pdf, idict); break; case IMG_TYPE_JPG: write_jpg(pdf, idict); break; case IMG_TYPE_JP2: write_jp2(pdf, idict); break; case IMG_TYPE_JBIG2: write_jbig2(pdf, idict); break; case IMG_TYPE_PDFMEMSTREAM: case IMG_TYPE_PDF: write_epdf(pdf, idict,(int) pdf_suppress_optional_info); break; case IMG_TYPE_PDFSTREAM: write_pdfstream(pdf, idict); break; default: normal_error("pdf backend","internal error: writing unknown image type"); } report_stop_file(filetype_image); if (img_type(idict) == IMG_TYPE_PNG) { write_additional_png_objects(pdf); } } if (img_state(idict) < DICT_WRITTEN) img_state(idict) = DICT_WRITTEN; }
static void read_scale_img(image * a) { image_dict *ad; if (a == NULL) { luaL_error(Luas, "the image scaler needs a valid image"); } else { ad = img_dict(a); if (a == NULL) { luaL_error(Luas, "the image scaler needs a valid dictionary"); } else { if (img_state(ad) == DICT_NEW) { if (img_type(ad) == IMG_TYPE_PDFSTREAM) check_pdfstream_dict(ad); else { read_img(ad); } } if ((img_type(ad) == IMG_TYPE_NONE) || (img_state(ad) == DICT_NEW)) { normal_warning("image","don't rely on the image data to be okay"); img_width(a) = 0; img_height(a) = 0; img_depth(a) = 0; } else if (is_wd_running(a) || is_ht_running(a) || is_dp_running(a)) { img_dimen(a) = scale_img(ad, img_dimen(a), img_transform(a)); } } } }
void check_pdfstream_dict(image_dict * idict) { if (!img_is_bbox(idict) && !img_nobbox(idict)) { normal_error("pdf backend","image.stream: no bbox given"); } if (img_state(idict) < DICT_FILESCANNED) { img_state(idict) = DICT_FILESCANNED; } }
static void copy_image(lua_State * L, lua_Number scale) { image *a, **aa, *b, **bb; if (lua_gettop(L) != 1) luaL_error(L, "img.copy() needs exactly 1 argument"); aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* a */ lua_pop(L, 1); /* - */ a = *aa; bb = (image **) lua_newuserdata(L, sizeof(image *)); /* b */ luaL_getmetatable(L, TYPE_IMG); /* m b */ lua_setmetatable(L, -2); /* b */ b = *bb = new_image(); if (!is_wd_running(a)) img_width(b) = do_zround(img_width(a) * scale); if (!is_ht_running(a)) img_height(b) = do_zround(img_height(a) * scale); if (!is_dp_running(a)) img_depth(b) = do_zround(img_depth(a) * scale); img_transform(b) = img_transform(a); img_dict(b) = img_dict(a); if (img_dictref(a) != LUA_NOREF) { lua_rawgeti(L, LUA_GLOBALSINDEX, img_dictref(a)); /* ad b */ img_dictref(b) = luaL_ref(L, LUA_GLOBALSINDEX); /* b */ } else assert(img_state(img_dict(a)) >= DICT_REFERED); }
static void copy_image(lua_State * L, lua_Number scale) { image *a, **aa, *b, **bb; image_dict *d; if (lua_gettop(L) == 0) luaL_error(L, "img.copy needs an image as argument"); aa = (image **) luaL_checkudata(L, 1, TYPE_IMG); /* a */ lua_pop(L, 1); /* - */ a = *aa; bb = (image **) lua_newuserdata(L, sizeof(image *)); /* b */ luaL_getmetatable(L, TYPE_IMG); /* m b */ lua_setmetatable(L, -2); /* b */ b = *bb = new_image(); if (!is_wd_running(a)) img_width(b) = do_zround(img_width(a) * scale); if (!is_ht_running(a)) img_height(b) = do_zround(img_height(a) * scale); if (!is_dp_running(a)) img_depth(b) = do_zround(img_depth(a) * scale); img_transform(b) = img_transform(a); img_dict(b) = img_dict(a); if (img_dictref(a) != LUA_NOREF) { lua_rawgeti(L, LUA_REGISTRYINDEX, img_dictref(a)); /* ad b */ img_dictref(b) = luaL_ref(L, LUA_REGISTRYINDEX); /* b */ d = img_dict(*aa); img_luaref(d) += 1; } else if (img_state(img_dict(a)) < DICT_REFERED) { luaL_error(L, "img.copy needs an proper image as argument"); } }
static int m_img_dict_gc(lua_State * L) { image_dict *ad, **add; add = (image_dict **) luaL_checkudata(L, 1, TYPE_IMG_DICT); ad = *add; #ifdef DEBUG printf("\n===== IMG_DICT GC FREE ===== ad=%d\n", ad); #endif if (img_state(ad) < DICT_REFERED) free_image_dict(ad); return 0; }
static int m_img_dict_gc(lua_State * L) { image_dict *ad, **add; add = (image_dict **) luaL_checkudata(L, 1, TYPE_IMG_DICT); ad = *add; if (img_luaref(ad) > 0) { luaL_error(L, "disposing image dict that has references"); } else { /* we need to check this */ if (img_state(ad) < DICT_REFERED) { free_image_dict(ad); } /* till here */ } return 0; }
static void read_scale_img(image * a) { image_dict *ad; assert(a != NULL); ad = img_dict(a); assert(ad != NULL); if (img_state(ad) == DICT_NEW) { if (img_type(ad) == IMG_TYPE_PDFSTREAM) check_pdfstream_dict(ad); else { fix_pdf_minorversion(static_pdf); read_img(static_pdf, ad, pdf_minor_version, pdf_inclusion_errorlevel); } } if (is_wd_running(a) || is_ht_running(a) || is_dp_running(a)) img_dimen(a) = scale_img(ad, img_dimen(a), img_transform(a)); }
void scan_pdfrefximage(PDF pdf) { /*tex One could scan transform as well. */ int transform = 0; /*tex Begin of experiment. */ int open = 0; /*tex End of experiment. */ image_dict *idict; /*tex This scans |<rule spec>| to |alt_rule|. */ scaled_whd alt_rule, dim; alt_rule = scan_alt_rule(); /*tex Begin of experiment. */ if (scan_keyword("keepopen")) { open = 1; } /*tex End of experiment. */ scan_int(); check_obj_type(pdf, obj_type_ximage, cur_val); tail_append(new_rule(image_rule)); idict = idict_array[obj_data_ptr(pdf, cur_val)]; /*tex Begin of experiment, */ if (open) { /*tex So we keep the original value when no close is given. */ idict->keepopen = 1; } /*tex End of experiment. */ if (img_state(idict) == DICT_NEW) { normal_warning("image","don't rely on the image data to be okay"); width(tail_par) = 0; height(tail_par) = 0; depth(tail_par) = 0; } else { if (alt_rule.wd != null_flag || alt_rule.ht != null_flag || alt_rule.dp != null_flag) { dim = scale_img(idict, alt_rule, transform); } else { dim = scale_img(idict, img_dimen(idict), img_transform(idict)); } width(tail_par) = dim.wd; height(tail_par) = dim.ht; depth(tail_par) = dim.dp; rule_transform(tail_par) = transform; rule_index(tail_par) = img_index(idict); } }
image_dict *new_image_dict(void) { image_dict *p = xtalloc(1, image_dict); memset(p, 0, sizeof(image_dict)); set_wd_running(p); set_ht_running(p); set_dp_running(p); img_transform(p) = 0; img_pagenum(p) = 1; img_type(p) = IMG_TYPE_NONE; img_pagebox(p) = PDF_BOX_SPEC_MEDIA; img_unset_bbox(p); img_unset_group(p); img_state(p) = DICT_NEW; /*tex A value of -1 means unused while the used counts from 0 */ img_index(p) = -1; img_luaref(p) = 0; img_errorlevel(p) = pdf_inclusion_errorlevel; fix_pdf_version(static_pdf); img_pdfmajorversion(p) = pdf_major_version; img_pdfminorversion(p) = pdf_minor_version; return p; }
static void lua_to_image(lua_State * L, image * a) { /* value key table ... */ int i; image_dict *d = img_dict(a); assert(d != NULL); lua_pushstring(L, IMG_ENV); /* s v k t ... */ lua_gettable(L, LUA_REGISTRYINDEX); /* t v k t ... */ lua_pushvalue(L, -3); /* k t v k t ... */ lua_gettable(L, -2); /* i? t v k t ... */ if (!lua_isnumber(L, -1)) /* !i t v k t ... */ luaL_error(L, "lua_to_image(): %s is not a valid image key", lua_tostring(L, -4)); i = (int) lua_tointeger(L, -1); /* i t v k t ... */ lua_pop(L, 2); /* v k t ... */ switch (i) { case P_WIDTH: if (lua_isnil(L, -1)) set_wd_running(a); else if (lua_type(L, -1) == LUA_TNUMBER) img_width(a) = (int) lua_tointeger(L, -1); else if (lua_type(L, -1) == LUA_TSTRING) img_width(a) = dimen_to_number(L, lua_tostring(L, -1)); else luaL_error(L, "image.width needs integer or nil value or dimension string"); break; case P_HEIGHT: if (lua_isnil(L, -1)) set_ht_running(a); else if (lua_type(L, -1) == LUA_TNUMBER) img_height(a) = (int) lua_tointeger(L, -1); else if (lua_type(L, -1) == LUA_TSTRING) img_height(a) = dimen_to_number(L, lua_tostring(L, -1)); else luaL_error(L, "image.height needs integer or nil value or dimension string"); break; case P_DEPTH: if (lua_isnil(L, -1)) set_dp_running(a); else if (lua_type(L, -1) == LUA_TNUMBER) img_depth(a) = (int) lua_tointeger(L, -1); else if (lua_type(L, -1) == LUA_TSTRING) img_depth(a) = dimen_to_number(L, lua_tostring(L, -1)); else luaL_error(L, "image.depth needs integer or nil value or dimension string"); break; case P_TRANSFORM: if (lua_isnumber(L, -1)) img_transform(a) = (int) lua_tointeger(L, -1); else luaL_error(L, "image.transform needs integer value"); break; /* now follow all image_dict entries */ case P_FILENAME: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.filename is now read-only"); if (img_type(d) == IMG_TYPE_PDFSTREAM) luaL_error(L, "image.filename can't be used with image.stream"); if (lua_isstring(L, -1)) { xfree(img_filename(d)); img_filename(d) = xstrdup(lua_tostring(L, -1)); } else luaL_error(L, "image.filename needs string value"); break; case P_VISIBLEFILENAME: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.visiblefilename is now read-only"); if (img_type(d) == IMG_TYPE_PDFSTREAM) luaL_error(L, "image.visiblefilename can't be used with image.stream"); if (lua_isstring(L, -1)) { xfree(img_visiblefilename(d)); img_visiblefilename(d) = xstrdup(lua_tostring(L, -1)); } else luaL_error(L, "image.visiblefilename needs string value"); break; case P_ATTR: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.attr is now read-only"); if (lua_isstring(L, -1) || lua_isnil(L, -1)) { xfree(img_attr(d)); if (lua_isstring(L, -1)) img_attr(d) = xstrdup(lua_tostring(L, -1)); } else luaL_error(L, "image.attr needs string or nil value"); break; case P_PAGE: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.page is now read-only"); if (lua_type(L, -1) == LUA_TSTRING) { xfree(img_pagename(d)); img_pagename(d) = xstrdup(lua_tostring(L, -1)); img_pagenum(d) = 0; } else if (lua_type(L, -1) == LUA_TNUMBER) { img_pagenum(d) = (int) lua_tointeger(L, -1); xfree(img_pagename(d)); } else luaL_error(L, "image.page needs integer or string value"); break; case P_COLORSPACE: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.colorspace is now read-only"); if (lua_isnil(L, -1)) img_colorspace(d) = 0; else if (lua_isnumber(L, -1)) img_colorspace(d) = (int) lua_tointeger(L, -1); else luaL_error(L, "image.colorspace needs integer or nil value"); break; case P_PAGEBOX: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.pagebox is now read-only"); if (lua_isnil(L, -1)) img_pagebox(d) = PDF_BOX_SPEC_NONE; else if (lua_isstring(L, -1)) img_pagebox(d) = luaL_checkoption(L, -1, "none", pdfboxspec_s); else luaL_error(L, "image.pagebox needs string or nil value"); break; case P_BBOX: if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.bbox is now read-only"); if (!lua_istable(L, -1)) luaL_error(L, "image.bbox needs table value"); if (lua_objlen(L, -1) != 4) luaL_error(L, "image.bbox table must have exactly 4 elements"); for (i = 1; i <= 4; i++) { /* v k t ... */ lua_pushinteger(L, i); /* idx v k t ... */ lua_gettable(L, -2); /* int v k t ... */ if (lua_type(L, -1) == LUA_TNUMBER) img_bbox(d)[i - 1] = (int) lua_tointeger(L, -1); else if (lua_type(L, -1) == LUA_TSTRING) img_bbox(d)[i - 1] = dimen_to_number(L, lua_tostring(L, -1)); else luaL_error(L, "image.bbox table needs integer value or dimension string elements"); lua_pop(L, 1); /* v k t ... */ } img_set_bbox(d); break; case P_STREAM: if (img_filename(d) != NULL) luaL_error(L, "image.stream can't be used with image.filename"); if (img_state(d) >= DICT_FILESCANNED) luaL_error(L, "image.stream is now read-only"); if (img_pdfstream_ptr(d) == NULL) new_img_pdfstream_struct(d); xfree(img_pdfstream_stream(d)); img_pdfstream_stream(d) = xstrdup(lua_tostring(L, -1)); img_type(d) = IMG_TYPE_PDFSTREAM; break; case P_FILEPATH: case P_TOTALPAGES: case P_XSIZE: case P_YSIZE: case P_XRES: case P_YRES: case P_ROTATION: case P_IMAGETYPE: case P_OBJNUM: case P_INDEX: case P_COLORDEPTH: luaL_error(L, "image.%s is a read-only variable", img_parms[i].name); break; default: assert(0); } /* v k t ... */ }
static void lua_to_image(lua_State * L, image * a, image_dict * d) { int i, t; const char *s; s = lua_tostring(L,-2); t = lua_type(L, -1); if (lua_key_eq(s,width)) { if (t == LUA_TNIL) { set_wd_running(a); } else if (t == LUA_TNUMBER) { img_width(a) = (int) lua_roundnumber(L, -1); } else if (t == LUA_TSTRING) { img_width(a) = dimen_to_number(L, lua_tostring(L, -1)); } else { luaL_error(L, "image.width needs integer or nil value or dimension string"); } } else if (lua_key_eq(s,height)) { if (t == LUA_TNIL) { set_ht_running(a); } else if (t == LUA_TNUMBER) { img_height(a) = (int) lua_roundnumber(L, -1); } else if (t == LUA_TSTRING) { img_height(a) = dimen_to_number(L, lua_tostring(L, -1)); } else { luaL_error(L, "image.height needs integer or nil value or dimension string"); } } else if (lua_key_eq(s,depth)) { if (t == LUA_TNIL) { set_dp_running(a); } else if (t == LUA_TNUMBER) { img_depth(a) = (int) lua_roundnumber(L, -1); } else if (t == LUA_TSTRING) { img_depth(a) = dimen_to_number(L, lua_tostring(L, -1)); } else { luaL_error(L, "image.depth needs integer or nil value or dimension string"); } } else if (lua_key_eq(s,transform)) { if (t == LUA_TNUMBER) { img_transform(a) = (int) lua_tointeger(L, -1); } else { luaL_error(L, "image.transform needs integer value"); } } else if (lua_key_eq(s,filename)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.filename is now read-only"); } else if (img_type(d) == IMG_TYPE_PDFSTREAM) { luaL_error(L, "image.filename can't be used with image.stream"); } else if (t == LUA_TSTRING) { xfree(img_filename(d)); img_filename(d) = xstrdup(lua_tostring(L, -1)); } else { luaL_error(L, "image.filename needs string value"); } } else if (lua_key_eq(s,visiblefilename)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.visiblefilename is now read-only"); } else if (img_type(d) == IMG_TYPE_PDFSTREAM) { luaL_error(L, "image.visiblefilename can't be used with image.stream"); } else if (t == LUA_TSTRING) { xfree(img_visiblefilename(d)); img_visiblefilename(d) = xstrdup(lua_tostring(L, -1)); } else { luaL_error(L, "image.visiblefilename needs string value"); } } else if (lua_key_eq(s,attr)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.attr is now read-only"); } else if (t == LUA_TSTRING) { xfree(img_attr(d)); img_attr(d) = xstrdup(lua_tostring(L, -1)); } else if (t == LUA_TNIL) { xfree(img_attr(d)); } else { luaL_error(L, "image.attr needs string or nil value"); } } else if (lua_key_eq(s,page)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.page is now read-only"); } else if (t == LUA_TSTRING) { xfree(img_pagename(d)); img_pagename(d) = xstrdup(lua_tostring(L, -1)); img_pagenum(d) = 0; } else if (t == LUA_TNUMBER) { img_pagenum(d) = (int) lua_tointeger(L, -1); xfree(img_pagename(d)); } else { luaL_error(L, "image.page needs integer or string value"); } } else if (lua_key_eq(s,colorspace)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.colorspace is now read-only"); } else if (t == LUA_TNIL) { img_colorspace(d) = 0; } else if (t == LUA_TNUMBER) { img_colorspace(d) = (int) lua_tointeger(L, -1); } else { luaL_error(L, "image.colorspace needs integer or nil value"); } } else if (lua_key_eq(s,pagebox)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.pagebox is now read-only"); } else if (t == LUA_TNIL) { img_pagebox(d) = PDF_BOX_SPEC_MEDIA; } else if (t == LUA_TNUMBER) { i = lua_tointeger(L,-1); if (i < 0 || i >= img_pageboxes_max) { img_pagebox(d) = PDF_BOX_SPEC_MEDIA; } else { img_pagebox(d) = i; } } else if (t == LUA_TSTRING) { img_pagebox(d) = PDF_BOX_SPEC_MEDIA; for (i = 0; i < img_pageboxes_max; i++) { lua_rawgeti(L, LUA_REGISTRYINDEX, img_pageboxes[i]); if (lua_rawequal(L,-1,-2)) { img_pagebox(d) = i; lua_pop(L, 1); break; } else { lua_pop(L, 1); } } } else { luaL_error(L, "image.pagebox needs string, number or nil value"); } } else if (lua_key_eq(s,keepopen)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.keepopen is now read-only"); } else if (t != LUA_TBOOLEAN) { luaL_error(L, "image.bbox needs boolean value"); } else { img_keepopen(d) = lua_toboolean(L, -1); } } else if (lua_key_eq(s,bbox)) { if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.bbox is now read-only"); } else if (t != LUA_TTABLE) { luaL_error(L, "image.bbox needs table value"); } else if (lua_rawlen(L, -1) != 4) { luaL_error(L, "image.bbox table must have exactly 4 elements"); } else { for (i = 1; i <= 4; i++) { /* v k t ... */ lua_pushinteger(L, i); /* idx v k t ... */ lua_gettable(L, -2); /* int v k t ... */ t = lua_type(L, -1); if (t == LUA_TNUMBER) { img_bbox(d)[i - 1] = (int) lua_roundnumber(L, -1); } else if (t == LUA_TSTRING) { img_bbox(d)[i - 1] = dimen_to_number(L, lua_tostring(L, -1)); } else { luaL_error(L, "image.bbox table needs integer value or dimension string elements"); } lua_pop(L, 1); /* v k t ... */ } img_set_bbox(d); } } else if (lua_key_eq(s,stream)) { if (img_filename(d) != NULL) { luaL_error(L, "image.stream can't be used with image.filename"); } else if (img_state(d) >= DICT_FILESCANNED) { luaL_error(L, "image.stream is now read-only"); } else { if (img_pdfstream_ptr(d) == NULL) { new_img_pdfstream_struct(d); } xfree(img_pdfstream_stream(d)); img_pdfstream_stream(d) = xstrdup(lua_tostring(L, -1)); img_type(d) = IMG_TYPE_PDFSTREAM; } } else { luaL_error(L, "image.%s can not be set", s); } }
void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform) { /*tex A transformation matrix: */ double a[6]; double xoff, yoff, tmp; pdfstructure *p = pdf->pstruct; scaledpos pos = pdf->posstruct->pos; /*tex The number of digits after the decimal point: */ int r; int k; scaledpos tmppos; pdffloat cm[6]; int groupref; a[0] = a[3] = 1.0e6; a[1] = a[2] = 0; if (img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM || img_type(idict) == IMG_TYPE_PDFSTREAM) { a[0] /= (double) img_xsize(idict); a[3] /= (double) img_ysize(idict); xoff = (double) img_xorig(idict) / (double) img_xsize(idict); yoff = (double) img_yorig(idict) / (double) img_ysize(idict); r = 6; } else { if (img_type(idict) == IMG_TYPE_PNG) { groupref = img_group_ref(idict); if ((groupref > 0) && (pdf->img_page_group_val == 0)) pdf->img_page_group_val = groupref; } a[0] /= (double) one_hundred_bp; a[3] = a[0]; xoff = yoff = 0; r = 4; } if ((transform & 7) > 3) { /*tex Mirror cases: */ a[0] *= -1; xoff *= -1; } switch ((transform + img_rotation(idict)) & 3) { case 0: /*tex No transform. */ break; case 1: /*tex rotation over 90 degrees (counterclockwise) */ a[1] = a[0]; a[2] = -a[3]; a[3] = a[0] = 0; tmp = yoff; yoff = xoff; xoff = -tmp; break; case 2: /*tex rotation over 180 degrees (counterclockwise) */ a[0] *= -1; a[3] *= -1; xoff *= -1; yoff *= -1; break; case 3: /*tex rotation over 270 degrees (counterclockwise) */ a[1] = -a[0]; a[2] = a[3]; a[3] = a[0] = 0; tmp = yoff; yoff = -xoff; xoff = tmp; break; default:; } xoff *= (double) dim.wd; yoff *= (double) (dim.ht + dim.dp); a[0] *= (double) dim.wd; a[1] *= (double) (dim.ht + dim.dp); a[2] *= (double) dim.wd; a[3] *= (double) (dim.ht + dim.dp); a[4] = (double) pos.h - xoff; a[5] = (double) pos.v - yoff; k = transform + img_rotation(idict); if ((transform & 7) > 3) k++; switch (k & 3) { case 0: /*tex No transform */ break; case 1: /*tex rotation over 90 degrees (counterclockwise) */ a[4] += (double) dim.wd; break; case 2: /*tex rotation over 180 degrees (counterclockwise) */ a[4] += (double) dim.wd; a[5] += (double) (dim.ht + dim.dp); break; case 3: /*tex rotation over 270 degrees (counterclockwise) */ a[5] += (double) (dim.ht + dim.dp); break; default:; } setpdffloat(cm[0], i64round(a[0]), r); setpdffloat(cm[1], i64round(a[1]), r); setpdffloat(cm[2], i64round(a[2]), r); setpdffloat(cm[3], i64round(a[3]), r); tmppos.h = round(a[4]); tmppos.v = round(a[5]); pdf_goto_pagemode(pdf); (void) calc_pdfpos(p, tmppos); cm[4] = p->cm[4]; cm[5] = p->cm[5]; if (pdf->img_page_group_val == 0) pdf->img_page_group_val = img_group_ref(idict); pdf_puts(pdf, "q\n"); pdf_print_cm(pdf, cm); pdf_puts(pdf, "/Im"); pdf_print_int(pdf, img_index(idict)); pdf_print_resname_prefix(pdf); pdf_puts(pdf, " Do\nQ\n"); addto_page_resources(pdf, obj_type_ximage, img_objnum(idict)); if (img_state(idict) < DICT_OUTIMG) img_state(idict) = DICT_OUTIMG; }
void read_img(image_dict * idict) { char *filepath = NULL; int callback_id; if (img_filename(idict) == NULL) { normal_error("pdf backend","image file name missing"); } callback_id = callback_defined(find_image_file_callback); if (img_filepath(idict) == NULL) { if (callback_id > 0) { /*tex We always callback, also for a mem stream. */ if (run_callback(callback_id, "S->S", img_filename(idict),&filepath)) { if (filepath && (strlen(filepath) > 0)) { img_filepath(idict) = strdup(filepath); } } } if (img_filepath(idict) == NULL && (strstr(img_filename(idict),"data:application/pdf,") != NULL)) { /*tex We need to check here for a pdf memstream. */ img_filepath(idict) = strdup(img_filename(idict)); } else if (callback_id == 0) { /*tex Otherwise we use kpse but only when we don't callback. */ img_filepath(idict) = kpse_find_file(img_filename(idict), kpse_tex_format, true); } if (img_filepath(idict) == NULL) { /*tex In any case we need a name. */ formatted_error("pdf backend","cannot find image file '%s'", img_filename(idict)); } } recorder_record_input(img_filepath(idict)); /*tex A few type checks. */ check_type_by_header(idict); check_type_by_extension(idict); /*tex Now we're ready to read the image. */ switch (img_type(idict)) { case IMG_TYPE_PDFMEMSTREAM: case IMG_TYPE_PDF: read_pdf_info(idict); break; case IMG_TYPE_PNG: read_png_info(idict); break; case IMG_TYPE_JPG: read_jpg_info(idict); break; case IMG_TYPE_JP2: read_jp2_info(idict); break; case IMG_TYPE_JBIG2: read_jbig2_info(idict); break; default: img_type(idict) = IMG_TYPE_NONE; if (pdf_ignore_unknown_images) { normal_warning("pdf backend","internal error: ignoring unknown image type"); } else { normal_error("pdf backend","internal error: unknown image type"); } break; } cur_file_name = NULL; if (img_type(idict) == IMG_TYPE_NONE) { img_state(idict) = DICT_NEW; } else if (img_state(idict) < DICT_FILESCANNED) { img_state(idict) = DICT_FILESCANNED; } }