From: Cristy Date: Sun, 2 Apr 2017 15:59:59 +0000 (-0400) Subject: https://github.com/ImageMagick/ImageMagick/issues/417 X-Git-Tag: 7.0.5-5~62 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa88fe8cff496362d2c0548ea9e82817424502bd;p=imagemagick https://github.com/ImageMagick/ImageMagick/issues/417 --- diff --git a/ChangeLog b/ChangeLog index 35d23a055..17419d29a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,8 @@ https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31650). * Patch two PCD writer problems, corrupt output and dark pixels (reference https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=3164). + * Support ICC based PDF's (reference + https://github.com/ImageMagick/ImageMagick/issues/417). 2017-03-24 7.0.5-4 Cristy * Release ImageMagick version 7.0.5-4, GIT revision 19754:350fff3:20170324. diff --git a/coders/pdf.c b/coders/pdf.c index d4a932600..221be1c20 100644 --- a/coders/pdf.c +++ b/coders/pdf.c @@ -1053,8 +1053,8 @@ static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16) return(0); q++; } - *q++='\0'; - return(q-utf16); + *q++=(wchar_t) '\0'; + return((size_t) (q-utf16)); } /* Compute UTF-16 string length. @@ -1083,7 +1083,7 @@ static size_t UTF8ToUTF16(const unsigned char *utf8,wchar_t *utf16) else return(0); } - return(p-utf8); + return((size_t) (p-utf8)); } static wchar_t *ConvertUTF8ToUTF16(const unsigned char *source,size_t *length) @@ -1215,9 +1215,13 @@ RestoreMSCWarning compression; const char + *device, *option, *value; + const StringInfo + *profile; + double pointsize; @@ -1263,6 +1267,7 @@ RestoreMSCWarning x; size_t + channels, info_id, length, object, @@ -1615,8 +1620,8 @@ RestoreMSCWarning (void) FormatLocaleString(buffer,MagickPathExtent,"/Contents %.20g 0 R\n", (double) object+1); (void) WriteBlobString(image,buffer); - (void) FormatLocaleString(buffer,MagickPathExtent,"/Thumb %.20g 0 R\n",(double) - object+8); + (void) FormatLocaleString(buffer,MagickPathExtent,"/Thumb %.20g 0 R\n", + (double) object+8); (void) WriteBlobString(image,buffer); (void) WriteBlobString(image,">>\n"); (void) WriteBlobString(image,"endobj\n"); @@ -1670,8 +1675,8 @@ RestoreMSCWarning (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g 0 obj\n",(double) object); (void) WriteBlobString(image,buffer); - (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g\n", - (double) offset); + (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g\n",(double) + offset); (void) WriteBlobString(image,buffer); (void) WriteBlobString(image,"endobj\n"); /* @@ -1722,14 +1727,15 @@ RestoreMSCWarning (void) WriteBlobString(image,"<<\n"); (void) WriteBlobString(image,"/Type /XObject\n"); (void) WriteBlobString(image,"/Subtype /Image\n"); - (void) FormatLocaleString(buffer,MagickPathExtent,"/Name /Im%.20g\n",(double) - image->scene); + (void) FormatLocaleString(buffer,MagickPathExtent,"/Name /Im%.20g\n", + (double) image->scene); (void) WriteBlobString(image,buffer); switch (compression) { case NoCompression: { - (void) FormatLocaleString(buffer,MagickPathExtent,CFormat,"ASCII85Decode"); + (void) FormatLocaleString(buffer,MagickPathExtent,CFormat, + "ASCII85Decode"); break; } case JPEGCompression: @@ -2158,24 +2164,68 @@ RestoreMSCWarning (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g 0 obj\n",(double) object); (void) WriteBlobString(image,buffer); + channels=0; if (image->colorspace == CMYKColorspace) - (void) CopyMagickString(buffer,"/DeviceCMYK\n",MagickPathExtent); + { + device="DeviceCMYK"; + channels=4; + } else if ((compression == FaxCompression) || (compression == Group4Compression) || ((image_info->type != TrueColorType) && (SetImageGray(image,exception) != MagickFalse))) - (void) CopyMagickString(buffer,"/DeviceGray\n",MagickPathExtent); + { + device="DeviceGray"; + channels=1; + } else - if ((image->storage_class == DirectClass) || (image->colors > 256) || - (compression == JPEGCompression) || + if ((image->storage_class == DirectClass) || + (image->colors > 256) || (compression == JPEGCompression) || (compression == JPEG2000Compression)) - (void) CopyMagickString(buffer,"/DeviceRGB\n",MagickPathExtent); + { + device="DeviceRGB"; + channels=3; + } + profile=GetImageProfile(image,"icc"); + if ((profile == (StringInfo *) NULL) || (channels == 0)) + { + if (channels != 0) + (void) FormatLocaleString(buffer,MagickPathExtent,"\%s\n",device); else (void) FormatLocaleString(buffer,MagickPathExtent, "[ /Indexed /DeviceRGB %.20g %.20g 0 R ]\n",(double) image->colors- 1,(double) object+3); - (void) WriteBlobString(image,buffer); + (void) WriteBlobString(image,buffer); + } + else + { + const unsigned char + *p; + + /* + Write ICC profile. + */ + (void) FormatLocaleString(buffer,MagickPathExtent, + "[/ICCBased %.20g 0 R]\n",(double) object+1); + (void) WriteBlobString(image,buffer); + (void) WriteBlobString(image,"endobj\n"); + xref[object++]=TellBlob(image); + (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g 0 obj\n", + (double) object); + (void) WriteBlobString(image,buffer); + (void) FormatLocaleString(buffer,MagickPathExtent,"<<\n/N %.20g\n" + "/Filter /ASCIIHexDecode\n/Length %.20g\n/Alternate /%s\n>>\n" + "stream\n",(double) channels,2.0*GetStringInfoLength(profile),device); + (void) WriteBlobString(image,buffer); + p=GetStringInfoDatum(profile); + for (i=0; i < (ssize_t) GetStringInfoLength(profile); i++) + { + (void) FormatLocaleString(buffer,MagickPathExtent,"%02x",*p++); + (void) WriteBlobString(image,buffer); + } + (void) WriteBlobString(image,"\nendstream\n"); + } (void) WriteBlobString(image,"endobj\n"); /* Write Thumb object. @@ -2828,7 +2878,7 @@ RestoreMSCWarning (void) FormatLocaleString(buffer,MagickPathExtent,"/Title (\xfe\xff"); (void) WriteBlobString(image,buffer); for (i=0; i < (ssize_t) length; i++) - WriteBlobMSBShort(image,(unsigned short) utf16[i]); + (void) WriteBlobMSBShort(image,(unsigned short) utf16[i]); (void) FormatLocaleString(buffer,MagickPathExtent,")\n"); (void) WriteBlobString(image,buffer); utf16=(wchar_t *) RelinquishMagickMemory(utf16);