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