]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/constitute.c
Update web pages
[imagemagick] / MagickCore / constitute.c
index d22fbb7eaa33300ea3b9c7fcd61550bfbbd59e4c..555be54c76db741af6dc2006f2ef224a5f9ba6ea 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-2015 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  %
   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"
 #include "MagickCore/geometry.h"
 #include "MagickCore/identify.h"
@@ -61,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"
-\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)
-%
-*/
-MagickExport 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)
-%
-*/
-MagickExport void ConstituteComponentTerminus(void)
-{
-  if (constitute_semaphore == (SemaphoreInfo *) NULL)
-    AcquireSemaphoreInfo(&constitute_semaphore);
-  DestroySemaphoreInfo(&constitute_semaphore);
-}
+#include "MagickCore/utility-private.h"
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -175,9 +129,9 @@ MagickExport 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;
@@ -192,21 +146,18 @@ 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);
-  status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels);
+  (void) SetImageBackgroundColor(image,exception);
+  status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels,exception);
   if (status == MagickFalse)
-    {
-      InheritException(exception,&image->exception);
-      image=DestroyImage(image);
-    }
+     image=DestroyImage(image);
   return(image);
 }
 \f
@@ -263,7 +214,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);
@@ -296,20 +247,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,
@@ -322,14 +276,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;
@@ -345,13 +301,18 @@ 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;
@@ -395,9 +356,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;
@@ -422,8 +383,7 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
     *read_info;
 
   MagickStatusType
-    flags,
-    thread_support;
+    flags;
 
   PolicyDomain
     domain;
@@ -435,17 +395,17 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
     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);
+  (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
+  (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
   domain=CoderPolicyDomain;
   rights=ReadPolicyRights;
   if (IsRightsAuthorized(domain,rights,read_info->magick) == MagickFalse)
@@ -453,6 +413,7 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
       errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
         "NotAuthorized","`%s'",read_info->filename);
+      read_info=DestroyImageInfo(read_info);
       return((Image *) NULL);
     }
   /*
@@ -483,9 +444,9 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
       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)
         {
@@ -513,17 +474,25 @@ 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
     {
@@ -532,7 +501,7 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
         {
           (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);
@@ -541,21 +510,21 @@ 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);
+        LockSemaphoreInfo(delegate_info->semaphore);
       (void) 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);
@@ -566,26 +535,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)
     {
@@ -614,20 +582,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;
@@ -637,48 +597,48 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
 
     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;
         (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;
         (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);
@@ -692,22 +652,22 @@ MagickExport Image *ReadImage(const ImageInfo *image_info,
     option=GetImageOption(read_info,"caption");
     if (option != (const char *) NULL)
       {
-        property=InterpretImageProperties(read_info,next,option);
-        (void) SetImageProperty(next,"caption",property);
+        property=InterpretImageProperties(read_info,next,option,exception);
+        (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);
-        (void) SetImageProperty(next,"comment",property);
+        property=InterpretImageProperties(read_info,next,option,exception);
+        (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);
-        (void) SetImageProperty(next,"label",property);
+        property=InterpretImageProperties(read_info,next,option,exception);
+        (void) SetImageProperty(next,"label",property,exception);
         property=DestroyString(property);
       }
     if (LocaleCompare(next->magick,"TEXT") == 0)
@@ -740,7 +700,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);
                 }
@@ -752,12 +712,12 @@ 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)
       {
@@ -808,20 +768,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,
@@ -834,14 +797,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;
@@ -853,7 +820,6 @@ 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);
@@ -862,13 +828,13 @@ MagickExport Image *ReadImages(const ImageInfo *image_info,
           read_info=DestroyImageInfo(read_info);
           return(ReadImage(image_info,exception));
         }
-      (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
+      (void) CopyMagickString(read_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,read_filename,
+          (int) scene,read_info->filename,exception);
         image=ReadImage(read_info,exception);
         if (image == (Image *) NULL)
           continue;
@@ -877,7 +843,9 @@ MagickExport Image *ReadImages(const ImageInfo *image_info,
       read_info=DestroyImageInfo(read_info);
       return(images);
     }
-  return(ReadImage(image_info,exception));
+  image=ReadImage(read_info,exception);
+  read_info=DestroyImageInfo(read_info);
+  return(image);
 }
 \f
 /*
@@ -986,7 +954,7 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
   Image *image,ExceptionInfo *exception)
 {
   char
-    filename[MaxTextExtent];
+    filename[MagickPathExtent];
 
   const char
     *option;
@@ -1007,9 +975,6 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
     status,
     temporary;
 
-  MagickStatusType
-    thread_support;
-
   PolicyDomain
     domain;
 
@@ -1020,40 +985,33 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
     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);
+  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);
   domain=CoderPolicyDomain;
   rights=WritePolicyRights;
   if (IsRightsAuthorized(domain,rights,write_info->magick) == MagickFalse)
     {
       sans_exception=DestroyExceptionInfo(sans_exception);
+      write_info=DestroyImageInfo(write_info);
       errno=EPERM;
       ThrowBinaryException(PolicyError,"NotAuthorized",filename);
     }
+  /*
+    Call appropriate image reader based on image type.
+  */
   magick_info=GetMagickInfo(write_info->magick,sans_exception);
   sans_exception=DestroyExceptionInfo(sans_exception);
   if (magick_info != (const MagickInfo *) NULL)
@@ -1072,13 +1030,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 ((IfMagickTrue(IsStringTrue(option))) &&
       (write_info->page == (char *) NULL) &&
       (GetPreviousImageInList(image) == (Image *) NULL) &&
       (GetNextImageInList(image) == (Image *) NULL) &&
-      (IsTaintImage(image) == MagickFalse))
+      (IfMagickFalse(IsTaintImage(image))) )
     {
       delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
       if ((delegate_info != (const DelegateInfo *) NULL) &&
@@ -1089,11 +1047,11 @@ 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);
         }
     }
@@ -1103,11 +1061,11 @@ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
       (GetMagickSeekableStream(magick_info) != MagickFalse))
     {
       char
-        filename[MaxTextExtent];
+        filename[MagickPathExtent];
 
-      (void) CopyMagickString(filename,image->filename,MaxTextExtent);
+      (void) CopyMagickString(filename,image->filename,MagickPathExtent);
       status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
-      (void) CopyMagickString(image->filename,filename,MaxTextExtent);
+      (void) CopyMagickString(image->filename,filename,MagickPathExtent);
       if (status != MagickFalse)
         {
           if (IsBlobSeekable(image) == MagickFalse)
@@ -1117,27 +1075,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
     {
@@ -1149,12 +1104,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
         {
@@ -1165,56 +1120,65 @@ 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))
@@ -1264,9 +1228,6 @@ MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
 {
 #define WriteImageTag  "Write/Image"
 
-  BlobInfo
-    *blob;
-
   ExceptionInfo
     *sans_exception;
 
@@ -1292,27 +1253,25 @@ 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)
@@ -1341,7 +1300,6 @@ 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)