]> granicus.if.org Git - imagemagick/commitdiff
Fixed incorrect page offset reported in #463 and #479.
authorDirk Lemstra <dirk@git.imagemagick.org>
Sun, 7 May 2017 20:43:29 +0000 (22:43 +0200)
committerDirk Lemstra <dirk@git.imagemagick.org>
Sun, 7 May 2017 20:43:29 +0000 (22:43 +0200)
coders/pdf.c

index 228284023f8d32541c18104b785b0df3e748dcca..55f32d6e72aba059266f2268dac782824e27bdd3 100644 (file)
@@ -1278,6 +1278,7 @@ RestoreMSCWarning
 
   ssize_t
     count,
+    page_count,
     y;
 
   struct tm
@@ -1426,6 +1427,7 @@ RestoreMSCWarning
     (double) object+1);
   (void) WriteBlobString(image,buffer);
   count=(ssize_t) (pages_id+ObjectsPerImage+1);
+  page_count=1;
   if (image_info->adjoin != MagickFalse)
     {
       Image
@@ -1437,6 +1439,10 @@ RestoreMSCWarning
       kid_image=image;
       for ( ; GetNextImageInList(kid_image) != (Image *) NULL; count+=ObjectsPerImage)
       {
+        page_count++;
+        profile=GetImageProfile(kid_image,"icc");
+        if (profile != (StringInfo *) NULL)
+          count+=2;
         (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g 0 R ",(double)
           count);
         (void) WriteBlobString(image,buffer);
@@ -1449,13 +1455,18 @@ RestoreMSCWarning
     }
   (void) WriteBlobString(image,"]\n");
   (void) FormatLocaleString(buffer,MagickPathExtent,"/Count %.20g\n",(double)
-    ((count-pages_id)/ObjectsPerImage));
+    page_count);
   (void) WriteBlobString(image,buffer);
   (void) WriteBlobString(image,">>\n");
   (void) WriteBlobString(image,"endobj\n");
   scene=0;
   do
   {
+    MagickBooleanType
+      has_icc_profile;
+
+    profile=GetImageProfile(image,"icc");
+    has_icc_profile=(profile != (StringInfo *) NULL) ? MagickTrue : MagickFalse;
     compression=image->compression;
     if (image_info->compression != UndefinedCompression)
       compression=image_info->compression;
@@ -1624,11 +1635,7 @@ RestoreMSCWarning
       (double) object+1);
     (void) WriteBlobString(image,buffer);
     (void) FormatLocaleString(buffer,MagickPathExtent,"/Thumb %.20g 0 R\n",
-      (double) object+8);
-    profile=GetImageProfile(image,"icc");
-    if (profile != (StringInfo *) NULL)
-      (void) FormatLocaleString(buffer,MagickPathExtent,"/Thumb %.20g 0 R\n",
-        (double) object+10);
+      (double) object+(has_icc_profile != MagickFalse ? 10 : 8));
     (void) WriteBlobString(image,buffer);
     (void) WriteBlobString(image,">>\n");
     (void) WriteBlobString(image,"endobj\n");
@@ -1811,11 +1818,7 @@ RestoreMSCWarning
     if (image->alpha_trait != UndefinedPixelTrait)
       {
         (void) FormatLocaleString(buffer,MagickPathExtent,"/SMask %.20g 0 R\n",
-          (double) object+7);
-        profile=GetImageProfile(image,"icc");
-        if (profile != (StringInfo *) NULL)
-          (void) FormatLocaleString(buffer,MagickPathExtent,
-            "/SMask %.20g 0 R\n",(double) object+9);
+          (double) object+(has_icc_profile != MagickFalse ? 9 : 7));
         (void) WriteBlobString(image,buffer);
       }
     (void) FormatLocaleString(buffer,MagickPathExtent,"/Length %.20g 0 R\n",
@@ -2330,11 +2333,7 @@ RestoreMSCWarning
       tile_image->rows);
     (void) WriteBlobString(image,buffer);
     (void) FormatLocaleString(buffer,MagickPathExtent,"/ColorSpace %.20g 0 R\n",
-      (double) object-1);
-    profile=GetImageProfile(image,"icc");
-    if (profile != (StringInfo *) NULL)
-      (void) FormatLocaleString(buffer,MagickPathExtent,
-        "/ColorSpace %.20g 0 R\n",(double) object-3);
+      (double) object-(has_icc_profile != MagickFalse ? 3 : 1));
     (void) WriteBlobString(image,buffer);
     (void) FormatLocaleString(buffer,MagickPathExtent,"/BitsPerComponent %d\n",
       (compression == FaxCompression) || (compression == Group4Compression) ?