blob: a76647536069b732df83b5c2264ffd682673dc17 [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)
cristy042ee782011-04-22 18:48:30 +0000291 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
cristye412c892010-07-26 12:31:36 +0000292 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%
cristy4ca38e22011-02-10 02:57:49 +0000398% Image *AppendImages(const Image *images,const MagickBooleanType stack,
cristy3ed852e2009-09-05 21:47:34 +0000399% ExceptionInfo *exception)
400%
401% A description of each parameter follows:
402%
cristy4ca38e22011-02-10 02:57:49 +0000403% o images: the image sequence.
cristy3ed852e2009-09-05 21:47:34 +0000404%
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*/
cristy4ca38e22011-02-10 02:57:49 +0000410MagickExport Image *AppendImages(const Image *images,
cristy3ed852e2009-09-05 21:47:34 +0000411 const MagickBooleanType stack,ExceptionInfo *exception)
412{
413#define AppendImageTag "Append/Image"
414
415 CacheView
416 *append_view,
417 *image_view;
418
cristy4ca38e22011-02-10 02:57:49 +0000419 const Image
420 *image;
421
cristy3ed852e2009-09-05 21:47:34 +0000422 Image
423 *append_image;
424
cristy3ed852e2009-09-05 21:47:34 +0000425 MagickBooleanType
426 matte,
427 proceed,
428 status;
429
cristybb503372010-05-27 20:51:26 +0000430 MagickOffsetType
431 n;
432
cristy3ed852e2009-09-05 21:47:34 +0000433 RectangleInfo
434 geometry;
435
436 register const Image
437 *next;
438
cristybb503372010-05-27 20:51:26 +0000439 size_t
cristy3ed852e2009-09-05 21:47:34 +0000440 height,
441 number_images,
442 width;
443
cristybb503372010-05-27 20:51:26 +0000444 ssize_t
445 x_offset,
446 y,
447 y_offset;
448
cristy3ed852e2009-09-05 21:47:34 +0000449 /*
cristy7c6dc152011-02-11 14:10:55 +0000450 Compute maximum area of appended area.
cristy3ed852e2009-09-05 21:47:34 +0000451 */
cristy4ca38e22011-02-10 02:57:49 +0000452 assert(images != (Image *) NULL);
453 assert(images->signature == MagickSignature);
454 if (images->debug != MagickFalse)
455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy3ed852e2009-09-05 21:47:34 +0000456 assert(exception != (ExceptionInfo *) NULL);
457 assert(exception->signature == MagickSignature);
cristy4ca38e22011-02-10 02:57:49 +0000458 image=images;
cristy3ed852e2009-09-05 21:47:34 +0000459 matte=image->matte;
460 number_images=1;
461 width=image->columns;
462 height=image->rows;
463 next=GetNextImageInList(image);
464 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
465 {
466 if (next->matte != MagickFalse)
467 matte=MagickTrue;
468 number_images++;
469 if (stack != MagickFalse)
470 {
471 if (next->columns > width)
472 width=next->columns;
473 height+=next->rows;
474 continue;
475 }
476 width+=next->columns;
477 if (next->rows > height)
478 height=next->rows;
479 }
480 /*
cristy7c6dc152011-02-11 14:10:55 +0000481 Append images.
cristy3ed852e2009-09-05 21:47:34 +0000482 */
483 append_image=CloneImage(image,width,height,MagickTrue,exception);
484 if (append_image == (Image *) NULL)
485 return((Image *) NULL);
486 if (SetImageStorageClass(append_image,DirectClass) == MagickFalse)
487 {
488 InheritException(exception,&append_image->exception);
489 append_image=DestroyImage(append_image);
490 return((Image *) NULL);
491 }
492 append_image->matte=matte;
493 (void) SetImageBackgroundColor(append_image);
494 status=MagickTrue;
495 x_offset=0;
496 y_offset=0;
497 append_view=AcquireCacheView(append_image);
cristybb503372010-05-27 20:51:26 +0000498 for (n=0; n < (MagickOffsetType) number_images; n++)
cristy3ed852e2009-09-05 21:47:34 +0000499 {
500 SetGeometry(append_image,&geometry);
501 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
502 if (stack != MagickFalse)
503 x_offset-=geometry.x;
504 else
505 y_offset-=geometry.y;
506 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +0000507#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy1a2bd532010-11-19 02:53:15 +0000508 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
cristy3ed852e2009-09-05 21:47:34 +0000509#endif
cristybb503372010-05-27 20:51:26 +0000510 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000511 {
512 MagickBooleanType
513 sync;
514
515 register const IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000516 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000517
518 register const PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000519 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000520
521 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000522 *restrict append_indexes;
cristy3ed852e2009-09-05 21:47:34 +0000523
cristy3ed852e2009-09-05 21:47:34 +0000524 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000525 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000526
cristycb6d09b2010-06-19 01:59:36 +0000527 register ssize_t
528 x;
529
cristy3ed852e2009-09-05 21:47:34 +0000530 if (status == MagickFalse)
531 continue;
532 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
533 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
534 image->columns,1,exception);
535 if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
536 {
537 status=MagickFalse;
538 continue;
539 }
540 indexes=GetCacheViewVirtualIndexQueue(image_view);
541 append_indexes=GetCacheViewAuthenticIndexQueue(append_view);
cristybb503372010-05-27 20:51:26 +0000542 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000543 {
cristyce70c172010-01-07 17:15:30 +0000544 SetRedPixelComponent(q,GetRedPixelComponent(p));
545 SetGreenPixelComponent(q,GetGreenPixelComponent(p));
546 SetBluePixelComponent(q,GetBluePixelComponent(p));
547 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000548 if (image->matte != MagickFalse)
cristyce70c172010-01-07 17:15:30 +0000549 SetOpacityPixelComponent(q,GetOpacityPixelComponent(p));
cristyff775322011-02-24 15:05:25 +0000550 if ((image->colorspace == CMYKColorspace) &&
551 (append_image->colorspace == CMYKColorspace))
cristy3ed852e2009-09-05 21:47:34 +0000552 append_indexes[x]=indexes[x];
553 p++;
554 q++;
555 }
556 sync=SyncCacheViewAuthenticPixels(append_view,exception);
557 if (sync == MagickFalse)
cristya65f35b2010-04-20 01:10:41 +0000558 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000559 }
560 image_view=DestroyCacheView(image_view);
561 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
562 if (proceed == MagickFalse)
563 break;
564 if (stack == MagickFalse)
565 {
cristyeaedf062010-05-29 22:36:02 +0000566 x_offset+=(ssize_t) image->columns;
cristy3ed852e2009-09-05 21:47:34 +0000567 y_offset=0;
568 }
569 else
570 {
571 x_offset=0;
cristyeaedf062010-05-29 22:36:02 +0000572 y_offset+=(ssize_t) image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000573 }
574 image=GetNextImageInList(image);
575 }
576 append_view=DestroyCacheView(append_view);
577 if (status == MagickFalse)
578 append_image=DestroyImage(append_image);
579 return(append_image);
580}
581
582/*
583%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
584% %
585% %
586% %
cristy3ed852e2009-09-05 21:47:34 +0000587% C a t c h I m a g e E x c e p t i o n %
588% %
589% %
590% %
591%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
592%
593% CatchImageException() returns if no exceptions are found in the image
594% sequence, otherwise it determines the most severe exception and reports
595% it as a warning or error depending on the severity.
596%
597% The format of the CatchImageException method is:
598%
599% ExceptionType CatchImageException(Image *image)
600%
601% A description of each parameter follows:
602%
603% o image: An image sequence.
604%
605*/
606MagickExport ExceptionType CatchImageException(Image *image)
607{
608 ExceptionInfo
609 *exception;
610
611 ExceptionType
612 severity;
613
614 assert(image != (const Image *) NULL);
615 assert(image->signature == MagickSignature);
616 if (image->debug != MagickFalse)
617 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
618 exception=AcquireExceptionInfo();
619 GetImageException(image,exception);
620 CatchException(exception);
621 severity=exception->severity;
622 exception=DestroyExceptionInfo(exception);
623 return(severity);
624}
625
626/*
627%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628% %
629% %
630% %
631% C l i p I m a g e P a t h %
632% %
633% %
634% %
635%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636%
637% ClipImagePath() sets the image clip mask based any clipping path information
638% if it exists.
639%
640% The format of the ClipImagePath method is:
641%
642% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
643% const MagickBooleanType inside)
644%
645% A description of each parameter follows:
646%
647% o image: the image.
648%
649% o pathname: name of clipping path resource. If name is preceded by #, use
650% clipping path numbered by name.
651%
652% o inside: if non-zero, later operations take effect inside clipping path.
653% Otherwise later operations take effect outside clipping path.
654%
655*/
656
657MagickExport MagickBooleanType ClipImage(Image *image)
658{
659 return(ClipImagePath(image,"#1",MagickTrue));
660}
661
662MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
663 const MagickBooleanType inside)
664{
665#define ClipImagePathTag "ClipPath/Image"
666
667 char
668 *property;
669
670 const char
671 *value;
672
673 Image
674 *clip_mask;
675
676 ImageInfo
677 *image_info;
678
679 assert(image != (const Image *) NULL);
680 assert(image->signature == MagickSignature);
681 if (image->debug != MagickFalse)
682 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
683 assert(pathname != NULL);
684 property=AcquireString(pathname);
685 (void) FormatMagickString(property,MaxTextExtent,"8BIM:1999,2998:%s",
686 pathname);
687 value=GetImageProperty(image,property);
688 property=DestroyString(property);
689 if (value == (const char *) NULL)
690 {
691 ThrowFileException(&image->exception,OptionError,"NoClipPathDefined",
692 image->filename);
693 return(MagickFalse);
694 }
695 image_info=AcquireImageInfo();
696 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
697 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
698 clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception);
699 image_info=DestroyImageInfo(image_info);
700 if (clip_mask == (Image *) NULL)
701 return(MagickFalse);
702 if (clip_mask->storage_class == PseudoClass)
703 {
704 (void) SyncImage(clip_mask);
705 if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse)
706 return(MagickFalse);
707 }
708 if (inside == MagickFalse)
709 (void) NegateImage(clip_mask,MagickFalse);
710 (void) FormatMagickString(clip_mask->magick_filename,MaxTextExtent,
711 "8BIM:1999,2998:%s\nPS",pathname);
712 (void) SetImageClipMask(image,clip_mask);
713 clip_mask=DestroyImage(clip_mask);
714 return(MagickTrue);
715}
716
717/*
718%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
719% %
720% %
721% %
722% C l o n e I m a g e %
723% %
724% %
725% %
726%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
727%
728% CloneImage() copies an image and returns the copy as a new image object.
anthony96f11ee2011-03-23 08:22:54 +0000729%
cristy3ed852e2009-09-05 21:47:34 +0000730% If the specified columns and rows is 0, an exact copy of the image is
731% returned, otherwise the pixel data is undefined and must be initialized
732% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
733% failure, a NULL image is returned and exception describes the reason for the
734% failure.
735%
736% The format of the CloneImage method is:
737%
cristybb503372010-05-27 20:51:26 +0000738% Image *CloneImage(const Image *image,const size_t columns,
739% const size_t rows,const MagickBooleanType orphan,
cristy3ed852e2009-09-05 21:47:34 +0000740% ExceptionInfo *exception)
741%
742% A description of each parameter follows:
743%
744% o image: the image.
745%
746% o columns: the number of columns in the cloned image.
747%
748% o rows: the number of rows in the cloned image.
749%
750% o detach: With a value other than 0, the cloned image is detached from
751% its parent I/O stream.
752%
753% o exception: return any errors or warnings in this structure.
754%
755*/
cristybb503372010-05-27 20:51:26 +0000756MagickExport Image *CloneImage(const Image *image,const size_t columns,
cristybee00932011-01-15 20:28:27 +0000757 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000758{
759 Image
760 *clone_image;
761
762 MagickRealType
763 scale;
764
765 size_t
766 length;
767
768 /*
769 Clone the image.
770 */
771 assert(image != (const Image *) NULL);
772 assert(image->signature == MagickSignature);
773 if (image->debug != MagickFalse)
774 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
775 assert(exception != (ExceptionInfo *) NULL);
776 assert(exception->signature == MagickSignature);
cristy73bd4a52010-10-05 11:24:23 +0000777 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000778 if (clone_image == (Image *) NULL)
779 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
780 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
781 clone_image->signature=MagickSignature;
782 clone_image->storage_class=image->storage_class;
783 clone_image->colorspace=image->colorspace;
784 clone_image->matte=image->matte;
785 clone_image->columns=image->columns;
786 clone_image->rows=image->rows;
787 clone_image->dither=image->dither;
788 if (image->colormap != (PixelPacket *) NULL)
789 {
790 /*
791 Allocate and copy the image colormap.
792 */
793 clone_image->colors=image->colors;
794 length=(size_t) image->colors;
795 clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
796 sizeof(*clone_image->colormap));
797 if (clone_image->colormap == (PixelPacket *) NULL)
798 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
799 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
800 sizeof(*clone_image->colormap));
801 }
802 (void) CloneImageProfiles(clone_image,image);
803 (void) CloneImageProperties(clone_image,image);
804 (void) CloneImageArtifacts(clone_image,image);
805 GetTimerInfo(&clone_image->timer);
806 GetExceptionInfo(&clone_image->exception);
807 InheritException(&clone_image->exception,&image->exception);
808 if (image->ascii85 != (void *) NULL)
809 Ascii85Initialize(clone_image);
810 clone_image->magick_columns=image->magick_columns;
811 clone_image->magick_rows=image->magick_rows;
812 clone_image->type=image->type;
813 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
814 MaxTextExtent);
815 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
816 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
817 clone_image->progress_monitor=image->progress_monitor;
818 clone_image->client_data=image->client_data;
819 clone_image->reference_count=1;
cristybee00932011-01-15 20:28:27 +0000820 clone_image->next=image->next;
821 clone_image->previous=image->previous;
cristy3ed852e2009-09-05 21:47:34 +0000822 clone_image->list=NewImageList();
823 clone_image->clip_mask=NewImageList();
824 clone_image->mask=NewImageList();
825 if (detach == MagickFalse)
826 clone_image->blob=ReferenceBlob(image->blob);
827 else
cristybee00932011-01-15 20:28:27 +0000828 {
829 clone_image->next=NewImageList();
830 clone_image->previous=NewImageList();
831 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
832 }
cristy73724512010-04-12 14:43:14 +0000833 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000834 clone_image->debug=IsEventLogging();
835 clone_image->semaphore=AllocateSemaphoreInfo();
836 if ((columns == 0) && (rows == 0))
837 {
838 if (image->montage != (char *) NULL)
839 (void) CloneString(&clone_image->montage,image->montage);
840 if (image->directory != (char *) NULL)
841 (void) CloneString(&clone_image->directory,image->directory);
842 if (image->clip_mask != (Image *) NULL)
843 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
844 exception);
845 if (image->mask != (Image *) NULL)
846 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
847 clone_image->cache=ReferencePixelCache(image->cache);
848 return(clone_image);
849 }
cristy1ab35fb2011-04-15 01:25:56 +0000850 if ((columns == image->columns) && (rows == image->rows))
851 {
852 if (image->clip_mask != (Image *) NULL)
853 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
854 exception);
855 if (image->mask != (Image *) NULL)
856 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
857 }
cristy3ed852e2009-09-05 21:47:34 +0000858 scale=(MagickRealType) columns/(MagickRealType) image->columns;
cristybb503372010-05-27 20:51:26 +0000859 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
860 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
861 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000862 scale=(MagickRealType) rows/(MagickRealType) image->rows;
cristybb503372010-05-27 20:51:26 +0000863 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
864 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
865 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000866 clone_image->columns=columns;
867 clone_image->rows=rows;
868 clone_image->cache=ClonePixelCache(image->cache);
869 return(clone_image);
870}
871
872/*
873%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
874% %
875% %
876% %
877% C l o n e I m a g e I n f o %
878% %
879% %
880% %
881%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882%
883% CloneImageInfo() makes a copy of the given image info structure. If
884% NULL is specified, a new image info structure is created initialized to
885% default values.
886%
887% The format of the CloneImageInfo method is:
888%
889% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
890%
891% A description of each parameter follows:
892%
893% o image_info: the image info.
894%
895*/
896MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
897{
898 ImageInfo
899 *clone_info;
900
901 clone_info=AcquireImageInfo();
902 if (image_info == (ImageInfo *) NULL)
903 return(clone_info);
904 clone_info->compression=image_info->compression;
905 clone_info->temporary=image_info->temporary;
906 clone_info->adjoin=image_info->adjoin;
907 clone_info->antialias=image_info->antialias;
908 clone_info->scene=image_info->scene;
909 clone_info->number_scenes=image_info->number_scenes;
910 clone_info->depth=image_info->depth;
911 if (image_info->size != (char *) NULL)
912 (void) CloneString(&clone_info->size,image_info->size);
913 if (image_info->extract != (char *) NULL)
914 (void) CloneString(&clone_info->extract,image_info->extract);
915 if (image_info->scenes != (char *) NULL)
916 (void) CloneString(&clone_info->scenes,image_info->scenes);
917 if (image_info->page != (char *) NULL)
918 (void) CloneString(&clone_info->page,image_info->page);
919 clone_info->interlace=image_info->interlace;
920 clone_info->endian=image_info->endian;
921 clone_info->units=image_info->units;
922 clone_info->quality=image_info->quality;
923 if (image_info->sampling_factor != (char *) NULL)
924 (void) CloneString(&clone_info->sampling_factor,
925 image_info->sampling_factor);
926 if (image_info->server_name != (char *) NULL)
927 (void) CloneString(&clone_info->server_name,image_info->server_name);
928 if (image_info->font != (char *) NULL)
929 (void) CloneString(&clone_info->font,image_info->font);
930 if (image_info->texture != (char *) NULL)
931 (void) CloneString(&clone_info->texture,image_info->texture);
932 if (image_info->density != (char *) NULL)
933 (void) CloneString(&clone_info->density,image_info->density);
934 clone_info->pointsize=image_info->pointsize;
935 clone_info->fuzz=image_info->fuzz;
936 clone_info->pen=image_info->pen;
937 clone_info->background_color=image_info->background_color;
938 clone_info->border_color=image_info->border_color;
939 clone_info->matte_color=image_info->matte_color;
940 clone_info->transparent_color=image_info->transparent_color;
941 clone_info->dither=image_info->dither;
942 clone_info->monochrome=image_info->monochrome;
943 clone_info->colors=image_info->colors;
944 clone_info->colorspace=image_info->colorspace;
945 clone_info->type=image_info->type;
946 clone_info->orientation=image_info->orientation;
947 clone_info->preview_type=image_info->preview_type;
948 clone_info->group=image_info->group;
949 clone_info->ping=image_info->ping;
950 clone_info->verbose=image_info->verbose;
951 if (image_info->view != (char *) NULL)
952 (void) CloneString(&clone_info->view,image_info->view);
953 if (image_info->authenticate != (char *) NULL)
954 (void) CloneString(&clone_info->authenticate,image_info->authenticate);
955 (void) CloneImageOptions(clone_info,image_info);
956 clone_info->progress_monitor=image_info->progress_monitor;
957 clone_info->client_data=image_info->client_data;
958 clone_info->cache=image_info->cache;
959 if (image_info->cache != (void *) NULL)
960 clone_info->cache=ReferencePixelCache(image_info->cache);
961 if (image_info->profile != (void *) NULL)
962 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
963 image_info->profile);
964 SetImageInfoFile(clone_info,image_info->file);
965 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
966 clone_info->stream=image_info->stream;
967 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
968 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
969 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
970 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
971 (void) CopyMagickString(clone_info->filename,image_info->filename,
972 MaxTextExtent);
973 clone_info->subimage=image_info->scene; /* deprecated */
974 clone_info->subrange=image_info->number_scenes; /* deprecated */
975 clone_info->channel=image_info->channel;
976 clone_info->debug=IsEventLogging();
977 clone_info->signature=image_info->signature;
978 return(clone_info);
979}
980
981/*
982%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
983% %
984% %
985% %
986% C o m b i n e I m a g e s %
987% %
988% %
989% %
990%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
991%
992% CombineImages() combines one or more images into a single image. The
993% grayscale value of the pixels of each image in the sequence is assigned in
994% order to the specified channels of the combined image. The typical
995% ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
996%
997% The format of the CombineImages method is:
998%
999% Image *CombineImages(const Image *image,const ChannelType channel,
1000% ExceptionInfo *exception)
1001%
1002% A description of each parameter follows:
1003%
1004% o image: the image.
1005%
1006% o exception: return any errors or warnings in this structure.
1007%
1008*/
1009MagickExport Image *CombineImages(const Image *image,const ChannelType channel,
1010 ExceptionInfo *exception)
1011{
1012#define CombineImageTag "Combine/Image"
1013
1014 CacheView
1015 *combine_view;
1016
1017 const Image
1018 *next;
1019
1020 Image
1021 *combine_image;
1022
cristy3ed852e2009-09-05 21:47:34 +00001023 MagickBooleanType
1024 status;
1025
cristybb503372010-05-27 20:51:26 +00001026 MagickOffsetType
1027 progress;
1028
1029 ssize_t
1030 y;
1031
cristy3ed852e2009-09-05 21:47:34 +00001032 /*
1033 Ensure the image are the same size.
1034 */
1035 assert(image != (const Image *) NULL);
1036 assert(image->signature == MagickSignature);
1037 if (image->debug != MagickFalse)
1038 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1039 assert(exception != (ExceptionInfo *) NULL);
1040 assert(exception->signature == MagickSignature);
1041 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1042 {
1043 if ((next->columns != image->columns) || (next->rows != image->rows))
1044 ThrowImageException(OptionError,"ImagesAreNotTheSameSize");
1045 }
1046 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1047 if (combine_image == (Image *) NULL)
1048 return((Image *) NULL);
1049 if (SetImageStorageClass(combine_image,DirectClass) == MagickFalse)
1050 {
1051 InheritException(exception,&combine_image->exception);
1052 combine_image=DestroyImage(combine_image);
1053 return((Image *) NULL);
1054 }
1055 if ((channel & OpacityChannel) != 0)
1056 combine_image->matte=MagickTrue;
1057 (void) SetImageBackgroundColor(combine_image);
1058 /*
1059 Combine images.
1060 */
1061 status=MagickTrue;
1062 progress=0;
1063 combine_view=AcquireCacheView(combine_image);
cristybb503372010-05-27 20:51:26 +00001064 for (y=0; y < (ssize_t) combine_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001065 {
1066 CacheView
1067 *image_view;
1068
1069 const Image
1070 *next;
1071
1072 PixelPacket
1073 *pixels;
1074
1075 register const PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001076 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001077
cristy3ed852e2009-09-05 21:47:34 +00001078 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00001079 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001080
cristycb6d09b2010-06-19 01:59:36 +00001081 register ssize_t
1082 x;
1083
cristy3ed852e2009-09-05 21:47:34 +00001084 if (status == MagickFalse)
1085 continue;
1086 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1087 1,exception);
1088 if (pixels == (PixelPacket *) NULL)
1089 {
1090 status=MagickFalse;
1091 continue;
1092 }
1093 next=image;
1094 if (((channel & RedChannel) != 0) && (next != (Image *) NULL))
1095 {
1096 image_view=AcquireCacheView(next);
1097 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1098 if (p == (const PixelPacket *) NULL)
1099 continue;
1100 q=pixels;
cristybb503372010-05-27 20:51:26 +00001101 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001102 {
cristyce70c172010-01-07 17:15:30 +00001103 SetRedPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001104 p++;
1105 q++;
1106 }
1107 image_view=DestroyCacheView(image_view);
1108 next=GetNextImageInList(next);
1109 }
1110 if (((channel & GreenChannel) != 0) && (next != (Image *) NULL))
1111 {
1112 image_view=AcquireCacheView(next);
1113 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1114 if (p == (const PixelPacket *) NULL)
1115 continue;
1116 q=pixels;
cristybb503372010-05-27 20:51:26 +00001117 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001118 {
cristyce70c172010-01-07 17:15:30 +00001119 SetGreenPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001120 p++;
1121 q++;
1122 }
1123 image_view=DestroyCacheView(image_view);
1124 next=GetNextImageInList(next);
1125 }
1126 if (((channel & BlueChannel) != 0) && (next != (Image *) NULL))
1127 {
1128 image_view=AcquireCacheView(next);
1129 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1130 if (p == (const PixelPacket *) NULL)
1131 continue;
1132 q=pixels;
cristybb503372010-05-27 20:51:26 +00001133 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001134 {
cristyce70c172010-01-07 17:15:30 +00001135 SetBluePixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001136 p++;
1137 q++;
1138 }
1139 image_view=DestroyCacheView(image_view);
1140 next=GetNextImageInList(next);
1141 }
1142 if (((channel & OpacityChannel) != 0) && (next != (Image *) NULL))
1143 {
1144 image_view=AcquireCacheView(next);
1145 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1146 if (p == (const PixelPacket *) NULL)
1147 continue;
1148 q=pixels;
cristybb503372010-05-27 20:51:26 +00001149 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001150 {
cristyce70c172010-01-07 17:15:30 +00001151 SetOpacityPixelComponent(q,PixelIntensityToQuantum(p));
cristy3ed852e2009-09-05 21:47:34 +00001152 p++;
1153 q++;
1154 }
1155 image_view=DestroyCacheView(image_view);
1156 next=GetNextImageInList(next);
1157 }
1158 if (((channel & IndexChannel) != 0) &&
1159 (image->colorspace == CMYKColorspace) && (next != (Image *) NULL))
1160 {
1161 IndexPacket
1162 *indexes;
1163
1164 image_view=AcquireCacheView(next);
1165 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1166 if (p == (const PixelPacket *) NULL)
1167 continue;
1168 indexes=GetCacheViewAuthenticIndexQueue(combine_view);
cristybb503372010-05-27 20:51:26 +00001169 for (x=0; x < (ssize_t) combine_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001170 {
1171 indexes[x]=PixelIntensityToQuantum(p);
1172 p++;
1173 }
1174 image_view=DestroyCacheView(image_view);
1175 next=GetNextImageInList(next);
1176 }
1177 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1178 status=MagickFalse;
1179 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1180 {
1181 MagickBooleanType
1182 proceed;
1183
cristy3ed852e2009-09-05 21:47:34 +00001184 proceed=SetImageProgress(image,CombineImageTag,progress++,
1185 combine_image->rows);
1186 if (proceed == MagickFalse)
1187 status=MagickFalse;
1188 }
1189 }
1190 combine_view=DestroyCacheView(combine_view);
1191 if (status == MagickFalse)
1192 combine_image=DestroyImage(combine_image);
1193 return(combine_image);
1194}
1195
1196/*
1197%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198% %
1199% %
1200% %
cristy3ed852e2009-09-05 21:47:34 +00001201% D e s t r o y I m a g e %
1202% %
1203% %
1204% %
1205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1206%
1207% DestroyImage() dereferences an image, deallocating memory associated with
1208% the image if the reference count becomes zero.
1209%
1210% The format of the DestroyImage method is:
1211%
1212% Image *DestroyImage(Image *image)
1213%
1214% A description of each parameter follows:
1215%
1216% o image: the image.
1217%
1218*/
1219MagickExport Image *DestroyImage(Image *image)
1220{
1221 MagickBooleanType
1222 destroy;
1223
1224 /*
1225 Dereference image.
1226 */
1227 assert(image != (Image *) NULL);
1228 assert(image->signature == MagickSignature);
1229 if (image->debug != MagickFalse)
1230 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1231 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001232 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001233 image->reference_count--;
1234 if (image->reference_count == 0)
1235 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001236 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001237 if (destroy == MagickFalse)
1238 return((Image *) NULL);
1239 /*
1240 Destroy image.
1241 */
1242 DestroyImagePixels(image);
1243 if (image->clip_mask != (Image *) NULL)
1244 image->clip_mask=DestroyImage(image->clip_mask);
1245 if (image->mask != (Image *) NULL)
1246 image->mask=DestroyImage(image->mask);
1247 if (image->montage != (char *) NULL)
1248 image->montage=DestroyString(image->montage);
1249 if (image->directory != (char *) NULL)
1250 image->directory=DestroyString(image->directory);
1251 if (image->colormap != (PixelPacket *) NULL)
1252 image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap);
1253 if (image->geometry != (char *) NULL)
1254 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001255 DestroyImageProfiles(image);
1256 DestroyImageProperties(image);
1257 DestroyImageArtifacts(image);
1258 if (image->ascii85 != (Ascii85Info*) NULL)
1259 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1260 DestroyBlob(image);
1261 (void) DestroyExceptionInfo(&image->exception);
1262 if (image->semaphore != (SemaphoreInfo *) NULL)
1263 DestroySemaphoreInfo(&image->semaphore);
1264 image->signature=(~MagickSignature);
1265 image=(Image *) RelinquishMagickMemory(image);
1266 return(image);
1267}
1268
1269/*
1270%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271% %
1272% %
1273% %
1274% D e s t r o y I m a g e I n f o %
1275% %
1276% %
1277% %
1278%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279%
1280% DestroyImageInfo() deallocates memory associated with an ImageInfo
1281% structure.
1282%
1283% The format of the DestroyImageInfo method is:
1284%
1285% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1286%
1287% A description of each parameter follows:
1288%
1289% o image_info: the image info.
1290%
1291*/
1292MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1293{
1294 assert(image_info != (ImageInfo *) NULL);
1295 assert(image_info->signature == MagickSignature);
1296 if (image_info->debug != MagickFalse)
1297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1298 image_info->filename);
1299 if (image_info->size != (char *) NULL)
1300 image_info->size=DestroyString(image_info->size);
1301 if (image_info->extract != (char *) NULL)
1302 image_info->extract=DestroyString(image_info->extract);
1303 if (image_info->scenes != (char *) NULL)
1304 image_info->scenes=DestroyString(image_info->scenes);
1305 if (image_info->page != (char *) NULL)
1306 image_info->page=DestroyString(image_info->page);
1307 if (image_info->sampling_factor != (char *) NULL)
1308 image_info->sampling_factor=DestroyString(
1309 image_info->sampling_factor);
1310 if (image_info->server_name != (char *) NULL)
1311 image_info->server_name=DestroyString(
1312 image_info->server_name);
1313 if (image_info->font != (char *) NULL)
1314 image_info->font=DestroyString(image_info->font);
1315 if (image_info->texture != (char *) NULL)
1316 image_info->texture=DestroyString(image_info->texture);
1317 if (image_info->density != (char *) NULL)
1318 image_info->density=DestroyString(image_info->density);
1319 if (image_info->view != (char *) NULL)
1320 image_info->view=DestroyString(image_info->view);
1321 if (image_info->authenticate != (char *) NULL)
1322 image_info->authenticate=DestroyString(
1323 image_info->authenticate);
1324 DestroyImageOptions(image_info);
1325 if (image_info->cache != (void *) NULL)
1326 image_info->cache=DestroyPixelCache(image_info->cache);
1327 if (image_info->profile != (StringInfo *) NULL)
1328 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1329 image_info->profile);
1330 image_info->signature=(~MagickSignature);
1331 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1332 return(image_info);
1333}
1334
1335/*
1336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337% %
1338% %
1339% %
1340+ D i s a s s o c i a t e I m a g e S t r e a m %
1341% %
1342% %
1343% %
1344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1345%
1346% DisassociateImageStream() disassociates the image stream.
1347%
1348% The format of the DisassociateImageStream method is:
1349%
1350% MagickBooleanType DisassociateImageStream(const Image *image)
1351%
1352% A description of each parameter follows:
1353%
1354% o image: the image.
1355%
1356*/
1357MagickExport void DisassociateImageStream(Image *image)
1358{
1359 assert(image != (const Image *) NULL);
1360 assert(image->signature == MagickSignature);
1361 if (image->debug != MagickFalse)
1362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1363 (void) DetachBlob(image->blob);
1364}
1365
1366/*
1367%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1368% %
1369% %
1370% %
1371% G e t I m a g e A l p h a C h a n n e l %
1372% %
1373% %
1374% %
1375%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1376%
1377% GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1378% not activated. That is, the image is RGB rather than RGBA or CMYK rather
1379% than CMYKA.
1380%
1381% The format of the GetImageAlphaChannel method is:
1382%
1383% MagickBooleanType GetImageAlphaChannel(const Image *image)
1384%
1385% A description of each parameter follows:
1386%
1387% o image: the image.
1388%
1389*/
1390MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1391{
1392 assert(image != (const Image *) NULL);
1393 if (image->debug != MagickFalse)
1394 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1395 assert(image->signature == MagickSignature);
1396 return(image->matte);
1397}
1398
1399/*
1400%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1401% %
1402% %
1403% %
1404% G e t I m a g e C l i p M a s k %
1405% %
1406% %
1407% %
1408%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1409%
1410% GetImageClipMask() returns the clip path associated with the image.
1411%
1412% The format of the GetImageClipMask method is:
1413%
1414% Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1415%
1416% A description of each parameter follows:
1417%
1418% o image: the image.
1419%
1420*/
1421MagickExport Image *GetImageClipMask(const Image *image,
1422 ExceptionInfo *exception)
1423{
1424 assert(image != (const Image *) NULL);
1425 if (image->debug != MagickFalse)
1426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1427 assert(image->signature == MagickSignature);
1428 if (image->clip_mask == (Image *) NULL)
1429 return((Image *) NULL);
1430 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1431}
1432
1433/*
1434%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1435% %
1436% %
1437% %
1438% G e t I m a g e E x c e p t i o n %
1439% %
1440% %
1441% %
1442%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1443%
1444% GetImageException() traverses an image sequence and returns any
1445% error more severe than noted by the exception parameter.
1446%
1447% The format of the GetImageException method is:
1448%
1449% void GetImageException(Image *image,ExceptionInfo *exception)
1450%
1451% A description of each parameter follows:
1452%
1453% o image: Specifies a pointer to a list of one or more images.
1454%
1455% o exception: return the highest severity exception.
1456%
1457*/
1458MagickExport void GetImageException(Image *image,ExceptionInfo *exception)
1459{
1460 register Image
1461 *next;
1462
1463 assert(image != (Image *) NULL);
1464 assert(image->signature == MagickSignature);
1465 if (image->debug != MagickFalse)
1466 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1467 assert(exception != (ExceptionInfo *) NULL);
1468 assert(exception->signature == MagickSignature);
1469 for (next=image; next != (Image *) NULL; next=GetNextImageInList(next))
1470 {
1471 if (next->exception.severity == UndefinedException)
1472 continue;
1473 if (next->exception.severity > exception->severity)
1474 InheritException(exception,&next->exception);
1475 next->exception.severity=UndefinedException;
1476 }
1477}
1478
1479/*
1480%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1481% %
1482% %
1483% %
1484% G e t I m a g e I n f o %
1485% %
1486% %
1487% %
1488%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1489%
1490% GetImageInfo() initializes image_info to default values.
1491%
1492% The format of the GetImageInfo method is:
1493%
1494% void GetImageInfo(ImageInfo *image_info)
1495%
1496% A description of each parameter follows:
1497%
1498% o image_info: the image info.
1499%
1500*/
1501MagickExport void GetImageInfo(ImageInfo *image_info)
1502{
cristyd9a29192010-10-16 16:49:53 +00001503 const char
1504 *synchronize;
1505
cristy3ed852e2009-09-05 21:47:34 +00001506 ExceptionInfo
1507 *exception;
1508
1509 /*
1510 File and image dimension members.
1511 */
1512 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1513 assert(image_info != (ImageInfo *) NULL);
1514 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1515 image_info->adjoin=MagickTrue;
1516 image_info->interlace=NoInterlace;
1517 image_info->channel=DefaultChannels;
1518 image_info->quality=UndefinedCompressionQuality;
1519 image_info->antialias=MagickTrue;
1520 image_info->dither=MagickTrue;
cristyd9a29192010-10-16 16:49:53 +00001521 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1522 if (synchronize != (const char *) NULL)
1523 image_info->synchronize=IsMagickTrue(synchronize);
cristy3ed852e2009-09-05 21:47:34 +00001524 exception=AcquireExceptionInfo();
1525 (void) QueryColorDatabase(BackgroundColor,&image_info->background_color,
1526 exception);
1527 (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception);
1528 (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception);
1529 (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color,
1530 exception);
1531 exception=DestroyExceptionInfo(exception);
1532 image_info->debug=IsEventLogging();
1533 image_info->signature=MagickSignature;
1534}
1535
1536/*
1537%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1538% %
1539% %
1540% %
cristy15781e52009-12-05 23:05:27 +00001541% G e t I m a g e I n f o F i l e %
1542% %
1543% %
1544% %
1545%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1546%
1547% GetImageInfoFile() returns the image info file member.
1548%
1549% The format of the GetImageInfoFile method is:
1550%
1551% FILE *GetImageInfoFile(const ImageInfo *image_info)
1552%
1553% A description of each parameter follows:
1554%
1555% o image_info: the image info.
1556%
1557*/
1558MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1559{
1560 return(image_info->file);
1561}
1562
1563/*
1564%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1565% %
1566% %
1567% %
cristy3ed852e2009-09-05 21:47:34 +00001568% G e t I m a g e M a s k %
1569% %
1570% %
1571% %
1572%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1573%
1574% GetImageMask() returns the mask associated with the image.
1575%
1576% The format of the GetImageMask method is:
1577%
1578% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1579%
1580% A description of each parameter follows:
1581%
1582% o image: the image.
1583%
1584*/
1585MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1586{
1587 assert(image != (const Image *) NULL);
1588 if (image->debug != MagickFalse)
1589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1590 assert(image->signature == MagickSignature);
1591 if (image->mask == (Image *) NULL)
1592 return((Image *) NULL);
1593 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1594}
1595
1596/*
1597%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1598% %
1599% %
1600% %
1601+ G e t I m a g e R e f e r e n c e C o u n t %
1602% %
1603% %
1604% %
1605%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1606%
1607% GetImageReferenceCount() returns the image reference count.
1608%
1609% The format of the GetReferenceCount method is:
1610%
cristybb503372010-05-27 20:51:26 +00001611% ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001612%
1613% A description of each parameter follows:
1614%
1615% o image: the image.
1616%
1617*/
cristybb503372010-05-27 20:51:26 +00001618MagickExport ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001619{
cristybb503372010-05-27 20:51:26 +00001620 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001621 reference_count;
1622
1623 assert(image != (Image *) NULL);
1624 assert(image->signature == MagickSignature);
1625 if (image->debug != MagickFalse)
1626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001627 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001628 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001629 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001630 return(reference_count);
1631}
1632
1633/*
1634%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1635% %
1636% %
1637% %
cristy3ed852e2009-09-05 21:47:34 +00001638% 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 %
1639% %
1640% %
1641% %
1642%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1643%
1644% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1645% image. A virtual pixel is any pixel access that is outside the boundaries
1646% of the image cache.
1647%
1648% The format of the GetImageVirtualPixelMethod() method is:
1649%
1650% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1651%
1652% A description of each parameter follows:
1653%
1654% o image: the image.
1655%
1656*/
1657MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1658{
1659 assert(image != (Image *) NULL);
1660 assert(image->signature == MagickSignature);
1661 if (image->debug != MagickFalse)
1662 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1663 return(GetPixelCacheVirtualMethod(image));
1664}
1665
1666/*
1667%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1668% %
1669% %
1670% %
1671% I n t e r p r e t I m a g e F i l e n a m e %
1672% %
1673% %
1674% %
1675%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1676%
1677% InterpretImageFilename() interprets embedded characters in an image filename.
1678% The filename length is returned.
1679%
1680% The format of the InterpretImageFilename method is:
1681%
1682% size_t InterpretImageFilename(const ImageInfo *image_info,
1683% Image *image,const char *format,int value,char *filename)
1684%
1685% A description of each parameter follows.
1686%
1687% o image_info: the image info..
1688%
1689% o image: the image.
1690%
1691% o format: A filename describing the format to use to write the numeric
1692% argument. Only the first numeric format identifier is replaced.
1693%
1694% o value: Numeric value to substitute into format filename.
1695%
1696% o filename: return the formatted filename in this character buffer.
1697%
1698*/
1699MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
1700 Image *image,const char *format,int value,char *filename)
1701{
1702 char
1703 *q;
1704
1705 int
1706 c;
1707
1708 MagickBooleanType
1709 canonical;
1710
1711 register const char
1712 *p;
1713
1714 canonical=MagickFalse;
1715 (void) CopyMagickString(filename,format,MaxTextExtent);
1716 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1717 {
1718 q=(char *) p+1;
1719 if (*q == '%')
1720 {
1721 p=q+1;
1722 continue;
1723 }
1724 if (*q == '0')
1725 {
cristybb503372010-05-27 20:51:26 +00001726 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001727 value;
1728
cristybb503372010-05-27 20:51:26 +00001729 value=(ssize_t) strtol(q,&q,10);
cristyda16f162011-02-19 23:52:17 +00001730 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00001731 }
1732 switch (*q)
1733 {
1734 case 'd':
1735 case 'o':
1736 case 'x':
1737 {
1738 q++;
1739 c=(*q);
1740 *q='\0';
1741 (void) FormatMagickString(filename+(p-format),(size_t) (MaxTextExtent-
1742 (p-format)),p,value);
1743 *q=c;
1744 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1745 canonical=MagickTrue;
1746 if (*(q-1) != '%')
1747 break;
1748 p++;
1749 break;
1750 }
1751 case '[':
1752 {
1753 char
1754 pattern[MaxTextExtent];
1755
1756 const char
1757 *value;
1758
cristy3ed852e2009-09-05 21:47:34 +00001759 register char
1760 *r;
1761
cristybb503372010-05-27 20:51:26 +00001762 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001763 i;
1764
cristycb6d09b2010-06-19 01:59:36 +00001765 ssize_t
1766 depth;
1767
cristy3ed852e2009-09-05 21:47:34 +00001768 /*
1769 Image option.
1770 */
1771 if (strchr(p,']') == (char *) NULL)
1772 break;
1773 depth=1;
1774 r=q+1;
1775 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1776 {
1777 if (*r == '[')
1778 depth++;
1779 if (*r == ']')
1780 depth--;
1781 if (depth <= 0)
1782 break;
1783 pattern[i]=(*r++);
1784 }
1785 pattern[i]='\0';
1786 if (LocaleNCompare(pattern,"filename:",9) != 0)
1787 break;
1788 value=(const char *) NULL;
1789 if ((image_info != (const ImageInfo *) NULL) &&
1790 (image != (const Image *) NULL))
cristy86fe49e2010-06-25 01:18:11 +00001791 value=GetMagickProperty(image_info,image,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001792 else
1793 if (image != (Image *) NULL)
cristy86fe49e2010-06-25 01:18:11 +00001794 value=GetImageProperty(image,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001795 else
1796 if (image_info != (ImageInfo *) NULL)
cristy86fe49e2010-06-25 01:18:11 +00001797 value=GetImageOption(image_info,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001798 if (value == (const char *) NULL)
1799 break;
1800 q--;
1801 c=(*q);
1802 *q='\0';
1803 (void) CopyMagickString(filename+(p-format),value,(size_t)
1804 (MaxTextExtent-(p-format)));
1805 *q=c;
1806 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1807 canonical=MagickTrue;
1808 if (*(q-1) != '%')
1809 break;
1810 p++;
1811 break;
1812 }
1813 default:
1814 break;
1815 }
1816 }
1817 for (q=filename; *q != '\0'; q++)
1818 if ((*q == '%') && (*(q+1) == '%'))
cristy27bf23e2011-01-10 13:35:22 +00001819 {
1820 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1821 canonical=MagickTrue;
1822 }
cristy3ed852e2009-09-05 21:47:34 +00001823 if (canonical == MagickFalse)
1824 (void) CopyMagickString(filename,format,MaxTextExtent);
1825 return(strlen(filename));
1826}
1827
1828/*
1829%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1830% %
1831% %
1832% %
1833% I s H i g h D y n a m i c R a n g e I m a g e %
1834% %
1835% %
1836% %
1837%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1838%
1839% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1840% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1841% 0..65535.
1842%
1843% The format of the IsHighDynamicRangeImage method is:
1844%
1845% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1846% ExceptionInfo *exception)
1847%
1848% A description of each parameter follows:
1849%
1850% o image: the image.
1851%
1852% o exception: return any errors or warnings in this structure.
1853%
1854*/
1855MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1856 ExceptionInfo *exception)
1857{
1858#if !defined(MAGICKCORE_HDRI_SUPPORT)
1859 (void) image;
1860 (void) exception;
1861 return(MagickFalse);
1862#else
1863 CacheView
1864 *image_view;
1865
cristy3ed852e2009-09-05 21:47:34 +00001866 MagickBooleanType
1867 status;
1868
1869 MagickPixelPacket
1870 zero;
1871
cristycb6d09b2010-06-19 01:59:36 +00001872 ssize_t
1873 y;
1874
cristy3ed852e2009-09-05 21:47:34 +00001875 assert(image != (Image *) NULL);
1876 assert(image->signature == MagickSignature);
1877 if (image->debug != MagickFalse)
1878 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1879 status=MagickTrue;
1880 GetMagickPixelPacket(image,&zero);
1881 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00001882#if defined(MAGICKCORE_OPENMP_SUPPORT)
1883 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00001884#endif
cristybb503372010-05-27 20:51:26 +00001885 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001886 {
1887 MagickPixelPacket
1888 pixel;
1889
1890 register const IndexPacket
1891 *indexes;
1892
1893 register const PixelPacket
1894 *p;
1895
cristybb503372010-05-27 20:51:26 +00001896 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001897 x;
1898
1899 if (status == MagickFalse)
1900 continue;
1901 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1902 if (p == (const PixelPacket *) NULL)
1903 {
1904 status=MagickFalse;
1905 continue;
1906 }
1907 indexes=GetCacheViewVirtualIndexQueue(image_view);
1908 pixel=zero;
cristybb503372010-05-27 20:51:26 +00001909 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001910 {
1911 SetMagickPixelPacket(image,p,indexes+x,&pixel);
1912 if ((pixel.red < 0.0) || (pixel.red > QuantumRange) ||
1913 (pixel.red != (QuantumAny) pixel.red))
1914 break;
1915 if ((pixel.green < 0.0) || (pixel.green > QuantumRange) ||
1916 (pixel.green != (QuantumAny) pixel.green))
1917 break;
1918 if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) ||
1919 (pixel.blue != (QuantumAny) pixel.blue))
1920 break;
1921 if (pixel.matte != MagickFalse)
1922 {
1923 if ((pixel.opacity < 0.0) || (pixel.opacity > QuantumRange) ||
1924 (pixel.opacity != (QuantumAny) pixel.opacity))
1925 break;
1926 }
1927 if (pixel.colorspace == CMYKColorspace)
1928 {
1929 if ((pixel.index < 0.0) || (pixel.index > QuantumRange) ||
1930 (pixel.index != (QuantumAny) pixel.index))
1931 break;
1932 }
1933 p++;
1934 }
cristybb503372010-05-27 20:51:26 +00001935 if (x < (ssize_t) image->columns)
cristy3ed852e2009-09-05 21:47:34 +00001936 status=MagickFalse;
1937 }
1938 image_view=DestroyCacheView(image_view);
1939 return(status != MagickFalse ? MagickFalse : MagickTrue);
1940#endif
1941}
1942
1943/*
1944%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1945% %
1946% %
1947% %
1948% I s I m a g e O b j e c t %
1949% %
1950% %
1951% %
1952%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1953%
1954% IsImageObject() returns MagickTrue if the image sequence contains a valid
1955% set of image objects.
1956%
1957% The format of the IsImageObject method is:
1958%
1959% MagickBooleanType IsImageObject(const Image *image)
1960%
1961% A description of each parameter follows:
1962%
1963% o image: the image.
1964%
1965*/
1966MagickExport MagickBooleanType IsImageObject(const Image *image)
1967{
1968 register const Image
1969 *p;
1970
1971 assert(image != (Image *) NULL);
1972 if (image->debug != MagickFalse)
1973 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1974 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1975 if (p->signature != MagickSignature)
1976 return(MagickFalse);
1977 return(MagickTrue);
1978}
1979
1980/*
1981%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1982% %
1983% %
1984% %
1985% I s T a i n t I m a g e %
1986% %
1987% %
1988% %
1989%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1990%
1991% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1992% since it was first constituted.
1993%
1994% The format of the IsTaintImage method is:
1995%
1996% MagickBooleanType IsTaintImage(const Image *image)
1997%
1998% A description of each parameter follows:
1999%
2000% o image: the image.
2001%
2002*/
2003MagickExport MagickBooleanType IsTaintImage(const Image *image)
2004{
2005 char
2006 magick[MaxTextExtent],
2007 filename[MaxTextExtent];
2008
2009 register const Image
2010 *p;
2011
2012 assert(image != (Image *) NULL);
2013 if (image->debug != MagickFalse)
2014 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2015 assert(image->signature == MagickSignature);
2016 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
2017 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
2018 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
2019 {
2020 if (p->taint != MagickFalse)
2021 return(MagickTrue);
2022 if (LocaleCompare(p->magick,magick) != 0)
2023 return(MagickTrue);
2024 if (LocaleCompare(p->filename,filename) != 0)
2025 return(MagickTrue);
2026 }
2027 return(MagickFalse);
2028}
2029
2030/*
2031%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2032% %
2033% %
2034% %
2035% M o d i f y I m a g e %
2036% %
2037% %
2038% %
2039%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2040%
2041% ModifyImage() ensures that there is only a single reference to the image
2042% to be modified, updating the provided image pointer to point to a clone of
2043% the original image if necessary.
2044%
2045% The format of the ModifyImage method is:
2046%
2047% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
2048%
2049% A description of each parameter follows:
2050%
2051% o image: the image.
2052%
2053% o exception: return any errors or warnings in this structure.
2054%
2055*/
2056MagickExport MagickBooleanType ModifyImage(Image **image,
2057 ExceptionInfo *exception)
2058{
2059 Image
2060 *clone_image;
2061
2062 assert(image != (Image **) NULL);
2063 assert(*image != (Image *) NULL);
2064 assert((*image)->signature == MagickSignature);
2065 if ((*image)->debug != MagickFalse)
2066 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
2067 if (GetImageReferenceCount(*image) <= 1)
2068 return(MagickTrue);
2069 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
cristyf84a1932010-01-03 18:00:18 +00002070 LockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002071 (*image)->reference_count--;
cristyf84a1932010-01-03 18:00:18 +00002072 UnlockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002073 *image=clone_image;
2074 return(MagickTrue);
2075}
2076
2077/*
2078%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2079% %
2080% %
2081% %
2082% N e w M a g i c k I m a g e %
2083% %
2084% %
2085% %
2086%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2087%
2088% NewMagickImage() creates a blank image canvas of the specified size and
2089% background color.
2090%
2091% The format of the NewMagickImage method is:
2092%
2093% 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% A description of each parameter follows:
2098%
2099% o image: the image.
2100%
2101% o width: the image width.
2102%
2103% o height: the image height.
2104%
2105% o background: the image color.
2106%
2107*/
2108MagickExport Image *NewMagickImage(const ImageInfo *image_info,
cristybb503372010-05-27 20:51:26 +00002109 const size_t width,const size_t height,
cristy3ed852e2009-09-05 21:47:34 +00002110 const MagickPixelPacket *background)
2111{
2112 CacheView
2113 *image_view;
2114
2115 ExceptionInfo
2116 *exception;
2117
2118 Image
2119 *image;
2120
cristybb503372010-05-27 20:51:26 +00002121 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002122 y;
2123
2124 MagickBooleanType
2125 status;
2126
2127 assert(image_info != (const ImageInfo *) NULL);
2128 if (image_info->debug != MagickFalse)
2129 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2130 assert(image_info->signature == MagickSignature);
2131 assert(background != (const MagickPixelPacket *) NULL);
2132 image=AcquireImage(image_info);
2133 image->columns=width;
2134 image->rows=height;
2135 image->colorspace=background->colorspace;
2136 image->matte=background->matte;
2137 image->fuzz=background->fuzz;
2138 image->depth=background->depth;
2139 status=MagickTrue;
2140 exception=(&image->exception);
2141 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00002142#if defined(MAGICKCORE_OPENMP_SUPPORT)
2143 #pragma omp parallel for schedule(dynamic,4) shared(status)
2144#endif
cristybb503372010-05-27 20:51:26 +00002145 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002146 {
2147 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002148 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002149
cristy3ed852e2009-09-05 21:47:34 +00002150 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002151 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002152
cristycb6d09b2010-06-19 01:59:36 +00002153 register ssize_t
2154 x;
2155
cristy48974b92009-12-19 02:36:06 +00002156 if (status == MagickFalse)
2157 continue;
cristy3ed852e2009-09-05 21:47:34 +00002158 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2159 if (q == (PixelPacket *) NULL)
2160 {
2161 status=MagickFalse;
2162 continue;
2163 }
2164 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002165 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002166 {
2167 SetPixelPacket(image,background,q,indexes+x);
2168 q++;
2169 }
2170 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2171 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002172 }
2173 image_view=DestroyCacheView(image_view);
2174 if (status == MagickFalse)
2175 image=DestroyImage(image);
2176 return(image);
2177}
2178
2179/*
2180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2181% %
2182% %
2183% %
2184% R e f e r e n c e I m a g e %
2185% %
2186% %
2187% %
2188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2189%
2190% ReferenceImage() increments the reference count associated with an image
2191% returning a pointer to the image.
2192%
2193% The format of the ReferenceImage method is:
2194%
2195% Image *ReferenceImage(Image *image)
2196%
2197% A description of each parameter follows:
2198%
2199% o image: the image.
2200%
2201*/
2202MagickExport Image *ReferenceImage(Image *image)
2203{
2204 assert(image != (Image *) NULL);
2205 if (image->debug != MagickFalse)
2206 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2207 assert(image->signature == MagickSignature);
cristyf84a1932010-01-03 18:00:18 +00002208 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002209 image->reference_count++;
cristyf84a1932010-01-03 18:00:18 +00002210 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002211 return(image);
2212}
2213
2214/*
2215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2216% %
2217% %
2218% %
2219% R e s e t I m a g e P a g e %
2220% %
2221% %
2222% %
2223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2224%
2225% ResetImagePage() resets the image page canvas and position.
2226%
2227% The format of the ResetImagePage method is:
2228%
2229% MagickBooleanType ResetImagePage(Image *image,const char *page)
2230%
2231% A description of each parameter follows:
2232%
2233% o image: the image.
2234%
2235% o page: the relative page specification.
2236%
2237*/
2238MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2239{
2240 MagickStatusType
2241 flags;
2242
2243 RectangleInfo
2244 geometry;
2245
2246 assert(image != (Image *) NULL);
2247 assert(image->signature == MagickSignature);
2248 if (image->debug != MagickFalse)
2249 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2250 flags=ParseAbsoluteGeometry(page,&geometry);
2251 if ((flags & WidthValue) != 0)
2252 {
2253 if ((flags & HeightValue) == 0)
2254 geometry.height=geometry.width;
2255 image->page.width=geometry.width;
2256 image->page.height=geometry.height;
2257 }
2258 if ((flags & AspectValue) != 0)
2259 {
2260 if ((flags & XValue) != 0)
2261 image->page.x+=geometry.x;
2262 if ((flags & YValue) != 0)
2263 image->page.y+=geometry.y;
2264 }
2265 else
2266 {
2267 if ((flags & XValue) != 0)
2268 {
2269 image->page.x=geometry.x;
2270 if ((image->page.width == 0) && (geometry.x > 0))
2271 image->page.width=image->columns+geometry.x;
2272 }
2273 if ((flags & YValue) != 0)
2274 {
2275 image->page.y=geometry.y;
2276 if ((image->page.height == 0) && (geometry.y > 0))
2277 image->page.height=image->rows+geometry.y;
2278 }
2279 }
2280 return(MagickTrue);
2281}
2282
2283/*
2284%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2285% %
2286% %
2287% %
2288% S e p a r a t e I m a g e C h a n n e l %
2289% %
2290% %
2291% %
2292%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2293%
2294% SeparateImageChannel() separates a channel from the image and returns it as
2295% a grayscale image. A channel is a particular color component of each pixel
2296% in the image.
2297%
2298% The format of the SeparateImageChannel method is:
2299%
2300% MagickBooleanType SeparateImageChannel(Image *image,
2301% const ChannelType channel)
2302%
2303% A description of each parameter follows:
2304%
2305% o image: the image.
2306%
2307% o channel: Identify which channel to extract: RedChannel, GreenChannel,
2308% BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2309% YellowChannel, or BlackChannel.
2310%
2311*/
2312MagickExport MagickBooleanType SeparateImageChannel(Image *image,
2313 const ChannelType channel)
2314{
2315#define SeparateImageTag "Separate/Image"
2316
2317 CacheView
2318 *image_view;
2319
2320 ExceptionInfo
2321 *exception;
2322
cristy3ed852e2009-09-05 21:47:34 +00002323 MagickBooleanType
2324 status;
2325
cristybb503372010-05-27 20:51:26 +00002326 MagickOffsetType
2327 progress;
2328
2329 ssize_t
2330 y;
2331
cristy3ed852e2009-09-05 21:47:34 +00002332 assert(image != (Image *) NULL);
2333 assert(image->signature == MagickSignature);
2334 if (image->debug != MagickFalse)
2335 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2336 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2337 return(MagickFalse);
2338 /*
2339 Separate image channels.
2340 */
2341 status=MagickTrue;
cristy11b66ce2010-03-11 13:34:19 +00002342 if (channel == GrayChannels)
cristy3ed852e2009-09-05 21:47:34 +00002343 image->matte=MagickTrue;
2344 progress=0;
2345 exception=(&image->exception);
2346 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002347#if defined(MAGICKCORE_OPENMP_SUPPORT)
2348 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00002349#endif
cristybb503372010-05-27 20:51:26 +00002350 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002351 {
2352 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002353 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002354
cristy3ed852e2009-09-05 21:47:34 +00002355 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002356 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002357
cristycb6d09b2010-06-19 01:59:36 +00002358 register ssize_t
2359 x;
2360
cristy3ed852e2009-09-05 21:47:34 +00002361 if (status == MagickFalse)
2362 continue;
2363 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2364 if (q == (PixelPacket *) NULL)
2365 {
2366 status=MagickFalse;
2367 continue;
2368 }
2369 indexes=GetCacheViewAuthenticIndexQueue(image_view);
2370 switch (channel)
2371 {
2372 case RedChannel:
2373 {
cristybb503372010-05-27 20:51:26 +00002374 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002375 {
cristyc5071682011-04-22 02:06:27 +00002376 SetGreenPixelComponent(q,GetRedPixelComponent(q));
2377 SetBluePixelComponent(q,GetRedPixelComponent(q));
cristy3ed852e2009-09-05 21:47:34 +00002378 q++;
2379 }
2380 break;
2381 }
2382 case GreenChannel:
2383 {
cristybb503372010-05-27 20:51:26 +00002384 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002385 {
cristyc5071682011-04-22 02:06:27 +00002386 SetRedPixelComponent(q,GetGreenPixelComponent(q));
2387 SetBluePixelComponent(q,GetGreenPixelComponent(q));
cristy3ed852e2009-09-05 21:47:34 +00002388 q++;
2389 }
2390 break;
2391 }
2392 case BlueChannel:
2393 {
cristybb503372010-05-27 20:51:26 +00002394 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002395 {
cristyc5071682011-04-22 02:06:27 +00002396 SetRedPixelComponent(q,GetBluePixelComponent(q));
2397 SetGreenPixelComponent(q,GetBluePixelComponent(q));
cristy3ed852e2009-09-05 21:47:34 +00002398 q++;
2399 }
2400 break;
2401 }
2402 case OpacityChannel:
2403 {
cristybb503372010-05-27 20:51:26 +00002404 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002405 {
cristyc5071682011-04-22 02:06:27 +00002406 SetRedPixelComponent(q,GetOpacityPixelComponent(q));
2407 SetGreenPixelComponent(q,GetOpacityPixelComponent(q));
2408 SetBluePixelComponent(q,GetOpacityPixelComponent(q));
cristy3ed852e2009-09-05 21:47:34 +00002409 q++;
2410 }
2411 break;
2412 }
2413 case BlackChannel:
2414 {
2415 if ((image->storage_class != PseudoClass) &&
2416 (image->colorspace != CMYKColorspace))
2417 break;
cristybb503372010-05-27 20:51:26 +00002418 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002419 {
cristyc5071682011-04-22 02:06:27 +00002420 SetRedPixelComponent(q,indexes[x]);
2421 SetGreenPixelComponent(q,indexes[x]);
2422 SetBluePixelComponent(q,indexes[x]);
cristy3ed852e2009-09-05 21:47:34 +00002423 q++;
2424 }
2425 break;
2426 }
2427 case TrueAlphaChannel:
2428 {
cristybb503372010-05-27 20:51:26 +00002429 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002430 {
cristyc5071682011-04-22 02:06:27 +00002431 SetRedPixelComponent(q,(Quantum) GetAlphaPixelComponent(q));
2432 SetGreenPixelComponent(q,(Quantum) GetAlphaPixelComponent(q));
2433 SetBluePixelComponent(q,(Quantum) GetAlphaPixelComponent(q));
cristy3ed852e2009-09-05 21:47:34 +00002434 q++;
2435 }
2436 break;
2437 }
2438 case GrayChannels:
2439 {
cristybb503372010-05-27 20:51:26 +00002440 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002441 {
cristyc5071682011-04-22 02:06:27 +00002442 SetOpacityPixelComponent(q,(Quantum) (QuantumRange-
2443 PixelIntensityToQuantum(q)));
cristy3ed852e2009-09-05 21:47:34 +00002444 q++;
2445 }
2446 break;
2447 }
2448 default:
2449 break;
2450 }
2451 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2452 status=MagickFalse;
2453 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2454 {
2455 MagickBooleanType
2456 proceed;
2457
cristyb5d5f722009-11-04 03:03:49 +00002458#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00002459 #pragma omp critical (MagickCore_SeparateImageChannel)
2460#endif
2461 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2462 if (proceed == MagickFalse)
2463 status=MagickFalse;
2464 }
2465 }
2466 image_view=DestroyCacheView(image_view);
cristy11b66ce2010-03-11 13:34:19 +00002467 if (channel != GrayChannels)
cristy3ed852e2009-09-05 21:47:34 +00002468 image->matte=MagickFalse;
2469 (void) SetImageColorspace(image,RGBColorspace);
2470 return(status);
2471}
2472
2473/*
2474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2475% %
2476% %
2477% %
2478% S e p a r a t e I m a g e s %
2479% %
2480% %
2481% %
2482%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2483%
2484% SeparateImages() returns a separate grayscale image for each channel
2485% specified.
2486%
2487% The format of the SeparateImages method is:
2488%
2489% MagickBooleanType SeparateImages(const Image *image,
2490% const ChannelType channel,ExceptionInfo *exception)
2491%
2492% A description of each parameter follows:
2493%
2494% o image: the image.
2495%
2496% o channel: Identify which channels to extract: RedChannel, GreenChannel,
2497% BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2498% YellowChannel, or BlackChannel.
2499%
2500% o exception: return any errors or warnings in this structure.
2501%
2502*/
2503MagickExport Image *SeparateImages(const Image *image,const ChannelType channel,
2504 ExceptionInfo *exception)
2505{
2506 Image
2507 *images,
2508 *separate_image;
2509
2510 assert(image != (Image *) NULL);
2511 assert(image->signature == MagickSignature);
2512 if (image->debug != MagickFalse)
2513 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2514 images=NewImageList();
2515 if ((channel & RedChannel) != 0)
2516 {
2517 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2518 (void) SeparateImageChannel(separate_image,RedChannel);
2519 AppendImageToList(&images,separate_image);
2520 }
2521 if ((channel & GreenChannel) != 0)
2522 {
2523 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2524 (void) SeparateImageChannel(separate_image,GreenChannel);
2525 AppendImageToList(&images,separate_image);
2526 }
2527 if ((channel & BlueChannel) != 0)
2528 {
2529 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2530 (void) SeparateImageChannel(separate_image,BlueChannel);
2531 AppendImageToList(&images,separate_image);
2532 }
2533 if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace))
2534 {
2535 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2536 (void) SeparateImageChannel(separate_image,BlackChannel);
2537 AppendImageToList(&images,separate_image);
2538 }
2539 if ((channel & OpacityChannel) != 0)
2540 {
2541 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2542 (void) SeparateImageChannel(separate_image,OpacityChannel);
2543 AppendImageToList(&images,separate_image);
2544 }
2545 return(images);
2546}
2547
2548/*
2549%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2550% %
2551% %
2552% %
2553% S e t I m a g e A l p h a C h a n n e l %
2554% %
2555% %
2556% %
2557%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2558%
2559% SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2560% channel.
2561%
2562% The format of the SetImageAlphaChannel method is:
2563%
2564% MagickBooleanType SetImageAlphaChannel(Image *image,
2565% const AlphaChannelType alpha_type)
2566%
2567% A description of each parameter follows:
2568%
2569% o image: the image.
2570%
2571% o alpha_type: The alpha channel type: ActivateAlphaChannel,
2572% CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2573% OpaqueAlphaChannel, ResetAlphaChannel, SetAlphaChannel,
2574% ShapeAlphaChannel, and TransparentAlphaChannel.
2575%
2576*/
2577MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2578 const AlphaChannelType alpha_type)
2579{
2580 MagickBooleanType
2581 status;
2582
2583 assert(image != (Image *) NULL);
2584 if (image->debug != MagickFalse)
2585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2586 assert(image->signature == MagickSignature);
2587 status=MagickFalse;
2588 switch (alpha_type)
2589 {
2590 case ActivateAlphaChannel:
2591 {
2592 image->matte=MagickTrue;
2593 break;
2594 }
2595 case BackgroundAlphaChannel:
2596 {
2597 CacheView
2598 *image_view;
2599
2600 ExceptionInfo
2601 *exception;
2602
2603 IndexPacket
2604 index;
2605
cristy3ed852e2009-09-05 21:47:34 +00002606 MagickBooleanType
2607 status;
2608
2609 MagickPixelPacket
2610 background;
2611
2612 PixelPacket
2613 pixel;
2614
cristycb6d09b2010-06-19 01:59:36 +00002615 ssize_t
2616 y;
2617
cristy3ed852e2009-09-05 21:47:34 +00002618 /*
2619 Set transparent pixels to background color.
2620 */
2621 if (image->matte == MagickFalse)
2622 break;
2623 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2624 break;
2625 GetMagickPixelPacket(image,&background);
2626 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2627 NULL,&background);
2628 if (image->colorspace == CMYKColorspace)
2629 ConvertRGBToCMYK(&background);
2630 index=0;
2631 SetPixelPacket(image,&background,&pixel,&index);
2632 status=MagickTrue;
2633 exception=(&image->exception);
2634 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002635 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2636 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00002637 #endif
cristybb503372010-05-27 20:51:26 +00002638 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002639 {
2640 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002641 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002642
cristy3ed852e2009-09-05 21:47:34 +00002643 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002644 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002645
cristycb6d09b2010-06-19 01:59:36 +00002646 register ssize_t
2647 x;
2648
cristy3ed852e2009-09-05 21:47:34 +00002649 if (status == MagickFalse)
2650 continue;
2651 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2652 exception);
2653 if (q == (PixelPacket *) NULL)
2654 {
2655 status=MagickFalse;
2656 continue;
2657 }
cristybb503372010-05-27 20:51:26 +00002658 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002659 {
2660 if (q->opacity == TransparentOpacity)
2661 {
cristya2d08742011-04-22 19:59:52 +00002662 SetRedPixelComponent(q,pixel.red);
2663 SetGreenPixelComponent(q,pixel.green);
2664 SetBluePixelComponent(q,pixel.blue);
cristy3ed852e2009-09-05 21:47:34 +00002665 }
2666 q++;
2667 }
2668 if (image->colorspace == CMYKColorspace)
2669 {
2670 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002671 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002672 indexes[x]=index;
2673 }
2674 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2675 status=MagickFalse;
2676 }
2677 image_view=DestroyCacheView(image_view);
2678 return(status);
2679 }
2680 case DeactivateAlphaChannel:
2681 {
2682 image->matte=MagickFalse;
2683 break;
2684 }
2685 case ShapeAlphaChannel:
2686 case CopyAlphaChannel:
2687 {
2688 /*
2689 Special usage case for SeparateImageChannel(): copy grayscale color to
2690 the alpha channel.
2691 */
2692 status=SeparateImageChannel(image,GrayChannels);
2693 image->matte=MagickTrue; /* make sure transparency is now on! */
2694 if (alpha_type == ShapeAlphaChannel)
2695 {
2696 MagickPixelPacket
2697 background;
2698
2699 /*
2700 Reset all color channels to background color.
2701 */
2702 GetMagickPixelPacket(image,&background);
2703 SetMagickPixelPacket(image,&(image->background_color),(IndexPacket *)
2704 NULL,&background);
cristy308b4e62009-09-21 14:40:44 +00002705 (void) LevelColorsImage(image,&background,&background,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00002706 }
2707 break;
2708 }
2709 case ExtractAlphaChannel:
2710 {
2711 status=SeparateImageChannel(image,TrueAlphaChannel);
2712 image->matte=MagickFalse;
2713 break;
2714 }
cristyf64d18b2010-04-30 12:47:03 +00002715 case ResetAlphaChannel: /* deprecated */
cristy3ed852e2009-09-05 21:47:34 +00002716 case OpaqueAlphaChannel:
2717 {
2718 status=SetImageOpacity(image,OpaqueOpacity);
2719 image->matte=MagickTrue;
2720 break;
2721 }
2722 case TransparentAlphaChannel:
2723 {
2724 status=SetImageOpacity(image,TransparentOpacity);
2725 image->matte=MagickTrue;
2726 break;
2727 }
2728 case SetAlphaChannel:
2729 {
2730 if (image->matte == MagickFalse)
2731 {
2732 status=SetImageOpacity(image,OpaqueOpacity);
2733 image->matte=MagickTrue;
2734 }
2735 break;
2736 }
2737 case UndefinedAlphaChannel:
2738 break;
2739 }
2740 return(status);
2741}
2742
2743/*
2744%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2745% %
2746% %
2747% %
2748% S e t I m a g e B a c k g r o u n d C o l o r %
2749% %
2750% %
2751% %
2752%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2753%
2754% SetImageBackgroundColor() initializes the image pixels to the image
2755% background color. The background color is defined by the background_color
2756% member of the image structure.
2757%
2758% The format of the SetImage method is:
2759%
2760% MagickBooleanType SetImageBackgroundColor(Image *image)
2761%
2762% A description of each parameter follows:
2763%
2764% o image: the image.
2765%
2766*/
2767MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2768{
2769 CacheView
2770 *image_view;
2771
2772 ExceptionInfo
2773 *exception;
2774
2775 IndexPacket
2776 index;
2777
cristy3ed852e2009-09-05 21:47:34 +00002778 MagickBooleanType
2779 status;
2780
2781 MagickPixelPacket
2782 background;
2783
2784 PixelPacket
2785 pixel;
2786
cristycb6d09b2010-06-19 01:59:36 +00002787 ssize_t
2788 y;
2789
cristy3ed852e2009-09-05 21:47:34 +00002790 assert(image != (Image *) NULL);
2791 if (image->debug != MagickFalse)
2792 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2793 assert(image->signature == MagickSignature);
2794 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2795 return(MagickFalse);
2796 if (image->background_color.opacity != OpaqueOpacity)
2797 image->matte=MagickTrue;
2798 GetMagickPixelPacket(image,&background);
2799 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2800 NULL,&background);
2801 if (image->colorspace == CMYKColorspace)
2802 ConvertRGBToCMYK(&background);
2803 index=0;
2804 SetPixelPacket(image,&background,&pixel,&index);
2805 /*
2806 Set image background color.
2807 */
2808 status=MagickTrue;
2809 exception=(&image->exception);
2810 image_view=AcquireCacheView(image);
cristybb503372010-05-27 20:51:26 +00002811 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002812 {
cristy3ed852e2009-09-05 21:47:34 +00002813 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002814 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002815
cristycb6d09b2010-06-19 01:59:36 +00002816 register ssize_t
2817 x;
2818
cristy3ed852e2009-09-05 21:47:34 +00002819 if (status == MagickFalse)
2820 continue;
2821 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2822 if (q == (PixelPacket *) NULL)
2823 {
2824 status=MagickFalse;
2825 continue;
2826 }
cristybb503372010-05-27 20:51:26 +00002827 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002828 *q++=pixel;
2829 if (image->colorspace == CMYKColorspace)
2830 {
cristy29058e62011-02-24 03:12:50 +00002831 register IndexPacket
2832 *restrict indexes;
2833
cristy3ed852e2009-09-05 21:47:34 +00002834 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002835 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002836 indexes[x]=index;
2837 }
2838 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2839 status=MagickFalse;
2840 }
2841 image_view=DestroyCacheView(image_view);
2842 return(status);
2843}
2844
2845/*
2846%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2847% %
2848% %
2849% %
cristya5b77cb2010-05-07 19:34:48 +00002850% S e t I m a g e C o l o r %
2851% %
2852% %
2853% %
2854%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2855%
2856% SetImageColor() set the entire image canvas to the specified color.
2857%
2858% The format of the SetImageColor method is:
2859%
2860% MagickBooleanType SetImageColor(Image *image,
2861% const MagickPixelPacket *color)
2862%
2863% A description of each parameter follows:
2864%
2865% o image: the image.
2866%
2867% o background: the image color.
2868%
2869*/
2870MagickExport MagickBooleanType SetImageColor(Image *image,
2871 const MagickPixelPacket *color)
2872{
2873 CacheView
2874 *image_view;
2875
2876 ExceptionInfo
2877 *exception;
2878
cristya5b77cb2010-05-07 19:34:48 +00002879 MagickBooleanType
2880 status;
2881
cristycb6d09b2010-06-19 01:59:36 +00002882 ssize_t
2883 y;
2884
cristya5b77cb2010-05-07 19:34:48 +00002885 assert(image != (Image *) NULL);
2886 if (image->debug != MagickFalse)
2887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2888 assert(image->signature == MagickSignature);
2889 assert(color != (const MagickPixelPacket *) NULL);
2890 image->colorspace=color->colorspace;
2891 image->matte=color->matte;
2892 image->fuzz=color->fuzz;
2893 image->depth=color->depth;
2894 status=MagickTrue;
2895 exception=(&image->exception);
2896 image_view=AcquireCacheView(image);
2897#if defined(MAGICKCORE_OPENMP_SUPPORT)
2898 #pragma omp parallel for schedule(dynamic,4) shared(status)
2899#endif
cristybb503372010-05-27 20:51:26 +00002900 for (y=0; y < (ssize_t) image->rows; y++)
cristya5b77cb2010-05-07 19:34:48 +00002901 {
2902 register IndexPacket
2903 *restrict indexes;
2904
cristya5b77cb2010-05-07 19:34:48 +00002905 register PixelPacket
2906 *restrict q;
2907
cristycb6d09b2010-06-19 01:59:36 +00002908 register ssize_t
2909 x;
2910
cristya5b77cb2010-05-07 19:34:48 +00002911 if (status == MagickFalse)
2912 continue;
2913 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2914 if (q == (PixelPacket *) NULL)
2915 {
2916 status=MagickFalse;
2917 continue;
2918 }
2919 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002920 for (x=0; x < (ssize_t) image->columns; x++)
cristya5b77cb2010-05-07 19:34:48 +00002921 {
2922 SetPixelPacket(image,color,q,indexes+x);
2923 q++;
2924 }
2925 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2926 status=MagickFalse;
2927 }
2928 image_view=DestroyCacheView(image_view);
2929 return(status);
2930}
2931
2932/*
2933%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2934% %
2935% %
2936% %
cristy3ed852e2009-09-05 21:47:34 +00002937% S e t I m a g e S t o r a g e C l a s s %
2938% %
2939% %
2940% %
2941%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2942%
2943% SetImageStorageClass() sets the image class: DirectClass for true color
2944% images or PseudoClass for colormapped images.
2945%
2946% The format of the SetImageStorageClass method is:
2947%
2948% MagickBooleanType SetImageStorageClass(Image *image,
2949% const ClassType storage_class)
2950%
2951% A description of each parameter follows:
2952%
2953% o image: the image.
2954%
2955% o storage_class: The image class.
2956%
2957*/
2958MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2959 const ClassType storage_class)
2960{
cristy3ed852e2009-09-05 21:47:34 +00002961 image->storage_class=storage_class;
cristy537e2722010-09-21 15:30:59 +00002962 return(MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00002963}
2964
2965/*
2966%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2967% %
2968% %
2969% %
2970% S e t I m a g e C l i p M a s k %
2971% %
2972% %
2973% %
2974%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2975%
2976% SetImageClipMask() associates a clip path with the image. The clip path
2977% must be the same dimensions as the image. Set any pixel component of
2978% the clip path to TransparentOpacity to prevent that corresponding image
2979% pixel component from being updated when SyncAuthenticPixels() is applied.
2980%
2981% The format of the SetImageClipMask method is:
2982%
2983% MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2984%
2985% A description of each parameter follows:
2986%
2987% o image: the image.
2988%
2989% o clip_mask: the image clip path.
2990%
2991*/
2992MagickExport MagickBooleanType SetImageClipMask(Image *image,
2993 const Image *clip_mask)
2994{
2995 assert(image != (Image *) NULL);
2996 if (image->debug != MagickFalse)
2997 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2998 assert(image->signature == MagickSignature);
2999 if (clip_mask != (const Image *) NULL)
3000 if ((clip_mask->columns != image->columns) ||
3001 (clip_mask->rows != image->rows))
3002 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3003 if (image->clip_mask != (Image *) NULL)
3004 image->clip_mask=DestroyImage(image->clip_mask);
3005 image->clip_mask=NewImageList();
3006 if (clip_mask == (Image *) NULL)
3007 return(MagickTrue);
3008 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3009 return(MagickFalse);
3010 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
3011 if (image->clip_mask == (Image *) NULL)
3012 return(MagickFalse);
3013 return(MagickTrue);
3014}
3015
3016/*
3017%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3018% %
3019% %
3020% %
3021% S e t I m a g e E x t e n t %
3022% %
3023% %
3024% %
3025%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3026%
3027% SetImageExtent() sets the image size (i.e. columns & rows).
3028%
3029% The format of the SetImageExtent method is:
3030%
3031% MagickBooleanType SetImageExtent(Image *image,
cristybb503372010-05-27 20:51:26 +00003032% const size_t columns,const size_t rows)
cristy3ed852e2009-09-05 21:47:34 +00003033%
3034% A description of each parameter follows:
3035%
3036% o image: the image.
3037%
3038% o columns: The image width in pixels.
3039%
3040% o rows: The image height in pixels.
3041%
3042*/
3043MagickExport MagickBooleanType SetImageExtent(Image *image,
cristybb503372010-05-27 20:51:26 +00003044 const size_t columns,const size_t rows)
cristy3ed852e2009-09-05 21:47:34 +00003045{
cristy537e2722010-09-21 15:30:59 +00003046 if ((columns == 0) || (rows == 0))
3047 return(MagickFalse);
3048 image->columns=columns;
3049 image->rows=rows;
3050 return(MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003051}
3052
3053/*
3054%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3055% %
3056% %
3057% %
3058+ S e t I m a g e I n f o %
3059% %
3060% %
3061% %
3062%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3063%
3064% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
3065% It is set to a type of image format based on the prefix or suffix of the
3066% filename. For example, `ps:image' returns PS indicating a Postscript image.
3067% JPEG is returned for this filename: `image.jpg'. The filename prefix has
3068% precendence over the suffix. Use an optional index enclosed in brackets
3069% after a file name to specify a desired scene of a multi-resolution image
3070% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
3071% indicates success.
3072%
3073% The format of the SetImageInfo method is:
3074%
3075% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00003076% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003077%
3078% A description of each parameter follows:
3079%
cristyd965a422010-03-03 17:47:35 +00003080% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00003081%
cristyd965a422010-03-03 17:47:35 +00003082% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00003083%
3084% o exception: return any errors or warnings in this structure.
3085%
3086*/
3087MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00003088 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003089{
3090 char
3091 extension[MaxTextExtent],
3092 filename[MaxTextExtent],
3093 magic[MaxTextExtent],
3094 *q,
3095 subimage[MaxTextExtent];
3096
3097 const MagicInfo
3098 *magic_info;
3099
3100 const MagickInfo
3101 *magick_info;
3102
3103 ExceptionInfo
3104 *sans_exception;
3105
3106 Image
3107 *image;
3108
3109 MagickBooleanType
3110 status;
3111
3112 register const char
3113 *p;
3114
3115 ssize_t
3116 count;
3117
3118 unsigned char
3119 magick[2*MaxTextExtent];
3120
3121 /*
3122 Look for 'image.format' in filename.
3123 */
3124 assert(image_info != (ImageInfo *) NULL);
3125 assert(image_info->signature == MagickSignature);
3126 if (image_info->debug != MagickFalse)
3127 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3128 image_info->filename);
3129 *subimage='\0';
cristyd965a422010-03-03 17:47:35 +00003130 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003131 {
cristyd965a422010-03-03 17:47:35 +00003132 GetPathComponent(image_info->filename,SubimagePath,subimage);
3133 if (*subimage != '\0')
cristy3ed852e2009-09-05 21:47:34 +00003134 {
cristyd965a422010-03-03 17:47:35 +00003135 /*
3136 Look for scene specification (e.g. img0001.pcd[4]).
3137 */
3138 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3139 {
3140 if (IsGeometry(subimage) != MagickFalse)
3141 (void) CloneString(&image_info->extract,subimage);
3142 }
3143 else
3144 {
cristybb503372010-05-27 20:51:26 +00003145 size_t
cristyd965a422010-03-03 17:47:35 +00003146 first,
3147 last;
cristy3ed852e2009-09-05 21:47:34 +00003148
cristyd965a422010-03-03 17:47:35 +00003149 (void) CloneString(&image_info->scenes,subimage);
3150 image_info->scene=StringToUnsignedLong(image_info->scenes);
3151 image_info->number_scenes=image_info->scene;
3152 p=image_info->scenes;
3153 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3154 {
3155 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3156 (*p == ','))
3157 p++;
cristybb503372010-05-27 20:51:26 +00003158 first=(size_t) strtol(p,&q,10);
cristyd965a422010-03-03 17:47:35 +00003159 last=first;
3160 while (isspace((int) ((unsigned char) *q)) != 0)
3161 q++;
3162 if (*q == '-')
cristybb503372010-05-27 20:51:26 +00003163 last=(size_t) strtol(q+1,&q,10);
cristyd965a422010-03-03 17:47:35 +00003164 if (first > last)
3165 Swap(first,last);
3166 if (first < image_info->scene)
3167 image_info->scene=first;
3168 if (last > image_info->number_scenes)
3169 image_info->number_scenes=last;
3170 p=q;
3171 }
3172 image_info->number_scenes-=image_info->scene-1;
3173 image_info->subimage=image_info->scene;
3174 image_info->subrange=image_info->number_scenes;
3175 }
cristy3ed852e2009-09-05 21:47:34 +00003176 }
3177 }
3178 *extension='\0';
3179 GetPathComponent(image_info->filename,ExtensionPath,extension);
3180#if defined(MAGICKCORE_ZLIB_DELEGATE)
3181 if (*extension != '\0')
3182 if ((LocaleCompare(extension,"gz") == 0) ||
3183 (LocaleCompare(extension,"Z") == 0) ||
3184 (LocaleCompare(extension,"wmz") == 0))
3185 {
3186 char
3187 path[MaxTextExtent];
3188
3189 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3190 path[strlen(path)-strlen(extension)-1]='\0';
3191 GetPathComponent(path,ExtensionPath,extension);
3192 }
3193#endif
3194#if defined(MAGICKCORE_BZLIB_DELEGATE)
3195 if (*extension != '\0')
3196 if (LocaleCompare(extension,"bz2") == 0)
3197 {
3198 char
3199 path[MaxTextExtent];
3200
3201 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3202 path[strlen(path)-strlen(extension)-1]='\0';
3203 GetPathComponent(path,ExtensionPath,extension);
3204 }
3205#endif
3206 image_info->affirm=MagickFalse;
3207 sans_exception=AcquireExceptionInfo();
3208 if (*extension != '\0')
3209 {
3210 MagickFormatType
3211 format_type;
3212
cristybb503372010-05-27 20:51:26 +00003213 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003214 i;
3215
3216 static const char
3217 *format_type_formats[] =
3218 {
3219 "AUTOTRACE",
3220 "BROWSE",
3221 "DCRAW",
3222 "EDIT",
3223 "EPHEMERAL",
3224 "LAUNCH",
3225 "MPEG:DECODE",
3226 "MPEG:ENCODE",
3227 "PRINT",
3228 "PS:ALPHA",
3229 "PS:CMYK",
3230 "PS:COLOR",
3231 "PS:GRAY",
3232 "PS:MONO",
3233 "SCAN",
3234 "SHOW",
3235 "WIN",
3236 (char *) NULL
3237 };
3238
3239 /*
3240 User specified image format.
3241 */
3242 (void) CopyMagickString(magic,extension,MaxTextExtent);
3243 LocaleUpper(magic);
3244 /*
3245 Look for explicit image formats.
3246 */
3247 format_type=UndefinedFormatType;
3248 i=0;
cristydd9a2532010-02-20 19:26:46 +00003249 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00003250 (format_type_formats[i] != (char *) NULL))
3251 {
3252 if ((*magic == *format_type_formats[i]) &&
3253 (LocaleCompare(magic,format_type_formats[i]) == 0))
3254 format_type=ExplicitFormatType;
3255 i++;
3256 }
3257 magick_info=GetMagickInfo(magic,sans_exception);
3258 if ((magick_info != (const MagickInfo *) NULL) &&
3259 (magick_info->format_type != UndefinedFormatType))
3260 format_type=magick_info->format_type;
3261 if (format_type == UndefinedFormatType)
3262 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3263 else
3264 if (format_type == ExplicitFormatType)
3265 {
3266 image_info->affirm=MagickTrue;
3267 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3268 }
3269 if (LocaleCompare(magic,"RGB") == 0)
3270 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3271 }
3272 /*
3273 Look for explicit 'format:image' in filename.
3274 */
3275 *magic='\0';
3276 GetPathComponent(image_info->filename,MagickPath,magic);
3277 if (*magic == '\0')
3278 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3279 else
3280 {
3281 /*
3282 User specified image format.
3283 */
3284 LocaleUpper(magic);
3285 if (IsMagickConflict(magic) == MagickFalse)
3286 {
3287 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3288 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3289 image_info->affirm=MagickTrue;
3290 else
3291 image_info->temporary=MagickTrue;
3292 }
3293 }
3294 magick_info=GetMagickInfo(magic,sans_exception);
3295 sans_exception=DestroyExceptionInfo(sans_exception);
3296 if ((magick_info == (const MagickInfo *) NULL) ||
3297 (GetMagickEndianSupport(magick_info) == MagickFalse))
3298 image_info->endian=UndefinedEndian;
3299 GetPathComponent(image_info->filename,CanonicalPath,filename);
3300 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00003301 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00003302 {
3303 /*
cristyd965a422010-03-03 17:47:35 +00003304 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00003305 */
cristyd965a422010-03-03 17:47:35 +00003306 (void) InterpretImageFilename(image_info,(Image *) NULL,
3307 image_info->filename,(int) image_info->scene,filename);
3308 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3309 (strchr(filename,'%') == (char *) NULL))
3310 image_info->adjoin=MagickFalse;
3311 }
3312 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3313 {
3314 /*
3315 Some image formats do not support multiple frames per file.
3316 */
cristy3ed852e2009-09-05 21:47:34 +00003317 magick_info=GetMagickInfo(magic,exception);
3318 if (magick_info != (const MagickInfo *) NULL)
3319 if (GetMagickAdjoin(magick_info) == MagickFalse)
3320 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003321 }
3322 if (image_info->affirm != MagickFalse)
3323 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00003324 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003325 {
3326 /*
cristyd965a422010-03-03 17:47:35 +00003327 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00003328 */
cristyd965a422010-03-03 17:47:35 +00003329 image=AcquireImage(image_info);
3330 (void) CopyMagickString(image->filename,image_info->filename,
3331 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003332 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3333 if (status == MagickFalse)
3334 {
3335 image=DestroyImage(image);
3336 return(MagickFalse);
3337 }
cristyd965a422010-03-03 17:47:35 +00003338 if ((IsBlobSeekable(image) == MagickFalse) ||
3339 (IsBlobExempt(image) != MagickFalse))
3340 {
3341 /*
3342 Copy standard input or pipe to temporary file.
3343 */
3344 *filename='\0';
3345 status=ImageToFile(image,filename,exception);
3346 (void) CloseBlob(image);
3347 if (status == MagickFalse)
3348 {
3349 image=DestroyImage(image);
3350 return(MagickFalse);
3351 }
3352 SetImageInfoFile(image_info,(FILE *) NULL);
3353 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3354 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3355 if (status == MagickFalse)
3356 {
3357 image=DestroyImage(image);
3358 return(MagickFalse);
3359 }
3360 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3361 image_info->temporary=MagickTrue;
3362 }
3363 (void) ResetMagickMemory(magick,0,sizeof(magick));
3364 count=ReadBlob(image,2*MaxTextExtent,magick);
3365 (void) CloseBlob(image);
3366 image=DestroyImage(image);
3367 /*
3368 Check magic.xml configuration file.
3369 */
3370 sans_exception=AcquireExceptionInfo();
3371 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3372 if ((magic_info != (const MagicInfo *) NULL) &&
3373 (GetMagicName(magic_info) != (char *) NULL))
3374 {
3375 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3376 MaxTextExtent);
3377 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3378 if ((magick_info == (const MagickInfo *) NULL) ||
3379 (GetMagickEndianSupport(magick_info) == MagickFalse))
3380 image_info->endian=UndefinedEndian;
3381 sans_exception=DestroyExceptionInfo(sans_exception);
3382 return(MagickTrue);
3383 }
cristy3ed852e2009-09-05 21:47:34 +00003384 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3385 if ((magick_info == (const MagickInfo *) NULL) ||
3386 (GetMagickEndianSupport(magick_info) == MagickFalse))
3387 image_info->endian=UndefinedEndian;
3388 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00003389 }
cristy3ed852e2009-09-05 21:47:34 +00003390 return(MagickTrue);
3391}
3392
3393/*
3394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3395% %
3396% %
3397% %
3398% S e t I m a g e I n f o B l o b %
3399% %
3400% %
3401% %
3402%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3403%
3404% SetImageInfoBlob() sets the image info blob member.
3405%
3406% The format of the SetImageInfoBlob method is:
3407%
3408% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3409% const size_t length)
3410%
3411% A description of each parameter follows:
3412%
3413% o image_info: the image info.
3414%
3415% o blob: the blob.
3416%
3417% o length: the blob length.
3418%
3419*/
3420MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3421 const size_t length)
3422{
3423 assert(image_info != (ImageInfo *) NULL);
3424 assert(image_info->signature == MagickSignature);
3425 if (image_info->debug != MagickFalse)
3426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3427 image_info->filename);
3428 image_info->blob=(void *) blob;
3429 image_info->length=length;
3430}
3431
3432/*
3433%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3434% %
3435% %
3436% %
3437% S e t I m a g e I n f o F i l e %
3438% %
3439% %
3440% %
3441%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3442%
3443% SetImageInfoFile() sets the image info file member.
3444%
3445% The format of the SetImageInfoFile method is:
3446%
3447% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3448%
3449% A description of each parameter follows:
3450%
3451% o image_info: the image info.
3452%
3453% o file: the file.
3454%
3455*/
3456MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3457{
3458 assert(image_info != (ImageInfo *) NULL);
3459 assert(image_info->signature == MagickSignature);
3460 if (image_info->debug != MagickFalse)
3461 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3462 image_info->filename);
3463 image_info->file=file;
3464}
3465
3466/*
3467%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3468% %
3469% %
3470% %
3471% S e t I m a g e M a s k %
3472% %
3473% %
3474% %
3475%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3476%
3477% SetImageMask() associates a mask with the image. The mask must be the same
3478% dimensions as the image.
3479%
3480% The format of the SetImageMask method is:
3481%
3482% MagickBooleanType SetImageMask(Image *image,const Image *mask)
3483%
3484% A description of each parameter follows:
3485%
3486% o image: the image.
3487%
3488% o mask: the image mask.
3489%
3490*/
3491MagickExport MagickBooleanType SetImageMask(Image *image,
3492 const Image *mask)
3493{
3494 assert(image != (Image *) NULL);
3495 if (image->debug != MagickFalse)
3496 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3497 assert(image->signature == MagickSignature);
3498 if (mask != (const Image *) NULL)
3499 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3500 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3501 if (image->mask != (Image *) NULL)
3502 image->mask=DestroyImage(image->mask);
3503 image->mask=NewImageList();
3504 if (mask == (Image *) NULL)
3505 return(MagickTrue);
3506 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3507 return(MagickFalse);
3508 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3509 if (image->mask == (Image *) NULL)
3510 return(MagickFalse);
3511 return(MagickTrue);
3512}
3513
3514/*
3515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3516% %
3517% %
3518% %
3519% S e t I m a g e O p a c i t y %
3520% %
3521% %
3522% %
3523%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3524%
3525% SetImageOpacity() sets the opacity levels of the image.
3526%
3527% The format of the SetImageOpacity method is:
3528%
3529% MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3530%
3531% A description of each parameter follows:
3532%
3533% o image: the image.
3534%
3535% o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3536% fully transparent.
3537%
3538*/
3539MagickExport MagickBooleanType SetImageOpacity(Image *image,
3540 const Quantum opacity)
3541{
3542 CacheView
3543 *image_view;
3544
3545 ExceptionInfo
3546 *exception;
3547
cristy3ed852e2009-09-05 21:47:34 +00003548 MagickBooleanType
3549 status;
3550
cristycb6d09b2010-06-19 01:59:36 +00003551 ssize_t
3552 y;
3553
cristy3ed852e2009-09-05 21:47:34 +00003554 assert(image != (Image *) NULL);
3555 if (image->debug != MagickFalse)
3556 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3557 assert(image->signature == MagickSignature);
3558 image->matte=opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
3559 status=MagickTrue;
3560 exception=(&image->exception);
3561 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00003562#if defined(MAGICKCORE_OPENMP_SUPPORT)
3563 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003564#endif
cristybb503372010-05-27 20:51:26 +00003565 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003566 {
cristy3ed852e2009-09-05 21:47:34 +00003567 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003568 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003569
cristycb6d09b2010-06-19 01:59:36 +00003570 register ssize_t
3571 x;
3572
cristy3ed852e2009-09-05 21:47:34 +00003573 if (status == MagickFalse)
3574 continue;
3575 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3576 if (q == (PixelPacket *) NULL)
3577 {
3578 status=MagickFalse;
3579 continue;
3580 }
cristybb503372010-05-27 20:51:26 +00003581 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003582 {
cristy46f08202010-01-10 04:04:21 +00003583 SetOpacityPixelComponent(q,opacity);
cristy3ed852e2009-09-05 21:47:34 +00003584 q++;
3585 }
3586 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3587 status=MagickFalse;
3588 }
3589 image_view=DestroyCacheView(image_view);
3590 return(status);
3591}
3592
3593/*
3594%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3595% %
3596% %
3597% %
3598% S e t I m a g e T y p e %
3599% %
3600% %
3601% %
3602%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3603%
3604% SetImageType() sets the type of image. Choose from these types:
3605%
3606% Bilevel Grayscale GrayscaleMatte
3607% Palette PaletteMatte TrueColor
3608% TrueColorMatte ColorSeparation ColorSeparationMatte
3609% OptimizeType
3610%
3611% The format of the SetImageType method is:
3612%
3613% MagickBooleanType SetImageType(Image *image,const ImageType type)
3614%
3615% A description of each parameter follows:
3616%
3617% o image: the image.
3618%
3619% o type: Image type.
3620%
3621*/
3622MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3623{
3624 const char
3625 *artifact;
3626
3627 ImageInfo
3628 *image_info;
3629
3630 MagickBooleanType
3631 status;
3632
3633 QuantizeInfo
3634 *quantize_info;
3635
3636 assert(image != (Image *) NULL);
3637 if (image->debug != MagickFalse)
3638 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3639 assert(image->signature == MagickSignature);
3640 status=MagickTrue;
3641 image_info=AcquireImageInfo();
3642 image_info->dither=image->dither;
3643 artifact=GetImageArtifact(image,"dither");
3644 if (artifact != (const char *) NULL)
3645 (void) SetImageOption(image_info,"dither",artifact);
3646 switch (type)
3647 {
3648 case BilevelType:
3649 {
3650 if (IsGrayImage(image,&image->exception) == MagickFalse)
3651 status=TransformImageColorspace(image,GRAYColorspace);
3652 if (IsMonochromeImage(image,&image->exception) == MagickFalse)
3653 {
3654 quantize_info=AcquireQuantizeInfo(image_info);
3655 quantize_info->number_colors=2;
3656 quantize_info->colorspace=GRAYColorspace;
3657 status=QuantizeImage(quantize_info,image);
3658 quantize_info=DestroyQuantizeInfo(quantize_info);
3659 }
3660 image->matte=MagickFalse;
3661 break;
3662 }
3663 case GrayscaleType:
3664 {
3665 if (IsGrayImage(image,&image->exception) == MagickFalse)
3666 status=TransformImageColorspace(image,GRAYColorspace);
3667 image->matte=MagickFalse;
3668 break;
3669 }
3670 case GrayscaleMatteType:
3671 {
3672 if (IsGrayImage(image,&image->exception) == MagickFalse)
3673 status=TransformImageColorspace(image,GRAYColorspace);
3674 if (image->matte == MagickFalse)
3675 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3676 break;
3677 }
3678 case PaletteType:
3679 {
3680 if (image->colorspace != RGBColorspace)
3681 status=TransformImageColorspace(image,RGBColorspace);
3682 if ((image->storage_class == DirectClass) || (image->colors > 256))
3683 {
3684 quantize_info=AcquireQuantizeInfo(image_info);
3685 quantize_info->number_colors=256;
3686 status=QuantizeImage(quantize_info,image);
3687 quantize_info=DestroyQuantizeInfo(quantize_info);
3688 }
3689 image->matte=MagickFalse;
3690 break;
3691 }
3692 case PaletteBilevelMatteType:
3693 {
3694 if (image->colorspace != RGBColorspace)
3695 status=TransformImageColorspace(image,RGBColorspace);
3696 if (image->matte == MagickFalse)
3697 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3698 (void) BilevelImageChannel(image,AlphaChannel,(double) QuantumRange/2.0);
3699 quantize_info=AcquireQuantizeInfo(image_info);
3700 status=QuantizeImage(quantize_info,image);
3701 quantize_info=DestroyQuantizeInfo(quantize_info);
3702 break;
3703 }
3704 case PaletteMatteType:
3705 {
3706 if (image->colorspace != RGBColorspace)
3707 status=TransformImageColorspace(image,RGBColorspace);
3708 if (image->matte == MagickFalse)
3709 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3710 quantize_info=AcquireQuantizeInfo(image_info);
3711 quantize_info->colorspace=TransparentColorspace;
3712 status=QuantizeImage(quantize_info,image);
3713 quantize_info=DestroyQuantizeInfo(quantize_info);
3714 break;
3715 }
3716 case TrueColorType:
3717 {
3718 if (image->colorspace != RGBColorspace)
3719 status=TransformImageColorspace(image,RGBColorspace);
3720 if (image->storage_class != DirectClass)
3721 status=SetImageStorageClass(image,DirectClass);
3722 image->matte=MagickFalse;
3723 break;
3724 }
3725 case TrueColorMatteType:
3726 {
3727 if (image->colorspace != RGBColorspace)
3728 status=TransformImageColorspace(image,RGBColorspace);
3729 if (image->storage_class != DirectClass)
3730 status=SetImageStorageClass(image,DirectClass);
3731 if (image->matte == MagickFalse)
3732 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3733 break;
3734 }
3735 case ColorSeparationType:
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 image->matte=MagickFalse;
3746 break;
3747 }
3748 case ColorSeparationMatteType:
3749 {
3750 if (image->colorspace != CMYKColorspace)
3751 {
3752 if (image->colorspace != RGBColorspace)
3753 status=TransformImageColorspace(image,RGBColorspace);
3754 status=TransformImageColorspace(image,CMYKColorspace);
3755 }
3756 if (image->storage_class != DirectClass)
3757 status=SetImageStorageClass(image,DirectClass);
3758 if (image->matte == MagickFalse)
3759 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3760 break;
3761 }
3762 case OptimizeType:
cristy5f1c1ff2010-12-23 21:38:06 +00003763 case UndefinedType:
cristy3ed852e2009-09-05 21:47:34 +00003764 break;
3765 }
3766 image->type=type;
3767 image_info=DestroyImageInfo(image_info);
3768 return(status);
3769}
3770
3771/*
3772%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3773% %
3774% %
3775% %
3776% 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 %
3777% %
3778% %
3779% %
3780%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3781%
3782% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3783% image and returns the previous setting. A virtual pixel is any pixel access
3784% that is outside the boundaries of the image cache.
3785%
3786% The format of the SetImageVirtualPixelMethod() method is:
3787%
3788% VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3789% const VirtualPixelMethod virtual_pixel_method)
3790%
3791% A description of each parameter follows:
3792%
3793% o image: the image.
3794%
3795% o virtual_pixel_method: choose the type of virtual pixel.
3796%
3797*/
3798MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3799 const VirtualPixelMethod virtual_pixel_method)
3800{
3801 assert(image != (const Image *) NULL);
3802 assert(image->signature == MagickSignature);
3803 if (image->debug != MagickFalse)
3804 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3805 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3806}
3807
3808/*
3809%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3810% %
3811% %
3812% %
cristy4285d782011-02-09 20:12:28 +00003813% S m u s h I m a g e s %
3814% %
3815% %
3816% %
3817%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3818%
3819% SmushImages() takes all images from the current image pointer to the end
3820% of the image list and smushes them to each other top-to-bottom if the
3821% stack parameter is true, otherwise left-to-right.
3822%
3823% The current gravity setting now effects how the image is justified in the
3824% final image.
3825%
3826% The format of the SmushImages method is:
3827%
cristy4ca38e22011-02-10 02:57:49 +00003828% Image *SmushImages(const Image *images,const MagickBooleanType stack,
cristy4285d782011-02-09 20:12:28 +00003829% ExceptionInfo *exception)
3830%
3831% A description of each parameter follows:
3832%
cristy4ca38e22011-02-10 02:57:49 +00003833% o images: the image sequence.
cristy4285d782011-02-09 20:12:28 +00003834%
3835% o stack: A value other than 0 stacks the images top-to-bottom.
3836%
3837% o offset: minimum distance in pixels between images.
3838%
3839% o exception: return any errors or warnings in this structure.
3840%
3841*/
cristy4ca38e22011-02-10 02:57:49 +00003842
cristy7c6dc152011-02-11 14:10:55 +00003843static ssize_t SmushXGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003844 const ssize_t offset,ExceptionInfo *exception)
cristy4ca38e22011-02-10 02:57:49 +00003845{
cristy4d727152011-02-10 19:57:21 +00003846 CacheView
3847 *left_view,
3848 *right_view;
3849
3850 const Image
3851 *left_image,
3852 *right_image;
3853
cristy4d727152011-02-10 19:57:21 +00003854 RectangleInfo
3855 left_geometry,
3856 right_geometry;
3857
cristydab7e912011-02-11 18:19:24 +00003858 register const PixelPacket
3859 *p;
3860
cristy4d727152011-02-10 19:57:21 +00003861 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003862 i,
cristy4d727152011-02-10 19:57:21 +00003863 y;
3864
cristy7c6dc152011-02-11 14:10:55 +00003865 size_t
3866 gap;
3867
cristy4d727152011-02-10 19:57:21 +00003868 ssize_t
cristy4d727152011-02-10 19:57:21 +00003869 x;
3870
3871 if (images->previous == (Image *) NULL)
3872 return(0);
3873 right_image=images;
3874 SetGeometry(smush_image,&right_geometry);
3875 GravityAdjustGeometry(right_image->columns,right_image->rows,
3876 right_image->gravity,&right_geometry);
3877 left_image=images->previous;
3878 SetGeometry(smush_image,&left_geometry);
3879 GravityAdjustGeometry(left_image->columns,left_image->rows,
3880 left_image->gravity,&left_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003881 gap=right_image->columns;
cristy4d727152011-02-10 19:57:21 +00003882 left_view=AcquireCacheView(left_image);
3883 right_view=AcquireCacheView(right_image);
3884 for (y=0; y < (ssize_t) smush_image->rows; y++)
3885 {
3886 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3887 {
cristydab7e912011-02-11 18:19:24 +00003888 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3889 if ((p == (const PixelPacket *) NULL) ||
3890 (p->opacity != TransparentOpacity) ||
cristy7c6dc152011-02-11 14:10:55 +00003891 ((left_image->columns-x-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003892 break;
3893 }
cristy4ef6f062011-02-10 20:30:22 +00003894 i=(ssize_t) left_image->columns-x-1;
cristy4d727152011-02-10 19:57:21 +00003895 for (x=0; x < (ssize_t) right_image->columns; x++)
3896 {
cristydab7e912011-02-11 18:19:24 +00003897 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
cristy279d8212011-02-10 20:05:02 +00003898 exception);
cristydab7e912011-02-11 18:19:24 +00003899 if ((p == (const PixelPacket *) NULL) ||
3900 (p->opacity != TransparentOpacity) || ((x+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003901 break;
3902 }
cristy7c6dc152011-02-11 14:10:55 +00003903 if ((x+i) < (ssize_t) gap)
3904 gap=(size_t) (x+i);
cristy4d727152011-02-10 19:57:21 +00003905 }
3906 right_view=DestroyCacheView(right_view);
3907 left_view=DestroyCacheView(left_view);
cristydab7e912011-02-11 18:19:24 +00003908 if (y < (ssize_t) smush_image->rows)
3909 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003910 return((ssize_t) gap-offset);
cristyad5e6ee2011-02-10 14:26:00 +00003911}
3912
cristy7c6dc152011-02-11 14:10:55 +00003913static ssize_t SmushYGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003914 const ssize_t offset,ExceptionInfo *exception)
cristyad5e6ee2011-02-10 14:26:00 +00003915{
cristy4d727152011-02-10 19:57:21 +00003916 CacheView
3917 *bottom_view,
3918 *top_view;
3919
3920 const Image
3921 *bottom_image,
3922 *top_image;
3923
cristy4d727152011-02-10 19:57:21 +00003924 RectangleInfo
3925 bottom_geometry,
3926 top_geometry;
3927
cristydab7e912011-02-11 18:19:24 +00003928 register const PixelPacket
3929 *p;
3930
cristy4d727152011-02-10 19:57:21 +00003931 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003932 i,
cristy4d727152011-02-10 19:57:21 +00003933 x;
3934
cristy7c6dc152011-02-11 14:10:55 +00003935 size_t
3936 gap;
3937
cristy4d727152011-02-10 19:57:21 +00003938 ssize_t
cristy4d727152011-02-10 19:57:21 +00003939 y;
3940
3941 if (images->previous == (Image *) NULL)
3942 return(0);
3943 bottom_image=images;
3944 SetGeometry(smush_image,&bottom_geometry);
3945 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3946 bottom_image->gravity,&bottom_geometry);
3947 top_image=images->previous;
3948 SetGeometry(smush_image,&top_geometry);
3949 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3950 &top_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003951 gap=bottom_image->rows;
cristy4d727152011-02-10 19:57:21 +00003952 top_view=AcquireCacheView(top_image);
3953 bottom_view=AcquireCacheView(bottom_image);
3954 for (x=0; x < (ssize_t) smush_image->columns; x++)
3955 {
3956 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3957 {
cristydab7e912011-02-11 18:19:24 +00003958 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3959 if ((p == (const PixelPacket *) NULL) ||
3960 (p->opacity != TransparentOpacity) || ((top_image->rows-y-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003961 break;
3962 }
cristy4ef6f062011-02-10 20:30:22 +00003963 i=(ssize_t) top_image->rows-y-1;
cristy4d727152011-02-10 19:57:21 +00003964 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3965 {
cristydab7e912011-02-11 18:19:24 +00003966 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3967 exception);
3968 if ((p == (const PixelPacket *) NULL) ||
3969 (p->opacity != TransparentOpacity) || ((y+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003970 break;
3971 }
cristy7c6dc152011-02-11 14:10:55 +00003972 if ((y+i) < (ssize_t) gap)
3973 gap=(size_t) (y+i);
cristy4d727152011-02-10 19:57:21 +00003974 }
3975 bottom_view=DestroyCacheView(bottom_view);
3976 top_view=DestroyCacheView(top_view);
cristydab7e912011-02-11 18:19:24 +00003977 if (x < (ssize_t) smush_image->columns)
3978 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003979 return((ssize_t) gap-offset);
cristy4ca38e22011-02-10 02:57:49 +00003980}
3981
3982MagickExport Image *SmushImages(const Image *images,
cristy4285d782011-02-09 20:12:28 +00003983 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3984{
3985#define SmushImageTag "Smush/Image"
3986
3987 CacheView
cristybb5dced2011-02-10 02:17:16 +00003988 *smush_view;
cristy4285d782011-02-09 20:12:28 +00003989
cristy4ca38e22011-02-10 02:57:49 +00003990 const Image
3991 *image;
3992
cristy4285d782011-02-09 20:12:28 +00003993 Image
3994 *smush_image;
3995
3996 MagickBooleanType
3997 matte,
3998 proceed,
3999 status;
4000
4001 MagickOffsetType
4002 n;
4003
4004 RectangleInfo
4005 geometry;
4006
4007 register const Image
4008 *next;
4009
4010 size_t
4011 height,
4012 number_images,
4013 width;
4014
4015 ssize_t
4016 x_offset,
cristy4285d782011-02-09 20:12:28 +00004017 y_offset;
4018
4019 /*
cristy7c6dc152011-02-11 14:10:55 +00004020 Compute maximum area of smushed area.
cristy4285d782011-02-09 20:12:28 +00004021 */
cristy4ca38e22011-02-10 02:57:49 +00004022 assert(images != (Image *) NULL);
4023 assert(images->signature == MagickSignature);
4024 if (images->debug != MagickFalse)
4025 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy4285d782011-02-09 20:12:28 +00004026 assert(exception != (ExceptionInfo *) NULL);
4027 assert(exception->signature == MagickSignature);
cristy4ca38e22011-02-10 02:57:49 +00004028 image=images;
cristy4285d782011-02-09 20:12:28 +00004029 matte=image->matte;
4030 number_images=1;
4031 width=image->columns;
4032 height=image->rows;
4033 next=GetNextImageInList(image);
4034 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
4035 {
4036 if (next->matte != MagickFalse)
4037 matte=MagickTrue;
4038 number_images++;
4039 if (stack != MagickFalse)
4040 {
4041 if (next->columns > width)
4042 width=next->columns;
4043 height+=next->rows;
cristy4ef6f062011-02-10 20:30:22 +00004044 if (next->previous != (Image *) NULL)
4045 height+=offset;
cristy4285d782011-02-09 20:12:28 +00004046 continue;
4047 }
4048 width+=next->columns;
cristy4ef6f062011-02-10 20:30:22 +00004049 if (next->previous != (Image *) NULL)
4050 width+=offset;
cristy4285d782011-02-09 20:12:28 +00004051 if (next->rows > height)
4052 height=next->rows;
4053 }
4054 /*
cristy7c6dc152011-02-11 14:10:55 +00004055 Smush images.
cristy4285d782011-02-09 20:12:28 +00004056 */
4057 smush_image=CloneImage(image,width,height,MagickTrue,exception);
4058 if (smush_image == (Image *) NULL)
4059 return((Image *) NULL);
4060 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
4061 {
4062 InheritException(exception,&smush_image->exception);
4063 smush_image=DestroyImage(smush_image);
4064 return((Image *) NULL);
4065 }
4066 smush_image->matte=matte;
4067 (void) SetImageBackgroundColor(smush_image);
4068 status=MagickTrue;
4069 x_offset=0;
4070 y_offset=0;
4071 smush_view=AcquireCacheView(smush_image);
4072 for (n=0; n < (MagickOffsetType) number_images; n++)
4073 {
4074 SetGeometry(smush_image,&geometry);
4075 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4076 if (stack != MagickFalse)
cristy4ca38e22011-02-10 02:57:49 +00004077 {
4078 x_offset-=geometry.x;
cristy7c6dc152011-02-11 14:10:55 +00004079 y_offset-=SmushYGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00004080 }
cristy4285d782011-02-09 20:12:28 +00004081 else
cristy4ca38e22011-02-10 02:57:49 +00004082 {
cristy7c6dc152011-02-11 14:10:55 +00004083 x_offset-=SmushXGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00004084 y_offset-=geometry.y;
cristy4ca38e22011-02-10 02:57:49 +00004085 }
cristybb5dced2011-02-10 02:17:16 +00004086 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
cristy4285d782011-02-09 20:12:28 +00004087 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4088 if (proceed == MagickFalse)
4089 break;
4090 if (stack == MagickFalse)
4091 {
4092 x_offset+=(ssize_t) image->columns;
4093 y_offset=0;
4094 }
4095 else
4096 {
4097 x_offset=0;
4098 y_offset+=(ssize_t) image->rows;
4099 }
4100 image=GetNextImageInList(image);
4101 }
cristy4ef6f062011-02-10 20:30:22 +00004102 if (stack == MagickFalse)
4103 smush_image->columns=(size_t) x_offset;
cristy4d727152011-02-10 19:57:21 +00004104 else
cristy4ef6f062011-02-10 20:30:22 +00004105 smush_image->rows=(size_t) y_offset;
4106 smush_view=DestroyCacheView(smush_view);
cristy4285d782011-02-09 20:12:28 +00004107 if (status == MagickFalse)
4108 smush_image=DestroyImage(smush_image);
4109 return(smush_image);
4110}
4111
4112/*
4113%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4114% %
4115% %
4116% %
cristy3ed852e2009-09-05 21:47:34 +00004117% S t r i p I m a g e %
4118% %
4119% %
4120% %
4121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4122%
cristy376bda92009-12-22 21:15:23 +00004123% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00004124%
4125% The format of the StripImage method is:
4126%
4127% MagickBooleanType StripImage(Image *image)
4128%
4129% A description of each parameter follows:
4130%
4131% o image: the image.
4132%
4133*/
4134MagickExport MagickBooleanType StripImage(Image *image)
4135{
4136 assert(image != (Image *) NULL);
4137 if (image->debug != MagickFalse)
4138 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4139 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00004140 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00004141 (void) DeleteImageProperty(image,"date:create");
4142 (void) DeleteImageProperty(image,"date:modify");
glennrpce91ed52010-12-23 22:37:49 +00004143 (void) SetImageArtifact(image,"png:include-chunk","none,gama");
cristy3ed852e2009-09-05 21:47:34 +00004144 return(MagickTrue);
4145}
4146
4147/*
4148%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4149% %
4150% %
4151% %
4152+ S y n c I m a g e %
4153% %
4154% %
4155% %
4156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4157%
4158% SyncImage() initializes the red, green, and blue intensities of each pixel
4159% as defined by the colormap index.
4160%
4161% The format of the SyncImage method is:
4162%
4163% MagickBooleanType SyncImage(Image *image)
4164%
4165% A description of each parameter follows:
4166%
4167% o image: the image.
4168%
4169*/
4170
4171static inline IndexPacket PushColormapIndex(Image *image,
cristybb503372010-05-27 20:51:26 +00004172 const size_t index,MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00004173{
4174 if (index < image->colors)
4175 return((IndexPacket) index);
4176 *range_exception=MagickTrue;
4177 return((IndexPacket) 0);
4178}
4179
4180MagickExport MagickBooleanType SyncImage(Image *image)
4181{
4182 CacheView
4183 *image_view;
4184
4185 ExceptionInfo
4186 *exception;
4187
cristy3ed852e2009-09-05 21:47:34 +00004188 MagickBooleanType
4189 range_exception,
4190 status;
4191
cristycb6d09b2010-06-19 01:59:36 +00004192 ssize_t
4193 y;
4194
cristy3ed852e2009-09-05 21:47:34 +00004195 assert(image != (Image *) NULL);
4196 if (image->debug != MagickFalse)
4197 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4198 assert(image->signature == MagickSignature);
4199 if (image->storage_class == DirectClass)
4200 return(MagickFalse);
4201 range_exception=MagickFalse;
4202 status=MagickTrue;
4203 exception=(&image->exception);
4204 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00004205#if defined(MAGICKCORE_OPENMP_SUPPORT)
4206 #pragma omp parallel for schedule(dynamic,4) shared(status)
4207#endif
cristybb503372010-05-27 20:51:26 +00004208 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004209 {
4210 IndexPacket
4211 index;
4212
4213 PixelPacket
4214 pixel;
4215
4216 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00004217 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00004218
cristy3ed852e2009-09-05 21:47:34 +00004219 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00004220 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004221
cristycb6d09b2010-06-19 01:59:36 +00004222 register ssize_t
4223 x;
4224
cristy48974b92009-12-19 02:36:06 +00004225 if (status == MagickFalse)
4226 continue;
cristy3ed852e2009-09-05 21:47:34 +00004227 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4228 if (q == (PixelPacket *) NULL)
4229 {
4230 status=MagickFalse;
4231 continue;
4232 }
4233 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00004234 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004235 {
cristyc5071682011-04-22 02:06:27 +00004236 index=PushColormapIndex(image,(size_t) indexes[x],&range_exception);
cristybb503372010-05-27 20:51:26 +00004237 pixel=image->colormap[(ssize_t) index];
cristya2d08742011-04-22 19:59:52 +00004238 SetRedPixelComponent(q,pixel.red);
4239 SetGreenPixelComponent(q,pixel.green);
4240 SetBluePixelComponent(q,pixel.blue);
cristyd0272592010-04-21 01:01:49 +00004241 if (image->matte != MagickFalse)
cristya2d08742011-04-22 19:59:52 +00004242 SetOpacityPixelComponent(q,pixel.opacity);
cristy3ed852e2009-09-05 21:47:34 +00004243 q++;
4244 }
4245 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4246 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004247 }
4248 image_view=DestroyCacheView(image_view);
4249 if (range_exception != MagickFalse)
4250 (void) ThrowMagickException(&image->exception,GetMagickModule(),
4251 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
4252 return(status);
4253}
cristy1626d332009-11-10 16:58:17 +00004254
4255/*
4256%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4257% %
4258% %
4259% %
4260% S y n c I m a g e S e t t i n g s %
4261% %
4262% %
4263% %
4264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4265%
4266% SyncImageSettings() sync the image info options to the image.
4267%
4268% The format of the SyncImageSettings method is:
4269%
4270% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4271% Image *image)
4272% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
4273% Image *image)
4274%
4275% A description of each parameter follows:
4276%
4277% o image_info: the image info.
4278%
4279% o image: the image.
4280%
4281*/
4282
4283MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
4284 Image *images)
4285{
4286 Image
4287 *image;
4288
4289 assert(image_info != (const ImageInfo *) NULL);
4290 assert(image_info->signature == MagickSignature);
4291 assert(images != (Image *) NULL);
4292 assert(images->signature == MagickSignature);
4293 if (images->debug != MagickFalse)
4294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4295 image=images;
4296 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
4297 (void) SyncImageSettings(image_info,image);
4298 (void) DeleteImageOption(image_info,"page");
4299 return(MagickTrue);
4300}
4301
4302MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
4303 Image *image)
4304{
4305 char
4306 property[MaxTextExtent];
4307
4308 const char
cristy9a703812010-07-26 14:50:29 +00004309 *option,
4310 *value;
cristy1626d332009-11-10 16:58:17 +00004311
4312 GeometryInfo
4313 geometry_info;
4314
4315 MagickStatusType
4316 flags;
4317
cristy19eb6412010-04-23 14:42:29 +00004318 ResolutionType
4319 units;
4320
cristy1626d332009-11-10 16:58:17 +00004321 /*
4322 Sync image options.
4323 */
4324 assert(image_info != (const ImageInfo *) NULL);
4325 assert(image_info->signature == MagickSignature);
4326 assert(image != (Image *) NULL);
4327 assert(image->signature == MagickSignature);
4328 if (image->debug != MagickFalse)
4329 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4330 option=GetImageOption(image_info,"background");
4331 if (option != (const char *) NULL)
4332 (void) QueryColorDatabase(option,&image->background_color,
4333 &image->exception);
4334 option=GetImageOption(image_info,"bias");
4335 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00004336 image->bias=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00004337 option=GetImageOption(image_info,"black-point-compensation");
4338 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004339 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004340 MagickBooleanOptions,MagickFalse,option);
4341 option=GetImageOption(image_info,"blue-primary");
4342 if (option != (const char *) NULL)
4343 {
4344 flags=ParseGeometry(option,&geometry_info);
4345 image->chromaticity.blue_primary.x=geometry_info.rho;
4346 image->chromaticity.blue_primary.y=geometry_info.sigma;
4347 if ((flags & SigmaValue) == 0)
4348 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4349 }
4350 option=GetImageOption(image_info,"bordercolor");
4351 if (option != (const char *) NULL)
4352 (void) QueryColorDatabase(option,&image->border_color,&image->exception);
4353 option=GetImageOption(image_info,"colors");
4354 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004355 image->colors=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004356 option=GetImageOption(image_info,"compose");
4357 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004358 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
cristy1626d332009-11-10 16:58:17 +00004359 MagickFalse,option);
4360 option=GetImageOption(image_info,"compress");
4361 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004362 image->compression=(CompressionType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004363 MagickCompressOptions,MagickFalse,option);
4364 option=GetImageOption(image_info,"debug");
4365 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004366 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00004367 MagickFalse,option);
cristydd5f5912010-07-31 23:37:23 +00004368 option=GetImageOption(image_info,"density");
4369 if (option != (const char *) NULL)
4370 {
4371 GeometryInfo
4372 geometry_info;
4373
4374 /*
4375 Set image density.
4376 */
4377 flags=ParseGeometry(option,&geometry_info);
4378 image->x_resolution=geometry_info.rho;
4379 image->y_resolution=geometry_info.sigma;
4380 if ((flags & SigmaValue) == 0)
4381 image->y_resolution=image->x_resolution;
4382 }
cristy1626d332009-11-10 16:58:17 +00004383 option=GetImageOption(image_info,"depth");
4384 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004385 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004386 option=GetImageOption(image_info,"endian");
4387 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004388 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
cristy1626d332009-11-10 16:58:17 +00004389 MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00004390 option=GetImageOption(image_info,"filter");
4391 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004392 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
cristy1626d332009-11-10 16:58:17 +00004393 MagickFalse,option);
4394 option=GetImageOption(image_info,"fuzz");
4395 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00004396 image->fuzz=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00004397 option=GetImageOption(image_info,"gravity");
4398 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004399 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
cristy1626d332009-11-10 16:58:17 +00004400 MagickFalse,option);
4401 option=GetImageOption(image_info,"green-primary");
4402 if (option != (const char *) NULL)
4403 {
4404 flags=ParseGeometry(option,&geometry_info);
4405 image->chromaticity.green_primary.x=geometry_info.rho;
4406 image->chromaticity.green_primary.y=geometry_info.sigma;
4407 if ((flags & SigmaValue) == 0)
4408 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4409 }
4410 option=GetImageOption(image_info,"intent");
4411 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004412 image->rendering_intent=(RenderingIntent) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004413 MagickIntentOptions,MagickFalse,option);
4414 option=GetImageOption(image_info,"interlace");
4415 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004416 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
cristy1626d332009-11-10 16:58:17 +00004417 MagickFalse,option);
4418 option=GetImageOption(image_info,"interpolate");
4419 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004420 image->interpolate=(InterpolatePixelMethod) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004421 MagickInterpolateOptions,MagickFalse,option);
4422 option=GetImageOption(image_info,"loop");
4423 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004424 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004425 option=GetImageOption(image_info,"mattecolor");
4426 if (option != (const char *) NULL)
4427 (void) QueryColorDatabase(option,&image->matte_color,&image->exception);
4428 option=GetImageOption(image_info,"orient");
4429 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004430 image->orientation=(OrientationType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004431 MagickOrientationOptions,MagickFalse,option);
cristy9a703812010-07-26 14:50:29 +00004432 option=GetImageOption(image_info,"page");
4433 if (option != (const char *) NULL)
4434 {
4435 char
4436 *geometry;
4437
4438 geometry=GetPageGeometry(option);
4439 flags=ParseAbsoluteGeometry(geometry,&image->page);
4440 geometry=DestroyString(geometry);
4441 }
cristy1626d332009-11-10 16:58:17 +00004442 option=GetImageOption(image_info,"quality");
4443 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004444 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004445 option=GetImageOption(image_info,"red-primary");
4446 if (option != (const char *) NULL)
4447 {
4448 flags=ParseGeometry(option,&geometry_info);
4449 image->chromaticity.red_primary.x=geometry_info.rho;
4450 image->chromaticity.red_primary.y=geometry_info.sigma;
4451 if ((flags & SigmaValue) == 0)
4452 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4453 }
4454 if (image_info->quality != UndefinedCompressionQuality)
4455 image->quality=image_info->quality;
4456 option=GetImageOption(image_info,"scene");
4457 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004458 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004459 option=GetImageOption(image_info,"taint");
4460 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004461 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00004462 MagickFalse,option);
4463 option=GetImageOption(image_info,"tile-offset");
4464 if (option != (const char *) NULL)
4465 {
4466 char
4467 *geometry;
4468
4469 geometry=GetPageGeometry(option);
4470 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4471 geometry=DestroyString(geometry);
4472 }
4473 option=GetImageOption(image_info,"transparent-color");
4474 if (option != (const char *) NULL)
4475 (void) QueryColorDatabase(option,&image->transparent_color,
4476 &image->exception);
4477 option=GetImageOption(image_info,"type");
4478 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004479 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
cristy1626d332009-11-10 16:58:17 +00004480 option);
4481 option=GetImageOption(image_info,"units");
4482 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004483 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00004484 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00004485 else
4486 units = image_info->units;
4487 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00004488 {
cristy19eb6412010-04-23 14:42:29 +00004489 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00004490 switch (image->units)
4491 {
4492 case PixelsPerInchResolution:
4493 {
cristy19eb6412010-04-23 14:42:29 +00004494 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00004495 {
4496 image->x_resolution/=2.54;
4497 image->y_resolution/=2.54;
4498 }
4499 break;
4500 }
4501 case PixelsPerCentimeterResolution:
4502 {
cristy19eb6412010-04-23 14:42:29 +00004503 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00004504 {
cristybb503372010-05-27 20:51:26 +00004505 image->x_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004506 image->x_resolution+0.5))/100.0;
cristybb503372010-05-27 20:51:26 +00004507 image->y_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004508 image->y_resolution+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00004509 }
4510 break;
4511 }
4512 default:
4513 break;
4514 }
cristy19eb6412010-04-23 14:42:29 +00004515 image->units=units;
cristy1626d332009-11-10 16:58:17 +00004516 }
4517 option=GetImageOption(image_info,"white-point");
4518 if (option != (const char *) NULL)
4519 {
4520 flags=ParseGeometry(option,&geometry_info);
4521 image->chromaticity.white_point.x=geometry_info.rho;
4522 image->chromaticity.white_point.y=geometry_info.sigma;
4523 if ((flags & SigmaValue) == 0)
4524 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4525 }
4526 ResetImageOptionIterator(image_info);
4527 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4528 {
4529 value=GetImageOption(image_info,option);
4530 if (value != (const char *) NULL)
4531 {
4532 (void) FormatMagickString(property,MaxTextExtent,"%s",option);
cristydf81b992011-02-27 14:33:24 +00004533 (void) SetImageArtifact(image,property,value);
cristy1626d332009-11-10 16:58:17 +00004534 }
4535 option=GetNextImageOption(image_info);
4536 }
4537 return(MagickTrue);
4538}