blob: 2a60c9bac6f405ec3ddad451cff0accde5b32383 [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,
751 const size_t rows,const MagickBooleanType detach,
cristy3ed852e2009-09-05 21:47:34 +0000752 ExceptionInfo *exception)
753{
754 Image
755 *clone_image;
756
757 MagickRealType
758 scale;
759
760 size_t
761 length;
762
763 /*
764 Clone the image.
765 */
766 assert(image != (const Image *) NULL);
767 assert(image->signature == MagickSignature);
768 if (image->debug != MagickFalse)
769 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
770 assert(exception != (ExceptionInfo *) NULL);
771 assert(exception->signature == MagickSignature);
cristy73bd4a52010-10-05 11:24:23 +0000772 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000773 if (clone_image == (Image *) NULL)
774 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
775 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
776 clone_image->signature=MagickSignature;
777 clone_image->storage_class=image->storage_class;
778 clone_image->colorspace=image->colorspace;
779 clone_image->matte=image->matte;
780 clone_image->columns=image->columns;
781 clone_image->rows=image->rows;
782 clone_image->dither=image->dither;
783 if (image->colormap != (PixelPacket *) NULL)
784 {
785 /*
786 Allocate and copy the image colormap.
787 */
788 clone_image->colors=image->colors;
789 length=(size_t) image->colors;
790 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
791 sizeof(*clone_image->colormap));
792 if (clone_image->colormap == (PixelPacket *) NULL)
793 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
794 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
795 sizeof(*clone_image->colormap));
796 }
797 (void) CloneImageProfiles(clone_image,image);
798 (void) CloneImageProperties(clone_image,image);
799 (void) CloneImageArtifacts(clone_image,image);
800 GetTimerInfo(&clone_image->timer);
801 GetExceptionInfo(&clone_image->exception);
802 InheritException(&clone_image->exception,&image->exception);
803 if (image->ascii85 != (void *) NULL)
804 Ascii85Initialize(clone_image);
805 clone_image->magick_columns=image->magick_columns;
806 clone_image->magick_rows=image->magick_rows;
807 clone_image->type=image->type;
808 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
809 MaxTextExtent);
810 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
811 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
812 clone_image->progress_monitor=image->progress_monitor;
813 clone_image->client_data=image->client_data;
814 clone_image->reference_count=1;
815 clone_image->next=NewImageList();
816 clone_image->previous=NewImageList();
817 clone_image->list=NewImageList();
818 clone_image->clip_mask=NewImageList();
819 clone_image->mask=NewImageList();
820 if (detach == MagickFalse)
821 clone_image->blob=ReferenceBlob(image->blob);
822 else
823 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
cristy73724512010-04-12 14:43:14 +0000824 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000825 clone_image->debug=IsEventLogging();
826 clone_image->semaphore=AllocateSemaphoreInfo();
827 if ((columns == 0) && (rows == 0))
828 {
829 if (image->montage != (char *) NULL)
830 (void) CloneString(&clone_image->montage,image->montage);
831 if (image->directory != (char *) NULL)
832 (void) CloneString(&clone_image->directory,image->directory);
833 if (image->clip_mask != (Image *) NULL)
834 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
835 exception);
836 if (image->mask != (Image *) NULL)
837 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
838 clone_image->cache=ReferencePixelCache(image->cache);
839 return(clone_image);
840 }
841 scale=(MagickRealType) columns/(MagickRealType) image->columns;
cristybb503372010-05-27 20:51:26 +0000842 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
843 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
844 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000845 scale=(MagickRealType) rows/(MagickRealType) image->rows;
cristybb503372010-05-27 20:51:26 +0000846 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
847 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
848 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000849 clone_image->columns=columns;
850 clone_image->rows=rows;
851 clone_image->cache=ClonePixelCache(image->cache);
852 return(clone_image);
853}
854
855/*
856%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
857% %
858% %
859% %
860% C l o n e I m a g e I n f o %
861% %
862% %
863% %
864%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
865%
866% CloneImageInfo() makes a copy of the given image info structure. If
867% NULL is specified, a new image info structure is created initialized to
868% default values.
869%
870% The format of the CloneImageInfo method is:
871%
872% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
873%
874% A description of each parameter follows:
875%
876% o image_info: the image info.
877%
878*/
879MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
880{
881 ImageInfo
882 *clone_info;
883
884 clone_info=AcquireImageInfo();
885 if (image_info == (ImageInfo *) NULL)
886 return(clone_info);
887 clone_info->compression=image_info->compression;
888 clone_info->temporary=image_info->temporary;
889 clone_info->adjoin=image_info->adjoin;
890 clone_info->antialias=image_info->antialias;
891 clone_info->scene=image_info->scene;
892 clone_info->number_scenes=image_info->number_scenes;
893 clone_info->depth=image_info->depth;
894 if (image_info->size != (char *) NULL)
895 (void) CloneString(&clone_info->size,image_info->size);
896 if (image_info->extract != (char *) NULL)
897 (void) CloneString(&clone_info->extract,image_info->extract);
898 if (image_info->scenes != (char *) NULL)
899 (void) CloneString(&clone_info->scenes,image_info->scenes);
900 if (image_info->page != (char *) NULL)
901 (void) CloneString(&clone_info->page,image_info->page);
902 clone_info->interlace=image_info->interlace;
903 clone_info->endian=image_info->endian;
904 clone_info->units=image_info->units;
905 clone_info->quality=image_info->quality;
906 if (image_info->sampling_factor != (char *) NULL)
907 (void) CloneString(&clone_info->sampling_factor,
908 image_info->sampling_factor);
909 if (image_info->server_name != (char *) NULL)
910 (void) CloneString(&clone_info->server_name,image_info->server_name);
911 if (image_info->font != (char *) NULL)
912 (void) CloneString(&clone_info->font,image_info->font);
913 if (image_info->texture != (char *) NULL)
914 (void) CloneString(&clone_info->texture,image_info->texture);
915 if (image_info->density != (char *) NULL)
916 (void) CloneString(&clone_info->density,image_info->density);
917 clone_info->pointsize=image_info->pointsize;
918 clone_info->fuzz=image_info->fuzz;
919 clone_info->pen=image_info->pen;
920 clone_info->background_color=image_info->background_color;
921 clone_info->border_color=image_info->border_color;
922 clone_info->matte_color=image_info->matte_color;
923 clone_info->transparent_color=image_info->transparent_color;
924 clone_info->dither=image_info->dither;
925 clone_info->monochrome=image_info->monochrome;
926 clone_info->colors=image_info->colors;
927 clone_info->colorspace=image_info->colorspace;
928 clone_info->type=image_info->type;
929 clone_info->orientation=image_info->orientation;
930 clone_info->preview_type=image_info->preview_type;
931 clone_info->group=image_info->group;
932 clone_info->ping=image_info->ping;
933 clone_info->verbose=image_info->verbose;
934 if (image_info->view != (char *) NULL)
935 (void) CloneString(&clone_info->view,image_info->view);
936 if (image_info->authenticate != (char *) NULL)
937 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
938 (void) CloneImageOptions(clone_info,image_info);
939 clone_info->progress_monitor=image_info->progress_monitor;
940 clone_info->client_data=image_info->client_data;
941 clone_info->cache=image_info->cache;
942 if (image_info->cache != (void *) NULL)
943 clone_info->cache=ReferencePixelCache(image_info->cache);
944 if (image_info->profile != (void *) NULL)
945 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
946 image_info->profile);
947 SetImageInfoFile(clone_info,image_info->file);
948 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
949 clone_info->stream=image_info->stream;
950 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
951 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
952 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
953 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
954 (void) CopyMagickString(clone_info->filename,image_info->filename,
955 MaxTextExtent);
956 clone_info->subimage=image_info->scene; /* deprecated */
957 clone_info->subrange=image_info->number_scenes; /* deprecated */
958 clone_info->channel=image_info->channel;
959 clone_info->debug=IsEventLogging();
960 clone_info->signature=image_info->signature;
961 return(clone_info);
962}
963
964/*
965%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
966% %
967% %
968% %
969% C o m b i n e I m a g e s %
970% %
971% %
972% %
973%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
974%
975% CombineImages() combines one or more images into a single image. The
976% grayscale value of the pixels of each image in the sequence is assigned in
977% order to the specified channels of the combined image. The typical
978% ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
979%
980% The format of the CombineImages method is:
981%
982% Image *CombineImages(const Image *image,const ChannelType channel,
983% ExceptionInfo *exception)
984%
985% A description of each parameter follows:
986%
987% o image: the image.
988%
989% o exception: return any errors or warnings in this structure.
990%
991*/
992MagickExport Image *CombineImages(const Image *image,const ChannelType channel,
993 ExceptionInfo *exception)
994{
995#define CombineImageTag "Combine/Image"
996
997 CacheView
998 *combine_view;
999
1000 const Image
1001 *next;
1002
1003 Image
1004 *combine_image;
1005
cristy3ed852e2009-09-05 21:47:34 +00001006 MagickBooleanType
1007 status;
1008
cristybb503372010-05-27 20:51:26 +00001009 MagickOffsetType
1010 progress;
1011
1012 ssize_t
1013 y;
1014
cristy3ed852e2009-09-05 21:47:34 +00001015 /*
1016 Ensure the image are the same size.
1017 */
1018 assert(image != (const Image *) NULL);
1019 assert(image->signature == MagickSignature);
1020 if (image->debug != MagickFalse)
1021 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1022 assert(exception != (ExceptionInfo *) NULL);
1023 assert(exception->signature == MagickSignature);
1024 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1025 {
1026 if ((next->columns != image->columns) || (next->rows != image->rows))
1027 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1028 }
1029 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1030 if (combine_image == (Image *) NULL)
1031 return((Image *) NULL);
1032 if (SetImageStorageClass(combine_image,DirectClass) == MagickFalse)
1033 {
1034 InheritException(exception,&combine_image->exception);
1035 combine_image=DestroyImage(combine_image);
1036 return((Image *) NULL);
1037 }
1038 if ((channel & OpacityChannel) != 0)
1039 combine_image->matte=MagickTrue;
1040 (void) SetImageBackgroundColor(combine_image);
1041 /*
1042 Combine images.
1043 */
1044 status=MagickTrue;
1045 progress=0;
1046 combine_view=AcquireCacheView(combine_image);
cristyb5d5f722009-11-04 03:03:49 +00001047#if defined(MAGICKCORE_OPENMP_SUPPORT)
1048 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00001049#endif
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
cristyb5d5f722009-11-04 03:03:49 +00001170#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00001171 #pragma omp critical (MagickCore_CombineImages)
1172#endif
1173 proceed=SetImageProgress(image,CombineImageTag,progress++,
1174 combine_image->rows);
1175 if (proceed == MagickFalse)
1176 status=MagickFalse;
1177 }
1178 }
1179 combine_view=DestroyCacheView(combine_view);
1180 if (status == MagickFalse)
1181 combine_image=DestroyImage(combine_image);
1182 return(combine_image);
1183}
1184
1185/*
1186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1187% %
1188% %
1189% %
cristy3ed852e2009-09-05 21:47:34 +00001190% D e s t r o y I m a g e %
1191% %
1192% %
1193% %
1194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1195%
1196% DestroyImage() dereferences an image, deallocating memory associated with
1197% the image if the reference count becomes zero.
1198%
1199% The format of the DestroyImage method is:
1200%
1201% Image *DestroyImage(Image *image)
1202%
1203% A description of each parameter follows:
1204%
1205% o image: the image.
1206%
1207*/
1208MagickExport Image *DestroyImage(Image *image)
1209{
1210 MagickBooleanType
1211 destroy;
1212
1213 /*
1214 Dereference image.
1215 */
1216 assert(image != (Image *) NULL);
1217 assert(image->signature == MagickSignature);
1218 if (image->debug != MagickFalse)
1219 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1220 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001221 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001222 image->reference_count--;
1223 if (image->reference_count == 0)
1224 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001225 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001226 if (destroy == MagickFalse)
1227 return((Image *) NULL);
1228 /*
1229 Destroy image.
1230 */
1231 DestroyImagePixels(image);
1232 if (image->clip_mask != (Image *) NULL)
1233 image->clip_mask=DestroyImage(image->clip_mask);
1234 if (image->mask != (Image *) NULL)
1235 image->mask=DestroyImage(image->mask);
1236 if (image->montage != (char *) NULL)
1237 image->montage=DestroyString(image->montage);
1238 if (image->directory != (char *) NULL)
1239 image->directory=DestroyString(image->directory);
1240 if (image->colormap != (PixelPacket *) NULL)
1241 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1242 if (image->geometry != (char *) NULL)
1243 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001244 DestroyImageProfiles(image);
1245 DestroyImageProperties(image);
1246 DestroyImageArtifacts(image);
1247 if (image->ascii85 != (Ascii85Info*) NULL)
1248 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1249 DestroyBlob(image);
1250 (void) DestroyExceptionInfo(&image->exception);
1251 if (image->semaphore != (SemaphoreInfo *) NULL)
1252 DestroySemaphoreInfo(&image->semaphore);
1253 image->signature=(~MagickSignature);
1254 image=(Image *) RelinquishMagickMemory(image);
1255 return(image);
1256}
1257
1258/*
1259%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1260% %
1261% %
1262% %
1263% D e s t r o y I m a g e I n f o %
1264% %
1265% %
1266% %
1267%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1268%
1269% DestroyImageInfo() deallocates memory associated with an ImageInfo
1270% structure.
1271%
1272% The format of the DestroyImageInfo method is:
1273%
1274% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1275%
1276% A description of each parameter follows:
1277%
1278% o image_info: the image info.
1279%
1280*/
1281MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1282{
1283 assert(image_info != (ImageInfo *) NULL);
1284 assert(image_info->signature == MagickSignature);
1285 if (image_info->debug != MagickFalse)
1286 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1287 image_info->filename);
1288 if (image_info->size != (char *) NULL)
1289 image_info->size=DestroyString(image_info->size);
1290 if (image_info->extract != (char *) NULL)
1291 image_info->extract=DestroyString(image_info->extract);
1292 if (image_info->scenes != (char *) NULL)
1293 image_info->scenes=DestroyString(image_info->scenes);
1294 if (image_info->page != (char *) NULL)
1295 image_info->page=DestroyString(image_info->page);
1296 if (image_info->sampling_factor != (char *) NULL)
1297 image_info->sampling_factor=DestroyString(
1298 image_info->sampling_factor);
1299 if (image_info->server_name != (char *) NULL)
1300 image_info->server_name=DestroyString(
1301 image_info->server_name);
1302 if (image_info->font != (char *) NULL)
1303 image_info->font=DestroyString(image_info->font);
1304 if (image_info->texture != (char *) NULL)
1305 image_info->texture=DestroyString(image_info->texture);
1306 if (image_info->density != (char *) NULL)
1307 image_info->density=DestroyString(image_info->density);
1308 if (image_info->view != (char *) NULL)
1309 image_info->view=DestroyString(image_info->view);
1310 if (image_info->authenticate != (char *) NULL)
1311 image_info->authenticate=DestroyString(
1312 image_info->authenticate);
1313 DestroyImageOptions(image_info);
1314 if (image_info->cache != (void *) NULL)
1315 image_info->cache=DestroyPixelCache(image_info->cache);
1316 if (image_info->profile != (StringInfo *) NULL)
1317 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1318 image_info->profile);
1319 image_info->signature=(~MagickSignature);
1320 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1321 return(image_info);
1322}
1323
1324/*
1325%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1326% %
1327% %
1328% %
1329+ D i s a s s o c i a t e I m a g e S t r e a m %
1330% %
1331% %
1332% %
1333%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1334%
1335% DisassociateImageStream() disassociates the image stream.
1336%
1337% The format of the DisassociateImageStream method is:
1338%
1339% MagickBooleanType DisassociateImageStream(const Image *image)
1340%
1341% A description of each parameter follows:
1342%
1343% o image: the image.
1344%
1345*/
1346MagickExport void DisassociateImageStream(Image *image)
1347{
1348 assert(image != (const Image *) NULL);
1349 assert(image->signature == MagickSignature);
1350 if (image->debug != MagickFalse)
1351 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1352 (void) DetachBlob(image->blob);
1353}
1354
1355/*
1356%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1357% %
1358% %
1359% %
1360% G e t I m a g e A l p h a C h a n n e l %
1361% %
1362% %
1363% %
1364%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1365%
1366% GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1367% not activated. That is, the image is RGB rather than RGBA or CMYK rather
1368% than CMYKA.
1369%
1370% The format of the GetImageAlphaChannel method is:
1371%
1372% MagickBooleanType GetImageAlphaChannel(const Image *image)
1373%
1374% A description of each parameter follows:
1375%
1376% o image: the image.
1377%
1378*/
1379MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1380{
1381 assert(image != (const Image *) NULL);
1382 if (image->debug != MagickFalse)
1383 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1384 assert(image->signature == MagickSignature);
1385 return(image->matte);
1386}
1387
1388/*
1389%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1390% %
1391% %
1392% %
1393% G e t I m a g e C l i p M a s k %
1394% %
1395% %
1396% %
1397%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1398%
1399% GetImageClipMask() returns the clip path associated with the image.
1400%
1401% The format of the GetImageClipMask method is:
1402%
1403% Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1404%
1405% A description of each parameter follows:
1406%
1407% o image: the image.
1408%
1409*/
1410MagickExport Image *GetImageClipMask(const Image *image,
1411 ExceptionInfo *exception)
1412{
1413 assert(image != (const Image *) NULL);
1414 if (image->debug != MagickFalse)
1415 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1416 assert(image->signature == MagickSignature);
1417 if (image->clip_mask == (Image *) NULL)
1418 return((Image *) NULL);
1419 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1420}
1421
1422/*
1423%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1424% %
1425% %
1426% %
1427% G e t I m a g e E x c e p t i o n %
1428% %
1429% %
1430% %
1431%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1432%
1433% GetImageException() traverses an image sequence and returns any
1434% error more severe than noted by the exception parameter.
1435%
1436% The format of the GetImageException method is:
1437%
1438% void GetImageException(Image *image,ExceptionInfo *exception)
1439%
1440% A description of each parameter follows:
1441%
1442% o image: Specifies a pointer to a list of one or more images.
1443%
1444% o exception: return the highest severity exception.
1445%
1446*/
1447MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1448{
1449 register Image
1450 *next;
1451
1452 assert(image != (Image *) NULL);
1453 assert(image->signature == MagickSignature);
1454 if (image->debug != MagickFalse)
1455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1456 assert(exception != (ExceptionInfo *) NULL);
1457 assert(exception->signature == MagickSignature);
1458 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1459 {
1460 if (next->exception.severity == UndefinedException)
1461 continue;
1462 if (next->exception.severity > exception->severity)
1463 InheritException(exception,&next->exception);
1464 next->exception.severity=UndefinedException;
1465 }
1466}
1467
1468/*
1469%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1470% %
1471% %
1472% %
1473% G e t I m a g e I n f o %
1474% %
1475% %
1476% %
1477%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1478%
1479% GetImageInfo() initializes image_info to default values.
1480%
1481% The format of the GetImageInfo method is:
1482%
1483% void GetImageInfo(ImageInfo *image_info)
1484%
1485% A description of each parameter follows:
1486%
1487% o image_info: the image info.
1488%
1489*/
1490MagickExport void GetImageInfo(ImageInfo *image_info)
1491{
cristyd9a29192010-10-16 16:49:53 +00001492 const char
1493 *synchronize;
1494
cristy3ed852e2009-09-05 21:47:34 +00001495 ExceptionInfo
1496 *exception;
1497
1498 /*
1499 File and image dimension members.
1500 */
1501 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1502 assert(image_info != (ImageInfo *) NULL);
1503 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1504 image_info->adjoin=MagickTrue;
1505 image_info->interlace=NoInterlace;
1506 image_info->channel=DefaultChannels;
1507 image_info->quality=UndefinedCompressionQuality;
1508 image_info->antialias=MagickTrue;
1509 image_info->dither=MagickTrue;
cristyd9a29192010-10-16 16:49:53 +00001510 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1511 if (synchronize != (const char *) NULL)
1512 image_info->synchronize=IsMagickTrue(synchronize);
cristy3ed852e2009-09-05 21:47:34 +00001513 exception=AcquireExceptionInfo();
1514 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1515 exception);
1516 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1517 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1518 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1519 exception);
1520 exception=DestroyExceptionInfo(exception);
1521 image_info->debug=IsEventLogging();
1522 image_info->signature=MagickSignature;
1523}
1524
1525/*
1526%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1527% %
1528% %
1529% %
cristy15781e52009-12-05 23:05:27 +00001530% G e t I m a g e I n f o F i l e %
1531% %
1532% %
1533% %
1534%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1535%
1536% GetImageInfoFile() returns the image info file member.
1537%
1538% The format of the GetImageInfoFile method is:
1539%
1540% FILE *GetImageInfoFile(const ImageInfo *image_info)
1541%
1542% A description of each parameter follows:
1543%
1544% o image_info: the image info.
1545%
1546*/
1547MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1548{
1549 return(image_info->file);
1550}
1551
1552/*
1553%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1554% %
1555% %
1556% %
cristy3ed852e2009-09-05 21:47:34 +00001557% G e t I m a g e M a s k %
1558% %
1559% %
1560% %
1561%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1562%
1563% GetImageMask() returns the mask associated with the image.
1564%
1565% The format of the GetImageMask method is:
1566%
1567% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1568%
1569% A description of each parameter follows:
1570%
1571% o image: the image.
1572%
1573*/
1574MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1575{
1576 assert(image != (const Image *) NULL);
1577 if (image->debug != MagickFalse)
1578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1579 assert(image->signature == MagickSignature);
1580 if (image->mask == (Image *) NULL)
1581 return((Image *) NULL);
1582 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1583}
1584
1585/*
1586%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1587% %
1588% %
1589% %
1590+ G e t I m a g e R e f e r e n c e C o u n t %
1591% %
1592% %
1593% %
1594%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1595%
1596% GetImageReferenceCount() returns the image reference count.
1597%
1598% The format of the GetReferenceCount method is:
1599%
cristybb503372010-05-27 20:51:26 +00001600% ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001601%
1602% A description of each parameter follows:
1603%
1604% o image: the image.
1605%
1606*/
cristybb503372010-05-27 20:51:26 +00001607MagickExport ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001608{
cristybb503372010-05-27 20:51:26 +00001609 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001610 reference_count;
1611
1612 assert(image != (Image *) NULL);
1613 assert(image->signature == MagickSignature);
1614 if (image->debug != MagickFalse)
1615 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001616 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001617 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001618 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001619 return(reference_count);
1620}
1621
1622/*
1623%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1624% %
1625% %
1626% %
cristy3ed852e2009-09-05 21:47:34 +00001627% 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 %
1628% %
1629% %
1630% %
1631%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1632%
1633% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1634% image. A virtual pixel is any pixel access that is outside the boundaries
1635% of the image cache.
1636%
1637% The format of the GetImageVirtualPixelMethod() method is:
1638%
1639% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1640%
1641% A description of each parameter follows:
1642%
1643% o image: the image.
1644%
1645*/
1646MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1647{
1648 assert(image != (Image *) NULL);
1649 assert(image->signature == MagickSignature);
1650 if (image->debug != MagickFalse)
1651 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1652 return(GetPixelCacheVirtualMethod(image));
1653}
1654
1655/*
1656%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1657% %
1658% %
1659% %
1660% I n t e r p r e t I m a g e F i l e n a m e %
1661% %
1662% %
1663% %
1664%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1665%
1666% InterpretImageFilename() interprets embedded characters in an image filename.
1667% The filename length is returned.
1668%
1669% The format of the InterpretImageFilename method is:
1670%
1671% size_t InterpretImageFilename(const ImageInfo *image_info,
1672% Image *image,const char *format,int value,char *filename)
1673%
1674% A description of each parameter follows.
1675%
1676% o image_info: the image info..
1677%
1678% o image: the image.
1679%
1680% o format: A filename describing the format to use to write the numeric
1681% argument. Only the first numeric format identifier is replaced.
1682%
1683% o value: Numeric value to substitute into format filename.
1684%
1685% o filename: return the formatted filename in this character buffer.
1686%
1687*/
1688MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1689 Image *image,const char *format,int value,char *filename)
1690{
1691 char
1692 *q;
1693
1694 int
1695 c;
1696
1697 MagickBooleanType
1698 canonical;
1699
1700 register const char
1701 *p;
1702
1703 canonical=MagickFalse;
1704 (void) CopyMagickString(filename,format,MaxTextExtent);
1705 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1706 {
1707 q=(char *) p+1;
1708 if (*q == '%')
1709 {
1710 p=q+1;
1711 continue;
1712 }
1713 if (*q == '0')
1714 {
cristybb503372010-05-27 20:51:26 +00001715 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001716 value;
1717
cristybb503372010-05-27 20:51:26 +00001718 value=(ssize_t) strtol(q,&q,10);
cristy3ed852e2009-09-05 21:47:34 +00001719 }
1720 switch (*q)
1721 {
1722 case 'd':
1723 case 'o':
1724 case 'x':
1725 {
1726 q++;
1727 c=(*q);
1728 *q='\0';
1729 (void) FormatMagickString(filename+(p-format),(size_t) (MaxTextExtent-
1730 (p-format)),p,value);
1731 *q=c;
1732 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1733 canonical=MagickTrue;
1734 if (*(q-1) != '%')
1735 break;
1736 p++;
1737 break;
1738 }
1739 case '[':
1740 {
1741 char
1742 pattern[MaxTextExtent];
1743
1744 const char
1745 *value;
1746
cristy3ed852e2009-09-05 21:47:34 +00001747 register char
1748 *r;
1749
cristybb503372010-05-27 20:51:26 +00001750 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001751 i;
1752
cristycb6d09b2010-06-19 01:59:36 +00001753 ssize_t
1754 depth;
1755
cristy3ed852e2009-09-05 21:47:34 +00001756 /*
1757 Image option.
1758 */
1759 if (strchr(p,']') == (char *) NULL)
1760 break;
1761 depth=1;
1762 r=q+1;
1763 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1764 {
1765 if (*r == '[')
1766 depth++;
1767 if (*r == ']')
1768 depth--;
1769 if (depth <= 0)
1770 break;
1771 pattern[i]=(*r++);
1772 }
1773 pattern[i]='\0';
1774 if (LocaleNCompare(pattern,"filename:",9) != 0)
1775 break;
1776 value=(const char *) NULL;
1777 if ((image_info != (const ImageInfo *) NULL) &&
1778 (image != (const Image *) NULL))
cristy86fe49e2010-06-25 01:18:11 +00001779 value=GetMagickProperty(image_info,image,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001780 else
1781 if (image != (Image *) NULL)
cristy86fe49e2010-06-25 01:18:11 +00001782 value=GetImageProperty(image,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001783 else
1784 if (image_info != (ImageInfo *) NULL)
cristy86fe49e2010-06-25 01:18:11 +00001785 value=GetImageOption(image_info,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001786 if (value == (const char *) NULL)
1787 break;
1788 q--;
1789 c=(*q);
1790 *q='\0';
1791 (void) CopyMagickString(filename+(p-format),value,(size_t)
1792 (MaxTextExtent-(p-format)));
1793 *q=c;
1794 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1795 canonical=MagickTrue;
1796 if (*(q-1) != '%')
1797 break;
1798 p++;
1799 break;
1800 }
1801 default:
1802 break;
1803 }
1804 }
1805 for (q=filename; *q != '\0'; q++)
1806 if ((*q == '%') && (*(q+1) == '%'))
1807 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1808 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:
3750 case UndefinedType:
3751 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% %
cristy3ed852e2009-09-05 21:47:34 +00003800% S t r i p I m a g e %
3801% %
3802% %
3803% %
3804%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3805%
cristy376bda92009-12-22 21:15:23 +00003806% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00003807%
3808% The format of the StripImage method is:
3809%
3810% MagickBooleanType StripImage(Image *image)
3811%
3812% A description of each parameter follows:
3813%
3814% o image: the image.
3815%
3816*/
3817MagickExport MagickBooleanType StripImage(Image *image)
3818{
3819 assert(image != (Image *) NULL);
3820 if (image->debug != MagickFalse)
3821 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3822 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00003823 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00003824 (void) DeleteImageProperty(image,"date:create");
3825 (void) DeleteImageProperty(image,"date:modify");
cristy3ed852e2009-09-05 21:47:34 +00003826 return(MagickTrue);
3827}
3828
3829/*
3830%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3831% %
3832% %
3833% %
3834+ S y n c I m a g e %
3835% %
3836% %
3837% %
3838%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3839%
3840% SyncImage() initializes the red, green, and blue intensities of each pixel
3841% as defined by the colormap index.
3842%
3843% The format of the SyncImage method is:
3844%
3845% MagickBooleanType SyncImage(Image *image)
3846%
3847% A description of each parameter follows:
3848%
3849% o image: the image.
3850%
3851*/
3852
3853static inline IndexPacket PushColormapIndex(Image *image,
cristybb503372010-05-27 20:51:26 +00003854 const size_t index,MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00003855{
3856 if (index < image->colors)
3857 return((IndexPacket) index);
3858 *range_exception=MagickTrue;
3859 return((IndexPacket) 0);
3860}
3861
3862MagickExport MagickBooleanType SyncImage(Image *image)
3863{
3864 CacheView
3865 *image_view;
3866
3867 ExceptionInfo
3868 *exception;
3869
cristy3ed852e2009-09-05 21:47:34 +00003870 MagickBooleanType
3871 range_exception,
3872 status;
3873
cristycb6d09b2010-06-19 01:59:36 +00003874 ssize_t
3875 y;
3876
cristy3ed852e2009-09-05 21:47:34 +00003877 assert(image != (Image *) NULL);
3878 if (image->debug != MagickFalse)
3879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3880 assert(image->signature == MagickSignature);
3881 if (image->storage_class == DirectClass)
3882 return(MagickFalse);
3883 range_exception=MagickFalse;
3884 status=MagickTrue;
3885 exception=(&image->exception);
3886 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00003887#if defined(MAGICKCORE_OPENMP_SUPPORT)
3888 #pragma omp parallel for schedule(dynamic,4) shared(status)
3889#endif
cristybb503372010-05-27 20:51:26 +00003890 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003891 {
3892 IndexPacket
3893 index;
3894
3895 PixelPacket
3896 pixel;
3897
3898 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00003899 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00003900
cristy3ed852e2009-09-05 21:47:34 +00003901 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003902 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003903
cristycb6d09b2010-06-19 01:59:36 +00003904 register ssize_t
3905 x;
3906
cristy48974b92009-12-19 02:36:06 +00003907 if (status == MagickFalse)
3908 continue;
cristy3ed852e2009-09-05 21:47:34 +00003909 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3910 if (q == (PixelPacket *) NULL)
3911 {
3912 status=MagickFalse;
3913 continue;
3914 }
3915 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00003916 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003917 {
cristybb503372010-05-27 20:51:26 +00003918 index=PushColormapIndex(image,(size_t) indexes[x],
cristy3ed852e2009-09-05 21:47:34 +00003919 &range_exception);
cristybb503372010-05-27 20:51:26 +00003920 pixel=image->colormap[(ssize_t) index];
cristy3ed852e2009-09-05 21:47:34 +00003921 q->red=pixel.red;
3922 q->green=pixel.green;
3923 q->blue=pixel.blue;
cristyd0272592010-04-21 01:01:49 +00003924 if (image->matte != MagickFalse)
3925 q->opacity=pixel.opacity;
cristy3ed852e2009-09-05 21:47:34 +00003926 q++;
3927 }
3928 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3929 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003930 }
3931 image_view=DestroyCacheView(image_view);
3932 if (range_exception != MagickFalse)
3933 (void) ThrowMagickException(&image->exception,GetMagickModule(),
3934 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
3935 return(status);
3936}
cristy1626d332009-11-10 16:58:17 +00003937
3938/*
3939%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3940% %
3941% %
3942% %
3943% S y n c I m a g e S e t t i n g s %
3944% %
3945% %
3946% %
3947%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3948%
3949% SyncImageSettings() sync the image info options to the image.
3950%
3951% The format of the SyncImageSettings method is:
3952%
3953% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3954% Image *image)
3955% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
3956% Image *image)
3957%
3958% A description of each parameter follows:
3959%
3960% o image_info: the image info.
3961%
3962% o image: the image.
3963%
3964*/
3965
3966MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
3967 Image *images)
3968{
3969 Image
3970 *image;
3971
3972 assert(image_info != (const ImageInfo *) NULL);
3973 assert(image_info->signature == MagickSignature);
3974 assert(images != (Image *) NULL);
3975 assert(images->signature == MagickSignature);
3976 if (images->debug != MagickFalse)
3977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3978 image=images;
3979 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
3980 (void) SyncImageSettings(image_info,image);
3981 (void) DeleteImageOption(image_info,"page");
3982 return(MagickTrue);
3983}
3984
3985MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
3986 Image *image)
3987{
3988 char
3989 property[MaxTextExtent];
3990
3991 const char
cristy9a703812010-07-26 14:50:29 +00003992 *option,
3993 *value;
cristy1626d332009-11-10 16:58:17 +00003994
3995 GeometryInfo
3996 geometry_info;
3997
3998 MagickStatusType
3999 flags;
4000
cristy19eb6412010-04-23 14:42:29 +00004001 ResolutionType
4002 units;
4003
cristy1626d332009-11-10 16:58:17 +00004004 /*
4005 Sync image options.
4006 */
4007 assert(image_info != (const ImageInfo *) NULL);
4008 assert(image_info->signature == MagickSignature);
4009 assert(image != (Image *) NULL);
4010 assert(image->signature == MagickSignature);
4011 if (image->debug != MagickFalse)
4012 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4013 option=GetImageOption(image_info,"background");
4014 if (option != (const char *) NULL)
4015 (void) QueryColorDatabase(option,&image->background_color,
4016 &image->exception);
4017 option=GetImageOption(image_info,"bias");
4018 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00004019 image->bias=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00004020 option=GetImageOption(image_info,"black-point-compensation");
4021 if (option != (const char *) NULL)
4022 image->black_point_compensation=(MagickBooleanType) ParseMagickOption(
4023 MagickBooleanOptions,MagickFalse,option);
4024 option=GetImageOption(image_info,"blue-primary");
4025 if (option != (const char *) NULL)
4026 {
4027 flags=ParseGeometry(option,&geometry_info);
4028 image->chromaticity.blue_primary.x=geometry_info.rho;
4029 image->chromaticity.blue_primary.y=geometry_info.sigma;
4030 if ((flags & SigmaValue) == 0)
4031 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4032 }
4033 option=GetImageOption(image_info,"bordercolor");
4034 if (option != (const char *) NULL)
4035 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4036 option=GetImageOption(image_info,"colors");
4037 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004038 image->colors=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004039 option=GetImageOption(image_info,"compose");
4040 if (option != (const char *) NULL)
4041 image->compose=(CompositeOperator) ParseMagickOption(MagickComposeOptions,
4042 MagickFalse,option);
4043 option=GetImageOption(image_info,"compress");
4044 if (option != (const char *) NULL)
4045 image->compression=(CompressionType) ParseMagickOption(
4046 MagickCompressOptions,MagickFalse,option);
4047 option=GetImageOption(image_info,"debug");
4048 if (option != (const char *) NULL)
4049 image->debug=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4050 MagickFalse,option);
cristydd5f5912010-07-31 23:37:23 +00004051 option=GetImageOption(image_info,"density");
4052 if (option != (const char *) NULL)
4053 {
4054 GeometryInfo
4055 geometry_info;
4056
4057 /*
4058 Set image density.
4059 */
4060 flags=ParseGeometry(option,&geometry_info);
4061 image->x_resolution=geometry_info.rho;
4062 image->y_resolution=geometry_info.sigma;
4063 if ((flags & SigmaValue) == 0)
4064 image->y_resolution=image->x_resolution;
4065 }
cristy1626d332009-11-10 16:58:17 +00004066 option=GetImageOption(image_info,"depth");
4067 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004068 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004069 option=GetImageOption(image_info,"endian");
4070 if (option != (const char *) NULL)
4071 image->endian=(EndianType) ParseMagickOption(MagickEndianOptions,
4072 MagickFalse,option);
4073 if (image_info->extract != (char *) NULL)
4074 (void) ParseAbsoluteGeometry(image_info->extract,&image->extract_info);
4075 option=GetImageOption(image_info,"filter");
4076 if (option != (const char *) NULL)
4077 image->filter=(FilterTypes) ParseMagickOption(MagickFilterOptions,
4078 MagickFalse,option);
4079 option=GetImageOption(image_info,"fuzz");
4080 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00004081 image->fuzz=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00004082 option=GetImageOption(image_info,"gravity");
4083 if (option != (const char *) NULL)
4084 image->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4085 MagickFalse,option);
4086 option=GetImageOption(image_info,"green-primary");
4087 if (option != (const char *) NULL)
4088 {
4089 flags=ParseGeometry(option,&geometry_info);
4090 image->chromaticity.green_primary.x=geometry_info.rho;
4091 image->chromaticity.green_primary.y=geometry_info.sigma;
4092 if ((flags & SigmaValue) == 0)
4093 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4094 }
4095 option=GetImageOption(image_info,"intent");
4096 if (option != (const char *) NULL)
4097 image->rendering_intent=(RenderingIntent) ParseMagickOption(
4098 MagickIntentOptions,MagickFalse,option);
4099 option=GetImageOption(image_info,"interlace");
4100 if (option != (const char *) NULL)
4101 image->interlace=(InterlaceType) ParseMagickOption(MagickInterlaceOptions,
4102 MagickFalse,option);
4103 option=GetImageOption(image_info,"interpolate");
4104 if (option != (const char *) NULL)
4105 image->interpolate=(InterpolatePixelMethod) ParseMagickOption(
4106 MagickInterpolateOptions,MagickFalse,option);
4107 option=GetImageOption(image_info,"loop");
4108 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004109 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004110 option=GetImageOption(image_info,"mattecolor");
4111 if (option != (const char *) NULL)
4112 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4113 option=GetImageOption(image_info,"orient");
4114 if (option != (const char *) NULL)
4115 image->orientation=(OrientationType) ParseMagickOption(
4116 MagickOrientationOptions,MagickFalse,option);
cristy9a703812010-07-26 14:50:29 +00004117 option=GetImageOption(image_info,"page");
4118 if (option != (const char *) NULL)
4119 {
4120 char
4121 *geometry;
4122
4123 geometry=GetPageGeometry(option);
4124 flags=ParseAbsoluteGeometry(geometry,&image->page);
4125 geometry=DestroyString(geometry);
4126 }
cristy1626d332009-11-10 16:58:17 +00004127 option=GetImageOption(image_info,"quality");
4128 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004129 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004130 option=GetImageOption(image_info,"red-primary");
4131 if (option != (const char *) NULL)
4132 {
4133 flags=ParseGeometry(option,&geometry_info);
4134 image->chromaticity.red_primary.x=geometry_info.rho;
4135 image->chromaticity.red_primary.y=geometry_info.sigma;
4136 if ((flags & SigmaValue) == 0)
4137 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4138 }
4139 if (image_info->quality != UndefinedCompressionQuality)
4140 image->quality=image_info->quality;
4141 option=GetImageOption(image_info,"scene");
4142 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004143 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004144 option=GetImageOption(image_info,"taint");
4145 if (option != (const char *) NULL)
4146 image->taint=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4147 MagickFalse,option);
4148 option=GetImageOption(image_info,"tile-offset");
4149 if (option != (const char *) NULL)
4150 {
4151 char
4152 *geometry;
4153
4154 geometry=GetPageGeometry(option);
4155 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4156 geometry=DestroyString(geometry);
4157 }
4158 option=GetImageOption(image_info,"transparent-color");
4159 if (option != (const char *) NULL)
4160 (void) QueryColorDatabase(option,&image->transparent_color,
4161 &image->exception);
4162 option=GetImageOption(image_info,"type");
4163 if (option != (const char *) NULL)
4164 image->type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
4165 option);
4166 option=GetImageOption(image_info,"units");
4167 if (option != (const char *) NULL)
cristy19eb6412010-04-23 14:42:29 +00004168 units=(ResolutionType) ParseMagickOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00004169 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00004170 else
4171 units = image_info->units;
4172 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00004173 {
cristy19eb6412010-04-23 14:42:29 +00004174 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00004175 switch (image->units)
4176 {
4177 case PixelsPerInchResolution:
4178 {
cristy19eb6412010-04-23 14:42:29 +00004179 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00004180 {
4181 image->x_resolution/=2.54;
4182 image->y_resolution/=2.54;
4183 }
4184 break;
4185 }
4186 case PixelsPerCentimeterResolution:
4187 {
cristy19eb6412010-04-23 14:42:29 +00004188 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00004189 {
cristybb503372010-05-27 20:51:26 +00004190 image->x_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004191 image->x_resolution+0.5))/100.0;
cristybb503372010-05-27 20:51:26 +00004192 image->y_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004193 image->y_resolution+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00004194 }
4195 break;
4196 }
4197 default:
4198 break;
4199 }
cristy19eb6412010-04-23 14:42:29 +00004200 image->units=units;
cristy1626d332009-11-10 16:58:17 +00004201 }
4202 option=GetImageOption(image_info,"white-point");
4203 if (option != (const char *) NULL)
4204 {
4205 flags=ParseGeometry(option,&geometry_info);
4206 image->chromaticity.white_point.x=geometry_info.rho;
4207 image->chromaticity.white_point.y=geometry_info.sigma;
4208 if ((flags & SigmaValue) == 0)
4209 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4210 }
4211 ResetImageOptionIterator(image_info);
4212 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4213 {
4214 value=GetImageOption(image_info,option);
4215 if (value != (const char *) NULL)
4216 {
4217 (void) FormatMagickString(property,MaxTextExtent,"%s",option);
4218 (void) SetImageArtifact(image,property,value);
4219 }
4220 option=GetNextImageOption(image_info);
4221 }
4222 return(MagickTrue);
4223}