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 if (IsStringTrue(GetImageOption(image_info,"filename:literal")) != MagickFalse)
2969 GetPathComponent(image_info->filename,SubcanonicalPath,component);
2970 (void) CopyMagickString(image_info->filename,component,
2971 MagickPathExtent);
2972 }
2973 }
2974 sans_exception=DestroyExceptionInfo(sans_exception);
2975 if ((magick_info == (const MagickInfo *) NULL) ||
2976 (GetMagickEndianSupport(magick_info) == MagickFalse))
2977 image_info->endian=UndefinedEndian;
2978 if ((image_info->adjoin != MagickFalse) && (frames > 1))
2979 {
2980 /*
2981 Test for multiple image support (e.g. image%02d.png).
2982 */
2983 (void) InterpretImageFilename(image_info,(Image *) NULL,
2984 image_info->filename,(int) image_info->scene,component,exception);
2985 if ((LocaleCompare(component,image_info->filename) != 0) &&
2986 (strchr(component,'%') == (char *) NULL))
2987 image_info->adjoin=MagickFalse;
2988 }
2989 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2990 {
2991 /*
2992 Some image formats do not support multiple frames per file.
2993 */
2994 magick_info=GetMagickInfo(magic,exception);
2995 if (magick_info != (const MagickInfo *) NULL)
2996 if (GetMagickAdjoin(magick_info) == MagickFalse)
2997 image_info->adjoin=MagickFalse;
2998 }
2999 if (image_info->affirm != MagickFalse)
3000 return(MagickTrue);
3001 if (frames == 0)
3002 {
3003 unsigned char
3004 *magick;
3005
3006 size_t
3007 magick_size;
3008
3009 /*
3010 Determine the image format from the first few bytes of the file.
3011 */
3012 magick_size=GetMagicPatternExtent(exception);
3013 if (magick_size == 0)
3014 return(MagickFalse);
3015 image=AcquireImage(image_info,exception);
3016 (void) CopyMagickString(image->filename,image_info->filename,
3017 MagickPathExtent);
3018 sans_exception=AcquireExceptionInfo();
3019 status=OpenBlob(image_info,image,ReadBinaryBlobMode,sans_exception);
3020 sans_exception=DestroyExceptionInfo(sans_exception);
3021 if (status == MagickFalse)
3022 {
3023 image=DestroyImage(image);
3024 return(MagickFalse);
3025 }
3026 if ((IsBlobSeekable(image) == MagickFalse) ||
3027 (IsBlobExempt(image) != MagickFalse))
3028 {
3029 /*
3030 Copy image to seekable temporary file.
3031 */
3032 *component='\0';
3033 status=ImageToFile(image,component,exception);
3034 if (CloseBlob(image) == MagickFalse)
3035 status=MagickFalse;
3036 if (status == MagickFalse)
3037 {
3038 (void) RelinquishUniqueFileResource(component);
3039 image=DestroyImage(image);
3040 return(MagickFalse);
3041 }
3042 SetImageInfoFile(image_info,(FILE *) NULL);
3043 (void) CopyMagickString(image->filename,component,MagickPathExtent);
3044 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3045 if (status == MagickFalse)
3046 {
3047 (void) RelinquishUniqueFileResource(component);
3048 image=DestroyImage(image);
3049 return(MagickFalse);
3050 }
3051 (void) CopyMagickString(image_info->filename,component,
3052 MagickPathExtent);
3053 image_info->temporary=MagickTrue;
3054 }
3055 magick=(unsigned char *) AcquireQuantumMemory(1,magick_size);
3056 if (magick == (unsigned char *) NULL)
3057 {
3058 (void) CloseBlob(image);
3059 image=DestroyImage(image);
3060 return(MagickFalse);
3061 }
3062 (void) memset(magick,0,magick_size);
3063 count=ReadBlob(image,magick_size,magick);
3064 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
3065 (void) CloseBlob(image);
3066 image=DestroyImage(image);
3067 /*
3068 Check magic cache.
3069 */
3070 sans_exception=AcquireExceptionInfo();
3071 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3072 magick=(unsigned char *) RelinquishMagickMemory(magick);
3073 if ((magic_info != (const MagicInfo *) NULL) &&
3074 (GetMagicName(magic_info) != (char *) NULL))
3075 {
3076 /*
3077 Try to use magick_info that was determined earlier by the extension
3078 */
3079 if ((magick_info != (const MagickInfo *) NULL) &&
3080 (GetMagickUseExtension(magick_info) != MagickFalse) &&
3081 (LocaleCompare(magick_info->magick_module,GetMagicName(
3082 magic_info)) == 0))
3083 (void) CopyMagickString(image_info->magick,magick_info->name,
3084 MagickPathExtent);
3085 else
3086 {
3087 (void) CopyMagickString(image_info->magick,GetMagicName(
3088 magic_info),MagickPathExtent);
3089 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3090 }
3091 if ((magick_info == (const MagickInfo *) NULL) ||
3092 (GetMagickEndianSupport(magick_info) == MagickFalse))
3093 image_info->endian=UndefinedEndian;
3094 sans_exception=DestroyExceptionInfo(sans_exception);
3095 return(MagickTrue);
3096 }
3097 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3098 if ((magick_info == (const MagickInfo *) NULL) ||
3099 (GetMagickEndianSupport(magick_info) == MagickFalse))
3100 image_info->endian=UndefinedEndian;
3101 sans_exception=DestroyExceptionInfo(sans_exception);
3102 }
3103 return(MagickTrue);
3104}
3105
3106/*
3107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3108% %
3109% %
3110% %
3111% S e t I m a g e I n f o B l o b %
3112% %
3113% %
3114% %
3115%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3116%
3117% SetImageInfoBlob() sets the image info blob member.
3118%
3119% The format of the SetImageInfoBlob method is:
3120%
3121% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3122% const size_t length)
3123%
3124% A description of each parameter follows:
3125%
3126% o image_info: the image info.
3127%
3128% o blob: the blob.
3129%
3130% o length: the blob length.
3131%
3132*/
3133MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3134 const size_t length)
3135{
3136 assert(image_info != (ImageInfo *) NULL);
3137 assert(image_info->signature == MagickCoreSignature);
3138 if (IsEventLogging() != MagickFalse)
3139 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3140 image_info->filename);
3141 image_info->blob=(void *) blob;
3142 image_info->length=length;
3143}
3144
3145/*
3146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3147% %
3148% %
3149% %
3150% S e t I m a g e I n f o C u s t o m S t r e a m %
3151% %
3152% %
3153% %
3154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3155%
3156% SetImageInfoCustomStream() sets the image info custom stream handlers.
3157%
3158% The format of the SetImageInfoCustomStream method is:
3159%
3160% void SetImageInfoCustomStream(ImageInfo *image_info,
3161% CustomStreamInfo *custom_stream)
3162%
3163% A description of each parameter follows:
3164%
3165% o image_info: the image info.
3166%
3167% o custom_stream: your custom stream methods.
3168%
3169*/
3170MagickExport void SetImageInfoCustomStream(ImageInfo *image_info,
3171 CustomStreamInfo *custom_stream)
3172{
3173 assert(image_info != (ImageInfo *) NULL);
3174 assert(image_info->signature == MagickCoreSignature);
3175 if (IsEventLogging() != MagickFalse)
3176 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3177 image_info->filename);
3178 image_info->custom_stream=(CustomStreamInfo *) custom_stream;
3179}
3180
3181/*
3182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3183% %
3184% %
3185% %
3186% S e t I m a g e I n f o F i l e %
3187% %
3188% %
3189% %
3190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3191%
3192% SetImageInfoFile() sets the image info file member.
3193%
3194% The format of the SetImageInfoFile method is:
3195%
3196% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3197%
3198% A description of each parameter follows:
3199%
3200% o image_info: the image info.
3201%
3202% o file: the file.
3203%
3204*/
3205MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3206{
3207 assert(image_info != (ImageInfo *) NULL);
3208 assert(image_info->signature == MagickCoreSignature);
3209 if (IsEventLogging() != MagickFalse)
3210 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3211 image_info->filename);
3212 image_info->file=file;
3213}
3214
3215/*
3216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3217% %
3218% %
3219% %
3220% S e t I m a g e M a s k %
3221% %
3222% %
3223% %
3224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3225%
3226% SetImageMask() associates a mask with the image. The mask must be the same
3227% dimensions as the image.
3228%
3229% The format of the SetImageMask method is:
3230%
3231% MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3232% const Image *mask,ExceptionInfo *exception)
3233%
3234% A description of each parameter follows:
3235%
3236% o image: the image.
3237%
3238% o type: the mask type, ReadPixelMask or WritePixelMask.
3239%
3240% o mask: the image mask.
3241%
3242% o exception: return any errors or warnings in this structure.
3243%
3244*/
3245MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
3246 const Image *mask,ExceptionInfo *exception)
3247{
3248 CacheView
3249 *mask_view,
3250 *image_view;
3251
3252 MagickBooleanType
3253 status;
3254
3255 ssize_t
3256 y;
3257
3258 /*
3259 Set image mask.
3260 */
3261 assert(image != (Image *) NULL);
3262 if (IsEventLogging() != MagickFalse)
3263 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3264 assert(image->signature == MagickCoreSignature);
3265 if (mask == (const Image *) NULL)
3266 {
3267 switch (type)
3268 {
3269 case ReadPixelMask:
3270 {
3271 image->channels=(ChannelType) ((unsigned int) image->channels &
3272 (unsigned int) ~ReadMaskChannel);
3273 break;
3274 }
3275 case WritePixelMask:
3276 {
3277 image->channels=(ChannelType) ((unsigned int) image->channels &
3278 (unsigned int) ~WriteMaskChannel);
3279 magick_fallthrough;
3280 }
3281 default:
3282 {
3283 image->channels=(ChannelType) ((unsigned int) image->channels &
3284 (unsigned int) ~CompositeMaskChannel);
3285 break;
3286 }
3287 }
3288 return(SyncImagePixelCache(image,exception));
3289 }
3290 switch (type)
3291 {
3292 case ReadPixelMask:
3293 {
3294 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3295 break;
3296 }
3297 case WritePixelMask:
3298 {
3299 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3300 break;
3301 }
3302 default:
3303 {
3304 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3305 break;
3306 }
3307 }
3308 if (SyncImagePixelCache(image,exception) == MagickFalse)
3309 return(MagickFalse);
3310 status=MagickTrue;
3311 image->mask_trait=UpdatePixelTrait;
3312 mask_view=AcquireVirtualCacheView(mask,exception);
3313 image_view=AcquireAuthenticCacheView(image,exception);
3314#if defined(MAGICKCORE_OPENMP_SUPPORT)
3315 #pragma omp parallel for schedule(static) shared(status) \
3316 magick_number_threads(mask,image,image->rows,2)
3317#endif
3318 for (y=0; y < (ssize_t) image->rows; y++)
3319 {
3320 const Quantum
3321 *magick_restrict p;
3322
3323 Quantum
3324 *magick_restrict q;
3325
3326 ssize_t
3327 x;
3328
3329 if (status == MagickFalse)
3330 continue;
3331 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
3332 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3333 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
3334 {
3335 status=MagickFalse;
3336 continue;
3337 }
3338 for (x=0; x < (ssize_t) image->columns; x++)
3339 {
3340 MagickRealType
3341 intensity;
3342
3343 intensity=0.0;
3344 if ((x < (ssize_t) mask->columns) && (y < (ssize_t) mask->rows))
3345 intensity=GetPixelIntensity(mask,p);
3346 switch (type)
3347 {
3348 case ReadPixelMask:
3349 {
3350 SetPixelReadMask(image,ClampToQuantum(intensity),q);
3351 break;
3352 }
3353 case WritePixelMask:
3354 {
3355 SetPixelWriteMask(image,ClampToQuantum(intensity),q);
3356 break;
3357 }
3358 default:
3359 {
3360 SetPixelCompositeMask(image,ClampToQuantum(intensity),q);
3361 break;
3362 }
3363 }
3364 p+=(ptrdiff_t) GetPixelChannels(mask);
3365 q+=(ptrdiff_t) GetPixelChannels(image);
3366 }
3367 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3368 status=MagickFalse;
3369 }
3370 image->mask_trait=UndefinedPixelTrait;
3371 mask_view=DestroyCacheView(mask_view);
3372 image_view=DestroyCacheView(image_view);
3373 return(status);
3374}
3375
3376/*
3377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3378% %
3379% %
3380% %
3381% S e t I m a g e R e g i o n M a s k %
3382% %
3383% %
3384% %
3385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3386%
3387% SetImageRegionMask() associates a mask with the image as defined by the
3388% specified region.
3389%
3390% The format of the SetImageRegionMask method is:
3391%
3392% MagickBooleanType SetImageRegionMask(Image *image,const PixelMask type,
3393% const RectangleInfo *region,ExceptionInfo *exception)
3394%
3395% A description of each parameter follows:
3396%
3397% o image: the image.
3398%
3399% o type: the mask type, ReadPixelMask or WritePixelMask.
3400%
3401% o geometry: the mask region.
3402%
3403% o exception: return any errors or warnings in this structure.
3404%
3405*/
3406MagickExport MagickBooleanType SetImageRegionMask(Image *image,
3407 const PixelMask type,const RectangleInfo *region,ExceptionInfo *exception)
3408{
3409 CacheView
3410 *image_view;
3411
3412 MagickBooleanType
3413 status;
3414
3415 ssize_t
3416 y;
3417
3418 /*
3419 Set image mask as defined by the region.
3420 */
3421 assert(image != (Image *) NULL);
3422 assert(image->signature == MagickCoreSignature);
3423 if (IsEventLogging() != MagickFalse)
3424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3425 if (region == (const RectangleInfo *) NULL)
3426 {
3427 switch (type)
3428 {
3429 case ReadPixelMask:
3430 {
3431 image->channels=(ChannelType) ((unsigned int) image->channels &
3432 (unsigned int) ~ReadMaskChannel);
3433 break;
3434 }
3435 case WritePixelMask:
3436 {
3437 image->channels=(ChannelType) ((unsigned int) image->channels &
3438 (unsigned int) ~WriteMaskChannel);
3439 break;
3440 }
3441 default:
3442 {
3443 image->channels=(ChannelType) ((unsigned int) image->channels &
3444 (unsigned int) ~CompositeMaskChannel);
3445 break;
3446 }
3447 }
3448 return(SyncImagePixelCache(image,exception));
3449 }
3450 switch (type)
3451 {
3452 case ReadPixelMask:
3453 {
3454 image->channels=(ChannelType) (image->channels | ReadMaskChannel);
3455 break;
3456 }
3457 case WritePixelMask:
3458 {
3459 image->channels=(ChannelType) (image->channels | WriteMaskChannel);
3460 break;
3461 }
3462 default:
3463 {
3464 image->channels=(ChannelType) (image->channels | CompositeMaskChannel);
3465 break;
3466 }
3467 }
3468 if (SyncImagePixelCache(image,exception) == MagickFalse)
3469 return(MagickFalse);
3470 status=MagickTrue;
3471 image->mask_trait=UpdatePixelTrait;
3472 image_view=AcquireAuthenticCacheView(image,exception);
3473#if defined(MAGICKCORE_OPENMP_SUPPORT)
3474 #pragma omp parallel for schedule(static) shared(status) \
3475 magick_number_threads(image,image,image->rows,2)
3476#endif
3477 for (y=0; y < (ssize_t) image->rows; y++)
3478 {
3479 Quantum
3480 *magick_restrict q;
3481
3482 ssize_t
3483 x;
3484
3485 if (status == MagickFalse)
3486 continue;
3487 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3488 if (q == (Quantum *) NULL)
3489 {
3490 status=MagickFalse;
3491 continue;
3492 }
3493 for (x=0; x < (ssize_t) image->columns; x++)
3494 {
3495 Quantum
3496 pixel;
3497
3498 pixel=QuantumRange;
3499 if (((x >= region->x) && (x < (region->x+(ssize_t) region->width))) &&
3500 ((y >= region->y) && (y < (region->y+(ssize_t) region->height))))
3501 pixel=(Quantum) 0;
3502 switch (type)
3503 {
3504 case ReadPixelMask:
3505 {
3506 SetPixelReadMask(image,pixel,q);
3507 break;
3508 }
3509 case WritePixelMask:
3510 {
3511 SetPixelWriteMask(image,pixel,q);
3512 break;
3513 }
3514 default:
3515 {
3516 SetPixelCompositeMask(image,pixel,q);
3517 break;
3518 }
3519 }
3520 q+=(ptrdiff_t) GetPixelChannels(image);
3521 }
3522 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3523 status=MagickFalse;
3524 }
3525 image->mask_trait=UndefinedPixelTrait;
3526 image_view=DestroyCacheView(image_view);
3527 return(status);
3528}
3529
3530/*
3531%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3532% %
3533% %
3534% %
3535% 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 %
3536% %
3537% %
3538% %
3539%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3540%
3541% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3542% image and returns the previous setting. A virtual pixel is any pixel access
3543% that is outside the boundaries of the image cache.
3544%
3545% The format of the SetImageVirtualPixelMethod() method is:
3546%
3547% VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3548% const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3549%
3550% A description of each parameter follows:
3551%
3552% o image: the image.
3553%
3554% o virtual_pixel_method: choose the type of virtual pixel.
3555%
3556% o exception: return any errors or warnings in this structure.
3557%
3558*/
3559MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3560 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
3561{
3562 assert(image != (const Image *) NULL);
3563 assert(image->signature == MagickCoreSignature);
3564 if (IsEventLogging() != MagickFalse)
3565 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3566 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
3567}
3568
3569/*
3570%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3571% %
3572% %
3573% %
3574% S m u s h I m a g e s %
3575% %
3576% %
3577% %
3578%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3579%
3580% SmushImages() takes all images from the current image pointer to the end
3581% of the image list and smushes them to each other top-to-bottom if the
3582% stack parameter is true, otherwise left-to-right.
3583%
3584% The current gravity setting now effects how the image is justified in the
3585% final image.
3586%
3587% The format of the SmushImages method is:
3588%
3589% Image *SmushImages(const Image *images,const MagickBooleanType stack,
3590% ExceptionInfo *exception)
3591%
3592% A description of each parameter follows:
3593%
3594% o images: the image sequence.
3595%
3596% o stack: A value other than 0 stacks the images top-to-bottom.
3597%
3598% o offset: minimum distance in pixels between images.
3599%
3600% o exception: return any errors or warnings in this structure.
3601%
3602*/
3603
3604static ssize_t SmushXGap(const Image *smush_image,const Image *images,
3605 const ssize_t offset,ExceptionInfo *exception)
3606{
3607 CacheView
3608 *left_view,
3609 *right_view;
3610
3611 const Image
3612 *left_image,
3613 *right_image;
3614
3615 RectangleInfo
3616 left_geometry,
3617 right_geometry;
3618
3619 const Quantum
3620 *p;
3621
3622 ssize_t
3623 i,
3624 y;
3625
3626 size_t
3627 gap;
3628
3629 ssize_t
3630 x;
3631
3632 if (images->previous == (Image *) NULL)
3633 return(0);
3634 right_image=images;
3635 SetGeometry(smush_image,&right_geometry);
3636 GravityAdjustGeometry(right_image->columns,right_image->rows,
3637 right_image->gravity,&right_geometry);
3638 left_image=images->previous;
3639 SetGeometry(smush_image,&left_geometry);
3640 GravityAdjustGeometry(left_image->columns,left_image->rows,
3641 left_image->gravity,&left_geometry);
3642 gap=right_image->columns;
3643 left_view=AcquireVirtualCacheView(left_image,exception);
3644 right_view=AcquireVirtualCacheView(right_image,exception);
3645 for (y=0; y < (ssize_t) smush_image->rows; y++)
3646 {
3647 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3648 {
3649 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3650 if ((p == (const Quantum *) NULL) ||
3651 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
3652 (((ssize_t) left_image->columns-x-1) >= (ssize_t) gap))
3653 break;
3654 }
3655 i=(ssize_t) left_image->columns-x-1;
3656 for (x=0; x < (ssize_t) right_image->columns; x++)
3657 {
3658 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
3659 exception);
3660 if ((p == (const Quantum *) NULL) ||
3661 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3662 ((x+i) >= (ssize_t) gap))
3663 break;
3664 }
3665 if ((x+i) < (ssize_t) gap)
3666 gap=(size_t) (x+i);
3667 }
3668 right_view=DestroyCacheView(right_view);
3669 left_view=DestroyCacheView(left_view);
3670 if (y < (ssize_t) smush_image->rows)
3671 return(offset);
3672 return((ssize_t) gap-offset);
3673}
3674
3675static ssize_t SmushYGap(const Image *smush_image,const Image *images,
3676 const ssize_t offset,ExceptionInfo *exception)
3677{
3678 CacheView
3679 *bottom_view,
3680 *top_view;
3681
3682 const Image
3683 *bottom_image,
3684 *top_image;
3685
3686 RectangleInfo
3687 bottom_geometry,
3688 top_geometry;
3689
3690 const Quantum
3691 *p;
3692
3693 ssize_t
3694 i,
3695 x;
3696
3697 size_t
3698 gap;
3699
3700 ssize_t
3701 y;
3702
3703 if (images->previous == (Image *) NULL)
3704 return(0);
3705 bottom_image=images;
3706 SetGeometry(smush_image,&bottom_geometry);
3707 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3708 bottom_image->gravity,&bottom_geometry);
3709 top_image=images->previous;
3710 SetGeometry(smush_image,&top_geometry);
3711 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3712 &top_geometry);
3713 gap=bottom_image->rows;
3714 top_view=AcquireVirtualCacheView(top_image,exception);
3715 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
3716 for (x=0; x < (ssize_t) smush_image->columns; x++)
3717 {
3718 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3719 {
3720 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3721 if ((p == (const Quantum *) NULL) ||
3722 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3723 (((ssize_t) top_image->rows-y-1) >= (ssize_t) gap))
3724 break;
3725 }
3726 i=(ssize_t) top_image->rows-y-1;
3727 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3728 {
3729 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3730 exception);
3731 if ((p == (const Quantum *) NULL) ||
3732 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3733 ((y+i) >= (ssize_t) gap))
3734 break;
3735 }
3736 if ((y+i) < (ssize_t) gap)
3737 gap=(size_t) (y+i);
3738 }
3739 bottom_view=DestroyCacheView(bottom_view);
3740 top_view=DestroyCacheView(top_view);
3741 if (x < (ssize_t) smush_image->columns)
3742 return(offset);
3743 return((ssize_t) gap-offset);
3744}
3745
3746MagickExport Image *SmushImages(const Image *images,
3747 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3748{
3749#define SmushImageTag "Smush/Image"
3750
3751 const Image
3752 *image;
3753
3754 Image
3755 *smush_image;
3756
3757 MagickBooleanType
3758 proceed,
3759 status;
3760
3761 MagickOffsetType
3762 n;
3763
3764 PixelTrait
3765 alpha_trait;
3766
3767 RectangleInfo
3768 geometry;
3769
3770 const Image
3771 *next;
3772
3773 size_t
3774 height,
3775 number_images,
3776 width;
3777
3778 ssize_t
3779 x_offset,
3780 y_offset;
3781
3782 /*
3783 Compute maximum area of smushed area.
3784 */
3785 assert(images != (Image *) NULL);
3786 assert(images->signature == MagickCoreSignature);
3787 assert(exception != (ExceptionInfo *) NULL);
3788 assert(exception->signature == MagickCoreSignature);
3789 if (IsEventLogging() != MagickFalse)
3790 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3791 image=images;
3792 alpha_trait=image->alpha_trait;
3793 number_images=1;
3794 width=image->columns;
3795 height=image->rows;
3796 next=GetNextImageInList(image);
3797 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3798 {
3799 if (next->alpha_trait != UndefinedPixelTrait)
3800 alpha_trait=BlendPixelTrait;
3801 number_images++;
3802 if (stack != MagickFalse)
3803 {
3804 if (next->columns > width)
3805 width=next->columns;
3806 height+=next->rows;
3807 if (next->previous != (Image *) NULL)
3808 height=(size_t) MagickMax((ssize_t) height+offset,0U);
3809 continue;
3810 }
3811 width+=next->columns;
3812 if (next->previous != (Image *) NULL)
3813 width=(size_t) MagickMax((ssize_t) width+offset,0U);
3814 if (next->rows > height)
3815 height=next->rows;
3816 }
3817 /*
3818 Smush images.
3819 */
3820 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3821 if (smush_image == (Image *) NULL)
3822 return((Image *) NULL);
3823 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
3824 {
3825 smush_image=DestroyImage(smush_image);
3826 return((Image *) NULL);
3827 }
3828 smush_image->alpha_trait=alpha_trait;
3829 (void) SetImageBackgroundColor(smush_image,exception);
3830 status=MagickTrue;
3831 x_offset=0;
3832 y_offset=0;
3833 for (n=0; n < (MagickOffsetType) number_images; n++)
3834 {
3835 SetGeometry(smush_image,&geometry);
3836 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3837 if (stack != MagickFalse)
3838 {
3839 x_offset-=geometry.x;
3840 y_offset-=SmushYGap(smush_image,image,offset,exception);
3841 }
3842 else
3843 {
3844 x_offset-=SmushXGap(smush_image,image,offset,exception);
3845 y_offset-=geometry.y;
3846 }
3847 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3848 y_offset,exception);
3849 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3850 if (proceed == MagickFalse)
3851 break;
3852 if (stack == MagickFalse)
3853 {
3854 x_offset+=(ssize_t) image->columns;
3855 y_offset=0;
3856 }
3857 else
3858 {
3859 x_offset=0;
3860 y_offset+=(ssize_t) image->rows;
3861 }
3862 image=GetNextImageInList(image);
3863 }
3864 if (stack == MagickFalse)
3865 smush_image->columns=(size_t) x_offset;
3866 else
3867 smush_image->rows=(size_t) y_offset;
3868 if (status == MagickFalse)
3869 smush_image=DestroyImage(smush_image);
3870 return(smush_image);
3871}
3872
3873/*
3874%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3875% %
3876% %
3877% %
3878% S t r i p I m a g e %
3879% %
3880% %
3881% %
3882%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3883%
3884% StripImage() strips an image of all profiles and comments.
3885%
3886% The format of the StripImage method is:
3887%
3888% MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
3889%
3890% A description of each parameter follows:
3891%
3892% o image: the image.
3893%
3894% o exception: return any errors or warnings in this structure.
3895%
3896*/
3897MagickExport MagickBooleanType StripImage(Image *image,
3898 ExceptionInfo *magick_unused(exception))
3899{
3900 MagickBooleanType
3901 status;
3902
3903 magick_unreferenced(exception);
3904 assert(image != (Image *) NULL);
3905 if (IsEventLogging() != MagickFalse)
3906 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3907 DestroyImageProfiles(image);
3908 (void) DeleteImageProperty(image,"comment");
3909 (void) DeleteImageProperty(image,"date:create");
3910 (void) DeleteImageProperty(image,"date:modify");
3911 (void) DeleteImageProperty(image,"date:timestamp");
3912 status=SetImageArtifact(image,"png:exclude-chunk",
3913 "bKGD,caNv,cHRM,eXIf,gAMA,iCCP,iTXt,pHYs,sRGB,tEXt,zCCP,zTXt,date");
3914 return(status);
3915}
3916
3917/*
3918%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3919% %
3920% %
3921% %
3922+ S y n c I m a g e %
3923% %
3924% %
3925% %
3926%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3927%
3928% SyncImage() initializes the red, green, and blue intensities of each pixel
3929% as defined by the colormap index.
3930%
3931% The format of the SyncImage method is:
3932%
3933% MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3934%
3935% A description of each parameter follows:
3936%
3937% o image: the image.
3938%
3939% o exception: return any errors or warnings in this structure.
3940%
3941*/
3942
3943static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3944 MagickBooleanType *range_exception)
3945{
3946 if ((size_t) index < image->colors)
3947 return(index);
3948 *range_exception=MagickTrue;
3949 return((Quantum) 0);
3950}
3951
3952MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
3953{
3954 CacheView
3955 *image_view;
3956
3957 MagickBooleanType
3958 range_exception,
3959 status,
3960 taint;
3961
3962 ssize_t
3963 y;
3964
3965 assert(image != (Image *) NULL);
3966 assert(image->signature == MagickCoreSignature);
3967 if (IsEventLogging() != MagickFalse)
3968 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3969 if (image->ping != MagickFalse)
3970 return(MagickTrue);
3971 if (image->storage_class != PseudoClass)
3972 return(MagickFalse);
3973 assert(image->colormap != (PixelInfo *) NULL);
3974 range_exception=MagickFalse;
3975 status=MagickTrue;
3976 taint=image->taint;
3977 image_view=AcquireAuthenticCacheView(image,exception);
3978#if defined(MAGICKCORE_OPENMP_SUPPORT)
3979 #pragma omp parallel for schedule(static) shared(range_exception,status) \
3980 magick_number_threads(image,image,image->rows,2)
3981#endif
3982 for (y=0; y < (ssize_t) image->rows; y++)
3983 {
3984 Quantum
3985 index;
3986
3987 Quantum
3988 *magick_restrict q;
3989
3990 ssize_t
3991 x;
3992
3993 if (status == MagickFalse)
3994 continue;
3995 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3996 if (q == (Quantum *) NULL)
3997 {
3998 status=MagickFalse;
3999 continue;
4000 }
4001 for (x=0; x < (ssize_t) image->columns; x++)
4002 {
4003 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
4004 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
4005 q+=(ptrdiff_t) GetPixelChannels(image);
4006 }
4007 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4008 status=MagickFalse;
4009 }
4010 image_view=DestroyCacheView(image_view);
4011 image->taint=taint;
4012 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
4013 (void) ThrowMagickException(exception,GetMagickModule(),
4014 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
4015 return(status);
4016}
4017
4018/*
4019%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4020% %
4021% %
4022% %
4023% S y n c I m a g e S e t t i n g s %
4024% %
4025% %
4026% %
4027%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4028%
4029% SyncImageSettings() syncs any image_info global options into per-image
4030% attributes.
4031%
4032% Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
4033% that operations and coders can find such settings. In IMv7 if a desired
4034% per-image artifact is not set, then it will directly look for a global
4035% option as a fallback, as such this copy is no longer needed, only the
4036% link set up.
4037%
4038% The format of the SyncImageSettings method is:
4039%
4040% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4041% Image *image,ExceptionInfo *exception)
4042% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4043% Image *image,ExceptionInfo *exception)
4044%
4045% A description of each parameter follows:
4046%
4047% o image_info: the image info.
4048%
4049% o image: the image.
4050%
4051% o exception: return any errors or warnings in this structure.
4052%
4053*/
4054
4055MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4056 Image *images,ExceptionInfo *exception)
4057{
4058 Image
4059 *image;
4060
4061 assert(image_info != (const ImageInfo *) NULL);
4062 assert(image_info->signature == MagickCoreSignature);
4063 assert(images != (Image *) NULL);
4064 assert(images->signature == MagickCoreSignature);
4065 if (IsEventLogging() != MagickFalse)
4066 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4067 image=images;
4068 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4069 (void) SyncImageSettings(image_info,image,exception);
4070 (void) DeleteImageOption(image_info,"page");
4071 return(MagickTrue);
4072}
4073
4074MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4075 Image *image,ExceptionInfo *exception)
4076{
4077 const char
4078 *option;
4079
4080 GeometryInfo
4081 geometry_info;
4082
4083 MagickStatusType
4084 flags;
4085
4086 ResolutionType
4087 units;
4088
4089 /*
4090 Sync image options.
4091 */
4092 assert(image_info != (const ImageInfo *) NULL);
4093 assert(image_info->signature == MagickCoreSignature);
4094 assert(image != (Image *) NULL);
4095 assert(image->signature == MagickCoreSignature);
4096 if (IsEventLogging() != MagickFalse)
4097 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4098 option=GetImageOption(image_info,"background");
4099 if (option != (const char *) NULL)
4100 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
4101 exception);
4102 option=GetImageOption(image_info,"black-point-compensation");
4103 if (option != (const char *) NULL)
4104 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
4105 MagickBooleanOptions,MagickFalse,option);
4106 option=GetImageOption(image_info,"blue-primary");
4107 if (option != (const char *) NULL)
4108 {
4109 flags=ParseGeometry(option,&geometry_info);
4110 if ((flags & RhoValue) != 0)
4111 image->chromaticity.blue_primary.x=geometry_info.rho;
4112 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4113 if ((flags & SigmaValue) != 0)
4114 image->chromaticity.blue_primary.y=geometry_info.sigma;
4115 }
4116 option=GetImageOption(image_info,"bordercolor");
4117 if (option != (const char *) NULL)
4118 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
4119 exception);
4120 /* FUTURE: do not sync compose to per-image compose setting here */
4121 option=GetImageOption(image_info,"compose");
4122 if (option != (const char *) NULL)
4123 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
4124 MagickFalse,option);
4125 /* -- */
4126 option=GetImageOption(image_info,"compress");
4127 if (option != (const char *) NULL)
4128 image->compression=(CompressionType) ParseCommandOption(
4129 MagickCompressOptions,MagickFalse,option);
4130 option=GetImageOption(image_info,"debug");
4131 if (option != (const char *) NULL)
4132 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4133 MagickFalse,option);
4134 option=GetImageOption(image_info,"density");
4135 if (option != (const char *) NULL)
4136 {
4137 flags=ParseGeometry(option,&geometry_info);
4138 if ((flags & RhoValue) != 0)
4139 image->resolution.x=geometry_info.rho;
4140 image->resolution.y=image->resolution.x;
4141 if ((flags & SigmaValue) != 0)
4142 image->resolution.y=geometry_info.sigma;
4143 }
4144 option=GetImageOption(image_info,"depth");
4145 if (option != (const char *) NULL)
4146 image->depth=StringToUnsignedLong(option);
4147 option=GetImageOption(image_info,"endian");
4148 if (option != (const char *) NULL)
4149 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
4150 MagickFalse,option);
4151 option=GetImageOption(image_info,"filter");
4152 if (option != (const char *) NULL)
4153 image->filter=(FilterType) ParseCommandOption(MagickFilterOptions,
4154 MagickFalse,option);
4155 option=GetImageOption(image_info,"fuzz");
4156 if (option != (const char *) NULL)
4157 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
4158 option=GetImageOption(image_info,"gravity");
4159 if (option != (const char *) NULL)
4160 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
4161 MagickFalse,option);
4162 option=GetImageOption(image_info,"green-primary");
4163 if (option != (const char *) NULL)
4164 {
4165 flags=ParseGeometry(option,&geometry_info);
4166 if ((flags & RhoValue) != 0)
4167 image->chromaticity.green_primary.x=geometry_info.rho;
4168 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4169 if ((flags & SigmaValue) != 0)
4170 image->chromaticity.green_primary.y=geometry_info.sigma;
4171 }
4172 option=GetImageOption(image_info,"intent");
4173 if (option != (const char *) NULL)
4174 image->rendering_intent=(RenderingIntent) ParseCommandOption(
4175 MagickIntentOptions,MagickFalse,option);
4176 option=GetImageOption(image_info,"intensity");
4177 if (option != (const char *) NULL)
4178 image->intensity=(PixelIntensityMethod) ParseCommandOption(
4179 MagickPixelIntensityOptions,MagickFalse,option);
4180 option=GetImageOption(image_info,"interlace");
4181 if (option != (const char *) NULL)
4182 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
4183 MagickFalse,option);
4184 option=GetImageOption(image_info,"interpolate");
4185 if (option != (const char *) NULL)
4186 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
4187 MagickInterpolateOptions,MagickFalse,option);
4188 option=GetImageOption(image_info,"loop");
4189 if (option != (const char *) NULL)
4190 image->iterations=StringToUnsignedLong(option);
4191 option=GetImageOption(image_info,"mattecolor");
4192 if (option != (const char *) NULL)
4193 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
4194 exception);
4195 option=GetImageOption(image_info,"orient");
4196 if (option != (const char *) NULL)
4197 image->orientation=(OrientationType) ParseCommandOption(
4198 MagickOrientationOptions,MagickFalse,option);
4199 option=GetImageOption(image_info,"page");
4200 if (option != (const char *) NULL)
4201 {
4202 char
4203 *geometry;
4204
4205 geometry=GetPageGeometry(option);
4206 flags=ParseAbsoluteGeometry(geometry,&image->page);
4207 geometry=DestroyString(geometry);
4208 }
4209 option=GetImageOption(image_info,"quality");
4210 if (option != (const char *) NULL)
4211 image->quality=StringToUnsignedLong(option);
4212 option=GetImageOption(image_info,"red-primary");
4213 if (option != (const char *) NULL)
4214 {
4215 flags=ParseGeometry(option,&geometry_info);
4216 if ((flags & RhoValue) != 0)
4217 image->chromaticity.red_primary.x=geometry_info.rho;
4218 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4219 if ((flags & SigmaValue) != 0)
4220 image->chromaticity.red_primary.y=geometry_info.sigma;
4221 }
4222 if (image_info->quality != UndefinedCompressionQuality)
4223 image->quality=image_info->quality;
4224 option=GetImageOption(image_info,"scene");
4225 if (option != (const char *) NULL)
4226 image->scene=StringToUnsignedLong(option);
4227 option=GetImageOption(image_info,"taint");
4228 if (option != (const char *) NULL)
4229 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
4230 MagickFalse,option);
4231 option=GetImageOption(image_info,"tile-offset");
4232 if (option != (const char *) NULL)
4233 {
4234 char
4235 *geometry;
4236
4237 geometry=GetPageGeometry(option);
4238 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4239 geometry=DestroyString(geometry);
4240 }
4241 option=GetImageOption(image_info,"transparent-color");
4242 if (option != (const char *) NULL)
4243 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
4244 exception);
4245 option=GetImageOption(image_info,"type");
4246 if (option != (const char *) NULL)
4247 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
4248 option);
4249 option=GetImageOption(image_info,"units");
4250 units=image_info->units;
4251 if (option != (const char *) NULL)
4252 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
4253 MagickFalse,option);
4254 if (units != UndefinedResolution)
4255 {
4256 if (image->units != units)
4257 switch (image->units)
4258 {
4259 case PixelsPerInchResolution:
4260 {
4261 if (units == PixelsPerCentimeterResolution)
4262 {
4263 image->resolution.x/=2.54;
4264 image->resolution.y/=2.54;
4265 }
4266 break;
4267 }
4268 case PixelsPerCentimeterResolution:
4269 {
4270 if (units == PixelsPerInchResolution)
4271 {
4272 image->resolution.x=(double) ((size_t) (100.0*2.54*
4273 image->resolution.x+0.5))/100.0;
4274 image->resolution.y=(double) ((size_t) (100.0*2.54*
4275 image->resolution.y+0.5))/100.0;
4276 }
4277 break;
4278 }
4279 default:
4280 break;
4281 }
4282 image->units=units;
4283 option=GetImageOption(image_info,"density");
4284 if (option != (const char *) NULL)
4285 {
4286 flags=ParseGeometry(option,&geometry_info);
4287 if ((flags & RhoValue) != 0)
4288 image->resolution.x=geometry_info.rho;
4289 image->resolution.y=image->resolution.x;
4290 if ((flags & SigmaValue) != 0)
4291 image->resolution.y=geometry_info.sigma;
4292 }
4293 }
4294 option=GetImageOption(image_info,"virtual-pixel");
4295 if (option != (const char *) NULL)
4296 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
4297 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
4298 exception);
4299 option=GetImageOption(image_info,"white-point");
4300 if (option != (const char *) NULL)
4301 {
4302 flags=ParseGeometry(option,&geometry_info);
4303 if ((flags & RhoValue) != 0)
4304 image->chromaticity.white_point.x=geometry_info.rho;
4305 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4306 if ((flags & SigmaValue) != 0)
4307 image->chromaticity.white_point.y=geometry_info.sigma;
4308 }
4309 /*
4310 Pointer to allow the lookup of pre-image artifact will fallback to a global
4311 option setting/define. This saves a lot of duplication of global options
4312 into per-image artifacts, while ensuring only specifically set per-image
4313 artifacts are preserved when parenthesis ends.
4314 */
4315 if (image->image_info != (ImageInfo *) NULL)
4316 image->image_info=DestroyImageInfo(image->image_info);
4317 image->image_info=CloneImageInfo(image_info);
4318 return(MagickTrue);
4319}