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