blob: c31f1a3633d8c02631fdaa841c533a0f8f2c0b28 [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*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/animate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/blob.h"
48#include "MagickCore/blob-private.h"
49#include "MagickCore/cache.h"
50#include "MagickCore/cache-private.h"
51#include "MagickCore/cache-view.h"
52#include "MagickCore/client.h"
53#include "MagickCore/color.h"
54#include "MagickCore/color-private.h"
55#include "MagickCore/colormap.h"
56#include "MagickCore/colorspace.h"
57#include "MagickCore/colorspace-private.h"
58#include "MagickCore/composite.h"
59#include "MagickCore/composite-private.h"
60#include "MagickCore/compress.h"
61#include "MagickCore/constitute.h"
62#include "MagickCore/display.h"
63#include "MagickCore/draw.h"
64#include "MagickCore/enhance.h"
65#include "MagickCore/exception.h"
66#include "MagickCore/exception-private.h"
67#include "MagickCore/gem.h"
68#include "MagickCore/geometry.h"
69#include "MagickCore/histogram.h"
70#include "MagickCore/image-private.h"
71#include "MagickCore/list.h"
72#include "MagickCore/magic.h"
73#include "MagickCore/magick.h"
cristy7832dc22011-09-05 01:21:53 +000074#include "MagickCore/magick-private.h"
cristy4c08aed2011-07-01 19:47:50 +000075#include "MagickCore/memory_.h"
76#include "MagickCore/module.h"
77#include "MagickCore/monitor.h"
78#include "MagickCore/monitor-private.h"
79#include "MagickCore/option.h"
80#include "MagickCore/paint.h"
81#include "MagickCore/pixel-accessor.h"
82#include "MagickCore/profile.h"
83#include "MagickCore/property.h"
84#include "MagickCore/quantize.h"
85#include "MagickCore/random_.h"
86#include "MagickCore/segment.h"
87#include "MagickCore/semaphore.h"
88#include "MagickCore/signature-private.h"
89#include "MagickCore/statistic.h"
90#include "MagickCore/string_.h"
91#include "MagickCore/string-private.h"
92#include "MagickCore/thread-private.h"
93#include "MagickCore/threshold.h"
94#include "MagickCore/timer.h"
95#include "MagickCore/utility.h"
cristyd1dd6e42011-09-04 01:46:08 +000096#include "MagickCore/utility-private.h"
cristy4c08aed2011-07-01 19:47:50 +000097#include "MagickCore/version.h"
98#include "MagickCore/xwindow-private.h"
cristy3ed852e2009-09-05 21:47:34 +000099
100/*
101 Constant declaration.
102*/
cristy94b11832011-09-08 19:46:03 +0000103const char
cristy7138c592009-09-08 13:58:52 +0000104 BackgroundColor[] = "#ffffff", /* white */
105 BorderColor[] = "#dfdfdf", /* gray */
cristy9639ba32011-09-05 15:09:42 +0000106 DefaultTileFrame[] = "15x15+3+3",
cristy7138c592009-09-08 13:58:52 +0000107 DefaultTileGeometry[] = "120x120+4+3>",
108 DefaultTileLabel[] = "%f\n%G\n%b",
cristy94b11832011-09-08 19:46:03 +0000109 ForegroundColor[] = "#000", /* black */
cristy7138c592009-09-08 13:58:52 +0000110 LoadImageTag[] = "Load/Image",
111 LoadImagesTag[] = "Load/Images",
cristy94b11832011-09-08 19:46:03 +0000112 MatteColor[] = "#bdbdbd", /* gray */
cristy7138c592009-09-08 13:58:52 +0000113 PSDensityGeometry[] = "72.0x72.0",
114 PSPageGeometry[] = "612x792",
115 SaveImageTag[] = "Save/Image",
116 SaveImagesTag[] = "Save/Images",
117 TransparentColor[] = "#00000000"; /* transparent black */
cristy3ed852e2009-09-05 21:47:34 +0000118
cristy94b11832011-09-08 19:46:03 +0000119const double
cristy3ed852e2009-09-05 21:47:34 +0000120 DefaultResolution = 72.0;
121
122/*
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124% %
125% %
126% %
127% A c q u i r e I m a g e %
128% %
129% %
130% %
131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132%
133% AcquireImage() returns a pointer to an image structure initialized to
134% default values.
135%
136% The format of the AcquireImage method is:
137%
cristy9950d572011-10-01 18:22:35 +0000138% Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000139%
140% A description of each parameter follows:
141%
142% o image_info: Many of the image default values are set from this
143% structure. For example, filename, compression, depth, background color,
144% and others.
145%
cristy9950d572011-10-01 18:22:35 +0000146% o exception: return any errors or warnings in this structure.
147%
cristy3ed852e2009-09-05 21:47:34 +0000148*/
cristy9950d572011-10-01 18:22:35 +0000149MagickExport Image *AcquireImage(const ImageInfo *image_info,
150 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000151{
cristye412c892010-07-26 12:31:36 +0000152 const char
cristyf3a660a2010-07-26 14:17:52 +0000153 *option;
cristye412c892010-07-26 12:31:36 +0000154
cristy3ed852e2009-09-05 21:47:34 +0000155 Image
156 *image;
157
158 MagickStatusType
159 flags;
160
161 /*
162 Allocate image structure.
163 */
164 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy73bd4a52010-10-05 11:24:23 +0000165 image=(Image *) AcquireMagickMemory(sizeof(*image));
cristy3ed852e2009-09-05 21:47:34 +0000166 if (image == (Image *) NULL)
167 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
168 (void) ResetMagickMemory(image,0,sizeof(*image));
169 /*
170 Initialize Image structure.
171 */
172 (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent);
173 image->storage_class=DirectClass;
174 image->depth=MAGICKCORE_QUANTUM_DEPTH;
175 image->colorspace=RGBColorspace;
176 image->interlace=NoInterlace;
177 image->ticks_per_second=UndefinedTicksPerSecond;
178 image->compose=OverCompositeOp;
179 image->blur=1.0;
cristy9950d572011-10-01 18:22:35 +0000180 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
181 &image->background_color,exception);
182 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
183 exception);
184 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
185 exception);
186 (void) QueryColorCompliance(TransparentColor,AllCompliance,
187 &image->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +0000188 image->x_resolution=DefaultResolution;
189 image->y_resolution=DefaultResolution;
190 image->units=PixelsPerInchResolution;
191 GetTimerInfo(&image->timer);
cristy73724512010-04-12 14:43:14 +0000192 image->ping=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000193 image->cache=AcquirePixelCache(0);
cristybd5a96c2011-08-21 00:04:26 +0000194 image->channel_mask=DefaultChannels;
cristyed231572011-07-14 02:18:59 +0000195 image->channel_map=AcquirePixelChannelMap();
cristy3ed852e2009-09-05 21:47:34 +0000196 image->blob=CloneBlobInfo((BlobInfo *) NULL);
197 image->debug=IsEventLogging();
198 image->reference_count=1;
199 image->semaphore=AllocateSemaphoreInfo();
200 image->signature=MagickSignature;
201 if (image_info == (ImageInfo *) NULL)
202 return(image);
203 /*
204 Transfer image info.
205 */
206 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
207 MagickFalse);
208 (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent);
209 (void) CopyMagickString(image->magick_filename,image_info->filename,
210 MaxTextExtent);
211 (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent);
212 if (image_info->size != (char *) NULL)
213 {
214 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
215 image->columns=image->extract_info.width;
216 image->rows=image->extract_info.height;
217 image->offset=image->extract_info.x;
218 image->extract_info.x=0;
219 image->extract_info.y=0;
220 }
221 if (image_info->extract != (char *) NULL)
222 {
223 RectangleInfo
224 geometry;
225
226 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
227 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
228 {
229 image->extract_info=geometry;
230 Swap(image->columns,image->extract_info.width);
231 Swap(image->rows,image->extract_info.height);
232 }
233 }
234 image->compression=image_info->compression;
235 image->quality=image_info->quality;
236 image->endian=image_info->endian;
237 image->interlace=image_info->interlace;
238 image->units=image_info->units;
239 if (image_info->density != (char *) NULL)
240 {
241 GeometryInfo
242 geometry_info;
243
244 flags=ParseGeometry(image_info->density,&geometry_info);
245 image->x_resolution=geometry_info.rho;
246 image->y_resolution=geometry_info.sigma;
247 if ((flags & SigmaValue) == 0)
248 image->y_resolution=image->x_resolution;
249 }
250 if (image_info->page != (char *) NULL)
251 {
252 char
253 *geometry;
254
255 image->page=image->extract_info;
256 geometry=GetPageGeometry(image_info->page);
257 (void) ParseAbsoluteGeometry(geometry,&image->page);
258 geometry=DestroyString(geometry);
259 }
260 if (image_info->depth != 0)
261 image->depth=image_info->depth;
262 image->dither=image_info->dither;
263 image->background_color=image_info->background_color;
264 image->border_color=image_info->border_color;
265 image->matte_color=image_info->matte_color;
266 image->transparent_color=image_info->transparent_color;
cristy73724512010-04-12 14:43:14 +0000267 image->ping=image_info->ping;
cristy3ed852e2009-09-05 21:47:34 +0000268 image->progress_monitor=image_info->progress_monitor;
269 image->client_data=image_info->client_data;
270 if (image_info->cache != (void *) NULL)
271 ClonePixelCacheMethods(image->cache,image_info->cache);
272 (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method);
cristy6fccee12011-10-20 18:43:18 +0000273 (void) SyncImageSettings(image_info,image,exception);
cristye412c892010-07-26 12:31:36 +0000274 option=GetImageOption(image_info,"delay");
275 if (option != (const char *) NULL)
276 {
277 GeometryInfo
278 geometry_info;
279
280 flags=ParseGeometry(option,&geometry_info);
281 if ((flags & GreaterValue) != 0)
282 {
283 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
284 image->delay=(size_t) floor(geometry_info.rho+0.5);
285 }
286 else
287 if ((flags & LessValue) != 0)
288 {
289 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
290 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
291 }
292 else
293 image->delay=(size_t) floor(geometry_info.rho+0.5);
294 if ((flags & SigmaValue) != 0)
295 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
296 }
297 option=GetImageOption(image_info,"dispose");
298 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +0000299 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
cristye412c892010-07-26 12:31:36 +0000300 MagickFalse,option);
cristy3ed852e2009-09-05 21:47:34 +0000301 return(image);
302}
303
304/*
305%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
306% %
307% %
308% %
cristy3ed852e2009-09-05 21:47:34 +0000309% A c q u i r e I m a g e I n f o %
310% %
311% %
312% %
313%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314%
315% AcquireImageInfo() allocates the ImageInfo structure.
316%
317% The format of the AcquireImageInfo method is:
318%
319% ImageInfo *AcquireImageInfo(void)
320%
321*/
322MagickExport ImageInfo *AcquireImageInfo(void)
323{
324 ImageInfo
325 *image_info;
326
cristy73bd4a52010-10-05 11:24:23 +0000327 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
cristy3ed852e2009-09-05 21:47:34 +0000328 if (image_info == (ImageInfo *) NULL)
329 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
330 GetImageInfo(image_info);
331 return(image_info);
332}
333
334/*
335%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336% %
337% %
338% %
339% A c q u i r e N e x t I m a g e %
340% %
341% %
342% %
343%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344%
345% AcquireNextImage() initializes the next image in a sequence to
346% default values. The next member of image points to the newly allocated
347% image. If there is a memory shortage, next is assigned NULL.
348%
349% The format of the AcquireNextImage method is:
350%
cristy9950d572011-10-01 18:22:35 +0000351% void AcquireNextImage(const ImageInfo *image_info,Image *image,
352% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000353%
354% A description of each parameter follows:
355%
356% o image_info: Many of the image default values are set from this
357% structure. For example, filename, compression, depth, background color,
358% and others.
359%
360% o image: the image.
361%
cristy9950d572011-10-01 18:22:35 +0000362% o exception: return any errors or warnings in this structure.
363%
cristy3ed852e2009-09-05 21:47:34 +0000364*/
cristy9950d572011-10-01 18:22:35 +0000365MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
366 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000367{
368 /*
369 Allocate image structure.
370 */
371 assert(image != (Image *) NULL);
372 assert(image->signature == MagickSignature);
373 if (image->debug != MagickFalse)
374 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy9950d572011-10-01 18:22:35 +0000375 image->next=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000376 if (GetNextImageInList(image) == (Image *) NULL)
377 return;
378 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
379 MaxTextExtent);
380 if (image_info != (ImageInfo *) NULL)
381 (void) CopyMagickString(GetNextImageInList(image)->filename,
382 image_info->filename,MaxTextExtent);
383 DestroyBlob(GetNextImageInList(image));
384 image->next->blob=ReferenceBlob(image->blob);
385 image->next->endian=image->endian;
386 image->next->scene=image->scene+1;
387 image->next->previous=image;
388}
389
390/*
391%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392% %
393% %
394% %
395% A p p e n d I m a g e s %
396% %
397% %
398% %
399%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
400%
401% AppendImages() takes all images from the current image pointer to the end
402% of the image list and appends them to each other top-to-bottom if the
403% stack parameter is true, otherwise left-to-right.
404%
405% The current gravity setting now effects how the image is justified in the
406% final image.
407%
408% The format of the AppendImages method is:
409%
cristy4ca38e22011-02-10 02:57:49 +0000410% Image *AppendImages(const Image *images,const MagickBooleanType stack,
cristy3ed852e2009-09-05 21:47:34 +0000411% ExceptionInfo *exception)
412%
413% A description of each parameter follows:
414%
cristy4ca38e22011-02-10 02:57:49 +0000415% o images: the image sequence.
cristy3ed852e2009-09-05 21:47:34 +0000416%
417% o stack: A value other than 0 stacks the images top-to-bottom.
418%
419% o exception: return any errors or warnings in this structure.
420%
421*/
cristy4ca38e22011-02-10 02:57:49 +0000422MagickExport Image *AppendImages(const Image *images,
cristy3ed852e2009-09-05 21:47:34 +0000423 const MagickBooleanType stack,ExceptionInfo *exception)
424{
425#define AppendImageTag "Append/Image"
426
427 CacheView
428 *append_view,
429 *image_view;
430
cristy4ca38e22011-02-10 02:57:49 +0000431 const Image
432 *image;
433
cristy3ed852e2009-09-05 21:47:34 +0000434 Image
435 *append_image;
436
cristy3ed852e2009-09-05 21:47:34 +0000437 MagickBooleanType
438 matte,
439 proceed,
440 status;
441
cristybb503372010-05-27 20:51:26 +0000442 MagickOffsetType
443 n;
444
cristy3ed852e2009-09-05 21:47:34 +0000445 RectangleInfo
446 geometry;
447
448 register const Image
449 *next;
450
cristybb503372010-05-27 20:51:26 +0000451 size_t
cristy3ed852e2009-09-05 21:47:34 +0000452 height,
453 number_images,
454 width;
455
cristybb503372010-05-27 20:51:26 +0000456 ssize_t
457 x_offset,
458 y,
459 y_offset;
460
cristy3ed852e2009-09-05 21:47:34 +0000461 /*
cristy7c6dc152011-02-11 14:10:55 +0000462 Compute maximum area of appended area.
cristy3ed852e2009-09-05 21:47:34 +0000463 */
cristy4ca38e22011-02-10 02:57:49 +0000464 assert(images != (Image *) NULL);
465 assert(images->signature == MagickSignature);
466 if (images->debug != MagickFalse)
467 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy3ed852e2009-09-05 21:47:34 +0000468 assert(exception != (ExceptionInfo *) NULL);
469 assert(exception->signature == MagickSignature);
cristy4ca38e22011-02-10 02:57:49 +0000470 image=images;
cristy3ed852e2009-09-05 21:47:34 +0000471 matte=image->matte;
472 number_images=1;
473 width=image->columns;
474 height=image->rows;
475 next=GetNextImageInList(image);
476 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
477 {
478 if (next->matte != MagickFalse)
479 matte=MagickTrue;
480 number_images++;
481 if (stack != MagickFalse)
482 {
483 if (next->columns > width)
484 width=next->columns;
485 height+=next->rows;
486 continue;
487 }
488 width+=next->columns;
489 if (next->rows > height)
490 height=next->rows;
491 }
492 /*
cristy7c6dc152011-02-11 14:10:55 +0000493 Append images.
cristy3ed852e2009-09-05 21:47:34 +0000494 */
495 append_image=CloneImage(image,width,height,MagickTrue,exception);
496 if (append_image == (Image *) NULL)
497 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000498 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000499 {
cristy3ed852e2009-09-05 21:47:34 +0000500 append_image=DestroyImage(append_image);
501 return((Image *) NULL);
502 }
503 append_image->matte=matte;
cristyea1a8aa2011-10-20 13:24:06 +0000504 (void) SetImageBackgroundColor(append_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000505 status=MagickTrue;
506 x_offset=0;
507 y_offset=0;
508 append_view=AcquireCacheView(append_image);
cristybb503372010-05-27 20:51:26 +0000509 for (n=0; n < (MagickOffsetType) number_images; n++)
cristy3ed852e2009-09-05 21:47:34 +0000510 {
511 SetGeometry(append_image,&geometry);
512 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
513 if (stack != MagickFalse)
514 x_offset-=geometry.x;
515 else
516 y_offset-=geometry.y;
517 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +0000518#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy1a2bd532010-11-19 02:53:15 +0000519 #pragma omp parallel for schedule(dynamic,4) shared(status) omp_throttle(1)
cristy3ed852e2009-09-05 21:47:34 +0000520#endif
cristybb503372010-05-27 20:51:26 +0000521 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000522 {
523 MagickBooleanType
524 sync;
525
cristy4c08aed2011-07-01 19:47:50 +0000526 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000527 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000528
cristy4c08aed2011-07-01 19:47:50 +0000529 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000530 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000531
cristycb6d09b2010-06-19 01:59:36 +0000532 register ssize_t
533 x;
534
cristy3ed852e2009-09-05 21:47:34 +0000535 if (status == MagickFalse)
536 continue;
537 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
538 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
539 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000540 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000541 {
542 status=MagickFalse;
543 continue;
544 }
cristybb503372010-05-27 20:51:26 +0000545 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000546 {
cristya905c052011-09-17 22:37:55 +0000547 register ssize_t
548 i;
549
550 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
551 {
552 PixelChannel
553 channel;
554
555 PixelTrait
556 append_traits,
557 traits;
558
559 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
560 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
561 append_traits=GetPixelChannelMapTraits(append_image,channel);
562 if ((traits == UndefinedPixelTrait) ||
563 (append_traits == UndefinedPixelTrait))
564 continue;
cristy0beccfa2011-09-25 20:47:53 +0000565 SetPixelChannel(append_image,channel,p[i],q);
cristya905c052011-09-17 22:37:55 +0000566 }
cristyed231572011-07-14 02:18:59 +0000567 p+=GetPixelChannels(image);
568 q+=GetPixelChannels(append_image);
cristy3ed852e2009-09-05 21:47:34 +0000569 }
570 sync=SyncCacheViewAuthenticPixels(append_view,exception);
571 if (sync == MagickFalse)
cristya65f35b2010-04-20 01:10:41 +0000572 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000573 }
574 image_view=DestroyCacheView(image_view);
575 proceed=SetImageProgress(image,AppendImageTag,n,number_images);
576 if (proceed == MagickFalse)
577 break;
578 if (stack == MagickFalse)
579 {
cristyeaedf062010-05-29 22:36:02 +0000580 x_offset+=(ssize_t) image->columns;
cristy3ed852e2009-09-05 21:47:34 +0000581 y_offset=0;
582 }
583 else
584 {
585 x_offset=0;
cristyeaedf062010-05-29 22:36:02 +0000586 y_offset+=(ssize_t) image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000587 }
588 image=GetNextImageInList(image);
589 }
590 append_view=DestroyCacheView(append_view);
591 if (status == MagickFalse)
592 append_image=DestroyImage(append_image);
593 return(append_image);
594}
595
596/*
597%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
598% %
599% %
600% %
cristy3ed852e2009-09-05 21:47:34 +0000601% C a t c h I m a g e E x c e p t i o n %
602% %
603% %
604% %
605%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
606%
607% CatchImageException() returns if no exceptions are found in the image
608% sequence, otherwise it determines the most severe exception and reports
609% it as a warning or error depending on the severity.
610%
611% The format of the CatchImageException method is:
612%
613% ExceptionType CatchImageException(Image *image)
614%
615% A description of each parameter follows:
616%
617% o image: An image sequence.
618%
619*/
620MagickExport ExceptionType CatchImageException(Image *image)
621{
622 ExceptionInfo
623 *exception;
624
625 ExceptionType
626 severity;
627
628 assert(image != (const Image *) NULL);
629 assert(image->signature == MagickSignature);
630 if (image->debug != MagickFalse)
631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
632 exception=AcquireExceptionInfo();
cristy3ed852e2009-09-05 21:47:34 +0000633 CatchException(exception);
634 severity=exception->severity;
635 exception=DestroyExceptionInfo(exception);
636 return(severity);
637}
638
639/*
640%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
641% %
642% %
643% %
644% C l i p I m a g e P a t h %
645% %
646% %
647% %
648%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
649%
650% ClipImagePath() sets the image clip mask based any clipping path information
651% if it exists.
652%
653% The format of the ClipImagePath method is:
654%
655% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000656% const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000657%
658% A description of each parameter follows:
659%
660% o image: the image.
661%
662% o pathname: name of clipping path resource. If name is preceded by #, use
663% clipping path numbered by name.
664%
665% o inside: if non-zero, later operations take effect inside clipping path.
666% Otherwise later operations take effect outside clipping path.
667%
cristy018f07f2011-09-04 21:15:19 +0000668% o exception: return any errors or warnings in this structure.
669%
cristy3ed852e2009-09-05 21:47:34 +0000670*/
671
cristy018f07f2011-09-04 21:15:19 +0000672MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000673{
cristy018f07f2011-09-04 21:15:19 +0000674 return(ClipImagePath(image,"#1",MagickTrue,exception));
cristy3ed852e2009-09-05 21:47:34 +0000675}
676
677MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000678 const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000679{
680#define ClipImagePathTag "ClipPath/Image"
681
682 char
683 *property;
684
685 const char
686 *value;
687
688 Image
689 *clip_mask;
690
691 ImageInfo
692 *image_info;
693
694 assert(image != (const Image *) NULL);
695 assert(image->signature == MagickSignature);
696 if (image->debug != MagickFalse)
697 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
698 assert(pathname != NULL);
699 property=AcquireString(pathname);
cristyb51dff52011-05-19 16:55:47 +0000700 (void) FormatLocaleString(property,MaxTextExtent,"8BIM:1999,2998:%s",
cristy3ed852e2009-09-05 21:47:34 +0000701 pathname);
cristyd15e6592011-10-15 00:13:06 +0000702 value=GetImageProperty(image,property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000703 property=DestroyString(property);
704 if (value == (const char *) NULL)
705 {
cristy6fccee12011-10-20 18:43:18 +0000706 ThrowFileException(exception,OptionError,"NoClipPathDefined",
cristy3ed852e2009-09-05 21:47:34 +0000707 image->filename);
708 return(MagickFalse);
709 }
710 image_info=AcquireImageInfo();
711 (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent);
712 (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent);
cristy6fccee12011-10-20 18:43:18 +0000713 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
cristy3ed852e2009-09-05 21:47:34 +0000714 image_info=DestroyImageInfo(image_info);
715 if (clip_mask == (Image *) NULL)
716 return(MagickFalse);
717 if (clip_mask->storage_class == PseudoClass)
718 {
cristyea1a8aa2011-10-20 13:24:06 +0000719 (void) SyncImage(clip_mask,exception);
cristy6fccee12011-10-20 18:43:18 +0000720 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000721 return(MagickFalse);
722 }
723 if (inside == MagickFalse)
cristy6fccee12011-10-20 18:43:18 +0000724 (void) NegateImage(clip_mask,MagickFalse,exception);
cristyb51dff52011-05-19 16:55:47 +0000725 (void) FormatLocaleString(clip_mask->magick_filename,MaxTextExtent,
cristy3ed852e2009-09-05 21:47:34 +0000726 "8BIM:1999,2998:%s\nPS",pathname);
cristy018f07f2011-09-04 21:15:19 +0000727 (void) SetImageClipMask(image,clip_mask,exception);
cristy3ed852e2009-09-05 21:47:34 +0000728 clip_mask=DestroyImage(clip_mask);
729 return(MagickTrue);
730}
731
732/*
733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
734% %
735% %
736% %
737% C l o n e I m a g e %
738% %
739% %
740% %
741%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
742%
743% CloneImage() copies an image and returns the copy as a new image object.
anthony96f11ee2011-03-23 08:22:54 +0000744%
cristy3ed852e2009-09-05 21:47:34 +0000745% If the specified columns and rows is 0, an exact copy of the image is
746% returned, otherwise the pixel data is undefined and must be initialized
747% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
748% failure, a NULL image is returned and exception describes the reason for the
749% failure.
750%
751% The format of the CloneImage method is:
752%
cristybb503372010-05-27 20:51:26 +0000753% Image *CloneImage(const Image *image,const size_t columns,
754% const size_t rows,const MagickBooleanType orphan,
cristy3ed852e2009-09-05 21:47:34 +0000755% ExceptionInfo *exception)
756%
757% A description of each parameter follows:
758%
759% o image: the image.
760%
761% o columns: the number of columns in the cloned image.
762%
763% o rows: the number of rows in the cloned image.
764%
765% o detach: With a value other than 0, the cloned image is detached from
766% its parent I/O stream.
767%
768% o exception: return any errors or warnings in this structure.
769%
770*/
cristybb503372010-05-27 20:51:26 +0000771MagickExport Image *CloneImage(const Image *image,const size_t columns,
cristybee00932011-01-15 20:28:27 +0000772 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000773{
774 Image
775 *clone_image;
776
777 MagickRealType
778 scale;
779
780 size_t
781 length;
782
783 /*
784 Clone the image.
785 */
786 assert(image != (const Image *) NULL);
787 assert(image->signature == MagickSignature);
788 if (image->debug != MagickFalse)
789 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
790 assert(exception != (ExceptionInfo *) NULL);
791 assert(exception->signature == MagickSignature);
cristy73bd4a52010-10-05 11:24:23 +0000792 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000793 if (clone_image == (Image *) NULL)
794 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
795 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
796 clone_image->signature=MagickSignature;
797 clone_image->storage_class=image->storage_class;
cristyed231572011-07-14 02:18:59 +0000798 clone_image->number_channels=image->number_channels;
cristyb3a73b52011-07-26 01:34:43 +0000799 clone_image->number_meta_channels=image->number_meta_channels;
cristy4c08aed2011-07-01 19:47:50 +0000800 clone_image->metacontent_extent=image->metacontent_extent;
cristy3ed852e2009-09-05 21:47:34 +0000801 clone_image->colorspace=image->colorspace;
802 clone_image->matte=image->matte;
803 clone_image->columns=image->columns;
804 clone_image->rows=image->rows;
805 clone_image->dither=image->dither;
cristy101ab702011-10-13 13:06:32 +0000806 if (image->colormap != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000807 {
808 /*
809 Allocate and copy the image colormap.
810 */
811 clone_image->colors=image->colors;
812 length=(size_t) image->colors;
cristy101ab702011-10-13 13:06:32 +0000813 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
cristy3ed852e2009-09-05 21:47:34 +0000814 sizeof(*clone_image->colormap));
cristy101ab702011-10-13 13:06:32 +0000815 if (clone_image->colormap == (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000816 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
817 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
818 sizeof(*clone_image->colormap));
819 }
820 (void) CloneImageProfiles(clone_image,image);
821 (void) CloneImageProperties(clone_image,image);
822 (void) CloneImageArtifacts(clone_image,image);
823 GetTimerInfo(&clone_image->timer);
cristy3ed852e2009-09-05 21:47:34 +0000824 if (image->ascii85 != (void *) NULL)
825 Ascii85Initialize(clone_image);
826 clone_image->magick_columns=image->magick_columns;
827 clone_image->magick_rows=image->magick_rows;
828 clone_image->type=image->type;
cristy636dcb52011-08-26 13:23:49 +0000829 clone_image->channel_mask=image->channel_mask;
cristyed231572011-07-14 02:18:59 +0000830 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +0000831 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
832 MaxTextExtent);
833 (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent);
834 (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent);
835 clone_image->progress_monitor=image->progress_monitor;
836 clone_image->client_data=image->client_data;
837 clone_image->reference_count=1;
cristybee00932011-01-15 20:28:27 +0000838 clone_image->next=image->next;
839 clone_image->previous=image->previous;
cristy3ed852e2009-09-05 21:47:34 +0000840 clone_image->list=NewImageList();
841 clone_image->clip_mask=NewImageList();
842 clone_image->mask=NewImageList();
843 if (detach == MagickFalse)
844 clone_image->blob=ReferenceBlob(image->blob);
845 else
cristybee00932011-01-15 20:28:27 +0000846 {
847 clone_image->next=NewImageList();
848 clone_image->previous=NewImageList();
849 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
850 }
cristy73724512010-04-12 14:43:14 +0000851 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000852 clone_image->debug=IsEventLogging();
853 clone_image->semaphore=AllocateSemaphoreInfo();
854 if ((columns == 0) && (rows == 0))
855 {
856 if (image->montage != (char *) NULL)
857 (void) CloneString(&clone_image->montage,image->montage);
858 if (image->directory != (char *) NULL)
859 (void) CloneString(&clone_image->directory,image->directory);
860 if (image->clip_mask != (Image *) NULL)
861 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
862 exception);
863 if (image->mask != (Image *) NULL)
864 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
865 clone_image->cache=ReferencePixelCache(image->cache);
866 return(clone_image);
867 }
cristy1ab35fb2011-04-15 01:25:56 +0000868 if ((columns == image->columns) && (rows == image->rows))
869 {
870 if (image->clip_mask != (Image *) NULL)
871 clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue,
872 exception);
873 if (image->mask != (Image *) NULL)
874 clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception);
875 }
cristy3ed852e2009-09-05 21:47:34 +0000876 scale=(MagickRealType) columns/(MagickRealType) image->columns;
cristybb503372010-05-27 20:51:26 +0000877 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
878 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
879 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000880 scale=(MagickRealType) rows/(MagickRealType) image->rows;
cristybb503372010-05-27 20:51:26 +0000881 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
882 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
883 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000884 clone_image->columns=columns;
885 clone_image->rows=rows;
886 clone_image->cache=ClonePixelCache(image->cache);
887 return(clone_image);
888}
889
890/*
891%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
892% %
893% %
894% %
895% C l o n e I m a g e I n f o %
896% %
897% %
898% %
899%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900%
901% CloneImageInfo() makes a copy of the given image info structure. If
902% NULL is specified, a new image info structure is created initialized to
903% default values.
904%
905% The format of the CloneImageInfo method is:
906%
907% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
908%
909% A description of each parameter follows:
910%
911% o image_info: the image info.
912%
913*/
914MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
915{
916 ImageInfo
917 *clone_info;
918
919 clone_info=AcquireImageInfo();
920 if (image_info == (ImageInfo *) NULL)
921 return(clone_info);
922 clone_info->compression=image_info->compression;
923 clone_info->temporary=image_info->temporary;
924 clone_info->adjoin=image_info->adjoin;
925 clone_info->antialias=image_info->antialias;
926 clone_info->scene=image_info->scene;
927 clone_info->number_scenes=image_info->number_scenes;
928 clone_info->depth=image_info->depth;
929 if (image_info->size != (char *) NULL)
930 (void) CloneString(&clone_info->size,image_info->size);
931 if (image_info->extract != (char *) NULL)
932 (void) CloneString(&clone_info->extract,image_info->extract);
933 if (image_info->scenes != (char *) NULL)
934 (void) CloneString(&clone_info->scenes,image_info->scenes);
935 if (image_info->page != (char *) NULL)
936 (void) CloneString(&clone_info->page,image_info->page);
937 clone_info->interlace=image_info->interlace;
938 clone_info->endian=image_info->endian;
939 clone_info->units=image_info->units;
940 clone_info->quality=image_info->quality;
941 if (image_info->sampling_factor != (char *) NULL)
942 (void) CloneString(&clone_info->sampling_factor,
943 image_info->sampling_factor);
944 if (image_info->server_name != (char *) NULL)
945 (void) CloneString(&clone_info->server_name,image_info->server_name);
946 if (image_info->font != (char *) NULL)
947 (void) CloneString(&clone_info->font,image_info->font);
948 if (image_info->texture != (char *) NULL)
949 (void) CloneString(&clone_info->texture,image_info->texture);
950 if (image_info->density != (char *) NULL)
951 (void) CloneString(&clone_info->density,image_info->density);
952 clone_info->pointsize=image_info->pointsize;
953 clone_info->fuzz=image_info->fuzz;
cristy3ed852e2009-09-05 21:47:34 +0000954 clone_info->background_color=image_info->background_color;
955 clone_info->border_color=image_info->border_color;
956 clone_info->matte_color=image_info->matte_color;
957 clone_info->transparent_color=image_info->transparent_color;
958 clone_info->dither=image_info->dither;
959 clone_info->monochrome=image_info->monochrome;
cristy3ed852e2009-09-05 21:47:34 +0000960 clone_info->colorspace=image_info->colorspace;
961 clone_info->type=image_info->type;
962 clone_info->orientation=image_info->orientation;
963 clone_info->preview_type=image_info->preview_type;
964 clone_info->group=image_info->group;
965 clone_info->ping=image_info->ping;
966 clone_info->verbose=image_info->verbose;
967 if (image_info->view != (char *) NULL)
968 (void) CloneString(&clone_info->view,image_info->view);
cristy3ed852e2009-09-05 21:47:34 +0000969 clone_info->progress_monitor=image_info->progress_monitor;
970 clone_info->client_data=image_info->client_data;
971 clone_info->cache=image_info->cache;
972 if (image_info->cache != (void *) NULL)
973 clone_info->cache=ReferencePixelCache(image_info->cache);
974 if (image_info->profile != (void *) NULL)
975 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
976 image_info->profile);
977 SetImageInfoFile(clone_info,image_info->file);
978 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
979 clone_info->stream=image_info->stream;
980 clone_info->virtual_pixel_method=image_info->virtual_pixel_method;
981 (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent);
982 (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent);
983 (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent);
984 (void) CopyMagickString(clone_info->filename,image_info->filename,
985 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +0000986 clone_info->channel=image_info->channel;
anthony1afdc7a2011-10-05 11:54:28 +0000987
988 (void) CloneImageOptions(clone_info,image_info);
cristy3ed852e2009-09-05 21:47:34 +0000989 clone_info->debug=IsEventLogging();
990 clone_info->signature=image_info->signature;
991 return(clone_info);
992}
993
994/*
995%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
996% %
997% %
998% %
999% C o m b i n e I m a g e s %
1000% %
1001% %
1002% %
1003%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1004%
1005% CombineImages() combines one or more images into a single image. The
1006% grayscale value of the pixels of each image in the sequence is assigned in
1007% order to the specified channels of the combined image. The typical
1008% ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc.
1009%
1010% The format of the CombineImages method is:
1011%
cristy3139dc22011-07-08 00:11:42 +00001012% Image *CombineImages(const Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001013%
1014% A description of each parameter follows:
1015%
1016% o image: the image.
1017%
1018% o exception: return any errors or warnings in this structure.
1019%
1020*/
cristya905c052011-09-17 22:37:55 +00001021
1022static inline size_t MagickMin(const size_t x,const size_t y)
1023{
1024 if (x < y)
1025 return(x);
1026 return(y);
1027}
1028
cristy3139dc22011-07-08 00:11:42 +00001029MagickExport Image *CombineImages(const Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001030{
1031#define CombineImageTag "Combine/Image"
1032
1033 CacheView
1034 *combine_view;
1035
cristy3ed852e2009-09-05 21:47:34 +00001036 Image
1037 *combine_image;
1038
cristy3ed852e2009-09-05 21:47:34 +00001039 MagickBooleanType
1040 status;
1041
cristybb503372010-05-27 20:51:26 +00001042 MagickOffsetType
1043 progress;
1044
1045 ssize_t
1046 y;
1047
cristy3ed852e2009-09-05 21:47:34 +00001048 /*
1049 Ensure the image are the same size.
1050 */
1051 assert(image != (const Image *) NULL);
1052 assert(image->signature == MagickSignature);
1053 if (image->debug != MagickFalse)
1054 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1055 assert(exception != (ExceptionInfo *) NULL);
1056 assert(exception->signature == MagickSignature);
cristy3ed852e2009-09-05 21:47:34 +00001057 combine_image=CloneImage(image,0,0,MagickTrue,exception);
1058 if (combine_image == (Image *) NULL)
1059 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00001060 if (SetImageStorageClass(combine_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001061 {
cristy3ed852e2009-09-05 21:47:34 +00001062 combine_image=DestroyImage(combine_image);
1063 return((Image *) NULL);
1064 }
cristyed231572011-07-14 02:18:59 +00001065 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
cristy3ed852e2009-09-05 21:47:34 +00001066 combine_image->matte=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00001067 /*
1068 Combine images.
1069 */
1070 status=MagickTrue;
1071 progress=0;
1072 combine_view=AcquireCacheView(combine_image);
cristybb503372010-05-27 20:51:26 +00001073 for (y=0; y < (ssize_t) combine_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001074 {
1075 CacheView
1076 *image_view;
1077
1078 const Image
1079 *next;
1080
cristy4c08aed2011-07-01 19:47:50 +00001081 Quantum
cristy3ed852e2009-09-05 21:47:34 +00001082 *pixels;
1083
cristy4c08aed2011-07-01 19:47:50 +00001084 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00001085 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00001086
cristy4c08aed2011-07-01 19:47:50 +00001087 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00001088 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00001089
cristycb6d09b2010-06-19 01:59:36 +00001090 register ssize_t
cristya905c052011-09-17 22:37:55 +00001091 i;
cristycb6d09b2010-06-19 01:59:36 +00001092
cristy3ed852e2009-09-05 21:47:34 +00001093 if (status == MagickFalse)
1094 continue;
1095 pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns,
1096 1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001097 if (pixels == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001098 {
1099 status=MagickFalse;
1100 continue;
1101 }
1102 next=image;
cristya905c052011-09-17 22:37:55 +00001103 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1104 {
1105 PixelChannel
1106 channel;
cristy3ed852e2009-09-05 21:47:34 +00001107
cristya905c052011-09-17 22:37:55 +00001108 PixelTrait
1109 combine_traits,
1110 traits;
1111
1112 register ssize_t
1113 x;
1114
1115 if (next == (Image *) NULL)
1116 continue;
1117 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1118 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
1119 combine_traits=GetPixelChannelMapTraits(combine_image,channel);
1120 if ((traits == UndefinedPixelTrait) ||
1121 (combine_traits == UndefinedPixelTrait))
1122 continue;
1123 image_view=AcquireCacheView(next);
1124 p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception);
1125 if (p == (const Quantum *) NULL)
1126 continue;
1127 q=pixels;
1128 for (x=0; x < (ssize_t) combine_image->columns; x++)
1129 {
1130 if (x < (ssize_t) image->columns)
1131 {
1132 q[i]=p[i];
1133 p+=GetPixelChannels(image);
1134 }
1135 q+=GetPixelChannels(combine_image);
cristy3ed852e2009-09-05 21:47:34 +00001136 }
cristya905c052011-09-17 22:37:55 +00001137 image_view=DestroyCacheView(image_view);
1138 next=GetNextImageInList(next);
1139 if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse)
1140 status=MagickFalse;
1141 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1142 {
1143 MagickBooleanType
1144 proceed;
1145
1146 proceed=SetImageProgress(image,CombineImageTag,progress++,
1147 combine_image->rows);
1148 if (proceed == MagickFalse)
1149 status=MagickFalse;
1150 }
1151 }
cristy3ed852e2009-09-05 21:47:34 +00001152 }
1153 combine_view=DestroyCacheView(combine_view);
1154 if (status == MagickFalse)
1155 combine_image=DestroyImage(combine_image);
1156 return(combine_image);
1157}
1158
1159/*
1160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1161% %
1162% %
1163% %
cristy3ed852e2009-09-05 21:47:34 +00001164% D e s t r o y I m a g e %
1165% %
1166% %
1167% %
1168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1169%
1170% DestroyImage() dereferences an image, deallocating memory associated with
1171% the image if the reference count becomes zero.
1172%
1173% The format of the DestroyImage method is:
1174%
1175% Image *DestroyImage(Image *image)
1176%
1177% A description of each parameter follows:
1178%
1179% o image: the image.
1180%
1181*/
1182MagickExport Image *DestroyImage(Image *image)
1183{
1184 MagickBooleanType
1185 destroy;
1186
1187 /*
1188 Dereference image.
1189 */
1190 assert(image != (Image *) NULL);
1191 assert(image->signature == MagickSignature);
1192 if (image->debug != MagickFalse)
1193 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1194 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001195 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001196 image->reference_count--;
1197 if (image->reference_count == 0)
1198 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001199 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001200 if (destroy == MagickFalse)
1201 return((Image *) NULL);
1202 /*
1203 Destroy image.
1204 */
1205 DestroyImagePixels(image);
cristyed231572011-07-14 02:18:59 +00001206 image->channel_map=DestroyPixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +00001207 if (image->clip_mask != (Image *) NULL)
1208 image->clip_mask=DestroyImage(image->clip_mask);
1209 if (image->mask != (Image *) NULL)
1210 image->mask=DestroyImage(image->mask);
1211 if (image->montage != (char *) NULL)
1212 image->montage=DestroyString(image->montage);
1213 if (image->directory != (char *) NULL)
1214 image->directory=DestroyString(image->directory);
cristy101ab702011-10-13 13:06:32 +00001215 if (image->colormap != (PixelInfo *) NULL)
1216 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
cristy3ed852e2009-09-05 21:47:34 +00001217 if (image->geometry != (char *) NULL)
1218 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001219 DestroyImageProfiles(image);
1220 DestroyImageProperties(image);
1221 DestroyImageArtifacts(image);
1222 if (image->ascii85 != (Ascii85Info*) NULL)
1223 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1224 DestroyBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001225 if (image->semaphore != (SemaphoreInfo *) NULL)
1226 DestroySemaphoreInfo(&image->semaphore);
1227 image->signature=(~MagickSignature);
1228 image=(Image *) RelinquishMagickMemory(image);
1229 return(image);
1230}
1231
1232/*
1233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1234% %
1235% %
1236% %
1237% D e s t r o y I m a g e I n f o %
1238% %
1239% %
1240% %
1241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1242%
1243% DestroyImageInfo() deallocates memory associated with an ImageInfo
1244% structure.
1245%
1246% The format of the DestroyImageInfo method is:
1247%
1248% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1249%
1250% A description of each parameter follows:
1251%
1252% o image_info: the image info.
1253%
1254*/
1255MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1256{
1257 assert(image_info != (ImageInfo *) NULL);
1258 assert(image_info->signature == MagickSignature);
1259 if (image_info->debug != MagickFalse)
1260 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1261 image_info->filename);
1262 if (image_info->size != (char *) NULL)
1263 image_info->size=DestroyString(image_info->size);
1264 if (image_info->extract != (char *) NULL)
1265 image_info->extract=DestroyString(image_info->extract);
1266 if (image_info->scenes != (char *) NULL)
1267 image_info->scenes=DestroyString(image_info->scenes);
1268 if (image_info->page != (char *) NULL)
1269 image_info->page=DestroyString(image_info->page);
1270 if (image_info->sampling_factor != (char *) NULL)
1271 image_info->sampling_factor=DestroyString(
1272 image_info->sampling_factor);
1273 if (image_info->server_name != (char *) NULL)
1274 image_info->server_name=DestroyString(
1275 image_info->server_name);
1276 if (image_info->font != (char *) NULL)
1277 image_info->font=DestroyString(image_info->font);
1278 if (image_info->texture != (char *) NULL)
1279 image_info->texture=DestroyString(image_info->texture);
1280 if (image_info->density != (char *) NULL)
1281 image_info->density=DestroyString(image_info->density);
1282 if (image_info->view != (char *) NULL)
1283 image_info->view=DestroyString(image_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001284 if (image_info->cache != (void *) NULL)
1285 image_info->cache=DestroyPixelCache(image_info->cache);
1286 if (image_info->profile != (StringInfo *) NULL)
1287 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1288 image_info->profile);
anthony1afdc7a2011-10-05 11:54:28 +00001289 DestroyImageOptions(image_info);
cristy3ed852e2009-09-05 21:47:34 +00001290 image_info->signature=(~MagickSignature);
1291 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1292 return(image_info);
1293}
1294
1295/*
1296%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1297% %
1298% %
1299% %
1300+ D i s a s s o c i a t e I m a g e S t r e a m %
1301% %
1302% %
1303% %
1304%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1305%
1306% DisassociateImageStream() disassociates the image stream.
1307%
1308% The format of the DisassociateImageStream method is:
1309%
1310% MagickBooleanType DisassociateImageStream(const Image *image)
1311%
1312% A description of each parameter follows:
1313%
1314% o image: the image.
1315%
1316*/
1317MagickExport void DisassociateImageStream(Image *image)
1318{
1319 assert(image != (const Image *) NULL);
1320 assert(image->signature == MagickSignature);
1321 if (image->debug != MagickFalse)
1322 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1323 (void) DetachBlob(image->blob);
1324}
1325
1326/*
1327%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328% %
1329% %
1330% %
1331% G e t I m a g e A l p h a C h a n n e l %
1332% %
1333% %
1334% %
1335%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1336%
1337% GetImageAlphaChannel() returns MagickFalse if the image alpha channel is
1338% not activated. That is, the image is RGB rather than RGBA or CMYK rather
1339% than CMYKA.
1340%
1341% The format of the GetImageAlphaChannel method is:
1342%
1343% MagickBooleanType GetImageAlphaChannel(const Image *image)
1344%
1345% A description of each parameter follows:
1346%
1347% o image: the image.
1348%
1349*/
1350MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image)
1351{
1352 assert(image != (const Image *) NULL);
1353 if (image->debug != MagickFalse)
1354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1355 assert(image->signature == MagickSignature);
1356 return(image->matte);
1357}
1358
1359/*
1360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1361% %
1362% %
1363% %
1364% G e t I m a g e C l i p M a s k %
1365% %
1366% %
1367% %
1368%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1369%
1370% GetImageClipMask() returns the clip path associated with the image.
1371%
1372% The format of the GetImageClipMask method is:
1373%
1374% Image *GetImageClipMask(const Image *image,ExceptionInfo *exception)
1375%
1376% A description of each parameter follows:
1377%
1378% o image: the image.
1379%
1380*/
1381MagickExport Image *GetImageClipMask(const Image *image,
1382 ExceptionInfo *exception)
1383{
1384 assert(image != (const Image *) NULL);
1385 if (image->debug != MagickFalse)
1386 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1387 assert(image->signature == MagickSignature);
1388 if (image->clip_mask == (Image *) NULL)
1389 return((Image *) NULL);
1390 return(CloneImage(image->clip_mask,0,0,MagickTrue,exception));
1391}
1392
1393/*
1394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1395% %
1396% %
1397% %
cristy3ed852e2009-09-05 21:47:34 +00001398% G e t I m a g e I n f o %
1399% %
1400% %
1401% %
1402%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1403%
1404% GetImageInfo() initializes image_info to default values.
1405%
1406% The format of the GetImageInfo method is:
1407%
1408% void GetImageInfo(ImageInfo *image_info)
1409%
1410% A description of each parameter follows:
1411%
1412% o image_info: the image info.
1413%
1414*/
1415MagickExport void GetImageInfo(ImageInfo *image_info)
1416{
cristyd9a29192010-10-16 16:49:53 +00001417 const char
1418 *synchronize;
1419
cristy3ed852e2009-09-05 21:47:34 +00001420 ExceptionInfo
1421 *exception;
1422
1423 /*
1424 File and image dimension members.
1425 */
1426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1427 assert(image_info != (ImageInfo *) NULL);
1428 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1429 image_info->adjoin=MagickTrue;
1430 image_info->interlace=NoInterlace;
1431 image_info->channel=DefaultChannels;
1432 image_info->quality=UndefinedCompressionQuality;
1433 image_info->antialias=MagickTrue;
1434 image_info->dither=MagickTrue;
cristyd9a29192010-10-16 16:49:53 +00001435 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1436 if (synchronize != (const char *) NULL)
1437 image_info->synchronize=IsMagickTrue(synchronize);
cristy3ed852e2009-09-05 21:47:34 +00001438 exception=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00001439 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1440 &image_info->background_color,exception);
1441 (void) QueryColorCompliance(BorderColor,AllCompliance,
1442 &image_info->border_color,exception);
1443 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
cristy3ed852e2009-09-05 21:47:34 +00001444 exception);
cristy9950d572011-10-01 18:22:35 +00001445 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1446 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00001447 exception=DestroyExceptionInfo(exception);
1448 image_info->debug=IsEventLogging();
1449 image_info->signature=MagickSignature;
1450}
1451
1452/*
1453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1454% %
1455% %
1456% %
cristy15781e52009-12-05 23:05:27 +00001457% G e t I m a g e I n f o F i l e %
1458% %
1459% %
1460% %
1461%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1462%
1463% GetImageInfoFile() returns the image info file member.
1464%
1465% The format of the GetImageInfoFile method is:
1466%
1467% FILE *GetImageInfoFile(const ImageInfo *image_info)
1468%
1469% A description of each parameter follows:
1470%
1471% o image_info: the image info.
1472%
1473*/
1474MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1475{
1476 return(image_info->file);
1477}
1478
1479/*
1480%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1481% %
1482% %
1483% %
cristy3ed852e2009-09-05 21:47:34 +00001484% G e t I m a g e M a s k %
1485% %
1486% %
1487% %
1488%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1489%
1490% GetImageMask() returns the mask associated with the image.
1491%
1492% The format of the GetImageMask method is:
1493%
1494% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1495%
1496% A description of each parameter follows:
1497%
1498% o image: the image.
1499%
1500*/
1501MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1502{
1503 assert(image != (const Image *) NULL);
1504 if (image->debug != MagickFalse)
1505 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1506 assert(image->signature == MagickSignature);
1507 if (image->mask == (Image *) NULL)
1508 return((Image *) NULL);
1509 return(CloneImage(image->mask,0,0,MagickTrue,exception));
1510}
1511
1512/*
1513%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1514% %
1515% %
1516% %
1517+ G e t I m a g e R e f e r e n c e C o u n t %
1518% %
1519% %
1520% %
1521%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1522%
1523% GetImageReferenceCount() returns the image reference count.
1524%
1525% The format of the GetReferenceCount method is:
1526%
cristybb503372010-05-27 20:51:26 +00001527% ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001528%
1529% A description of each parameter follows:
1530%
1531% o image: the image.
1532%
1533*/
cristybb503372010-05-27 20:51:26 +00001534MagickExport ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001535{
cristybb503372010-05-27 20:51:26 +00001536 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001537 reference_count;
1538
1539 assert(image != (Image *) NULL);
1540 assert(image->signature == MagickSignature);
1541 if (image->debug != MagickFalse)
1542 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001543 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001544 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001545 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001546 return(reference_count);
1547}
1548
1549/*
1550%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1551% %
1552% %
1553% %
cristy3ed852e2009-09-05 21:47:34 +00001554% 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 %
1555% %
1556% %
1557% %
1558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1559%
1560% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1561% image. A virtual pixel is any pixel access that is outside the boundaries
1562% of the image cache.
1563%
1564% The format of the GetImageVirtualPixelMethod() method is:
1565%
1566% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1567%
1568% A description of each parameter follows:
1569%
1570% o image: the image.
1571%
1572*/
1573MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1574{
1575 assert(image != (Image *) NULL);
1576 assert(image->signature == MagickSignature);
1577 if (image->debug != MagickFalse)
1578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1579 return(GetPixelCacheVirtualMethod(image));
1580}
1581
1582/*
1583%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584% %
1585% %
1586% %
1587% I n t e r p r e t I m a g e F i l e n a m e %
1588% %
1589% %
1590% %
1591%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1592%
1593% InterpretImageFilename() interprets embedded characters in an image filename.
1594% The filename length is returned.
1595%
1596% The format of the InterpretImageFilename method is:
1597%
1598% size_t InterpretImageFilename(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00001599% Image *image,const char *format,int value,char *filename,
1600% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001601%
1602% A description of each parameter follows.
1603%
1604% o image_info: the image info..
1605%
1606% o image: the image.
1607%
1608% o format: A filename describing the format to use to write the numeric
1609% argument. Only the first numeric format identifier is replaced.
1610%
1611% o value: Numeric value to substitute into format filename.
1612%
1613% o filename: return the formatted filename in this character buffer.
1614%
cristy6fccee12011-10-20 18:43:18 +00001615% o exception: return any errors or warnings in this structure.
1616%
cristy3ed852e2009-09-05 21:47:34 +00001617*/
1618MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00001619 Image *image,const char *format,int value,char *filename,
1620 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001621{
1622 char
1623 *q;
1624
1625 int
1626 c;
1627
1628 MagickBooleanType
1629 canonical;
1630
1631 register const char
1632 *p;
1633
cristyad785752011-07-27 23:13:03 +00001634 size_t
1635 length;
1636
cristy3ed852e2009-09-05 21:47:34 +00001637 canonical=MagickFalse;
cristyc7b79fc2011-07-28 00:24:17 +00001638 length=0;
cristy3ed852e2009-09-05 21:47:34 +00001639 (void) CopyMagickString(filename,format,MaxTextExtent);
1640 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1641 {
1642 q=(char *) p+1;
1643 if (*q == '%')
1644 {
1645 p=q+1;
1646 continue;
1647 }
1648 if (*q == '0')
1649 {
cristybb503372010-05-27 20:51:26 +00001650 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001651 value;
1652
cristybb503372010-05-27 20:51:26 +00001653 value=(ssize_t) strtol(q,&q,10);
cristyda16f162011-02-19 23:52:17 +00001654 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00001655 }
1656 switch (*q)
1657 {
1658 case 'd':
1659 case 'o':
1660 case 'x':
1661 {
1662 q++;
1663 c=(*q);
1664 *q='\0';
cristyb51dff52011-05-19 16:55:47 +00001665 (void) FormatLocaleString(filename+(p-format),(size_t) (MaxTextExtent-
cristy3ed852e2009-09-05 21:47:34 +00001666 (p-format)),p,value);
1667 *q=c;
1668 (void) ConcatenateMagickString(filename,q,MaxTextExtent);
1669 canonical=MagickTrue;
1670 if (*(q-1) != '%')
1671 break;
1672 p++;
1673 break;
1674 }
1675 case '[':
1676 {
1677 char
1678 pattern[MaxTextExtent];
1679
1680 const char
1681 *value;
1682
cristy3ed852e2009-09-05 21:47:34 +00001683 register char
1684 *r;
1685
cristybb503372010-05-27 20:51:26 +00001686 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001687 i;
1688
cristycb6d09b2010-06-19 01:59:36 +00001689 ssize_t
1690 depth;
1691
cristy3ed852e2009-09-05 21:47:34 +00001692 /*
1693 Image option.
1694 */
1695 if (strchr(p,']') == (char *) NULL)
1696 break;
1697 depth=1;
1698 r=q+1;
1699 for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++)
1700 {
1701 if (*r == '[')
1702 depth++;
1703 if (*r == ']')
1704 depth--;
1705 if (depth <= 0)
1706 break;
1707 pattern[i]=(*r++);
1708 }
1709 pattern[i]='\0';
1710 if (LocaleNCompare(pattern,"filename:",9) != 0)
1711 break;
1712 value=(const char *) NULL;
1713 if ((image_info != (const ImageInfo *) NULL) &&
1714 (image != (const Image *) NULL))
cristy6fccee12011-10-20 18:43:18 +00001715 value=GetMagickProperty(image_info,image,pattern,exception);
cristy3ed852e2009-09-05 21:47:34 +00001716 else
1717 if (image != (Image *) NULL)
cristy6fccee12011-10-20 18:43:18 +00001718 value=GetImageProperty(image,pattern,exception);
cristy3ed852e2009-09-05 21:47:34 +00001719 else
1720 if (image_info != (ImageInfo *) NULL)
cristy86fe49e2010-06-25 01:18:11 +00001721 value=GetImageOption(image_info,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001722 if (value == (const char *) NULL)
1723 break;
1724 q--;
1725 c=(*q);
1726 *q='\0';
cristyad785752011-07-27 23:13:03 +00001727 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
1728 (MaxTextExtent-(p-format-length)));
1729 length+=strlen(pattern)-1;
cristy3ed852e2009-09-05 21:47:34 +00001730 *q=c;
1731 (void) ConcatenateMagickString(filename,r+1,MaxTextExtent);
1732 canonical=MagickTrue;
1733 if (*(q-1) != '%')
1734 break;
1735 p++;
1736 break;
1737 }
1738 default:
1739 break;
1740 }
1741 }
1742 for (q=filename; *q != '\0'; q++)
1743 if ((*q == '%') && (*(q+1) == '%'))
cristy27bf23e2011-01-10 13:35:22 +00001744 {
1745 (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
1746 canonical=MagickTrue;
1747 }
cristy3ed852e2009-09-05 21:47:34 +00001748 if (canonical == MagickFalse)
1749 (void) CopyMagickString(filename,format,MaxTextExtent);
1750 return(strlen(filename));
1751}
1752
1753/*
1754%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1755% %
1756% %
1757% %
1758% I s H i g h D y n a m i c R a n g e I m a g e %
1759% %
1760% %
1761% %
1762%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1763%
1764% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1765% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1766% 0..65535.
1767%
1768% The format of the IsHighDynamicRangeImage method is:
1769%
1770% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1771% ExceptionInfo *exception)
1772%
1773% A description of each parameter follows:
1774%
1775% o image: the image.
1776%
1777% o exception: return any errors or warnings in this structure.
1778%
1779*/
1780MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1781 ExceptionInfo *exception)
1782{
1783#if !defined(MAGICKCORE_HDRI_SUPPORT)
1784 (void) image;
1785 (void) exception;
1786 return(MagickFalse);
1787#else
1788 CacheView
1789 *image_view;
1790
cristy3ed852e2009-09-05 21:47:34 +00001791 MagickBooleanType
1792 status;
1793
cristycb6d09b2010-06-19 01:59:36 +00001794 ssize_t
1795 y;
1796
cristy3ed852e2009-09-05 21:47:34 +00001797 assert(image != (Image *) NULL);
1798 assert(image->signature == MagickSignature);
1799 if (image->debug != MagickFalse)
1800 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1801 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00001802 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00001803#if defined(MAGICKCORE_OPENMP_SUPPORT)
1804 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00001805#endif
cristybb503372010-05-27 20:51:26 +00001806 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001807 {
cristy4c08aed2011-07-01 19:47:50 +00001808 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001809 pixel;
1810
cristy4c08aed2011-07-01 19:47:50 +00001811 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001812 *p;
1813
cristybb503372010-05-27 20:51:26 +00001814 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001815 x;
1816
1817 if (status == MagickFalse)
1818 continue;
1819 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001820 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001821 {
1822 status=MagickFalse;
1823 continue;
1824 }
cristy3ed852e2009-09-05 21:47:34 +00001825 pixel=zero;
cristybb503372010-05-27 20:51:26 +00001826 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001827 {
cristya905c052011-09-17 22:37:55 +00001828 PixelTrait
1829 traits;
1830
1831 register ssize_t
1832 i;
1833
1834 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1835 {
1836 MagickRealType
1837 pixel;
1838
1839 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
1840 if (traits == UndefinedPixelTrait)
1841 continue;
cristya13d0822011-09-19 00:19:19 +00001842 pixel=(MagickRealType) p[i];
cristya905c052011-09-17 22:37:55 +00001843 if ((pixel < 0.0) || (pixel > QuantumRange) ||
1844 (pixel != (QuantumAny) pixel))
1845 break;
1846 }
cristyed231572011-07-14 02:18:59 +00001847 p+=GetPixelChannels(image);
cristya905c052011-09-17 22:37:55 +00001848 if (i < (ssize_t) GetPixelChannels(image))
1849 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00001850 }
cristybb503372010-05-27 20:51:26 +00001851 if (x < (ssize_t) image->columns)
cristy3ed852e2009-09-05 21:47:34 +00001852 status=MagickFalse;
1853 }
1854 image_view=DestroyCacheView(image_view);
1855 return(status != MagickFalse ? MagickFalse : MagickTrue);
1856#endif
1857}
1858
1859/*
1860%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1861% %
1862% %
1863% %
1864% I s I m a g e O b j e c t %
1865% %
1866% %
1867% %
1868%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1869%
1870% IsImageObject() returns MagickTrue if the image sequence contains a valid
1871% set of image objects.
1872%
1873% The format of the IsImageObject method is:
1874%
1875% MagickBooleanType IsImageObject(const Image *image)
1876%
1877% A description of each parameter follows:
1878%
1879% o image: the image.
1880%
1881*/
1882MagickExport MagickBooleanType IsImageObject(const Image *image)
1883{
1884 register const Image
1885 *p;
1886
1887 assert(image != (Image *) NULL);
1888 if (image->debug != MagickFalse)
1889 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1890 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1891 if (p->signature != MagickSignature)
1892 return(MagickFalse);
1893 return(MagickTrue);
1894}
1895
1896/*
1897%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1898% %
1899% %
1900% %
1901% I s T a i n t I m a g e %
1902% %
1903% %
1904% %
1905%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1906%
1907% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1908% since it was first constituted.
1909%
1910% The format of the IsTaintImage method is:
1911%
1912% MagickBooleanType IsTaintImage(const Image *image)
1913%
1914% A description of each parameter follows:
1915%
1916% o image: the image.
1917%
1918*/
1919MagickExport MagickBooleanType IsTaintImage(const Image *image)
1920{
1921 char
1922 magick[MaxTextExtent],
1923 filename[MaxTextExtent];
1924
1925 register const Image
1926 *p;
1927
1928 assert(image != (Image *) NULL);
1929 if (image->debug != MagickFalse)
1930 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1931 assert(image->signature == MagickSignature);
1932 (void) CopyMagickString(magick,image->magick,MaxTextExtent);
1933 (void) CopyMagickString(filename,image->filename,MaxTextExtent);
1934 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1935 {
1936 if (p->taint != MagickFalse)
1937 return(MagickTrue);
1938 if (LocaleCompare(p->magick,magick) != 0)
1939 return(MagickTrue);
1940 if (LocaleCompare(p->filename,filename) != 0)
1941 return(MagickTrue);
1942 }
1943 return(MagickFalse);
1944}
1945
1946/*
1947%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1948% %
1949% %
1950% %
1951% M o d i f y I m a g e %
1952% %
1953% %
1954% %
1955%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1956%
1957% ModifyImage() ensures that there is only a single reference to the image
1958% to be modified, updating the provided image pointer to point to a clone of
1959% the original image if necessary.
1960%
1961% The format of the ModifyImage method is:
1962%
1963% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1964%
1965% A description of each parameter follows:
1966%
1967% o image: the image.
1968%
1969% o exception: return any errors or warnings in this structure.
1970%
1971*/
1972MagickExport MagickBooleanType ModifyImage(Image **image,
1973 ExceptionInfo *exception)
1974{
1975 Image
1976 *clone_image;
1977
1978 assert(image != (Image **) NULL);
1979 assert(*image != (Image *) NULL);
1980 assert((*image)->signature == MagickSignature);
1981 if ((*image)->debug != MagickFalse)
1982 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1983 if (GetImageReferenceCount(*image) <= 1)
1984 return(MagickTrue);
1985 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
cristyf84a1932010-01-03 18:00:18 +00001986 LockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001987 (*image)->reference_count--;
cristyf84a1932010-01-03 18:00:18 +00001988 UnlockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001989 *image=clone_image;
1990 return(MagickTrue);
1991}
1992
1993/*
1994%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1995% %
1996% %
1997% %
1998% N e w M a g i c k I m a g e %
1999% %
2000% %
2001% %
2002%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2003%
2004% NewMagickImage() creates a blank image canvas of the specified size and
2005% background color.
2006%
2007% The format of the NewMagickImage method is:
2008%
2009% Image *NewMagickImage(const ImageInfo *image_info,
cristy0740a982011-10-13 15:01:01 +00002010% const size_t width,const size_t height,const PixelInfo *background,
2011% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002012%
2013% A description of each parameter follows:
2014%
2015% o image: the image.
2016%
2017% o width: the image width.
2018%
2019% o height: the image height.
2020%
2021% o background: the image color.
2022%
cristy0740a982011-10-13 15:01:01 +00002023% o exception: return any errors or warnings in this structure.
2024%
cristy3ed852e2009-09-05 21:47:34 +00002025*/
2026MagickExport Image *NewMagickImage(const ImageInfo *image_info,
cristy0740a982011-10-13 15:01:01 +00002027 const size_t width,const size_t height,const PixelInfo *background,
2028 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002029{
2030 CacheView
2031 *image_view;
2032
cristy3ed852e2009-09-05 21:47:34 +00002033 Image
2034 *image;
2035
cristy3ed852e2009-09-05 21:47:34 +00002036 MagickBooleanType
2037 status;
2038
cristya905c052011-09-17 22:37:55 +00002039 ssize_t
2040 y;
2041
cristy3ed852e2009-09-05 21:47:34 +00002042 assert(image_info != (const ImageInfo *) NULL);
2043 if (image_info->debug != MagickFalse)
2044 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2045 assert(image_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +00002046 assert(background != (const PixelInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00002047 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00002048 image->columns=width;
2049 image->rows=height;
2050 image->colorspace=background->colorspace;
2051 image->matte=background->matte;
2052 image->fuzz=background->fuzz;
2053 image->depth=background->depth;
2054 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00002055 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00002056#if defined(MAGICKCORE_OPENMP_SUPPORT)
2057 #pragma omp parallel for schedule(dynamic,4) shared(status)
2058#endif
cristybb503372010-05-27 20:51:26 +00002059 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002060 {
cristy4c08aed2011-07-01 19:47:50 +00002061 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002062 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002063
cristycb6d09b2010-06-19 01:59:36 +00002064 register ssize_t
2065 x;
2066
cristy48974b92009-12-19 02:36:06 +00002067 if (status == MagickFalse)
2068 continue;
cristy3ed852e2009-09-05 21:47:34 +00002069 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002070 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002071 {
2072 status=MagickFalse;
2073 continue;
2074 }
cristybb503372010-05-27 20:51:26 +00002075 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002076 {
cristy4c08aed2011-07-01 19:47:50 +00002077 SetPixelPixelInfo(image,background,q);
cristyed231572011-07-14 02:18:59 +00002078 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00002079 }
2080 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2081 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002082 }
2083 image_view=DestroyCacheView(image_view);
2084 if (status == MagickFalse)
2085 image=DestroyImage(image);
2086 return(image);
2087}
2088
2089/*
2090%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2091% %
2092% %
2093% %
2094% R e f e r e n c e I m a g e %
2095% %
2096% %
2097% %
2098%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2099%
2100% ReferenceImage() increments the reference count associated with an image
2101% returning a pointer to the image.
2102%
2103% The format of the ReferenceImage method is:
2104%
2105% Image *ReferenceImage(Image *image)
2106%
2107% A description of each parameter follows:
2108%
2109% o image: the image.
2110%
2111*/
2112MagickExport Image *ReferenceImage(Image *image)
2113{
2114 assert(image != (Image *) NULL);
2115 if (image->debug != MagickFalse)
2116 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2117 assert(image->signature == MagickSignature);
cristyf84a1932010-01-03 18:00:18 +00002118 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002119 image->reference_count++;
cristyf84a1932010-01-03 18:00:18 +00002120 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002121 return(image);
2122}
2123
2124/*
2125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2126% %
2127% %
2128% %
2129% R e s e t I m a g e P a g e %
2130% %
2131% %
2132% %
2133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2134%
2135% ResetImagePage() resets the image page canvas and position.
2136%
2137% The format of the ResetImagePage method is:
2138%
2139% MagickBooleanType ResetImagePage(Image *image,const char *page)
2140%
2141% A description of each parameter follows:
2142%
2143% o image: the image.
2144%
2145% o page: the relative page specification.
2146%
2147*/
2148MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2149{
2150 MagickStatusType
2151 flags;
2152
2153 RectangleInfo
2154 geometry;
2155
2156 assert(image != (Image *) NULL);
2157 assert(image->signature == MagickSignature);
2158 if (image->debug != MagickFalse)
2159 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2160 flags=ParseAbsoluteGeometry(page,&geometry);
2161 if ((flags & WidthValue) != 0)
2162 {
2163 if ((flags & HeightValue) == 0)
2164 geometry.height=geometry.width;
2165 image->page.width=geometry.width;
2166 image->page.height=geometry.height;
2167 }
2168 if ((flags & AspectValue) != 0)
2169 {
2170 if ((flags & XValue) != 0)
2171 image->page.x+=geometry.x;
2172 if ((flags & YValue) != 0)
2173 image->page.y+=geometry.y;
2174 }
2175 else
2176 {
2177 if ((flags & XValue) != 0)
2178 {
2179 image->page.x=geometry.x;
2180 if ((image->page.width == 0) && (geometry.x > 0))
2181 image->page.width=image->columns+geometry.x;
2182 }
2183 if ((flags & YValue) != 0)
2184 {
2185 image->page.y=geometry.y;
2186 if ((image->page.height == 0) && (geometry.y > 0))
2187 image->page.height=image->rows+geometry.y;
2188 }
2189 }
2190 return(MagickTrue);
2191}
2192
2193/*
2194%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2195% %
2196% %
2197% %
2198% S e p a r a t e I m a g e C h a n n e l %
2199% %
2200% %
2201% %
2202%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2203%
cristy3139dc22011-07-08 00:11:42 +00002204% SeparateImage() separates a channel from the image and returns it as
cristy3ed852e2009-09-05 21:47:34 +00002205% a grayscale image. A channel is a particular color component of each pixel
2206% in the image.
2207%
cristy3139dc22011-07-08 00:11:42 +00002208% The format of the SeparateImage method is:
cristy3ed852e2009-09-05 21:47:34 +00002209%
cristye941a752011-10-15 01:52:48 +00002210% MagickBooleanType SeparateImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002211%
2212% A description of each parameter follows:
2213%
2214% o image: the image.
2215%
cristye941a752011-10-15 01:52:48 +00002216% o exception: return any errors or warnings in this structure.
2217%
cristy3ed852e2009-09-05 21:47:34 +00002218*/
cristye941a752011-10-15 01:52:48 +00002219MagickExport MagickBooleanType SeparateImage(Image *image,
2220 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002221{
2222#define SeparateImageTag "Separate/Image"
2223
2224 CacheView
2225 *image_view;
2226
cristy3ed852e2009-09-05 21:47:34 +00002227 MagickBooleanType
2228 status;
2229
cristybb503372010-05-27 20:51:26 +00002230 MagickOffsetType
2231 progress;
2232
2233 ssize_t
2234 y;
2235
cristy3ed852e2009-09-05 21:47:34 +00002236 assert(image != (Image *) NULL);
2237 assert(image->signature == MagickSignature);
2238 if (image->debug != MagickFalse)
2239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy574cc262011-08-05 01:23:58 +00002240 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002241 return(MagickFalse);
2242 /*
2243 Separate image channels.
2244 */
2245 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00002246 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00002247 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00002248#if defined(MAGICKCORE_OPENMP_SUPPORT)
2249 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00002250#endif
cristybb503372010-05-27 20:51:26 +00002251 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002252 {
cristy4c08aed2011-07-01 19:47:50 +00002253 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002254 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002255
cristycb6d09b2010-06-19 01:59:36 +00002256 register ssize_t
2257 x;
2258
cristy3ed852e2009-09-05 21:47:34 +00002259 if (status == MagickFalse)
2260 continue;
2261 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002262 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002263 {
2264 status=MagickFalse;
2265 continue;
2266 }
cristy3139dc22011-07-08 00:11:42 +00002267 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002268 {
cristya13d0822011-09-19 00:19:19 +00002269 register ssize_t
2270 i;
2271
2272 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2273 {
2274 PixelTrait
2275 traits;
2276
2277 register ssize_t
2278 j;
2279
2280 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2281 if (traits == UndefinedPixelTrait)
2282 continue;
2283 if ((traits & UpdatePixelTrait) != 0)
2284 for (j=0; j < (ssize_t) GetPixelChannels(image); j++)
2285 q[j]=q[i];
2286 }
cristyed231572011-07-14 02:18:59 +00002287 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00002288 }
2289 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2290 status=MagickFalse;
2291 if (image->progress_monitor != (MagickProgressMonitor) NULL)
2292 {
2293 MagickBooleanType
2294 proceed;
2295
cristyb5d5f722009-11-04 03:03:49 +00002296#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3139dc22011-07-08 00:11:42 +00002297 #pragma omp critical (MagickCore_SeparateImage)
cristy3ed852e2009-09-05 21:47:34 +00002298#endif
2299 proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows);
2300 if (proceed == MagickFalse)
2301 status=MagickFalse;
2302 }
2303 }
2304 image_view=DestroyCacheView(image_view);
cristy63240882011-08-05 19:05:27 +00002305 (void) SetImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00002306 return(status);
2307}
2308
2309/*
2310%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2311% %
2312% %
2313% %
2314% S e p a r a t e I m a g e s %
2315% %
2316% %
2317% %
2318%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2319%
2320% SeparateImages() returns a separate grayscale image for each channel
2321% specified.
2322%
2323% The format of the SeparateImages method is:
2324%
2325% MagickBooleanType SeparateImages(const Image *image,
cristy3139dc22011-07-08 00:11:42 +00002326% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002327%
2328% A description of each parameter follows:
2329%
2330% o image: the image.
2331%
cristy3ed852e2009-09-05 21:47:34 +00002332% o exception: return any errors or warnings in this structure.
2333%
2334*/
cristy3139dc22011-07-08 00:11:42 +00002335MagickExport Image *SeparateImages(const Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002336{
cristybd5a96c2011-08-21 00:04:26 +00002337 ChannelType
2338 channel_mask;
2339
cristy3ed852e2009-09-05 21:47:34 +00002340 Image
2341 *images,
2342 *separate_image;
2343
cristya13d0822011-09-19 00:19:19 +00002344 register ssize_t
2345 i;
2346
cristy3ed852e2009-09-05 21:47:34 +00002347 assert(image != (Image *) NULL);
2348 assert(image->signature == MagickSignature);
2349 if (image->debug != MagickFalse)
2350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2351 images=NewImageList();
cristya13d0822011-09-19 00:19:19 +00002352 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
2353 {
2354 PixelTrait
2355 traits;
2356
2357 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
2358 if (traits == UndefinedPixelTrait)
2359 continue;
2360 if ((traits & UpdatePixelTrait) != 0)
2361 {
2362 separate_image=CloneImage(image,0,0,MagickTrue,exception);
2363 if (separate_image != (Image *) NULL)
2364 {
2365 channel_mask=SetPixelChannelMask(separate_image,
2366 (ChannelType) (1 << i));
cristye941a752011-10-15 01:52:48 +00002367 (void) SeparateImage(separate_image,exception);
cristya13d0822011-09-19 00:19:19 +00002368 (void) SetPixelChannelMap(separate_image,channel_mask);
2369 AppendImageToList(&images,separate_image);
2370 }
2371 }
2372 }
cristy3ed852e2009-09-05 21:47:34 +00002373 return(images);
2374}
2375
2376/*
2377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2378% %
2379% %
2380% %
2381% S e t I m a g e A l p h a C h a n n e l %
2382% %
2383% %
2384% %
2385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2386%
2387% SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha
2388% channel.
2389%
2390% The format of the SetImageAlphaChannel method is:
2391%
2392% MagickBooleanType SetImageAlphaChannel(Image *image,
cristy63240882011-08-05 19:05:27 +00002393% const AlphaChannelType alpha_type,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002394%
2395% A description of each parameter follows:
2396%
2397% o image: the image.
2398%
2399% o alpha_type: The alpha channel type: ActivateAlphaChannel,
2400% CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel,
cristy4c08aed2011-07-01 19:47:50 +00002401% OpaqueAlphaChannel, SetAlphaChannel, ShapeAlphaChannel, and
2402% TransparentAlphaChannel.
cristy3ed852e2009-09-05 21:47:34 +00002403%
cristy63240882011-08-05 19:05:27 +00002404% o exception: return any errors or warnings in this structure.
2405%
cristy3ed852e2009-09-05 21:47:34 +00002406*/
2407MagickExport MagickBooleanType SetImageAlphaChannel(Image *image,
cristy63240882011-08-05 19:05:27 +00002408 const AlphaChannelType alpha_type,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002409{
cristybd5a96c2011-08-21 00:04:26 +00002410 ChannelType
2411 channel_mask;
2412
cristy3ed852e2009-09-05 21:47:34 +00002413 MagickBooleanType
2414 status;
2415
2416 assert(image != (Image *) NULL);
2417 if (image->debug != MagickFalse)
2418 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2419 assert(image->signature == MagickSignature);
cristy327d5e92011-08-07 01:16:47 +00002420 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00002421 switch (alpha_type)
2422 {
2423 case ActivateAlphaChannel:
2424 {
2425 image->matte=MagickTrue;
2426 break;
2427 }
2428 case BackgroundAlphaChannel:
2429 {
2430 CacheView
2431 *image_view;
2432
cristy4c08aed2011-07-01 19:47:50 +00002433 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00002434 background;
2435
cristyf1918832011-10-25 11:40:59 +00002436 PixelInfo
2437 pixel;
2438
cristycb6d09b2010-06-19 01:59:36 +00002439 ssize_t
2440 y;
2441
cristy3ed852e2009-09-05 21:47:34 +00002442 /*
2443 Set transparent pixels to background color.
2444 */
2445 if (image->matte == MagickFalse)
2446 break;
cristy574cc262011-08-05 01:23:58 +00002447 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002448 break;
cristyf1918832011-10-25 11:40:59 +00002449 GetPixelInfo(image,&background);
2450 SetPixelInfoPacket(image,&image->background_color,&background);
2451 SetPacketPixelInfo(image,&background,&pixel);
cristy3ed852e2009-09-05 21:47:34 +00002452 image_view=AcquireCacheView(image);
cristya13d0822011-09-19 00:19:19 +00002453#if defined(MAGICKCORE_OPENMP_SUPPORT)
2454 #pragma omp parallel for schedule(dynamic,4) shared(status)
2455#endif
cristybb503372010-05-27 20:51:26 +00002456 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002457 {
cristy4c08aed2011-07-01 19:47:50 +00002458 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002459 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002460
cristycb6d09b2010-06-19 01:59:36 +00002461 register ssize_t
2462 x;
2463
cristy3ed852e2009-09-05 21:47:34 +00002464 if (status == MagickFalse)
2465 continue;
2466 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
2467 exception);
cristyacd2ed22011-08-30 01:44:23 +00002468 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002469 {
2470 status=MagickFalse;
2471 continue;
2472 }
cristybb503372010-05-27 20:51:26 +00002473 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002474 {
cristy4c08aed2011-07-01 19:47:50 +00002475 if (GetPixelAlpha(image,q) == TransparentAlpha)
cristya13d0822011-09-19 00:19:19 +00002476 SetPixelPixelInfo(image,&background,q);
cristyed231572011-07-14 02:18:59 +00002477 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00002478 }
cristy3ed852e2009-09-05 21:47:34 +00002479 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2480 status=MagickFalse;
2481 }
2482 image_view=DestroyCacheView(image_view);
2483 return(status);
2484 }
2485 case DeactivateAlphaChannel:
2486 {
2487 image->matte=MagickFalse;
2488 break;
2489 }
2490 case ShapeAlphaChannel:
2491 case CopyAlphaChannel:
2492 {
2493 /*
cristy3139dc22011-07-08 00:11:42 +00002494 Special usage case for SeparateImage(): copy grayscale color to
cristy3ed852e2009-09-05 21:47:34 +00002495 the alpha channel.
2496 */
cristybd5a96c2011-08-21 00:04:26 +00002497 channel_mask=SetPixelChannelMask(image,GrayChannel);
cristye941a752011-10-15 01:52:48 +00002498 status=SeparateImage(image,exception);
cristybd5a96c2011-08-21 00:04:26 +00002499 (void) SetPixelChannelMask(image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00002500 image->matte=MagickTrue; /* make sure transparency is now on! */
2501 if (alpha_type == ShapeAlphaChannel)
2502 {
cristy4c08aed2011-07-01 19:47:50 +00002503 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00002504 background;
2505
2506 /*
2507 Reset all color channels to background color.
2508 */
cristyf1918832011-10-25 11:40:59 +00002509 GetPixelInfo(image,&background);
2510 SetPixelInfoPacket(image,&(image->background_color),&background);
cristy7c0a0a42011-08-23 17:57:25 +00002511 (void) LevelImageColors(image,&background,&background,MagickTrue,
2512 exception);
cristy3ed852e2009-09-05 21:47:34 +00002513 }
2514 break;
2515 }
2516 case ExtractAlphaChannel:
2517 {
cristybd5a96c2011-08-21 00:04:26 +00002518 channel_mask=SetPixelChannelMask(image,AlphaChannel);
cristye941a752011-10-15 01:52:48 +00002519 status=SeparateImage(image,exception);
cristybd5a96c2011-08-21 00:04:26 +00002520 (void) SetPixelChannelMask(image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00002521 image->matte=MagickFalse;
2522 break;
2523 }
cristy3ed852e2009-09-05 21:47:34 +00002524 case OpaqueAlphaChannel:
2525 {
cristye941a752011-10-15 01:52:48 +00002526 status=SetImageAlpha(image,OpaqueAlpha,exception);
cristy3ed852e2009-09-05 21:47:34 +00002527 image->matte=MagickTrue;
2528 break;
2529 }
2530 case TransparentAlphaChannel:
2531 {
cristye941a752011-10-15 01:52:48 +00002532 status=SetImageAlpha(image,TransparentAlpha,exception);
cristy3ed852e2009-09-05 21:47:34 +00002533 image->matte=MagickTrue;
2534 break;
2535 }
2536 case SetAlphaChannel:
2537 {
2538 if (image->matte == MagickFalse)
2539 {
cristye941a752011-10-15 01:52:48 +00002540 status=SetImageAlpha(image,OpaqueAlpha,exception);
cristy3ed852e2009-09-05 21:47:34 +00002541 image->matte=MagickTrue;
2542 }
2543 break;
2544 }
2545 case UndefinedAlphaChannel:
2546 break;
2547 }
cristy6e437132011-08-12 13:02:19 +00002548 if (status == MagickFalse)
2549 return(status);
2550 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002551}
2552
2553/*
2554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2555% %
2556% %
2557% %
2558% S e t I m a g e B a c k g r o u n d C o l o r %
2559% %
2560% %
2561% %
2562%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2563%
2564% SetImageBackgroundColor() initializes the image pixels to the image
2565% background color. The background color is defined by the background_color
2566% member of the image structure.
2567%
2568% The format of the SetImage method is:
2569%
cristyea1a8aa2011-10-20 13:24:06 +00002570% MagickBooleanType SetImageBackgroundColor(Image *image,
2571% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002572%
2573% A description of each parameter follows:
2574%
2575% o image: the image.
2576%
cristyea1a8aa2011-10-20 13:24:06 +00002577% o exception: return any errors or warnings in this structure.
2578%
cristy3ed852e2009-09-05 21:47:34 +00002579*/
cristyea1a8aa2011-10-20 13:24:06 +00002580MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2581 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002582{
2583 CacheView
2584 *image_view;
2585
cristy3ed852e2009-09-05 21:47:34 +00002586 MagickBooleanType
2587 status;
2588
cristy4c08aed2011-07-01 19:47:50 +00002589 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00002590 background;
2591
cristyf1918832011-10-25 11:40:59 +00002592 PixelInfo
2593 pixel;
2594
cristycb6d09b2010-06-19 01:59:36 +00002595 ssize_t
2596 y;
2597
cristy3ed852e2009-09-05 21:47:34 +00002598 assert(image != (Image *) NULL);
2599 if (image->debug != MagickFalse)
2600 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2601 assert(image->signature == MagickSignature);
cristy574cc262011-08-05 01:23:58 +00002602 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002603 return(MagickFalse);
cristy4c08aed2011-07-01 19:47:50 +00002604 if (image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00002605 image->matte=MagickTrue;
cristy4c08aed2011-07-01 19:47:50 +00002606 GetPixelInfo(image,&background);
cristyf1918832011-10-25 11:40:59 +00002607 SetPixelInfoPacket(image,&image->background_color,&background);
2608 SetPacketPixelInfo(image,&background,&pixel);
cristy3ed852e2009-09-05 21:47:34 +00002609 /*
2610 Set image background color.
2611 */
2612 status=MagickTrue;
cristyf1918832011-10-25 11:40:59 +00002613 pixel.black=0;
cristy3ed852e2009-09-05 21:47:34 +00002614 image_view=AcquireCacheView(image);
cristybb503372010-05-27 20:51:26 +00002615 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002616 {
cristy4c08aed2011-07-01 19:47:50 +00002617 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002618 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002619
cristycb6d09b2010-06-19 01:59:36 +00002620 register ssize_t
2621 x;
2622
cristy3ed852e2009-09-05 21:47:34 +00002623 if (status == MagickFalse)
2624 continue;
2625 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002626 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002627 {
2628 status=MagickFalse;
2629 continue;
2630 }
cristybb503372010-05-27 20:51:26 +00002631 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +00002632 {
cristya13d0822011-09-19 00:19:19 +00002633 SetPixelPixelInfo(image,&background,q);
cristyed231572011-07-14 02:18:59 +00002634 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002635 }
cristy3ed852e2009-09-05 21:47:34 +00002636 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2637 status=MagickFalse;
2638 }
2639 image_view=DestroyCacheView(image_view);
2640 return(status);
2641}
2642
2643/*
2644%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2645% %
2646% %
2647% %
cristya5b77cb2010-05-07 19:34:48 +00002648% S e t I m a g e C o l o r %
2649% %
2650% %
2651% %
2652%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2653%
2654% SetImageColor() set the entire image canvas to the specified color.
2655%
2656% The format of the SetImageColor method is:
2657%
cristye941a752011-10-15 01:52:48 +00002658% MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2659% ExeptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002660%
2661% A description of each parameter follows:
2662%
2663% o image: the image.
2664%
2665% o background: the image color.
2666%
cristye941a752011-10-15 01:52:48 +00002667% o exception: return any errors or warnings in this structure.
2668%
cristya5b77cb2010-05-07 19:34:48 +00002669*/
2670MagickExport MagickBooleanType SetImageColor(Image *image,
cristye941a752011-10-15 01:52:48 +00002671 const PixelInfo *color,ExceptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002672{
2673 CacheView
2674 *image_view;
2675
cristya5b77cb2010-05-07 19:34:48 +00002676 MagickBooleanType
2677 status;
2678
cristycb6d09b2010-06-19 01:59:36 +00002679 ssize_t
2680 y;
2681
cristya5b77cb2010-05-07 19:34:48 +00002682 assert(image != (Image *) NULL);
2683 if (image->debug != MagickFalse)
2684 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2685 assert(image->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +00002686 assert(color != (const PixelInfo *) NULL);
cristya5b77cb2010-05-07 19:34:48 +00002687 image->colorspace=color->colorspace;
2688 image->matte=color->matte;
2689 image->fuzz=color->fuzz;
2690 image->depth=color->depth;
2691 status=MagickTrue;
cristya5b77cb2010-05-07 19:34:48 +00002692 image_view=AcquireCacheView(image);
2693#if defined(MAGICKCORE_OPENMP_SUPPORT)
2694 #pragma omp parallel for schedule(dynamic,4) shared(status)
2695#endif
cristybb503372010-05-27 20:51:26 +00002696 for (y=0; y < (ssize_t) image->rows; y++)
cristya5b77cb2010-05-07 19:34:48 +00002697 {
cristy4c08aed2011-07-01 19:47:50 +00002698 register Quantum
cristya5b77cb2010-05-07 19:34:48 +00002699 *restrict q;
2700
cristycb6d09b2010-06-19 01:59:36 +00002701 register ssize_t
2702 x;
2703
cristya5b77cb2010-05-07 19:34:48 +00002704 if (status == MagickFalse)
2705 continue;
2706 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002707 if (q == (Quantum *) NULL)
cristya5b77cb2010-05-07 19:34:48 +00002708 {
2709 status=MagickFalse;
2710 continue;
2711 }
cristybb503372010-05-27 20:51:26 +00002712 for (x=0; x < (ssize_t) image->columns; x++)
cristya5b77cb2010-05-07 19:34:48 +00002713 {
cristy4c08aed2011-07-01 19:47:50 +00002714 SetPixelPixelInfo(image,color,q);
cristyed231572011-07-14 02:18:59 +00002715 q+=GetPixelChannels(image);
cristya5b77cb2010-05-07 19:34:48 +00002716 }
2717 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2718 status=MagickFalse;
2719 }
2720 image_view=DestroyCacheView(image_view);
2721 return(status);
2722}
2723
2724/*
2725%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2726% %
2727% %
2728% %
cristy3ed852e2009-09-05 21:47:34 +00002729% S e t I m a g e S t o r a g e C l a s s %
2730% %
2731% %
2732% %
2733%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2734%
2735% SetImageStorageClass() sets the image class: DirectClass for true color
2736% images or PseudoClass for colormapped images.
2737%
2738% The format of the SetImageStorageClass method is:
2739%
2740% MagickBooleanType SetImageStorageClass(Image *image,
cristy63240882011-08-05 19:05:27 +00002741% const ClassType storage_class,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002742%
2743% A description of each parameter follows:
2744%
2745% o image: the image.
2746%
2747% o storage_class: The image class.
2748%
cristy574cc262011-08-05 01:23:58 +00002749% o exception: return any errors or warnings in this structure.
2750%
cristy3ed852e2009-09-05 21:47:34 +00002751*/
2752MagickExport MagickBooleanType SetImageStorageClass(Image *image,
cristy574cc262011-08-05 01:23:58 +00002753 const ClassType storage_class,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002754{
cristy3ed852e2009-09-05 21:47:34 +00002755 image->storage_class=storage_class;
cristy6e437132011-08-12 13:02:19 +00002756 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002757}
2758
2759/*
2760%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2761% %
2762% %
2763% %
2764% S e t I m a g e C l i p M a s k %
2765% %
2766% %
2767% %
2768%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2769%
2770% SetImageClipMask() associates a clip path with the image. The clip path
2771% must be the same dimensions as the image. Set any pixel component of
cristy4c08aed2011-07-01 19:47:50 +00002772% the clip path to TransparentAlpha to prevent that corresponding image
cristy3ed852e2009-09-05 21:47:34 +00002773% pixel component from being updated when SyncAuthenticPixels() is applied.
2774%
2775% The format of the SetImageClipMask method is:
2776%
cristy018f07f2011-09-04 21:15:19 +00002777% MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask,
2778% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002779%
2780% A description of each parameter follows:
2781%
2782% o image: the image.
2783%
2784% o clip_mask: the image clip path.
2785%
cristy018f07f2011-09-04 21:15:19 +00002786% o exception: return any errors or warnings in this structure.
2787%
cristy3ed852e2009-09-05 21:47:34 +00002788*/
2789MagickExport MagickBooleanType SetImageClipMask(Image *image,
cristy018f07f2011-09-04 21:15:19 +00002790 const Image *clip_mask,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002791{
2792 assert(image != (Image *) NULL);
2793 if (image->debug != MagickFalse)
2794 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2795 assert(image->signature == MagickSignature);
2796 if (clip_mask != (const Image *) NULL)
2797 if ((clip_mask->columns != image->columns) ||
2798 (clip_mask->rows != image->rows))
2799 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
2800 if (image->clip_mask != (Image *) NULL)
2801 image->clip_mask=DestroyImage(image->clip_mask);
2802 image->clip_mask=NewImageList();
2803 if (clip_mask == (Image *) NULL)
2804 return(MagickTrue);
cristy6fccee12011-10-20 18:43:18 +00002805 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002806 return(MagickFalse);
cristy6fccee12011-10-20 18:43:18 +00002807 image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00002808 if (image->clip_mask == (Image *) NULL)
2809 return(MagickFalse);
2810 return(MagickTrue);
2811}
2812
2813/*
2814%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2815% %
2816% %
2817% %
2818% S e t I m a g e E x t e n t %
2819% %
2820% %
2821% %
2822%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2823%
2824% SetImageExtent() sets the image size (i.e. columns & rows).
2825%
2826% The format of the SetImageExtent method is:
2827%
cristy08429172011-07-14 17:18:16 +00002828% MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002829% const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002830%
2831% A description of each parameter follows:
2832%
2833% o image: the image.
2834%
2835% o columns: The image width in pixels.
2836%
2837% o rows: The image height in pixels.
2838%
cristy63240882011-08-05 19:05:27 +00002839% o exception: return any errors or warnings in this structure.
2840%
cristy3ed852e2009-09-05 21:47:34 +00002841*/
cristy08429172011-07-14 17:18:16 +00002842MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002843 const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002844{
cristy537e2722010-09-21 15:30:59 +00002845 if ((columns == 0) || (rows == 0))
2846 return(MagickFalse);
2847 image->columns=columns;
2848 image->rows=rows;
cristy6e437132011-08-12 13:02:19 +00002849 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002850}
2851
2852/*
2853%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2854% %
2855% %
2856% %
2857+ S e t I m a g e I n f o %
2858% %
2859% %
2860% %
2861%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2862%
2863% SetImageInfo() initializes the `magick' field of the ImageInfo structure.
2864% It is set to a type of image format based on the prefix or suffix of the
2865% filename. For example, `ps:image' returns PS indicating a Postscript image.
2866% JPEG is returned for this filename: `image.jpg'. The filename prefix has
2867% precendence over the suffix. Use an optional index enclosed in brackets
2868% after a file name to specify a desired scene of a multi-resolution image
2869% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2870% indicates success.
2871%
2872% The format of the SetImageInfo method is:
2873%
2874% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002875% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002876%
2877% A description of each parameter follows:
2878%
cristyd965a422010-03-03 17:47:35 +00002879% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00002880%
cristyd965a422010-03-03 17:47:35 +00002881% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00002882%
2883% o exception: return any errors or warnings in this structure.
2884%
2885*/
2886MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002887 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002888{
2889 char
2890 extension[MaxTextExtent],
2891 filename[MaxTextExtent],
2892 magic[MaxTextExtent],
2893 *q,
2894 subimage[MaxTextExtent];
2895
2896 const MagicInfo
2897 *magic_info;
2898
2899 const MagickInfo
2900 *magick_info;
2901
2902 ExceptionInfo
2903 *sans_exception;
2904
2905 Image
2906 *image;
2907
2908 MagickBooleanType
2909 status;
2910
2911 register const char
2912 *p;
2913
2914 ssize_t
2915 count;
2916
2917 unsigned char
2918 magick[2*MaxTextExtent];
2919
2920 /*
2921 Look for 'image.format' in filename.
2922 */
2923 assert(image_info != (ImageInfo *) NULL);
2924 assert(image_info->signature == MagickSignature);
2925 if (image_info->debug != MagickFalse)
2926 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2927 image_info->filename);
2928 *subimage='\0';
cristyd965a422010-03-03 17:47:35 +00002929 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00002930 {
cristyd965a422010-03-03 17:47:35 +00002931 GetPathComponent(image_info->filename,SubimagePath,subimage);
2932 if (*subimage != '\0')
cristy3ed852e2009-09-05 21:47:34 +00002933 {
cristyd965a422010-03-03 17:47:35 +00002934 /*
2935 Look for scene specification (e.g. img0001.pcd[4]).
2936 */
2937 if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse)
2938 {
2939 if (IsGeometry(subimage) != MagickFalse)
2940 (void) CloneString(&image_info->extract,subimage);
2941 }
2942 else
2943 {
cristybb503372010-05-27 20:51:26 +00002944 size_t
cristyd965a422010-03-03 17:47:35 +00002945 first,
2946 last;
cristy3ed852e2009-09-05 21:47:34 +00002947
cristyd965a422010-03-03 17:47:35 +00002948 (void) CloneString(&image_info->scenes,subimage);
2949 image_info->scene=StringToUnsignedLong(image_info->scenes);
2950 image_info->number_scenes=image_info->scene;
2951 p=image_info->scenes;
2952 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2953 {
2954 while ((isspace((int) ((unsigned char) *p)) != 0) ||
2955 (*p == ','))
2956 p++;
cristybb503372010-05-27 20:51:26 +00002957 first=(size_t) strtol(p,&q,10);
cristyd965a422010-03-03 17:47:35 +00002958 last=first;
2959 while (isspace((int) ((unsigned char) *q)) != 0)
2960 q++;
2961 if (*q == '-')
cristybb503372010-05-27 20:51:26 +00002962 last=(size_t) strtol(q+1,&q,10);
cristyd965a422010-03-03 17:47:35 +00002963 if (first > last)
2964 Swap(first,last);
2965 if (first < image_info->scene)
2966 image_info->scene=first;
2967 if (last > image_info->number_scenes)
2968 image_info->number_scenes=last;
2969 p=q;
2970 }
2971 image_info->number_scenes-=image_info->scene-1;
cristyd965a422010-03-03 17:47:35 +00002972 }
cristy3ed852e2009-09-05 21:47:34 +00002973 }
2974 }
2975 *extension='\0';
2976 GetPathComponent(image_info->filename,ExtensionPath,extension);
2977#if defined(MAGICKCORE_ZLIB_DELEGATE)
2978 if (*extension != '\0')
2979 if ((LocaleCompare(extension,"gz") == 0) ||
2980 (LocaleCompare(extension,"Z") == 0) ||
2981 (LocaleCompare(extension,"wmz") == 0))
2982 {
2983 char
2984 path[MaxTextExtent];
2985
2986 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2987 path[strlen(path)-strlen(extension)-1]='\0';
2988 GetPathComponent(path,ExtensionPath,extension);
2989 }
2990#endif
2991#if defined(MAGICKCORE_BZLIB_DELEGATE)
2992 if (*extension != '\0')
2993 if (LocaleCompare(extension,"bz2") == 0)
2994 {
2995 char
2996 path[MaxTextExtent];
2997
2998 (void) CopyMagickString(path,image_info->filename,MaxTextExtent);
2999 path[strlen(path)-strlen(extension)-1]='\0';
3000 GetPathComponent(path,ExtensionPath,extension);
3001 }
3002#endif
3003 image_info->affirm=MagickFalse;
3004 sans_exception=AcquireExceptionInfo();
3005 if (*extension != '\0')
3006 {
3007 MagickFormatType
3008 format_type;
3009
cristybb503372010-05-27 20:51:26 +00003010 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003011 i;
3012
3013 static const char
3014 *format_type_formats[] =
3015 {
3016 "AUTOTRACE",
3017 "BROWSE",
3018 "DCRAW",
3019 "EDIT",
3020 "EPHEMERAL",
3021 "LAUNCH",
3022 "MPEG:DECODE",
3023 "MPEG:ENCODE",
3024 "PRINT",
3025 "PS:ALPHA",
3026 "PS:CMYK",
3027 "PS:COLOR",
3028 "PS:GRAY",
3029 "PS:MONO",
3030 "SCAN",
3031 "SHOW",
3032 "WIN",
3033 (char *) NULL
3034 };
3035
3036 /*
3037 User specified image format.
3038 */
3039 (void) CopyMagickString(magic,extension,MaxTextExtent);
3040 LocaleUpper(magic);
3041 /*
3042 Look for explicit image formats.
3043 */
3044 format_type=UndefinedFormatType;
3045 i=0;
cristydd9a2532010-02-20 19:26:46 +00003046 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00003047 (format_type_formats[i] != (char *) NULL))
3048 {
3049 if ((*magic == *format_type_formats[i]) &&
3050 (LocaleCompare(magic,format_type_formats[i]) == 0))
3051 format_type=ExplicitFormatType;
3052 i++;
3053 }
3054 magick_info=GetMagickInfo(magic,sans_exception);
3055 if ((magick_info != (const MagickInfo *) NULL) &&
3056 (magick_info->format_type != UndefinedFormatType))
3057 format_type=magick_info->format_type;
3058 if (format_type == UndefinedFormatType)
3059 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3060 else
3061 if (format_type == ExplicitFormatType)
3062 {
3063 image_info->affirm=MagickTrue;
3064 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3065 }
3066 if (LocaleCompare(magic,"RGB") == 0)
3067 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
3068 }
3069 /*
3070 Look for explicit 'format:image' in filename.
3071 */
3072 *magic='\0';
3073 GetPathComponent(image_info->filename,MagickPath,magic);
3074 if (*magic == '\0')
3075 (void) CopyMagickString(magic,image_info->magick,MaxTextExtent);
3076 else
3077 {
3078 /*
3079 User specified image format.
3080 */
3081 LocaleUpper(magic);
3082 if (IsMagickConflict(magic) == MagickFalse)
3083 {
3084 (void) CopyMagickString(image_info->magick,magic,MaxTextExtent);
3085 if (LocaleCompare(magic,"EPHEMERAL") != 0)
3086 image_info->affirm=MagickTrue;
3087 else
3088 image_info->temporary=MagickTrue;
3089 }
3090 }
3091 magick_info=GetMagickInfo(magic,sans_exception);
3092 sans_exception=DestroyExceptionInfo(sans_exception);
3093 if ((magick_info == (const MagickInfo *) NULL) ||
3094 (GetMagickEndianSupport(magick_info) == MagickFalse))
3095 image_info->endian=UndefinedEndian;
3096 GetPathComponent(image_info->filename,CanonicalPath,filename);
3097 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
cristyd965a422010-03-03 17:47:35 +00003098 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00003099 {
3100 /*
cristyd965a422010-03-03 17:47:35 +00003101 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00003102 */
cristyd965a422010-03-03 17:47:35 +00003103 (void) InterpretImageFilename(image_info,(Image *) NULL,
cristy6fccee12011-10-20 18:43:18 +00003104 image_info->filename,(int) image_info->scene,filename,exception);
cristyd965a422010-03-03 17:47:35 +00003105 if ((LocaleCompare(filename,image_info->filename) != 0) &&
3106 (strchr(filename,'%') == (char *) NULL))
3107 image_info->adjoin=MagickFalse;
3108 }
3109 if ((image_info->adjoin != MagickFalse) && (frames > 0))
3110 {
3111 /*
3112 Some image formats do not support multiple frames per file.
3113 */
cristy3ed852e2009-09-05 21:47:34 +00003114 magick_info=GetMagickInfo(magic,exception);
3115 if (magick_info != (const MagickInfo *) NULL)
3116 if (GetMagickAdjoin(magick_info) == MagickFalse)
3117 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003118 }
3119 if (image_info->affirm != MagickFalse)
3120 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00003121 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00003122 {
3123 /*
cristyd965a422010-03-03 17:47:35 +00003124 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00003125 */
cristy9950d572011-10-01 18:22:35 +00003126 image=AcquireImage(image_info,exception);
cristyd965a422010-03-03 17:47:35 +00003127 (void) CopyMagickString(image->filename,image_info->filename,
3128 MaxTextExtent);
cristy3ed852e2009-09-05 21:47:34 +00003129 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3130 if (status == MagickFalse)
3131 {
3132 image=DestroyImage(image);
3133 return(MagickFalse);
3134 }
cristyd965a422010-03-03 17:47:35 +00003135 if ((IsBlobSeekable(image) == MagickFalse) ||
3136 (IsBlobExempt(image) != MagickFalse))
3137 {
3138 /*
3139 Copy standard input or pipe to temporary file.
3140 */
3141 *filename='\0';
3142 status=ImageToFile(image,filename,exception);
3143 (void) CloseBlob(image);
3144 if (status == MagickFalse)
3145 {
3146 image=DestroyImage(image);
3147 return(MagickFalse);
3148 }
3149 SetImageInfoFile(image_info,(FILE *) NULL);
3150 (void) CopyMagickString(image->filename,filename,MaxTextExtent);
3151 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
3152 if (status == MagickFalse)
3153 {
3154 image=DestroyImage(image);
3155 return(MagickFalse);
3156 }
3157 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3158 image_info->temporary=MagickTrue;
3159 }
3160 (void) ResetMagickMemory(magick,0,sizeof(magick));
3161 count=ReadBlob(image,2*MaxTextExtent,magick);
3162 (void) CloseBlob(image);
3163 image=DestroyImage(image);
3164 /*
3165 Check magic.xml configuration file.
3166 */
3167 sans_exception=AcquireExceptionInfo();
3168 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
3169 if ((magic_info != (const MagicInfo *) NULL) &&
3170 (GetMagicName(magic_info) != (char *) NULL))
3171 {
3172 (void) CopyMagickString(image_info->magick,GetMagicName(magic_info),
3173 MaxTextExtent);
3174 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3175 if ((magick_info == (const MagickInfo *) NULL) ||
3176 (GetMagickEndianSupport(magick_info) == MagickFalse))
3177 image_info->endian=UndefinedEndian;
3178 sans_exception=DestroyExceptionInfo(sans_exception);
3179 return(MagickTrue);
3180 }
cristy3ed852e2009-09-05 21:47:34 +00003181 magick_info=GetMagickInfo(image_info->magick,sans_exception);
3182 if ((magick_info == (const MagickInfo *) NULL) ||
3183 (GetMagickEndianSupport(magick_info) == MagickFalse))
3184 image_info->endian=UndefinedEndian;
3185 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00003186 }
cristy3ed852e2009-09-05 21:47:34 +00003187 return(MagickTrue);
3188}
3189
3190/*
3191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3192% %
3193% %
3194% %
3195% S e t I m a g e I n f o B l o b %
3196% %
3197% %
3198% %
3199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3200%
3201% SetImageInfoBlob() sets the image info blob member.
3202%
3203% The format of the SetImageInfoBlob method is:
3204%
3205% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3206% const size_t length)
3207%
3208% A description of each parameter follows:
3209%
3210% o image_info: the image info.
3211%
3212% o blob: the blob.
3213%
3214% o length: the blob length.
3215%
3216*/
3217MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
3218 const size_t length)
3219{
3220 assert(image_info != (ImageInfo *) NULL);
3221 assert(image_info->signature == MagickSignature);
3222 if (image_info->debug != MagickFalse)
3223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3224 image_info->filename);
3225 image_info->blob=(void *) blob;
3226 image_info->length=length;
3227}
3228
3229/*
3230%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3231% %
3232% %
3233% %
3234% S e t I m a g e I n f o F i l e %
3235% %
3236% %
3237% %
3238%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3239%
3240% SetImageInfoFile() sets the image info file member.
3241%
3242% The format of the SetImageInfoFile method is:
3243%
3244% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3245%
3246% A description of each parameter follows:
3247%
3248% o image_info: the image info.
3249%
3250% o file: the file.
3251%
3252*/
3253MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
3254{
3255 assert(image_info != (ImageInfo *) NULL);
3256 assert(image_info->signature == MagickSignature);
3257 if (image_info->debug != MagickFalse)
3258 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
3259 image_info->filename);
3260 image_info->file=file;
3261}
3262
3263/*
3264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3265% %
3266% %
3267% %
3268% S e t I m a g e M a s k %
3269% %
3270% %
3271% %
3272%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3273%
3274% SetImageMask() associates a mask with the image. The mask must be the same
3275% dimensions as the image.
3276%
3277% The format of the SetImageMask method is:
3278%
cristy018f07f2011-09-04 21:15:19 +00003279% MagickBooleanType SetImageMask(Image *image,const Image *mask,
3280% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003281%
3282% A description of each parameter follows:
3283%
3284% o image: the image.
3285%
3286% o mask: the image mask.
3287%
cristy018f07f2011-09-04 21:15:19 +00003288% o exception: return any errors or warnings in this structure.
3289%
cristy3ed852e2009-09-05 21:47:34 +00003290*/
3291MagickExport MagickBooleanType SetImageMask(Image *image,
cristy018f07f2011-09-04 21:15:19 +00003292 const Image *mask,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003293{
3294 assert(image != (Image *) NULL);
3295 if (image->debug != MagickFalse)
3296 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3297 assert(image->signature == MagickSignature);
3298 if (mask != (const Image *) NULL)
3299 if ((mask->columns != image->columns) || (mask->rows != image->rows))
3300 ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename);
3301 if (image->mask != (Image *) NULL)
3302 image->mask=DestroyImage(image->mask);
3303 image->mask=NewImageList();
3304 if (mask == (Image *) NULL)
3305 return(MagickTrue);
cristy6fccee12011-10-20 18:43:18 +00003306 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003307 return(MagickFalse);
cristy6fccee12011-10-20 18:43:18 +00003308 image->mask=CloneImage(mask,0,0,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00003309 if (image->mask == (Image *) NULL)
3310 return(MagickFalse);
3311 return(MagickTrue);
3312}
3313
3314/*
3315%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3316% %
3317% %
3318% %
cristyb6a294d2011-10-03 00:55:17 +00003319% S e t I m a g e A l p h a %
cristy3ed852e2009-09-05 21:47:34 +00003320% %
3321% %
3322% %
3323%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3324%
cristye941a752011-10-15 01:52:48 +00003325% SetImageAlpha() sets the alpha levels of the image.
cristy3ed852e2009-09-05 21:47:34 +00003326%
cristyb6a294d2011-10-03 00:55:17 +00003327% The format of the SetImageAlpha method is:
cristy3ed852e2009-09-05 21:47:34 +00003328%
cristye941a752011-10-15 01:52:48 +00003329% MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3330% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003331%
3332% A description of each parameter follows:
3333%
3334% o image: the image.
3335%
cristyb6a294d2011-10-03 00:55:17 +00003336% o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
cristy3ed852e2009-09-05 21:47:34 +00003337% fully transparent.
3338%
3339*/
cristye941a752011-10-15 01:52:48 +00003340MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3341 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003342{
3343 CacheView
3344 *image_view;
3345
cristy3ed852e2009-09-05 21:47:34 +00003346 MagickBooleanType
3347 status;
3348
cristycb6d09b2010-06-19 01:59:36 +00003349 ssize_t
3350 y;
3351
cristy3ed852e2009-09-05 21:47:34 +00003352 assert(image != (Image *) NULL);
3353 if (image->debug != MagickFalse)
3354 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3355 assert(image->signature == MagickSignature);
cristyb6a294d2011-10-03 00:55:17 +00003356 image->matte=alpha != OpaqueAlpha ? MagickTrue : MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003357 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00003358 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00003359#if defined(MAGICKCORE_OPENMP_SUPPORT)
3360 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003361#endif
cristybb503372010-05-27 20:51:26 +00003362 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003363 {
cristy4c08aed2011-07-01 19:47:50 +00003364 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003365 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003366
cristycb6d09b2010-06-19 01:59:36 +00003367 register ssize_t
3368 x;
3369
cristy3ed852e2009-09-05 21:47:34 +00003370 if (status == MagickFalse)
3371 continue;
3372 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00003373 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003374 {
3375 status=MagickFalse;
3376 continue;
3377 }
cristybb503372010-05-27 20:51:26 +00003378 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003379 {
cristyb6a294d2011-10-03 00:55:17 +00003380 SetPixelAlpha(image,alpha,q);
cristyed231572011-07-14 02:18:59 +00003381 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00003382 }
3383 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3384 status=MagickFalse;
3385 }
3386 image_view=DestroyCacheView(image_view);
3387 return(status);
3388}
3389
3390/*
3391%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3392% %
3393% %
3394% %
3395% S e t I m a g e T y p e %
3396% %
3397% %
3398% %
3399%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3400%
3401% SetImageType() sets the type of image. Choose from these types:
3402%
3403% Bilevel Grayscale GrayscaleMatte
3404% Palette PaletteMatte TrueColor
3405% TrueColorMatte ColorSeparation ColorSeparationMatte
3406% OptimizeType
3407%
3408% The format of the SetImageType method is:
3409%
cristy018f07f2011-09-04 21:15:19 +00003410% MagickBooleanType SetImageType(Image *image,const ImageType type,
3411% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003412%
3413% A description of each parameter follows:
3414%
3415% o image: the image.
3416%
3417% o type: Image type.
3418%
cristy018f07f2011-09-04 21:15:19 +00003419% o exception: return any errors or warnings in this structure.
3420%
cristy3ed852e2009-09-05 21:47:34 +00003421*/
cristy018f07f2011-09-04 21:15:19 +00003422MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type,
3423 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003424{
3425 const char
3426 *artifact;
3427
3428 ImageInfo
3429 *image_info;
3430
3431 MagickBooleanType
3432 status;
3433
3434 QuantizeInfo
3435 *quantize_info;
3436
3437 assert(image != (Image *) NULL);
3438 if (image->debug != MagickFalse)
3439 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3440 assert(image->signature == MagickSignature);
3441 status=MagickTrue;
3442 image_info=AcquireImageInfo();
3443 image_info->dither=image->dither;
3444 artifact=GetImageArtifact(image,"dither");
3445 if (artifact != (const char *) NULL)
3446 (void) SetImageOption(image_info,"dither",artifact);
3447 switch (type)
3448 {
3449 case BilevelType:
3450 {
cristy6fccee12011-10-20 18:43:18 +00003451 if (IsImageGray(image,exception) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003452 status=TransformImageColorspace(image,GRAYColorspace,exception);
cristy6fccee12011-10-20 18:43:18 +00003453 if (IsImageMonochrome(image,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003454 {
3455 quantize_info=AcquireQuantizeInfo(image_info);
3456 quantize_info->number_colors=2;
3457 quantize_info->colorspace=GRAYColorspace;
cristy018f07f2011-09-04 21:15:19 +00003458 status=QuantizeImage(quantize_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003459 quantize_info=DestroyQuantizeInfo(quantize_info);
3460 }
3461 image->matte=MagickFalse;
3462 break;
3463 }
3464 case GrayscaleType:
3465 {
cristy6fccee12011-10-20 18:43:18 +00003466 if (IsImageGray(image,exception) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003467 status=TransformImageColorspace(image,GRAYColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003468 image->matte=MagickFalse;
3469 break;
3470 }
3471 case GrayscaleMatteType:
3472 {
cristy6fccee12011-10-20 18:43:18 +00003473 if (IsImageGray(image,exception) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003474 status=TransformImageColorspace(image,GRAYColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003475 if (image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00003476 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00003477 break;
3478 }
3479 case PaletteType:
3480 {
cristy510d06a2011-07-06 23:43:54 +00003481 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003482 status=TransformImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003483 if ((image->storage_class == DirectClass) || (image->colors > 256))
3484 {
3485 quantize_info=AcquireQuantizeInfo(image_info);
3486 quantize_info->number_colors=256;
cristy018f07f2011-09-04 21:15:19 +00003487 status=QuantizeImage(quantize_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003488 quantize_info=DestroyQuantizeInfo(quantize_info);
3489 }
3490 image->matte=MagickFalse;
3491 break;
3492 }
3493 case PaletteBilevelMatteType:
3494 {
cristybd5a96c2011-08-21 00:04:26 +00003495 ChannelType
3496 channel_mask;
3497
cristy510d06a2011-07-06 23:43:54 +00003498 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003499 status=TransformImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003500 if (image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00003501 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristybd5a96c2011-08-21 00:04:26 +00003502 channel_mask=SetPixelChannelMask(image,AlphaChannel);
cristye941a752011-10-15 01:52:48 +00003503 (void) BilevelImage(image,(double) QuantumRange/2.0,exception);
cristybd5a96c2011-08-21 00:04:26 +00003504 (void) SetPixelChannelMask(image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00003505 quantize_info=AcquireQuantizeInfo(image_info);
cristy018f07f2011-09-04 21:15:19 +00003506 status=QuantizeImage(quantize_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003507 quantize_info=DestroyQuantizeInfo(quantize_info);
3508 break;
3509 }
3510 case PaletteMatteType:
3511 {
cristy510d06a2011-07-06 23:43:54 +00003512 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003513 status=TransformImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003514 if (image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00003515 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00003516 quantize_info=AcquireQuantizeInfo(image_info);
3517 quantize_info->colorspace=TransparentColorspace;
cristy018f07f2011-09-04 21:15:19 +00003518 status=QuantizeImage(quantize_info,image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003519 quantize_info=DestroyQuantizeInfo(quantize_info);
3520 break;
3521 }
3522 case TrueColorType:
3523 {
cristy510d06a2011-07-06 23:43:54 +00003524 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003525 status=TransformImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003526 if (image->storage_class != DirectClass)
cristy6fccee12011-10-20 18:43:18 +00003527 status=SetImageStorageClass(image,DirectClass,exception);
cristy3ed852e2009-09-05 21:47:34 +00003528 image->matte=MagickFalse;
3529 break;
3530 }
3531 case TrueColorMatteType:
3532 {
cristy510d06a2011-07-06 23:43:54 +00003533 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003534 status=TransformImageColorspace(image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003535 if (image->storage_class != DirectClass)
cristy6fccee12011-10-20 18:43:18 +00003536 status=SetImageStorageClass(image,DirectClass,exception);
cristy3ed852e2009-09-05 21:47:34 +00003537 if (image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00003538 (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00003539 break;
3540 }
3541 case ColorSeparationType:
3542 {
3543 if (image->colorspace != CMYKColorspace)
3544 {
cristy510d06a2011-07-06 23:43:54 +00003545 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003546 status=TransformImageColorspace(image,RGBColorspace,exception);
3547 status=TransformImageColorspace(image,CMYKColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003548 }
3549 if (image->storage_class != DirectClass)
cristy6fccee12011-10-20 18:43:18 +00003550 status=SetImageStorageClass(image,DirectClass,exception);
cristy3ed852e2009-09-05 21:47:34 +00003551 image->matte=MagickFalse;
3552 break;
3553 }
3554 case ColorSeparationMatteType:
3555 {
3556 if (image->colorspace != CMYKColorspace)
3557 {
cristy510d06a2011-07-06 23:43:54 +00003558 if (IsRGBColorspace(image->colorspace) == MagickFalse)
cristye941a752011-10-15 01:52:48 +00003559 status=TransformImageColorspace(image,RGBColorspace,exception);
3560 status=TransformImageColorspace(image,CMYKColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00003561 }
3562 if (image->storage_class != DirectClass)
cristy6fccee12011-10-20 18:43:18 +00003563 status=SetImageStorageClass(image,DirectClass,exception);
cristy3ed852e2009-09-05 21:47:34 +00003564 if (image->matte == MagickFalse)
cristy327d5e92011-08-07 01:16:47 +00003565 status=SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00003566 break;
3567 }
3568 case OptimizeType:
cristy5f1c1ff2010-12-23 21:38:06 +00003569 case UndefinedType:
cristy3ed852e2009-09-05 21:47:34 +00003570 break;
3571 }
3572 image->type=type;
3573 image_info=DestroyImageInfo(image_info);
3574 return(status);
3575}
3576
3577/*
3578%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3579% %
3580% %
3581% %
3582% 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 %
3583% %
3584% %
3585% %
3586%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3587%
3588% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3589% image and returns the previous setting. A virtual pixel is any pixel access
3590% that is outside the boundaries of the image cache.
3591%
3592% The format of the SetImageVirtualPixelMethod() method is:
3593%
3594% VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3595% const VirtualPixelMethod virtual_pixel_method)
3596%
3597% A description of each parameter follows:
3598%
3599% o image: the image.
3600%
3601% o virtual_pixel_method: choose the type of virtual pixel.
3602%
3603*/
3604MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image,
3605 const VirtualPixelMethod virtual_pixel_method)
3606{
3607 assert(image != (const Image *) NULL);
3608 assert(image->signature == MagickSignature);
3609 if (image->debug != MagickFalse)
3610 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3611 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method));
3612}
3613
3614/*
3615%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3616% %
3617% %
3618% %
cristy4285d782011-02-09 20:12:28 +00003619% S m u s h I m a g e s %
3620% %
3621% %
3622% %
3623%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3624%
3625% SmushImages() takes all images from the current image pointer to the end
3626% of the image list and smushes them to each other top-to-bottom if the
3627% stack parameter is true, otherwise left-to-right.
3628%
3629% The current gravity setting now effects how the image is justified in the
3630% final image.
3631%
3632% The format of the SmushImages method is:
3633%
cristy4ca38e22011-02-10 02:57:49 +00003634% Image *SmushImages(const Image *images,const MagickBooleanType stack,
cristy4285d782011-02-09 20:12:28 +00003635% ExceptionInfo *exception)
3636%
3637% A description of each parameter follows:
3638%
cristy4ca38e22011-02-10 02:57:49 +00003639% o images: the image sequence.
cristy4285d782011-02-09 20:12:28 +00003640%
3641% o stack: A value other than 0 stacks the images top-to-bottom.
3642%
3643% o offset: minimum distance in pixels between images.
3644%
3645% o exception: return any errors or warnings in this structure.
3646%
3647*/
cristy4ca38e22011-02-10 02:57:49 +00003648
cristy7c6dc152011-02-11 14:10:55 +00003649static ssize_t SmushXGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003650 const ssize_t offset,ExceptionInfo *exception)
cristy4ca38e22011-02-10 02:57:49 +00003651{
cristy4d727152011-02-10 19:57:21 +00003652 CacheView
3653 *left_view,
3654 *right_view;
3655
3656 const Image
3657 *left_image,
3658 *right_image;
3659
cristy4d727152011-02-10 19:57:21 +00003660 RectangleInfo
3661 left_geometry,
3662 right_geometry;
3663
cristy4c08aed2011-07-01 19:47:50 +00003664 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003665 *p;
3666
cristy4d727152011-02-10 19:57:21 +00003667 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003668 i,
cristy4d727152011-02-10 19:57:21 +00003669 y;
3670
cristy7c6dc152011-02-11 14:10:55 +00003671 size_t
3672 gap;
3673
cristy4d727152011-02-10 19:57:21 +00003674 ssize_t
cristy4d727152011-02-10 19:57:21 +00003675 x;
3676
3677 if (images->previous == (Image *) NULL)
3678 return(0);
3679 right_image=images;
3680 SetGeometry(smush_image,&right_geometry);
3681 GravityAdjustGeometry(right_image->columns,right_image->rows,
3682 right_image->gravity,&right_geometry);
3683 left_image=images->previous;
3684 SetGeometry(smush_image,&left_geometry);
3685 GravityAdjustGeometry(left_image->columns,left_image->rows,
3686 left_image->gravity,&left_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003687 gap=right_image->columns;
cristy4d727152011-02-10 19:57:21 +00003688 left_view=AcquireCacheView(left_image);
3689 right_view=AcquireCacheView(right_image);
3690 for (y=0; y < (ssize_t) smush_image->rows; y++)
3691 {
3692 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3693 {
cristydab7e912011-02-11 18:19:24 +00003694 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003695 if ((p == (const Quantum *) NULL) ||
3696 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
cristy7c6dc152011-02-11 14:10:55 +00003697 ((left_image->columns-x-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003698 break;
3699 }
cristy4ef6f062011-02-10 20:30:22 +00003700 i=(ssize_t) left_image->columns-x-1;
cristy4d727152011-02-10 19:57:21 +00003701 for (x=0; x < (ssize_t) right_image->columns; x++)
3702 {
cristydab7e912011-02-11 18:19:24 +00003703 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
cristy279d8212011-02-10 20:05:02 +00003704 exception);
cristy4c08aed2011-07-01 19:47:50 +00003705 if ((p == (const Quantum *) NULL) ||
3706 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3707 ((x+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003708 break;
3709 }
cristy7c6dc152011-02-11 14:10:55 +00003710 if ((x+i) < (ssize_t) gap)
3711 gap=(size_t) (x+i);
cristy4d727152011-02-10 19:57:21 +00003712 }
3713 right_view=DestroyCacheView(right_view);
3714 left_view=DestroyCacheView(left_view);
cristydab7e912011-02-11 18:19:24 +00003715 if (y < (ssize_t) smush_image->rows)
3716 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003717 return((ssize_t) gap-offset);
cristyad5e6ee2011-02-10 14:26:00 +00003718}
3719
cristy7c6dc152011-02-11 14:10:55 +00003720static ssize_t SmushYGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003721 const ssize_t offset,ExceptionInfo *exception)
cristyad5e6ee2011-02-10 14:26:00 +00003722{
cristy4d727152011-02-10 19:57:21 +00003723 CacheView
3724 *bottom_view,
3725 *top_view;
3726
3727 const Image
3728 *bottom_image,
3729 *top_image;
3730
cristy4d727152011-02-10 19:57:21 +00003731 RectangleInfo
3732 bottom_geometry,
3733 top_geometry;
3734
cristy4c08aed2011-07-01 19:47:50 +00003735 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003736 *p;
3737
cristy4d727152011-02-10 19:57:21 +00003738 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003739 i,
cristy4d727152011-02-10 19:57:21 +00003740 x;
3741
cristy7c6dc152011-02-11 14:10:55 +00003742 size_t
3743 gap;
3744
cristy4d727152011-02-10 19:57:21 +00003745 ssize_t
cristy4d727152011-02-10 19:57:21 +00003746 y;
3747
3748 if (images->previous == (Image *) NULL)
3749 return(0);
3750 bottom_image=images;
3751 SetGeometry(smush_image,&bottom_geometry);
3752 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3753 bottom_image->gravity,&bottom_geometry);
3754 top_image=images->previous;
3755 SetGeometry(smush_image,&top_geometry);
3756 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3757 &top_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003758 gap=bottom_image->rows;
cristy4d727152011-02-10 19:57:21 +00003759 top_view=AcquireCacheView(top_image);
3760 bottom_view=AcquireCacheView(bottom_image);
3761 for (x=0; x < (ssize_t) smush_image->columns; x++)
3762 {
3763 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3764 {
cristydab7e912011-02-11 18:19:24 +00003765 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003766 if ((p == (const Quantum *) NULL) ||
3767 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3768 ((top_image->rows-y-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003769 break;
3770 }
cristy4ef6f062011-02-10 20:30:22 +00003771 i=(ssize_t) top_image->rows-y-1;
cristy4d727152011-02-10 19:57:21 +00003772 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3773 {
cristydab7e912011-02-11 18:19:24 +00003774 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3775 exception);
cristy4c08aed2011-07-01 19:47:50 +00003776 if ((p == (const Quantum *) NULL) ||
3777 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3778 ((y+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003779 break;
3780 }
cristy7c6dc152011-02-11 14:10:55 +00003781 if ((y+i) < (ssize_t) gap)
3782 gap=(size_t) (y+i);
cristy4d727152011-02-10 19:57:21 +00003783 }
3784 bottom_view=DestroyCacheView(bottom_view);
3785 top_view=DestroyCacheView(top_view);
cristydab7e912011-02-11 18:19:24 +00003786 if (x < (ssize_t) smush_image->columns)
3787 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003788 return((ssize_t) gap-offset);
cristy4ca38e22011-02-10 02:57:49 +00003789}
3790
3791MagickExport Image *SmushImages(const Image *images,
cristy4285d782011-02-09 20:12:28 +00003792 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3793{
3794#define SmushImageTag "Smush/Image"
3795
3796 CacheView
cristybb5dced2011-02-10 02:17:16 +00003797 *smush_view;
cristy4285d782011-02-09 20:12:28 +00003798
cristy4ca38e22011-02-10 02:57:49 +00003799 const Image
3800 *image;
3801
cristy4285d782011-02-09 20:12:28 +00003802 Image
3803 *smush_image;
3804
3805 MagickBooleanType
3806 matte,
3807 proceed,
3808 status;
3809
3810 MagickOffsetType
3811 n;
3812
3813 RectangleInfo
3814 geometry;
3815
3816 register const Image
3817 *next;
3818
3819 size_t
3820 height,
3821 number_images,
3822 width;
3823
3824 ssize_t
3825 x_offset,
cristy4285d782011-02-09 20:12:28 +00003826 y_offset;
3827
3828 /*
cristy7c6dc152011-02-11 14:10:55 +00003829 Compute maximum area of smushed area.
cristy4285d782011-02-09 20:12:28 +00003830 */
cristy4ca38e22011-02-10 02:57:49 +00003831 assert(images != (Image *) NULL);
3832 assert(images->signature == MagickSignature);
3833 if (images->debug != MagickFalse)
3834 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy4285d782011-02-09 20:12:28 +00003835 assert(exception != (ExceptionInfo *) NULL);
3836 assert(exception->signature == MagickSignature);
cristy4ca38e22011-02-10 02:57:49 +00003837 image=images;
cristy4285d782011-02-09 20:12:28 +00003838 matte=image->matte;
3839 number_images=1;
3840 width=image->columns;
3841 height=image->rows;
3842 next=GetNextImageInList(image);
3843 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3844 {
3845 if (next->matte != MagickFalse)
3846 matte=MagickTrue;
3847 number_images++;
3848 if (stack != MagickFalse)
3849 {
3850 if (next->columns > width)
3851 width=next->columns;
3852 height+=next->rows;
cristy4ef6f062011-02-10 20:30:22 +00003853 if (next->previous != (Image *) NULL)
3854 height+=offset;
cristy4285d782011-02-09 20:12:28 +00003855 continue;
3856 }
3857 width+=next->columns;
cristy4ef6f062011-02-10 20:30:22 +00003858 if (next->previous != (Image *) NULL)
3859 width+=offset;
cristy4285d782011-02-09 20:12:28 +00003860 if (next->rows > height)
3861 height=next->rows;
3862 }
3863 /*
cristy7c6dc152011-02-11 14:10:55 +00003864 Smush images.
cristy4285d782011-02-09 20:12:28 +00003865 */
3866 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3867 if (smush_image == (Image *) NULL)
3868 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003869 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
cristy4285d782011-02-09 20:12:28 +00003870 {
cristy4285d782011-02-09 20:12:28 +00003871 smush_image=DestroyImage(smush_image);
3872 return((Image *) NULL);
3873 }
3874 smush_image->matte=matte;
cristyea1a8aa2011-10-20 13:24:06 +00003875 (void) SetImageBackgroundColor(smush_image,exception);
cristy4285d782011-02-09 20:12:28 +00003876 status=MagickTrue;
3877 x_offset=0;
3878 y_offset=0;
3879 smush_view=AcquireCacheView(smush_image);
3880 for (n=0; n < (MagickOffsetType) number_images; n++)
3881 {
3882 SetGeometry(smush_image,&geometry);
3883 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3884 if (stack != MagickFalse)
cristy4ca38e22011-02-10 02:57:49 +00003885 {
3886 x_offset-=geometry.x;
cristy7c6dc152011-02-11 14:10:55 +00003887 y_offset-=SmushYGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003888 }
cristy4285d782011-02-09 20:12:28 +00003889 else
cristy4ca38e22011-02-10 02:57:49 +00003890 {
cristy7c6dc152011-02-11 14:10:55 +00003891 x_offset-=SmushXGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003892 y_offset-=geometry.y;
cristy4ca38e22011-02-10 02:57:49 +00003893 }
cristye941a752011-10-15 01:52:48 +00003894 status=CompositeImage(smush_image,OverCompositeOp,image,x_offset,y_offset,
3895 exception);
cristy4285d782011-02-09 20:12:28 +00003896 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3897 if (proceed == MagickFalse)
3898 break;
3899 if (stack == MagickFalse)
3900 {
3901 x_offset+=(ssize_t) image->columns;
3902 y_offset=0;
3903 }
3904 else
3905 {
3906 x_offset=0;
3907 y_offset+=(ssize_t) image->rows;
3908 }
3909 image=GetNextImageInList(image);
3910 }
cristy4ef6f062011-02-10 20:30:22 +00003911 if (stack == MagickFalse)
3912 smush_image->columns=(size_t) x_offset;
cristy4d727152011-02-10 19:57:21 +00003913 else
cristy4ef6f062011-02-10 20:30:22 +00003914 smush_image->rows=(size_t) y_offset;
3915 smush_view=DestroyCacheView(smush_view);
cristy4285d782011-02-09 20:12:28 +00003916 if (status == MagickFalse)
3917 smush_image=DestroyImage(smush_image);
3918 return(smush_image);
3919}
3920
3921/*
3922%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3923% %
3924% %
3925% %
cristy3ed852e2009-09-05 21:47:34 +00003926% S t r i p I m a g e %
3927% %
3928% %
3929% %
3930%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3931%
cristy376bda92009-12-22 21:15:23 +00003932% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00003933%
3934% The format of the StripImage method is:
3935%
cristye941a752011-10-15 01:52:48 +00003936% MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003937%
3938% A description of each parameter follows:
3939%
3940% o image: the image.
3941%
cristye941a752011-10-15 01:52:48 +00003942% o exception: return any errors or warnings in this structure.
3943%
cristy3ed852e2009-09-05 21:47:34 +00003944*/
cristye941a752011-10-15 01:52:48 +00003945MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003946{
cristye941a752011-10-15 01:52:48 +00003947 MagickBooleanType
3948 status;
3949
cristy3ed852e2009-09-05 21:47:34 +00003950 assert(image != (Image *) NULL);
3951 if (image->debug != MagickFalse)
3952 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye941a752011-10-15 01:52:48 +00003953 (void) exception;
cristy3ed852e2009-09-05 21:47:34 +00003954 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00003955 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00003956 (void) DeleteImageProperty(image,"date:create");
3957 (void) DeleteImageProperty(image,"date:modify");
cristye941a752011-10-15 01:52:48 +00003958 status=SetImageArtifact(image,"png:include-chunk","none,trns,gama");
3959 return(status);
cristy3ed852e2009-09-05 21:47:34 +00003960}
3961
3962/*
3963%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3964% %
3965% %
3966% %
3967+ S y n c I m a g e %
3968% %
3969% %
3970% %
3971%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3972%
3973% SyncImage() initializes the red, green, and blue intensities of each pixel
3974% as defined by the colormap index.
3975%
3976% The format of the SyncImage method is:
3977%
cristyea1a8aa2011-10-20 13:24:06 +00003978% MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003979%
3980% A description of each parameter follows:
3981%
3982% o image: the image.
3983%
cristyea1a8aa2011-10-20 13:24:06 +00003984% o exception: return any errors or warnings in this structure.
3985%
cristy3ed852e2009-09-05 21:47:34 +00003986*/
3987
cristy4c08aed2011-07-01 19:47:50 +00003988static inline Quantum PushColormapIndex(Image *image,
cristybb503372010-05-27 20:51:26 +00003989 const size_t index,MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00003990{
3991 if (index < image->colors)
cristy4c08aed2011-07-01 19:47:50 +00003992 return((Quantum) index);
cristy3ed852e2009-09-05 21:47:34 +00003993 *range_exception=MagickTrue;
cristy4c08aed2011-07-01 19:47:50 +00003994 return((Quantum) 0);
cristy3ed852e2009-09-05 21:47:34 +00003995}
3996
cristyea1a8aa2011-10-20 13:24:06 +00003997MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003998{
3999 CacheView
4000 *image_view;
4001
cristy3ed852e2009-09-05 21:47:34 +00004002 MagickBooleanType
4003 range_exception,
4004 status;
4005
cristycb6d09b2010-06-19 01:59:36 +00004006 ssize_t
4007 y;
4008
cristy3ed852e2009-09-05 21:47:34 +00004009 assert(image != (Image *) NULL);
4010 if (image->debug != MagickFalse)
4011 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
4012 assert(image->signature == MagickSignature);
4013 if (image->storage_class == DirectClass)
4014 return(MagickFalse);
4015 range_exception=MagickFalse;
4016 status=MagickTrue;
cristy3ed852e2009-09-05 21:47:34 +00004017 image_view=AcquireCacheView(image);
cristy48974b92009-12-19 02:36:06 +00004018#if defined(MAGICKCORE_OPENMP_SUPPORT)
4019 #pragma omp parallel for schedule(dynamic,4) shared(status)
4020#endif
cristybb503372010-05-27 20:51:26 +00004021 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004022 {
cristy4c08aed2011-07-01 19:47:50 +00004023 Quantum
cristy3ed852e2009-09-05 21:47:34 +00004024 index;
4025
cristy4c08aed2011-07-01 19:47:50 +00004026 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004027 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004028
cristycb6d09b2010-06-19 01:59:36 +00004029 register ssize_t
4030 x;
4031
cristy48974b92009-12-19 02:36:06 +00004032 if (status == MagickFalse)
4033 continue;
cristy3ed852e2009-09-05 21:47:34 +00004034 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004035 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004036 {
4037 status=MagickFalse;
4038 continue;
4039 }
cristybb503372010-05-27 20:51:26 +00004040 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004041 {
cristy4c08aed2011-07-01 19:47:50 +00004042 index=PushColormapIndex(image,(size_t) GetPixelIndex(image,q),
cristyc8d25bc2011-04-29 02:19:30 +00004043 &range_exception);
cristy101ab702011-10-13 13:06:32 +00004044 SetPixelPixelInfo(image,image->colormap+(ssize_t) index,q);
cristyed231572011-07-14 02:18:59 +00004045 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004046 }
4047 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4048 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004049 }
4050 image_view=DestroyCacheView(image_view);
4051 if (range_exception != MagickFalse)
cristy6fccee12011-10-20 18:43:18 +00004052 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
4053 "InvalidColormapIndex","`%s'",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00004054 return(status);
4055}
cristy1626d332009-11-10 16:58:17 +00004056
4057/*
4058%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4059% %
4060% %
4061% %
4062% S y n c I m a g e S e t t i n g s %
4063% %
4064% %
4065% %
4066%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4067%
4068% SyncImageSettings() sync the image info options to the image.
4069%
4070% The format of the SyncImageSettings method is:
4071%
4072% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00004073% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00004074% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00004075% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00004076%
4077% A description of each parameter follows:
4078%
4079% o image_info: the image info.
4080%
4081% o image: the image.
4082%
cristy6fccee12011-10-20 18:43:18 +00004083% o exception: return any errors or warnings in this structure.
4084%
cristy1626d332009-11-10 16:58:17 +00004085*/
4086
4087MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00004088 Image *images,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00004089{
4090 Image
4091 *image;
4092
4093 assert(image_info != (const ImageInfo *) NULL);
4094 assert(image_info->signature == MagickSignature);
4095 assert(images != (Image *) NULL);
4096 assert(images->signature == MagickSignature);
4097 if (images->debug != MagickFalse)
4098 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
4099 image=images;
4100 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
cristy6fccee12011-10-20 18:43:18 +00004101 (void) SyncImageSettings(image_info,image,exception);
cristy1626d332009-11-10 16:58:17 +00004102 (void) DeleteImageOption(image_info,"page");
4103 return(MagickTrue);
4104}
4105
4106MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00004107 Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00004108{
4109 char
4110 property[MaxTextExtent];
4111
4112 const char
cristy9a703812010-07-26 14:50:29 +00004113 *option,
4114 *value;
cristy1626d332009-11-10 16:58:17 +00004115
4116 GeometryInfo
4117 geometry_info;
4118
4119 MagickStatusType
4120 flags;
4121
cristy19eb6412010-04-23 14:42:29 +00004122 ResolutionType
4123 units;
4124
cristy1626d332009-11-10 16:58:17 +00004125 /*
4126 Sync image options.
4127 */
4128 assert(image_info != (const ImageInfo *) NULL);
4129 assert(image_info->signature == MagickSignature);
4130 assert(image != (Image *) NULL);
4131 assert(image->signature == MagickSignature);
4132 if (image->debug != MagickFalse)
4133 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4134 option=GetImageOption(image_info,"background");
4135 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00004136 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
cristy6fccee12011-10-20 18:43:18 +00004137 exception);
cristy1626d332009-11-10 16:58:17 +00004138 option=GetImageOption(image_info,"bias");
4139 if (option != (const char *) NULL)
cristyf2f27272009-12-17 14:48:46 +00004140 image->bias=SiPrefixToDouble(option,QuantumRange);
cristy1626d332009-11-10 16:58:17 +00004141 option=GetImageOption(image_info,"black-point-compensation");
4142 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004143 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004144 MagickBooleanOptions,MagickFalse,option);
4145 option=GetImageOption(image_info,"blue-primary");
4146 if (option != (const char *) NULL)
4147 {
4148 flags=ParseGeometry(option,&geometry_info);
4149 image->chromaticity.blue_primary.x=geometry_info.rho;
4150 image->chromaticity.blue_primary.y=geometry_info.sigma;
4151 if ((flags & SigmaValue) == 0)
4152 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
4153 }
4154 option=GetImageOption(image_info,"bordercolor");
4155 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00004156 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
cristy6fccee12011-10-20 18:43:18 +00004157 exception);
cristy1626d332009-11-10 16:58:17 +00004158 option=GetImageOption(image_info,"compose");
4159 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004160 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
cristy1626d332009-11-10 16:58:17 +00004161 MagickFalse,option);
4162 option=GetImageOption(image_info,"compress");
4163 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004164 image->compression=(CompressionType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004165 MagickCompressOptions,MagickFalse,option);
4166 option=GetImageOption(image_info,"debug");
4167 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004168 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00004169 MagickFalse,option);
cristydd5f5912010-07-31 23:37:23 +00004170 option=GetImageOption(image_info,"density");
4171 if (option != (const char *) NULL)
4172 {
4173 GeometryInfo
4174 geometry_info;
4175
cristydd5f5912010-07-31 23:37:23 +00004176 flags=ParseGeometry(option,&geometry_info);
4177 image->x_resolution=geometry_info.rho;
4178 image->y_resolution=geometry_info.sigma;
4179 if ((flags & SigmaValue) == 0)
4180 image->y_resolution=image->x_resolution;
4181 }
cristy1626d332009-11-10 16:58:17 +00004182 option=GetImageOption(image_info,"depth");
4183 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004184 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004185 option=GetImageOption(image_info,"endian");
4186 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004187 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
cristy1626d332009-11-10 16:58:17 +00004188 MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00004189 option=GetImageOption(image_info,"filter");
4190 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004191 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
cristy1626d332009-11-10 16:58:17 +00004192 MagickFalse,option);
4193 option=GetImageOption(image_info,"fuzz");
4194 if (option != (const char *) NULL)
cristybe469dc2011-10-15 15:32:24 +00004195 image->fuzz=SiPrefixToDouble(option,(double) QuantumRange+1.0);
cristy1626d332009-11-10 16:58:17 +00004196 option=GetImageOption(image_info,"gravity");
4197 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004198 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
cristy1626d332009-11-10 16:58:17 +00004199 MagickFalse,option);
4200 option=GetImageOption(image_info,"green-primary");
4201 if (option != (const char *) NULL)
4202 {
4203 flags=ParseGeometry(option,&geometry_info);
4204 image->chromaticity.green_primary.x=geometry_info.rho;
4205 image->chromaticity.green_primary.y=geometry_info.sigma;
4206 if ((flags & SigmaValue) == 0)
4207 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
4208 }
4209 option=GetImageOption(image_info,"intent");
4210 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004211 image->rendering_intent=(RenderingIntent) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004212 MagickIntentOptions,MagickFalse,option);
4213 option=GetImageOption(image_info,"interlace");
4214 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004215 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
cristy1626d332009-11-10 16:58:17 +00004216 MagickFalse,option);
4217 option=GetImageOption(image_info,"interpolate");
4218 if (option != (const char *) NULL)
cristy5c4e2582011-09-11 19:21:03 +00004219 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004220 MagickInterpolateOptions,MagickFalse,option);
4221 option=GetImageOption(image_info,"loop");
4222 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004223 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004224 option=GetImageOption(image_info,"mattecolor");
4225 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00004226 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
cristy6fccee12011-10-20 18:43:18 +00004227 exception);
cristy1626d332009-11-10 16:58:17 +00004228 option=GetImageOption(image_info,"orient");
4229 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004230 image->orientation=(OrientationType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00004231 MagickOrientationOptions,MagickFalse,option);
cristy9a703812010-07-26 14:50:29 +00004232 option=GetImageOption(image_info,"page");
4233 if (option != (const char *) NULL)
4234 {
4235 char
4236 *geometry;
4237
4238 geometry=GetPageGeometry(option);
4239 flags=ParseAbsoluteGeometry(geometry,&image->page);
4240 geometry=DestroyString(geometry);
4241 }
cristy1626d332009-11-10 16:58:17 +00004242 option=GetImageOption(image_info,"quality");
4243 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004244 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004245 option=GetImageOption(image_info,"red-primary");
4246 if (option != (const char *) NULL)
4247 {
4248 flags=ParseGeometry(option,&geometry_info);
4249 image->chromaticity.red_primary.x=geometry_info.rho;
4250 image->chromaticity.red_primary.y=geometry_info.sigma;
4251 if ((flags & SigmaValue) == 0)
4252 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
4253 }
4254 if (image_info->quality != UndefinedCompressionQuality)
4255 image->quality=image_info->quality;
4256 option=GetImageOption(image_info,"scene");
4257 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00004258 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00004259 option=GetImageOption(image_info,"taint");
4260 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004261 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00004262 MagickFalse,option);
4263 option=GetImageOption(image_info,"tile-offset");
4264 if (option != (const char *) NULL)
4265 {
4266 char
4267 *geometry;
4268
4269 geometry=GetPageGeometry(option);
4270 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
4271 geometry=DestroyString(geometry);
4272 }
4273 option=GetImageOption(image_info,"transparent-color");
4274 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00004275 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
cristy6fccee12011-10-20 18:43:18 +00004276 exception);
cristy1626d332009-11-10 16:58:17 +00004277 option=GetImageOption(image_info,"type");
4278 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004279 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
cristy1626d332009-11-10 16:58:17 +00004280 option);
4281 option=GetImageOption(image_info,"units");
4282 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00004283 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00004284 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00004285 else
4286 units = image_info->units;
4287 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00004288 {
cristy19eb6412010-04-23 14:42:29 +00004289 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00004290 switch (image->units)
4291 {
4292 case PixelsPerInchResolution:
4293 {
cristy19eb6412010-04-23 14:42:29 +00004294 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00004295 {
4296 image->x_resolution/=2.54;
4297 image->y_resolution/=2.54;
4298 }
4299 break;
4300 }
4301 case PixelsPerCentimeterResolution:
4302 {
cristy19eb6412010-04-23 14:42:29 +00004303 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00004304 {
cristybb503372010-05-27 20:51:26 +00004305 image->x_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004306 image->x_resolution+0.5))/100.0;
cristybb503372010-05-27 20:51:26 +00004307 image->y_resolution=(double) ((size_t) (100.0*2.54*
cristy1f9ce9f2010-04-28 11:55:12 +00004308 image->y_resolution+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00004309 }
4310 break;
4311 }
4312 default:
4313 break;
4314 }
cristy19eb6412010-04-23 14:42:29 +00004315 image->units=units;
cristy1626d332009-11-10 16:58:17 +00004316 }
4317 option=GetImageOption(image_info,"white-point");
4318 if (option != (const char *) NULL)
4319 {
4320 flags=ParseGeometry(option,&geometry_info);
4321 image->chromaticity.white_point.x=geometry_info.rho;
4322 image->chromaticity.white_point.y=geometry_info.sigma;
4323 if ((flags & SigmaValue) == 0)
4324 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
4325 }
4326 ResetImageOptionIterator(image_info);
4327 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
4328 {
4329 value=GetImageOption(image_info,option);
4330 if (value != (const char *) NULL)
4331 {
cristyb51dff52011-05-19 16:55:47 +00004332 (void) FormatLocaleString(property,MaxTextExtent,"%s",option);
cristydf81b992011-02-27 14:33:24 +00004333 (void) SetImageArtifact(image,property,value);
cristy1626d332009-11-10 16:58:17 +00004334 }
4335 option=GetNextImageOption(image_info);
4336 }
4337 return(MagickTrue);
4338}