diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2015-03-20 07:59:58 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2015-03-20 07:59:58 +0000 |
commit | 1c4d9737a17683a411b60f40cada6490e39d2b2c (patch) | |
tree | cb1682fccccf5d174a925337e76a267ac9a02489 /Build/source/texk/web2c/luatexdir/image | |
parent | 49256ac120db7b7f06e54a931701fe8b3d2b4bdb (diff) |
texk/web2c/luatexdir: Sync with luatex beta-0.80.0
git-svn-id: svn://tug.org/texlive/trunk@36570 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/image')
14 files changed, 174 insertions, 29 deletions
diff --git a/Build/source/texk/web2c/luatexdir/image/epdf.h b/Build/source/texk/web2c/luatexdir/image/epdf.h index 4982b6af10c..c0d17b29778 100644 --- a/Build/source/texk/web2c/luatexdir/image/epdf.h +++ b/Build/source/texk/web2c/luatexdir/image/epdf.h @@ -17,7 +17,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: epdf.h 5081 2014-11-07 18:38:33Z luigi $ */ // this is the common header file for C++ sources pdftoepdf.cc and lepdflib.cc diff --git a/Build/source/texk/web2c/luatexdir/image/image.h b/Build/source/texk/web2c/luatexdir/image/image.h index 0526b84ec57..32ead6a0f65 100644 --- a/Build/source/texk/web2c/luatexdir/image/image.h +++ b/Build/source/texk/web2c/luatexdir/image/image.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: image.h 4847 2014-03-05 18:13:17Z luigi $ */ #ifndef IMAGE_H # define IMAGE_H diff --git a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h index bbe4d3c8a63..4e2dc36717c 100644 --- a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h +++ b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: pdftoepdf.h 4351 2011-10-03 22:22:01Z hhenkel $ */ #ifndef PDFTOEPDF_H # define PDFTOEPDF_H diff --git a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w index 492492c5fd3..9c09a65f645 100644 --- a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w +++ b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.w @@ -19,9 +19,7 @@ % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. @ @c -static const char _svn_version[] = - "$Id: pdftoepdf.w 4847 2014-03-05 18:13:17Z luigi $" - "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/image/pdftoepdf.w $"; + // define DEBUG #define __STDC_FORMAT_MACROS /* for PRId64 etc. */ diff --git a/Build/source/texk/web2c/luatexdir/image/writeimg.h b/Build/source/texk/web2c/luatexdir/image/writeimg.h index 1cf6683856e..13f2d3642a5 100644 --- a/Build/source/texk/web2c/luatexdir/image/writeimg.h +++ b/Build/source/texk/web2c/luatexdir/image/writeimg.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: writeimg.h 4405 2012-05-07 21:16:45Z hhenkel $ */ #ifndef WRITEIMG_H # define WRITEIMG_H diff --git a/Build/source/texk/web2c/luatexdir/image/writeimg.w b/Build/source/texk/web2c/luatexdir/image/writeimg.w index e8a770684b5..3f6da1a4bee 100644 --- a/Build/source/texk/web2c/luatexdir/image/writeimg.w +++ b/Build/source/texk/web2c/luatexdir/image/writeimg.w @@ -21,9 +21,7 @@ @* Image inclusion. @ @c -static const char _svn_version[] = - "$Id: writeimg.w 4956 2014-03-28 12:12:17Z luigi $" - "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/image/writeimg.w $"; + #include "ptexlib.h" #include <assert.h> diff --git a/Build/source/texk/web2c/luatexdir/image/writejbig2.h b/Build/source/texk/web2c/luatexdir/image/writejbig2.h index 6609c2d2f99..95019b6c81b 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejbig2.h +++ b/Build/source/texk/web2c/luatexdir/image/writejbig2.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: writejbig2.h 4051 2011-01-09 22:41:33Z hhenkel $ */ #ifndef WRITEJBIG2_H # define WRITEJBIG2_H diff --git a/Build/source/texk/web2c/luatexdir/image/writejbig2.w b/Build/source/texk/web2c/luatexdir/image/writejbig2.w index 371e5452776..7b676fb6e87 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejbig2.w +++ b/Build/source/texk/web2c/luatexdir/image/writejbig2.w @@ -80,9 +80,7 @@ object exists, reference it. Else create fresh one. 09 Dec. 2002: JBIG2 seg. page numbers > 0 are now set to 1, see PDF Ref. @ @c -static const char _svn_version[] = - "$Id: writejbig2.w 4847 2014-03-05 18:13:17Z luigi $" - "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/image/writejbig2.w $"; + #undef DEBUG diff --git a/Build/source/texk/web2c/luatexdir/image/writejp2.h b/Build/source/texk/web2c/luatexdir/image/writejp2.h index 04e350f3c9e..ed9bbe47c72 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejp2.h +++ b/Build/source/texk/web2c/luatexdir/image/writejp2.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: writejp2.h 4060 2011-01-11 00:01:57Z hhenkel $ */ #ifndef WRITEJP2_H # define WRITEJP2_H diff --git a/Build/source/texk/web2c/luatexdir/image/writejp2.w b/Build/source/texk/web2c/luatexdir/image/writejp2.w index 61549a67738..8ea537e9f75 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejp2.w +++ b/Build/source/texk/web2c/luatexdir/image/writejp2.w @@ -19,9 +19,7 @@ % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. @ @c -static const char _svn_version[] = - "$Id: writejp2.w 4847 2014-03-05 18:13:17Z luigi $" - "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/image/writejp2.w $"; + @ Basic JPEG~2000 image support. Section and Table references below: Information technology --- JPEG~2000 image coding system: Core coding system. diff --git a/Build/source/texk/web2c/luatexdir/image/writejpg.h b/Build/source/texk/web2c/luatexdir/image/writejpg.h index d3c7cdb806a..8ef290d4746 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejpg.h +++ b/Build/source/texk/web2c/luatexdir/image/writejpg.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: writejpg.h 2653 2009-06-27 14:30:05Z taco $ */ #ifndef WRITEJPG_H # define WRITEJPG_H diff --git a/Build/source/texk/web2c/luatexdir/image/writejpg.w b/Build/source/texk/web2c/luatexdir/image/writejpg.w index 82091660418..cb4cd673ae8 100644 --- a/Build/source/texk/web2c/luatexdir/image/writejpg.w +++ b/Build/source/texk/web2c/luatexdir/image/writejpg.w @@ -19,9 +19,7 @@ % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. @ @c -static const char _svn_version[] = - "$Id: writejpg.w 4847 2014-03-05 18:13:17Z luigi $" - "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/image/writejpg.w $"; + #include "ptexlib.h" #include <assert.h> @@ -101,6 +99,152 @@ typedef enum { /* JPEG marker codes */ } JPEG_MARKER; @ @c +static unsigned char +myget_unsigned_byte (FILE *file) +{ + int ch; + ch = fgetc (file); + return (unsigned char) ch; +} + +@ @c +static unsigned short +myget_unsigned_pair (FILE *file) +{ + unsigned short pair = myget_unsigned_byte(file); + pair = (pair << 8) | myget_unsigned_byte(file); + return pair; +} + +@ @c +static unsigned int +read_exif_bytes(unsigned char **p, int n, int b) +{ + unsigned int rval = 0; + unsigned char *pp = *p; + if (b) { + switch (n) { + case 4: + rval += *pp++; rval <<= 8; + rval += *pp++; rval <<= 8; + case 2: + rval += *pp++; rval <<= 8; + rval += *pp; + break; + } + } else { + pp += n; + switch (n) { + case 4: + rval += *--pp; rval <<= 8; + rval += *--pp; rval <<= 8; + case 2: + rval += *--pp; rval <<= 8; + rval += *--pp; + break; + } + } + *p += n; + return rval; +} + +@ @c +static void +read_APP1_Exif (FILE *fp, unsigned short length, int *xx, int *yy) +{ + /* this doesn't save the data, just reads the tags we need */ + /* based on info from http://www.exif.org/Exif2-2.PDF */ + unsigned char *buffer = (unsigned char *)xmalloc(length); + unsigned char *p, *rp; + unsigned char *tiff_header; + char bigendian; + int i; + int num_fields, tag, type; + int value = 0, num = 0, den = 0; /* silence uninitialized warnings */ + double xres = 72.0; + double yres = 72.0; + double res_unit = 1.0; + fread(buffer, length, 1, fp); + p = buffer; + while ((p < buffer + length) && (*p == 0)) + ++p; + tiff_header = p; + if ((*p == 'M') && (*(p+1) == 'M')) + bigendian = 1; + else if ((*p == 'I') && (*(p+1) == 'I')) + bigendian = 0; + else + goto err; + p += 2; + i = read_exif_bytes(&p, 2, bigendian); + if (i != 42) + goto err; + i = read_exif_bytes(&p, 4, bigendian); + p = tiff_header + i; + num_fields = read_exif_bytes(&p, 2, bigendian); + while (num_fields-- > 0) { + tag = read_exif_bytes(&p, 2, bigendian); + type = read_exif_bytes(&p, 2, bigendian); + read_exif_bytes(&p, 4, bigendian); + switch (type) { + case 1: /* byte */ + value = *p++; + p += 3; + break; + case 3: /* short */ + value = read_exif_bytes(&p, 2, bigendian); + p += 2; + break; + case 4: /* long */ + case 9: /* slong */ + value = read_exif_bytes(&p, 4, bigendian); + break; + case 5: /* rational */ + case 10: /* srational */ + value = read_exif_bytes(&p, 4, bigendian); + rp = tiff_header + value; + num = read_exif_bytes(&rp, 4, bigendian); + den = read_exif_bytes(&rp, 4, bigendian); + break; + case 7: /* undefined */ + value = *p++; + p += 3; + break; + case 2: /* ascii */ + default: + p += 4; + break; + } + switch (tag) { + case 282: /* x res */ + if (den != 0) + xres = num / den; + break; + case 283: /* y res */ + if (den != 0) + yres = num / den; + break; + case 296: /* res unit */ + switch (value) { + case 2: + res_unit = 1.0; + break; + case 3: + res_unit = 2.54; + break; + } + } + } + + *xx = (int)(xres * res_unit); + *yy = (int)(yres * res_unit); + +err: + free(buffer); + return; +} + +@ @c static void close_and_cleanup_jpg(image_dict * idict) { assert(idict != NULL); @@ -116,6 +260,7 @@ static void close_and_cleanup_jpg(image_dict * idict) void read_jpg_info(PDF pdf, image_dict * idict, img_readtype_e readtype) { int i, units = 0; + unsigned short appmk, length; unsigned char jpg_id[] = "JFIF"; assert(idict != NULL); assert(img_type(idict) == IMG_TYPE_JPG); @@ -131,8 +276,9 @@ void read_jpg_info(PDF pdf, image_dict * idict, img_readtype_e readtype) xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); if ((unsigned int) read2bytes(img_file(idict)) != 0xFFD8) luatex_fail("reading JPEG image failed (no JPEG header found)"); - /* currently only true JFIF files allow extracting |img_xres| and |img_yres| */ - if ((unsigned int) read2bytes(img_file(idict)) == 0xFFE0) { /* check for JFIF */ + /* currently JFIF and Exif files allow extracting |img_xres| and |img_yres| */ + appmk = read2bytes(img_file(idict)); + if (appmk == 0xFFE0) { /* check for JFIF */ (void) read2bytes(img_file(idict)); for (i = 0; i < 5; i++) { if (xgetc(img_file(idict)) != jpg_id[i]) @@ -155,13 +301,30 @@ void read_jpg_info(PDF pdf, image_dict * idict, img_readtype_e readtype) break; } } - /* if either xres or yres is 0 but the other isn't, set it to the value of the other */ + /* if either xres or yres is 0 but the other isn't, + set it to the value of the other */ if ((img_xres(idict) == 0) && (img_yres(idict) != 0)) { img_xres(idict) = img_yres(idict); } if ((img_yres(idict) == 0) && (img_xres(idict) != 0)) { img_yres(idict) = img_xres(idict); } + } else if (appmk == 0xFFE1) { /* check for Exif */ + FILE *fp = img_file(idict); + int xxres = 0; + int yyres = 0; + char app_sig[32]; + length = myget_unsigned_pair(fp) - 2; + if (length > 5) { + if (fread(app_sig, sizeof(char), 5, fp) != 5) + return; + length -= 5; + if (!memcmp(app_sig, "Exif\000", 5)) { + read_APP1_Exif(fp, length, &xxres, &yyres); + } + } + img_xres(idict) = xxres; + img_yres(idict) = yyres; } xfseek(img_file(idict), 0, SEEK_SET, img_filepath(idict)); while (1) { diff --git a/Build/source/texk/web2c/luatexdir/image/writepng.h b/Build/source/texk/web2c/luatexdir/image/writepng.h index d728582014a..4dd425c0405 100644 --- a/Build/source/texk/web2c/luatexdir/image/writepng.h +++ b/Build/source/texk/web2c/luatexdir/image/writepng.h @@ -18,7 +18,6 @@ You should have received a copy of the GNU General Public License along with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */ -/* $Id: writepng.h 4227 2011-04-30 07:11:25Z oneiros $ */ #ifndef WRITEPNG_H # define WRITEPNG_H diff --git a/Build/source/texk/web2c/luatexdir/image/writepng.w b/Build/source/texk/web2c/luatexdir/image/writepng.w index 6b2ad9197fc..40f8e0e2635 100644 --- a/Build/source/texk/web2c/luatexdir/image/writepng.w +++ b/Build/source/texk/web2c/luatexdir/image/writepng.w @@ -19,9 +19,7 @@ % with LuaTeX; if not, see <http://www.gnu.org/licenses/>. @ @c -static const char _svn_version[] = - "$Id: writepng.w 5081 2014-11-07 18:38:33Z luigi $" - "$URL: https://foundry.supelec.fr/svn/luatex/trunk/source/texk/web2c/luatexdir/image/writepng.w $"; + #include "ptexlib.h" #include <assert.h> |