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->debug=image_info->debug;
1016 clone_info->signature=image_info->signature;
1017 return(clone_info);
1018}
1019
1020/*
1021%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1022% %
1023% %
1024% %
1025% C o p y I m a g e P i x e l s %
1026% %
1027% %
1028% %
1029%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1030%
1031% CopyImagePixels() copies pixels from the source image as defined by the
1032% geometry the destination image at the specified offset.
1033%
1034% The format of the CopyImagePixels method is:
1035%
1036% MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
1037% const RectangleInfo *geometry,const OffsetInfo *offset,
1038% ExceptionInfo *exception);
1039%
1040% A description of each parameter follows:
1041%
1042% o image: the destination image.
1043%
1044% o source_image: the source image.
1045%
1046% o geometry: define the dimensions of the source pixel rectangle.
1047%
1048% o offset: define the offset in the destination image.
1049%
1050% o exception: return any errors or warnings in this structure.
1051%
1052*/
1053MagickExport MagickBooleanType CopyImagePixels(Image *image,
1054 const Image *source_image,const RectangleInfo *geometry,
1055 const OffsetInfo *offset,ExceptionInfo *exception)
1056{
1057#define CopyImageTag "Copy/Image"
1058
1059 CacheView
1060 *image_view,
1061 *source_view;
1062
1063 MagickBooleanType
1064 status;
1065
1066 MagickOffsetType
1067 progress;
1068
1069 ssize_t
1070 y;
1071
1072 assert(image != (Image *) NULL);
1073 assert(source_image != (Image *) NULL);
1074 assert(geometry != (RectangleInfo *) NULL);
1075 assert(offset != (OffsetInfo *) NULL);
1076 if (IsEventLogging() != MagickFalse)
1077 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1078 if ((offset->x < 0) || (offset->y < 0) ||
1079 ((offset->x+(ssize_t) geometry->width) > (ssize_t) image->columns) ||
1080 ((offset->y+(ssize_t) geometry->height) > (ssize_t) image->rows))
1081 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1082 image->filename);
1083 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1084 return(MagickFalse);
1085 /*
1086 Copy image pixels.
1087 */
1088 status=MagickTrue;
1089 progress=0;
1090 source_view=AcquireVirtualCacheView(source_image,exception);
1091 image_view=AcquireAuthenticCacheView(image,exception);
1092#if defined(MAGICKCORE_OPENMP_SUPPORT)
1093 #pragma omp parallel for schedule(static) shared(progress,status) \
1094 magick_number_threads(image,source_image,geometry->height,2)
1095#endif
1096 for (y=0; y < (ssize_t) geometry->height; y++)
1097 {
1098 MagickBooleanType
1099 sync;
1100
1101 const Quantum
1102 *magick_restrict p;
1103
1104 ssize_t
1105 x;
1106
1107 Quantum
1108 *magick_restrict q;
1109
1110 if (status == MagickFalse)
1111 continue;
1112 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1113 geometry->width,1,exception);
1114 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1115 geometry->width,1,exception);
1116 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1117 {
1118 status=MagickFalse;
1119 continue;
1120 }
1121 for (x=0; x < (ssize_t) geometry->width; x++)
1122 {
1123 ssize_t
1124 i;
1125
1126 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1127 {
1128 PixelChannel channel = GetPixelChannelChannel(image,i);
1129 PixelTrait traits = GetPixelChannelTraits(image,channel);
1130 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1131 if ((traits == UndefinedPixelTrait) ||
1132 ((traits & UpdatePixelTrait) == 0) ||
1133 (source_traits == UndefinedPixelTrait))
1134 continue;
1135 SetPixelChannel(image,channel,p[i],q);
1136 }
1137 p+=(ptrdiff_t) GetPixelChannels(source_image);
1138 q+=(ptrdiff_t) GetPixelChannels(image);
1139 }
1140 sync=SyncCacheViewAuthenticPixels(image_view,exception);
1141 if (sync == MagickFalse)
1142 status=MagickFalse;
1143 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1144 {
1145 MagickBooleanType
1146 proceed;
1147
1148#if defined(MAGICKCORE_OPENMP_SUPPORT)
1149 #pragma omp atomic
1150#endif
1151 progress++;
1152 proceed=SetImageProgress(image,CopyImageTag,progress,image->rows);
1153 if (proceed == MagickFalse)
1154 status=MagickFalse;
1155 }
1156 }
1157 source_view=DestroyCacheView(source_view);
1158 image_view=DestroyCacheView(image_view);
1159 return(status);
1160}
1161
1162/*
1163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1164% %
1165% %
1166% %
1167% D e s t r o y I m a g e %
1168% %
1169% %
1170% %
1171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1172%
1173% DestroyImage() dereferences an image, deallocating memory associated with
1174% the image if the reference count becomes zero.
1175%
1176% The format of the DestroyImage method is:
1177%
1178% Image *DestroyImage(Image *image)
1179%
1180% A description of each parameter follows:
1181%
1182% o image: the image.
1183%
1184*/
1185MagickExport Image *DestroyImage(Image *image)
1186{
1187 MagickBooleanType
1188 destroy;
1189
1190 /*
1191 Dereference image.
1192 */
1193 assert(image != (Image *) NULL);
1194 assert(image->signature == MagickCoreSignature);
1195 if (IsEventLogging() != MagickFalse)
1196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1197 destroy=MagickFalse;
1198 LockSemaphoreInfo(image->semaphore);
1199 image->reference_count--;
1200 if (image->reference_count == 0)
1201 destroy=MagickTrue;
1202 UnlockSemaphoreInfo(image->semaphore);
1203 if (destroy == MagickFalse)
1204 return((Image *) NULL);
1205 /*
1206 Destroy image.
1207 */
1208 DestroyImagePixels(image);
1209 image->channel_map=DestroyPixelChannelMap(image->channel_map);
1210 if (image->montage != (char *) NULL)
1211 image->montage=DestroyString(image->montage);
1212 if (image->directory != (char *) NULL)
1213 image->directory=DestroyString(image->directory);
1214 if (image->colormap != (PixelInfo *) NULL)
1215 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
1216 if (image->geometry != (char *) NULL)
1217 image->geometry=DestroyString(image->geometry);
1218 DestroyImageProfiles(image);
1219 DestroyImageProperties(image);
1220 DestroyImageArtifacts(image);
1221 if (image->ascii85 != (Ascii85Info *) NULL)
1222 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1223 if (image->image_info != (ImageInfo *) NULL)
1224 image->image_info=DestroyImageInfo(image->image_info);
1225 DestroyBlob(image);
1226 if (image->semaphore != (SemaphoreInfo *) NULL)
1227 RelinquishSemaphoreInfo(&image->semaphore);
1228 image->signature=(~MagickCoreSignature);
1229 image=(Image *) RelinquishMagickMemory(image);
1230 return(image);
1231}
1232
1233/*
1234%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1235% %
1236% %
1237% %
1238% D e s t r o y I m a g e I n f o %
1239% %
1240% %
1241% %
1242%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1243%
1244% DestroyImageInfo() deallocates memory associated with an ImageInfo
1245% structure.
1246%
1247% The format of the DestroyImageInfo method is:
1248%
1249% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1250%
1251% A description of each parameter follows:
1252%
1253% o image_info: the image info.
1254%
1255*/
1256MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1257{
1258 assert(image_info != (ImageInfo *) NULL);
1259 assert(image_info->signature == MagickCoreSignature);
1260 if (IsEventLogging() != MagickFalse)
1261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1262 image_info->filename);
1263 if (image_info->size != (char *) NULL)
1264 image_info->size=DestroyString(image_info->size);
1265 if (image_info->extract != (char *) NULL)
1266 image_info->extract=DestroyString(image_info->extract);
1267 if (image_info->scenes != (char *) NULL)
1268 image_info->scenes=DestroyString(image_info->scenes);
1269 if (image_info->page != (char *) NULL)
1270 image_info->page=DestroyString(image_info->page);
1271 if (image_info->sampling_factor != (char *) NULL)
1272 image_info->sampling_factor=DestroyString(
1273 image_info->sampling_factor);
1274 if (image_info->server_name != (char *) NULL)
1275 image_info->server_name=DestroyString(
1276 image_info->server_name);
1277 if (image_info->font != (char *) NULL)
1278 image_info->font=DestroyString(image_info->font);
1279 if (image_info->texture != (char *) NULL)
1280 image_info->texture=DestroyString(image_info->texture);
1281 if (image_info->density != (char *) NULL)
1282 image_info->density=DestroyString(image_info->density);
1283 if (image_info->cache != (void *) NULL)
1284 image_info->cache=DestroyPixelCache(image_info->cache);
1285 if (image_info->profile != (StringInfo *) NULL)
1286 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1287 image_info->profile);
1288 DestroyImageOptions(image_info);
1289 image_info->signature=(~MagickCoreSignature);
1290 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1291 return(image_info);
1292}
1293
1294/*
1295%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1296% %
1297% %
1298% %
1299+ D i s a s s o c i a t e I m a g e S t r e a m %
1300% %
1301% %
1302% %
1303%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1304%
1305% DisassociateImageStream() disassociates the image stream. It checks if the
1306% blob of the specified image is referenced by other images. If the reference
1307% count is higher then 1 a new blob is assigned to the specified image.
1308%
1309% The format of the DisassociateImageStream method is:
1310%
1311% void DisassociateImageStream(const Image *image)
1312%
1313% A description of each parameter follows:
1314%
1315% o image: the image.
1316%
1317*/
1318MagickExport void DisassociateImageStream(Image *image)
1319{
1320 assert(image != (Image *) NULL);
1321 assert(image->signature == MagickCoreSignature);
1322 if (IsEventLogging() != MagickFalse)
1323 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1324 DisassociateBlob(image);
1325}
1326
1327/*
1328%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1329% %
1330% %
1331% %
1332% G e t I m a g e I n f o %
1333% %
1334% %
1335% %
1336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337%
1338% GetImageInfo() initializes image_info to default values.
1339%
1340% The format of the GetImageInfo method is:
1341%
1342% void GetImageInfo(ImageInfo *image_info)
1343%
1344% A description of each parameter follows:
1345%
1346% o image_info: the image info.
1347%
1348*/
1349MagickExport void GetImageInfo(ImageInfo *image_info)
1350{
1351 char
1352 *synchronize;
1353
1354 /*
1355 File and image dimension members.
1356 */
1357 assert(image_info != (ImageInfo *) NULL);
1358 if (IsEventLogging() != MagickFalse)
1359 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1360 (void) memset(image_info,0,sizeof(*image_info));
1361 image_info->adjoin=MagickTrue;
1362 image_info->interlace=NoInterlace;
1363 image_info->channel=AllChannels;
1364 image_info->quality=UndefinedCompressionQuality;
1365 image_info->antialias=MagickTrue;
1366 image_info->dither=MagickTrue;
1367 image_info->depth=0;
1368 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1369 if (synchronize != (const char *) NULL)
1370 {
1371 image_info->synchronize=IsStringTrue(synchronize);
1372 synchronize=DestroyString(synchronize);
1373 }
1374 GetPixelInfoRGBA(BackgroundColorRGBA,&image_info->background_color);
1375 GetPixelInfoRGBA(BorderColorRGBA,&image_info->border_color);
1376 GetPixelInfoRGBA(MatteColorRGBA,&image_info->matte_color);
1377 GetPixelInfoRGBA(TransparentColorRGBA,&image_info->transparent_color);
1378 image_info->debug=(GetLogEventMask() & ImageEvent) != 0 ? MagickTrue :
1379 MagickFalse;
1380 image_info->signature=MagickCoreSignature;
1381}
1382
1383/*
1384%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1385% %
1386% %
1387% %
1388% G e t I m a g e I n f o F i l e %
1389% %
1390% %
1391% %
1392%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393%
1394% GetImageInfoFile() returns the image info file member.
1395%
1396% The format of the GetImageInfoFile method is:
1397%
1398% FILE *GetImageInfoFile(const ImageInfo *image_info)
1399%
1400% A description of each parameter follows:
1401%
1402% o image_info: the image info.
1403%
1404*/
1405MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1406{
1407 return(image_info->file);
1408}
1409
1410/*
1411%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1412% %
1413% %
1414% %
1415% G e t I m a g e M a s k %
1416% %
1417% %
1418% %
1419%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1420%
1421% GetImageMask() returns the mask associated with the image.
1422%
1423% The format of the GetImageMask method is:
1424%
1425% Image *GetImageMask(const Image *image,const PixelMask type,
1426% ExceptionInfo *exception)
1427%
1428% A description of each parameter follows:
1429%
1430% o image: the image.
1431%
1432% o type: the mask type, ReadPixelMask or WritePixelMask.
1433%
1434*/
1435MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1436 ExceptionInfo *exception)
1437{
1438 CacheView
1439 *mask_view,
1440 *image_view;
1441
1442 Image
1443 *mask_image;
1444
1445 MagickBooleanType
1446 status;
1447
1448 ssize_t
1449 y;
1450
1451 /*
1452 Get image mask.
1453 */
1454 assert(image != (Image *) NULL);
1455 assert(image->signature == MagickCoreSignature);
1456 if (IsEventLogging() != MagickFalse)
1457 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1458 switch (type)
1459 {
1460 case ReadPixelMask:
1461 {
1462 if ((image->channels & ReadMaskChannel) == 0)
1463 return((Image *) NULL);
1464 break;
1465 }
1466 case WritePixelMask:
1467 {
1468 if ((image->channels & WriteMaskChannel) == 0)
1469 return((Image *) NULL);
1470 break;
1471 }
1472 default:
1473 {
1474 if ((image->channels & CompositeMaskChannel) == 0)
1475 return((Image *) NULL);
1476 break;
1477 }
1478 }
1479 mask_image=AcquireImage((ImageInfo *) NULL,exception);
1480 status=SetImageExtent(mask_image,image->columns,image->rows,exception);
1481 if (status == MagickFalse)
1482 return(DestroyImage(mask_image));
1483 status=MagickTrue;
1484 mask_image->alpha_trait=UndefinedPixelTrait;
1485 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
1486 image_view=AcquireVirtualCacheView(image,exception);
1487 mask_view=AcquireAuthenticCacheView(mask_image,exception);
1488#if defined(MAGICKCORE_OPENMP_SUPPORT)
1489 #pragma omp parallel for schedule(static) shared(status) \
1490 magick_number_threads(image,image,image->rows,2)
1491#endif
1492 for (y=0; y < (ssize_t) image->rows; y++)
1493 {
1494 const Quantum
1495 *magick_restrict p;
1496
1497 Quantum
1498 *magick_restrict q;
1499
1500 ssize_t
1501 x;
1502
1503 if (status == MagickFalse)
1504 continue;
1505 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1506 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1507 exception);
1508 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1509 {
1510 status=MagickFalse;
1511 continue;
1512 }
1513 for (x=0; x < (ssize_t) image->columns; x++)
1514 {
1515 switch (type)
1516 {
1517 case ReadPixelMask:
1518 {
1519 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1520 break;
1521 }
1522 case WritePixelMask:
1523 {
1524 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1525 break;
1526 }
1527 default:
1528 {
1529 SetPixelGray(mask_image,GetPixelCompositeMask(image,p),q);
1530 break;
1531 }
1532 }
1533 p+=(ptrdiff_t) GetPixelChannels(image);
1534 q+=(ptrdiff_t) GetPixelChannels(mask_image);
1535 }
1536 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1537 status=MagickFalse;
1538 }
1539 mask_view=DestroyCacheView(mask_view);
1540 image_view=DestroyCacheView(image_view);
1541 if (status == MagickFalse)
1542 mask_image=DestroyImage(mask_image);
1543 return(mask_image);
1544}
1545
1546/*
1547%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1548% %
1549% %
1550% %
1551+ G e t I m a g e R e f e r e n c e C o u n t %
1552% %
1553% %
1554% %
1555%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1556%
1557% GetImageReferenceCount() returns the image reference count.
1558%
1559% The format of the GetReferenceCount method is:
1560%
1561% ssize_t GetImageReferenceCount(Image *image)
1562%
1563% A description of each parameter follows:
1564%
1565% o image: the image.
1566%
1567*/
1568MagickExport ssize_t GetImageReferenceCount(Image *image)
1569{
1570 ssize_t
1571 reference_count;
1572
1573 assert(image != (Image *) NULL);
1574 assert(image->signature == MagickCoreSignature);
1575 if (IsEventLogging() != MagickFalse)
1576 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1577 LockSemaphoreInfo(image->semaphore);
1578 reference_count=image->reference_count;
1579 UnlockSemaphoreInfo(image->semaphore);
1580 return(reference_count);
1581}
1582
1583/*
1584%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1585% %
1586% %
1587% %
1588% 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 %
1589% %
1590% %
1591% %
1592%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1593%
1594% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1595% image. A virtual pixel is any pixel access that is outside the boundaries
1596% of the image cache.
1597%
1598% The format of the GetImageVirtualPixelMethod() method is:
1599%
1600% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1601%
1602% A description of each parameter follows:
1603%
1604% o image: the image.
1605%
1606*/
1607MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1608{
1609 assert(image != (Image *) NULL);
1610 assert(image->signature == MagickCoreSignature);
1611 if (IsEventLogging() != MagickFalse)
1612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1613 return(GetPixelCacheVirtualMethod(image));
1614}
1615
1616/*
1617%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1618% %
1619% %
1620% %
1621% I n t e r p r e t I m a g e F i l e n a m e %
1622% %
1623% %
1624% %
1625%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1626%
1627% InterpretImageFilename() interprets embedded characters in an image filename.
1628% The filename length is returned.
1629%
1630% The format of the InterpretImageFilename method is:
1631%
1632% size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1633% const char *format,int value,char *filename,ExceptionInfo *exception)
1634%
1635% A description of each parameter follows.
1636%
1637% o image_info: the image info.
1638%
1639% o image: the image.
1640%
1641% o format: A filename describing the format to use to write the numeric
1642% argument. Only the first numeric format identifier is replaced.
1643%
1644% o value: Numeric value to substitute into format filename.
1645%
1646% o filename: return the formatted filename in this character buffer.
1647%
1648% o exception: return any errors or warnings in this structure.
1649%
1650*/
1651
1652static inline MagickBooleanType IsValidFormatSpecifier(const char *start,
1653 const char *end)
1654{
1655 char
1656 specifier = end[-1];
1657
1658 size_t
1659 length = end-start;
1660
1661 /*
1662 Is this a valid format specifier?
1663 */
1664 if ((specifier != 'd') && (specifier != 'x') && (specifier != 'o'))
1665 return(MagickFalse);
1666 if ((length == 1) && (*start == specifier))
1667 return(MagickTrue);
1668 if (length >= 2)
1669 {
1670 size_t
1671 i = 0;
1672
1673 if (*start == '0')
1674 {
1675 if ((length >= 3) && (start[1] == '0'))
1676 return(MagickFalse);
1677 i=1;
1678 }
1679 for ( ; i < (length-1); i++)
1680 if (isdigit((int) ((unsigned char) start[i])) == 0)
1681 return(MagickFalse);
1682 return(MagickTrue);
1683 }
1684 return(MagickFalse);
1685}
1686
1687MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1688 Image *image,const char *format,int value,char *filename,
1689 ExceptionInfo *exception)
1690{
1691 char
1692 *p = filename,
1693 pattern[MagickPathExtent];
1694
1695 const char
1696 *cursor = format;
1697
1698 assert(format != (const char *) NULL);
1699 assert(filename != (char *) NULL);
1700 if (IsStringTrue(GetImageOption(image_info,"filename:literal")) != MagickFalse)
1701 {
1702 (void) CopyMagickString(filename,format,MagickPathExtent);
1703 return(strlen(filename));
1704 }
1705 while ((*cursor != '\0') && ((p-filename) < ((ssize_t) MagickPathExtent-1)))
1706 {
1707 const char
1708 *specifier_start,
1709 *start;
1710
1711 if (*cursor != '%')
1712 {
1713 *p++=(*cursor++);
1714 continue;
1715 }
1716 start=cursor++; /* Skip '%' */
1717 if (*cursor == '%')
1718 {
1719 *p++='%';
1720 cursor++;
1721 continue;
1722 }
1723 specifier_start=cursor;
1724 while (isdigit((int) ((unsigned char) *cursor)) != 0)
1725 cursor++;
1726 if ((*cursor == 'd') || (*cursor == 'o') || (*cursor == 'x'))
1727 {
1728 const char
1729 *specifier_end = cursor+1;
1730
1731 if (IsValidFormatSpecifier(specifier_start,specifier_end) != MagickFalse)
1732 {
1733 char
1734 format_specifier[MagickPathExtent];
1735
1736 size_t
1737 length = cursor-specifier_start,
1738 pattern_length;
1739
1740 ssize_t
1741 count;
1742
1743 (void) snprintf(format_specifier,sizeof(format_specifier),
1744 "%%%.*s%c",(int) length,specifier_start,*cursor);
1745 count=FormatLocaleString(pattern,sizeof(pattern),format_specifier,
1746 value);
1747 pattern_length=strlen(pattern);
1748 if ((count <= 0) || ((size_t) count != pattern_length))
1749 return(0);
1750 if ((p-filename+pattern_length) >= MagickPathExtent)
1751 return(0);
1752 (void) CopyMagickString(p,pattern,MagickPathExtent-(p-filename));
1753 p+=pattern_length;
1754 cursor++;
1755 continue;
1756 }
1757 else
1758 {
1759 /*
1760 Invalid specifier — treat as literal.
1761 */
1762 cursor=start;
1763 *p++=(*cursor++);
1764 continue;
1765 }
1766 }
1767 if (*cursor == '[')
1768 {
1769 const char
1770 *end = strchr(cursor,']'),
1771 *option = (const char *) NULL;
1772
1773 size_t
1774 extent,
1775 option_length;
1776
1777 if (end == (const char *) NULL)
1778 continue;
1779 extent=(size_t) (end-cursor-1);
1780 if (extent >= sizeof(pattern))
1781 continue;
1782 (void) CopyMagickString(pattern,cursor+1,extent+1);
1783 pattern[extent]='\0';
1784 if (image != NULL)
1785 {
1786 option=GetImageProperty(image,pattern,exception);
1787 if (option == (const char *) NULL)
1788 option=GetImageArtifact(image,pattern);
1789 }
1790 if ((option == (const char *) NULL) &&
1791 (image_info != (ImageInfo *) NULL))
1792 option=GetImageOption(image_info,pattern);
1793 if (option == (const char *) NULL)
1794 continue;
1795 option_length=strlen(option);
1796 if ((p-filename+option_length) >= MagickPathExtent)
1797 return(0);
1798 (void) CopyMagickString(p,option,MagickPathExtent-(p-filename));
1799 p+=option_length;
1800 cursor=end+1;
1801 continue;
1802 }
1803 /*
1804 Invalid or unsupported specifier — treat as literal.
1805 */
1806 cursor=start;
1807 if ((p-filename+1) >= MagickPathExtent)
1808 return(0);
1809 *p++=(*cursor++);
1810 }
1811 *p='\0';
1812 return(strlen(filename));
1813}
1814
1815/*
1816%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1817% %
1818% %
1819% %
1820% I s H i g h D y n a m i c R a n g e I m a g e %
1821% %
1822% %
1823% %
1824%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1825%
1826% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1827% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1828% 0..65535.
1829%
1830% The format of the IsHighDynamicRangeImage method is:
1831%
1832% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1833% ExceptionInfo *exception)
1834%
1835% A description of each parameter follows:
1836%
1837% o image: the image.
1838%
1839% o exception: return any errors or warnings in this structure.
1840%
1841*/
1842MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1843 ExceptionInfo *exception)
1844{
1845#if !defined(MAGICKCORE_HDRI_SUPPORT)
1846 (void) image;
1847 (void) exception;
1848 return(MagickFalse);
1849#else
1850 CacheView
1851 *image_view;
1852
1853 MagickBooleanType
1854 hdri = MagickFalse;
1855
1856 ssize_t
1857 y;
1858
1859 assert(image != (Image *) NULL);
1860 assert(image->signature == MagickCoreSignature);
1861 if (IsEventLogging() != MagickFalse)
1862 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1863 image_view=AcquireVirtualCacheView(image,exception);
1864#if defined(MAGICKCORE_OPENMP_SUPPORT)
1865 #pragma omp parallel for schedule(static) shared(hdri) \
1866 magick_number_threads(image,image,image->rows,2)
1867#endif
1868 for (y=0; y < (ssize_t) image->rows; y++)
1869 {
1870 const Quantum
1871 *p;
1872
1873 ssize_t
1874 x;
1875
1876 if (hdri != MagickFalse)
1877 continue;
1878 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1879 if (p == (const Quantum *) NULL)
1880 continue;
1881 for (x=0; x < (ssize_t) image->columns; x++)
1882 {
1883 ssize_t
1884 i;
1885
1886 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1887 {
1888 double
1889 pixel;
1890
1891 PixelTrait
1892 traits;
1893
1894 traits=GetPixelChannelTraits(image,(PixelChannel) i);
1895 if (traits == UndefinedPixelTrait)
1896 continue;
1897 pixel=(double) p[i];
1898 if ((pixel < 0.0) || (pixel > (double) QuantumRange) ||
1899 (pixel != (double) ((QuantumAny) pixel)))
1900 {
1901 hdri=MagickTrue;
1902 break;
1903 }
1904 }
1905 if (hdri != MagickFalse)
1906 break;
1907 p+=(ptrdiff_t) GetPixelChannels(image);
1908 }
1909 }
1910 image_view=DestroyCacheView(image_view);
1911 return(hdri);
1912#endif
1913}
1914
1915/*
1916%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1917% %
1918% %
1919% %
1920% I s I m a g e O b j e c t %
1921% %
1922% %
1923% %
1924%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1925%
1926% IsImageObject() returns MagickTrue if the image sequence contains a valid
1927% set of image objects.
1928%
1929% The format of the IsImageObject method is:
1930%
1931% MagickBooleanType IsImageObject(const Image *image)
1932%
1933% A description of each parameter follows:
1934%
1935% o image: the image.
1936%
1937*/
1938MagickExport MagickBooleanType IsImageObject(const Image *image)
1939{
1940 const Image
1941 *p;
1942
1943 assert(image != (Image *) NULL);
1944 if (IsEventLogging() != MagickFalse)
1945 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1946 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1947 if (p->signature != MagickCoreSignature)
1948 return(MagickFalse);
1949 return(MagickTrue);
1950}
1951
1952/*
1953%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1954% %
1955% %
1956% %
1957% I s T a i n t I m a g e %
1958% %
1959% %
1960% %
1961%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1962%
1963% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1964% since it was first constituted.
1965%
1966% The format of the IsTaintImage method is:
1967%
1968% MagickBooleanType IsTaintImage(const Image *image)
1969%
1970% A description of each parameter follows:
1971%
1972% o image: the image.
1973%
1974*/
1975MagickExport MagickBooleanType IsTaintImage(const Image *image)
1976{
1977 char
1978 magick[MagickPathExtent],
1979 filename[MagickPathExtent];
1980
1981 const Image
1982 *p;
1983
1984 assert(image != (Image *) NULL);
1985 assert(image->signature == MagickCoreSignature);
1986 if (IsEventLogging() != MagickFalse)
1987 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1988 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1989 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
1990 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1991 {
1992 if (p->taint != MagickFalse)
1993 return(MagickTrue);
1994 if (LocaleCompare(p->magick,magick) != 0)
1995 return(MagickTrue);
1996 if (LocaleCompare(p->filename,filename) != 0)
1997 return(MagickTrue);
1998 }
1999 return(MagickFalse);
2000}
2001
2002/*
2003%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2004% %
2005% %
2006% %
2007% M o d i f y I m a g e %
2008% %
2009% %
2010% %
2011%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2012%
2013% ModifyImage() ensures that there is only a single reference to the image
2014% to be modified, updating the provided image pointer to point to a clone of
2015% the original image if necessary.
2016%
2017% The format of the ModifyImage method is:
2018%
2019% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2020%
2021% A description of each parameter follows:
2022%
2023% o image: the image.
2024%
2025% o exception: return any errors or warnings in this structure.
2026%
2027*/
2028MagickExport MagickBooleanType ModifyImage(Image **image,
2029 ExceptionInfo *exception)
2030{
2031 Image
2032 *clone_image;
2033
2034 assert(image != (Image **) NULL);
2035 assert(*image != (Image *) NULL);
2036 assert((*image)->signature == MagickCoreSignature);
2037 if (IsEventLogging() != MagickFalse)
2038 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2039 if (GetImageReferenceCount(*image) <= 1)
2040 return(MagickTrue);
2041 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
2042 LockSemaphoreInfo((*image)->semaphore);
2043 (*image)->reference_count--;
2044 UnlockSemaphoreInfo((*image)->semaphore);
2045 *image=clone_image;
2046 return(MagickTrue);
2047}
2048
2049/*
2050%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2051% %
2052% %
2053% %
2054% N e w M a g i c k I m a g e %
2055% %
2056% %
2057% %
2058%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2059%
2060% NewMagickImage() creates a blank image canvas of the specified size and
2061% background color.
2062%
2063% The format of the NewMagickImage method is:
2064%
2065% Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2066% const size_t height,const PixelInfo *background,
2067% ExceptionInfo *exception)
2068%
2069% A description of each parameter follows:
2070%
2071% o image: the image.
2072%
2073% o width: the image width.
2074%
2075% o height: the image height.
2076%
2077% o background: the image color.
2078%
2079% o exception: return any errors or warnings in this structure.
2080%
2081*/
2082MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2083 const size_t width,const size_t height,const PixelInfo *background,
2084 ExceptionInfo *exception)
2085{
2086 CacheView
2087 *image_view;
2088
2089 Image
2090 *image;
2091
2092 MagickBooleanType
2093 status;
2094
2095 ssize_t
2096 y;
2097
2098 assert(image_info != (const ImageInfo *) NULL);
2099 assert(image_info->signature == MagickCoreSignature);
2100 assert(background != (const PixelInfo *) NULL);
2101 if (IsEventLogging() != MagickFalse)
2102 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2103 image=AcquireImage(image_info,exception);
2104 image->columns=width;
2105 image->rows=height;
2106 image->colorspace=background->colorspace;
2107 image->alpha_trait=background->alpha_trait;
2108 image->fuzz=background->fuzz;
2109 image->depth=background->depth;
2110 status=MagickTrue;
2111 image_view=AcquireAuthenticCacheView(image,exception);
2112#if defined(MAGICKCORE_OPENMP_SUPPORT)
2113 #pragma omp parallel for schedule(static) shared(status) \
2114 magick_number_threads(image,image,image->rows,2)
2115#endif
2116 for (y=0; y < (ssize_t) image->rows; y++)
2117 {
2118 Quantum
2119 *magick_restrict q;
2120
2121 ssize_t
2122 x;
2123
2124 if (status == MagickFalse)
2125 continue;
2126 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2127 if (q == (Quantum *) NULL)
2128 {
2129 status=MagickFalse;
2130 continue;
2131 }
2132 for (x=0; x < (ssize_t) image->columns; x++)
2133 {
2134 SetPixelViaPixelInfo(image,background,q);
2135 q+=(ptrdiff_t) GetPixelChannels(image);
2136 }
2137 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2138 status=MagickFalse;
2139 }
2140 image_view=DestroyCacheView(image_view);
2141 if (status == MagickFalse)
2142 image=DestroyImage(image);
2143 return(image);
2144}
2145
2146/*
2147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2148% %
2149% %
2150% %
2151% R e f e r e n c e I m a g e %
2152% %
2153% %
2154% %
2155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2156%
2157% ReferenceImage() increments the reference count associated with an image
2158% returning a pointer to the image.
2159%
2160% The format of the ReferenceImage method is:
2161%
2162% Image *ReferenceImage(Image *image)
2163%
2164% A description of each parameter follows:
2165%
2166% o image: the image.
2167%
2168*/
2169MagickExport Image *ReferenceImage(Image *image)
2170{
2171 assert(image != (Image *) NULL);
2172 assert(image->signature == MagickCoreSignature);
2173 if (IsEventLogging() != MagickFalse)
2174 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2175 LockSemaphoreInfo(image->semaphore);
2176 image->reference_count++;
2177 UnlockSemaphoreInfo(image->semaphore);
2178 return(image);
2179}
2180
2181/*
2182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2183% %
2184% %
2185% %
2186% R e s e t I m a g e P a g e %
2187% %
2188% %
2189% %
2190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2191%
2192% ResetImagePage() resets the image page canvas and position.
2193%
2194% The format of the ResetImagePage method is:
2195%
2196% MagickBooleanType ResetImagePage(Image *image,const char *page)
2197%
2198% A description of each parameter follows:
2199%
2200% o image: the image.
2201%
2202% o page: the relative page specification.
2203%
2204*/
2205MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2206{
2207 MagickStatusType
2208 flags;
2209
2211 geometry;
2212
2213 assert(image != (Image *) NULL);
2214 assert(image->signature == MagickCoreSignature);
2215 if (IsEventLogging() != MagickFalse)
2216 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2217 flags=ParseAbsoluteGeometry(page,&geometry);
2218 if ((flags & WidthValue) != 0)
2219 {
2220 if ((flags & HeightValue) == 0)
2221 geometry.height=geometry.width;
2222 image->page.width=geometry.width;
2223 image->page.height=geometry.height;
2224 }
2225 if ((flags & AspectValue) != 0)
2226 {
2227 if ((flags & XValue) != 0)
2228 image->page.x+=geometry.x;
2229 if ((flags & YValue) != 0)
2230 image->page.y+=geometry.y;
2231 }
2232 else
2233 {
2234 if ((flags & XValue) != 0)
2235 {
2236 image->page.x=geometry.x;
2237 if ((image->page.width == 0) && (geometry.x > 0))
2238 image->page.width=(size_t) ((ssize_t) image->columns+geometry.x);
2239 }
2240 if ((flags & YValue) != 0)
2241 {
2242 image->page.y=geometry.y;
2243 if ((image->page.height == 0) && (geometry.y > 0))
2244 image->page.height=(size_t) ((ssize_t) image->rows+geometry.y);
2245 }
2246 }
2247 return(MagickTrue);
2248}
2249
2250/*
2251%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2252% %
2253% %
2254% %
2255% R e s e t I m a g e P i x e l s %
2256% %
2257% %
2258% %
2259%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2260%
2261% ResetImagePixels() reset the image pixels, that is, all the pixel components
2262% are zeroed.
2263%
2264% The format of the SetImage method is:
2265%
2266% MagickBooleanType ResetImagePixels(Image *image,
2267% ExceptionInfo *exception)
2268%
2269% A description of each parameter follows:
2270%
2271% o image: the image.
2272%
2273% o exception: return any errors or warnings in this structure.
2274%
2275*/
2276MagickExport MagickBooleanType ResetImagePixels(Image *image,
2277 ExceptionInfo *exception)
2278{
2279 CacheView
2280 *image_view;
2281
2282 MagickBooleanType
2283 status;
2284
2285 size_t
2286 length;
2287
2288 ssize_t
2289 y;
2290
2291 void
2292 *pixels;
2293
2294 assert(image != (Image *) NULL);
2295 assert(image->signature == MagickCoreSignature);
2296 if (IsEventLogging() != MagickFalse)
2297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2298 pixels=AcquirePixelCachePixels(image,&length,exception);
2299 if (pixels != (void *) NULL)
2300 {
2301 /*
2302 Reset in-core image pixels.
2303 */
2304 (void) memset(pixels,0,length);
2305 return(MagickTrue);
2306 }
2307 /*
2308 Reset image pixels.
2309 */
2310 status=MagickTrue;
2311 image_view=AcquireAuthenticCacheView(image,exception);
2312#if defined(MAGICKCORE_OPENMP_SUPPORT)
2313 #pragma omp parallel for schedule(static) shared(status) \
2314 magick_number_threads(image,image,image->rows,2)
2315#endif
2316 for (y=0; y < (ssize_t) image->rows; y++)
2317 {
2318 Quantum
2319 *magick_restrict q;
2320
2321 ssize_t
2322 x;
2323
2324 if (status == MagickFalse)
2325 continue;
2326 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2327 if (q == (Quantum *) NULL)
2328 {
2329 status=MagickFalse;
2330 continue;
2331 }
2332 for (x=0; x < (ssize_t) image->columns; x++)
2333 {
2334 (void) memset(q,0,GetPixelChannels(image)*sizeof(Quantum));
2335 q+=(ptrdiff_t) GetPixelChannels(image);
2336 }
2337 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2338 status=MagickFalse;
2339 }
2340 image_view=DestroyCacheView(image_view);
2341 return(status);
2342}
2343
2344/*
2345%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2346% %
2347% %
2348% %
2349% S e t I m a g e A l p h a %
2350% %
2351% %
2352% %
2353%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2354%
2355% SetImageAlpha() sets the alpha levels of the image.
2356%
2357% The format of the SetImageAlpha method is:
2358%
2359% MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2360% ExceptionInfo *exception)
2361%
2362% A description of each parameter follows:
2363%
2364% o image: the image.
2365%
2366% o alpha: the level of transparency: 0 is fully transparent and QuantumRange
2367% is fully opaque.
2368%
2369% o exception: return any errors or warnings in this structure.
2370%
2371*/
2372MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2373 ExceptionInfo *exception)
2374{
2375 CacheView
2376 *image_view;
2377
2378 MagickBooleanType
2379 status;
2380
2381 ssize_t
2382 y;
2383
2384 assert(image != (Image *) NULL);
2385 assert(image->signature == MagickCoreSignature);
2386 if (IsEventLogging() != MagickFalse)
2387 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2388 image->alpha_trait=BlendPixelTrait;
2389 status=MagickTrue;
2390 image_view=AcquireAuthenticCacheView(image,exception);
2391#if defined(MAGICKCORE_OPENMP_SUPPORT)
2392 #pragma omp parallel for schedule(static) shared(status) \
2393 magick_number_threads(image,image,image->rows,2)
2394#endif
2395 for (y=0; y < (ssize_t) image->rows; y++)
2396 {
2397 Quantum
2398 *magick_restrict q;
2399
2400 ssize_t
2401 x;
2402
2403 if (status == MagickFalse)
2404 continue;
2405 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2406 if (q == (Quantum *) NULL)
2407 {
2408 status=MagickFalse;
2409 continue;
2410 }
2411 for (x=0; x < (ssize_t) image->columns; x++)
2412 {
2413 if (GetPixelWriteMask(image,q) > (QuantumRange/2))
2414 SetPixelAlpha(image,alpha,q);
2415 q+=(ptrdiff_t) GetPixelChannels(image);
2416 }
2417 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2418 status=MagickFalse;
2419 }
2420 image_view=DestroyCacheView(image_view);
2421 return(status);
2422}
2423
2424/*
2425%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2426% %
2427% %
2428% %
2429% S e t I m a g e B a c k g r o u n d C o l o r %
2430% %
2431% %
2432% %
2433%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2434%
2435% SetImageBackgroundColor() initializes the image pixels to the image
2436% background color. The background color is defined by the background_color
2437% member of the image structure.
2438%
2439% The format of the SetImage method is:
2440%
2441% MagickBooleanType SetImageBackgroundColor(Image *image,
2442% ExceptionInfo *exception)
2443%
2444% A description of each parameter follows:
2445%
2446% o image: the image.
2447%
2448% o exception: return any errors or warnings in this structure.
2449%
2450*/
2451MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2452 ExceptionInfo *exception)
2453{
2454 CacheView
2455 *image_view;
2456
2457 MagickBooleanType
2458 status;
2459
2460 PixelInfo
2461 background;
2462
2463 ssize_t
2464 y;
2465
2466 assert(image != (Image *) NULL);
2467 assert(image->signature == MagickCoreSignature);
2468 if (IsEventLogging() != MagickFalse)
2469 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2470 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
2471 return(MagickFalse);
2472 if ((image->background_color.alpha_trait != UndefinedPixelTrait) &&
2473 ((image->alpha_trait & BlendPixelTrait) == 0))
2474 (void) SetImageAlphaChannel(image,ActivateAlphaChannel,exception);
2475 ConformPixelInfo(image,&image->background_color,&background,exception);
2476 /*
2477 Set image background color.
2478 */
2479 status=MagickTrue;
2480 image_view=AcquireAuthenticCacheView(image,exception);
2481#if defined(MAGICKCORE_OPENMP_SUPPORT)
2482 #pragma omp parallel for schedule(static) shared(status) \
2483 magick_number_threads(image,image,image->rows,2)
2484#endif
2485 for (y=0; y < (ssize_t) image->rows; y++)
2486 {
2487 Quantum
2488 *magick_restrict q;
2489
2490 ssize_t
2491 x;
2492
2493 if (status == MagickFalse)
2494 continue;
2495 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2496 if (q == (Quantum *) NULL)
2497 {
2498 status=MagickFalse;
2499 continue;
2500 }
2501 for (x=0; x < (ssize_t) image->columns; x++)
2502 {
2503 SetPixelViaPixelInfo(image,&background,q);
2504 q+=(ptrdiff_t) GetPixelChannels(image);
2505 }
2506 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2507 status=MagickFalse;
2508 }
2509 image_view=DestroyCacheView(image_view);
2510 return(status);
2511}
2512
2513/*
2514%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2515% %
2516% %
2517% %
2518% S e t I m a g e C h a n n e l M a s k %
2519% %
2520% %
2521% %
2522%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2523%
2524% SetImageChannelMask() sets the image channel mask from the specified channel
2525% mask.
2526%
2527% The format of the SetImageChannelMask method is:
2528%
2529% ChannelType SetImageChannelMask(Image *image,
2530% const ChannelType channel_mask)
2531%
2532% A description of each parameter follows:
2533%
2534% o image: the image.
2535%
2536% o channel_mask: the channel mask.
2537%
2538*/
2539MagickExport ChannelType SetImageChannelMask(Image *image,
2540 const ChannelType channel_mask)
2541{
2542 return(SetPixelChannelMask(image,channel_mask));
2543}
2544
2545/*
2546%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2547% %
2548% %
2549% %
2550% S e t I m a g e C o l o r %
2551% %
2552% %
2553% %
2554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2555%
2556% SetImageColor() set the entire image canvas to the specified color.
2557%
2558% The format of the SetImageColor method is:
2559%
2560% MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2561% ExceptionInfo *exception)
2562%
2563% A description of each parameter follows:
2564%
2565% o image: the image.
2566%
2567% o background: the image color.
2568%
2569% o exception: return any errors or warnings in this structure.
2570%
2571*/
2572MagickExport MagickBooleanType SetImageColor(Image *image,
2573 const PixelInfo *color,ExceptionInfo *exception)
2574{
2575 CacheView
2576 *image_view;
2577
2578 MagickBooleanType
2579 status;
2580
2581 ssize_t
2582 y;
2583
2584 assert(image != (Image *) NULL);
2585 assert(image->signature == MagickCoreSignature);
2586 assert(color != (const PixelInfo *) NULL);
2587 if (IsEventLogging() != MagickFalse)
2588 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2589 image->colorspace=color->colorspace;
2590 image->alpha_trait=color->alpha_trait;
2591 image->fuzz=color->fuzz;
2592 image->depth=color->depth;
2593 status=MagickTrue;
2594 image_view=AcquireAuthenticCacheView(image,exception);
2595#if defined(MAGICKCORE_OPENMP_SUPPORT)
2596 #pragma omp parallel for schedule(static) shared(status) \
2597 magick_number_threads(image,image,image->rows,2)
2598#endif
2599 for (y=0; y < (ssize_t) image->rows; y++)
2600 {
2601 Quantum
2602 *magick_restrict q;
2603
2604 ssize_t
2605 x;
2606
2607 if (status == MagickFalse)
2608 continue;
2609 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2610 if (q == (Quantum *) NULL)
2611 {
2612 status=MagickFalse;
2613 continue;
2614 }
2615 for (x=0; x < (ssize_t) image->columns; x++)
2616 {
2617 SetPixelViaPixelInfo(image,color,q);
2618 q+=(ptrdiff_t) GetPixelChannels(image);
2619 }
2620 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2621 status=MagickFalse;
2622 }
2623 image_view=DestroyCacheView(image_view);
2624 return(status);
2625}
2626
2627/*
2628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2629% %
2630% %
2631% %
2632% S e t I m a g e S t o r a g e C l a s s %
2633% %
2634% %
2635% %
2636%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2637%
2638% SetImageStorageClass() sets the image class: DirectClass for true color
2639% images or PseudoClass for colormapped images.
2640%
2641% The format of the SetImageStorageClass method is:
2642%
2643% MagickBooleanType SetImageStorageClass(Image *image,
2644% const ClassType storage_class,ExceptionInfo *exception)
2645%
2646% A description of each parameter follows:
2647%
2648% o image: the image.
2649%
2650% o storage_class: The image class.
2651%
2652% o exception: return any errors or warnings in this structure.
2653%
2654*/
2655MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2656 const ClassType storage_class,ExceptionInfo *exception)
2657{
2658 assert(image != (Image *) NULL);
2659 assert(image->signature == MagickCoreSignature);
2660 assert(exception != (ExceptionInfo *) NULL);
2661 assert(exception->signature == MagickCoreSignature);
2662 if (IsEventLogging() != MagickFalse)
2663 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2664 image->storage_class=storage_class;
2665 return(SyncImagePixelCache(image,exception));
2666}
2667
2668/*
2669%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2670% %
2671% %
2672% %
2673% S e t I m a g e E x t e n t %
2674% %
2675% %
2676% %
2677%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2678%
2679% SetImageExtent() sets the image size (i.e. columns & rows).
2680%
2681% The format of the SetImageExtent method is:
2682%
2683% MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2684% const size_t rows,ExceptionInfo *exception)
2685%
2686% A description of each parameter follows:
2687%
2688% o image: the image.
2689%
2690% o columns: The image width in pixels.
2691%
2692% o rows: The image height in pixels.
2693%
2694% o exception: return any errors or warnings in this structure.
2695%
2696*/
2697MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
2698 const size_t rows,ExceptionInfo *exception)
2699{
2700 if ((columns == 0) || (rows == 0))
2701 ThrowBinaryException(ImageError,"NegativeOrZeroImageSize",image->filename);
2702 image->columns=columns;
2703 image->rows=rows;
2704 if (image->depth == 0)
2705 {
2706 image->depth=8;
2707 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2708 "ImageDepthNotSupported","`%s'",image->filename);
2709 }
2710 if (image->depth > (8*sizeof(MagickSizeType)))
2711 {
2712 image->depth=8*sizeof(MagickSizeType);
2713 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2714 "ImageDepthNotSupported","`%s'",image->filename);
2715 }
2716 return(SyncImagePixelCache(image,exception));
2717}
2718
2719/*
2720%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2721% %
2722% %
2723% %
2724+ S e t I m a g e I n f o %
2725% %
2726% %
2727% %
2728%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2729%
2730% SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
2731% It is set to a type of image format based on the prefix or suffix of the
2732% filename. For example, 'ps:image' returns PS indicating a Postscript image.
2733% JPEG is returned for this filename: 'image.jpg'. The filename prefix has
2734% precedence over the suffix. Use an optional index enclosed in brackets
2735% after a file name to specify a desired scene of a multi-resolution image
2736% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2737% indicates success.
2738%
2739% The format of the SetImageInfo method is:
2740%
2741% MagickBooleanType SetImageInfo(ImageInfo *image_info,
2742% const unsigned int frames,ExceptionInfo *exception)
2743%
2744% A description of each parameter follows:
2745%
2746% o image_info: the image info.
2747%
2748% o frames: the number of images you intend to write.
2749%
2750% o exception: return any errors or warnings in this structure.
2751%
2752*/
2753
2754static const MagickInfo *SetImageInfoFromExtension(ImageInfo *image_info,
2755 const char *component,char *magic,ExceptionInfo *exception)
2756{
2757 const MagickInfo
2758 *magick_info;
2759
2760 MagickFormatType
2761 format_type;
2762
2763 ssize_t
2764 i;
2765
2766 static const char
2767 *format_type_formats[] =
2768 {
2769 "AUTOTRACE",
2770 "BROWSE",
2771 "DCRAW",
2772 "EDIT",
2773 "LAUNCH",
2774 "MPEG:DECODE",
2775 "MPEG:ENCODE",
2776 "PRINT",
2777 "PS:ALPHA",
2778 "PS:CMYK",
2779 "PS:COLOR",
2780 "PS:GRAY",
2781 "PS:MONO",
2782 "SCAN",
2783 "SHOW",
2784 "WIN",
2785 (char *) NULL
2786 };
2787
2788 /*
2789 User specified image format.
2790 */
2791 (void) CopyMagickString(magic,component,MagickPathExtent);
2792 LocaleUpper(magic);
2793 /*
2794 Look for explicit image formats.
2795 */
2796 format_type=UndefinedFormatType;
2797 magick_info=GetMagickInfo(magic,exception);
2798 if ((magick_info != (const MagickInfo *) NULL) &&
2799 (magick_info->format_type != UndefinedFormatType))
2800 format_type=magick_info->format_type;
2801 i=0;
2802 while ((format_type == UndefinedFormatType) &&
2803 (format_type_formats[i] != (char *) NULL))
2804 {
2805 if ((*magic == *format_type_formats[i]) &&
2806 (LocaleCompare(magic,format_type_formats[i]) == 0))
2807 format_type=ExplicitFormatType;
2808 i++;
2809 }
2810 if (format_type == UndefinedFormatType)
2811 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2812 else
2813 if (format_type == ExplicitFormatType)
2814 {
2815 image_info->affirm=MagickTrue;
2816 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2817 }
2818 if (LocaleCompare(magic,"RGB") == 0)
2819 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2820 return(magick_info);
2821}
2822
2823MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
2824 const unsigned int frames,ExceptionInfo *exception)
2825{
2826 char
2827 component[MagickPathExtent],
2828 magic[MagickPathExtent],
2829 path[MagickPathExtent],
2830 *q;
2831
2832 const MagicInfo
2833 *magic_info;
2834
2835 const MagickInfo
2836 *magick_info;
2837
2839 *sans_exception;
2840
2841 Image
2842 *image;
2843
2844 MagickBooleanType
2845 status;
2846
2847 const char
2848 *p;
2849
2850 ssize_t
2851 count;
2852
2853 /*
2854 Look for 'image.format' in filename.
2855 */
2856 assert(image_info != (ImageInfo *) NULL);
2857 assert(image_info->signature == MagickCoreSignature);
2858 if (IsEventLogging() != MagickFalse)
2859 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2860 image_info->filename);
2861 *component='\0';
2862 GetPathComponent(image_info->filename,SubimagePath,component);
2863 if (*component != '\0')
2864 {
2865 /*
2866 Look for scene specification (e.g. img0001.pcd[4]).
2867 */
2868 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
2869 {
2870 if (IsGeometry(component) != MagickFalse)
2871 (void) CloneString(&image_info->extract,component);
2872 }
2873 else
2874 {
2875 size_t
2876 first,
2877 last;
2878
2879 (void) CloneString(&image_info->scenes,component);
2880 image_info->scene=StringToUnsignedLong(image_info->scenes);
2881 image_info->number_scenes=image_info->scene;
2882 p=image_info->scenes;
2883 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2884 {
2885 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2886 p++;
2887 first=(size_t) strtol(p,&q,10);
2888 last=first;
2889 while (isspace((int) ((unsigned char) *q)) != 0)
2890 q++;
2891 if (*q == '-')
2892 last=(size_t) strtol(q+1,&q,10);
2893 if (first > last)
2894 Swap(first,last);
2895 if (first < image_info->scene)
2896 image_info->scene=first;
2897 if (last > image_info->number_scenes)
2898 image_info->number_scenes=last;
2899 p=q;
2900 }
2901 image_info->number_scenes-=image_info->scene-1;
2902 }
2903 }
2904 *component='\0';
2905 if (*image_info->magick == '\0')
2906 GetPathComponent(image_info->filename,ExtensionPath,component);
2907 if (*component != '\0')
2908 {
2909 /*
2910 Base path sans any compression extension.
2911 */
2912 GetPathComponent(image_info->filename,BasePathSansCompressExtension,path);
2913 GetPathComponent(path,ExtensionPath,component);
2914 }
2915 image_info->affirm=MagickFalse;
2916 sans_exception=AcquireExceptionInfo();
2917 if ((*component != '\0') && (IsGlob(component) == MagickFalse))
2918 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2919 sans_exception);
2920 /*
2921 Look for explicit 'format:image' in filename.
2922 */
2923 *magic='\0';
2924 GetPathComponent(image_info->filename,MagickPath,magic);
2925 if (*magic == '\0')
2926 {
2927 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
2928 magick_info=GetMagickInfo(magic,sans_exception);
2929 if ((magick_info != (const MagickInfo *) NULL) &&
2930 (magick_info->format_type == ExplicitFormatType))
2931 image_info->affirm=MagickTrue;
2932 if (frames == 0)
2933 GetPathComponent(image_info->filename,CanonicalPath,component);
2934 else
2935 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2936 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
2937 }
2938 else
2939 {
2940 const DelegateInfo
2941 *delegate_info;
2942
2943 /*
2944 User specified image format.
2945 */
2946 LocaleUpper(magic);
2947 magick_info=GetMagickInfo(magic,sans_exception);
2948 delegate_info=(const DelegateInfo *) NULL;
2949 if (magick_info == (const MagickInfo *) NULL)
2950 {
2951 delegate_info=GetDelegateInfo(magic,"*",sans_exception);
2952 if (delegate_info == (const DelegateInfo *) NULL)
2953 delegate_info=GetDelegateInfo("*",magic,sans_exception);
2954 if ((delegate_info == (const DelegateInfo *) NULL) &&
2955 ((*component != '\0') && (IsGlob(component) == MagickFalse)))
2956 {
2957 /*
2958 Retry in case GetMagickInfo loaded a custom module.
2959 */
2960 magick_info=SetImageInfoFromExtension(image_info,component,magic,
2961 sans_exception);
2962 }
2963 }
2964 if (((magick_info != (const MagickInfo *) NULL) ||
2965 (delegate_info != (const DelegateInfo *) NULL)) &&
2966 (IsMagickConflict(magic) == MagickFalse))
2967 {
2968 image_info->affirm=MagickTrue;
2969 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
2970 GetPathComponent(image_info->filename,CanonicalPath,component);
2971 (void) CopyMagickString(image_info->filename,component,
2972 MagickPathExtent);
2973 }
2974 }
2975 sans_exception=DestroyExceptionInfo(sans_exception);
2976 if ((magick_info == (const MagickInfo *) NULL) ||
2977 (GetMagickEndianSupport(magick_info) == MagickFalse))
2978 image_info->endian=UndefinedEndian;
2979 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2980 {
2981 /*
2982 Test for multiple image support (e.g. image%02d.png).
2983 */
2984 (void) InterpretImageFilename(image_info,(Image *) NULL,
2985 image_info->filename,(int) image_info->scene,component,exception);
2986 if ((LocaleCompare(component,image_info->filename) != 0) &&
2987 (strchr(component,'%') == (char *) NULL))
2988 image_info->adjoin=MagickFalse;
2989 }
2990 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2991 {
2992 /*
2993 Some image formats do not support multiple frames per file.
2994 */
2995 magick_info=GetMagickInfo(magic,exception);
2996 if (magick_info != (const MagickInfo *) NULL)
2997 if (GetMagickAdjoin(magick_info) == MagickFalse)
2998 image_info->adjoin=MagickFalse;
2999 }
3000 if (image_info->affirm != MagickFalse)
3001 return(MagickTrue);
3002 if (frames == 0)
3003 {
3004 unsigned char
3005 *magick;
3006
3007 size_t
3008 magick_size;
3009
3010 /*
3011 Determine the image format from the first few bytes of the file.
3012 */
3013 magick_size=GetMagicPatternExtent(exception);
3014 if (magick_size == 0)
3015 return(MagickFalse);
3016 image=AcquireImage(image_info,exception);
3017 (void) CopyMagickString(image->filename,image_info->filename,
3018 MagickPathExtent);
3019 sans_exception=AcquireExceptionInfo();
3020 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3021 sans_exception=DestroyExceptionInfo(sans_exception);
3022 if (status == MagickFalse)
3023 {
3024 image=DestroyImage(image);
3025 return(MagickFalse);
3026 }
3027 if ((IsBlobSeekable(image) == MagickFalse) ||
3028 (IsBlobExempt(image) != MagickFalse))
3029 {
3030 /*
3031 Copy image to seekable temporary file.
3032 */
3033 *component='\0';
3034 status=ImageToFile(image,component,exception);
3035 if (CloseBlob(image) == MagickFalse)
3036 status=MagickFalse;
3037 if (status == MagickFalse)
3038 {
3039 (void) RelinquishUniqueFileResource(component);
3040 image=DestroyImage(image);
3041 return(MagickFalse);
3042 }
3043 SetImageInfoFile(image_info,(FILE *) NULL);
3044 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3045 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3046 if (status == MagickFalse)
3047 {
3048 (void) RelinquishUniqueFileResource(component);
3049 image=DestroyImage(image);
3050 return(MagickFalse);
3051 }
3052 (void) CopyMagickString(image_info->filename,component,
3053 MagickPathExtent);
3054 image_info->temporary=MagickTrue;
3055 }
3056 magick=(unsigned char *) AcquireQuantumMemory(1,magick_size);
3057 if (magick == (unsigned char *) NULL)
3058 {
3059 (void) CloseBlob(image);
3060 image=DestroyImage(image);
3061 return(MagickFalse);
3062 }
3063 (void) memset(magick,0,magick_size);
3064 count=ReadBlob(image,magick_size,magick);
3065 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3066 (void) CloseBlob(image);
3067 image=DestroyImage(image);
3068 /*
3069 Check magic cache.
3070 */
3071 sans_exception=AcquireExceptionInfo();
3072 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3073 magick=(unsigned char *) RelinquishMagickMemory(magick);
3074 if ((magic_info != (const MagicInfo *) NULL) &&
3075 (GetMagicName(magic_info) != (char *) NULL))
3076 {
3077 /*
3078 Try to use magick_info that was determined earlier by the extension
3079 */
3080 if ((magick_info != (const MagickInfo *) NULL) &&
3081 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3082 (LocaleCompare(magick_info->magick_module,GetMagicName(
3083 magic_info)) == 0))
3084 (void) CopyMagickString(image_info->magick,magick_info->name,
3085 MagickPathExtent);
3086 else
3087 {
3088 (void) CopyMagickString(image_info->magick,GetMagicName(
3089 magic_info),MagickPathExtent);
3090 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3091 }
3092 if ((magick_info == (const MagickInfo *) NULL) ||
3093 (GetMagickEndianSupport(magick_info) == MagickFalse))
3094 image_info->endian=UndefinedEndian;
3095 sans_exception=DestroyExceptionInfo(sans_exception);
3096 return(MagickTrue);
3097 }
3098 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3099 if ((magick_info == (const MagickInfo *) NULL) ||
3100 (GetMagickEndianSupport(magick_info) == MagickFalse))
3101 image_info->endian=UndefinedEndian;
3102 sans_exception=DestroyExceptionInfo(sans_exception);
3103 }
3104 return(MagickTrue);
3105}
3106
3107/*
3108%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3109% %
3110% %
3111% %
3112% S e t I m a g e I n f o B l o b %
3113% %
3114% %
3115% %
3116%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3117%
3118% SetImageInfoBlob() sets the image info blob member.
3119%
3120% The format of the SetImageInfoBlob method is:
3121%
3122% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3123% const size_t length)
3124%
3125% A description of each parameter follows:
3126%
3127% o image_info: the image info.
3128%
3129% o blob: the blob.
3130%
3131% o length: the blob length.
3132%
3133*/
3134MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3135 const size_t length)
3136{
3137 assert(image_info != (ImageInfo *) NULL);
3138 assert(image_info->signature == MagickCoreSignature);
3139 if (IsEventLogging() != MagickFalse)
3140 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3141 image_info->filename);
3142 image_info->blob=(void *) blob;
3143 image_info->length=length;
3144}
3145
3146/*
3147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3148% %
3149% %
3150% %
3151% S e t I m a g e I n f o C u s t o m S t r e a m %
3152% %
3153% %
3154% %
3155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3156%
3157% SetImageInfoCustomStream() sets the image info custom stream handlers.
3158%
3159% The format of the SetImageInfoCustomStream method is:
3160%
3161% void SetImageInfoCustomStream(ImageInfo *image_info,
3162% CustomStreamInfo *custom_stream)
3163%
3164% A description of each parameter follows:
3165%
3166% o image_info: the image info.
3167%
3168% o custom_stream: your custom stream methods.
3169%
3170*/
3171MagickExport void SetImageInfoCustomStream(ImageInfo *image_info,
3172 CustomStreamInfo *custom_stream)
3173{
3174 assert(image_info != (ImageInfo *) NULL);
3175 assert(image_info->signature == MagickCoreSignature);
3176 if (IsEventLogging() != MagickFalse)
3177 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3178 image_info->filename);
3179 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3180}
3181
3182/*
3183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3184% %
3185% %
3186% %
3187% S e t I m a g e I n f o F i l e %
3188% %
3189% %
3190% %
3191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3192%
3193% SetImageInfoFile() sets the image info file member.
3194%
3195% The format of the SetImageInfoFile method is:
3196%
3197% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3198%
3199% A description of each parameter follows:
3200%
3201% o image_info: the image info.
3202%
3203% o file: the file.
3204%
3205*/
3206MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3207{
3208 assert(image_info != (ImageInfo *) NULL);
3209 assert(image_info->signature == MagickCoreSignature);
3210 if (IsEventLogging() != MagickFalse)
3211 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3212 image_info->filename);
3213 image_info->file=file;
3214}
3215
3216/*
3217%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3218% %
3219% %
3220% %
3221% S e t I m a g e M a s k %
3222% %
3223% %
3224% %
3225%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3226%
3227% SetImageMask() associates a mask with the image. The mask must be the same
3228% dimensions as the image.
3229%
3230% The format of the SetImageMask method is:
3231%
3232% MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3233% const Image *mask,ExceptionInfo *exception)
3234%
3235% A description of each parameter follows:
3236%
3237% o image: the image.
3238%
3239% o type: the mask type, ReadPixelMask or WritePixelMask.
3240%
3241% o mask: the image mask.
3242%
3243% o exception: return any errors or warnings in this structure.
3244%
3245*/
3246MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3247 const Image *mask,ExceptionInfo *exception)
3248{
3249 CacheView
3250 *mask_view,
3251 *image_view;
3252
3253 MagickBooleanType
3254 status;
3255
3256 ssize_t
3257 y;
3258
3259 /*
3260 Set image mask.
3261 */
3262 assert(image != (Image *) NULL);
3263 if (IsEventLogging() != MagickFalse)
3264 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3265 assert(image->signature == MagickCoreSignature);
3266 if (mask == (const Image *) NULL)
3267 {
3268 switch (type)
3269 {
3270 case ReadPixelMask:
3271 {
3272 image->channels=(ChannelType) ((unsigned int) image->channels &
3273 (unsigned int) ~ReadMaskChannel);
3274 break;
3275 }
3276 case WritePixelMask:
3277 {
3278 image->channels=(ChannelType) ((unsigned int) image->channels &
3279 (unsigned int) ~WriteMaskChannel);
3280 magick_fallthrough;
3281 }
3282 default:
3283 {
3284 image->channels=(ChannelType) ((unsigned int) image->channels &
3285 (unsigned int) ~CompositeMaskChannel);
3286 break;
3287 }
3288 }
3289 return(SyncImagePixelCache(image,exception));
3290 }
3291 switch (type)
3292 {
3293 case ReadPixelMask:
3294 {
3295 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3296 break;
3297 }
3298 case WritePixelMask:
3299 {
3300 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3301 break;
3302 }
3303 default:
3304 {
3305 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3306 break;
3307 }
3308 }
3309 if (SyncImagePixelCache(image,exception) == MagickFalse)
3310 return(MagickFalse);
3311 status=MagickTrue;
3312 image->mask_trait=UpdatePixelTrait;
3313 mask_view=AcquireVirtualCacheView(mask,exception);
3314 image_view=AcquireAuthenticCacheView(image,exception);
3315#if defined(MAGICKCORE_OPENMP_SUPPORT)
3316 #pragma omp parallel for schedule(static) shared(status) \
3317 magick_number_threads(mask,image,image->rows,2)
3318#endif
3319 for (y=0; y < (ssize_t) image->rows; y++)
3320 {
3321 const Quantum
3322 *magick_restrict p;
3323
3324 Quantum
3325 *magick_restrict q;
3326
3327 ssize_t
3328 x;
3329
3330 if (status == MagickFalse)
3331 continue;
3332 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3333 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3334 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3335 {
3336 status=MagickFalse;
3337 continue;
3338 }
3339 for (x=0; x < (ssize_t) image->columns; x++)
3340 {
3341 MagickRealType
3342 intensity;
3343
3344 intensity=0.0;
3345 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3346 intensity=GetPixelIntensity(mask,p);
3347 switch (type)
3348 {
3349 case ReadPixelMask:
3350 {
3351 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3352 break;
3353 }
3354 case WritePixelMask:
3355 {
3356 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3357 break;
3358 }
3359 default:
3360 {
3361 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3362 break;
3363 }
3364 }
3365 p+=(ptrdiff_t) GetPixelChannels(mask);
3366 q+=(ptrdiff_t) GetPixelChannels(image);
3367 }
3368 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3369 status=MagickFalse;
3370 }
3371 image->mask_trait=UndefinedPixelTrait;
3372 mask_view=DestroyCacheView(mask_view);
3373 image_view=DestroyCacheView(image_view);
3374 return(status);
3375}
3376
3377/*
3378%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3379% %
3380% %
3381% %
3382% S e t I m a g e R e g i o n M a s k %
3383% %
3384% %
3385% %
3386%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3387%
3388% SetImageRegionMask() associates a mask with the image as defined by the
3389% specified region.
3390%
3391% The format of the SetImageRegionMask method is:
3392%
3393% MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3394% const RectangleInfo *region,ExceptionInfo *exception)
3395%
3396% A description of each parameter follows:
3397%
3398% o image: the image.
3399%
3400% o type: the mask type, ReadPixelMask or WritePixelMask.
3401%
3402% o geometry: the mask region.
3403%
3404% o exception: return any errors or warnings in this structure.
3405%
3406*/
3407MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3408 const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3409{
3410 CacheView
3411 *image_view;
3412
3413 MagickBooleanType
3414 status;
3415
3416 ssize_t
3417 y;
3418
3419 /*
3420 Set image mask as defined by the region.
3421 */
3422 assert(image != (Image *) NULL);
3423 assert(image->signature == MagickCoreSignature);
3424 if (IsEventLogging() != MagickFalse)
3425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3426 if (region == (const RectangleInfo *) NULL)
3427 {
3428 switch (type)
3429 {
3430 case ReadPixelMask:
3431 {
3432 image->channels=(ChannelType) ((unsigned int) image->channels &
3433 (unsigned int) ~ReadMaskChannel);
3434 break;
3435 }
3436 case WritePixelMask:
3437 {
3438 image->channels=(ChannelType) ((unsigned int) image->channels &
3439 (unsigned int) ~WriteMaskChannel);
3440 break;
3441 }
3442 default:
3443 {
3444 image->channels=(ChannelType) ((unsigned int) image->channels &
3445 (unsigned int) ~CompositeMaskChannel);
3446 break;
3447 }
3448 }
3449 return(SyncImagePixelCache(image,exception));
3450 }
3451 switch (type)
3452 {
3453 case ReadPixelMask:
3454 {
3455 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3456 break;
3457 }
3458 case WritePixelMask:
3459 {
3460 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3461 break;
3462 }
3463 default:
3464 {
3465 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3466 break;
3467 }
3468 }
3469 if (SyncImagePixelCache(image,exception) == MagickFalse)
3470 return(MagickFalse);
3471 status=MagickTrue;
3472 image->mask_trait=UpdatePixelTrait;
3473 image_view=AcquireAuthenticCacheView(image,exception);
3474#if defined(MAGICKCORE_OPENMP_SUPPORT)
3475 #pragma omp parallel for schedule(static) shared(status) \
3476 magick_number_threads(image,image,image->rows,2)
3477#endif
3478 for (y=0; y < (ssize_t) image->rows; y++)
3479 {
3480 Quantum
3481 *magick_restrict q;
3482
3483 ssize_t
3484 x;
3485
3486 if (status == MagickFalse)
3487 continue;
3488 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3489 if (q == (Quantum *) NULL)
3490 {
3491 status=MagickFalse;
3492 continue;
3493 }
3494 for (x=0; x < (ssize_t) image->columns; x++)
3495 {
3496 Quantum
3497 pixel;
3498
3499 pixel=QuantumRange;
3500 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3501 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3502 pixel=(Quantum) 0;
3503 switch (type)
3504 {
3505 case ReadPixelMask:
3506 {
3507 SetPixelReadMask(image,pixel,q);
3508 break;
3509 }
3510 case WritePixelMask:
3511 {
3512 SetPixelWriteMask(image,pixel,q);
3513 break;
3514 }
3515 default:
3516 {
3517 SetPixelCompositeMask(image,pixel,q);
3518 break;
3519 }
3520 }
3521 q+=(ptrdiff_t) GetPixelChannels(image);
3522 }
3523 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3524 status=MagickFalse;
3525 }
3526 image->mask_trait=UndefinedPixelTrait;
3527 image_view=DestroyCacheView(image_view);
3528 return(status);
3529}
3530
3531/*
3532%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3533% %
3534% %
3535% %
3536% 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 %
3537% %
3538% %
3539% %
3540%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3541%
3542% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3543% image and returns the previous setting. A virtual pixel is any pixel access
3544% that is outside the boundaries of the image cache.
3545%
3546% The format of the SetImageVirtualPixelMethod() method is:
3547%
3548% VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3549% const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3550%
3551% A description of each parameter follows:
3552%
3553% o image: the image.
3554%
3555% o virtual_pixel_method: choose the type of virtual pixel.
3556%
3557% o exception: return any errors or warnings in this structure.
3558%
3559*/
3560MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3561 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3562{
3563 assert(image != (const Image *) NULL);
3564 assert(image->signature == MagickCoreSignature);
3565 if (IsEventLogging() != MagickFalse)
3566 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3567 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3568}
3569
3570/*
3571%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3572% %
3573% %
3574% %
3575% S m u s h I m a g e s %
3576% %
3577% %
3578% %
3579%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3580%
3581% SmushImages() takes all images from the current image pointer to the end
3582% of the image list and smushes them to each other top-to-bottom if the
3583% stack parameter is true, otherwise left-to-right.
3584%
3585% The current gravity setting now effects how the image is justified in the
3586% final image.
3587%
3588% The format of the SmushImages method is:
3589%
3590% Image *SmushImages(const Image *images,const MagickBooleanType stack,
3591% ExceptionInfo *exception)
3592%
3593% A description of each parameter follows:
3594%
3595% o images: the image sequence.
3596%
3597% o stack: A value other than 0 stacks the images top-to-bottom.
3598%
3599% o offset: minimum distance in pixels between images.
3600%
3601% o exception: return any errors or warnings in this structure.
3602%
3603*/
3604
3605static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3606 const ssize_t offset,ExceptionInfo *exception)
3607{
3608 CacheView
3609 *left_view,
3610 *right_view;
3611
3612 const Image
3613 *left_image,
3614 *right_image;
3615
3617 left_geometry,
3618 right_geometry;
3619
3620 const Quantum
3621 *p;
3622
3623 ssize_t
3624 i,
3625 y;
3626
3627 size_t
3628 gap;
3629
3630 ssize_t
3631 x;
3632
3633 if (images->previous == (Image *) NULL)
3634 return(0);
3635 right_image=images;
3636 SetGeometry(smush_image,&right_geometry);
3637 GravityAdjustGeometry(right_image->columns,right_image->rows,
3638 right_image->gravity,&right_geometry);
3639 left_image=images->previous;
3640 SetGeometry(smush_image,&left_geometry);
3641 GravityAdjustGeometry(left_image->columns,left_image->rows,
3642 left_image->gravity,&left_geometry);
3643 gap=right_image->columns;
3644 left_view=AcquireVirtualCacheView(left_image,exception);
3645 right_view=AcquireVirtualCacheView(right_image,exception);
3646 for (y=0; y < (ssize_t) smush_image->rows; y++)
3647 {
3648 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3649 {
3650 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3651 if ((p == (const Quantum *) NULL) ||
3652 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3653 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3654 break;
3655 }
3656 i=(ssize_t) left_image->columns-x-1;
3657 for (x=0; x < (ssize_t) right_image->columns; x++)
3658 {
3659 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3660 exception);
3661 if ((p == (const Quantum *) NULL) ||
3662 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3663 ((x+i) >= (ssize_t) gap))
3664 break;
3665 }
3666 if ((x+i) < (ssize_t) gap)
3667 gap=(size_t) (x+i);
3668 }
3669 right_view=DestroyCacheView(right_view);
3670 left_view=DestroyCacheView(left_view);
3671 if (y < (ssize_t) smush_image->rows)
3672 return(offset);
3673 return((ssize_t) gap-offset);
3674}
3675
3676static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3677 const ssize_t offset,ExceptionInfo *exception)
3678{
3679 CacheView
3680 *bottom_view,
3681 *top_view;
3682
3683 const Image
3684 *bottom_image,
3685 *top_image;
3686
3688 bottom_geometry,
3689 top_geometry;
3690
3691 const Quantum
3692 *p;
3693
3694 ssize_t
3695 i,
3696 x;
3697
3698 size_t
3699 gap;
3700
3701 ssize_t
3702 y;
3703
3704 if (images->previous == (Image *) NULL)
3705 return(0);
3706 bottom_image=images;
3707 SetGeometry(smush_image,&bottom_geometry);
3708 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3709 bottom_image->gravity,&bottom_geometry);
3710 top_image=images->previous;
3711 SetGeometry(smush_image,&top_geometry);
3712 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3713 &top_geometry);
3714 gap=bottom_image->rows;
3715 top_view=AcquireVirtualCacheView(top_image,exception);
3716 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3717 for (x=0; x < (ssize_t) smush_image->columns; x++)
3718 {
3719 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3720 {
3721 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3722 if ((p == (const Quantum *) NULL) ||
3723 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3724 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3725 break;
3726 }
3727 i=(ssize_t) top_image->rows-y-1;
3728 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3729 {
3730 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3731 exception);
3732 if ((p == (const Quantum *) NULL) ||
3733 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3734 ((y+i) >= (ssize_t) gap))
3735 break;
3736 }
3737 if ((y+i) < (ssize_t) gap)
3738 gap=(size_t) (y+i);
3739 }
3740 bottom_view=DestroyCacheView(bottom_view);
3741 top_view=DestroyCacheView(top_view);
3742 if (x < (ssize_t) smush_image->columns)
3743 return(offset);
3744 return((ssize_t) gap-offset);
3745}
3746
3747MagickExport Image *SmushImages(const Image *images,
3748 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3749{
3750#define SmushImageTag "Smush/Image"
3751
3752 const Image
3753 *image;
3754
3755 Image
3756 *smush_image;
3757
3758 MagickBooleanType
3759 proceed,
3760 status;
3761
3762 MagickOffsetType
3763 n;
3764
3765 PixelTrait
3766 alpha_trait;
3767
3769 geometry;
3770
3771 const Image
3772 *next;
3773
3774 size_t
3775 height,
3776 number_images,
3777 width;
3778
3779 ssize_t
3780 x_offset,
3781 y_offset;
3782
3783 /*
3784 Compute maximum area of smushed area.
3785 */
3786 assert(images != (Image *) NULL);
3787 assert(images->signature == MagickCoreSignature);
3788 assert(exception != (ExceptionInfo *) NULL);
3789 assert(exception->signature == MagickCoreSignature);
3790 if (IsEventLogging() != MagickFalse)
3791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3792 image=images;
3793 alpha_trait=image->alpha_trait;
3794 number_images=1;
3795 width=image->columns;
3796 height=image->rows;
3797 next=GetNextImageInList(image);
3798 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3799 {
3800 if (next->alpha_trait != UndefinedPixelTrait)
3801 alpha_trait=BlendPixelTrait;
3802 number_images++;
3803 if (stack != MagickFalse)
3804 {
3805 if (next->columns > width)
3806 width=next->columns;
3807 height+=next->rows;
3808 if (next->previous != (Image *) NULL)
3809 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3810 continue;
3811 }
3812 width+=next->columns;
3813 if (next->previous != (Image *) NULL)
3814 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3815 if (next->rows > height)
3816 height=next->rows;
3817 }
3818 /*
3819 Smush images.
3820 */
3821 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3822 if (smush_image == (Image *) NULL)
3823 return((Image *) NULL);
3824 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3825 {
3826 smush_image=DestroyImage(smush_image);
3827 return((Image *) NULL);
3828 }
3829 smush_image->alpha_trait=alpha_trait;
3830 (void) SetImageBackgroundColor(smush_image,exception);
3831 status=MagickTrue;
3832 x_offset=0;
3833 y_offset=0;
3834 for (n=0; n < (MagickOffsetType) number_images; n++)
3835 {
3836 SetGeometry(smush_image,&geometry);
3837 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3838 if (stack != MagickFalse)
3839 {
3840 x_offset-=geometry.x;
3841 y_offset-=SmushYGap(smush_image,image,offset,exception);
3842 }
3843 else
3844 {
3845 x_offset-=SmushXGap(smush_image,image,offset,exception);
3846 y_offset-=geometry.y;
3847 }
3848 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3849 y_offset,exception);
3850 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3851 if (proceed == MagickFalse)
3852 break;
3853 if (stack == MagickFalse)
3854 {
3855 x_offset+=(ssize_t) image->columns;
3856 y_offset=0;
3857 }
3858 else
3859 {
3860 x_offset=0;
3861 y_offset+=(ssize_t) image->rows;
3862 }
3863 image=GetNextImageInList(image);
3864 }
3865 if (stack == MagickFalse)
3866 smush_image->columns=(size_t) x_offset;
3867 else
3868 smush_image->rows=(size_t) y_offset;
3869 if (status == MagickFalse)
3870 smush_image=DestroyImage(smush_image);
3871 return(smush_image);
3872}
3873
3874/*
3875%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3876% %
3877% %
3878% %
3879% S t r i p I m a g e %
3880% %
3881% %
3882% %
3883%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3884%
3885% StripImage() strips an image of all profiles and comments.
3886%
3887% The format of the StripImage method is:
3888%
3889% MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3890%
3891% A description of each parameter follows:
3892%
3893% o image: the image.
3894%
3895% o exception: return any errors or warnings in this structure.
3896%
3897*/
3898MagickExport MagickBooleanType StripImage(Image *image,
3899 ExceptionInfo *magick_unused(exception))
3900{
3901 MagickBooleanType
3902 status;
3903
3904 magick_unreferenced(exception);
3905 assert(image != (Image *) NULL);
3906 if (IsEventLogging() != MagickFalse)
3907 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3908 DestroyImageProfiles(image);
3909 (void) DeleteImageProperty(image,"comment");
3910 (void) DeleteImageProperty(image,"date:create");
3911 (void) DeleteImageProperty(image,"date:modify");
3912 (void) DeleteImageProperty(image,"date:timestamp");
3913 status=SetImageArtifact(image,"png:exclude-chunk",
3914 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3915 return(status);
3916}
3917
3918/*
3919%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3920% %
3921% %
3922% %
3923+ S y n c I m a g e %
3924% %
3925% %
3926% %
3927%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3928%
3929% SyncImage() initializes the red, green, and blue intensities of each pixel
3930% as defined by the colormap index.
3931%
3932% The format of the SyncImage method is:
3933%
3934% MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3935%
3936% A description of each parameter follows:
3937%
3938% o image: the image.
3939%
3940% o exception: return any errors or warnings in this structure.
3941%
3942*/
3943
3944static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3945 MagickBooleanType *range_exception)
3946{
3947 if ((size_t) index < image->colors)
3948 return(index);
3949 *range_exception=MagickTrue;
3950 return((Quantum) 0);
3951}
3952
3953MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3954{
3955 CacheView
3956 *image_view;
3957
3958 MagickBooleanType
3959 range_exception,
3960 status,
3961 taint;
3962
3963 ssize_t
3964 y;
3965
3966 assert(image != (Image *) NULL);
3967 assert(image->signature == MagickCoreSignature);
3968 if (IsEventLogging() != MagickFalse)
3969 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3970 if (image->ping != MagickFalse)
3971 return(MagickTrue);
3972 if (image->storage_class != PseudoClass)
3973 return(MagickFalse);
3974 assert(image->colormap != (PixelInfo *) NULL);
3975 range_exception=MagickFalse;
3976 status=MagickTrue;
3977 taint=image->taint;
3978 image_view=AcquireAuthenticCacheView(image,exception);
3979#if defined(MAGICKCORE_OPENMP_SUPPORT)
3980 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3981 magick_number_threads(image,image,image->rows,2)
3982#endif
3983 for (y=0; y < (ssize_t) image->rows; y++)
3984 {
3985 Quantum
3986 index;
3987
3988 Quantum
3989 *magick_restrict q;
3990
3991 ssize_t
3992 x;
3993
3994 if (status == MagickFalse)
3995 continue;
3996 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3997 if (q == (Quantum *) NULL)
3998 {
3999 status=MagickFalse;
4000 continue;
4001 }
4002 for (x=0; x < (ssize_t) image->columns; x++)
4003 {
4004 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4005 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4006 q+=(ptrdiff_t) GetPixelChannels(image);
4007 }
4008 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4009 status=MagickFalse;
4010 }
4011 image_view=DestroyCacheView(image_view);
4012 image->taint=taint;
4013 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4014 (void) ThrowMagickException(exception,GetMagickModule(),
4015 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
4016 return(status);
4017}
4018
4019/*
4020%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4021% %
4022% %
4023% %
4024% S y n c I m a g e S e t t i n g s %
4025% %
4026% %
4027% %
4028%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4029%
4030% SyncImageSettings() syncs any image_info global options into per-image
4031% attributes.
4032%
4033% Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
4034% that operations and coders can find such settings. In IMv7 if a desired
4035% per-image artifact is not set, then it will directly look for a global
4036% option as a fallback, as such this copy is no longer needed, only the
4037% link set up.
4038%
4039% The format of the SyncImageSettings method is:
4040%
4041% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4042% Image *image,ExceptionInfo *exception)
4043% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4044% Image *image,ExceptionInfo *exception)
4045%
4046% A description of each parameter follows:
4047%
4048% o image_info: the image info.
4049%
4050% o image: the image.
4051%
4052% o exception: return any errors or warnings in this structure.
4053%
4054*/
4055
4056MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4057 Image *images,ExceptionInfo *exception)
4058{
4059 Image
4060 *image;
4061
4062 assert(image_info != (const ImageInfo *) NULL);
4063 assert(image_info->signature == MagickCoreSignature);
4064 assert(images != (Image *) NULL);
4065 assert(images->signature == MagickCoreSignature);
4066 if (IsEventLogging() != MagickFalse)
4067 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4068 image=images;
4069 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4070 (void) SyncImageSettings(image_info,image,exception);
4071 (void) DeleteImageOption(image_info,"page");
4072 return(MagickTrue);
4073}
4074
4075MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4076 Image *image,ExceptionInfo *exception)
4077{
4078 const char
4079 *option;
4080
4082 geometry_info;
4083
4084 MagickStatusType
4085 flags;
4086
4087 ResolutionType
4088 units;
4089
4090 /*
4091 Sync image options.
4092 */
4093 assert(image_info != (const ImageInfo *) NULL);
4094 assert(image_info->signature == MagickCoreSignature);
4095 assert(image != (Image *) NULL);
4096 assert(image->signature == MagickCoreSignature);
4097 if (IsEventLogging() != MagickFalse)
4098 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4099 option=GetImageOption(image_info,"background");
4100 if (option != (const char *) NULL)
4101 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4102 exception);
4103 option=GetImageOption(image_info,"black-point-compensation");
4104 if (option != (const char *) NULL)
4105 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4106 MagickBooleanOptions,MagickFalse,option);
4107 option=GetImageOption(image_info,"blue-primary");
4108 if (option != (const char *) NULL)
4109 {
4110 flags=ParseGeometry(option,&geometry_info);
4111 if ((flags & RhoValue) != 0)
4112 image->chromaticity.blue_primary.x=geometry_info.rho;
4113 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4114 if ((flags & SigmaValue) != 0)
4115 image->chromaticity.blue_primary.y=geometry_info.sigma;
4116 }
4117 option=GetImageOption(image_info,"bordercolor");
4118 if (option != (const char *) NULL)
4119 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4120 exception);
4121 /* FUTURE: do not sync compose to per-image compose setting here */
4122 option=GetImageOption(image_info,"compose");
4123 if (option != (const char *) NULL)
4124 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4125 MagickFalse,option);
4126 /* -- */
4127 option=GetImageOption(image_info,"compress");
4128 if (option != (const char *) NULL)
4129 image->compression=(CompressionType) ParseCommandOption(
4130 MagickCompressOptions,MagickFalse,option);
4131 option=GetImageOption(image_info,"debug");
4132 if (option != (const char *) NULL)
4133 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4134 MagickFalse,option);
4135 option=GetImageOption(image_info,"density");
4136 if (option != (const char *) NULL)
4137 {
4138 flags=ParseGeometry(option,&geometry_info);
4139 if ((flags & RhoValue) != 0)
4140 image->resolution.x=geometry_info.rho;
4141 image->resolution.y=image->resolution.x;
4142 if ((flags & SigmaValue) != 0)
4143 image->resolution.y=geometry_info.sigma;
4144 }
4145 option=GetImageOption(image_info,"depth");
4146 if (option != (const char *) NULL)
4147 image->depth=StringToUnsignedLong(option);
4148 option=GetImageOption(image_info,"endian");
4149 if (option != (const char *) NULL)
4150 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4151 MagickFalse,option);
4152 option=GetImageOption(image_info,"filter");
4153 if (option != (const char *) NULL)
4154 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4155 MagickFalse,option);
4156 option=GetImageOption(image_info,"fuzz");
4157 if (option != (const char *) NULL)
4158 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4159 option=GetImageOption(image_info,"gravity");
4160 if (option != (const char *) NULL)
4161 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4162 MagickFalse,option);
4163 option=GetImageOption(image_info,"green-primary");
4164 if (option != (const char *) NULL)
4165 {
4166 flags=ParseGeometry(option,&geometry_info);
4167 if ((flags & RhoValue) != 0)
4168 image->chromaticity.green_primary.x=geometry_info.rho;
4169 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4170 if ((flags & SigmaValue) != 0)
4171 image->chromaticity.green_primary.y=geometry_info.sigma;
4172 }
4173 option=GetImageOption(image_info,"intent");
4174 if (option != (const char *) NULL)
4175 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4176 MagickIntentOptions,MagickFalse,option);
4177 option=GetImageOption(image_info,"intensity");
4178 if (option != (const char *) NULL)
4179 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4180 MagickPixelIntensityOptions,MagickFalse,option);
4181 option=GetImageOption(image_info,"interlace");
4182 if (option != (const char *) NULL)
4183 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4184 MagickFalse,option);
4185 option=GetImageOption(image_info,"interpolate");
4186 if (option != (const char *) NULL)
4187 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4188 MagickInterpolateOptions,MagickFalse,option);
4189 option=GetImageOption(image_info,"loop");
4190 if (option != (const char *) NULL)
4191 image->iterations=StringToUnsignedLong(option);
4192 option=GetImageOption(image_info,"mattecolor");
4193 if (option != (const char *) NULL)
4194 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4195 exception);
4196 option=GetImageOption(image_info,"orient");
4197 if (option != (const char *) NULL)
4198 image->orientation=(OrientationType) ParseCommandOption(
4199 MagickOrientationOptions,MagickFalse,option);
4200 option=GetImageOption(image_info,"page");
4201 if (option != (const char *) NULL)
4202 {
4203 char
4204 *geometry;
4205
4206 geometry=GetPageGeometry(option);
4207 flags=ParseAbsoluteGeometry(geometry,&image->page);
4208 geometry=DestroyString(geometry);
4209 }
4210 option=GetImageOption(image_info,"quality");
4211 if (option != (const char *) NULL)
4212 image->quality=StringToUnsignedLong(option);
4213 option=GetImageOption(image_info,"red-primary");
4214 if (option != (const char *) NULL)
4215 {
4216 flags=ParseGeometry(option,&geometry_info);
4217 if ((flags & RhoValue) != 0)
4218 image->chromaticity.red_primary.x=geometry_info.rho;
4219 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4220 if ((flags & SigmaValue) != 0)
4221 image->chromaticity.red_primary.y=geometry_info.sigma;
4222 }
4223 if (image_info->quality != UndefinedCompressionQuality)
4224 image->quality=image_info->quality;
4225 option=GetImageOption(image_info,"scene");
4226 if (option != (const char *) NULL)
4227 image->scene=StringToUnsignedLong(option);
4228 option=GetImageOption(image_info,"taint");
4229 if (option != (const char *) NULL)
4230 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4231 MagickFalse,option);
4232 option=GetImageOption(image_info,"tile-offset");
4233 if (option != (const char *) NULL)
4234 {
4235 char
4236 *geometry;
4237
4238 geometry=GetPageGeometry(option);
4239 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4240 geometry=DestroyString(geometry);
4241 }
4242 option=GetImageOption(image_info,"transparent-color");
4243 if (option != (const char *) NULL)
4244 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4245 exception);
4246 option=GetImageOption(image_info,"type");
4247 if (option != (const char *) NULL)
4248 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4249 option);
4250 option=GetImageOption(image_info,"units");
4251 units=image_info->units;
4252 if (option != (const char *) NULL)
4253 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4254 MagickFalse,option);
4255 if (units != UndefinedResolution)
4256 {
4257 if (image->units != units)
4258 switch (image->units)
4259 {
4260 case PixelsPerInchResolution:
4261 {
4262 if (units == PixelsPerCentimeterResolution)
4263 {
4264 image->resolution.x/=2.54;
4265 image->resolution.y/=2.54;
4266 }
4267 break;
4268 }
4269 case PixelsPerCentimeterResolution:
4270 {
4271 if (units == PixelsPerInchResolution)
4272 {
4273 image->resolution.x=(double) ((size_t) (100.0*2.54*
4274 image->resolution.x+0.5))/100.0;
4275 image->resolution.y=(double) ((size_t) (100.0*2.54*
4276 image->resolution.y+0.5))/100.0;
4277 }
4278 break;
4279 }
4280 default:
4281 break;
4282 }
4283 image->units=units;
4284 option=GetImageOption(image_info,"density");
4285 if (option != (const char *) NULL)
4286 {
4287 flags=ParseGeometry(option,&geometry_info);
4288 if ((flags & RhoValue) != 0)
4289 image->resolution.x=geometry_info.rho;
4290 image->resolution.y=image->resolution.x;
4291 if ((flags & SigmaValue) != 0)
4292 image->resolution.y=geometry_info.sigma;
4293 }
4294 }
4295 option=GetImageOption(image_info,"virtual-pixel");
4296 if (option != (const char *) NULL)
4297 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4298 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4299 exception);
4300 option=GetImageOption(image_info,"white-point");
4301 if (option != (const char *) NULL)
4302 {
4303 flags=ParseGeometry(option,&geometry_info);
4304 if ((flags & RhoValue) != 0)
4305 image->chromaticity.white_point.x=geometry_info.rho;
4306 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4307 if ((flags & SigmaValue) != 0)
4308 image->chromaticity.white_point.y=geometry_info.sigma;
4309 }
4310 /*
4311 Pointer to allow the lookup of pre-image artifact will fallback to a global
4312 option setting/define. This saves a lot of duplication of global options
4313 into per-image artifacts, while ensuring only specifically set per-image
4314 artifacts are preserved when parenthesis ends.
4315 */
4316 if (image->image_info != (ImageInfo *) NULL)
4317 image->image_info=DestroyImageInfo(image->image_info);
4318 image->image_info=CloneImageInfo(image_info);
4319 return(MagickTrue);
4320}