]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/constitute.c
...
[imagemagick] / MagickCore / constitute.c
index b0749ced66dc5e11a766d3d36e84285debfa8e41..71ba791cafe165bcde9134a0b596805015d44630 100644 (file)
 %                  MagickCore Methods to Consitute an Image                   %
 %                                                                             %
 %                             Software Design                                 %
-%                               John Cristy                                   %
+%                                  Cristy                                     %
 %                               October 1998                                  %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
   Include declarations.
 */
 #include "MagickCore/studio.h"
+#include "MagickCore/attribute.h"
 #include "MagickCore/blob.h"
 #include "MagickCore/blob-private.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
 #include "MagickCore/cache.h"
 #include "MagickCore/client.h"
+#include "MagickCore/colorspace-private.h"
 #include "MagickCore/constitute.h"
 #include "MagickCore/constitute-private.h"
 #include "MagickCore/delegate.h"
@@ -62,6 +64,7 @@
 #include "MagickCore/pixel-accessor.h"
 #include "MagickCore/policy.h"
 #include "MagickCore/profile.h"
+#include "MagickCore/profile-private.h"
 #include "MagickCore/property.h"
 #include "MagickCore/quantum.h"
 #include "MagickCore/resize.h"
 #include "MagickCore/string_.h"
 #include "MagickCore/string-private.h"
 #include "MagickCore/timer.h"
+#include "MagickCore/token.h"
 #include "MagickCore/transform.h"
 #include "MagickCore/utility.h"
 #include "MagickCore/utility-private.h"
 \f
-static SemaphoreInfo
-  *constitute_semaphore = (SemaphoreInfo *) NULL;
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-+   C o n s t i t u t e C o m p o n e n t G e n e s i s                       %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  ConstituteComponentGenesis() instantiates the constitute component.
-%
-%  The format of the ConstituteComponentGenesis method is:
-%
-%      MagickBooleanType ConstituteComponentGenesis(void)
-%
-*/
-MagickPrivate MagickBooleanType ConstituteComponentGenesis(void)
-{
-  AcquireSemaphoreInfo(&constitute_semaphore);
-  return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-+   C o n s t i t u t e C o m p o n e n t T e r m i n u s                     %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  ConstituteComponentTerminus() destroys the constitute component.
-%
-%  The format of the ConstituteComponentTerminus method is:
-%
-%      ConstituteComponentTerminus(void)
-%
-*/
-MagickPrivate void ConstituteComponentTerminus(void)
-{
-  if (constitute_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&constitute_semaphore);
-  DestroySemaphoreInfo(&constitute_semaphore);
-}
-\f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
@@ -177,9 +129,9 @@ MagickPrivate void ConstituteComponentTerminus(void)
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport Image *ConstituteImage(const size_t columns,
-  const size_t rows,const char *map,const StorageType storage,
-  const void *pixels,ExceptionInfo *exception)
+MagickExport Image *ConstituteImage(const size_t columns,const size_t rows,
+  const char *map,const StorageType storage,const void *pixels,
+  ExceptionInfo *exception)
 {
   Image
     *image;
@@ -194,15 +146,15 @@ MagickExport Image *ConstituteImage(const size_t columns,
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",map);
   assert(pixels != (void *) NULL);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
-  image=AcquireImage((ImageInfo *) NULL);
+  assert(exception->signature == MagickCoreSignature);
+  image=AcquireImage((ImageInfo *) NULL,exception);
   if (image == (Image *) NULL)
     return((Image *) NULL);
   if ((columns == 0) || (rows == 0))
     ThrowImageException(OptionError,"NonZeroWidthAndHeightRequired");
   image->columns=columns;
   image->rows=rows;
-  (void) SetImageBackgroundColor(image);
+  (void) SetImageBackgroundColor(image,exception);
   status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels,exception);
   if (status == MagickFalse)
      image=DestroyImage(image);
@@ -245,6 +197,8 @@ extern "C" {
 static size_t PingStream(const Image *magick_unused(image),
   const void *magick_unused(pixels),const size_t columns)
 {
+  magick_unreferenced(image);
+  magick_unreferenced(pixels);
   return(columns);
 }
 
@@ -262,7 +216,7 @@ MagickExport Image *PingImage(const ImageInfo *image_info,
     *ping_info;
 
   assert(image_info != (ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
@@ -295,20 +249,23 @@ MagickExport Image *PingImage(const ImageInfo *image_info,
 %
 %  The format of the PingImage method is:
 %
-%      Image *PingImages(const ImageInfo *image_info,ExceptionInfo *exception)
+%      Image *PingImages(ImageInfo *image_info,const char *filename,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image_info: the image info.
 %
+%    o filename: the image filename.
+%
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport Image *PingImages(const ImageInfo *image_info,
+MagickExport Image *PingImages(ImageInfo *image_info,const char *filename,
   ExceptionInfo *exception)
 {
   char
-    filename[MaxTextExtent];
+    ping_filename[MagickPathExtent];
 
   Image
     *image,
@@ -321,14 +278,16 @@ MagickExport Image *PingImages(const ImageInfo *image_info,
     Ping image list from a file.
   */
   assert(image_info != (ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
+  (void) SetImageOption(image_info,"filename",filename);
+  (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
   (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
-    (int) image_info->scene,filename);
-  if (LocaleCompare(filename,image_info->filename) != 0)
+    (int) image_info->scene,ping_filename,exception);
+  if (LocaleCompare(ping_filename,image_info->filename) != 0)
     {
       ExceptionInfo
         *sans;
@@ -344,13 +303,19 @@ MagickExport Image *PingImages(const ImageInfo *image_info,
       sans=AcquireExceptionInfo();
       (void) SetImageInfo(read_info,0,sans);
       sans=DestroyExceptionInfo(sans);
-      (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
+      if (read_info->number_scenes == 0)
+        {
+          read_info=DestroyImageInfo(read_info);
+          return(PingImage(image_info,exception));
+        }
+      (void) CopyMagickString(ping_filename,read_info->filename,
+        MagickPathExtent);
       images=NewImageList();
       extent=(ssize_t) (read_info->scene+read_info->number_scenes);
       for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
       {
-        (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(int)
-          scene,read_info->filename);
+        (void) InterpretImageFilename(image_info,(Image *) NULL,ping_filename,
+          (int) scene,read_info->filename,exception);
         image=PingImage(read_info,exception);
         if (image == (Image *) NULL)
           continue;
@@ -394,9 +359,9 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
   ExceptionInfo *exception)
 {
   char
-    filename[MaxTextExtent],
-    magick[MaxTextExtent],
-    magick_filename[MaxTextExtent];
+    filename[MagickPathExtent],
+    magick[MagickPathExtent],
+    magick_filename[MagickPathExtent];
 
   const char
     *value;
@@ -421,39 +386,23 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
     *read_info;
 
   MagickStatusType
-    flags,
-    thread_support;
-
-  PolicyDomain
-    domain;
-
-  PolicyRights
-    rights;
+    flags;
 
   /*
     Determine image type from filename prefix or suffix (e.g. image.jpg).
   */
   assert(image_info != (ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   assert(image_info->filename != (char *) NULL);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
   read_info=CloneImageInfo(image_info);
-  (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
+  (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
   (void) SetImageInfo(read_info,0,exception);
-  (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
-  (void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
-  domain=CoderPolicyDomain;
-  rights=ReadPolicyRights;
-  if (IsRightsAuthorized(domain,rights,read_info->magick) == MagickFalse)
-    {
-      errno=EPERM;
-      (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
-        "NotAuthorized","`%s'",read_info->filename);
-      return((Image *) NULL);
-    }
+  (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
+  (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
   /*
     Call appropriate image reader based on image type.
   */
@@ -462,13 +411,29 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
   sans_exception=DestroyExceptionInfo(sans_exception);
   if (magick_info != (const MagickInfo *) NULL)
     {
+      PolicyDomain
+        domain;
+
+      PolicyRights
+        rights;
+
+      domain=CoderPolicyDomain;
+      rights=ReadPolicyRights;
+      if (IsRightsAuthorized(domain,rights,magick_info->module) == MagickFalse)
+        {
+          errno=EPERM;
+          (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
+            "NotAuthorized","`%s'",read_info->filename);
+          read_info=DestroyImageInfo(read_info);
+          return((Image *) NULL);
+        }
       if (GetMagickEndianSupport(magick_info) == MagickFalse)
         read_info->endian=UndefinedEndian;
       else
         if ((image_info->endian == UndefinedEndian) &&
             (GetMagickRawSupport(magick_info) != MagickFalse))
           {
-            size_t
+            unsigned long
               lsb_first;
 
             lsb_first=1;
@@ -477,14 +442,14 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
          }
     }
   if ((magick_info != (const MagickInfo *) NULL) &&
-      (GetMagickSeekableStream(magick_info) != MagickFalse))
+      (GetMagickDecoderSeekableStream(magick_info) != MagickFalse))
     {
       MagickBooleanType
         status;
 
-      image=AcquireImage(read_info);
+      image=AcquireImage(read_info,exception);
       (void) CopyMagickString(image->filename,read_info->filename,
-        MaxTextExtent);
+        MagickPathExtent);
       status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
       if (status == MagickFalse)
         {
@@ -512,26 +477,38 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
       image=DestroyImage(image);
     }
   image=NewImageList();
-  if (constitute_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&constitute_semaphore);
+  if ((magick_info == (const MagickInfo *) NULL) ||
+      (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
+    {
+      delegate_info=GetDelegateInfo(read_info->magick,(char *) NULL,exception);
+      if (delegate_info == (const DelegateInfo *) NULL)
+        {
+          (void) SetImageInfo(read_info,0,exception);
+          (void) CopyMagickString(read_info->filename,filename,
+            MagickPathExtent);
+          magick_info=GetMagickInfo(read_info->magick,exception);
+        }
+    }
   if ((magick_info != (const MagickInfo *) NULL) &&
       (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL))
     {
-      thread_support=GetMagickThreadSupport(magick_info);
-      if ((thread_support & DecoderThreadSupport) == 0)
-        LockSemaphoreInfo(constitute_semaphore);
+      if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
+        LockSemaphoreInfo(magick_info->semaphore);
       image=GetImageDecoder(magick_info)(read_info,exception);
-      if ((thread_support & DecoderThreadSupport) == 0)
-        UnlockSemaphoreInfo(constitute_semaphore);
+      if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
+        UnlockSemaphoreInfo(magick_info->semaphore);
     }
   else
     {
+      MagickBooleanType
+        status;
+
       delegate_info=GetDelegateInfo(read_info->magick,(char *) NULL,exception);
       if (delegate_info == (const DelegateInfo *) NULL)
         {
           (void) ThrowMagickException(exception,GetMagickModule(),
             MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
-            read_info->filename);
+            read_info->magick);
           if (read_info->temporary != MagickFalse)
             (void) RelinquishUniqueFileResource(read_info->filename);
           read_info=DestroyImageInfo(read_info);
@@ -540,24 +517,25 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
       /*
         Let our decoding delegate process the image.
       */
-      image=AcquireImage(read_info);
+      image=AcquireImage(read_info,exception);
       if (image == (Image *) NULL)
         {
           read_info=DestroyImageInfo(read_info);
           return((Image *) NULL);
         }
       (void) CopyMagickString(image->filename,read_info->filename,
-        MaxTextExtent);
+        MagickPathExtent);
       *read_info->filename='\0';
       if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
-        LockSemaphoreInfo(constitute_semaphore);
-      (void) InvokeDelegate(read_info,image,read_info->magick,(char *) NULL,
+        LockSemaphoreInfo(delegate_info->semaphore);
+      status=InvokeDelegate(read_info,image,read_info->magick,(char *) NULL,
         exception);
       if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
-        UnlockSemaphoreInfo(constitute_semaphore);
+        UnlockSemaphoreInfo(delegate_info->semaphore);
       image=DestroyImageList(image);
       read_info->temporary=MagickTrue;
-      (void) SetImageInfo(read_info,0,exception);
+      if (status != MagickFalse)
+        (void) SetImageInfo(read_info,0,exception);
       magick_info=GetMagickInfo(read_info->magick,exception);
       if ((magick_info == (const MagickInfo *) NULL) ||
           (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
@@ -565,26 +543,25 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
           if (IsPathAccessible(read_info->filename) != MagickFalse)
             (void) ThrowMagickException(exception,GetMagickModule(),
               MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
-              read_info->filename);
+              read_info->magick);
           else
             ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
               read_info->filename);
           read_info=DestroyImageInfo(read_info);
           return((Image *) NULL);
         }
-      thread_support=GetMagickThreadSupport(magick_info);
-      if ((thread_support & DecoderThreadSupport) == 0)
-        LockSemaphoreInfo(constitute_semaphore);
+      if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
+        LockSemaphoreInfo(magick_info->semaphore);
       image=(Image *) (GetImageDecoder(magick_info))(read_info,exception);
-      if ((thread_support & DecoderThreadSupport) == 0)
-        UnlockSemaphoreInfo(constitute_semaphore);
+      if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
+        UnlockSemaphoreInfo(magick_info->semaphore);
     }
   if (read_info->temporary != MagickFalse)
     {
       (void) RelinquishUniqueFileResource(read_info->filename);
       read_info->temporary=MagickFalse;
       if (image != (Image *) NULL)
-        (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+        (void) CopyMagickString(image->filename,filename,MagickPathExtent);
     }
   if (image == (Image *) NULL)
     {
@@ -613,20 +590,12 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
           image=GetFirstImageInList(clones);
         }
     }
-  if (GetBlobError(image) != MagickFalse)
-    {
-      ThrowFileException(exception,FileOpenError,
-        "AnErrorHasOccurredReadingFromFile",read_info->filename);
-      image=DestroyImageList(image);
-      read_info=DestroyImageInfo(read_info);
-      return((Image *) NULL);
-    }
   for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
   {
     char
-      magick_path[MaxTextExtent],
+      magick_path[MagickPathExtent],
       *property,
-      timestamp[MaxTextExtent];
+      timestamp[MagickPathExtent];
 
     const char
       *option;
@@ -634,53 +603,63 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
     const StringInfo
       *profile;
 
+    ssize_t
+      option_type;
+
     next->taint=MagickFalse;
     GetPathComponent(magick_filename,MagickPath,magick_path);
-    if (*magick_path == '\0')
-      (void) CopyMagickString(next->magick,magick,MaxTextExtent);
+    if (*magick_path == '\0' && *next->magick == '\0')
+      (void) CopyMagickString(next->magick,magick,MagickPathExtent);
     (void) CopyMagickString(next->magick_filename,magick_filename,
-      MaxTextExtent);
+      MagickPathExtent);
     if (IsBlobTemporary(image) != MagickFalse)
-      (void) CopyMagickString(next->filename,filename,MaxTextExtent);
+      (void) CopyMagickString(next->filename,filename,MagickPathExtent);
     if (next->magick_columns == 0)
       next->magick_columns=next->columns;
     if (next->magick_rows == 0)
       next->magick_rows=next->rows;
-    value=GetImageProperty(next,"tiff:Orientation");
+    value=GetImageProperty(next,"tiff:Orientation",exception);
     if (value == (char *) NULL)
-      value=GetImageProperty(next,"exif:Orientation");
+      value=GetImageProperty(next,"exif:Orientation",exception);
     if (value != (char *) NULL)
       {
         next->orientation=(OrientationType) StringToLong(value);
         (void) DeleteImageProperty(next,"tiff:Orientation");
         (void) DeleteImageProperty(next,"exif:Orientation");
       }
-    value=GetImageProperty(next,"exif:XResolution");
+    value=GetImageProperty(next,"exif:XResolution",exception);
     if (value != (char *) NULL)
       {
-        geometry_info.rho=next->x_resolution;
+        geometry_info.rho=next->resolution.x;
         geometry_info.sigma=1.0;
         flags=ParseGeometry(value,&geometry_info);
         if (geometry_info.sigma != 0)
-          next->x_resolution=geometry_info.rho/geometry_info.sigma;
+          next->resolution.x=geometry_info.rho/geometry_info.sigma;
+        if (strchr(value,',') != (char *) NULL)
+          next->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
         (void) DeleteImageProperty(next,"exif:XResolution");
       }
-    value=GetImageProperty(next,"exif:YResolution");
+    value=GetImageProperty(next,"exif:YResolution",exception);
     if (value != (char *) NULL)
       {
-        geometry_info.rho=next->y_resolution;
+        geometry_info.rho=next->resolution.y;
         geometry_info.sigma=1.0;
         flags=ParseGeometry(value,&geometry_info);
         if (geometry_info.sigma != 0)
-          next->y_resolution=geometry_info.rho/geometry_info.sigma;
+          next->resolution.y=geometry_info.rho/geometry_info.sigma;
+        if (strchr(value,',') != (char *) NULL)
+          next->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
         (void) DeleteImageProperty(next,"exif:YResolution");
       }
-    value=GetImageProperty(next,"tiff:ResolutionUnit");
+    value=GetImageProperty(next,"tiff:ResolutionUnit",exception);
     if (value == (char *) NULL)
-      value=GetImageProperty(next,"exif:ResolutionUnit");
+      value=GetImageProperty(next,"exif:ResolutionUnit",exception);
     if (value != (char *) NULL)
       {
-        next->units=(ResolutionType) (StringToLong(value)-1);
+        option_type=ParseCommandOption(MagickResolutionOptions,MagickFalse,
+          value);
+        if (option_type >= 0)
+          next->units=(ResolutionType) option_type;
         (void) DeleteImageProperty(next,"exif:ResolutionUnit");
         (void) DeleteImageProperty(next,"tiff:ResolutionUnit");
       }
@@ -692,21 +671,21 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
     if (option != (const char *) NULL)
       {
         property=InterpretImageProperties(read_info,next,option,exception);
-        (void) SetImageProperty(next,"caption",property);
+        (void) SetImageProperty(next,"caption",property,exception);
         property=DestroyString(property);
       }
     option=GetImageOption(read_info,"comment");
     if (option != (const char *) NULL)
       {
         property=InterpretImageProperties(read_info,next,option,exception);
-        (void) SetImageProperty(next,"comment",property);
+        (void) SetImageProperty(next,"comment",property,exception);
         property=DestroyString(property);
       }
     option=GetImageOption(read_info,"label");
     if (option != (const char *) NULL)
       {
         property=InterpretImageProperties(read_info,next,option,exception);
-        (void) SetImageProperty(next,"label",property);
+        (void) SetImageProperty(next,"label",property,exception);
         property=DestroyString(property);
       }
     if (LocaleCompare(next->magick,"TEXT") == 0)
@@ -739,7 +718,7 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
                   flags=ParseRegionGeometry(next,read_info->extract,&geometry,
                     exception);
                   size_image=ResizeImage(next,geometry.width,geometry.height,
-                    next->filter,next->blur,exception);
+                    next->filter,exception);
                   if (size_image != (Image *) NULL)
                     ReplaceImageInList(&next,size_image);
                 }
@@ -751,18 +730,15 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
     profile=GetImageProfile(next,"iptc");
     if (profile == (const StringInfo *) NULL)
       profile=GetImageProfile(next,"8bim");
-    (void) FormatMagickTime(GetBlobProperties(next)->st_mtime,MaxTextExtent,
+    (void) FormatMagickTime(GetBlobProperties(next)->st_mtime,MagickPathExtent,
       timestamp);
-    (void) SetImageProperty(next,"date:modify",timestamp);
-    (void) FormatMagickTime(GetBlobProperties(next)->st_ctime,MaxTextExtent,
+    (void) SetImageProperty(next,"date:modify",timestamp,exception);
+    (void) FormatMagickTime(GetBlobProperties(next)->st_ctime,MagickPathExtent,
       timestamp);
-    (void) SetImageProperty(next,"date:create",timestamp);
+    (void) SetImageProperty(next,"date:create",timestamp,exception);
     option=GetImageOption(image_info,"delay");
     if (option != (const char *) NULL)
       {
-        GeometryInfo
-          geometry_info;
-
         flags=ParseGeometry(option,&geometry_info);
         if ((flags & GreaterValue) != 0)
           {
@@ -782,8 +758,12 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
       }
     option=GetImageOption(image_info,"dispose");
     if (option != (const char *) NULL)
-      next->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
-        MagickFalse,option);
+      {
+        option_type=ParseCommandOption(MagickDisposeOptions,MagickFalse,
+          option);
+        if (option_type >= 0)
+          next->dispose=(DisposeType) option_type;
+      }
     if (read_info->verbose != MagickFalse)
       (void) IdentifyImage(next,stderr,MagickFalse,exception);
     image=next;
@@ -807,20 +787,23 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
 %
 %  The format of the ReadImage method is:
 %
-%      Image *ReadImages(const ImageInfo *image_info,ExceptionInfo *exception)
+%      Image *ReadImages(ImageInfo *image_info,const char *filename,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image_info: the image info.
 %
+%    o filename: the image filename.
+%
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport Image *ReadImages(const ImageInfo *image_info,
+MagickExport Image *ReadImages(ImageInfo *image_info,const char *filename,
   ExceptionInfo *exception)
 {
   char
-    filename[MaxTextExtent];
+    read_filename[MagickPathExtent];
 
   Image
     *image,
@@ -833,14 +816,18 @@ MagickExport Image *ReadImages(const ImageInfo *image_info,
     Read image list from a file.
   */
   assert(image_info != (ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image_info->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
-    (int) image_info->scene,filename);
-  if (LocaleCompare(filename,image_info->filename) != 0)
+  read_info=CloneImageInfo(image_info);
+  *read_info->magick='\0';
+  (void) SetImageOption(read_info,"filename",filename);
+  (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
+  (void) InterpretImageFilename(read_info,(Image *) NULL,filename,
+    (int) read_info->scene,read_filename,exception);
+  if (LocaleCompare(read_filename,read_info->filename) != 0)
     {
       ExceptionInfo
         *sans;
@@ -852,31 +839,33 @@ MagickExport Image *ReadImages(const ImageInfo *image_info,
       /*
         Images of the form image-%d.png[1-5].
       */
-      read_info=CloneImageInfo(image_info);
       sans=AcquireExceptionInfo();
       (void) SetImageInfo(read_info,0,sans);
       sans=DestroyExceptionInfo(sans);
-      if (read_info->number_scenes == 0)
+      if (read_info->number_scenes != 0)
         {
+          (void) CopyMagickString(read_filename,read_info->filename,
+            MagickPathExtent);
+          images=NewImageList();
+          extent=(ssize_t) (read_info->scene+read_info->number_scenes);
+          scene=(ssize_t) read_info->scene;
+          for ( ; scene < (ssize_t) extent; scene++)
+          {
+            (void) InterpretImageFilename(image_info,(Image *) NULL,
+              read_filename,(int) scene,read_info->filename,exception);
+            image=ReadImage(read_info,exception);
+            if (image == (Image *) NULL)
+              continue;
+            AppendImageToList(&images,image);
+          }
           read_info=DestroyImageInfo(read_info);
-          return(ReadImage(image_info,exception));
+          return(images);
         }
-      (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
-      images=NewImageList();
-      extent=(ssize_t) (read_info->scene+read_info->number_scenes);
-      for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
-      {
-        (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(int)
-          scene,read_info->filename);
-        image=ReadImage(read_info,exception);
-        if (image == (Image *) NULL)
-          continue;
-        AppendImageToList(&images,image);
-      }
-      read_info=DestroyImageInfo(read_info);
-      return(images);
     }
-  return(ReadImage(image_info,exception));
+  (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
+  image=ReadImage(read_info,exception);
+  read_info=DestroyImageInfo(read_info);
+  return(image);
 }
 \f
 /*
@@ -985,7 +974,7 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
   Image *image,ExceptionInfo *exception)
 {
   char
-    filename[MaxTextExtent];
+    filename[MagickPathExtent];
 
   const char
     *option;
@@ -1006,64 +995,55 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
     status,
     temporary;
 
-  MagickStatusType
-    thread_support;
-
-  PolicyDomain
-    domain;
-
-  PolicyRights
-    rights;
-
   /*
     Determine image type from filename prefix or suffix (e.g. image.jpg).
   */
   assert(image_info != (ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       image_info->filename);
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   assert(exception != (ExceptionInfo *) NULL);
   sans_exception=AcquireExceptionInfo();
   write_info=CloneImageInfo(image_info);
-  (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
-  if (*write_info->magick == '\0')
-    (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
+  (void) CopyMagickString(write_info->filename,image->filename,
+    MagickPathExtent);
   (void) SetImageInfo(write_info,1,sans_exception);
-  if (LocaleCompare(write_info->magick,"clipmask") == 0)
-    {
-      if (image->clip_mask == (Image *) NULL)
-        {
-          (void) ThrowMagickException(exception,GetMagickModule(),
-            OptionError,"NoClipPathDefined","`%s'",image->filename);
-          return(MagickFalse);
-        }
-      image=image->clip_mask;
-      (void) SetImageInfo(write_info,1,sans_exception);
-    }
-  (void) CopyMagickString(filename,image->filename,MaxTextExtent);
-  (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
-  domain=CoderPolicyDomain;
-  rights=WritePolicyRights;
-  if (IsRightsAuthorized(domain,rights,write_info->magick) == MagickFalse)
-    {
-      sans_exception=DestroyExceptionInfo(sans_exception);
-      errno=EPERM;
-      ThrowBinaryException(PolicyError,"NotAuthorized",filename);
-    }
+  if (*write_info->magick == '\0')
+    (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
+  (void) CopyMagickString(filename,image->filename,MagickPathExtent);
+  (void) CopyMagickString(image->filename,write_info->filename,
+    MagickPathExtent);
+  /*
+    Call appropriate image writer based on image type.
+  */
   magick_info=GetMagickInfo(write_info->magick,sans_exception);
   sans_exception=DestroyExceptionInfo(sans_exception);
   if (magick_info != (const MagickInfo *) NULL)
     {
+      PolicyDomain
+        domain;
+
+      PolicyRights
+        rights;
+
+      domain=CoderPolicyDomain;
+      rights=WritePolicyRights;
+      if (IsRightsAuthorized(domain,rights,magick_info->module) == MagickFalse)
+        {
+          write_info=DestroyImageInfo(write_info);
+          errno=EPERM;
+          ThrowBinaryException(PolicyError,"NotAuthorized",filename);
+        }
       if (GetMagickEndianSupport(magick_info) == MagickFalse)
         image->endian=UndefinedEndian;
       else
         if ((image_info->endian == UndefinedEndian) &&
             (GetMagickRawSupport(magick_info) != MagickFalse))
           {
-            size_t
+            unsigned long
               lsb_first;
 
             lsb_first=1;
@@ -1071,13 +1051,13 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
          }
     }
   (void) SyncImageProfiles(image);
+  DisassociateImageStream(image);
   option=GetImageOption(image_info,"delegate:bimodal");
-  if ((option != (const char *) NULL) &&
-      (IsMagickTrue(option) != MagickFalse) &&
+  if ((IsStringTrue(option) != MagickFalse) &&
       (write_info->page == (char *) NULL) &&
       (GetPreviousImageInList(image) == (Image *) NULL) &&
       (GetNextImageInList(image) == (Image *) NULL) &&
-      (IsTaintImage(image) == MagickFalse))
+      (IsTaintImage(image) == MagickFalse) )
     {
       delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
       if ((delegate_info != (const DelegateInfo *) NULL) &&
@@ -1088,25 +1068,25 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
             Process image with bi-modal delegate.
           */
           (void) CopyMagickString(image->filename,image->magick_filename,
-            MaxTextExtent);
+            MagickPathExtent);
           status=InvokeDelegate(write_info,image,image->magick,
             write_info->magick,exception);
           write_info=DestroyImageInfo(write_info);
-          (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+          (void) CopyMagickString(image->filename,filename,MagickPathExtent);
           return(status);
         }
     }
   status=MagickFalse;
   temporary=MagickFalse;
   if ((magick_info != (const MagickInfo *) NULL) &&
-      (GetMagickSeekableStream(magick_info) != MagickFalse))
+      (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
     {
       char
-        filename[MaxTextExtent];
+        image_filename[MagickPathExtent];
 
-      (void) CopyMagickString(filename,image->filename,MaxTextExtent);
+      (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
       status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
-      (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+      (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
       if (status != MagickFalse)
         {
           if (IsBlobSeekable(image) == MagickFalse)
@@ -1116,27 +1096,24 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
               */
               write_info->adjoin=MagickTrue;
               (void) CopyMagickString(write_info->filename,image->filename,
-                MaxTextExtent);
+                MagickPathExtent);
               (void) AcquireUniqueFilename(image->filename);
               temporary=MagickTrue;
             }
           (void) CloseBlob(image);
         }
     }
-  if (constitute_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&constitute_semaphore);
   if ((magick_info != (const MagickInfo *) NULL) &&
       (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
     {
       /*
         Call appropriate image writer based on image type.
       */
-      thread_support=GetMagickThreadSupport(magick_info);
-      if ((thread_support & EncoderThreadSupport) == 0)
-        LockSemaphoreInfo(constitute_semaphore);
+      if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
+        LockSemaphoreInfo(magick_info->semaphore);
       status=GetImageEncoder(magick_info)(write_info,image,exception);
-      if ((thread_support & EncoderThreadSupport) == 0)
-        UnlockSemaphoreInfo(constitute_semaphore);
+      if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
+        UnlockSemaphoreInfo(magick_info->semaphore);
     }
   else
     {
@@ -1148,12 +1125,12 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
           */
           *write_info->filename='\0';
           if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
-            LockSemaphoreInfo(constitute_semaphore);
+            LockSemaphoreInfo(delegate_info->semaphore);
           status=InvokeDelegate(write_info,image,(char *) NULL,
             write_info->magick,exception);
           if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
-            UnlockSemaphoreInfo(constitute_semaphore);
-          (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+            UnlockSemaphoreInfo(delegate_info->semaphore);
+          (void) CopyMagickString(image->filename,filename,MagickPathExtent);
         }
       else
         {
@@ -1164,56 +1141,66 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
               (magick_info == (const MagickInfo *) NULL))
             {
               (void) CopyMagickString(write_info->magick,image->magick,
-                MaxTextExtent);
+                MagickPathExtent);
               magick_info=GetMagickInfo(write_info->magick,exception);
             }
           if ((magick_info == (const MagickInfo *) NULL) ||
               (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
             {
               char
-                extension[MaxTextExtent];
+                extension[MagickPathExtent];
 
               GetPathComponent(image->filename,ExtensionPath,extension);
               if (*extension != '\0')
                 magick_info=GetMagickInfo(extension,exception);
               else
                 magick_info=GetMagickInfo(image->magick,exception);
-              (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+              (void) CopyMagickString(image->filename,filename,
+                MagickPathExtent);
             }
           if ((magick_info == (const MagickInfo *) NULL) ||
               (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
-            (void) ThrowMagickException(exception,GetMagickModule(),
-              MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'",
-              image->filename);
-          else
+            {
+              magick_info=GetMagickInfo(image->magick,exception);
+              if ((magick_info == (const MagickInfo *) NULL) ||
+                  (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
+                (void) ThrowMagickException(exception,GetMagickModule(),
+                  MissingDelegateError,"NoEncodeDelegateForThisImageFormat",
+                  "`%s'",write_info->magick);
+              else
+                (void) ThrowMagickException(exception,GetMagickModule(),
+                  MissingDelegateWarning,"NoEncodeDelegateForThisImageFormat",
+                  "`%s'",write_info->magick);
+            }
+          if ((magick_info != (const MagickInfo *) NULL) &&
+              (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
             {
               /*
                 Call appropriate image writer based on image type.
               */
-              thread_support=GetMagickThreadSupport(magick_info);
-              if ((thread_support & EncoderThreadSupport) == 0)
-                LockSemaphoreInfo(constitute_semaphore);
+              if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
+                LockSemaphoreInfo(magick_info->semaphore);
               status=GetImageEncoder(magick_info)(write_info,image,exception);
-              if ((thread_support & EncoderThreadSupport) == 0)
-                UnlockSemaphoreInfo(constitute_semaphore);
+              if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
+                UnlockSemaphoreInfo(magick_info->semaphore);
             }
         }
     }
-  if (GetBlobError(image) != MagickFalse)
-    ThrowFileException(exception,FileOpenError,
-      "AnErrorHasOccurredWritingToFile",image->filename);
-  if (temporary == MagickTrue)
+  if (temporary != MagickFalse)
     {
       /*
         Copy temporary image file to permanent.
       */
       status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
       if (status != MagickFalse)
-        status=ImageToFile(image,write_info->filename,exception);
+        {
+          (void) RelinquishUniqueFileResource(write_info->filename);
+          status=ImageToFile(image,write_info->filename,exception);
+        }
       (void) CloseBlob(image);
       (void) RelinquishUniqueFileResource(image->filename);
       (void) CopyMagickString(image->filename,write_info->filename,
-        MaxTextExtent);
+        MagickPathExtent);
     }
   if ((LocaleCompare(write_info->magick,"info") != 0) &&
       (write_info->verbose != MagickFalse))
@@ -1263,9 +1250,6 @@ MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
 {
 #define WriteImageTag  "Write/Image"
 
-  BlobInfo
-    *blob;
-
   ExceptionInfo
     *sans_exception;
 
@@ -1276,7 +1260,7 @@ MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
     proceed;
 
   MagickOffsetType
-    i;
+    progress;
 
   MagickProgressMonitor
     progress_monitor;
@@ -1291,30 +1275,36 @@ MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
     *p;
 
   assert(image_info != (const ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   assert(images != (Image *) NULL);
-  assert(images->signature == MagickSignature);
+  assert(images->signature == MagickCoreSignature);
   if (images->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
   assert(exception != (ExceptionInfo *) NULL);
   write_info=CloneImageInfo(image_info);
+  *write_info->magick='\0';
   images=GetFirstImageInList(images);
-  blob=CloneBlobInfo(images->blob);  /* thread specific I/O handler */
-  DestroyBlob(images);
-  images->blob=blob;
   if (filename != (const char *) NULL)
     for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
-      (void) CopyMagickString(p->filename,filename,MaxTextExtent);
-  (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
-  if (*write_info->magick == '\0')
-    (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
+      (void) CopyMagickString(p->filename,filename,MagickPathExtent);
+  (void) CopyMagickString(write_info->filename,images->filename,
+    MagickPathExtent);
   sans_exception=AcquireExceptionInfo();
   (void) SetImageInfo(write_info,(unsigned int) GetImageListLength(images),
     sans_exception);
   sans_exception=DestroyExceptionInfo(sans_exception);
+  if (*write_info->magick == '\0')
+    (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
   p=images;
   for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
-    if (p->scene >= GetNextImageInList(p)->scene)
+  {
+    register Image
+      *next;
+
+    next=GetNextImageInList(p);
+    if (next == (Image *) NULL)
+      break;
+    if (p->scene >= next->scene)
       {
         register ssize_t
           i;
@@ -1327,12 +1317,13 @@ MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
           p->scene=(size_t) i++;
         break;
       }
+  }
   /*
     Write images.
   */
   status=MagickTrue;
   progress_monitor=(MagickProgressMonitor) NULL;
-  i=0;
+  progress=0;
   number_images=GetImageListLength(images);
   for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
   {
@@ -1340,14 +1331,13 @@ MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
       progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
         p->client_data);
     status&=WriteImage(write_info,p,exception);
-    GetImageException(p,exception);
     if (number_images != 1)
       (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
     if (write_info->adjoin != MagickFalse)
       break;
     if (number_images != 1)
       {
-        proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
+        proceed=SetImageProgress(p,WriteImageTag,progress++,number_images);
         if (proceed == MagickFalse)
           break;
       }