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