From 3dd4620522785049a6e43d8c2baf9cceb67680e1 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Tue, 24 Jan 2017 04:34:51 +0000 Subject: dvipdfm-x/jpegimage.c: Support Exif tags 0x5110, 0x5111 and 0x5112 in order to avoid warnings for some kind of jpeg images. Changes are borrowed from writejpg.w by Luigi. git-svn-id: svn://tug.org/texlive/trunk@43039 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/dvipdfm-x/jpegimage.c | 68 +++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 8 deletions(-) (limited to 'Build/source/texk/dvipdfm-x/jpegimage.c') diff --git a/Build/source/texk/dvipdfm-x/jpegimage.c b/Build/source/texk/dvipdfm-x/jpegimage.c index 18f6655fbd5..54857ea8a12 100644 --- a/Build/source/texk/dvipdfm-x/jpegimage.c +++ b/Build/source/texk/dvipdfm-x/jpegimage.c @@ -1,6 +1,6 @@ /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks. - Copyright (C) 2002-2016 by Jin-Hwan Cho and Shunsaku Hirata, + Copyright (C) 2002-2017 by Jin-Hwan Cho and Shunsaku Hirata, the dvipdfmx project team. Copyright (C) 1998, 1999 by Mark A. Wicks @@ -608,6 +608,9 @@ read_exif_bytes (unsigned char **pp, int n, int endian) #define JPEG_EXIF_TAG_XRESOLUTION 282 #define JPEG_EXIF_TAG_YRESOLUTION 283 #define JPEG_EXIF_TAG_RESOLUTIONUNIT 296 +#define JPEG_EXIF_TAG_RESUNIT_MS 0x5110 +#define JPEG_EXIF_TAG_XRES_MS 0x5111 +#define JPEG_EXIF_TAG_YRES_MS 0x5112 static size_t read_APP1_Exif (struct JPEG_info *j_info, FILE *fp, size_t length) { @@ -619,8 +622,12 @@ read_APP1_Exif (struct JPEG_info *j_info, FILE *fp, size_t length) int endian; int num_fields; int value = 0, offset; - double xres = 72.0, yres = 72.0; - double res_unit = 1.0; + double xres = 0.0, yres = 0.0; + double res_unit = 0.0; + unsigned int xres_ms = 0; + unsigned int yres_ms = 0; + double res_unit_ms = 0.0; + double exifxdpi = 0.0, exifydpi = 0.0; fread(buffer, length, 1, fp); if (length < 10) @@ -715,6 +722,34 @@ read_APP1_Exif (struct JPEG_info *j_info, FILE *fp, size_t length) else if (value == 3) res_unit = 2.54; /* cm */ break; + case JPEG_EXIF_TAG_RESUNIT_MS: /* PixelUnit */ + if (type != JPEG_EXIF_TYPE_BYTE || count != 1) { + WARN("%s: Invalid data for ResolutionUnit in Exif chunk.", JPEG_DEBUG_STR); + goto err; + } + value = read_exif_bytes(&p, 1, endian); + p += 3; + if (value == 1) + res_unit_ms = 0.0254; /* Unit is meter */ + else + res_unit_ms = 0.0; + break; + case JPEG_EXIF_TAG_XRES_MS: /* PixelPerUnitX */ + if (type != JPEG_EXIF_TYPE_LONG || count != 1) { + WARN("%s: Invalid data for PixelPerUnitX in Exif chunk.", JPEG_DEBUG_STR); + goto err; + } + value = read_exif_bytes(&p, 4, endian); + xres_ms = value; + break; + case JPEG_EXIF_TAG_YRES_MS: /* PixelPerUnitY */ + if (type != JPEG_EXIF_TYPE_LONG || count != 1) { + WARN("%s: Invalid data for PixelPerUnitY in Exif chunk.", JPEG_DEBUG_STR); + goto err; + } + value = read_exif_bytes(&p, 4, endian); + yres_ms = value; + break; default: /* 40901 ColorSpace and 42240 Gamma unsupported... */ p += 4; @@ -726,18 +761,35 @@ read_APP1_Exif (struct JPEG_info *j_info, FILE *fp, size_t length) goto err; } +/* Calculate Exif resolution, if given. + */ + if (xres > 0.0 && yres > 0.0) { + exifxdpi = xres * res_unit; + exifydpi = yres * res_unit; + } else if (xres_ms > 0 && yres_ms > 0 && res_unit_ms > 0.0) { + exifxdpi = xres_ms * res_unit_ms; + exifydpi = yres_ms * res_unit_ms; + } else { + exifxdpi = 72.0 * res_unit; + exifydpi = 72.0 * res_unit; + } + /* Do not overwrite j_info->xdpi and j_info->ydpi if they are * already determined in JFIF. */ if (j_info->xdpi < 0.1 && j_info->ydpi < 0.1) { - j_info->xdpi = xres * res_unit; - j_info->ydpi = yres * res_unit; + j_info->xdpi = exifxdpi; + j_info->ydpi = exifydpi; } else { - if (j_info->xdpi != xres * res_unit || - j_info->ydpi != yres * res_unit) { + double xxx1 = floor(exifxdpi+0.5); + double xxx2 = floor(j_info->xdpi+0.5); + double yyy1 = floor(exifydpi+0.5); + double yyy2 = floor(j_info->ydpi+0.5); + + if (xxx1 != xxx2 || yyy1 != yyy2) { WARN("%s: Inconsistent resolution may have " \ "specified in Exif and JFIF: %gx%g - %gx%g", JPEG_DEBUG_STR, - xres * res_unit, yres * res_unit, j_info->xdpi, j_info->ydpi); + xxx1, yyy1, xxx2, yyy2); } } -- cgit v1.2.3