MagickCore 6.9.12-98
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
image.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% IIIII M M AAA GGGG EEEEE %
7% I MM MM A A G E %
8% I M M M AAAAA G GG EEE %
9% I M M A A G G E %
10% IIIII M M A A GGGG EEEEE %
11% %
12% %
13% MagickCore Image Methods %
14% %
15% Software Design %
16% Cristy %
17% July 1992 %
18% %
19% %
20% Copyright 1999 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/*
41 Include declarations.
42*/
43#include "magick/studio.h"
44#include "magick/animate.h"
45#include "magick/artifact.h"
46#include "magick/blob.h"
47#include "magick/blob-private.h"
48#include "magick/cache.h"
49#include "magick/cache-private.h"
50#include "magick/cache-view.h"
51#include "magick/channel.h"
52#include "magick/client.h"
53#include "magick/color.h"
54#include "magick/color-private.h"
55#include "magick/colormap.h"
56#include "magick/colorspace.h"
57#include "magick/colorspace-private.h"
58#include "magick/composite.h"
59#include "magick/composite-private.h"
60#include "magick/compress.h"
61#include "magick/constitute.h"
62#include "magick/delegate.h"
63#include "magick/deprecate.h"
64#include "magick/display.h"
65#include "magick/draw.h"
66#include "magick/enhance.h"
67#include "magick/exception.h"
68#include "magick/exception-private.h"
69#include "magick/gem.h"
70#include "magick/geometry.h"
71#include "magick/histogram.h"
72#include "magick/image-private.h"
73#include "magick/list.h"
74#include "magick/magic.h"
75#include "magick/magick.h"
76#include "magick/memory_.h"
77#include "magick/memory-private.h"
78#include "magick/module.h"
79#include "magick/monitor.h"
80#include "magick/monitor-private.h"
81#include "magick/option.h"
82#include "magick/paint.h"
83#include "magick/pixel-accessor.h"
84#include "magick/pixel-private.h"
85#include "magick/profile.h"
86#include "magick/property.h"
87#include "magick/quantize.h"
88#include "magick/random_.h"
89#include "magick/resource_.h"
90#include "magick/segment.h"
91#include "magick/semaphore.h"
92#include "magick/signature-private.h"
93#include "magick/statistic.h"
94#include "magick/string_.h"
95#include "magick/string-private.h"
96#include "magick/thread-private.h"
97#include "magick/threshold.h"
98#include "magick/timer.h"
99#include "magick/timer-private.h"
100#include "magick/token.h"
101#include "magick/token-private.h"
102#include "magick/utility.h"
103#include "magick/version.h"
104#include "magick/xwindow-private.h"
105␌
106/*
107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108% %
109% %
110% %
111% A c q u i r e I m a g e %
112% %
113% %
114% %
115%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116%
117% AcquireImage() returns a pointer to an image structure initialized to
118% default values.
119%
120% The format of the AcquireImage method is:
121%
122% Image *AcquireImage(const ImageInfo *image_info)
123%
124% A description of each parameter follows:
125%
126% o image_info: Many of the image default values are set from this
127% structure. For example, filename, compression, depth, background color,
128% and others.
129%
130*/
131MagickExport Image *AcquireImage(const ImageInfo *image_info)
132{
133 const char
134 *option;
135
136 Image
137 *image;
138
139 MagickStatusType
140 flags;
141
142 /*
143 Allocate image structure.
144 */
145 if (IsEventLogging() != MagickFalse)
146 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
147 image=(Image *) AcquireCriticalMemory(sizeof(*image));
148 (void) memset(image,0,sizeof(*image));
149 /*
150 Initialize Image structure.
151 */
152 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
153 image->storage_class=DirectClass;
154 image->depth=MAGICKCORE_QUANTUM_DEPTH;
155 image->colorspace=sRGBColorspace;
156 image->rendering_intent=PerceptualIntent;
157 image->gamma=1.000f/2.200f;
158 image->chromaticity.red_primary.x=0.6400f;
159 image->chromaticity.red_primary.y=0.3300f;
160 image->chromaticity.red_primary.z=0.0300f;
161 image->chromaticity.green_primary.x=0.3000f;
162 image->chromaticity.green_primary.y=0.6000f;
163 image->chromaticity.green_primary.z=0.1000f;
164 image->chromaticity.blue_primary.x=0.1500f;
165 image->chromaticity.blue_primary.y=0.0600f;
166 image->chromaticity.blue_primary.z=0.7900f;
167 image->chromaticity.white_point.x=0.3127f;
168 image->chromaticity.white_point.y=0.3290f;
169 image->chromaticity.white_point.z=0.3583f;
170 image->interlace=NoInterlace;
171 image->ticks_per_second=UndefinedTicksPerSecond;
172 image->compose=OverCompositeOp;
173 image->blur=1.0;
174 GetPixelPacketRGBA(BackgroundColorRGBA,&image->background_color);
175 GetPixelPacketRGBA(BorderColorRGBA,&image->border_color);
176 GetPixelPacketRGBA(MatteColorRGBA,&image->matte_color);
177 GetPixelPacketRGBA(TransparentColorRGBA,&image->transparent_color);
178 GetTimerInfo(&image->timer);
179 image->ping=MagickFalse;
180 image->cache=AcquirePixelCache(0);
181 image->blob=CloneBlobInfo((BlobInfo *) NULL);
182 InitializeExceptionInfo(&image->exception);
183 image->timestamp=GetMagickTime();
184 image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
185 != 0 ? MagickTrue : MagickFalse;
186 image->reference_count=1;
187 image->semaphore=AllocateSemaphoreInfo();
188 image->signature=MagickCoreSignature;
189 if (image_info == (ImageInfo *) NULL)
190 return(image);
191 /*
192 Transfer image info.
193 */
194 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
195 MagickFalse);
196 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
197 (void) CopyMagickString(image->magick_filename,image_info->filename,
198 MaxTextExtent);
199 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
200 if (image_info->size != (char *) NULL)
201 {
202 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
203 image->columns=image->extract_info.width;
204 image->rows=image->extract_info.height;
205 image->offset=image->extract_info.x;
206 image->extract_info.x=0;
207 image->extract_info.y=0;
208 }
209 if (image_info->extract != (char *) NULL)
210 {
212 geometry;
213
214 (void) memset(&geometry,0,sizeof(geometry));
215 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
216 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
217 {
218 image->extract_info=geometry;
219 Swap(image->columns,image->extract_info.width);
220 Swap(image->rows,image->extract_info.height);
221 }
222 }
223 image->compression=image_info->compression;
224 image->quality=image_info->quality;
225 image->endian=image_info->endian;
226 image->interlace=image_info->interlace;
227 image->units=image_info->units;
228 if (image_info->density != (char *) NULL)
229 {
231 geometry_info;
232
233 flags=ParseGeometry(image_info->density,&geometry_info);
234 if ((flags & RhoValue) != 0)
235 image->x_resolution=geometry_info.rho;
236 image->y_resolution=image->x_resolution;
237 if ((flags & SigmaValue) != 0)
238 image->y_resolution=geometry_info.sigma;
239 }
240 if (image_info->page != (char *) NULL)
241 {
242 char
243 *geometry;
244
245 image->page=image->extract_info;
246 geometry=GetPageGeometry(image_info->page);
247 (void) ParseAbsoluteGeometry(geometry,&image->page);
248 geometry=DestroyString(geometry);
249 }
250 if (image_info->depth != 0)
251 image->depth=image_info->depth;
252 image->dither=image_info->dither;
253 image->background_color=image_info->background_color;
254 image->border_color=image_info->border_color;
255 image->matte_color=image_info->matte_color;
256 image->transparent_color=image_info->transparent_color;
257 image->ping=image_info->ping;
258 image->progress_monitor=image_info->progress_monitor;
259 image->client_data=image_info->client_data;
260 if (image_info->cache != (void *) NULL)
261 ClonePixelCacheMethods(image->cache,image_info->cache);
262 (void) SyncImageSettings(image_info,image);
263 option=GetImageOption(image_info,"delay");
264 if (option != (const char *) NULL)
265 {
267 geometry_info;
268
269 flags=ParseGeometry(option,&geometry_info);
270 if ((flags & GreaterValue) != 0)
271 {
272 if ((double) image->delay > floor(geometry_info.rho+0.5))
273 image->delay=(size_t) CastDoubleToLong(floor(
274 geometry_info.rho+0.5));
275 }
276 else
277 if ((flags & LessValue) != 0)
278 {
279 if ((double) image->delay < floor(geometry_info.rho+0.5))
280 image->ticks_per_second=CastDoubleToLong(floor(
281 geometry_info.sigma+0.5));
282 }
283 else
284 image->delay=(size_t) CastDoubleToLong(floor(
285 geometry_info.rho+0.5));
286 if ((flags & SigmaValue) != 0)
287 image->ticks_per_second=CastDoubleToLong(floor(
288 geometry_info.sigma+0.5));
289 }
290 option=GetImageOption(image_info,"dispose");
291 if (option != (const char *) NULL)
292 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
293 MagickFalse,option);
294 return(image);
295}
296␌
297/*
298%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299% %
300% %
301% %
302% A c q u i r e I m a g e I n f o %
303% %
304% %
305% %
306%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
307%
308% AcquireImageInfo() allocates the ImageInfo structure.
309%
310% The format of the AcquireImageInfo method is:
311%
312% ImageInfo *AcquireImageInfo(void)
313%
314*/
315MagickExport ImageInfo *AcquireImageInfo(void)
316{
318 *image_info;
319
320 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
321 if (image_info == (ImageInfo *) NULL)
322 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
323 GetImageInfo(image_info);
324 return(image_info);
325}
326␌
327/*
328%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
329% %
330% %
331% %
332% A c q u i r e N e x t I m a g e %
333% %
334% %
335% %
336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337%
338% AcquireNextImage() initializes the next image in a sequence to
339% default values. The next member of image points to the newly allocated
340% image. If there is a memory shortage, next is assigned NULL.
341%
342% The format of the AcquireNextImage method is:
343%
344% void AcquireNextImage(const ImageInfo *image_info,Image *image)
345%
346% A description of each parameter follows:
347%
348% o image_info: Many of the image default values are set from this
349% structure. For example, filename, compression, depth, background color,
350% and others.
351%
352% o image: the image.
353%
354*/
355MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
356{
357 /*
358 Allocate image structure.
359 */
360 assert(image != (Image *) NULL);
361 assert(image->signature == MagickCoreSignature);
362 if (IsEventLogging() != MagickFalse)
363 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
364 image->next=AcquireImage(image_info);
365 if (GetNextImageInList(image) == (Image *) NULL)
366 return;
367 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
368 MaxTextExtent);
369 if (image_info != (ImageInfo *) NULL)
370 (void) CopyMagickString(GetNextImageInList(image)->filename,
371 image_info->filename,MaxTextExtent);
372 DestroyBlob(GetNextImageInList(image));
373 image->next->blob=ReferenceBlob(image->blob);
374 image->next->endian=image->endian;
375 image->next->scene=image->scene+1;
376 image->next->previous=image;
377}
378␌
379/*
380%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381% %
382% %
383% %
384% A p p e n d I m a g e s %
385% %
386% %
387% %
388%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389%
390% AppendImages() takes all images from the current image pointer to the end
391% of the image list and appends them to each other top-to-bottom if the
392% stack parameter is true, otherwise left-to-right.
393%
394% The current gravity setting now effects how the image is justified in the
395% final image.
396%
397% The format of the AppendImages method is:
398%
399% Image *AppendImages(const Image *images,const MagickBooleanType stack,
400% ExceptionInfo *exception)
401%
402% A description of each parameter follows:
403%
404% o images: the image sequence.
405%
406% o stack: A value other than 0 stacks the images top-to-bottom.
407%
408% o exception: return any errors or warnings in this structure.
409%
410*/
411MagickExport Image *AppendImages(const Image *images,
412 const MagickBooleanType stack,ExceptionInfo *exception)
413{
414#define AppendImageTag "Append/Image"
415
417 *append_view;
418
419 Image
420 *append_image;
421
422 MagickBooleanType
423 homogeneous_colorspace,
424 matte,
425 status;
426
427 MagickOffsetType
428 n;
429
431 geometry;
432
433 const Image
434 *next;
435
436 size_t
437 depth,
438 height,
439 number_images,
440 width;
441
442 ssize_t
443 x_offset,
444 y,
445 y_offset;
446
447 /*
448 Compute maximum area of appended area.
449 */
450 assert(images != (Image *) NULL);
451 assert(images->signature == MagickCoreSignature);
452 assert(exception != (ExceptionInfo *) NULL);
453 assert(exception->signature == MagickCoreSignature);
454 if (IsEventLogging() != MagickFalse)
455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
456 matte=images->matte;
457 number_images=1;
458 width=images->columns;
459 height=images->rows;
460 depth=images->depth;
461 homogeneous_colorspace=MagickTrue;
462 next=GetNextImageInList(images);
463 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
464 {
465 if (next->depth > depth)
466 depth=next->depth;
467 if (next->colorspace != images->colorspace)
468 homogeneous_colorspace=MagickFalse;
469 if (next->matte != MagickFalse)
470 matte=MagickTrue;
471 number_images++;
472 if (stack != MagickFalse)
473 {
474 if (next->columns > width)
475 width=next->columns;
476 height+=next->rows;
477 continue;
478 }
479 width+=next->columns;
480 if (next->rows > height)
481 height=next->rows;
482 }
483 /*
484 Append images.
485 */
486 append_image=CloneImage(images,width,height,MagickTrue,exception);
487 if (append_image == (Image *) NULL)
488 return((Image *) NULL);
489 if (SetImageStorageClass(append_image,DirectClass) == MagickFalse)
490 {
491 InheritException(exception,&append_image->exception);
492 append_image=DestroyImage(append_image);
493 return((Image *) NULL);
494 }
495 if (homogeneous_colorspace == MagickFalse)
496 (void) SetImageColorspace(append_image,sRGBColorspace);
497 append_image->depth=depth;
498 append_image->matte=matte;
499 append_image->page=images->page;
500 (void) SetImageBackgroundColor(append_image);
501 status=MagickTrue;
502 x_offset=0;
503 y_offset=0;
504 next=images;
505 append_view=AcquireAuthenticCacheView(append_image,exception);
506 for (n=0; n < (MagickOffsetType) number_images; n++)
507 {
509 *image_view;
510
511 MagickBooleanType
512 proceed;
513
514 SetGeometry(append_image,&geometry);
515 GravityAdjustGeometry(next->columns,next->rows,next->gravity,&geometry);
516 if (stack != MagickFalse)
517 x_offset-=geometry.x;
518 else
519 y_offset-=geometry.y;
520 image_view=AcquireVirtualCacheView(next,exception);
521#if defined(MAGICKCORE_OPENMP_SUPPORT)
522 #pragma omp parallel for schedule(static) shared(status) \
523 magick_number_threads(next,next,next->rows,1)
524#endif
525 for (y=0; y < (ssize_t) next->rows; y++)
526 {
527 MagickBooleanType
528 sync;
529
530 const IndexPacket
531 *magick_restrict indexes;
532
533 const PixelPacket
534 *magick_restrict p;
535
536 IndexPacket
537 *magick_restrict append_indexes;
538
540 *magick_restrict q;
541
542 ssize_t
543 x;
544
545 if (status == MagickFalse)
546 continue;
547 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
548 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
549 next->columns,1,exception);
550 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
551 {
552 status=MagickFalse;
553 continue;
554 }
555 indexes=GetCacheViewVirtualIndexQueue(image_view);
556 append_indexes=GetCacheViewAuthenticIndexQueue(append_view);
557 for (x=0; x < (ssize_t) next->columns; x++)
558 {
559 SetPixelRed(q,GetPixelRed(p));
560 SetPixelGreen(q,GetPixelGreen(p));
561 SetPixelBlue(q,GetPixelBlue(p));
562 SetPixelOpacity(q,OpaqueOpacity);
563 if (next->matte != MagickFalse)
564 SetPixelOpacity(q,GetPixelOpacity(p));
565 if ((next->colorspace == CMYKColorspace) &&
566 (append_image->colorspace == CMYKColorspace))
567 SetPixelIndex(append_indexes+x,GetPixelIndex(indexes+x));
568 p++;
569 q++;
570 }
571 sync=SyncCacheViewAuthenticPixels(append_view,exception);
572 if (sync == MagickFalse)
573 status=MagickFalse;
574 }
575 image_view=DestroyCacheView(image_view);
576 if (stack == MagickFalse)
577 {
578 x_offset+=(ssize_t) next->columns;
579 y_offset=0;
580 }
581 else
582 {
583 x_offset=0;
584 y_offset+=(ssize_t) next->rows;
585 }
586 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
587 if (proceed == MagickFalse)
588 break;
589 next=GetNextImageInList(next);
590 }
591 append_view=DestroyCacheView(append_view);
592 if (status == MagickFalse)
593 append_image=DestroyImage(append_image);
594 return(append_image);
595}
596␌
597/*
598%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599% %
600% %
601% %
602% C a t c h I m a g e E x c e p t i o n %
603% %
604% %
605% %
606%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
607%
608% CatchImageException() returns if no exceptions are found in the image
609% sequence, otherwise it determines the most severe exception and reports
610% it as a warning or error depending on the severity.
611%
612% The format of the CatchImageException method is:
613%
614% ExceptionType CatchImageException(Image *image)
615%
616% A description of each parameter follows:
617%
618% o image: An image sequence.
619%
620*/
621MagickExport ExceptionType CatchImageException(Image *image)
622{
624 *exception;
625
626 ExceptionType
627 severity;
628
629 assert(image != (const Image *) NULL);
630 assert(image->signature == MagickCoreSignature);
631 if (IsEventLogging() != MagickFalse)
632 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
633 exception=AcquireExceptionInfo();
634 GetImageException(image,exception);
635 CatchException(exception);
636 severity=exception->severity;
637 exception=DestroyExceptionInfo(exception);
638 return(severity);
639}
640␌
641/*
642%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
643% %
644% %
645% %
646% C l i p I m a g e P a t h %
647% %
648% %
649% %
650%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
651%
652% ClipImagePath() sets the image clip mask based any clipping path information
653% if it exists.
654%
655% The format of the ClipImagePath method is:
656%
657% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
658% const MagickBooleanType inside)
659%
660% A description of each parameter follows:
661%
662% o image: the image.
663%
664% o pathname: name of clipping path resource. If name is preceded by #, use
665% clipping path numbered by name.
666%
667% o inside: if non-zero, later operations take effect inside clipping path.
668% Otherwise later operations take effect outside clipping path.
669%
670*/
671
672MagickExport MagickBooleanType ClipImage(Image *image)
673{
674 return(ClipImagePath(image,"#1",MagickTrue));
675}
676
677MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
678 const MagickBooleanType inside)
679{
680#define ClipImagePathTag "ClipPath/Image"
681
682 char
683 *property;
684
685 const char
686 *value;
687
688 Image
689 *clip_mask;
690
692 *image_info;
693
694 assert(image != (const Image *) NULL);
695 assert(image->signature == MagickCoreSignature);
696 assert(pathname != NULL);
697 if (IsEventLogging() != MagickFalse)
698 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
699 property=AcquireString(pathname);
700 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
701 pathname);
702 value=GetImageProperty(image,property);
703 property=DestroyString(property);
704 if (value == (const char *) NULL)
705 {
706 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
707 image->filename);
708 return(MagickFalse);
709 }
710 image_info=AcquireImageInfo();
711 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
712 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
713 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
714 image_info=DestroyImageInfo(image_info);
715 if (clip_mask == (Image *) NULL)
716 return(MagickFalse);
717 if (clip_mask->storage_class == PseudoClass)
718 {
719 (void) SyncImage(clip_mask);
720 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
721 return(MagickFalse);
722 }
723 if (inside == MagickFalse)
724 (void) NegateImage(clip_mask,MagickFalse);
725 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
726 "8BIM:1999,2998:%s\nPS",pathname);
727 (void) SetImageClipMask(image,clip_mask);
728 clip_mask=DestroyImage(clip_mask);
729 return(MagickTrue);
730}
731␌
732/*
733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734% %
735% %
736% %
737% C l o n e I m a g e %
738% %
739% %
740% %
741%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742%
743% CloneImage() copies an image and returns the copy as a new image object.
744%
745% If the specified columns and rows is 0, an exact copy of the image is
746% returned, otherwise the pixel data is undefined and must be initialized
747% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
748% failure, a NULL image is returned and exception describes the reason for the
749% failure.
750%
751% The format of the CloneImage method is:
752%
753% Image *CloneImage(const Image *image,const size_t columns,
754% const size_t rows,const MagickBooleanType orphan,
755% ExceptionInfo *exception)
756%
757% A description of each parameter follows:
758%
759% o image: the image.
760%
761% o columns: the number of columns in the cloned image.
762%
763% o rows: the number of rows in the cloned image.
764%
765% o detach: With a value other than 0, the cloned image is detached from
766% its parent I/O stream.
767%
768% o exception: return any errors or warnings in this structure.
769%
770*/
771MagickExport Image *CloneImage(const Image *image,const size_t columns,
772 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
773{
774 double
775 scale_x,
776 scale_y;
777
778 Image
779 *clone_image;
780
781 size_t
782 length;
783
784 /*
785 Clone the image.
786 */
787 assert(image != (const Image *) NULL);
788 assert(image->signature == MagickCoreSignature);
789 assert(exception != (ExceptionInfo *) NULL);
790 assert(exception->signature == MagickCoreSignature);
791 if (IsEventLogging() != MagickFalse)
792 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
793 if ((image->columns == 0) || (image->rows == 0))
794 {
795 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
796 "NegativeOrZeroImageSize","`%s'",image->filename);
797 return((Image *) NULL);
798 }
799 clone_image=(Image *) AcquireCriticalMemory(sizeof(*clone_image));
800 (void) memset(clone_image,0,sizeof(*clone_image));
801 clone_image->signature=MagickCoreSignature;
802 clone_image->storage_class=image->storage_class;
803 clone_image->channels=image->channels;
804 clone_image->colorspace=image->colorspace;
805 clone_image->matte=image->matte;
806 clone_image->columns=image->columns;
807 clone_image->rows=image->rows;
808 clone_image->dither=image->dither;
809 (void) CloneImageProfiles(clone_image,image);
810 (void) CloneImageProperties(clone_image,image);
811 (void) CloneImageArtifacts(clone_image,image);
812 GetTimerInfo(&clone_image->timer);
813 InitializeExceptionInfo(&clone_image->exception);
814 InheritException(&clone_image->exception,&image->exception);
815 if (image->ascii85 != (void *) NULL)
816 Ascii85Initialize(clone_image);
817 clone_image->extent=image->extent;
818 clone_image->magick_columns=image->magick_columns;
819 clone_image->magick_rows=image->magick_rows;
820 clone_image->type=image->type;
821 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
822 MaxTextExtent);
823 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
824 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
825 clone_image->progress_monitor=image->progress_monitor;
826 clone_image->client_data=image->client_data;
827 clone_image->reference_count=1;
828 clone_image->next=image->next;
829 clone_image->previous=image->previous;
830 clone_image->list=NewImageList();
831 clone_image->clip_mask=NewImageList();
832 clone_image->mask=NewImageList();
833 if (detach == MagickFalse)
834 clone_image->blob=ReferenceBlob(image->blob);
835 else
836 {
837 clone_image->next=NewImageList();
838 clone_image->previous=NewImageList();
839 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
840 }
841 clone_image->ping=image->ping;
842 clone_image->debug=image->debug;
843 clone_image->semaphore=AllocateSemaphoreInfo();
844 if (image->colormap != (PixelPacket *) NULL)
845 {
846 /*
847 Allocate and copy the image colormap.
848 */
849 clone_image->colors=image->colors;
850 length=(size_t) image->colors;
851 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length+1,
852 sizeof(*clone_image->colormap));
853 if (clone_image->colormap == (PixelPacket *) NULL)
854 {
855 clone_image=DestroyImage(clone_image);
856 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
857 }
858 (void) memcpy(clone_image->colormap,image->colormap,length*
859 sizeof(*clone_image->colormap));
860 }
861 if ((columns == 0) || (rows == 0))
862 {
863 if (image->montage != (char *) NULL)
864 (void) CloneString(&clone_image->montage,image->montage);
865 if (image->directory != (char *) NULL)
866 (void) CloneString(&clone_image->directory,image->directory);
867 if (image->clip_mask != (Image *) NULL)
868 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
869 exception);
870 if (image->mask != (Image *) NULL)
871 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
872 clone_image->cache=ReferencePixelCache(image->cache);
873 return(clone_image);
874 }
875 if ((columns == image->columns) && (rows == image->rows))
876 {
877 if (image->clip_mask != (Image *) NULL)
878 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
879 exception);
880 if (image->mask != (Image *) NULL)
881 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
882 }
883 scale_x=1.0;
884 scale_y=1.0;
885 if (image->columns != 0)
886 scale_x=(double) columns/(double) image->columns;
887 if (image->rows != 0)
888 scale_y=(double) rows/(double) image->rows;
889 clone_image->page.width=(size_t) CastDoubleToLong(floor(scale_x*
890 image->page.width+0.5));
891 clone_image->page.height=(size_t) CastDoubleToLong(floor(scale_y*
892 image->page.height+0.5));
893 if (MagickAbsoluteValue(scale_x-scale_y) < 2.0)
894 scale_x=scale_y=MagickMin(scale_x,scale_y);
895 clone_image->page.x=CastDoubleToLong(ceil(scale_x*image->page.x-0.5));
896 clone_image->tile_offset.x=CastDoubleToLong(ceil(scale_x*
897 image->tile_offset.x-0.5));
898 clone_image->page.y=CastDoubleToLong(ceil(scale_y*image->page.y-0.5));
899 clone_image->tile_offset.y=CastDoubleToLong(ceil(scale_y*
900 image->tile_offset.y-0.5));
901 clone_image->cache=ClonePixelCache(image->cache);
902 if (SetImageExtent(clone_image,columns,rows) == MagickFalse)
903 {
904 InheritException(exception,&clone_image->exception);
905 clone_image=DestroyImage(clone_image);
906 }
907 return(clone_image);
908}
909␌
910/*
911%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912% %
913% %
914% %
915% C l o n e I m a g e I n f o %
916% %
917% %
918% %
919%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
920%
921% CloneImageInfo() makes a copy of the given image info structure. If
922% NULL is specified, a new image info structure is created initialized to
923% default values.
924%
925% The format of the CloneImageInfo method is:
926%
927% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
928%
929% A description of each parameter follows:
930%
931% o image_info: the image info.
932%
933*/
934MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
935{
937 *clone_info;
938
939 clone_info=AcquireImageInfo();
940 if (image_info == (ImageInfo *) NULL)
941 return(clone_info);
942 clone_info->compression=image_info->compression;
943 clone_info->temporary=image_info->temporary;
944 clone_info->adjoin=image_info->adjoin;
945 clone_info->antialias=image_info->antialias;
946 clone_info->scene=image_info->scene;
947 clone_info->number_scenes=image_info->number_scenes;
948 clone_info->depth=image_info->depth;
949 if (image_info->size != (char *) NULL)
950 (void) CloneString(&clone_info->size,image_info->size);
951 if (image_info->extract != (char *) NULL)
952 (void) CloneString(&clone_info->extract,image_info->extract);
953 if (image_info->scenes != (char *) NULL)
954 (void) CloneString(&clone_info->scenes,image_info->scenes);
955 if (image_info->page != (char *) NULL)
956 (void) CloneString(&clone_info->page,image_info->page);
957 clone_info->interlace=image_info->interlace;
958 clone_info->endian=image_info->endian;
959 clone_info->units=image_info->units;
960 clone_info->quality=image_info->quality;
961 if (image_info->sampling_factor != (char *) NULL)
962 (void) CloneString(&clone_info->sampling_factor,
963 image_info->sampling_factor);
964 if (image_info->server_name != (char *) NULL)
965 (void) CloneString(&clone_info->server_name,image_info->server_name);
966 if (image_info->font != (char *) NULL)
967 (void) CloneString(&clone_info->font,image_info->font);
968 if (image_info->texture != (char *) NULL)
969 (void) CloneString(&clone_info->texture,image_info->texture);
970 if (image_info->density != (char *) NULL)
971 (void) CloneString(&clone_info->density,image_info->density);
972 clone_info->pointsize=image_info->pointsize;
973 clone_info->fuzz=image_info->fuzz;
974 clone_info->pen=image_info->pen;
975 clone_info->background_color=image_info->background_color;
976 clone_info->border_color=image_info->border_color;
977 clone_info->matte_color=image_info->matte_color;
978 clone_info->transparent_color=image_info->transparent_color;
979 clone_info->dither=image_info->dither;
980 clone_info->monochrome=image_info->monochrome;
981 clone_info->colors=image_info->colors;
982 clone_info->colorspace=image_info->colorspace;
983 clone_info->type=image_info->type;
984 clone_info->orientation=image_info->orientation;
985 clone_info->preview_type=image_info->preview_type;
986 clone_info->group=image_info->group;
987 clone_info->ping=image_info->ping;
988 clone_info->verbose=image_info->verbose;
989 if (image_info->view != (char *) NULL)
990 (void) CloneString(&clone_info->view,image_info->view);
991 if (image_info->authenticate != (char *) NULL)
992 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
993 (void) CloneImageOptions(clone_info,image_info);
994 clone_info->progress_monitor=image_info->progress_monitor;
995 clone_info->client_data=image_info->client_data;
996 clone_info->cache=image_info->cache;
997 if (image_info->cache != (void *) NULL)
998 clone_info->cache=ReferencePixelCache(image_info->cache);
999 if (image_info->profile != (void *) NULL)
1000 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
1001 image_info->profile);
1002 SetImageInfoFile(clone_info,image_info->file);
1003 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
1004 clone_info->stream=image_info->stream;
1005 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
1006 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
1007 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
1008 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
1009 (void) CopyMagickString(clone_info->filename,image_info->filename,
1010 MaxTextExtent);
1011 clone_info->subimage=image_info->scene; /* deprecated */
1012 clone_info->subrange=image_info->number_scenes; /* deprecated */
1013 clone_info->channel=image_info->channel;
1014 clone_info->debug=image_info->debug;
1015 clone_info->signature=image_info->signature;
1016 return(clone_info);
1017}
1018␌
1019/*
1020%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021% %
1022% %
1023% %
1024% C o p y I m a g e P i x e l s %
1025% %
1026% %
1027% %
1028%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1029%
1030% CopyImagePixels() copies pixels from the source image as defined by the
1031% geometry the destination image at the specified offset.
1032%
1033% The format of the CopyImagePixels method is:
1034%
1035% MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1036% const RectangleInfo *geometry,const OffsetInfo *offset,
1037% ExceptionInfo *exception)
1038%
1039% A description of each parameter follows:
1040%
1041% o image: the destination image.
1042%
1043% o source_image: the source image.
1044%
1045% o geometry: define the dimensions of the source pixel rectangle.
1046%
1047% o offset: define the offset in the destination image.
1048%
1049% o exception: return the highest severity exception.
1050%
1051*/
1052MagickExport MagickBooleanType CopyImagePixels(Image *image,
1053 const Image *source_image,const RectangleInfo *geometry,
1054 const OffsetInfo *offset,ExceptionInfo *exception)
1055{
1056#define CopyImageTag "Copy/Image"
1057
1058 CacheView
1059 *image_view,
1060 *source_view;
1061
1062 MagickBooleanType
1063 status;
1064
1065 MagickOffsetType
1066 progress;
1067
1068 ssize_t
1069 y;
1070
1071 assert(image != (Image *) NULL);
1072 assert(source_image != (Image *) NULL);
1073 assert(geometry != (RectangleInfo *) NULL);
1074 assert(offset != (OffsetInfo *) NULL);
1075 if (IsEventLogging() != MagickFalse)
1076 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1077 if ((offset->x < 0) || (offset->y < 0) ||
1078 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1079 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1080 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1081 image->filename);
1082 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
1083 return(MagickFalse);
1084 /*
1085 Copy image pixels.
1086 */
1087 status=MagickTrue;
1088 progress=0;
1089 source_view=AcquireVirtualCacheView(source_image,exception);
1090 image_view=AcquireAuthenticCacheView(image,exception);
1091#if defined(MAGICKCORE_OPENMP_SUPPORT)
1092 #pragma omp parallel for schedule(static) shared(progress,status) \
1093 magick_number_threads(source_image,image,geometry->height,1)
1094#endif
1095 for (y=0; y < (ssize_t) geometry->height; y++)
1096 {
1097 const IndexPacket
1098 *magick_restrict source_indexes;
1099
1100 const PixelPacket
1101 *magick_restrict p;
1102
1103 IndexPacket
1104 *magick_restrict indexes;
1105
1107 *magick_restrict q;
1108
1109 ssize_t
1110 x;
1111
1112 if (status == MagickFalse)
1113 continue;
1114 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1115 geometry->width,1,exception);
1116 q=GetCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1117 geometry->width,1,exception);
1118 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
1119 {
1120 status=MagickFalse;
1121 continue;
1122 }
1123 source_indexes=GetCacheViewVirtualIndexQueue(source_view);
1124 indexes=GetCacheViewAuthenticIndexQueue(image_view);
1125 for (x=0; x < (ssize_t) geometry->width; x++)
1126 {
1127 *q=(*p);
1128 if (image->colorspace == CMYKColorspace)
1129 indexes[x]=source_indexes[x];
1130 p++;
1131 q++;
1132 }
1133 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
1134 status=MagickFalse;
1135 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1136 {
1137 MagickBooleanType
1138 proceed;
1139
1140#if defined(MAGICKCORE_OPENMP_SUPPORT)
1141 #pragma omp atomic
1142#endif
1143 progress++;
1144 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1145 if (proceed == MagickFalse)
1146 status=MagickFalse;
1147 }
1148 }
1149 image_view=DestroyCacheView(image_view);
1150 source_view=DestroyCacheView(source_view);
1151 return(status);
1152}
1153␌
1154/*
1155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1156% %
1157% %
1158% %
1159% D e s t r o y I m a g e %
1160% %
1161% %
1162% %
1163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1164%
1165% DestroyImage() dereferences an image, deallocating memory associated with
1166% the image if the reference count becomes zero.
1167%
1168% The format of the DestroyImage method is:
1169%
1170% Image *DestroyImage(Image *image)
1171%
1172% A description of each parameter follows:
1173%
1174% o image: the image.
1175%
1176*/
1177MagickExport Image *DestroyImage(Image *image)
1178{
1179 MagickBooleanType
1180 destroy;
1181
1182 /*
1183 Dereference image.
1184 */
1185 assert(image != (Image *) NULL);
1186 assert(image->signature == MagickCoreSignature);
1187 if (IsEventLogging() != MagickFalse)
1188 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1189 destroy=MagickFalse;
1190 LockSemaphoreInfo(image->semaphore);
1191 image->reference_count--;
1192 if (image->reference_count == 0)
1193 destroy=MagickTrue;
1194 UnlockSemaphoreInfo(image->semaphore);
1195 if (destroy == MagickFalse)
1196 return((Image *) NULL);
1197 /*
1198 Destroy image.
1199 */
1200 DestroyImagePixels(image);
1201 if (image->clip_mask != (Image *) NULL)
1202 image->clip_mask=DestroyImage(image->clip_mask);
1203 if (image->mask != (Image *) NULL)
1204 image->mask=DestroyImage(image->mask);
1205 if (image->montage != (char *) NULL)
1206 image->montage=DestroyString(image->montage);
1207 if (image->directory != (char *) NULL)
1208 image->directory=DestroyString(image->directory);
1209 if (image->colormap != (PixelPacket *) NULL)
1210 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1211 if (image->geometry != (char *) NULL)
1212 image->geometry=DestroyString(image->geometry);
1213 DestroyImageProfiles(image);
1214 DestroyImageProperties(image);
1215 DestroyImageArtifacts(image);
1216 if (image->ascii85 != (Ascii85Info*) NULL)
1217 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1218 DestroyBlob(image);
1219 (void) ClearExceptionInfo(&image->exception,MagickTrue);
1220 if (image->semaphore != (SemaphoreInfo *) NULL)
1221 DestroySemaphoreInfo(&image->semaphore);
1222 image->signature=(~MagickCoreSignature);
1223 image=(Image *) RelinquishMagickMemory(image);
1224 return(image);
1225}
1226␌
1227/*
1228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1229% %
1230% %
1231% %
1232% D e s t r o y I m a g e I n f o %
1233% %
1234% %
1235% %
1236%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1237%
1238% DestroyImageInfo() deallocates memory associated with an ImageInfo
1239% structure.
1240%
1241% The format of the DestroyImageInfo method is:
1242%
1243% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1244%
1245% A description of each parameter follows:
1246%
1247% o image_info: the image info.
1248%
1249*/
1250MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1251{
1252 assert(image_info != (ImageInfo *) NULL);
1253 assert(image_info->signature == MagickCoreSignature);
1254 if (IsEventLogging() != MagickFalse)
1255 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1256 image_info->filename);
1257 if (image_info->size != (char *) NULL)
1258 image_info->size=DestroyString(image_info->size);
1259 if (image_info->extract != (char *) NULL)
1260 image_info->extract=DestroyString(image_info->extract);
1261 if (image_info->scenes != (char *) NULL)
1262 image_info->scenes=DestroyString(image_info->scenes);
1263 if (image_info->page != (char *) NULL)
1264 image_info->page=DestroyString(image_info->page);
1265 if (image_info->sampling_factor != (char *) NULL)
1266 image_info->sampling_factor=DestroyString(
1267 image_info->sampling_factor);
1268 if (image_info->server_name != (char *) NULL)
1269 image_info->server_name=DestroyString(
1270 image_info->server_name);
1271 if (image_info->font != (char *) NULL)
1272 image_info->font=DestroyString(image_info->font);
1273 if (image_info->texture != (char *) NULL)
1274 image_info->texture=DestroyString(image_info->texture);
1275 if (image_info->density != (char *) NULL)
1276 image_info->density=DestroyString(image_info->density);
1277 if (image_info->view != (char *) NULL)
1278 image_info->view=DestroyString(image_info->view);
1279 if (image_info->authenticate != (char *) NULL)
1280 image_info->authenticate=DestroyString(
1281 image_info->authenticate);
1282 DestroyImageOptions(image_info);
1283 if (image_info->cache != (void *) NULL)
1284 image_info->cache=DestroyPixelCache(image_info->cache);
1285 if (image_info->profile != (StringInfo *) NULL)
1286 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1287 image_info->profile);
1288 image_info->signature=(~MagickCoreSignature);
1289 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1290 return(image_info);
1291}
1292␌
1293/*
1294%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1295% %
1296% %
1297% %
1298+ D i s a s s o c i a t e I m a g e S t r e a m %
1299% %
1300% %
1301% %
1302%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1303%
1304% DisassociateImageStream() disassociates the image stream. It checks if the
1305% blob of the specified image is referenced by other images. If the reference
1306% count is higher then 1 a new blob is assigned to the specified image.
1307%
1308% The format of the DisassociateImageStream method is:
1309%
1310% void DisassociateImageStream(const Image *image)
1311%
1312% A description of each parameter follows:
1313%
1314% o image: the image.
1315%
1316*/
1317MagickExport void DisassociateImageStream(Image *image)
1318{
1319 assert(image != (Image *) NULL);
1320 assert(image->signature == MagickCoreSignature);
1321 if (IsEventLogging() != MagickFalse)
1322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1323 DisassociateBlob(image);
1324}
1325␌
1326/*
1327%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328% %
1329% %
1330% %
1331% G e t I m a g e C l i p M a s k %
1332% %
1333% %
1334% %
1335%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1336%
1337% GetImageClipMask() returns the clip path associated with the image.
1338%
1339% The format of the GetImageClipMask method is:
1340%
1341% Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1342%
1343% A description of each parameter follows:
1344%
1345% o image: the image.
1346%
1347*/
1348MagickExport Image *GetImageClipMask(const Image *image,
1349 ExceptionInfo *exception)
1350{
1351 assert(image != (const Image *) NULL);
1352 assert(image->signature == MagickCoreSignature);
1353 if (IsEventLogging() != MagickFalse)
1354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1355 if (image->clip_mask == (Image *) NULL)
1356 return((Image *) NULL);
1357 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1358}
1359␌
1360/*
1361%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1362% %
1363% %
1364% %
1365% G e t I m a g e E x c e p t i o n %
1366% %
1367% %
1368% %
1369%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1370%
1371% GetImageException() traverses an image sequence and returns any
1372% error more severe than noted by the exception parameter.
1373%
1374% The format of the GetImageException method is:
1375%
1376% void GetImageException(Image *image,ExceptionInfo *exception)
1377%
1378% A description of each parameter follows:
1379%
1380% o image: Specifies a pointer to a list of one or more images.
1381%
1382% o exception: return the highest severity exception.
1383%
1384*/
1385MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1386{
1387 Image
1388 *next;
1389
1390 assert(image != (Image *) NULL);
1391 assert(image->signature == MagickCoreSignature);
1392 assert(exception != (ExceptionInfo *) NULL);
1393 assert(exception->signature == MagickCoreSignature);
1394 if (IsEventLogging() != MagickFalse)
1395 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1396 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1397 {
1398 if (next->exception.severity == UndefinedException)
1399 continue;
1400 if (next->exception.severity > exception->severity)
1401 InheritException(exception,&next->exception);
1402 next->exception.severity=UndefinedException;
1403 }
1404}
1405␌
1406/*
1407%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1408% %
1409% %
1410% %
1411% G e t I m a g e I n f o %
1412% %
1413% %
1414% %
1415%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1416%
1417% GetImageInfo() initializes image_info to default values.
1418%
1419% The format of the GetImageInfo method is:
1420%
1421% void GetImageInfo(ImageInfo *image_info)
1422%
1423% A description of each parameter follows:
1424%
1425% o image_info: the image info.
1426%
1427*/
1428MagickExport void GetImageInfo(ImageInfo *image_info)
1429{
1430 char
1431 *synchronize;
1432
1433 /*
1434 File and image dimension members.
1435 */
1436 assert(image_info != (ImageInfo *) NULL);
1437 if (IsEventLogging() != MagickFalse)
1438 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1439 (void) memset(image_info,0,sizeof(*image_info));
1440 image_info->adjoin=MagickTrue;
1441 image_info->interlace=NoInterlace;
1442 image_info->channel=DefaultChannels;
1443 image_info->quality=UndefinedCompressionQuality;
1444 image_info->antialias=MagickTrue;
1445 image_info->dither=MagickTrue;
1446 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1447 if (synchronize != (const char *) NULL)
1448 {
1449 image_info->synchronize=IsStringTrue(synchronize);
1450 synchronize=DestroyString(synchronize);
1451 }
1452 GetPixelPacketRGBA(BackgroundColorRGBA,&image_info->background_color);
1453 GetPixelPacketRGBA(BorderColorRGBA,&image_info->border_color);
1454 GetPixelPacketRGBA(MatteColorRGBA,&image_info->matte_color);
1455 GetPixelPacketRGBA(TransparentColorRGBA,&image_info->transparent_color);
1456 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1457 MagickFalse;
1458 image_info->signature=MagickCoreSignature;
1459}
1460␌
1461/*
1462%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1463% %
1464% %
1465% %
1466% G e t I m a g e I n f o F i l e %
1467% %
1468% %
1469% %
1470%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1471%
1472% GetImageInfoFile() returns the image info file member.
1473%
1474% The format of the GetImageInfoFile method is:
1475%
1476% FILE *GetImageInfoFile(const ImageInfo *image_info)
1477%
1478% A description of each parameter follows:
1479%
1480% o image_info: the image info.
1481%
1482*/
1483MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1484{
1485 return(image_info->file);
1486}
1487␌
1488/*
1489%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1490% %
1491% %
1492% %
1493% G e t I m a g e M a s k %
1494% %
1495% %
1496% %
1497%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1498%
1499% GetImageMask() returns the mask associated with the image.
1500%
1501% The format of the GetImageMask method is:
1502%
1503% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1504%
1505% A description of each parameter follows:
1506%
1507% o image: the image.
1508%
1509*/
1510MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1511{
1512 assert(image != (const Image *) NULL);
1513 assert(image->signature == MagickCoreSignature);
1514 if (IsEventLogging() != MagickFalse)
1515 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1516 if (image->mask == (Image *) NULL)
1517 return((Image *) NULL);
1518 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1519}
1520␌
1521/*
1522%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1523% %
1524% %
1525% %
1526% G e t I m a g e C h a n n e l s %
1527% %
1528% %
1529% %
1530%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1531%
1532% GetImageChannels() returns the number of pixel channels associated with the
1533% specified image.
1534%
1535% The format of the GetChannels method is:
1536%
1537% size_t GetImageChannels(Image *image)
1538%
1539% A description of each parameter follows:
1540%
1541% o image: the image.
1542%
1543*/
1544MagickExport size_t GetImageChannels(Image *image)
1545{
1546 assert(image != (Image *) NULL);
1547 assert(image->signature == MagickCoreSignature);
1548 if (IsEventLogging() != MagickFalse)
1549 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1550 return(image->channels);
1551}
1552␌
1553/*
1554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1555% %
1556% %
1557% %
1558+ G e t I m a g e R e f e r e n c e C o u n t %
1559% %
1560% %
1561% %
1562%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1563%
1564% GetImageReferenceCount() returns the image reference count.
1565%
1566% The format of the GetReferenceCount method is:
1567%
1568% ssize_t GetImageReferenceCount(Image *image)
1569%
1570% A description of each parameter follows:
1571%
1572% o image: the image.
1573%
1574*/
1575MagickExport ssize_t GetImageReferenceCount(Image *image)
1576{
1577 ssize_t
1578 reference_count;
1579
1580 assert(image != (Image *) NULL);
1581 assert(image->signature == MagickCoreSignature);
1582 if (IsEventLogging() != MagickFalse)
1583 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1584 LockSemaphoreInfo(image->semaphore);
1585 reference_count=image->reference_count;
1586 UnlockSemaphoreInfo(image->semaphore);
1587 return(reference_count);
1588}
1589␌
1590/*
1591%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592% %
1593% %
1594% %
1595% G e t I m a g e V i r t u a l P i x e l M e t h o d %
1596% %
1597% %
1598% %
1599%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1600%
1601% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1602% image. A virtual pixel is any pixel access that is outside the boundaries
1603% of the image cache.
1604%
1605% The format of the GetImageVirtualPixelMethod() method is:
1606%
1607% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1608%
1609% A description of each parameter follows:
1610%
1611% o image: the image.
1612%
1613*/
1614MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1615{
1616 assert(image != (Image *) NULL);
1617 assert(image->signature == MagickCoreSignature);
1618 if (IsEventLogging() != MagickFalse)
1619 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1620 return(GetPixelCacheVirtualMethod(image));
1621}
1622␌
1623/*
1624%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1625% %
1626% %
1627% %
1628% I n t e r p r e t I m a g e F i l e n a m e %
1629% %
1630% %
1631% %
1632%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1633%
1634% InterpretImageFilename() interprets embedded characters in an image filename.
1635% The filename length is returned.
1636%
1637% The format of the InterpretImageFilename method is:
1638%
1639% size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1640% const char *format,int value,char *filename)
1641%
1642% A description of each parameter follows.
1643%
1644% o image_info: the image info..
1645%
1646% o image: the image.
1647%
1648% o format: A filename describing the format to use to write the numeric
1649% argument. Only the first numeric format identifier is replaced.
1650%
1651% o value: Numeric value to substitute into format filename.
1652%
1653% o filename: return the formatted filename in this character buffer.
1654%
1655*/
1656MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1657 Image *image,const char *format,int value,char *filename)
1658{
1659 char
1660 *q;
1661
1662 const char
1663 *p;
1664
1665 int
1666 c;
1667
1668 MagickBooleanType
1669 canonical;
1670
1671 ssize_t
1672 offset;
1673
1674 canonical=MagickFalse;
1675 offset=0;
1676 (void) CopyMagickString(filename,format,MaxTextExtent);
1677 if (IsStringTrue(GetImageOption(image_info,"filename:literal")) != MagickFalse)
1678 return(strlen(filename));
1679 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1680 {
1681 q=(char *) p+1;
1682 if (*q == '%')
1683 {
1684 p++;
1685 continue;
1686 }
1687 switch (*q)
1688 {
1689 case 'd':
1690 case 'o':
1691 case 'x':
1692 {
1693 ssize_t
1694 count;
1695
1696 q++;
1697 c=(*q);
1698 *q='\0';
1699 count=FormatLocaleString(filename+(p-format-offset),(size_t)
1700 (MaxTextExtent-(p-format-offset)),p,value);
1701 if ((count <= 0) || (count > (MagickPathExtent-(p-format-offset))))
1702 return(0);
1703 offset+=(ssize_t) ((q-p)-count);
1704 *q=c;
1705 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1706 canonical=MagickTrue;
1707 if (*(q-1) != '%')
1708 break;
1709 p++;
1710 break;
1711 }
1712 case '[':
1713 {
1714 char
1715 pattern[MaxTextExtent];
1716
1717 const char
1718 *value;
1719
1720 char
1721 *r;
1722
1723 ssize_t
1724 i;
1725
1726 ssize_t
1727 depth;
1728
1729 /*
1730 Image option.
1731 */
1732 if (strchr(p,']') == (char *) NULL)
1733 break;
1734 depth=1;
1735 r=q+1;
1736 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1737 {
1738 if (*r == '[')
1739 depth++;
1740 if (*r == ']')
1741 depth--;
1742 if (depth <= 0)
1743 break;
1744 pattern[i]=(*r++);
1745 }
1746 pattern[i]='\0';
1747 if (LocaleNCompare(pattern,"filename:",9) != 0)
1748 break;
1749 value=(const char *) NULL;
1750 if (image != (Image *) NULL)
1751 value=GetImageProperty(image,pattern);
1752 if ((value == (const char *) NULL) &&
1753 (image != (Image *) NULL))
1754 value=GetImageArtifact(image,pattern);
1755 if ((value == (const char *) NULL) &&
1756 (image_info != (ImageInfo *) NULL))
1757 value=GetImageOption(image_info,pattern);
1758 if (value == (const char *) NULL)
1759 break;
1760 q--;
1761 c=(*q);
1762 *q='\0';
1763 (void) CopyMagickString(filename+(p-format-offset),value,(size_t)
1764 (MaxTextExtent-(p-format-offset)));
1765 offset+=(ssize_t) strlen(pattern)-(ssize_t) strlen(value)+3;
1766 *q=c;
1767 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1768 canonical=MagickTrue;
1769 if (*(q-1) != '%')
1770 break;
1771 p++;
1772 break;
1773 }
1774 default:
1775 break;
1776 }
1777 }
1778 if (canonical == MagickFalse)
1779 (void) CopyMagickString(filename,format,MaxTextExtent);
1780 else
1781 for (q=filename; *q != '\0'; q++)
1782 if ((*q == '%') && (*(q+1) == '%'))
1783 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1784 return(strlen(filename));
1785}
1786␌
1787/*
1788%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1789% %
1790% %
1791% %
1792% I s H i g h D y n a m i c R a n g e I m a g e %
1793% %
1794% %
1795% %
1796%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1797%
1798% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1799% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1800% 0..65535.
1801%
1802% The format of the IsHighDynamicRangeImage method is:
1803%
1804% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1805% ExceptionInfo *exception)
1806%
1807% A description of each parameter follows:
1808%
1809% o image: the image.
1810%
1811% o exception: return any errors or warnings in this structure.
1812%
1813*/
1814MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1815 ExceptionInfo *exception)
1816{
1817#if !defined(MAGICKCORE_HDRI_SUPPORT)
1818 (void) image;
1819 (void) exception;
1820 return(MagickFalse);
1821#else
1822 CacheView
1823 *image_view;
1824
1825 MagickBooleanType
1826 status;
1827
1829 zero;
1830
1831 ssize_t
1832 y;
1833
1834 assert(image != (Image *) NULL);
1835 assert(image->signature == MagickCoreSignature);
1836 if (IsEventLogging() != MagickFalse)
1837 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1838 status=MagickTrue;
1839 GetMagickPixelPacket(image,&zero);
1840 image_view=AcquireVirtualCacheView(image,exception);
1841#if defined(MAGICKCORE_OPENMP_SUPPORT)
1842 #pragma omp parallel for schedule(static) shared(status) \
1843 magick_number_threads(image,image,image->rows,1)
1844#endif
1845 for (y=0; y < (ssize_t) image->rows; y++)
1846 {
1848 pixel;
1849
1850 const IndexPacket
1851 *indexes;
1852
1853 const PixelPacket
1854 *p;
1855
1856 ssize_t
1857 x;
1858
1859 if (status == MagickFalse)
1860 continue;
1861 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1862 if (p == (const PixelPacket *) NULL)
1863 {
1864 status=MagickFalse;
1865 continue;
1866 }
1867 indexes=GetCacheViewVirtualIndexQueue(image_view);
1868 pixel=zero;
1869 for (x=0; x < (ssize_t) image->columns; x++)
1870 {
1871 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1872 if ((pixel.red < 0.0) || (pixel.red > (MagickRealType) QuantumRange) ||
1873 (pixel.red != (QuantumAny) pixel.red))
1874 break;
1875 if ((pixel.green < 0.0) ||
1876 (pixel.green > (MagickRealType) QuantumRange) ||
1877 (pixel.green != (QuantumAny) pixel.green))
1878 break;
1879 if ((pixel.blue < 0.0) || (pixel.blue > (MagickRealType) QuantumRange) ||
1880 (pixel.blue != (QuantumAny) pixel.blue))
1881 break;
1882 if (pixel.matte != MagickFalse)
1883 {
1884 if ((pixel.opacity < 0.0) || (pixel.opacity > (MagickRealType) QuantumRange) ||
1885 (pixel.opacity != (QuantumAny) pixel.opacity))
1886 break;
1887 }
1888 if (pixel.colorspace == CMYKColorspace)
1889 {
1890 if ((pixel.index < 0.0) ||
1891 (pixel.index > (MagickRealType) QuantumRange) ||
1892 (pixel.index != (QuantumAny) pixel.index))
1893 break;
1894 }
1895 p++;
1896 }
1897 if (x < (ssize_t) image->columns)
1898 status=MagickFalse;
1899 }
1900 image_view=DestroyCacheView(image_view);
1901 return(status != MagickFalse ? MagickFalse : MagickTrue);
1902#endif
1903}
1904␌
1905/*
1906%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1907% %
1908% %
1909% %
1910% I s I m a g e O b j e c t %
1911% %
1912% %
1913% %
1914%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1915%
1916% IsImageObject() returns MagickTrue if the image sequence contains a valid
1917% set of image objects.
1918%
1919% The format of the IsImageObject method is:
1920%
1921% MagickBooleanType IsImageObject(const Image *image)
1922%
1923% A description of each parameter follows:
1924%
1925% o image: the image.
1926%
1927*/
1928MagickExport MagickBooleanType IsImageObject(const Image *image)
1929{
1930 const Image
1931 *p;
1932
1933 assert(image != (Image *) NULL);
1934 if (IsEventLogging() != MagickFalse)
1935 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1936 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1937 if (p->signature != MagickCoreSignature)
1938 return(MagickFalse);
1939 return(MagickTrue);
1940}
1941␌
1942/*
1943%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1944% %
1945% %
1946% %
1947% I s T a i n t I m a g e %
1948% %
1949% %
1950% %
1951%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1952%
1953% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1954% since it was first constituted.
1955%
1956% The format of the IsTaintImage method is:
1957%
1958% MagickBooleanType IsTaintImage(const Image *image)
1959%
1960% A description of each parameter follows:
1961%
1962% o image: the image.
1963%
1964*/
1965MagickExport MagickBooleanType IsTaintImage(const Image *image)
1966{
1967 char
1968 magick[MaxTextExtent],
1969 filename[MaxTextExtent];
1970
1971 const Image
1972 *p;
1973
1974 assert(image != (Image *) NULL);
1975 assert(image->signature == MagickCoreSignature);
1976 if (IsEventLogging() != MagickFalse)
1977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1978 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1979 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1980 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1981 {
1982 if (p->taint != MagickFalse)
1983 return(MagickTrue);
1984 if (LocaleCompare(p->magick,magick) != 0)
1985 return(MagickTrue);
1986 if (LocaleCompare(p->filename,filename) != 0)
1987 return(MagickTrue);
1988 }
1989 return(MagickFalse);
1990}
1991␌
1992/*
1993%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1994% %
1995% %
1996% %
1997% M o d i f y I m a g e %
1998% %
1999% %
2000% %
2001%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2002%
2003% ModifyImage() ensures that there is only a single reference to the image
2004% to be modified, updating the provided image pointer to point to a clone of
2005% the original image if necessary.
2006%
2007% The format of the ModifyImage method is:
2008%
2009% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2010%
2011% A description of each parameter follows:
2012%
2013% o image: the image.
2014%
2015% o exception: return any errors or warnings in this structure.
2016%
2017*/
2018MagickExport MagickBooleanType ModifyImage(Image **image,
2019 ExceptionInfo *exception)
2020{
2021 Image
2022 *clone_image;
2023
2024 assert(image != (Image **) NULL);
2025 assert(*image != (Image *) NULL);
2026 assert((*image)->signature == MagickCoreSignature);
2027 if (IsEventLogging() != MagickFalse)
2028 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2029 if (GetImageReferenceCount(*image) <= 1)
2030 return(MagickTrue);
2031 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2032 LockSemaphoreInfo((*image)->semaphore);
2033 (*image)->reference_count--;
2034 UnlockSemaphoreInfo((*image)->semaphore);
2035 *image=clone_image;
2036 return(MagickTrue);
2037}
2038␌
2039/*
2040%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2041% %
2042% %
2043% %
2044% N e w M a g i c k I m a g e %
2045% %
2046% %
2047% %
2048%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2049%
2050% NewMagickImage() creates a blank image canvas of the specified size and
2051% background color.
2052%
2053% The format of the NewMagickImage method is:
2054%
2055% Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2056% const size_t height,const MagickPixelPacket *background)
2057%
2058% A description of each parameter follows:
2059%
2060% o image: the image.
2061%
2062% o width: the image width.
2063%
2064% o height: the image height.
2065%
2066% o background: the image color.
2067%
2068*/
2069MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2070 const size_t width,const size_t height,const MagickPixelPacket *background)
2071{
2072 CacheView
2073 *image_view;
2074
2076 *exception;
2077
2078 Image
2079 *image;
2080
2081 ssize_t
2082 y;
2083
2084 MagickBooleanType
2085 status;
2086
2087 assert(image_info != (const ImageInfo *) NULL);
2088 assert(image_info->signature == MagickCoreSignature);
2089 assert(background != (const MagickPixelPacket *) NULL);
2090 if (IsEventLogging() != MagickFalse)
2091 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2092 image=AcquireImage(image_info);
2093 image->columns=width;
2094 image->rows=height;
2095 image->colorspace=background->colorspace;
2096 image->matte=background->matte;
2097 image->fuzz=background->fuzz;
2098 image->depth=background->depth;
2099 status=MagickTrue;
2100 exception=(&image->exception);
2101 image_view=AcquireAuthenticCacheView(image,exception);
2102#if defined(MAGICKCORE_OPENMP_SUPPORT)
2103 #pragma omp parallel for schedule(static) shared(status) \
2104 magick_number_threads(image,image,image->rows,1)
2105#endif
2106 for (y=0; y < (ssize_t) image->rows; y++)
2107 {
2108 IndexPacket
2109 *magick_restrict indexes;
2110
2112 *magick_restrict q;
2113
2114 ssize_t
2115 x;
2116
2117 if (status == MagickFalse)
2118 continue;
2119 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2120 if (q == (PixelPacket *) NULL)
2121 {
2122 status=MagickFalse;
2123 continue;
2124 }
2125 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2126 for (x=0; x < (ssize_t) image->columns; x++)
2127 {
2128 SetPixelPacket(image,background,q,indexes+x);
2129 q++;
2130 }
2131 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2132 status=MagickFalse;
2133 }
2134 image_view=DestroyCacheView(image_view);
2135 if (status == MagickFalse)
2136 image=DestroyImage(image);
2137 return(image);
2138}
2139␌
2140/*
2141%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2142% %
2143% %
2144% %
2145% R e f e r e n c e I m a g e %
2146% %
2147% %
2148% %
2149%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2150%
2151% ReferenceImage() increments the reference count associated with an image
2152% returning a pointer to the image.
2153%
2154% The format of the ReferenceImage method is:
2155%
2156% Image *ReferenceImage(Image *image)
2157%
2158% A description of each parameter follows:
2159%
2160% o image: the image.
2161%
2162*/
2163MagickExport Image *ReferenceImage(Image *image)
2164{
2165 assert(image != (Image *) NULL);
2166 assert(image->signature == MagickCoreSignature);
2167 if (IsEventLogging() != MagickFalse)
2168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2169 LockSemaphoreInfo(image->semaphore);
2170 image->reference_count++;
2171 UnlockSemaphoreInfo(image->semaphore);
2172 return(image);
2173}
2174␌
2175/*
2176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2177% %
2178% %
2179% %
2180% R e s e t I m a g e P a g e %
2181% %
2182% %
2183% %
2184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2185%
2186% ResetImagePage() resets the image page canvas and position.
2187%
2188% The format of the ResetImagePage method is:
2189%
2190% MagickBooleanType ResetImagePage(Image *image,const char *page)
2191%
2192% A description of each parameter follows:
2193%
2194% o image: the image.
2195%
2196% o page: the relative page specification.
2197%
2198*/
2199MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2200{
2201 MagickStatusType
2202 flags;
2203
2205 geometry;
2206
2207 assert(image != (Image *) NULL);
2208 assert(image->signature == MagickCoreSignature);
2209 if (IsEventLogging() != MagickFalse)
2210 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2211 flags=ParseAbsoluteGeometry(page,&geometry);
2212 if ((flags & WidthValue) != 0)
2213 {
2214 if ((flags & HeightValue) == 0)
2215 geometry.height=geometry.width;
2216 image->page.width=geometry.width;
2217 image->page.height=geometry.height;
2218 }
2219 if ((flags & AspectValue) != 0)
2220 {
2221 if ((flags & XValue) != 0)
2222 image->page.x+=geometry.x;
2223 if ((flags & YValue) != 0)
2224 image->page.y+=geometry.y;
2225 }
2226 else
2227 {
2228 if ((flags & XValue) != 0)
2229 {
2230 image->page.x=geometry.x;
2231 if ((image->page.width == 0) && (geometry.x > 0))
2232 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2233 }
2234 if ((flags & YValue) != 0)
2235 {
2236 image->page.y=geometry.y;
2237 if ((image->page.height == 0) && (geometry.y > 0))
2238 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2239 }
2240 }
2241 return(MagickTrue);
2242}
2243␌
2244/*
2245%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2246% %
2247% %
2248% %
2249% R e s e t I m a g e P i x e l s %
2250% %
2251% %
2252% %
2253%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2254%
2255% ResetImagePixels() reset the image pixels, that is, all the pixel components
2256% are zeroed.
2257%
2258% The format of the SetImage method is:
2259%
2260% MagickBooleanType ResetImagePixels(Image *image,
2261% ExceptionInfo *exception)
2262%
2263% A description of each parameter follows:
2264%
2265% o image: the image.
2266%
2267% o exception: return any errors or warnings in this structure.
2268%
2269*/
2270MagickExport MagickBooleanType ResetImagePixels(Image *image,
2271 ExceptionInfo *exception)
2272{
2273 CacheView
2274 *image_view;
2275
2276 const void
2277 *pixels;
2278
2279 MagickBooleanType
2280 status;
2281
2282 MagickSizeType
2283 length;
2284
2285 ssize_t
2286 y;
2287
2288 assert(image != (Image *) NULL);
2289 assert(image->signature == MagickCoreSignature);
2290 if (IsEventLogging() != MagickFalse)
2291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2292 pixels=AcquirePixelCachePixels(image,&length,exception);
2293 if (pixels != (void *) NULL)
2294 {
2295 /*
2296 Reset in-core image pixels.
2297 */
2298 (void) memset((void *) pixels,0,(size_t) length);
2299 return(MagickTrue);
2300 }
2301 /*
2302 Reset image pixels.
2303 */
2304 status=MagickTrue;
2305 image_view=AcquireAuthenticCacheView(image,exception);
2306#if defined(MAGICKCORE_OPENMP_SUPPORT)
2307 #pragma omp parallel for schedule(static) shared(status) \
2308 magick_number_threads(image,image,image->rows,1)
2309#endif
2310 for (y=0; y < (ssize_t) image->rows; y++)
2311 {
2312 IndexPacket
2313 *magick_restrict indexes;
2314
2316 *magick_restrict q;
2317
2318 ssize_t
2319 x;
2320
2321 if (status == MagickFalse)
2322 continue;
2323 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2324 if (q == (PixelPacket *) NULL)
2325 {
2326 status=MagickFalse;
2327 continue;
2328 }
2329 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2330 for (x=0; x < (ssize_t) image->columns; x++)
2331 {
2332 (void) memset(q,0,sizeof(PixelPacket));
2333 if ((image->storage_class == PseudoClass) ||
2334 (image->colorspace == CMYKColorspace))
2335 indexes[x]=0;
2336 q++;
2337 }
2338 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2339 status=MagickFalse;
2340 }
2341 image_view=DestroyCacheView(image_view);
2342 return(status);
2343}
2344␌
2345/*
2346%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2347% %
2348% %
2349% %
2350% S e t I m a g e B a c k g r o u n d C o l o r %
2351% %
2352% %
2353% %
2354%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2355%
2356% SetImageBackgroundColor() initializes the image pixels to the image
2357% background color. The background color is defined by the background_color
2358% member of the image structure.
2359%
2360% The format of the SetImage method is:
2361%
2362% MagickBooleanType SetImageBackgroundColor(Image *image)
2363%
2364% A description of each parameter follows:
2365%
2366% o image: the image.
2367%
2368*/
2369MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2370{
2371 CacheView
2372 *image_view;
2373
2375 *exception;
2376
2377 IndexPacket
2378 index;
2379
2380 MagickBooleanType
2381 status;
2382
2384 background;
2385
2387 pixel;
2388
2389 ssize_t
2390 y;
2391
2392 assert(image != (Image *) NULL);
2393 assert(image->signature == MagickCoreSignature);
2394 if (IsEventLogging() != MagickFalse)
2395 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2396 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2397 return(MagickFalse);
2398 if ((IsPixelGray(&image->background_color) == MagickFalse) &&
2399 (IsGrayColorspace(image->colorspace) != MagickFalse))
2400 (void) TransformImageColorspace(image,RGBColorspace);
2401 if ((image->background_color.opacity != OpaqueOpacity) &&
2402 (image->matte == MagickFalse))
2403 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
2404 GetMagickPixelPacket(image,&background);
2405 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2406 NULL,&background);
2407 if (image->colorspace == CMYKColorspace)
2408 ConvertRGBToCMYK(&background);
2409 index=0;
2410 pixel.opacity=OpaqueOpacity;
2411 SetPixelPacket(image,&background,&pixel,&index);
2412 /*
2413 Set image background color.
2414 */
2415 status=MagickTrue;
2416 exception=(&image->exception);
2417 image_view=AcquireAuthenticCacheView(image,exception);
2418 for (y=0; y < (ssize_t) image->rows; y++)
2419 {
2421 *magick_restrict q;
2422
2423 ssize_t
2424 x;
2425
2426 if (status == MagickFalse)
2427 continue;
2428 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2429 if (q == (PixelPacket *) NULL)
2430 {
2431 status=MagickFalse;
2432 continue;
2433 }
2434 for (x=0; x < (ssize_t) image->columns; x++)
2435 *q++=pixel;
2436 if (image->colorspace == CMYKColorspace)
2437 {
2438 IndexPacket
2439 *magick_restrict indexes;
2440
2441 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2442 for (x=0; x < (ssize_t) image->columns; x++)
2443 SetPixelIndex(indexes+x,index);
2444 }
2445 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2446 status=MagickFalse;
2447 }
2448 image_view=DestroyCacheView(image_view);
2449 return(status);
2450}
2451␌
2452/*
2453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2454% %
2455% %
2456% %
2457% S e t I m a g e C h a n n e l s %
2458% %
2459% %
2460% %
2461%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2462%
2463% SetImageChannels() sets the number of pixels channels associated with the
2464% image.
2465%
2466% The format of the SetImageChannels method is:
2467%
2468% MagickBooleanType SetImageChannels(Image *image,const size_t channels)
2469%
2470% A description of each parameter follows:
2471%
2472% o image: the image.
2473%
2474% o channels: The number of pixel channels.
2475%
2476*/
2477MagickExport MagickBooleanType SetImageChannels(Image *image,
2478 const size_t channels)
2479{
2480 image->channels=channels;
2481 return(MagickTrue);
2482}
2483␌
2484/*
2485%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2486% %
2487% %
2488% %
2489% S e t I m a g e C o l o r %
2490% %
2491% %
2492% %
2493%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2494%
2495% SetImageColor() set the entire image canvas to the specified color.
2496%
2497% The format of the SetImageColor method is:
2498%
2499% MagickBooleanType SetImageColor(Image *image,
2500% const MagickPixelPacket *color)
2501%
2502% A description of each parameter follows:
2503%
2504% o image: the image.
2505%
2506% o background: the image color.
2507%
2508*/
2509MagickExport MagickBooleanType SetImageColor(Image *image,
2510 const MagickPixelPacket *color)
2511{
2512 CacheView
2513 *image_view;
2514
2516 *exception;
2517
2518 MagickBooleanType
2519 status;
2520
2521 ssize_t
2522 y;
2523
2524 assert(image != (Image *) NULL);
2525 assert(image->signature == MagickCoreSignature);
2526 assert(color != (const MagickPixelPacket *) NULL);
2527 if (IsEventLogging() != MagickFalse)
2528 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2529 image->colorspace=color->colorspace;
2530 image->matte=color->matte;
2531 image->fuzz=color->fuzz;
2532 image->depth=color->depth;
2533 status=MagickTrue;
2534 exception=(&image->exception);
2535 image_view=AcquireAuthenticCacheView(image,exception);
2536#if defined(MAGICKCORE_OPENMP_SUPPORT)
2537 #pragma omp parallel for schedule(static) shared(status) \
2538 magick_number_threads(image,image,image->rows,1)
2539#endif
2540 for (y=0; y < (ssize_t) image->rows; y++)
2541 {
2542 IndexPacket
2543 *magick_restrict indexes;
2544
2546 *magick_restrict q;
2547
2548 ssize_t
2549 x;
2550
2551 if (status == MagickFalse)
2552 continue;
2553 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2554 if (q == (PixelPacket *) NULL)
2555 {
2556 status=MagickFalse;
2557 continue;
2558 }
2559 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2560 for (x=0; x < (ssize_t) image->columns; x++)
2561 {
2562 SetPixelPacket(image,color,q,
2563 indexes == (IndexPacket *) NULL ? NULL : indexes+x);
2564 q++;
2565 }
2566 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2567 status=MagickFalse;
2568 }
2569 image_view=DestroyCacheView(image_view);
2570 return(status);
2571}
2572␌
2573/*
2574%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2575% %
2576% %
2577% %
2578% S e t I m a g e S t o r a g e C l a s s %
2579% %
2580% %
2581% %
2582%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2583%
2584% SetImageStorageClass() sets the image class: DirectClass for true color
2585% images or PseudoClass for colormapped images.
2586%
2587% The format of the SetImageStorageClass method is:
2588%
2589% MagickBooleanType SetImageStorageClass(Image *image,
2590% const ClassType storage_class)
2591%
2592% A description of each parameter follows:
2593%
2594% o image: the image.
2595%
2596% o storage_class: The image class.
2597%
2598*/
2599MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2600 const ClassType storage_class)
2601{
2602 assert(image != (Image *) NULL);
2603 assert(image->signature == MagickCoreSignature);
2604 if (IsEventLogging() != MagickFalse)
2605 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2606 image->storage_class=storage_class;
2607 return(SyncImagePixelCache(image,&image->exception));
2608}
2609␌
2610/*
2611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2612% %
2613% %
2614% %
2615% S e t I m a g e C l i p M a s k %
2616% %
2617% %
2618% %
2619%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2620%
2621% SetImageClipMask() associates a clip path with the image. The clip path
2622% must be the same dimensions as the image. Set any pixel component of
2623% the clip path to TransparentOpacity to prevent that corresponding image
2624% pixel component from being updated when SyncAuthenticPixels() is applied.
2625%
2626% The format of the SetImageClipMask method is:
2627%
2628% MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2629%
2630% A description of each parameter follows:
2631%
2632% o image: the image.
2633%
2634% o clip_mask: the image clip path.
2635%
2636*/
2637MagickExport MagickBooleanType SetImageClipMask(Image *image,
2638 const Image *clip_mask)
2639{
2640 assert(image != (Image *) NULL);
2641 assert(image->signature == MagickCoreSignature);
2642 if (IsEventLogging() != MagickFalse)
2643 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2644 if (clip_mask != (const Image *) NULL)
2645 if ((clip_mask->columns != image->columns) ||
2646 (clip_mask->rows != image->rows))
2647 ThrowBinaryImageException(ImageError,"ImageSizeDiffers",image->filename);
2648 if (image->clip_mask != (Image *) NULL)
2649 image->clip_mask=DestroyImage(image->clip_mask);
2650 image->clip_mask=NewImageList();
2651 if (clip_mask == (Image *) NULL)
2652 return(MagickTrue);
2653 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2654 return(MagickFalse);
2655 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2656 if (image->clip_mask == (Image *) NULL)
2657 return(MagickFalse);
2658 return(MagickTrue);
2659}
2660␌
2661/*
2662%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2663% %
2664% %
2665% %
2666% S e t I m a g e E x t e n t %
2667% %
2668% %
2669% %
2670%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2671%
2672% SetImageExtent() sets the image size (i.e. columns & rows).
2673%
2674% The format of the SetImageExtent method is:
2675%
2676% MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2677% const size_t rows)
2678%
2679% A description of each parameter follows:
2680%
2681% o image: the image.
2682%
2683% o columns: The image width in pixels.
2684%
2685% o rows: The image height in pixels.
2686%
2687*/
2688MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2689 const size_t rows)
2690{
2691 if ((columns == 0) || (rows == 0))
2692 ThrowBinaryImageException(ImageError,"NegativeOrZeroImageSize",
2693 image->filename);
2694 image->columns=columns;
2695 image->rows=rows;
2696 if (image->depth == 0)
2697 {
2698 image->depth=8;
2699 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2700 ImageError,"ImageDepthNotSupported","`%s'",image->filename);
2701 }
2702 if (image->depth > (8*sizeof(MagickSizeType)))
2703 {
2704 image->depth=8*sizeof(MagickSizeType);
2705 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2706 ImageError,"ImageDepthNotSupported","`%s'",image->filename);
2707 }
2708 return(SyncImagePixelCache(image,&image->exception));
2709}
2710␌
2711/*
2712%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2713% %
2714% %
2715% %
2716+ S e t I m a g e I n f o %
2717% %
2718% %
2719% %
2720%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2721%
2722% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2723% It is set to a type of image format based on the prefix or suffix of the
2724% filename. For example, `ps:image' returns PS indicating a Postscript image.
2725% JPEG is returned for this filename: `image.jpg'. The filename prefix has
2726% precendence over the suffix. Use an optional index enclosed in brackets
2727% after a file name to specify a desired scene of a multi-resolution image
2728% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2729% indicates success.
2730%
2731% The format of the SetImageInfo method is:
2732%
2733% MagickBooleanType SetImageInfo(ImageInfo *image_info,
2734% const unsigned int frames,ExceptionInfo *exception)
2735%
2736% A description of each parameter follows:
2737%
2738% o image_info: the image info.
2739%
2740% o frames: the number of images you intend to write.
2741%
2742% o exception: return any errors or warnings in this structure.
2743%
2744*/
2745MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2746 const unsigned int frames,ExceptionInfo *exception)
2747{
2748 char
2749 extension[MaxTextExtent],
2750 filename[MaxTextExtent],
2751 magic[MaxTextExtent],
2752 *q,
2753 subimage[MaxTextExtent];
2754
2755 const MagicInfo
2756 *magic_info;
2757
2758 const MagickInfo
2759 *magick_info;
2760
2762 *sans_exception;
2763
2764 Image
2765 *image;
2766
2767 MagickBooleanType
2768 status;
2769
2770 const char
2771 *p;
2772
2773 ssize_t
2774 count;
2775
2776 unsigned char
2777 magick[2*MaxTextExtent];
2778
2779 /*
2780 Look for 'image.format' in filename.
2781 */
2782 assert(image_info != (ImageInfo *) NULL);
2783 assert(image_info->signature == MagickCoreSignature);
2784 if (IsEventLogging() != MagickFalse)
2785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2786 image_info->filename);
2787 *subimage='\0';
2788 GetPathComponent(image_info->filename,SubimagePath,subimage);
2789 if (*subimage != '\0')
2790 {
2791 /*
2792 Look for scene specification (e.g. img0001.pcd[4]).
2793 */
2794 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2795 {
2796 if (IsGeometry(subimage) != MagickFalse)
2797 (void) CloneString(&image_info->extract,subimage);
2798 }
2799 else
2800 {
2801 size_t
2802 first,
2803 last;
2804
2805 (void) CloneString(&image_info->scenes,subimage);
2806 image_info->scene=StringToUnsignedLong(image_info->scenes);
2807 image_info->number_scenes=image_info->scene;
2808 p=image_info->scenes;
2809 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2810 {
2811 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2812 p++;
2813 first=(size_t) strtol(p,&q,10);
2814 last=first;
2815 while (isspace((int) ((unsigned char) *q)) != 0)
2816 q++;
2817 if (*q == '-')
2818 last=(size_t) strtol(q+1,&q,10);
2819 if (first > last)
2820 Swap(first,last);
2821 if (first < image_info->scene)
2822 image_info->scene=first;
2823 if (last > image_info->number_scenes)
2824 image_info->number_scenes=last;
2825 p=q;
2826 }
2827 image_info->number_scenes-=image_info->scene-1;
2828 image_info->subimage=image_info->scene;
2829 image_info->subrange=image_info->number_scenes;
2830 }
2831 }
2832 *extension='\0';
2833 if (*image_info->magick == '\0')
2834 GetPathComponent(image_info->filename,ExtensionPath,extension);
2835 if (*extension != '\0')
2836 {
2837 char
2838 path[MaxTextExtent];
2839
2840 /*
2841 Base path sans any compression extension.
2842 */
2843 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2844 GetPathComponent(path,ExtensionPath,extension);
2845 }
2846 image_info->affirm=MagickFalse;
2847 sans_exception=AcquireExceptionInfo();
2848 if ((*extension != '\0') && (IsGlob(extension) == MagickFalse))
2849 {
2850 MagickFormatType
2851 format_type;
2852
2853 ssize_t
2854 i;
2855
2856 static const char
2857 *format_type_formats[] =
2858 {
2859 "AUTOTRACE",
2860 "BROWSE",
2861 "DCRAW",
2862 "EDIT",
2863 "LAUNCH",
2864 "MPEG:DECODE",
2865 "MPEG:ENCODE",
2866 "PRINT",
2867 "PS:ALPHA",
2868 "PS:CMYK",
2869 "PS:COLOR",
2870 "PS:GRAY",
2871 "PS:MONO",
2872 "SCAN",
2873 "SHOW",
2874 "WIN",
2875 (char *) NULL
2876 };
2877
2878 /*
2879 User specified image format.
2880 */
2881 (void) CopyMagickString(magic,extension,MaxTextExtent);
2882 LocaleUpper(magic);
2883 /*
2884 Look for explicit image formats.
2885 */
2886 format_type=UndefinedFormatType;
2887 i=0;
2888 while ((format_type == UndefinedFormatType) &&
2889 (format_type_formats[i] != (char *) NULL))
2890 {
2891 if ((*magic == *format_type_formats[i]) &&
2892 (LocaleCompare(magic,format_type_formats[i]) == 0))
2893 format_type=ExplicitFormatType;
2894 i++;
2895 }
2896 magick_info=GetMagickInfo(magic,sans_exception);
2897 if ((magick_info != (const MagickInfo *) NULL) &&
2898 (magick_info->format_type != UndefinedFormatType))
2899 format_type=magick_info->format_type;
2900 if (format_type == UndefinedFormatType)
2901 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2902 else
2903 if (format_type == ExplicitFormatType)
2904 {
2905 image_info->affirm=MagickTrue;
2906 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2907 }
2908 if (LocaleCompare(magic,"RGB") == 0)
2909 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2910 }
2911 /*
2912 Look for explicit 'format:image' in filename.
2913 */
2914 *magic='\0';
2915 GetPathComponent(image_info->filename,MagickPath,magic);
2916 if (*magic == '\0')
2917 {
2918 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
2919 magick_info=GetMagickInfo(magic,sans_exception);
2920 if ((magick_info != (const MagickInfo *) NULL) &&
2921 (magick_info->format_type == ExplicitFormatType))
2922 image_info->affirm=MagickTrue;
2923 if (frames == 0)
2924 GetPathComponent(image_info->filename,CanonicalPath,filename);
2925 else
2926 GetPathComponent(image_info->filename,SubcanonicalPath,filename);
2927 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2928 }
2929 else
2930 {
2931 const DelegateInfo
2932 *delegate_info;
2933
2934 /*
2935 User specified image format.
2936 */
2937 LocaleUpper(magic);
2938 magick_info=GetMagickInfo(magic,sans_exception);
2939 delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2940 if (delegate_info == (const DelegateInfo *) NULL)
2941 delegate_info=GetDelegateInfo("*",magic,sans_exception);
2942 if (((magick_info != (const MagickInfo *) NULL) ||
2943 (delegate_info != (const DelegateInfo *) NULL)) &&
2944 (IsMagickConflict(magic) == MagickFalse))
2945 {
2946 image_info->affirm=MagickTrue;
2947 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2948 GetPathComponent(image_info->filename,CanonicalPath,filename);
2949 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2950 }
2951 }
2952 sans_exception=DestroyExceptionInfo(sans_exception);
2953 if ((magick_info == (const MagickInfo *) NULL) ||
2954 (GetMagickEndianSupport(magick_info) == MagickFalse))
2955 image_info->endian=UndefinedEndian;
2956 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2957 {
2958 /*
2959 Test for multiple image support (e.g. image%02d.png).
2960 */
2961 (void) InterpretImageFilename(image_info,(Image *) NULL,
2962 image_info->filename,(int) image_info->scene,filename);
2963 if ((LocaleCompare(filename,image_info->filename) != 0) &&
2964 (strchr(filename,'%') == (char *) NULL))
2965 image_info->adjoin=MagickFalse;
2966 }
2967 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2968 {
2969 /*
2970 Some image formats do not support multiple frames per file.
2971 */
2972 magick_info=GetMagickInfo(magic,exception);
2973 if (magick_info != (const MagickInfo *) NULL)
2974 if (GetMagickAdjoin(magick_info) == MagickFalse)
2975 image_info->adjoin=MagickFalse;
2976 }
2977 if (image_info->affirm != MagickFalse)
2978 return(MagickTrue);
2979 if (frames == 0)
2980 {
2981 /*
2982 Determine the image format from the first few bytes of the file.
2983 */
2984 image=AcquireImage(image_info);
2985 (void) CopyMagickString(image->filename,image_info->filename,
2986 MaxTextExtent);
2987 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2988 if (status == MagickFalse)
2989 {
2990 image=DestroyImage(image);
2991 return(MagickFalse);
2992 }
2993 if ((IsBlobSeekable(image) == MagickFalse) ||
2994 (IsBlobExempt(image) != MagickFalse))
2995 {
2996 /*
2997 Copy image to a seekable temporary file.
2998 */
2999 *filename='\0';
3000 status=ImageToFile(image,filename,exception);
3001 (void) CloseBlob(image);
3002 if (status == MagickFalse)
3003 {
3004 (void) RelinquishUniqueFileResource(filename);
3005 image=DestroyImage(image);
3006 return(MagickFalse);
3007 }
3008 SetImageInfoFile(image_info,(FILE *) NULL);
3009 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3010 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3011 if (status == MagickFalse)
3012 {
3013 (void) RelinquishUniqueFileResource(filename);
3014 image=DestroyImage(image);
3015 return(MagickFalse);
3016 }
3017 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3018 image_info->temporary=MagickTrue;
3019 }
3020 (void) memset(magick,0,sizeof(magick));
3021 count=ReadBlob(image,2*MaxTextExtent,magick);
3022 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3023 (void) CloseBlob(image);
3024 image=DestroyImage(image);
3025 /*
3026 Check magic.xml configuration file.
3027 */
3028 sans_exception=AcquireExceptionInfo();
3029 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3030 if ((magic_info != (const MagicInfo *) NULL) &&
3031 (GetMagicName(magic_info) != (char *) NULL))
3032 {
3033 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3034 MaxTextExtent);
3035 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3036 if ((magick_info == (const MagickInfo *) NULL) ||
3037 (GetMagickEndianSupport(magick_info) == MagickFalse))
3038 image_info->endian=UndefinedEndian;
3039 sans_exception=DestroyExceptionInfo(sans_exception);
3040 return(MagickTrue);
3041 }
3042 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3043 if ((magick_info == (const MagickInfo *) NULL) ||
3044 (GetMagickEndianSupport(magick_info) == MagickFalse))
3045 image_info->endian=UndefinedEndian;
3046 sans_exception=DestroyExceptionInfo(sans_exception);
3047 }
3048 return(MagickTrue);
3049}
3050␌
3051/*
3052%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3053% %
3054% %
3055% %
3056% S e t I m a g e I n f o B l o b %
3057% %
3058% %
3059% %
3060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3061%
3062% SetImageInfoBlob() sets the image info blob member.
3063%
3064% The format of the SetImageInfoBlob method is:
3065%
3066% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3067% const size_t length)
3068%
3069% A description of each parameter follows:
3070%
3071% o image_info: the image info.
3072%
3073% o blob: the blob.
3074%
3075% o length: the blob length.
3076%
3077*/
3078MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3079 const size_t length)
3080{
3081 assert(image_info != (ImageInfo *) NULL);
3082 assert(image_info->signature == MagickCoreSignature);
3083 if (IsEventLogging() != MagickFalse)
3084 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3085 image_info->filename);
3086 image_info->blob=(void *) blob;
3087 image_info->length=length;
3088}
3089␌
3090/*
3091%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3092% %
3093% %
3094% %
3095% S e t I m a g e I n f o F i l e %
3096% %
3097% %
3098% %
3099%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3100%
3101% SetImageInfoFile() sets the image info file member.
3102%
3103% The format of the SetImageInfoFile method is:
3104%
3105% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3106%
3107% A description of each parameter follows:
3108%
3109% o image_info: the image info.
3110%
3111% o file: the file.
3112%
3113*/
3114MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3115{
3116 assert(image_info != (ImageInfo *) NULL);
3117 assert(image_info->signature == MagickCoreSignature);
3118 if (IsEventLogging() != MagickFalse)
3119 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3120 image_info->filename);
3121 image_info->file=file;
3122}
3123␌
3124/*
3125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3126% %
3127% %
3128% %
3129% S e t I m a g e M a s k %
3130% %
3131% %
3132% %
3133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3134%
3135% SetImageMask() associates a mask with the image. The mask must be the same
3136% dimensions as the image.
3137%
3138% The format of the SetImageMask method is:
3139%
3140% MagickBooleanType SetImageMask(Image *image,const Image *mask)
3141%
3142% A description of each parameter follows:
3143%
3144% o image: the image.
3145%
3146% o mask: the image mask.
3147%
3148*/
3149MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask)
3150{
3151 assert(image != (Image *) NULL);
3152 assert(image->signature == MagickCoreSignature);
3153 if (IsEventLogging() != MagickFalse)
3154 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3155 if (mask != (const Image *) NULL)
3156 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3157 ThrowBinaryImageException(ImageError,"ImageSizeDiffers",image->filename);
3158 if (image->mask != (Image *) NULL)
3159 image->mask=DestroyImage(image->mask);
3160 image->mask=NewImageList();
3161 if (mask == (Image *) NULL)
3162 return(MagickTrue);
3163 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3164 return(MagickFalse);
3165 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3166 if (image->mask == (Image *) NULL)
3167 return(MagickFalse);
3168 return(MagickTrue);
3169}
3170␌
3171/*
3172%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3173% %
3174% %
3175% %
3176% S e t I m a g e O p a c i t y %
3177% %
3178% %
3179% %
3180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3181%
3182% SetImageOpacity() sets the opacity levels of the image.
3183%
3184% The format of the SetImageOpacity method is:
3185%
3186% MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3187%
3188% A description of each parameter follows:
3189%
3190% o image: the image.
3191%
3192% o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3193% fully transparent.
3194%
3195*/
3196MagickExport MagickBooleanType SetImageOpacity(Image *image,
3197 const Quantum opacity)
3198{
3199 CacheView
3200 *image_view;
3201
3203 *exception;
3204
3205 MagickBooleanType
3206 status;
3207
3208 ssize_t
3209 y;
3210
3211 assert(image != (Image *) NULL);
3212 assert(image->signature == MagickCoreSignature);
3213 if (IsEventLogging() != MagickFalse)
3214 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3215 image->matte=MagickTrue;
3216 status=MagickTrue;
3217 exception=(&image->exception);
3218 image_view=AcquireAuthenticCacheView(image,exception);
3219#if defined(MAGICKCORE_OPENMP_SUPPORT)
3220 #pragma omp parallel for schedule(static) shared(status) \
3221 magick_number_threads(image,image,image->rows,1)
3222#endif
3223 for (y=0; y < (ssize_t) image->rows; y++)
3224 {
3226 *magick_restrict q;
3227
3228 ssize_t
3229 x;
3230
3231 if (status == MagickFalse)
3232 continue;
3233 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3234 if (q == (PixelPacket *) NULL)
3235 {
3236 status=MagickFalse;
3237 continue;
3238 }
3239 for (x=0; x < (ssize_t) image->columns; x++)
3240 {
3241 SetPixelOpacity(q,opacity);
3242 q++;
3243 }
3244 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3245 status=MagickFalse;
3246 }
3247 image_view=DestroyCacheView(image_view);
3248 return(status);
3249}
3250␌
3251/*
3252%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3253% %
3254% %
3255% %
3256% S e t I m a g e V i r t u a l P i x e l M e t h o d %
3257% %
3258% %
3259% %
3260%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3261%
3262% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3263% image and returns the previous setting. A virtual pixel is any pixel access
3264% that is outside the boundaries of the image cache.
3265%
3266% The format of the SetImageVirtualPixelMethod() method is:
3267%
3268% VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3269% const VirtualPixelMethod virtual_pixel_method)
3270%
3271% A description of each parameter follows:
3272%
3273% o image: the image.
3274%
3275% o virtual_pixel_method: choose the type of virtual pixel.
3276%
3277*/
3278MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3279 const VirtualPixelMethod virtual_pixel_method)
3280{
3281 assert(image != (const Image *) NULL);
3282 assert(image->signature == MagickCoreSignature);
3283 if (IsEventLogging() != MagickFalse)
3284 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3285 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3286}
3287␌
3288/*
3289%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3290% %
3291% %
3292% %
3293% S m u s h I m a g e s %
3294% %
3295% %
3296% %
3297%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3298%
3299% SmushImages() takes all images from the current image pointer to the end
3300% of the image list and smushes them to each other top-to-bottom if the
3301% stack parameter is true, otherwise left-to-right.
3302%
3303% The current gravity setting now effects how the image is justified in the
3304% final image.
3305%
3306% The format of the SmushImages method is:
3307%
3308% Image *SmushImages(const Image *images,const MagickBooleanType stack,
3309% ExceptionInfo *exception)
3310%
3311% A description of each parameter follows:
3312%
3313% o images: the image sequence.
3314%
3315% o stack: A value other than 0 stacks the images top-to-bottom.
3316%
3317% o offset: minimum distance in pixels between images.
3318%
3319% o exception: return any errors or warnings in this structure.
3320%
3321*/
3322
3323static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3324 const ssize_t offset,ExceptionInfo *exception)
3325{
3326 CacheView
3327 *left_view,
3328 *right_view;
3329
3330 const Image
3331 *left_image,
3332 *right_image;
3333
3335 left_geometry,
3336 right_geometry;
3337
3338 const PixelPacket
3339 *p;
3340
3341 ssize_t
3342 i,
3343 y;
3344
3345 size_t
3346 gap;
3347
3348 ssize_t
3349 x;
3350
3351 if (images->previous == (Image *) NULL)
3352 return(0);
3353 right_image=images;
3354 SetGeometry(smush_image,&right_geometry);
3355 GravityAdjustGeometry(right_image->columns,right_image->rows,
3356 right_image->gravity,&right_geometry);
3357 left_image=images->previous;
3358 SetGeometry(smush_image,&left_geometry);
3359 GravityAdjustGeometry(left_image->columns,left_image->rows,
3360 left_image->gravity,&left_geometry);
3361 gap=right_image->columns;
3362 left_view=AcquireVirtualCacheView(left_image,exception);
3363 right_view=AcquireVirtualCacheView(right_image,exception);
3364 for (y=0; y < (ssize_t) smush_image->rows; y++)
3365 {
3366 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3367 {
3368 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3369 if ((p == (const PixelPacket *) NULL) ||
3370 (GetPixelOpacity(p) != TransparentOpacity) ||
3371 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3372 break;
3373 }
3374 i=(ssize_t) left_image->columns-x-1;
3375 for (x=0; x < (ssize_t) right_image->columns; x++)
3376 {
3377 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3378 exception);
3379 if ((p == (const PixelPacket *) NULL) ||
3380 (GetPixelOpacity(p) != TransparentOpacity) ||
3381 ((x+i) >= (ssize_t) gap))
3382 break;
3383 }
3384 if ((x+i) < (ssize_t) gap)
3385 gap=(size_t) (x+i);
3386 }
3387 right_view=DestroyCacheView(right_view);
3388 left_view=DestroyCacheView(left_view);
3389 if (y < (ssize_t) smush_image->rows)
3390 return(offset);
3391 return((ssize_t) gap-offset);
3392}
3393
3394static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3395 const ssize_t offset,ExceptionInfo *exception)
3396{
3397 CacheView
3398 *bottom_view,
3399 *top_view;
3400
3401 const Image
3402 *bottom_image,
3403 *top_image;
3404
3406 bottom_geometry,
3407 top_geometry;
3408
3409 const PixelPacket
3410 *p;
3411
3412 ssize_t
3413 i,
3414 x;
3415
3416 size_t
3417 gap;
3418
3419 ssize_t
3420 y;
3421
3422 if (images->previous == (Image *) NULL)
3423 return(0);
3424 bottom_image=images;
3425 SetGeometry(smush_image,&bottom_geometry);
3426 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3427 bottom_image->gravity,&bottom_geometry);
3428 top_image=images->previous;
3429 SetGeometry(smush_image,&top_geometry);
3430 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3431 &top_geometry);
3432 gap=bottom_image->rows;
3433 top_view=AcquireVirtualCacheView(top_image,exception);
3434 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3435 for (x=0; x < (ssize_t) smush_image->columns; x++)
3436 {
3437 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3438 {
3439 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3440 if ((p == (const PixelPacket *) NULL) ||
3441 (GetPixelOpacity(p) != TransparentOpacity) ||
3442 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3443 break;
3444 }
3445 i=(ssize_t) top_image->rows-y-1;
3446 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3447 {
3448 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3449 exception);
3450 if ((p == (const PixelPacket *) NULL) ||
3451 (GetPixelOpacity(p) != TransparentOpacity) ||
3452 ((y+i) >= (ssize_t) gap))
3453 break;
3454 }
3455 if ((y+i) < (ssize_t) gap)
3456 gap=(size_t) (y+i);
3457 }
3458 bottom_view=DestroyCacheView(bottom_view);
3459 top_view=DestroyCacheView(top_view);
3460 if (x < (ssize_t) smush_image->columns)
3461 return(offset);
3462 return((ssize_t) gap-offset);
3463}
3464
3465MagickExport Image *SmushImages(const Image *images,
3466 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3467{
3468#define SmushImageTag "Smush/Image"
3469
3470 CacheView
3471 *smush_view;
3472
3473 const Image
3474 *image;
3475
3476 Image
3477 *smush_image;
3478
3479 MagickBooleanType
3480 matte,
3481 proceed,
3482 status;
3483
3484 MagickOffsetType
3485 n;
3486
3488 geometry;
3489
3490 const Image
3491 *next;
3492
3493 size_t
3494 height,
3495 number_images,
3496 width;
3497
3498 ssize_t
3499 x_offset,
3500 y_offset;
3501
3502 /*
3503 Compute maximum area of smushed area.
3504 */
3505 assert(images != (Image *) NULL);
3506 assert(images->signature == MagickCoreSignature);
3507 assert(exception != (ExceptionInfo *) NULL);
3508 assert(exception->signature == MagickCoreSignature);
3509 if (IsEventLogging() != MagickFalse)
3510 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3511 image=images;
3512 matte=image->matte;
3513 number_images=1;
3514 width=image->columns;
3515 height=image->rows;
3516 next=GetNextImageInList(image);
3517 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3518 {
3519 if (next->matte != MagickFalse)
3520 matte=MagickTrue;
3521 number_images++;
3522 if (stack != MagickFalse)
3523 {
3524 if (next->columns > width)
3525 width=next->columns;
3526 height+=next->rows;
3527 if (next->previous != (Image *) NULL)
3528 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3529 continue;
3530 }
3531 width+=next->columns;
3532 if (next->previous != (Image *) NULL)
3533 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3534 if (next->rows > height)
3535 height=next->rows;
3536 }
3537 /*
3538 Smush images.
3539 */
3540 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3541 if (smush_image == (Image *) NULL)
3542 return((Image *) NULL);
3543 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
3544 {
3545 InheritException(exception,&smush_image->exception);
3546 smush_image=DestroyImage(smush_image);
3547 return((Image *) NULL);
3548 }
3549 smush_image->matte=matte;
3550 (void) SetImageBackgroundColor(smush_image);
3551 status=MagickTrue;
3552 x_offset=0;
3553 y_offset=0;
3554 smush_view=AcquireVirtualCacheView(smush_image,exception);
3555 for (n=0; n < (MagickOffsetType) number_images; n++)
3556 {
3557 SetGeometry(smush_image,&geometry);
3558 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3559 if (stack != MagickFalse)
3560 {
3561 x_offset-=geometry.x;
3562 y_offset-=SmushYGap(smush_image,image,offset,exception);
3563 }
3564 else
3565 {
3566 x_offset-=SmushXGap(smush_image,image,offset,exception);
3567 y_offset-=geometry.y;
3568 }
3569 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
3570 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3571 if (proceed == MagickFalse)
3572 break;
3573 if (stack == MagickFalse)
3574 {
3575 x_offset+=(ssize_t) image->columns;
3576 y_offset=0;
3577 }
3578 else
3579 {
3580 x_offset=0;
3581 y_offset+=(ssize_t) image->rows;
3582 }
3583 image=GetNextImageInList(image);
3584 }
3585 if (stack == MagickFalse)
3586 smush_image->columns=(size_t) x_offset;
3587 else
3588 smush_image->rows=(size_t) y_offset;
3589 smush_view=DestroyCacheView(smush_view);
3590 if (status == MagickFalse)
3591 smush_image=DestroyImage(smush_image);
3592 return(smush_image);
3593}
3594␌
3595/*
3596%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3597% %
3598% %
3599% %
3600% S t r i p I m a g e %
3601% %
3602% %
3603% %
3604%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3605%
3606% StripImage() strips an image of all profiles and comments.
3607%
3608% The format of the StripImage method is:
3609%
3610% MagickBooleanType StripImage(Image *image)
3611%
3612% A description of each parameter follows:
3613%
3614% o image: the image.
3615%
3616*/
3617MagickExport MagickBooleanType StripImage(Image *image)
3618{
3619 MagickBooleanType
3620 status;
3621
3622 assert(image != (Image *) NULL);
3623 if (IsEventLogging() != MagickFalse)
3624 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3625 DestroyImageProfiles(image);
3626 (void) DeleteImageProperty(image,"comment");
3627 (void) DeleteImageProperty(image,"date:create");
3628 (void) DeleteImageProperty(image,"date:modify");
3629 status=SetImageArtifact(image,"png:exclude-chunk",
3630 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3631 return(status);
3632}
3633␌
3634/*
3635%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3636% %
3637% %
3638% %
3639+ S y n c I m a g e %
3640% %
3641% %
3642% %
3643%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3644%
3645% SyncImage() initializes the red, green, and blue intensities of each pixel
3646% as defined by the colormap index.
3647%
3648% The format of the SyncImage method is:
3649%
3650% MagickBooleanType SyncImage(Image *image)
3651%
3652% A description of each parameter follows:
3653%
3654% o image: the image.
3655%
3656*/
3657
3658static inline IndexPacket PushColormapIndex(Image *image,
3659 const size_t index,MagickBooleanType *range_exception)
3660{
3661 if (index < image->colors)
3662 return((IndexPacket) index);
3663 *range_exception=MagickTrue;
3664 return((IndexPacket) 0);
3665}
3666
3667MagickExport MagickBooleanType SyncImage(Image *image)
3668{
3669 CacheView
3670 *image_view;
3671
3673 *exception;
3674
3675 MagickBooleanType
3676 range_exception,
3677 status,
3678 taint;
3679
3680 ssize_t
3681 y;
3682
3683 assert(image != (Image *) NULL);
3684 assert(image->signature == MagickCoreSignature);
3685 if (IsEventLogging() != MagickFalse)
3686 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3687 if (image->ping != MagickFalse)
3688 return(MagickTrue);
3689 if (image->storage_class != PseudoClass)
3690 return(MagickFalse);
3691 assert(image->colormap != (PixelPacket *) NULL);
3692 range_exception=MagickFalse;
3693 status=MagickTrue;
3694 taint=image->taint;
3695 exception=(&image->exception);
3696 image_view=AcquireAuthenticCacheView(image,exception);
3697#if defined(MAGICKCORE_OPENMP_SUPPORT)
3698 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3699 magick_number_threads(image,image,image->rows,1)
3700#endif
3701 for (y=0; y < (ssize_t) image->rows; y++)
3702 {
3703 IndexPacket
3704 index;
3705
3706 IndexPacket
3707 *magick_restrict indexes;
3708
3710 *magick_restrict q;
3711
3712 ssize_t
3713 x;
3714
3715 if (status == MagickFalse)
3716 continue;
3717 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3718 if (q == (PixelPacket *) NULL)
3719 {
3720 status=MagickFalse;
3721 continue;
3722 }
3723 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3724 for (x=0; x < (ssize_t) image->columns; x++)
3725 {
3726 index=PushColormapIndex(image,(size_t) GetPixelIndex(indexes+x),
3727 &range_exception);
3728 if (image->matte == MagickFalse)
3729 SetPixelRgb(q,image->colormap+(ssize_t) index)
3730 else
3731 SetPixelRGBO(q,image->colormap+(ssize_t) index);
3732 q++;
3733 }
3734 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3735 status=MagickFalse;
3736 }
3737 image_view=DestroyCacheView(image_view);
3738 image->taint=taint;
3739 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3740 (void) ThrowMagickException(&image->exception,GetMagickModule(),
3741 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3742 return(status);
3743}
3744␌
3745/*
3746%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3747% %
3748% %
3749% %
3750% S y n c I m a g e S e t t i n g s %
3751% %
3752% %
3753% %
3754%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3755%
3756% SyncImageSettings() syncs image_info options into per-image attributes.
3757%
3758% The format of the SyncImageSettings method is:
3759%
3760% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3761% Image *image)
3762% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3763% Image *image)
3764%
3765% A description of each parameter follows:
3766%
3767% o image_info: the image info.
3768%
3769% o image: the image.
3770%
3771*/
3772
3773MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3774 Image *images)
3775{
3776 Image
3777 *image;
3778
3779 assert(image_info != (const ImageInfo *) NULL);
3780 assert(image_info->signature == MagickCoreSignature);
3781 assert(images != (Image *) NULL);
3782 assert(images->signature == MagickCoreSignature);
3783 if (IsEventLogging() != MagickFalse)
3784 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3785 image=images;
3786 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3787 (void) SyncImageSettings(image_info,image);
3788 (void) DeleteImageOption(image_info,"page");
3789 return(MagickTrue);
3790}
3791
3792MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3793 Image *image)
3794{
3795 char
3796 property[MaxTextExtent];
3797
3798 const char
3799 *option,
3800 *value;
3801
3803 geometry_info;
3804
3805 MagickStatusType
3806 flags;
3807
3808 ResolutionType
3809 units;
3810
3811 /*
3812 Sync image options.
3813 */
3814 assert(image_info != (const ImageInfo *) NULL);
3815 assert(image_info->signature == MagickCoreSignature);
3816 assert(image != (Image *) NULL);
3817 assert(image->signature == MagickCoreSignature);
3818 if (IsEventLogging() != MagickFalse)
3819 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3820 option=GetImageOption(image_info,"background");
3821 if (option != (const char *) NULL)
3822 (void) QueryColorDatabase(option,&image->background_color,
3823 &image->exception);
3824 option=GetImageOption(image_info,"bias");
3825 if (option != (const char *) NULL)
3826 image->bias=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3827 option=GetImageOption(image_info,"black-point-compensation");
3828 if (option != (const char *) NULL)
3829 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3830 MagickBooleanOptions,MagickFalse,option);
3831 option=GetImageOption(image_info,"blue-primary");
3832 if (option != (const char *) NULL)
3833 {
3834 flags=ParseGeometry(option,&geometry_info);
3835 if ((flags & RhoValue) != 0)
3836 image->chromaticity.blue_primary.x=geometry_info.rho;
3837 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3838 if ((flags & SigmaValue) != 0)
3839 image->chromaticity.blue_primary.y=geometry_info.sigma;
3840 }
3841 option=GetImageOption(image_info,"bordercolor");
3842 if (option != (const char *) NULL)
3843 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
3844 option=GetImageOption(image_info,"colors");
3845 if (option != (const char *) NULL)
3846 image->colors=StringToUnsignedLong(option);
3847 option=GetImageOption(image_info,"compose");
3848 if (option != (const char *) NULL)
3849 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3850 MagickFalse,option);
3851 option=GetImageOption(image_info,"compress");
3852 if (option != (const char *) NULL)
3853 image->compression=(CompressionType) ParseCommandOption(
3854 MagickCompressOptions,MagickFalse,option);
3855 option=GetImageOption(image_info,"debug");
3856 if (option != (const char *) NULL)
3857 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3858 MagickFalse,option);
3859 option=GetImageOption(image_info,"density");
3860 if (option != (const char *) NULL)
3861 {
3863 geometry_info;
3864
3865 /*
3866 Set image density.
3867 */
3868 flags=ParseGeometry(option,&geometry_info);
3869 if ((flags & RhoValue) != 0)
3870 image->x_resolution=geometry_info.rho;
3871 image->y_resolution=image->x_resolution;
3872 if ((flags & SigmaValue) != 0)
3873 image->y_resolution=geometry_info.sigma;
3874 }
3875 option=GetImageOption(image_info,"depth");
3876 if (option != (const char *) NULL)
3877 image->depth=StringToUnsignedLong(option);
3878 option=GetImageOption(image_info,"endian");
3879 if (option != (const char *) NULL)
3880 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3881 MagickFalse,option);
3882 option=GetImageOption(image_info,"filter");
3883 if (option != (const char *) NULL)
3884 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3885 MagickFalse,option);
3886 option=GetImageOption(image_info,"fuzz");
3887 if (option != (const char *) NULL)
3888 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3889 option=GetImageOption(image_info,"gravity");
3890 if (option != (const char *) NULL)
3891 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3892 MagickFalse,option);
3893 option=GetImageOption(image_info,"green-primary");
3894 if (option != (const char *) NULL)
3895 {
3896 flags=ParseGeometry(option,&geometry_info);
3897 if ((flags & RhoValue) != 0)
3898 image->chromaticity.green_primary.x=geometry_info.rho;
3899 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3900 if ((flags & SigmaValue) != 0)
3901 image->chromaticity.green_primary.y=geometry_info.sigma;
3902 }
3903 option=GetImageOption(image_info,"intensity");
3904 if (option != (const char *) NULL)
3905 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3906 MagickPixelIntensityOptions,MagickFalse,option);
3907 option=GetImageOption(image_info,"intent");
3908 if (option != (const char *) NULL)
3909 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3910 MagickIntentOptions,MagickFalse,option);
3911 option=GetImageOption(image_info,"interlace");
3912 if (option != (const char *) NULL)
3913 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3914 MagickFalse,option);
3915 option=GetImageOption(image_info,"interpolate");
3916 if (option != (const char *) NULL)
3917 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
3918 MagickInterpolateOptions,MagickFalse,option);
3919 option=GetImageOption(image_info,"loop");
3920 if (option != (const char *) NULL)
3921 image->iterations=StringToUnsignedLong(option);
3922 option=GetImageOption(image_info,"mattecolor");
3923 if (option != (const char *) NULL)
3924 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
3925 option=GetImageOption(image_info,"orient");
3926 if (option != (const char *) NULL)
3927 image->orientation=(OrientationType) ParseCommandOption(
3928 MagickOrientationOptions,MagickFalse,option);
3929 option=GetImageOption(image_info,"page");
3930 if (option != (const char *) NULL)
3931 {
3932 char
3933 *geometry;
3934
3935 geometry=GetPageGeometry(option);
3936 flags=ParseAbsoluteGeometry(geometry,&image->page);
3937 geometry=DestroyString(geometry);
3938 }
3939 option=GetImageOption(image_info,"quality");
3940 if (option != (const char *) NULL)
3941 image->quality=StringToUnsignedLong(option);
3942 option=GetImageOption(image_info,"red-primary");
3943 if (option != (const char *) NULL)
3944 {
3945 flags=ParseGeometry(option,&geometry_info);
3946 if ((flags & RhoValue) != 0)
3947 image->chromaticity.red_primary.x=geometry_info.rho;
3948 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3949 if ((flags & SigmaValue) != 0)
3950 image->chromaticity.red_primary.y=geometry_info.sigma;
3951 }
3952 if (image_info->quality != UndefinedCompressionQuality)
3953 image->quality=image_info->quality;
3954 option=GetImageOption(image_info,"scene");
3955 if (option != (const char *) NULL)
3956 image->scene=StringToUnsignedLong(option);
3957 option=GetImageOption(image_info,"taint");
3958 if (option != (const char *) NULL)
3959 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3960 MagickFalse,option);
3961 option=GetImageOption(image_info,"tile-offset");
3962 if (option != (const char *) NULL)
3963 {
3964 char
3965 *geometry;
3966
3967 geometry=GetPageGeometry(option);
3968 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3969 geometry=DestroyString(geometry);
3970 }
3971 option=GetImageOption(image_info,"transparent-color");
3972 if (option != (const char *) NULL)
3973 (void) QueryColorDatabase(option,&image->transparent_color,
3974 &image->exception);
3975 option=GetImageOption(image_info,"type");
3976 if (option != (const char *) NULL)
3977 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3978 option);
3979 option=GetImageOption(image_info,"units");
3980 units=image_info->units;
3981 if (option != (const char *) NULL)
3982 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
3983 MagickFalse,option);
3984 if (units != UndefinedResolution)
3985 {
3986 if (image->units != units)
3987 switch (image->units)
3988 {
3989 case PixelsPerInchResolution:
3990 {
3991 if (units == PixelsPerCentimeterResolution)
3992 {
3993 image->x_resolution/=2.54;
3994 image->y_resolution/=2.54;
3995 }
3996 break;
3997 }
3998 case PixelsPerCentimeterResolution:
3999 {
4000 if (units == PixelsPerInchResolution)
4001 {
4002 image->x_resolution=(double) ((size_t) (100.0*2.54*
4003 image->x_resolution+0.5))/100.0;
4004 image->y_resolution=(double) ((size_t) (100.0*2.54*
4005 image->y_resolution+0.5))/100.0;
4006 }
4007 break;
4008 }
4009 default:
4010 break;
4011 }
4012 image->units=units;
4013 option=GetImageOption(image_info,"density");
4014 if (option != (const char *) NULL)
4015 {
4016 flags=ParseGeometry(option,&geometry_info);
4017 if ((flags & RhoValue) != 0)
4018 image->x_resolution=geometry_info.rho;
4019 image->y_resolution=image->x_resolution;
4020 if ((flags & SigmaValue) != 0)
4021 image->y_resolution=geometry_info.sigma;
4022 }
4023 }
4024 option=GetImageOption(image_info,"white-point");
4025 if (option != (const char *) NULL)
4026 {
4027 flags=ParseGeometry(option,&geometry_info);
4028 if ((flags & RhoValue) != 0)
4029 image->chromaticity.white_point.x=geometry_info.rho;
4030 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4031 if ((flags & SigmaValue) != 0)
4032 image->chromaticity.white_point.y=geometry_info.sigma;
4033 }
4034 ResetImageOptionIterator(image_info);
4035 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4036 {
4037 value=GetImageOption(image_info,option);
4038 if (value != (const char *) NULL)
4039 {
4040 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4041 (void) SetImageArtifact(image,property,value);
4042 }
4043 option=GetNextImageOption(image_info);
4044 }
4045 return(MagickTrue);
4046}