diff options
author | Khaled Hosny <khaledhosny@eglug.org> | 2013-03-23 22:35:06 +0000 |
---|---|---|
committer | Khaled Hosny <khaledhosny@eglug.org> | 2013-03-23 22:35:06 +0000 |
commit | d965cf1c26b428c5f69f0fa925ef06e9e3d56fdf (patch) | |
tree | fccb6dc7deafcf204fb00b8611ef27547cafabb4 /Build/source/texk/web2c/xetexdir/image | |
parent | f9f93ae098d3cdbf7824cba24bcb9dc9ab87c0f3 (diff) |
XeTeX 0.9999.1
git-svn-id: svn://tug.org/texlive/trunk@29480 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/xetexdir/image')
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/README | 1 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/bmpimage.c | 202 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/bmpimage.h | 71 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/jpegimage.c | 553 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/jpegimage.h | 168 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/mfileio.c | 126 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/mfileio.h | 61 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/numbers.c | 227 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/numbers.h | 78 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/pngimage.c | 162 | ||||
-rw-r--r-- | Build/source/texk/web2c/xetexdir/image/pngimage.h | 71 |
11 files changed, 1720 insertions, 0 deletions
diff --git a/Build/source/texk/web2c/xetexdir/image/README b/Build/source/texk/web2c/xetexdir/image/README new file mode 100644 index 00000000000..744d2fa2ef4 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/README @@ -0,0 +1 @@ +The files in this directory are derived from DVIPDFMx project diff --git a/Build/source/texk/web2c/xetexdir/image/bmpimage.c b/Build/source/texk/web2c/xetexdir/image/bmpimage.c new file mode 100644 index 00000000000..27310327e36 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/bmpimage.c @@ -0,0 +1,202 @@ +/****************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\****************************************************************************/ + +/* this file is derived from the dvipdfmx project; + the original header follows... */ + +/* $Header: /home/cvsroot/dvipdfmx/src/bmpimage.c,v 1.2 2004/07/27 12:08:46 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +/* + * BMP SUPPORT: + */ + +#include "bmpimage.h" + +#define DIB_FILE_HEADER_SIZE 14 +#define DIB_CORE_HEADER_SIZE 14 +#define DIB_INFO_HEADER_SIZE 40 + +#define DIB_COMPRESS_NONE 0 +#define DIB_COMPRESS_RLE8 1 +#define DIB_COMPRESS_RLE4 2 + +#define DIB_HEADER_SIZE_MAX (DIB_FILE_HEADER_SIZE+DIB_INFO_HEADER_SIZE) + +static void +WARN(const char *fmt, ...) +{ + va_list argp; + + fprintf(stderr, "** WARNING ** "); + va_start(argp, fmt); + vfprintf(stderr, fmt, argp); + va_end(argp); + fprintf(stderr, "\n"); +} + +int +check_for_bmp (FILE *fp) +{ + unsigned char sigbytes[2]; + + if (!fp) + return 0; + + rewind(fp); + if (fread(sigbytes, 1, sizeof(sigbytes), fp) != sizeof(sigbytes) || + sigbytes[0] != 'B' || sigbytes[1] != 'M') + return 0; + else + return 1; + + return 0; +} + +int +bmp_scan_file(struct bmp_info *info, FILE *fp) +{ + unsigned char buf[DIB_HEADER_SIZE_MAX+4]; + unsigned char *p; + long offset, fsize, hsize, compression; + long psize; /* Bytes per palette color: 3 for OS2, 4 for Win */ + unsigned short bit_count; /* Bits per pix */ + int num_palette, flip; + int i; + unsigned long biXPelsPerMeter, biYPelsPerMeter; + + p = buf; + + rewind(fp); + if (fread(buf, 1, DIB_FILE_HEADER_SIZE + 4, fp) + != DIB_FILE_HEADER_SIZE + 4) { + WARN("Could not read BMP file header..."); + } + + if (p[0] != 'B' || p[1] != 'M') { + WARN("File not starting with \'B\' \'M\'... Not a BMP file?"); + return -1; + } + p += 2; + +#define ULONG_LE(b) ((b)[0] + ((b)[1] << 8) +\ + ((b)[2] << 16) + ((b)[3] << 24)) +#define USHORT_LE(b) ((b)[0] + ((b)[1] << 8)) + + fsize = ULONG_LE(p); p += 4; + if (ULONG_LE(p) != 0) { + WARN("Not a BMP file???"); + return -1; + } + p += 4; + offset = ULONG_LE(p); p += 4; + + /* info header */ + hsize = ULONG_LE(p); p += 4; + if (fread(p, sizeof(char), hsize - 4, fp) != hsize - 4) { + WARN("Could not read BMP file header..."); + return -1; + } + flip = 1; + if (hsize == DIB_CORE_HEADER_SIZE) { + info->width = USHORT_LE(p); p += 2; + info->height = USHORT_LE(p); p += 2; + if (USHORT_LE(p) != 1) { + WARN("Unknown bcPlanes value in BMP COREHEADER."); + return -1; + } + p += 2; + bit_count = USHORT_LE(p); p += 2; + compression = DIB_COMPRESS_NONE; + psize = 3; + } else if (hsize == DIB_INFO_HEADER_SIZE) { + info->width = ULONG_LE(p); p += 4; + info->height = ULONG_LE(p); p += 4; + if (USHORT_LE(p) != 1) { + WARN("Unknown biPlanes value in BMP INFOHEADER."); + return -1; + } + p += 2; + bit_count = USHORT_LE(p); p += 2; + compression = ULONG_LE(p); p += 4; + /* ignore biSizeImage */ p += 4; + biXPelsPerMeter = ULONG_LE(p); p += 4; + biYPelsPerMeter = ULONG_LE(p); p += 4; + info->xdpi = biXPelsPerMeter * 0.0254; /* convert pixels per meter to DPI */ + info->ydpi = biYPelsPerMeter * 0.0254; + if (info->height < 0) { + info->height = -info->height; + flip = 0; + } + psize = 4; + } else { + WARN("Unknown BMP header type."); + return -1; + } + + if (bit_count < 24) { + if (bit_count != 1 && + bit_count != 4 && bit_count != 8) { + WARN("Unsupported palette size: %ld", bit_count); + return -1; + } + num_palette = (offset - hsize - DIB_FILE_HEADER_SIZE) / psize; + info->bits_per_component = bit_count; + info->num_components = 1; + } else if (bit_count == 24) { /* full color */ + num_palette = 1; /* dummy */ + info->bits_per_component = 8; + info->num_components = 3; + } else { + WARN("Unkown BMP bitCount: %ld", bit_count); + return -1; + } + + if (info->width == 0 || info->height == 0 || num_palette < 1) { + WARN("Invalid BMP file: width=%ld, height=%ld, #palette=%d", + info->width, info->height, num_palette); + return -1; + } + + return 0; +} + diff --git a/Build/source/texk/web2c/xetexdir/image/bmpimage.h b/Build/source/texk/web2c/xetexdir/image/bmpimage.h new file mode 100644 index 00000000000..cef4f8b27ad --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/bmpimage.h @@ -0,0 +1,71 @@ +/****************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\****************************************************************************/ + +/* this file is derived from the dvipdfmx project; + the original header follows... */ + +/* $Header: /home/cvsroot/dvipdfmx/src/bmpimage.h,v 1.1 2004/07/25 11:54:20 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + + +#ifndef _BMPIMAGE_H_ +#define _BMPIMAGE_H_ + +#if HAVE_CONFIG_H +#include <w2c/config.h> +#endif + +#include "mfileio.h" + +struct bmp_info { + int width; + int height; + double xdpi; + double ydpi; + int bits_per_component; + int num_components; +}; + +extern int bmp_scan_file(struct bmp_info *info, FILE *file); +extern int check_for_bmp(FILE *file); + +#endif /* _BMPIMAGE_H_ */ diff --git a/Build/source/texk/web2c/xetexdir/image/jpegimage.c b/Build/source/texk/web2c/xetexdir/image/jpegimage.c new file mode 100644 index 00000000000..e35844785eb --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/jpegimage.c @@ -0,0 +1,553 @@ +/****************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2009 by SIL International + + SIL Author(s): Jonathan Kew + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\****************************************************************************/ + +/* this file is derived from the dvipdfmx project; + the original header follows... */ + +/* $Header: /home/cvsroot/dvipdfmx/src/jpegimage.c,v 1.8 2004/09/05 13:30:05 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + + +/* + * JPEG SUPPORT + * + * Accroding to Libjpeg document: + * + * CAUTION: it appears that Adobe Photoshop writes inverted data in CMYK + * JPEG files: 0 represents 100% ink coverage, rather than 0% ink as you'd + * expect.... + * + * To wrok with this problem, we must detect whether CMYK JPEG file is + * created by Photoshop. But there are no reliable way to determine this. + * + * According to Adobe Technical Note #5516, + * "Supporting the DCT Filters in PostScript Level 2", Section 18, p.27. + * + * DCTDecode ignores and skips any APPE marker segment does not begin with + * the `Adobe' 5-character string. + * + * PDF Reference Manual 4th ed., p.61-62. + * + * The JPEG filter implementation in Adobe Acrobat products does not + * support features of the JPEG standard that are irrelevant to images. + * In addition, certain choices have been made regarding reserved marker + * codes and other optional features of the standard. For details, see + * Adobe Technical Note #5116, Supporting the DCT Filters in PostScript + * Level 2. + */ + +#include "mfileio.h" +#include "numbers.h" + +#include "jpegimage.h" + +#include <stdlib.h> +#include <string.h> + +#include "kpathsea/lib.h" /* for xmalloc/xrealloc prototypes */ + +#define JPEG_DEBUG_STR "JPEG" +#define JPEG_DEBUG 3 + + +#define HAVE_APPn_JFIF (1 << 0) +#define HAVE_APPn_ADOBE (1 << 1) +#define HAVE_APPn_ICC (1 << 2) + +static void JPEG_info_init (struct JPEG_info *j_info); +static void JPEG_info_clear (struct JPEG_info *j_info); + +#define RELEASE(p) free(p) +#define NEW(n, t) (t*)xmalloc(n * sizeof(t)) +#define RENEW(p, n, t) ((p) ? (t*)xrealloc(p, (n) * sizeof(t)) : NEW(n, t)) + +int +check_for_jpeg (FILE *fp) +{ + unsigned char jpeg_sig[2]; + + rewind(fp); + if (fread(jpeg_sig, sizeof(unsigned char), 2, fp) != 2) + return 0; + else if (jpeg_sig[0] != 0xff || jpeg_sig[1] != JM_SOI) + return 0; + + return 1; +} + +static void +JPEG_info_init (struct JPEG_info *j_info) +{ + j_info->width = 0; + j_info->height = 0; + j_info->bits_per_component = 0; + j_info->num_components = 0; + + j_info->xdpi = 72.0; + j_info->ydpi = 72.0; + + j_info->flags = 0; + j_info->num_appn = 0; + j_info->max_appn = 0; + j_info->appn = NULL; + + memset(j_info->skipbits, 0, MAX_COUNT / 8 + 1); +} + +static void +JPEG_release_APPn_data (JPEG_marker marker, JPEG_APPn_sig app_sig, void *app_data) +{ + if (marker == JM_APP0 && + app_sig == JS_APPn_JFIF) { + struct JPEG_APPn_JFIF *data; + + data = (struct JPEG_APPn_JFIF *) app_data; + if (data->thumbnail) + RELEASE(data->thumbnail); + data->thumbnail = NULL; + + RELEASE(data); + } else if (marker == JM_APP2 && + app_sig == JS_APPn_ICC) { + struct JPEG_APPn_ICC *data; + + data = (struct JPEG_APPn_ICC *) app_data; + if (data->chunk) + RELEASE(data->chunk); + data->chunk = NULL; + + RELEASE(data); + } else if (marker == JM_APP14 && + app_sig == JS_APPn_ADOBE) { + struct JPEG_APPn_Adobe *data; + + data = (struct JPEG_APPn_Adobe *) app_data; + + RELEASE(data); + } +} + +static void +JPEG_info_clear (struct JPEG_info *j_info) +{ + if (j_info->num_appn > 0 && + j_info->appn != NULL) { + int i; + + for (i = 0; i < j_info->num_appn; i++) + JPEG_release_APPn_data(j_info->appn[i].marker, + j_info->appn[i].app_sig, j_info->appn[i].app_data); + RELEASE(j_info->appn); + } + j_info->appn = NULL; + j_info->num_appn = 0; + j_info->max_appn = 0; + j_info->flags = 0; +} + +static JPEG_marker +JPEG_get_marker (FILE *fp) +{ + int c; + + c = fgetc(fp); + if (c != 255) + return -1; + + for (;;) { + c = fgetc(fp); + if (c < 0) + return -1; + else if (c > 0 && c < 255) { + return c; + } + } + + return -1; +} + +static int +add_APPn_marker (struct JPEG_info *j_info, + JPEG_marker marker, int app_sig, void *app_data) +{ + int n; + + if (j_info->num_appn >= j_info->max_appn) { + j_info->max_appn += 16; + j_info->appn = RENEW(j_info->appn, j_info->max_appn, struct JPEG_ext); + } + n = j_info->num_appn; + + j_info->appn[n].marker = marker; + j_info->appn[n].app_sig = app_sig; + j_info->appn[n].app_data = app_data; + + j_info->num_appn += 1; + + return n; +} + +static unsigned short +read_APP14_Adobe (struct JPEG_info *j_info, FILE *fp, unsigned short length) +{ + struct JPEG_APPn_Adobe *app_data; + + app_data = NEW(1, struct JPEG_APPn_Adobe); + app_data->version = get_unsigned_pair(fp); + app_data->flag0 = get_unsigned_pair(fp); + app_data->flag1 = get_unsigned_pair(fp); + app_data->transform = get_unsigned_byte(fp); + + add_APPn_marker(j_info, JM_APP14, JS_APPn_ADOBE, app_data); + + return 7; +} + +static unsigned long +read_exif_bytes(unsigned char **p, int n, int b) +{ + unsigned long 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; +} + +static unsigned short +read_APP1_Exif (struct JPEG_info *j_info, FILE *fp, unsigned short length) +{ + /* 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 = NEW(length, unsigned char); + unsigned char *p, *rp; + unsigned char *tiff_header; + char bigendian; + int i; + double rational_value; + int num_fields, tag, type, count, value, num, den; + 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); + count = 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; + } + } + } + + + j_info->xdpi = xres * res_unit; + j_info->ydpi = yres * res_unit; + +err: + RELEASE(buffer); + return length; +} + +static unsigned short +read_APP0_JFIF (struct JPEG_info *j_info, FILE *fp, unsigned short length) +{ + struct JPEG_APPn_JFIF *app_data; + unsigned short thumb_data_len; + + app_data = NEW(1, struct JPEG_APPn_JFIF); + app_data->version = get_unsigned_pair(fp); + app_data->units = get_unsigned_byte(fp); + app_data->Xdensity = get_unsigned_pair(fp); + app_data->Ydensity = get_unsigned_pair(fp); + app_data->Xthumbnail = get_unsigned_byte(fp); + app_data->Ythumbnail = get_unsigned_byte(fp); + thumb_data_len = 3 * app_data->Xthumbnail * app_data->Ythumbnail; + if (thumb_data_len > 0) { + app_data->thumbnail = NEW(thumb_data_len, unsigned char); + fread(app_data->thumbnail, 1, thumb_data_len, fp); + } else { + app_data->thumbnail = NULL; + } + + add_APPn_marker(j_info, JM_APP0, JS_APPn_JFIF, app_data); + + switch (app_data->units) { + case 1: + j_info->xdpi = app_data->Xdensity; + j_info->ydpi = app_data->Ydensity; + break; + case 2: /* density is in pixels per cm */ + j_info->xdpi = app_data->Xdensity * 2.54; + j_info->ydpi = app_data->Ydensity * 2.54; + break; + default: /* FIXME: not sure what to do with this.... */ + j_info->xdpi = 72.0; + j_info->ydpi = 72.0 * app_data->Ydensity / app_data->Xdensity; + break; + } + + return (9 + thumb_data_len); +} + +static unsigned short +read_APP0_JFXX (struct JPEG_info *j_info, FILE *fp, unsigned short length) +{ + unsigned char extension_code; + + extension_code = get_unsigned_byte(fp); + /* Extension Code: + * + * 0x10: Thumbnail coded using JPEG + * 0x11: Thumbnail stored using 1 byte/pixel + * 0x13: Thumbnail stored using 3 bytes/pixel + */ + seek_relative(fp, length-1); /* Thunbnail image */ + + /* Ignore */ + + return length; +} + +static unsigned short +read_APP2_ICC (struct JPEG_info *j_info, FILE *fp, unsigned short length) +{ + struct JPEG_APPn_ICC *app_data; + + app_data = NEW(1, struct JPEG_APPn_ICC); + app_data->seq_id = get_unsigned_byte(fp); /* Starting at 1 */ + app_data->num_chunks = get_unsigned_byte(fp); + app_data->length = length - 2; + app_data->chunk = NEW(app_data->length, unsigned char); + fread(app_data->chunk, 1, app_data->length, fp); + + add_APPn_marker(j_info, JM_APP2, JS_APPn_ICC, app_data); + + return length; +} + + +int +JPEG_scan_file (struct JPEG_info *j_info, FILE *fp) +{ + JPEG_marker marker; + unsigned short length; + int found_SOFn, count; + char app_sig[128]; + + JPEG_info_init(j_info); + + rewind(fp); + count = 0; + found_SOFn = 0; + while (!found_SOFn && + (marker = JPEG_get_marker(fp)) >= 0) { + if (marker == JM_SOI || + (marker >= JM_RST0 && marker <= JM_RST7)) { + count++; + continue; + } + length = get_unsigned_pair(fp) - 2; + switch (marker) { + case JM_SOF0: case JM_SOF1: case JM_SOF2: case JM_SOF3: + case JM_SOF5: case JM_SOF6: case JM_SOF7: case JM_SOF9: + case JM_SOF10: case JM_SOF11: case JM_SOF13: case JM_SOF14: + case JM_SOF15: + j_info->bits_per_component = get_unsigned_byte(fp); + j_info->height = get_unsigned_pair(fp); + j_info->width = get_unsigned_pair(fp); + j_info->num_components = get_unsigned_byte(fp); + found_SOFn = 1; + break; + case JM_APP0: + if (length > 5) { + if (fread(app_sig, sizeof(char), 5, fp) != 5) + return -1; + length -= 5; + if (!memcmp(app_sig, "JFIF\000", 5)) { + j_info->flags |= HAVE_APPn_JFIF; + length -= read_APP0_JFIF(j_info, fp, length); + } else if (!memcmp(app_sig, "JFXX", 5)) { + length -= read_APP0_JFXX(j_info, fp, length); + } + } + seek_relative(fp, length); + break; + case JM_APP1: + if (length > 5) { + if (fread(app_sig, sizeof(char), 5, fp) != 5) + return -1; + length -= 5; + if (!memcmp(app_sig, "Exif\000", 5)) { + length -= read_APP1_Exif(j_info, fp, length); + } + } + seek_relative(fp, length); + break; + case JM_APP2: + if (length >= 14) { + if (fread(app_sig, sizeof(char), 12, fp) != 12) + return -1; + length -= 12; + if (!memcmp(app_sig, "ICC_PROFILE\000", 12)) { + j_info->flags |= HAVE_APPn_ICC; + length -= read_APP2_ICC(j_info, fp, length); + if (count < MAX_COUNT) { + j_info->skipbits[count / 8] |= (1 << (7 - (count % 8))); + } + } + } + seek_relative(fp, length); + break; + case JM_APP14: + if (length > 5) { + if (fread(app_sig, sizeof(char), 5, fp) != 5) + return -1; + length -= 5; + if (!memcmp(app_sig, "Adobe", 5)) { + j_info->flags |= HAVE_APPn_ADOBE; + length -= read_APP14_Adobe(j_info, fp, length); + } else { + if (count < MAX_COUNT) { + j_info->skipbits[count/8] |= (1 << (7 - (count % 8))); + } + } + } + seek_relative(fp, length); + break; + default: + seek_relative(fp, length); + if (marker >= JM_APP0 && + marker <= JM_APP15) { + if (count < MAX_COUNT) { + j_info->skipbits[count / 8] |= (1 << (7 - (count % 8))); + } + } + break; + } + count++; + } + + return (found_SOFn ? 0 : -1); +} diff --git a/Build/source/texk/web2c/xetexdir/image/jpegimage.h b/Build/source/texk/web2c/xetexdir/image/jpegimage.h new file mode 100644 index 00000000000..432cef96546 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/jpegimage.h @@ -0,0 +1,168 @@ +/****************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\****************************************************************************/ + +/* this file is derived from the dvipdfmx project; + the original header follows... */ + +/* $Header: /home/cvsroot/dvipdfmx/src/jpegimage.h,v 1.2 2004/03/11 11:50:21 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _JPEGIMAGE_H_ +#define _JPEGIMAGE_H_ + +#include "mfileio.h" + +/* JPEG Markers */ +typedef enum { + JM_SOF0 = 0xc0, + JM_SOF1 = 0xc1, + JM_SOF2 = 0xc2, + JM_SOF3 = 0xc3, + JM_SOF5 = 0xc5, + JM_DHT = 0xc4, + JM_SOF6 = 0xc6, + JM_SOF7 = 0xc7, + JM_SOF9 = 0xc9, + JM_SOF10 = 0xca, + JM_SOF11 = 0xcb, + JM_DAC = 0xcc, + JM_SOF13 = 0xcd, + JM_SOF14 = 0xce, + JM_SOF15 = 0xcf, + + JM_RST0 = 0xd0, + JM_RST1 = 0xd1, + JM_RST2 = 0xd2, + JM_RST3 = 0xd3, + JM_RST4 = 0xd4, + JM_RST5 = 0xd5, + JM_RST6 = 0xd6, + JM_RST7 = 0xd7, + + JM_SOI = 0xd8, + JM_EOI = 0xd9, + JM_SOS = 0xda, + JM_DQT = 0xdb, + JM_DNL = 0xdc, + JM_DRI = 0xdd, + JM_DHP = 0xde, + JM_EXP = 0xdf, + + JM_APP0 = 0xe0, + JM_APP1 = 0xe1, + JM_APP2 = 0xe2, + JM_APP14 = 0xee, + JM_APP15 = 0xef, + + JM_COM = 0xfe +} JPEG_marker; + +typedef enum { + JS_APPn_JFIF, + JS_APPn_ADOBE, + JS_APPn_ICC +} JPEG_APPn_sig; + +struct JPEG_APPn_JFIF /* APP0 */ +{ + unsigned short version; + unsigned char units; /* 0: only aspect ratio + * 1: dots per inch + * 2: dots per cm + */ + unsigned short Xdensity; + unsigned short Ydensity; + unsigned char Xthumbnail; + unsigned char Ythumbnail; + unsigned char *thumbnail; /* Thumbnail data. */ +}; + +struct JPEG_APPn_ICC /* APP2 */ +{ + unsigned char seq_id; + unsigned char num_chunks; + unsigned char *chunk; + + /* Length of ICC profile data in this chunk. */ + unsigned short length; +}; + +struct JPEG_APPn_Adobe /* APP14 */ +{ + unsigned short version; + unsigned short flag0; + unsigned short flag1; + unsigned char transform; /* color transform code */ +}; + +struct JPEG_ext +{ + JPEG_marker marker; + JPEG_APPn_sig app_sig; + void *app_data; +}; + +#define MAX_COUNT 1024 +struct JPEG_info +{ + unsigned short height; + unsigned short width; + + unsigned char bits_per_component; + unsigned char num_components; + + double xdpi; + double ydpi; + + /* Application specific extensions */ + int flags; + int num_appn, max_appn; + struct JPEG_ext *appn; + + /* Skip chunks not necessary. */ + char skipbits[MAX_COUNT / 8 + 1]; +}; + +extern int check_for_jpeg(FILE *fp); +extern int JPEG_scan_file(struct JPEG_info *info, FILE *fp); + +#endif /* _JPEGIMAGE_H_ */ diff --git a/Build/source/texk/web2c/xetexdir/image/mfileio.c b/Build/source/texk/web2c/xetexdir/image/mfileio.c new file mode 100644 index 00000000000..e6c1a229850 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/mfileio.c @@ -0,0 +1,126 @@ +/* $Header: /home/cvsroot/dvipdfmx/src/mfileio.c,v 1.3 2002/10/30 02:27:11 chofchof Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#include <stdio.h> +#include <stdlib.h> +#include "mfileio.h" + +#ifdef IODEBUG +static FILE *iodebug_file = NULL; +static long event = 0; +static void io_debug_init(void) +{ + if (!iodebug_file) { + iodebug_file = fopen ("fopen.log", "wb"); + fprintf (stderr, "\n*** File IO debugging started ***\n"); + } + if (!iodebug_file) { + fprintf (stderr, "\nError opening io log\n"); + } +} +#endif + +#ifdef IODEBUG +FILE *mfopen(const char *name, const char *mode, const char *function, int line) +{ + FILE *tmp; + io_debug_init(); + tmp = fopen (name, mode); + event += 1; + fprintf(iodebug_file, "%p %07ld [fopen] %s:%d\n", tmp, event, + function, line); + return tmp; +} +int mfclose(FILE *file, const char *function, int line) +{ + io_debug_init(); + event += 1; + fprintf(iodebug_file, "%p %07ld [fclose] %s:%d\n", file, event, + function, line); + return fclose(file); +} +#endif + +static void os_error() +{ + fprintf (stderr, "io: An OS command failed that should not have.\n"); + exit(-1); +} + +void seek_absolute (FILE *file, long pos) +{ + if (fseek(file, pos, SEEK_SET)) { + os_error(); + } +} + +void seek_relative (FILE *file, long pos) +{ + if (fseek(file, pos, SEEK_CUR)) { + os_error(); + } +} + + +void seek_end (FILE *file) +{ + if (fseek(file, 0L, SEEK_END)) { + os_error(); + } +} + +long tell_position (FILE *file) +{ + long size; + if ((size = ftell (file)) < 0) { + os_error(); + } + return size; +} + +long file_size (FILE *file) +{ + long size; + /* Seek to end */ + seek_end (file); + size = tell_position (file); + rewind (file); + return (size); +} + +/* Unlike fgets, mfgets works with \r, \n, or \r\n end of lines. */ +char *mfgets (char *buffer, unsigned long length, FILE *file) +{ + int ch = 0, i = 0; + while (i < length-1 && (ch = fgetc (file)) >= 0 && ch != '\n' && ch != '\r') + buffer[i++] = ch; + buffer[i] = 0; + if (ch < 0 && i == 0) + return NULL; + if (ch == '\r' && (ch = fgetc (file)) >= 0 && (ch != '\n')) + ungetc (ch, file); + return buffer; +} + +char work_buffer[WORK_BUFFER_SIZE]; diff --git a/Build/source/texk/web2c/xetexdir/image/mfileio.h b/Build/source/texk/web2c/xetexdir/image/mfileio.h new file mode 100644 index 00000000000..e31fef23244 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/mfileio.h @@ -0,0 +1,61 @@ +/* $Header: /home/cvsroot/dvipdfmx/src/mfileio.h,v 1.3 2002/10/30 02:27:12 chofchof Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _MFILEIO_H_ +#define _MFILEIO_H_ + +#include <stdio.h> +#include "numbers.h" + +#ifdef IODEBUG +FILE *mfopen (const char *name, const char *mode, + const char *function, int line); +int mfclose (FILE *file, const char *function, int line); +#define MFOPEN(name,mode) \ + mfopen((name),(mode),__FUNCTION__,__LINE__) +#define MFCLOSE(file) \ + mfclose((file),__FUNCTION__,__LINE__) +#else +#define MFOPEN(name,mode) fopen((name),(mode)) +#define MFCLOSE(file) fclose(file) +#endif + +extern UNSIGNED_BYTE read_byte (FILE *); + +extern void seek_absolute (FILE *file, long pos); +extern void seek_relative (FILE *file, long pos); + +extern void seek_end (FILE *file); + +extern long tell_position (FILE *file); + +extern long file_size (FILE *file); + +extern char *mfgets (char *buffer, unsigned long size, FILE *file); + +extern char work_buffer[]; + +#define WORK_BUFFER_SIZE 1024 + +#endif /* _MFILEIO_H_ */ diff --git a/Build/source/texk/web2c/xetexdir/image/numbers.c b/Build/source/texk/web2c/xetexdir/image/numbers.c new file mode 100644 index 00000000000..06864f1e2bb --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/numbers.c @@ -0,0 +1,227 @@ +/* $Header: /home/cvsroot/dvipdfmx/src/numbers.c,v 1.8 2004/03/03 13:19:00 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#include <stdlib.h> + +#include "mfileio.h" +#include "numbers.h" + +UNSIGNED_BYTE get_unsigned_byte (FILE *file) +{ + int ch; + if ((ch = fgetc (file)) < 0) { + fprintf (stderr, "File ended prematurely\n"); + exit(-1); + } + return (UNSIGNED_BYTE) ch; +} + +UNSIGNED_BYTE sget_unsigned_byte (char *s) +{ + return *((unsigned char *) s); +} + +SIGNED_BYTE get_signed_byte (FILE *file) +{ + int byte; + byte = get_unsigned_byte(file); + if (byte >= 0x80) + byte -= 0x100; + return (SIGNED_BYTE) byte; +} + +UNSIGNED_PAIR get_unsigned_pair (FILE *file) +{ + int i; + UNSIGNED_BYTE byte; + UNSIGNED_PAIR pair = 0; + for (i=0; i<2; i++) { + byte = get_unsigned_byte(file); + pair = pair*0x100u + byte; + } + return pair; +} + +UNSIGNED_PAIR sget_unsigned_pair (unsigned char *s) +{ + int i; + UNSIGNED_BYTE byte; + UNSIGNED_PAIR pair = 0; + for (i=0; i<2; i++) { + byte = *(s++); + pair = pair*0x100u + byte; + } + return pair; +} + +SIGNED_PAIR get_signed_pair (FILE *file) +{ + int i; + long pair = 0; + for (i=0; i<2; i++) { + pair = pair*0x100 + get_unsigned_byte(file); + } + if (pair >= 0x8000) { + pair -= 0x10000l; + } + return (SIGNED_PAIR) pair; +} + + +UNSIGNED_TRIPLE get_unsigned_triple(FILE *file) +{ + int i; + long triple = 0; + for (i=0; i<3; i++) { + triple = triple*0x100u + get_unsigned_byte(file); + } + return (UNSIGNED_TRIPLE) triple; +} + +SIGNED_TRIPLE get_signed_triple(FILE *file) +{ + int i; + long triple = 0; + for (i=0; i<3; i++) { + triple = triple*0x100 + get_unsigned_byte(file); + } + if (triple >= 0x800000l) + triple -= 0x1000000l; + return (SIGNED_TRIPLE) triple; +} + +SIGNED_QUAD get_signed_quad(FILE *file) +{ + int byte, i; + long quad = 0; + + /* Check sign on first byte before reading others */ + byte = get_unsigned_byte(file); + quad = byte; + if (quad >= 0x80) + quad = byte - 0x100; + for (i=0; i<3; i++) { + quad = quad*0x100 + get_unsigned_byte(file); + } + return (SIGNED_QUAD) quad; +} + +UNSIGNED_QUAD get_unsigned_quad(FILE *file) +{ + int i; + unsigned long quad = 0; + for (i=0; i<4; i++) { + quad = quad*0x100u + get_unsigned_byte(file); + } + return (UNSIGNED_QUAD) quad; +} + +#if 0 +SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw) +{ + int sign = 1; + unsigned long a, b, c, d, ad, bd, bc, ac; + unsigned long e, f, g, h, i, j, k; + unsigned long result; + /* Make positive. */ + if (sq < 0) { + sign = -sign; + sq = -sq; + } + if (fw < 0) { + sign = -sign; + fw = -fw; + } + a = ((unsigned long) sq) >> 16u; + b = ((unsigned long) sq) & 0xffffu; + c = ((unsigned long) fw) >> 16u; + d = ((unsigned long) fw) & 0xffffu; + ad = a*d; bd = b*d; bc = b*c; ac = a*c; + e = bd >> 16u; + f = ad >> 16u; + g = ad & 0xffffu; + h = bc >> 16u; + i = bc & 0xffffu; + j = ac >> 16u; + k = ac & 0xffffu; + result = (e+g+i + (1<<3)) >> 4u; /* 1<<3 is for rounding */ + result += (f+h+k) << 12u; + result += j << 28u; + return (sign > 0) ? result : result * -1L; +} + +SIGNED_QUAD axboverc (SIGNED_QUAD n1, SIGNED_QUAD n2, SIGNED_QUAD divide) +{ + int sign = 1; + unsigned long a, b, c, d, ad, bd, bc, ac, e, f, g, h, i, j, o; + unsigned long high, low; + SIGNED_QUAD result = 0; + /* Make positive. */ + if (n1 < 0) { + sign = -sign; + n1 = -n1; + } + if (n2 < 0) { + sign = -sign; + n2 = -n2; + } + if (divide < 0) { + sign = -sign; + divide = -divide; + } + a = ((unsigned long) n1) >> 16u; + b = ((unsigned long) n1) & 0xffffu; + c = ((unsigned long) n2) >> 16u; + d = ((unsigned long) n2) & 0xffffu; + ad = a*d; bd = b*d; bc = b*c; ac = a*c; + e = bd >> 16u; f = bd & 0xffffu; + g = ad >> 16u; h = ad & 0xffffu; + i = bc >> 16u; j = bc & 0xffffu; + o = e+h+j; + high = g+i+(o>>16u)+ac; o &= 0xffffu; + low = (o << 16) + f; + if (high >= divide) + ERROR ("Overflow in axboc"); + { + int k; + for (k=0; k<32; k++) { + high *= 2; + result *= 2; + if (low >= 0x80000000) { + low -= 0x80000000; + high += 1; + } + low *= 2; + if (high > divide) { + high -= divide; + result += 1; + } + } + } + high *= 2; + if (high >= divide) + result += 1; + return (sign>0)?result:-result; +} +#endif diff --git a/Build/source/texk/web2c/xetexdir/image/numbers.h b/Build/source/texk/web2c/xetexdir/image/numbers.h new file mode 100644 index 00000000000..1f61607654e --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/numbers.h @@ -0,0 +1,78 @@ +/* $Header: /home/cvsroot/dvipdfmx/src/numbers.h,v 1.9 2005/07/20 10:41:54 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002, 2012 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#ifndef _NUMBERS_H_ +#define _NUMBERS_H_ + +#include <stdio.h> +#include <math.h> + +typedef unsigned char Ubyte; +typedef int UNSIGNED_BYTE, SIGNED_BYTE, SIGNED_PAIR; +typedef unsigned UNSIGNED_PAIR; +typedef long UNSIGNED_TRIPLE, SIGNED_TRIPLE, SIGNED_QUAD; +typedef unsigned long UNSIGNED_QUAD; + +extern UNSIGNED_BYTE get_unsigned_byte (FILE *); +extern UNSIGNED_BYTE sget_unsigned_byte (char *); +extern SIGNED_BYTE get_signed_byte (FILE *); +extern UNSIGNED_PAIR get_unsigned_pair (FILE *); +extern UNSIGNED_PAIR sget_unsigned_pair (unsigned char *); +extern SIGNED_PAIR get_signed_pair (FILE *); +extern UNSIGNED_TRIPLE get_unsigned_triple (FILE *); +extern SIGNED_TRIPLE get_signed_triple (FILE *); +extern SIGNED_QUAD get_signed_quad (FILE *); +extern UNSIGNED_QUAD get_unsigned_quad (FILE *); + +typedef signed long fixword; + +extern SIGNED_QUAD sqxfw (SIGNED_QUAD sq, fixword fw); +extern SIGNED_QUAD axboverc (SIGNED_QUAD n1, SIGNED_QUAD n2, SIGNED_QUAD divide); + +#ifndef MAX +# define MAX(a,b) ((a)>(b)?(a):(b)) +#endif +#ifndef MIN +# define MIN(a,b) ((a)<(b)?(a):(b)) +#endif +#define ISODD(n) (((n)/2)*2!=(n)) +#define ISEVEN(n) (((n)/2)*2==(n)) + +#define ROUND(n,acc) (floor(((double)n)/(acc)+0.5)*(acc)) + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L +# define __C99__ +#endif + +#ifndef __C99__ +# ifndef round +# define round(v) (floor((v) + 0.5)) +# endif +# ifndef trunc +# define trunc(v) ((v) > 0.0 ? floor((v)) : ceil((v))) +# endif +#endif +#define round_at(v,acc) (round(((double)(v))/(acc))*(acc)) + +#endif /* _NUMBERS_H_ */ diff --git a/Build/source/texk/web2c/xetexdir/image/pngimage.c b/Build/source/texk/web2c/xetexdir/image/pngimage.c new file mode 100644 index 00000000000..42279345881 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/pngimage.c @@ -0,0 +1,162 @@ +/****************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\****************************************************************************/ + +/* this file is derived from the dvipdfmx project; + the original header follows... */ + +/* $Header: /home/cvsroot/dvipdfmx/src/pngimage.c,v 1.24 2004/09/11 14:50:29 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + +#if HAVE_CONFIG_H +#include <w2c/config.h> +#endif + +/* + * PNG SUPPORT + * + * All bitdepth less than 16 is supported. + * Supported color types are: PALETTE, RGB, GRAY, RGB_ALPHA, GRAY_ALPHA. + * Supported ancillary chunks: tRNS, cHRM + gAMA, (sRGB), (iCCP) + * + * gAMA support is available only when cHRM exists. cHRM support is not + * tested well. CalRGB/CalGray colorspace is used for PNG images that + * have cHRM chunk (but not sRGB). + * + * LIMITATIONS + * + * Recent version of PDF (>= 1.5) support 16 bpc, but 16 bit bitdepth PNG + * images are automatically converted to 8 bit bitpedth image. + * + * TODO + * + * sBIT ? iTXT, tEXT and tIME as MetaData ?, pHYS (see below) + * 16 bpc support for PDF-1.5. JBIG compression for monochrome image. + * Predictor for deflate ? + */ + +#define PNG_DEBUG_STR "PNG" +#define PNG_DEBUG 3 + +/* + * Write, MNG, Progressive not required. + */ +#define PNG_NO_WRITE_SUPPORTED +#define PNG_NO_MNG_FEATURES +#define PNG_NO_PROGRESSIVE_READ +#if 0 +/* 16_TO_8 required. */ +#define PNG_NO_READ_TRANSFORMS +#endif + +#include <png.h> +#include "pngimage.h" + +#define PDF_TRANS_TYPE_NONE 0 +#define PDF_TRANS_TYPE_BINARY 1 +#define PDF_TRANS_TYPE_ALPHA 2 + +int +check_for_png (FILE *png_file) +{ + unsigned char sigbytes[4]; + + rewind (png_file); + if (fread (sigbytes, 1, sizeof(sigbytes), png_file) != + sizeof(sigbytes) || + (png_sig_cmp (sigbytes, 0, sizeof(sigbytes)))) + return 0; + else + return 1; +} + +int +png_scan_file (struct png_info *info, FILE *png_file) +{ + png_bytep stream_data_ptr; + int trans_type; + /* Libpng stuff */ + png_structp png_ptr; + png_infop png_info_ptr; + png_byte bpc, color_type; + png_uint_32 width, height, rowbytes; + + rewind (png_file); + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (png_ptr == NULL || + (png_info_ptr = png_create_info_struct (png_ptr)) == NULL) { + fprintf(stderr, "WARNING: %s: Creating Libpng read/info struct failed.", PNG_DEBUG_STR); + if (png_ptr) + png_destroy_read_struct(&png_ptr, NULL, NULL); + return -1; + } + + /* Inititializing file IO. */ + png_init_io (png_ptr, png_file); + + /* Read PNG info-header and get some info. */ + png_read_info(png_ptr, png_info_ptr); + color_type = png_get_color_type (png_ptr, png_info_ptr); + width = png_get_image_width (png_ptr, png_info_ptr); + height = png_get_image_height(png_ptr, png_info_ptr); + bpc = png_get_bit_depth (png_ptr, png_info_ptr); + + info->xdpi = png_get_x_pixels_per_meter(png_ptr, png_info_ptr) * 0.0254; + info->ydpi = png_get_y_pixels_per_meter(png_ptr, png_info_ptr) * 0.0254; + + if (info->xdpi == 0) + info->xdpi = 72; + if (info->ydpi == 0) + info->ydpi = 72; + + /* Values listed below will not be modified in the remaining process. */ + info->width = width; + info->height = height; + info->bits_per_component = bpc; + + /* Cleanup */ + if (png_info_ptr) + png_destroy_info_struct(png_ptr, &png_info_ptr); + if (png_ptr) + png_destroy_read_struct(&png_ptr, NULL, NULL); + + return 0; +} diff --git a/Build/source/texk/web2c/xetexdir/image/pngimage.h b/Build/source/texk/web2c/xetexdir/image/pngimage.h new file mode 100644 index 00000000000..a908244da08 --- /dev/null +++ b/Build/source/texk/web2c/xetexdir/image/pngimage.h @@ -0,0 +1,71 @@ +/****************************************************************************\ + Part of the XeTeX typesetting system + Copyright (c) 1994-2006 by SIL International + + SIL Author(s): Jonathan Kew + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +\****************************************************************************/ + +/* this file is derived from the dvipdfmx project; + the original header follows... */ + +/* $Header: /home/cvsroot/dvipdfmx/src/pngimage.h,v 1.4 2004/03/11 11:50:25 hirata Exp $ + + This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. + + Copyright (C) 2002 by Jin-Hwan Cho and Shunsaku Hirata, + the dvipdfmx project team <dvipdfmx@project.ktug.or.kr> + + Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. +*/ + + +#ifndef _PNGIMAGE_H_ +#define _PNGIMAGE_H_ + +#if HAVE_CONFIG_H +#include <w2c/config.h> +#endif + +#include "mfileio.h" + +struct png_info { + int width; + int height; + double xdpi; + double ydpi; + int bits_per_component; + int num_components; +}; + +extern int png_scan_file (struct png_info *info, FILE *file); +extern int check_for_png (FILE *file); + +#endif /* _PNGIMAGE_H_ */ |