MagickCore  7.0.10
constitute.c
Go to the documentation of this file.
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 % Cristy %
17 % October 1998 %
18 % %
19 % %
20 % Copyright 1999-2020 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 % https://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 
39 /*
40  Include declarations.
41 */
42 #include "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/blob.h"
46 #include "MagickCore/exception.h"
48 #include "MagickCore/cache.h"
49 #include "MagickCore/client.h"
52 #include "MagickCore/constitute.h"
54 #include "MagickCore/delegate.h"
55 #include "MagickCore/geometry.h"
56 #include "MagickCore/identify.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
63 #include "MagickCore/option.h"
64 #include "MagickCore/pixel.h"
66 #include "MagickCore/policy.h"
67 #include "MagickCore/profile.h"
69 #include "MagickCore/property.h"
70 #include "MagickCore/quantum.h"
71 #include "MagickCore/resize.h"
72 #include "MagickCore/resource_.h"
73 #include "MagickCore/semaphore.h"
74 #include "MagickCore/statistic.h"
75 #include "MagickCore/stream.h"
76 #include "MagickCore/string_.h"
78 #include "MagickCore/timer.h"
79 #include "MagickCore/token.h"
80 #include "MagickCore/transform.h"
81 #include "MagickCore/utility.h"
83 
84 /*
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 % %
87 % %
88 % %
89 % C o n s t i t u t e I m a g e %
90 % %
91 % %
92 % %
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %
95 % ConstituteImage() returns an image from the pixel data you supply.
96 % The pixel data must be in scanline order top-to-bottom. The data can be
97 % char, short int, int, float, or double. Float and double require the
98 % pixels to be normalized [0..1], otherwise [0..QuantumRange]. For example, to
99 % create a 640x480 image from unsigned red-green-blue character data, use:
100 %
101 % image = ConstituteImage(640,480,"RGB",CharPixel,pixels,&exception);
102 %
103 % The format of the ConstituteImage method is:
104 %
105 % Image *ConstituteImage(const size_t columns,const size_t rows,
106 % const char *map,const StorageType storage,const void *pixels,
107 % ExceptionInfo *exception)
108 %
109 % A description of each parameter follows:
110 %
111 % o columns: width in pixels of the image.
112 %
113 % o rows: height in pixels of the image.
114 %
115 % o map: This string reflects the expected ordering of the pixel array.
116 % It can be any combination or order of R = red, G = green, B = blue,
117 % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan,
118 % Y = yellow, M = magenta, K = black, I = intensity (for grayscale),
119 % P = pad.
120 %
121 % o storage: Define the data type of the pixels. Float and double types are
122 % expected to be normalized [0..1] otherwise [0..QuantumRange]. Choose
123 % from these types: CharPixel, DoublePixel, FloatPixel, IntegerPixel,
124 % LongPixel, QuantumPixel, or ShortPixel.
125 %
126 % o pixels: This array of values contain the pixel components as defined by
127 % map and type. You must preallocate this array where the expected
128 % length varies depending on the values of width, height, map, and type.
129 %
130 % o exception: return any errors or warnings in this structure.
131 %
132 */
133 MagickExport Image *ConstituteImage(const size_t columns,const size_t rows,
134  const char *map,const StorageType storage,const void *pixels,
135  ExceptionInfo *exception)
136 {
137  Image
138  *image;
139 
141  status;
142 
143  register ssize_t
144  i;
145 
146  size_t
147  length;
148 
149  /*
150  Allocate image structure.
151  */
152  assert(map != (const char *) NULL);
153  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",map);
154  assert(pixels != (void *) NULL);
155  assert(exception != (ExceptionInfo *) NULL);
156  assert(exception->signature == MagickCoreSignature);
157  image=AcquireImage((ImageInfo *) NULL,exception);
158  if (image == (Image *) NULL)
159  return((Image *) NULL);
160  length=strlen(map);
161  for (i=0; i < (ssize_t) length; i++)
162  {
163  switch (map[i])
164  {
165  case 'a':
166  case 'A':
167  case 'O':
168  case 'o':
169  {
171  break;
172  }
173  case 'C':
174  case 'c':
175  case 'm':
176  case 'M':
177  case 'Y':
178  case 'y':
179  case 'K':
180  case 'k':
181  {
182  image->colorspace=CMYKColorspace;
183  break;
184  }
185  case 'I':
186  case 'i':
187  {
188  image->colorspace=GRAYColorspace;
189  break;
190  }
191  default:
192  {
193  if (length == 1)
194  image->colorspace=GRAYColorspace;
195  break;
196  }
197  }
198  }
199  status=SetImageExtent(image,columns,rows,exception);
200  if (status == MagickFalse)
201  return(DestroyImageList(image));
202  status=ResetImagePixels(image,exception);
203  if (status == MagickFalse)
204  return(DestroyImageList(image));
205  status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels,exception);
206  if (status == MagickFalse)
207  image=DestroyImage(image);
208  return(image);
209 }
210 
211 /*
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213 % %
214 % %
215 % %
216 % P i n g I m a g e %
217 % %
218 % %
219 % %
220 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 %
222 % PingImage() returns all the properties of an image or image sequence
223 % except for the pixels. It is much faster and consumes far less memory
224 % than ReadImage(). On failure, a NULL image is returned and exception
225 % describes the reason for the failure.
226 %
227 % The format of the PingImage method is:
228 %
229 % Image *PingImage(const ImageInfo *image_info,ExceptionInfo *exception)
230 %
231 % A description of each parameter follows:
232 %
233 % o image_info: Ping the image defined by the file or filename members of
234 % this structure.
235 %
236 % o exception: return any errors or warnings in this structure.
237 %
238 */
239 
240 #if defined(__cplusplus) || defined(c_plusplus)
241 extern "C" {
242 #endif
243 
244 static size_t PingStream(const Image *magick_unused(image),
245  const void *magick_unused(pixels),const size_t columns)
246 {
247  magick_unreferenced(image);
248  magick_unreferenced(pixels);
249  return(columns);
250 }
251 
252 #if defined(__cplusplus) || defined(c_plusplus)
253 }
254 #endif
255 
257  ExceptionInfo *exception)
258 {
259  Image
260  *image;
261 
262  ImageInfo
263  *ping_info;
264 
265  assert(image_info != (ImageInfo *) NULL);
266  assert(image_info->signature == MagickCoreSignature);
267  if (image_info->debug != MagickFalse)
269  image_info->filename);
270  assert(exception != (ExceptionInfo *) NULL);
271  ping_info=CloneImageInfo(image_info);
272  ping_info->ping=MagickTrue;
273  image=ReadStream(ping_info,&PingStream,exception);
274  if (image != (Image *) NULL)
275  {
276  ResetTimer(&image->timer);
277  if (ping_info->verbose != MagickFalse)
278  (void) IdentifyImage(image,stdout,MagickFalse,exception);
279  }
280  ping_info=DestroyImageInfo(ping_info);
281  return(image);
282 }
283 
284 /*
285 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286 % %
287 % %
288 % %
289 % P i n g I m a g e s %
290 % %
291 % %
292 % %
293 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
294 %
295 % PingImages() pings one or more images and returns them as an image list.
296 %
297 % The format of the PingImage method is:
298 %
299 % Image *PingImages(ImageInfo *image_info,const char *filename,
300 % ExceptionInfo *exception)
301 %
302 % A description of each parameter follows:
303 %
304 % o image_info: the image info.
305 %
306 % o filename: the image filename.
307 %
308 % o exception: return any errors or warnings in this structure.
309 %
310 */
311 MagickExport Image *PingImages(ImageInfo *image_info,const char *filename,
312  ExceptionInfo *exception)
313 {
314  char
315  ping_filename[MagickPathExtent];
316 
317  Image
318  *image,
319  *images;
320 
321  ImageInfo
322  *read_info;
323 
324  /*
325  Ping image list from a file.
326  */
327  assert(image_info != (ImageInfo *) NULL);
328  assert(image_info->signature == MagickCoreSignature);
329  if (image_info->debug != MagickFalse)
331  image_info->filename);
332  assert(exception != (ExceptionInfo *) NULL);
333  (void) SetImageOption(image_info,"filename",filename);
334  (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
335  (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename,
336  (int) image_info->scene,ping_filename,exception);
337  if (LocaleCompare(ping_filename,image_info->filename) != 0)
338  {
340  *sans;
341 
342  ssize_t
343  extent,
344  scene;
345 
346  /*
347  Images of the form image-%d.png[1-5].
348  */
349  read_info=CloneImageInfo(image_info);
350  sans=AcquireExceptionInfo();
351  (void) SetImageInfo(read_info,0,sans);
352  sans=DestroyExceptionInfo(sans);
353  if (read_info->number_scenes == 0)
354  {
355  read_info=DestroyImageInfo(read_info);
356  return(PingImage(image_info,exception));
357  }
358  (void) CopyMagickString(ping_filename,read_info->filename,
360  images=NewImageList();
361  extent=(ssize_t) (read_info->scene+read_info->number_scenes);
362  for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++)
363  {
364  (void) InterpretImageFilename(image_info,(Image *) NULL,ping_filename,
365  (int) scene,read_info->filename,exception);
366  image=PingImage(read_info,exception);
367  if (image == (Image *) NULL)
368  continue;
369  AppendImageToList(&images,image);
370  }
371  read_info=DestroyImageInfo(read_info);
372  return(images);
373  }
374  return(PingImage(image_info,exception));
375 }
376 
377 /*
378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
379 % %
380 % %
381 % %
382 % R e a d I m a g e %
383 % %
384 % %
385 % %
386 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
387 %
388 % ReadImage() reads an image or image sequence from a file or file handle.
389 % The method returns a NULL if there is a memory shortage or if the image
390 % cannot be read. On failure, a NULL image is returned and exception
391 % describes the reason for the failure.
392 %
393 % The format of the ReadImage method is:
394 %
395 % Image *ReadImage(const ImageInfo *image_info,ExceptionInfo *exception)
396 %
397 % A description of each parameter follows:
398 %
399 % o image_info: Read the image defined by the file or filename members of
400 % this structure.
401 %
402 % o exception: return any errors or warnings in this structure.
403 %
404 */
405 
406 static MagickBooleanType IsCoderAuthorized(const char *coder,
407  const PolicyRights rights,ExceptionInfo *exception)
408 {
409  if (IsRightsAuthorized(CoderPolicyDomain,rights,coder) == MagickFalse)
410  {
411  errno=EPERM;
413  "NotAuthorized","`%s'",coder);
414  return(MagickFalse);
415  }
416  return(MagickTrue);
417 }
418 
420  ExceptionInfo *exception)
421 {
422  char
423  filename[MagickPathExtent],
424  magick[MagickPathExtent],
425  magick_filename[MagickPathExtent];
426 
427  const char
428  *value;
429 
430  const DelegateInfo
431  *delegate_info;
432 
433  const MagickInfo
434  *magick_info;
435 
437  *decoder;
438 
440  *sans_exception;
441 
443  geometry_info;
444 
445  Image
446  *image,
447  *next;
448 
449  ImageInfo
450  *read_info;
451 
453  status;
454 
456  flags;
457 
458  /*
459  Determine image type from filename prefix or suffix (e.g. image.jpg).
460  */
461  assert(image_info != (ImageInfo *) NULL);
462  assert(image_info->signature == MagickCoreSignature);
463  assert(image_info->filename != (char *) NULL);
464  if (image_info->debug != MagickFalse)
466  image_info->filename);
467  assert(exception != (ExceptionInfo *) NULL);
468  read_info=CloneImageInfo(image_info);
469  (void) CopyMagickString(magick_filename,read_info->filename,MagickPathExtent);
470  (void) SetImageInfo(read_info,0,exception);
471  (void) CopyMagickString(filename,read_info->filename,MagickPathExtent);
472  (void) CopyMagickString(magick,read_info->magick,MagickPathExtent);
473  /*
474  Call appropriate image reader based on image type.
475  */
476  sans_exception=AcquireExceptionInfo();
477  magick_info=GetMagickInfo(read_info->magick,sans_exception);
478  if (sans_exception->severity == PolicyError)
479  magick_info=GetMagickInfo(read_info->magick,exception);
480  sans_exception=DestroyExceptionInfo(sans_exception);
481  if (magick_info != (const MagickInfo *) NULL)
482  {
483  if (GetMagickEndianSupport(magick_info) == MagickFalse)
484  read_info->endian=UndefinedEndian;
485  else
486  if ((image_info->endian == UndefinedEndian) &&
487  (GetMagickRawSupport(magick_info) != MagickFalse))
488  {
489  unsigned long
490  lsb_first;
491 
492  lsb_first=1;
493  read_info->endian=(*(char *) &lsb_first) == 1 ? LSBEndian :
494  MSBEndian;
495  }
496  }
497  if ((magick_info != (const MagickInfo *) NULL) &&
499  {
500  image=AcquireImage(read_info,exception);
501  (void) CopyMagickString(image->filename,read_info->filename,
503  status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
504  if (status == MagickFalse)
505  {
506  read_info=DestroyImageInfo(read_info);
507  image=DestroyImage(image);
508  return((Image *) NULL);
509  }
510  if (IsBlobSeekable(image) == MagickFalse)
511  {
512  /*
513  Coder requires a seekable stream.
514  */
515  *read_info->filename='\0';
516  status=ImageToFile(image,read_info->filename,exception);
517  if (status == MagickFalse)
518  {
519  (void) CloseBlob(image);
520  read_info=DestroyImageInfo(read_info);
521  image=DestroyImage(image);
522  return((Image *) NULL);
523  }
524  read_info->temporary=MagickTrue;
525  }
526  (void) CloseBlob(image);
527  image=DestroyImage(image);
528  }
529  image=NewImageList();
530  decoder=GetImageDecoder(magick_info);
531  if (decoder == (DecodeImageHandler *) NULL)
532  {
533  delegate_info=GetDelegateInfo(read_info->magick,(char *) NULL,exception);
534  if (delegate_info == (const DelegateInfo *) NULL)
535  {
536  (void) SetImageInfo(read_info,0,exception);
537  (void) CopyMagickString(read_info->filename,filename,
539  magick_info=GetMagickInfo(read_info->magick,exception);
540  decoder=GetImageDecoder(magick_info);
541  }
542  }
543  if (decoder != (DecodeImageHandler *) NULL)
544  {
545  /*
546  Call appropriate image reader based on image type.
547  */
548  if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
549  LockSemaphoreInfo(magick_info->semaphore);
550  status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
551  image=(Image *) NULL;
552  if (status != MagickFalse)
553  image=decoder(read_info,exception);
554  if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
555  UnlockSemaphoreInfo(magick_info->semaphore);
556  }
557  else
558  {
559  delegate_info=GetDelegateInfo(read_info->magick,(char *) NULL,exception);
560  if (delegate_info == (const DelegateInfo *) NULL)
561  {
562  (void) ThrowMagickException(exception,GetMagickModule(),
563  MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
564  read_info->magick);
565  if (read_info->temporary != MagickFalse)
566  (void) RelinquishUniqueFileResource(read_info->filename);
567  read_info=DestroyImageInfo(read_info);
568  return((Image *) NULL);
569  }
570  /*
571  Let our decoding delegate process the image.
572  */
573  image=AcquireImage(read_info,exception);
574  if (image == (Image *) NULL)
575  {
576  read_info=DestroyImageInfo(read_info);
577  return((Image *) NULL);
578  }
579  (void) CopyMagickString(image->filename,read_info->filename,
581  *read_info->filename='\0';
582  if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
583  LockSemaphoreInfo(delegate_info->semaphore);
584  status=InvokeDelegate(read_info,image,read_info->magick,(char *) NULL,
585  exception);
586  if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
587  UnlockSemaphoreInfo(delegate_info->semaphore);
588  image=DestroyImageList(image);
589  read_info->temporary=MagickTrue;
590  if (status != MagickFalse)
591  (void) SetImageInfo(read_info,0,exception);
592  magick_info=GetMagickInfo(read_info->magick,exception);
593  decoder=GetImageDecoder(magick_info);
594  if (decoder == (DecodeImageHandler *) NULL)
595  {
596  if (IsPathAccessible(read_info->filename) != MagickFalse)
597  (void) ThrowMagickException(exception,GetMagickModule(),
598  MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'",
599  read_info->magick);
600  else
601  ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
602  read_info->filename);
603  read_info=DestroyImageInfo(read_info);
604  return((Image *) NULL);
605  }
606  /*
607  Call appropriate image reader based on image type.
608  */
609  if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
610  LockSemaphoreInfo(magick_info->semaphore);
611  status=IsCoderAuthorized(read_info->magick,ReadPolicyRights,exception);
612  image=(Image *) NULL;
613  if (status != MagickFalse)
614  image=(decoder)(read_info,exception);
615  if (GetMagickDecoderThreadSupport(magick_info) == MagickFalse)
616  UnlockSemaphoreInfo(magick_info->semaphore);
617  }
618  if (read_info->temporary != MagickFalse)
619  {
620  (void) RelinquishUniqueFileResource(read_info->filename);
621  read_info->temporary=MagickFalse;
622  if (image != (Image *) NULL)
623  (void) CopyMagickString(image->filename,filename,MagickPathExtent);
624  }
625  if (image == (Image *) NULL)
626  {
627  read_info=DestroyImageInfo(read_info);
628  return(image);
629  }
630  if (exception->severity >= ErrorException)
632  "Coder (%s) generated an image despite an error (%d), "
633  "notify the developers",image->magick,exception->severity);
634  if (IsBlobTemporary(image) != MagickFalse)
635  (void) RelinquishUniqueFileResource(read_info->filename);
636  if ((IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse) &&
637  (GetImageListLength(image) != 1))
638  {
639  Image
640  *clones;
641 
642  clones=CloneImages(image,read_info->scenes,exception);
643  if (clones != (Image *) NULL)
644  {
645  image=DestroyImageList(image);
646  image=GetFirstImageInList(clones);
647  }
648  }
649  for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
650  {
651  char
652  magick_path[MagickPathExtent],
653  *property,
654  timestamp[MagickPathExtent];
655 
656  const char
657  *option;
658 
659  const StringInfo
660  *profile;
661 
662  ssize_t
663  option_type;
664 
665  static const char
666  *source_date_epoch = (const char *) NULL;
667 
668  static MagickBooleanType
669  epoch_initalized = MagickFalse;
670 
671  next->taint=MagickFalse;
672  GetPathComponent(magick_filename,MagickPath,magick_path);
673  if (*magick_path == '\0' && *next->magick == '\0')
674  (void) CopyMagickString(next->magick,magick,MagickPathExtent);
675  (void) CopyMagickString(next->magick_filename,magick_filename,
677  if (IsBlobTemporary(image) != MagickFalse)
678  (void) CopyMagickString(next->filename,filename,MagickPathExtent);
679  if (next->magick_columns == 0)
680  next->magick_columns=next->columns;
681  if (next->magick_rows == 0)
682  next->magick_rows=next->rows;
683  (void) GetImageProperty(next,"exif:*",exception);
684  (void) GetImageProperty(next,"icc:*",exception);
685  (void) GetImageProperty(next,"iptc:*",exception);
686  (void) GetImageProperty(next,"xmp:*",exception);
687  value=GetImageProperty(next,"exif:Orientation",exception);
688  if (value == (char *) NULL)
689  value=GetImageProperty(next,"tiff:Orientation",exception);
690  if (value != (char *) NULL)
691  {
693  (void) DeleteImageProperty(next,"tiff:Orientation");
694  (void) DeleteImageProperty(next,"exif:Orientation");
695  }
696  value=GetImageProperty(next,"exif:XResolution",exception);
697  if (value != (char *) NULL)
698  {
699  geometry_info.rho=next->resolution.x;
700  geometry_info.sigma=1.0;
701  flags=ParseGeometry(value,&geometry_info);
702  if (geometry_info.sigma != 0)
703  next->resolution.x=geometry_info.rho/geometry_info.sigma;
704  if (strchr(value,',') != (char *) NULL)
705  next->resolution.x=geometry_info.rho+geometry_info.sigma/1000.0;
706  (void) DeleteImageProperty(next,"exif:XResolution");
707  }
708  value=GetImageProperty(next,"exif:YResolution",exception);
709  if (value != (char *) NULL)
710  {
711  geometry_info.rho=next->resolution.y;
712  geometry_info.sigma=1.0;
713  flags=ParseGeometry(value,&geometry_info);
714  if (geometry_info.sigma != 0)
715  next->resolution.y=geometry_info.rho/geometry_info.sigma;
716  if (strchr(value,',') != (char *) NULL)
717  next->resolution.y=geometry_info.rho+geometry_info.sigma/1000.0;
718  (void) DeleteImageProperty(next,"exif:YResolution");
719  }
720  value=GetImageProperty(next,"exif:ResolutionUnit",exception);
721  if (value == (char *) NULL)
722  value=GetImageProperty(next,"tiff:ResolutionUnit",exception);
723  if (value != (char *) NULL)
724  {
726  value);
727  if (option_type >= 0)
728  next->units=(ResolutionType) option_type;
729  (void) DeleteImageProperty(next,"exif:ResolutionUnit");
730  (void) DeleteImageProperty(next,"tiff:ResolutionUnit");
731  }
732  if (next->page.width == 0)
733  next->page.width=next->columns;
734  if (next->page.height == 0)
735  next->page.height=next->rows;
736  option=GetImageOption(read_info,"caption");
737  if (option != (const char *) NULL)
738  {
739  property=InterpretImageProperties(read_info,next,option,exception);
740  (void) SetImageProperty(next,"caption",property,exception);
741  property=DestroyString(property);
742  }
743  option=GetImageOption(read_info,"comment");
744  if (option != (const char *) NULL)
745  {
746  property=InterpretImageProperties(read_info,next,option,exception);
747  (void) SetImageProperty(next,"comment",property,exception);
748  property=DestroyString(property);
749  }
750  option=GetImageOption(read_info,"label");
751  if (option != (const char *) NULL)
752  {
753  property=InterpretImageProperties(read_info,next,option,exception);
754  (void) SetImageProperty(next,"label",property,exception);
755  property=DestroyString(property);
756  }
757  if (LocaleCompare(next->magick,"TEXT") == 0)
758  (void) ParseAbsoluteGeometry("0x0+0+0",&next->page);
759  if ((read_info->extract != (char *) NULL) &&
760  (read_info->stream == (StreamHandler) NULL))
761  {
763  geometry;
764 
765  SetGeometry(next,&geometry);
766  flags=ParseAbsoluteGeometry(read_info->extract,&geometry);
767  if ((next->columns != geometry.width) ||
768  (next->rows != geometry.height))
769  {
770  if (((flags & XValue) != 0) || ((flags & YValue) != 0))
771  {
772  Image
773  *crop_image;
774 
775  crop_image=CropImage(next,&geometry,exception);
776  if (crop_image != (Image *) NULL)
777  ReplaceImageInList(&next,crop_image);
778  }
779  else
780  if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0))
781  {
782  Image
783  *size_image;
784 
785  flags=ParseRegionGeometry(next,read_info->extract,&geometry,
786  exception);
787  size_image=ResizeImage(next,geometry.width,geometry.height,
788  next->filter,exception);
789  if (size_image != (Image *) NULL)
790  ReplaceImageInList(&next,size_image);
791  }
792  }
793  }
794  profile=GetImageProfile(next,"icc");
795  if (profile == (const StringInfo *) NULL)
796  profile=GetImageProfile(next,"icm");
797  profile=GetImageProfile(next,"iptc");
798  if (profile == (const StringInfo *) NULL)
799  profile=GetImageProfile(next,"8bim");
800  if (epoch_initalized == MagickFalse)
801  {
802  source_date_epoch=getenv("SOURCE_DATE_EPOCH");
803  epoch_initalized=MagickTrue;
804  }
805  if (source_date_epoch == (const char *) NULL)
806  {
807  (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_mtime,
808  MagickPathExtent,timestamp);
809  (void) SetImageProperty(next,"date:modify",timestamp,exception);
810  (void) FormatMagickTime((time_t) GetBlobProperties(next)->st_ctime,
811  MagickPathExtent,timestamp);
812  (void) SetImageProperty(next,"date:create",timestamp,exception);
813  }
814  option=GetImageOption(image_info,"delay");
815  if (option != (const char *) NULL)
816  {
817  flags=ParseGeometry(option,&geometry_info);
818  if ((flags & GreaterValue) != 0)
819  {
820  if (next->delay > (size_t) floor(geometry_info.rho+0.5))
821  next->delay=(size_t) floor(geometry_info.rho+0.5);
822  }
823  else
824  if ((flags & LessValue) != 0)
825  {
826  if (next->delay < (size_t) floor(geometry_info.rho+0.5))
827  next->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
828  }
829  else
830  next->delay=(size_t) floor(geometry_info.rho+0.5);
831  if ((flags & SigmaValue) != 0)
832  next->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
833  }
834  option=GetImageOption(image_info,"dispose");
835  if (option != (const char *) NULL)
836  {
838  option);
839  if (option_type >= 0)
840  next->dispose=(DisposeType) option_type;
841  }
842  if (read_info->verbose != MagickFalse)
843  (void) IdentifyImage(next,stderr,MagickFalse,exception);
844  image=next;
845  }
846  read_info=DestroyImageInfo(read_info);
847  if (GetBlobError(image) != MagickFalse)
848  ThrowReaderException(CorruptImageError,"UnableToReadImageData");
849  return(GetFirstImageInList(image));
850 }
851 
852 /*
853 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
854 % %
855 % %
856 % %
857 % R e a d I m a g e s %
858 % %
859 % %
860 % %
861 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
862 %
863 % ReadImages() reads one or more images and returns them as an image list.
864 %
865 % The format of the ReadImage method is:
866 %
867 % Image *ReadImages(ImageInfo *image_info,const char *filename,
868 % ExceptionInfo *exception)
869 %
870 % A description of each parameter follows:
871 %
872 % o image_info: the image info.
873 %
874 % o filename: the image filename.
875 %
876 % o exception: return any errors or warnings in this structure.
877 %
878 */
879 MagickExport Image *ReadImages(ImageInfo *image_info,const char *filename,
880  ExceptionInfo *exception)
881 {
882  char
883  read_filename[MagickPathExtent];
884 
885  Image
886  *image,
887  *images;
888 
889  ImageInfo
890  *read_info;
891 
892  /*
893  Read image list from a file.
894  */
895  assert(image_info != (ImageInfo *) NULL);
896  assert(image_info->signature == MagickCoreSignature);
897  if (image_info->debug != MagickFalse)
899  image_info->filename);
900  assert(exception != (ExceptionInfo *) NULL);
901  read_info=CloneImageInfo(image_info);
902  *read_info->magick='\0';
903  (void) SetImageOption(read_info,"filename",filename);
904  (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
905  (void) InterpretImageFilename(read_info,(Image *) NULL,filename,
906  (int) read_info->scene,read_filename,exception);
907  if (LocaleCompare(read_filename,read_info->filename) != 0)
908  {
910  *sans;
911 
912  ssize_t
913  extent,
914  scene;
915 
916  /*
917  Images of the form image-%d.png[1-5].
918  */
919  sans=AcquireExceptionInfo();
920  (void) SetImageInfo(read_info,0,sans);
921  sans=DestroyExceptionInfo(sans);
922  if (read_info->number_scenes != 0)
923  {
924  (void) CopyMagickString(read_filename,read_info->filename,
926  images=NewImageList();
927  extent=(ssize_t) (read_info->scene+read_info->number_scenes);
928  scene=(ssize_t) read_info->scene;
929  for ( ; scene < (ssize_t) extent; scene++)
930  {
931  (void) InterpretImageFilename(image_info,(Image *) NULL,
932  read_filename,(int) scene,read_info->filename,exception);
933  image=ReadImage(read_info,exception);
934  if (image == (Image *) NULL)
935  continue;
936  AppendImageToList(&images,image);
937  }
938  read_info=DestroyImageInfo(read_info);
939  return(images);
940  }
941  }
942  (void) CopyMagickString(read_info->filename,filename,MagickPathExtent);
943  image=ReadImage(read_info,exception);
944  read_info=DestroyImageInfo(read_info);
945  return(image);
946 }
947 
948 /*
949 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
950 % %
951 % %
952 % %
953 + R e a d I n l i n e I m a g e %
954 % %
955 % %
956 % %
957 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
958 %
959 % ReadInlineImage() reads a Base64-encoded inline image or image sequence.
960 % The method returns a NULL if there is a memory shortage or if the image
961 % cannot be read. On failure, a NULL image is returned and exception
962 % describes the reason for the failure.
963 %
964 % The format of the ReadInlineImage method is:
965 %
966 % Image *ReadInlineImage(const ImageInfo *image_info,const char *content,
967 % ExceptionInfo *exception)
968 %
969 % A description of each parameter follows:
970 %
971 % o image_info: the image info.
972 %
973 % o content: the image encoded in Base64.
974 %
975 % o exception: return any errors or warnings in this structure.
976 %
977 */
979  const char *content,ExceptionInfo *exception)
980 {
981  Image
982  *image;
983 
984  ImageInfo
985  *read_info;
986 
987  unsigned char
988  *blob;
989 
990  size_t
991  length;
992 
993  register const char
994  *p;
995 
996  /*
997  Skip over header (e.g. data:image/gif;base64,).
998  */
999  image=NewImageList();
1000  for (p=content; (*p != ',') && (*p != '\0'); p++) ;
1001  if (*p == '\0')
1002  ThrowReaderException(CorruptImageError,"CorruptImage");
1003  p++;
1004  length=0;
1005  blob=Base64Decode(p,&length);
1006  if (length == 0)
1007  {
1008  blob=(unsigned char *) RelinquishMagickMemory(blob);
1009  ThrowReaderException(CorruptImageError,"CorruptImage");
1010  }
1011  read_info=CloneImageInfo(image_info);
1012  (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
1013  (void *) NULL);
1014  *read_info->filename='\0';
1015  *read_info->magick='\0';
1016  image=BlobToImage(read_info,blob,length,exception);
1017  blob=(unsigned char *) RelinquishMagickMemory(blob);
1018  read_info=DestroyImageInfo(read_info);
1019  return(image);
1020 }
1021 
1022 /*
1023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1024 % %
1025 % %
1026 % %
1027 % W r i t e I m a g e %
1028 % %
1029 % %
1030 % %
1031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1032 %
1033 % WriteImage() writes an image or an image sequence to a file or file handle.
1034 % If writing to a file is on disk, the name is defined by the filename member
1035 % of the image structure. WriteImage() returns MagickFalse is there is a
1036 % memory shortage or if the image cannot be written. Check the exception
1037 % member of image to determine the cause for any failure.
1038 %
1039 % The format of the WriteImage method is:
1040 %
1041 % MagickBooleanType WriteImage(const ImageInfo *image_info,Image *image,
1042 % ExceptionInfo *exception)
1043 %
1044 % A description of each parameter follows:
1045 %
1046 % o image_info: the image info.
1047 %
1048 % o image: the image.
1049 %
1050 % o exception: return any errors or warnings in this structure.
1051 %
1052 */
1054  Image *image,ExceptionInfo *exception)
1055 {
1056  char
1057  filename[MagickPathExtent];
1058 
1059  const char
1060  *option;
1061 
1062  const DelegateInfo
1063  *delegate_info;
1064 
1065  const MagickInfo
1066  *magick_info;
1067 
1069  *encoder;
1070 
1072  *sans_exception;
1073 
1074  ImageInfo
1075  *write_info;
1076 
1078  status,
1079  temporary;
1080 
1081  /*
1082  Determine image type from filename prefix or suffix (e.g. image.jpg).
1083  */
1084  assert(image_info != (ImageInfo *) NULL);
1085  assert(image_info->signature == MagickCoreSignature);
1086  assert(image != (Image *) NULL);
1087  if (image->debug != MagickFalse)
1089  image_info->filename);
1090  assert(image->signature == MagickCoreSignature);
1091  assert(exception != (ExceptionInfo *) NULL);
1092  sans_exception=AcquireExceptionInfo();
1093  write_info=CloneImageInfo(image_info);
1094  (void) CopyMagickString(write_info->filename,image->filename,
1096  (void) SetImageInfo(write_info,1,sans_exception);
1097  if (*write_info->magick == '\0')
1098  (void) CopyMagickString(write_info->magick,image->magick,MagickPathExtent);
1099  (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1100  (void) CopyMagickString(image->filename,write_info->filename,
1102  /*
1103  Call appropriate image writer based on image type.
1104  */
1105  magick_info=GetMagickInfo(write_info->magick,sans_exception);
1106  if (sans_exception->severity == PolicyError)
1107  magick_info=GetMagickInfo(write_info->magick,exception);
1108  sans_exception=DestroyExceptionInfo(sans_exception);
1109  if (magick_info != (const MagickInfo *) NULL)
1110  {
1111  if (GetMagickEndianSupport(magick_info) == MagickFalse)
1112  image->endian=UndefinedEndian;
1113  else
1114  if ((image_info->endian == UndefinedEndian) &&
1115  (GetMagickRawSupport(magick_info) != MagickFalse))
1116  {
1117  unsigned long
1118  lsb_first;
1119 
1120  lsb_first=1;
1121  image->endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
1122  }
1123  }
1124  (void) SyncImageProfiles(image);
1125  DisassociateImageStream(image);
1126  option=GetImageOption(image_info,"delegate:bimodal");
1127  if ((IsStringTrue(option) != MagickFalse) &&
1128  (write_info->page == (char *) NULL) &&
1129  (GetPreviousImageInList(image) == (Image *) NULL) &&
1130  (GetNextImageInList(image) == (Image *) NULL) &&
1131  (IsTaintImage(image) == MagickFalse) )
1132  {
1133  delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception);
1134  if ((delegate_info != (const DelegateInfo *) NULL) &&
1135  (GetDelegateMode(delegate_info) == 0) &&
1137  {
1138  /*
1139  Process image with bi-modal delegate.
1140  */
1141  (void) CopyMagickString(image->filename,image->magick_filename,
1143  status=InvokeDelegate(write_info,image,image->magick,
1144  write_info->magick,exception);
1145  write_info=DestroyImageInfo(write_info);
1146  (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1147  return(status);
1148  }
1149  }
1150  status=MagickFalse;
1151  temporary=MagickFalse;
1152  if ((magick_info != (const MagickInfo *) NULL) &&
1153  (GetMagickEncoderSeekableStream(magick_info) != MagickFalse))
1154  {
1155  char
1156  image_filename[MagickPathExtent];
1157 
1158  (void) CopyMagickString(image_filename,image->filename,MagickPathExtent);
1159  status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception);
1160  (void) CopyMagickString(image->filename, image_filename,MagickPathExtent);
1161  if (status != MagickFalse)
1162  {
1163  if (IsBlobSeekable(image) == MagickFalse)
1164  {
1165  /*
1166  A seekable stream is required by the encoder.
1167  */
1168  write_info->adjoin=MagickTrue;
1169  (void) CopyMagickString(write_info->filename,image->filename,
1171  (void) AcquireUniqueFilename(image->filename);
1172  temporary=MagickTrue;
1173  }
1174  (void) CloseBlob(image);
1175  }
1176  }
1177  encoder=GetImageEncoder(magick_info);
1178  if (encoder != (EncodeImageHandler *) NULL)
1179  {
1180  /*
1181  Call appropriate image writer based on image type.
1182  */
1183  if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1184  LockSemaphoreInfo(magick_info->semaphore);
1185  status=IsCoderAuthorized(write_info->magick,WritePolicyRights,exception);
1186  if (status != MagickFalse)
1187  status=encoder(write_info,image,exception);
1188  if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1189  UnlockSemaphoreInfo(magick_info->semaphore);
1190  }
1191  else
1192  {
1193  delegate_info=GetDelegateInfo((char *) NULL,write_info->magick,exception);
1194  if (delegate_info != (DelegateInfo *) NULL)
1195  {
1196  /*
1197  Process the image with delegate.
1198  */
1199  *write_info->filename='\0';
1200  if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1201  LockSemaphoreInfo(delegate_info->semaphore);
1202  status=InvokeDelegate(write_info,image,(char *) NULL,
1203  write_info->magick,exception);
1204  if (GetDelegateThreadSupport(delegate_info) == MagickFalse)
1205  UnlockSemaphoreInfo(delegate_info->semaphore);
1206  (void) CopyMagickString(image->filename,filename,MagickPathExtent);
1207  }
1208  else
1209  {
1210  sans_exception=AcquireExceptionInfo();
1211  magick_info=GetMagickInfo(write_info->magick,sans_exception);
1212  if (sans_exception->severity == PolicyError)
1213  magick_info=GetMagickInfo(write_info->magick,exception);
1214  sans_exception=DestroyExceptionInfo(sans_exception);
1215  if ((write_info->affirm == MagickFalse) &&
1216  (magick_info == (const MagickInfo *) NULL))
1217  {
1218  (void) CopyMagickString(write_info->magick,image->magick,
1220  magick_info=GetMagickInfo(write_info->magick,exception);
1221  }
1222  encoder=GetImageEncoder(magick_info);
1223  if (encoder == (EncodeImageHandler *) NULL)
1224  {
1225  char
1226  extension[MagickPathExtent];
1227 
1228  GetPathComponent(image->filename,ExtensionPath,extension);
1229  if (*extension != '\0')
1230  magick_info=GetMagickInfo(extension,exception);
1231  else
1232  magick_info=GetMagickInfo(image->magick,exception);
1233  (void) CopyMagickString(image->filename,filename,
1235  encoder=GetImageEncoder(magick_info);
1236  }
1237  if (encoder == (EncodeImageHandler *) NULL)
1238  {
1239  magick_info=GetMagickInfo(image->magick,exception);
1240  encoder=GetImageEncoder(magick_info);
1241  if (encoder == (EncodeImageHandler *) NULL)
1242  (void) ThrowMagickException(exception,GetMagickModule(),
1243  MissingDelegateError,"NoEncodeDelegateForThisImageFormat",
1244  "`%s'",write_info->magick);
1245  }
1246  if (encoder != (EncodeImageHandler *) NULL)
1247  {
1248  /*
1249  Call appropriate image writer based on image type.
1250  */
1251  if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1252  LockSemaphoreInfo(magick_info->semaphore);
1253  status=IsCoderAuthorized(write_info->magick,WritePolicyRights,
1254  exception);
1255  if (status != MagickFalse)
1256  status=encoder(write_info,image,exception);
1257  if (GetMagickEncoderThreadSupport(magick_info) == MagickFalse)
1258  UnlockSemaphoreInfo(magick_info->semaphore);
1259  }
1260  }
1261  }
1262  if (temporary != MagickFalse)
1263  {
1264  /*
1265  Copy temporary image file to permanent.
1266  */
1267  status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception);
1268  if (status != MagickFalse)
1269  {
1270  (void) RelinquishUniqueFileResource(write_info->filename);
1271  status=ImageToFile(image,write_info->filename,exception);
1272  }
1273  (void) CloseBlob(image);
1274  (void) RelinquishUniqueFileResource(image->filename);
1275  (void) CopyMagickString(image->filename,write_info->filename,
1277  }
1278  if ((LocaleCompare(write_info->magick,"info") != 0) &&
1279  (write_info->verbose != MagickFalse))
1280  (void) IdentifyImage(image,stdout,MagickFalse,exception);
1281  write_info=DestroyImageInfo(write_info);
1282  if (GetBlobError(image) != MagickFalse)
1283  ThrowWriterException(FileOpenError,"UnableToWriteFile");
1284  return(status);
1285 }
1286 
1287 /*
1288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1289 % %
1290 % %
1291 % %
1292 % W r i t e I m a g e s %
1293 % %
1294 % %
1295 % %
1296 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297 %
1298 % WriteImages() writes an image sequence into one or more files. While
1299 % WriteImage() can write an image sequence, it is limited to writing
1300 % the sequence into a single file using a format which supports multiple
1301 % frames. WriteImages(), however, does not have this limitation, instead it
1302 % generates multiple output files if necessary (or when requested). When
1303 % ImageInfo's adjoin flag is set to MagickFalse, the file name is expected
1304 % to include a printf-style formatting string for the frame number (e.g.
1305 % "image%02d.png").
1306 %
1307 % The format of the WriteImages method is:
1308 %
1309 % MagickBooleanType WriteImages(const ImageInfo *image_info,Image *images,
1310 % const char *filename,ExceptionInfo *exception)
1311 %
1312 % A description of each parameter follows:
1313 %
1314 % o image_info: the image info.
1315 %
1316 % o images: the image list.
1317 %
1318 % o filename: the image filename.
1319 %
1320 % o exception: return any errors or warnings in this structure.
1321 %
1322 */
1324  Image *images,const char *filename,ExceptionInfo *exception)
1325 {
1326 #define WriteImageTag "Write/Image"
1327 
1329  *sans_exception;
1330 
1331  ImageInfo
1332  *write_info;
1333 
1335  proceed;
1336 
1338  progress;
1339 
1341  progress_monitor;
1342 
1344  number_images;
1345 
1347  status;
1348 
1349  register Image
1350  *p;
1351 
1352  assert(image_info != (const ImageInfo *) NULL);
1353  assert(image_info->signature == MagickCoreSignature);
1354  assert(images != (Image *) NULL);
1355  assert(images->signature == MagickCoreSignature);
1356  if (images->debug != MagickFalse)
1357  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
1358  assert(exception != (ExceptionInfo *) NULL);
1359  write_info=CloneImageInfo(image_info);
1360  *write_info->magick='\0';
1361  images=GetFirstImageInList(images);
1362  if (filename != (const char *) NULL)
1363  for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1364  (void) CopyMagickString(p->filename,filename,MagickPathExtent);
1365  (void) CopyMagickString(write_info->filename,images->filename,
1367  sans_exception=AcquireExceptionInfo();
1368  (void) SetImageInfo(write_info,(unsigned int) GetImageListLength(images),
1369  sans_exception);
1370  sans_exception=DestroyExceptionInfo(sans_exception);
1371  if (*write_info->magick == '\0')
1372  (void) CopyMagickString(write_info->magick,images->magick,MagickPathExtent);
1373  p=images;
1374  for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p))
1375  {
1376  register Image
1377  *next;
1378 
1379  next=GetNextImageInList(p);
1380  if (next == (Image *) NULL)
1381  break;
1382  if (p->scene >= next->scene)
1383  {
1384  register ssize_t
1385  i;
1386 
1387  /*
1388  Generate consistent scene numbers.
1389  */
1390  i=(ssize_t) images->scene;
1391  for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1392  p->scene=(size_t) i++;
1393  break;
1394  }
1395  }
1396  /*
1397  Write images.
1398  */
1399  status=MagickTrue;
1400  progress_monitor=(MagickProgressMonitor) NULL;
1401  progress=0;
1402  number_images=GetImageListLength(images);
1403  for (p=images; p != (Image *) NULL; p=GetNextImageInList(p))
1404  {
1405  if (number_images != 1)
1406  progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL,
1407  p->client_data);
1408  status&=WriteImage(write_info,p,exception);
1409  if (number_images != 1)
1410  (void) SetImageProgressMonitor(p,progress_monitor,p->client_data);
1411  if (write_info->adjoin != MagickFalse)
1412  break;
1413  if (number_images != 1)
1414  {
1415 #if defined(MAGICKCORE_OPENMP_SUPPORT)
1416  #pragma omp atomic
1417 #endif
1418  progress++;
1419  proceed=SetImageProgress(p,WriteImageTag,progress,number_images);
1420  if (proceed == MagickFalse)
1421  break;
1422  }
1423  }
1424  write_info=DestroyImageInfo(write_info);
1425  return(status != 0 ? MagickTrue : MagickFalse);
1426 }
size_t rows
Definition: image.h:172
MagickExport Image * ResizeImage(const Image *image, const size_t columns, const size_t rows, const FilterType filter, ExceptionInfo *exception)
Definition: resize.c:3705
MagickExport Image * CloneImages(const Image *images, const char *scenes, ExceptionInfo *exception)
Definition: list.c:206
EndianType endian
Definition: image.h:404
size_t signature
Definition: image.h:488
DisposeType dispose
Definition: image.h:237
char magick[MagickPathExtent]
Definition: image.h:480
MagickExport MagickBooleanType GetDelegateThreadSupport(const DelegateInfo *delegate_info)
Definition: delegate.c:1527
char * scenes
Definition: image.h:390
MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, const PolicyRights rights, const char *pattern)
Definition: policy.c:595
ssize_t ticks_per_second
Definition: image.h:245
FilterType filter
Definition: image.h:219
MagickExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:449
MagickExport ssize_t ParseCommandOption(const CommandOption option, const MagickBooleanType list, const char *options)
Definition: option.c:2988
OrientationType
Definition: image.h:76
MagickExport MagickBooleanType GetBlobError(const Image *image)
Definition: blob.c:1714
char * extract
Definition: image.h:390
PolicyRights
Definition: policy.h:41
size_t signature
Definition: exception.h:123
size_t number_scenes
Definition: image.h:396
MagickExport Image * PingImage(const ImageInfo *image_info, ExceptionInfo *exception)
Definition: constitute.c:256
double rho
Definition: geometry.h:106
MagickExport MagickStatusType ParseAbsoluteGeometry(const char *geometry, RectangleInfo *region_info)
Definition: geometry.c:703
EndianType endian
Definition: image.h:228
MagickBooleanType taint
Definition: image.h:169
StorageType
Definition: pixel.h:145
MagickExport MagickBooleanType IdentifyImage(Image *image, FILE *file, const MagickBooleanType verbose, ExceptionInfo *exception)
Definition: identify.c:469
MagickBooleanType debug
Definition: image.h:485
MagickExport MagickBooleanType GetMagickEncoderThreadSupport(const MagickInfo *magick_info)
Definition: magick.c:543
MagickExport const DelegateInfo * GetDelegateInfo(const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1212
MagickExport Image * ReadInlineImage(const ImageInfo *image_info, const char *content, ExceptionInfo *exception)
Definition: constitute.c:978
MagickExport ExceptionInfo * AcquireExceptionInfo(void)
Definition: exception.c:115
static MagickBooleanType IsCoderAuthorized(const char *coder, const PolicyRights rights, ExceptionInfo *exception)
Definition: constitute.c:406
MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
Definition: delegate.c:1494
MagickExport size_t CopyMagickString(char *magick_restrict destination, const char *magick_restrict source, const size_t length)
Definition: string.c:756
MagickBooleanType EncodeImageHandler(const ImageInfo *, Image *, ExceptionInfo *)
Definition: magick.h:62
ResolutionType units
Definition: image.h:198
size_t delay
Definition: image.h:240
#define WriteImageTag
char magick[MagickPathExtent]
Definition: image.h:319
size_t magick_rows
Definition: image.h:324
MagickExport MagickBooleanType ImageToFile(Image *image, char *filename, ExceptionInfo *exception)
Definition: blob.c:2299
MagickBooleanType verbose
Definition: image.h:445
static long StringToLong(const char *magick_restrict value)
MagickExport const char * GetImageOption(const ImageInfo *image_info, const char *option)
Definition: option.c:2319
double sigma
Definition: geometry.h:106
size_t width
Definition: geometry.h:130
MagickExport MagickBooleanType AcquireUniqueFilename(char *path)
Definition: utility.c:111
Definition: log.h:52
ssize_t MagickOffsetType
Definition: magick-type.h:133
MagickExport MagickBooleanType SetImageOption(ImageInfo *image_info, const char *option, const char *value)
Definition: option.c:3258
Definition: image.h:151
MagickExport Image * GetPreviousImageInList(const Image *images)
Definition: list.c:816
SemaphoreInfo * semaphore
Definition: delegate.h:45
StreamHandler stream
Definition: image.h:468
MagickExport MagickBooleanType GetMagickRawSupport(const MagickInfo *magick_info)
Definition: magick.c:970
MagickExport Image * CropImage(const Image *image, const RectangleInfo *geometry, ExceptionInfo *exception)
Definition: transform.c:537
MagickExport const struct stat * GetBlobProperties(const Image *)
Definition: blob.c:1812
double x
Definition: geometry.h:123
MagickExport Image * PingImages(ImageInfo *image_info, const char *filename, ExceptionInfo *exception)
Definition: constitute.c:311
#define MagickCoreSignature
MagickExport MagickBooleanType ImportImagePixels(Image *image, const ssize_t x, const ssize_t y, const size_t width, const size_t height, const char *map, const StorageType type, const void *pixels, ExceptionInfo *exception)
Definition: pixel.c:4138
MagickExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:293
MagickExport MagickBooleanType GetMagickDecoderSeekableStream(const MagickInfo *magick_info)
Definition: magick.c:413
MagickExport Image * GetFirstImageInList(const Image *images)
Definition: list.c:574
SemaphoreInfo * semaphore
Definition: magick.h:96
MagickExport Image * BlobToImage(const ImageInfo *image_info, const void *blob, const size_t length, ExceptionInfo *exception)
Definition: blob.c:422
MagickExport void GetPathComponent(const char *path, PathType type, char *component)
Definition: utility.c:1223
MagickBooleanType
Definition: magick-type.h:169
MagickExport Image * NewImageList(void)
Definition: list.c:951
size_t scene
Definition: image.h:240
unsigned int MagickStatusType
Definition: magick-type.h:125
MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info, Image *image, ExceptionInfo *exception)
Definition: constitute.c:1053
MagickExport unsigned char * Base64Decode(const char *source, size_t *length)
Definition: utility.c:346
char filename[MagickPathExtent]
Definition: image.h:480
double y
Definition: geometry.h:123
MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path)
Definition: resource.c:1098
MagickExport MagickBooleanType CloseBlob(Image *)
MagickExport MagickBooleanType SetImageProperty(Image *image, const char *property, const char *value, ExceptionInfo *exception)
Definition: property.c:4205
MagickExport const StringInfo * GetImageProfile(const Image *image, const char *name)
Definition: profile.c:259
size_t scene
Definition: image.h:396
#define magick_unused(x)
RectangleInfo page
Definition: image.h:212
size_t magick_columns
Definition: image.h:324
size_t MagickSizeType
Definition: magick-type.h:134
#define MagickPathExtent
MagickExport MagickBooleanType IsStringTrue(const char *value)
Definition: string.c:1415
MagickExport MagickBooleanType IsBlobTemporary(const Image *image)
Definition: blob.c:2967
#define ThrowFileException(exception, severity, tag, context)
PixelTrait alpha_trait
Definition: image.h:280
static size_t PingStream(const Image *magick_unused(image), const void *magick_unused(pixels), const size_t columns)
Definition: constitute.c:244
MagickExport Image * ReadImage(const ImageInfo *image_info, ExceptionInfo *exception)
Definition: constitute.c:419
MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info, const unsigned int frames, ExceptionInfo *exception)
Definition: image.c:2693
#define ThrowReaderException(severity, tag)
char magick_filename[MagickPathExtent]
Definition: image.h:319
MagickExport DecodeImageHandler * GetImageDecoder(const MagickInfo *magick_info)
Definition: magick.c:223
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1145
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1660
MagickExport MagickBooleanType IsPathAccessible(const char *path)
Definition: utility.c:1477
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
MagickExport const MagickInfo * GetMagickInfo(const char *name, ExceptionInfo *exception)
Definition: magick.c:610
MagickExport Image * AcquireImage(const ImageInfo *image_info, ExceptionInfo *exception)
Definition: image.c:134
MagickExport MagickBooleanType OpenBlob(const ImageInfo *, Image *, const BlobMode, ExceptionInfo *)
MagickBooleanType(* MagickProgressMonitor)(const char *, const MagickOffsetType, const MagickSizeType, void *)
Definition: monitor.h:26
size_t height
Definition: geometry.h:130
MagickExport void ResetTimer(TimerInfo *time_info)
Definition: timer.c:442
MagickExport EncodeImageHandler * GetImageEncoder(const MagickInfo *magick_info)
Definition: magick.c:253
MagickExport Image * ReadStream(const ImageInfo *image_info, StreamHandler stream, ExceptionInfo *exception)
Definition: stream.c:1002
MagickExport MagickProgressMonitor SetImageProgressMonitor(Image *image, const MagickProgressMonitor progress_monitor, void *client_data)
Definition: monitor.c:194
MagickExport Image * DestroyImageList(Image *images)
Definition: list.c:475
MagickExport MagickBooleanType GetMagickEndianSupport(const MagickInfo *magick_info)
Definition: magick.c:575
MagickExport size_t InterpretImageFilename(const ImageInfo *image_info, Image *image, const char *format, int value, char *filename, ExceptionInfo *exception)
Definition: image.c:1628
MagickExport MagickBooleanType IsBlobSeekable(const Image *image)
Definition: blob.c:2888
MagickExport MagickBooleanType SetImageExtent(Image *image, const size_t columns, const size_t rows, ExceptionInfo *exception)
Definition: image.c:2637
MagickExport Image * ReadImages(ImageInfo *image_info, const char *filename, ExceptionInfo *exception)
Definition: constitute.c:879
TimerInfo timer
Definition: image.h:300
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1435
MagickExport MagickBooleanType GetMagickDecoderThreadSupport(const MagickInfo *magick_info)
Definition: magick.c:447
DisposeType
Definition: layer.h:27
char filename[MagickPathExtent]
Definition: image.h:319
#define GetMagickModule()
Definition: log.h:28
MagickBooleanType affirm
Definition: image.h:384
MagickExport Image * ConstituteImage(const size_t columns, const size_t rows, const char *map, const StorageType storage, const void *pixels, ExceptionInfo *exception)
Definition: constitute.c:133
MagickExport MagickBooleanType GetMagickEncoderSeekableStream(const MagickInfo *magick_info)
Definition: magick.c:509
MagickExport char * InterpretImageProperties(ImageInfo *image_info, Image *image, const char *embed_text, ExceptionInfo *exception)
Definition: property.c:3482
MagickExport MagickBooleanType ResetImagePixels(Image *image, ExceptionInfo *exception)
Definition: image.c:2220
MagickExport ImageInfo * DestroyImageInfo(ImageInfo *image_info)
Definition: image.c:1231
MagickExport MagickBooleanType IsTaintImage(const Image *image)
Definition: image.c:1919
MagickExport void ReplaceImageInList(Image **images, Image *replace)
Definition: list.c:1179
MagickExport Image * GetNextImageInList(const Image *images)
Definition: list.c:784
MagickExport char * DestroyString(char *string)
Definition: string.c:813
MagickExport MagickBooleanType DeleteImageProperty(Image *image, const char *property)
Definition: property.c:279
MagickExport const char * GetImageProperty(const Image *image, const char *property, ExceptionInfo *exception)
Definition: property.c:2217
MagickExport ImageInfo * CloneImageInfo(const ImageInfo *image_info)
Definition: image.c:919
MagickExport MagickStatusType ParseGeometry(const char *geometry, GeometryInfo *geometry_info)
Definition: geometry.c:853
MagickExport void AppendImageToList(Image **images, const Image *append)
Definition: list.c:80
MagickExport void SetGeometry(const Image *image, RectangleInfo *geometry)
Definition: geometry.c:1689
MagickPrivate MagickBooleanType SyncImageProfiles(Image *)
Definition: profile.c:2363
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1122
PointInfo resolution
Definition: image.h:209
#define magick_unreferenced(x)
MagickExport MagickProgressMonitor SetImageInfoProgressMonitor(ImageInfo *image_info, const MagickProgressMonitor progress_monitor, void *client_data)
Definition: monitor.c:243
MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, Image *image, const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1677
ResolutionType
Definition: image.h:89
#define MagickExport
OrientationType orientation
Definition: image.h:166
MagickBooleanType adjoin
Definition: image.h:384
char * page
Definition: image.h:390
MagickExport ssize_t FormatMagickTime(const time_t time, const size_t length, char *timestamp)
Definition: timer.c:255
MagickBooleanType ping
Definition: image.h:445
MagickExport MagickBooleanType IsSceneGeometry(const char *geometry, const MagickBooleanType pedantic)
Definition: geometry.c:651
MagickExport size_t GetImageListLength(const Image *images)
Definition: list.c:709
#define ThrowWriterException(severity, tag)
void * client_data
Definition: image.h:306
MagickExport Image * DestroyImage(Image *image)
Definition: image.c:1160
ColorspaceType colorspace
Definition: image.h:157
MagickExport MagickStatusType ParseRegionGeometry(const Image *image, const char *geometry, RectangleInfo *region_info, ExceptionInfo *exception)
Definition: geometry.c:1650
MagickExport void DisassociateImageStream(Image *image)
Definition: image.c:1293
size_t(* StreamHandler)(const Image *, const void *, const size_t)
Definition: stream.h:31
MagickExport MagickBooleanType SetImageProgress(const Image *image, const char *tag, const MagickOffsetType offset, const MagickSizeType extent)
Definition: monitor.c:136
MagickBooleanType temporary
Definition: image.h:384
MagickBooleanType debug
Definition: image.h:334
MagickExport ExceptionInfo * DestroyExceptionInfo(ExceptionInfo *exception)
Definition: exception.c:418
MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info, Image *images, const char *filename, ExceptionInfo *exception)
Definition: constitute.c:1323
ExceptionType severity
Definition: exception.h:104
Image * DecodeImageHandler(const ImageInfo *, ExceptionInfo *)
Definition: magick.h:59