]> granicus.if.org Git - imagemagick/blob - magick/constitute.c
Remove previous geometry changes
[imagemagick] / magick / constitute.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %     CCCC   OOO   N   N  SSSSS  TTTTT  IIIII  TTTTT  U   U  TTTTT  EEEEE     %
7 %    C      O   O  NN  N  SS       T      I      T    U   U    T    E         %
8 %    C      O   O  N N N  ESSS     T      I      T    U   U    T    EEE       %
9 %    C      O   O  N  NN     SS    T      I      T    U   U    T    E         %
10 %     CCCC   OOO   N   N  SSSSS    T    IIIII    T     UUU     T    EEEEE     %
11 %                                                                             %
12 %                                                                             %
13 %                  MagickCore Methods to Consitute an Image                   %
14 %                                                                             %
15 %                             Software Design                                 %
16 %                               John Cristy                                   %
17 %                               October 1998                                  %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %
37 */
38 \f
39 /*
40   Include declarations.
41 */
42 #include "magick/studio.h"
43 #include "magick/blob.h"
44 #include "magick/blob-private.h"
45 #include "magick/exception.h"
46 #include "magick/exception-private.h"
47 #include "magick/cache.h"
48 #include "magick/client.h"
49 #include "magick/constitute.h"
50 #include "magick/delegate.h"
51 #include "magick/geometry.h"
52 #include "magick/identify.h"
53 #include "magick/image-private.h"
54 #include "magick/list.h"
55 #include "magick/magick.h"
56 #include "magick/memory_.h"
57 #include "magick/monitor.h"
58 #include "magick/monitor-private.h"
59 #include "magick/option.h"
60 #include "magick/pixel.h"
61 #include "magick/policy.h"
62 #include "magick/profile.h"
63 #include "magick/property.h"
64 #include "magick/quantum.h"
65 #include "magick/resize.h"
66 #include "magick/resource_.h"
67 #include "magick/semaphore.h"
68 #include "magick/statistic.h"
69 #include "magick/stream.h"
70 #include "magick/string_.h"
71 #include "magick/string-private.h"
72 #include "magick/timer.h"
73 #include "magick/transform.h"
74 #include "magick/utility.h"
75 \f
76 static SemaphoreInfo
77   *constitute_semaphore = (SemaphoreInfo *) NULL;
78 \f
79 /*
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %                                                                             %
82 %                                                                             %
83 %                                                                             %
84 +   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                       %
85 %                                                                             %
86 %                                                                             %
87 %                                                                             %
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 %
90 %  ConstituteComponentGenesis() instantiates the constitute component.
91 %
92 %  The format of the ConstituteComponentGenesis method is:
93 %
94 %      MagickBooleanType ConstituteComponentGenesis(void)
95 %
96 */
97 MagickExport MagickBooleanType ConstituteComponentGenesis(void)
98 {
99   AcquireSemaphoreInfo(&constitute_semaphore);
100   return(MagickTrue);
101 }
102 \f
103 /*
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 %                                                                             %
106 %                                                                             %
107 %                                                                             %
108 +   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                     %
109 %                                                                             %
110 %                                                                             %
111 %                                                                             %
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 %
114 %  ConstituteComponentTerminus() destroys the constitute component.
115 %
116 %  The format of the ConstituteComponentTerminus method is:
117 %
118 %      ConstituteComponentTerminus(void)
119 %
120 */
121 MagickExport void ConstituteComponentTerminus(void)
122 {
123   if (constitute_semaphore == (SemaphoreInfo *) NULL)
124     AcquireSemaphoreInfo(&constitute_semaphore);
125   DestroySemaphoreInfo(&constitute_semaphore);
126 }
127 \f
128 /*
129 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 %                                                                             %
131 %                                                                             %
132 %                                                                             %
133 %   C o n s t i t u t e I m a g e                                             %
134 %                                                                             %
135 %                                                                             %
136 %                                                                             %
137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138 %
139 %  ConstituteImage() returns an image from the pixel data you supply.
140 %  The pixel data must be in scanline order top-to-bottom.  The data can be
141 %  char, short int, int, float, or double.  Float and double require the
142 %  pixels to be normalized [0..1], otherwise [0..QuantumRange].  For example, to
143 %  create a 640x480 image from unsigned red-green-blue character data, use:
144 %
145 %      image = ConstituteImage(640,480,"RGB",CharPixel,pixels,&exception);
146 %
147 %  The format of the ConstituteImage method is:
148 %
149 %      Image *ConstituteImage(const unsigned long columns,
150 %        const unsigned long rows,const char *map,const StorageType storage,
151 %        const void *pixels,ExceptionInfo *exception)
152 %
153 %  A description of each parameter follows:
154 %
155 %    o columns: width in pixels of the image.
156 %
157 %    o rows: height in pixels of the image.
158 %
159 %    o map:  This string reflects the expected ordering of the pixel array.
160 %      It can be any combination or order of R = red, G = green, B = blue,
161 %      A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
162 %      Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
163 %      P = pad.
164 %
165 %    o storage: Define the data type of the pixels.  Float and double types are
166 %      expected to be normalized [0..1] otherwise [0..QuantumRange].  Choose
167 %      from these types: CharPixel, DoublePixel, FloatPixel, IntegerPixel,
168 %      LongPixel, QuantumPixel, or ShortPixel.
169 %
170 %    o pixels: This array of values contain the pixel components as defined by
171 %      map and type.  You must preallocate this array where the expected
172 %      length varies depending on the values of width, height, map, and type.
173 %
174 %    o exception: return any errors or warnings in this structure.
175 %
176 */
177 MagickExport Image *ConstituteImage(const unsigned long columns,
178   const unsigned long rows,const char *map,const StorageType storage,
179   const void *pixels,ExceptionInfo *exception)
180 {
181   Image
182     *image;
183
184   MagickBooleanType
185     status;
186
187   /*
188     Allocate image structure.
189   */
190   assert(map != (const char *) NULL);
191   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",map);
192   assert(pixels != (void *) NULL);
193   assert(exception != (ExceptionInfo *) NULL);
194   assert(exception->signature == MagickSignature);
195   image=AcquireImage((ImageInfo *) NULL);
196   if (image == (Image *) NULL)
197     return((Image *) NULL);
198   if ((columns == 0) || (rows == 0))
199     ThrowImageException(OptionError,"NonZeroWidthAndHeightRequired");
200   image->columns=columns;
201   image->rows=rows;
202   (void) SetImageBackgroundColor(image);
203   status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels);
204   if (status == MagickFalse)
205     {
206       InheritException(exception,&image->exception);
207       image=DestroyImage(image);
208     }
209   return(image);
210 }
211 \f
212 /*
213 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 %                                                                             %
215 %                                                                             %
216 %                                                                             %
217 %   P i n g I m a g e                                                         %
218 %                                                                             %
219 %                                                                             %
220 %                                                                             %
221 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 %
223 %  PingImage() returns all the properties of an image or image sequence
224 %  except for the pixels.  It is much faster and consumes far less memory
225 %  than ReadImage().  On failure, a NULL image is returned and exception
226 %  describes the reason for the failure.
227 %
228 %  The format of the PingImage method is:
229 %
230 %      Image *PingImage(const ImageInfo *image_info,ExceptionInfo *exception)
231 %
232 %  A description of each parameter follows:
233 %
234 %    o image_info: Ping the image defined by the file or filename members of
235 %      this structure.
236 %
237 %    o exception: return any errors or warnings in this structure.
238 %
239 */
240
241 #if defined(__cplusplus) || defined(c_plusplus)
242 extern "C" {
243 #endif
244
245 static size_t PingStream(const Image *magick_unused(image),
246   const void *magick_unused(pixels),const size_t columns)
247 {
248   return(columns);
249 }
250
251 #if defined(__cplusplus) || defined(c_plusplus)
252 }
253 #endif
254
255 MagickExport Image *PingImage(const ImageInfo *image_info,
256   ExceptionInfo *exception)
257 {
258   Image
259     *image;
260
261   ImageInfo
262     *ping_info;
263
264   assert(image_info != (ImageInfo *) NULL);
265   assert(image_info->signature == MagickSignature);
266   if (image_info->debug != MagickFalse)
267     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
268       image_info->filename);
269   assert(exception != (ExceptionInfo *) NULL);
270   ping_info=CloneImageInfo(image_info);
271   ping_info->ping=MagickTrue;
272   image=ReadStream(ping_info,&PingStream,exception);
273   if (image != (Image *) NULL)
274     {
275       ResetTimer(&image->timer);
276       if (ping_info->verbose != MagickFalse)
277         (void) IdentifyImage(image,stdout,MagickFalse);
278     }
279   ping_info=DestroyImageInfo(ping_info);
280   return(image);
281 }
282 \f
283 /*
284 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 %                                                                             %
286 %                                                                             %
287 %                                                                             %
288 %   P i n g I m a g e s                                                       %
289 %                                                                             %
290 %                                                                             %
291 %                                                                             %
292 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
293 %
294 %  PingImages() pings one or more images and returns them as an image list.
295 %
296 %  The format of the PingImage method is:
297 %
298 %      Image *PingImages(const ImageInfo *image_info,ExceptionInfo *exception)
299 %
300 %  A description of each parameter follows:
301 %
302 %    o image_info: the image info.
303 %
304 %    o exception: return any errors or warnings in this structure.
305 %
306 */
307 MagickExport Image *PingImages(const ImageInfo *image_info,
308   ExceptionInfo *exception)
309 {
310   char
311     filename[MaxTextExtent];
312
313   Image
314     *image,
315     *images;
316
317   ImageInfo
318     *read_info;
319
320   /*
321     Ping image list from a file.
322   */
323   assert(image_info != (ImageInfo *) NULL);
324   assert(image_info->signature == MagickSignature);
325   if (image_info->debug != MagickFalse)
326     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
327       image_info->filename);
328   assert(exception != (ExceptionInfo *) NULL);
329   (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
330     (int) image_info->scene,filename);
331   if (LocaleCompare(filename,image_info->filename) != 0)
332     {
333       ExceptionInfo
334         *sans;
335
336       long
337         extent,
338         scene;
339
340       /*
341         Images of the form image-%d.png[1-5].
342       */
343       read_info=CloneImageInfo(image_info);
344       sans=AcquireExceptionInfo();
345       (void) SetImageInfo(read_info,0,sans);
346       sans=DestroyExceptionInfo(sans);
347       (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
348       images=NewImageList();
349       extent=(long) (read_info->scene+read_info->number_scenes);
350       for (scene=(long) read_info->scene; scene < (long) extent; scene++)
351       {
352         (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(int)
353           scene,read_info->filename);
354         image=PingImage(read_info,exception);
355         if (image == (Image *) NULL)
356           continue;
357         AppendImageToList(&images,image);
358       }
359       read_info=DestroyImageInfo(read_info);
360       return(images);
361     }
362   return(PingImage(image_info,exception));
363 }
364 \f
365 /*
366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367 %                                                                             %
368 %                                                                             %
369 %                                                                             %
370 %   R e a d I m a g e                                                         %
371 %                                                                             %
372 %                                                                             %
373 %                                                                             %
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 %
376 %  ReadImage() reads an image or image sequence from a file or file handle.
377 %  The method returns a NULL if there is a memory shortage or if the image
378 %  cannot be read.  On failure, a NULL image is returned and exception
379 %  describes the reason for the failure.
380 %
381 %  The format of the ReadImage method is:
382 %
383 %      Image *ReadImage(const ImageInfo *image_info,ExceptionInfo *exception)
384 %
385 %  A description of each parameter follows:
386 %
387 %    o image_info: Read the image defined by the file or filename members of
388 %      this structure.
389 %
390 %    o exception: return any errors or warnings in this structure.
391 %
392 */
393 MagickExport Image *ReadImage(const ImageInfo *image_info,
394   ExceptionInfo *exception)
395 {
396   char
397     filename[MaxTextExtent],
398     magick[MaxTextExtent],
399     magick_filename[MaxTextExtent];
400
401   const char
402     *value;
403
404   const DelegateInfo
405     *delegate_info;
406
407   const MagickInfo
408     *magick_info;
409
410   ExceptionInfo
411     *sans_exception;
412
413   GeometryInfo
414     geometry_info;
415
416   Image
417     *image,
418     *next;
419
420   ImageInfo
421     *read_info;
422
423   MagickStatusType
424     flags,
425     thread_support;
426
427   PolicyDomain
428     domain;
429
430   PolicyRights
431     rights;
432
433   /*
434     Determine image type from filename prefix or suffix (e.g. image.jpg).
435   */
436   assert(image_info != (ImageInfo *) NULL);
437   assert(image_info->signature == MagickSignature);
438   assert(image_info->filename != (char *) NULL);
439   if (image_info->debug != MagickFalse)
440     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
441       image_info->filename);
442   assert(exception != (ExceptionInfo *) NULL);
443   read_info=CloneImageInfo(image_info);
444   (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
445   (void) SetImageInfo(read_info,0,exception);
446   (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
447   (void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
448   domain=CoderPolicyDomain;
449   rights=ReadPolicyRights;
450   if (IsRightsAuthorized(domain,rights,read_info->magick) == MagickFalse)
451     {
452       errno=EPERM;
453       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
454         "NotAuthorized","`%s'",read_info->filename);
455       return((Image *) NULL);
456     }
457   /*
458     Call appropriate image reader based on image type.
459   */
460   sans_exception=AcquireExceptionInfo();
461   magick_info=GetMagickInfo(read_info->magick,sans_exception);
462   sans_exception=DestroyExceptionInfo(sans_exception);
463   if (magick_info != (const MagickInfo *) NULL)
464     {
465       if (GetMagickEndianSupport(magick_info) == MagickFalse)
466         read_info->endian=UndefinedEndian;
467       else
468         if ((image_info->endian == UndefinedEndian) &&
469             (GetMagickRawSupport(magick_info) != MagickFalse))
470           {
471             unsigned long
472               lsb_first;
473
474             lsb_first=1;
475             read_info->endian=(*(char *) &lsb_first) == 1 ? LSBEndian :
476               MSBEndian;
477          }
478     }
479   if ((magick_info != (const MagickInfo *) NULL) &&
480       (GetMagickSeekableStream(magick_info) != MagickFalse))
481     {
482       MagickBooleanType
483         status;
484
485       image=AcquireImage(read_info);
486       (void) CopyMagickString(image->filename,read_info->filename,
487         MaxTextExtent);
488       status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
489       if (status == MagickFalse)
490         {
491           read_info=DestroyImageInfo(read_info);
492           image=DestroyImage(image);
493           return((Image *) NULL);
494         }
495       if (IsBlobSeekable(image) == MagickFalse)
496         {
497           /*
498             Coder requires a seekable stream.
499           */
500           *read_info->filename='\0';
501           status=ImageToFile(image,read_info->filename,exception);
502           if (status == MagickFalse)
503             {
504               (void) CloseBlob(image);
505               read_info=DestroyImageInfo(read_info);
506               image=DestroyImage(image);
507               return((Image *) NULL);
508             }
509           read_info->temporary=MagickTrue;
510         }
511       (void) CloseBlob(image);
512       image=DestroyImage(image);
513     }
514   image=NewImageList();
515   if (constitute_semaphore == (SemaphoreInfo *) NULL)
516     AcquireSemaphoreInfo(&constitute_semaphore);
517   if ((magick_info != (const MagickInfo *) NULL) &&
518       (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL))
519     {
520       thread_support=GetMagickThreadSupport(magick_info);
521       if ((thread_support & DecoderThreadSupport) == 0)
522         LockSemaphoreInfo(constitute_semaphore);
523       image=GetImageDecoder(magick_info)(read_info,exception);
524       if ((thread_support & DecoderThreadSupport) == 0)
525         UnlockSemaphoreInfo(constitute_semaphore);
526     }
527   else
528     {
529       delegate_info=GetDelegateInfo(read_info->magick,(char *) NULL,exception);
530       if (delegate_info == (const DelegateInfo *) NULL)
531         {
532           (void) ThrowMagickException(exception,GetMagickModule(),
533             MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
534             read_info->filename);
535           if (read_info->temporary != MagickFalse)
536             (void) RelinquishUniqueFileResource(read_info->filename);
537           read_info=DestroyImageInfo(read_info);
538           return((Image *) NULL);
539         }
540       /*
541         Let our decoding delegate process the image.
542       */
543       image=AcquireImage(read_info);
544       if (image == (Image *) NULL)
545         {
546           read_info=DestroyImageInfo(read_info);
547           return((Image *) NULL);
548         }
549       (void) CopyMagickString(image->filename,read_info->filename,
550         MaxTextExtent);
551       *read_info->filename='\0';
552       if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
553         LockSemaphoreInfo(constitute_semaphore);
554       (void) InvokeDelegate(read_info,image,read_info->magick,(char *) NULL,
555         exception);
556       if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
557         UnlockSemaphoreInfo(constitute_semaphore);
558       image=DestroyImageList(image);
559       read_info->temporary=MagickTrue;
560       (void) SetImageInfo(read_info,0,exception);
561       magick_info=GetMagickInfo(read_info->magick,exception);
562       if ((magick_info == (const MagickInfo *) NULL) ||
563           (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL))
564         {
565           if (IsPathAccessible(read_info->filename) != MagickFalse)
566             (void) ThrowMagickException(exception,GetMagickModule(),
567               MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
568               read_info->filename);
569           else
570             ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
571               read_info->filename);
572           read_info=DestroyImageInfo(read_info);
573           return((Image *) NULL);
574         }
575       thread_support=GetMagickThreadSupport(magick_info);
576       if ((thread_support & DecoderThreadSupport) == 0)
577         LockSemaphoreInfo(constitute_semaphore);
578       image=(Image *) (GetImageDecoder(magick_info))(read_info,exception);
579       if ((thread_support & DecoderThreadSupport) == 0)
580         UnlockSemaphoreInfo(constitute_semaphore);
581     }
582   if (read_info->temporary != MagickFalse)
583     {
584       (void) RelinquishUniqueFileResource(read_info->filename);
585       read_info->temporary=MagickFalse;
586       if (image != (Image *) NULL)
587         (void) CopyMagickString(image->filename,filename,MaxTextExtent);
588     }
589   if (image == (Image *) NULL)
590     {
591       read_info=DestroyImageInfo(read_info);
592       return(image);
593     }
594   if (exception->severity >= ErrorException)
595     (void) LogMagickEvent(ExceptionEvent,GetMagickModule(),
596       "Coder (%s) generated an image despite an error (%d), "
597       "notify the developers",image->magick,exception->severity);
598   if (IsBlobTemporary(image) != MagickFalse)
599     (void) RelinquishUniqueFileResource(read_info->filename);
600   if ((GetNextImageInList(image) != (Image *) NULL) &&
601       (IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse))
602     {
603       Image
604         *clones;
605
606       clones=CloneImages(image,read_info->scenes,exception);
607       if (clones == (Image *) NULL)
608         (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
609           "SubimageSpecificationReturnsNoImages","`%s'",read_info->filename);
610       else
611         {
612           image=DestroyImageList(image);
613           image=GetFirstImageInList(clones);
614         }
615     }
616   if (GetBlobError(image) != MagickFalse)
617     {
618       ThrowFileException(exception,FileOpenError,
619         "AnErrorHasOccurredReadingFromFile",read_info->filename);
620       image=DestroyImageList(image);
621       read_info=DestroyImageInfo(read_info);
622       return((Image *) NULL);
623     }
624   for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
625   {
626     char
627       timestamp[MaxTextExtent];
628
629     const StringInfo
630       *profile;
631
632     next->taint=MagickFalse;
633     if (next->magick_columns == 0)
634       next->magick_columns=next->columns;
635     if (next->magick_rows == 0)
636       next->magick_rows=next->rows;
637     if ((LocaleCompare(magick,"HTTP") != 0) &&
638         (LocaleCompare(magick,"FTP") != 0))
639       (void) CopyMagickString(next->magick,magick,MaxTextExtent);
640     (void) CopyMagickString(next->magick_filename,magick_filename,
641       MaxTextExtent);
642     if (IsBlobTemporary(image) != MagickFalse)
643       (void) CopyMagickString(next->filename,filename,MaxTextExtent);
644     value=GetImageProperty(next,"tiff:Orientation");
645     if (value == (char *) NULL)
646       value=GetImageProperty(next,"exif:Orientation");
647     if (value != (char *) NULL)
648       {
649         next->orientation=(OrientationType) StringToLong(value);
650         (void) DeleteImageProperty(next,"tiff:Orientation");
651         (void) DeleteImageProperty(next,"exif:Orientation");
652       }
653     value=GetImageProperty(next,"tiff:XResolution");
654     if (value == (char *) NULL)
655       value=GetImageProperty(next,"exif:XResolution");
656     if (value != (char *) NULL)
657       {
658         geometry_info.rho=next->x_resolution;
659         geometry_info.sigma=1.0;
660         flags=ParseGeometry(value,&geometry_info);
661         if (geometry_info.sigma != 0)
662           next->x_resolution=geometry_info.rho/geometry_info.sigma;
663         (void) DeleteImageProperty(next,"exif:XResolution");
664         (void) DeleteImageProperty(next,"tiff:XResolution");
665       }
666     value=GetImageProperty(next,"tiff:YResolution");
667     if (value == (char *) NULL)
668       value=GetImageProperty(next,"exif:YResolution");
669     if (value != (char *) NULL)
670       {
671         geometry_info.rho=next->y_resolution;
672         geometry_info.sigma=1.0;
673         flags=ParseGeometry(value,&geometry_info);
674         if (geometry_info.sigma != 0)
675           next->y_resolution=geometry_info.rho/geometry_info.sigma;
676         (void) DeleteImageProperty(next,"exif:YResolution");
677         (void) DeleteImageProperty(next,"tiff:YResolution");
678       }
679     value=GetImageProperty(next,"tiff:ResolutionUnit");
680     if (value == (char *) NULL)
681       value=GetImageProperty(next,"exif:ResolutionUnit");
682     if (value != (char *) NULL)
683       {
684         next->units=(ResolutionType) (StringToLong(value)-1);
685         (void) DeleteImageProperty(next,"exif:ResolutionUnit");
686         (void) DeleteImageProperty(next,"tiff:ResolutionUnit");
687       }
688     if (next->page.width == 0)
689       next->page.width=next->columns;
690     if (next->page.height == 0)
691       next->page.height=next->rows;
692     if (*read_info->filename != '\0')
693       {
694         char
695           *property;
696
697         const char
698           *option;
699
700         option=GetImageOption(read_info,"caption");
701         if (option != (const char *) NULL)
702           {
703             property=InterpretImageProperties(read_info,next,option);
704             (void) SetImageProperty(next,"caption",property);
705             property=DestroyString(property);
706           }
707         option=GetImageOption(read_info,"comment");
708         if (option != (const char *) NULL)
709           {
710             property=InterpretImageProperties(read_info,next,option);
711             (void) SetImageProperty(next,"comment",property);
712             property=DestroyString(property);
713           }
714         option=GetImageOption(read_info,"label");
715         if (option != (const char *) NULL)
716           {
717             property=InterpretImageProperties(read_info,next,option);
718             (void) SetImageProperty(next,"label",property);
719             property=DestroyString(property);
720           }
721       }
722     if (LocaleCompare(next->magick,"TEXT") == 0)
723       (void) ParseAbsoluteGeometry("0x0+0+0",&next->page);
724     if ((read_info->extract != (char *) NULL) &&
725         (read_info->stream == (StreamHandler) NULL))
726       {
727         RectangleInfo
728           geometry;
729
730         flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
731         if ((next->columns != geometry.width) ||
732             (next->rows != geometry.height))
733           {
734             if (((flags & XValue) != 0) || ((flags & YValue) != 0))
735               {
736                 Image
737                   *crop_image;
738
739                 crop_image=CropImage(next,&geometry,exception);
740                 if (crop_image != (Image *) NULL)
741                   ReplaceImageInList(&next,crop_image);
742               }
743             else
744               if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
745                 {
746                   Image
747                     *size_image;
748
749                   flags=ParseRegionGeometry(next,read_info->extract,&geometry,
750                     exception);
751                   size_image=ResizeImage(next,geometry.width,geometry.height,
752                     next->filter,next->blur,exception);
753                   if (size_image != (Image *) NULL)
754                     ReplaceImageInList(&next,size_image);
755                 }
756           }
757       }
758     profile=GetImageProfile(next,"icc");
759     if (profile == (const StringInfo *) NULL)
760       profile=GetImageProfile(next,"icm");
761     if (profile != (const StringInfo *) NULL)
762       {
763         next->color_profile.length=GetStringInfoLength(profile);
764         next->color_profile.info=GetStringInfoDatum(profile);
765       }
766     profile=GetImageProfile(next,"iptc");
767     if (profile == (const StringInfo *) NULL)
768       profile=GetImageProfile(next,"8bim");
769     if (profile != (const StringInfo *) NULL)
770       {
771         next->iptc_profile.length=GetStringInfoLength(profile);
772         next->iptc_profile.info=GetStringInfoDatum(profile);
773       }
774     (void) FormatMagickTime(GetBlobProperties(next)->st_mtime,MaxTextExtent,
775       timestamp);
776     (void) SetImageProperty(next,"date:modify",timestamp);
777     (void) FormatMagickTime(GetBlobProperties(next)->st_ctime,MaxTextExtent,
778       timestamp);
779     (void) SetImageProperty(next,"date:create",timestamp);
780     if (read_info->verbose != MagickFalse)
781       (void) IdentifyImage(next,stdout,MagickFalse);
782     image=next;
783   }
784   read_info=DestroyImageInfo(read_info);
785   return(GetFirstImageInList(image));
786 }
787 \f
788 /*
789 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
790 %                                                                             %
791 %                                                                             %
792 %                                                                             %
793 %   R e a d I m a g e s                                                       %
794 %                                                                             %
795 %                                                                             %
796 %                                                                             %
797 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
798 %
799 %  ReadImages() reads one or more images and returns them as an image list.
800 %
801 %  The format of the ReadImage method is:
802 %
803 %      Image *ReadImages(const ImageInfo *image_info,ExceptionInfo *exception)
804 %
805 %  A description of each parameter follows:
806 %
807 %    o image_info: the image info.
808 %
809 %    o exception: return any errors or warnings in this structure.
810 %
811 */
812 MagickExport Image *ReadImages(const ImageInfo *image_info,
813   ExceptionInfo *exception)
814 {
815   char
816     filename[MaxTextExtent];
817
818   Image
819     *image,
820     *images;
821
822   ImageInfo
823     *read_info;
824
825   /*
826     Read image list from a file.
827   */
828   assert(image_info != (ImageInfo *) NULL);
829   assert(image_info->signature == MagickSignature);
830   if (image_info->debug != MagickFalse)
831     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
832       image_info->filename);
833   assert(exception != (ExceptionInfo *) NULL);
834   (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
835     (int) image_info->scene,filename);
836   if (LocaleCompare(filename,image_info->filename) != 0)
837     {
838       ExceptionInfo
839         *sans;
840
841       long
842         extent,
843         scene;
844
845       /*
846         Images of the form image-%d.png[1-5].
847       */
848       read_info=CloneImageInfo(image_info);
849       sans=AcquireExceptionInfo();
850       (void) SetImageInfo(read_info,0,sans);
851       sans=DestroyExceptionInfo(sans);
852       (void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
853       images=NewImageList();
854       extent=(long) (read_info->scene+read_info->number_scenes);
855       for (scene=(long) read_info->scene; scene < (long) extent; scene++)
856       {
857         (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(int)
858           scene,read_info->filename);
859         image=ReadImage(read_info,exception);
860         if (image == (Image *) NULL)
861           continue;
862         AppendImageToList(&images,image);
863       }
864       read_info=DestroyImageInfo(read_info);
865       return(images);
866     }
867   return(ReadImage(image_info,exception));
868 }
869 \f
870 /*
871 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
872 %                                                                             %
873 %                                                                             %
874 %                                                                             %
875 +   R e a d I n l i n e I m a g e                                             %
876 %                                                                             %
877 %                                                                             %
878 %                                                                             %
879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
880 %
881 %  ReadInlineImage() reads a Base64-encoded inline image or image sequence.
882 %  The method returns a NULL if there is a memory shortage or if the image
883 %  cannot be read.  On failure, a NULL image is returned and exception
884 %  describes the reason for the failure.
885 %
886 %  The format of the ReadInlineImage method is:
887 %
888 %      Image *ReadInlineImage(const ImageInfo *image_info,const char *content,
889 %        ExceptionInfo *exception)
890 %
891 %  A description of each parameter follows:
892 %
893 %    o image_info: the image info.
894 %
895 %    o content: the image encoded in Base64.
896 %
897 %    o exception: return any errors or warnings in this structure.
898 %
899 */
900 MagickExport Image *ReadInlineImage(const ImageInfo *image_info,
901   const char *content,ExceptionInfo *exception)
902 {
903   Image
904     *image;
905
906   ImageInfo
907     *read_info;
908
909   unsigned char
910     *blob;
911
912   size_t
913     length;
914
915   register const char
916     *p;
917
918   image=NewImageList();
919   for (p=content; (*p != ',') && (*p != '\0'); p++) ;
920   if (*p == '\0')
921     ThrowReaderException(CorruptImageError,"CorruptImage");
922   p++;
923   length=0;
924   blob=Base64Decode(p,&length);
925   if (length == 0)
926     ThrowReaderException(CorruptImageError,"CorruptImage");
927   read_info=CloneImageInfo(image_info);
928   (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
929     (void *) NULL);
930   image=BlobToImage(read_info,blob,length,exception);
931   blob=(unsigned char *) RelinquishMagickMemory(blob);
932   read_info=DestroyImageInfo(read_info);
933   return(image);
934 }
935 \f
936 /*
937 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
938 %                                                                             %
939 %                                                                             %
940 %                                                                             %
941 %   W r i t e I m a g e                                                       %
942 %                                                                             %
943 %                                                                             %
944 %                                                                             %
945 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
946 %
947 %  WriteImage() writes an image or an image sequence to a file or filehandle.
948 %  If writing to a file on disk, the name is defined by the filename member of
949 %  the image structure.  Write() returns MagickFalse is these is a memory
950 %  shortage or if the image cannot be written.  Check the exception member of
951 %  image to determine the cause for any failure.
952 %
953 %  The format of the WriteImage method is:
954 %
955 %      MagickBooleanType WriteImage(const ImageInfo *image_info,Image *image)
956 %
957 %  A description of each parameter follows:
958 %
959 %    o image_info: the image info.
960 %
961 %    o image: the image.
962 %
963 */
964 MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info,
965   Image *image)
966 {
967   char
968     filename[MaxTextExtent];
969
970   const char
971     *option;
972
973   const DelegateInfo
974     *delegate_info;
975
976   const MagickInfo
977     *magick_info;
978
979   ExceptionInfo
980     *sans_exception;
981
982   ImageInfo
983     *write_info;
984
985   MagickBooleanType
986     status,
987     temporary;
988
989   MagickStatusType
990     thread_support;
991
992   PolicyDomain
993     domain;
994
995   PolicyRights
996     rights;
997
998   /*
999     Determine image type from filename prefix or suffix (e.g. image.jpg).
1000   */
1001   assert(image_info != (ImageInfo *) NULL);
1002   assert(image_info->signature == MagickSignature);
1003   if (image->debug != MagickFalse)
1004     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1005       image_info->filename);
1006   assert(image != (Image *) NULL);
1007   assert(image->signature == MagickSignature);
1008   sans_exception=AcquireExceptionInfo();
1009   write_info=CloneImageInfo(image_info);
1010   (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent);
1011   if (*write_info->magick == '\0')
1012     (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent);
1013   (void) SetImageInfo(write_info,1,sans_exception);
1014   if (LocaleCompare(write_info->magick,"clipmask") == 0)
1015     {
1016       if (image->clip_mask == (Image *) NULL)
1017         {
1018           (void) ThrowMagickException(&image->exception,GetMagickModule(),
1019             OptionError,"NoClipPathDefined","`%s'",image->filename);
1020           return(MagickFalse);
1021         }
1022       image=image->clip_mask;
1023       (void) SetImageInfo(write_info,1,sans_exception);
1024     }
1025   (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1026   (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent);
1027   domain=CoderPolicyDomain;
1028   rights=WritePolicyRights;
1029   if (IsRightsAuthorized(domain,rights,write_info->magick) == MagickFalse)
1030     {
1031       sans_exception=DestroyExceptionInfo(sans_exception);
1032       errno=EPERM;
1033       ThrowBinaryException(PolicyError,"NotAuthorized",filename);
1034     }
1035   magick_info=GetMagickInfo(write_info->magick,sans_exception);
1036   sans_exception=DestroyExceptionInfo(sans_exception);
1037   if (magick_info != (const MagickInfo *) NULL)
1038     {
1039       if (GetMagickEndianSupport(magick_info) == MagickFalse)
1040         image->endian=UndefinedEndian;
1041       else
1042         if ((image_info->endian == UndefinedEndian) &&
1043             (GetMagickRawSupport(magick_info) != MagickFalse))
1044           {
1045             unsigned long
1046               lsb_first;
1047
1048             lsb_first=1;
1049             image->endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1050          }
1051     }
1052   (void) SyncImageProfiles(image);
1053   option=GetImageOption(image_info,"delegate:bimodal");
1054   if ((option != (const char *) NULL) && 
1055       (IsMagickTrue(option) != MagickFalse) &&
1056       (write_info->page == (char *) NULL) &&
1057       (GetPreviousImageInList(image) == (Image *) NULL) &&
1058       (GetNextImageInList(image) == (Image *) NULL) &&
1059       (IsTaintImage(image) == MagickFalse))
1060     {
1061       delegate_info=GetDelegateInfo(image->magick,write_info->magick,
1062         &image->exception);
1063       if ((delegate_info != (const DelegateInfo *) NULL) &&
1064           (GetDelegateMode(delegate_info) == 0) &&
1065           (IsPathAccessible(image->magick_filename) != MagickFalse))
1066         {
1067           /*
1068             Process image with bi-modal delegate.
1069           */
1070           (void) CopyMagickString(image->filename,image->magick_filename,
1071             MaxTextExtent);
1072           status=InvokeDelegate(write_info,image,image->magick,
1073             write_info->magick,&image->exception);
1074           write_info=DestroyImageInfo(write_info);
1075           (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1076           return(status);
1077         }
1078     }
1079   status=MagickFalse;
1080   temporary=MagickFalse;
1081   if ((magick_info != (const MagickInfo *) NULL) &&
1082       (GetMagickSeekableStream(magick_info) != MagickFalse))
1083     {
1084       char
1085         filename[MaxTextExtent];
1086
1087       (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1088       status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception);
1089       (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1090       if (status != MagickFalse)
1091         {
1092           if (IsBlobSeekable(image) == MagickFalse)
1093             {
1094               /*
1095                 A seekable stream is required by the encoder.
1096               */
1097               (void) CopyMagickString(write_info->filename,image->filename,
1098                 MaxTextExtent);
1099               (void) AcquireUniqueFilename(image->filename);
1100               temporary=MagickTrue;
1101             }
1102           (void) CloseBlob(image);
1103         }
1104     }
1105   if (constitute_semaphore == (SemaphoreInfo *) NULL)
1106     AcquireSemaphoreInfo(&constitute_semaphore);
1107   if ((magick_info != (const MagickInfo *) NULL) &&
1108       (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL))
1109     {
1110       /*
1111         Call appropriate image writer based on image type.
1112       */
1113       thread_support=GetMagickThreadSupport(magick_info);
1114       if ((thread_support & EncoderThreadSupport) == 0)
1115         LockSemaphoreInfo(constitute_semaphore);
1116       status=GetImageEncoder(magick_info)(write_info,image);
1117       if ((thread_support & EncoderThreadSupport) == 0)
1118         UnlockSemaphoreInfo(constitute_semaphore);
1119     }
1120   else
1121     {
1122       delegate_info=GetDelegateInfo((char *) NULL,write_info->magick,
1123         &image->exception);
1124       if (delegate_info != (DelegateInfo *) NULL)
1125         {
1126           /*
1127             Process the image with delegate.
1128           */
1129           *write_info->filename='\0';
1130           if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1131             LockSemaphoreInfo(constitute_semaphore);
1132           status=InvokeDelegate(write_info,image,(char *) NULL,
1133             write_info->magick,&image->exception);
1134           if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1135             UnlockSemaphoreInfo(constitute_semaphore);
1136           (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1137         }
1138       else
1139         {
1140           sans_exception=AcquireExceptionInfo();
1141           magick_info=GetMagickInfo(write_info->magick,sans_exception);
1142           sans_exception=DestroyExceptionInfo(sans_exception);
1143           if ((write_info->affirm == MagickFalse) &&
1144               (magick_info == (const MagickInfo *) NULL))
1145             {
1146               (void) CopyMagickString(write_info->magick,image->magick,
1147                 MaxTextExtent);
1148               magick_info=GetMagickInfo(write_info->magick,&image->exception);
1149             }
1150           if ((magick_info == (const MagickInfo *) NULL) ||
1151               (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1152             {
1153               magick_info=GetMagickInfo(image->magick,&image->exception);
1154               (void) CopyMagickString(image->filename,filename,MaxTextExtent);
1155             }
1156           if ((magick_info == (const MagickInfo *) NULL) ||
1157               (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL))
1158             (void) ThrowMagickException(&image->exception,GetMagickModule(),
1159               MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'",
1160               image->filename);
1161           else
1162             {
1163               /*
1164                 Call appropriate image writer based on image type.
1165               */
1166               thread_support=GetMagickThreadSupport(magick_info);
1167               if ((thread_support & EncoderThreadSupport) == 0)
1168                 LockSemaphoreInfo(constitute_semaphore);
1169               status=GetImageEncoder(magick_info)(write_info,image);
1170               if ((thread_support & EncoderThreadSupport) == 0)
1171                 UnlockSemaphoreInfo(constitute_semaphore);
1172             }
1173         }
1174     }
1175   if (GetBlobError(image) != MagickFalse)
1176     ThrowFileException(&image->exception,FileOpenError,
1177       "AnErrorHasOccurredWritingToFile",image->filename);
1178   if (temporary == MagickTrue)
1179     {
1180       /*
1181         Copy temporary image file to permanent.
1182       */
1183       status=OpenBlob(write_info,image,ReadBinaryBlobMode,&image->exception);
1184       if (status != MagickFalse)
1185         status=ImageToFile(image,write_info->filename,&image->exception);
1186       (void) RelinquishUniqueFileResource(image->filename);
1187       (void) CopyMagickString(image->filename,write_info->filename,
1188         MaxTextExtent);
1189       (void) CloseBlob(image);
1190     }
1191   if ((LocaleCompare(write_info->magick,"info") != 0) &&
1192       (write_info->verbose != MagickFalse))
1193     (void) IdentifyImage(image,stdout,MagickFalse);
1194   write_info=DestroyImageInfo(write_info);
1195   return(status);
1196 }
1197 \f
1198 /*
1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1200 %                                                                             %
1201 %                                                                             %
1202 %                                                                             %
1203 %   W r i t e I m a g e s                                                     %
1204 %                                                                             %
1205 %                                                                             %
1206 %                                                                             %
1207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1208 %
1209 %  WriteImages() writes an image sequence.
1210 %
1211 %  The format of the WriteImages method is:
1212 %
1213 %      MagickBooleanType WriteImages(const ImageInfo *image_info,Image *images,
1214 %        const char *filename,ExceptionInfo *exception)
1215 %
1216 %  A description of each parameter follows:
1217 %
1218 %    o image_info: the image info.
1219 %
1220 %    o images: the image list.
1221 %
1222 %    o filename: the image filename.
1223 %
1224 %    o exception: return any errors or warnings in this structure.
1225 %
1226 */
1227 MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info,
1228   Image *images,const char *filename,ExceptionInfo *exception)
1229 {
1230 #define WriteImageTag  "Write/Image"
1231
1232   BlobInfo
1233     *blob;
1234
1235   ExceptionInfo
1236     *sans_exception;
1237
1238   ImageInfo
1239     *write_info;
1240
1241   MagickBooleanType
1242     proceed;
1243
1244   MagickOffsetType
1245     i;
1246
1247   MagickProgressMonitor
1248     progress_monitor;
1249
1250   MagickSizeType
1251     number_images;
1252
1253   MagickStatusType
1254     status;
1255
1256   register Image
1257     *p;
1258
1259   assert(image_info != (const ImageInfo *) NULL);
1260   assert(image_info->signature == MagickSignature);
1261   assert(images != (Image *) NULL);
1262   assert(images->signature == MagickSignature);
1263   if (images->debug != MagickFalse)
1264     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
1265   assert(exception != (ExceptionInfo *) NULL);
1266   write_info=CloneImageInfo(image_info);
1267   images=GetFirstImageInList(images);
1268   blob=CloneBlobInfo(images->blob);  /* thread specific I/O handler */
1269   DestroyBlob(images);
1270   images->blob=blob;
1271   if (filename != (const char *) NULL)
1272     for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1273       (void) CopyMagickString(p->filename,filename,MaxTextExtent);
1274   (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent);
1275   if (*write_info->magick == '\0')
1276     (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent);
1277   sans_exception=AcquireExceptionInfo();
1278   (void) SetImageInfo(write_info,(unsigned int) GetImageListLength(images),
1279     sans_exception);
1280   sans_exception=DestroyExceptionInfo(sans_exception);
1281   p=images;
1282   for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1283     if (p->scene >= GetNextImageInList(p)->scene)
1284       {
1285         register long
1286           i;
1287
1288         /*
1289           Generate consistent scene numbers.
1290         */
1291         i=(long) images->scene;
1292         for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1293           p->scene=(unsigned long) i++;
1294         break;
1295       }
1296   /*
1297     Write images.
1298   */
1299   status=MagickTrue;
1300   progress_monitor=(MagickProgressMonitor) NULL;
1301   i=0;
1302   number_images=GetImageListLength(images);
1303   for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1304   {
1305     if (number_images != 1)
1306       progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1307         p->client_data);
1308     status&=WriteImage(write_info,p);
1309     GetImageException(p,exception);
1310     if (number_images != 1)
1311       (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1312     if (write_info->adjoin != MagickFalse)
1313       break;
1314     if (number_images != 1)
1315       {
1316         proceed=SetImageProgress(p,WriteImageTag,i++,number_images);
1317         if (proceed == MagickFalse)
1318           break;
1319       }
1320   }
1321   write_info=DestroyImageInfo(write_info);
1322   return(status != 0 ? MagickTrue : MagickFalse);
1323 }