blob: ebd487eff149ffaf776a9bb6ac1f2682601eb1de [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 %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
cristyb56bb242014-11-25 17:12:48 +000020% Copyright 1999-2015 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"
cristyac245f82012-05-05 17:13:57 +000086#include "MagickCore/resource_.h"
cristy4c08aed2011-07-01 19:47:50 +000087#include "MagickCore/segment.h"
88#include "MagickCore/semaphore.h"
89#include "MagickCore/signature-private.h"
90#include "MagickCore/statistic.h"
91#include "MagickCore/string_.h"
92#include "MagickCore/string-private.h"
93#include "MagickCore/thread-private.h"
94#include "MagickCore/threshold.h"
95#include "MagickCore/timer.h"
cristy63a81872012-03-22 15:52:52 +000096#include "MagickCore/token.h"
cristy4c08aed2011-07-01 19:47:50 +000097#include "MagickCore/utility.h"
cristyd1dd6e42011-09-04 01:46:08 +000098#include "MagickCore/utility-private.h"
cristy4c08aed2011-07-01 19:47:50 +000099#include "MagickCore/version.h"
100#include "MagickCore/xwindow-private.h"
cristy3ed852e2009-09-05 21:47:34 +0000101
102/*
103 Constant declaration.
104*/
cristy94b11832011-09-08 19:46:03 +0000105const char
cristy7138c592009-09-08 13:58:52 +0000106 BackgroundColor[] = "#ffffff", /* white */
107 BorderColor[] = "#dfdfdf", /* gray */
cristy9639ba32011-09-05 15:09:42 +0000108 DefaultTileFrame[] = "15x15+3+3",
cristy7138c592009-09-08 13:58:52 +0000109 DefaultTileGeometry[] = "120x120+4+3>",
110 DefaultTileLabel[] = "%f\n%G\n%b",
cristy94b11832011-09-08 19:46:03 +0000111 ForegroundColor[] = "#000", /* black */
cristy7138c592009-09-08 13:58:52 +0000112 LoadImageTag[] = "Load/Image",
113 LoadImagesTag[] = "Load/Images",
cristy94b11832011-09-08 19:46:03 +0000114 MatteColor[] = "#bdbdbd", /* gray */
cristy7138c592009-09-08 13:58:52 +0000115 PSDensityGeometry[] = "72.0x72.0",
116 PSPageGeometry[] = "612x792",
117 SaveImageTag[] = "Save/Image",
118 SaveImagesTag[] = "Save/Images",
119 TransparentColor[] = "#00000000"; /* transparent black */
cristy3ed852e2009-09-05 21:47:34 +0000120
cristy94b11832011-09-08 19:46:03 +0000121const double
cristy3ed852e2009-09-05 21:47:34 +0000122 DefaultResolution = 72.0;
123
124/*
125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126% %
127% %
128% %
129% A c q u i r e I m a g e %
130% %
131% %
132% %
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134%
135% AcquireImage() returns a pointer to an image structure initialized to
136% default values.
137%
138% The format of the AcquireImage method is:
139%
cristy9950d572011-10-01 18:22:35 +0000140% Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000141%
142% A description of each parameter follows:
143%
144% o image_info: Many of the image default values are set from this
145% structure. For example, filename, compression, depth, background color,
146% and others.
147%
cristy9950d572011-10-01 18:22:35 +0000148% o exception: return any errors or warnings in this structure.
149%
cristy3ed852e2009-09-05 21:47:34 +0000150*/
cristy9950d572011-10-01 18:22:35 +0000151MagickExport Image *AcquireImage(const ImageInfo *image_info,
152 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000153{
cristye412c892010-07-26 12:31:36 +0000154 const char
cristyf3a660a2010-07-26 14:17:52 +0000155 *option;
cristye412c892010-07-26 12:31:36 +0000156
cristy3ed852e2009-09-05 21:47:34 +0000157 Image
158 *image;
159
160 MagickStatusType
161 flags;
162
163 /*
164 Allocate image structure.
165 */
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy73bd4a52010-10-05 11:24:23 +0000167 image=(Image *) AcquireMagickMemory(sizeof(*image));
cristy3ed852e2009-09-05 21:47:34 +0000168 if (image == (Image *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(image,0,sizeof(*image));
171 /*
172 Initialize Image structure.
173 */
cristy151b66d2015-04-15 10:50:31 +0000174 (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000175 image->storage_class=DirectClass;
176 image->depth=MAGICKCORE_QUANTUM_DEPTH;
cristy8d951092012-02-08 18:54:56 +0000177 image->colorspace=sRGBColorspace;
cristye540eb42012-04-16 12:50:34 +0000178 image->rendering_intent=PerceptualIntent;
cristy6b221892012-05-03 01:21:35 +0000179 image->gamma=1.000f/2.200f;
180 image->chromaticity.red_primary.x=0.6400f;
181 image->chromaticity.red_primary.y=0.3300f;
cristyf767ec92012-05-03 01:27:21 +0000182 image->chromaticity.red_primary.z=0.0300f;
cristy6b221892012-05-03 01:21:35 +0000183 image->chromaticity.green_primary.x=0.3000f;
184 image->chromaticity.green_primary.y=0.6000f;
cristyf767ec92012-05-03 01:27:21 +0000185 image->chromaticity.green_primary.z=0.1000f;
cristy6b221892012-05-03 01:21:35 +0000186 image->chromaticity.blue_primary.x=0.1500f;
187 image->chromaticity.blue_primary.y=0.0600f;
cristyf767ec92012-05-03 01:27:21 +0000188 image->chromaticity.blue_primary.z=0.7900f;
cristy6b221892012-05-03 01:21:35 +0000189 image->chromaticity.white_point.x=0.3127f;
190 image->chromaticity.white_point.y=0.3290f;
cristyf767ec92012-05-03 01:27:21 +0000191 image->chromaticity.white_point.z=0.3583f;
cristy3ed852e2009-09-05 21:47:34 +0000192 image->interlace=NoInterlace;
193 image->ticks_per_second=UndefinedTicksPerSecond;
194 image->compose=OverCompositeOp;
cristy9950d572011-10-01 18:22:35 +0000195 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
196 &image->background_color,exception);
197 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
198 exception);
199 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
200 exception);
201 (void) QueryColorCompliance(TransparentColor,AllCompliance,
202 &image->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +0000203 GetTimerInfo(&image->timer);
204 image->cache=AcquirePixelCache(0);
cristybd5a96c2011-08-21 00:04:26 +0000205 image->channel_mask=DefaultChannels;
cristyed231572011-07-14 02:18:59 +0000206 image->channel_map=AcquirePixelChannelMap();
cristy3ed852e2009-09-05 21:47:34 +0000207 image->blob=CloneBlobInfo((BlobInfo *) NULL);
cristybd686c62013-02-03 19:01:05 +0000208 image->timestamp=time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000209 image->debug=IsEventLogging();
210 image->reference_count=1;
cristy3d162a92014-02-16 14:05:06 +0000211 image->semaphore=AcquireSemaphoreInfo();
cristy3ed852e2009-09-05 21:47:34 +0000212 image->signature=MagickSignature;
213 if (image_info == (ImageInfo *) NULL)
214 return(image);
215 /*
216 Transfer image info.
217 */
218 SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue :
219 MagickFalse);
cristy151b66d2015-04-15 10:50:31 +0000220 (void) CopyMagickString(image->filename,image_info->filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000221 (void) CopyMagickString(image->magick_filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +0000222 MagickPathExtent);
223 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000224 if (image_info->size != (char *) NULL)
225 {
226 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
227 image->columns=image->extract_info.width;
228 image->rows=image->extract_info.height;
229 image->offset=image->extract_info.x;
230 image->extract_info.x=0;
231 image->extract_info.y=0;
232 }
233 if (image_info->extract != (char *) NULL)
234 {
235 RectangleInfo
236 geometry;
237
238 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
239 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
240 {
241 image->extract_info=geometry;
242 Swap(image->columns,image->extract_info.width);
243 Swap(image->rows,image->extract_info.height);
244 }
245 }
246 image->compression=image_info->compression;
247 image->quality=image_info->quality;
248 image->endian=image_info->endian;
249 image->interlace=image_info->interlace;
250 image->units=image_info->units;
251 if (image_info->density != (char *) NULL)
252 {
253 GeometryInfo
254 geometry_info;
255
256 flags=ParseGeometry(image_info->density,&geometry_info);
cristy2a11bef2011-10-28 18:33:11 +0000257 image->resolution.x=geometry_info.rho;
258 image->resolution.y=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +0000259 if ((flags & SigmaValue) == 0)
cristy2a11bef2011-10-28 18:33:11 +0000260 image->resolution.y=image->resolution.x;
cristy3ed852e2009-09-05 21:47:34 +0000261 }
262 if (image_info->page != (char *) NULL)
263 {
264 char
265 *geometry;
266
267 image->page=image->extract_info;
268 geometry=GetPageGeometry(image_info->page);
269 (void) ParseAbsoluteGeometry(geometry,&image->page);
270 geometry=DestroyString(geometry);
271 }
272 if (image_info->depth != 0)
273 image->depth=image_info->depth;
274 image->dither=image_info->dither;
275 image->background_color=image_info->background_color;
276 image->border_color=image_info->border_color;
277 image->matte_color=image_info->matte_color;
278 image->transparent_color=image_info->transparent_color;
cristy73724512010-04-12 14:43:14 +0000279 image->ping=image_info->ping;
cristy3ed852e2009-09-05 21:47:34 +0000280 image->progress_monitor=image_info->progress_monitor;
281 image->client_data=image_info->client_data;
282 if (image_info->cache != (void *) NULL)
283 ClonePixelCacheMethods(image->cache,image_info->cache);
cristy1a780952013-02-10 17:15:30 +0000284 /*
285 Set all global options that map to per-image settings.
286 */
cristy6fccee12011-10-20 18:43:18 +0000287 (void) SyncImageSettings(image_info,image,exception);
cristy1a780952013-02-10 17:15:30 +0000288 /*
289 Global options that are only set for new images.
290 */
291 image->image_info=(ImageInfo *) NULL;
cristye412c892010-07-26 12:31:36 +0000292 option=GetImageOption(image_info,"delay");
293 if (option != (const char *) NULL)
294 {
295 GeometryInfo
296 geometry_info;
297
298 flags=ParseGeometry(option,&geometry_info);
299 if ((flags & GreaterValue) != 0)
300 {
301 if (image->delay > (size_t) floor(geometry_info.rho+0.5))
302 image->delay=(size_t) floor(geometry_info.rho+0.5);
303 }
304 else
305 if ((flags & LessValue) != 0)
306 {
307 if (image->delay < (size_t) floor(geometry_info.rho+0.5))
308 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
309 }
310 else
311 image->delay=(size_t) floor(geometry_info.rho+0.5);
312 if ((flags & SigmaValue) != 0)
313 image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5);
314 }
315 option=GetImageOption(image_info,"dispose");
316 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +0000317 image->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions,
cristye412c892010-07-26 12:31:36 +0000318 MagickFalse,option);
cristy3ed852e2009-09-05 21:47:34 +0000319 return(image);
320}
321
322/*
323%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324% %
325% %
326% %
cristy3ed852e2009-09-05 21:47:34 +0000327% A c q u i r e I m a g e I n f o %
328% %
329% %
330% %
331%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332%
333% AcquireImageInfo() allocates the ImageInfo structure.
334%
335% The format of the AcquireImageInfo method is:
336%
337% ImageInfo *AcquireImageInfo(void)
338%
339*/
340MagickExport ImageInfo *AcquireImageInfo(void)
341{
342 ImageInfo
343 *image_info;
344
cristy73bd4a52010-10-05 11:24:23 +0000345 image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info));
cristy3ed852e2009-09-05 21:47:34 +0000346 if (image_info == (ImageInfo *) NULL)
347 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
348 GetImageInfo(image_info);
349 return(image_info);
350}
351
352/*
353%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354% %
355% %
356% %
357% A c q u i r e N e x t I m a g e %
358% %
359% %
360% %
361%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
362%
363% AcquireNextImage() initializes the next image in a sequence to
364% default values. The next member of image points to the newly allocated
365% image. If there is a memory shortage, next is assigned NULL.
366%
367% The format of the AcquireNextImage method is:
368%
cristy9950d572011-10-01 18:22:35 +0000369% void AcquireNextImage(const ImageInfo *image_info,Image *image,
370% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000371%
372% A description of each parameter follows:
373%
374% o image_info: Many of the image default values are set from this
375% structure. For example, filename, compression, depth, background color,
376% and others.
377%
378% o image: the image.
379%
cristy9950d572011-10-01 18:22:35 +0000380% o exception: return any errors or warnings in this structure.
381%
cristy3ed852e2009-09-05 21:47:34 +0000382*/
cristy9950d572011-10-01 18:22:35 +0000383MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image,
384 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000385{
386 /*
387 Allocate image structure.
388 */
389 assert(image != (Image *) NULL);
390 assert(image->signature == MagickSignature);
391 if (image->debug != MagickFalse)
392 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy9950d572011-10-01 18:22:35 +0000393 image->next=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +0000394 if (GetNextImageInList(image) == (Image *) NULL)
395 return;
396 (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename,
cristy151b66d2015-04-15 10:50:31 +0000397 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000398 if (image_info != (ImageInfo *) NULL)
399 (void) CopyMagickString(GetNextImageInList(image)->filename,
cristy151b66d2015-04-15 10:50:31 +0000400 image_info->filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000401 DestroyBlob(GetNextImageInList(image));
402 image->next->blob=ReferenceBlob(image->blob);
403 image->next->endian=image->endian;
404 image->next->scene=image->scene+1;
405 image->next->previous=image;
406}
407
408/*
409%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410% %
411% %
412% %
413% A p p e n d I m a g e s %
414% %
415% %
416% %
417%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418%
419% AppendImages() takes all images from the current image pointer to the end
420% of the image list and appends them to each other top-to-bottom if the
421% stack parameter is true, otherwise left-to-right.
422%
anthony7bcfe7f2012-03-30 14:01:22 +0000423% The current gravity setting effects how the image is justified in the
cristy3ed852e2009-09-05 21:47:34 +0000424% final image.
425%
426% The format of the AppendImages method is:
427%
cristy4ca38e22011-02-10 02:57:49 +0000428% Image *AppendImages(const Image *images,const MagickBooleanType stack,
cristy3ed852e2009-09-05 21:47:34 +0000429% ExceptionInfo *exception)
430%
431% A description of each parameter follows:
432%
cristy4ca38e22011-02-10 02:57:49 +0000433% o images: the image sequence.
cristy3ed852e2009-09-05 21:47:34 +0000434%
435% o stack: A value other than 0 stacks the images top-to-bottom.
436%
437% o exception: return any errors or warnings in this structure.
438%
439*/
cristy4ca38e22011-02-10 02:57:49 +0000440MagickExport Image *AppendImages(const Image *images,
cristy3ed852e2009-09-05 21:47:34 +0000441 const MagickBooleanType stack,ExceptionInfo *exception)
442{
443#define AppendImageTag "Append/Image"
444
445 CacheView
cristyeeebdde2012-04-14 16:29:34 +0000446 *append_view;
cristy4ca38e22011-02-10 02:57:49 +0000447
cristy3ed852e2009-09-05 21:47:34 +0000448 Image
449 *append_image;
450
cristy3ed852e2009-09-05 21:47:34 +0000451 MagickBooleanType
cristy3ed852e2009-09-05 21:47:34 +0000452 status;
453
cristybb503372010-05-27 20:51:26 +0000454 MagickOffsetType
455 n;
456
cristy5a5e4d92012-08-29 00:06:25 +0000457 PixelTrait
458 alpha_trait;
459
cristy3ed852e2009-09-05 21:47:34 +0000460 RectangleInfo
461 geometry;
462
463 register const Image
464 *next;
465
cristybb503372010-05-27 20:51:26 +0000466 size_t
cristy3ed852e2009-09-05 21:47:34 +0000467 height,
468 number_images,
469 width;
470
cristybb503372010-05-27 20:51:26 +0000471 ssize_t
472 x_offset,
473 y,
474 y_offset;
475
cristy3ed852e2009-09-05 21:47:34 +0000476 /*
cristy7c6dc152011-02-11 14:10:55 +0000477 Compute maximum area of appended area.
cristy3ed852e2009-09-05 21:47:34 +0000478 */
cristy4ca38e22011-02-10 02:57:49 +0000479 assert(images != (Image *) NULL);
480 assert(images->signature == MagickSignature);
481 if (images->debug != MagickFalse)
482 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy3ed852e2009-09-05 21:47:34 +0000483 assert(exception != (ExceptionInfo *) NULL);
484 assert(exception->signature == MagickSignature);
cristy5a5e4d92012-08-29 00:06:25 +0000485 alpha_trait=images->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +0000486 number_images=1;
cristyeeebdde2012-04-14 16:29:34 +0000487 width=images->columns;
488 height=images->rows;
489 next=GetNextImageInList(images);
cristy3ed852e2009-09-05 21:47:34 +0000490 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
491 {
cristy17f11b02014-12-20 19:37:04 +0000492 if (next->alpha_trait != UndefinedPixelTrait)
cristy5a5e4d92012-08-29 00:06:25 +0000493 alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +0000494 number_images++;
495 if (stack != MagickFalse)
496 {
497 if (next->columns > width)
498 width=next->columns;
499 height+=next->rows;
500 continue;
501 }
502 width+=next->columns;
503 if (next->rows > height)
504 height=next->rows;
505 }
506 /*
cristy7c6dc152011-02-11 14:10:55 +0000507 Append images.
cristy3ed852e2009-09-05 21:47:34 +0000508 */
cristyeeebdde2012-04-14 16:29:34 +0000509 append_image=CloneImage(images,width,height,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000510 if (append_image == (Image *) NULL)
511 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000512 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000513 {
cristy3ed852e2009-09-05 21:47:34 +0000514 append_image=DestroyImage(append_image);
515 return((Image *) NULL);
516 }
cristy5a5e4d92012-08-29 00:06:25 +0000517 append_image->alpha_trait=alpha_trait;
cristyea1a8aa2011-10-20 13:24:06 +0000518 (void) SetImageBackgroundColor(append_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000519 status=MagickTrue;
520 x_offset=0;
521 y_offset=0;
cristyeeebdde2012-04-14 16:29:34 +0000522 next=images;
cristy46ff2672012-12-14 15:32:26 +0000523 append_view=AcquireAuthenticCacheView(append_image,exception);
cristybb503372010-05-27 20:51:26 +0000524 for (n=0; n < (MagickOffsetType) number_images; n++)
cristy3ed852e2009-09-05 21:47:34 +0000525 {
cristyeeebdde2012-04-14 16:29:34 +0000526 CacheView
527 *image_view;
528
529 Image
530 *image;
531
cristy9eed59f2013-02-19 15:26:48 +0000532 MagickBooleanType
533 proceed;
534
cristyeeebdde2012-04-14 16:29:34 +0000535 image=CloneImage(next,0,0,MagickTrue,exception);
536 if (image == (Image *) NULL)
537 break;
538 (void) TransformImageColorspace(image,append_image->colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000539 SetGeometry(append_image,&geometry);
540 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
541 if (stack != MagickFalse)
542 x_offset-=geometry.x;
543 else
544 y_offset-=geometry.y;
cristy46ff2672012-12-14 15:32:26 +0000545 image_view=AcquireVirtualCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +0000546#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy9a5a52f2012-10-09 14:40:31 +0000547 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +0000548 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000549#endif
cristybb503372010-05-27 20:51:26 +0000550 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000551 {
552 MagickBooleanType
553 sync;
554
cristye14e3202012-04-11 18:48:17 +0000555 PixelInfo
556 pixel;
557
cristy4c08aed2011-07-01 19:47:50 +0000558 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000559 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000560
cristy4c08aed2011-07-01 19:47:50 +0000561 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000562 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000563
cristycb6d09b2010-06-19 01:59:36 +0000564 register ssize_t
565 x;
566
cristy3ed852e2009-09-05 21:47:34 +0000567 if (status == MagickFalse)
568 continue;
569 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
570 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
571 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000572 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000573 {
574 status=MagickFalse;
575 continue;
576 }
cristye14e3202012-04-11 18:48:17 +0000577 GetPixelInfo(image,&pixel);
cristybb503372010-05-27 20:51:26 +0000578 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000579 {
cristy883fde12013-04-08 00:50:13 +0000580 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +0000581 {
cristyc3a58022013-10-09 23:22:42 +0000582 SetPixelBackgoundColor(append_image,q);
cristy10a6c612012-01-29 21:41:05 +0000583 p+=GetPixelChannels(image);
584 q+=GetPixelChannels(append_image);
585 continue;
586 }
cristye14e3202012-04-11 18:48:17 +0000587 GetPixelInfoPixel(image,p,&pixel);
cristy11a06d32015-01-04 12:03:27 +0000588 SetPixelViaPixelInfo(append_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +0000589 p+=GetPixelChannels(image);
590 q+=GetPixelChannels(append_image);
cristy3ed852e2009-09-05 21:47:34 +0000591 }
592 sync=SyncCacheViewAuthenticPixels(append_view,exception);
593 if (sync == MagickFalse)
cristya65f35b2010-04-20 01:10:41 +0000594 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000595 }
596 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +0000597 if (stack == MagickFalse)
598 {
cristyeaedf062010-05-29 22:36:02 +0000599 x_offset+=(ssize_t) image->columns;
cristy3ed852e2009-09-05 21:47:34 +0000600 y_offset=0;
601 }
602 else
603 {
604 x_offset=0;
cristyeaedf062010-05-29 22:36:02 +0000605 y_offset+=(ssize_t) image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000606 }
cristyeeebdde2012-04-14 16:29:34 +0000607 image=DestroyImage(image);
608 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
609 if (proceed == MagickFalse)
610 break;
611 next=GetNextImageInList(next);
cristy3ed852e2009-09-05 21:47:34 +0000612 }
613 append_view=DestroyCacheView(append_view);
614 if (status == MagickFalse)
615 append_image=DestroyImage(append_image);
616 return(append_image);
617}
618
619/*
620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621% %
622% %
623% %
cristy3ed852e2009-09-05 21:47:34 +0000624% C a t c h I m a g e E x c e p t i o n %
625% %
626% %
627% %
628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629%
630% CatchImageException() returns if no exceptions are found in the image
631% sequence, otherwise it determines the most severe exception and reports
632% it as a warning or error depending on the severity.
633%
634% The format of the CatchImageException method is:
635%
636% ExceptionType CatchImageException(Image *image)
637%
638% A description of each parameter follows:
639%
640% o image: An image sequence.
641%
642*/
643MagickExport ExceptionType CatchImageException(Image *image)
644{
645 ExceptionInfo
646 *exception;
647
648 ExceptionType
649 severity;
650
651 assert(image != (const Image *) NULL);
652 assert(image->signature == MagickSignature);
653 if (image->debug != MagickFalse)
654 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
655 exception=AcquireExceptionInfo();
cristy3ed852e2009-09-05 21:47:34 +0000656 CatchException(exception);
657 severity=exception->severity;
658 exception=DestroyExceptionInfo(exception);
659 return(severity);
660}
661
662/*
663%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664% %
665% %
666% %
667% C l i p I m a g e P a t h %
668% %
669% %
670% %
671%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672%
673% ClipImagePath() sets the image clip mask based any clipping path information
674% if it exists.
675%
676% The format of the ClipImagePath method is:
677%
678% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000679% const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000680%
681% A description of each parameter follows:
682%
683% o image: the image.
684%
685% o pathname: name of clipping path resource. If name is preceded by #, use
686% clipping path numbered by name.
687%
688% o inside: if non-zero, later operations take effect inside clipping path.
689% Otherwise later operations take effect outside clipping path.
690%
cristy018f07f2011-09-04 21:15:19 +0000691% o exception: return any errors or warnings in this structure.
692%
cristy3ed852e2009-09-05 21:47:34 +0000693*/
694
cristy018f07f2011-09-04 21:15:19 +0000695MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000696{
cristy018f07f2011-09-04 21:15:19 +0000697 return(ClipImagePath(image,"#1",MagickTrue,exception));
cristy3ed852e2009-09-05 21:47:34 +0000698}
699
700MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000701 const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000702{
703#define ClipImagePathTag "ClipPath/Image"
704
705 char
706 *property;
707
708 const char
709 *value;
710
711 Image
712 *clip_mask;
713
714 ImageInfo
715 *image_info;
716
717 assert(image != (const Image *) NULL);
718 assert(image->signature == MagickSignature);
719 if (image->debug != MagickFalse)
720 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
721 assert(pathname != NULL);
722 property=AcquireString(pathname);
cristy151b66d2015-04-15 10:50:31 +0000723 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
cristy3ed852e2009-09-05 21:47:34 +0000724 pathname);
cristyd15e6592011-10-15 00:13:06 +0000725 value=GetImageProperty(image,property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000726 property=DestroyString(property);
727 if (value == (const char *) NULL)
728 {
cristy6fccee12011-10-20 18:43:18 +0000729 ThrowFileException(exception,OptionError,"NoClipPathDefined",
cristy3ed852e2009-09-05 21:47:34 +0000730 image->filename);
731 return(MagickFalse);
732 }
733 image_info=AcquireImageInfo();
cristy151b66d2015-04-15 10:50:31 +0000734 (void) CopyMagickString(image_info->filename,image->filename,MagickPathExtent);
735 (void) ConcatenateMagickString(image_info->filename,pathname,MagickPathExtent);
cristy6fccee12011-10-20 18:43:18 +0000736 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
cristy3ed852e2009-09-05 21:47:34 +0000737 image_info=DestroyImageInfo(image_info);
738 if (clip_mask == (Image *) NULL)
739 return(MagickFalse);
740 if (clip_mask->storage_class == PseudoClass)
741 {
cristyea1a8aa2011-10-20 13:24:06 +0000742 (void) SyncImage(clip_mask,exception);
cristy6fccee12011-10-20 18:43:18 +0000743 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000744 return(MagickFalse);
745 }
746 if (inside == MagickFalse)
cristy6fccee12011-10-20 18:43:18 +0000747 (void) NegateImage(clip_mask,MagickFalse,exception);
cristy151b66d2015-04-15 10:50:31 +0000748 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
cristy3ed852e2009-09-05 21:47:34 +0000749 "8BIM:1999,2998:%s\nPS",pathname);
cristy10a6c612012-01-29 21:41:05 +0000750 (void) SetImageMask(image,clip_mask,exception);
cristy3ed852e2009-09-05 21:47:34 +0000751 clip_mask=DestroyImage(clip_mask);
752 return(MagickTrue);
753}
754
755/*
756%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
757% %
758% %
759% %
760% C l o n e I m a g e %
761% %
762% %
763% %
764%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765%
766% CloneImage() copies an image and returns the copy as a new image object.
anthony96f11ee2011-03-23 08:22:54 +0000767%
cristy3ed852e2009-09-05 21:47:34 +0000768% If the specified columns and rows is 0, an exact copy of the image is
769% returned, otherwise the pixel data is undefined and must be initialized
770% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
771% failure, a NULL image is returned and exception describes the reason for the
772% failure.
773%
774% The format of the CloneImage method is:
775%
cristybb503372010-05-27 20:51:26 +0000776% Image *CloneImage(const Image *image,const size_t columns,
777% const size_t rows,const MagickBooleanType orphan,
cristy3ed852e2009-09-05 21:47:34 +0000778% ExceptionInfo *exception)
779%
780% A description of each parameter follows:
781%
782% o image: the image.
783%
784% o columns: the number of columns in the cloned image.
785%
786% o rows: the number of rows in the cloned image.
787%
788% o detach: With a value other than 0, the cloned image is detached from
789% its parent I/O stream.
790%
791% o exception: return any errors or warnings in this structure.
792%
793*/
cristybb503372010-05-27 20:51:26 +0000794MagickExport Image *CloneImage(const Image *image,const size_t columns,
cristybee00932011-01-15 20:28:27 +0000795 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000796{
797 Image
798 *clone_image;
799
cristya19f1d72012-08-07 18:24:38 +0000800 double
cristy3ed852e2009-09-05 21:47:34 +0000801 scale;
802
803 size_t
804 length;
805
806 /*
807 Clone the image.
808 */
809 assert(image != (const Image *) NULL);
810 assert(image->signature == MagickSignature);
811 if (image->debug != MagickFalse)
812 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
813 assert(exception != (ExceptionInfo *) NULL);
814 assert(exception->signature == MagickSignature);
cristybe1cfca2014-10-21 14:00:29 +0000815 if ((image->columns == 0) || (image->rows == 0))
816 {
817 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
818 "NegativeOrZeroImageSize","`%s'",image->filename);
819 return((Image *) NULL);
820 }
cristy73bd4a52010-10-05 11:24:23 +0000821 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000822 if (clone_image == (Image *) NULL)
823 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
824 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
825 clone_image->signature=MagickSignature;
826 clone_image->storage_class=image->storage_class;
cristyed231572011-07-14 02:18:59 +0000827 clone_image->number_channels=image->number_channels;
cristyb3a73b52011-07-26 01:34:43 +0000828 clone_image->number_meta_channels=image->number_meta_channels;
cristy4c08aed2011-07-01 19:47:50 +0000829 clone_image->metacontent_extent=image->metacontent_extent;
cristy3ed852e2009-09-05 21:47:34 +0000830 clone_image->colorspace=image->colorspace;
cristy883fde12013-04-08 00:50:13 +0000831 clone_image->read_mask=image->read_mask;
832 clone_image->write_mask=image->write_mask;
cristy8a46d822012-08-28 23:32:39 +0000833 clone_image->alpha_trait=image->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +0000834 clone_image->columns=image->columns;
835 clone_image->rows=image->rows;
836 clone_image->dither=image->dither;
cristy101ab702011-10-13 13:06:32 +0000837 if (image->colormap != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000838 {
839 /*
840 Allocate and copy the image colormap.
841 */
842 clone_image->colors=image->colors;
843 length=(size_t) image->colors;
cristy101ab702011-10-13 13:06:32 +0000844 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
cristy3ed852e2009-09-05 21:47:34 +0000845 sizeof(*clone_image->colormap));
cristy101ab702011-10-13 13:06:32 +0000846 if (clone_image->colormap == (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000847 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
848 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
849 sizeof(*clone_image->colormap));
850 }
851 (void) CloneImageProfiles(clone_image,image);
852 (void) CloneImageProperties(clone_image,image);
853 (void) CloneImageArtifacts(clone_image,image);
854 GetTimerInfo(&clone_image->timer);
cristy3ed852e2009-09-05 21:47:34 +0000855 if (image->ascii85 != (void *) NULL)
856 Ascii85Initialize(clone_image);
857 clone_image->magick_columns=image->magick_columns;
858 clone_image->magick_rows=image->magick_rows;
859 clone_image->type=image->type;
cristy636dcb52011-08-26 13:23:49 +0000860 clone_image->channel_mask=image->channel_mask;
cristyed231572011-07-14 02:18:59 +0000861 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +0000862 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
cristy151b66d2015-04-15 10:50:31 +0000863 MagickPathExtent);
864 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
865 (void) CopyMagickString(clone_image->filename,image->filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000866 clone_image->progress_monitor=image->progress_monitor;
867 clone_image->client_data=image->client_data;
868 clone_image->reference_count=1;
cristybee00932011-01-15 20:28:27 +0000869 clone_image->next=image->next;
870 clone_image->previous=image->previous;
cristy3ed852e2009-09-05 21:47:34 +0000871 clone_image->list=NewImageList();
cristy3ed852e2009-09-05 21:47:34 +0000872 if (detach == MagickFalse)
873 clone_image->blob=ReferenceBlob(image->blob);
874 else
cristybee00932011-01-15 20:28:27 +0000875 {
876 clone_image->next=NewImageList();
877 clone_image->previous=NewImageList();
878 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
879 }
cristy73724512010-04-12 14:43:14 +0000880 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000881 clone_image->debug=IsEventLogging();
cristy3d162a92014-02-16 14:05:06 +0000882 clone_image->semaphore=AcquireSemaphoreInfo();
cristy58a749e2014-05-25 17:36:53 +0000883 if ((columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000884 {
885 if (image->montage != (char *) NULL)
886 (void) CloneString(&clone_image->montage,image->montage);
887 if (image->directory != (char *) NULL)
888 (void) CloneString(&clone_image->directory,image->directory);
cristy3ed852e2009-09-05 21:47:34 +0000889 clone_image->cache=ReferencePixelCache(image->cache);
890 return(clone_image);
891 }
cristy51d26762014-05-26 01:29:41 +0000892 scale=1.0;
893 if (image->columns != 0)
894 scale=(double) columns/(double) image->columns;
cristybb503372010-05-27 20:51:26 +0000895 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
896 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
897 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
cristy51d26762014-05-26 01:29:41 +0000898 scale=1.0;
899 if (image->rows != 0)
cristya19f1d72012-08-07 18:24:38 +0000900 scale=(double) rows/(double) image->rows;
cristybb503372010-05-27 20:51:26 +0000901 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
902 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
903 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000904 clone_image->columns=columns;
905 clone_image->rows=rows;
906 clone_image->cache=ClonePixelCache(image->cache);
907 return(clone_image);
908}
909
910/*
911%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
912% %
913% %
914% %
915% C l o n e I m a g e I n f o %
916% %
917% %
918% %
919%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
920%
921% CloneImageInfo() makes a copy of the given image info structure. If
922% NULL is specified, a new image info structure is created initialized to
923% default values.
924%
925% The format of the CloneImageInfo method is:
926%
927% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
928%
929% A description of each parameter follows:
930%
931% o image_info: the image info.
932%
933*/
934MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
935{
936 ImageInfo
937 *clone_info;
938
939 clone_info=AcquireImageInfo();
940 if (image_info == (ImageInfo *) NULL)
941 return(clone_info);
942 clone_info->compression=image_info->compression;
943 clone_info->temporary=image_info->temporary;
944 clone_info->adjoin=image_info->adjoin;
945 clone_info->antialias=image_info->antialias;
946 clone_info->scene=image_info->scene;
947 clone_info->number_scenes=image_info->number_scenes;
948 clone_info->depth=image_info->depth;
anthony72feaa62012-01-17 06:46:23 +0000949 (void) CloneString(&clone_info->size,image_info->size);
950 (void) CloneString(&clone_info->extract,image_info->extract);
951 (void) CloneString(&clone_info->scenes,image_info->scenes);
952 (void) CloneString(&clone_info->page,image_info->page);
cristy3ed852e2009-09-05 21:47:34 +0000953 clone_info->interlace=image_info->interlace;
954 clone_info->endian=image_info->endian;
955 clone_info->units=image_info->units;
956 clone_info->quality=image_info->quality;
anthony72feaa62012-01-17 06:46:23 +0000957 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
958 (void) CloneString(&clone_info->server_name,image_info->server_name);
959 (void) CloneString(&clone_info->font,image_info->font);
960 (void) CloneString(&clone_info->texture,image_info->texture);
961 (void) CloneString(&clone_info->density,image_info->density);
cristy3ed852e2009-09-05 21:47:34 +0000962 clone_info->pointsize=image_info->pointsize;
963 clone_info->fuzz=image_info->fuzz;
cristy3ed852e2009-09-05 21:47:34 +0000964 clone_info->background_color=image_info->background_color;
965 clone_info->border_color=image_info->border_color;
966 clone_info->matte_color=image_info->matte_color;
967 clone_info->transparent_color=image_info->transparent_color;
968 clone_info->dither=image_info->dither;
969 clone_info->monochrome=image_info->monochrome;
cristy3ed852e2009-09-05 21:47:34 +0000970 clone_info->colorspace=image_info->colorspace;
971 clone_info->type=image_info->type;
972 clone_info->orientation=image_info->orientation;
973 clone_info->preview_type=image_info->preview_type;
974 clone_info->group=image_info->group;
975 clone_info->ping=image_info->ping;
976 clone_info->verbose=image_info->verbose;
anthony72feaa62012-01-17 06:46:23 +0000977 (void) CloneString(&clone_info->view,image_info->view);
cristy3ed852e2009-09-05 21:47:34 +0000978 clone_info->progress_monitor=image_info->progress_monitor;
979 clone_info->client_data=image_info->client_data;
980 clone_info->cache=image_info->cache;
981 if (image_info->cache != (void *) NULL)
982 clone_info->cache=ReferencePixelCache(image_info->cache);
983 if (image_info->profile != (void *) NULL)
984 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
985 image_info->profile);
986 SetImageInfoFile(clone_info,image_info->file);
987 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
988 clone_info->stream=image_info->stream;
cristy957f2612015-06-21 23:51:58 +0000989 (void) CopyMagickString(clone_info->magick,image_info->magick,
990 MagickPathExtent);
991 (void) CopyMagickString(clone_info->unique,image_info->unique,
992 MagickPathExtent);
cristy151b66d2015-04-15 10:50:31 +0000993 (void) CopyMagickString(clone_info->zero,image_info->zero,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000994 (void) CopyMagickString(clone_info->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +0000995 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000996 clone_info->channel=image_info->channel;
anthony1afdc7a2011-10-05 11:54:28 +0000997 (void) CloneImageOptions(clone_info,image_info);
cristy3ed852e2009-09-05 21:47:34 +0000998 clone_info->debug=IsEventLogging();
999 clone_info->signature=image_info->signature;
1000 return(clone_info);
1001}
1002
1003/*
1004%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1005% %
1006% %
1007% %
cristy957f2612015-06-21 23:51:58 +00001008% C o p y I m a g e P i x e l s %
1009% %
1010% %
1011% %
1012%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1013%
1014% CopyImagePixels() copies pixels from the source image as defined by the
1015% geometry the destination image at the specified offset.
1016%
1017% The format of the CopyImagePixels method is:
1018%
1019% MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
cristy17fbd722015-06-22 00:46:58 +00001020% const RectangleInfo *geometry,const OffsetInfo *offset,
1021% ExceptionInfo *exception);
cristy957f2612015-06-21 23:51:58 +00001022%
1023% A description of each parameter follows:
1024%
1025% o image: the destination image.
1026%
1027% o source_image: the source image.
1028%
1029% o geometry: define the dimensions of the source pixel rectangle.
1030%
1031% o offset: define the offset in the destination image.
1032%
cristy17fbd722015-06-22 00:46:58 +00001033% o exception: return any errors or warnings in this structure.
1034%
cristy957f2612015-06-21 23:51:58 +00001035*/
1036MagickExport MagickBooleanType CopyImagePixels(Image *image,
1037 const Image *source_image,const RectangleInfo *geometry,
cristy17fbd722015-06-22 00:46:58 +00001038 const OffsetInfo *offset,ExceptionInfo *exception)
cristy957f2612015-06-21 23:51:58 +00001039{
cristy17fbd722015-06-22 00:46:58 +00001040#define CopyImageTag "Copy/Image"
1041
1042 CacheView
1043 *image_view,
1044 *source_view;
1045
1046 MagickBooleanType
1047 status;
1048
1049 MagickOffsetType
1050 progress;
1051
1052 ssize_t
1053 y;
1054
cristy957f2612015-06-21 23:51:58 +00001055 assert(image != (Image *) NULL);
1056 if (image->debug != MagickFalse)
1057 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1058 assert(source_image != (Image *) NULL);
1059 assert(geometry != (RectangleInfo *) NULL);
1060 assert(offset != (OffsetInfo *) NULL);
cristy8c4c1c42015-06-22 23:51:22 +00001061 if ((offset->x < 0) || (offset->y < 0) ||
1062 ((offset->x+geometry->width) >= (ssize_t) image->columns) ||
1063 ((offset->y+geometry->height) >= (ssize_t) image->rows))
cristye742cae2015-06-22 19:40:29 +00001064 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1065 image->filename);
cristy8c4c1c42015-06-22 23:51:22 +00001066 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1067 return(MagickFalse);
cristy17fbd722015-06-22 00:46:58 +00001068 /*
1069 Copy image pixels.
1070 */
1071 status=MagickTrue;
1072 progress=0;
1073 source_view=AcquireVirtualCacheView(source_image,exception);
1074 image_view=AcquireAuthenticCacheView(image,exception);
1075#if defined(MAGICKCORE_OPENMP_SUPPORT)
1076 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristye742cae2015-06-22 19:40:29 +00001077 magick_threads(image,source_image,geometry->height,1)
cristy17fbd722015-06-22 00:46:58 +00001078#endif
cristye742cae2015-06-22 19:40:29 +00001079 for (y=0; y < (ssize_t) geometry->height; y++)
cristy17fbd722015-06-22 00:46:58 +00001080 {
1081 MagickBooleanType
1082 sync;
1083
1084 register const Quantum
1085 *restrict p;
1086
1087 register ssize_t
1088 x;
1089
1090 register Quantum
1091 *restrict q;
1092
1093 if (status == MagickFalse)
1094 continue;
cristye742cae2015-06-22 19:40:29 +00001095 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1096 geometry->width,1,exception);
1097 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1098 geometry->width,1,exception);
cristy17fbd722015-06-22 00:46:58 +00001099 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1100 {
1101 status=MagickFalse;
1102 continue;
1103 }
cristye742cae2015-06-22 19:40:29 +00001104 for (x=0; x < (ssize_t) geometry->width; x++)
cristy17fbd722015-06-22 00:46:58 +00001105 {
1106 register ssize_t
1107 i;
1108
1109 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1110 {
1111 PixelChannel channel=GetPixelChannelChannel(image,i);
1112 PixelTrait traits=GetPixelChannelTraits(image,channel);
1113 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1114 if ((traits == UndefinedPixelTrait) ||
1115 (source_traits == UndefinedPixelTrait))
1116 continue;
1117 SetPixelChannel(source_image,channel,p[i],q);
1118 }
1119 p+=GetPixelChannels(image);
1120 q+=GetPixelChannels(source_image);
1121 }
1122 sync=SyncCacheViewAuthenticPixels(source_view,exception);
1123 if (sync == MagickFalse)
1124 status=MagickFalse;
1125 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1126 {
1127 MagickBooleanType
1128 proceed;
1129
1130#if defined(MAGICKCORE_OPENMP_SUPPORT)
1131 #pragma omp critical (MagickCore_CopyImage)
1132#endif
1133 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1134 if (proceed == MagickFalse)
1135 status=MagickFalse;
1136 }
1137 }
1138 source_view=DestroyCacheView(source_view);
1139 image_view=DestroyCacheView(image_view);
1140 return(status);
cristy957f2612015-06-21 23:51:58 +00001141}
1142
1143/*
1144%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1145% %
1146% %
1147% %
cristy3ed852e2009-09-05 21:47:34 +00001148% D e s t r o y I m a g e %
1149% %
1150% %
1151% %
1152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1153%
1154% DestroyImage() dereferences an image, deallocating memory associated with
1155% the image if the reference count becomes zero.
1156%
1157% The format of the DestroyImage method is:
1158%
1159% Image *DestroyImage(Image *image)
1160%
1161% A description of each parameter follows:
1162%
1163% o image: the image.
1164%
1165*/
1166MagickExport Image *DestroyImage(Image *image)
1167{
1168 MagickBooleanType
1169 destroy;
1170
1171 /*
1172 Dereference image.
1173 */
1174 assert(image != (Image *) NULL);
1175 assert(image->signature == MagickSignature);
1176 if (image->debug != MagickFalse)
1177 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1178 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001179 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001180 image->reference_count--;
1181 if (image->reference_count == 0)
1182 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001183 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001184 if (destroy == MagickFalse)
1185 return((Image *) NULL);
1186 /*
1187 Destroy image.
1188 */
1189 DestroyImagePixels(image);
cristyed231572011-07-14 02:18:59 +00001190 image->channel_map=DestroyPixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +00001191 if (image->montage != (char *) NULL)
1192 image->montage=DestroyString(image->montage);
1193 if (image->directory != (char *) NULL)
1194 image->directory=DestroyString(image->directory);
cristy101ab702011-10-13 13:06:32 +00001195 if (image->colormap != (PixelInfo *) NULL)
1196 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
cristy3ed852e2009-09-05 21:47:34 +00001197 if (image->geometry != (char *) NULL)
1198 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001199 DestroyImageProfiles(image);
1200 DestroyImageProperties(image);
1201 DestroyImageArtifacts(image);
1202 if (image->ascii85 != (Ascii85Info*) NULL)
1203 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
1204 DestroyBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001205 if (image->semaphore != (SemaphoreInfo *) NULL)
cristy3d162a92014-02-16 14:05:06 +00001206 RelinquishSemaphoreInfo(&image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001207 image->signature=(~MagickSignature);
1208 image=(Image *) RelinquishMagickMemory(image);
1209 return(image);
1210}
1211
1212/*
1213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1214% %
1215% %
1216% %
1217% D e s t r o y I m a g e I n f o %
1218% %
1219% %
1220% %
1221%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1222%
1223% DestroyImageInfo() deallocates memory associated with an ImageInfo
1224% structure.
1225%
1226% The format of the DestroyImageInfo method is:
1227%
1228% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1229%
1230% A description of each parameter follows:
1231%
1232% o image_info: the image info.
1233%
1234*/
1235MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1236{
1237 assert(image_info != (ImageInfo *) NULL);
1238 assert(image_info->signature == MagickSignature);
1239 if (image_info->debug != MagickFalse)
1240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1241 image_info->filename);
1242 if (image_info->size != (char *) NULL)
1243 image_info->size=DestroyString(image_info->size);
1244 if (image_info->extract != (char *) NULL)
1245 image_info->extract=DestroyString(image_info->extract);
1246 if (image_info->scenes != (char *) NULL)
1247 image_info->scenes=DestroyString(image_info->scenes);
1248 if (image_info->page != (char *) NULL)
1249 image_info->page=DestroyString(image_info->page);
1250 if (image_info->sampling_factor != (char *) NULL)
1251 image_info->sampling_factor=DestroyString(
1252 image_info->sampling_factor);
1253 if (image_info->server_name != (char *) NULL)
1254 image_info->server_name=DestroyString(
1255 image_info->server_name);
1256 if (image_info->font != (char *) NULL)
1257 image_info->font=DestroyString(image_info->font);
1258 if (image_info->texture != (char *) NULL)
1259 image_info->texture=DestroyString(image_info->texture);
1260 if (image_info->density != (char *) NULL)
1261 image_info->density=DestroyString(image_info->density);
1262 if (image_info->view != (char *) NULL)
1263 image_info->view=DestroyString(image_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001264 if (image_info->cache != (void *) NULL)
1265 image_info->cache=DestroyPixelCache(image_info->cache);
1266 if (image_info->profile != (StringInfo *) NULL)
1267 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1268 image_info->profile);
anthony1afdc7a2011-10-05 11:54:28 +00001269 DestroyImageOptions(image_info);
cristy3ed852e2009-09-05 21:47:34 +00001270 image_info->signature=(~MagickSignature);
1271 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1272 return(image_info);
1273}
1274
1275/*
1276%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1277% %
1278% %
1279% %
1280+ D i s a s s o c i a t e I m a g e S t r e a m %
1281% %
1282% %
1283% %
1284%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285%
cristy4916cb42014-09-20 00:44:37 +00001286% DisassociateImageStream() disassociates the image stream. It checks if the
1287% blob of the specified image is referenced by other images. If the reference
1288% count is higher then 1 a new blob is assigned to the specified image.
cristy3ed852e2009-09-05 21:47:34 +00001289%
1290% The format of the DisassociateImageStream method is:
1291%
dirkcfe4c1c2014-09-20 07:38:59 +00001292% void DisassociateImageStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001293%
1294% A description of each parameter follows:
1295%
1296% o image: the image.
1297%
1298*/
1299MagickExport void DisassociateImageStream(Image *image)
1300{
cristy4916cb42014-09-20 00:44:37 +00001301 assert(image != (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001302 assert(image->signature == MagickSignature);
1303 if (image->debug != MagickFalse)
1304 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy10f10ec2014-09-20 01:00:50 +00001305 DisassociateBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001306}
1307
1308/*
1309%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1310% %
1311% %
1312% %
cristy3ed852e2009-09-05 21:47:34 +00001313% G e t I m a g e I n f o %
1314% %
1315% %
1316% %
1317%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1318%
1319% GetImageInfo() initializes image_info to default values.
1320%
1321% The format of the GetImageInfo method is:
1322%
1323% void GetImageInfo(ImageInfo *image_info)
1324%
1325% A description of each parameter follows:
1326%
1327% o image_info: the image info.
1328%
1329*/
1330MagickExport void GetImageInfo(ImageInfo *image_info)
1331{
cristyfa0ea942012-12-21 02:42:29 +00001332 char
1333 *synchronize;
1334
cristy3ed852e2009-09-05 21:47:34 +00001335 ExceptionInfo
1336 *exception;
1337
1338 /*
1339 File and image dimension members.
1340 */
1341 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1342 assert(image_info != (ImageInfo *) NULL);
1343 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1344 image_info->adjoin=MagickTrue;
1345 image_info->interlace=NoInterlace;
1346 image_info->channel=DefaultChannels;
1347 image_info->quality=UndefinedCompressionQuality;
1348 image_info->antialias=MagickTrue;
1349 image_info->dither=MagickTrue;
cristyfa0ea942012-12-21 02:42:29 +00001350 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1351 if (synchronize != (const char *) NULL)
1352 {
1353 image_info->synchronize=IsStringTrue(synchronize);
1354 synchronize=DestroyString(synchronize);
1355 }
cristy3ed852e2009-09-05 21:47:34 +00001356 exception=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00001357 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1358 &image_info->background_color,exception);
1359 (void) QueryColorCompliance(BorderColor,AllCompliance,
1360 &image_info->border_color,exception);
1361 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
cristy3ed852e2009-09-05 21:47:34 +00001362 exception);
cristy9950d572011-10-01 18:22:35 +00001363 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1364 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00001365 exception=DestroyExceptionInfo(exception);
1366 image_info->debug=IsEventLogging();
1367 image_info->signature=MagickSignature;
1368}
1369
1370/*
1371%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1372% %
1373% %
1374% %
cristy15781e52009-12-05 23:05:27 +00001375% G e t I m a g e I n f o F i l e %
1376% %
1377% %
1378% %
1379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1380%
1381% GetImageInfoFile() returns the image info file member.
1382%
1383% The format of the GetImageInfoFile method is:
1384%
1385% FILE *GetImageInfoFile(const ImageInfo *image_info)
1386%
1387% A description of each parameter follows:
1388%
1389% o image_info: the image info.
1390%
1391*/
1392MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1393{
1394 return(image_info->file);
1395}
1396
1397/*
1398%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1399% %
1400% %
1401% %
cristy3ed852e2009-09-05 21:47:34 +00001402% G e t I m a g e M a s k %
1403% %
1404% %
1405% %
1406%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1407%
1408% GetImageMask() returns the mask associated with the image.
1409%
1410% The format of the GetImageMask method is:
1411%
1412% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1413%
1414% A description of each parameter follows:
1415%
1416% o image: the image.
1417%
1418*/
1419MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1420{
cristy10a6c612012-01-29 21:41:05 +00001421 CacheView
1422 *mask_view,
1423 *image_view;
1424
1425 Image
1426 *mask_image;
1427
1428 MagickBooleanType
1429 status;
1430
1431 ssize_t
1432 y;
1433
1434 /*
1435 Get image mask.
1436 */
1437 assert(image != (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001438 if (image->debug != MagickFalse)
1439 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1440 assert(image->signature == MagickSignature);
cristy10a6c612012-01-29 21:41:05 +00001441 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1442 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001443 return((Image *) NULL);
cristy10a6c612012-01-29 21:41:05 +00001444 status=MagickTrue;
cristy5ccdd122012-06-13 22:29:02 +00001445 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
cristy883fde12013-04-08 00:50:13 +00001446 mask_image->read_mask=MagickFalse;
cristy46ff2672012-12-14 15:32:26 +00001447 image_view=AcquireVirtualCacheView(image,exception);
1448 mask_view=AcquireAuthenticCacheView(mask_image,exception);
cristy10a6c612012-01-29 21:41:05 +00001449 for (y=0; y < (ssize_t) image->rows; y++)
1450 {
1451 register const Quantum
1452 *restrict p;
1453
1454 register Quantum
1455 *restrict q;
1456
1457 register ssize_t
1458 x;
1459
1460 if (status == MagickFalse)
1461 continue;
1462 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1463 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1464 exception);
1465 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1466 {
1467 status=MagickFalse;
1468 continue;
1469 }
1470 for (x=0; x < (ssize_t) image->columns; x++)
1471 {
cristy883fde12013-04-08 00:50:13 +00001472 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
cristy10a6c612012-01-29 21:41:05 +00001473 p+=GetPixelChannels(image);
1474 q+=GetPixelChannels(mask_image);
1475 }
1476 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1477 status=MagickFalse;
1478 }
1479 mask_view=DestroyCacheView(mask_view);
1480 image_view=DestroyCacheView(image_view);
cristy1c2f48d2012-12-14 01:20:55 +00001481 if (status == MagickFalse)
1482 mask_image=DestroyImage(mask_image);
cristy10a6c612012-01-29 21:41:05 +00001483 return(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001484}
1485
1486/*
1487%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1488% %
1489% %
1490% %
1491+ G e t I m a g e R e f e r e n c e C o u n t %
1492% %
1493% %
1494% %
1495%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1496%
1497% GetImageReferenceCount() returns the image reference count.
1498%
1499% The format of the GetReferenceCount method is:
1500%
cristybb503372010-05-27 20:51:26 +00001501% ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001502%
1503% A description of each parameter follows:
1504%
1505% o image: the image.
1506%
1507*/
cristybb503372010-05-27 20:51:26 +00001508MagickExport ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001509{
cristybb503372010-05-27 20:51:26 +00001510 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001511 reference_count;
1512
1513 assert(image != (Image *) NULL);
1514 assert(image->signature == MagickSignature);
1515 if (image->debug != MagickFalse)
1516 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001517 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001518 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001519 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001520 return(reference_count);
1521}
1522
1523/*
1524%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1525% %
1526% %
1527% %
cristy3ed852e2009-09-05 21:47:34 +00001528% 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 %
1529% %
1530% %
1531% %
1532%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1533%
1534% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1535% image. A virtual pixel is any pixel access that is outside the boundaries
1536% of the image cache.
1537%
1538% The format of the GetImageVirtualPixelMethod() method is:
1539%
1540% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1541%
1542% A description of each parameter follows:
1543%
1544% o image: the image.
1545%
1546*/
1547MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1548{
1549 assert(image != (Image *) NULL);
1550 assert(image->signature == MagickSignature);
1551 if (image->debug != MagickFalse)
1552 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1553 return(GetPixelCacheVirtualMethod(image));
1554}
1555
1556/*
1557%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1558% %
1559% %
1560% %
1561% I n t e r p r e t I m a g e F i l e n a m e %
1562% %
1563% %
1564% %
1565%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1566%
1567% InterpretImageFilename() interprets embedded characters in an image filename.
1568% The filename length is returned.
1569%
1570% The format of the InterpretImageFilename method is:
1571%
cristyee2b1232012-03-04 02:58:28 +00001572% size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1573% const char *format,int value,char *filename,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001574%
1575% A description of each parameter follows.
1576%
1577% o image_info: the image info..
1578%
1579% o image: the image.
1580%
1581% o format: A filename describing the format to use to write the numeric
1582% argument. Only the first numeric format identifier is replaced.
1583%
1584% o value: Numeric value to substitute into format filename.
1585%
1586% o filename: return the formatted filename in this character buffer.
1587%
cristy6fccee12011-10-20 18:43:18 +00001588% o exception: return any errors or warnings in this structure.
1589%
cristy3ed852e2009-09-05 21:47:34 +00001590*/
1591MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00001592 Image *image,const char *format,int value,char *filename,
1593 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001594{
1595 char
1596 *q;
1597
1598 int
1599 c;
1600
1601 MagickBooleanType
1602 canonical;
1603
1604 register const char
1605 *p;
1606
cristyad785752011-07-27 23:13:03 +00001607 size_t
1608 length;
1609
cristy3ed852e2009-09-05 21:47:34 +00001610 canonical=MagickFalse;
cristyc7b79fc2011-07-28 00:24:17 +00001611 length=0;
cristy151b66d2015-04-15 10:50:31 +00001612 (void) CopyMagickString(filename,format,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001613 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1614 {
1615 q=(char *) p+1;
1616 if (*q == '%')
1617 {
1618 p=q+1;
1619 continue;
1620 }
1621 if (*q == '0')
1622 {
cristybb503372010-05-27 20:51:26 +00001623 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001624 value;
1625
cristybb503372010-05-27 20:51:26 +00001626 value=(ssize_t) strtol(q,&q,10);
cristyda16f162011-02-19 23:52:17 +00001627 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00001628 }
1629 switch (*q)
1630 {
1631 case 'd':
1632 case 'o':
1633 case 'x':
1634 {
1635 q++;
1636 c=(*q);
1637 *q='\0';
cristy151b66d2015-04-15 10:50:31 +00001638 (void) FormatLocaleString(filename+(p-format),(size_t) (MagickPathExtent-
cristy3ed852e2009-09-05 21:47:34 +00001639 (p-format)),p,value);
1640 *q=c;
cristy151b66d2015-04-15 10:50:31 +00001641 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001642 canonical=MagickTrue;
1643 if (*(q-1) != '%')
1644 break;
1645 p++;
1646 break;
1647 }
1648 case '[':
1649 {
1650 char
cristy151b66d2015-04-15 10:50:31 +00001651 pattern[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001652
1653 const char
1654 *value;
1655
cristy3ed852e2009-09-05 21:47:34 +00001656 register char
1657 *r;
1658
cristybb503372010-05-27 20:51:26 +00001659 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001660 i;
1661
cristycb6d09b2010-06-19 01:59:36 +00001662 ssize_t
1663 depth;
1664
cristy3ed852e2009-09-05 21:47:34 +00001665 /*
1666 Image option.
1667 */
anthony2cfa1a12012-05-12 05:18:07 +00001668 /* FUTURE: Compare update with code from InterpretImageProperties()
cristy97fc9f32012-06-13 21:04:44 +00001669 Note that a 'filename:' property should not need depth recursion.
anthony2cfa1a12012-05-12 05:18:07 +00001670 */
cristy3ed852e2009-09-05 21:47:34 +00001671 if (strchr(p,']') == (char *) NULL)
1672 break;
1673 depth=1;
1674 r=q+1;
cristy151b66d2015-04-15 10:50:31 +00001675 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
cristy3ed852e2009-09-05 21:47:34 +00001676 {
1677 if (*r == '[')
1678 depth++;
1679 if (*r == ']')
1680 depth--;
1681 if (depth <= 0)
1682 break;
1683 pattern[i]=(*r++);
1684 }
1685 pattern[i]='\0';
1686 if (LocaleNCompare(pattern,"filename:",9) != 0)
1687 break;
1688 value=(const char *) NULL;
anthony06762232012-04-29 11:45:40 +00001689#if 0
1690 // FUTURE: remove this code. -- Anthony 29 Arpil 2012
anthony2cfa1a12012-05-12 05:18:07 +00001691 // Removed as GetMagickProperty() will will never match a "filename:"
cristy97fc9f32012-06-13 21:04:44 +00001692 // string as this is not a 'known' image property.
anthony06762232012-04-29 11:45:40 +00001693 //
cristy3ed852e2009-09-05 21:47:34 +00001694 if ((image_info != (const ImageInfo *) NULL) &&
1695 (image != (const Image *) NULL))
cristy6fccee12011-10-20 18:43:18 +00001696 value=GetMagickProperty(image_info,image,pattern,exception);
cristy3ed852e2009-09-05 21:47:34 +00001697 else
anthony06762232012-04-29 11:45:40 +00001698#endif
1699 if (image != (Image *) NULL)
1700 value=GetImageProperty(image,pattern,exception);
cristy1a780952013-02-10 17:15:30 +00001701 if ((value == (const char *) NULL) && (image != (Image *) NULL))
anthony06762232012-04-29 11:45:40 +00001702 value=GetImageArtifact(image,pattern);
1703 if ((value == (const char *) NULL) &&
1704 (image_info != (ImageInfo *) NULL))
1705 value=GetImageOption(image_info,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001706 if (value == (const char *) NULL)
1707 break;
1708 q--;
1709 c=(*q);
1710 *q='\0';
cristyad785752011-07-27 23:13:03 +00001711 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
cristy151b66d2015-04-15 10:50:31 +00001712 (MagickPathExtent-(p-format-length)));
cristyad785752011-07-27 23:13:03 +00001713 length+=strlen(pattern)-1;
cristy3ed852e2009-09-05 21:47:34 +00001714 *q=c;
cristy151b66d2015-04-15 10:50:31 +00001715 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001716 canonical=MagickTrue;
1717 if (*(q-1) != '%')
1718 break;
1719 p++;
1720 break;
1721 }
1722 default:
1723 break;
1724 }
1725 }
1726 for (q=filename; *q != '\0'; q++)
1727 if ((*q == '%') && (*(q+1) == '%'))
cristy27bf23e2011-01-10 13:35:22 +00001728 {
cristy151b66d2015-04-15 10:50:31 +00001729 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
cristy27bf23e2011-01-10 13:35:22 +00001730 canonical=MagickTrue;
1731 }
cristy3ed852e2009-09-05 21:47:34 +00001732 if (canonical == MagickFalse)
cristy151b66d2015-04-15 10:50:31 +00001733 (void) CopyMagickString(filename,format,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001734 return(strlen(filename));
1735}
1736
1737/*
1738%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1739% %
1740% %
1741% %
1742% I s H i g h D y n a m i c R a n g e I m a g e %
1743% %
1744% %
1745% %
1746%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1747%
1748% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1749% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1750% 0..65535.
1751%
1752% The format of the IsHighDynamicRangeImage method is:
1753%
1754% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1755% ExceptionInfo *exception)
1756%
1757% A description of each parameter follows:
1758%
1759% o image: the image.
1760%
1761% o exception: return any errors or warnings in this structure.
1762%
1763*/
1764MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1765 ExceptionInfo *exception)
1766{
1767#if !defined(MAGICKCORE_HDRI_SUPPORT)
1768 (void) image;
1769 (void) exception;
1770 return(MagickFalse);
1771#else
1772 CacheView
1773 *image_view;
1774
cristy3ed852e2009-09-05 21:47:34 +00001775 MagickBooleanType
1776 status;
1777
cristycb6d09b2010-06-19 01:59:36 +00001778 ssize_t
1779 y;
1780
cristy3ed852e2009-09-05 21:47:34 +00001781 assert(image != (Image *) NULL);
1782 assert(image->signature == MagickSignature);
1783 if (image->debug != MagickFalse)
1784 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1785 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00001786 image_view=AcquireVirtualCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00001787#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00001788 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00001789 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00001790#endif
cristybb503372010-05-27 20:51:26 +00001791 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001792 {
cristy4c08aed2011-07-01 19:47:50 +00001793 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001794 *p;
1795
cristybb503372010-05-27 20:51:26 +00001796 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001797 x;
1798
1799 if (status == MagickFalse)
1800 continue;
1801 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001802 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001803 {
1804 status=MagickFalse;
1805 continue;
1806 }
cristybb503372010-05-27 20:51:26 +00001807 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001808 {
cristya905c052011-09-17 22:37:55 +00001809 register ssize_t
1810 i;
1811
cristy883fde12013-04-08 00:50:13 +00001812 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +00001813 {
1814 p+=GetPixelChannels(image);
1815 continue;
1816 }
cristya905c052011-09-17 22:37:55 +00001817 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1818 {
cristya19f1d72012-08-07 18:24:38 +00001819 double
cristya905c052011-09-17 22:37:55 +00001820 pixel;
1821
cristyb0a657e2012-08-29 00:45:37 +00001822 PixelTrait
1823 traits;
1824
1825 traits=GetPixelChannelTraits(image,(PixelChannel) i);
cristya905c052011-09-17 22:37:55 +00001826 if (traits == UndefinedPixelTrait)
1827 continue;
cristya19f1d72012-08-07 18:24:38 +00001828 pixel=(double) p[i];
cristya905c052011-09-17 22:37:55 +00001829 if ((pixel < 0.0) || (pixel > QuantumRange) ||
cristy569b0e32013-08-15 16:07:35 +00001830 (pixel != (double) ((QuantumAny) pixel)))
cristya905c052011-09-17 22:37:55 +00001831 break;
1832 }
cristyed231572011-07-14 02:18:59 +00001833 p+=GetPixelChannels(image);
cristya905c052011-09-17 22:37:55 +00001834 if (i < (ssize_t) GetPixelChannels(image))
1835 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00001836 }
cristybb503372010-05-27 20:51:26 +00001837 if (x < (ssize_t) image->columns)
cristy3ed852e2009-09-05 21:47:34 +00001838 status=MagickFalse;
1839 }
1840 image_view=DestroyCacheView(image_view);
1841 return(status != MagickFalse ? MagickFalse : MagickTrue);
1842#endif
1843}
1844
1845/*
1846%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1847% %
1848% %
1849% %
1850% I s I m a g e O b j e c t %
1851% %
1852% %
1853% %
1854%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1855%
1856% IsImageObject() returns MagickTrue if the image sequence contains a valid
1857% set of image objects.
1858%
1859% The format of the IsImageObject method is:
1860%
1861% MagickBooleanType IsImageObject(const Image *image)
1862%
1863% A description of each parameter follows:
1864%
1865% o image: the image.
1866%
1867*/
1868MagickExport MagickBooleanType IsImageObject(const Image *image)
1869{
1870 register const Image
1871 *p;
1872
1873 assert(image != (Image *) NULL);
1874 if (image->debug != MagickFalse)
1875 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1876 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1877 if (p->signature != MagickSignature)
1878 return(MagickFalse);
1879 return(MagickTrue);
1880}
1881
1882/*
1883%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1884% %
1885% %
1886% %
1887% I s T a i n t I m a g e %
1888% %
1889% %
1890% %
1891%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1892%
1893% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1894% since it was first constituted.
1895%
1896% The format of the IsTaintImage method is:
1897%
1898% MagickBooleanType IsTaintImage(const Image *image)
1899%
1900% A description of each parameter follows:
1901%
1902% o image: the image.
1903%
1904*/
1905MagickExport MagickBooleanType IsTaintImage(const Image *image)
1906{
1907 char
cristy151b66d2015-04-15 10:50:31 +00001908 magick[MagickPathExtent],
1909 filename[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001910
1911 register const Image
1912 *p;
1913
1914 assert(image != (Image *) NULL);
1915 if (image->debug != MagickFalse)
1916 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1917 assert(image->signature == MagickSignature);
cristy151b66d2015-04-15 10:50:31 +00001918 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1919 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001920 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1921 {
1922 if (p->taint != MagickFalse)
1923 return(MagickTrue);
1924 if (LocaleCompare(p->magick,magick) != 0)
1925 return(MagickTrue);
1926 if (LocaleCompare(p->filename,filename) != 0)
1927 return(MagickTrue);
1928 }
1929 return(MagickFalse);
1930}
1931
1932/*
1933%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1934% %
1935% %
1936% %
1937% M o d i f y I m a g e %
1938% %
1939% %
1940% %
1941%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1942%
1943% ModifyImage() ensures that there is only a single reference to the image
1944% to be modified, updating the provided image pointer to point to a clone of
1945% the original image if necessary.
1946%
1947% The format of the ModifyImage method is:
1948%
1949% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1950%
1951% A description of each parameter follows:
1952%
1953% o image: the image.
1954%
1955% o exception: return any errors or warnings in this structure.
1956%
1957*/
1958MagickExport MagickBooleanType ModifyImage(Image **image,
1959 ExceptionInfo *exception)
1960{
1961 Image
1962 *clone_image;
1963
1964 assert(image != (Image **) NULL);
1965 assert(*image != (Image *) NULL);
1966 assert((*image)->signature == MagickSignature);
1967 if ((*image)->debug != MagickFalse)
1968 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1969 if (GetImageReferenceCount(*image) <= 1)
1970 return(MagickTrue);
1971 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
cristyf84a1932010-01-03 18:00:18 +00001972 LockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001973 (*image)->reference_count--;
cristyf84a1932010-01-03 18:00:18 +00001974 UnlockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001975 *image=clone_image;
1976 return(MagickTrue);
1977}
1978
1979/*
1980%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1981% %
1982% %
1983% %
1984% N e w M a g i c k I m a g e %
1985% %
1986% %
1987% %
1988%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1989%
1990% NewMagickImage() creates a blank image canvas of the specified size and
1991% background color.
1992%
1993% The format of the NewMagickImage method is:
1994%
cristy44410ab2014-05-25 20:39:43 +00001995% Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
1996% const size_t height,const PixelInfo *background,
cristy0740a982011-10-13 15:01:01 +00001997% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001998%
1999% A description of each parameter follows:
2000%
2001% o image: the image.
2002%
2003% o width: the image width.
2004%
2005% o height: the image height.
2006%
2007% o background: the image color.
2008%
cristy0740a982011-10-13 15:01:01 +00002009% o exception: return any errors or warnings in this structure.
2010%
cristy3ed852e2009-09-05 21:47:34 +00002011*/
2012MagickExport Image *NewMagickImage(const ImageInfo *image_info,
cristy0740a982011-10-13 15:01:01 +00002013 const size_t width,const size_t height,const PixelInfo *background,
2014 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002015{
2016 CacheView
2017 *image_view;
2018
cristy3ed852e2009-09-05 21:47:34 +00002019 Image
2020 *image;
2021
cristy3ed852e2009-09-05 21:47:34 +00002022 MagickBooleanType
2023 status;
2024
cristya905c052011-09-17 22:37:55 +00002025 ssize_t
2026 y;
2027
cristy3ed852e2009-09-05 21:47:34 +00002028 assert(image_info != (const ImageInfo *) NULL);
2029 if (image_info->debug != MagickFalse)
2030 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2031 assert(image_info->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +00002032 assert(background != (const PixelInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00002033 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00002034 image->columns=width;
2035 image->rows=height;
2036 image->colorspace=background->colorspace;
cristy8a46d822012-08-28 23:32:39 +00002037 image->alpha_trait=background->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +00002038 image->fuzz=background->fuzz;
2039 image->depth=background->depth;
2040 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002041 image_view=AcquireAuthenticCacheView(image,exception);
cristy48974b92009-12-19 02:36:06 +00002042#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00002043 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00002044 magick_threads(image,image,image->rows,1)
cristy48974b92009-12-19 02:36:06 +00002045#endif
cristybb503372010-05-27 20:51:26 +00002046 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002047 {
cristy4c08aed2011-07-01 19:47:50 +00002048 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002049 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002050
cristycb6d09b2010-06-19 01:59:36 +00002051 register ssize_t
2052 x;
2053
cristy48974b92009-12-19 02:36:06 +00002054 if (status == MagickFalse)
2055 continue;
cristy3ed852e2009-09-05 21:47:34 +00002056 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002057 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002058 {
2059 status=MagickFalse;
2060 continue;
2061 }
cristybb503372010-05-27 20:51:26 +00002062 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002063 {
cristy11a06d32015-01-04 12:03:27 +00002064 SetPixelViaPixelInfo(image,background,q);
cristyed231572011-07-14 02:18:59 +00002065 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00002066 }
2067 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2068 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002069 }
2070 image_view=DestroyCacheView(image_view);
2071 if (status == MagickFalse)
2072 image=DestroyImage(image);
2073 return(image);
2074}
2075
2076/*
2077%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2078% %
2079% %
2080% %
2081% R e f e r e n c e I m a g e %
2082% %
2083% %
2084% %
2085%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2086%
2087% ReferenceImage() increments the reference count associated with an image
2088% returning a pointer to the image.
2089%
2090% The format of the ReferenceImage method is:
2091%
2092% Image *ReferenceImage(Image *image)
2093%
2094% A description of each parameter follows:
2095%
2096% o image: the image.
2097%
2098*/
2099MagickExport Image *ReferenceImage(Image *image)
2100{
2101 assert(image != (Image *) NULL);
2102 if (image->debug != MagickFalse)
2103 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2104 assert(image->signature == MagickSignature);
cristyf84a1932010-01-03 18:00:18 +00002105 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002106 image->reference_count++;
cristyf84a1932010-01-03 18:00:18 +00002107 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002108 return(image);
2109}
2110
2111/*
2112%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2113% %
2114% %
2115% %
2116% R e s e t I m a g e P a g e %
2117% %
2118% %
2119% %
2120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2121%
2122% ResetImagePage() resets the image page canvas and position.
2123%
2124% The format of the ResetImagePage method is:
2125%
2126% MagickBooleanType ResetImagePage(Image *image,const char *page)
2127%
2128% A description of each parameter follows:
2129%
2130% o image: the image.
2131%
2132% o page: the relative page specification.
2133%
2134*/
2135MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2136{
2137 MagickStatusType
2138 flags;
2139
2140 RectangleInfo
2141 geometry;
2142
2143 assert(image != (Image *) NULL);
2144 assert(image->signature == MagickSignature);
2145 if (image->debug != MagickFalse)
2146 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2147 flags=ParseAbsoluteGeometry(page,&geometry);
2148 if ((flags & WidthValue) != 0)
2149 {
2150 if ((flags & HeightValue) == 0)
2151 geometry.height=geometry.width;
2152 image->page.width=geometry.width;
2153 image->page.height=geometry.height;
2154 }
2155 if ((flags & AspectValue) != 0)
2156 {
2157 if ((flags & XValue) != 0)
2158 image->page.x+=geometry.x;
2159 if ((flags & YValue) != 0)
2160 image->page.y+=geometry.y;
2161 }
2162 else
2163 {
2164 if ((flags & XValue) != 0)
2165 {
2166 image->page.x=geometry.x;
2167 if ((image->page.width == 0) && (geometry.x > 0))
2168 image->page.width=image->columns+geometry.x;
2169 }
2170 if ((flags & YValue) != 0)
2171 {
2172 image->page.y=geometry.y;
2173 if ((image->page.height == 0) && (geometry.y > 0))
2174 image->page.height=image->rows+geometry.y;
2175 }
2176 }
2177 return(MagickTrue);
2178}
2179
2180/*
2181%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2182% %
2183% %
2184% %
cristy3ed852e2009-09-05 21:47:34 +00002185% S e t I m a g e B a c k g r o u n d C o l o r %
2186% %
2187% %
2188% %
2189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2190%
2191% SetImageBackgroundColor() initializes the image pixels to the image
2192% background color. The background color is defined by the background_color
2193% member of the image structure.
2194%
2195% The format of the SetImage method is:
2196%
cristyea1a8aa2011-10-20 13:24:06 +00002197% MagickBooleanType SetImageBackgroundColor(Image *image,
2198% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002199%
2200% A description of each parameter follows:
2201%
2202% o image: the image.
2203%
cristyea1a8aa2011-10-20 13:24:06 +00002204% o exception: return any errors or warnings in this structure.
2205%
cristy3ed852e2009-09-05 21:47:34 +00002206*/
cristyea1a8aa2011-10-20 13:24:06 +00002207MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2208 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002209{
2210 CacheView
2211 *image_view;
2212
cristy3ed852e2009-09-05 21:47:34 +00002213 MagickBooleanType
2214 status;
2215
dirkdc896c12014-10-15 16:28:15 +00002216 PixelInfo
2217 background;
2218
cristycb6d09b2010-06-19 01:59:36 +00002219 ssize_t
2220 y;
2221
cristy3ed852e2009-09-05 21:47:34 +00002222 assert(image != (Image *) NULL);
2223 if (image->debug != MagickFalse)
2224 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2225 assert(image->signature == MagickSignature);
cristy574cc262011-08-05 01:23:58 +00002226 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002227 return(MagickFalse);
dirkbfdd5bc2014-11-04 19:47:44 +00002228 ConformPixelInfo(image,&image->background_color,&background,exception);
cristy3ed852e2009-09-05 21:47:34 +00002229 /*
2230 Set image background color.
2231 */
2232 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002233 image_view=AcquireAuthenticCacheView(image,exception);
cristybb503372010-05-27 20:51:26 +00002234 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002235 {
cristy4c08aed2011-07-01 19:47:50 +00002236 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002237 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002238
cristycb6d09b2010-06-19 01:59:36 +00002239 register ssize_t
2240 x;
2241
cristy3ed852e2009-09-05 21:47:34 +00002242 if (status == MagickFalse)
2243 continue;
2244 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002245 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002246 {
2247 status=MagickFalse;
2248 continue;
2249 }
cristybb503372010-05-27 20:51:26 +00002250 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +00002251 {
cristy11a06d32015-01-04 12:03:27 +00002252 SetPixelViaPixelInfo(image,&background,q);
cristyed231572011-07-14 02:18:59 +00002253 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002254 }
cristy3ed852e2009-09-05 21:47:34 +00002255 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2256 status=MagickFalse;
2257 }
2258 image_view=DestroyCacheView(image_view);
2259 return(status);
2260}
2261
2262/*
2263%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2264% %
2265% %
2266% %
cristycf1296e2012-08-26 23:40:49 +00002267% S e t I m a g e C h a n n e l M a s k %
2268% %
2269% %
2270% %
2271%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2272%
2273% SetImageChannelMask() sets the image channel mask from the specified channel
2274% mask.
2275%
2276% The format of the SetImageChannelMask method is:
2277%
2278% ChannelType SetImageChannelMask(Image *image,
2279% const ChannelType channel_mask)
2280%
2281% A description of each parameter follows:
2282%
2283% o image: the image.
2284%
2285% o channel_mask: the channel mask.
2286%
2287*/
2288MagickExport ChannelType SetImageChannelMask(Image *image,
2289 const ChannelType channel_mask)
2290{
cristybcd59342015-06-07 14:07:19 +00002291 return(SetPixelChannelMask(image,channel_mask));
cristycf1296e2012-08-26 23:40:49 +00002292}
2293
2294/*
2295%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2296% %
2297% %
2298% %
cristya5b77cb2010-05-07 19:34:48 +00002299% S e t I m a g e C o l o r %
2300% %
2301% %
2302% %
2303%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2304%
2305% SetImageColor() set the entire image canvas to the specified color.
2306%
2307% The format of the SetImageColor method is:
2308%
cristye941a752011-10-15 01:52:48 +00002309% MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2310% ExeptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002311%
2312% A description of each parameter follows:
2313%
2314% o image: the image.
2315%
2316% o background: the image color.
2317%
cristye941a752011-10-15 01:52:48 +00002318% o exception: return any errors or warnings in this structure.
2319%
cristya5b77cb2010-05-07 19:34:48 +00002320*/
2321MagickExport MagickBooleanType SetImageColor(Image *image,
cristye941a752011-10-15 01:52:48 +00002322 const PixelInfo *color,ExceptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002323{
2324 CacheView
2325 *image_view;
2326
cristya5b77cb2010-05-07 19:34:48 +00002327 MagickBooleanType
2328 status;
2329
cristycb6d09b2010-06-19 01:59:36 +00002330 ssize_t
2331 y;
2332
cristya5b77cb2010-05-07 19:34:48 +00002333 assert(image != (Image *) NULL);
2334 if (image->debug != MagickFalse)
2335 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2336 assert(image->signature == MagickSignature);
cristy4c08aed2011-07-01 19:47:50 +00002337 assert(color != (const PixelInfo *) NULL);
cristya5b77cb2010-05-07 19:34:48 +00002338 image->colorspace=color->colorspace;
cristy8a46d822012-08-28 23:32:39 +00002339 image->alpha_trait=color->alpha_trait;
cristya5b77cb2010-05-07 19:34:48 +00002340 image->fuzz=color->fuzz;
2341 image->depth=color->depth;
2342 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002343 image_view=AcquireAuthenticCacheView(image,exception);
cristya5b77cb2010-05-07 19:34:48 +00002344#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00002345 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00002346 magick_threads(image,image,image->rows,1)
cristya5b77cb2010-05-07 19:34:48 +00002347#endif
cristybb503372010-05-27 20:51:26 +00002348 for (y=0; y < (ssize_t) image->rows; y++)
cristya5b77cb2010-05-07 19:34:48 +00002349 {
cristy4c08aed2011-07-01 19:47:50 +00002350 register Quantum
cristya5b77cb2010-05-07 19:34:48 +00002351 *restrict q;
2352
cristycb6d09b2010-06-19 01:59:36 +00002353 register ssize_t
2354 x;
2355
cristya5b77cb2010-05-07 19:34:48 +00002356 if (status == MagickFalse)
2357 continue;
2358 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002359 if (q == (Quantum *) NULL)
cristya5b77cb2010-05-07 19:34:48 +00002360 {
2361 status=MagickFalse;
2362 continue;
2363 }
cristybb503372010-05-27 20:51:26 +00002364 for (x=0; x < (ssize_t) image->columns; x++)
cristya5b77cb2010-05-07 19:34:48 +00002365 {
cristy11a06d32015-01-04 12:03:27 +00002366 SetPixelViaPixelInfo(image,color,q);
cristyed231572011-07-14 02:18:59 +00002367 q+=GetPixelChannels(image);
cristya5b77cb2010-05-07 19:34:48 +00002368 }
2369 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2370 status=MagickFalse;
2371 }
2372 image_view=DestroyCacheView(image_view);
2373 return(status);
2374}
2375
2376/*
2377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2378% %
2379% %
2380% %
cristy3ed852e2009-09-05 21:47:34 +00002381% S e t I m a g e S t o r a g e C l a s s %
2382% %
2383% %
2384% %
2385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2386%
2387% SetImageStorageClass() sets the image class: DirectClass for true color
2388% images or PseudoClass for colormapped images.
2389%
2390% The format of the SetImageStorageClass method is:
2391%
2392% MagickBooleanType SetImageStorageClass(Image *image,
cristy63240882011-08-05 19:05:27 +00002393% const ClassType storage_class,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 storage_class: The image class.
2400%
cristy574cc262011-08-05 01:23:58 +00002401% o exception: return any errors or warnings in this structure.
2402%
cristy3ed852e2009-09-05 21:47:34 +00002403*/
2404MagickExport MagickBooleanType SetImageStorageClass(Image *image,
cristy574cc262011-08-05 01:23:58 +00002405 const ClassType storage_class,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002406{
cristy3ed852e2009-09-05 21:47:34 +00002407 image->storage_class=storage_class;
cristy6e437132011-08-12 13:02:19 +00002408 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002409}
2410
2411/*
2412%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2413% %
2414% %
2415% %
cristy3ed852e2009-09-05 21:47:34 +00002416% S e t I m a g e E x t e n t %
2417% %
2418% %
2419% %
2420%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2421%
2422% SetImageExtent() sets the image size (i.e. columns & rows).
2423%
2424% The format of the SetImageExtent method is:
2425%
cristy08429172011-07-14 17:18:16 +00002426% MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002427% const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002428%
2429% A description of each parameter follows:
2430%
2431% o image: the image.
2432%
2433% o columns: The image width in pixels.
2434%
2435% o rows: The image height in pixels.
2436%
cristy63240882011-08-05 19:05:27 +00002437% o exception: return any errors or warnings in this structure.
2438%
cristy3ed852e2009-09-05 21:47:34 +00002439*/
cristy08429172011-07-14 17:18:16 +00002440MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002441 const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002442{
cristy537e2722010-09-21 15:30:59 +00002443 if ((columns == 0) || (rows == 0))
2444 return(MagickFalse);
2445 image->columns=columns;
2446 image->rows=rows;
cristy6e437132011-08-12 13:02:19 +00002447 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002448}
2449
2450/*
2451%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2452% %
2453% %
2454% %
2455+ S e t I m a g e I n f o %
2456% %
2457% %
2458% %
2459%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2460%
anthonye5b39652012-04-21 05:37:29 +00002461% SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
cristy3ed852e2009-09-05 21:47:34 +00002462% It is set to a type of image format based on the prefix or suffix of the
anthonye5b39652012-04-21 05:37:29 +00002463% filename. For example, 'ps:image' returns PS indicating a Postscript image.
2464% JPEG is returned for this filename: 'image.jpg'. The filename prefix has
cristy3ed852e2009-09-05 21:47:34 +00002465% precendence over the suffix. Use an optional index enclosed in brackets
2466% after a file name to specify a desired scene of a multi-resolution image
2467% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2468% indicates success.
2469%
2470% The format of the SetImageInfo method is:
2471%
2472% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002473% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002474%
2475% A description of each parameter follows:
2476%
cristyd965a422010-03-03 17:47:35 +00002477% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00002478%
cristyd965a422010-03-03 17:47:35 +00002479% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00002480%
2481% o exception: return any errors or warnings in this structure.
2482%
2483*/
2484MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002485 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002486{
2487 char
dirk8f681612015-04-16 21:05:08 +00002488 component[MagickPathExtent],
cristy151b66d2015-04-15 10:50:31 +00002489 magic[MagickPathExtent],
dirk8f681612015-04-16 21:05:08 +00002490 *q;
cristy3ed852e2009-09-05 21:47:34 +00002491
2492 const MagicInfo
2493 *magic_info;
2494
2495 const MagickInfo
2496 *magick_info;
2497
2498 ExceptionInfo
2499 *sans_exception;
2500
2501 Image
2502 *image;
2503
2504 MagickBooleanType
2505 status;
2506
2507 register const char
2508 *p;
2509
2510 ssize_t
2511 count;
2512
cristy3ed852e2009-09-05 21:47:34 +00002513 /*
2514 Look for 'image.format' in filename.
2515 */
2516 assert(image_info != (ImageInfo *) NULL);
2517 assert(image_info->signature == MagickSignature);
2518 if (image_info->debug != MagickFalse)
2519 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2520 image_info->filename);
dirk8f681612015-04-16 21:05:08 +00002521 *component='\0';
2522 GetPathComponent(image_info->filename,SubimagePath,component);
2523 if (*component != '\0')
cristy3ed852e2009-09-05 21:47:34 +00002524 {
cristy4f96a1d2014-01-04 15:31:36 +00002525 /*
2526 Look for scene specification (e.g. img0001.pcd[4]).
2527 */
dirk8f681612015-04-16 21:05:08 +00002528 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002529 {
dirk8f681612015-04-16 21:05:08 +00002530 if (IsGeometry(component) != MagickFalse)
2531 (void) CloneString(&image_info->extract,component);
cristy4f96a1d2014-01-04 15:31:36 +00002532 }
2533 else
2534 {
2535 size_t
2536 first,
2537 last;
cristy3ed852e2009-09-05 21:47:34 +00002538
dirk8f681612015-04-16 21:05:08 +00002539 (void) CloneString(&image_info->scenes,component);
cristy4f96a1d2014-01-04 15:31:36 +00002540 image_info->scene=StringToUnsignedLong(image_info->scenes);
2541 image_info->number_scenes=image_info->scene;
2542 p=image_info->scenes;
2543 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2544 {
2545 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2546 p++;
2547 first=(size_t) strtol(p,&q,10);
2548 last=first;
2549 while (isspace((int) ((unsigned char) *q)) != 0)
2550 q++;
2551 if (*q == '-')
2552 last=(size_t) strtol(q+1,&q,10);
2553 if (first > last)
2554 Swap(first,last);
2555 if (first < image_info->scene)
2556 image_info->scene=first;
2557 if (last > image_info->number_scenes)
2558 image_info->number_scenes=last;
2559 p=q;
2560 }
2561 image_info->number_scenes-=image_info->scene-1;
cristy3ed852e2009-09-05 21:47:34 +00002562 }
2563 }
dirk8f681612015-04-16 21:05:08 +00002564 *component='\0';
cristy6f7cebf2014-12-27 12:10:39 +00002565 if (*image_info->magick == '\0')
dirk8f681612015-04-16 21:05:08 +00002566 GetPathComponent(image_info->filename,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002567#if defined(MAGICKCORE_ZLIB_DELEGATE)
dirk8f681612015-04-16 21:05:08 +00002568 if (*component != '\0')
2569 if ((LocaleCompare(component,"gz") == 0) ||
2570 (LocaleCompare(component,"Z") == 0) ||
2571 (LocaleCompare(component,"svgz") == 0) ||
2572 (LocaleCompare(component,"wmz") == 0))
cristy3ed852e2009-09-05 21:47:34 +00002573 {
2574 char
cristy151b66d2015-04-15 10:50:31 +00002575 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002576
cristy151b66d2015-04-15 10:50:31 +00002577 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
dirk8f681612015-04-16 21:05:08 +00002578 path[strlen(path)-strlen(component)-1]='\0';
2579 GetPathComponent(path,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002580 }
2581#endif
2582#if defined(MAGICKCORE_BZLIB_DELEGATE)
dirk8f681612015-04-16 21:05:08 +00002583 if (*component != '\0')
2584 if (LocaleCompare(component,"bz2") == 0)
cristy3ed852e2009-09-05 21:47:34 +00002585 {
2586 char
cristy151b66d2015-04-15 10:50:31 +00002587 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002588
cristy151b66d2015-04-15 10:50:31 +00002589 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
dirk8f681612015-04-16 21:05:08 +00002590 path[strlen(path)-strlen(component)-1]='\0';
2591 GetPathComponent(path,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002592 }
2593#endif
2594 image_info->affirm=MagickFalse;
2595 sans_exception=AcquireExceptionInfo();
dirk8f681612015-04-16 21:05:08 +00002596 if (*component != '\0')
cristy3ed852e2009-09-05 21:47:34 +00002597 {
2598 MagickFormatType
2599 format_type;
2600
cristybb503372010-05-27 20:51:26 +00002601 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002602 i;
2603
2604 static const char
2605 *format_type_formats[] =
2606 {
2607 "AUTOTRACE",
2608 "BROWSE",
2609 "DCRAW",
2610 "EDIT",
2611 "EPHEMERAL",
2612 "LAUNCH",
2613 "MPEG:DECODE",
2614 "MPEG:ENCODE",
2615 "PRINT",
2616 "PS:ALPHA",
2617 "PS:CMYK",
2618 "PS:COLOR",
2619 "PS:GRAY",
2620 "PS:MONO",
2621 "SCAN",
2622 "SHOW",
2623 "WIN",
2624 (char *) NULL
2625 };
2626
2627 /*
2628 User specified image format.
2629 */
dirk8f681612015-04-16 21:05:08 +00002630 (void) CopyMagickString(magic,component,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002631 LocaleUpper(magic);
2632 /*
2633 Look for explicit image formats.
2634 */
2635 format_type=UndefinedFormatType;
dirk80fd8af2015-02-22 00:45:51 +00002636 magick_info=GetMagickInfo(magic,sans_exception);
2637 if ((magick_info != (const MagickInfo *) NULL) &&
2638 (magick_info->format_type != UndefinedFormatType))
2639 format_type=magick_info->format_type;
cristy3ed852e2009-09-05 21:47:34 +00002640 i=0;
cristydd9a2532010-02-20 19:26:46 +00002641 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00002642 (format_type_formats[i] != (char *) NULL))
2643 {
2644 if ((*magic == *format_type_formats[i]) &&
2645 (LocaleCompare(magic,format_type_formats[i]) == 0))
2646 format_type=ExplicitFormatType;
2647 i++;
2648 }
cristy3ed852e2009-09-05 21:47:34 +00002649 if (format_type == UndefinedFormatType)
cristy151b66d2015-04-15 10:50:31 +00002650 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002651 else
2652 if (format_type == ExplicitFormatType)
2653 {
2654 image_info->affirm=MagickTrue;
cristy151b66d2015-04-15 10:50:31 +00002655 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002656 }
2657 if (LocaleCompare(magic,"RGB") == 0)
2658 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2659 }
2660 /*
2661 Look for explicit 'format:image' in filename.
2662 */
2663 *magic='\0';
2664 GetPathComponent(image_info->filename,MagickPath,magic);
2665 if (*magic == '\0')
cristy151b66d2015-04-15 10:50:31 +00002666 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002667 else
2668 {
2669 /*
2670 User specified image format.
2671 */
2672 LocaleUpper(magic);
2673 if (IsMagickConflict(magic) == MagickFalse)
2674 {
cristy151b66d2015-04-15 10:50:31 +00002675 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002676 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2677 image_info->affirm=MagickTrue;
2678 else
2679 image_info->temporary=MagickTrue;
2680 }
2681 }
2682 magick_info=GetMagickInfo(magic,sans_exception);
2683 sans_exception=DestroyExceptionInfo(sans_exception);
2684 if ((magick_info == (const MagickInfo *) NULL) ||
2685 (GetMagickEndianSupport(magick_info) == MagickFalse))
2686 image_info->endian=UndefinedEndian;
dirk8f681612015-04-16 21:05:08 +00002687 GetPathComponent(image_info->filename,CanonicalPath,component);
2688 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002689 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00002690 {
2691 /*
cristyd965a422010-03-03 17:47:35 +00002692 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00002693 */
cristyd965a422010-03-03 17:47:35 +00002694 (void) InterpretImageFilename(image_info,(Image *) NULL,
dirk8f681612015-04-16 21:05:08 +00002695 image_info->filename,(int) image_info->scene,component,exception);
2696 if ((LocaleCompare(component,image_info->filename) != 0) &&
2697 (strchr(component,'%') == (char *) NULL))
cristyd965a422010-03-03 17:47:35 +00002698 image_info->adjoin=MagickFalse;
2699 }
2700 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2701 {
2702 /*
2703 Some image formats do not support multiple frames per file.
2704 */
cristy3ed852e2009-09-05 21:47:34 +00002705 magick_info=GetMagickInfo(magic,exception);
2706 if (magick_info != (const MagickInfo *) NULL)
2707 if (GetMagickAdjoin(magick_info) == MagickFalse)
2708 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002709 }
2710 if (image_info->affirm != MagickFalse)
2711 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00002712 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00002713 {
dirk8f681612015-04-16 21:05:08 +00002714 unsigned char
2715 *magick;
2716
2717 size_t
2718 magick_size;
2719
cristy3ed852e2009-09-05 21:47:34 +00002720 /*
cristyd965a422010-03-03 17:47:35 +00002721 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00002722 */
cristy4f06b882015-04-17 00:16:45 +00002723 magick_size=GetMagicPatternExtent(exception);
dirk8f681612015-04-16 21:05:08 +00002724 if (magick_size == 0)
2725 return(MagickFalse);
cristy9950d572011-10-01 18:22:35 +00002726 image=AcquireImage(image_info,exception);
cristyd965a422010-03-03 17:47:35 +00002727 (void) CopyMagickString(image->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00002728 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002729 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2730 if (status == MagickFalse)
2731 {
2732 image=DestroyImage(image);
2733 return(MagickFalse);
2734 }
cristyd965a422010-03-03 17:47:35 +00002735 if ((IsBlobSeekable(image) == MagickFalse) ||
2736 (IsBlobExempt(image) != MagickFalse))
2737 {
2738 /*
2739 Copy standard input or pipe to temporary file.
2740 */
dirk8f681612015-04-16 21:05:08 +00002741 *component='\0';
2742 status=ImageToFile(image,component,exception);
cristyd965a422010-03-03 17:47:35 +00002743 (void) CloseBlob(image);
2744 if (status == MagickFalse)
2745 {
2746 image=DestroyImage(image);
2747 return(MagickFalse);
2748 }
2749 SetImageInfoFile(image_info,(FILE *) NULL);
dirk8f681612015-04-16 21:05:08 +00002750 (void) CopyMagickString(image->filename,component,MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002751 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2752 if (status == MagickFalse)
2753 {
2754 image=DestroyImage(image);
2755 return(MagickFalse);
2756 }
dirk8f681612015-04-16 21:05:08 +00002757 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002758 image_info->temporary=MagickTrue;
2759 }
dirk8f681612015-04-16 21:05:08 +00002760 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2761 if (magick == (unsigned char *) NULL)
2762 {
2763 (void) CloseBlob(image);
2764 image=DestroyImage(image);
2765 return(MagickFalse);
2766 }
2767 (void) ResetMagickMemory(magick,0,magick_size);
2768 count=ReadBlob(image,magick_size,magick);
cristyae958042013-01-05 15:48:19 +00002769 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
cristyd965a422010-03-03 17:47:35 +00002770 (void) CloseBlob(image);
2771 image=DestroyImage(image);
2772 /*
2773 Check magic.xml configuration file.
2774 */
2775 sans_exception=AcquireExceptionInfo();
2776 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
dirk8f681612015-04-16 21:05:08 +00002777 magick=(unsigned char *) RelinquishMagickMemory(magick);
cristyd965a422010-03-03 17:47:35 +00002778 if ((magic_info != (const MagicInfo *) NULL) &&
2779 (GetMagicName(magic_info) != (char *) NULL))
2780 {
dirkca89a9b2015-02-22 01:19:21 +00002781 /*
2782 Try to use magick_info that was determined earlier by the extension
2783 */
2784 if ((magick_info != (const MagickInfo *) NULL) &&
2785 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2786 (LocaleCompare(magick_info->module,GetMagicName(
2787 magic_info)) == 0))
2788 (void) CopyMagickString(image_info->magick,magick_info->name,
cristy151b66d2015-04-15 10:50:31 +00002789 MagickPathExtent);
dirkca89a9b2015-02-22 01:19:21 +00002790 else
2791 {
2792 (void) CopyMagickString(image_info->magick,GetMagicName(
cristy151b66d2015-04-15 10:50:31 +00002793 magic_info),MagickPathExtent);
dirkca89a9b2015-02-22 01:19:21 +00002794 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2795 }
cristyd965a422010-03-03 17:47:35 +00002796 if ((magick_info == (const MagickInfo *) NULL) ||
2797 (GetMagickEndianSupport(magick_info) == MagickFalse))
2798 image_info->endian=UndefinedEndian;
2799 sans_exception=DestroyExceptionInfo(sans_exception);
2800 return(MagickTrue);
2801 }
cristy3ed852e2009-09-05 21:47:34 +00002802 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2803 if ((magick_info == (const MagickInfo *) NULL) ||
2804 (GetMagickEndianSupport(magick_info) == MagickFalse))
2805 image_info->endian=UndefinedEndian;
2806 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00002807 }
cristy3ed852e2009-09-05 21:47:34 +00002808 return(MagickTrue);
2809}
2810
2811/*
2812%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2813% %
2814% %
2815% %
2816% S e t I m a g e I n f o B l o b %
2817% %
2818% %
2819% %
2820%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2821%
2822% SetImageInfoBlob() sets the image info blob member.
2823%
2824% The format of the SetImageInfoBlob method is:
2825%
2826% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2827% const size_t length)
2828%
2829% A description of each parameter follows:
2830%
2831% o image_info: the image info.
2832%
2833% o blob: the blob.
2834%
2835% o length: the blob length.
2836%
2837*/
2838MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2839 const size_t length)
2840{
2841 assert(image_info != (ImageInfo *) NULL);
2842 assert(image_info->signature == MagickSignature);
2843 if (image_info->debug != MagickFalse)
2844 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2845 image_info->filename);
2846 image_info->blob=(void *) blob;
2847 image_info->length=length;
2848}
2849
2850/*
2851%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2852% %
2853% %
2854% %
2855% S e t I m a g e I n f o F i l e %
2856% %
2857% %
2858% %
2859%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2860%
2861% SetImageInfoFile() sets the image info file member.
2862%
2863% The format of the SetImageInfoFile method is:
2864%
2865% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2866%
2867% A description of each parameter follows:
2868%
2869% o image_info: the image info.
2870%
2871% o file: the file.
2872%
2873*/
2874MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2875{
2876 assert(image_info != (ImageInfo *) NULL);
2877 assert(image_info->signature == MagickSignature);
2878 if (image_info->debug != MagickFalse)
2879 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2880 image_info->filename);
2881 image_info->file=file;
2882}
2883
2884/*
2885%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2886% %
2887% %
2888% %
2889% S e t I m a g e M a s k %
2890% %
2891% %
2892% %
2893%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2894%
2895% SetImageMask() associates a mask with the image. The mask must be the same
2896% dimensions as the image.
2897%
2898% The format of the SetImageMask method is:
2899%
cristy018f07f2011-09-04 21:15:19 +00002900% MagickBooleanType SetImageMask(Image *image,const Image *mask,
2901% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002902%
2903% A description of each parameter follows:
2904%
2905% o image: the image.
2906%
2907% o mask: the image mask.
2908%
cristy018f07f2011-09-04 21:15:19 +00002909% o exception: return any errors or warnings in this structure.
2910%
cristy3ed852e2009-09-05 21:47:34 +00002911*/
cristy10a6c612012-01-29 21:41:05 +00002912MagickExport MagickBooleanType SetImageMask(Image *image,const Image *mask,
2913 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002914{
cristy10a6c612012-01-29 21:41:05 +00002915 CacheView
2916 *mask_view,
2917 *image_view;
2918
2919 MagickBooleanType
2920 status;
2921
2922 ssize_t
2923 y;
2924
2925 /*
2926 Set image mask.
2927 */
cristy3ed852e2009-09-05 21:47:34 +00002928 assert(image != (Image *) NULL);
2929 if (image->debug != MagickFalse)
2930 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
2931 assert(image->signature == MagickSignature);
cristy10a6c612012-01-29 21:41:05 +00002932 if (mask == (const Image *) NULL)
2933 {
cristy883fde12013-04-08 00:50:13 +00002934 image->read_mask=MagickFalse;
cristyd5be1f12013-03-18 23:55:01 +00002935 return(SyncImagePixelCache(image,exception));
cristy10a6c612012-01-29 21:41:05 +00002936 }
cristy883fde12013-04-08 00:50:13 +00002937 image->read_mask=MagickTrue;
cristyd5be1f12013-03-18 23:55:01 +00002938 if (SyncImagePixelCache(image,exception) == MagickFalse)
2939 return(MagickFalse);
2940 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002941 mask_view=AcquireVirtualCacheView(mask,exception);
2942 image_view=AcquireAuthenticCacheView(image,exception);
cristyd5be1f12013-03-18 23:55:01 +00002943#if defined(MAGICKCORE_OPENMP_SUPPORT)
2944 #pragma omp parallel for schedule(static,4) shared(status) \
2945 magick_threads(mask,image,1,1)
2946#endif
cristy10a6c612012-01-29 21:41:05 +00002947 for (y=0; y < (ssize_t) image->rows; y++)
2948 {
2949 register const Quantum
2950 *restrict p;
2951
2952 register Quantum
2953 *restrict q;
2954
2955 register ssize_t
2956 x;
2957
2958 if (status == MagickFalse)
2959 continue;
2960 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2961 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2962 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2963 {
2964 status=MagickFalse;
2965 continue;
2966 }
2967 for (x=0; x < (ssize_t) image->columns; x++)
2968 {
cristy883fde12013-04-08 00:50:13 +00002969 SetPixelReadMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
cristy10a6c612012-01-29 21:41:05 +00002970 p+=GetPixelChannels(mask);
2971 q+=GetPixelChannels(image);
2972 }
2973 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2974 status=MagickFalse;
2975 }
2976 mask_view=DestroyCacheView(mask_view);
2977 image_view=DestroyCacheView(image_view);
2978 return(status);
cristy3ed852e2009-09-05 21:47:34 +00002979}
2980
2981/*
2982%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2983% %
2984% %
2985% %
cristyb6a294d2011-10-03 00:55:17 +00002986% S e t I m a g e A l p h a %
cristy3ed852e2009-09-05 21:47:34 +00002987% %
2988% %
2989% %
2990%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2991%
cristye941a752011-10-15 01:52:48 +00002992% SetImageAlpha() sets the alpha levels of the image.
cristy3ed852e2009-09-05 21:47:34 +00002993%
cristyb6a294d2011-10-03 00:55:17 +00002994% The format of the SetImageAlpha method is:
cristy3ed852e2009-09-05 21:47:34 +00002995%
cristye941a752011-10-15 01:52:48 +00002996% MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
2997% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002998%
2999% A description of each parameter follows:
3000%
3001% o image: the image.
3002%
cristyb6a294d2011-10-03 00:55:17 +00003003% o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
cristy3ed852e2009-09-05 21:47:34 +00003004% fully transparent.
3005%
3006*/
cristye941a752011-10-15 01:52:48 +00003007MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3008 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003009{
3010 CacheView
3011 *image_view;
3012
cristy3ed852e2009-09-05 21:47:34 +00003013 MagickBooleanType
3014 status;
3015
cristycb6d09b2010-06-19 01:59:36 +00003016 ssize_t
3017 y;
3018
cristy3ed852e2009-09-05 21:47:34 +00003019 assert(image != (Image *) NULL);
3020 if (image->debug != MagickFalse)
3021 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3022 assert(image->signature == MagickSignature);
cristy8a46d822012-08-28 23:32:39 +00003023 image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00003024 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00003025 image_view=AcquireAuthenticCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003026#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003027 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00003028 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003029#endif
cristybb503372010-05-27 20:51:26 +00003030 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003031 {
cristy4c08aed2011-07-01 19:47:50 +00003032 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003033 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003034
cristycb6d09b2010-06-19 01:59:36 +00003035 register ssize_t
3036 x;
3037
cristy3ed852e2009-09-05 21:47:34 +00003038 if (status == MagickFalse)
3039 continue;
3040 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00003041 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003042 {
3043 status=MagickFalse;
3044 continue;
3045 }
cristybb503372010-05-27 20:51:26 +00003046 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003047 {
cristy718128d2014-09-24 12:29:52 +00003048 if (GetPixelReadMask(image,q) == 0)
3049 {
3050 q+=GetPixelChannels(image);
3051 continue;
3052 }
3053 SetPixelAlpha(image,alpha,q);
cristyed231572011-07-14 02:18:59 +00003054 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00003055 }
3056 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3057 status=MagickFalse;
3058 }
3059 image_view=DestroyCacheView(image_view);
3060 return(status);
3061}
3062
3063/*
3064%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3065% %
3066% %
3067% %
cristy3ed852e2009-09-05 21:47:34 +00003068% 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 %
3069% %
3070% %
3071% %
3072%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3073%
3074% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3075% image and returns the previous setting. A virtual pixel is any pixel access
3076% that is outside the boundaries of the image cache.
3077%
3078% The format of the SetImageVirtualPixelMethod() method is:
3079%
cristy387430f2012-02-07 13:09:46 +00003080% VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3081% const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003082%
3083% A description of each parameter follows:
3084%
3085% o image: the image.
3086%
3087% o virtual_pixel_method: choose the type of virtual pixel.
3088%
cristy387430f2012-02-07 13:09:46 +00003089% o exception: return any errors or warnings in this structure.
3090%
cristy3ed852e2009-09-05 21:47:34 +00003091*/
cristy387430f2012-02-07 13:09:46 +00003092MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3093 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003094{
3095 assert(image != (const Image *) NULL);
3096 assert(image->signature == MagickSignature);
3097 if (image->debug != MagickFalse)
3098 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy387430f2012-02-07 13:09:46 +00003099 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
cristy3ed852e2009-09-05 21:47:34 +00003100}
3101
3102/*
3103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3104% %
3105% %
3106% %
cristy4285d782011-02-09 20:12:28 +00003107% S m u s h I m a g e s %
3108% %
3109% %
3110% %
3111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3112%
3113% SmushImages() takes all images from the current image pointer to the end
3114% of the image list and smushes them to each other top-to-bottom if the
3115% stack parameter is true, otherwise left-to-right.
3116%
3117% The current gravity setting now effects how the image is justified in the
3118% final image.
3119%
3120% The format of the SmushImages method is:
3121%
cristy4ca38e22011-02-10 02:57:49 +00003122% Image *SmushImages(const Image *images,const MagickBooleanType stack,
cristy4285d782011-02-09 20:12:28 +00003123% ExceptionInfo *exception)
3124%
3125% A description of each parameter follows:
3126%
cristy4ca38e22011-02-10 02:57:49 +00003127% o images: the image sequence.
cristy4285d782011-02-09 20:12:28 +00003128%
3129% o stack: A value other than 0 stacks the images top-to-bottom.
3130%
3131% o offset: minimum distance in pixels between images.
3132%
3133% o exception: return any errors or warnings in this structure.
3134%
3135*/
cristy4ca38e22011-02-10 02:57:49 +00003136
cristy7c6dc152011-02-11 14:10:55 +00003137static ssize_t SmushXGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003138 const ssize_t offset,ExceptionInfo *exception)
cristy4ca38e22011-02-10 02:57:49 +00003139{
cristy4d727152011-02-10 19:57:21 +00003140 CacheView
3141 *left_view,
3142 *right_view;
3143
3144 const Image
3145 *left_image,
3146 *right_image;
3147
cristy4d727152011-02-10 19:57:21 +00003148 RectangleInfo
3149 left_geometry,
3150 right_geometry;
3151
cristy4c08aed2011-07-01 19:47:50 +00003152 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003153 *p;
3154
cristy4d727152011-02-10 19:57:21 +00003155 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003156 i,
cristy4d727152011-02-10 19:57:21 +00003157 y;
3158
cristy7c6dc152011-02-11 14:10:55 +00003159 size_t
3160 gap;
3161
cristy4d727152011-02-10 19:57:21 +00003162 ssize_t
cristy4d727152011-02-10 19:57:21 +00003163 x;
3164
3165 if (images->previous == (Image *) NULL)
3166 return(0);
3167 right_image=images;
3168 SetGeometry(smush_image,&right_geometry);
3169 GravityAdjustGeometry(right_image->columns,right_image->rows,
3170 right_image->gravity,&right_geometry);
3171 left_image=images->previous;
3172 SetGeometry(smush_image,&left_geometry);
3173 GravityAdjustGeometry(left_image->columns,left_image->rows,
3174 left_image->gravity,&left_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003175 gap=right_image->columns;
cristy46ff2672012-12-14 15:32:26 +00003176 left_view=AcquireVirtualCacheView(left_image,exception);
3177 right_view=AcquireVirtualCacheView(right_image,exception);
cristy4d727152011-02-10 19:57:21 +00003178 for (y=0; y < (ssize_t) smush_image->rows; y++)
3179 {
3180 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3181 {
cristydab7e912011-02-11 18:19:24 +00003182 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003183 if ((p == (const Quantum *) NULL) ||
3184 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
cristy7c6dc152011-02-11 14:10:55 +00003185 ((left_image->columns-x-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003186 break;
3187 }
cristy4ef6f062011-02-10 20:30:22 +00003188 i=(ssize_t) left_image->columns-x-1;
cristy4d727152011-02-10 19:57:21 +00003189 for (x=0; x < (ssize_t) right_image->columns; x++)
3190 {
cristydab7e912011-02-11 18:19:24 +00003191 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
cristy279d8212011-02-10 20:05:02 +00003192 exception);
cristy4c08aed2011-07-01 19:47:50 +00003193 if ((p == (const Quantum *) NULL) ||
3194 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3195 ((x+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003196 break;
3197 }
cristy7c6dc152011-02-11 14:10:55 +00003198 if ((x+i) < (ssize_t) gap)
3199 gap=(size_t) (x+i);
cristy4d727152011-02-10 19:57:21 +00003200 }
3201 right_view=DestroyCacheView(right_view);
3202 left_view=DestroyCacheView(left_view);
cristydab7e912011-02-11 18:19:24 +00003203 if (y < (ssize_t) smush_image->rows)
3204 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003205 return((ssize_t) gap-offset);
cristyad5e6ee2011-02-10 14:26:00 +00003206}
3207
cristy7c6dc152011-02-11 14:10:55 +00003208static ssize_t SmushYGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003209 const ssize_t offset,ExceptionInfo *exception)
cristyad5e6ee2011-02-10 14:26:00 +00003210{
cristy4d727152011-02-10 19:57:21 +00003211 CacheView
3212 *bottom_view,
3213 *top_view;
3214
3215 const Image
3216 *bottom_image,
3217 *top_image;
3218
cristy4d727152011-02-10 19:57:21 +00003219 RectangleInfo
3220 bottom_geometry,
3221 top_geometry;
3222
cristy4c08aed2011-07-01 19:47:50 +00003223 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003224 *p;
3225
cristy4d727152011-02-10 19:57:21 +00003226 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003227 i,
cristy4d727152011-02-10 19:57:21 +00003228 x;
3229
cristy7c6dc152011-02-11 14:10:55 +00003230 size_t
3231 gap;
3232
cristy4d727152011-02-10 19:57:21 +00003233 ssize_t
cristy4d727152011-02-10 19:57:21 +00003234 y;
3235
3236 if (images->previous == (Image *) NULL)
3237 return(0);
3238 bottom_image=images;
3239 SetGeometry(smush_image,&bottom_geometry);
3240 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3241 bottom_image->gravity,&bottom_geometry);
3242 top_image=images->previous;
3243 SetGeometry(smush_image,&top_geometry);
3244 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3245 &top_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003246 gap=bottom_image->rows;
cristy46ff2672012-12-14 15:32:26 +00003247 top_view=AcquireVirtualCacheView(top_image,exception);
3248 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
cristy4d727152011-02-10 19:57:21 +00003249 for (x=0; x < (ssize_t) smush_image->columns; x++)
3250 {
3251 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3252 {
cristydab7e912011-02-11 18:19:24 +00003253 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003254 if ((p == (const Quantum *) NULL) ||
3255 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3256 ((top_image->rows-y-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003257 break;
3258 }
cristy4ef6f062011-02-10 20:30:22 +00003259 i=(ssize_t) top_image->rows-y-1;
cristy4d727152011-02-10 19:57:21 +00003260 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3261 {
cristydab7e912011-02-11 18:19:24 +00003262 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3263 exception);
cristy4c08aed2011-07-01 19:47:50 +00003264 if ((p == (const Quantum *) NULL) ||
3265 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3266 ((y+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003267 break;
3268 }
cristy7c6dc152011-02-11 14:10:55 +00003269 if ((y+i) < (ssize_t) gap)
3270 gap=(size_t) (y+i);
cristy4d727152011-02-10 19:57:21 +00003271 }
3272 bottom_view=DestroyCacheView(bottom_view);
3273 top_view=DestroyCacheView(top_view);
cristydab7e912011-02-11 18:19:24 +00003274 if (x < (ssize_t) smush_image->columns)
3275 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003276 return((ssize_t) gap-offset);
cristy4ca38e22011-02-10 02:57:49 +00003277}
3278
3279MagickExport Image *SmushImages(const Image *images,
cristy4285d782011-02-09 20:12:28 +00003280 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3281{
3282#define SmushImageTag "Smush/Image"
3283
cristy4ca38e22011-02-10 02:57:49 +00003284 const Image
3285 *image;
3286
cristy4285d782011-02-09 20:12:28 +00003287 Image
3288 *smush_image;
3289
3290 MagickBooleanType
cristy4285d782011-02-09 20:12:28 +00003291 proceed,
3292 status;
3293
3294 MagickOffsetType
3295 n;
3296
cristy5a5e4d92012-08-29 00:06:25 +00003297 PixelTrait
3298 alpha_trait;
3299
cristy4285d782011-02-09 20:12:28 +00003300 RectangleInfo
3301 geometry;
3302
3303 register const Image
3304 *next;
3305
3306 size_t
3307 height,
3308 number_images,
3309 width;
3310
3311 ssize_t
3312 x_offset,
cristy4285d782011-02-09 20:12:28 +00003313 y_offset;
3314
3315 /*
cristy7c6dc152011-02-11 14:10:55 +00003316 Compute maximum area of smushed area.
cristy4285d782011-02-09 20:12:28 +00003317 */
cristy4ca38e22011-02-10 02:57:49 +00003318 assert(images != (Image *) NULL);
3319 assert(images->signature == MagickSignature);
3320 if (images->debug != MagickFalse)
3321 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy4285d782011-02-09 20:12:28 +00003322 assert(exception != (ExceptionInfo *) NULL);
3323 assert(exception->signature == MagickSignature);
cristy4ca38e22011-02-10 02:57:49 +00003324 image=images;
cristy5a5e4d92012-08-29 00:06:25 +00003325 alpha_trait=image->alpha_trait;
cristy4285d782011-02-09 20:12:28 +00003326 number_images=1;
3327 width=image->columns;
3328 height=image->rows;
3329 next=GetNextImageInList(image);
3330 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3331 {
cristy17f11b02014-12-20 19:37:04 +00003332 if (next->alpha_trait != UndefinedPixelTrait)
cristy5a5e4d92012-08-29 00:06:25 +00003333 alpha_trait=BlendPixelTrait;
cristy4285d782011-02-09 20:12:28 +00003334 number_images++;
3335 if (stack != MagickFalse)
3336 {
3337 if (next->columns > width)
3338 width=next->columns;
3339 height+=next->rows;
cristy4ef6f062011-02-10 20:30:22 +00003340 if (next->previous != (Image *) NULL)
3341 height+=offset;
cristy4285d782011-02-09 20:12:28 +00003342 continue;
3343 }
3344 width+=next->columns;
cristy4ef6f062011-02-10 20:30:22 +00003345 if (next->previous != (Image *) NULL)
3346 width+=offset;
cristy4285d782011-02-09 20:12:28 +00003347 if (next->rows > height)
3348 height=next->rows;
3349 }
3350 /*
cristy7c6dc152011-02-11 14:10:55 +00003351 Smush images.
cristy4285d782011-02-09 20:12:28 +00003352 */
3353 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3354 if (smush_image == (Image *) NULL)
3355 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003356 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
cristy4285d782011-02-09 20:12:28 +00003357 {
cristy4285d782011-02-09 20:12:28 +00003358 smush_image=DestroyImage(smush_image);
3359 return((Image *) NULL);
3360 }
cristy5a5e4d92012-08-29 00:06:25 +00003361 smush_image->alpha_trait=alpha_trait;
cristyea1a8aa2011-10-20 13:24:06 +00003362 (void) SetImageBackgroundColor(smush_image,exception);
cristy4285d782011-02-09 20:12:28 +00003363 status=MagickTrue;
3364 x_offset=0;
3365 y_offset=0;
cristy4285d782011-02-09 20:12:28 +00003366 for (n=0; n < (MagickOffsetType) number_images; n++)
3367 {
3368 SetGeometry(smush_image,&geometry);
3369 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3370 if (stack != MagickFalse)
cristy4ca38e22011-02-10 02:57:49 +00003371 {
3372 x_offset-=geometry.x;
cristy7c6dc152011-02-11 14:10:55 +00003373 y_offset-=SmushYGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003374 }
cristy4285d782011-02-09 20:12:28 +00003375 else
cristy4ca38e22011-02-10 02:57:49 +00003376 {
cristy7c6dc152011-02-11 14:10:55 +00003377 x_offset-=SmushXGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003378 y_offset-=geometry.y;
cristy4ca38e22011-02-10 02:57:49 +00003379 }
cristy39172402012-03-30 13:04:39 +00003380 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3381 y_offset,exception);
cristy4285d782011-02-09 20:12:28 +00003382 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3383 if (proceed == MagickFalse)
3384 break;
3385 if (stack == MagickFalse)
3386 {
3387 x_offset+=(ssize_t) image->columns;
3388 y_offset=0;
3389 }
3390 else
3391 {
3392 x_offset=0;
3393 y_offset+=(ssize_t) image->rows;
3394 }
3395 image=GetNextImageInList(image);
3396 }
cristy4ef6f062011-02-10 20:30:22 +00003397 if (stack == MagickFalse)
3398 smush_image->columns=(size_t) x_offset;
cristy4d727152011-02-10 19:57:21 +00003399 else
cristy4ef6f062011-02-10 20:30:22 +00003400 smush_image->rows=(size_t) y_offset;
cristy4285d782011-02-09 20:12:28 +00003401 if (status == MagickFalse)
3402 smush_image=DestroyImage(smush_image);
3403 return(smush_image);
3404}
3405
3406/*
3407%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3408% %
3409% %
3410% %
cristy3ed852e2009-09-05 21:47:34 +00003411% S t r i p I m a g e %
3412% %
3413% %
3414% %
3415%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3416%
cristy376bda92009-12-22 21:15:23 +00003417% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00003418%
3419% The format of the StripImage method is:
3420%
cristye941a752011-10-15 01:52:48 +00003421% MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003422%
3423% A description of each parameter follows:
3424%
3425% o image: the image.
3426%
cristye941a752011-10-15 01:52:48 +00003427% o exception: return any errors or warnings in this structure.
3428%
cristy3ed852e2009-09-05 21:47:34 +00003429*/
cristye941a752011-10-15 01:52:48 +00003430MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003431{
cristye941a752011-10-15 01:52:48 +00003432 MagickBooleanType
3433 status;
3434
cristy3ed852e2009-09-05 21:47:34 +00003435 assert(image != (Image *) NULL);
3436 if (image->debug != MagickFalse)
3437 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye941a752011-10-15 01:52:48 +00003438 (void) exception;
cristy3ed852e2009-09-05 21:47:34 +00003439 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00003440 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00003441 (void) DeleteImageProperty(image,"date:create");
3442 (void) DeleteImageProperty(image,"date:modify");
cristy42e14902014-05-01 22:40:40 +00003443 status=SetImageArtifact(image,"png:exclude-chunk",
3444 "EXIF,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
cristye941a752011-10-15 01:52:48 +00003445 return(status);
cristy3ed852e2009-09-05 21:47:34 +00003446}
3447
3448/*
3449%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3450% %
3451% %
3452% %
3453+ S y n c I m a g e %
3454% %
3455% %
3456% %
3457%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3458%
3459% SyncImage() initializes the red, green, and blue intensities of each pixel
3460% as defined by the colormap index.
3461%
3462% The format of the SyncImage method is:
3463%
cristyea1a8aa2011-10-20 13:24:06 +00003464% MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003465%
3466% A description of each parameter follows:
3467%
3468% o image: the image.
3469%
cristyea1a8aa2011-10-20 13:24:06 +00003470% o exception: return any errors or warnings in this structure.
3471%
cristy3ed852e2009-09-05 21:47:34 +00003472*/
3473
cristyaedc0312012-01-08 01:07:37 +00003474static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3475 MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00003476{
cristyc8d63672012-01-11 13:03:13 +00003477 if ((size_t) index < image->colors)
cristyaedc0312012-01-08 01:07:37 +00003478 return(index);
cristy3ed852e2009-09-05 21:47:34 +00003479 *range_exception=MagickTrue;
cristyd9657d22012-08-23 14:25:31 +00003480 return((Quantum) 0);
cristy3ed852e2009-09-05 21:47:34 +00003481}
3482
cristyea1a8aa2011-10-20 13:24:06 +00003483MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003484{
3485 CacheView
3486 *image_view;
3487
cristy3ed852e2009-09-05 21:47:34 +00003488 MagickBooleanType
3489 range_exception,
dirkf5cb0472014-10-24 20:10:14 +00003490 status,
3491 taint;
cristy3ed852e2009-09-05 21:47:34 +00003492
cristycb6d09b2010-06-19 01:59:36 +00003493 ssize_t
3494 y;
3495
cristy3ed852e2009-09-05 21:47:34 +00003496 assert(image != (Image *) NULL);
3497 if (image->debug != MagickFalse)
3498 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3499 assert(image->signature == MagickSignature);
3500 if (image->storage_class == DirectClass)
3501 return(MagickFalse);
3502 range_exception=MagickFalse;
3503 status=MagickTrue;
dirkf5cb0472014-10-24 20:10:14 +00003504 taint=image->taint;
cristy46ff2672012-12-14 15:32:26 +00003505 image_view=AcquireAuthenticCacheView(image,exception);
cristy48974b92009-12-19 02:36:06 +00003506#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003507 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
cristy5e6b2592012-12-19 14:08:11 +00003508 magick_threads(image,image,image->rows,1)
cristy48974b92009-12-19 02:36:06 +00003509#endif
cristybb503372010-05-27 20:51:26 +00003510 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003511 {
cristy4c08aed2011-07-01 19:47:50 +00003512 Quantum
cristy3ed852e2009-09-05 21:47:34 +00003513 index;
3514
cristy4c08aed2011-07-01 19:47:50 +00003515 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003516 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003517
cristycb6d09b2010-06-19 01:59:36 +00003518 register ssize_t
3519 x;
3520
cristy48974b92009-12-19 02:36:06 +00003521 if (status == MagickFalse)
3522 continue;
cristy3ed852e2009-09-05 21:47:34 +00003523 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00003524 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003525 {
3526 status=MagickFalse;
3527 continue;
3528 }
cristybb503372010-05-27 20:51:26 +00003529 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003530 {
cristyaedc0312012-01-08 01:07:37 +00003531 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
cristy11a06d32015-01-04 12:03:27 +00003532 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
cristyed231572011-07-14 02:18:59 +00003533 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00003534 }
3535 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3536 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003537 }
3538 image_view=DestroyCacheView(image_view);
dirkf5cb0472014-10-24 20:10:14 +00003539 image->taint=taint;
cristycaf45802012-06-16 18:28:54 +00003540 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
cristy6fccee12011-10-20 18:43:18 +00003541 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
cristyefe601c2013-01-05 17:51:12 +00003542 "InvalidColormapIndex","`%s'",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00003543 return(status);
3544}
cristy1626d332009-11-10 16:58:17 +00003545
3546/*
3547%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3548% %
3549% %
3550% %
3551% S y n c I m a g e S e t t i n g s %
3552% %
3553% %
3554% %
3555%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3556%
anthony5f78bca2012-10-05 06:51:00 +00003557% SyncImageSettings() syncs any image_info global options into per-image
3558% attributes.
3559%
anthonyc7994672012-11-17 05:33:27 +00003560% Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
anthony5f78bca2012-10-05 06:51:00 +00003561% that operations and coders can find such settings. In IMv7 if a desired
3562% per-image artifact is not set, then it will directly look for a global
anthonyc7994672012-11-17 05:33:27 +00003563% option as a fallback, as such this copy is no longer needed, only the
3564% link set up.
cristy1626d332009-11-10 16:58:17 +00003565%
3566% The format of the SyncImageSettings method is:
3567%
3568% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003569% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003570% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003571% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003572%
3573% A description of each parameter follows:
3574%
3575% o image_info: the image info.
3576%
3577% o image: the image.
3578%
cristy6fccee12011-10-20 18:43:18 +00003579% o exception: return any errors or warnings in this structure.
3580%
cristy1626d332009-11-10 16:58:17 +00003581*/
3582
3583MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003584 Image *images,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003585{
3586 Image
3587 *image;
3588
3589 assert(image_info != (const ImageInfo *) NULL);
3590 assert(image_info->signature == MagickSignature);
3591 assert(images != (Image *) NULL);
3592 assert(images->signature == MagickSignature);
3593 if (images->debug != MagickFalse)
3594 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3595 image=images;
3596 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
cristy6fccee12011-10-20 18:43:18 +00003597 (void) SyncImageSettings(image_info,image,exception);
cristy1626d332009-11-10 16:58:17 +00003598 (void) DeleteImageOption(image_info,"page");
3599 return(MagickTrue);
3600}
3601
3602MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003603 Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003604{
cristy1626d332009-11-10 16:58:17 +00003605 const char
cristy202c1482012-10-05 23:47:57 +00003606 *option;
cristy1626d332009-11-10 16:58:17 +00003607
3608 GeometryInfo
3609 geometry_info;
3610
3611 MagickStatusType
3612 flags;
3613
cristy19eb6412010-04-23 14:42:29 +00003614 ResolutionType
3615 units;
3616
cristy1626d332009-11-10 16:58:17 +00003617 /*
3618 Sync image options.
3619 */
3620 assert(image_info != (const ImageInfo *) NULL);
3621 assert(image_info->signature == MagickSignature);
3622 assert(image != (Image *) NULL);
3623 assert(image->signature == MagickSignature);
3624 if (image->debug != MagickFalse)
3625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3626 option=GetImageOption(image_info,"background");
3627 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003628 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
cristy6fccee12011-10-20 18:43:18 +00003629 exception);
cristy1626d332009-11-10 16:58:17 +00003630 option=GetImageOption(image_info,"black-point-compensation");
3631 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003632 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003633 MagickBooleanOptions,MagickFalse,option);
3634 option=GetImageOption(image_info,"blue-primary");
3635 if (option != (const char *) NULL)
3636 {
3637 flags=ParseGeometry(option,&geometry_info);
3638 image->chromaticity.blue_primary.x=geometry_info.rho;
3639 image->chromaticity.blue_primary.y=geometry_info.sigma;
3640 if ((flags & SigmaValue) == 0)
3641 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3642 }
3643 option=GetImageOption(image_info,"bordercolor");
3644 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003645 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
cristy6fccee12011-10-20 18:43:18 +00003646 exception);
anthony72feaa62012-01-17 06:46:23 +00003647 /* FUTURE: do not sync compose to per-image compose setting here */
cristy1626d332009-11-10 16:58:17 +00003648 option=GetImageOption(image_info,"compose");
3649 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003650 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
cristy1626d332009-11-10 16:58:17 +00003651 MagickFalse,option);
anthony72feaa62012-01-17 06:46:23 +00003652 /* -- */
cristy1626d332009-11-10 16:58:17 +00003653 option=GetImageOption(image_info,"compress");
3654 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003655 image->compression=(CompressionType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003656 MagickCompressOptions,MagickFalse,option);
3657 option=GetImageOption(image_info,"debug");
3658 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003659 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00003660 MagickFalse,option);
cristydd5f5912010-07-31 23:37:23 +00003661 option=GetImageOption(image_info,"density");
3662 if (option != (const char *) NULL)
3663 {
3664 GeometryInfo
3665 geometry_info;
3666
cristydd5f5912010-07-31 23:37:23 +00003667 flags=ParseGeometry(option,&geometry_info);
cristy2a11bef2011-10-28 18:33:11 +00003668 image->resolution.x=geometry_info.rho;
3669 image->resolution.y=geometry_info.sigma;
cristydd5f5912010-07-31 23:37:23 +00003670 if ((flags & SigmaValue) == 0)
cristy2a11bef2011-10-28 18:33:11 +00003671 image->resolution.y=image->resolution.x;
cristydd5f5912010-07-31 23:37:23 +00003672 }
cristy1626d332009-11-10 16:58:17 +00003673 option=GetImageOption(image_info,"depth");
3674 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003675 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003676 option=GetImageOption(image_info,"endian");
3677 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003678 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
cristy1626d332009-11-10 16:58:17 +00003679 MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00003680 option=GetImageOption(image_info,"filter");
3681 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003682 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
cristy1626d332009-11-10 16:58:17 +00003683 MagickFalse,option);
3684 option=GetImageOption(image_info,"fuzz");
3685 if (option != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00003686 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
cristy1626d332009-11-10 16:58:17 +00003687 option=GetImageOption(image_info,"gravity");
3688 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003689 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
cristy1626d332009-11-10 16:58:17 +00003690 MagickFalse,option);
3691 option=GetImageOption(image_info,"green-primary");
3692 if (option != (const char *) NULL)
3693 {
3694 flags=ParseGeometry(option,&geometry_info);
3695 image->chromaticity.green_primary.x=geometry_info.rho;
3696 image->chromaticity.green_primary.y=geometry_info.sigma;
3697 if ((flags & SigmaValue) == 0)
3698 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3699 }
3700 option=GetImageOption(image_info,"intent");
3701 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003702 image->rendering_intent=(RenderingIntent) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003703 MagickIntentOptions,MagickFalse,option);
cristy313634e2013-03-26 00:52:19 +00003704 option=GetImageOption(image_info,"intensity");
3705 if (option != (const char *) NULL)
3706 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3707 MagickPixelIntensityOptions,MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00003708 option=GetImageOption(image_info,"interlace");
3709 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003710 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
cristy1626d332009-11-10 16:58:17 +00003711 MagickFalse,option);
3712 option=GetImageOption(image_info,"interpolate");
3713 if (option != (const char *) NULL)
cristy5c4e2582011-09-11 19:21:03 +00003714 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003715 MagickInterpolateOptions,MagickFalse,option);
3716 option=GetImageOption(image_info,"loop");
3717 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003718 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003719 option=GetImageOption(image_info,"mattecolor");
3720 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003721 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
cristy6fccee12011-10-20 18:43:18 +00003722 exception);
cristy1626d332009-11-10 16:58:17 +00003723 option=GetImageOption(image_info,"orient");
3724 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003725 image->orientation=(OrientationType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003726 MagickOrientationOptions,MagickFalse,option);
cristy14ed6a22013-12-28 23:48:05 +00003727 option=GetImageOption(image_info,"page");
3728 if (option != (const char *) NULL)
3729 {
3730 char
3731 *geometry;
3732
3733 geometry=GetPageGeometry(option);
3734 flags=ParseAbsoluteGeometry(geometry,&image->page);
3735 geometry=DestroyString(geometry);
3736 }
cristy1626d332009-11-10 16:58:17 +00003737 option=GetImageOption(image_info,"quality");
3738 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003739 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003740 option=GetImageOption(image_info,"red-primary");
3741 if (option != (const char *) NULL)
3742 {
3743 flags=ParseGeometry(option,&geometry_info);
3744 image->chromaticity.red_primary.x=geometry_info.rho;
3745 image->chromaticity.red_primary.y=geometry_info.sigma;
3746 if ((flags & SigmaValue) == 0)
3747 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3748 }
3749 if (image_info->quality != UndefinedCompressionQuality)
3750 image->quality=image_info->quality;
3751 option=GetImageOption(image_info,"scene");
3752 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003753 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003754 option=GetImageOption(image_info,"taint");
3755 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003756 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00003757 MagickFalse,option);
3758 option=GetImageOption(image_info,"tile-offset");
3759 if (option != (const char *) NULL)
3760 {
3761 char
3762 *geometry;
3763
3764 geometry=GetPageGeometry(option);
3765 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3766 geometry=DestroyString(geometry);
3767 }
3768 option=GetImageOption(image_info,"transparent-color");
3769 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003770 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
cristy6fccee12011-10-20 18:43:18 +00003771 exception);
cristy1626d332009-11-10 16:58:17 +00003772 option=GetImageOption(image_info,"type");
3773 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003774 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
cristy1626d332009-11-10 16:58:17 +00003775 option);
3776 option=GetImageOption(image_info,"units");
cristyc8d63672012-01-11 13:03:13 +00003777 units=image_info->units;
cristy1626d332009-11-10 16:58:17 +00003778 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003779 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00003780 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00003781 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00003782 {
cristy19eb6412010-04-23 14:42:29 +00003783 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00003784 switch (image->units)
3785 {
3786 case PixelsPerInchResolution:
3787 {
cristy19eb6412010-04-23 14:42:29 +00003788 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00003789 {
cristy2a11bef2011-10-28 18:33:11 +00003790 image->resolution.x/=2.54;
3791 image->resolution.y/=2.54;
cristy1626d332009-11-10 16:58:17 +00003792 }
3793 break;
3794 }
3795 case PixelsPerCentimeterResolution:
3796 {
cristy19eb6412010-04-23 14:42:29 +00003797 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00003798 {
cristy2a11bef2011-10-28 18:33:11 +00003799 image->resolution.x=(double) ((size_t) (100.0*2.54*
3800 image->resolution.x+0.5))/100.0;
3801 image->resolution.y=(double) ((size_t) (100.0*2.54*
3802 image->resolution.y+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00003803 }
3804 break;
3805 }
3806 default:
3807 break;
3808 }
cristy19eb6412010-04-23 14:42:29 +00003809 image->units=units;
cristy1626d332009-11-10 16:58:17 +00003810 }
anthonyfd706f92012-01-19 04:22:02 +00003811 option=GetImageOption(image_info,"virtual-pixel");
3812 if (option != (const char *) NULL)
cristy387430f2012-02-07 13:09:46 +00003813 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3814 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3815 exception);
cristy1626d332009-11-10 16:58:17 +00003816 option=GetImageOption(image_info,"white-point");
3817 if (option != (const char *) NULL)
3818 {
3819 flags=ParseGeometry(option,&geometry_info);
3820 image->chromaticity.white_point.x=geometry_info.rho;
3821 image->chromaticity.white_point.y=geometry_info.sigma;
3822 if ((flags & SigmaValue) == 0)
3823 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3824 }
3825 ResetImageOptionIterator(image_info);
anthony5f78bca2012-10-05 06:51:00 +00003826#if 0
cristy1626d332009-11-10 16:58:17 +00003827 {
anthony643c6132012-11-07 14:50:28 +00003828 /* IMv6: Copy freeform global options into per-image artifacts, so
3829 * various operations and coders can access them.
3830 *
3831 * This has a problem, as per-image artefacts may have been set in
3832 * parenthesis, but may not be unset when parenthesis ends.
3833 */
cristy202c1482012-10-05 23:47:57 +00003834 char
cristy151b66d2015-04-15 10:50:31 +00003835 property[MagickPathExtent];
cristy202c1482012-10-05 23:47:57 +00003836
3837 const char
3838 *value;
3839
cristy202c1482012-10-05 23:47:57 +00003840 for (option=GetNextImageOption(image_info); option != (const char *) NULL; )
3841 {
3842 value=GetImageOption(image_info,option);
3843 if (value != (const char *) NULL)
3844 {
cristy151b66d2015-04-15 10:50:31 +00003845 (void) FormatLocaleString(property,MagickPathExtent,"%s",option);
cristy202c1482012-10-05 23:47:57 +00003846 (void) SetImageArtifact(image,property,value);
3847 }
3848 option=GetNextImageOption(image_info);
3849 }
cristy1626d332009-11-10 16:58:17 +00003850 }
anthony5f78bca2012-10-05 06:51:00 +00003851#else
anthony643c6132012-11-07 14:50:28 +00003852 /* IMv7: pointer to allow the lookup of pre-image artefact will fallback to
3853 a global option setting/define. This saves a lot of duplication of
3854 global options into per-image artifacts, while ensuring only specifically
3855 set per-image artifacts are preverved when parenthesis ends.
anthony5f78bca2012-10-05 06:51:00 +00003856
anthony643c6132012-11-07 14:50:28 +00003857 This pointer is never explictally freed, as it is only used as a back
3858 reference, not as the main pointer to the image_info structure. Images
anthonyc7994672012-11-17 05:33:27 +00003859 being removed from a image_info image list (or yet to be added to such),
3860 should have this pointer reset to NULL.
anthony643c6132012-11-07 14:50:28 +00003861 */
cristy1a780952013-02-10 17:15:30 +00003862 image->image_info=image_info;
anthony5f78bca2012-10-05 06:51:00 +00003863#endif
cristy1626d332009-11-10 16:58:17 +00003864 return(MagickTrue);
3865}