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