blob: f5aaa892283c6def18685878bad56524eb8f1682 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% IIIII M M AAA GGGG EEEEE %
7% I MM MM A A G E %
8% I M M M AAAAA G GG EEE %
9% I M M A A G G E %
10% IIIII M M A A GGGG EEEEE %
11% %
12% %
13% MagickCore Image Methods %
14% %
15% Software Design %
16% John Cristy %
17% July 1992 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
43#include "magick/studio.h"
44#include "magick/animate.h"
45#include "magick/artifact.h"
46#include "magick/blob.h"
47#include "magick/blob-private.h"
48#include "magick/cache.h"
49#include "magick/cache-private.h"
50#include "magick/cache-view.h"
51#include "magick/client.h"
52#include "magick/color.h"
53#include "magick/color-private.h"
cristy316d5172009-09-17 19:31:25 +000054#include "magick/colormap.h"
cristy3ed852e2009-09-05 21:47:34 +000055#include "magick/colorspace.h"
56#include "magick/colorspace-private.h"
57#include "magick/composite.h"
58#include "magick/composite-private.h"
59#include "magick/compress.h"
60#include "magick/constitute.h"
61#include "magick/deprecate.h"
62#include "magick/display.h"
63#include "magick/draw.h"
64#include "magick/enhance.h"
65#include "magick/exception.h"
66#include "magick/exception-private.h"
67#include "magick/gem.h"
68#include "magick/geometry.h"
cristyf2e11662009-10-14 01:24:43 +000069#include "magick/histogram.h"
cristy3ed852e2009-09-05 21:47:34 +000070#include "magick/image-private.h"
cristyf2e11662009-10-14 01:24:43 +000071#include "magick/list.h"
cristy3ed852e2009-09-05 21:47:34 +000072#include "magick/magic.h"
73#include "magick/magick.h"
74#include "magick/memory_.h"
75#include "magick/module.h"
76#include "magick/monitor.h"
77#include "magick/monitor-private.h"
78#include "magick/option.h"
79#include "magick/paint.h"
80#include "magick/pixel-private.h"
81#include "magick/profile.h"
82#include "magick/property.h"
83#include "magick/quantize.h"
84#include "magick/random_.h"
85#include "magick/segment.h"
86#include "magick/semaphore.h"
87#include "magick/signature-private.h"
88#include "magick/statistic.h"
89#include "magick/string_.h"
cristyf2f27272009-12-17 14:48:46 +000090#include "magick/string-private.h"
cristy3ed852e2009-09-05 21:47:34 +000091#include "magick/thread-private.h"
92#include "magick/threshold.h"
93#include "magick/timer.h"
94#include "magick/utility.h"
95#include "magick/version.h"
96#include "magick/xwindow-private.h"
97
98/*
99 Constant declaration.
100*/
101const char
cristy7138c592009-09-08 13:58:52 +0000102 BackgroundColor[] = "#ffffff", /* white */
103 BorderColor[] = "#dfdfdf", /* gray */
104 DefaultTileFrame[] = "15x15+3+3",
105 DefaultTileGeometry[] = "120x120+4+3>",
106 DefaultTileLabel[] = "%f\n%G\n%b",
107 ForegroundColor[] = "#000", /* black */
108 LoadImageTag[] = "Load/Image",
109 LoadImagesTag[] = "Load/Images",
110 MatteColor[] = "#bdbdbd", /* gray */
111 PSDensityGeometry[] = "72.0x72.0",
112 PSPageGeometry[] = "612x792",
113 SaveImageTag[] = "Save/Image",
114 SaveImagesTag[] = "Save/Images",
115 TransparentColor[] = "#00000000"; /* transparent black */
cristy3ed852e2009-09-05 21:47:34 +0000116
117const double
118 DefaultResolution = 72.0;
119
120/*
121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122% %
123% %
124% %
125% A c q u i r e I m a g e %
126% %
127% %
128% %
129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130%
131% AcquireImage() returns a pointer to an image structure initialized to
132% default values.
133%
134% The format of the AcquireImage method is:
135%
136% Image *AcquireImage(const ImageInfo *image_info)
137%
138% A description of each parameter follows:
139%
140% o image_info: Many of the image default values are set from this
141% structure. For example, filename, compression, depth, background color,
142% and others.
143%
144*/
145MagickExport Image *AcquireImage(const ImageInfo *image_info)
146{
cristye412c892010-07-26 12:31:36 +0000147 const char
cristyf3a660a2010-07-26 14:17:52 +0000148 *option;
cristye412c892010-07-26 12:31:36 +0000149
cristy3ed852e2009-09-05 21:47:34 +0000150 Image
151 *image;
152
153 MagickStatusType
154 flags;
155
156 /*
157 Allocate image structure.
158 */
159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy73bd4a52010-10-05 11:24:23 +0000160 image=(Image *) AcquireMagickMemory(sizeof(*image));
cristy3ed852e2009-09-05 21:47:34 +0000161 if (image == (Image *) NULL)
162 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
163 (void) ResetMagickMemory(image,0,sizeof(*image));
164 /*
165 Initialize Image structure.
166 */
167 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
168 image->storage_class=DirectClass;
169 image->depth=MAGICKCORE_QUANTUM_DEPTH;
170 image->colorspace=RGBColorspace;
171 image->interlace=NoInterlace;
172 image->ticks_per_second=UndefinedTicksPerSecond;
173 image->compose=OverCompositeOp;
174 image->blur=1.0;
175 GetExceptionInfo(&image->exception);
176 (void) QueryColorDatabase(BackgroundColor,&image->background_color,
177 &image->exception);
178 (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception);
179 (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception);
180 (void) QueryColorDatabase(TransparentColor,&image->transparent_color,
181 &image->exception);
182 image->x_resolution=DefaultResolution;
183 image->y_resolution=DefaultResolution;
184 image->units=PixelsPerInchResolution;
185 GetTimerInfo(&image->timer);
cristy73724512010-04-12 14:43:14 +0000186 image->ping=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000187 image->cache=AcquirePixelCache(0);
188 image->blob=CloneBlobInfo((BlobInfo *) NULL);
189 image->debug=IsEventLogging();
190 image->reference_count=1;
191 image->semaphore=AllocateSemaphoreInfo();
192 image->signature=MagickSignature;
193 if (image_info == (ImageInfo *) NULL)
194 return(image);
195 /*
196 Transfer image info.
197 */
198 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
199 MagickFalse);
200 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
201 (void) CopyMagickString(image->magick_filename,image_info->filename,
202 MaxTextExtent);
203 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
204 if (image_info->size != (char *) NULL)
205 {
206 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
207 image->columns=image->extract_info.width;
208 image->rows=image->extract_info.height;
209 image->offset=image->extract_info.x;
210 image->extract_info.x=0;
211 image->extract_info.y=0;
212 }
213 if (image_info->extract != (char *) NULL)
214 {
215 RectangleInfo
216 geometry;
217
218 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
219 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
220 {
221 image->extract_info=geometry;
222 Swap(image->columns,image->extract_info.width);
223 Swap(image->rows,image->extract_info.height);
224 }
225 }
226 image->compression=image_info->compression;
227 image->quality=image_info->quality;
228 image->endian=image_info->endian;
229 image->interlace=image_info->interlace;
230 image->units=image_info->units;
231 if (image_info->density != (char *) NULL)
232 {
233 GeometryInfo
234 geometry_info;
235
236 flags=ParseGeometry(image_info->density,&geometry_info);
237 image->x_resolution=geometry_info.rho;
238 image->y_resolution=geometry_info.sigma;
239 if ((flags & SigmaValue) == 0)
240 image->y_resolution=image->x_resolution;
241 }
242 if (image_info->page != (char *) NULL)
243 {
244 char
245 *geometry;
246
247 image->page=image->extract_info;
248 geometry=GetPageGeometry(image_info->page);
249 (void) ParseAbsoluteGeometry(geometry,&image->page);
250 geometry=DestroyString(geometry);
251 }
252 if (image_info->depth != 0)
253 image->depth=image_info->depth;
254 image->dither=image_info->dither;
255 image->background_color=image_info->background_color;
256 image->border_color=image_info->border_color;
257 image->matte_color=image_info->matte_color;
258 image->transparent_color=image_info->transparent_color;
cristy73724512010-04-12 14:43:14 +0000259 image->ping=image_info->ping;
cristy3ed852e2009-09-05 21:47:34 +0000260 image->progress_monitor=image_info->progress_monitor;
261 image->client_data=image_info->client_data;
262 if (image_info->cache != (void *) NULL)
263 ClonePixelCacheMethods(image->cache,image_info->cache);
264 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
cristy6b9aca12010-02-21 01:50:11 +0000265 (void) SyncImageSettings(image_info,image);
cristye412c892010-07-26 12:31:36 +0000266 option=GetImageOption(image_info,"delay");
267 if (option != (const char *) NULL)
268 {
269 GeometryInfo
270 geometry_info;
271
272 flags=ParseGeometry(option,&geometry_info);
273 if ((flags & GreaterValue) != 0)
274 {
275 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
276 image->delay=(size_t) floor(geometry_info.rho+0.5);
277 }
278 else
279 if ((flags & LessValue) != 0)
280 {
281 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
282 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
283 }
284 else
285 image->delay=(size_t) floor(geometry_info.rho+0.5);
286 if ((flags & SigmaValue) != 0)
287 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
288 }
289 option=GetImageOption(image_info,"dispose");
290 if (option != (const char *) NULL)
291 image->dispose=(DisposeType) ParseMagickOption(MagickDisposeOptions,
292 MagickFalse,option);
cristy3ed852e2009-09-05 21:47:34 +0000293 return(image);
294}
295
296/*
297%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298% %
299% %
300% %
cristy3ed852e2009-09-05 21:47:34 +0000301% A c q u i r e I m a g e I n f o %
302% %
303% %
304% %
305%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306%
307% AcquireImageInfo() allocates the ImageInfo structure.
308%
309% The format of the AcquireImageInfo method is:
310%
311% ImageInfo *AcquireImageInfo(void)
312%
313*/
314MagickExport ImageInfo *AcquireImageInfo(void)
315{
316 ImageInfo
317 *image_info;
318
cristy73bd4a52010-10-05 11:24:23 +0000319 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
cristy3ed852e2009-09-05 21:47:34 +0000320 if (image_info == (ImageInfo *) NULL)
321 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
322 GetImageInfo(image_info);
323 return(image_info);
324}
325
326/*
327%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328% %
329% %
330% %
331% A c q u i r e N e x t I m a g e %
332% %
333% %
334% %
335%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336%
337% AcquireNextImage() initializes the next image in a sequence to
338% default values. The next member of image points to the newly allocated
339% image. If there is a memory shortage, next is assigned NULL.
340%
341% The format of the AcquireNextImage method is:
342%
343% void AcquireNextImage(const ImageInfo *image_info,Image *image)
344%
345% A description of each parameter follows:
346%
347% o image_info: Many of the image default values are set from this
348% structure. For example, filename, compression, depth, background color,
349% and others.
350%
351% o image: the image.
352%
353*/
354MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image)
355{
356 /*
357 Allocate image structure.
358 */
359 assert(image != (Image *) NULL);
360 assert(image->signature == MagickSignature);
361 if (image->debug != MagickFalse)
362 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
363 image->next=AcquireImage(image_info);
364 if (GetNextImageInList(image) == (Image *) NULL)
365 return;
366 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
367 MaxTextExtent);
368 if (image_info != (ImageInfo *) NULL)
369 (void) CopyMagickString(GetNextImageInList(image)->filename,
370 image_info->filename,MaxTextExtent);
371 DestroyBlob(GetNextImageInList(image));
372 image->next->blob=ReferenceBlob(image->blob);
373 image->next->endian=image->endian;
374 image->next->scene=image->scene+1;
375 image->next->previous=image;
376}
377
378/*
379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380% %
381% %
382% %
383% A p p e n d I m a g e s %
384% %
385% %
386% %
387%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
388%
389% AppendImages() takes all images from the current image pointer to the end
390% of the image list and appends them to each other top-to-bottom if the
391% stack parameter is true, otherwise left-to-right.
392%
393% The current gravity setting now effects how the image is justified in the
394% final image.
395%
396% The format of the AppendImages method is:
397%
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 {
2376 q->green=q->red;
2377 q->blue=q->red;
2378 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 {
2386 q->red=q->green;
2387 q->blue=q->green;
2388 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 {
2396 q->red=q->blue;
2397 q->green=q->blue;
2398 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 {
2406 q->red=q->opacity;
2407 q->green=q->opacity;
2408 q->blue=q->opacity;
2409 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 {
2420 q->red=indexes[x];
2421 q->green=indexes[x];
2422 q->blue=indexes[x];
2423 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 {
cristy46f08202010-01-10 04:04:21 +00002431 q->red=(Quantum) GetAlphaPixelComponent(q);
2432 q->green=(Quantum) GetAlphaPixelComponent(q);
2433 q->blue=(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 {
2442 q->opacity=(Quantum) (QuantumRange-PixelIntensityToQuantum(q));
2443 q++;
2444 }
2445 break;
2446 }
2447 default:
2448 break;
2449 }
2450 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2451 status=MagickFalse;
2452 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2453 {
2454 MagickBooleanType
2455 proceed;
2456
cristyb5d5f722009-11-04 03:03:49 +00002457#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00002458 #pragma omp critical (MagickCore_SeparateImageChannel)
2459#endif
2460 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2461 if (proceed == MagickFalse)
2462 status=MagickFalse;
2463 }
2464 }
2465 image_view=DestroyCacheView(image_view);
cristy11b66ce2010-03-11 13:34:19 +00002466 if (channel != GrayChannels)
cristy3ed852e2009-09-05 21:47:34 +00002467 image->matte=MagickFalse;
2468 (void) SetImageColorspace(image,RGBColorspace);
2469 return(status);
2470}
2471
2472/*
2473%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2474% %
2475% %
2476% %
2477% S e p a r a t e I m a g e s %
2478% %
2479% %
2480% %
2481%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2482%
2483% SeparateImages() returns a separate grayscale image for each channel
2484% specified.
2485%
2486% The format of the SeparateImages method is:
2487%
2488% MagickBooleanType SeparateImages(const Image *image,
2489% const ChannelType channel,ExceptionInfo *exception)
2490%
2491% A description of each parameter follows:
2492%
2493% o image: the image.
2494%
2495% o channel: Identify which channels to extract: RedChannel, GreenChannel,
2496% BlueChannel, OpacityChannel, CyanChannel, MagentaChannel,
2497% YellowChannel, or BlackChannel.
2498%
2499% o exception: return any errors or warnings in this structure.
2500%
2501*/
2502MagickExport Image *SeparateImages(const Image *image,const ChannelType channel,
2503 ExceptionInfo *exception)
2504{
2505 Image
2506 *images,
2507 *separate_image;
2508
2509 assert(image != (Image *) NULL);
2510 assert(image->signature == MagickSignature);
2511 if (image->debug != MagickFalse)
2512 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2513 images=NewImageList();
2514 if ((channel & RedChannel) != 0)
2515 {
2516 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2517 (void) SeparateImageChannel(separate_image,RedChannel);
2518 AppendImageToList(&images,separate_image);
2519 }
2520 if ((channel & GreenChannel) != 0)
2521 {
2522 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2523 (void) SeparateImageChannel(separate_image,GreenChannel);
2524 AppendImageToList(&images,separate_image);
2525 }
2526 if ((channel & BlueChannel) != 0)
2527 {
2528 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2529 (void) SeparateImageChannel(separate_image,BlueChannel);
2530 AppendImageToList(&images,separate_image);
2531 }
2532 if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace))
2533 {
2534 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2535 (void) SeparateImageChannel(separate_image,BlackChannel);
2536 AppendImageToList(&images,separate_image);
2537 }
2538 if ((channel & OpacityChannel) != 0)
2539 {
2540 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2541 (void) SeparateImageChannel(separate_image,OpacityChannel);
2542 AppendImageToList(&images,separate_image);
2543 }
2544 return(images);
2545}
2546
2547/*
2548%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2549% %
2550% %
2551% %
2552% S e t I m a g e A l p h a C h a n n e l %
2553% %
2554% %
2555% %
2556%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2557%
2558% SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2559% channel.
2560%
2561% The format of the SetImageAlphaChannel method is:
2562%
2563% MagickBooleanType SetImageAlphaChannel(Image *image,
2564% const AlphaChannelType alpha_type)
2565%
2566% A description of each parameter follows:
2567%
2568% o image: the image.
2569%
2570% o alpha_type: The alpha channel type: ActivateAlphaChannel,
2571% CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
2572% OpaqueAlphaChannel, ResetAlphaChannel, SetAlphaChannel,
2573% ShapeAlphaChannel, and TransparentAlphaChannel.
2574%
2575*/
2576MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
2577 const AlphaChannelType alpha_type)
2578{
2579 MagickBooleanType
2580 status;
2581
2582 assert(image != (Image *) NULL);
2583 if (image->debug != MagickFalse)
2584 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2585 assert(image->signature == MagickSignature);
2586 status=MagickFalse;
2587 switch (alpha_type)
2588 {
2589 case ActivateAlphaChannel:
2590 {
2591 image->matte=MagickTrue;
2592 break;
2593 }
2594 case BackgroundAlphaChannel:
2595 {
2596 CacheView
2597 *image_view;
2598
2599 ExceptionInfo
2600 *exception;
2601
2602 IndexPacket
2603 index;
2604
cristy3ed852e2009-09-05 21:47:34 +00002605 MagickBooleanType
2606 status;
2607
2608 MagickPixelPacket
2609 background;
2610
2611 PixelPacket
2612 pixel;
2613
cristycb6d09b2010-06-19 01:59:36 +00002614 ssize_t
2615 y;
2616
cristy3ed852e2009-09-05 21:47:34 +00002617 /*
2618 Set transparent pixels to background color.
2619 */
2620 if (image->matte == MagickFalse)
2621 break;
2622 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2623 break;
2624 GetMagickPixelPacket(image,&background);
2625 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2626 NULL,&background);
2627 if (image->colorspace == CMYKColorspace)
2628 ConvertRGBToCMYK(&background);
2629 index=0;
2630 SetPixelPacket(image,&background,&pixel,&index);
2631 status=MagickTrue;
2632 exception=(&image->exception);
2633 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002634 #if defined(MAGICKCORE_OPENMP_SUPPORT)
2635 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00002636 #endif
cristybb503372010-05-27 20:51:26 +00002637 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002638 {
2639 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00002640 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00002641
cristy3ed852e2009-09-05 21:47:34 +00002642 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002643 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002644
cristycb6d09b2010-06-19 01:59:36 +00002645 register ssize_t
2646 x;
2647
cristy3ed852e2009-09-05 21:47:34 +00002648 if (status == MagickFalse)
2649 continue;
2650 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2651 exception);
2652 if (q == (PixelPacket *) NULL)
2653 {
2654 status=MagickFalse;
2655 continue;
2656 }
cristybb503372010-05-27 20:51:26 +00002657 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002658 {
2659 if (q->opacity == TransparentOpacity)
2660 {
2661 q->red=pixel.red;
2662 q->green=pixel.green;
2663 q->blue=pixel.blue;
2664 }
2665 q++;
2666 }
2667 if (image->colorspace == CMYKColorspace)
2668 {
2669 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002670 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002671 indexes[x]=index;
2672 }
2673 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2674 status=MagickFalse;
2675 }
2676 image_view=DestroyCacheView(image_view);
2677 return(status);
2678 }
2679 case DeactivateAlphaChannel:
2680 {
2681 image->matte=MagickFalse;
2682 break;
2683 }
2684 case ShapeAlphaChannel:
2685 case CopyAlphaChannel:
2686 {
2687 /*
2688 Special usage case for SeparateImageChannel(): copy grayscale color to
2689 the alpha channel.
2690 */
2691 status=SeparateImageChannel(image,GrayChannels);
2692 image->matte=MagickTrue; /* make sure transparency is now on! */
2693 if (alpha_type == ShapeAlphaChannel)
2694 {
2695 MagickPixelPacket
2696 background;
2697
2698 /*
2699 Reset all color channels to background color.
2700 */
2701 GetMagickPixelPacket(image,&background);
2702 SetMagickPixelPacket(image,&(image->background_color),(IndexPacket *)
2703 NULL,&background);
cristy308b4e62009-09-21 14:40:44 +00002704 (void) LevelColorsImage(image,&background,&background,MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00002705 }
2706 break;
2707 }
2708 case ExtractAlphaChannel:
2709 {
2710 status=SeparateImageChannel(image,TrueAlphaChannel);
2711 image->matte=MagickFalse;
2712 break;
2713 }
cristyf64d18b2010-04-30 12:47:03 +00002714 case ResetAlphaChannel: /* deprecated */
cristy3ed852e2009-09-05 21:47:34 +00002715 case OpaqueAlphaChannel:
2716 {
2717 status=SetImageOpacity(image,OpaqueOpacity);
2718 image->matte=MagickTrue;
2719 break;
2720 }
2721 case TransparentAlphaChannel:
2722 {
2723 status=SetImageOpacity(image,TransparentOpacity);
2724 image->matte=MagickTrue;
2725 break;
2726 }
2727 case SetAlphaChannel:
2728 {
2729 if (image->matte == MagickFalse)
2730 {
2731 status=SetImageOpacity(image,OpaqueOpacity);
2732 image->matte=MagickTrue;
2733 }
2734 break;
2735 }
2736 case UndefinedAlphaChannel:
2737 break;
2738 }
2739 return(status);
2740}
2741
2742/*
2743%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2744% %
2745% %
2746% %
2747% S e t I m a g e B a c k g r o u n d C o l o r %
2748% %
2749% %
2750% %
2751%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2752%
2753% SetImageBackgroundColor() initializes the image pixels to the image
2754% background color. The background color is defined by the background_color
2755% member of the image structure.
2756%
2757% The format of the SetImage method is:
2758%
2759% MagickBooleanType SetImageBackgroundColor(Image *image)
2760%
2761% A description of each parameter follows:
2762%
2763% o image: the image.
2764%
2765*/
2766MagickExport MagickBooleanType SetImageBackgroundColor(Image *image)
2767{
2768 CacheView
2769 *image_view;
2770
2771 ExceptionInfo
2772 *exception;
2773
2774 IndexPacket
2775 index;
2776
cristy3ed852e2009-09-05 21:47:34 +00002777 MagickBooleanType
2778 status;
2779
2780 MagickPixelPacket
2781 background;
2782
2783 PixelPacket
2784 pixel;
2785
cristycb6d09b2010-06-19 01:59:36 +00002786 ssize_t
2787 y;
2788
cristy3ed852e2009-09-05 21:47:34 +00002789 assert(image != (Image *) NULL);
2790 if (image->debug != MagickFalse)
2791 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2792 assert(image->signature == MagickSignature);
2793 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
2794 return(MagickFalse);
2795 if (image->background_color.opacity != OpaqueOpacity)
2796 image->matte=MagickTrue;
2797 GetMagickPixelPacket(image,&background);
2798 SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *)
2799 NULL,&background);
2800 if (image->colorspace == CMYKColorspace)
2801 ConvertRGBToCMYK(&background);
2802 index=0;
2803 SetPixelPacket(image,&background,&pixel,&index);
2804 /*
2805 Set image background color.
2806 */
2807 status=MagickTrue;
2808 exception=(&image->exception);
2809 image_view=AcquireCacheView(image);
cristybb503372010-05-27 20:51:26 +00002810 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002811 {
cristy3ed852e2009-09-05 21:47:34 +00002812 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002813 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002814
cristycb6d09b2010-06-19 01:59:36 +00002815 register ssize_t
2816 x;
2817
cristy3ed852e2009-09-05 21:47:34 +00002818 if (status == MagickFalse)
2819 continue;
2820 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2821 if (q == (PixelPacket *) NULL)
2822 {
2823 status=MagickFalse;
2824 continue;
2825 }
cristybb503372010-05-27 20:51:26 +00002826 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002827 *q++=pixel;
2828 if (image->colorspace == CMYKColorspace)
2829 {
cristy29058e62011-02-24 03:12:50 +00002830 register IndexPacket
2831 *restrict indexes;
2832
cristy3ed852e2009-09-05 21:47:34 +00002833 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002834 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002835 indexes[x]=index;
2836 }
2837 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2838 status=MagickFalse;
2839 }
2840 image_view=DestroyCacheView(image_view);
2841 return(status);
2842}
2843
2844/*
2845%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2846% %
2847% %
2848% %
cristya5b77cb2010-05-07 19:34:48 +00002849% S e t I m a g e C o l o r %
2850% %
2851% %
2852% %
2853%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2854%
2855% SetImageColor() set the entire image canvas to the specified color.
2856%
2857% The format of the SetImageColor method is:
2858%
2859% MagickBooleanType SetImageColor(Image *image,
2860% const MagickPixelPacket *color)
2861%
2862% A description of each parameter follows:
2863%
2864% o image: the image.
2865%
2866% o background: the image color.
2867%
2868*/
2869MagickExport MagickBooleanType SetImageColor(Image *image,
2870 const MagickPixelPacket *color)
2871{
2872 CacheView
2873 *image_view;
2874
2875 ExceptionInfo
2876 *exception;
2877
cristya5b77cb2010-05-07 19:34:48 +00002878 MagickBooleanType
2879 status;
2880
cristycb6d09b2010-06-19 01:59:36 +00002881 ssize_t
2882 y;
2883
cristya5b77cb2010-05-07 19:34:48 +00002884 assert(image != (Image *) NULL);
2885 if (image->debug != MagickFalse)
2886 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2887 assert(image->signature == MagickSignature);
2888 assert(color != (const MagickPixelPacket *) NULL);
2889 image->colorspace=color->colorspace;
2890 image->matte=color->matte;
2891 image->fuzz=color->fuzz;
2892 image->depth=color->depth;
2893 status=MagickTrue;
2894 exception=(&image->exception);
2895 image_view=AcquireCacheView(image);
2896#if defined(MAGICKCORE_OPENMP_SUPPORT)
2897 #pragma omp parallel for schedule(dynamic,4) shared(status)
2898#endif
cristybb503372010-05-27 20:51:26 +00002899 for (y=0; y < (ssize_t) image->rows; y++)
cristya5b77cb2010-05-07 19:34:48 +00002900 {
2901 register IndexPacket
2902 *restrict indexes;
2903
cristya5b77cb2010-05-07 19:34:48 +00002904 register PixelPacket
2905 *restrict q;
2906
cristycb6d09b2010-06-19 01:59:36 +00002907 register ssize_t
2908 x;
2909
cristya5b77cb2010-05-07 19:34:48 +00002910 if (status == MagickFalse)
2911 continue;
2912 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2913 if (q == (PixelPacket *) NULL)
2914 {
2915 status=MagickFalse;
2916 continue;
2917 }
2918 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002919 for (x=0; x < (ssize_t) image->columns; x++)
cristya5b77cb2010-05-07 19:34:48 +00002920 {
2921 SetPixelPacket(image,color,q,indexes+x);
2922 q++;
2923 }
2924 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2925 status=MagickFalse;
2926 }
2927 image_view=DestroyCacheView(image_view);
2928 return(status);
2929}
2930
2931/*
2932%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2933% %
2934% %
2935% %
cristy3ed852e2009-09-05 21:47:34 +00002936% S e t I m a g e S t o r a g e C l a s s %
2937% %
2938% %
2939% %
2940%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2941%
2942% SetImageStorageClass() sets the image class: DirectClass for true color
2943% images or PseudoClass for colormapped images.
2944%
2945% The format of the SetImageStorageClass method is:
2946%
2947% MagickBooleanType SetImageStorageClass(Image *image,
2948% const ClassType storage_class)
2949%
2950% A description of each parameter follows:
2951%
2952% o image: the image.
2953%
2954% o storage_class: The image class.
2955%
2956*/
2957MagickExport MagickBooleanType SetImageStorageClass(Image *image,
2958 const ClassType storage_class)
2959{
cristy3ed852e2009-09-05 21:47:34 +00002960 image->storage_class=storage_class;
cristy537e2722010-09-21 15:30:59 +00002961 return(MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00002962}
2963
2964/*
2965%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2966% %
2967% %
2968% %
2969% S e t I m a g e C l i p M a s k %
2970% %
2971% %
2972% %
2973%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2974%
2975% SetImageClipMask() associates a clip path with the image. The clip path
2976% must be the same dimensions as the image. Set any pixel component of
2977% the clip path to TransparentOpacity to prevent that corresponding image
2978% pixel component from being updated when SyncAuthenticPixels() is applied.
2979%
2980% The format of the SetImageClipMask method is:
2981%
2982% MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask)
2983%
2984% A description of each parameter follows:
2985%
2986% o image: the image.
2987%
2988% o clip_mask: the image clip path.
2989%
2990*/
2991MagickExport MagickBooleanType SetImageClipMask(Image *image,
2992 const Image *clip_mask)
2993{
2994 assert(image != (Image *) NULL);
2995 if (image->debug != MagickFalse)
2996 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2997 assert(image->signature == MagickSignature);
2998 if (clip_mask != (const Image *) NULL)
2999 if ((clip_mask->columns != image->columns) ||
3000 (clip_mask->rows != image->rows))
3001 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3002 if (image->clip_mask != (Image *) NULL)
3003 image->clip_mask=DestroyImage(image->clip_mask);
3004 image->clip_mask=NewImageList();
3005 if (clip_mask == (Image *) NULL)
3006 return(MagickTrue);
3007 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3008 return(MagickFalse);
3009 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception);
3010 if (image->clip_mask == (Image *) NULL)
3011 return(MagickFalse);
3012 return(MagickTrue);
3013}
3014
3015/*
3016%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3017% %
3018% %
3019% %
3020% S e t I m a g e E x t e n t %
3021% %
3022% %
3023% %
3024%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3025%
3026% SetImageExtent() sets the image size (i.e. columns & rows).
3027%
3028% The format of the SetImageExtent method is:
3029%
3030% MagickBooleanType SetImageExtent(Image *image,
cristybb503372010-05-27 20:51:26 +00003031% const size_t columns,const size_t rows)
cristy3ed852e2009-09-05 21:47:34 +00003032%
3033% A description of each parameter follows:
3034%
3035% o image: the image.
3036%
3037% o columns: The image width in pixels.
3038%
3039% o rows: The image height in pixels.
3040%
3041*/
3042MagickExport MagickBooleanType SetImageExtent(Image *image,
cristybb503372010-05-27 20:51:26 +00003043 const size_t columns,const size_t rows)
cristy3ed852e2009-09-05 21:47:34 +00003044{
cristy537e2722010-09-21 15:30:59 +00003045 if ((columns == 0) || (rows == 0))
3046 return(MagickFalse);
3047 image->columns=columns;
3048 image->rows=rows;
3049 return(MagickTrue);
cristy3ed852e2009-09-05 21:47:34 +00003050}
3051
3052/*
3053%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3054% %
3055% %
3056% %
3057+ S e t I m a g e I n f o %
3058% %
3059% %
3060% %
3061%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3062%
3063% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
3064% It is set to a type of image format based on the prefix or suffix of the
3065% filename. For example, `ps:image' returns PS indicating a Postscript image.
3066% JPEG is returned for this filename: `image.jpg'. The filename prefix has
3067% precendence over the suffix. Use an optional index enclosed in brackets
3068% after a file name to specify a desired scene of a multi-resolution image
3069% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
3070% indicates success.
3071%
3072% The format of the SetImageInfo method is:
3073%
3074% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00003075% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003076%
3077% A description of each parameter follows:
3078%
cristyd965a422010-03-03 17:47:35 +00003079% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00003080%
cristyd965a422010-03-03 17:47:35 +00003081% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00003082%
3083% o exception: return any errors or warnings in this structure.
3084%
3085*/
3086MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00003087 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003088{
3089 char
3090 extension[MaxTextExtent],
3091 filename[MaxTextExtent],
3092 magic[MaxTextExtent],
3093 *q,
3094 subimage[MaxTextExtent];
3095
3096 const MagicInfo
3097 *magic_info;
3098
3099 const MagickInfo
3100 *magick_info;
3101
3102 ExceptionInfo
3103 *sans_exception;
3104
3105 Image
3106 *image;
3107
3108 MagickBooleanType
3109 status;
3110
3111 register const char
3112 *p;
3113
3114 ssize_t
3115 count;
3116
3117 unsigned char
3118 magick[2*MaxTextExtent];
3119
3120 /*
3121 Look for 'image.format' in filename.
3122 */
3123 assert(image_info != (ImageInfo *) NULL);
3124 assert(image_info->signature == MagickSignature);
3125 if (image_info->debug != MagickFalse)
3126 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3127 image_info->filename);
3128 *subimage='\0';
cristyd965a422010-03-03 17:47:35 +00003129 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003130 {
cristyd965a422010-03-03 17:47:35 +00003131 GetPathComponent(image_info->filename,SubimagePath,subimage);
3132 if (*subimage != '\0')
cristy3ed852e2009-09-05 21:47:34 +00003133 {
cristyd965a422010-03-03 17:47:35 +00003134 /*
3135 Look for scene specification (e.g. img0001.pcd[4]).
3136 */
3137 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
3138 {
3139 if (IsGeometry(subimage) != MagickFalse)
3140 (void) CloneString(&image_info->extract,subimage);
3141 }
3142 else
3143 {
cristybb503372010-05-27 20:51:26 +00003144 size_t
cristyd965a422010-03-03 17:47:35 +00003145 first,
3146 last;
cristy3ed852e2009-09-05 21:47:34 +00003147
cristyd965a422010-03-03 17:47:35 +00003148 (void) CloneString(&image_info->scenes,subimage);
3149 image_info->scene=StringToUnsignedLong(image_info->scenes);
3150 image_info->number_scenes=image_info->scene;
3151 p=image_info->scenes;
3152 for (q=(char *) image_info->scenes; *q != '\0'; p++)
3153 {
3154 while ((isspace((int) ((unsigned char) *p)) != 0) ||
3155 (*p == ','))
3156 p++;
cristybb503372010-05-27 20:51:26 +00003157 first=(size_t) strtol(p,&q,10);
cristyd965a422010-03-03 17:47:35 +00003158 last=first;
3159 while (isspace((int) ((unsigned char) *q)) != 0)
3160 q++;
3161 if (*q == '-')
cristybb503372010-05-27 20:51:26 +00003162 last=(size_t) strtol(q+1,&q,10);
cristyd965a422010-03-03 17:47:35 +00003163 if (first > last)
3164 Swap(first,last);
3165 if (first < image_info->scene)
3166 image_info->scene=first;
3167 if (last > image_info->number_scenes)
3168 image_info->number_scenes=last;
3169 p=q;
3170 }
3171 image_info->number_scenes-=image_info->scene-1;
3172 image_info->subimage=image_info->scene;
3173 image_info->subrange=image_info->number_scenes;
3174 }
cristy3ed852e2009-09-05 21:47:34 +00003175 }
3176 }
3177 *extension='\0';
3178 GetPathComponent(image_info->filename,ExtensionPath,extension);
3179#if defined(MAGICKCORE_ZLIB_DELEGATE)
3180 if (*extension != '\0')
3181 if ((LocaleCompare(extension,"gz") == 0) ||
3182 (LocaleCompare(extension,"Z") == 0) ||
3183 (LocaleCompare(extension,"wmz") == 0))
3184 {
3185 char
3186 path[MaxTextExtent];
3187
3188 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3189 path[strlen(path)-strlen(extension)-1]='\0';
3190 GetPathComponent(path,ExtensionPath,extension);
3191 }
3192#endif
3193#if defined(MAGICKCORE_BZLIB_DELEGATE)
3194 if (*extension != '\0')
3195 if (LocaleCompare(extension,"bz2") == 0)
3196 {
3197 char
3198 path[MaxTextExtent];
3199
3200 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
3201 path[strlen(path)-strlen(extension)-1]='\0';
3202 GetPathComponent(path,ExtensionPath,extension);
3203 }
3204#endif
3205 image_info->affirm=MagickFalse;
3206 sans_exception=AcquireExceptionInfo();
3207 if (*extension != '\0')
3208 {
3209 MagickFormatType
3210 format_type;
3211
cristybb503372010-05-27 20:51:26 +00003212 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003213 i;
3214
3215 static const char
3216 *format_type_formats[] =
3217 {
3218 "AUTOTRACE",
3219 "BROWSE",
3220 "DCRAW",
3221 "EDIT",
3222 "EPHEMERAL",
3223 "LAUNCH",
3224 "MPEG:DECODE",
3225 "MPEG:ENCODE",
3226 "PRINT",
3227 "PS:ALPHA",
3228 "PS:CMYK",
3229 "PS:COLOR",
3230 "PS:GRAY",
3231 "PS:MONO",
3232 "SCAN",
3233 "SHOW",
3234 "WIN",
3235 (char *) NULL
3236 };
3237
3238 /*
3239 User specified image format.
3240 */
3241 (void) CopyMagickString(magic,extension,MaxTextExtent);
3242 LocaleUpper(magic);
3243 /*
3244 Look for explicit image formats.
3245 */
3246 format_type=UndefinedFormatType;
3247 i=0;
cristydd9a2532010-02-20 19:26:46 +00003248 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00003249 (format_type_formats[i] != (char *) NULL))
3250 {
3251 if ((*magic == *format_type_formats[i]) &&
3252 (LocaleCompare(magic,format_type_formats[i]) == 0))
3253 format_type=ExplicitFormatType;
3254 i++;
3255 }
3256 magick_info=GetMagickInfo(magic,sans_exception);
3257 if ((magick_info != (const MagickInfo *) NULL) &&
3258 (magick_info->format_type != UndefinedFormatType))
3259 format_type=magick_info->format_type;
3260 if (format_type == UndefinedFormatType)
3261 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3262 else
3263 if (format_type == ExplicitFormatType)
3264 {
3265 image_info->affirm=MagickTrue;
3266 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3267 }
3268 if (LocaleCompare(magic,"RGB") == 0)
3269 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3270 }
3271 /*
3272 Look for explicit 'format:image' in filename.
3273 */
3274 *magic='\0';
3275 GetPathComponent(image_info->filename,MagickPath,magic);
3276 if (*magic == '\0')
3277 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3278 else
3279 {
3280 /*
3281 User specified image format.
3282 */
3283 LocaleUpper(magic);
3284 if (IsMagickConflict(magic) == MagickFalse)
3285 {
3286 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3287 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3288 image_info->affirm=MagickTrue;
3289 else
3290 image_info->temporary=MagickTrue;
3291 }
3292 }
3293 magick_info=GetMagickInfo(magic,sans_exception);
3294 sans_exception=DestroyExceptionInfo(sans_exception);
3295 if ((magick_info == (const MagickInfo *) NULL) ||
3296 (GetMagickEndianSupport(magick_info) == MagickFalse))
3297 image_info->endian=UndefinedEndian;
3298 GetPathComponent(image_info->filename,CanonicalPath,filename);
3299 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00003300 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00003301 {
3302 /*
cristyd965a422010-03-03 17:47:35 +00003303 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00003304 */
cristyd965a422010-03-03 17:47:35 +00003305 (void) InterpretImageFilename(image_info,(Image *) NULL,
3306 image_info->filename,(int) image_info->scene,filename);
3307 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3308 (strchr(filename,'%') == (char *) NULL))
3309 image_info->adjoin=MagickFalse;
3310 }
3311 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3312 {
3313 /*
3314 Some image formats do not support multiple frames per file.
3315 */
cristy3ed852e2009-09-05 21:47:34 +00003316 magick_info=GetMagickInfo(magic,exception);
3317 if (magick_info != (const MagickInfo *) NULL)
3318 if (GetMagickAdjoin(magick_info) == MagickFalse)
3319 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003320 }
3321 if (image_info->affirm != MagickFalse)
3322 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00003323 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003324 {
3325 /*
cristyd965a422010-03-03 17:47:35 +00003326 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00003327 */
cristyd965a422010-03-03 17:47:35 +00003328 image=AcquireImage(image_info);
3329 (void) CopyMagickString(image->filename,image_info->filename,
3330 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003331 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3332 if (status == MagickFalse)
3333 {
3334 image=DestroyImage(image);
3335 return(MagickFalse);
3336 }
cristyd965a422010-03-03 17:47:35 +00003337 if ((IsBlobSeekable(image) == MagickFalse) ||
3338 (IsBlobExempt(image) != MagickFalse))
3339 {
3340 /*
3341 Copy standard input or pipe to temporary file.
3342 */
3343 *filename='\0';
3344 status=ImageToFile(image,filename,exception);
3345 (void) CloseBlob(image);
3346 if (status == MagickFalse)
3347 {
3348 image=DestroyImage(image);
3349 return(MagickFalse);
3350 }
3351 SetImageInfoFile(image_info,(FILE *) NULL);
3352 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3353 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3354 if (status == MagickFalse)
3355 {
3356 image=DestroyImage(image);
3357 return(MagickFalse);
3358 }
3359 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3360 image_info->temporary=MagickTrue;
3361 }
3362 (void) ResetMagickMemory(magick,0,sizeof(magick));
3363 count=ReadBlob(image,2*MaxTextExtent,magick);
3364 (void) CloseBlob(image);
3365 image=DestroyImage(image);
3366 /*
3367 Check magic.xml configuration file.
3368 */
3369 sans_exception=AcquireExceptionInfo();
3370 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3371 if ((magic_info != (const MagicInfo *) NULL) &&
3372 (GetMagicName(magic_info) != (char *) NULL))
3373 {
3374 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3375 MaxTextExtent);
3376 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3377 if ((magick_info == (const MagickInfo *) NULL) ||
3378 (GetMagickEndianSupport(magick_info) == MagickFalse))
3379 image_info->endian=UndefinedEndian;
3380 sans_exception=DestroyExceptionInfo(sans_exception);
3381 return(MagickTrue);
3382 }
cristy3ed852e2009-09-05 21:47:34 +00003383 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3384 if ((magick_info == (const MagickInfo *) NULL) ||
3385 (GetMagickEndianSupport(magick_info) == MagickFalse))
3386 image_info->endian=UndefinedEndian;
3387 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00003388 }
cristy3ed852e2009-09-05 21:47:34 +00003389 return(MagickTrue);
3390}
3391
3392/*
3393%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3394% %
3395% %
3396% %
3397% S e t I m a g e I n f o B l o b %
3398% %
3399% %
3400% %
3401%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3402%
3403% SetImageInfoBlob() sets the image info blob member.
3404%
3405% The format of the SetImageInfoBlob method is:
3406%
3407% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3408% const size_t length)
3409%
3410% A description of each parameter follows:
3411%
3412% o image_info: the image info.
3413%
3414% o blob: the blob.
3415%
3416% o length: the blob length.
3417%
3418*/
3419MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3420 const size_t length)
3421{
3422 assert(image_info != (ImageInfo *) NULL);
3423 assert(image_info->signature == MagickSignature);
3424 if (image_info->debug != MagickFalse)
3425 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3426 image_info->filename);
3427 image_info->blob=(void *) blob;
3428 image_info->length=length;
3429}
3430
3431/*
3432%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3433% %
3434% %
3435% %
3436% S e t I m a g e I n f o F i l e %
3437% %
3438% %
3439% %
3440%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3441%
3442% SetImageInfoFile() sets the image info file member.
3443%
3444% The format of the SetImageInfoFile method is:
3445%
3446% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3447%
3448% A description of each parameter follows:
3449%
3450% o image_info: the image info.
3451%
3452% o file: the file.
3453%
3454*/
3455MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3456{
3457 assert(image_info != (ImageInfo *) NULL);
3458 assert(image_info->signature == MagickSignature);
3459 if (image_info->debug != MagickFalse)
3460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3461 image_info->filename);
3462 image_info->file=file;
3463}
3464
3465/*
3466%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3467% %
3468% %
3469% %
3470% S e t I m a g e M a s k %
3471% %
3472% %
3473% %
3474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3475%
3476% SetImageMask() associates a mask with the image. The mask must be the same
3477% dimensions as the image.
3478%
3479% The format of the SetImageMask method is:
3480%
3481% MagickBooleanType SetImageMask(Image *image,const Image *mask)
3482%
3483% A description of each parameter follows:
3484%
3485% o image: the image.
3486%
3487% o mask: the image mask.
3488%
3489*/
3490MagickExport MagickBooleanType SetImageMask(Image *image,
3491 const Image *mask)
3492{
3493 assert(image != (Image *) NULL);
3494 if (image->debug != MagickFalse)
3495 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3496 assert(image->signature == MagickSignature);
3497 if (mask != (const Image *) NULL)
3498 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3499 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3500 if (image->mask != (Image *) NULL)
3501 image->mask=DestroyImage(image->mask);
3502 image->mask=NewImageList();
3503 if (mask == (Image *) NULL)
3504 return(MagickTrue);
3505 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
3506 return(MagickFalse);
3507 image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception);
3508 if (image->mask == (Image *) NULL)
3509 return(MagickFalse);
3510 return(MagickTrue);
3511}
3512
3513/*
3514%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3515% %
3516% %
3517% %
3518% S e t I m a g e O p a c i t y %
3519% %
3520% %
3521% %
3522%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3523%
3524% SetImageOpacity() sets the opacity levels of the image.
3525%
3526% The format of the SetImageOpacity method is:
3527%
3528% MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity)
3529%
3530% A description of each parameter follows:
3531%
3532% o image: the image.
3533%
3534% o opacity: the level of transparency: 0 is fully opaque and QuantumRange is
3535% fully transparent.
3536%
3537*/
3538MagickExport MagickBooleanType SetImageOpacity(Image *image,
3539 const Quantum opacity)
3540{
3541 CacheView
3542 *image_view;
3543
3544 ExceptionInfo
3545 *exception;
3546
cristy3ed852e2009-09-05 21:47:34 +00003547 MagickBooleanType
3548 status;
3549
cristycb6d09b2010-06-19 01:59:36 +00003550 ssize_t
3551 y;
3552
cristy3ed852e2009-09-05 21:47:34 +00003553 assert(image != (Image *) NULL);
3554 if (image->debug != MagickFalse)
3555 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3556 assert(image->signature == MagickSignature);
3557 image->matte=opacity != OpaqueOpacity ? MagickTrue : MagickFalse;
3558 status=MagickTrue;
3559 exception=(&image->exception);
3560 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00003561#if defined(MAGICKCORE_OPENMP_SUPPORT)
3562 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003563#endif
cristybb503372010-05-27 20:51:26 +00003564 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003565 {
cristy3ed852e2009-09-05 21:47:34 +00003566 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003567 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003568
cristycb6d09b2010-06-19 01:59:36 +00003569 register ssize_t
3570 x;
3571
cristy3ed852e2009-09-05 21:47:34 +00003572 if (status == MagickFalse)
3573 continue;
3574 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
3575 if (q == (PixelPacket *) NULL)
3576 {
3577 status=MagickFalse;
3578 continue;
3579 }
cristybb503372010-05-27 20:51:26 +00003580 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003581 {
cristy46f08202010-01-10 04:04:21 +00003582 SetOpacityPixelComponent(q,opacity);
cristy3ed852e2009-09-05 21:47:34 +00003583 q++;
3584 }
3585 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3586 status=MagickFalse;
3587 }
3588 image_view=DestroyCacheView(image_view);
3589 return(status);
3590}
3591
3592/*
3593%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3594% %
3595% %
3596% %
3597% S e t I m a g e T y p e %
3598% %
3599% %
3600% %
3601%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3602%
3603% SetImageType() sets the type of image. Choose from these types:
3604%
3605% Bilevel Grayscale GrayscaleMatte
3606% Palette PaletteMatte TrueColor
3607% TrueColorMatte ColorSeparation ColorSeparationMatte
3608% OptimizeType
3609%
3610% The format of the SetImageType method is:
3611%
3612% MagickBooleanType SetImageType(Image *image,const ImageType type)
3613%
3614% A description of each parameter follows:
3615%
3616% o image: the image.
3617%
3618% o type: Image type.
3619%
3620*/
3621MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type)
3622{
3623 const char
3624 *artifact;
3625
3626 ImageInfo
3627 *image_info;
3628
3629 MagickBooleanType
3630 status;
3631
3632 QuantizeInfo
3633 *quantize_info;
3634
3635 assert(image != (Image *) NULL);
3636 if (image->debug != MagickFalse)
3637 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3638 assert(image->signature == MagickSignature);
3639 status=MagickTrue;
3640 image_info=AcquireImageInfo();
3641 image_info->dither=image->dither;
3642 artifact=GetImageArtifact(image,"dither");
3643 if (artifact != (const char *) NULL)
3644 (void) SetImageOption(image_info,"dither",artifact);
3645 switch (type)
3646 {
3647 case BilevelType:
3648 {
3649 if (IsGrayImage(image,&image->exception) == MagickFalse)
3650 status=TransformImageColorspace(image,GRAYColorspace);
3651 if (IsMonochromeImage(image,&image->exception) == MagickFalse)
3652 {
3653 quantize_info=AcquireQuantizeInfo(image_info);
3654 quantize_info->number_colors=2;
3655 quantize_info->colorspace=GRAYColorspace;
3656 status=QuantizeImage(quantize_info,image);
3657 quantize_info=DestroyQuantizeInfo(quantize_info);
3658 }
3659 image->matte=MagickFalse;
3660 break;
3661 }
3662 case GrayscaleType:
3663 {
3664 if (IsGrayImage(image,&image->exception) == MagickFalse)
3665 status=TransformImageColorspace(image,GRAYColorspace);
3666 image->matte=MagickFalse;
3667 break;
3668 }
3669 case GrayscaleMatteType:
3670 {
3671 if (IsGrayImage(image,&image->exception) == MagickFalse)
3672 status=TransformImageColorspace(image,GRAYColorspace);
3673 if (image->matte == MagickFalse)
3674 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3675 break;
3676 }
3677 case PaletteType:
3678 {
3679 if (image->colorspace != RGBColorspace)
3680 status=TransformImageColorspace(image,RGBColorspace);
3681 if ((image->storage_class == DirectClass) || (image->colors > 256))
3682 {
3683 quantize_info=AcquireQuantizeInfo(image_info);
3684 quantize_info->number_colors=256;
3685 status=QuantizeImage(quantize_info,image);
3686 quantize_info=DestroyQuantizeInfo(quantize_info);
3687 }
3688 image->matte=MagickFalse;
3689 break;
3690 }
3691 case PaletteBilevelMatteType:
3692 {
3693 if (image->colorspace != RGBColorspace)
3694 status=TransformImageColorspace(image,RGBColorspace);
3695 if (image->matte == MagickFalse)
3696 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3697 (void) BilevelImageChannel(image,AlphaChannel,(double) QuantumRange/2.0);
3698 quantize_info=AcquireQuantizeInfo(image_info);
3699 status=QuantizeImage(quantize_info,image);
3700 quantize_info=DestroyQuantizeInfo(quantize_info);
3701 break;
3702 }
3703 case PaletteMatteType:
3704 {
3705 if (image->colorspace != RGBColorspace)
3706 status=TransformImageColorspace(image,RGBColorspace);
3707 if (image->matte == MagickFalse)
3708 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3709 quantize_info=AcquireQuantizeInfo(image_info);
3710 quantize_info->colorspace=TransparentColorspace;
3711 status=QuantizeImage(quantize_info,image);
3712 quantize_info=DestroyQuantizeInfo(quantize_info);
3713 break;
3714 }
3715 case TrueColorType:
3716 {
3717 if (image->colorspace != RGBColorspace)
3718 status=TransformImageColorspace(image,RGBColorspace);
3719 if (image->storage_class != DirectClass)
3720 status=SetImageStorageClass(image,DirectClass);
3721 image->matte=MagickFalse;
3722 break;
3723 }
3724 case TrueColorMatteType:
3725 {
3726 if (image->colorspace != RGBColorspace)
3727 status=TransformImageColorspace(image,RGBColorspace);
3728 if (image->storage_class != DirectClass)
3729 status=SetImageStorageClass(image,DirectClass);
3730 if (image->matte == MagickFalse)
3731 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3732 break;
3733 }
3734 case ColorSeparationType:
3735 {
3736 if (image->colorspace != CMYKColorspace)
3737 {
3738 if (image->colorspace != RGBColorspace)
3739 status=TransformImageColorspace(image,RGBColorspace);
3740 status=TransformImageColorspace(image,CMYKColorspace);
3741 }
3742 if (image->storage_class != DirectClass)
3743 status=SetImageStorageClass(image,DirectClass);
3744 image->matte=MagickFalse;
3745 break;
3746 }
3747 case ColorSeparationMatteType:
3748 {
3749 if (image->colorspace != CMYKColorspace)
3750 {
3751 if (image->colorspace != RGBColorspace)
3752 status=TransformImageColorspace(image,RGBColorspace);
3753 status=TransformImageColorspace(image,CMYKColorspace);
3754 }
3755 if (image->storage_class != DirectClass)
3756 status=SetImageStorageClass(image,DirectClass);
3757 if (image->matte == MagickFalse)
3758 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel);
3759 break;
3760 }
3761 case OptimizeType:
cristy5f1c1ff2010-12-23 21:38:06 +00003762 case UndefinedType:
cristy3ed852e2009-09-05 21:47:34 +00003763 break;
3764 }
3765 image->type=type;
3766 image_info=DestroyImageInfo(image_info);
3767 return(status);
3768}
3769
3770/*
3771%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3772% %
3773% %
3774% %
3775% 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 %
3776% %
3777% %
3778% %
3779%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3780%
3781% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3782% image and returns the previous setting. A virtual pixel is any pixel access
3783% that is outside the boundaries of the image cache.
3784%
3785% The format of the SetImageVirtualPixelMethod() method is:
3786%
3787% VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3788% const VirtualPixelMethod virtual_pixel_method)
3789%
3790% A description of each parameter follows:
3791%
3792% o image: the image.
3793%
3794% o virtual_pixel_method: choose the type of virtual pixel.
3795%
3796*/
3797MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3798 const VirtualPixelMethod virtual_pixel_method)
3799{
3800 assert(image != (const Image *) NULL);
3801 assert(image->signature == MagickSignature);
3802 if (image->debug != MagickFalse)
3803 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3804 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3805}
3806
3807/*
3808%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3809% %
3810% %
3811% %
cristy4285d782011-02-09 20:12:28 +00003812% S m u s h I m a g e s %
3813% %
3814% %
3815% %
3816%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3817%
3818% SmushImages() takes all images from the current image pointer to the end
3819% of the image list and smushes them to each other top-to-bottom if the
3820% stack parameter is true, otherwise left-to-right.
3821%
3822% The current gravity setting now effects how the image is justified in the
3823% final image.
3824%
3825% The format of the SmushImages method is:
3826%
cristy4ca38e22011-02-10 02:57:49 +00003827% Image *SmushImages(const Image *images,const MagickBooleanType stack,
cristy4285d782011-02-09 20:12:28 +00003828% ExceptionInfo *exception)
3829%
3830% A description of each parameter follows:
3831%
cristy4ca38e22011-02-10 02:57:49 +00003832% o images: the image sequence.
cristy4285d782011-02-09 20:12:28 +00003833%
3834% o stack: A value other than 0 stacks the images top-to-bottom.
3835%
3836% o offset: minimum distance in pixels between images.
3837%
3838% o exception: return any errors or warnings in this structure.
3839%
3840*/
cristy4ca38e22011-02-10 02:57:49 +00003841
cristy7c6dc152011-02-11 14:10:55 +00003842static ssize_t SmushXGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003843 const ssize_t offset,ExceptionInfo *exception)
cristy4ca38e22011-02-10 02:57:49 +00003844{
cristy4d727152011-02-10 19:57:21 +00003845 CacheView
3846 *left_view,
3847 *right_view;
3848
3849 const Image
3850 *left_image,
3851 *right_image;
3852
cristy4d727152011-02-10 19:57:21 +00003853 RectangleInfo
3854 left_geometry,
3855 right_geometry;
3856
cristydab7e912011-02-11 18:19:24 +00003857 register const PixelPacket
3858 *p;
3859
cristy4d727152011-02-10 19:57:21 +00003860 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003861 i,
cristy4d727152011-02-10 19:57:21 +00003862 y;
3863
cristy7c6dc152011-02-11 14:10:55 +00003864 size_t
3865 gap;
3866
cristy4d727152011-02-10 19:57:21 +00003867 ssize_t
cristy4d727152011-02-10 19:57:21 +00003868 x;
3869
3870 if (images->previous == (Image *) NULL)
3871 return(0);
3872 right_image=images;
3873 SetGeometry(smush_image,&right_geometry);
3874 GravityAdjustGeometry(right_image->columns,right_image->rows,
3875 right_image->gravity,&right_geometry);
3876 left_image=images->previous;
3877 SetGeometry(smush_image,&left_geometry);
3878 GravityAdjustGeometry(left_image->columns,left_image->rows,
3879 left_image->gravity,&left_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003880 gap=right_image->columns;
cristy4d727152011-02-10 19:57:21 +00003881 left_view=AcquireCacheView(left_image);
3882 right_view=AcquireCacheView(right_image);
3883 for (y=0; y < (ssize_t) smush_image->rows; y++)
3884 {
3885 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3886 {
cristydab7e912011-02-11 18:19:24 +00003887 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
3888 if ((p == (const PixelPacket *) NULL) ||
3889 (p->opacity != TransparentOpacity) ||
cristy7c6dc152011-02-11 14:10:55 +00003890 ((left_image->columns-x-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003891 break;
3892 }
cristy4ef6f062011-02-10 20:30:22 +00003893 i=(ssize_t) left_image->columns-x-1;
cristy4d727152011-02-10 19:57:21 +00003894 for (x=0; x < (ssize_t) right_image->columns; x++)
3895 {
cristydab7e912011-02-11 18:19:24 +00003896 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
cristy279d8212011-02-10 20:05:02 +00003897 exception);
cristydab7e912011-02-11 18:19:24 +00003898 if ((p == (const PixelPacket *) NULL) ||
3899 (p->opacity != TransparentOpacity) || ((x+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003900 break;
3901 }
cristy7c6dc152011-02-11 14:10:55 +00003902 if ((x+i) < (ssize_t) gap)
3903 gap=(size_t) (x+i);
cristy4d727152011-02-10 19:57:21 +00003904 }
3905 right_view=DestroyCacheView(right_view);
3906 left_view=DestroyCacheView(left_view);
cristydab7e912011-02-11 18:19:24 +00003907 if (y < (ssize_t) smush_image->rows)
3908 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003909 return((ssize_t) gap-offset);
cristyad5e6ee2011-02-10 14:26:00 +00003910}
3911
cristy7c6dc152011-02-11 14:10:55 +00003912static ssize_t SmushYGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003913 const ssize_t offset,ExceptionInfo *exception)
cristyad5e6ee2011-02-10 14:26:00 +00003914{
cristy4d727152011-02-10 19:57:21 +00003915 CacheView
3916 *bottom_view,
3917 *top_view;
3918
3919 const Image
3920 *bottom_image,
3921 *top_image;
3922
cristy4d727152011-02-10 19:57:21 +00003923 RectangleInfo
3924 bottom_geometry,
3925 top_geometry;
3926
cristydab7e912011-02-11 18:19:24 +00003927 register const PixelPacket
3928 *p;
3929
cristy4d727152011-02-10 19:57:21 +00003930 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003931 i,
cristy4d727152011-02-10 19:57:21 +00003932 x;
3933
cristy7c6dc152011-02-11 14:10:55 +00003934 size_t
3935 gap;
3936
cristy4d727152011-02-10 19:57:21 +00003937 ssize_t
cristy4d727152011-02-10 19:57:21 +00003938 y;
3939
3940 if (images->previous == (Image *) NULL)
3941 return(0);
3942 bottom_image=images;
3943 SetGeometry(smush_image,&bottom_geometry);
3944 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3945 bottom_image->gravity,&bottom_geometry);
3946 top_image=images->previous;
3947 SetGeometry(smush_image,&top_geometry);
3948 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3949 &top_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003950 gap=bottom_image->rows;
cristy4d727152011-02-10 19:57:21 +00003951 top_view=AcquireCacheView(top_image);
3952 bottom_view=AcquireCacheView(bottom_image);
3953 for (x=0; x < (ssize_t) smush_image->columns; x++)
3954 {
3955 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3956 {
cristydab7e912011-02-11 18:19:24 +00003957 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
3958 if ((p == (const PixelPacket *) NULL) ||
3959 (p->opacity != TransparentOpacity) || ((top_image->rows-y-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003960 break;
3961 }
cristy4ef6f062011-02-10 20:30:22 +00003962 i=(ssize_t) top_image->rows-y-1;
cristy4d727152011-02-10 19:57:21 +00003963 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3964 {
cristydab7e912011-02-11 18:19:24 +00003965 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3966 exception);
3967 if ((p == (const PixelPacket *) NULL) ||
3968 (p->opacity != TransparentOpacity) || ((y+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003969 break;
3970 }
cristy7c6dc152011-02-11 14:10:55 +00003971 if ((y+i) < (ssize_t) gap)
3972 gap=(size_t) (y+i);
cristy4d727152011-02-10 19:57:21 +00003973 }
3974 bottom_view=DestroyCacheView(bottom_view);
3975 top_view=DestroyCacheView(top_view);
cristydab7e912011-02-11 18:19:24 +00003976 if (x < (ssize_t) smush_image->columns)
3977 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003978 return((ssize_t) gap-offset);
cristy4ca38e22011-02-10 02:57:49 +00003979}
3980
3981MagickExport Image *SmushImages(const Image *images,
cristy4285d782011-02-09 20:12:28 +00003982 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3983{
3984#define SmushImageTag "Smush/Image"
3985
3986 CacheView
cristybb5dced2011-02-10 02:17:16 +00003987 *smush_view;
cristy4285d782011-02-09 20:12:28 +00003988
cristy4ca38e22011-02-10 02:57:49 +00003989 const Image
3990 *image;
3991
cristy4285d782011-02-09 20:12:28 +00003992 Image
3993 *smush_image;
3994
3995 MagickBooleanType
3996 matte,
3997 proceed,
3998 status;
3999
4000 MagickOffsetType
4001 n;
4002
4003 RectangleInfo
4004 geometry;
4005
4006 register const Image
4007 *next;
4008
4009 size_t
4010 height,
4011 number_images,
4012 width;
4013
4014 ssize_t
4015 x_offset,
cristy4285d782011-02-09 20:12:28 +00004016 y_offset;
4017
4018 /*
cristy7c6dc152011-02-11 14:10:55 +00004019 Compute maximum area of smushed area.
cristy4285d782011-02-09 20:12:28 +00004020 */
cristy4ca38e22011-02-10 02:57:49 +00004021 assert(images != (Image *) NULL);
4022 assert(images->signature == MagickSignature);
4023 if (images->debug != MagickFalse)
4024 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy4285d782011-02-09 20:12:28 +00004025 assert(exception != (ExceptionInfo *) NULL);
4026 assert(exception->signature == MagickSignature);
cristy4ca38e22011-02-10 02:57:49 +00004027 image=images;
cristy4285d782011-02-09 20:12:28 +00004028 matte=image->matte;
4029 number_images=1;
4030 width=image->columns;
4031 height=image->rows;
4032 next=GetNextImageInList(image);
4033 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
4034 {
4035 if (next->matte != MagickFalse)
4036 matte=MagickTrue;
4037 number_images++;
4038 if (stack != MagickFalse)
4039 {
4040 if (next->columns > width)
4041 width=next->columns;
4042 height+=next->rows;
cristy4ef6f062011-02-10 20:30:22 +00004043 if (next->previous != (Image *) NULL)
4044 height+=offset;
cristy4285d782011-02-09 20:12:28 +00004045 continue;
4046 }
4047 width+=next->columns;
cristy4ef6f062011-02-10 20:30:22 +00004048 if (next->previous != (Image *) NULL)
4049 width+=offset;
cristy4285d782011-02-09 20:12:28 +00004050 if (next->rows > height)
4051 height=next->rows;
4052 }
4053 /*
cristy7c6dc152011-02-11 14:10:55 +00004054 Smush images.
cristy4285d782011-02-09 20:12:28 +00004055 */
4056 smush_image=CloneImage(image,width,height,MagickTrue,exception);
4057 if (smush_image == (Image *) NULL)
4058 return((Image *) NULL);
4059 if (SetImageStorageClass(smush_image,DirectClass) == MagickFalse)
4060 {
4061 InheritException(exception,&smush_image->exception);
4062 smush_image=DestroyImage(smush_image);
4063 return((Image *) NULL);
4064 }
4065 smush_image->matte=matte;
4066 (void) SetImageBackgroundColor(smush_image);
4067 status=MagickTrue;
4068 x_offset=0;
4069 y_offset=0;
4070 smush_view=AcquireCacheView(smush_image);
4071 for (n=0; n < (MagickOffsetType) number_images; n++)
4072 {
4073 SetGeometry(smush_image,&geometry);
4074 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
4075 if (stack != MagickFalse)
cristy4ca38e22011-02-10 02:57:49 +00004076 {
4077 x_offset-=geometry.x;
cristy7c6dc152011-02-11 14:10:55 +00004078 y_offset-=SmushYGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00004079 }
cristy4285d782011-02-09 20:12:28 +00004080 else
cristy4ca38e22011-02-10 02:57:49 +00004081 {
cristy7c6dc152011-02-11 14:10:55 +00004082 x_offset-=SmushXGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00004083 y_offset-=geometry.y;
cristy4ca38e22011-02-10 02:57:49 +00004084 }
cristybb5dced2011-02-10 02:17:16 +00004085 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset);
cristy4285d782011-02-09 20:12:28 +00004086 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
4087 if (proceed == MagickFalse)
4088 break;
4089 if (stack == MagickFalse)
4090 {
4091 x_offset+=(ssize_t) image->columns;
4092 y_offset=0;
4093 }
4094 else
4095 {
4096 x_offset=0;
4097 y_offset+=(ssize_t) image->rows;
4098 }
4099 image=GetNextImageInList(image);
4100 }
cristy4ef6f062011-02-10 20:30:22 +00004101 if (stack == MagickFalse)
4102 smush_image->columns=(size_t) x_offset;
cristy4d727152011-02-10 19:57:21 +00004103 else
cristy4ef6f062011-02-10 20:30:22 +00004104 smush_image->rows=(size_t) y_offset;
4105 smush_view=DestroyCacheView(smush_view);
cristy4285d782011-02-09 20:12:28 +00004106 if (status == MagickFalse)
4107 smush_image=DestroyImage(smush_image);
4108 return(smush_image);
4109}
4110
4111/*
4112%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4113% %
4114% %
4115% %
cristy3ed852e2009-09-05 21:47:34 +00004116% S t r i p I m a g e %
4117% %
4118% %
4119% %
4120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4121%
cristy376bda92009-12-22 21:15:23 +00004122% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00004123%
4124% The format of the StripImage method is:
4125%
4126% MagickBooleanType StripImage(Image *image)
4127%
4128% A description of each parameter follows:
4129%
4130% o image: the image.
4131%
4132*/
4133MagickExport MagickBooleanType StripImage(Image *image)
4134{
4135 assert(image != (Image *) NULL);
4136 if (image->debug != MagickFalse)
4137 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4138 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00004139 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00004140 (void) DeleteImageProperty(image,"date:create");
4141 (void) DeleteImageProperty(image,"date:modify");
glennrpce91ed52010-12-23 22:37:49 +00004142 (void) SetImageArtifact(image,"png:include-chunk","none,gama");
cristy3ed852e2009-09-05 21:47:34 +00004143 return(MagickTrue);
4144}
4145
4146/*
4147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4148% %
4149% %
4150% %
4151+ S y n c I m a g e %
4152% %
4153% %
4154% %
4155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4156%
4157% SyncImage() initializes the red, green, and blue intensities of each pixel
4158% as defined by the colormap index.
4159%
4160% The format of the SyncImage method is:
4161%
4162% MagickBooleanType SyncImage(Image *image)
4163%
4164% A description of each parameter follows:
4165%
4166% o image: the image.
4167%
4168*/
4169
4170static inline IndexPacket PushColormapIndex(Image *image,
cristybb503372010-05-27 20:51:26 +00004171 const size_t index,MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00004172{
4173 if (index < image->colors)
4174 return((IndexPacket) index);
4175 *range_exception=MagickTrue;
4176 return((IndexPacket) 0);
4177}
4178
4179MagickExport MagickBooleanType SyncImage(Image *image)
4180{
4181 CacheView
4182 *image_view;
4183
4184 ExceptionInfo
4185 *exception;
4186
cristy3ed852e2009-09-05 21:47:34 +00004187 MagickBooleanType
4188 range_exception,
4189 status;
4190
cristycb6d09b2010-06-19 01:59:36 +00004191 ssize_t
4192 y;
4193
cristy3ed852e2009-09-05 21:47:34 +00004194 assert(image != (Image *) NULL);
4195 if (image->debug != MagickFalse)
4196 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4197 assert(image->signature == MagickSignature);
4198 if (image->storage_class == DirectClass)
4199 return(MagickFalse);
4200 range_exception=MagickFalse;
4201 status=MagickTrue;
4202 exception=(&image->exception);
4203 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00004204#if defined(MAGICKCORE_OPENMP_SUPPORT)
4205 #pragma omp parallel for schedule(dynamic,4) shared(status)
4206#endif
cristybb503372010-05-27 20:51:26 +00004207 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004208 {
4209 IndexPacket
4210 index;
4211
4212 PixelPacket
4213 pixel;
4214
4215 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +00004216 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +00004217
cristy3ed852e2009-09-05 21:47:34 +00004218 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00004219 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004220
cristycb6d09b2010-06-19 01:59:36 +00004221 register ssize_t
4222 x;
4223
cristy48974b92009-12-19 02:36:06 +00004224 if (status == MagickFalse)
4225 continue;
cristy3ed852e2009-09-05 21:47:34 +00004226 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
4227 if (q == (PixelPacket *) NULL)
4228 {
4229 status=MagickFalse;
4230 continue;
4231 }
4232 indexes=GetCacheViewAuthenticIndexQueue(image_view);
cristybb503372010-05-27 20:51:26 +00004233 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004234 {
cristybb503372010-05-27 20:51:26 +00004235 index=PushColormapIndex(image,(size_t) indexes[x],
cristy3ed852e2009-09-05 21:47:34 +00004236 &range_exception);
cristybb503372010-05-27 20:51:26 +00004237 pixel=image->colormap[(ssize_t) index];
cristy3ed852e2009-09-05 21:47:34 +00004238 q->red=pixel.red;
4239 q->green=pixel.green;
4240 q->blue=pixel.blue;
cristyd0272592010-04-21 01:01:49 +00004241 if (image->matte != MagickFalse)
4242 q->opacity=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)
4339 image->black_point_compensation=(MagickBooleanType) ParseMagickOption(
4340 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)
4358 image->compose=(CompositeOperator) ParseMagickOption(MagickComposeOptions,
4359 MagickFalse,option);
4360 option=GetImageOption(image_info,"compress");
4361 if (option != (const char *) NULL)
4362 image->compression=(CompressionType) ParseMagickOption(
4363 MagickCompressOptions,MagickFalse,option);
4364 option=GetImageOption(image_info,"debug");
4365 if (option != (const char *) NULL)
4366 image->debug=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4367 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)
4388 image->endian=(EndianType) ParseMagickOption(MagickEndianOptions,
4389 MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00004390 option=GetImageOption(image_info,"filter");
4391 if (option != (const char *) NULL)
4392 image->filter=(FilterTypes) ParseMagickOption(MagickFilterOptions,
4393 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)
4399 image->gravity=(GravityType) ParseMagickOption(MagickGravityOptions,
4400 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)
4412 image->rendering_intent=(RenderingIntent) ParseMagickOption(
4413 MagickIntentOptions,MagickFalse,option);
4414 option=GetImageOption(image_info,"interlace");
4415 if (option != (const char *) NULL)
4416 image->interlace=(InterlaceType) ParseMagickOption(MagickInterlaceOptions,
4417 MagickFalse,option);
4418 option=GetImageOption(image_info,"interpolate");
4419 if (option != (const char *) NULL)
4420 image->interpolate=(InterpolatePixelMethod) ParseMagickOption(
4421 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)
4430 image->orientation=(OrientationType) ParseMagickOption(
4431 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)
4461 image->taint=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions,
4462 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)
4479 image->type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse,
4480 option);
4481 option=GetImageOption(image_info,"units");
4482 if (option != (const char *) NULL)
cristy19eb6412010-04-23 14:42:29 +00004483 units=(ResolutionType) ParseMagickOption(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}