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