blob: 93afc44b49ee063b7b865a3a36ee31bd41981530 [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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{
cristye412c892010-07-26 12:31:36 +0000147 const char
cristyf3a660a2010-07-26 14:17:52 +0000148 *option;
cristye412c892010-07-26 12:31:36 +0000149
cristy3ed852e2009-09-05 21:47:34 +0000150 Image
151 *image;
152
153 MagickStatusType
154 flags;
155
156 /*
157 Allocate image structure.
158 */
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy73bd4a52010-10-05 11:24:23 +0000160 image=(Image *) AcquireMagickMemory(sizeof(*image));
cristy3ed852e2009-09-05 21:47:34 +0000161 if (image == (Image *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 (void) ResetMagickMemory(image,0,sizeof(*image));
164 /*
165 Initialize Image structure.
166 */
167 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
168 image->storage_class=DirectClass;
169 image->depth=MAGICKCORE_QUANTUM_DEPTH;
170 image->colorspace=RGBColorspace;
171 image->interlace=NoInterlace;
172 image->ticks_per_second=UndefinedTicksPerSecond;
173 image->compose=OverCompositeOp;
174 image->blur=1.0;
175 GetExceptionInfo(&image->exception);
176 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
177 &image->exception);
178 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
179 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
180 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
181 &image->exception);
182 image->x_resolution=DefaultResolution;
183 image->y_resolution=DefaultResolution;
184 image->units=PixelsPerInchResolution;
185 GetTimerInfo(&image->timer);
cristy73724512010-04-12 14:43:14 +0000186 image->ping=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000187 image->cache=AcquirePixelCache(0);
188 image->blob=CloneBlobInfo((BlobInfo *) NULL);
189 image->debug=IsEventLogging();
190 image->reference_count=1;
191 image->semaphore=AllocateSemaphoreInfo();
192 image->signature=MagickSignature;
193 if (image_info == (ImageInfo *) NULL)
194 return(image);
195 /*
196 Transfer image info.
197 */
198 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
199 MagickFalse);
200 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
201 (void) CopyMagickString(image->magick_filename,image_info->filename,
202 MaxTextExtent);
203 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
204 if (image_info->size != (char *) NULL)
205 {
206 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
207 image->columns=image->extract_info.width;
208 image->rows=image->extract_info.height;
209 image->offset=image->extract_info.x;
210 image->extract_info.x=0;
211 image->extract_info.y=0;
212 }
213 if (image_info->extract != (char *) NULL)
214 {
215 RectangleInfo
216 geometry;
217
218 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
219 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
220 {
221 image->extract_info=geometry;
222 Swap(image->columns,image->extract_info.width);
223 Swap(image->rows,image->extract_info.height);
224 }
225 }
226 image->compression=image_info->compression;
227 image->quality=image_info->quality;
228 image->endian=image_info->endian;
229 image->interlace=image_info->interlace;
230 image->units=image_info->units;
231 if (image_info->density != (char *) NULL)
232 {
233 GeometryInfo
234 geometry_info;
235
236 flags=ParseGeometry(image_info->density,&geometry_info);
237 image->x_resolution=geometry_info.rho;
238 image->y_resolution=geometry_info.sigma;
239 if ((flags & SigmaValue) == 0)
240 image->y_resolution=image->x_resolution;
241 }
242 if (image_info->page != (char *) NULL)
243 {
244 char
245 *geometry;
246
247 image->page=image->extract_info;
248 geometry=GetPageGeometry(image_info->page);
249 (void) ParseAbsoluteGeometry(geometry,&image->page);
250 geometry=DestroyString(geometry);
251 }
252 if (image_info->depth != 0)
253 image->depth=image_info->depth;
254 image->dither=image_info->dither;
255 image->background_color=image_info->background_color;
256 image->border_color=image_info->border_color;
257 image->matte_color=image_info->matte_color;
258 image->transparent_color=image_info->transparent_color;
cristy73724512010-04-12 14:43:14 +0000259 image->ping=image_info->ping;
cristy3ed852e2009-09-05 21:47:34 +0000260 image->progress_monitor=image_info->progress_monitor;
261 image->client_data=image_info->client_data;
262 if (image_info->cache != (void *) NULL)
263 ClonePixelCacheMethods(image->cache,image_info->cache);
264 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
cristy6b9aca12010-02-21 01:50:11 +0000265 (void) SyncImageSettings(image_info,image);
cristye412c892010-07-26 12:31:36 +0000266 option=GetImageOption(image_info,"delay");
267 if (option != (const char *) NULL)
268 {
269 GeometryInfo
270 geometry_info;
271
272 flags=ParseGeometry(option,&geometry_info);
273 if ((flags & GreaterValue) != 0)
274 {
275 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
276 image->delay=(size_t) floor(geometry_info.rho+0.5);
277 }
278 else
279 if ((flags & LessValue) != 0)
280 {
281 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
282 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
283 }
284 else
285 image->delay=(size_t) floor(geometry_info.rho+0.5);
286 if ((flags & SigmaValue) != 0)
287 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
288 }
289 option=GetImageOption(image_info,"dispose");
290 if (option != (const char *) NULL)
291 image->dispose=(DisposeType) ParseMagickOption(MagickDisposeOptions,
292 MagickFalse,option);
cristy3ed852e2009-09-05 21:47:34 +0000293 return(image);
294}
295
296/*
297%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298% %
299% %
300% %
cristy3ed852e2009-09-05 21:47:34 +0000301% A c q u i r e I m a g e I n f o %
302% %
303% %
304% %
305%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306%
307% AcquireImageInfo() allocates the ImageInfo structure.
308%
309% The format of the AcquireImageInfo method is:
310%
311% ImageInfo *AcquireImageInfo(void)
312%
313*/
314MagickExport ImageInfo *AcquireImageInfo(void)
315{
316 ImageInfo
317 *image_info;
318
cristy73bd4a52010-10-05 11:24:23 +0000319 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
cristy3ed852e2009-09-05 21:47:34 +0000320 if (image_info == (ImageInfo *) NULL)
321 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
322 GetImageInfo(image_info);
323 return(image_info);
324}
325
326/*
327%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328% %
329% %
330% %
331% A c q u i r e N e x t I m a g e %
332% %
333% %
334% %
335%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336%
337% AcquireNextImage() initializes the next image in a sequence to
338% default values. The next member of image points to the newly allocated
339% image. If there is a memory shortage, next is assigned NULL.
340%
341% The format of the AcquireNextImage method is:
342%
343% void AcquireNextImage(const ImageInfo *image_info,Image *image)
344%
345% A description of each parameter follows:
346%
347% o image_info: Many of the image default values are set from this
348% structure. For example, filename, compression, depth, background color,
349% and others.
350%
351% o image: the image.
352%
353*/
354MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
355{
356 /*
357 Allocate image structure.
358 */
359 assert(image != (Image *) NULL);
360 assert(image->signature == MagickSignature);
361 if (image->debug != MagickFalse)
362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
363 image->next=AcquireImage(image_info);
364 if (GetNextImageInList(image) == (Image *) NULL)
365 return;
366 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
367 MaxTextExtent);
368 if (image_info != (ImageInfo *) NULL)
369 (void) CopyMagickString(GetNextImageInList(image)->filename,
370 image_info->filename,MaxTextExtent);
371 DestroyBlob(GetNextImageInList(image));
372 image->next->blob=ReferenceBlob(image->blob);
373 image->next->endian=image->endian;
374 image->next->scene=image->scene+1;
375 image->next->previous=image;
376}
377
378/*
379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380% %
381% %
382% %
383% A p p e n d I m a g e s %
384% %
385% %
386% %
387%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388%
389% AppendImages() takes all images from the current image pointer to the end
390% of the image list and appends them to each other top-to-bottom if the
391% stack parameter is true, otherwise left-to-right.
392%
393% The current gravity setting now effects how the image is justified in the
394% final image.
395%
396% The format of the AppendImages method is:
397%
398% Image *AppendImages(const Image *image,const MagickBooleanType stack,
399% ExceptionInfo *exception)
400%
401% A description of each parameter follows:
402%
403% o image: the image sequence.
404%
405% o stack: A value other than 0 stacks the images top-to-bottom.
406%
407% o exception: return any errors or warnings in this structure.
408%
409*/
410MagickExport Image *AppendImages(const Image *image,
411 const MagickBooleanType stack,ExceptionInfo *exception)
412{
413#define AppendImageTag "Append/Image"
414
415 CacheView
416 *append_view,
417 *image_view;
418
419 Image
420 *append_image;
421
cristy3ed852e2009-09-05 21:47:34 +0000422 MagickBooleanType
423 matte,
424 proceed,
425 status;
426
cristybb503372010-05-27 20:51:26 +0000427 MagickOffsetType
428 n;
429
cristy3ed852e2009-09-05 21:47:34 +0000430 RectangleInfo
431 geometry;
432
433 register const Image
434 *next;
435
cristybb503372010-05-27 20:51:26 +0000436 size_t
cristy3ed852e2009-09-05 21:47:34 +0000437 height,
438 number_images,
439 width;
440
cristybb503372010-05-27 20:51:26 +0000441 ssize_t
442 x_offset,
443 y,
444 y_offset;
445
cristy3ed852e2009-09-05 21:47:34 +0000446 /*
447 Ensure the image have the same column width.
448 */
449 assert(image != (Image *) NULL);
450 assert(image->signature == MagickSignature);
451 if (image->debug != MagickFalse)
452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
453 assert(exception != (ExceptionInfo *) NULL);
454 assert(exception->signature == MagickSignature);
455 matte=image->matte;
456 number_images=1;
457 width=image->columns;
458 height=image->rows;
459 next=GetNextImageInList(image);
460 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
461 {
462 if (next->matte != MagickFalse)
463 matte=MagickTrue;
464 number_images++;
465 if (stack != MagickFalse)
466 {
467 if (next->columns > width)
468 width=next->columns;
469 height+=next->rows;
470 continue;
471 }
472 width+=next->columns;
473 if (next->rows > height)
474 height=next->rows;
475 }
476 /*
477 Initialize append next attributes.
478 */
479 append_image=CloneImage(image,width,height,MagickTrue,exception);
480 if (append_image == (Image *) NULL)
481 return((Image *) NULL);
482 if (SetImageStorageClass(append_image,DirectClass) == MagickFalse)
483 {
484 InheritException(exception,&append_image->exception);
485 append_image=DestroyImage(append_image);
486 return((Image *) NULL);
487 }
488 append_image->matte=matte;
489 (void) SetImageBackgroundColor(append_image);
490 status=MagickTrue;
491 x_offset=0;
492 y_offset=0;
493 append_view=AcquireCacheView(append_image);
cristybb503372010-05-27 20:51:26 +0000494 for (n=0; n < (MagickOffsetType) number_images; n++)
cristy3ed852e2009-09-05 21:47:34 +0000495 {
496 SetGeometry(append_image,&geometry);
497 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
498 if (stack != MagickFalse)
499 x_offset-=geometry.x;
500 else
501 y_offset-=geometry.y;
502 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +0000503#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy1a2bd532010-11-19 02:53:15 +0000504 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
cristy3ed852e2009-09-05 21:47:34 +0000505#endif
cristybb503372010-05-27 20:51:26 +0000506 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000507 {
508 MagickBooleanType
509 sync;
510
511 register const IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000512 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000513
514 register const PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000515 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000516
517 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000518 *restrict append_indexes;
cristy3ed852e2009-09-05 21:47:34 +0000519
cristy3ed852e2009-09-05 21:47:34 +0000520 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000521 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000522
cristycb6d09b2010-06-19 01:59:36 +0000523 register ssize_t
524 x;
525
cristy3ed852e2009-09-05 21:47:34 +0000526 if (status == MagickFalse)
527 continue;
528 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
529 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
530 image->columns,1,exception);
531 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
532 {
533 status=MagickFalse;
534 continue;
535 }
536 indexes=GetCacheViewVirtualIndexQueue(image_view);
537 append_indexes=GetCacheViewAuthenticIndexQueue(append_view);
cristybb503372010-05-27 20:51:26 +0000538 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000539 {
cristyce70c172010-01-07 17:15:30 +0000540 SetRedPixelComponent(q,GetRedPixelComponent(p));
541 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
542 SetBluePixelComponent(q,GetBluePixelComponent(p));
543 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000544 if (image->matte != MagickFalse)
cristyce70c172010-01-07 17:15:30 +0000545 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +0000546 if (image->colorspace == CMYKColorspace)
547 append_indexes[x]=indexes[x];
548 p++;
549 q++;
550 }
551 sync=SyncCacheViewAuthenticPixels(append_view,exception);
552 if (sync == MagickFalse)
cristya65f35b2010-04-20 01:10:41 +0000553 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000554 }
555 image_view=DestroyCacheView(image_view);
556 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
557 if (proceed == MagickFalse)
558 break;
559 if (stack == MagickFalse)
560 {
cristyeaedf062010-05-29 22:36:02 +0000561 x_offset+=(ssize_t) image->columns;
cristy3ed852e2009-09-05 21:47:34 +0000562 y_offset=0;
563 }
564 else
565 {
566 x_offset=0;
cristyeaedf062010-05-29 22:36:02 +0000567 y_offset+=(ssize_t) image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000568 }
569 image=GetNextImageInList(image);
570 }
571 append_view=DestroyCacheView(append_view);
572 if (status == MagickFalse)
573 append_image=DestroyImage(append_image);
574 return(append_image);
575}
576
577/*
578%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
579% %
580% %
581% %
cristy3ed852e2009-09-05 21:47:34 +0000582% C a t c h I m a g e E x c e p t i o n %
583% %
584% %
585% %
586%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587%
588% CatchImageException() returns if no exceptions are found in the image
589% sequence, otherwise it determines the most severe exception and reports
590% it as a warning or error depending on the severity.
591%
592% The format of the CatchImageException method is:
593%
594% ExceptionType CatchImageException(Image *image)
595%
596% A description of each parameter follows:
597%
598% o image: An image sequence.
599%
600*/
601MagickExport ExceptionType CatchImageException(Image *image)
602{
603 ExceptionInfo
604 *exception;
605
606 ExceptionType
607 severity;
608
609 assert(image != (const Image *) NULL);
610 assert(image->signature == MagickSignature);
611 if (image->debug != MagickFalse)
612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
613 exception=AcquireExceptionInfo();
614 GetImageException(image,exception);
615 CatchException(exception);
616 severity=exception->severity;
617 exception=DestroyExceptionInfo(exception);
618 return(severity);
619}
620
621/*
622%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
623% %
624% %
625% %
626% C l i p I m a g e P a t h %
627% %
628% %
629% %
630%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
631%
632% ClipImagePath() sets the image clip mask based any clipping path information
633% if it exists.
634%
635% The format of the ClipImagePath method is:
636%
637% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
638% const MagickBooleanType inside)
639%
640% A description of each parameter follows:
641%
642% o image: the image.
643%
644% o pathname: name of clipping path resource. If name is preceded by #, use
645% clipping path numbered by name.
646%
647% o inside: if non-zero, later operations take effect inside clipping path.
648% Otherwise later operations take effect outside clipping path.
649%
650*/
651
652MagickExport MagickBooleanType ClipImage(Image *image)
653{
654 return(ClipImagePath(image,"#1",MagickTrue));
655}
656
657MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
658 const MagickBooleanType inside)
659{
660#define ClipImagePathTag "ClipPath/Image"
661
662 char
663 *property;
664
665 const char
666 *value;
667
668 Image
669 *clip_mask;
670
671 ImageInfo
672 *image_info;
673
674 assert(image != (const Image *) NULL);
675 assert(image->signature == MagickSignature);
676 if (image->debug != MagickFalse)
677 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
678 assert(pathname != NULL);
679 property=AcquireString(pathname);
680 (void) FormatMagickString(property,MaxTextExtent,"8BIM:1999,2998:%s",
681 pathname);
682 value=GetImageProperty(image,property);
683 property=DestroyString(property);
684 if (value == (const char *) NULL)
685 {
686 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
687 image->filename);
688 return(MagickFalse);
689 }
690 image_info=AcquireImageInfo();
691 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
692 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
693 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
694 image_info=DestroyImageInfo(image_info);
695 if (clip_mask == (Image *) NULL)
696 return(MagickFalse);
697 if (clip_mask->storage_class == PseudoClass)
698 {
699 (void) SyncImage(clip_mask);
700 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
701 return(MagickFalse);
702 }
703 if (inside == MagickFalse)
704 (void) NegateImage(clip_mask,MagickFalse);
705 (void) FormatMagickString(clip_mask->magick_filename,MaxTextExtent,
706 "8BIM:1999,2998:%s\nPS",pathname);
707 (void) SetImageClipMask(image,clip_mask);
708 clip_mask=DestroyImage(clip_mask);
709 return(MagickTrue);
710}
711
712/*
713%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
714% %
715% %
716% %
717% C l o n e I m a g e %
718% %
719% %
720% %
721%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
722%
723% CloneImage() copies an image and returns the copy as a new image object.
724% If the specified columns and rows is 0, an exact copy of the image is
725% returned, otherwise the pixel data is undefined and must be initialized
726% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
727% failure, a NULL image is returned and exception describes the reason for the
728% failure.
729%
730% The format of the CloneImage method is:
731%
cristybb503372010-05-27 20:51:26 +0000732% Image *CloneImage(const Image *image,const size_t columns,
733% const size_t rows,const MagickBooleanType orphan,
cristy3ed852e2009-09-05 21:47:34 +0000734% ExceptionInfo *exception)
735%
736% A description of each parameter follows:
737%
738% o image: the image.
739%
740% o columns: the number of columns in the cloned image.
741%
742% o rows: the number of rows in the cloned image.
743%
744% o detach: With a value other than 0, the cloned image is detached from
745% its parent I/O stream.
746%
747% o exception: return any errors or warnings in this structure.
748%
749*/
cristybb503372010-05-27 20:51:26 +0000750MagickExport Image *CloneImage(const Image *image,const size_t columns,
cristybee00932011-01-15 20:28:27 +0000751 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000752{
753 Image
754 *clone_image;
755
756 MagickRealType
757 scale;
758
759 size_t
760 length;
761
762 /*
763 Clone the image.
764 */
765 assert(image != (const Image *) NULL);
766 assert(image->signature == MagickSignature);
767 if (image->debug != MagickFalse)
768 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
769 assert(exception != (ExceptionInfo *) NULL);
770 assert(exception->signature == MagickSignature);
cristy73bd4a52010-10-05 11:24:23 +0000771 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000772 if (clone_image == (Image *) NULL)
773 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
774 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
775 clone_image->signature=MagickSignature;
776 clone_image->storage_class=image->storage_class;
777 clone_image->colorspace=image->colorspace;
778 clone_image->matte=image->matte;
779 clone_image->columns=image->columns;
780 clone_image->rows=image->rows;
781 clone_image->dither=image->dither;
782 if (image->colormap != (PixelPacket *) NULL)
783 {
784 /*
785 Allocate and copy the image colormap.
786 */
787 clone_image->colors=image->colors;
788 length=(size_t) image->colors;
789 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
790 sizeof(*clone_image->colormap));
791 if (clone_image->colormap == (PixelPacket *) NULL)
792 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
793 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
794 sizeof(*clone_image->colormap));
795 }
796 (void) CloneImageProfiles(clone_image,image);
797 (void) CloneImageProperties(clone_image,image);
798 (void) CloneImageArtifacts(clone_image,image);
799 GetTimerInfo(&clone_image->timer);
800 GetExceptionInfo(&clone_image->exception);
801 InheritException(&clone_image->exception,&image->exception);
802 if (image->ascii85 != (void *) NULL)
803 Ascii85Initialize(clone_image);
804 clone_image->magick_columns=image->magick_columns;
805 clone_image->magick_rows=image->magick_rows;
806 clone_image->type=image->type;
807 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
808 MaxTextExtent);
809 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
810 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
811 clone_image->progress_monitor=image->progress_monitor;
812 clone_image->client_data=image->client_data;
813 clone_image->reference_count=1;
cristybee00932011-01-15 20:28:27 +0000814 clone_image->next=image->next;
815 clone_image->previous=image->previous;
cristy3ed852e2009-09-05 21:47:34 +0000816 clone_image->list=NewImageList();
817 clone_image->clip_mask=NewImageList();
818 clone_image->mask=NewImageList();
819 if (detach == MagickFalse)
820 clone_image->blob=ReferenceBlob(image->blob);
821 else
cristybee00932011-01-15 20:28:27 +0000822 {
823 clone_image->next=NewImageList();
824 clone_image->previous=NewImageList();
825 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
826 }
cristy73724512010-04-12 14:43:14 +0000827 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000828 clone_image->debug=IsEventLogging();
829 clone_image->semaphore=AllocateSemaphoreInfo();
830 if ((columns == 0) && (rows == 0))
831 {
832 if (image->montage != (char *) NULL)
833 (void) CloneString(&clone_image->montage,image->montage);
834 if (image->directory != (char *) NULL)
835 (void) CloneString(&clone_image->directory,image->directory);
836 if (image->clip_mask != (Image *) NULL)
837 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
838 exception);
839 if (image->mask != (Image *) NULL)
840 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
841 clone_image->cache=ReferencePixelCache(image->cache);
842 return(clone_image);
843 }
844 scale=(MagickRealType) columns/(MagickRealType) image->columns;
cristybb503372010-05-27 20:51:26 +0000845 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
846 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
847 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000848 scale=(MagickRealType) rows/(MagickRealType) image->rows;
cristybb503372010-05-27 20:51:26 +0000849 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
850 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
851 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000852 clone_image->columns=columns;
853 clone_image->rows=rows;
854 clone_image->cache=ClonePixelCache(image->cache);
855 return(clone_image);
856}
857
858/*
859%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
860% %
861% %
862% %
863% C l o n e I m a g e I n f o %
864% %
865% %
866% %
867%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
868%
869% CloneImageInfo() makes a copy of the given image info structure. If
870% NULL is specified, a new image info structure is created initialized to
871% default values.
872%
873% The format of the CloneImageInfo method is:
874%
875% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
876%
877% A description of each parameter follows:
878%
879% o image_info: the image info.
880%
881*/
882MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
883{
884 ImageInfo
885 *clone_info;
886
887 clone_info=AcquireImageInfo();
888 if (image_info == (ImageInfo *) NULL)
889 return(clone_info);
890 clone_info->compression=image_info->compression;
891 clone_info->temporary=image_info->temporary;
892 clone_info->adjoin=image_info->adjoin;
893 clone_info->antialias=image_info->antialias;
894 clone_info->scene=image_info->scene;
895 clone_info->number_scenes=image_info->number_scenes;
896 clone_info->depth=image_info->depth;
897 if (image_info->size != (char *) NULL)
898 (void) CloneString(&clone_info->size,image_info->size);
899 if (image_info->extract != (char *) NULL)
900 (void) CloneString(&clone_info->extract,image_info->extract);
901 if (image_info->scenes != (char *) NULL)
902 (void) CloneString(&clone_info->scenes,image_info->scenes);
903 if (image_info->page != (char *) NULL)
904 (void) CloneString(&clone_info->page,image_info->page);
905 clone_info->interlace=image_info->interlace;
906 clone_info->endian=image_info->endian;
907 clone_info->units=image_info->units;
908 clone_info->quality=image_info->quality;
909 if (image_info->sampling_factor != (char *) NULL)
910 (void) CloneString(&clone_info->sampling_factor,
911 image_info->sampling_factor);
912 if (image_info->server_name != (char *) NULL)
913 (void) CloneString(&clone_info->server_name,image_info->server_name);
914 if (image_info->font != (char *) NULL)
915 (void) CloneString(&clone_info->font,image_info->font);
916 if (image_info->texture != (char *) NULL)
917 (void) CloneString(&clone_info->texture,image_info->texture);
918 if (image_info->density != (char *) NULL)
919 (void) CloneString(&clone_info->density,image_info->density);
920 clone_info->pointsize=image_info->pointsize;
921 clone_info->fuzz=image_info->fuzz;
922 clone_info->pen=image_info->pen;
923 clone_info->background_color=image_info->background_color;
924 clone_info->border_color=image_info->border_color;
925 clone_info->matte_color=image_info->matte_color;
926 clone_info->transparent_color=image_info->transparent_color;
927 clone_info->dither=image_info->dither;
928 clone_info->monochrome=image_info->monochrome;
929 clone_info->colors=image_info->colors;
930 clone_info->colorspace=image_info->colorspace;
931 clone_info->type=image_info->type;
932 clone_info->orientation=image_info->orientation;
933 clone_info->preview_type=image_info->preview_type;
934 clone_info->group=image_info->group;
935 clone_info->ping=image_info->ping;
936 clone_info->verbose=image_info->verbose;
937 if (image_info->view != (char *) NULL)
938 (void) CloneString(&clone_info->view,image_info->view);
939 if (image_info->authenticate != (char *) NULL)
940 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
941 (void) CloneImageOptions(clone_info,image_info);
942 clone_info->progress_monitor=image_info->progress_monitor;
943 clone_info->client_data=image_info->client_data;
944 clone_info->cache=image_info->cache;
945 if (image_info->cache != (void *) NULL)
946 clone_info->cache=ReferencePixelCache(image_info->cache);
947 if (image_info->profile != (void *) NULL)
948 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
949 image_info->profile);
950 SetImageInfoFile(clone_info,image_info->file);
951 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
952 clone_info->stream=image_info->stream;
953 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
954 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
955 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
956 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
957 (void) CopyMagickString(clone_info->filename,image_info->filename,
958 MaxTextExtent);
959 clone_info->subimage=image_info->scene; /* deprecated */
960 clone_info->subrange=image_info->number_scenes; /* deprecated */
961 clone_info->channel=image_info->channel;
962 clone_info->debug=IsEventLogging();
963 clone_info->signature=image_info->signature;
964 return(clone_info);
965}
966
967/*
968%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
969% %
970% %
971% %
972% C o m b i n e I m a g e s %
973% %
974% %
975% %
976%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
977%
978% CombineImages() combines one or more images into a single image. The
979% grayscale value of the pixels of each image in the sequence is assigned in
980% order to the specified channels of the combined image. The typical
981% ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
982%
983% The format of the CombineImages method is:
984%
985% Image *CombineImages(const Image *image,const ChannelType channel,
986% ExceptionInfo *exception)
987%
988% A description of each parameter follows:
989%
990% o image: the image.
991%
992% o exception: return any errors or warnings in this structure.
993%
994*/
995MagickExport Image *CombineImages(const Image *image,const ChannelType channel,
996 ExceptionInfo *exception)
997{
998#define CombineImageTag "Combine/Image"
999
1000 CacheView
1001 *combine_view;
1002
1003 const Image
1004 *next;
1005
1006 Image
1007 *combine_image;
1008
cristy3ed852e2009-09-05 21:47:34 +00001009 MagickBooleanType
1010 status;
1011
cristybb503372010-05-27 20:51:26 +00001012 MagickOffsetType
1013 progress;
1014
1015 ssize_t
1016 y;
1017
cristy3ed852e2009-09-05 21:47:34 +00001018 /*
1019 Ensure the image are the same size.
1020 */
1021 assert(image != (const Image *) NULL);
1022 assert(image->signature == MagickSignature);
1023 if (image->debug != MagickFalse)
1024 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1025 assert(exception != (ExceptionInfo *) NULL);
1026 assert(exception->signature == MagickSignature);
1027 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1028 {
1029 if ((next->columns != image->columns) || (next->rows != image->rows))
1030 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1031 }
1032 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1033 if (combine_image == (Image *) NULL)
1034 return((Image *) NULL);
1035 if (SetImageStorageClass(combine_image,DirectClass) == MagickFalse)
1036 {
1037 InheritException(exception,&combine_image->exception);
1038 combine_image=DestroyImage(combine_image);
1039 return((Image *) NULL);
1040 }
1041 if ((channel & OpacityChannel) != 0)
1042 combine_image->matte=MagickTrue;
1043 (void) SetImageBackgroundColor(combine_image);
1044 /*
1045 Combine images.
1046 */
1047 status=MagickTrue;
1048 progress=0;
1049 combine_view=AcquireCacheView(combine_image);
cristybb503372010-05-27 20:51:26 +00001050 for (y=0; y < (ssize_t) combine_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001051 {
1052 CacheView
1053 *image_view;
1054
1055 const Image
1056 *next;
1057
1058 PixelPacket
1059 *pixels;
1060
1061 register const PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001062 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001063
cristy3ed852e2009-09-05 21:47:34 +00001064 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001065 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001066
cristycb6d09b2010-06-19 01:59:36 +00001067 register ssize_t
1068 x;
1069
cristy3ed852e2009-09-05 21:47:34 +00001070 if (status == MagickFalse)
1071 continue;
1072 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1073 1,exception);
1074 if (pixels == (PixelPacket *) NULL)
1075 {
1076 status=MagickFalse;
1077 continue;
1078 }
1079 next=image;
1080 if (((channel & RedChannel) != 0) && (next != (Image *) NULL))
1081 {
1082 image_view=AcquireCacheView(next);
1083 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1084 if (p == (const PixelPacket *) NULL)
1085 continue;
1086 q=pixels;
cristybb503372010-05-27 20:51:26 +00001087 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001088 {
cristyce70c172010-01-07 17:15:30 +00001089 SetRedPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001090 p++;
1091 q++;
1092 }
1093 image_view=DestroyCacheView(image_view);
1094 next=GetNextImageInList(next);
1095 }
1096 if (((channel & GreenChannel) != 0) && (next != (Image *) NULL))
1097 {
1098 image_view=AcquireCacheView(next);
1099 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1100 if (p == (const PixelPacket *) NULL)
1101 continue;
1102 q=pixels;
cristybb503372010-05-27 20:51:26 +00001103 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001104 {
cristyce70c172010-01-07 17:15:30 +00001105 SetGreenPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001106 p++;
1107 q++;
1108 }
1109 image_view=DestroyCacheView(image_view);
1110 next=GetNextImageInList(next);
1111 }
1112 if (((channel & BlueChannel) != 0) && (next != (Image *) NULL))
1113 {
1114 image_view=AcquireCacheView(next);
1115 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1116 if (p == (const PixelPacket *) NULL)
1117 continue;
1118 q=pixels;
cristybb503372010-05-27 20:51:26 +00001119 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001120 {
cristyce70c172010-01-07 17:15:30 +00001121 SetBluePixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001122 p++;
1123 q++;
1124 }
1125 image_view=DestroyCacheView(image_view);
1126 next=GetNextImageInList(next);
1127 }
1128 if (((channel & OpacityChannel) != 0) && (next != (Image *) NULL))
1129 {
1130 image_view=AcquireCacheView(next);
1131 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1132 if (p == (const PixelPacket *) NULL)
1133 continue;
1134 q=pixels;
cristybb503372010-05-27 20:51:26 +00001135 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001136 {
cristyce70c172010-01-07 17:15:30 +00001137 SetOpacityPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001138 p++;
1139 q++;
1140 }
1141 image_view=DestroyCacheView(image_view);
1142 next=GetNextImageInList(next);
1143 }
1144 if (((channel & IndexChannel) != 0) &&
1145 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1146 {
1147 IndexPacket
1148 *indexes;
1149
1150 image_view=AcquireCacheView(next);
1151 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1152 if (p == (const PixelPacket *) NULL)
1153 continue;
1154 indexes=GetCacheViewAuthenticIndexQueue(combine_view);
cristybb503372010-05-27 20:51:26 +00001155 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001156 {
1157 indexes[x]=PixelIntensityToQuantum(p);
1158 p++;
1159 }
1160 image_view=DestroyCacheView(image_view);
1161 next=GetNextImageInList(next);
1162 }
1163 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1164 status=MagickFalse;
1165 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1166 {
1167 MagickBooleanType
1168 proceed;
1169
cristy3ed852e2009-09-05 21:47:34 +00001170 proceed=SetImageProgress(image,CombineImageTag,progress++,
1171 combine_image->rows);
1172 if (proceed == MagickFalse)
1173 status=MagickFalse;
1174 }
1175 }
1176 combine_view=DestroyCacheView(combine_view);
1177 if (status == MagickFalse)
1178 combine_image=DestroyImage(combine_image);
1179 return(combine_image);
1180}
1181
1182/*
1183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1184% %
1185% %
1186% %
cristy3ed852e2009-09-05 21:47:34 +00001187% D e s t r o y I m a g e %
1188% %
1189% %
1190% %
1191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1192%
1193% DestroyImage() dereferences an image, deallocating memory associated with
1194% the image if the reference count becomes zero.
1195%
1196% The format of the DestroyImage method is:
1197%
1198% Image *DestroyImage(Image *image)
1199%
1200% A description of each parameter follows:
1201%
1202% o image: the image.
1203%
1204*/
1205MagickExport Image *DestroyImage(Image *image)
1206{
1207 MagickBooleanType
1208 destroy;
1209
1210 /*
1211 Dereference image.
1212 */
1213 assert(image != (Image *) NULL);
1214 assert(image->signature == MagickSignature);
1215 if (image->debug != MagickFalse)
1216 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1217 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001218 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001219 image->reference_count--;
1220 if (image->reference_count == 0)
1221 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001222 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001223 if (destroy == MagickFalse)
1224 return((Image *) NULL);
1225 /*
1226 Destroy image.
1227 */
1228 DestroyImagePixels(image);
1229 if (image->clip_mask != (Image *) NULL)
1230 image->clip_mask=DestroyImage(image->clip_mask);
1231 if (image->mask != (Image *) NULL)
1232 image->mask=DestroyImage(image->mask);
1233 if (image->montage != (char *) NULL)
1234 image->montage=DestroyString(image->montage);
1235 if (image->directory != (char *) NULL)
1236 image->directory=DestroyString(image->directory);
1237 if (image->colormap != (PixelPacket *) NULL)
1238 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1239 if (image->geometry != (char *) NULL)
1240 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001241 DestroyImageProfiles(image);
1242 DestroyImageProperties(image);
1243 DestroyImageArtifacts(image);
1244 if (image->ascii85 != (Ascii85Info*) NULL)
1245 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1246 DestroyBlob(image);
1247 (void) DestroyExceptionInfo(&image->exception);
1248 if (image->semaphore != (SemaphoreInfo *) NULL)
1249 DestroySemaphoreInfo(&image->semaphore);
1250 image->signature=(~MagickSignature);
1251 image=(Image *) RelinquishMagickMemory(image);
1252 return(image);
1253}
1254
1255/*
1256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1257% %
1258% %
1259% %
1260% D e s t r o y I m a g e I n f o %
1261% %
1262% %
1263% %
1264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1265%
1266% DestroyImageInfo() deallocates memory associated with an ImageInfo
1267% structure.
1268%
1269% The format of the DestroyImageInfo method is:
1270%
1271% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1272%
1273% A description of each parameter follows:
1274%
1275% o image_info: the image info.
1276%
1277*/
1278MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1279{
1280 assert(image_info != (ImageInfo *) NULL);
1281 assert(image_info->signature == MagickSignature);
1282 if (image_info->debug != MagickFalse)
1283 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1284 image_info->filename);
1285 if (image_info->size != (char *) NULL)
1286 image_info->size=DestroyString(image_info->size);
1287 if (image_info->extract != (char *) NULL)
1288 image_info->extract=DestroyString(image_info->extract);
1289 if (image_info->scenes != (char *) NULL)
1290 image_info->scenes=DestroyString(image_info->scenes);
1291 if (image_info->page != (char *) NULL)
1292 image_info->page=DestroyString(image_info->page);
1293 if (image_info->sampling_factor != (char *) NULL)
1294 image_info->sampling_factor=DestroyString(
1295 image_info->sampling_factor);
1296 if (image_info->server_name != (char *) NULL)
1297 image_info->server_name=DestroyString(
1298 image_info->server_name);
1299 if (image_info->font != (char *) NULL)
1300 image_info->font=DestroyString(image_info->font);
1301 if (image_info->texture != (char *) NULL)
1302 image_info->texture=DestroyString(image_info->texture);
1303 if (image_info->density != (char *) NULL)
1304 image_info->density=DestroyString(image_info->density);
1305 if (image_info->view != (char *) NULL)
1306 image_info->view=DestroyString(image_info->view);
1307 if (image_info->authenticate != (char *) NULL)
1308 image_info->authenticate=DestroyString(
1309 image_info->authenticate);
1310 DestroyImageOptions(image_info);
1311 if (image_info->cache != (void *) NULL)
1312 image_info->cache=DestroyPixelCache(image_info->cache);
1313 if (image_info->profile != (StringInfo *) NULL)
1314 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1315 image_info->profile);
1316 image_info->signature=(~MagickSignature);
1317 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1318 return(image_info);
1319}
1320
1321/*
1322%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1323% %
1324% %
1325% %
1326+ D i s a s s o c i a t e I m a g e S t r e a m %
1327% %
1328% %
1329% %
1330%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1331%
1332% DisassociateImageStream() disassociates the image stream.
1333%
1334% The format of the DisassociateImageStream method is:
1335%
1336% MagickBooleanType DisassociateImageStream(const Image *image)
1337%
1338% A description of each parameter follows:
1339%
1340% o image: the image.
1341%
1342*/
1343MagickExport void DisassociateImageStream(Image *image)
1344{
1345 assert(image != (const Image *) NULL);
1346 assert(image->signature == MagickSignature);
1347 if (image->debug != MagickFalse)
1348 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1349 (void) DetachBlob(image->blob);
1350}
1351
1352/*
1353%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1354% %
1355% %
1356% %
1357% G e t I m a g e A l p h a C h a n n e l %
1358% %
1359% %
1360% %
1361%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1362%
1363% GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1364% not activated. That is, the image is RGB rather than RGBA or CMYK rather
1365% than CMYKA.
1366%
1367% The format of the GetImageAlphaChannel method is:
1368%
1369% MagickBooleanType GetImageAlphaChannel(const Image *image)
1370%
1371% A description of each parameter follows:
1372%
1373% o image: the image.
1374%
1375*/
1376MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1377{
1378 assert(image != (const Image *) NULL);
1379 if (image->debug != MagickFalse)
1380 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1381 assert(image->signature == MagickSignature);
1382 return(image->matte);
1383}
1384
1385/*
1386%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1387% %
1388% %
1389% %
1390% G e t I m a g e C l i p M a s k %
1391% %
1392% %
1393% %
1394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1395%
1396% GetImageClipMask() returns the clip path associated with the image.
1397%
1398% The format of the GetImageClipMask method is:
1399%
1400% Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1401%
1402% A description of each parameter follows:
1403%
1404% o image: the image.
1405%
1406*/
1407MagickExport Image *GetImageClipMask(const Image *image,
1408 ExceptionInfo *exception)
1409{
1410 assert(image != (const Image *) NULL);
1411 if (image->debug != MagickFalse)
1412 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1413 assert(image->signature == MagickSignature);
1414 if (image->clip_mask == (Image *) NULL)
1415 return((Image *) NULL);
1416 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1417}
1418
1419/*
1420%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1421% %
1422% %
1423% %
1424% G e t I m a g e E x c e p t i o n %
1425% %
1426% %
1427% %
1428%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1429%
1430% GetImageException() traverses an image sequence and returns any
1431% error more severe than noted by the exception parameter.
1432%
1433% The format of the GetImageException method is:
1434%
1435% void GetImageException(Image *image,ExceptionInfo *exception)
1436%
1437% A description of each parameter follows:
1438%
1439% o image: Specifies a pointer to a list of one or more images.
1440%
1441% o exception: return the highest severity exception.
1442%
1443*/
1444MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1445{
1446 register Image
1447 *next;
1448
1449 assert(image != (Image *) NULL);
1450 assert(image->signature == MagickSignature);
1451 if (image->debug != MagickFalse)
1452 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1453 assert(exception != (ExceptionInfo *) NULL);
1454 assert(exception->signature == MagickSignature);
1455 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1456 {
1457 if (next->exception.severity == UndefinedException)
1458 continue;
1459 if (next->exception.severity > exception->severity)
1460 InheritException(exception,&next->exception);
1461 next->exception.severity=UndefinedException;
1462 }
1463}
1464
1465/*
1466%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1467% %
1468% %
1469% %
1470% G e t I m a g e I n f o %
1471% %
1472% %
1473% %
1474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1475%
1476% GetImageInfo() initializes image_info to default values.
1477%
1478% The format of the GetImageInfo method is:
1479%
1480% void GetImageInfo(ImageInfo *image_info)
1481%
1482% A description of each parameter follows:
1483%
1484% o image_info: the image info.
1485%
1486*/
1487MagickExport void GetImageInfo(ImageInfo *image_info)
1488{
cristyd9a29192010-10-16 16:49:53 +00001489 const char
1490 *synchronize;
1491
cristy3ed852e2009-09-05 21:47:34 +00001492 ExceptionInfo
1493 *exception;
1494
1495 /*
1496 File and image dimension members.
1497 */
1498 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1499 assert(image_info != (ImageInfo *) NULL);
1500 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1501 image_info->adjoin=MagickTrue;
1502 image_info->interlace=NoInterlace;
1503 image_info->channel=DefaultChannels;
1504 image_info->quality=UndefinedCompressionQuality;
1505 image_info->antialias=MagickTrue;
1506 image_info->dither=MagickTrue;
cristyd9a29192010-10-16 16:49:53 +00001507 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1508 if (synchronize != (const char *) NULL)
1509 image_info->synchronize=IsMagickTrue(synchronize);
cristy3ed852e2009-09-05 21:47:34 +00001510 exception=AcquireExceptionInfo();
1511 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1512 exception);
1513 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1514 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1515 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1516 exception);
1517 exception=DestroyExceptionInfo(exception);
1518 image_info->debug=IsEventLogging();
1519 image_info->signature=MagickSignature;
1520}
1521
1522/*
1523%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1524% %
1525% %
1526% %
cristy15781e52009-12-05 23:05:27 +00001527% G e t I m a g e I n f o F i l e %
1528% %
1529% %
1530% %
1531%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1532%
1533% GetImageInfoFile() returns the image info file member.
1534%
1535% The format of the GetImageInfoFile method is:
1536%
1537% FILE *GetImageInfoFile(const ImageInfo *image_info)
1538%
1539% A description of each parameter follows:
1540%
1541% o image_info: the image info.
1542%
1543*/
1544MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1545{
1546 return(image_info->file);
1547}
1548
1549/*
1550%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1551% %
1552% %
1553% %
cristy3ed852e2009-09-05 21:47:34 +00001554% G e t I m a g e M a s k %
1555% %
1556% %
1557% %
1558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1559%
1560% GetImageMask() returns the mask associated with the image.
1561%
1562% The format of the GetImageMask method is:
1563%
1564% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1565%
1566% A description of each parameter follows:
1567%
1568% o image: the image.
1569%
1570*/
1571MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1572{
1573 assert(image != (const Image *) NULL);
1574 if (image->debug != MagickFalse)
1575 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1576 assert(image->signature == MagickSignature);
1577 if (image->mask == (Image *) NULL)
1578 return((Image *) NULL);
1579 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1580}
1581
1582/*
1583%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584% %
1585% %
1586% %
1587+ G e t I m a g e R e f e r e n c e C o u n t %
1588% %
1589% %
1590% %
1591%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592%
1593% GetImageReferenceCount() returns the image reference count.
1594%
1595% The format of the GetReferenceCount method is:
1596%
cristybb503372010-05-27 20:51:26 +00001597% ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001598%
1599% A description of each parameter follows:
1600%
1601% o image: the image.
1602%
1603*/
cristybb503372010-05-27 20:51:26 +00001604MagickExport ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001605{
cristybb503372010-05-27 20:51:26 +00001606 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001607 reference_count;
1608
1609 assert(image != (Image *) NULL);
1610 assert(image->signature == MagickSignature);
1611 if (image->debug != MagickFalse)
1612 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001613 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001614 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001615 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001616 return(reference_count);
1617}
1618
1619/*
1620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1621% %
1622% %
1623% %
cristy3ed852e2009-09-05 21:47:34 +00001624% 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 %
1625% %
1626% %
1627% %
1628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1629%
1630% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1631% image. A virtual pixel is any pixel access that is outside the boundaries
1632% of the image cache.
1633%
1634% The format of the GetImageVirtualPixelMethod() method is:
1635%
1636% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1637%
1638% A description of each parameter follows:
1639%
1640% o image: the image.
1641%
1642*/
1643MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1644{
1645 assert(image != (Image *) NULL);
1646 assert(image->signature == MagickSignature);
1647 if (image->debug != MagickFalse)
1648 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1649 return(GetPixelCacheVirtualMethod(image));
1650}
1651
1652/*
1653%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1654% %
1655% %
1656% %
1657% I n t e r p r e t I m a g e F i l e n a m e %
1658% %
1659% %
1660% %
1661%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1662%
1663% InterpretImageFilename() interprets embedded characters in an image filename.
1664% The filename length is returned.
1665%
1666% The format of the InterpretImageFilename method is:
1667%
1668% size_t InterpretImageFilename(const ImageInfo *image_info,
1669% Image *image,const char *format,int value,char *filename)
1670%
1671% A description of each parameter follows.
1672%
1673% o image_info: the image info..
1674%
1675% o image: the image.
1676%
1677% o format: A filename describing the format to use to write the numeric
1678% argument. Only the first numeric format identifier is replaced.
1679%
1680% o value: Numeric value to substitute into format filename.
1681%
1682% o filename: return the formatted filename in this character buffer.
1683%
1684*/
1685MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1686 Image *image,const char *format,int value,char *filename)
1687{
1688 char
1689 *q;
1690
1691 int
1692 c;
1693
1694 MagickBooleanType
1695 canonical;
1696
1697 register const char
1698 *p;
1699
1700 canonical=MagickFalse;
1701 (void) CopyMagickString(filename,format,MaxTextExtent);
1702 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1703 {
1704 q=(char *) p+1;
1705 if (*q == '%')
1706 {
1707 p=q+1;
1708 continue;
1709 }
1710 if (*q == '0')
1711 {
cristybb503372010-05-27 20:51:26 +00001712 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001713 value;
1714
cristybb503372010-05-27 20:51:26 +00001715 value=(ssize_t) strtol(q,&q,10);
cristy3ed852e2009-09-05 21:47:34 +00001716 }
1717 switch (*q)
1718 {
1719 case 'd':
1720 case 'o':
1721 case 'x':
1722 {
1723 q++;
1724 c=(*q);
1725 *q='\0';
1726 (void) FormatMagickString(filename+(p-format),(size_t) (MaxTextExtent-
1727 (p-format)),p,value);
1728 *q=c;
1729 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1730 canonical=MagickTrue;
1731 if (*(q-1) != '%')
1732 break;
1733 p++;
1734 break;
1735 }
1736 case '[':
1737 {
1738 char
1739 pattern[MaxTextExtent];
1740
1741 const char
1742 *value;
1743
cristy3ed852e2009-09-05 21:47:34 +00001744 register char
1745 *r;
1746
cristybb503372010-05-27 20:51:26 +00001747 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001748 i;
1749
cristycb6d09b2010-06-19 01:59:36 +00001750 ssize_t
1751 depth;
1752
cristy3ed852e2009-09-05 21:47:34 +00001753 /*
1754 Image option.
1755 */
1756 if (strchr(p,']') == (char *) NULL)
1757 break;
1758 depth=1;
1759 r=q+1;
1760 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1761 {
1762 if (*r == '[')
1763 depth++;
1764 if (*r == ']')
1765 depth--;
1766 if (depth <= 0)
1767 break;
1768 pattern[i]=(*r++);
1769 }
1770 pattern[i]='\0';
1771 if (LocaleNCompare(pattern,"filename:",9) != 0)
1772 break;
1773 value=(const char *) NULL;
1774 if ((image_info != (const ImageInfo *) NULL) &&
1775 (image != (const Image *) NULL))
cristy86fe49e2010-06-25 01:18:11 +00001776 value=GetMagickProperty(image_info,image,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001777 else
1778 if (image != (Image *) NULL)
cristy86fe49e2010-06-25 01:18:11 +00001779 value=GetImageProperty(image,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001780 else
1781 if (image_info != (ImageInfo *) NULL)
cristy86fe49e2010-06-25 01:18:11 +00001782 value=GetImageOption(image_info,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001783 if (value == (const char *) NULL)
1784 break;
1785 q--;
1786 c=(*q);
1787 *q='\0';
1788 (void) CopyMagickString(filename+(p-format),value,(size_t)
1789 (MaxTextExtent-(p-format)));
1790 *q=c;
1791 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1792 canonical=MagickTrue;
1793 if (*(q-1) != '%')
1794 break;
1795 p++;
1796 break;
1797 }
1798 default:
1799 break;
1800 }
1801 }
1802 for (q=filename; *q != '\0'; q++)
1803 if ((*q == '%') && (*(q+1) == '%'))
cristy27bf23e2011-01-10 13:35:22 +00001804 {
1805 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1806 canonical=MagickTrue;
1807 }
cristy3ed852e2009-09-05 21:47:34 +00001808 if (canonical == MagickFalse)
1809 (void) CopyMagickString(filename,format,MaxTextExtent);
1810 return(strlen(filename));
1811}
1812
1813/*
1814%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1815% %
1816% %
1817% %
1818% I s H i g h D y n a m i c R a n g e I m a g e %
1819% %
1820% %
1821% %
1822%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1823%
1824% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1825% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1826% 0..65535.
1827%
1828% The format of the IsHighDynamicRangeImage method is:
1829%
1830% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1831% ExceptionInfo *exception)
1832%
1833% A description of each parameter follows:
1834%
1835% o image: the image.
1836%
1837% o exception: return any errors or warnings in this structure.
1838%
1839*/
1840MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1841 ExceptionInfo *exception)
1842{
1843#if !defined(MAGICKCORE_HDRI_SUPPORT)
1844 (void) image;
1845 (void) exception;
1846 return(MagickFalse);
1847#else
1848 CacheView
1849 *image_view;
1850
cristy3ed852e2009-09-05 21:47:34 +00001851 MagickBooleanType
1852 status;
1853
1854 MagickPixelPacket
1855 zero;
1856
cristycb6d09b2010-06-19 01:59:36 +00001857 ssize_t
1858 y;
1859
cristy3ed852e2009-09-05 21:47:34 +00001860 assert(image != (Image *) NULL);
1861 assert(image->signature == MagickSignature);
1862 if (image->debug != MagickFalse)
1863 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1864 status=MagickTrue;
1865 GetMagickPixelPacket(image,&zero);
1866 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00001867#if defined(MAGICKCORE_OPENMP_SUPPORT)
1868 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00001869#endif
cristybb503372010-05-27 20:51:26 +00001870 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001871 {
1872 MagickPixelPacket
1873 pixel;
1874
1875 register const IndexPacket
1876 *indexes;
1877
1878 register const PixelPacket
1879 *p;
1880
cristybb503372010-05-27 20:51:26 +00001881 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001882 x;
1883
1884 if (status == MagickFalse)
1885 continue;
1886 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1887 if (p == (const PixelPacket *) NULL)
1888 {
1889 status=MagickFalse;
1890 continue;
1891 }
1892 indexes=GetCacheViewVirtualIndexQueue(image_view);
1893 pixel=zero;
cristybb503372010-05-27 20:51:26 +00001894 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001895 {
1896 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1897 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1898 (pixel.red != (QuantumAny) pixel.red))
1899 break;
1900 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1901 (pixel.green != (QuantumAny) pixel.green))
1902 break;
1903 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1904 (pixel.blue != (QuantumAny) pixel.blue))
1905 break;
1906 if (pixel.matte != MagickFalse)
1907 {
1908 if ((pixel.opacity < 0.0) || (pixel.opacity > QuantumRange) ||
1909 (pixel.opacity != (QuantumAny) pixel.opacity))
1910 break;
1911 }
1912 if (pixel.colorspace == CMYKColorspace)
1913 {
1914 if ((pixel.index < 0.0) || (pixel.index > QuantumRange) ||
1915 (pixel.index != (QuantumAny) pixel.index))
1916 break;
1917 }
1918 p++;
1919 }
cristybb503372010-05-27 20:51:26 +00001920 if (x < (ssize_t) image->columns)
cristy3ed852e2009-09-05 21:47:34 +00001921 status=MagickFalse;
1922 }
1923 image_view=DestroyCacheView(image_view);
1924 return(status != MagickFalse ? MagickFalse : MagickTrue);
1925#endif
1926}
1927
1928/*
1929%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1930% %
1931% %
1932% %
1933% I s I m a g e O b j e c t %
1934% %
1935% %
1936% %
1937%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1938%
1939% IsImageObject() returns MagickTrue if the image sequence contains a valid
1940% set of image objects.
1941%
1942% The format of the IsImageObject method is:
1943%
1944% MagickBooleanType IsImageObject(const Image *image)
1945%
1946% A description of each parameter follows:
1947%
1948% o image: the image.
1949%
1950*/
1951MagickExport MagickBooleanType IsImageObject(const Image *image)
1952{
1953 register const Image
1954 *p;
1955
1956 assert(image != (Image *) NULL);
1957 if (image->debug != MagickFalse)
1958 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1959 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1960 if (p->signature != MagickSignature)
1961 return(MagickFalse);
1962 return(MagickTrue);
1963}
1964
1965/*
1966%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1967% %
1968% %
1969% %
1970% I s T a i n t I m a g e %
1971% %
1972% %
1973% %
1974%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1975%
1976% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1977% since it was first constituted.
1978%
1979% The format of the IsTaintImage method is:
1980%
1981% MagickBooleanType IsTaintImage(const Image *image)
1982%
1983% A description of each parameter follows:
1984%
1985% o image: the image.
1986%
1987*/
1988MagickExport MagickBooleanType IsTaintImage(const Image *image)
1989{
1990 char
1991 magick[MaxTextExtent],
1992 filename[MaxTextExtent];
1993
1994 register const Image
1995 *p;
1996
1997 assert(image != (Image *) NULL);
1998 if (image->debug != MagickFalse)
1999 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2000 assert(image->signature == MagickSignature);
2001 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2002 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2003 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2004 {
2005 if (p->taint != MagickFalse)
2006 return(MagickTrue);
2007 if (LocaleCompare(p->magick,magick) != 0)
2008 return(MagickTrue);
2009 if (LocaleCompare(p->filename,filename) != 0)
2010 return(MagickTrue);
2011 }
2012 return(MagickFalse);
2013}
2014
2015/*
2016%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2017% %
2018% %
2019% %
2020% M o d i f y I m a g e %
2021% %
2022% %
2023% %
2024%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2025%
2026% ModifyImage() ensures that there is only a single reference to the image
2027% to be modified, updating the provided image pointer to point to a clone of
2028% the original image if necessary.
2029%
2030% The format of the ModifyImage method is:
2031%
2032% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2033%
2034% A description of each parameter follows:
2035%
2036% o image: the image.
2037%
2038% o exception: return any errors or warnings in this structure.
2039%
2040*/
2041MagickExport MagickBooleanType ModifyImage(Image **image,
2042 ExceptionInfo *exception)
2043{
2044 Image
2045 *clone_image;
2046
2047 assert(image != (Image **) NULL);
2048 assert(*image != (Image *) NULL);
2049 assert((*image)->signature == MagickSignature);
2050 if ((*image)->debug != MagickFalse)
2051 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2052 if (GetImageReferenceCount(*image) <= 1)
2053 return(MagickTrue);
2054 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
cristyf84a1932010-01-03 18:00:18 +00002055 LockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002056 (*image)->reference_count--;
cristyf84a1932010-01-03 18:00:18 +00002057 UnlockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002058 *image=clone_image;
2059 return(MagickTrue);
2060}
2061
2062/*
2063%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2064% %
2065% %
2066% %
2067% N e w M a g i c k I m a g e %
2068% %
2069% %
2070% %
2071%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2072%
2073% NewMagickImage() creates a blank image canvas of the specified size and
2074% background color.
2075%
2076% The format of the NewMagickImage method is:
2077%
2078% Image *NewMagickImage(const ImageInfo *image_info,
cristybb503372010-05-27 20:51:26 +00002079% const size_t width,const size_t height,
cristy3ed852e2009-09-05 21:47:34 +00002080% const MagickPixelPacket *background)
2081%
2082% A description of each parameter follows:
2083%
2084% o image: the image.
2085%
2086% o width: the image width.
2087%
2088% o height: the image height.
2089%
2090% o background: the image color.
2091%
2092*/
2093MagickExport Image *NewMagickImage(const ImageInfo *image_info,
cristybb503372010-05-27 20:51:26 +00002094 const size_t width,const size_t height,
cristy3ed852e2009-09-05 21:47:34 +00002095 const MagickPixelPacket *background)
2096{
2097 CacheView
2098 *image_view;
2099
2100 ExceptionInfo
2101 *exception;
2102
2103 Image
2104 *image;
2105
cristybb503372010-05-27 20:51:26 +00002106 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002107 y;
2108
2109 MagickBooleanType
2110 status;
2111
2112 assert(image_info != (const ImageInfo *) NULL);
2113 if (image_info->debug != MagickFalse)
2114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2115 assert(image_info->signature == MagickSignature);
2116 assert(background != (const MagickPixelPacket *) NULL);
2117 image=AcquireImage(image_info);
2118 image->columns=width;
2119 image->rows=height;
2120 image->colorspace=background->colorspace;
2121 image->matte=background->matte;
2122 image->fuzz=background->fuzz;
2123 image->depth=background->depth;
2124 status=MagickTrue;
2125 exception=(&image->exception);
2126 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00002127#if defined(MAGICKCORE_OPENMP_SUPPORT)
2128 #pragma omp parallel for schedule(dynamic,4) shared(status)
2129#endif
cristybb503372010-05-27 20:51:26 +00002130 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002131 {
2132 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002133 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002134
cristy3ed852e2009-09-05 21:47:34 +00002135 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002136 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002137
cristycb6d09b2010-06-19 01:59:36 +00002138 register ssize_t
2139 x;
2140
cristy48974b92009-12-19 02:36:06 +00002141 if (status == MagickFalse)
2142 continue;
cristy3ed852e2009-09-05 21:47:34 +00002143 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2144 if (q == (PixelPacket *) NULL)
2145 {
2146 status=MagickFalse;
2147 continue;
2148 }
2149 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002150 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002151 {
2152 SetPixelPacket(image,background,q,indexes+x);
2153 q++;
2154 }
2155 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2156 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002157 }
2158 image_view=DestroyCacheView(image_view);
2159 if (status == MagickFalse)
2160 image=DestroyImage(image);
2161 return(image);
2162}
2163
2164/*
2165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2166% %
2167% %
2168% %
2169% R e f e r e n c e I m a g e %
2170% %
2171% %
2172% %
2173%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2174%
2175% ReferenceImage() increments the reference count associated with an image
2176% returning a pointer to the image.
2177%
2178% The format of the ReferenceImage method is:
2179%
2180% Image *ReferenceImage(Image *image)
2181%
2182% A description of each parameter follows:
2183%
2184% o image: the image.
2185%
2186*/
2187MagickExport Image *ReferenceImage(Image *image)
2188{
2189 assert(image != (Image *) NULL);
2190 if (image->debug != MagickFalse)
2191 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2192 assert(image->signature == MagickSignature);
cristyf84a1932010-01-03 18:00:18 +00002193 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002194 image->reference_count++;
cristyf84a1932010-01-03 18:00:18 +00002195 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002196 return(image);
2197}
2198
2199/*
2200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2201% %
2202% %
2203% %
2204% R e s e t I m a g e P a g e %
2205% %
2206% %
2207% %
2208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2209%
2210% ResetImagePage() resets the image page canvas and position.
2211%
2212% The format of the ResetImagePage method is:
2213%
2214% MagickBooleanType ResetImagePage(Image *image,const char *page)
2215%
2216% A description of each parameter follows:
2217%
2218% o image: the image.
2219%
2220% o page: the relative page specification.
2221%
2222*/
2223MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2224{
2225 MagickStatusType
2226 flags;
2227
2228 RectangleInfo
2229 geometry;
2230
2231 assert(image != (Image *) NULL);
2232 assert(image->signature == MagickSignature);
2233 if (image->debug != MagickFalse)
2234 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2235 flags=ParseAbsoluteGeometry(page,&geometry);
2236 if ((flags & WidthValue) != 0)
2237 {
2238 if ((flags & HeightValue) == 0)
2239 geometry.height=geometry.width;
2240 image->page.width=geometry.width;
2241 image->page.height=geometry.height;
2242 }
2243 if ((flags & AspectValue) != 0)
2244 {
2245 if ((flags & XValue) != 0)
2246 image->page.x+=geometry.x;
2247 if ((flags & YValue) != 0)
2248 image->page.y+=geometry.y;
2249 }
2250 else
2251 {
2252 if ((flags & XValue) != 0)
2253 {
2254 image->page.x=geometry.x;
2255 if ((image->page.width == 0) && (geometry.x > 0))
2256 image->page.width=image->columns+geometry.x;
2257 }
2258 if ((flags & YValue) != 0)
2259 {
2260 image->page.y=geometry.y;
2261 if ((image->page.height == 0) && (geometry.y > 0))
2262 image->page.height=image->rows+geometry.y;
2263 }
2264 }
2265 return(MagickTrue);
2266}
2267
2268/*
2269%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2270% %
2271% %
2272% %
2273% S e p a r a t e I m a g e C h a n n e l %
2274% %
2275% %
2276% %
2277%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2278%
2279% SeparateImageChannel() separates a channel from the image and returns it as
2280% a grayscale image. A channel is a particular color component of each pixel
2281% in the image.
2282%
2283% The format of the SeparateImageChannel method is:
2284%
2285% MagickBooleanType SeparateImageChannel(Image *image,
2286% const ChannelType channel)
2287%
2288% A description of each parameter follows:
2289%
2290% o image: the image.
2291%
2292% o channel: Identify which channel to extract: RedChannel, GreenChannel,
2293% BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2294% YellowChannel, or BlackChannel.
2295%
2296*/
2297MagickExport MagickBooleanType SeparateImageChannel(Image *image,
2298 const ChannelType channel)
2299{
2300#define SeparateImageTag "Separate/Image"
2301
2302 CacheView
2303 *image_view;
2304
2305 ExceptionInfo
2306 *exception;
2307
cristy3ed852e2009-09-05 21:47:34 +00002308 MagickBooleanType
2309 status;
2310
cristybb503372010-05-27 20:51:26 +00002311 MagickOffsetType
2312 progress;
2313
2314 ssize_t
2315 y;
2316
cristy3ed852e2009-09-05 21:47:34 +00002317 assert(image != (Image *) NULL);
2318 assert(image->signature == MagickSignature);
2319 if (image->debug != MagickFalse)
2320 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2321 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2322 return(MagickFalse);
2323 /*
2324 Separate image channels.
2325 */
2326 status=MagickTrue;
cristy11b66ce2010-03-11 13:34:19 +00002327 if (channel == GrayChannels)
cristy3ed852e2009-09-05 21:47:34 +00002328 image->matte=MagickTrue;
2329 progress=0;
2330 exception=(&image->exception);
2331 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002332#if defined(MAGICKCORE_OPENMP_SUPPORT)
2333 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00002334#endif
cristybb503372010-05-27 20:51:26 +00002335 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002336 {
2337 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002338 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002339
cristy3ed852e2009-09-05 21:47:34 +00002340 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002341 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002342
cristycb6d09b2010-06-19 01:59:36 +00002343 register ssize_t
2344 x;
2345
cristy3ed852e2009-09-05 21:47:34 +00002346 if (status == MagickFalse)
2347 continue;
2348 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2349 if (q == (PixelPacket *) NULL)
2350 {
2351 status=MagickFalse;
2352 continue;
2353 }
2354 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2355 switch (channel)
2356 {
2357 case RedChannel:
2358 {
cristybb503372010-05-27 20:51:26 +00002359 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002360 {
2361 q->green=q->red;
2362 q->blue=q->red;
2363 q++;
2364 }
2365 break;
2366 }
2367 case GreenChannel:
2368 {
cristybb503372010-05-27 20:51:26 +00002369 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002370 {
2371 q->red=q->green;
2372 q->blue=q->green;
2373 q++;
2374 }
2375 break;
2376 }
2377 case BlueChannel:
2378 {
cristybb503372010-05-27 20:51:26 +00002379 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002380 {
2381 q->red=q->blue;
2382 q->green=q->blue;
2383 q++;
2384 }
2385 break;
2386 }
2387 case OpacityChannel:
2388 {
cristybb503372010-05-27 20:51:26 +00002389 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002390 {
2391 q->red=q->opacity;
2392 q->green=q->opacity;
2393 q->blue=q->opacity;
2394 q++;
2395 }
2396 break;
2397 }
2398 case BlackChannel:
2399 {
2400 if ((image->storage_class != PseudoClass) &&
2401 (image->colorspace != CMYKColorspace))
2402 break;
cristybb503372010-05-27 20:51:26 +00002403 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002404 {
2405 q->red=indexes[x];
2406 q->green=indexes[x];
2407 q->blue=indexes[x];
2408 q++;
2409 }
2410 break;
2411 }
2412 case TrueAlphaChannel:
2413 {
cristybb503372010-05-27 20:51:26 +00002414 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002415 {
cristy46f08202010-01-10 04:04:21 +00002416 q->red=(Quantum) GetAlphaPixelComponent(q);
2417 q->green=(Quantum) GetAlphaPixelComponent(q);
2418 q->blue=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +00002419 q++;
2420 }
2421 break;
2422 }
2423 case GrayChannels:
2424 {
cristybb503372010-05-27 20:51:26 +00002425 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002426 {
2427 q->opacity=(Quantum) (QuantumRange-PixelIntensityToQuantum(q));
2428 q++;
2429 }
2430 break;
2431 }
2432 default:
2433 break;
2434 }
2435 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2436 status=MagickFalse;
2437 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2438 {
2439 MagickBooleanType
2440 proceed;
2441
cristyb5d5f722009-11-04 03:03:49 +00002442#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00002443 #pragma omp critical (MagickCore_SeparateImageChannel)
2444#endif
2445 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2446 if (proceed == MagickFalse)
2447 status=MagickFalse;
2448 }
2449 }
2450 image_view=DestroyCacheView(image_view);
cristy11b66ce2010-03-11 13:34:19 +00002451 if (channel != GrayChannels)
cristy3ed852e2009-09-05 21:47:34 +00002452 image->matte=MagickFalse;
2453 (void) SetImageColorspace(image,RGBColorspace);
2454 return(status);
2455}
2456
2457/*
2458%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2459% %
2460% %
2461% %
2462% S e p a r a t e I m a g e s %
2463% %
2464% %
2465% %
2466%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2467%
2468% SeparateImages() returns a separate grayscale image for each channel
2469% specified.
2470%
2471% The format of the SeparateImages method is:
2472%
2473% MagickBooleanType SeparateImages(const Image *image,
2474% const ChannelType channel,ExceptionInfo *exception)
2475%
2476% A description of each parameter follows:
2477%
2478% o image: the image.
2479%
2480% o channel: Identify which channels to extract: RedChannel, GreenChannel,
2481% BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2482% YellowChannel, or BlackChannel.
2483%
2484% o exception: return any errors or warnings in this structure.
2485%
2486*/
2487MagickExport Image *SeparateImages(const Image *image,const ChannelType channel,
2488 ExceptionInfo *exception)
2489{
2490 Image
2491 *images,
2492 *separate_image;
2493
2494 assert(image != (Image *) NULL);
2495 assert(image->signature == MagickSignature);
2496 if (image->debug != MagickFalse)
2497 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2498 images=NewImageList();
2499 if ((channel & RedChannel) != 0)
2500 {
2501 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2502 (void) SeparateImageChannel(separate_image,RedChannel);
2503 AppendImageToList(&images,separate_image);
2504 }
2505 if ((channel & GreenChannel) != 0)
2506 {
2507 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2508 (void) SeparateImageChannel(separate_image,GreenChannel);
2509 AppendImageToList(&images,separate_image);
2510 }
2511 if ((channel & BlueChannel) != 0)
2512 {
2513 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2514 (void) SeparateImageChannel(separate_image,BlueChannel);
2515 AppendImageToList(&images,separate_image);
2516 }
2517 if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace))
2518 {
2519 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2520 (void) SeparateImageChannel(separate_image,BlackChannel);
2521 AppendImageToList(&images,separate_image);
2522 }
2523 if ((channel & OpacityChannel) != 0)
2524 {
2525 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2526 (void) SeparateImageChannel(separate_image,OpacityChannel);
2527 AppendImageToList(&images,separate_image);
2528 }
2529 return(images);
2530}
2531
2532/*
2533%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2534% %
2535% %
2536% %
2537% S e t I m a g e A l p h a C h a n n e l %
2538% %
2539% %
2540% %
2541%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2542%
2543% SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2544% channel.
2545%
2546% The format of the SetImageAlphaChannel method is:
2547%
2548% MagickBooleanType SetImageAlphaChannel(Image *image,
2549% const AlphaChannelType alpha_type)
2550%
2551% A description of each parameter follows:
2552%
2553% o image: the image.
2554%
2555% o alpha_type: The alpha channel type: ActivateAlphaChannel,
2556% CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2557% OpaqueAlphaChannel, ResetAlphaChannel, SetAlphaChannel,
2558% ShapeAlphaChannel, and TransparentAlphaChannel.
2559%
2560*/
2561MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2562 const AlphaChannelType alpha_type)
2563{
2564 MagickBooleanType
2565 status;
2566
2567 assert(image != (Image *) NULL);
2568 if (image->debug != MagickFalse)
2569 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2570 assert(image->signature == MagickSignature);
2571 status=MagickFalse;
2572 switch (alpha_type)
2573 {
2574 case ActivateAlphaChannel:
2575 {
2576 image->matte=MagickTrue;
2577 break;
2578 }
2579 case BackgroundAlphaChannel:
2580 {
2581 CacheView
2582 *image_view;
2583
2584 ExceptionInfo
2585 *exception;
2586
2587 IndexPacket
2588 index;
2589
cristy3ed852e2009-09-05 21:47:34 +00002590 MagickBooleanType
2591 status;
2592
2593 MagickPixelPacket
2594 background;
2595
2596 PixelPacket
2597 pixel;
2598
cristycb6d09b2010-06-19 01:59:36 +00002599 ssize_t
2600 y;
2601
cristy3ed852e2009-09-05 21:47:34 +00002602 /*
2603 Set transparent pixels to background color.
2604 */
2605 if (image->matte == MagickFalse)
2606 break;
2607 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2608 break;
2609 GetMagickPixelPacket(image,&background);
2610 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2611 NULL,&background);
2612 if (image->colorspace == CMYKColorspace)
2613 ConvertRGBToCMYK(&background);
2614 index=0;
2615 SetPixelPacket(image,&background,&pixel,&index);
2616 status=MagickTrue;
2617 exception=(&image->exception);
2618 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002619 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2620 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00002621 #endif
cristybb503372010-05-27 20:51:26 +00002622 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002623 {
2624 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002625 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002626
cristy3ed852e2009-09-05 21:47:34 +00002627 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002628 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002629
cristycb6d09b2010-06-19 01:59:36 +00002630 register ssize_t
2631 x;
2632
cristy3ed852e2009-09-05 21:47:34 +00002633 if (status == MagickFalse)
2634 continue;
2635 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2636 exception);
2637 if (q == (PixelPacket *) NULL)
2638 {
2639 status=MagickFalse;
2640 continue;
2641 }
cristybb503372010-05-27 20:51:26 +00002642 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002643 {
2644 if (q->opacity == TransparentOpacity)
2645 {
2646 q->red=pixel.red;
2647 q->green=pixel.green;
2648 q->blue=pixel.blue;
2649 }
2650 q++;
2651 }
2652 if (image->colorspace == CMYKColorspace)
2653 {
2654 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002655 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002656 indexes[x]=index;
2657 }
2658 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2659 status=MagickFalse;
2660 }
2661 image_view=DestroyCacheView(image_view);
2662 return(status);
2663 }
2664 case DeactivateAlphaChannel:
2665 {
2666 image->matte=MagickFalse;
2667 break;
2668 }
2669 case ShapeAlphaChannel:
2670 case CopyAlphaChannel:
2671 {
2672 /*
2673 Special usage case for SeparateImageChannel(): copy grayscale color to
2674 the alpha channel.
2675 */
2676 status=SeparateImageChannel(image,GrayChannels);
2677 image->matte=MagickTrue; /* make sure transparency is now on! */
2678 if (alpha_type == ShapeAlphaChannel)
2679 {
2680 MagickPixelPacket
2681 background;
2682
2683 /*
2684 Reset all color channels to background color.
2685 */
2686 GetMagickPixelPacket(image,&background);
2687 SetMagickPixelPacket(image,&(image->background_color),(IndexPacket *)
2688 NULL,&background);
cristy308b4e62009-09-21 14:40:44 +00002689 (void) LevelColorsImage(image,&background,&background,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00002690 }
2691 break;
2692 }
2693 case ExtractAlphaChannel:
2694 {
2695 status=SeparateImageChannel(image,TrueAlphaChannel);
2696 image->matte=MagickFalse;
2697 break;
2698 }
cristyf64d18b2010-04-30 12:47:03 +00002699 case ResetAlphaChannel: /* deprecated */
cristy3ed852e2009-09-05 21:47:34 +00002700 case OpaqueAlphaChannel:
2701 {
2702 status=SetImageOpacity(image,OpaqueOpacity);
2703 image->matte=MagickTrue;
2704 break;
2705 }
2706 case TransparentAlphaChannel:
2707 {
2708 status=SetImageOpacity(image,TransparentOpacity);
2709 image->matte=MagickTrue;
2710 break;
2711 }
2712 case SetAlphaChannel:
2713 {
2714 if (image->matte == MagickFalse)
2715 {
2716 status=SetImageOpacity(image,OpaqueOpacity);
2717 image->matte=MagickTrue;
2718 }
2719 break;
2720 }
2721 case UndefinedAlphaChannel:
2722 break;
2723 }
2724 return(status);
2725}
2726
2727/*
2728%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2729% %
2730% %
2731% %
2732% S e t I m a g e B a c k g r o u n d C o l o r %
2733% %
2734% %
2735% %
2736%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2737%
2738% SetImageBackgroundColor() initializes the image pixels to the image
2739% background color. The background color is defined by the background_color
2740% member of the image structure.
2741%
2742% The format of the SetImage method is:
2743%
2744% MagickBooleanType SetImageBackgroundColor(Image *image)
2745%
2746% A description of each parameter follows:
2747%
2748% o image: the image.
2749%
2750*/
2751MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2752{
2753 CacheView
2754 *image_view;
2755
2756 ExceptionInfo
2757 *exception;
2758
2759 IndexPacket
2760 index;
2761
cristy3ed852e2009-09-05 21:47:34 +00002762 MagickBooleanType
2763 status;
2764
2765 MagickPixelPacket
2766 background;
2767
2768 PixelPacket
2769 pixel;
2770
cristycb6d09b2010-06-19 01:59:36 +00002771 ssize_t
2772 y;
2773
cristy3ed852e2009-09-05 21:47:34 +00002774 assert(image != (Image *) NULL);
2775 if (image->debug != MagickFalse)
2776 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2777 assert(image->signature == MagickSignature);
2778 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2779 return(MagickFalse);
2780 if (image->background_color.opacity != OpaqueOpacity)
2781 image->matte=MagickTrue;
2782 GetMagickPixelPacket(image,&background);
2783 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2784 NULL,&background);
2785 if (image->colorspace == CMYKColorspace)
2786 ConvertRGBToCMYK(&background);
2787 index=0;
2788 SetPixelPacket(image,&background,&pixel,&index);
2789 /*
2790 Set image background color.
2791 */
2792 status=MagickTrue;
2793 exception=(&image->exception);
2794 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002795#if defined(MAGICKCORE_OPENMP_SUPPORT)
2796 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00002797#endif
cristybb503372010-05-27 20:51:26 +00002798 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002799 {
2800 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002801 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002802
cristy3ed852e2009-09-05 21:47:34 +00002803 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002804 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002805
cristycb6d09b2010-06-19 01:59:36 +00002806 register ssize_t
2807 x;
2808
cristy3ed852e2009-09-05 21:47:34 +00002809 if (status == MagickFalse)
2810 continue;
2811 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2812 if (q == (PixelPacket *) NULL)
2813 {
2814 status=MagickFalse;
2815 continue;
2816 }
cristybb503372010-05-27 20:51:26 +00002817 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002818 *q++=pixel;
2819 if (image->colorspace == CMYKColorspace)
2820 {
2821 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002822 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002823 indexes[x]=index;
2824 }
2825 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2826 status=MagickFalse;
2827 }
2828 image_view=DestroyCacheView(image_view);
2829 return(status);
2830}
2831
2832/*
2833%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2834% %
2835% %
2836% %
cristya5b77cb2010-05-07 19:34:48 +00002837% S e t I m a g e C o l o r %
2838% %
2839% %
2840% %
2841%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2842%
2843% SetImageColor() set the entire image canvas to the specified color.
2844%
2845% The format of the SetImageColor method is:
2846%
2847% MagickBooleanType SetImageColor(Image *image,
2848% const MagickPixelPacket *color)
2849%
2850% A description of each parameter follows:
2851%
2852% o image: the image.
2853%
2854% o background: the image color.
2855%
2856*/
2857MagickExport MagickBooleanType SetImageColor(Image *image,
2858 const MagickPixelPacket *color)
2859{
2860 CacheView
2861 *image_view;
2862
2863 ExceptionInfo
2864 *exception;
2865
cristya5b77cb2010-05-07 19:34:48 +00002866 MagickBooleanType
2867 status;
2868
cristycb6d09b2010-06-19 01:59:36 +00002869 ssize_t
2870 y;
2871
cristya5b77cb2010-05-07 19:34:48 +00002872 assert(image != (Image *) NULL);
2873 if (image->debug != MagickFalse)
2874 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2875 assert(image->signature == MagickSignature);
2876 assert(color != (const MagickPixelPacket *) NULL);
2877 image->colorspace=color->colorspace;
2878 image->matte=color->matte;
2879 image->fuzz=color->fuzz;
2880 image->depth=color->depth;
2881 status=MagickTrue;
2882 exception=(&image->exception);
2883 image_view=AcquireCacheView(image);
2884#if defined(MAGICKCORE_OPENMP_SUPPORT)
2885 #pragma omp parallel for schedule(dynamic,4) shared(status)
2886#endif
cristybb503372010-05-27 20:51:26 +00002887 for (y=0; y < (ssize_t) image->rows; y++)
cristya5b77cb2010-05-07 19:34:48 +00002888 {
2889 register IndexPacket
2890 *restrict indexes;
2891
cristya5b77cb2010-05-07 19:34:48 +00002892 register PixelPacket
2893 *restrict q;
2894
cristycb6d09b2010-06-19 01:59:36 +00002895 register ssize_t
2896 x;
2897
cristya5b77cb2010-05-07 19:34:48 +00002898 if (status == MagickFalse)
2899 continue;
2900 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2901 if (q == (PixelPacket *) NULL)
2902 {
2903 status=MagickFalse;
2904 continue;
2905 }
2906 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002907 for (x=0; x < (ssize_t) image->columns; x++)
cristya5b77cb2010-05-07 19:34:48 +00002908 {
2909 SetPixelPacket(image,color,q,indexes+x);
2910 q++;
2911 }
2912 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2913 status=MagickFalse;
2914 }
2915 image_view=DestroyCacheView(image_view);
2916 return(status);
2917}
2918
2919/*
2920%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2921% %
2922% %
2923% %
cristy3ed852e2009-09-05 21:47:34 +00002924% S e t I m a g e S t o r a g e C l a s s %
2925% %
2926% %
2927% %
2928%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2929%
2930% SetImageStorageClass() sets the image class: DirectClass for true color
2931% images or PseudoClass for colormapped images.
2932%
2933% The format of the SetImageStorageClass method is:
2934%
2935% MagickBooleanType SetImageStorageClass(Image *image,
2936% const ClassType storage_class)
2937%
2938% A description of each parameter follows:
2939%
2940% o image: the image.
2941%
2942% o storage_class: The image class.
2943%
2944*/
2945MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2946 const ClassType storage_class)
2947{
cristy3ed852e2009-09-05 21:47:34 +00002948 image->storage_class=storage_class;
cristy537e2722010-09-21 15:30:59 +00002949 return(MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00002950}
2951
2952/*
2953%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2954% %
2955% %
2956% %
2957% S e t I m a g e C l i p M a s k %
2958% %
2959% %
2960% %
2961%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2962%
2963% SetImageClipMask() associates a clip path with the image. The clip path
2964% must be the same dimensions as the image. Set any pixel component of
2965% the clip path to TransparentOpacity to prevent that corresponding image
2966% pixel component from being updated when SyncAuthenticPixels() is applied.
2967%
2968% The format of the SetImageClipMask method is:
2969%
2970% MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2971%
2972% A description of each parameter follows:
2973%
2974% o image: the image.
2975%
2976% o clip_mask: the image clip path.
2977%
2978*/
2979MagickExport MagickBooleanType SetImageClipMask(Image *image,
2980 const Image *clip_mask)
2981{
2982 assert(image != (Image *) NULL);
2983 if (image->debug != MagickFalse)
2984 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2985 assert(image->signature == MagickSignature);
2986 if (clip_mask != (const Image *) NULL)
2987 if ((clip_mask->columns != image->columns) ||
2988 (clip_mask->rows != image->rows))
2989 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2990 if (image->clip_mask != (Image *) NULL)
2991 image->clip_mask=DestroyImage(image->clip_mask);
2992 image->clip_mask=NewImageList();
2993 if (clip_mask == (Image *) NULL)
2994 return(MagickTrue);
2995 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2996 return(MagickFalse);
2997 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
2998 if (image->clip_mask == (Image *) NULL)
2999 return(MagickFalse);
3000 return(MagickTrue);
3001}
3002
3003/*
3004%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3005% %
3006% %
3007% %
3008% S e t I m a g e E x t e n t %
3009% %
3010% %
3011% %
3012%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3013%
3014% SetImageExtent() sets the image size (i.e. columns & rows).
3015%
3016% The format of the SetImageExtent method is:
3017%
3018% MagickBooleanType SetImageExtent(Image *image,
cristybb503372010-05-27 20:51:26 +00003019% const size_t columns,const size_t rows)
cristy3ed852e2009-09-05 21:47:34 +00003020%
3021% A description of each parameter follows:
3022%
3023% o image: the image.
3024%
3025% o columns: The image width in pixels.
3026%
3027% o rows: The image height in pixels.
3028%
3029*/
3030MagickExport MagickBooleanType SetImageExtent(Image *image,
cristybb503372010-05-27 20:51:26 +00003031 const size_t columns,const size_t rows)
cristy3ed852e2009-09-05 21:47:34 +00003032{
cristy537e2722010-09-21 15:30:59 +00003033 if ((columns == 0) || (rows == 0))
3034 return(MagickFalse);
3035 image->columns=columns;
3036 image->rows=rows;
3037 return(MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003038}
3039
3040/*
3041%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3042% %
3043% %
3044% %
3045+ S e t I m a g e I n f o %
3046% %
3047% %
3048% %
3049%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3050%
3051% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
3052% It is set to a type of image format based on the prefix or suffix of the
3053% filename. For example, `ps:image' returns PS indicating a Postscript image.
3054% JPEG is returned for this filename: `image.jpg'. The filename prefix has
3055% precendence over the suffix. Use an optional index enclosed in brackets
3056% after a file name to specify a desired scene of a multi-resolution image
3057% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
3058% indicates success.
3059%
3060% The format of the SetImageInfo method is:
3061%
3062% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00003063% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003064%
3065% A description of each parameter follows:
3066%
cristyd965a422010-03-03 17:47:35 +00003067% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00003068%
cristyd965a422010-03-03 17:47:35 +00003069% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00003070%
3071% o exception: return any errors or warnings in this structure.
3072%
3073*/
3074MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00003075 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003076{
3077 char
3078 extension[MaxTextExtent],
3079 filename[MaxTextExtent],
3080 magic[MaxTextExtent],
3081 *q,
3082 subimage[MaxTextExtent];
3083
3084 const MagicInfo
3085 *magic_info;
3086
3087 const MagickInfo
3088 *magick_info;
3089
3090 ExceptionInfo
3091 *sans_exception;
3092
3093 Image
3094 *image;
3095
3096 MagickBooleanType
3097 status;
3098
3099 register const char
3100 *p;
3101
3102 ssize_t
3103 count;
3104
3105 unsigned char
3106 magick[2*MaxTextExtent];
3107
3108 /*
3109 Look for 'image.format' in filename.
3110 */
3111 assert(image_info != (ImageInfo *) NULL);
3112 assert(image_info->signature == MagickSignature);
3113 if (image_info->debug != MagickFalse)
3114 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3115 image_info->filename);
3116 *subimage='\0';
cristyd965a422010-03-03 17:47:35 +00003117 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003118 {
cristyd965a422010-03-03 17:47:35 +00003119 GetPathComponent(image_info->filename,SubimagePath,subimage);
3120 if (*subimage != '\0')
cristy3ed852e2009-09-05 21:47:34 +00003121 {
cristyd965a422010-03-03 17:47:35 +00003122 /*
3123 Look for scene specification (e.g. img0001.pcd[4]).
3124 */
3125 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3126 {
3127 if (IsGeometry(subimage) != MagickFalse)
3128 (void) CloneString(&image_info->extract,subimage);
3129 }
3130 else
3131 {
cristybb503372010-05-27 20:51:26 +00003132 size_t
cristyd965a422010-03-03 17:47:35 +00003133 first,
3134 last;
cristy3ed852e2009-09-05 21:47:34 +00003135
cristyd965a422010-03-03 17:47:35 +00003136 (void) CloneString(&image_info->scenes,subimage);
3137 image_info->scene=StringToUnsignedLong(image_info->scenes);
3138 image_info->number_scenes=image_info->scene;
3139 p=image_info->scenes;
3140 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3141 {
3142 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3143 (*p == ','))
3144 p++;
cristybb503372010-05-27 20:51:26 +00003145 first=(size_t) strtol(p,&q,10);
cristyd965a422010-03-03 17:47:35 +00003146 last=first;
3147 while (isspace((int) ((unsigned char) *q)) != 0)
3148 q++;
3149 if (*q == '-')
cristybb503372010-05-27 20:51:26 +00003150 last=(size_t) strtol(q+1,&q,10);
cristyd965a422010-03-03 17:47:35 +00003151 if (first > last)
3152 Swap(first,last);
3153 if (first < image_info->scene)
3154 image_info->scene=first;
3155 if (last > image_info->number_scenes)
3156 image_info->number_scenes=last;
3157 p=q;
3158 }
3159 image_info->number_scenes-=image_info->scene-1;
3160 image_info->subimage=image_info->scene;
3161 image_info->subrange=image_info->number_scenes;
3162 }
cristy3ed852e2009-09-05 21:47:34 +00003163 }
3164 }
3165 *extension='\0';
3166 GetPathComponent(image_info->filename,ExtensionPath,extension);
3167#if defined(MAGICKCORE_ZLIB_DELEGATE)
3168 if (*extension != '\0')
3169 if ((LocaleCompare(extension,"gz") == 0) ||
3170 (LocaleCompare(extension,"Z") == 0) ||
3171 (LocaleCompare(extension,"wmz") == 0))
3172 {
3173 char
3174 path[MaxTextExtent];
3175
3176 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3177 path[strlen(path)-strlen(extension)-1]='\0';
3178 GetPathComponent(path,ExtensionPath,extension);
3179 }
3180#endif
3181#if defined(MAGICKCORE_BZLIB_DELEGATE)
3182 if (*extension != '\0')
3183 if (LocaleCompare(extension,"bz2") == 0)
3184 {
3185 char
3186 path[MaxTextExtent];
3187
3188 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3189 path[strlen(path)-strlen(extension)-1]='\0';
3190 GetPathComponent(path,ExtensionPath,extension);
3191 }
3192#endif
3193 image_info->affirm=MagickFalse;
3194 sans_exception=AcquireExceptionInfo();
3195 if (*extension != '\0')
3196 {
3197 MagickFormatType
3198 format_type;
3199
cristybb503372010-05-27 20:51:26 +00003200 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003201 i;
3202
3203 static const char
3204 *format_type_formats[] =
3205 {
3206 "AUTOTRACE",
3207 "BROWSE",
3208 "DCRAW",
3209 "EDIT",
3210 "EPHEMERAL",
3211 "LAUNCH",
3212 "MPEG:DECODE",
3213 "MPEG:ENCODE",
3214 "PRINT",
3215 "PS:ALPHA",
3216 "PS:CMYK",
3217 "PS:COLOR",
3218 "PS:GRAY",
3219 "PS:MONO",
3220 "SCAN",
3221 "SHOW",
3222 "WIN",
3223 (char *) NULL
3224 };
3225
3226 /*
3227 User specified image format.
3228 */
3229 (void) CopyMagickString(magic,extension,MaxTextExtent);
3230 LocaleUpper(magic);
3231 /*
3232 Look for explicit image formats.
3233 */
3234 format_type=UndefinedFormatType;
3235 i=0;
cristydd9a2532010-02-20 19:26:46 +00003236 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00003237 (format_type_formats[i] != (char *) NULL))
3238 {
3239 if ((*magic == *format_type_formats[i]) &&
3240 (LocaleCompare(magic,format_type_formats[i]) == 0))
3241 format_type=ExplicitFormatType;
3242 i++;
3243 }
3244 magick_info=GetMagickInfo(magic,sans_exception);
3245 if ((magick_info != (const MagickInfo *) NULL) &&
3246 (magick_info->format_type != UndefinedFormatType))
3247 format_type=magick_info->format_type;
3248 if (format_type == UndefinedFormatType)
3249 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3250 else
3251 if (format_type == ExplicitFormatType)
3252 {
3253 image_info->affirm=MagickTrue;
3254 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3255 }
3256 if (LocaleCompare(magic,"RGB") == 0)
3257 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3258 }
3259 /*
3260 Look for explicit 'format:image' in filename.
3261 */
3262 *magic='\0';
3263 GetPathComponent(image_info->filename,MagickPath,magic);
3264 if (*magic == '\0')
3265 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3266 else
3267 {
3268 /*
3269 User specified image format.
3270 */
3271 LocaleUpper(magic);
3272 if (IsMagickConflict(magic) == MagickFalse)
3273 {
3274 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3275 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3276 image_info->affirm=MagickTrue;
3277 else
3278 image_info->temporary=MagickTrue;
3279 }
3280 }
3281 magick_info=GetMagickInfo(magic,sans_exception);
3282 sans_exception=DestroyExceptionInfo(sans_exception);
3283 if ((magick_info == (const MagickInfo *) NULL) ||
3284 (GetMagickEndianSupport(magick_info) == MagickFalse))
3285 image_info->endian=UndefinedEndian;
3286 GetPathComponent(image_info->filename,CanonicalPath,filename);
3287 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00003288 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00003289 {
3290 /*
cristyd965a422010-03-03 17:47:35 +00003291 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00003292 */
cristyd965a422010-03-03 17:47:35 +00003293 (void) InterpretImageFilename(image_info,(Image *) NULL,
3294 image_info->filename,(int) image_info->scene,filename);
3295 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3296 (strchr(filename,'%') == (char *) NULL))
3297 image_info->adjoin=MagickFalse;
3298 }
3299 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3300 {
3301 /*
3302 Some image formats do not support multiple frames per file.
3303 */
cristy3ed852e2009-09-05 21:47:34 +00003304 magick_info=GetMagickInfo(magic,exception);
3305 if (magick_info != (const MagickInfo *) NULL)
3306 if (GetMagickAdjoin(magick_info) == MagickFalse)
3307 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003308 }
3309 if (image_info->affirm != MagickFalse)
3310 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00003311 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003312 {
3313 /*
cristyd965a422010-03-03 17:47:35 +00003314 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00003315 */
cristyd965a422010-03-03 17:47:35 +00003316 image=AcquireImage(image_info);
3317 (void) CopyMagickString(image->filename,image_info->filename,
3318 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003319 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3320 if (status == MagickFalse)
3321 {
3322 image=DestroyImage(image);
3323 return(MagickFalse);
3324 }
cristyd965a422010-03-03 17:47:35 +00003325 if ((IsBlobSeekable(image) == MagickFalse) ||
3326 (IsBlobExempt(image) != MagickFalse))
3327 {
3328 /*
3329 Copy standard input or pipe to temporary file.
3330 */
3331 *filename='\0';
3332 status=ImageToFile(image,filename,exception);
3333 (void) CloseBlob(image);
3334 if (status == MagickFalse)
3335 {
3336 image=DestroyImage(image);
3337 return(MagickFalse);
3338 }
3339 SetImageInfoFile(image_info,(FILE *) NULL);
3340 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3341 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3342 if (status == MagickFalse)
3343 {
3344 image=DestroyImage(image);
3345 return(MagickFalse);
3346 }
3347 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3348 image_info->temporary=MagickTrue;
3349 }
3350 (void) ResetMagickMemory(magick,0,sizeof(magick));
3351 count=ReadBlob(image,2*MaxTextExtent,magick);
3352 (void) CloseBlob(image);
3353 image=DestroyImage(image);
3354 /*
3355 Check magic.xml configuration file.
3356 */
3357 sans_exception=AcquireExceptionInfo();
3358 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3359 if ((magic_info != (const MagicInfo *) NULL) &&
3360 (GetMagicName(magic_info) != (char *) NULL))
3361 {
3362 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3363 MaxTextExtent);
3364 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3365 if ((magick_info == (const MagickInfo *) NULL) ||
3366 (GetMagickEndianSupport(magick_info) == MagickFalse))
3367 image_info->endian=UndefinedEndian;
3368 sans_exception=DestroyExceptionInfo(sans_exception);
3369 return(MagickTrue);
3370 }
cristy3ed852e2009-09-05 21:47:34 +00003371 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3372 if ((magick_info == (const MagickInfo *) NULL) ||
3373 (GetMagickEndianSupport(magick_info) == MagickFalse))
3374 image_info->endian=UndefinedEndian;
3375 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00003376 }
cristy3ed852e2009-09-05 21:47:34 +00003377 return(MagickTrue);
3378}
3379
3380/*
3381%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3382% %
3383% %
3384% %
3385% S e t I m a g e I n f o B l o b %
3386% %
3387% %
3388% %
3389%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3390%
3391% SetImageInfoBlob() sets the image info blob member.
3392%
3393% The format of the SetImageInfoBlob method is:
3394%
3395% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3396% const size_t length)
3397%
3398% A description of each parameter follows:
3399%
3400% o image_info: the image info.
3401%
3402% o blob: the blob.
3403%
3404% o length: the blob length.
3405%
3406*/
3407MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3408 const size_t length)
3409{
3410 assert(image_info != (ImageInfo *) NULL);
3411 assert(image_info->signature == MagickSignature);
3412 if (image_info->debug != MagickFalse)
3413 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3414 image_info->filename);
3415 image_info->blob=(void *) blob;
3416 image_info->length=length;
3417}
3418
3419/*
3420%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3421% %
3422% %
3423% %
3424% S e t I m a g e I n f o F i l e %
3425% %
3426% %
3427% %
3428%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3429%
3430% SetImageInfoFile() sets the image info file member.
3431%
3432% The format of the SetImageInfoFile method is:
3433%
3434% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3435%
3436% A description of each parameter follows:
3437%
3438% o image_info: the image info.
3439%
3440% o file: the file.
3441%
3442*/
3443MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3444{
3445 assert(image_info != (ImageInfo *) NULL);
3446 assert(image_info->signature == MagickSignature);
3447 if (image_info->debug != MagickFalse)
3448 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3449 image_info->filename);
3450 image_info->file=file;
3451}
3452
3453/*
3454%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3455% %
3456% %
3457% %
3458% S e t I m a g e M a s k %
3459% %
3460% %
3461% %
3462%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3463%
3464% SetImageMask() associates a mask with the image. The mask must be the same
3465% dimensions as the image.
3466%
3467% The format of the SetImageMask method is:
3468%
3469% MagickBooleanType SetImageMask(Image *image,const Image *mask)
3470%
3471% A description of each parameter follows:
3472%
3473% o image: the image.
3474%
3475% o mask: the image mask.
3476%
3477*/
3478MagickExport MagickBooleanType SetImageMask(Image *image,
3479 const Image *mask)
3480{
3481 assert(image != (Image *) NULL);
3482 if (image->debug != MagickFalse)
3483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3484 assert(image->signature == MagickSignature);
3485 if (mask != (const Image *) NULL)
3486 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3487 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3488 if (image->mask != (Image *) NULL)
3489 image->mask=DestroyImage(image->mask);
3490 image->mask=NewImageList();
3491 if (mask == (Image *) NULL)
3492 return(MagickTrue);
3493 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3494 return(MagickFalse);
3495 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3496 if (image->mask == (Image *) NULL)
3497 return(MagickFalse);
3498 return(MagickTrue);
3499}
3500
3501/*
3502%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3503% %
3504% %
3505% %
3506% S e t I m a g e O p a c i t y %
3507% %
3508% %
3509% %
3510%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3511%
3512% SetImageOpacity() sets the opacity levels of the image.
3513%
3514% The format of the SetImageOpacity method is:
3515%
3516% MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3517%
3518% A description of each parameter follows:
3519%
3520% o image: the image.
3521%
3522% o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3523% fully transparent.
3524%
3525*/
3526MagickExport MagickBooleanType SetImageOpacity(Image *image,
3527 const Quantum opacity)
3528{
3529 CacheView
3530 *image_view;
3531
3532 ExceptionInfo
3533 *exception;
3534
cristy3ed852e2009-09-05 21:47:34 +00003535 MagickBooleanType
3536 status;
3537
cristycb6d09b2010-06-19 01:59:36 +00003538 ssize_t
3539 y;
3540
cristy3ed852e2009-09-05 21:47:34 +00003541 assert(image != (Image *) NULL);
3542 if (image->debug != MagickFalse)
3543 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3544 assert(image->signature == MagickSignature);
3545 image->matte=opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
3546 status=MagickTrue;
3547 exception=(&image->exception);
3548 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00003549#if defined(MAGICKCORE_OPENMP_SUPPORT)
3550 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003551#endif
cristybb503372010-05-27 20:51:26 +00003552 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003553 {
cristy3ed852e2009-09-05 21:47:34 +00003554 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003555 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003556
cristycb6d09b2010-06-19 01:59:36 +00003557 register ssize_t
3558 x;
3559
cristy3ed852e2009-09-05 21:47:34 +00003560 if (status == MagickFalse)
3561 continue;
3562 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3563 if (q == (PixelPacket *) NULL)
3564 {
3565 status=MagickFalse;
3566 continue;
3567 }
cristybb503372010-05-27 20:51:26 +00003568 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003569 {
cristy46f08202010-01-10 04:04:21 +00003570 SetOpacityPixelComponent(q,opacity);
cristy3ed852e2009-09-05 21:47:34 +00003571 q++;
3572 }
3573 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3574 status=MagickFalse;
3575 }
3576 image_view=DestroyCacheView(image_view);
3577 return(status);
3578}
3579
3580/*
3581%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3582% %
3583% %
3584% %
3585% S e t I m a g e T y p e %
3586% %
3587% %
3588% %
3589%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3590%
3591% SetImageType() sets the type of image. Choose from these types:
3592%
3593% Bilevel Grayscale GrayscaleMatte
3594% Palette PaletteMatte TrueColor
3595% TrueColorMatte ColorSeparation ColorSeparationMatte
3596% OptimizeType
3597%
3598% The format of the SetImageType method is:
3599%
3600% MagickBooleanType SetImageType(Image *image,const ImageType type)
3601%
3602% A description of each parameter follows:
3603%
3604% o image: the image.
3605%
3606% o type: Image type.
3607%
3608*/
3609MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3610{
3611 const char
3612 *artifact;
3613
3614 ImageInfo
3615 *image_info;
3616
3617 MagickBooleanType
3618 status;
3619
3620 QuantizeInfo
3621 *quantize_info;
3622
3623 assert(image != (Image *) NULL);
3624 if (image->debug != MagickFalse)
3625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3626 assert(image->signature == MagickSignature);
3627 status=MagickTrue;
3628 image_info=AcquireImageInfo();
3629 image_info->dither=image->dither;
3630 artifact=GetImageArtifact(image,"dither");
3631 if (artifact != (const char *) NULL)
3632 (void) SetImageOption(image_info,"dither",artifact);
3633 switch (type)
3634 {
3635 case BilevelType:
3636 {
3637 if (IsGrayImage(image,&image->exception) == MagickFalse)
3638 status=TransformImageColorspace(image,GRAYColorspace);
3639 if (IsMonochromeImage(image,&image->exception) == MagickFalse)
3640 {
3641 quantize_info=AcquireQuantizeInfo(image_info);
3642 quantize_info->number_colors=2;
3643 quantize_info->colorspace=GRAYColorspace;
3644 status=QuantizeImage(quantize_info,image);
3645 quantize_info=DestroyQuantizeInfo(quantize_info);
3646 }
3647 image->matte=MagickFalse;
3648 break;
3649 }
3650 case GrayscaleType:
3651 {
3652 if (IsGrayImage(image,&image->exception) == MagickFalse)
3653 status=TransformImageColorspace(image,GRAYColorspace);
3654 image->matte=MagickFalse;
3655 break;
3656 }
3657 case GrayscaleMatteType:
3658 {
3659 if (IsGrayImage(image,&image->exception) == MagickFalse)
3660 status=TransformImageColorspace(image,GRAYColorspace);
3661 if (image->matte == MagickFalse)
3662 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3663 break;
3664 }
3665 case PaletteType:
3666 {
3667 if (image->colorspace != RGBColorspace)
3668 status=TransformImageColorspace(image,RGBColorspace);
3669 if ((image->storage_class == DirectClass) || (image->colors > 256))
3670 {
3671 quantize_info=AcquireQuantizeInfo(image_info);
3672 quantize_info->number_colors=256;
3673 status=QuantizeImage(quantize_info,image);
3674 quantize_info=DestroyQuantizeInfo(quantize_info);
3675 }
3676 image->matte=MagickFalse;
3677 break;
3678 }
3679 case PaletteBilevelMatteType:
3680 {
3681 if (image->colorspace != RGBColorspace)
3682 status=TransformImageColorspace(image,RGBColorspace);
3683 if (image->matte == MagickFalse)
3684 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3685 (void) BilevelImageChannel(image,AlphaChannel,(double) QuantumRange/2.0);
3686 quantize_info=AcquireQuantizeInfo(image_info);
3687 status=QuantizeImage(quantize_info,image);
3688 quantize_info=DestroyQuantizeInfo(quantize_info);
3689 break;
3690 }
3691 case PaletteMatteType:
3692 {
3693 if (image->colorspace != RGBColorspace)
3694 status=TransformImageColorspace(image,RGBColorspace);
3695 if (image->matte == MagickFalse)
3696 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3697 quantize_info=AcquireQuantizeInfo(image_info);
3698 quantize_info->colorspace=TransparentColorspace;
3699 status=QuantizeImage(quantize_info,image);
3700 quantize_info=DestroyQuantizeInfo(quantize_info);
3701 break;
3702 }
3703 case TrueColorType:
3704 {
3705 if (image->colorspace != RGBColorspace)
3706 status=TransformImageColorspace(image,RGBColorspace);
3707 if (image->storage_class != DirectClass)
3708 status=SetImageStorageClass(image,DirectClass);
3709 image->matte=MagickFalse;
3710 break;
3711 }
3712 case TrueColorMatteType:
3713 {
3714 if (image->colorspace != RGBColorspace)
3715 status=TransformImageColorspace(image,RGBColorspace);
3716 if (image->storage_class != DirectClass)
3717 status=SetImageStorageClass(image,DirectClass);
3718 if (image->matte == MagickFalse)
3719 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3720 break;
3721 }
3722 case ColorSeparationType:
3723 {
3724 if (image->colorspace != CMYKColorspace)
3725 {
3726 if (image->colorspace != RGBColorspace)
3727 status=TransformImageColorspace(image,RGBColorspace);
3728 status=TransformImageColorspace(image,CMYKColorspace);
3729 }
3730 if (image->storage_class != DirectClass)
3731 status=SetImageStorageClass(image,DirectClass);
3732 image->matte=MagickFalse;
3733 break;
3734 }
3735 case ColorSeparationMatteType:
3736 {
3737 if (image->colorspace != CMYKColorspace)
3738 {
3739 if (image->colorspace != RGBColorspace)
3740 status=TransformImageColorspace(image,RGBColorspace);
3741 status=TransformImageColorspace(image,CMYKColorspace);
3742 }
3743 if (image->storage_class != DirectClass)
3744 status=SetImageStorageClass(image,DirectClass);
3745 if (image->matte == MagickFalse)
3746 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3747 break;
3748 }
3749 case OptimizeType:
cristy5f1c1ff2010-12-23 21:38:06 +00003750 case UndefinedType:
cristy3ed852e2009-09-05 21:47:34 +00003751 break;
3752 }
3753 image->type=type;
3754 image_info=DestroyImageInfo(image_info);
3755 return(status);
3756}
3757
3758/*
3759%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3760% %
3761% %
3762% %
3763% 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 %
3764% %
3765% %
3766% %
3767%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3768%
3769% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3770% image and returns the previous setting. A virtual pixel is any pixel access
3771% that is outside the boundaries of the image cache.
3772%
3773% The format of the SetImageVirtualPixelMethod() method is:
3774%
3775% VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3776% const VirtualPixelMethod virtual_pixel_method)
3777%
3778% A description of each parameter follows:
3779%
3780% o image: the image.
3781%
3782% o virtual_pixel_method: choose the type of virtual pixel.
3783%
3784*/
3785MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3786 const VirtualPixelMethod virtual_pixel_method)
3787{
3788 assert(image != (const Image *) NULL);
3789 assert(image->signature == MagickSignature);
3790 if (image->debug != MagickFalse)
3791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3792 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3793}
3794
3795/*
3796%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3797% %
3798% %
3799% %
cristy4285d782011-02-09 20:12:28 +00003800% S m u s h I m a g e s %
3801% %
3802% %
3803% %
3804%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3805%
3806% SmushImages() takes all images from the current image pointer to the end
3807% of the image list and smushes them to each other top-to-bottom if the
3808% stack parameter is true, otherwise left-to-right.
3809%
3810% The current gravity setting now effects how the image is justified in the
3811% final image.
3812%
3813% The format of the SmushImages method is:
3814%
3815% Image *SmushImages(const Image *image,const MagickBooleanType stack,
3816% ExceptionInfo *exception)
3817%
3818% A description of each parameter follows:
3819%
3820% o image: the image sequence.
3821%
3822% o stack: A value other than 0 stacks the images top-to-bottom.
3823%
3824% o offset: minimum distance in pixels between images.
3825%
3826% o exception: return any errors or warnings in this structure.
3827%
3828*/
3829MagickExport Image *SmushImages(const Image *image,
3830 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3831{
3832#define SmushImageTag "Smush/Image"
3833
3834 CacheView
cristybb5dced2011-02-10 02:17:16 +00003835 *smush_view;
cristy4285d782011-02-09 20:12:28 +00003836
3837 Image
3838 *smush_image;
3839
3840 MagickBooleanType
3841 matte,
3842 proceed,
3843 status;
3844
3845 MagickOffsetType
3846 n;
3847
3848 RectangleInfo
3849 geometry;
3850
3851 register const Image
3852 *next;
3853
3854 size_t
3855 height,
3856 number_images,
3857 width;
3858
3859 ssize_t
3860 x_offset,
cristy4285d782011-02-09 20:12:28 +00003861 y_offset;
3862
3863 /*
3864 Ensure the image have the same column width.
3865 */
3866 assert(image != (Image *) NULL);
3867 assert(image->signature == MagickSignature);
3868 if (image->debug != MagickFalse)
3869 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3870 assert(exception != (ExceptionInfo *) NULL);
3871 assert(exception->signature == MagickSignature);
3872 matte=image->matte;
3873 number_images=1;
3874 width=image->columns;
3875 height=image->rows;
3876 next=GetNextImageInList(image);
3877 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3878 {
3879 if (next->matte != MagickFalse)
3880 matte=MagickTrue;
3881 number_images++;
3882 if (stack != MagickFalse)
3883 {
3884 if (next->columns > width)
3885 width=next->columns;
3886 height+=next->rows;
3887 continue;
3888 }
3889 width+=next->columns;
3890 if (next->rows > height)
3891 height=next->rows;
3892 }
3893 /*
3894 Initialize smush next attributes.
3895 */
3896 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3897 if (smush_image == (Image *) NULL)
3898 return((Image *) NULL);
3899 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
3900 {
3901 InheritException(exception,&smush_image->exception);
3902 smush_image=DestroyImage(smush_image);
3903 return((Image *) NULL);
3904 }
3905 smush_image->matte=matte;
3906 (void) SetImageBackgroundColor(smush_image);
3907 status=MagickTrue;
3908 x_offset=0;
3909 y_offset=0;
3910 smush_view=AcquireCacheView(smush_image);
3911 for (n=0; n < (MagickOffsetType) number_images; n++)
3912 {
3913 SetGeometry(smush_image,&geometry);
3914 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3915 if (stack != MagickFalse)
3916 x_offset-=geometry.x;
3917 else
3918 y_offset-=geometry.y;
cristybb5dced2011-02-10 02:17:16 +00003919 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
cristy4285d782011-02-09 20:12:28 +00003920 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3921 if (proceed == MagickFalse)
3922 break;
3923 if (stack == MagickFalse)
3924 {
3925 x_offset+=(ssize_t) image->columns;
3926 y_offset=0;
3927 }
3928 else
3929 {
3930 x_offset=0;
3931 y_offset+=(ssize_t) image->rows;
3932 }
3933 image=GetNextImageInList(image);
3934 }
3935 smush_view=DestroyCacheView(smush_view);
3936 if (status == MagickFalse)
3937 smush_image=DestroyImage(smush_image);
3938 return(smush_image);
3939}
3940
3941/*
3942%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3943% %
3944% %
3945% %
cristy3ed852e2009-09-05 21:47:34 +00003946% S t r i p I m a g e %
3947% %
3948% %
3949% %
3950%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3951%
cristy376bda92009-12-22 21:15:23 +00003952% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00003953%
3954% The format of the StripImage method is:
3955%
3956% MagickBooleanType StripImage(Image *image)
3957%
3958% A description of each parameter follows:
3959%
3960% o image: the image.
3961%
3962*/
3963MagickExport MagickBooleanType StripImage(Image *image)
3964{
3965 assert(image != (Image *) NULL);
3966 if (image->debug != MagickFalse)
3967 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3968 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00003969 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00003970 (void) DeleteImageProperty(image,"date:create");
3971 (void) DeleteImageProperty(image,"date:modify");
glennrpce91ed52010-12-23 22:37:49 +00003972 (void) SetImageArtifact(image,"png:include-chunk","none,gama");
cristy3ed852e2009-09-05 21:47:34 +00003973 return(MagickTrue);
3974}
3975
3976/*
3977%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3978% %
3979% %
3980% %
3981+ S y n c I m a g e %
3982% %
3983% %
3984% %
3985%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3986%
3987% SyncImage() initializes the red, green, and blue intensities of each pixel
3988% as defined by the colormap index.
3989%
3990% The format of the SyncImage method is:
3991%
3992% MagickBooleanType SyncImage(Image *image)
3993%
3994% A description of each parameter follows:
3995%
3996% o image: the image.
3997%
3998*/
3999
4000static inline IndexPacket PushColormapIndex(Image *image,
cristybb503372010-05-27 20:51:26 +00004001 const size_t index,MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00004002{
4003 if (index < image->colors)
4004 return((IndexPacket) index);
4005 *range_exception=MagickTrue;
4006 return((IndexPacket) 0);
4007}
4008
4009MagickExport MagickBooleanType SyncImage(Image *image)
4010{
4011 CacheView
4012 *image_view;
4013
4014 ExceptionInfo
4015 *exception;
4016
cristy3ed852e2009-09-05 21:47:34 +00004017 MagickBooleanType
4018 range_exception,
4019 status;
4020
cristycb6d09b2010-06-19 01:59:36 +00004021 ssize_t
4022 y;
4023
cristy3ed852e2009-09-05 21:47:34 +00004024 assert(image != (Image *) NULL);
4025 if (image->debug != MagickFalse)
4026 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4027 assert(image->signature == MagickSignature);
4028 if (image->storage_class == DirectClass)
4029 return(MagickFalse);
4030 range_exception=MagickFalse;
4031 status=MagickTrue;
4032 exception=(&image->exception);
4033 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00004034#if defined(MAGICKCORE_OPENMP_SUPPORT)
4035 #pragma omp parallel for schedule(dynamic,4) shared(status)
4036#endif
cristybb503372010-05-27 20:51:26 +00004037 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004038 {
4039 IndexPacket
4040 index;
4041
4042 PixelPacket
4043 pixel;
4044
4045 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00004046 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00004047
cristy3ed852e2009-09-05 21:47:34 +00004048 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00004049 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004050
cristycb6d09b2010-06-19 01:59:36 +00004051 register ssize_t
4052 x;
4053
cristy48974b92009-12-19 02:36:06 +00004054 if (status == MagickFalse)
4055 continue;
cristy3ed852e2009-09-05 21:47:34 +00004056 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4057 if (q == (PixelPacket *) NULL)
4058 {
4059 status=MagickFalse;
4060 continue;
4061 }
4062 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00004063 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004064 {
cristybb503372010-05-27 20:51:26 +00004065 index=PushColormapIndex(image,(size_t) indexes[x],
cristy3ed852e2009-09-05 21:47:34 +00004066 &range_exception);
cristybb503372010-05-27 20:51:26 +00004067 pixel=image->colormap[(ssize_t) index];
cristy3ed852e2009-09-05 21:47:34 +00004068 q->red=pixel.red;
4069 q->green=pixel.green;
4070 q->blue=pixel.blue;
cristyd0272592010-04-21 01:01:49 +00004071 if (image->matte != MagickFalse)
4072 q->opacity=pixel.opacity;
cristy3ed852e2009-09-05 21:47:34 +00004073 q++;
4074 }
4075 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4076 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004077 }
4078 image_view=DestroyCacheView(image_view);
4079 if (range_exception != MagickFalse)
4080 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4081 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4082 return(status);
4083}
cristy1626d332009-11-10 16:58:17 +00004084
4085/*
4086%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4087% %
4088% %
4089% %
4090% S y n c I m a g e S e t t i n g s %
4091% %
4092% %
4093% %
4094%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4095%
4096% SyncImageSettings() sync the image info options to the image.
4097%
4098% The format of the SyncImageSettings method is:
4099%
4100% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4101% Image *image)
4102% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4103% Image *image)
4104%
4105% A description of each parameter follows:
4106%
4107% o image_info: the image info.
4108%
4109% o image: the image.
4110%
4111*/
4112
4113MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4114 Image *images)
4115{
4116 Image
4117 *image;
4118
4119 assert(image_info != (const ImageInfo *) NULL);
4120 assert(image_info->signature == MagickSignature);
4121 assert(images != (Image *) NULL);
4122 assert(images->signature == MagickSignature);
4123 if (images->debug != MagickFalse)
4124 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4125 image=images;
4126 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4127 (void) SyncImageSettings(image_info,image);
4128 (void) DeleteImageOption(image_info,"page");
4129 return(MagickTrue);
4130}
4131
4132MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4133 Image *image)
4134{
4135 char
4136 property[MaxTextExtent];
4137
4138 const char
cristy9a703812010-07-26 14:50:29 +00004139 *option,
4140 *value;
cristy1626d332009-11-10 16:58:17 +00004141
4142 GeometryInfo
4143 geometry_info;
4144
4145 MagickStatusType
4146 flags;
4147
cristy19eb6412010-04-23 14:42:29 +00004148 ResolutionType
4149 units;
4150
cristy1626d332009-11-10 16:58:17 +00004151 /*
4152 Sync image options.
4153 */
4154 assert(image_info != (const ImageInfo *) NULL);
4155 assert(image_info->signature == MagickSignature);
4156 assert(image != (Image *) NULL);
4157 assert(image->signature == MagickSignature);
4158 if (image->debug != MagickFalse)
4159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4160 option=GetImageOption(image_info,"background");
4161 if (option != (const char *) NULL)
4162 (void) QueryColorDatabase(option,&image->background_color,
4163 &image->exception);
4164 option=GetImageOption(image_info,"bias");
4165 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00004166 image->bias=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00004167 option=GetImageOption(image_info,"black-point-compensation");
4168 if (option != (const char *) NULL)
4169 image->black_point_compensation=(MagickBooleanType) ParseMagickOption(
4170 MagickBooleanOptions,MagickFalse,option);
4171 option=GetImageOption(image_info,"blue-primary");
4172 if (option != (const char *) NULL)
4173 {
4174 flags=ParseGeometry(option,&geometry_info);
4175 image->chromaticity.blue_primary.x=geometry_info.rho;
4176 image->chromaticity.blue_primary.y=geometry_info.sigma;
4177 if ((flags & SigmaValue) == 0)
4178 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4179 }
4180 option=GetImageOption(image_info,"bordercolor");
4181 if (option != (const char *) NULL)
4182 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4183 option=GetImageOption(image_info,"colors");
4184 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004185 image->colors=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004186 option=GetImageOption(image_info,"compose");
4187 if (option != (const char *) NULL)
4188 image->compose=(CompositeOperator) ParseMagickOption(MagickComposeOptions,
4189 MagickFalse,option);
4190 option=GetImageOption(image_info,"compress");
4191 if (option != (const char *) NULL)
4192 image->compression=(CompressionType) ParseMagickOption(
4193 MagickCompressOptions,MagickFalse,option);
4194 option=GetImageOption(image_info,"debug");
4195 if (option != (const char *) NULL)
4196 image->debug=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4197 MagickFalse,option);
cristydd5f5912010-07-31 23:37:23 +00004198 option=GetImageOption(image_info,"density");
4199 if (option != (const char *) NULL)
4200 {
4201 GeometryInfo
4202 geometry_info;
4203
4204 /*
4205 Set image density.
4206 */
4207 flags=ParseGeometry(option,&geometry_info);
4208 image->x_resolution=geometry_info.rho;
4209 image->y_resolution=geometry_info.sigma;
4210 if ((flags & SigmaValue) == 0)
4211 image->y_resolution=image->x_resolution;
4212 }
cristy1626d332009-11-10 16:58:17 +00004213 option=GetImageOption(image_info,"depth");
4214 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004215 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004216 option=GetImageOption(image_info,"endian");
4217 if (option != (const char *) NULL)
4218 image->endian=(EndianType) ParseMagickOption(MagickEndianOptions,
4219 MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00004220 option=GetImageOption(image_info,"filter");
4221 if (option != (const char *) NULL)
4222 image->filter=(FilterTypes) ParseMagickOption(MagickFilterOptions,
4223 MagickFalse,option);
4224 option=GetImageOption(image_info,"fuzz");
4225 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00004226 image->fuzz=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00004227 option=GetImageOption(image_info,"gravity");
4228 if (option != (const char *) NULL)
4229 image->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4230 MagickFalse,option);
4231 option=GetImageOption(image_info,"green-primary");
4232 if (option != (const char *) NULL)
4233 {
4234 flags=ParseGeometry(option,&geometry_info);
4235 image->chromaticity.green_primary.x=geometry_info.rho;
4236 image->chromaticity.green_primary.y=geometry_info.sigma;
4237 if ((flags & SigmaValue) == 0)
4238 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4239 }
4240 option=GetImageOption(image_info,"intent");
4241 if (option != (const char *) NULL)
4242 image->rendering_intent=(RenderingIntent) ParseMagickOption(
4243 MagickIntentOptions,MagickFalse,option);
4244 option=GetImageOption(image_info,"interlace");
4245 if (option != (const char *) NULL)
4246 image->interlace=(InterlaceType) ParseMagickOption(MagickInterlaceOptions,
4247 MagickFalse,option);
4248 option=GetImageOption(image_info,"interpolate");
4249 if (option != (const char *) NULL)
4250 image->interpolate=(InterpolatePixelMethod) ParseMagickOption(
4251 MagickInterpolateOptions,MagickFalse,option);
4252 option=GetImageOption(image_info,"loop");
4253 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004254 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004255 option=GetImageOption(image_info,"mattecolor");
4256 if (option != (const char *) NULL)
4257 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4258 option=GetImageOption(image_info,"orient");
4259 if (option != (const char *) NULL)
4260 image->orientation=(OrientationType) ParseMagickOption(
4261 MagickOrientationOptions,MagickFalse,option);
cristy9a703812010-07-26 14:50:29 +00004262 option=GetImageOption(image_info,"page");
4263 if (option != (const char *) NULL)
4264 {
4265 char
4266 *geometry;
4267
4268 geometry=GetPageGeometry(option);
4269 flags=ParseAbsoluteGeometry(geometry,&image->page);
4270 geometry=DestroyString(geometry);
4271 }
cristy1626d332009-11-10 16:58:17 +00004272 option=GetImageOption(image_info,"quality");
4273 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004274 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004275 option=GetImageOption(image_info,"red-primary");
4276 if (option != (const char *) NULL)
4277 {
4278 flags=ParseGeometry(option,&geometry_info);
4279 image->chromaticity.red_primary.x=geometry_info.rho;
4280 image->chromaticity.red_primary.y=geometry_info.sigma;
4281 if ((flags & SigmaValue) == 0)
4282 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4283 }
4284 if (image_info->quality != UndefinedCompressionQuality)
4285 image->quality=image_info->quality;
4286 option=GetImageOption(image_info,"scene");
4287 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004288 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004289 option=GetImageOption(image_info,"taint");
4290 if (option != (const char *) NULL)
4291 image->taint=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4292 MagickFalse,option);
4293 option=GetImageOption(image_info,"tile-offset");
4294 if (option != (const char *) NULL)
4295 {
4296 char
4297 *geometry;
4298
4299 geometry=GetPageGeometry(option);
4300 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4301 geometry=DestroyString(geometry);
4302 }
4303 option=GetImageOption(image_info,"transparent-color");
4304 if (option != (const char *) NULL)
4305 (void) QueryColorDatabase(option,&image->transparent_color,
4306 &image->exception);
4307 option=GetImageOption(image_info,"type");
4308 if (option != (const char *) NULL)
4309 image->type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
4310 option);
4311 option=GetImageOption(image_info,"units");
4312 if (option != (const char *) NULL)
cristy19eb6412010-04-23 14:42:29 +00004313 units=(ResolutionType) ParseMagickOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00004314 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00004315 else
4316 units = image_info->units;
4317 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00004318 {
cristy19eb6412010-04-23 14:42:29 +00004319 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00004320 switch (image->units)
4321 {
4322 case PixelsPerInchResolution:
4323 {
cristy19eb6412010-04-23 14:42:29 +00004324 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00004325 {
4326 image->x_resolution/=2.54;
4327 image->y_resolution/=2.54;
4328 }
4329 break;
4330 }
4331 case PixelsPerCentimeterResolution:
4332 {
cristy19eb6412010-04-23 14:42:29 +00004333 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00004334 {
cristybb503372010-05-27 20:51:26 +00004335 image->x_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004336 image->x_resolution+0.5))/100.0;
cristybb503372010-05-27 20:51:26 +00004337 image->y_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004338 image->y_resolution+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00004339 }
4340 break;
4341 }
4342 default:
4343 break;
4344 }
cristy19eb6412010-04-23 14:42:29 +00004345 image->units=units;
cristy1626d332009-11-10 16:58:17 +00004346 }
4347 option=GetImageOption(image_info,"white-point");
4348 if (option != (const char *) NULL)
4349 {
4350 flags=ParseGeometry(option,&geometry_info);
4351 image->chromaticity.white_point.x=geometry_info.rho;
4352 image->chromaticity.white_point.y=geometry_info.sigma;
4353 if ((flags & SigmaValue) == 0)
4354 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4355 }
4356 ResetImageOptionIterator(image_info);
4357 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4358 {
4359 value=GetImageOption(image_info,option);
4360 if (value != (const char *) NULL)
4361 {
4362 (void) FormatMagickString(property,MaxTextExtent,"%s",option);
4363 (void) SetImageArtifact(image,property,value);
4364 }
4365 option=GetNextImageOption(image_info);
4366 }
4367 return(MagickTrue);
4368}