]> granicus.if.org Git - imagemagick/commitdiff
Support inline images with data URLS
authorCristy <urban-warrior@imagemagick.org>
Sun, 23 Aug 2015 14:55:57 +0000 (10:55 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sun, 23 Aug 2015 14:55:57 +0000 (10:55 -0400)
MagickCore/coder.c
MagickCore/module.c
coders/inline.c
coders/miff.c
coders/mpc.c

index ccf57e1f9003367f6e0a7bb4e62d3f1c11762fe7..3b94c06c4cfa3161367e4f30337d76c028105e09 100644 (file)
@@ -108,6 +108,7 @@ static const CoderMapInfo
     { "CR2", "DNG" },
     { "CRW", "DNG" },
     { "CUR", "ICON" },
+    { "DATA", "INLINE" },
     { "DCR", "DNG" },
     { "DCX", "PCX" },
     { "DFONT", "TTF" },
index 60650c970aeb8ffcd8b81c0290ee6ef792c2c829..37f9a4f31a6ecfff54a862545ef63a957414257b 100644 (file)
@@ -1354,8 +1354,12 @@ MagickPrivate MagickBooleanType OpenModules(ExceptionInfo *exception)
   (void) GetMagickInfo((char *) NULL,exception);
   number_modules=0;
   modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception);
-  if (modules == (char **) NULL)
-    return(MagickFalse);
+  if ((modules == (char **) NULL) || (*modules == (char *) NULL)
+    {
+      if (modules != (char **) NULL) 
+        modules=(char **) RelinquishMagickMemory(modules);
+      return(MagickFalse);
+    }
   for (i=0; i < (ssize_t) number_modules; i++)
     (void) OpenModule(modules[i],exception);
   /*
index 1b0babfa4f38563b9999cd6b32483a86a4c2d31a..f3ed29ff03b9e5ef5d8d7a784210dd66114d1be3 100644 (file)
@@ -123,8 +123,21 @@ static Image *ReadINLINEImage(const ImageInfo *image_info,
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickCoreSignature);
-  if (LocaleNCompare(image_info->filename,"data:",5) == 0)
-    return(ReadInlineImage(image_info,image_info->filename,exception));
+  if (LocaleCompare(image_info->magick,"DATA") == 0)
+    {
+      char
+        *filename;
+
+      Image
+        *data_image;
+
+      filename=AcquireString("data:");
+      (void) ConcatenateMagickString(filename,image_info->filename,
+        MagickPathExtent);
+      data_image=ReadInlineImage(image_info,filename,exception);
+      filename=DestroyString(filename);
+      return(data_image);
+    }
   image=AcquireImage(image_info,exception);
   status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
   if (status == MagickFalse)
@@ -196,6 +209,11 @@ ModuleExport size_t RegisterINLINEImage(void)
   MagickInfo
     *entry;
 
+  entry=AcquireMagickInfo("DATA","INLINE","Base64-encoded inline images");
+  entry->decoder=(DecodeImageHandler *) ReadINLINEImage;
+  entry->encoder=(EncodeImageHandler *) WriteINLINEImage;
+  entry->format_type=ImplicitFormatType;
+  (void) RegisterMagickInfo(entry);
   entry=AcquireMagickInfo("INLINE","INLINE","Base64-encoded inline images");
   entry->decoder=(DecodeImageHandler *) ReadINLINEImage;
   entry->encoder=(EncodeImageHandler *) WriteINLINEImage;
@@ -226,6 +244,7 @@ ModuleExport size_t RegisterINLINEImage(void)
 ModuleExport void UnregisterINLINEImage(void)
 {
   (void) UnregisterMagickInfo("INLINE");
+  (void) UnregisterMagickInfo("DATA");
 }
 \f
 /*
@@ -298,7 +317,8 @@ static MagickBooleanType WriteINLINEImage(const ImageInfo *image_info,
   if ((magick_info == (const MagickInfo *) NULL) ||
       (GetMagickMimeType(magick_info) == (const char *) NULL))
     ThrowWriterException(CorruptImageError,"ImageTypeNotSupported");
-  (void) CopyMagickString(image->filename,write_info->filename,MagickPathExtent);
+  (void) CopyMagickString(image->filename,write_info->filename,
+    MagickPathExtent);
   blob_length=2048;
   write_image=CloneImage(image,0,0,MagickTrue,exception);
   if (write_image == (Image *) NULL)
index 20a235243434bae98f0d80d0323aeda61cdb6733..a7b870b38a116fcb712157061f2326f182a4be56 100644 (file)
@@ -2049,16 +2049,16 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
     /*
       Write MIFF header.
     */
-    (void) WriteBlobString(image,"id=ImageMagick  version=1.0\n");
+    (void) WriteBlobString(image,"id=ImageMagick  version=2.0\n");
     (void) FormatLocaleString(buffer,MagickPathExtent,
       "class=%s  colors=%.20g  alpha-trait=%s\n",CommandOptionToMnemonic(
       MagickClassOptions,image->storage_class),(double) image->colors,
       CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
       image->alpha_trait));
     (void) WriteBlobString(image,buffer);
-    (void) FormatLocaleString(buffer,MagickPathExtent,"columns=%.20g  rows=%.20g  "
-      "depth=%.20g\n",(double) image->columns,(double) image->rows,(double)
-      image->depth);
+    (void) FormatLocaleString(buffer,MagickPathExtent,
+      "columns=%.20g  rows=%.20g  depth=%.20g\n",(double) image->columns,
+      (double) image->rows,(double) image->depth);
     (void) WriteBlobString(image,buffer);
     if (image->type != UndefinedType)
       {
@@ -2074,9 +2074,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
       }
     if (image->intensity != UndefinedPixelIntensityMethod)
       {
-        (void) FormatLocaleString(buffer,MagickPathExtent,"pixel-intensity=%s\n",
-          CommandOptionToMnemonic(MagickPixelIntensityOptions,
-          image->intensity));
+        (void) FormatLocaleString(buffer,MagickPathExtent,
+          "pixel-intensity=%s\n",CommandOptionToMnemonic(
+          MagickPixelIntensityOptions,image->intensity));
         (void) WriteBlobString(image,buffer);
       }
     if (image->endian != UndefinedEndian)
@@ -2120,8 +2120,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
         }
     if ((image->tile_offset.x != 0) || (image->tile_offset.y != 0))
       {
-        (void) FormatLocaleString(buffer,MagickPathExtent,"tile-offset=%+ld%+ld\n",
-          (long) image->tile_offset.x,(long) image->tile_offset.y);
+        (void) FormatLocaleString(buffer,MagickPathExtent,
+          "tile-offset=%+ld%+ld\n",(long) image->tile_offset.x,(long)
+          image->tile_offset.y);
         (void) WriteBlobString(image,buffer);
       }
     if ((GetNextImageInList(image) != (Image *) NULL) ||
@@ -2148,8 +2149,8 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
           }
         if (image->iterations != 0)
           {
-            (void) FormatLocaleString(buffer,MagickPathExtent,"iterations=%.20g\n",
-              (double) image->iterations);
+            (void) FormatLocaleString(buffer,MagickPathExtent,
+              "iterations=%.20g\n",(double) image->iterations);
             (void) WriteBlobString(image,buffer);
           }
         if (image->delay != 0)
@@ -2179,8 +2180,9 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
       }
     if (image->rendering_intent != UndefinedIntent)
       {
-        (void) FormatLocaleString(buffer,MagickPathExtent,"rendering-intent=%s\n",
-          CommandOptionToMnemonic(MagickIntentOptions,image->rendering_intent));
+        (void) FormatLocaleString(buffer,MagickPathExtent,
+          "rendering-intent=%s\n",CommandOptionToMnemonic(MagickIntentOptions,
+          image->rendering_intent));
         (void) WriteBlobString(image,buffer);
       }
     if (image->gamma != 0.0)
@@ -2404,8 +2406,8 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
         bzip_info.bzalloc=AcquireBZIPMemory;
         bzip_info.bzfree=RelinquishBZIPMemory;
         code=BZ2_bzCompressInit(&bzip_info,(int) (image->quality ==
-          UndefinedCompressionQuality ? 7 : MagickMin(image->quality/10,
-          9)),(int) image_info->verbose,0);
+          UndefinedCompressionQuality ? 7 : MagickMin(image->quality/10,9)),
+          (int) image_info->verbose,0);
         if (code != BZ_OK)
           status=MagickFalse;
         break;
@@ -2682,8 +2684,8 @@ static MagickBooleanType WriteMIFFImage(const ImageInfo *image_info,
     if (GetNextImageInList(image) == (Image *) NULL)
       break;
     image=SyncNextImageInList(image);
-    status=SetImageProgress(image,SaveImagesTag,scene++,
-      GetImageListLength(image));
+    status=SetImageProgress(image,SaveImagesTag,scene++,GetImageListLength(
+      image));
     if (status == MagickFalse)
       break;
   } while (image_info->adjoin != MagickFalse);
index 7e99669cc0098ebf369c4a3a0b9e0ac6edd2a5d2..76939dcc7c26a8a0b5aa783b2f1450d47fc00a23 100644 (file)
@@ -1133,9 +1133,9 @@ static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image,
       }
     if (image->intensity != UndefinedPixelIntensityMethod)
       {
-        (void) FormatLocaleString(buffer,MagickPathExtent,"pixel-intensity=%s\n",
-          CommandOptionToMnemonic(MagickPixelIntensityOptions,
-          image->intensity));
+        (void) FormatLocaleString(buffer,MagickPathExtent,
+          "pixel-intensity=%s\n",CommandOptionToMnemonic(
+          MagickPixelIntensityOptions,image->intensity));
         (void) WriteBlobString(image,buffer);
       }
     if (image->endian != UndefinedEndian)
@@ -1209,8 +1209,8 @@ static MagickBooleanType WriteMPCImage(const ImageInfo *image_info,Image *image,
           }
         if (image->iterations != 0)
           {
-            (void) FormatLocaleString(buffer,MagickPathExtent,"iterations=%.20g\n",
-              (double) image->iterations);
+            (void) FormatLocaleString(buffer,MagickPathExtent,
+              "iterations=%.20g\n",(double) image->iterations);
             (void) WriteBlobString(image,buffer);
           }
         if (image->delay != 0)