blob: bc38f07072fe4cef8127c899d58b62846521dd93 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% John Cristy %
17% July 1992 %
18% %
19% %
cristy16af1cb2009-12-11 21:38:29 +000020% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% 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% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
43#include "magick/studio.h"
44#include "magick/animate.h"
45#include "magick/artifact.h"
46#include "magick/blob.h"
47#include "magick/blob-private.h"
48#include "magick/cache.h"
49#include "magick/cache-private.h"
50#include "magick/cache-view.h"
51#include "magick/client.h"
52#include "magick/color.h"
53#include "magick/color-private.h"
cristy316d5172009-09-17 19:31:25 +000054#include "magick/colormap.h"
cristy3ed852e2009-09-05 21:47:34 +000055#include "magick/colorspace.h"
56#include "magick/colorspace-private.h"
57#include "magick/composite.h"
58#include "magick/composite-private.h"
59#include "magick/compress.h"
60#include "magick/constitute.h"
61#include "magick/deprecate.h"
62#include "magick/display.h"
63#include "magick/draw.h"
64#include "magick/enhance.h"
65#include "magick/exception.h"
66#include "magick/exception-private.h"
67#include "magick/gem.h"
68#include "magick/geometry.h"
cristyf2e11662009-10-14 01:24:43 +000069#include "magick/histogram.h"
cristy3ed852e2009-09-05 21:47:34 +000070#include "magick/image-private.h"
cristyf2e11662009-10-14 01:24:43 +000071#include "magick/list.h"
cristy3ed852e2009-09-05 21:47:34 +000072#include "magick/magic.h"
73#include "magick/magick.h"
74#include "magick/memory_.h"
75#include "magick/module.h"
76#include "magick/monitor.h"
77#include "magick/monitor-private.h"
78#include "magick/option.h"
79#include "magick/paint.h"
80#include "magick/pixel-private.h"
81#include "magick/profile.h"
82#include "magick/property.h"
83#include "magick/quantize.h"
84#include "magick/random_.h"
85#include "magick/segment.h"
86#include "magick/semaphore.h"
87#include "magick/signature-private.h"
88#include "magick/statistic.h"
89#include "magick/string_.h"
cristyf2f27272009-12-17 14:48:46 +000090#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000091#include "magick/thread-private.h"
92#include "magick/threshold.h"
93#include "magick/timer.h"
94#include "magick/utility.h"
95#include "magick/version.h"
96#include "magick/xwindow-private.h"
97
98/*
99 Constant declaration.
100*/
101const char
cristy7138c592009-09-08 13:58:52 +0000102 BackgroundColor[] = "#ffffff", /* white */
103 BorderColor[] = "#dfdfdf", /* gray */
104 DefaultTileFrame[] = "15x15+3+3",
105 DefaultTileGeometry[] = "120x120+4+3>",
106 DefaultTileLabel[] = "%f\n%G\n%b",
107 ForegroundColor[] = "#000", /* black */
108 LoadImageTag[] = "Load/Image",
109 LoadImagesTag[] = "Load/Images",
110 MatteColor[] = "#bdbdbd", /* gray */
111 PSDensityGeometry[] = "72.0x72.0",
112 PSPageGeometry[] = "612x792",
113 SaveImageTag[] = "Save/Image",
114 SaveImagesTag[] = "Save/Images",
115 TransparentColor[] = "#00000000"; /* transparent black */
cristy3ed852e2009-09-05 21:47:34 +0000116
117const double
118 DefaultResolution = 72.0;
119
120/*
121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122% %
123% %
124% %
125% A c q u i r e I m a g e %
126% %
127% %
128% %
129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130%
131% AcquireImage() returns a pointer to an image structure initialized to
132% default values.
133%
134% The format of the AcquireImage method is:
135%
136% Image *AcquireImage(const ImageInfo *image_info)
137%
138% A description of each parameter follows:
139%
140% o image_info: Many of the image default values are set from this
141% structure. For example, filename, compression, depth, background color,
142% and others.
143%
144*/
145MagickExport Image *AcquireImage(const ImageInfo *image_info)
146{
147 Image
148 *image;
149
150 MagickStatusType
151 flags;
152
153 /*
154 Allocate image structure.
155 */
156 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy90823212009-12-12 20:48:33 +0000157 image=(Image *) AcquireAlignedMemory(1,sizeof(*image));
cristy3ed852e2009-09-05 21:47:34 +0000158 if (image == (Image *) NULL)
159 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
160 (void) ResetMagickMemory(image,0,sizeof(*image));
161 /*
162 Initialize Image structure.
163 */
164 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
165 image->storage_class=DirectClass;
166 image->depth=MAGICKCORE_QUANTUM_DEPTH;
167 image->colorspace=RGBColorspace;
168 image->interlace=NoInterlace;
169 image->ticks_per_second=UndefinedTicksPerSecond;
170 image->compose=OverCompositeOp;
171 image->blur=1.0;
172 GetExceptionInfo(&image->exception);
173 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
174 &image->exception);
175 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
176 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
177 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
178 &image->exception);
179 image->x_resolution=DefaultResolution;
180 image->y_resolution=DefaultResolution;
181 image->units=PixelsPerInchResolution;
182 GetTimerInfo(&image->timer);
cristy73724512010-04-12 14:43:14 +0000183 image->ping=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000184 image->cache=AcquirePixelCache(0);
185 image->blob=CloneBlobInfo((BlobInfo *) NULL);
186 image->debug=IsEventLogging();
187 image->reference_count=1;
188 image->semaphore=AllocateSemaphoreInfo();
189 image->signature=MagickSignature;
190 if (image_info == (ImageInfo *) NULL)
191 return(image);
192 /*
193 Transfer image info.
194 */
195 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
196 MagickFalse);
197 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
198 (void) CopyMagickString(image->magick_filename,image_info->filename,
199 MaxTextExtent);
200 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
201 if (image_info->size != (char *) NULL)
202 {
203 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
204 image->columns=image->extract_info.width;
205 image->rows=image->extract_info.height;
206 image->offset=image->extract_info.x;
207 image->extract_info.x=0;
208 image->extract_info.y=0;
209 }
210 if (image_info->extract != (char *) NULL)
211 {
212 RectangleInfo
213 geometry;
214
215 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
216 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
217 {
218 image->extract_info=geometry;
219 Swap(image->columns,image->extract_info.width);
220 Swap(image->rows,image->extract_info.height);
221 }
222 }
223 image->compression=image_info->compression;
224 image->quality=image_info->quality;
225 image->endian=image_info->endian;
226 image->interlace=image_info->interlace;
227 image->units=image_info->units;
228 if (image_info->density != (char *) NULL)
229 {
230 GeometryInfo
231 geometry_info;
232
233 flags=ParseGeometry(image_info->density,&geometry_info);
234 image->x_resolution=geometry_info.rho;
235 image->y_resolution=geometry_info.sigma;
236 if ((flags & SigmaValue) == 0)
237 image->y_resolution=image->x_resolution;
238 }
239 if (image_info->page != (char *) NULL)
240 {
241 char
242 *geometry;
243
244 image->page=image->extract_info;
245 geometry=GetPageGeometry(image_info->page);
246 (void) ParseAbsoluteGeometry(geometry,&image->page);
247 geometry=DestroyString(geometry);
248 }
249 if (image_info->depth != 0)
250 image->depth=image_info->depth;
251 image->dither=image_info->dither;
252 image->background_color=image_info->background_color;
253 image->border_color=image_info->border_color;
254 image->matte_color=image_info->matte_color;
255 image->transparent_color=image_info->transparent_color;
cristy73724512010-04-12 14:43:14 +0000256 image->ping=image_info->ping;
cristy3ed852e2009-09-05 21:47:34 +0000257 image->progress_monitor=image_info->progress_monitor;
258 image->client_data=image_info->client_data;
259 if (image_info->cache != (void *) NULL)
260 ClonePixelCacheMethods(image->cache,image_info->cache);
261 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
cristy6b9aca12010-02-21 01:50:11 +0000262 (void) SyncImageSettings(image_info,image);
cristy3ed852e2009-09-05 21:47:34 +0000263 return(image);
264}
265
266/*
267%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
268% %
269% %
270% %
cristy3ed852e2009-09-05 21:47:34 +0000271% A c q u i r e I m a g e I n f o %
272% %
273% %
274% %
275%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
276%
277% AcquireImageInfo() allocates the ImageInfo structure.
278%
279% The format of the AcquireImageInfo method is:
280%
281% ImageInfo *AcquireImageInfo(void)
282%
283*/
284MagickExport ImageInfo *AcquireImageInfo(void)
285{
286 ImageInfo
287 *image_info;
288
cristy90823212009-12-12 20:48:33 +0000289 image_info=(ImageInfo *) AcquireAlignedMemory(1,sizeof(*image_info));
cristy3ed852e2009-09-05 21:47:34 +0000290 if (image_info == (ImageInfo *) NULL)
291 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
292 GetImageInfo(image_info);
293 return(image_info);
294}
295
296/*
297%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298% %
299% %
300% %
301% A c q u i r e N e x t I m a g e %
302% %
303% %
304% %
305%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306%
307% AcquireNextImage() initializes the next image in a sequence to
308% default values. The next member of image points to the newly allocated
309% image. If there is a memory shortage, next is assigned NULL.
310%
311% The format of the AcquireNextImage method is:
312%
313% void AcquireNextImage(const ImageInfo *image_info,Image *image)
314%
315% A description of each parameter follows:
316%
317% o image_info: Many of the image default values are set from this
318% structure. For example, filename, compression, depth, background color,
319% and others.
320%
321% o image: the image.
322%
323*/
324MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
325{
326 /*
327 Allocate image structure.
328 */
329 assert(image != (Image *) NULL);
330 assert(image->signature == MagickSignature);
331 if (image->debug != MagickFalse)
332 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
333 image->next=AcquireImage(image_info);
334 if (GetNextImageInList(image) == (Image *) NULL)
335 return;
336 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
337 MaxTextExtent);
338 if (image_info != (ImageInfo *) NULL)
339 (void) CopyMagickString(GetNextImageInList(image)->filename,
340 image_info->filename,MaxTextExtent);
341 DestroyBlob(GetNextImageInList(image));
342 image->next->blob=ReferenceBlob(image->blob);
343 image->next->endian=image->endian;
344 image->next->scene=image->scene+1;
345 image->next->previous=image;
346}
347
348/*
349%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350% %
351% %
352% %
353% A p p e n d I m a g e s %
354% %
355% %
356% %
357%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358%
359% AppendImages() takes all images from the current image pointer to the end
360% of the image list and appends them to each other top-to-bottom if the
361% stack parameter is true, otherwise left-to-right.
362%
363% The current gravity setting now effects how the image is justified in the
364% final image.
365%
366% The format of the AppendImages method is:
367%
368% Image *AppendImages(const Image *image,const MagickBooleanType stack,
369% ExceptionInfo *exception)
370%
371% A description of each parameter follows:
372%
373% o image: the image sequence.
374%
375% o stack: A value other than 0 stacks the images top-to-bottom.
376%
377% o exception: return any errors or warnings in this structure.
378%
379*/
380MagickExport Image *AppendImages(const Image *image,
381 const MagickBooleanType stack,ExceptionInfo *exception)
382{
383#define AppendImageTag "Append/Image"
384
385 CacheView
386 *append_view,
387 *image_view;
388
389 Image
390 *append_image;
391
392 long
393 n,
394 x_offset,
395 y,
396 y_offset;
397
398 MagickBooleanType
399 matte,
400 proceed,
401 status;
402
403 RectangleInfo
404 geometry;
405
406 register const Image
407 *next;
408
409 unsigned long
410 height,
411 number_images,
412 width;
413
414 /*
415 Ensure the image have the same column width.
416 */
417 assert(image != (Image *) NULL);
418 assert(image->signature == MagickSignature);
419 if (image->debug != MagickFalse)
420 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
421 assert(exception != (ExceptionInfo *) NULL);
422 assert(exception->signature == MagickSignature);
423 matte=image->matte;
424 number_images=1;
425 width=image->columns;
426 height=image->rows;
427 next=GetNextImageInList(image);
428 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
429 {
430 if (next->matte != MagickFalse)
431 matte=MagickTrue;
432 number_images++;
433 if (stack != MagickFalse)
434 {
435 if (next->columns > width)
436 width=next->columns;
437 height+=next->rows;
438 continue;
439 }
440 width+=next->columns;
441 if (next->rows > height)
442 height=next->rows;
443 }
444 /*
445 Initialize append next attributes.
446 */
447 append_image=CloneImage(image,width,height,MagickTrue,exception);
448 if (append_image == (Image *) NULL)
449 return((Image *) NULL);
450 if (SetImageStorageClass(append_image,DirectClass) == MagickFalse)
451 {
452 InheritException(exception,&append_image->exception);
453 append_image=DestroyImage(append_image);
454 return((Image *) NULL);
455 }
456 append_image->matte=matte;
457 (void) SetImageBackgroundColor(append_image);
458 status=MagickTrue;
459 x_offset=0;
460 y_offset=0;
461 append_view=AcquireCacheView(append_image);
462 for (n=0; n < (long) number_images; n++)
463 {
464 SetGeometry(append_image,&geometry);
465 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
466 if (stack != MagickFalse)
467 x_offset-=geometry.x;
468 else
469 y_offset-=geometry.y;
470 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +0000471#if defined(MAGICKCORE_OPENMP_SUPPORT)
472 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +0000473#endif
474 for (y=0; y < (long) image->rows; y++)
475 {
476 MagickBooleanType
477 sync;
478
479 register const IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000480 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000481
482 register const PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000483 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000484
485 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000486 *restrict append_indexes;
cristy3ed852e2009-09-05 21:47:34 +0000487
488 register long
489 x;
490
491 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000492 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000493
494 if (status == MagickFalse)
495 continue;
496 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
497 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
498 image->columns,1,exception);
499 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
500 {
501 status=MagickFalse;
502 continue;
503 }
504 indexes=GetCacheViewVirtualIndexQueue(image_view);
505 append_indexes=GetCacheViewAuthenticIndexQueue(append_view);
506 for (x=0; x < (long) image->columns; x++)
507 {
cristyce70c172010-01-07 17:15:30 +0000508 SetRedPixelComponent(q,GetRedPixelComponent(p));
509 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
510 SetBluePixelComponent(q,GetBluePixelComponent(p));
511 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000512 if (image->matte != MagickFalse)
cristyce70c172010-01-07 17:15:30 +0000513 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +0000514 if (image->colorspace == CMYKColorspace)
515 append_indexes[x]=indexes[x];
516 p++;
517 q++;
518 }
519 sync=SyncCacheViewAuthenticPixels(append_view,exception);
520 if (sync == MagickFalse)
cristya65f35b2010-04-20 01:10:41 +0000521 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000522 }
523 image_view=DestroyCacheView(image_view);
524 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
525 if (proceed == MagickFalse)
526 break;
527 if (stack == MagickFalse)
528 {
529 x_offset+=image->columns;
530 y_offset=0;
531 }
532 else
533 {
534 x_offset=0;
535 y_offset+=image->rows;
536 }
537 image=GetNextImageInList(image);
538 }
539 append_view=DestroyCacheView(append_view);
540 if (status == MagickFalse)
541 append_image=DestroyImage(append_image);
542 return(append_image);
543}
544
545/*
546%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547% %
548% %
549% %
cristy3ed852e2009-09-05 21:47:34 +0000550% C a t c h I m a g e E x c e p t i o n %
551% %
552% %
553% %
554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
555%
556% CatchImageException() returns if no exceptions are found in the image
557% sequence, otherwise it determines the most severe exception and reports
558% it as a warning or error depending on the severity.
559%
560% The format of the CatchImageException method is:
561%
562% ExceptionType CatchImageException(Image *image)
563%
564% A description of each parameter follows:
565%
566% o image: An image sequence.
567%
568*/
569MagickExport ExceptionType CatchImageException(Image *image)
570{
571 ExceptionInfo
572 *exception;
573
574 ExceptionType
575 severity;
576
577 assert(image != (const Image *) NULL);
578 assert(image->signature == MagickSignature);
579 if (image->debug != MagickFalse)
580 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
581 exception=AcquireExceptionInfo();
582 GetImageException(image,exception);
583 CatchException(exception);
584 severity=exception->severity;
585 exception=DestroyExceptionInfo(exception);
586 return(severity);
587}
588
589/*
590%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
591% %
592% %
593% %
594% C l i p I m a g e P a t h %
595% %
596% %
597% %
598%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
599%
600% ClipImagePath() sets the image clip mask based any clipping path information
601% if it exists.
602%
603% The format of the ClipImagePath method is:
604%
605% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
606% const MagickBooleanType inside)
607%
608% A description of each parameter follows:
609%
610% o image: the image.
611%
612% o pathname: name of clipping path resource. If name is preceded by #, use
613% clipping path numbered by name.
614%
615% o inside: if non-zero, later operations take effect inside clipping path.
616% Otherwise later operations take effect outside clipping path.
617%
618*/
619
620MagickExport MagickBooleanType ClipImage(Image *image)
621{
622 return(ClipImagePath(image,"#1",MagickTrue));
623}
624
625MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
626 const MagickBooleanType inside)
627{
628#define ClipImagePathTag "ClipPath/Image"
629
630 char
631 *property;
632
633 const char
634 *value;
635
636 Image
637 *clip_mask;
638
639 ImageInfo
640 *image_info;
641
642 assert(image != (const Image *) NULL);
643 assert(image->signature == MagickSignature);
644 if (image->debug != MagickFalse)
645 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
646 assert(pathname != NULL);
647 property=AcquireString(pathname);
648 (void) FormatMagickString(property,MaxTextExtent,"8BIM:1999,2998:%s",
649 pathname);
650 value=GetImageProperty(image,property);
651 property=DestroyString(property);
652 if (value == (const char *) NULL)
653 {
654 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
655 image->filename);
656 return(MagickFalse);
657 }
658 image_info=AcquireImageInfo();
659 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
660 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
661 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
662 image_info=DestroyImageInfo(image_info);
663 if (clip_mask == (Image *) NULL)
664 return(MagickFalse);
665 if (clip_mask->storage_class == PseudoClass)
666 {
667 (void) SyncImage(clip_mask);
668 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
669 return(MagickFalse);
670 }
671 if (inside == MagickFalse)
672 (void) NegateImage(clip_mask,MagickFalse);
673 (void) FormatMagickString(clip_mask->magick_filename,MaxTextExtent,
674 "8BIM:1999,2998:%s\nPS",pathname);
675 (void) SetImageClipMask(image,clip_mask);
676 clip_mask=DestroyImage(clip_mask);
677 return(MagickTrue);
678}
679
680/*
681%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
682% %
683% %
684% %
685% C l o n e I m a g e %
686% %
687% %
688% %
689%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
690%
691% CloneImage() copies an image and returns the copy as a new image object.
692% If the specified columns and rows is 0, an exact copy of the image is
693% returned, otherwise the pixel data is undefined and must be initialized
694% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
695% failure, a NULL image is returned and exception describes the reason for the
696% failure.
697%
698% The format of the CloneImage method is:
699%
700% Image *CloneImage(const Image *image,const unsigned long columns,
701% const unsigned long rows,const MagickBooleanType orphan,
702% ExceptionInfo *exception)
703%
704% A description of each parameter follows:
705%
706% o image: the image.
707%
708% o columns: the number of columns in the cloned image.
709%
710% o rows: the number of rows in the cloned image.
711%
712% o detach: With a value other than 0, the cloned image is detached from
713% its parent I/O stream.
714%
715% o exception: return any errors or warnings in this structure.
716%
717*/
718MagickExport Image *CloneImage(const Image *image,const unsigned long columns,
719 const unsigned long rows,const MagickBooleanType detach,
720 ExceptionInfo *exception)
721{
722 Image
723 *clone_image;
724
725 MagickRealType
726 scale;
727
728 size_t
729 length;
730
731 /*
732 Clone the image.
733 */
734 assert(image != (const Image *) NULL);
735 assert(image->signature == MagickSignature);
736 if (image->debug != MagickFalse)
737 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
738 assert(exception != (ExceptionInfo *) NULL);
739 assert(exception->signature == MagickSignature);
cristy90823212009-12-12 20:48:33 +0000740 clone_image=(Image *) AcquireAlignedMemory(1,sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000741 if (clone_image == (Image *) NULL)
742 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
743 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
744 clone_image->signature=MagickSignature;
745 clone_image->storage_class=image->storage_class;
746 clone_image->colorspace=image->colorspace;
747 clone_image->matte=image->matte;
748 clone_image->columns=image->columns;
749 clone_image->rows=image->rows;
750 clone_image->dither=image->dither;
751 if (image->colormap != (PixelPacket *) NULL)
752 {
753 /*
754 Allocate and copy the image colormap.
755 */
756 clone_image->colors=image->colors;
757 length=(size_t) image->colors;
758 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
759 sizeof(*clone_image->colormap));
760 if (clone_image->colormap == (PixelPacket *) NULL)
761 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
762 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
763 sizeof(*clone_image->colormap));
764 }
765 (void) CloneImageProfiles(clone_image,image);
766 (void) CloneImageProperties(clone_image,image);
767 (void) CloneImageArtifacts(clone_image,image);
768 GetTimerInfo(&clone_image->timer);
769 GetExceptionInfo(&clone_image->exception);
770 InheritException(&clone_image->exception,&image->exception);
771 if (image->ascii85 != (void *) NULL)
772 Ascii85Initialize(clone_image);
773 clone_image->magick_columns=image->magick_columns;
774 clone_image->magick_rows=image->magick_rows;
775 clone_image->type=image->type;
776 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
777 MaxTextExtent);
778 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
779 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
780 clone_image->progress_monitor=image->progress_monitor;
781 clone_image->client_data=image->client_data;
782 clone_image->reference_count=1;
783 clone_image->next=NewImageList();
784 clone_image->previous=NewImageList();
785 clone_image->list=NewImageList();
786 clone_image->clip_mask=NewImageList();
787 clone_image->mask=NewImageList();
788 if (detach == MagickFalse)
789 clone_image->blob=ReferenceBlob(image->blob);
790 else
791 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
cristy73724512010-04-12 14:43:14 +0000792 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000793 clone_image->debug=IsEventLogging();
794 clone_image->semaphore=AllocateSemaphoreInfo();
795 if ((columns == 0) && (rows == 0))
796 {
797 if (image->montage != (char *) NULL)
798 (void) CloneString(&clone_image->montage,image->montage);
799 if (image->directory != (char *) NULL)
800 (void) CloneString(&clone_image->directory,image->directory);
801 if (image->clip_mask != (Image *) NULL)
802 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
803 exception);
804 if (image->mask != (Image *) NULL)
805 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
806 clone_image->cache=ReferencePixelCache(image->cache);
807 return(clone_image);
808 }
809 scale=(MagickRealType) columns/(MagickRealType) image->columns;
cristy06609ee2010-03-17 20:21:27 +0000810 clone_image->page.width=(unsigned long) floor(scale*image->page.width+0.5);
811 clone_image->page.x=(long) ceil(scale*image->page.x-0.5);
812 clone_image->tile_offset.x=(long) ceil(scale*image->tile_offset.x-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000813 scale=(MagickRealType) rows/(MagickRealType) image->rows;
cristy06609ee2010-03-17 20:21:27 +0000814 clone_image->page.height=(unsigned long) floor(scale*image->page.height+0.5);
cristy342de4c2010-03-26 19:17:25 +0000815 clone_image->page.y=(long) ceil(scale*image->page.y-0.5);
cristy06609ee2010-03-17 20:21:27 +0000816 clone_image->tile_offset.y=(long) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000817 clone_image->columns=columns;
818 clone_image->rows=rows;
819 clone_image->cache=ClonePixelCache(image->cache);
820 return(clone_image);
821}
822
823/*
824%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
825% %
826% %
827% %
828% C l o n e I m a g e I n f o %
829% %
830% %
831% %
832%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
833%
834% CloneImageInfo() makes a copy of the given image info structure. If
835% NULL is specified, a new image info structure is created initialized to
836% default values.
837%
838% The format of the CloneImageInfo method is:
839%
840% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
841%
842% A description of each parameter follows:
843%
844% o image_info: the image info.
845%
846*/
847MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
848{
849 ImageInfo
850 *clone_info;
851
852 clone_info=AcquireImageInfo();
853 if (image_info == (ImageInfo *) NULL)
854 return(clone_info);
855 clone_info->compression=image_info->compression;
856 clone_info->temporary=image_info->temporary;
857 clone_info->adjoin=image_info->adjoin;
858 clone_info->antialias=image_info->antialias;
859 clone_info->scene=image_info->scene;
860 clone_info->number_scenes=image_info->number_scenes;
861 clone_info->depth=image_info->depth;
862 if (image_info->size != (char *) NULL)
863 (void) CloneString(&clone_info->size,image_info->size);
864 if (image_info->extract != (char *) NULL)
865 (void) CloneString(&clone_info->extract,image_info->extract);
866 if (image_info->scenes != (char *) NULL)
867 (void) CloneString(&clone_info->scenes,image_info->scenes);
868 if (image_info->page != (char *) NULL)
869 (void) CloneString(&clone_info->page,image_info->page);
870 clone_info->interlace=image_info->interlace;
871 clone_info->endian=image_info->endian;
872 clone_info->units=image_info->units;
873 clone_info->quality=image_info->quality;
874 if (image_info->sampling_factor != (char *) NULL)
875 (void) CloneString(&clone_info->sampling_factor,
876 image_info->sampling_factor);
877 if (image_info->server_name != (char *) NULL)
878 (void) CloneString(&clone_info->server_name,image_info->server_name);
879 if (image_info->font != (char *) NULL)
880 (void) CloneString(&clone_info->font,image_info->font);
881 if (image_info->texture != (char *) NULL)
882 (void) CloneString(&clone_info->texture,image_info->texture);
883 if (image_info->density != (char *) NULL)
884 (void) CloneString(&clone_info->density,image_info->density);
885 clone_info->pointsize=image_info->pointsize;
886 clone_info->fuzz=image_info->fuzz;
887 clone_info->pen=image_info->pen;
888 clone_info->background_color=image_info->background_color;
889 clone_info->border_color=image_info->border_color;
890 clone_info->matte_color=image_info->matte_color;
891 clone_info->transparent_color=image_info->transparent_color;
892 clone_info->dither=image_info->dither;
893 clone_info->monochrome=image_info->monochrome;
894 clone_info->colors=image_info->colors;
895 clone_info->colorspace=image_info->colorspace;
896 clone_info->type=image_info->type;
897 clone_info->orientation=image_info->orientation;
898 clone_info->preview_type=image_info->preview_type;
899 clone_info->group=image_info->group;
900 clone_info->ping=image_info->ping;
901 clone_info->verbose=image_info->verbose;
902 if (image_info->view != (char *) NULL)
903 (void) CloneString(&clone_info->view,image_info->view);
904 if (image_info->authenticate != (char *) NULL)
905 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
906 (void) CloneImageOptions(clone_info,image_info);
907 clone_info->progress_monitor=image_info->progress_monitor;
908 clone_info->client_data=image_info->client_data;
909 clone_info->cache=image_info->cache;
910 if (image_info->cache != (void *) NULL)
911 clone_info->cache=ReferencePixelCache(image_info->cache);
912 if (image_info->profile != (void *) NULL)
913 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
914 image_info->profile);
915 SetImageInfoFile(clone_info,image_info->file);
916 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
917 clone_info->stream=image_info->stream;
918 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
919 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
920 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
921 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
922 (void) CopyMagickString(clone_info->filename,image_info->filename,
923 MaxTextExtent);
924 clone_info->subimage=image_info->scene; /* deprecated */
925 clone_info->subrange=image_info->number_scenes; /* deprecated */
926 clone_info->channel=image_info->channel;
927 clone_info->debug=IsEventLogging();
928 clone_info->signature=image_info->signature;
929 return(clone_info);
930}
931
932/*
933%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
934% %
935% %
936% %
937% C o m b i n e I m a g e s %
938% %
939% %
940% %
941%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
942%
943% CombineImages() combines one or more images into a single image. The
944% grayscale value of the pixels of each image in the sequence is assigned in
945% order to the specified channels of the combined image. The typical
946% ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
947%
948% The format of the CombineImages method is:
949%
950% Image *CombineImages(const Image *image,const ChannelType channel,
951% ExceptionInfo *exception)
952%
953% A description of each parameter follows:
954%
955% o image: the image.
956%
957% o exception: return any errors or warnings in this structure.
958%
959*/
960MagickExport Image *CombineImages(const Image *image,const ChannelType channel,
961 ExceptionInfo *exception)
962{
963#define CombineImageTag "Combine/Image"
964
965 CacheView
966 *combine_view;
967
968 const Image
969 *next;
970
971 Image
972 *combine_image;
973
974 long
975 progress,
976 y;
977
978 MagickBooleanType
979 status;
980
981 /*
982 Ensure the image are the same size.
983 */
984 assert(image != (const Image *) NULL);
985 assert(image->signature == MagickSignature);
986 if (image->debug != MagickFalse)
987 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
988 assert(exception != (ExceptionInfo *) NULL);
989 assert(exception->signature == MagickSignature);
990 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
991 {
992 if ((next->columns != image->columns) || (next->rows != image->rows))
993 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
994 }
995 combine_image=CloneImage(image,0,0,MagickTrue,exception);
996 if (combine_image == (Image *) NULL)
997 return((Image *) NULL);
998 if (SetImageStorageClass(combine_image,DirectClass) == MagickFalse)
999 {
1000 InheritException(exception,&combine_image->exception);
1001 combine_image=DestroyImage(combine_image);
1002 return((Image *) NULL);
1003 }
1004 if ((channel & OpacityChannel) != 0)
1005 combine_image->matte=MagickTrue;
1006 (void) SetImageBackgroundColor(combine_image);
1007 /*
1008 Combine images.
1009 */
1010 status=MagickTrue;
1011 progress=0;
1012 combine_view=AcquireCacheView(combine_image);
cristyb5d5f722009-11-04 03:03:49 +00001013#if defined(MAGICKCORE_OPENMP_SUPPORT)
1014 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00001015#endif
1016 for (y=0; y < (long) combine_image->rows; y++)
1017 {
1018 CacheView
1019 *image_view;
1020
1021 const Image
1022 *next;
1023
1024 PixelPacket
1025 *pixels;
1026
1027 register const PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001028 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001029
1030 register long
1031 x;
1032
1033 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001034 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001035
1036 if (status == MagickFalse)
1037 continue;
1038 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1039 1,exception);
1040 if (pixels == (PixelPacket *) NULL)
1041 {
1042 status=MagickFalse;
1043 continue;
1044 }
1045 next=image;
1046 if (((channel & RedChannel) != 0) && (next != (Image *) NULL))
1047 {
1048 image_view=AcquireCacheView(next);
1049 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1050 if (p == (const PixelPacket *) NULL)
1051 continue;
1052 q=pixels;
1053 for (x=0; x < (long) combine_image->columns; x++)
1054 {
cristyce70c172010-01-07 17:15:30 +00001055 SetRedPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001056 p++;
1057 q++;
1058 }
1059 image_view=DestroyCacheView(image_view);
1060 next=GetNextImageInList(next);
1061 }
1062 if (((channel & GreenChannel) != 0) && (next != (Image *) NULL))
1063 {
1064 image_view=AcquireCacheView(next);
1065 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1066 if (p == (const PixelPacket *) NULL)
1067 continue;
1068 q=pixels;
1069 for (x=0; x < (long) combine_image->columns; x++)
1070 {
cristyce70c172010-01-07 17:15:30 +00001071 SetGreenPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001072 p++;
1073 q++;
1074 }
1075 image_view=DestroyCacheView(image_view);
1076 next=GetNextImageInList(next);
1077 }
1078 if (((channel & BlueChannel) != 0) && (next != (Image *) NULL))
1079 {
1080 image_view=AcquireCacheView(next);
1081 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1082 if (p == (const PixelPacket *) NULL)
1083 continue;
1084 q=pixels;
1085 for (x=0; x < (long) combine_image->columns; x++)
1086 {
cristyce70c172010-01-07 17:15:30 +00001087 SetBluePixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001088 p++;
1089 q++;
1090 }
1091 image_view=DestroyCacheView(image_view);
1092 next=GetNextImageInList(next);
1093 }
1094 if (((channel & OpacityChannel) != 0) && (next != (Image *) NULL))
1095 {
1096 image_view=AcquireCacheView(next);
1097 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1098 if (p == (const PixelPacket *) NULL)
1099 continue;
1100 q=pixels;
1101 for (x=0; x < (long) combine_image->columns; x++)
1102 {
cristyce70c172010-01-07 17:15:30 +00001103 SetOpacityPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001104 p++;
1105 q++;
1106 }
1107 image_view=DestroyCacheView(image_view);
1108 next=GetNextImageInList(next);
1109 }
1110 if (((channel & IndexChannel) != 0) &&
1111 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1112 {
1113 IndexPacket
1114 *indexes;
1115
1116 image_view=AcquireCacheView(next);
1117 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1118 if (p == (const PixelPacket *) NULL)
1119 continue;
1120 indexes=GetCacheViewAuthenticIndexQueue(combine_view);
1121 for (x=0; x < (long) combine_image->columns; x++)
1122 {
1123 indexes[x]=PixelIntensityToQuantum(p);
1124 p++;
1125 }
1126 image_view=DestroyCacheView(image_view);
1127 next=GetNextImageInList(next);
1128 }
1129 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1130 status=MagickFalse;
1131 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1132 {
1133 MagickBooleanType
1134 proceed;
1135
cristyb5d5f722009-11-04 03:03:49 +00001136#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00001137 #pragma omp critical (MagickCore_CombineImages)
1138#endif
1139 proceed=SetImageProgress(image,CombineImageTag,progress++,
1140 combine_image->rows);
1141 if (proceed == MagickFalse)
1142 status=MagickFalse;
1143 }
1144 }
1145 combine_view=DestroyCacheView(combine_view);
1146 if (status == MagickFalse)
1147 combine_image=DestroyImage(combine_image);
1148 return(combine_image);
1149}
1150
1151/*
1152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1153% %
1154% %
1155% %
cristy3ed852e2009-09-05 21:47:34 +00001156% D e s t r o y I m a g e %
1157% %
1158% %
1159% %
1160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1161%
1162% DestroyImage() dereferences an image, deallocating memory associated with
1163% the image if the reference count becomes zero.
1164%
1165% The format of the DestroyImage method is:
1166%
1167% Image *DestroyImage(Image *image)
1168%
1169% A description of each parameter follows:
1170%
1171% o image: the image.
1172%
1173*/
1174MagickExport Image *DestroyImage(Image *image)
1175{
1176 MagickBooleanType
1177 destroy;
1178
1179 /*
1180 Dereference image.
1181 */
1182 assert(image != (Image *) NULL);
1183 assert(image->signature == MagickSignature);
1184 if (image->debug != MagickFalse)
1185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1186 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001187 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001188 image->reference_count--;
1189 if (image->reference_count == 0)
1190 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001191 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001192 if (destroy == MagickFalse)
1193 return((Image *) NULL);
1194 /*
1195 Destroy image.
1196 */
1197 DestroyImagePixels(image);
1198 if (image->clip_mask != (Image *) NULL)
1199 image->clip_mask=DestroyImage(image->clip_mask);
1200 if (image->mask != (Image *) NULL)
1201 image->mask=DestroyImage(image->mask);
1202 if (image->montage != (char *) NULL)
1203 image->montage=DestroyString(image->montage);
1204 if (image->directory != (char *) NULL)
1205 image->directory=DestroyString(image->directory);
1206 if (image->colormap != (PixelPacket *) NULL)
1207 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1208 if (image->geometry != (char *) NULL)
1209 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001210 DestroyImageProfiles(image);
1211 DestroyImageProperties(image);
1212 DestroyImageArtifacts(image);
1213 if (image->ascii85 != (Ascii85Info*) NULL)
1214 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1215 DestroyBlob(image);
1216 (void) DestroyExceptionInfo(&image->exception);
1217 if (image->semaphore != (SemaphoreInfo *) NULL)
1218 DestroySemaphoreInfo(&image->semaphore);
1219 image->signature=(~MagickSignature);
1220 image=(Image *) RelinquishMagickMemory(image);
1221 return(image);
1222}
1223
1224/*
1225%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1226% %
1227% %
1228% %
1229% D e s t r o y I m a g e I n f o %
1230% %
1231% %
1232% %
1233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1234%
1235% DestroyImageInfo() deallocates memory associated with an ImageInfo
1236% structure.
1237%
1238% The format of the DestroyImageInfo method is:
1239%
1240% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1241%
1242% A description of each parameter follows:
1243%
1244% o image_info: the image info.
1245%
1246*/
1247MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1248{
1249 assert(image_info != (ImageInfo *) NULL);
1250 assert(image_info->signature == MagickSignature);
1251 if (image_info->debug != MagickFalse)
1252 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1253 image_info->filename);
1254 if (image_info->size != (char *) NULL)
1255 image_info->size=DestroyString(image_info->size);
1256 if (image_info->extract != (char *) NULL)
1257 image_info->extract=DestroyString(image_info->extract);
1258 if (image_info->scenes != (char *) NULL)
1259 image_info->scenes=DestroyString(image_info->scenes);
1260 if (image_info->page != (char *) NULL)
1261 image_info->page=DestroyString(image_info->page);
1262 if (image_info->sampling_factor != (char *) NULL)
1263 image_info->sampling_factor=DestroyString(
1264 image_info->sampling_factor);
1265 if (image_info->server_name != (char *) NULL)
1266 image_info->server_name=DestroyString(
1267 image_info->server_name);
1268 if (image_info->font != (char *) NULL)
1269 image_info->font=DestroyString(image_info->font);
1270 if (image_info->texture != (char *) NULL)
1271 image_info->texture=DestroyString(image_info->texture);
1272 if (image_info->density != (char *) NULL)
1273 image_info->density=DestroyString(image_info->density);
1274 if (image_info->view != (char *) NULL)
1275 image_info->view=DestroyString(image_info->view);
1276 if (image_info->authenticate != (char *) NULL)
1277 image_info->authenticate=DestroyString(
1278 image_info->authenticate);
1279 DestroyImageOptions(image_info);
1280 if (image_info->cache != (void *) NULL)
1281 image_info->cache=DestroyPixelCache(image_info->cache);
1282 if (image_info->profile != (StringInfo *) NULL)
1283 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1284 image_info->profile);
1285 image_info->signature=(~MagickSignature);
1286 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1287 return(image_info);
1288}
1289
1290/*
1291%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1292% %
1293% %
1294% %
1295+ D i s a s s o c i a t e I m a g e S t r e a m %
1296% %
1297% %
1298% %
1299%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1300%
1301% DisassociateImageStream() disassociates the image stream.
1302%
1303% The format of the DisassociateImageStream method is:
1304%
1305% MagickBooleanType DisassociateImageStream(const Image *image)
1306%
1307% A description of each parameter follows:
1308%
1309% o image: the image.
1310%
1311*/
1312MagickExport void DisassociateImageStream(Image *image)
1313{
1314 assert(image != (const Image *) NULL);
1315 assert(image->signature == MagickSignature);
1316 if (image->debug != MagickFalse)
1317 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1318 (void) DetachBlob(image->blob);
1319}
1320
1321/*
1322%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1323% %
1324% %
1325% %
1326% G e t I m a g e A l p h a C h a n n e l %
1327% %
1328% %
1329% %
1330%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1331%
1332% GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1333% not activated. That is, the image is RGB rather than RGBA or CMYK rather
1334% than CMYKA.
1335%
1336% The format of the GetImageAlphaChannel method is:
1337%
1338% MagickBooleanType GetImageAlphaChannel(const Image *image)
1339%
1340% A description of each parameter follows:
1341%
1342% o image: the image.
1343%
1344*/
1345MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1346{
1347 assert(image != (const Image *) NULL);
1348 if (image->debug != MagickFalse)
1349 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1350 assert(image->signature == MagickSignature);
1351 return(image->matte);
1352}
1353
1354/*
1355%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1356% %
1357% %
1358% %
1359% G e t I m a g e C l i p M a s k %
1360% %
1361% %
1362% %
1363%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1364%
1365% GetImageClipMask() returns the clip path associated with the image.
1366%
1367% The format of the GetImageClipMask method is:
1368%
1369% Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1370%
1371% A description of each parameter follows:
1372%
1373% o image: the image.
1374%
1375*/
1376MagickExport Image *GetImageClipMask(const Image *image,
1377 ExceptionInfo *exception)
1378{
1379 assert(image != (const Image *) NULL);
1380 if (image->debug != MagickFalse)
1381 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1382 assert(image->signature == MagickSignature);
1383 if (image->clip_mask == (Image *) NULL)
1384 return((Image *) NULL);
1385 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1386}
1387
1388/*
1389%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390% %
1391% %
1392% %
1393% G e t I m a g e E x c e p t i o n %
1394% %
1395% %
1396% %
1397%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1398%
1399% GetImageException() traverses an image sequence and returns any
1400% error more severe than noted by the exception parameter.
1401%
1402% The format of the GetImageException method is:
1403%
1404% void GetImageException(Image *image,ExceptionInfo *exception)
1405%
1406% A description of each parameter follows:
1407%
1408% o image: Specifies a pointer to a list of one or more images.
1409%
1410% o exception: return the highest severity exception.
1411%
1412*/
1413MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1414{
1415 register Image
1416 *next;
1417
1418 assert(image != (Image *) NULL);
1419 assert(image->signature == MagickSignature);
1420 if (image->debug != MagickFalse)
1421 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1422 assert(exception != (ExceptionInfo *) NULL);
1423 assert(exception->signature == MagickSignature);
1424 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1425 {
1426 if (next->exception.severity == UndefinedException)
1427 continue;
1428 if (next->exception.severity > exception->severity)
1429 InheritException(exception,&next->exception);
1430 next->exception.severity=UndefinedException;
1431 }
1432}
1433
1434/*
1435%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1436% %
1437% %
1438% %
1439% G e t I m a g e I n f o %
1440% %
1441% %
1442% %
1443%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1444%
1445% GetImageInfo() initializes image_info to default values.
1446%
1447% The format of the GetImageInfo method is:
1448%
1449% void GetImageInfo(ImageInfo *image_info)
1450%
1451% A description of each parameter follows:
1452%
1453% o image_info: the image info.
1454%
1455*/
1456MagickExport void GetImageInfo(ImageInfo *image_info)
1457{
1458 ExceptionInfo
1459 *exception;
1460
1461 /*
1462 File and image dimension members.
1463 */
1464 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1465 assert(image_info != (ImageInfo *) NULL);
1466 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1467 image_info->adjoin=MagickTrue;
1468 image_info->interlace=NoInterlace;
1469 image_info->channel=DefaultChannels;
1470 image_info->quality=UndefinedCompressionQuality;
1471 image_info->antialias=MagickTrue;
1472 image_info->dither=MagickTrue;
1473 exception=AcquireExceptionInfo();
1474 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1475 exception);
1476 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1477 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1478 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1479 exception);
1480 exception=DestroyExceptionInfo(exception);
1481 image_info->debug=IsEventLogging();
1482 image_info->signature=MagickSignature;
1483}
1484
1485/*
1486%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1487% %
1488% %
1489% %
cristy15781e52009-12-05 23:05:27 +00001490% G e t I m a g e I n f o F i l e %
1491% %
1492% %
1493% %
1494%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495%
1496% GetImageInfoFile() returns the image info file member.
1497%
1498% The format of the GetImageInfoFile method is:
1499%
1500% FILE *GetImageInfoFile(const ImageInfo *image_info)
1501%
1502% A description of each parameter follows:
1503%
1504% o image_info: the image info.
1505%
1506*/
1507MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1508{
1509 return(image_info->file);
1510}
1511
1512/*
1513%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1514% %
1515% %
1516% %
cristy3ed852e2009-09-05 21:47:34 +00001517% G e t I m a g e M a s k %
1518% %
1519% %
1520% %
1521%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1522%
1523% GetImageMask() returns the mask associated with the image.
1524%
1525% The format of the GetImageMask method is:
1526%
1527% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1528%
1529% A description of each parameter follows:
1530%
1531% o image: the image.
1532%
1533*/
1534MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1535{
1536 assert(image != (const Image *) NULL);
1537 if (image->debug != MagickFalse)
1538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1539 assert(image->signature == MagickSignature);
1540 if (image->mask == (Image *) NULL)
1541 return((Image *) NULL);
1542 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1543}
1544
1545/*
1546%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1547% %
1548% %
1549% %
1550+ G e t I m a g e R e f e r e n c e C o u n t %
1551% %
1552% %
1553% %
1554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1555%
1556% GetImageReferenceCount() returns the image reference count.
1557%
1558% The format of the GetReferenceCount method is:
1559%
1560% long GetImageReferenceCount(Image *image)
1561%
1562% A description of each parameter follows:
1563%
1564% o image: the image.
1565%
1566*/
1567MagickExport long GetImageReferenceCount(Image *image)
1568{
1569 long
1570 reference_count;
1571
1572 assert(image != (Image *) NULL);
1573 assert(image->signature == MagickSignature);
1574 if (image->debug != MagickFalse)
1575 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001576 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001577 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001578 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001579 return(reference_count);
1580}
1581
1582/*
1583%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584% %
1585% %
1586% %
cristy3ed852e2009-09-05 21:47:34 +00001587% 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 %
1588% %
1589% %
1590% %
1591%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592%
1593% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1594% image. A virtual pixel is any pixel access that is outside the boundaries
1595% of the image cache.
1596%
1597% The format of the GetImageVirtualPixelMethod() method is:
1598%
1599% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1600%
1601% A description of each parameter follows:
1602%
1603% o image: the image.
1604%
1605*/
1606MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1607{
1608 assert(image != (Image *) NULL);
1609 assert(image->signature == MagickSignature);
1610 if (image->debug != MagickFalse)
1611 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1612 return(GetPixelCacheVirtualMethod(image));
1613}
1614
1615/*
1616%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1617% %
1618% %
1619% %
1620% I n t e r p r e t I m a g e F i l e n a m e %
1621% %
1622% %
1623% %
1624%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1625%
1626% InterpretImageFilename() interprets embedded characters in an image filename.
1627% The filename length is returned.
1628%
1629% The format of the InterpretImageFilename method is:
1630%
1631% size_t InterpretImageFilename(const ImageInfo *image_info,
1632% Image *image,const char *format,int value,char *filename)
1633%
1634% A description of each parameter follows.
1635%
1636% o image_info: the image info..
1637%
1638% o image: the image.
1639%
1640% o format: A filename describing the format to use to write the numeric
1641% argument. Only the first numeric format identifier is replaced.
1642%
1643% o value: Numeric value to substitute into format filename.
1644%
1645% o filename: return the formatted filename in this character buffer.
1646%
1647*/
1648MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1649 Image *image,const char *format,int value,char *filename)
1650{
1651 char
1652 *q;
1653
1654 int
1655 c;
1656
1657 MagickBooleanType
1658 canonical;
1659
1660 register const char
1661 *p;
1662
1663 canonical=MagickFalse;
1664 (void) CopyMagickString(filename,format,MaxTextExtent);
1665 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1666 {
1667 q=(char *) p+1;
1668 if (*q == '%')
1669 {
1670 p=q+1;
1671 continue;
1672 }
1673 if (*q == '0')
1674 {
1675 long
1676 value;
1677
1678 value=strtol(q,&q,10);
1679 }
1680 switch (*q)
1681 {
1682 case 'd':
1683 case 'o':
1684 case 'x':
1685 {
1686 q++;
1687 c=(*q);
1688 *q='\0';
1689 (void) FormatMagickString(filename+(p-format),(size_t) (MaxTextExtent-
1690 (p-format)),p,value);
1691 *q=c;
1692 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1693 canonical=MagickTrue;
1694 if (*(q-1) != '%')
1695 break;
1696 p++;
1697 break;
1698 }
1699 case '[':
1700 {
1701 char
1702 pattern[MaxTextExtent];
1703
1704 const char
1705 *value;
1706
1707 long
1708 depth;
1709
1710 register char
1711 *r;
1712
1713 register long
1714 i;
1715
1716 /*
1717 Image option.
1718 */
1719 if (strchr(p,']') == (char *) NULL)
1720 break;
1721 depth=1;
1722 r=q+1;
1723 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1724 {
1725 if (*r == '[')
1726 depth++;
1727 if (*r == ']')
1728 depth--;
1729 if (depth <= 0)
1730 break;
1731 pattern[i]=(*r++);
1732 }
1733 pattern[i]='\0';
1734 if (LocaleNCompare(pattern,"filename:",9) != 0)
1735 break;
1736 value=(const char *) NULL;
1737 if ((image_info != (const ImageInfo *) NULL) &&
1738 (image != (const Image *) NULL))
1739 value=GetMagickProperty(image_info,image,pattern);
1740 else
1741 if (image != (Image *) NULL)
1742 value=GetImageProperty(image,pattern);
1743 else
1744 if (image_info != (ImageInfo *) NULL)
1745 value=GetImageOption(image_info,pattern);
1746 if (value == (const char *) NULL)
1747 break;
1748 q--;
1749 c=(*q);
1750 *q='\0';
1751 (void) CopyMagickString(filename+(p-format),value,(size_t)
1752 (MaxTextExtent-(p-format)));
1753 *q=c;
1754 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1755 canonical=MagickTrue;
1756 if (*(q-1) != '%')
1757 break;
1758 p++;
1759 break;
1760 }
1761 default:
1762 break;
1763 }
1764 }
1765 for (q=filename; *q != '\0'; q++)
1766 if ((*q == '%') && (*(q+1) == '%'))
1767 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1768 if (canonical == MagickFalse)
1769 (void) CopyMagickString(filename,format,MaxTextExtent);
1770 return(strlen(filename));
1771}
1772
1773/*
1774%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1775% %
1776% %
1777% %
1778% I s H i g h D y n a m i c R a n g e I m a g e %
1779% %
1780% %
1781% %
1782%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1783%
1784% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1785% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1786% 0..65535.
1787%
1788% The format of the IsHighDynamicRangeImage method is:
1789%
1790% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1791% ExceptionInfo *exception)
1792%
1793% A description of each parameter follows:
1794%
1795% o image: the image.
1796%
1797% o exception: return any errors or warnings in this structure.
1798%
1799*/
1800MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1801 ExceptionInfo *exception)
1802{
1803#if !defined(MAGICKCORE_HDRI_SUPPORT)
1804 (void) image;
1805 (void) exception;
1806 return(MagickFalse);
1807#else
1808 CacheView
1809 *image_view;
1810
1811 long
1812 y;
1813
1814 MagickBooleanType
1815 status;
1816
1817 MagickPixelPacket
1818 zero;
1819
1820 assert(image != (Image *) NULL);
1821 assert(image->signature == MagickSignature);
1822 if (image->debug != MagickFalse)
1823 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1824 status=MagickTrue;
1825 GetMagickPixelPacket(image,&zero);
1826 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00001827#if defined(MAGICKCORE_OPENMP_SUPPORT)
1828 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00001829#endif
1830 for (y=0; y < (long) image->rows; y++)
1831 {
1832 MagickPixelPacket
1833 pixel;
1834
1835 register const IndexPacket
1836 *indexes;
1837
1838 register const PixelPacket
1839 *p;
1840
1841 register long
1842 x;
1843
1844 if (status == MagickFalse)
1845 continue;
1846 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1847 if (p == (const PixelPacket *) NULL)
1848 {
1849 status=MagickFalse;
1850 continue;
1851 }
1852 indexes=GetCacheViewVirtualIndexQueue(image_view);
1853 pixel=zero;
1854 for (x=0; x < (long) image->columns; x++)
1855 {
1856 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1857 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1858 (pixel.red != (QuantumAny) pixel.red))
1859 break;
1860 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1861 (pixel.green != (QuantumAny) pixel.green))
1862 break;
1863 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1864 (pixel.blue != (QuantumAny) pixel.blue))
1865 break;
1866 if (pixel.matte != MagickFalse)
1867 {
1868 if ((pixel.opacity < 0.0) || (pixel.opacity > QuantumRange) ||
1869 (pixel.opacity != (QuantumAny) pixel.opacity))
1870 break;
1871 }
1872 if (pixel.colorspace == CMYKColorspace)
1873 {
1874 if ((pixel.index < 0.0) || (pixel.index > QuantumRange) ||
1875 (pixel.index != (QuantumAny) pixel.index))
1876 break;
1877 }
1878 p++;
1879 }
1880 if (x < (long) image->columns)
1881 status=MagickFalse;
1882 }
1883 image_view=DestroyCacheView(image_view);
1884 return(status != MagickFalse ? MagickFalse : MagickTrue);
1885#endif
1886}
1887
1888/*
1889%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1890% %
1891% %
1892% %
1893% I s I m a g e O b j e c t %
1894% %
1895% %
1896% %
1897%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1898%
1899% IsImageObject() returns MagickTrue if the image sequence contains a valid
1900% set of image objects.
1901%
1902% The format of the IsImageObject method is:
1903%
1904% MagickBooleanType IsImageObject(const Image *image)
1905%
1906% A description of each parameter follows:
1907%
1908% o image: the image.
1909%
1910*/
1911MagickExport MagickBooleanType IsImageObject(const Image *image)
1912{
1913 register const Image
1914 *p;
1915
1916 assert(image != (Image *) NULL);
1917 if (image->debug != MagickFalse)
1918 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1919 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1920 if (p->signature != MagickSignature)
1921 return(MagickFalse);
1922 return(MagickTrue);
1923}
1924
1925/*
1926%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1927% %
1928% %
1929% %
1930% I s T a i n t I m a g e %
1931% %
1932% %
1933% %
1934%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1935%
1936% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1937% since it was first constituted.
1938%
1939% The format of the IsTaintImage method is:
1940%
1941% MagickBooleanType IsTaintImage(const Image *image)
1942%
1943% A description of each parameter follows:
1944%
1945% o image: the image.
1946%
1947*/
1948MagickExport MagickBooleanType IsTaintImage(const Image *image)
1949{
1950 char
1951 magick[MaxTextExtent],
1952 filename[MaxTextExtent];
1953
1954 register const Image
1955 *p;
1956
1957 assert(image != (Image *) NULL);
1958 if (image->debug != MagickFalse)
1959 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1960 assert(image->signature == MagickSignature);
1961 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1962 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1963 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1964 {
1965 if (p->taint != MagickFalse)
1966 return(MagickTrue);
1967 if (LocaleCompare(p->magick,magick) != 0)
1968 return(MagickTrue);
1969 if (LocaleCompare(p->filename,filename) != 0)
1970 return(MagickTrue);
1971 }
1972 return(MagickFalse);
1973}
1974
1975/*
1976%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1977% %
1978% %
1979% %
1980% M o d i f y I m a g e %
1981% %
1982% %
1983% %
1984%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1985%
1986% ModifyImage() ensures that there is only a single reference to the image
1987% to be modified, updating the provided image pointer to point to a clone of
1988% the original image if necessary.
1989%
1990% The format of the ModifyImage method is:
1991%
1992% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1993%
1994% A description of each parameter follows:
1995%
1996% o image: the image.
1997%
1998% o exception: return any errors or warnings in this structure.
1999%
2000*/
2001MagickExport MagickBooleanType ModifyImage(Image **image,
2002 ExceptionInfo *exception)
2003{
2004 Image
2005 *clone_image;
2006
2007 assert(image != (Image **) NULL);
2008 assert(*image != (Image *) NULL);
2009 assert((*image)->signature == MagickSignature);
2010 if ((*image)->debug != MagickFalse)
2011 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2012 if (GetImageReferenceCount(*image) <= 1)
2013 return(MagickTrue);
2014 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
cristyf84a1932010-01-03 18:00:18 +00002015 LockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002016 (*image)->reference_count--;
cristyf84a1932010-01-03 18:00:18 +00002017 UnlockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002018 *image=clone_image;
2019 return(MagickTrue);
2020}
2021
2022/*
2023%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2024% %
2025% %
2026% %
2027% N e w M a g i c k I m a g e %
2028% %
2029% %
2030% %
2031%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2032%
2033% NewMagickImage() creates a blank image canvas of the specified size and
2034% background color.
2035%
2036% The format of the NewMagickImage method is:
2037%
2038% Image *NewMagickImage(const ImageInfo *image_info,
2039% const unsigned long width,const unsigned long height,
2040% const MagickPixelPacket *background)
2041%
2042% A description of each parameter follows:
2043%
2044% o image: the image.
2045%
2046% o width: the image width.
2047%
2048% o height: the image height.
2049%
2050% o background: the image color.
2051%
2052*/
2053MagickExport Image *NewMagickImage(const ImageInfo *image_info,
2054 const unsigned long width,const unsigned long height,
2055 const MagickPixelPacket *background)
2056{
2057 CacheView
2058 *image_view;
2059
2060 ExceptionInfo
2061 *exception;
2062
2063 Image
2064 *image;
2065
2066 long
2067 y;
2068
2069 MagickBooleanType
2070 status;
2071
2072 assert(image_info != (const ImageInfo *) NULL);
2073 if (image_info->debug != MagickFalse)
2074 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2075 assert(image_info->signature == MagickSignature);
2076 assert(background != (const MagickPixelPacket *) NULL);
2077 image=AcquireImage(image_info);
2078 image->columns=width;
2079 image->rows=height;
2080 image->colorspace=background->colorspace;
2081 image->matte=background->matte;
2082 image->fuzz=background->fuzz;
2083 image->depth=background->depth;
2084 status=MagickTrue;
2085 exception=(&image->exception);
2086 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00002087#if defined(MAGICKCORE_OPENMP_SUPPORT)
2088 #pragma omp parallel for schedule(dynamic,4) shared(status)
2089#endif
cristy3ed852e2009-09-05 21:47:34 +00002090 for (y=0; y < (long) image->rows; y++)
2091 {
2092 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002093 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002094
2095 register long
2096 x;
2097
2098 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002099 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002100
cristy48974b92009-12-19 02:36:06 +00002101 if (status == MagickFalse)
2102 continue;
cristy3ed852e2009-09-05 21:47:34 +00002103 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2104 if (q == (PixelPacket *) NULL)
2105 {
2106 status=MagickFalse;
2107 continue;
2108 }
2109 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2110 for (x=0; x < (long) image->columns; x++)
2111 {
2112 SetPixelPacket(image,background,q,indexes+x);
2113 q++;
2114 }
2115 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2116 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002117 }
2118 image_view=DestroyCacheView(image_view);
2119 if (status == MagickFalse)
2120 image=DestroyImage(image);
2121 return(image);
2122}
2123
2124/*
2125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2126% %
2127% %
2128% %
2129% R e f e r e n c e I m a g e %
2130% %
2131% %
2132% %
2133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2134%
2135% ReferenceImage() increments the reference count associated with an image
2136% returning a pointer to the image.
2137%
2138% The format of the ReferenceImage method is:
2139%
2140% Image *ReferenceImage(Image *image)
2141%
2142% A description of each parameter follows:
2143%
2144% o image: the image.
2145%
2146*/
2147MagickExport Image *ReferenceImage(Image *image)
2148{
2149 assert(image != (Image *) NULL);
2150 if (image->debug != MagickFalse)
2151 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2152 assert(image->signature == MagickSignature);
cristyf84a1932010-01-03 18:00:18 +00002153 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002154 image->reference_count++;
cristyf84a1932010-01-03 18:00:18 +00002155 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002156 return(image);
2157}
2158
2159/*
2160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2161% %
2162% %
2163% %
2164% R e s e t I m a g e P a g e %
2165% %
2166% %
2167% %
2168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2169%
2170% ResetImagePage() resets the image page canvas and position.
2171%
2172% The format of the ResetImagePage method is:
2173%
2174% MagickBooleanType ResetImagePage(Image *image,const char *page)
2175%
2176% A description of each parameter follows:
2177%
2178% o image: the image.
2179%
2180% o page: the relative page specification.
2181%
2182*/
2183MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2184{
2185 MagickStatusType
2186 flags;
2187
2188 RectangleInfo
2189 geometry;
2190
2191 assert(image != (Image *) NULL);
2192 assert(image->signature == MagickSignature);
2193 if (image->debug != MagickFalse)
2194 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2195 flags=ParseAbsoluteGeometry(page,&geometry);
2196 if ((flags & WidthValue) != 0)
2197 {
2198 if ((flags & HeightValue) == 0)
2199 geometry.height=geometry.width;
2200 image->page.width=geometry.width;
2201 image->page.height=geometry.height;
2202 }
2203 if ((flags & AspectValue) != 0)
2204 {
2205 if ((flags & XValue) != 0)
2206 image->page.x+=geometry.x;
2207 if ((flags & YValue) != 0)
2208 image->page.y+=geometry.y;
2209 }
2210 else
2211 {
2212 if ((flags & XValue) != 0)
2213 {
2214 image->page.x=geometry.x;
2215 if ((image->page.width == 0) && (geometry.x > 0))
2216 image->page.width=image->columns+geometry.x;
2217 }
2218 if ((flags & YValue) != 0)
2219 {
2220 image->page.y=geometry.y;
2221 if ((image->page.height == 0) && (geometry.y > 0))
2222 image->page.height=image->rows+geometry.y;
2223 }
2224 }
2225 return(MagickTrue);
2226}
2227
2228/*
2229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2230% %
2231% %
2232% %
2233% S e p a r a t e I m a g e C h a n n e l %
2234% %
2235% %
2236% %
2237%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2238%
2239% SeparateImageChannel() separates a channel from the image and returns it as
2240% a grayscale image. A channel is a particular color component of each pixel
2241% in the image.
2242%
2243% The format of the SeparateImageChannel method is:
2244%
2245% MagickBooleanType SeparateImageChannel(Image *image,
2246% const ChannelType channel)
2247%
2248% A description of each parameter follows:
2249%
2250% o image: the image.
2251%
2252% o channel: Identify which channel to extract: RedChannel, GreenChannel,
2253% BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2254% YellowChannel, or BlackChannel.
2255%
2256*/
2257MagickExport MagickBooleanType SeparateImageChannel(Image *image,
2258 const ChannelType channel)
2259{
2260#define SeparateImageTag "Separate/Image"
2261
2262 CacheView
2263 *image_view;
2264
2265 ExceptionInfo
2266 *exception;
2267
2268 long
2269 progress,
2270 y;
2271
2272 MagickBooleanType
2273 status;
2274
2275 assert(image != (Image *) NULL);
2276 assert(image->signature == MagickSignature);
2277 if (image->debug != MagickFalse)
2278 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2279 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2280 return(MagickFalse);
2281 /*
2282 Separate image channels.
2283 */
2284 status=MagickTrue;
cristy11b66ce2010-03-11 13:34:19 +00002285 if (channel == GrayChannels)
cristy3ed852e2009-09-05 21:47:34 +00002286 image->matte=MagickTrue;
2287 progress=0;
2288 exception=(&image->exception);
2289 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002290#if defined(MAGICKCORE_OPENMP_SUPPORT)
2291 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00002292#endif
2293 for (y=0; y < (long) image->rows; y++)
2294 {
2295 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002296 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002297
2298 register long
2299 x;
2300
2301 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002302 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002303
2304 if (status == MagickFalse)
2305 continue;
2306 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2307 if (q == (PixelPacket *) NULL)
2308 {
2309 status=MagickFalse;
2310 continue;
2311 }
2312 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2313 switch (channel)
2314 {
2315 case RedChannel:
2316 {
2317 for (x=0; x < (long) image->columns; x++)
2318 {
2319 q->green=q->red;
2320 q->blue=q->red;
2321 q++;
2322 }
2323 break;
2324 }
2325 case GreenChannel:
2326 {
2327 for (x=0; x < (long) image->columns; x++)
2328 {
2329 q->red=q->green;
2330 q->blue=q->green;
2331 q++;
2332 }
2333 break;
2334 }
2335 case BlueChannel:
2336 {
2337 for (x=0; x < (long) image->columns; x++)
2338 {
2339 q->red=q->blue;
2340 q->green=q->blue;
2341 q++;
2342 }
2343 break;
2344 }
2345 case OpacityChannel:
2346 {
2347 for (x=0; x < (long) image->columns; x++)
2348 {
2349 q->red=q->opacity;
2350 q->green=q->opacity;
2351 q->blue=q->opacity;
2352 q++;
2353 }
2354 break;
2355 }
2356 case BlackChannel:
2357 {
2358 if ((image->storage_class != PseudoClass) &&
2359 (image->colorspace != CMYKColorspace))
2360 break;
2361 for (x=0; x < (long) image->columns; x++)
2362 {
2363 q->red=indexes[x];
2364 q->green=indexes[x];
2365 q->blue=indexes[x];
2366 q++;
2367 }
2368 break;
2369 }
2370 case TrueAlphaChannel:
2371 {
2372 for (x=0; x < (long) image->columns; x++)
2373 {
cristy46f08202010-01-10 04:04:21 +00002374 q->red=(Quantum) GetAlphaPixelComponent(q);
2375 q->green=(Quantum) GetAlphaPixelComponent(q);
2376 q->blue=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +00002377 q++;
2378 }
2379 break;
2380 }
2381 case GrayChannels:
2382 {
2383 for (x=0; x < (long) image->columns; x++)
2384 {
2385 q->opacity=(Quantum) (QuantumRange-PixelIntensityToQuantum(q));
2386 q++;
2387 }
2388 break;
2389 }
2390 default:
2391 break;
2392 }
2393 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2394 status=MagickFalse;
2395 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2396 {
2397 MagickBooleanType
2398 proceed;
2399
cristyb5d5f722009-11-04 03:03:49 +00002400#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00002401 #pragma omp critical (MagickCore_SeparateImageChannel)
2402#endif
2403 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2404 if (proceed == MagickFalse)
2405 status=MagickFalse;
2406 }
2407 }
2408 image_view=DestroyCacheView(image_view);
cristy11b66ce2010-03-11 13:34:19 +00002409 if (channel != GrayChannels)
cristy3ed852e2009-09-05 21:47:34 +00002410 image->matte=MagickFalse;
2411 (void) SetImageColorspace(image,RGBColorspace);
2412 return(status);
2413}
2414
2415/*
2416%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2417% %
2418% %
2419% %
2420% S e p a r a t e I m a g e s %
2421% %
2422% %
2423% %
2424%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2425%
2426% SeparateImages() returns a separate grayscale image for each channel
2427% specified.
2428%
2429% The format of the SeparateImages method is:
2430%
2431% MagickBooleanType SeparateImages(const Image *image,
2432% const ChannelType channel,ExceptionInfo *exception)
2433%
2434% A description of each parameter follows:
2435%
2436% o image: the image.
2437%
2438% o channel: Identify which channels to extract: RedChannel, GreenChannel,
2439% BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2440% YellowChannel, or BlackChannel.
2441%
2442% o exception: return any errors or warnings in this structure.
2443%
2444*/
2445MagickExport Image *SeparateImages(const Image *image,const ChannelType channel,
2446 ExceptionInfo *exception)
2447{
2448 Image
2449 *images,
2450 *separate_image;
2451
2452 assert(image != (Image *) NULL);
2453 assert(image->signature == MagickSignature);
2454 if (image->debug != MagickFalse)
2455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2456 images=NewImageList();
2457 if ((channel & RedChannel) != 0)
2458 {
2459 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2460 (void) SeparateImageChannel(separate_image,RedChannel);
2461 AppendImageToList(&images,separate_image);
2462 }
2463 if ((channel & GreenChannel) != 0)
2464 {
2465 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2466 (void) SeparateImageChannel(separate_image,GreenChannel);
2467 AppendImageToList(&images,separate_image);
2468 }
2469 if ((channel & BlueChannel) != 0)
2470 {
2471 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2472 (void) SeparateImageChannel(separate_image,BlueChannel);
2473 AppendImageToList(&images,separate_image);
2474 }
2475 if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace))
2476 {
2477 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2478 (void) SeparateImageChannel(separate_image,BlackChannel);
2479 AppendImageToList(&images,separate_image);
2480 }
2481 if ((channel & OpacityChannel) != 0)
2482 {
2483 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2484 (void) SeparateImageChannel(separate_image,OpacityChannel);
2485 AppendImageToList(&images,separate_image);
2486 }
2487 return(images);
2488}
2489
2490/*
2491%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2492% %
2493% %
2494% %
2495% S e t I m a g e A l p h a C h a n n e l %
2496% %
2497% %
2498% %
2499%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2500%
2501% SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2502% channel.
2503%
2504% The format of the SetImageAlphaChannel method is:
2505%
2506% MagickBooleanType SetImageAlphaChannel(Image *image,
2507% const AlphaChannelType alpha_type)
2508%
2509% A description of each parameter follows:
2510%
2511% o image: the image.
2512%
2513% o alpha_type: The alpha channel type: ActivateAlphaChannel,
2514% CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2515% OpaqueAlphaChannel, ResetAlphaChannel, SetAlphaChannel,
2516% ShapeAlphaChannel, and TransparentAlphaChannel.
2517%
2518*/
2519MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2520 const AlphaChannelType alpha_type)
2521{
2522 MagickBooleanType
2523 status;
2524
2525 assert(image != (Image *) NULL);
2526 if (image->debug != MagickFalse)
2527 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2528 assert(image->signature == MagickSignature);
2529 status=MagickFalse;
2530 switch (alpha_type)
2531 {
2532 case ActivateAlphaChannel:
2533 {
2534 image->matte=MagickTrue;
2535 break;
2536 }
2537 case BackgroundAlphaChannel:
2538 {
2539 CacheView
2540 *image_view;
2541
2542 ExceptionInfo
2543 *exception;
2544
2545 IndexPacket
2546 index;
2547
2548 long
2549 y;
2550
2551 MagickBooleanType
2552 status;
2553
2554 MagickPixelPacket
2555 background;
2556
2557 PixelPacket
2558 pixel;
2559
2560 /*
2561 Set transparent pixels to background color.
2562 */
2563 if (image->matte == MagickFalse)
2564 break;
2565 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2566 break;
2567 GetMagickPixelPacket(image,&background);
2568 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2569 NULL,&background);
2570 if (image->colorspace == CMYKColorspace)
2571 ConvertRGBToCMYK(&background);
2572 index=0;
2573 SetPixelPacket(image,&background,&pixel,&index);
2574 status=MagickTrue;
2575 exception=(&image->exception);
2576 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002577 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2578 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00002579 #endif
2580 for (y=0; y < (long) image->rows; y++)
2581 {
2582 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002583 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002584
2585 register long
2586 x;
2587
2588 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002589 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002590
2591 if (status == MagickFalse)
2592 continue;
2593 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2594 exception);
2595 if (q == (PixelPacket *) NULL)
2596 {
2597 status=MagickFalse;
2598 continue;
2599 }
2600 for (x=0; x < (long) image->columns; x++)
2601 {
2602 if (q->opacity == TransparentOpacity)
2603 {
2604 q->red=pixel.red;
2605 q->green=pixel.green;
2606 q->blue=pixel.blue;
2607 }
2608 q++;
2609 }
2610 if (image->colorspace == CMYKColorspace)
2611 {
2612 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2613 for (x=0; x < (long) image->columns; x++)
2614 indexes[x]=index;
2615 }
2616 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2617 status=MagickFalse;
2618 }
2619 image_view=DestroyCacheView(image_view);
2620 return(status);
2621 }
2622 case DeactivateAlphaChannel:
2623 {
2624 image->matte=MagickFalse;
2625 break;
2626 }
2627 case ShapeAlphaChannel:
2628 case CopyAlphaChannel:
2629 {
2630 /*
2631 Special usage case for SeparateImageChannel(): copy grayscale color to
2632 the alpha channel.
2633 */
2634 status=SeparateImageChannel(image,GrayChannels);
2635 image->matte=MagickTrue; /* make sure transparency is now on! */
2636 if (alpha_type == ShapeAlphaChannel)
2637 {
2638 MagickPixelPacket
2639 background;
2640
2641 /*
2642 Reset all color channels to background color.
2643 */
2644 GetMagickPixelPacket(image,&background);
2645 SetMagickPixelPacket(image,&(image->background_color),(IndexPacket *)
2646 NULL,&background);
cristy308b4e62009-09-21 14:40:44 +00002647 (void) LevelColorsImage(image,&background,&background,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00002648 }
2649 break;
2650 }
2651 case ExtractAlphaChannel:
2652 {
2653 status=SeparateImageChannel(image,TrueAlphaChannel);
2654 image->matte=MagickFalse;
2655 break;
2656 }
2657 case ResetAlphaChannel:
2658 case OpaqueAlphaChannel:
2659 {
2660 status=SetImageOpacity(image,OpaqueOpacity);
2661 image->matte=MagickTrue;
2662 break;
2663 }
2664 case TransparentAlphaChannel:
2665 {
2666 status=SetImageOpacity(image,TransparentOpacity);
2667 image->matte=MagickTrue;
2668 break;
2669 }
2670 case SetAlphaChannel:
2671 {
2672 if (image->matte == MagickFalse)
2673 {
2674 status=SetImageOpacity(image,OpaqueOpacity);
2675 image->matte=MagickTrue;
2676 }
2677 break;
2678 }
2679 case UndefinedAlphaChannel:
2680 break;
2681 }
2682 return(status);
2683}
2684
2685/*
2686%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2687% %
2688% %
2689% %
2690% S e t I m a g e B a c k g r o u n d C o l o r %
2691% %
2692% %
2693% %
2694%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2695%
2696% SetImageBackgroundColor() initializes the image pixels to the image
2697% background color. The background color is defined by the background_color
2698% member of the image structure.
2699%
2700% The format of the SetImage method is:
2701%
2702% MagickBooleanType SetImageBackgroundColor(Image *image)
2703%
2704% A description of each parameter follows:
2705%
2706% o image: the image.
2707%
2708*/
2709MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2710{
2711 CacheView
2712 *image_view;
2713
2714 ExceptionInfo
2715 *exception;
2716
2717 IndexPacket
2718 index;
2719
2720 long
2721 y;
2722
2723 MagickBooleanType
2724 status;
2725
2726 MagickPixelPacket
2727 background;
2728
2729 PixelPacket
2730 pixel;
2731
2732 assert(image != (Image *) NULL);
2733 if (image->debug != MagickFalse)
2734 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2735 assert(image->signature == MagickSignature);
2736 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2737 return(MagickFalse);
2738 if (image->background_color.opacity != OpaqueOpacity)
2739 image->matte=MagickTrue;
2740 GetMagickPixelPacket(image,&background);
2741 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2742 NULL,&background);
2743 if (image->colorspace == CMYKColorspace)
2744 ConvertRGBToCMYK(&background);
2745 index=0;
2746 SetPixelPacket(image,&background,&pixel,&index);
2747 /*
2748 Set image background color.
2749 */
2750 status=MagickTrue;
2751 exception=(&image->exception);
2752 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002753#if defined(MAGICKCORE_OPENMP_SUPPORT)
2754 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00002755#endif
2756 for (y=0; y < (long) image->rows; y++)
2757 {
2758 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002759 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002760
2761 register long
2762 x;
2763
2764 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002765 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002766
2767 if (status == MagickFalse)
2768 continue;
2769 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2770 if (q == (PixelPacket *) NULL)
2771 {
2772 status=MagickFalse;
2773 continue;
2774 }
2775 for (x=0; x < (long) image->columns; x++)
2776 *q++=pixel;
2777 if (image->colorspace == CMYKColorspace)
2778 {
2779 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2780 for (x=0; x < (long) image->columns; x++)
2781 indexes[x]=index;
2782 }
2783 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2784 status=MagickFalse;
2785 }
2786 image_view=DestroyCacheView(image_view);
2787 return(status);
2788}
2789
2790/*
2791%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2792% %
2793% %
2794% %
2795% S e t I m a g e S t o r a g e C l a s s %
2796% %
2797% %
2798% %
2799%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2800%
2801% SetImageStorageClass() sets the image class: DirectClass for true color
2802% images or PseudoClass for colormapped images.
2803%
2804% The format of the SetImageStorageClass method is:
2805%
2806% MagickBooleanType SetImageStorageClass(Image *image,
2807% const ClassType storage_class)
2808%
2809% A description of each parameter follows:
2810%
2811% o image: the image.
2812%
2813% o storage_class: The image class.
2814%
2815*/
2816MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2817 const ClassType storage_class)
2818{
2819 Cache
2820 cache;
2821
2822 if (image->storage_class == storage_class)
2823 return(MagickTrue);
2824 image->storage_class=storage_class;
2825 cache=GetImagePixelCache(image,MagickTrue,&image->exception);
2826 return(cache == (Cache) NULL ? MagickFalse : MagickTrue);
2827}
2828
2829/*
2830%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2831% %
2832% %
2833% %
2834% S e t I m a g e C l i p M a s k %
2835% %
2836% %
2837% %
2838%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2839%
2840% SetImageClipMask() associates a clip path with the image. The clip path
2841% must be the same dimensions as the image. Set any pixel component of
2842% the clip path to TransparentOpacity to prevent that corresponding image
2843% pixel component from being updated when SyncAuthenticPixels() is applied.
2844%
2845% The format of the SetImageClipMask method is:
2846%
2847% MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2848%
2849% A description of each parameter follows:
2850%
2851% o image: the image.
2852%
2853% o clip_mask: the image clip path.
2854%
2855*/
2856MagickExport MagickBooleanType SetImageClipMask(Image *image,
2857 const Image *clip_mask)
2858{
2859 assert(image != (Image *) NULL);
2860 if (image->debug != MagickFalse)
2861 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2862 assert(image->signature == MagickSignature);
2863 if (clip_mask != (const Image *) NULL)
2864 if ((clip_mask->columns != image->columns) ||
2865 (clip_mask->rows != image->rows))
2866 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2867 if (image->clip_mask != (Image *) NULL)
2868 image->clip_mask=DestroyImage(image->clip_mask);
2869 image->clip_mask=NewImageList();
2870 if (clip_mask == (Image *) NULL)
2871 return(MagickTrue);
2872 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2873 return(MagickFalse);
2874 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2875 if (image->clip_mask == (Image *) NULL)
2876 return(MagickFalse);
2877 return(MagickTrue);
2878}
2879
2880/*
2881%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2882% %
2883% %
2884% %
2885% S e t I m a g e E x t e n t %
2886% %
2887% %
2888% %
2889%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2890%
2891% SetImageExtent() sets the image size (i.e. columns & rows).
2892%
2893% The format of the SetImageExtent method is:
2894%
2895% MagickBooleanType SetImageExtent(Image *image,
2896% const unsigned long columns,const unsigned long rows)
2897%
2898% A description of each parameter follows:
2899%
2900% o image: the image.
2901%
2902% o columns: The image width in pixels.
2903%
2904% o rows: The image height in pixels.
2905%
2906*/
2907MagickExport MagickBooleanType SetImageExtent(Image *image,
2908 const unsigned long columns,const unsigned long rows)
2909{
2910 Cache
2911 cache;
2912
2913 if ((columns != 0) && (rows != 0))
2914 {
2915 image->columns=columns;
2916 image->rows=rows;
2917 }
2918 cache=GetImagePixelCache(image,MagickTrue,&image->exception);
2919 return(cache == (Cache) NULL ? MagickFalse : MagickTrue);
2920}
2921
2922/*
2923%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2924% %
2925% %
2926% %
2927+ S e t I m a g e I n f o %
2928% %
2929% %
2930% %
2931%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2932%
2933% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2934% It is set to a type of image format based on the prefix or suffix of the
2935% filename. For example, `ps:image' returns PS indicating a Postscript image.
2936% JPEG is returned for this filename: `image.jpg'. The filename prefix has
2937% precendence over the suffix. Use an optional index enclosed in brackets
2938% after a file name to specify a desired scene of a multi-resolution image
2939% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2940% indicates success.
2941%
2942% The format of the SetImageInfo method is:
2943%
2944% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002945% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002946%
2947% A description of each parameter follows:
2948%
cristyd965a422010-03-03 17:47:35 +00002949% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00002950%
cristyd965a422010-03-03 17:47:35 +00002951% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00002952%
2953% o exception: return any errors or warnings in this structure.
2954%
2955*/
2956MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002957 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002958{
2959 char
2960 extension[MaxTextExtent],
2961 filename[MaxTextExtent],
2962 magic[MaxTextExtent],
2963 *q,
2964 subimage[MaxTextExtent];
2965
2966 const MagicInfo
2967 *magic_info;
2968
2969 const MagickInfo
2970 *magick_info;
2971
2972 ExceptionInfo
2973 *sans_exception;
2974
2975 Image
2976 *image;
2977
2978 MagickBooleanType
2979 status;
2980
2981 register const char
2982 *p;
2983
2984 ssize_t
2985 count;
2986
2987 unsigned char
2988 magick[2*MaxTextExtent];
2989
2990 /*
2991 Look for 'image.format' in filename.
2992 */
2993 assert(image_info != (ImageInfo *) NULL);
2994 assert(image_info->signature == MagickSignature);
2995 if (image_info->debug != MagickFalse)
2996 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2997 image_info->filename);
2998 *subimage='\0';
cristyd965a422010-03-03 17:47:35 +00002999 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003000 {
cristyd965a422010-03-03 17:47:35 +00003001 GetPathComponent(image_info->filename,SubimagePath,subimage);
3002 if (*subimage != '\0')
cristy3ed852e2009-09-05 21:47:34 +00003003 {
cristyd965a422010-03-03 17:47:35 +00003004 /*
3005 Look for scene specification (e.g. img0001.pcd[4]).
3006 */
3007 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3008 {
3009 if (IsGeometry(subimage) != MagickFalse)
3010 (void) CloneString(&image_info->extract,subimage);
3011 }
3012 else
3013 {
3014 unsigned long
3015 first,
3016 last;
cristy3ed852e2009-09-05 21:47:34 +00003017
cristyd965a422010-03-03 17:47:35 +00003018 (void) CloneString(&image_info->scenes,subimage);
3019 image_info->scene=StringToUnsignedLong(image_info->scenes);
3020 image_info->number_scenes=image_info->scene;
3021 p=image_info->scenes;
3022 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3023 {
3024 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3025 (*p == ','))
3026 p++;
3027 first=(unsigned long) strtol(p,&q,10);
3028 last=first;
3029 while (isspace((int) ((unsigned char) *q)) != 0)
3030 q++;
3031 if (*q == '-')
3032 last=(unsigned long) strtol(q+1,&q,10);
3033 if (first > last)
3034 Swap(first,last);
3035 if (first < image_info->scene)
3036 image_info->scene=first;
3037 if (last > image_info->number_scenes)
3038 image_info->number_scenes=last;
3039 p=q;
3040 }
3041 image_info->number_scenes-=image_info->scene-1;
3042 image_info->subimage=image_info->scene;
3043 image_info->subrange=image_info->number_scenes;
3044 }
cristy3ed852e2009-09-05 21:47:34 +00003045 }
3046 }
3047 *extension='\0';
3048 GetPathComponent(image_info->filename,ExtensionPath,extension);
3049#if defined(MAGICKCORE_ZLIB_DELEGATE)
3050 if (*extension != '\0')
3051 if ((LocaleCompare(extension,"gz") == 0) ||
3052 (LocaleCompare(extension,"Z") == 0) ||
3053 (LocaleCompare(extension,"wmz") == 0))
3054 {
3055 char
3056 path[MaxTextExtent];
3057
3058 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3059 path[strlen(path)-strlen(extension)-1]='\0';
3060 GetPathComponent(path,ExtensionPath,extension);
3061 }
3062#endif
3063#if defined(MAGICKCORE_BZLIB_DELEGATE)
3064 if (*extension != '\0')
3065 if (LocaleCompare(extension,"bz2") == 0)
3066 {
3067 char
3068 path[MaxTextExtent];
3069
3070 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3071 path[strlen(path)-strlen(extension)-1]='\0';
3072 GetPathComponent(path,ExtensionPath,extension);
3073 }
3074#endif
3075 image_info->affirm=MagickFalse;
3076 sans_exception=AcquireExceptionInfo();
3077 if (*extension != '\0')
3078 {
3079 MagickFormatType
3080 format_type;
3081
3082 register long
3083 i;
3084
3085 static const char
3086 *format_type_formats[] =
3087 {
3088 "AUTOTRACE",
3089 "BROWSE",
3090 "DCRAW",
3091 "EDIT",
3092 "EPHEMERAL",
3093 "LAUNCH",
3094 "MPEG:DECODE",
3095 "MPEG:ENCODE",
3096 "PRINT",
3097 "PS:ALPHA",
3098 "PS:CMYK",
3099 "PS:COLOR",
3100 "PS:GRAY",
3101 "PS:MONO",
3102 "SCAN",
3103 "SHOW",
3104 "WIN",
3105 (char *) NULL
3106 };
3107
3108 /*
3109 User specified image format.
3110 */
3111 (void) CopyMagickString(magic,extension,MaxTextExtent);
3112 LocaleUpper(magic);
3113 /*
3114 Look for explicit image formats.
3115 */
3116 format_type=UndefinedFormatType;
3117 i=0;
cristydd9a2532010-02-20 19:26:46 +00003118 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00003119 (format_type_formats[i] != (char *) NULL))
3120 {
3121 if ((*magic == *format_type_formats[i]) &&
3122 (LocaleCompare(magic,format_type_formats[i]) == 0))
3123 format_type=ExplicitFormatType;
3124 i++;
3125 }
3126 magick_info=GetMagickInfo(magic,sans_exception);
3127 if ((magick_info != (const MagickInfo *) NULL) &&
3128 (magick_info->format_type != UndefinedFormatType))
3129 format_type=magick_info->format_type;
3130 if (format_type == UndefinedFormatType)
3131 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3132 else
3133 if (format_type == ExplicitFormatType)
3134 {
3135 image_info->affirm=MagickTrue;
3136 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3137 }
3138 if (LocaleCompare(magic,"RGB") == 0)
3139 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3140 }
3141 /*
3142 Look for explicit 'format:image' in filename.
3143 */
3144 *magic='\0';
3145 GetPathComponent(image_info->filename,MagickPath,magic);
3146 if (*magic == '\0')
3147 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3148 else
3149 {
3150 /*
3151 User specified image format.
3152 */
3153 LocaleUpper(magic);
3154 if (IsMagickConflict(magic) == MagickFalse)
3155 {
3156 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3157 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3158 image_info->affirm=MagickTrue;
3159 else
3160 image_info->temporary=MagickTrue;
3161 }
3162 }
3163 magick_info=GetMagickInfo(magic,sans_exception);
3164 sans_exception=DestroyExceptionInfo(sans_exception);
3165 if ((magick_info == (const MagickInfo *) NULL) ||
3166 (GetMagickEndianSupport(magick_info) == MagickFalse))
3167 image_info->endian=UndefinedEndian;
3168 GetPathComponent(image_info->filename,CanonicalPath,filename);
3169 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00003170 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00003171 {
3172 /*
cristyd965a422010-03-03 17:47:35 +00003173 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00003174 */
cristyd965a422010-03-03 17:47:35 +00003175 (void) InterpretImageFilename(image_info,(Image *) NULL,
3176 image_info->filename,(int) image_info->scene,filename);
3177 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3178 (strchr(filename,'%') == (char *) NULL))
3179 image_info->adjoin=MagickFalse;
3180 }
3181 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3182 {
3183 /*
3184 Some image formats do not support multiple frames per file.
3185 */
cristy3ed852e2009-09-05 21:47:34 +00003186 magick_info=GetMagickInfo(magic,exception);
3187 if (magick_info != (const MagickInfo *) NULL)
3188 if (GetMagickAdjoin(magick_info) == MagickFalse)
3189 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003190 }
3191 if (image_info->affirm != MagickFalse)
3192 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00003193 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003194 {
3195 /*
cristyd965a422010-03-03 17:47:35 +00003196 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00003197 */
cristyd965a422010-03-03 17:47:35 +00003198 image=AcquireImage(image_info);
3199 (void) CopyMagickString(image->filename,image_info->filename,
3200 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003201 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3202 if (status == MagickFalse)
3203 {
3204 image=DestroyImage(image);
3205 return(MagickFalse);
3206 }
cristyd965a422010-03-03 17:47:35 +00003207 if ((IsBlobSeekable(image) == MagickFalse) ||
3208 (IsBlobExempt(image) != MagickFalse))
3209 {
3210 /*
3211 Copy standard input or pipe to temporary file.
3212 */
3213 *filename='\0';
3214 status=ImageToFile(image,filename,exception);
3215 (void) CloseBlob(image);
3216 if (status == MagickFalse)
3217 {
3218 image=DestroyImage(image);
3219 return(MagickFalse);
3220 }
3221 SetImageInfoFile(image_info,(FILE *) NULL);
3222 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3223 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3224 if (status == MagickFalse)
3225 {
3226 image=DestroyImage(image);
3227 return(MagickFalse);
3228 }
3229 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3230 image_info->temporary=MagickTrue;
3231 }
3232 (void) ResetMagickMemory(magick,0,sizeof(magick));
3233 count=ReadBlob(image,2*MaxTextExtent,magick);
3234 (void) CloseBlob(image);
3235 image=DestroyImage(image);
3236 /*
3237 Check magic.xml configuration file.
3238 */
3239 sans_exception=AcquireExceptionInfo();
3240 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3241 if ((magic_info != (const MagicInfo *) NULL) &&
3242 (GetMagicName(magic_info) != (char *) NULL))
3243 {
3244 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3245 MaxTextExtent);
3246 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3247 if ((magick_info == (const MagickInfo *) NULL) ||
3248 (GetMagickEndianSupport(magick_info) == MagickFalse))
3249 image_info->endian=UndefinedEndian;
3250 sans_exception=DestroyExceptionInfo(sans_exception);
3251 return(MagickTrue);
3252 }
cristy3ed852e2009-09-05 21:47:34 +00003253 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3254 if ((magick_info == (const MagickInfo *) NULL) ||
3255 (GetMagickEndianSupport(magick_info) == MagickFalse))
3256 image_info->endian=UndefinedEndian;
3257 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00003258 }
cristy3ed852e2009-09-05 21:47:34 +00003259 return(MagickTrue);
3260}
3261
3262/*
3263%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3264% %
3265% %
3266% %
3267% S e t I m a g e I n f o B l o b %
3268% %
3269% %
3270% %
3271%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3272%
3273% SetImageInfoBlob() sets the image info blob member.
3274%
3275% The format of the SetImageInfoBlob method is:
3276%
3277% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3278% const size_t length)
3279%
3280% A description of each parameter follows:
3281%
3282% o image_info: the image info.
3283%
3284% o blob: the blob.
3285%
3286% o length: the blob length.
3287%
3288*/
3289MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3290 const size_t length)
3291{
3292 assert(image_info != (ImageInfo *) NULL);
3293 assert(image_info->signature == MagickSignature);
3294 if (image_info->debug != MagickFalse)
3295 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3296 image_info->filename);
3297 image_info->blob=(void *) blob;
3298 image_info->length=length;
3299}
3300
3301/*
3302%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3303% %
3304% %
3305% %
3306% S e t I m a g e I n f o F i l e %
3307% %
3308% %
3309% %
3310%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3311%
3312% SetImageInfoFile() sets the image info file member.
3313%
3314% The format of the SetImageInfoFile method is:
3315%
3316% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3317%
3318% A description of each parameter follows:
3319%
3320% o image_info: the image info.
3321%
3322% o file: the file.
3323%
3324*/
3325MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3326{
3327 assert(image_info != (ImageInfo *) NULL);
3328 assert(image_info->signature == MagickSignature);
3329 if (image_info->debug != MagickFalse)
3330 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3331 image_info->filename);
3332 image_info->file=file;
3333}
3334
3335/*
3336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3337% %
3338% %
3339% %
3340% S e t I m a g e M a s k %
3341% %
3342% %
3343% %
3344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3345%
3346% SetImageMask() associates a mask with the image. The mask must be the same
3347% dimensions as the image.
3348%
3349% The format of the SetImageMask method is:
3350%
3351% MagickBooleanType SetImageMask(Image *image,const Image *mask)
3352%
3353% A description of each parameter follows:
3354%
3355% o image: the image.
3356%
3357% o mask: the image mask.
3358%
3359*/
3360MagickExport MagickBooleanType SetImageMask(Image *image,
3361 const Image *mask)
3362{
3363 assert(image != (Image *) NULL);
3364 if (image->debug != MagickFalse)
3365 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3366 assert(image->signature == MagickSignature);
3367 if (mask != (const Image *) NULL)
3368 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3369 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3370 if (image->mask != (Image *) NULL)
3371 image->mask=DestroyImage(image->mask);
3372 image->mask=NewImageList();
3373 if (mask == (Image *) NULL)
3374 return(MagickTrue);
3375 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3376 return(MagickFalse);
3377 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3378 if (image->mask == (Image *) NULL)
3379 return(MagickFalse);
3380 return(MagickTrue);
3381}
3382
3383/*
3384%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3385% %
3386% %
3387% %
3388% S e t I m a g e O p a c i t y %
3389% %
3390% %
3391% %
3392%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3393%
3394% SetImageOpacity() sets the opacity levels of the image.
3395%
3396% The format of the SetImageOpacity method is:
3397%
3398% MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3399%
3400% A description of each parameter follows:
3401%
3402% o image: the image.
3403%
3404% o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3405% fully transparent.
3406%
3407*/
3408MagickExport MagickBooleanType SetImageOpacity(Image *image,
3409 const Quantum opacity)
3410{
3411 CacheView
3412 *image_view;
3413
3414 ExceptionInfo
3415 *exception;
3416
3417 long
3418 y;
3419
3420 MagickBooleanType
3421 status;
3422
3423 assert(image != (Image *) NULL);
3424 if (image->debug != MagickFalse)
3425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3426 assert(image->signature == MagickSignature);
3427 image->matte=opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
3428 status=MagickTrue;
3429 exception=(&image->exception);
3430 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00003431#if defined(MAGICKCORE_OPENMP_SUPPORT)
3432 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003433#endif
3434 for (y=0; y < (long) image->rows; y++)
3435 {
3436 register long
3437 x;
3438
3439 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003440 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003441
3442 if (status == MagickFalse)
3443 continue;
3444 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3445 if (q == (PixelPacket *) NULL)
3446 {
3447 status=MagickFalse;
3448 continue;
3449 }
3450 for (x=0; x < (long) image->columns; x++)
3451 {
cristy46f08202010-01-10 04:04:21 +00003452 SetOpacityPixelComponent(q,opacity);
cristy3ed852e2009-09-05 21:47:34 +00003453 q++;
3454 }
3455 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3456 status=MagickFalse;
3457 }
3458 image_view=DestroyCacheView(image_view);
3459 return(status);
3460}
3461
3462/*
3463%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3464% %
3465% %
3466% %
3467% S e t I m a g e T y p e %
3468% %
3469% %
3470% %
3471%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3472%
3473% SetImageType() sets the type of image. Choose from these types:
3474%
3475% Bilevel Grayscale GrayscaleMatte
3476% Palette PaletteMatte TrueColor
3477% TrueColorMatte ColorSeparation ColorSeparationMatte
3478% OptimizeType
3479%
3480% The format of the SetImageType method is:
3481%
3482% MagickBooleanType SetImageType(Image *image,const ImageType type)
3483%
3484% A description of each parameter follows:
3485%
3486% o image: the image.
3487%
3488% o type: Image type.
3489%
3490*/
3491MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3492{
3493 const char
3494 *artifact;
3495
3496 ImageInfo
3497 *image_info;
3498
3499 MagickBooleanType
3500 status;
3501
3502 QuantizeInfo
3503 *quantize_info;
3504
3505 assert(image != (Image *) NULL);
3506 if (image->debug != MagickFalse)
3507 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3508 assert(image->signature == MagickSignature);
3509 status=MagickTrue;
3510 image_info=AcquireImageInfo();
3511 image_info->dither=image->dither;
3512 artifact=GetImageArtifact(image,"dither");
3513 if (artifact != (const char *) NULL)
3514 (void) SetImageOption(image_info,"dither",artifact);
3515 switch (type)
3516 {
3517 case BilevelType:
3518 {
3519 if (IsGrayImage(image,&image->exception) == MagickFalse)
3520 status=TransformImageColorspace(image,GRAYColorspace);
3521 if (IsMonochromeImage(image,&image->exception) == MagickFalse)
3522 {
3523 quantize_info=AcquireQuantizeInfo(image_info);
3524 quantize_info->number_colors=2;
3525 quantize_info->colorspace=GRAYColorspace;
3526 status=QuantizeImage(quantize_info,image);
3527 quantize_info=DestroyQuantizeInfo(quantize_info);
3528 }
3529 image->matte=MagickFalse;
3530 break;
3531 }
3532 case GrayscaleType:
3533 {
3534 if (IsGrayImage(image,&image->exception) == MagickFalse)
3535 status=TransformImageColorspace(image,GRAYColorspace);
3536 image->matte=MagickFalse;
3537 break;
3538 }
3539 case GrayscaleMatteType:
3540 {
3541 if (IsGrayImage(image,&image->exception) == MagickFalse)
3542 status=TransformImageColorspace(image,GRAYColorspace);
3543 if (image->matte == MagickFalse)
3544 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3545 break;
3546 }
3547 case PaletteType:
3548 {
3549 if (image->colorspace != RGBColorspace)
3550 status=TransformImageColorspace(image,RGBColorspace);
3551 if ((image->storage_class == DirectClass) || (image->colors > 256))
3552 {
3553 quantize_info=AcquireQuantizeInfo(image_info);
3554 quantize_info->number_colors=256;
3555 status=QuantizeImage(quantize_info,image);
3556 quantize_info=DestroyQuantizeInfo(quantize_info);
3557 }
3558 image->matte=MagickFalse;
3559 break;
3560 }
3561 case PaletteBilevelMatteType:
3562 {
3563 if (image->colorspace != RGBColorspace)
3564 status=TransformImageColorspace(image,RGBColorspace);
3565 if (image->matte == MagickFalse)
3566 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3567 (void) BilevelImageChannel(image,AlphaChannel,(double) QuantumRange/2.0);
3568 quantize_info=AcquireQuantizeInfo(image_info);
3569 status=QuantizeImage(quantize_info,image);
3570 quantize_info=DestroyQuantizeInfo(quantize_info);
3571 break;
3572 }
3573 case PaletteMatteType:
3574 {
3575 if (image->colorspace != RGBColorspace)
3576 status=TransformImageColorspace(image,RGBColorspace);
3577 if (image->matte == MagickFalse)
3578 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3579 quantize_info=AcquireQuantizeInfo(image_info);
3580 quantize_info->colorspace=TransparentColorspace;
3581 status=QuantizeImage(quantize_info,image);
3582 quantize_info=DestroyQuantizeInfo(quantize_info);
3583 break;
3584 }
3585 case TrueColorType:
3586 {
3587 if (image->colorspace != RGBColorspace)
3588 status=TransformImageColorspace(image,RGBColorspace);
3589 if (image->storage_class != DirectClass)
3590 status=SetImageStorageClass(image,DirectClass);
3591 image->matte=MagickFalse;
3592 break;
3593 }
3594 case TrueColorMatteType:
3595 {
3596 if (image->colorspace != RGBColorspace)
3597 status=TransformImageColorspace(image,RGBColorspace);
3598 if (image->storage_class != DirectClass)
3599 status=SetImageStorageClass(image,DirectClass);
3600 if (image->matte == MagickFalse)
3601 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3602 break;
3603 }
3604 case ColorSeparationType:
3605 {
3606 if (image->colorspace != CMYKColorspace)
3607 {
3608 if (image->colorspace != RGBColorspace)
3609 status=TransformImageColorspace(image,RGBColorspace);
3610 status=TransformImageColorspace(image,CMYKColorspace);
3611 }
3612 if (image->storage_class != DirectClass)
3613 status=SetImageStorageClass(image,DirectClass);
3614 image->matte=MagickFalse;
3615 break;
3616 }
3617 case ColorSeparationMatteType:
3618 {
3619 if (image->colorspace != CMYKColorspace)
3620 {
3621 if (image->colorspace != RGBColorspace)
3622 status=TransformImageColorspace(image,RGBColorspace);
3623 status=TransformImageColorspace(image,CMYKColorspace);
3624 }
3625 if (image->storage_class != DirectClass)
3626 status=SetImageStorageClass(image,DirectClass);
3627 if (image->matte == MagickFalse)
3628 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3629 break;
3630 }
3631 case OptimizeType:
3632 case UndefinedType:
3633 break;
3634 }
3635 image->type=type;
3636 image_info=DestroyImageInfo(image_info);
3637 return(status);
3638}
3639
3640/*
3641%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3642% %
3643% %
3644% %
3645% 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 %
3646% %
3647% %
3648% %
3649%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3650%
3651% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3652% image and returns the previous setting. A virtual pixel is any pixel access
3653% that is outside the boundaries of the image cache.
3654%
3655% The format of the SetImageVirtualPixelMethod() method is:
3656%
3657% VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3658% const VirtualPixelMethod virtual_pixel_method)
3659%
3660% A description of each parameter follows:
3661%
3662% o image: the image.
3663%
3664% o virtual_pixel_method: choose the type of virtual pixel.
3665%
3666*/
3667MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3668 const VirtualPixelMethod virtual_pixel_method)
3669{
3670 assert(image != (const Image *) NULL);
3671 assert(image->signature == MagickSignature);
3672 if (image->debug != MagickFalse)
3673 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3674 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3675}
3676
3677/*
3678%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3679% %
3680% %
3681% %
cristy3ed852e2009-09-05 21:47:34 +00003682% S t r i p I m a g e %
3683% %
3684% %
3685% %
3686%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3687%
cristy376bda92009-12-22 21:15:23 +00003688% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00003689%
3690% The format of the StripImage method is:
3691%
3692% MagickBooleanType StripImage(Image *image)
3693%
3694% A description of each parameter follows:
3695%
3696% o image: the image.
3697%
3698*/
3699MagickExport MagickBooleanType StripImage(Image *image)
3700{
3701 assert(image != (Image *) NULL);
3702 if (image->debug != MagickFalse)
3703 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3704 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00003705 (void) DeleteImageProperty(image,"comment");
cristy3ed852e2009-09-05 21:47:34 +00003706 return(MagickTrue);
3707}
3708
3709/*
3710%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3711% %
3712% %
3713% %
3714+ S y n c I m a g e %
3715% %
3716% %
3717% %
3718%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3719%
3720% SyncImage() initializes the red, green, and blue intensities of each pixel
3721% as defined by the colormap index.
3722%
3723% The format of the SyncImage method is:
3724%
3725% MagickBooleanType SyncImage(Image *image)
3726%
3727% A description of each parameter follows:
3728%
3729% o image: the image.
3730%
3731*/
3732
3733static inline IndexPacket PushColormapIndex(Image *image,
3734 const unsigned long index,MagickBooleanType *range_exception)
3735{
3736 if (index < image->colors)
3737 return((IndexPacket) index);
3738 *range_exception=MagickTrue;
3739 return((IndexPacket) 0);
3740}
3741
3742MagickExport MagickBooleanType SyncImage(Image *image)
3743{
3744 CacheView
3745 *image_view;
3746
3747 ExceptionInfo
3748 *exception;
3749
3750 long
3751 y;
3752
3753 MagickBooleanType
3754 range_exception,
3755 status;
3756
3757 assert(image != (Image *) NULL);
3758 if (image->debug != MagickFalse)
3759 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3760 assert(image->signature == MagickSignature);
3761 if (image->storage_class == DirectClass)
3762 return(MagickFalse);
3763 range_exception=MagickFalse;
3764 status=MagickTrue;
3765 exception=(&image->exception);
3766 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00003767#if defined(MAGICKCORE_OPENMP_SUPPORT)
3768 #pragma omp parallel for schedule(dynamic,4) shared(status)
3769#endif
cristy3ed852e2009-09-05 21:47:34 +00003770 for (y=0; y < (long) image->rows; y++)
3771 {
3772 IndexPacket
3773 index;
3774
3775 PixelPacket
3776 pixel;
3777
3778 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00003779 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00003780
3781 register long
3782 x;
3783
3784 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003785 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003786
cristy48974b92009-12-19 02:36:06 +00003787 if (status == MagickFalse)
3788 continue;
cristy3ed852e2009-09-05 21:47:34 +00003789 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3790 if (q == (PixelPacket *) NULL)
3791 {
3792 status=MagickFalse;
3793 continue;
3794 }
3795 indexes=GetCacheViewAuthenticIndexQueue(image_view);
3796 for (x=0; x < (long) image->columns; x++)
3797 {
3798 index=PushColormapIndex(image,(unsigned long) indexes[x],
3799 &range_exception);
3800 pixel=image->colormap[(long) index];
3801 q->red=pixel.red;
3802 q->green=pixel.green;
3803 q->blue=pixel.blue;
cristyd0272592010-04-21 01:01:49 +00003804 if (image->matte != MagickFalse)
3805 q->opacity=pixel.opacity;
cristy3ed852e2009-09-05 21:47:34 +00003806 q++;
3807 }
3808 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3809 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003810 }
3811 image_view=DestroyCacheView(image_view);
3812 if (range_exception != MagickFalse)
3813 (void) ThrowMagickException(&image->exception,GetMagickModule(),
3814 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
3815 return(status);
3816}
cristy1626d332009-11-10 16:58:17 +00003817
3818/*
3819%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3820% %
3821% %
3822% %
3823% S y n c I m a g e S e t t i n g s %
3824% %
3825% %
3826% %
3827%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3828%
3829% SyncImageSettings() sync the image info options to the image.
3830%
3831% The format of the SyncImageSettings method is:
3832%
3833% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3834% Image *image)
3835% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3836% Image *image)
3837%
3838% A description of each parameter follows:
3839%
3840% o image_info: the image info.
3841%
3842% o image: the image.
3843%
3844*/
3845
3846MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3847 Image *images)
3848{
3849 Image
3850 *image;
3851
3852 assert(image_info != (const ImageInfo *) NULL);
3853 assert(image_info->signature == MagickSignature);
3854 assert(images != (Image *) NULL);
3855 assert(images->signature == MagickSignature);
3856 if (images->debug != MagickFalse)
3857 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3858 image=images;
3859 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3860 (void) SyncImageSettings(image_info,image);
3861 (void) DeleteImageOption(image_info,"page");
3862 return(MagickTrue);
3863}
3864
3865MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3866 Image *image)
3867{
3868 char
3869 property[MaxTextExtent];
3870
3871 const char
3872 *value,
3873 *option;
3874
3875 GeometryInfo
3876 geometry_info;
3877
3878 MagickStatusType
3879 flags;
3880
cristy19eb6412010-04-23 14:42:29 +00003881 ResolutionType
3882 units;
3883
cristy1626d332009-11-10 16:58:17 +00003884 /*
3885 Sync image options.
3886 */
3887 assert(image_info != (const ImageInfo *) NULL);
3888 assert(image_info->signature == MagickSignature);
3889 assert(image != (Image *) NULL);
3890 assert(image->signature == MagickSignature);
3891 if (image->debug != MagickFalse)
3892 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3893 option=GetImageOption(image_info,"background");
3894 if (option != (const char *) NULL)
3895 (void) QueryColorDatabase(option,&image->background_color,
3896 &image->exception);
3897 option=GetImageOption(image_info,"bias");
3898 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00003899 image->bias=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00003900 option=GetImageOption(image_info,"black-point-compensation");
3901 if (option != (const char *) NULL)
3902 image->black_point_compensation=(MagickBooleanType) ParseMagickOption(
3903 MagickBooleanOptions,MagickFalse,option);
3904 option=GetImageOption(image_info,"blue-primary");
3905 if (option != (const char *) NULL)
3906 {
3907 flags=ParseGeometry(option,&geometry_info);
3908 image->chromaticity.blue_primary.x=geometry_info.rho;
3909 image->chromaticity.blue_primary.y=geometry_info.sigma;
3910 if ((flags & SigmaValue) == 0)
3911 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3912 }
3913 option=GetImageOption(image_info,"bordercolor");
3914 if (option != (const char *) NULL)
3915 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
3916 option=GetImageOption(image_info,"colors");
3917 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003918 image->colors=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003919 option=GetImageOption(image_info,"compose");
3920 if (option != (const char *) NULL)
3921 image->compose=(CompositeOperator) ParseMagickOption(MagickComposeOptions,
3922 MagickFalse,option);
3923 option=GetImageOption(image_info,"compress");
3924 if (option != (const char *) NULL)
3925 image->compression=(CompressionType) ParseMagickOption(
3926 MagickCompressOptions,MagickFalse,option);
3927 option=GetImageOption(image_info,"debug");
3928 if (option != (const char *) NULL)
3929 image->debug=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
3930 MagickFalse,option);
3931 option=GetImageOption(image_info,"delay");
3932 if (option != (const char *) NULL)
3933 {
3934 GeometryInfo
3935 geometry_info;
3936
3937 flags=ParseGeometry(option,&geometry_info);
3938 if ((flags & GreaterValue) != 0)
3939 {
cristy06609ee2010-03-17 20:21:27 +00003940 if (image->delay > (unsigned long) floor(geometry_info.rho+0.5))
3941 image->delay=(unsigned long) floor(geometry_info.rho+0.5);
cristy1626d332009-11-10 16:58:17 +00003942 }
3943 else
3944 if ((flags & LessValue) != 0)
3945 {
cristy06609ee2010-03-17 20:21:27 +00003946 if (image->delay < (unsigned long) floor(geometry_info.rho+0.5))
3947 image->ticks_per_second=(long) floor(geometry_info.sigma+0.5);
cristy1626d332009-11-10 16:58:17 +00003948 }
3949 else
cristy06609ee2010-03-17 20:21:27 +00003950 image->delay=(unsigned long) floor(geometry_info.rho+0.5);
cristy1626d332009-11-10 16:58:17 +00003951 if ((flags & SigmaValue) != 0)
cristy06609ee2010-03-17 20:21:27 +00003952 image->ticks_per_second=(long) floor(geometry_info.sigma+0.5);
cristy1626d332009-11-10 16:58:17 +00003953 }
3954 option=GetImageOption(image_info,"density");
3955 if (option != (const char *) NULL)
3956 {
3957 GeometryInfo
3958 geometry_info;
3959
3960 /*
3961 Set image density.
3962 */
3963 flags=ParseGeometry(option,&geometry_info);
3964 image->x_resolution=geometry_info.rho;
3965 image->y_resolution=geometry_info.sigma;
3966 if ((flags & SigmaValue) == 0)
3967 image->y_resolution=image->x_resolution;
3968 }
3969 option=GetImageOption(image_info,"depth");
3970 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003971 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003972 option=GetImageOption(image_info,"dispose");
3973 if (option != (const char *) NULL)
3974 image->dispose=(DisposeType) ParseMagickOption(MagickDisposeOptions,
3975 MagickFalse,option);
3976 option=GetImageOption(image_info,"endian");
3977 if (option != (const char *) NULL)
3978 image->endian=(EndianType) ParseMagickOption(MagickEndianOptions,
3979 MagickFalse,option);
3980 if (image_info->extract != (char *) NULL)
3981 (void) ParseAbsoluteGeometry(image_info->extract,&image->extract_info);
3982 option=GetImageOption(image_info,"filter");
3983 if (option != (const char *) NULL)
3984 image->filter=(FilterTypes) ParseMagickOption(MagickFilterOptions,
3985 MagickFalse,option);
3986 option=GetImageOption(image_info,"fuzz");
3987 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00003988 image->fuzz=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00003989 option=GetImageOption(image_info,"gravity");
3990 if (option != (const char *) NULL)
3991 image->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
3992 MagickFalse,option);
3993 option=GetImageOption(image_info,"green-primary");
3994 if (option != (const char *) NULL)
3995 {
3996 flags=ParseGeometry(option,&geometry_info);
3997 image->chromaticity.green_primary.x=geometry_info.rho;
3998 image->chromaticity.green_primary.y=geometry_info.sigma;
3999 if ((flags & SigmaValue) == 0)
4000 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4001 }
4002 option=GetImageOption(image_info,"intent");
4003 if (option != (const char *) NULL)
4004 image->rendering_intent=(RenderingIntent) ParseMagickOption(
4005 MagickIntentOptions,MagickFalse,option);
4006 option=GetImageOption(image_info,"interlace");
4007 if (option != (const char *) NULL)
4008 image->interlace=(InterlaceType) ParseMagickOption(MagickInterlaceOptions,
4009 MagickFalse,option);
4010 option=GetImageOption(image_info,"interpolate");
4011 if (option != (const char *) NULL)
4012 image->interpolate=(InterpolatePixelMethod) ParseMagickOption(
4013 MagickInterpolateOptions,MagickFalse,option);
4014 option=GetImageOption(image_info,"loop");
4015 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004016 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004017 option=GetImageOption(image_info,"mattecolor");
4018 if (option != (const char *) NULL)
4019 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4020 option=GetImageOption(image_info,"orient");
4021 if (option != (const char *) NULL)
4022 image->orientation=(OrientationType) ParseMagickOption(
4023 MagickOrientationOptions,MagickFalse,option);
4024 option=GetImageOption(image_info,"quality");
4025 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004026 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004027 option=GetImageOption(image_info,"page");
4028 if (option != (const char *) NULL)
4029 {
4030 char
4031 *geometry;
4032
4033 geometry=GetPageGeometry(option);
4034 flags=ParseAbsoluteGeometry(geometry,&image->page);
4035 geometry=DestroyString(geometry);
4036 }
4037 option=GetImageOption(image_info,"red-primary");
4038 if (option != (const char *) NULL)
4039 {
4040 flags=ParseGeometry(option,&geometry_info);
4041 image->chromaticity.red_primary.x=geometry_info.rho;
4042 image->chromaticity.red_primary.y=geometry_info.sigma;
4043 if ((flags & SigmaValue) == 0)
4044 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4045 }
4046 if (image_info->quality != UndefinedCompressionQuality)
4047 image->quality=image_info->quality;
4048 option=GetImageOption(image_info,"scene");
4049 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004050 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004051 option=GetImageOption(image_info,"taint");
4052 if (option != (const char *) NULL)
4053 image->taint=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4054 MagickFalse,option);
4055 option=GetImageOption(image_info,"tile-offset");
4056 if (option != (const char *) NULL)
4057 {
4058 char
4059 *geometry;
4060
4061 geometry=GetPageGeometry(option);
4062 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4063 geometry=DestroyString(geometry);
4064 }
4065 option=GetImageOption(image_info,"transparent-color");
4066 if (option != (const char *) NULL)
4067 (void) QueryColorDatabase(option,&image->transparent_color,
4068 &image->exception);
4069 option=GetImageOption(image_info,"type");
4070 if (option != (const char *) NULL)
4071 image->type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
4072 option);
4073 option=GetImageOption(image_info,"units");
4074 if (option != (const char *) NULL)
cristy19eb6412010-04-23 14:42:29 +00004075 units=(ResolutionType) ParseMagickOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00004076 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00004077 else
4078 units = image_info->units;
4079 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00004080 {
cristy19eb6412010-04-23 14:42:29 +00004081 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00004082 switch (image->units)
4083 {
4084 case PixelsPerInchResolution:
4085 {
cristy19eb6412010-04-23 14:42:29 +00004086 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00004087 {
4088 image->x_resolution/=2.54;
4089 image->y_resolution/=2.54;
4090 }
4091 break;
4092 }
4093 case PixelsPerCentimeterResolution:
4094 {
cristy19eb6412010-04-23 14:42:29 +00004095 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00004096 {
cristy1f9ce9f2010-04-28 11:55:12 +00004097 image->x_resolution=(double) ((unsigned long) (100.0*2.54*
4098 image->x_resolution+0.5))/100.0;
4099 image->y_resolution=(double) ((unsigned long) (100.0*2.54*
4100 image->y_resolution+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00004101 }
4102 break;
4103 }
4104 default:
4105 break;
4106 }
cristy19eb6412010-04-23 14:42:29 +00004107 image->units=units;
cristy1626d332009-11-10 16:58:17 +00004108 }
4109 option=GetImageOption(image_info,"white-point");
4110 if (option != (const char *) NULL)
4111 {
4112 flags=ParseGeometry(option,&geometry_info);
4113 image->chromaticity.white_point.x=geometry_info.rho;
4114 image->chromaticity.white_point.y=geometry_info.sigma;
4115 if ((flags & SigmaValue) == 0)
4116 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4117 }
4118 ResetImageOptionIterator(image_info);
4119 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4120 {
4121 value=GetImageOption(image_info,option);
4122 if (value != (const char *) NULL)
4123 {
4124 (void) FormatMagickString(property,MaxTextExtent,"%s",option);
4125 (void) SetImageArtifact(image,property,value);
4126 }
4127 option=GetNextImageOption(image_info);
4128 }
4129 return(MagickTrue);
4130}