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