[PATCH] OLE macintosh (PICT image header)

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
prahal
Posts: 1
Joined: 2012-11-12T02:32:27-07:00
Authentication code: 67789

[PATCH] OLE macintosh (PICT image header)

Post by prahal » 2012-11-12T02:50:46-07:00

http://www.openflow.org/documents/OpenFlow_2011.pps is of format macintosh and has its thumbnail as "pict". Extracted with libgsf (gnome) gsf-office-thumbnailer use convert from imagemagick to make it a png. But convert fails on two issues:
  • - seems that macintosh ole embed PICT without a platform header but instead use "PICT" as header.
    - builtin BMP magic from imagemagick match "PI" offset 0
This patch fixes both though I am not confident removing the match from "BMP" to "PI" is right. But the list of builting magic is sorted alphabetically thus this match always happens first :/

Code: Select all

--- a/magick/magic.c	2011-12-19 02:54:26.000000000 +0100
+++ b/magick/magic.c	2012-11-12 09:43:11.553998032 +0100
@@ -93,7 +93,7 @@
     { "BMP", 0, MagickString("CI") },
     { "BMP", 0, MagickString("CP") },
     { "BMP", 0, MagickString("IC") },
-    { "BMP", 0, MagickString("PI") },
+    //{ "BMP", 0, MagickString("PI") },
     { "CALS", 21, MagickString("version: MIL-STD-1840") },
     { "CALS", 0, MagickString("srcdocid:") },
     { "CALS", 9, MagickString("srcdocid:") },
@@ -152,6 +152,7 @@
     { "PFA", 0, MagickString("%!PS-AdobeFont-1.0") },
     { "PFB", 6, MagickString("%!PS-AdobeFont-1.0") },
     { "PGX", 0, MagickString("\050\107\020\115\046") },
+    { "PICT", 0, MagickString("PICT") },
     { "PICT", 522, MagickString("\000\021\002\377\014\000") },
     { "PNG", 0, MagickString("\211PNG\r\n\032\n") },
     { "PBM", 0, MagickString("P1") },
--- a/coders/pict.c	2012-08-30 13:41:56.000000000 +0200
+++ b/coders/pict.c	2012-11-12 08:54:36.891992713 +0100
@@ -744,6 +744,11 @@
 */
 static MagickBooleanType IsPICT(const unsigned char *magick,const size_t length)
 {
+  /* Embedded OLE2 macintosh have "PICT" instead of 512 platform header */
+  if (length < 12)
+    return(MagickFalse);
+  if (memcmp(magick,"PICT",4) == 0)
+    return(MagickTrue);
   if (length < 528)
     return(MagickFalse);
   if (memcmp(magick+522,"\000\021\002\377\014\000",6) == 0)
@@ -792,7 +797,8 @@
   ExceptionInfo *exception)
 {
   char
-    geometry[MaxTextExtent];
+    geometry[MaxTextExtent],
+    header_ole[4];
 
   Image
     *image;
@@ -863,8 +869,17 @@
   */
   pixmap.bits_per_pixel=0;
   pixmap.component_count=0;
-  for (i=0; i < 512; i++)
-    (void) ReadBlobByte(image);  /* skip header */
+  /* skip header : 512 for standard PICT and 4, ie "PICT" for OLE2 */
+  header_ole[0] = ReadBlobByte(image);
+  header_ole[1] = ReadBlobByte(image);
+  header_ole[2] = ReadBlobByte(image);
+  header_ole[3] = ReadBlobByte(image);
+  if (!((header_ole[0] == 0x50) &&
+      (header_ole[1] == 0x49) &&
+      (header_ole[2] == 0x43) &&
+      (header_ole[3] == 0x54 )))
+    for (i=0; i < 508; i++)
+      (void) ReadBlobByte(image);
   (void) ReadBlobMSBShort(image);  /* skip picture size */
   ReadRectangle(image,frame);
   while ((c=ReadBlobByte(image)) == 0) ;
--- a/config/mime.xml	2009-09-05 23:47:34.000000000 +0200
+++ b/config/mime.xml	2012-11-12 09:10:27.484276414 +0100
@@ -755,6 +755,7 @@
   <mime type="image/x-pict" description="Macintosh Quickdraw/PICT drawing" priority="100" pattern="*.pict" />
   <mime type="image/x-pict" description="Macintosh Quickdraw/PICT drawing" priority="100" pattern="*.pict1" />
   <mime type="image/x-pict" description="Macintosh Quickdraw/PICT drawing" priority="100" pattern="*.pict2" />
+  <mime type="image/x-pict" description="Macintosh Quickdraw/PICT drawing" data-type="string" offset="0" magic="PICT" priority="50" />
   <mime type="application/x-ufraw" acronym="UFRaw" description="Unidentified Flying Raw" priority="100" pattern="*.ufraw" />
   <mime type="image/x-adobe-dng" acronym="DNG" description="Digital Negative" priority="100" pattern="*.dng" />
   <mime type="image/x-canon-crw" description="Canon RaW" data-type="string" offset="0" magic="II\x1a\x00\x00\x00HEAPCCDR" priority="50" />

User avatar
magick
Site Admin
Posts: 11063
Joined: 2003-05-31T11:32:55-07:00

Re: [PATCH] OLE macintosh (PICT image header)

Post by magick » 2012-11-12T05:39:58-07:00

Thanks, we'll get your the patch in ImageMagick by the next point release.

Post Reply