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*/
1656
1657static inline MagickBooleanType IsValidFormatSpecifier(const char *start,
1658 const char *end)
1659{
1660 char
1661 specifier = end[-1];
1662
1663 size_t
1664 length = end-start;
1665
1666 /*
1667 Is this a valid format specifier?
1668 */
1669 if ((specifier != 'd') && (specifier != 'x') && (specifier != 'o'))
1670 return(MagickFalse);
1671 if ((length == 1) && (*start == specifier))
1672 return(MagickTrue);
1673 if (length >= 2)
1674 {
1675 size_t
1676 i = 0;
1677
1678 if (*start == '0')
1679 {
1680 if ((length >= 3) && (start[1] == '0'))
1681 return(MagickFalse);
1682 i=1;
1683 }
1684 for ( ; i < (length-1); i++)
1685 if (isdigit((int) ((unsigned char) start[i])) == 0)
1686 return(MagickFalse);
1687 return(MagickTrue);
1688 }
1689 return(MagickFalse);
1690}
1691
1692MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1693 Image *image,const char *format,int value,char *filename)
1694{
1695 char
1696 *p = filename,
1697 pattern[MagickPathExtent];
1698
1699 const char
1700 *cursor = format;
1701
1702 assert(format != (const char *) NULL);
1703 assert(filename != (char *) NULL);
1704 if (IsStringTrue(GetImageOption(image_info,"filename:literal")) != MagickFalse)
1705 {
1706 (void) CopyMagickString(filename,format,MagickPathExtent);
1707 return(strlen(filename));
1708 }
1709 while ((*cursor != '\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1710 {
1711 const char
1712 *specifier_start,
1713 *start;
1714
1715 if (*cursor != '%')
1716 {
1717 *p++=(*cursor++);
1718 continue;
1719 }
1720 start=cursor++; /* Skip '%' */
1721 if (*cursor == '%')
1722 {
1723 *p++='%';
1724 cursor++;
1725 continue;
1726 }
1727 specifier_start=cursor;
1728 while (isdigit((int) ((unsigned char) *cursor)) != 0)
1729 cursor++;
1730 if ((*cursor == 'd') || (*cursor == 'o') || (*cursor == 'x'))
1731 {
1732 const char
1733 *specifier_end = cursor+1;
1734
1735 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1736 {
1737 char
1738 format_specifier[MagickPathExtent];
1739
1740 size_t
1741 length = cursor-specifier_start,
1742 pattern_length;
1743
1744 ssize_t
1745 count;
1746
1747 (void) snprintf(format_specifier,sizeof(format_specifier),
1748 "%%%.*s%c",(int) length,specifier_start,*cursor);
1749 count=FormatLocaleString(pattern,sizeof(pattern),format_specifier,
1750 value);
1751 pattern_length=strlen(pattern);
1752 if ((count <= 0) || ((size_t) count != pattern_length))
1753 return(0);
1754 if ((p-filename+pattern_length) >= MagickPathExtent)
1755 return(0);
1756 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
1757 p+=pattern_length;
1758 cursor++;
1759 continue;
1760 }
1761 else
1762 {
1763 /*
1764 Invalid specifier — treat as literal.
1765 */
1766 cursor=start;
1767 *p++=(*cursor++);
1768 continue;
1769 }
1770 }
1771 if (*cursor == '[')
1772 {
1773 const char
1774 *end = strchr(cursor,']'),
1775 *option = (const char *) NULL;
1776
1777 size_t
1778 extent,
1779 option_length;
1780
1781 if (end == (const char *) NULL)
1782 continue;
1783 extent=(size_t) (end-cursor-1);
1784 if (extent >= sizeof(pattern))
1785 continue;
1786 (void) CopyMagickString(pattern,cursor+1,extent+1);
1787 pattern[extent]='\0';
1788 if (image != NULL)
1789 {
1790 option=GetImageProperty(image,pattern);
1791 if (option == (const char *) NULL)
1792 option=GetImageArtifact(image,pattern);
1793 }
1794 if ((option == (const char *) NULL) &&
1795 (image_info != (ImageInfo *) NULL))
1796 option=GetImageOption(image_info,pattern);
1797 if (option == (const char *) NULL)
1798 continue;
1799 option_length=strlen(option);
1800 if ((p-filename+option_length) >= MagickPathExtent)
1801 return(0);
1802 (void) CopyMagickString(p,option,MagickPathExtent-(p-filename));
1803 p+=option_length;
1804 cursor=end+1;
1805 continue;
1806 }
1807 /*
1808 Invalid or unsupported specifier — treat as literal.
1809 */
1810 cursor=start;
1811 if ((p-filename+1) >= MagickPathExtent)
1812 return(0);
1813 *p++=(*cursor++);
1814 }
1815 *p='\0';
1816 return(strlen(filename));
1817}
1818␌
1819/*
1820%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1821% %
1822% %
1823% %
1824% I s H i g h D y n a m i c R a n g e I m a g e %
1825% %
1826% %
1827% %
1828%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1829%
1830% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1831% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1832% 0..65535.
1833%
1834% The format of the IsHighDynamicRangeImage method is:
1835%
1836% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1837% ExceptionInfo *exception)
1838%
1839% A description of each parameter follows:
1840%
1841% o image: the image.
1842%
1843% o exception: return any errors or warnings in this structure.
1844%
1845*/
1846MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1847 ExceptionInfo *exception)
1848{
1849#if !defined(MAGICKCORE_HDRI_SUPPORT)
1850 (void) image;
1851 (void) exception;
1852 return(MagickFalse);
1853#else
1854 CacheView
1855 *image_view;
1856
1857 MagickBooleanType
1858 status;
1859
1861 zero;
1862
1863 ssize_t
1864 y;
1865
1866 assert(image != (Image *) NULL);
1867 assert(image->signature == MagickCoreSignature);
1868 if (IsEventLogging() != MagickFalse)
1869 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1870 status=MagickTrue;
1871 GetMagickPixelPacket(image,&zero);
1872 image_view=AcquireVirtualCacheView(image,exception);
1873#if defined(MAGICKCORE_OPENMP_SUPPORT)
1874 #pragma omp parallel for schedule(static) shared(status) \
1875 magick_number_threads(image,image,image->rows,1)
1876#endif
1877 for (y=0; y < (ssize_t) image->rows; y++)
1878 {
1880 pixel;
1881
1882 const IndexPacket
1883 *indexes;
1884
1885 const PixelPacket
1886 *p;
1887
1888 ssize_t
1889 x;
1890
1891 if (status == MagickFalse)
1892 continue;
1893 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1894 if (p == (const PixelPacket *) NULL)
1895 {
1896 status=MagickFalse;
1897 continue;
1898 }
1899 indexes=GetCacheViewVirtualIndexQueue(image_view);
1900 pixel=zero;
1901 for (x=0; x < (ssize_t) image->columns; x++)
1902 {
1903 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1904 if ((pixel.red < 0.0) || (pixel.red > (MagickRealType) QuantumRange) ||
1905 (pixel.red != (QuantumAny) pixel.red))
1906 break;
1907 if ((pixel.green < 0.0) ||
1908 (pixel.green > (MagickRealType) QuantumRange) ||
1909 (pixel.green != (QuantumAny) pixel.green))
1910 break;
1911 if ((pixel.blue < 0.0) || (pixel.blue > (MagickRealType) QuantumRange) ||
1912 (pixel.blue != (QuantumAny) pixel.blue))
1913 break;
1914 if (pixel.matte != MagickFalse)
1915 {
1916 if ((pixel.opacity < 0.0) || (pixel.opacity > (MagickRealType) QuantumRange) ||
1917 (pixel.opacity != (QuantumAny) pixel.opacity))
1918 break;
1919 }
1920 if (pixel.colorspace == CMYKColorspace)
1921 {
1922 if ((pixel.index < 0.0) ||
1923 (pixel.index > (MagickRealType) QuantumRange) ||
1924 (pixel.index != (QuantumAny) pixel.index))
1925 break;
1926 }
1927 p++;
1928 }
1929 if (x < (ssize_t) image->columns)
1930 status=MagickFalse;
1931 }
1932 image_view=DestroyCacheView(image_view);
1933 return(status != MagickFalse ? MagickFalse : MagickTrue);
1934#endif
1935}
1936␌
1937/*
1938%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1939% %
1940% %
1941% %
1942% I s I m a g e O b j e c t %
1943% %
1944% %
1945% %
1946%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1947%
1948% IsImageObject() returns MagickTrue if the image sequence contains a valid
1949% set of image objects.
1950%
1951% The format of the IsImageObject method is:
1952%
1953% MagickBooleanType IsImageObject(const Image *image)
1954%
1955% A description of each parameter follows:
1956%
1957% o image: the image.
1958%
1959*/
1960MagickExport MagickBooleanType IsImageObject(const Image *image)
1961{
1962 const Image
1963 *p;
1964
1965 assert(image != (Image *) NULL);
1966 if (IsEventLogging() != MagickFalse)
1967 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1968 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1969 if (p->signature != MagickCoreSignature)
1970 return(MagickFalse);
1971 return(MagickTrue);
1972}
1973␌
1974/*
1975%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1976% %
1977% %
1978% %
1979% I s T a i n t I m a g e %
1980% %
1981% %
1982% %
1983%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1984%
1985% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1986% since it was first constituted.
1987%
1988% The format of the IsTaintImage method is:
1989%
1990% MagickBooleanType IsTaintImage(const Image *image)
1991%
1992% A description of each parameter follows:
1993%
1994% o image: the image.
1995%
1996*/
1997MagickExport MagickBooleanType IsTaintImage(const Image *image)
1998{
1999 char
2000 magick[MaxTextExtent],
2001 filename[MaxTextExtent];
2002
2003 const Image
2004 *p;
2005
2006 assert(image != (Image *) NULL);
2007 assert(image->signature == MagickCoreSignature);
2008 if (IsEventLogging() != MagickFalse)
2009 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2010 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2011 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2012 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2013 {
2014 if (p->taint != MagickFalse)
2015 return(MagickTrue);
2016 if (LocaleCompare(p->magick,magick) != 0)
2017 return(MagickTrue);
2018 if (LocaleCompare(p->filename,filename) != 0)
2019 return(MagickTrue);
2020 }
2021 return(MagickFalse);
2022}
2023␌
2024/*
2025%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2026% %
2027% %
2028% %
2029% M o d i f y I m a g e %
2030% %
2031% %
2032% %
2033%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2034%
2035% ModifyImage() ensures that there is only a single reference to the image
2036% to be modified, updating the provided image pointer to point to a clone of
2037% the original image if necessary.
2038%
2039% The format of the ModifyImage method is:
2040%
2041% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2042%
2043% A description of each parameter follows:
2044%
2045% o image: the image.
2046%
2047% o exception: return any errors or warnings in this structure.
2048%
2049*/
2050MagickExport MagickBooleanType ModifyImage(Image **image,
2051 ExceptionInfo *exception)
2052{
2053 Image
2054 *clone_image;
2055
2056 assert(image != (Image **) NULL);
2057 assert(*image != (Image *) NULL);
2058 assert((*image)->signature == MagickCoreSignature);
2059 if (IsEventLogging() != MagickFalse)
2060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2061 if (GetImageReferenceCount(*image) <= 1)
2062 return(MagickTrue);
2063 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2064 LockSemaphoreInfo((*image)->semaphore);
2065 (*image)->reference_count--;
2066 UnlockSemaphoreInfo((*image)->semaphore);
2067 *image=clone_image;
2068 return(MagickTrue);
2069}
2070␌
2071/*
2072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2073% %
2074% %
2075% %
2076% N e w M a g i c k I m a g e %
2077% %
2078% %
2079% %
2080%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2081%
2082% NewMagickImage() creates a blank image canvas of the specified size and
2083% background color.
2084%
2085% The format of the NewMagickImage method is:
2086%
2087% Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2088% const size_t height,const MagickPixelPacket *background)
2089%
2090% A description of each parameter follows:
2091%
2092% o image: the image.
2093%
2094% o width: the image width.
2095%
2096% o height: the image height.
2097%
2098% o background: the image color.
2099%
2100*/
2101MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2102 const size_t width,const size_t height,const MagickPixelPacket *background)
2103{
2104 CacheView
2105 *image_view;
2106
2108 *exception;
2109
2110 Image
2111 *image;
2112
2113 ssize_t
2114 y;
2115
2116 MagickBooleanType
2117 status;
2118
2119 assert(image_info != (const ImageInfo *) NULL);
2120 assert(image_info->signature == MagickCoreSignature);
2121 assert(background != (const MagickPixelPacket *) NULL);
2122 if (IsEventLogging() != MagickFalse)
2123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2124 image=AcquireImage(image_info);
2125 image->columns=width;
2126 image->rows=height;
2127 image->colorspace=background->colorspace;
2128 image->matte=background->matte;
2129 image->fuzz=background->fuzz;
2130 image->depth=background->depth;
2131 status=MagickTrue;
2132 exception=(&image->exception);
2133 image_view=AcquireAuthenticCacheView(image,exception);
2134#if defined(MAGICKCORE_OPENMP_SUPPORT)
2135 #pragma omp parallel for schedule(static) shared(status) \
2136 magick_number_threads(image,image,image->rows,1)
2137#endif
2138 for (y=0; y < (ssize_t) image->rows; y++)
2139 {
2140 IndexPacket
2141 *magick_restrict indexes;
2142
2144 *magick_restrict q;
2145
2146 ssize_t
2147 x;
2148
2149 if (status == MagickFalse)
2150 continue;
2151 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2152 if (q == (PixelPacket *) NULL)
2153 {
2154 status=MagickFalse;
2155 continue;
2156 }
2157 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2158 for (x=0; x < (ssize_t) image->columns; x++)
2159 {
2160 SetPixelPacket(image,background,q,indexes+x);
2161 q++;
2162 }
2163 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2164 status=MagickFalse;
2165 }
2166 image_view=DestroyCacheView(image_view);
2167 if (status == MagickFalse)
2168 image=DestroyImage(image);
2169 return(image);
2170}
2171␌
2172/*
2173%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2174% %
2175% %
2176% %
2177% R e f e r e n c e I m a g e %
2178% %
2179% %
2180% %
2181%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2182%
2183% ReferenceImage() increments the reference count associated with an image
2184% returning a pointer to the image.
2185%
2186% The format of the ReferenceImage method is:
2187%
2188% Image *ReferenceImage(Image *image)
2189%
2190% A description of each parameter follows:
2191%
2192% o image: the image.
2193%
2194*/
2195MagickExport Image *ReferenceImage(Image *image)
2196{
2197 assert(image != (Image *) NULL);
2198 assert(image->signature == MagickCoreSignature);
2199 if (IsEventLogging() != MagickFalse)
2200 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2201 LockSemaphoreInfo(image->semaphore);
2202 image->reference_count++;
2203 UnlockSemaphoreInfo(image->semaphore);
2204 return(image);
2205}
2206␌
2207/*
2208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2209% %
2210% %
2211% %
2212% R e s e t I m a g e P a g e %
2213% %
2214% %
2215% %
2216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2217%
2218% ResetImagePage() resets the image page canvas and position.
2219%
2220% The format of the ResetImagePage method is:
2221%
2222% MagickBooleanType ResetImagePage(Image *image,const char *page)
2223%
2224% A description of each parameter follows:
2225%
2226% o image: the image.
2227%
2228% o page: the relative page specification.
2229%
2230*/
2231MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2232{
2233 MagickStatusType
2234 flags;
2235
2237 geometry;
2238
2239 assert(image != (Image *) NULL);
2240 assert(image->signature == MagickCoreSignature);
2241 if (IsEventLogging() != MagickFalse)
2242 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2243 flags=ParseAbsoluteGeometry(page,&geometry);
2244 if ((flags & WidthValue) != 0)
2245 {
2246 if ((flags & HeightValue) == 0)
2247 geometry.height=geometry.width;
2248 image->page.width=geometry.width;
2249 image->page.height=geometry.height;
2250 }
2251 if ((flags & AspectValue) != 0)
2252 {
2253 if ((flags & XValue) != 0)
2254 image->page.x+=geometry.x;
2255 if ((flags & YValue) != 0)
2256 image->page.y+=geometry.y;
2257 }
2258 else
2259 {
2260 if ((flags & XValue) != 0)
2261 {
2262 image->page.x=geometry.x;
2263 if ((image->page.width == 0) && (geometry.x > 0))
2264 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2265 }
2266 if ((flags & YValue) != 0)
2267 {
2268 image->page.y=geometry.y;
2269 if ((image->page.height == 0) && (geometry.y > 0))
2270 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2271 }
2272 }
2273 return(MagickTrue);
2274}
2275␌
2276/*
2277%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2278% %
2279% %
2280% %
2281% R e s e t I m a g e P i x e l s %
2282% %
2283% %
2284% %
2285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2286%
2287% ResetImagePixels() reset the image pixels, that is, all the pixel components
2288% are zeroed.
2289%
2290% The format of the SetImage method is:
2291%
2292% MagickBooleanType ResetImagePixels(Image *image,
2293% ExceptionInfo *exception)
2294%
2295% A description of each parameter follows:
2296%
2297% o image: the image.
2298%
2299% o exception: return any errors or warnings in this structure.
2300%
2301*/
2302MagickExport MagickBooleanType ResetImagePixels(Image *image,
2303 ExceptionInfo *exception)
2304{
2305 CacheView
2306 *image_view;
2307
2308 const void
2309 *pixels;
2310
2311 MagickBooleanType
2312 status;
2313
2314 MagickSizeType
2315 length;
2316
2317 ssize_t
2318 y;
2319
2320 assert(image != (Image *) NULL);
2321 assert(image->signature == MagickCoreSignature);
2322 if (IsEventLogging() != MagickFalse)
2323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2324 pixels=AcquirePixelCachePixels(image,&length,exception);
2325 if (pixels != (void *) NULL)
2326 {
2327 /*
2328 Reset in-core image pixels.
2329 */
2330 (void) memset((void *) pixels,0,(size_t) length);
2331 return(MagickTrue);
2332 }
2333 /*
2334 Reset image pixels.
2335 */
2336 status=MagickTrue;
2337 image_view=AcquireAuthenticCacheView(image,exception);
2338#if defined(MAGICKCORE_OPENMP_SUPPORT)
2339 #pragma omp parallel for schedule(static) shared(status) \
2340 magick_number_threads(image,image,image->rows,1)
2341#endif
2342 for (y=0; y < (ssize_t) image->rows; y++)
2343 {
2344 IndexPacket
2345 *magick_restrict indexes;
2346
2348 *magick_restrict q;
2349
2350 ssize_t
2351 x;
2352
2353 if (status == MagickFalse)
2354 continue;
2355 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2356 if (q == (PixelPacket *) NULL)
2357 {
2358 status=MagickFalse;
2359 continue;
2360 }
2361 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2362 for (x=0; x < (ssize_t) image->columns; x++)
2363 {
2364 (void) memset(q,0,sizeof(PixelPacket));
2365 if ((image->storage_class == PseudoClass) ||
2366 (image->colorspace == CMYKColorspace))
2367 indexes[x]=0;
2368 q++;
2369 }
2370 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2371 status=MagickFalse;
2372 }
2373 image_view=DestroyCacheView(image_view);
2374 return(status);
2375}
2376␌
2377/*
2378%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2379% %
2380% %
2381% %
2382% S e t I m a g e B a c k g r o u n d C o l o r %
2383% %
2384% %
2385% %
2386%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2387%
2388% SetImageBackgroundColor() initializes the image pixels to the image
2389% background color. The background color is defined by the background_color
2390% member of the image structure.
2391%
2392% The format of the SetImage method is:
2393%
2394% MagickBooleanType SetImageBackgroundColor(Image *image)
2395%
2396% A description of each parameter follows:
2397%
2398% o image: the image.
2399%
2400*/
2401MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2402{
2403 CacheView
2404 *image_view;
2405
2407 *exception;
2408
2409 IndexPacket
2410 index;
2411
2412 MagickBooleanType
2413 status;
2414
2416 background;
2417
2419 pixel;
2420
2421 ssize_t
2422 y;
2423
2424 assert(image != (Image *) NULL);
2425 assert(image->signature == MagickCoreSignature);
2426 if (IsEventLogging() != MagickFalse)
2427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2428 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2429 return(MagickFalse);
2430 if ((IsPixelGray(&image->background_color) == MagickFalse) &&
2431 (IsGrayColorspace(image->colorspace) != MagickFalse))
2432 (void) TransformImageColorspace(image,RGBColorspace);
2433 if ((image->background_color.opacity != OpaqueOpacity) &&
2434 (image->matte == MagickFalse))
2435 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
2436 GetMagickPixelPacket(image,&background);
2437 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2438 NULL,&background);
2439 if (image->colorspace == CMYKColorspace)
2440 ConvertRGBToCMYK(&background);
2441 index=0;
2442 pixel.opacity=OpaqueOpacity;
2443 SetPixelPacket(image,&background,&pixel,&index);
2444 /*
2445 Set image background color.
2446 */
2447 status=MagickTrue;
2448 exception=(&image->exception);
2449 image_view=AcquireAuthenticCacheView(image,exception);
2450 for (y=0; y < (ssize_t) image->rows; y++)
2451 {
2453 *magick_restrict q;
2454
2455 ssize_t
2456 x;
2457
2458 if (status == MagickFalse)
2459 continue;
2460 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2461 if (q == (PixelPacket *) NULL)
2462 {
2463 status=MagickFalse;
2464 continue;
2465 }
2466 for (x=0; x < (ssize_t) image->columns; x++)
2467 *q++=pixel;
2468 if (image->colorspace == CMYKColorspace)
2469 {
2470 IndexPacket
2471 *magick_restrict indexes;
2472
2473 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2474 for (x=0; x < (ssize_t) image->columns; x++)
2475 SetPixelIndex(indexes+x,index);
2476 }
2477 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2478 status=MagickFalse;
2479 }
2480 image_view=DestroyCacheView(image_view);
2481 return(status);
2482}
2483␌
2484/*
2485%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2486% %
2487% %
2488% %
2489% S e t I m a g e C h a n n e l s %
2490% %
2491% %
2492% %
2493%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2494%
2495% SetImageChannels() sets the number of pixels channels associated with the
2496% image.
2497%
2498% The format of the SetImageChannels method is:
2499%
2500% MagickBooleanType SetImageChannels(Image *image,const size_t channels)
2501%
2502% A description of each parameter follows:
2503%
2504% o image: the image.
2505%
2506% o channels: The number of pixel channels.
2507%
2508*/
2509MagickExport MagickBooleanType SetImageChannels(Image *image,
2510 const size_t channels)
2511{
2512 image->channels=channels;
2513 return(MagickTrue);
2514}
2515␌
2516/*
2517%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2518% %
2519% %
2520% %
2521% S e t I m a g e C o l o r %
2522% %
2523% %
2524% %
2525%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2526%
2527% SetImageColor() set the entire image canvas to the specified color.
2528%
2529% The format of the SetImageColor method is:
2530%
2531% MagickBooleanType SetImageColor(Image *image,
2532% const MagickPixelPacket *color)
2533%
2534% A description of each parameter follows:
2535%
2536% o image: the image.
2537%
2538% o background: the image color.
2539%
2540*/
2541MagickExport MagickBooleanType SetImageColor(Image *image,
2542 const MagickPixelPacket *color)
2543{
2544 CacheView
2545 *image_view;
2546
2548 *exception;
2549
2550 MagickBooleanType
2551 status;
2552
2553 ssize_t
2554 y;
2555
2556 assert(image != (Image *) NULL);
2557 assert(image->signature == MagickCoreSignature);
2558 assert(color != (const MagickPixelPacket *) NULL);
2559 if (IsEventLogging() != MagickFalse)
2560 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2561 image->colorspace=color->colorspace;
2562 image->matte=color->matte;
2563 image->fuzz=color->fuzz;
2564 image->depth=color->depth;
2565 status=MagickTrue;
2566 exception=(&image->exception);
2567 image_view=AcquireAuthenticCacheView(image,exception);
2568#if defined(MAGICKCORE_OPENMP_SUPPORT)
2569 #pragma omp parallel for schedule(static) shared(status) \
2570 magick_number_threads(image,image,image->rows,1)
2571#endif
2572 for (y=0; y < (ssize_t) image->rows; y++)
2573 {
2574 IndexPacket
2575 *magick_restrict indexes;
2576
2578 *magick_restrict q;
2579
2580 ssize_t
2581 x;
2582
2583 if (status == MagickFalse)
2584 continue;
2585 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2586 if (q == (PixelPacket *) NULL)
2587 {
2588 status=MagickFalse;
2589 continue;
2590 }
2591 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2592 for (x=0; x < (ssize_t) image->columns; x++)
2593 {
2594 SetPixelPacket(image,color,q,
2595 indexes == (IndexPacket *) NULL ? NULL : indexes+x);
2596 q++;
2597 }
2598 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2599 status=MagickFalse;
2600 }
2601 image_view=DestroyCacheView(image_view);
2602 return(status);
2603}
2604␌
2605/*
2606%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2607% %
2608% %
2609% %
2610% S e t I m a g e S t o r a g e C l a s s %
2611% %
2612% %
2613% %
2614%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2615%
2616% SetImageStorageClass() sets the image class: DirectClass for true color
2617% images or PseudoClass for colormapped images.
2618%
2619% The format of the SetImageStorageClass method is:
2620%
2621% MagickBooleanType SetImageStorageClass(Image *image,
2622% const ClassType storage_class)
2623%
2624% A description of each parameter follows:
2625%
2626% o image: the image.
2627%
2628% o storage_class: The image class.
2629%
2630*/
2631MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2632 const ClassType storage_class)
2633{
2634 assert(image != (Image *) NULL);
2635 assert(image->signature == MagickCoreSignature);
2636 if (IsEventLogging() != MagickFalse)
2637 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2638 image->storage_class=storage_class;
2639 return(SyncImagePixelCache(image,&image->exception));
2640}
2641␌
2642/*
2643%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2644% %
2645% %
2646% %
2647% S e t I m a g e C l i p M a s k %
2648% %
2649% %
2650% %
2651%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2652%
2653% SetImageClipMask() associates a clip path with the image. The clip path
2654% must be the same dimensions as the image. Set any pixel component of
2655% the clip path to TransparentOpacity to prevent that corresponding image
2656% pixel component from being updated when SyncAuthenticPixels() is applied.
2657%
2658% The format of the SetImageClipMask method is:
2659%
2660% MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2661%
2662% A description of each parameter follows:
2663%
2664% o image: the image.
2665%
2666% o clip_mask: the image clip path.
2667%
2668*/
2669MagickExport MagickBooleanType SetImageClipMask(Image *image,
2670 const Image *clip_mask)
2671{
2672 assert(image != (Image *) NULL);
2673 assert(image->signature == MagickCoreSignature);
2674 if (IsEventLogging() != MagickFalse)
2675 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2676 if (clip_mask != (const Image *) NULL)
2677 if ((clip_mask->columns != image->columns) ||
2678 (clip_mask->rows != image->rows))
2679 ThrowBinaryImageException(ImageError,"ImageSizeDiffers",image->filename);
2680 if (image->clip_mask != (Image *) NULL)
2681 image->clip_mask=DestroyImage(image->clip_mask);
2682 image->clip_mask=NewImageList();
2683 if (clip_mask == (Image *) NULL)
2684 return(MagickTrue);
2685 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2686 return(MagickFalse);
2687 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2688 if (image->clip_mask == (Image *) NULL)
2689 return(MagickFalse);
2690 return(MagickTrue);
2691}
2692␌
2693/*
2694%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2695% %
2696% %
2697% %
2698% S e t I m a g e E x t e n t %
2699% %
2700% %
2701% %
2702%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2703%
2704% SetImageExtent() sets the image size (i.e. columns & rows).
2705%
2706% The format of the SetImageExtent method is:
2707%
2708% MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2709% const size_t rows)
2710%
2711% A description of each parameter follows:
2712%
2713% o image: the image.
2714%
2715% o columns: The image width in pixels.
2716%
2717% o rows: The image height in pixels.
2718%
2719*/
2720MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2721 const size_t rows)
2722{
2723 if ((columns == 0) || (rows == 0))
2724 ThrowBinaryImageException(ImageError,"NegativeOrZeroImageSize",
2725 image->filename);
2726 image->columns=columns;
2727 image->rows=rows;
2728 if (image->depth == 0)
2729 {
2730 image->depth=8;
2731 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2732 ImageError,"ImageDepthNotSupported","`%s'",image->filename);
2733 }
2734 if (image->depth > (8*sizeof(MagickSizeType)))
2735 {
2736 image->depth=8*sizeof(MagickSizeType);
2737 (void) ThrowMagickException(&image->exception,GetMagickModule(),
2738 ImageError,"ImageDepthNotSupported","`%s'",image->filename);
2739 }
2740 return(SyncImagePixelCache(image,&image->exception));
2741}
2742␌
2743/*
2744%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2745% %
2746% %
2747% %
2748+ S e t I m a g e I n f o %
2749% %
2750% %
2751% %
2752%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2753%
2754% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2755% It is set to a type of image format based on the prefix or suffix of the
2756% filename. For example, `ps:image' returns PS indicating a Postscript image.
2757% JPEG is returned for this filename: `image.jpg'. The filename prefix has
2758% precendence over the suffix. Use an optional index enclosed in brackets
2759% after a file name to specify a desired scene of a multi-resolution image
2760% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2761% indicates success.
2762%
2763% The format of the SetImageInfo method is:
2764%
2765% MagickBooleanType SetImageInfo(ImageInfo *image_info,
2766% const unsigned int frames,ExceptionInfo *exception)
2767%
2768% A description of each parameter follows:
2769%
2770% o image_info: the image info.
2771%
2772% o frames: the number of images you intend to write.
2773%
2774% o exception: return any errors or warnings in this structure.
2775%
2776*/
2777MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2778 const unsigned int frames,ExceptionInfo *exception)
2779{
2780 char
2781 extension[MaxTextExtent],
2782 filename[MaxTextExtent],
2783 magic[MaxTextExtent],
2784 *q,
2785 subimage[MaxTextExtent];
2786
2787 const MagicInfo
2788 *magic_info;
2789
2790 const MagickInfo
2791 *magick_info;
2792
2794 *sans_exception;
2795
2796 Image
2797 *image;
2798
2799 MagickBooleanType
2800 status;
2801
2802 const char
2803 *p;
2804
2805 ssize_t
2806 count;
2807
2808 unsigned char
2809 magick[2*MaxTextExtent];
2810
2811 /*
2812 Look for 'image.format' in filename.
2813 */
2814 assert(image_info != (ImageInfo *) NULL);
2815 assert(image_info->signature == MagickCoreSignature);
2816 if (IsEventLogging() != MagickFalse)
2817 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2818 image_info->filename);
2819 *subimage='\0';
2820 GetPathComponent(image_info->filename,SubimagePath,subimage);
2821 if (*subimage != '\0')
2822 {
2823 /*
2824 Look for scene specification (e.g. img0001.pcd[4]).
2825 */
2826 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2827 {
2828 if (IsGeometry(subimage) != MagickFalse)
2829 (void) CloneString(&image_info->extract,subimage);
2830 }
2831 else
2832 {
2833 size_t
2834 first,
2835 last;
2836
2837 (void) CloneString(&image_info->scenes,subimage);
2838 image_info->scene=StringToUnsignedLong(image_info->scenes);
2839 image_info->number_scenes=image_info->scene;
2840 p=image_info->scenes;
2841 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2842 {
2843 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2844 p++;
2845 first=(size_t) strtol(p,&q,10);
2846 last=first;
2847 while (isspace((int) ((unsigned char) *q)) != 0)
2848 q++;
2849 if (*q == '-')
2850 last=(size_t) strtol(q+1,&q,10);
2851 if (first > last)
2852 Swap(first,last);
2853 if (first < image_info->scene)
2854 image_info->scene=first;
2855 if (last > image_info->number_scenes)
2856 image_info->number_scenes=last;
2857 p=q;
2858 }
2859 image_info->number_scenes-=image_info->scene-1;
2860 image_info->subimage=image_info->scene;
2861 image_info->subrange=image_info->number_scenes;
2862 }
2863 }
2864 *extension='\0';
2865 if (*image_info->magick == '\0')
2866 GetPathComponent(image_info->filename,ExtensionPath,extension);
2867 if (*extension != '\0')
2868 {
2869 char
2870 path[MaxTextExtent];
2871
2872 /*
2873 Base path sans any compression extension.
2874 */
2875 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2876 GetPathComponent(path,ExtensionPath,extension);
2877 }
2878 image_info->affirm=MagickFalse;
2879 sans_exception=AcquireExceptionInfo();
2880 if ((*extension != '\0') && (IsGlob(extension) == MagickFalse))
2881 {
2882 MagickFormatType
2883 format_type;
2884
2885 ssize_t
2886 i;
2887
2888 static const char
2889 *format_type_formats[] =
2890 {
2891 "AUTOTRACE",
2892 "BROWSE",
2893 "DCRAW",
2894 "EDIT",
2895 "LAUNCH",
2896 "MPEG:DECODE",
2897 "MPEG:ENCODE",
2898 "PRINT",
2899 "PS:ALPHA",
2900 "PS:CMYK",
2901 "PS:COLOR",
2902 "PS:GRAY",
2903 "PS:MONO",
2904 "SCAN",
2905 "SHOW",
2906 "WIN",
2907 (char *) NULL
2908 };
2909
2910 /*
2911 User specified image format.
2912 */
2913 (void) CopyMagickString(magic,extension,MaxTextExtent);
2914 LocaleUpper(magic);
2915 /*
2916 Look for explicit image formats.
2917 */
2918 format_type=UndefinedFormatType;
2919 i=0;
2920 while ((format_type == UndefinedFormatType) &&
2921 (format_type_formats[i] != (char *) NULL))
2922 {
2923 if ((*magic == *format_type_formats[i]) &&
2924 (LocaleCompare(magic,format_type_formats[i]) == 0))
2925 format_type=ExplicitFormatType;
2926 i++;
2927 }
2928 magick_info=GetMagickInfo(magic,sans_exception);
2929 if ((magick_info != (const MagickInfo *) NULL) &&
2930 (magick_info->format_type != UndefinedFormatType))
2931 format_type=magick_info->format_type;
2932 if (format_type == UndefinedFormatType)
2933 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2934 else
2935 if (format_type == ExplicitFormatType)
2936 {
2937 image_info->affirm=MagickTrue;
2938 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2939 }
2940 if (LocaleCompare(magic,"RGB") == 0)
2941 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2942 }
2943 /*
2944 Look for explicit 'format:image' in filename.
2945 */
2946 *magic='\0';
2947 GetPathComponent(image_info->filename,MagickPath,magic);
2948 if (*magic == '\0')
2949 {
2950 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
2951 magick_info=GetMagickInfo(magic,sans_exception);
2952 if ((magick_info != (const MagickInfo *) NULL) &&
2953 (magick_info->format_type == ExplicitFormatType))
2954 image_info->affirm=MagickTrue;
2955 if (frames == 0)
2956 GetPathComponent(image_info->filename,CanonicalPath,filename);
2957 else
2958 GetPathComponent(image_info->filename,SubcanonicalPath,filename);
2959 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2960 }
2961 else
2962 {
2963 const DelegateInfo
2964 *delegate_info;
2965
2966 /*
2967 User specified image format.
2968 */
2969 LocaleUpper(magic);
2970 magick_info=GetMagickInfo(magic,sans_exception);
2971 delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2972 if (delegate_info == (const DelegateInfo *) NULL)
2973 delegate_info=GetDelegateInfo("*",magic,sans_exception);
2974 if (((magick_info != (const MagickInfo *) NULL) ||
2975 (delegate_info != (const DelegateInfo *) NULL)) &&
2976 (IsMagickConflict(magic) == MagickFalse))
2977 {
2978 image_info->affirm=MagickTrue;
2979 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
2980 GetPathComponent(image_info->filename,CanonicalPath,filename);
2981 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
2982 }
2983 }
2984 sans_exception=DestroyExceptionInfo(sans_exception);
2985 if ((magick_info == (const MagickInfo *) NULL) ||
2986 (GetMagickEndianSupport(magick_info) == MagickFalse))
2987 image_info->endian=UndefinedEndian;
2988 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2989 {
2990 /*
2991 Test for multiple image support (e.g. image%02d.png).
2992 */
2993 (void) InterpretImageFilename(image_info,(Image *) NULL,
2994 image_info->filename,(int) image_info->scene,filename);
2995 if ((LocaleCompare(filename,image_info->filename) != 0) &&
2996 (strchr(filename,'%') == (char *) NULL))
2997 image_info->adjoin=MagickFalse;
2998 }
2999 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3000 {
3001 /*
3002 Some image formats do not support multiple frames per file.
3003 */
3004 magick_info=GetMagickInfo(magic,exception);
3005 if (magick_info != (const MagickInfo *) NULL)
3006 if (GetMagickAdjoin(magick_info) == MagickFalse)
3007 image_info->adjoin=MagickFalse;
3008 }
3009 if (image_info->affirm != MagickFalse)
3010 return(MagickTrue);
3011 if (frames == 0)
3012 {
3013 /*
3014 Determine the image format from the first few bytes of the file.
3015 */
3016 image=AcquireImage(image_info);
3017 (void) CopyMagickString(image->filename,image_info->filename,
3018 MaxTextExtent);
3019 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3020 if (status == MagickFalse)
3021 {
3022 image=DestroyImage(image);
3023 return(MagickFalse);
3024 }
3025 if ((IsBlobSeekable(image) == MagickFalse) ||
3026 (IsBlobExempt(image) != MagickFalse))
3027 {
3028 /*
3029 Copy image to a seekable temporary file.
3030 */
3031 *filename='\0';
3032 status=ImageToFile(image,filename,exception);
3033 (void) CloseBlob(image);
3034 if (status == MagickFalse)
3035 {
3036 (void) RelinquishUniqueFileResource(filename);
3037 image=DestroyImage(image);
3038 return(MagickFalse);
3039 }
3040 SetImageInfoFile(image_info,(FILE *) NULL);
3041 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3042 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3043 if (status == MagickFalse)
3044 {
3045 (void) RelinquishUniqueFileResource(filename);
3046 image=DestroyImage(image);
3047 return(MagickFalse);
3048 }
3049 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3050 image_info->temporary=MagickTrue;
3051 }
3052 (void) memset(magick,0,sizeof(magick));
3053 count=ReadBlob(image,2*MaxTextExtent,magick);
3054 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3055 (void) CloseBlob(image);
3056 image=DestroyImage(image);
3057 /*
3058 Check magic.xml configuration file.
3059 */
3060 sans_exception=AcquireExceptionInfo();
3061 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3062 if ((magic_info != (const MagicInfo *) NULL) &&
3063 (GetMagicName(magic_info) != (char *) NULL))
3064 {
3065 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3066 MaxTextExtent);
3067 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3068 if ((magick_info == (const MagickInfo *) NULL) ||
3069 (GetMagickEndianSupport(magick_info) == MagickFalse))
3070 image_info->endian=UndefinedEndian;
3071 sans_exception=DestroyExceptionInfo(sans_exception);
3072 return(MagickTrue);
3073 }
3074 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3075 if ((magick_info == (const MagickInfo *) NULL) ||
3076 (GetMagickEndianSupport(magick_info) == MagickFalse))
3077 image_info->endian=UndefinedEndian;
3078 sans_exception=DestroyExceptionInfo(sans_exception);
3079 }
3080 return(MagickTrue);
3081}
3082␌
3083/*
3084%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3085% %
3086% %
3087% %
3088% S e t I m a g e I n f o B l o b %
3089% %
3090% %
3091% %
3092%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3093%
3094% SetImageInfoBlob() sets the image info blob member.
3095%
3096% The format of the SetImageInfoBlob method is:
3097%
3098% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3099% const size_t length)
3100%
3101% A description of each parameter follows:
3102%
3103% o image_info: the image info.
3104%
3105% o blob: the blob.
3106%
3107% o length: the blob length.
3108%
3109*/
3110MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3111 const size_t length)
3112{
3113 assert(image_info != (ImageInfo *) NULL);
3114 assert(image_info->signature == MagickCoreSignature);
3115 if (IsEventLogging() != MagickFalse)
3116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3117 image_info->filename);
3118 image_info->blob=(void *) blob;
3119 image_info->length=length;
3120}
3121␌
3122/*
3123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3124% %
3125% %
3126% %
3127% S e t I m a g e I n f o F i l e %
3128% %
3129% %
3130% %
3131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3132%
3133% SetImageInfoFile() sets the image info file member.
3134%
3135% The format of the SetImageInfoFile method is:
3136%
3137% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3138%
3139% A description of each parameter follows:
3140%
3141% o image_info: the image info.
3142%
3143% o file: the file.
3144%
3145*/
3146MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3147{
3148 assert(image_info != (ImageInfo *) NULL);
3149 assert(image_info->signature == MagickCoreSignature);
3150 if (IsEventLogging() != MagickFalse)
3151 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3152 image_info->filename);
3153 image_info->file=file;
3154}
3155␌
3156/*
3157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3158% %
3159% %
3160% %
3161% S e t I m a g e M a s k %
3162% %
3163% %
3164% %
3165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3166%
3167% SetImageMask() associates a mask with the image. The mask must be the same
3168% dimensions as the image.
3169%
3170% The format of the SetImageMask method is:
3171%
3172% MagickBooleanType SetImageMask(Image *image,const Image *mask)
3173%
3174% A description of each parameter follows:
3175%
3176% o image: the image.
3177%
3178% o mask: the image mask.
3179%
3180*/
3181MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask)
3182{
3183 assert(image != (Image *) NULL);
3184 assert(image->signature == MagickCoreSignature);
3185 if (IsEventLogging() != MagickFalse)
3186 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3187 if (mask != (const Image *) NULL)
3188 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3189 ThrowBinaryImageException(ImageError,"ImageSizeDiffers",image->filename);
3190 if (image->mask != (Image *) NULL)
3191 image->mask=DestroyImage(image->mask);
3192 image->mask=NewImageList();
3193 if (mask == (Image *) NULL)
3194 return(MagickTrue);
3195 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3196 return(MagickFalse);
3197 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3198 if (image->mask == (Image *) NULL)
3199 return(MagickFalse);
3200 return(MagickTrue);
3201}
3202␌
3203/*
3204%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3205% %
3206% %
3207% %
3208% S e t I m a g e O p a c i t y %
3209% %
3210% %
3211% %
3212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3213%
3214% SetImageOpacity() sets the opacity levels of the image.
3215%
3216% The format of the SetImageOpacity method is:
3217%
3218% MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3219%
3220% A description of each parameter follows:
3221%
3222% o image: the image.
3223%
3224% o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3225% fully transparent.
3226%
3227*/
3228MagickExport MagickBooleanType SetImageOpacity(Image *image,
3229 const Quantum opacity)
3230{
3231 CacheView
3232 *image_view;
3233
3235 *exception;
3236
3237 MagickBooleanType
3238 status;
3239
3240 ssize_t
3241 y;
3242
3243 assert(image != (Image *) NULL);
3244 assert(image->signature == MagickCoreSignature);
3245 if (IsEventLogging() != MagickFalse)
3246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3247 image->matte=MagickTrue;
3248 status=MagickTrue;
3249 exception=(&image->exception);
3250 image_view=AcquireAuthenticCacheView(image,exception);
3251#if defined(MAGICKCORE_OPENMP_SUPPORT)
3252 #pragma omp parallel for schedule(static) shared(status) \
3253 magick_number_threads(image,image,image->rows,1)
3254#endif
3255 for (y=0; y < (ssize_t) image->rows; y++)
3256 {
3258 *magick_restrict q;
3259
3260 ssize_t
3261 x;
3262
3263 if (status == MagickFalse)
3264 continue;
3265 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3266 if (q == (PixelPacket *) NULL)
3267 {
3268 status=MagickFalse;
3269 continue;
3270 }
3271 for (x=0; x < (ssize_t) image->columns; x++)
3272 {
3273 SetPixelOpacity(q,opacity);
3274 q++;
3275 }
3276 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3277 status=MagickFalse;
3278 }
3279 image_view=DestroyCacheView(image_view);
3280 return(status);
3281}
3282␌
3283/*
3284%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3285% %
3286% %
3287% %
3288% 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 %
3289% %
3290% %
3291% %
3292%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3293%
3294% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3295% image and returns the previous setting. A virtual pixel is any pixel access
3296% that is outside the boundaries of the image cache.
3297%
3298% The format of the SetImageVirtualPixelMethod() method is:
3299%
3300% VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3301% const VirtualPixelMethod virtual_pixel_method)
3302%
3303% A description of each parameter follows:
3304%
3305% o image: the image.
3306%
3307% o virtual_pixel_method: choose the type of virtual pixel.
3308%
3309*/
3310MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3311 const VirtualPixelMethod virtual_pixel_method)
3312{
3313 assert(image != (const Image *) NULL);
3314 assert(image->signature == MagickCoreSignature);
3315 if (IsEventLogging() != MagickFalse)
3316 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3317 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3318}
3319␌
3320/*
3321%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3322% %
3323% %
3324% %
3325% S m u s h I m a g e s %
3326% %
3327% %
3328% %
3329%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3330%
3331% SmushImages() takes all images from the current image pointer to the end
3332% of the image list and smushes them to each other top-to-bottom if the
3333% stack parameter is true, otherwise left-to-right.
3334%
3335% The current gravity setting now effects how the image is justified in the
3336% final image.
3337%
3338% The format of the SmushImages method is:
3339%
3340% Image *SmushImages(const Image *images,const MagickBooleanType stack,
3341% ExceptionInfo *exception)
3342%
3343% A description of each parameter follows:
3344%
3345% o images: the image sequence.
3346%
3347% o stack: A value other than 0 stacks the images top-to-bottom.
3348%
3349% o offset: minimum distance in pixels between images.
3350%
3351% o exception: return any errors or warnings in this structure.
3352%
3353*/
3354
3355static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3356 const ssize_t offset,ExceptionInfo *exception)
3357{
3358 CacheView
3359 *left_view,
3360 *right_view;
3361
3362 const Image
3363 *left_image,
3364 *right_image;
3365
3367 left_geometry,
3368 right_geometry;
3369
3370 const PixelPacket
3371 *p;
3372
3373 ssize_t
3374 i,
3375 y;
3376
3377 size_t
3378 gap;
3379
3380 ssize_t
3381 x;
3382
3383 if (images->previous == (Image *) NULL)
3384 return(0);
3385 right_image=images;
3386 SetGeometry(smush_image,&right_geometry);
3387 GravityAdjustGeometry(right_image->columns,right_image->rows,
3388 right_image->gravity,&right_geometry);
3389 left_image=images->previous;
3390 SetGeometry(smush_image,&left_geometry);
3391 GravityAdjustGeometry(left_image->columns,left_image->rows,
3392 left_image->gravity,&left_geometry);
3393 gap=right_image->columns;
3394 left_view=AcquireVirtualCacheView(left_image,exception);
3395 right_view=AcquireVirtualCacheView(right_image,exception);
3396 for (y=0; y < (ssize_t) smush_image->rows; y++)
3397 {
3398 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3399 {
3400 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3401 if ((p == (const PixelPacket *) NULL) ||
3402 (GetPixelOpacity(p) != TransparentOpacity) ||
3403 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3404 break;
3405 }
3406 i=(ssize_t) left_image->columns-x-1;
3407 for (x=0; x < (ssize_t) right_image->columns; x++)
3408 {
3409 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3410 exception);
3411 if ((p == (const PixelPacket *) NULL) ||
3412 (GetPixelOpacity(p) != TransparentOpacity) ||
3413 ((x+i) >= (ssize_t) gap))
3414 break;
3415 }
3416 if ((x+i) < (ssize_t) gap)
3417 gap=(size_t) (x+i);
3418 }
3419 right_view=DestroyCacheView(right_view);
3420 left_view=DestroyCacheView(left_view);
3421 if (y < (ssize_t) smush_image->rows)
3422 return(offset);
3423 return((ssize_t) gap-offset);
3424}
3425
3426static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3427 const ssize_t offset,ExceptionInfo *exception)
3428{
3429 CacheView
3430 *bottom_view,
3431 *top_view;
3432
3433 const Image
3434 *bottom_image,
3435 *top_image;
3436
3438 bottom_geometry,
3439 top_geometry;
3440
3441 const PixelPacket
3442 *p;
3443
3444 ssize_t
3445 i,
3446 x;
3447
3448 size_t
3449 gap;
3450
3451 ssize_t
3452 y;
3453
3454 if (images->previous == (Image *) NULL)
3455 return(0);
3456 bottom_image=images;
3457 SetGeometry(smush_image,&bottom_geometry);
3458 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3459 bottom_image->gravity,&bottom_geometry);
3460 top_image=images->previous;
3461 SetGeometry(smush_image,&top_geometry);
3462 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3463 &top_geometry);
3464 gap=bottom_image->rows;
3465 top_view=AcquireVirtualCacheView(top_image,exception);
3466 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3467 for (x=0; x < (ssize_t) smush_image->columns; x++)
3468 {
3469 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3470 {
3471 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3472 if ((p == (const PixelPacket *) NULL) ||
3473 (GetPixelOpacity(p) != TransparentOpacity) ||
3474 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3475 break;
3476 }
3477 i=(ssize_t) top_image->rows-y-1;
3478 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3479 {
3480 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3481 exception);
3482 if ((p == (const PixelPacket *) NULL) ||
3483 (GetPixelOpacity(p) != TransparentOpacity) ||
3484 ((y+i) >= (ssize_t) gap))
3485 break;
3486 }
3487 if ((y+i) < (ssize_t) gap)
3488 gap=(size_t) (y+i);
3489 }
3490 bottom_view=DestroyCacheView(bottom_view);
3491 top_view=DestroyCacheView(top_view);
3492 if (x < (ssize_t) smush_image->columns)
3493 return(offset);
3494 return((ssize_t) gap-offset);
3495}
3496
3497MagickExport Image *SmushImages(const Image *images,
3498 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3499{
3500#define SmushImageTag "Smush/Image"
3501
3502 CacheView
3503 *smush_view;
3504
3505 const Image
3506 *image;
3507
3508 Image
3509 *smush_image;
3510
3511 MagickBooleanType
3512 matte,
3513 proceed,
3514 status;
3515
3516 MagickOffsetType
3517 n;
3518
3520 geometry;
3521
3522 const Image
3523 *next;
3524
3525 size_t
3526 height,
3527 number_images,
3528 width;
3529
3530 ssize_t
3531 x_offset,
3532 y_offset;
3533
3534 /*
3535 Compute maximum area of smushed area.
3536 */
3537 assert(images != (Image *) NULL);
3538 assert(images->signature == MagickCoreSignature);
3539 assert(exception != (ExceptionInfo *) NULL);
3540 assert(exception->signature == MagickCoreSignature);
3541 if (IsEventLogging() != MagickFalse)
3542 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3543 image=images;
3544 matte=image->matte;
3545 number_images=1;
3546 width=image->columns;
3547 height=image->rows;
3548 next=GetNextImageInList(image);
3549 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3550 {
3551 if (next->matte != MagickFalse)
3552 matte=MagickTrue;
3553 number_images++;
3554 if (stack != MagickFalse)
3555 {
3556 if (next->columns > width)
3557 width=next->columns;
3558 height+=next->rows;
3559 if (next->previous != (Image *) NULL)
3560 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3561 continue;
3562 }
3563 width+=next->columns;
3564 if (next->previous != (Image *) NULL)
3565 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3566 if (next->rows > height)
3567 height=next->rows;
3568 }
3569 /*
3570 Smush images.
3571 */
3572 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3573 if (smush_image == (Image *) NULL)
3574 return((Image *) NULL);
3575 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
3576 {
3577 InheritException(exception,&smush_image->exception);
3578 smush_image=DestroyImage(smush_image);
3579 return((Image *) NULL);
3580 }
3581 smush_image->matte=matte;
3582 (void) SetImageBackgroundColor(smush_image);
3583 status=MagickTrue;
3584 x_offset=0;
3585 y_offset=0;
3586 smush_view=AcquireVirtualCacheView(smush_image,exception);
3587 for (n=0; n < (MagickOffsetType) number_images; n++)
3588 {
3589 SetGeometry(smush_image,&geometry);
3590 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3591 if (stack != MagickFalse)
3592 {
3593 x_offset-=geometry.x;
3594 y_offset-=SmushYGap(smush_image,image,offset,exception);
3595 }
3596 else
3597 {
3598 x_offset-=SmushXGap(smush_image,image,offset,exception);
3599 y_offset-=geometry.y;
3600 }
3601 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
3602 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3603 if (proceed == MagickFalse)
3604 break;
3605 if (stack == MagickFalse)
3606 {
3607 x_offset+=(ssize_t) image->columns;
3608 y_offset=0;
3609 }
3610 else
3611 {
3612 x_offset=0;
3613 y_offset+=(ssize_t) image->rows;
3614 }
3615 image=GetNextImageInList(image);
3616 }
3617 if (stack == MagickFalse)
3618 smush_image->columns=(size_t) x_offset;
3619 else
3620 smush_image->rows=(size_t) y_offset;
3621 smush_view=DestroyCacheView(smush_view);
3622 if (status == MagickFalse)
3623 smush_image=DestroyImage(smush_image);
3624 return(smush_image);
3625}
3626␌
3627/*
3628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3629% %
3630% %
3631% %
3632% S t r i p I m a g e %
3633% %
3634% %
3635% %
3636%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3637%
3638% StripImage() strips an image of all profiles and comments.
3639%
3640% The format of the StripImage method is:
3641%
3642% MagickBooleanType StripImage(Image *image)
3643%
3644% A description of each parameter follows:
3645%
3646% o image: the image.
3647%
3648*/
3649MagickExport MagickBooleanType StripImage(Image *image)
3650{
3651 MagickBooleanType
3652 status;
3653
3654 assert(image != (Image *) NULL);
3655 if (IsEventLogging() != MagickFalse)
3656 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3657 DestroyImageProfiles(image);
3658 (void) DeleteImageProperty(image,"comment");
3659 (void) DeleteImageProperty(image,"date:create");
3660 (void) DeleteImageProperty(image,"date:modify");
3661 status=SetImageArtifact(image,"png:exclude-chunk",
3662 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3663 return(status);
3664}
3665␌
3666/*
3667%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3668% %
3669% %
3670% %
3671+ S y n c I m a g e %
3672% %
3673% %
3674% %
3675%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3676%
3677% SyncImage() initializes the red, green, and blue intensities of each pixel
3678% as defined by the colormap index.
3679%
3680% The format of the SyncImage method is:
3681%
3682% MagickBooleanType SyncImage(Image *image)
3683%
3684% A description of each parameter follows:
3685%
3686% o image: the image.
3687%
3688*/
3689
3690static inline IndexPacket PushColormapIndex(Image *image,
3691 const size_t index,MagickBooleanType *range_exception)
3692{
3693 if (index < image->colors)
3694 return((IndexPacket) index);
3695 *range_exception=MagickTrue;
3696 return((IndexPacket) 0);
3697}
3698
3699MagickExport MagickBooleanType SyncImage(Image *image)
3700{
3701 CacheView
3702 *image_view;
3703
3705 *exception;
3706
3707 MagickBooleanType
3708 range_exception,
3709 status,
3710 taint;
3711
3712 ssize_t
3713 y;
3714
3715 assert(image != (Image *) NULL);
3716 assert(image->signature == MagickCoreSignature);
3717 if (IsEventLogging() != MagickFalse)
3718 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3719 if (image->ping != MagickFalse)
3720 return(MagickTrue);
3721 if (image->storage_class != PseudoClass)
3722 return(MagickFalse);
3723 assert(image->colormap != (PixelPacket *) NULL);
3724 range_exception=MagickFalse;
3725 status=MagickTrue;
3726 taint=image->taint;
3727 exception=(&image->exception);
3728 image_view=AcquireAuthenticCacheView(image,exception);
3729#if defined(MAGICKCORE_OPENMP_SUPPORT)
3730 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3731 magick_number_threads(image,image,image->rows,1)
3732#endif
3733 for (y=0; y < (ssize_t) image->rows; y++)
3734 {
3735 IndexPacket
3736 index;
3737
3738 IndexPacket
3739 *magick_restrict indexes;
3740
3742 *magick_restrict q;
3743
3744 ssize_t
3745 x;
3746
3747 if (status == MagickFalse)
3748 continue;
3749 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3750 if (q == (PixelPacket *) NULL)
3751 {
3752 status=MagickFalse;
3753 continue;
3754 }
3755 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3756 for (x=0; x < (ssize_t) image->columns; x++)
3757 {
3758 index=PushColormapIndex(image,(size_t) GetPixelIndex(indexes+x),
3759 &range_exception);
3760 if (image->matte == MagickFalse)
3761 SetPixelRgb(q,image->colormap+(ssize_t) index)
3762 else
3763 SetPixelRGBO(q,image->colormap+(ssize_t) index);
3764 q++;
3765 }
3766 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3767 status=MagickFalse;
3768 }
3769 image_view=DestroyCacheView(image_view);
3770 image->taint=taint;
3771 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
3772 (void) ThrowMagickException(&image->exception,GetMagickModule(),
3773 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
3774 return(status);
3775}
3776␌
3777/*
3778%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3779% %
3780% %
3781% %
3782% S y n c I m a g e S e t t i n g s %
3783% %
3784% %
3785% %
3786%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3787%
3788% SyncImageSettings() syncs image_info options into per-image attributes.
3789%
3790% The format of the SyncImageSettings method is:
3791%
3792% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3793% Image *image)
3794% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3795% Image *image)
3796%
3797% A description of each parameter follows:
3798%
3799% o image_info: the image info.
3800%
3801% o image: the image.
3802%
3803*/
3804
3805MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3806 Image *images)
3807{
3808 Image
3809 *image;
3810
3811 assert(image_info != (const ImageInfo *) NULL);
3812 assert(image_info->signature == MagickCoreSignature);
3813 assert(images != (Image *) NULL);
3814 assert(images->signature == MagickCoreSignature);
3815 if (IsEventLogging() != MagickFalse)
3816 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3817 image=images;
3818 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3819 (void) SyncImageSettings(image_info,image);
3820 (void) DeleteImageOption(image_info,"page");
3821 return(MagickTrue);
3822}
3823
3824MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3825 Image *image)
3826{
3827 char
3828 property[MaxTextExtent];
3829
3830 const char
3831 *option,
3832 *value;
3833
3835 geometry_info;
3836
3837 MagickStatusType
3838 flags;
3839
3840 ResolutionType
3841 units;
3842
3843 /*
3844 Sync image options.
3845 */
3846 assert(image_info != (const ImageInfo *) NULL);
3847 assert(image_info->signature == MagickCoreSignature);
3848 assert(image != (Image *) NULL);
3849 assert(image->signature == MagickCoreSignature);
3850 if (IsEventLogging() != MagickFalse)
3851 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3852 option=GetImageOption(image_info,"background");
3853 if (option != (const char *) NULL)
3854 (void) QueryColorDatabase(option,&image->background_color,
3855 &image->exception);
3856 option=GetImageOption(image_info,"bias");
3857 if (option != (const char *) NULL)
3858 image->bias=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3859 option=GetImageOption(image_info,"black-point-compensation");
3860 if (option != (const char *) NULL)
3861 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
3862 MagickBooleanOptions,MagickFalse,option);
3863 option=GetImageOption(image_info,"blue-primary");
3864 if (option != (const char *) NULL)
3865 {
3866 flags=ParseGeometry(option,&geometry_info);
3867 if ((flags & RhoValue) != 0)
3868 image->chromaticity.blue_primary.x=geometry_info.rho;
3869 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3870 if ((flags & SigmaValue) != 0)
3871 image->chromaticity.blue_primary.y=geometry_info.sigma;
3872 }
3873 option=GetImageOption(image_info,"bordercolor");
3874 if (option != (const char *) NULL)
3875 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
3876 option=GetImageOption(image_info,"colors");
3877 if (option != (const char *) NULL)
3878 image->colors=StringToUnsignedLong(option);
3879 option=GetImageOption(image_info,"compose");
3880 if (option != (const char *) NULL)
3881 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
3882 MagickFalse,option);
3883 option=GetImageOption(image_info,"compress");
3884 if (option != (const char *) NULL)
3885 image->compression=(CompressionType) ParseCommandOption(
3886 MagickCompressOptions,MagickFalse,option);
3887 option=GetImageOption(image_info,"debug");
3888 if (option != (const char *) NULL)
3889 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3890 MagickFalse,option);
3891 option=GetImageOption(image_info,"density");
3892 if (option != (const char *) NULL)
3893 {
3895 geometry_info;
3896
3897 /*
3898 Set image density.
3899 */
3900 flags=ParseGeometry(option,&geometry_info);
3901 if ((flags & RhoValue) != 0)
3902 image->x_resolution=geometry_info.rho;
3903 image->y_resolution=image->x_resolution;
3904 if ((flags & SigmaValue) != 0)
3905 image->y_resolution=geometry_info.sigma;
3906 }
3907 option=GetImageOption(image_info,"depth");
3908 if (option != (const char *) NULL)
3909 image->depth=StringToUnsignedLong(option);
3910 option=GetImageOption(image_info,"endian");
3911 if (option != (const char *) NULL)
3912 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
3913 MagickFalse,option);
3914 option=GetImageOption(image_info,"filter");
3915 if (option != (const char *) NULL)
3916 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
3917 MagickFalse,option);
3918 option=GetImageOption(image_info,"fuzz");
3919 if (option != (const char *) NULL)
3920 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
3921 option=GetImageOption(image_info,"gravity");
3922 if (option != (const char *) NULL)
3923 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
3924 MagickFalse,option);
3925 option=GetImageOption(image_info,"green-primary");
3926 if (option != (const char *) NULL)
3927 {
3928 flags=ParseGeometry(option,&geometry_info);
3929 if ((flags & RhoValue) != 0)
3930 image->chromaticity.green_primary.x=geometry_info.rho;
3931 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3932 if ((flags & SigmaValue) != 0)
3933 image->chromaticity.green_primary.y=geometry_info.sigma;
3934 }
3935 option=GetImageOption(image_info,"intensity");
3936 if (option != (const char *) NULL)
3937 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3938 MagickPixelIntensityOptions,MagickFalse,option);
3939 option=GetImageOption(image_info,"intent");
3940 if (option != (const char *) NULL)
3941 image->rendering_intent=(RenderingIntent) ParseCommandOption(
3942 MagickIntentOptions,MagickFalse,option);
3943 option=GetImageOption(image_info,"interlace");
3944 if (option != (const char *) NULL)
3945 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
3946 MagickFalse,option);
3947 option=GetImageOption(image_info,"interpolate");
3948 if (option != (const char *) NULL)
3949 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
3950 MagickInterpolateOptions,MagickFalse,option);
3951 option=GetImageOption(image_info,"loop");
3952 if (option != (const char *) NULL)
3953 image->iterations=StringToUnsignedLong(option);
3954 option=GetImageOption(image_info,"mattecolor");
3955 if (option != (const char *) NULL)
3956 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
3957 option=GetImageOption(image_info,"orient");
3958 if (option != (const char *) NULL)
3959 image->orientation=(OrientationType) ParseCommandOption(
3960 MagickOrientationOptions,MagickFalse,option);
3961 option=GetImageOption(image_info,"page");
3962 if (option != (const char *) NULL)
3963 {
3964 char
3965 *geometry;
3966
3967 geometry=GetPageGeometry(option);
3968 flags=ParseAbsoluteGeometry(geometry,&image->page);
3969 geometry=DestroyString(geometry);
3970 }
3971 option=GetImageOption(image_info,"quality");
3972 if (option != (const char *) NULL)
3973 image->quality=StringToUnsignedLong(option);
3974 option=GetImageOption(image_info,"red-primary");
3975 if (option != (const char *) NULL)
3976 {
3977 flags=ParseGeometry(option,&geometry_info);
3978 if ((flags & RhoValue) != 0)
3979 image->chromaticity.red_primary.x=geometry_info.rho;
3980 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3981 if ((flags & SigmaValue) != 0)
3982 image->chromaticity.red_primary.y=geometry_info.sigma;
3983 }
3984 if (image_info->quality != UndefinedCompressionQuality)
3985 image->quality=image_info->quality;
3986 option=GetImageOption(image_info,"scene");
3987 if (option != (const char *) NULL)
3988 image->scene=StringToUnsignedLong(option);
3989 option=GetImageOption(image_info,"taint");
3990 if (option != (const char *) NULL)
3991 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
3992 MagickFalse,option);
3993 option=GetImageOption(image_info,"tile-offset");
3994 if (option != (const char *) NULL)
3995 {
3996 char
3997 *geometry;
3998
3999 geometry=GetPageGeometry(option);
4000 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4001 geometry=DestroyString(geometry);
4002 }
4003 option=GetImageOption(image_info,"transparent-color");
4004 if (option != (const char *) NULL)
4005 (void) QueryColorDatabase(option,&image->transparent_color,
4006 &image->exception);
4007 option=GetImageOption(image_info,"type");
4008 if (option != (const char *) NULL)
4009 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4010 option);
4011 option=GetImageOption(image_info,"units");
4012 units=image_info->units;
4013 if (option != (const char *) NULL)
4014 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4015 MagickFalse,option);
4016 if (units != UndefinedResolution)
4017 {
4018 if (image->units != units)
4019 switch (image->units)
4020 {
4021 case PixelsPerInchResolution:
4022 {
4023 if (units == PixelsPerCentimeterResolution)
4024 {
4025 image->x_resolution/=2.54;
4026 image->y_resolution/=2.54;
4027 }
4028 break;
4029 }
4030 case PixelsPerCentimeterResolution:
4031 {
4032 if (units == PixelsPerInchResolution)
4033 {
4034 image->x_resolution=(double) ((size_t) (100.0*2.54*
4035 image->x_resolution+0.5))/100.0;
4036 image->y_resolution=(double) ((size_t) (100.0*2.54*
4037 image->y_resolution+0.5))/100.0;
4038 }
4039 break;
4040 }
4041 default:
4042 break;
4043 }
4044 image->units=units;
4045 option=GetImageOption(image_info,"density");
4046 if (option != (const char *) NULL)
4047 {
4048 flags=ParseGeometry(option,&geometry_info);
4049 if ((flags & RhoValue) != 0)
4050 image->x_resolution=geometry_info.rho;
4051 image->y_resolution=image->x_resolution;
4052 if ((flags & SigmaValue) != 0)
4053 image->y_resolution=geometry_info.sigma;
4054 }
4055 }
4056 option=GetImageOption(image_info,"white-point");
4057 if (option != (const char *) NULL)
4058 {
4059 flags=ParseGeometry(option,&geometry_info);
4060 if ((flags & RhoValue) != 0)
4061 image->chromaticity.white_point.x=geometry_info.rho;
4062 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4063 if ((flags & SigmaValue) != 0)
4064 image->chromaticity.white_point.y=geometry_info.sigma;
4065 }
4066 ResetImageOptionIterator(image_info);
4067 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4068 {
4069 value=GetImageOption(image_info,option);
4070 if (value != (const char *) NULL)
4071 {
4072 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
4073 (void) SetImageArtifact(image,property,value);
4074 }
4075 option=GetNextImageOption(image_info);
4076 }
4077 return(MagickTrue);
4078}