blob: 6d1d3b102293924a1d1697ba09f99227a48920e7 [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% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 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();
cristye1c94d92015-06-28 12:16:33 +0000212 image->signature=MagickCoreSignature;
cristy3ed852e2009-09-05 21:47:34 +0000213 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);
cristyee2f5d62015-07-28 13:19:43 +0000220 (void) CopyMagickString(image->filename,image_info->filename,
221 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000222 (void) CopyMagickString(image->magick_filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +0000223 MagickPathExtent);
224 (void) CopyMagickString(image->magick,image_info->magick,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000225 if (image_info->size != (char *) NULL)
226 {
227 (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info);
228 image->columns=image->extract_info.width;
229 image->rows=image->extract_info.height;
230 image->offset=image->extract_info.x;
231 image->extract_info.x=0;
232 image->extract_info.y=0;
233 }
234 if (image_info->extract != (char *) NULL)
235 {
236 RectangleInfo
237 geometry;
238
239 flags=ParseAbsoluteGeometry(image_info->extract,&geometry);
240 if (((flags & XValue) != 0) || ((flags & YValue) != 0))
241 {
242 image->extract_info=geometry;
243 Swap(image->columns,image->extract_info.width);
244 Swap(image->rows,image->extract_info.height);
245 }
246 }
247 image->compression=image_info->compression;
248 image->quality=image_info->quality;
249 image->endian=image_info->endian;
250 image->interlace=image_info->interlace;
251 image->units=image_info->units;
252 if (image_info->density != (char *) NULL)
253 {
254 GeometryInfo
255 geometry_info;
256
257 flags=ParseGeometry(image_info->density,&geometry_info);
cristy2a11bef2011-10-28 18:33:11 +0000258 image->resolution.x=geometry_info.rho;
259 image->resolution.y=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +0000260 if ((flags & SigmaValue) == 0)
cristy2a11bef2011-10-28 18:33:11 +0000261 image->resolution.y=image->resolution.x;
cristy3ed852e2009-09-05 21:47:34 +0000262 }
263 if (image_info->page != (char *) NULL)
264 {
265 char
266 *geometry;
267
268 image->page=image->extract_info;
269 geometry=GetPageGeometry(image_info->page);
270 (void) ParseAbsoluteGeometry(geometry,&image->page);
271 geometry=DestroyString(geometry);
272 }
273 if (image_info->depth != 0)
274 image->depth=image_info->depth;
275 image->dither=image_info->dither;
276 image->background_color=image_info->background_color;
277 image->border_color=image_info->border_color;
278 image->matte_color=image_info->matte_color;
279 image->transparent_color=image_info->transparent_color;
cristy73724512010-04-12 14:43:14 +0000280 image->ping=image_info->ping;
cristy3ed852e2009-09-05 21:47:34 +0000281 image->progress_monitor=image_info->progress_monitor;
282 image->client_data=image_info->client_data;
283 if (image_info->cache != (void *) NULL)
284 ClonePixelCacheMethods(image->cache,image_info->cache);
cristy1a780952013-02-10 17:15:30 +0000285 /*
286 Set all global options that map to per-image settings.
287 */
cristy6fccee12011-10-20 18:43:18 +0000288 (void) SyncImageSettings(image_info,image,exception);
cristy1a780952013-02-10 17:15:30 +0000289 /*
290 Global options that are only set for new images.
291 */
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);
cristye1c94d92015-06-28 12:16:33 +0000390 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000391 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
Cristya38b4562015-12-28 08:47:22 -0500467 depth,
cristy3ed852e2009-09-05 21:47:34 +0000468 height,
469 number_images,
470 width;
471
cristybb503372010-05-27 20:51:26 +0000472 ssize_t
473 x_offset,
474 y,
475 y_offset;
476
cristy3ed852e2009-09-05 21:47:34 +0000477 /*
cristy7c6dc152011-02-11 14:10:55 +0000478 Compute maximum area of appended area.
cristy3ed852e2009-09-05 21:47:34 +0000479 */
cristy4ca38e22011-02-10 02:57:49 +0000480 assert(images != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000481 assert(images->signature == MagickCoreSignature);
cristy4ca38e22011-02-10 02:57:49 +0000482 if (images->debug != MagickFalse)
483 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy3ed852e2009-09-05 21:47:34 +0000484 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000485 assert(exception->signature == MagickCoreSignature);
cristy5a5e4d92012-08-29 00:06:25 +0000486 alpha_trait=images->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +0000487 number_images=1;
cristyeeebdde2012-04-14 16:29:34 +0000488 width=images->columns;
489 height=images->rows;
Cristya38b4562015-12-28 08:47:22 -0500490 depth=images->depth;
cristyeeebdde2012-04-14 16:29:34 +0000491 next=GetNextImageInList(images);
cristy3ed852e2009-09-05 21:47:34 +0000492 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
493 {
Cristya38b4562015-12-28 08:47:22 -0500494 if (next->depth > depth)
495 depth=next->depth;
cristy17f11b02014-12-20 19:37:04 +0000496 if (next->alpha_trait != UndefinedPixelTrait)
cristy5a5e4d92012-08-29 00:06:25 +0000497 alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +0000498 number_images++;
499 if (stack != MagickFalse)
500 {
501 if (next->columns > width)
502 width=next->columns;
503 height+=next->rows;
504 continue;
505 }
506 width+=next->columns;
507 if (next->rows > height)
508 height=next->rows;
509 }
510 /*
cristy7c6dc152011-02-11 14:10:55 +0000511 Append images.
cristy3ed852e2009-09-05 21:47:34 +0000512 */
cristyeeebdde2012-04-14 16:29:34 +0000513 append_image=CloneImage(images,width,height,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000514 if (append_image == (Image *) NULL)
515 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000516 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000517 {
cristy3ed852e2009-09-05 21:47:34 +0000518 append_image=DestroyImage(append_image);
519 return((Image *) NULL);
520 }
Cristya38b4562015-12-28 08:47:22 -0500521 append_image->depth=depth;
cristy5a5e4d92012-08-29 00:06:25 +0000522 append_image->alpha_trait=alpha_trait;
cristyea1a8aa2011-10-20 13:24:06 +0000523 (void) SetImageBackgroundColor(append_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000524 status=MagickTrue;
525 x_offset=0;
526 y_offset=0;
cristyeeebdde2012-04-14 16:29:34 +0000527 next=images;
cristy46ff2672012-12-14 15:32:26 +0000528 append_view=AcquireAuthenticCacheView(append_image,exception);
cristybb503372010-05-27 20:51:26 +0000529 for (n=0; n < (MagickOffsetType) number_images; n++)
cristy3ed852e2009-09-05 21:47:34 +0000530 {
cristyeeebdde2012-04-14 16:29:34 +0000531 CacheView
532 *image_view;
533
534 Image
535 *image;
536
cristy9eed59f2013-02-19 15:26:48 +0000537 MagickBooleanType
538 proceed;
539
cristyeeebdde2012-04-14 16:29:34 +0000540 image=CloneImage(next,0,0,MagickTrue,exception);
541 if (image == (Image *) NULL)
542 break;
543 (void) TransformImageColorspace(image,append_image->colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000544 SetGeometry(append_image,&geometry);
545 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
546 if (stack != MagickFalse)
547 x_offset-=geometry.x;
548 else
549 y_offset-=geometry.y;
cristy46ff2672012-12-14 15:32:26 +0000550 image_view=AcquireVirtualCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +0000551#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy9a5a52f2012-10-09 14:40:31 +0000552 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +0000553 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000554#endif
cristybb503372010-05-27 20:51:26 +0000555 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000556 {
557 MagickBooleanType
558 sync;
559
cristye14e3202012-04-11 18:48:17 +0000560 PixelInfo
561 pixel;
562
cristy4c08aed2011-07-01 19:47:50 +0000563 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +0100564 *magick_restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000565
cristy4c08aed2011-07-01 19:47:50 +0000566 register Quantum
dirk05d2ff72015-11-18 23:13:43 +0100567 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000568
cristycb6d09b2010-06-19 01:59:36 +0000569 register ssize_t
570 x;
571
cristy3ed852e2009-09-05 21:47:34 +0000572 if (status == MagickFalse)
573 continue;
574 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
575 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
576 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000577 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000578 {
579 status=MagickFalse;
580 continue;
581 }
cristye14e3202012-04-11 18:48:17 +0000582 GetPixelInfo(image,&pixel);
cristybb503372010-05-27 20:51:26 +0000583 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000584 {
cristy883fde12013-04-08 00:50:13 +0000585 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +0000586 {
cristyc3a58022013-10-09 23:22:42 +0000587 SetPixelBackgoundColor(append_image,q);
cristy10a6c612012-01-29 21:41:05 +0000588 p+=GetPixelChannels(image);
589 q+=GetPixelChannels(append_image);
590 continue;
591 }
cristye14e3202012-04-11 18:48:17 +0000592 GetPixelInfoPixel(image,p,&pixel);
cristy11a06d32015-01-04 12:03:27 +0000593 SetPixelViaPixelInfo(append_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +0000594 p+=GetPixelChannels(image);
595 q+=GetPixelChannels(append_image);
cristy3ed852e2009-09-05 21:47:34 +0000596 }
597 sync=SyncCacheViewAuthenticPixels(append_view,exception);
598 if (sync == MagickFalse)
cristya65f35b2010-04-20 01:10:41 +0000599 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000600 }
601 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +0000602 if (stack == MagickFalse)
603 {
cristyeaedf062010-05-29 22:36:02 +0000604 x_offset+=(ssize_t) image->columns;
cristy3ed852e2009-09-05 21:47:34 +0000605 y_offset=0;
606 }
607 else
608 {
609 x_offset=0;
cristyeaedf062010-05-29 22:36:02 +0000610 y_offset+=(ssize_t) image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000611 }
cristyeeebdde2012-04-14 16:29:34 +0000612 image=DestroyImage(image);
613 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
614 if (proceed == MagickFalse)
615 break;
616 next=GetNextImageInList(next);
cristy3ed852e2009-09-05 21:47:34 +0000617 }
618 append_view=DestroyCacheView(append_view);
619 if (status == MagickFalse)
620 append_image=DestroyImage(append_image);
621 return(append_image);
622}
623
624/*
625%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
626% %
627% %
628% %
cristy3ed852e2009-09-05 21:47:34 +0000629% C a t c h I m a g e E x c e p t i o n %
630% %
631% %
632% %
633%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634%
635% CatchImageException() returns if no exceptions are found in the image
636% sequence, otherwise it determines the most severe exception and reports
637% it as a warning or error depending on the severity.
638%
639% The format of the CatchImageException method is:
640%
641% ExceptionType CatchImageException(Image *image)
642%
643% A description of each parameter follows:
644%
645% o image: An image sequence.
646%
647*/
648MagickExport ExceptionType CatchImageException(Image *image)
649{
650 ExceptionInfo
651 *exception;
652
653 ExceptionType
654 severity;
655
656 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000657 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000658 if (image->debug != MagickFalse)
659 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
660 exception=AcquireExceptionInfo();
cristy3ed852e2009-09-05 21:47:34 +0000661 CatchException(exception);
662 severity=exception->severity;
663 exception=DestroyExceptionInfo(exception);
664 return(severity);
665}
666
667/*
668%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
669% %
670% %
671% %
672% C l i p I m a g e P a t h %
673% %
674% %
675% %
676%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677%
678% ClipImagePath() sets the image clip mask based any clipping path information
679% if it exists.
680%
681% The format of the ClipImagePath method is:
682%
683% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000684% const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000685%
686% A description of each parameter follows:
687%
688% o image: the image.
689%
690% o pathname: name of clipping path resource. If name is preceded by #, use
691% clipping path numbered by name.
692%
693% o inside: if non-zero, later operations take effect inside clipping path.
694% Otherwise later operations take effect outside clipping path.
695%
cristy018f07f2011-09-04 21:15:19 +0000696% o exception: return any errors or warnings in this structure.
697%
cristy3ed852e2009-09-05 21:47:34 +0000698*/
699
cristy018f07f2011-09-04 21:15:19 +0000700MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000701{
cristy018f07f2011-09-04 21:15:19 +0000702 return(ClipImagePath(image,"#1",MagickTrue,exception));
cristy3ed852e2009-09-05 21:47:34 +0000703}
704
705MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000706 const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000707{
708#define ClipImagePathTag "ClipPath/Image"
709
710 char
711 *property;
712
713 const char
714 *value;
715
716 Image
717 *clip_mask;
718
719 ImageInfo
720 *image_info;
721
722 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000723 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000724 if (image->debug != MagickFalse)
725 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
726 assert(pathname != NULL);
727 property=AcquireString(pathname);
cristy151b66d2015-04-15 10:50:31 +0000728 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
cristy3ed852e2009-09-05 21:47:34 +0000729 pathname);
cristyd15e6592011-10-15 00:13:06 +0000730 value=GetImageProperty(image,property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000731 property=DestroyString(property);
732 if (value == (const char *) NULL)
733 {
cristy6fccee12011-10-20 18:43:18 +0000734 ThrowFileException(exception,OptionError,"NoClipPathDefined",
cristy3ed852e2009-09-05 21:47:34 +0000735 image->filename);
736 return(MagickFalse);
737 }
738 image_info=AcquireImageInfo();
cristyee2f5d62015-07-28 13:19:43 +0000739 (void) CopyMagickString(image_info->filename,image->filename,
740 MagickPathExtent);
741 (void) ConcatenateMagickString(image_info->filename,pathname,
742 MagickPathExtent);
cristy6fccee12011-10-20 18:43:18 +0000743 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
cristy3ed852e2009-09-05 21:47:34 +0000744 image_info=DestroyImageInfo(image_info);
745 if (clip_mask == (Image *) NULL)
746 return(MagickFalse);
747 if (clip_mask->storage_class == PseudoClass)
748 {
cristyea1a8aa2011-10-20 13:24:06 +0000749 (void) SyncImage(clip_mask,exception);
cristy6fccee12011-10-20 18:43:18 +0000750 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000751 return(MagickFalse);
752 }
753 if (inside == MagickFalse)
cristy6fccee12011-10-20 18:43:18 +0000754 (void) NegateImage(clip_mask,MagickFalse,exception);
cristy151b66d2015-04-15 10:50:31 +0000755 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
cristy3ed852e2009-09-05 21:47:34 +0000756 "8BIM:1999,2998:%s\nPS",pathname);
cristyacd0d4c2015-07-25 16:12:33 +0000757 (void) SetImageMask(image,ReadPixelMask,clip_mask,exception);
cristy3ed852e2009-09-05 21:47:34 +0000758 clip_mask=DestroyImage(clip_mask);
759 return(MagickTrue);
760}
761
762/*
763%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
764% %
765% %
766% %
767% C l o n e I m a g e %
768% %
769% %
770% %
771%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
772%
773% CloneImage() copies an image and returns the copy as a new image object.
anthony96f11ee2011-03-23 08:22:54 +0000774%
cristy3ed852e2009-09-05 21:47:34 +0000775% If the specified columns and rows is 0, an exact copy of the image is
776% returned, otherwise the pixel data is undefined and must be initialized
777% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
778% failure, a NULL image is returned and exception describes the reason for the
779% failure.
780%
781% The format of the CloneImage method is:
782%
cristybb503372010-05-27 20:51:26 +0000783% Image *CloneImage(const Image *image,const size_t columns,
784% const size_t rows,const MagickBooleanType orphan,
cristy3ed852e2009-09-05 21:47:34 +0000785% ExceptionInfo *exception)
786%
787% A description of each parameter follows:
788%
789% o image: the image.
790%
791% o columns: the number of columns in the cloned image.
792%
793% o rows: the number of rows in the cloned image.
794%
795% o detach: With a value other than 0, the cloned image is detached from
796% its parent I/O stream.
797%
798% o exception: return any errors or warnings in this structure.
799%
800*/
cristybb503372010-05-27 20:51:26 +0000801MagickExport Image *CloneImage(const Image *image,const size_t columns,
cristybee00932011-01-15 20:28:27 +0000802 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000803{
804 Image
805 *clone_image;
806
cristya19f1d72012-08-07 18:24:38 +0000807 double
cristy3ed852e2009-09-05 21:47:34 +0000808 scale;
809
810 size_t
811 length;
812
813 /*
814 Clone the image.
815 */
816 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000817 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000818 if (image->debug != MagickFalse)
819 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
820 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000821 assert(exception->signature == MagickCoreSignature);
cristybe1cfca2014-10-21 14:00:29 +0000822 if ((image->columns == 0) || (image->rows == 0))
823 {
824 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
825 "NegativeOrZeroImageSize","`%s'",image->filename);
826 return((Image *) NULL);
827 }
cristy73bd4a52010-10-05 11:24:23 +0000828 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000829 if (clone_image == (Image *) NULL)
830 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
831 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
cristye1c94d92015-06-28 12:16:33 +0000832 clone_image->signature=MagickCoreSignature;
cristy3ed852e2009-09-05 21:47:34 +0000833 clone_image->storage_class=image->storage_class;
cristyed231572011-07-14 02:18:59 +0000834 clone_image->number_channels=image->number_channels;
cristyb3a73b52011-07-26 01:34:43 +0000835 clone_image->number_meta_channels=image->number_meta_channels;
cristy4c08aed2011-07-01 19:47:50 +0000836 clone_image->metacontent_extent=image->metacontent_extent;
cristy3ed852e2009-09-05 21:47:34 +0000837 clone_image->colorspace=image->colorspace;
cristy883fde12013-04-08 00:50:13 +0000838 clone_image->read_mask=image->read_mask;
839 clone_image->write_mask=image->write_mask;
cristy8a46d822012-08-28 23:32:39 +0000840 clone_image->alpha_trait=image->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +0000841 clone_image->columns=image->columns;
842 clone_image->rows=image->rows;
843 clone_image->dither=image->dither;
cristy101ab702011-10-13 13:06:32 +0000844 if (image->colormap != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000845 {
846 /*
847 Allocate and copy the image colormap.
848 */
849 clone_image->colors=image->colors;
850 length=(size_t) image->colors;
cristy101ab702011-10-13 13:06:32 +0000851 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
cristy3ed852e2009-09-05 21:47:34 +0000852 sizeof(*clone_image->colormap));
cristy101ab702011-10-13 13:06:32 +0000853 if (clone_image->colormap == (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000854 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
855 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
856 sizeof(*clone_image->colormap));
857 }
Cristy36421ee2015-08-28 11:58:20 -0400858 clone_image->image_info=CloneImageInfo(image->image_info);
cristy3ed852e2009-09-05 21:47:34 +0000859 (void) CloneImageProfiles(clone_image,image);
860 (void) CloneImageProperties(clone_image,image);
861 (void) CloneImageArtifacts(clone_image,image);
862 GetTimerInfo(&clone_image->timer);
cristy3ed852e2009-09-05 21:47:34 +0000863 if (image->ascii85 != (void *) NULL)
864 Ascii85Initialize(clone_image);
865 clone_image->magick_columns=image->magick_columns;
866 clone_image->magick_rows=image->magick_rows;
867 clone_image->type=image->type;
cristy636dcb52011-08-26 13:23:49 +0000868 clone_image->channel_mask=image->channel_mask;
cristyed231572011-07-14 02:18:59 +0000869 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +0000870 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
cristy151b66d2015-04-15 10:50:31 +0000871 MagickPathExtent);
872 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
cristy25baba02015-07-28 00:36:29 +0000873 (void) CopyMagickString(clone_image->filename,image->filename,
874 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000875 clone_image->progress_monitor=image->progress_monitor;
876 clone_image->client_data=image->client_data;
877 clone_image->reference_count=1;
cristybee00932011-01-15 20:28:27 +0000878 clone_image->next=image->next;
879 clone_image->previous=image->previous;
cristy3ed852e2009-09-05 21:47:34 +0000880 clone_image->list=NewImageList();
cristy3ed852e2009-09-05 21:47:34 +0000881 if (detach == MagickFalse)
882 clone_image->blob=ReferenceBlob(image->blob);
883 else
cristybee00932011-01-15 20:28:27 +0000884 {
885 clone_image->next=NewImageList();
886 clone_image->previous=NewImageList();
887 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
888 }
cristy73724512010-04-12 14:43:14 +0000889 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000890 clone_image->debug=IsEventLogging();
cristy3d162a92014-02-16 14:05:06 +0000891 clone_image->semaphore=AcquireSemaphoreInfo();
cristy58a749e2014-05-25 17:36:53 +0000892 if ((columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000893 {
894 if (image->montage != (char *) NULL)
895 (void) CloneString(&clone_image->montage,image->montage);
896 if (image->directory != (char *) NULL)
897 (void) CloneString(&clone_image->directory,image->directory);
cristy3ed852e2009-09-05 21:47:34 +0000898 clone_image->cache=ReferencePixelCache(image->cache);
899 return(clone_image);
900 }
cristy51d26762014-05-26 01:29:41 +0000901 scale=1.0;
902 if (image->columns != 0)
903 scale=(double) columns/(double) image->columns;
cristybb503372010-05-27 20:51:26 +0000904 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
905 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
906 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
cristy51d26762014-05-26 01:29:41 +0000907 scale=1.0;
908 if (image->rows != 0)
cristyee2f5d62015-07-28 13:19:43 +0000909 scale=(double) rows/(double) image->rows;
cristybb503372010-05-27 20:51:26 +0000910 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
911 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
912 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000913 clone_image->columns=columns;
914 clone_image->rows=rows;
915 clone_image->cache=ClonePixelCache(image->cache);
916 return(clone_image);
917}
918
919/*
920%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
921% %
922% %
923% %
924% C l o n e I m a g e I n f o %
925% %
926% %
927% %
928%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
929%
930% CloneImageInfo() makes a copy of the given image info structure. If
931% NULL is specified, a new image info structure is created initialized to
932% default values.
933%
934% The format of the CloneImageInfo method is:
935%
936% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
937%
938% A description of each parameter follows:
939%
940% o image_info: the image info.
941%
942*/
943MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
944{
945 ImageInfo
946 *clone_info;
947
948 clone_info=AcquireImageInfo();
949 if (image_info == (ImageInfo *) NULL)
950 return(clone_info);
951 clone_info->compression=image_info->compression;
952 clone_info->temporary=image_info->temporary;
953 clone_info->adjoin=image_info->adjoin;
954 clone_info->antialias=image_info->antialias;
955 clone_info->scene=image_info->scene;
956 clone_info->number_scenes=image_info->number_scenes;
957 clone_info->depth=image_info->depth;
anthony72feaa62012-01-17 06:46:23 +0000958 (void) CloneString(&clone_info->size,image_info->size);
959 (void) CloneString(&clone_info->extract,image_info->extract);
960 (void) CloneString(&clone_info->scenes,image_info->scenes);
961 (void) CloneString(&clone_info->page,image_info->page);
cristy3ed852e2009-09-05 21:47:34 +0000962 clone_info->interlace=image_info->interlace;
963 clone_info->endian=image_info->endian;
964 clone_info->units=image_info->units;
965 clone_info->quality=image_info->quality;
anthony72feaa62012-01-17 06:46:23 +0000966 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
967 (void) CloneString(&clone_info->server_name,image_info->server_name);
968 (void) CloneString(&clone_info->font,image_info->font);
969 (void) CloneString(&clone_info->texture,image_info->texture);
970 (void) CloneString(&clone_info->density,image_info->density);
cristy3ed852e2009-09-05 21:47:34 +0000971 clone_info->pointsize=image_info->pointsize;
972 clone_info->fuzz=image_info->fuzz;
cristy3ed852e2009-09-05 21:47:34 +0000973 clone_info->background_color=image_info->background_color;
974 clone_info->border_color=image_info->border_color;
975 clone_info->matte_color=image_info->matte_color;
976 clone_info->transparent_color=image_info->transparent_color;
977 clone_info->dither=image_info->dither;
978 clone_info->monochrome=image_info->monochrome;
cristy3ed852e2009-09-05 21:47:34 +0000979 clone_info->colorspace=image_info->colorspace;
980 clone_info->type=image_info->type;
981 clone_info->orientation=image_info->orientation;
982 clone_info->preview_type=image_info->preview_type;
983 clone_info->group=image_info->group;
984 clone_info->ping=image_info->ping;
985 clone_info->verbose=image_info->verbose;
cristy3ed852e2009-09-05 21:47:34 +0000986 clone_info->progress_monitor=image_info->progress_monitor;
987 clone_info->client_data=image_info->client_data;
988 clone_info->cache=image_info->cache;
989 if (image_info->cache != (void *) NULL)
990 clone_info->cache=ReferencePixelCache(image_info->cache);
991 if (image_info->profile != (void *) NULL)
992 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
993 image_info->profile);
994 SetImageInfoFile(clone_info,image_info->file);
995 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
996 clone_info->stream=image_info->stream;
cristy957f2612015-06-21 23:51:58 +0000997 (void) CopyMagickString(clone_info->magick,image_info->magick,
998 MagickPathExtent);
999 (void) CopyMagickString(clone_info->unique,image_info->unique,
1000 MagickPathExtent);
cristy151b66d2015-04-15 10:50:31 +00001001 (void) CopyMagickString(clone_info->zero,image_info->zero,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001002 (void) CopyMagickString(clone_info->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00001003 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001004 clone_info->channel=image_info->channel;
anthony1afdc7a2011-10-05 11:54:28 +00001005 (void) CloneImageOptions(clone_info,image_info);
cristy3ed852e2009-09-05 21:47:34 +00001006 clone_info->debug=IsEventLogging();
1007 clone_info->signature=image_info->signature;
1008 return(clone_info);
1009}
1010
1011/*
1012%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1013% %
1014% %
1015% %
cristy957f2612015-06-21 23:51:58 +00001016% C o p y I m a g e P i x e l s %
1017% %
1018% %
1019% %
1020%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1021%
1022% CopyImagePixels() copies pixels from the source image as defined by the
1023% geometry the destination image at the specified offset.
1024%
1025% The format of the CopyImagePixels method is:
1026%
1027% MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
cristy17fbd722015-06-22 00:46:58 +00001028% const RectangleInfo *geometry,const OffsetInfo *offset,
1029% ExceptionInfo *exception);
cristy957f2612015-06-21 23:51:58 +00001030%
1031% A description of each parameter follows:
1032%
1033% o image: the destination image.
1034%
1035% o source_image: the source image.
1036%
1037% o geometry: define the dimensions of the source pixel rectangle.
1038%
1039% o offset: define the offset in the destination image.
1040%
cristy17fbd722015-06-22 00:46:58 +00001041% o exception: return any errors or warnings in this structure.
1042%
cristy957f2612015-06-21 23:51:58 +00001043*/
1044MagickExport MagickBooleanType CopyImagePixels(Image *image,
1045 const Image *source_image,const RectangleInfo *geometry,
cristy17fbd722015-06-22 00:46:58 +00001046 const OffsetInfo *offset,ExceptionInfo *exception)
cristy957f2612015-06-21 23:51:58 +00001047{
cristy17fbd722015-06-22 00:46:58 +00001048#define CopyImageTag "Copy/Image"
1049
1050 CacheView
1051 *image_view,
1052 *source_view;
1053
1054 MagickBooleanType
1055 status;
1056
1057 MagickOffsetType
1058 progress;
1059
1060 ssize_t
1061 y;
1062
cristy957f2612015-06-21 23:51:58 +00001063 assert(image != (Image *) NULL);
1064 if (image->debug != MagickFalse)
1065 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1066 assert(source_image != (Image *) NULL);
1067 assert(geometry != (RectangleInfo *) NULL);
1068 assert(offset != (OffsetInfo *) NULL);
cristy8c4c1c42015-06-22 23:51:22 +00001069 if ((offset->x < 0) || (offset->y < 0) ||
Cristy7d049b72015-09-26 20:50:55 -04001070 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1071 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
cristye742cae2015-06-22 19:40:29 +00001072 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1073 image->filename);
cristy8c4c1c42015-06-22 23:51:22 +00001074 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1075 return(MagickFalse);
cristy17fbd722015-06-22 00:46:58 +00001076 /*
1077 Copy image pixels.
1078 */
1079 status=MagickTrue;
1080 progress=0;
1081 source_view=AcquireVirtualCacheView(source_image,exception);
1082 image_view=AcquireAuthenticCacheView(image,exception);
1083#if defined(MAGICKCORE_OPENMP_SUPPORT)
1084 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristye742cae2015-06-22 19:40:29 +00001085 magick_threads(image,source_image,geometry->height,1)
cristy17fbd722015-06-22 00:46:58 +00001086#endif
cristye742cae2015-06-22 19:40:29 +00001087 for (y=0; y < (ssize_t) geometry->height; y++)
cristy17fbd722015-06-22 00:46:58 +00001088 {
1089 MagickBooleanType
1090 sync;
1091
1092 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001093 *magick_restrict p;
cristy17fbd722015-06-22 00:46:58 +00001094
1095 register ssize_t
1096 x;
1097
1098 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01001099 *magick_restrict q;
cristy17fbd722015-06-22 00:46:58 +00001100
1101 if (status == MagickFalse)
1102 continue;
cristye742cae2015-06-22 19:40:29 +00001103 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1104 geometry->width,1,exception);
1105 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1106 geometry->width,1,exception);
cristy17fbd722015-06-22 00:46:58 +00001107 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1108 {
1109 status=MagickFalse;
1110 continue;
1111 }
cristye742cae2015-06-22 19:40:29 +00001112 for (x=0; x < (ssize_t) geometry->width; x++)
cristy17fbd722015-06-22 00:46:58 +00001113 {
1114 register ssize_t
1115 i;
1116
1117 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1118 {
1119 PixelChannel channel=GetPixelChannelChannel(image,i);
1120 PixelTrait traits=GetPixelChannelTraits(image,channel);
1121 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1122 if ((traits == UndefinedPixelTrait) ||
1123 (source_traits == UndefinedPixelTrait))
1124 continue;
dirkd00a0022015-07-05 09:54:39 +00001125 SetPixelChannel(image,channel,p[i],q);
cristy17fbd722015-06-22 00:46:58 +00001126 }
dirkd00a0022015-07-05 09:54:39 +00001127 p+=GetPixelChannels(source_image);
1128 q+=GetPixelChannels(image);
cristy17fbd722015-06-22 00:46:58 +00001129 }
dirkd00a0022015-07-05 09:54:39 +00001130 sync=SyncCacheViewAuthenticPixels(image_view,exception);
cristy17fbd722015-06-22 00:46:58 +00001131 if (sync == MagickFalse)
1132 status=MagickFalse;
1133 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1134 {
1135 MagickBooleanType
1136 proceed;
1137
1138#if defined(MAGICKCORE_OPENMP_SUPPORT)
1139 #pragma omp critical (MagickCore_CopyImage)
1140#endif
1141 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1142 if (proceed == MagickFalse)
1143 status=MagickFalse;
1144 }
1145 }
1146 source_view=DestroyCacheView(source_view);
1147 image_view=DestroyCacheView(image_view);
1148 return(status);
cristy957f2612015-06-21 23:51:58 +00001149}
1150
1151/*
1152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1153% %
1154% %
1155% %
cristy3ed852e2009-09-05 21:47:34 +00001156% D e s t r o y I m a g e %
1157% %
1158% %
1159% %
1160%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1161%
1162% DestroyImage() dereferences an image, deallocating memory associated with
1163% the image if the reference count becomes zero.
1164%
1165% The format of the DestroyImage method is:
1166%
1167% Image *DestroyImage(Image *image)
1168%
1169% A description of each parameter follows:
1170%
1171% o image: the image.
1172%
1173*/
1174MagickExport Image *DestroyImage(Image *image)
1175{
1176 MagickBooleanType
1177 destroy;
1178
1179 /*
1180 Dereference image.
1181 */
1182 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001183 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001184 if (image->debug != MagickFalse)
1185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1186 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001187 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001188 image->reference_count--;
1189 if (image->reference_count == 0)
1190 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001191 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001192 if (destroy == MagickFalse)
1193 return((Image *) NULL);
1194 /*
1195 Destroy image.
1196 */
1197 DestroyImagePixels(image);
cristyed231572011-07-14 02:18:59 +00001198 image->channel_map=DestroyPixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +00001199 if (image->montage != (char *) NULL)
1200 image->montage=DestroyString(image->montage);
1201 if (image->directory != (char *) NULL)
1202 image->directory=DestroyString(image->directory);
cristy101ab702011-10-13 13:06:32 +00001203 if (image->colormap != (PixelInfo *) NULL)
1204 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
cristy3ed852e2009-09-05 21:47:34 +00001205 if (image->geometry != (char *) NULL)
1206 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001207 DestroyImageProfiles(image);
1208 DestroyImageProperties(image);
1209 DestroyImageArtifacts(image);
Cristy36421ee2015-08-28 11:58:20 -04001210 if (image->ascii85 != (Ascii85Info *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001211 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
Cristy36421ee2015-08-28 11:58:20 -04001212 if (image->image_info != (ImageInfo *) NULL)
1213 image->image_info=DestroyImageInfo(image->image_info);
cristy3ed852e2009-09-05 21:47:34 +00001214 DestroyBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001215 if (image->semaphore != (SemaphoreInfo *) NULL)
cristy3d162a92014-02-16 14:05:06 +00001216 RelinquishSemaphoreInfo(&image->semaphore);
cristye1c94d92015-06-28 12:16:33 +00001217 image->signature=(~MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001218 image=(Image *) RelinquishMagickMemory(image);
1219 return(image);
1220}
1221
1222/*
1223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1224% %
1225% %
1226% %
1227% D e s t r o y I m a g e I n f o %
1228% %
1229% %
1230% %
1231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1232%
1233% DestroyImageInfo() deallocates memory associated with an ImageInfo
1234% structure.
1235%
1236% The format of the DestroyImageInfo method is:
1237%
1238% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1239%
1240% A description of each parameter follows:
1241%
1242% o image_info: the image info.
1243%
1244*/
1245MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1246{
1247 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001248 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001249 if (image_info->debug != MagickFalse)
1250 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1251 image_info->filename);
1252 if (image_info->size != (char *) NULL)
1253 image_info->size=DestroyString(image_info->size);
1254 if (image_info->extract != (char *) NULL)
1255 image_info->extract=DestroyString(image_info->extract);
1256 if (image_info->scenes != (char *) NULL)
1257 image_info->scenes=DestroyString(image_info->scenes);
1258 if (image_info->page != (char *) NULL)
1259 image_info->page=DestroyString(image_info->page);
1260 if (image_info->sampling_factor != (char *) NULL)
1261 image_info->sampling_factor=DestroyString(
1262 image_info->sampling_factor);
1263 if (image_info->server_name != (char *) NULL)
1264 image_info->server_name=DestroyString(
1265 image_info->server_name);
1266 if (image_info->font != (char *) NULL)
1267 image_info->font=DestroyString(image_info->font);
1268 if (image_info->texture != (char *) NULL)
1269 image_info->texture=DestroyString(image_info->texture);
1270 if (image_info->density != (char *) NULL)
1271 image_info->density=DestroyString(image_info->density);
cristy3ed852e2009-09-05 21:47:34 +00001272 if (image_info->cache != (void *) NULL)
1273 image_info->cache=DestroyPixelCache(image_info->cache);
1274 if (image_info->profile != (StringInfo *) NULL)
1275 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1276 image_info->profile);
anthony1afdc7a2011-10-05 11:54:28 +00001277 DestroyImageOptions(image_info);
cristye1c94d92015-06-28 12:16:33 +00001278 image_info->signature=(~MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001279 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1280 return(image_info);
1281}
1282
1283/*
1284%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1285% %
1286% %
1287% %
1288+ D i s a s s o c i a t e I m a g e S t r e a m %
1289% %
1290% %
1291% %
1292%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1293%
cristy4916cb42014-09-20 00:44:37 +00001294% DisassociateImageStream() disassociates the image stream. It checks if the
1295% blob of the specified image is referenced by other images. If the reference
1296% count is higher then 1 a new blob is assigned to the specified image.
cristy3ed852e2009-09-05 21:47:34 +00001297%
1298% The format of the DisassociateImageStream method is:
1299%
dirkcfe4c1c2014-09-20 07:38:59 +00001300% void DisassociateImageStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001301%
1302% A description of each parameter follows:
1303%
1304% o image: the image.
1305%
1306*/
1307MagickExport void DisassociateImageStream(Image *image)
1308{
cristy4916cb42014-09-20 00:44:37 +00001309 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001310 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001311 if (image->debug != MagickFalse)
1312 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy10f10ec2014-09-20 01:00:50 +00001313 DisassociateBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001314}
1315
1316/*
1317%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1318% %
1319% %
1320% %
cristy3ed852e2009-09-05 21:47:34 +00001321% G e t I m a g e I n f o %
1322% %
1323% %
1324% %
1325%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1326%
1327% GetImageInfo() initializes image_info to default values.
1328%
1329% The format of the GetImageInfo method is:
1330%
1331% void GetImageInfo(ImageInfo *image_info)
1332%
1333% A description of each parameter follows:
1334%
1335% o image_info: the image info.
1336%
1337*/
1338MagickExport void GetImageInfo(ImageInfo *image_info)
1339{
cristyfa0ea942012-12-21 02:42:29 +00001340 char
1341 *synchronize;
1342
cristy3ed852e2009-09-05 21:47:34 +00001343 ExceptionInfo
1344 *exception;
1345
1346 /*
1347 File and image dimension members.
1348 */
1349 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1350 assert(image_info != (ImageInfo *) NULL);
1351 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1352 image_info->adjoin=MagickTrue;
1353 image_info->interlace=NoInterlace;
1354 image_info->channel=DefaultChannels;
1355 image_info->quality=UndefinedCompressionQuality;
1356 image_info->antialias=MagickTrue;
1357 image_info->dither=MagickTrue;
cristyfa0ea942012-12-21 02:42:29 +00001358 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1359 if (synchronize != (const char *) NULL)
1360 {
1361 image_info->synchronize=IsStringTrue(synchronize);
1362 synchronize=DestroyString(synchronize);
1363 }
cristy3ed852e2009-09-05 21:47:34 +00001364 exception=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00001365 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1366 &image_info->background_color,exception);
1367 (void) QueryColorCompliance(BorderColor,AllCompliance,
1368 &image_info->border_color,exception);
1369 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
cristy3ed852e2009-09-05 21:47:34 +00001370 exception);
cristy9950d572011-10-01 18:22:35 +00001371 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1372 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00001373 exception=DestroyExceptionInfo(exception);
1374 image_info->debug=IsEventLogging();
cristye1c94d92015-06-28 12:16:33 +00001375 image_info->signature=MagickCoreSignature;
cristy3ed852e2009-09-05 21:47:34 +00001376}
1377
1378/*
1379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1380% %
1381% %
1382% %
cristy15781e52009-12-05 23:05:27 +00001383% G e t I m a g e I n f o F i l e %
1384% %
1385% %
1386% %
1387%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1388%
1389% GetImageInfoFile() returns the image info file member.
1390%
1391% The format of the GetImageInfoFile method is:
1392%
1393% FILE *GetImageInfoFile(const ImageInfo *image_info)
1394%
1395% A description of each parameter follows:
1396%
1397% o image_info: the image info.
1398%
1399*/
1400MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1401{
1402 return(image_info->file);
1403}
1404
1405/*
1406%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1407% %
1408% %
1409% %
cristy3ed852e2009-09-05 21:47:34 +00001410% G e t I m a g e M a s k %
1411% %
1412% %
1413% %
1414%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1415%
1416% GetImageMask() returns the mask associated with the image.
1417%
1418% The format of the GetImageMask method is:
1419%
dirkaf131f12016-01-10 01:29:22 +01001420% Image *GetImageMask(const Image *image,const PixelMask type,
1421% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001422%
1423% A description of each parameter follows:
1424%
1425% o image: the image.
1426%
dirkaf131f12016-01-10 01:29:22 +01001427% o type: the mask type, ReadPixelMask or WritePixelMask.
1428%
cristy3ed852e2009-09-05 21:47:34 +00001429*/
dirkaf131f12016-01-10 01:29:22 +01001430MagickExport Image *GetImageMask(const Image *image,const PixelMask type,
1431 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001432{
cristy10a6c612012-01-29 21:41:05 +00001433 CacheView
1434 *mask_view,
1435 *image_view;
1436
1437 Image
1438 *mask_image;
1439
1440 MagickBooleanType
1441 status;
1442
1443 ssize_t
1444 y;
1445
1446 /*
1447 Get image mask.
1448 */
1449 assert(image != (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001450 if (image->debug != MagickFalse)
1451 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00001452 assert(image->signature == MagickCoreSignature);
cristy10a6c612012-01-29 21:41:05 +00001453 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1454 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001455 return((Image *) NULL);
cristy10a6c612012-01-29 21:41:05 +00001456 status=MagickTrue;
dirk4a26ef62015-11-19 21:47:29 +01001457 mask_image->alpha_trait=UndefinedPixelTrait;
dirkcd1d8792015-11-19 22:46:24 +01001458 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
Cristy0596ce22015-11-20 21:11:22 -05001459 mask_image->read_mask=MagickFalse;
cristy46ff2672012-12-14 15:32:26 +00001460 image_view=AcquireVirtualCacheView(image,exception);
1461 mask_view=AcquireAuthenticCacheView(mask_image,exception);
cristy10a6c612012-01-29 21:41:05 +00001462 for (y=0; y < (ssize_t) image->rows; y++)
1463 {
1464 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01001465 *magick_restrict p;
cristy10a6c612012-01-29 21:41:05 +00001466
1467 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01001468 *magick_restrict q;
cristy10a6c612012-01-29 21:41:05 +00001469
1470 register ssize_t
1471 x;
1472
1473 if (status == MagickFalse)
1474 continue;
1475 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1476 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1477 exception);
1478 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1479 {
1480 status=MagickFalse;
1481 continue;
1482 }
1483 for (x=0; x < (ssize_t) image->columns; x++)
1484 {
dirkaf131f12016-01-10 01:29:22 +01001485 switch (type)
1486 {
1487 case WritePixelMask:
1488 {
1489 SetPixelGray(mask_image,GetPixelWriteMask(image,p),q);
1490 break;
1491 }
1492 default:
1493 {
1494 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
1495 break;
1496 }
1497 }
cristy10a6c612012-01-29 21:41:05 +00001498 p+=GetPixelChannels(image);
1499 q+=GetPixelChannels(mask_image);
1500 }
1501 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1502 status=MagickFalse;
1503 }
1504 mask_view=DestroyCacheView(mask_view);
1505 image_view=DestroyCacheView(image_view);
cristy1c2f48d2012-12-14 01:20:55 +00001506 if (status == MagickFalse)
1507 mask_image=DestroyImage(mask_image);
cristy10a6c612012-01-29 21:41:05 +00001508 return(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001509}
1510
1511/*
1512%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1513% %
1514% %
1515% %
1516+ G e t I m a g e R e f e r e n c e C o u n t %
1517% %
1518% %
1519% %
1520%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1521%
1522% GetImageReferenceCount() returns the image reference count.
1523%
1524% The format of the GetReferenceCount method is:
1525%
cristybb503372010-05-27 20:51:26 +00001526% ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001527%
1528% A description of each parameter follows:
1529%
1530% o image: the image.
1531%
1532*/
cristybb503372010-05-27 20:51:26 +00001533MagickExport ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001534{
cristybb503372010-05-27 20:51:26 +00001535 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001536 reference_count;
1537
1538 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001539 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001540 if (image->debug != MagickFalse)
1541 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001542 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001543 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001544 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001545 return(reference_count);
1546}
1547
1548/*
1549%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1550% %
1551% %
1552% %
cristy3ed852e2009-09-05 21:47:34 +00001553% 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 %
1554% %
1555% %
1556% %
1557%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1558%
1559% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1560% image. A virtual pixel is any pixel access that is outside the boundaries
1561% of the image cache.
1562%
1563% The format of the GetImageVirtualPixelMethod() method is:
1564%
1565% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1566%
1567% A description of each parameter follows:
1568%
1569% o image: the image.
1570%
1571*/
1572MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1573{
1574 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001575 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001576 if (image->debug != MagickFalse)
1577 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1578 return(GetPixelCacheVirtualMethod(image));
1579}
1580
1581/*
1582%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1583% %
1584% %
1585% %
1586% I n t e r p r e t I m a g e F i l e n a m e %
1587% %
1588% %
1589% %
1590%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1591%
1592% InterpretImageFilename() interprets embedded characters in an image filename.
1593% The filename length is returned.
1594%
1595% The format of the InterpretImageFilename method is:
1596%
cristyee2b1232012-03-04 02:58:28 +00001597% size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1598% const char *format,int value,char *filename,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001599%
1600% A description of each parameter follows.
1601%
1602% o image_info: the image info..
1603%
1604% o image: the image.
1605%
1606% o format: A filename describing the format to use to write the numeric
1607% argument. Only the first numeric format identifier is replaced.
1608%
1609% o value: Numeric value to substitute into format filename.
1610%
1611% o filename: return the formatted filename in this character buffer.
1612%
cristy6fccee12011-10-20 18:43:18 +00001613% o exception: return any errors or warnings in this structure.
1614%
cristy3ed852e2009-09-05 21:47:34 +00001615*/
1616MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00001617 Image *image,const char *format,int value,char *filename,
1618 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001619{
1620 char
1621 *q;
1622
1623 int
1624 c;
1625
1626 MagickBooleanType
1627 canonical;
1628
1629 register const char
1630 *p;
1631
cristyad785752011-07-27 23:13:03 +00001632 size_t
1633 length;
1634
cristy3ed852e2009-09-05 21:47:34 +00001635 canonical=MagickFalse;
cristyc7b79fc2011-07-28 00:24:17 +00001636 length=0;
cristy151b66d2015-04-15 10:50:31 +00001637 (void) CopyMagickString(filename,format,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001638 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1639 {
1640 q=(char *) p+1;
1641 if (*q == '%')
1642 {
1643 p=q+1;
1644 continue;
1645 }
1646 if (*q == '0')
1647 {
cristybb503372010-05-27 20:51:26 +00001648 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001649 value;
1650
cristybb503372010-05-27 20:51:26 +00001651 value=(ssize_t) strtol(q,&q,10);
cristyda16f162011-02-19 23:52:17 +00001652 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00001653 }
1654 switch (*q)
1655 {
1656 case 'd':
1657 case 'o':
1658 case 'x':
1659 {
1660 q++;
1661 c=(*q);
1662 *q='\0';
cristyee2f5d62015-07-28 13:19:43 +00001663 (void) FormatLocaleString(filename+(p-format),(size_t)
1664 (MagickPathExtent-(p-format)),p,value);
cristy3ed852e2009-09-05 21:47:34 +00001665 *q=c;
cristy151b66d2015-04-15 10:50:31 +00001666 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001667 canonical=MagickTrue;
1668 if (*(q-1) != '%')
1669 break;
1670 p++;
1671 break;
1672 }
1673 case '[':
1674 {
1675 char
cristy151b66d2015-04-15 10:50:31 +00001676 pattern[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001677
1678 const char
1679 *value;
1680
cristy3ed852e2009-09-05 21:47:34 +00001681 register char
1682 *r;
1683
cristybb503372010-05-27 20:51:26 +00001684 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001685 i;
1686
cristycb6d09b2010-06-19 01:59:36 +00001687 ssize_t
1688 depth;
1689
cristy3ed852e2009-09-05 21:47:34 +00001690 /*
1691 Image option.
1692 */
anthony2cfa1a12012-05-12 05:18:07 +00001693 /* FUTURE: Compare update with code from InterpretImageProperties()
cristy97fc9f32012-06-13 21:04:44 +00001694 Note that a 'filename:' property should not need depth recursion.
anthony2cfa1a12012-05-12 05:18:07 +00001695 */
cristy3ed852e2009-09-05 21:47:34 +00001696 if (strchr(p,']') == (char *) NULL)
1697 break;
1698 depth=1;
1699 r=q+1;
cristy151b66d2015-04-15 10:50:31 +00001700 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
cristy3ed852e2009-09-05 21:47:34 +00001701 {
1702 if (*r == '[')
1703 depth++;
1704 if (*r == ']')
1705 depth--;
1706 if (depth <= 0)
1707 break;
1708 pattern[i]=(*r++);
1709 }
1710 pattern[i]='\0';
1711 if (LocaleNCompare(pattern,"filename:",9) != 0)
1712 break;
1713 value=(const char *) NULL;
anthony06762232012-04-29 11:45:40 +00001714 if (image != (Image *) NULL)
1715 value=GetImageProperty(image,pattern,exception);
cristy1a780952013-02-10 17:15:30 +00001716 if ((value == (const char *) NULL) && (image != (Image *) NULL))
anthony06762232012-04-29 11:45:40 +00001717 value=GetImageArtifact(image,pattern);
1718 if ((value == (const char *) NULL) &&
1719 (image_info != (ImageInfo *) NULL))
1720 value=GetImageOption(image_info,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001721 if (value == (const char *) NULL)
1722 break;
1723 q--;
1724 c=(*q);
1725 *q='\0';
cristyad785752011-07-27 23:13:03 +00001726 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
cristy151b66d2015-04-15 10:50:31 +00001727 (MagickPathExtent-(p-format-length)));
cristyad785752011-07-27 23:13:03 +00001728 length+=strlen(pattern)-1;
cristy3ed852e2009-09-05 21:47:34 +00001729 *q=c;
cristy151b66d2015-04-15 10:50:31 +00001730 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001731 canonical=MagickTrue;
1732 if (*(q-1) != '%')
1733 break;
1734 p++;
1735 break;
1736 }
1737 default:
1738 break;
1739 }
1740 }
1741 for (q=filename; *q != '\0'; q++)
1742 if ((*q == '%') && (*(q+1) == '%'))
cristy27bf23e2011-01-10 13:35:22 +00001743 {
cristy151b66d2015-04-15 10:50:31 +00001744 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
cristy27bf23e2011-01-10 13:35:22 +00001745 canonical=MagickTrue;
1746 }
cristy3ed852e2009-09-05 21:47:34 +00001747 if (canonical == MagickFalse)
cristy151b66d2015-04-15 10:50:31 +00001748 (void) CopyMagickString(filename,format,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001749 return(strlen(filename));
1750}
1751
1752/*
1753%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1754% %
1755% %
1756% %
1757% I s H i g h D y n a m i c R a n g e I m a g e %
1758% %
1759% %
1760% %
1761%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1762%
1763% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1764% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1765% 0..65535.
1766%
1767% The format of the IsHighDynamicRangeImage method is:
1768%
1769% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1770% ExceptionInfo *exception)
1771%
1772% A description of each parameter follows:
1773%
1774% o image: the image.
1775%
1776% o exception: return any errors or warnings in this structure.
1777%
1778*/
1779MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1780 ExceptionInfo *exception)
1781{
1782#if !defined(MAGICKCORE_HDRI_SUPPORT)
1783 (void) image;
1784 (void) exception;
1785 return(MagickFalse);
1786#else
1787 CacheView
1788 *image_view;
1789
cristy3ed852e2009-09-05 21:47:34 +00001790 MagickBooleanType
1791 status;
1792
cristycb6d09b2010-06-19 01:59:36 +00001793 ssize_t
1794 y;
1795
cristy3ed852e2009-09-05 21:47:34 +00001796 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001797 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001798 if (image->debug != MagickFalse)
1799 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1800 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00001801 image_view=AcquireVirtualCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00001802#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00001803 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00001804 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00001805#endif
cristybb503372010-05-27 20:51:26 +00001806 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001807 {
cristy4c08aed2011-07-01 19:47:50 +00001808 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001809 *p;
1810
cristybb503372010-05-27 20:51:26 +00001811 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001812 x;
1813
1814 if (status == MagickFalse)
1815 continue;
1816 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001817 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001818 {
1819 status=MagickFalse;
1820 continue;
1821 }
cristybb503372010-05-27 20:51:26 +00001822 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001823 {
cristya905c052011-09-17 22:37:55 +00001824 register ssize_t
1825 i;
1826
cristy883fde12013-04-08 00:50:13 +00001827 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +00001828 {
1829 p+=GetPixelChannels(image);
1830 continue;
1831 }
cristya905c052011-09-17 22:37:55 +00001832 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1833 {
cristya19f1d72012-08-07 18:24:38 +00001834 double
cristya905c052011-09-17 22:37:55 +00001835 pixel;
1836
cristyb0a657e2012-08-29 00:45:37 +00001837 PixelTrait
1838 traits;
1839
1840 traits=GetPixelChannelTraits(image,(PixelChannel) i);
cristya905c052011-09-17 22:37:55 +00001841 if (traits == UndefinedPixelTrait)
1842 continue;
cristya19f1d72012-08-07 18:24:38 +00001843 pixel=(double) p[i];
cristya905c052011-09-17 22:37:55 +00001844 if ((pixel < 0.0) || (pixel > QuantumRange) ||
cristy569b0e32013-08-15 16:07:35 +00001845 (pixel != (double) ((QuantumAny) pixel)))
cristya905c052011-09-17 22:37:55 +00001846 break;
1847 }
cristyed231572011-07-14 02:18:59 +00001848 p+=GetPixelChannels(image);
cristya905c052011-09-17 22:37:55 +00001849 if (i < (ssize_t) GetPixelChannels(image))
1850 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00001851 }
cristybb503372010-05-27 20:51:26 +00001852 if (x < (ssize_t) image->columns)
cristy3ed852e2009-09-05 21:47:34 +00001853 status=MagickFalse;
1854 }
1855 image_view=DestroyCacheView(image_view);
1856 return(status != MagickFalse ? MagickFalse : MagickTrue);
1857#endif
1858}
1859
1860/*
1861%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1862% %
1863% %
1864% %
1865% I s I m a g e O b j e c t %
1866% %
1867% %
1868% %
1869%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1870%
1871% IsImageObject() returns MagickTrue if the image sequence contains a valid
1872% set of image objects.
1873%
1874% The format of the IsImageObject method is:
1875%
1876% MagickBooleanType IsImageObject(const Image *image)
1877%
1878% A description of each parameter follows:
1879%
1880% o image: the image.
1881%
1882*/
1883MagickExport MagickBooleanType IsImageObject(const Image *image)
1884{
1885 register const Image
1886 *p;
1887
1888 assert(image != (Image *) NULL);
1889 if (image->debug != MagickFalse)
1890 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1891 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
cristye1c94d92015-06-28 12:16:33 +00001892 if (p->signature != MagickCoreSignature)
cristy3ed852e2009-09-05 21:47:34 +00001893 return(MagickFalse);
1894 return(MagickTrue);
1895}
1896
1897/*
1898%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1899% %
1900% %
1901% %
1902% I s T a i n t I m a g e %
1903% %
1904% %
1905% %
1906%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1907%
1908% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1909% since it was first constituted.
1910%
1911% The format of the IsTaintImage method is:
1912%
1913% MagickBooleanType IsTaintImage(const Image *image)
1914%
1915% A description of each parameter follows:
1916%
1917% o image: the image.
1918%
1919*/
1920MagickExport MagickBooleanType IsTaintImage(const Image *image)
1921{
1922 char
cristy151b66d2015-04-15 10:50:31 +00001923 magick[MagickPathExtent],
1924 filename[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001925
1926 register const Image
1927 *p;
1928
1929 assert(image != (Image *) NULL);
1930 if (image->debug != MagickFalse)
1931 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00001932 assert(image->signature == MagickCoreSignature);
cristy151b66d2015-04-15 10:50:31 +00001933 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1934 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001935 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1936 {
1937 if (p->taint != MagickFalse)
1938 return(MagickTrue);
1939 if (LocaleCompare(p->magick,magick) != 0)
1940 return(MagickTrue);
1941 if (LocaleCompare(p->filename,filename) != 0)
1942 return(MagickTrue);
1943 }
1944 return(MagickFalse);
1945}
1946
1947/*
1948%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1949% %
1950% %
1951% %
1952% M o d i f y I m a g e %
1953% %
1954% %
1955% %
1956%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1957%
1958% ModifyImage() ensures that there is only a single reference to the image
1959% to be modified, updating the provided image pointer to point to a clone of
1960% the original image if necessary.
1961%
1962% The format of the ModifyImage method is:
1963%
1964% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1965%
1966% A description of each parameter follows:
1967%
1968% o image: the image.
1969%
1970% o exception: return any errors or warnings in this structure.
1971%
1972*/
1973MagickExport MagickBooleanType ModifyImage(Image **image,
1974 ExceptionInfo *exception)
1975{
1976 Image
1977 *clone_image;
1978
1979 assert(image != (Image **) NULL);
1980 assert(*image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001981 assert((*image)->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001982 if ((*image)->debug != MagickFalse)
1983 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1984 if (GetImageReferenceCount(*image) <= 1)
1985 return(MagickTrue);
1986 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
cristyf84a1932010-01-03 18:00:18 +00001987 LockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001988 (*image)->reference_count--;
cristyf84a1932010-01-03 18:00:18 +00001989 UnlockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001990 *image=clone_image;
1991 return(MagickTrue);
1992}
1993
1994/*
1995%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1996% %
1997% %
1998% %
1999% N e w M a g i c k I m a g e %
2000% %
2001% %
2002% %
2003%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2004%
2005% NewMagickImage() creates a blank image canvas of the specified size and
2006% background color.
2007%
2008% The format of the NewMagickImage method is:
2009%
cristy44410ab2014-05-25 20:39:43 +00002010% Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
2011% const size_t height,const PixelInfo *background,
cristy0740a982011-10-13 15:01:01 +00002012% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002013%
2014% A description of each parameter follows:
2015%
2016% o image: the image.
2017%
2018% o width: the image width.
2019%
2020% o height: the image height.
2021%
2022% o background: the image color.
2023%
cristy0740a982011-10-13 15:01:01 +00002024% o exception: return any errors or warnings in this structure.
2025%
cristy3ed852e2009-09-05 21:47:34 +00002026*/
2027MagickExport Image *NewMagickImage(const ImageInfo *image_info,
cristy0740a982011-10-13 15:01:01 +00002028 const size_t width,const size_t height,const PixelInfo *background,
2029 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002030{
2031 CacheView
2032 *image_view;
2033
cristy3ed852e2009-09-05 21:47:34 +00002034 Image
2035 *image;
2036
cristy3ed852e2009-09-05 21:47:34 +00002037 MagickBooleanType
2038 status;
2039
cristya905c052011-09-17 22:37:55 +00002040 ssize_t
2041 y;
2042
cristy3ed852e2009-09-05 21:47:34 +00002043 assert(image_info != (const ImageInfo *) NULL);
2044 if (image_info->debug != MagickFalse)
2045 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002046 assert(image_info->signature == MagickCoreSignature);
cristy4c08aed2011-07-01 19:47:50 +00002047 assert(background != (const PixelInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00002048 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00002049 image->columns=width;
2050 image->rows=height;
2051 image->colorspace=background->colorspace;
cristy8a46d822012-08-28 23:32:39 +00002052 image->alpha_trait=background->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +00002053 image->fuzz=background->fuzz;
2054 image->depth=background->depth;
2055 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002056 image_view=AcquireAuthenticCacheView(image,exception);
cristy48974b92009-12-19 02:36:06 +00002057#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00002058 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00002059 magick_threads(image,image,image->rows,1)
cristy48974b92009-12-19 02:36:06 +00002060#endif
cristybb503372010-05-27 20:51:26 +00002061 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002062 {
cristy4c08aed2011-07-01 19:47:50 +00002063 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01002064 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002065
cristycb6d09b2010-06-19 01:59:36 +00002066 register ssize_t
2067 x;
2068
cristy48974b92009-12-19 02:36:06 +00002069 if (status == MagickFalse)
2070 continue;
cristy3ed852e2009-09-05 21:47:34 +00002071 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002072 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002073 {
2074 status=MagickFalse;
2075 continue;
2076 }
cristybb503372010-05-27 20:51:26 +00002077 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002078 {
cristy11a06d32015-01-04 12:03:27 +00002079 SetPixelViaPixelInfo(image,background,q);
cristyed231572011-07-14 02:18:59 +00002080 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00002081 }
2082 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2083 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002084 }
2085 image_view=DestroyCacheView(image_view);
2086 if (status == MagickFalse)
2087 image=DestroyImage(image);
2088 return(image);
2089}
2090
2091/*
2092%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2093% %
2094% %
2095% %
2096% R e f e r e n c e I m a g e %
2097% %
2098% %
2099% %
2100%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2101%
2102% ReferenceImage() increments the reference count associated with an image
2103% returning a pointer to the image.
2104%
2105% The format of the ReferenceImage method is:
2106%
2107% Image *ReferenceImage(Image *image)
2108%
2109% A description of each parameter follows:
2110%
2111% o image: the image.
2112%
2113*/
2114MagickExport Image *ReferenceImage(Image *image)
2115{
2116 assert(image != (Image *) NULL);
2117 if (image->debug != MagickFalse)
2118 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002119 assert(image->signature == MagickCoreSignature);
cristyf84a1932010-01-03 18:00:18 +00002120 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002121 image->reference_count++;
cristyf84a1932010-01-03 18:00:18 +00002122 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002123 return(image);
2124}
2125
2126/*
2127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2128% %
2129% %
2130% %
2131% R e s e t I m a g e P a g e %
2132% %
2133% %
2134% %
2135%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2136%
2137% ResetImagePage() resets the image page canvas and position.
2138%
2139% The format of the ResetImagePage method is:
2140%
2141% MagickBooleanType ResetImagePage(Image *image,const char *page)
2142%
2143% A description of each parameter follows:
2144%
2145% o image: the image.
2146%
2147% o page: the relative page specification.
2148%
2149*/
2150MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2151{
2152 MagickStatusType
2153 flags;
2154
2155 RectangleInfo
2156 geometry;
2157
2158 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002159 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002160 if (image->debug != MagickFalse)
2161 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2162 flags=ParseAbsoluteGeometry(page,&geometry);
2163 if ((flags & WidthValue) != 0)
2164 {
2165 if ((flags & HeightValue) == 0)
2166 geometry.height=geometry.width;
2167 image->page.width=geometry.width;
2168 image->page.height=geometry.height;
2169 }
2170 if ((flags & AspectValue) != 0)
2171 {
2172 if ((flags & XValue) != 0)
2173 image->page.x+=geometry.x;
2174 if ((flags & YValue) != 0)
2175 image->page.y+=geometry.y;
2176 }
2177 else
2178 {
2179 if ((flags & XValue) != 0)
2180 {
2181 image->page.x=geometry.x;
2182 if ((image->page.width == 0) && (geometry.x > 0))
2183 image->page.width=image->columns+geometry.x;
2184 }
2185 if ((flags & YValue) != 0)
2186 {
2187 image->page.y=geometry.y;
2188 if ((image->page.height == 0) && (geometry.y > 0))
2189 image->page.height=image->rows+geometry.y;
2190 }
2191 }
2192 return(MagickTrue);
2193}
2194
2195/*
2196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2197% %
2198% %
2199% %
cristy3ed852e2009-09-05 21:47:34 +00002200% S e t I m a g e B a c k g r o u n d C o l o r %
2201% %
2202% %
2203% %
2204%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2205%
2206% SetImageBackgroundColor() initializes the image pixels to the image
2207% background color. The background color is defined by the background_color
2208% member of the image structure.
2209%
2210% The format of the SetImage method is:
2211%
cristyea1a8aa2011-10-20 13:24:06 +00002212% MagickBooleanType SetImageBackgroundColor(Image *image,
2213% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002214%
2215% A description of each parameter follows:
2216%
2217% o image: the image.
2218%
cristyea1a8aa2011-10-20 13:24:06 +00002219% o exception: return any errors or warnings in this structure.
2220%
cristy3ed852e2009-09-05 21:47:34 +00002221*/
cristyea1a8aa2011-10-20 13:24:06 +00002222MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2223 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002224{
2225 CacheView
2226 *image_view;
2227
cristy3ed852e2009-09-05 21:47:34 +00002228 MagickBooleanType
2229 status;
2230
dirkdc896c12014-10-15 16:28:15 +00002231 PixelInfo
2232 background;
2233
cristycb6d09b2010-06-19 01:59:36 +00002234 ssize_t
2235 y;
2236
cristy3ed852e2009-09-05 21:47:34 +00002237 assert(image != (Image *) NULL);
2238 if (image->debug != MagickFalse)
2239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002240 assert(image->signature == MagickCoreSignature);
cristy574cc262011-08-05 01:23:58 +00002241 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002242 return(MagickFalse);
dirkbfdd5bc2014-11-04 19:47:44 +00002243 ConformPixelInfo(image,&image->background_color,&background,exception);
cristy3ed852e2009-09-05 21:47:34 +00002244 /*
2245 Set image background color.
2246 */
2247 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002248 image_view=AcquireAuthenticCacheView(image,exception);
cristybb503372010-05-27 20:51:26 +00002249 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002250 {
cristy4c08aed2011-07-01 19:47:50 +00002251 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01002252 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002253
cristycb6d09b2010-06-19 01:59:36 +00002254 register ssize_t
2255 x;
2256
cristy3ed852e2009-09-05 21:47:34 +00002257 if (status == MagickFalse)
2258 continue;
2259 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002260 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002261 {
2262 status=MagickFalse;
2263 continue;
2264 }
cristybb503372010-05-27 20:51:26 +00002265 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +00002266 {
cristy11a06d32015-01-04 12:03:27 +00002267 SetPixelViaPixelInfo(image,&background,q);
cristyed231572011-07-14 02:18:59 +00002268 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002269 }
cristy3ed852e2009-09-05 21:47:34 +00002270 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2271 status=MagickFalse;
2272 }
2273 image_view=DestroyCacheView(image_view);
2274 return(status);
2275}
2276
2277/*
2278%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2279% %
2280% %
2281% %
cristycf1296e2012-08-26 23:40:49 +00002282% S e t I m a g e C h a n n e l M a s k %
2283% %
2284% %
2285% %
2286%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2287%
2288% SetImageChannelMask() sets the image channel mask from the specified channel
2289% mask.
2290%
2291% The format of the SetImageChannelMask method is:
2292%
2293% ChannelType SetImageChannelMask(Image *image,
2294% const ChannelType channel_mask)
2295%
2296% A description of each parameter follows:
2297%
2298% o image: the image.
2299%
2300% o channel_mask: the channel mask.
2301%
2302*/
2303MagickExport ChannelType SetImageChannelMask(Image *image,
2304 const ChannelType channel_mask)
2305{
cristybcd59342015-06-07 14:07:19 +00002306 return(SetPixelChannelMask(image,channel_mask));
cristycf1296e2012-08-26 23:40:49 +00002307}
2308
2309/*
2310%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2311% %
2312% %
2313% %
cristya5b77cb2010-05-07 19:34:48 +00002314% S e t I m a g e C o l o r %
2315% %
2316% %
2317% %
2318%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2319%
2320% SetImageColor() set the entire image canvas to the specified color.
2321%
2322% The format of the SetImageColor method is:
2323%
cristye941a752011-10-15 01:52:48 +00002324% MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2325% ExeptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002326%
2327% A description of each parameter follows:
2328%
2329% o image: the image.
2330%
2331% o background: the image color.
2332%
cristye941a752011-10-15 01:52:48 +00002333% o exception: return any errors or warnings in this structure.
2334%
cristya5b77cb2010-05-07 19:34:48 +00002335*/
2336MagickExport MagickBooleanType SetImageColor(Image *image,
cristye941a752011-10-15 01:52:48 +00002337 const PixelInfo *color,ExceptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002338{
2339 CacheView
2340 *image_view;
2341
cristya5b77cb2010-05-07 19:34:48 +00002342 MagickBooleanType
2343 status;
2344
cristycb6d09b2010-06-19 01:59:36 +00002345 ssize_t
2346 y;
2347
cristya5b77cb2010-05-07 19:34:48 +00002348 assert(image != (Image *) NULL);
2349 if (image->debug != MagickFalse)
2350 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002351 assert(image->signature == MagickCoreSignature);
cristy4c08aed2011-07-01 19:47:50 +00002352 assert(color != (const PixelInfo *) NULL);
cristya5b77cb2010-05-07 19:34:48 +00002353 image->colorspace=color->colorspace;
cristy8a46d822012-08-28 23:32:39 +00002354 image->alpha_trait=color->alpha_trait;
cristya5b77cb2010-05-07 19:34:48 +00002355 image->fuzz=color->fuzz;
2356 image->depth=color->depth;
2357 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002358 image_view=AcquireAuthenticCacheView(image,exception);
cristya5b77cb2010-05-07 19:34:48 +00002359#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00002360 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00002361 magick_threads(image,image,image->rows,1)
cristya5b77cb2010-05-07 19:34:48 +00002362#endif
cristybb503372010-05-27 20:51:26 +00002363 for (y=0; y < (ssize_t) image->rows; y++)
cristya5b77cb2010-05-07 19:34:48 +00002364 {
cristy4c08aed2011-07-01 19:47:50 +00002365 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01002366 *magick_restrict q;
cristya5b77cb2010-05-07 19:34:48 +00002367
cristycb6d09b2010-06-19 01:59:36 +00002368 register ssize_t
2369 x;
2370
cristya5b77cb2010-05-07 19:34:48 +00002371 if (status == MagickFalse)
2372 continue;
2373 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002374 if (q == (Quantum *) NULL)
cristya5b77cb2010-05-07 19:34:48 +00002375 {
2376 status=MagickFalse;
2377 continue;
2378 }
cristybb503372010-05-27 20:51:26 +00002379 for (x=0; x < (ssize_t) image->columns; x++)
cristya5b77cb2010-05-07 19:34:48 +00002380 {
cristy11a06d32015-01-04 12:03:27 +00002381 SetPixelViaPixelInfo(image,color,q);
cristyed231572011-07-14 02:18:59 +00002382 q+=GetPixelChannels(image);
cristya5b77cb2010-05-07 19:34:48 +00002383 }
2384 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2385 status=MagickFalse;
2386 }
2387 image_view=DestroyCacheView(image_view);
2388 return(status);
2389}
2390
2391/*
2392%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2393% %
2394% %
2395% %
cristy3ed852e2009-09-05 21:47:34 +00002396% S e t I m a g e S t o r a g e C l a s s %
2397% %
2398% %
2399% %
2400%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2401%
2402% SetImageStorageClass() sets the image class: DirectClass for true color
2403% images or PseudoClass for colormapped images.
2404%
2405% The format of the SetImageStorageClass method is:
2406%
2407% MagickBooleanType SetImageStorageClass(Image *image,
cristy63240882011-08-05 19:05:27 +00002408% const ClassType storage_class,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002409%
2410% A description of each parameter follows:
2411%
2412% o image: the image.
2413%
2414% o storage_class: The image class.
2415%
cristy574cc262011-08-05 01:23:58 +00002416% o exception: return any errors or warnings in this structure.
2417%
cristy3ed852e2009-09-05 21:47:34 +00002418*/
2419MagickExport MagickBooleanType SetImageStorageClass(Image *image,
cristy574cc262011-08-05 01:23:58 +00002420 const ClassType storage_class,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002421{
cristy3ed852e2009-09-05 21:47:34 +00002422 image->storage_class=storage_class;
cristy6e437132011-08-12 13:02:19 +00002423 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002424}
2425
2426/*
2427%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2428% %
2429% %
2430% %
cristy3ed852e2009-09-05 21:47:34 +00002431% S e t I m a g e E x t e n t %
2432% %
2433% %
2434% %
2435%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2436%
2437% SetImageExtent() sets the image size (i.e. columns & rows).
2438%
2439% The format of the SetImageExtent method is:
2440%
cristy08429172011-07-14 17:18:16 +00002441% MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002442% const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002443%
2444% A description of each parameter follows:
2445%
2446% o image: the image.
2447%
2448% o columns: The image width in pixels.
2449%
2450% o rows: The image height in pixels.
2451%
cristy63240882011-08-05 19:05:27 +00002452% o exception: return any errors or warnings in this structure.
2453%
cristy3ed852e2009-09-05 21:47:34 +00002454*/
cristy08429172011-07-14 17:18:16 +00002455MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002456 const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002457{
cristy537e2722010-09-21 15:30:59 +00002458 if ((columns == 0) || (rows == 0))
2459 return(MagickFalse);
2460 image->columns=columns;
2461 image->rows=rows;
cristyda950bb2015-07-18 23:17:28 +00002462 if (image->depth > (8*sizeof(MagickSizeType)))
2463 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
cristy6e437132011-08-12 13:02:19 +00002464 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002465}
2466
2467/*
2468%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2469% %
2470% %
2471% %
2472+ S e t I m a g e I n f o %
2473% %
2474% %
2475% %
2476%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2477%
anthonye5b39652012-04-21 05:37:29 +00002478% SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
cristy3ed852e2009-09-05 21:47:34 +00002479% It is set to a type of image format based on the prefix or suffix of the
anthonye5b39652012-04-21 05:37:29 +00002480% filename. For example, 'ps:image' returns PS indicating a Postscript image.
2481% JPEG is returned for this filename: 'image.jpg'. The filename prefix has
cristy3ed852e2009-09-05 21:47:34 +00002482% precendence over the suffix. Use an optional index enclosed in brackets
2483% after a file name to specify a desired scene of a multi-resolution image
2484% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2485% indicates success.
2486%
2487% The format of the SetImageInfo method is:
2488%
2489% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002490% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002491%
2492% A description of each parameter follows:
2493%
cristyd965a422010-03-03 17:47:35 +00002494% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00002495%
cristyd965a422010-03-03 17:47:35 +00002496% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00002497%
2498% o exception: return any errors or warnings in this structure.
2499%
2500*/
2501MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002502 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002503{
2504 char
dirk8f681612015-04-16 21:05:08 +00002505 component[MagickPathExtent],
cristy151b66d2015-04-15 10:50:31 +00002506 magic[MagickPathExtent],
dirk8f681612015-04-16 21:05:08 +00002507 *q;
cristy3ed852e2009-09-05 21:47:34 +00002508
2509 const MagicInfo
2510 *magic_info;
2511
2512 const MagickInfo
2513 *magick_info;
2514
2515 ExceptionInfo
2516 *sans_exception;
2517
2518 Image
2519 *image;
2520
2521 MagickBooleanType
2522 status;
2523
2524 register const char
2525 *p;
2526
2527 ssize_t
2528 count;
2529
cristy3ed852e2009-09-05 21:47:34 +00002530 /*
2531 Look for 'image.format' in filename.
2532 */
2533 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002534 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002535 if (image_info->debug != MagickFalse)
2536 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2537 image_info->filename);
dirk8f681612015-04-16 21:05:08 +00002538 *component='\0';
2539 GetPathComponent(image_info->filename,SubimagePath,component);
2540 if (*component != '\0')
cristy3ed852e2009-09-05 21:47:34 +00002541 {
cristy4f96a1d2014-01-04 15:31:36 +00002542 /*
2543 Look for scene specification (e.g. img0001.pcd[4]).
2544 */
dirk8f681612015-04-16 21:05:08 +00002545 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002546 {
dirk8f681612015-04-16 21:05:08 +00002547 if (IsGeometry(component) != MagickFalse)
2548 (void) CloneString(&image_info->extract,component);
cristy4f96a1d2014-01-04 15:31:36 +00002549 }
2550 else
2551 {
2552 size_t
2553 first,
2554 last;
cristy3ed852e2009-09-05 21:47:34 +00002555
dirk8f681612015-04-16 21:05:08 +00002556 (void) CloneString(&image_info->scenes,component);
cristy4f96a1d2014-01-04 15:31:36 +00002557 image_info->scene=StringToUnsignedLong(image_info->scenes);
2558 image_info->number_scenes=image_info->scene;
2559 p=image_info->scenes;
2560 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2561 {
2562 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2563 p++;
2564 first=(size_t) strtol(p,&q,10);
2565 last=first;
2566 while (isspace((int) ((unsigned char) *q)) != 0)
2567 q++;
2568 if (*q == '-')
2569 last=(size_t) strtol(q+1,&q,10);
2570 if (first > last)
2571 Swap(first,last);
2572 if (first < image_info->scene)
2573 image_info->scene=first;
2574 if (last > image_info->number_scenes)
2575 image_info->number_scenes=last;
2576 p=q;
2577 }
2578 image_info->number_scenes-=image_info->scene-1;
cristy3ed852e2009-09-05 21:47:34 +00002579 }
2580 }
dirk8f681612015-04-16 21:05:08 +00002581 *component='\0';
cristy6f7cebf2014-12-27 12:10:39 +00002582 if (*image_info->magick == '\0')
dirk8f681612015-04-16 21:05:08 +00002583 GetPathComponent(image_info->filename,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002584#if defined(MAGICKCORE_ZLIB_DELEGATE)
dirk8f681612015-04-16 21:05:08 +00002585 if (*component != '\0')
2586 if ((LocaleCompare(component,"gz") == 0) ||
2587 (LocaleCompare(component,"Z") == 0) ||
2588 (LocaleCompare(component,"svgz") == 0) ||
2589 (LocaleCompare(component,"wmz") == 0))
cristy3ed852e2009-09-05 21:47:34 +00002590 {
2591 char
cristy151b66d2015-04-15 10:50:31 +00002592 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002593
cristy151b66d2015-04-15 10:50:31 +00002594 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
dirk8f681612015-04-16 21:05:08 +00002595 path[strlen(path)-strlen(component)-1]='\0';
2596 GetPathComponent(path,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002597 }
2598#endif
2599#if defined(MAGICKCORE_BZLIB_DELEGATE)
dirk8f681612015-04-16 21:05:08 +00002600 if (*component != '\0')
2601 if (LocaleCompare(component,"bz2") == 0)
cristy3ed852e2009-09-05 21:47:34 +00002602 {
2603 char
cristy151b66d2015-04-15 10:50:31 +00002604 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002605
cristy151b66d2015-04-15 10:50:31 +00002606 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
dirk8f681612015-04-16 21:05:08 +00002607 path[strlen(path)-strlen(component)-1]='\0';
2608 GetPathComponent(path,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002609 }
2610#endif
2611 image_info->affirm=MagickFalse;
2612 sans_exception=AcquireExceptionInfo();
dirk8f681612015-04-16 21:05:08 +00002613 if (*component != '\0')
cristy3ed852e2009-09-05 21:47:34 +00002614 {
2615 MagickFormatType
2616 format_type;
2617
cristybb503372010-05-27 20:51:26 +00002618 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002619 i;
2620
2621 static const char
2622 *format_type_formats[] =
2623 {
2624 "AUTOTRACE",
2625 "BROWSE",
2626 "DCRAW",
2627 "EDIT",
2628 "EPHEMERAL",
2629 "LAUNCH",
2630 "MPEG:DECODE",
2631 "MPEG:ENCODE",
2632 "PRINT",
2633 "PS:ALPHA",
2634 "PS:CMYK",
2635 "PS:COLOR",
2636 "PS:GRAY",
2637 "PS:MONO",
2638 "SCAN",
2639 "SHOW",
2640 "WIN",
2641 (char *) NULL
2642 };
2643
2644 /*
2645 User specified image format.
2646 */
dirk8f681612015-04-16 21:05:08 +00002647 (void) CopyMagickString(magic,component,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002648 LocaleUpper(magic);
2649 /*
2650 Look for explicit image formats.
2651 */
2652 format_type=UndefinedFormatType;
dirk80fd8af2015-02-22 00:45:51 +00002653 magick_info=GetMagickInfo(magic,sans_exception);
2654 if ((magick_info != (const MagickInfo *) NULL) &&
2655 (magick_info->format_type != UndefinedFormatType))
2656 format_type=magick_info->format_type;
cristy3ed852e2009-09-05 21:47:34 +00002657 i=0;
cristydd9a2532010-02-20 19:26:46 +00002658 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00002659 (format_type_formats[i] != (char *) NULL))
2660 {
2661 if ((*magic == *format_type_formats[i]) &&
2662 (LocaleCompare(magic,format_type_formats[i]) == 0))
2663 format_type=ExplicitFormatType;
2664 i++;
2665 }
cristy3ed852e2009-09-05 21:47:34 +00002666 if (format_type == UndefinedFormatType)
cristy151b66d2015-04-15 10:50:31 +00002667 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002668 else
2669 if (format_type == ExplicitFormatType)
2670 {
2671 image_info->affirm=MagickTrue;
cristy151b66d2015-04-15 10:50:31 +00002672 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002673 }
2674 if (LocaleCompare(magic,"RGB") == 0)
2675 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2676 }
2677 /*
2678 Look for explicit 'format:image' in filename.
2679 */
2680 *magic='\0';
2681 GetPathComponent(image_info->filename,MagickPath,magic);
2682 if (*magic == '\0')
cristy151b66d2015-04-15 10:50:31 +00002683 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002684 else
2685 {
2686 /*
2687 User specified image format.
2688 */
2689 LocaleUpper(magic);
2690 if (IsMagickConflict(magic) == MagickFalse)
2691 {
cristy151b66d2015-04-15 10:50:31 +00002692 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002693 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2694 image_info->affirm=MagickTrue;
2695 else
2696 image_info->temporary=MagickTrue;
2697 }
2698 }
2699 magick_info=GetMagickInfo(magic,sans_exception);
2700 sans_exception=DestroyExceptionInfo(sans_exception);
2701 if ((magick_info == (const MagickInfo *) NULL) ||
2702 (GetMagickEndianSupport(magick_info) == MagickFalse))
2703 image_info->endian=UndefinedEndian;
dirk8f681612015-04-16 21:05:08 +00002704 GetPathComponent(image_info->filename,CanonicalPath,component);
2705 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002706 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00002707 {
2708 /*
cristyd965a422010-03-03 17:47:35 +00002709 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00002710 */
cristyd965a422010-03-03 17:47:35 +00002711 (void) InterpretImageFilename(image_info,(Image *) NULL,
dirk8f681612015-04-16 21:05:08 +00002712 image_info->filename,(int) image_info->scene,component,exception);
2713 if ((LocaleCompare(component,image_info->filename) != 0) &&
2714 (strchr(component,'%') == (char *) NULL))
cristyd965a422010-03-03 17:47:35 +00002715 image_info->adjoin=MagickFalse;
2716 }
2717 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2718 {
2719 /*
2720 Some image formats do not support multiple frames per file.
2721 */
cristy3ed852e2009-09-05 21:47:34 +00002722 magick_info=GetMagickInfo(magic,exception);
2723 if (magick_info != (const MagickInfo *) NULL)
2724 if (GetMagickAdjoin(magick_info) == MagickFalse)
2725 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002726 }
2727 if (image_info->affirm != MagickFalse)
2728 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00002729 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00002730 {
dirk8f681612015-04-16 21:05:08 +00002731 unsigned char
2732 *magick;
2733
2734 size_t
2735 magick_size;
2736
cristy3ed852e2009-09-05 21:47:34 +00002737 /*
cristyd965a422010-03-03 17:47:35 +00002738 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00002739 */
cristy4f06b882015-04-17 00:16:45 +00002740 magick_size=GetMagicPatternExtent(exception);
dirk8f681612015-04-16 21:05:08 +00002741 if (magick_size == 0)
2742 return(MagickFalse);
cristy9950d572011-10-01 18:22:35 +00002743 image=AcquireImage(image_info,exception);
cristyd965a422010-03-03 17:47:35 +00002744 (void) CopyMagickString(image->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00002745 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002746 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2747 if (status == MagickFalse)
2748 {
2749 image=DestroyImage(image);
2750 return(MagickFalse);
2751 }
cristyd965a422010-03-03 17:47:35 +00002752 if ((IsBlobSeekable(image) == MagickFalse) ||
2753 (IsBlobExempt(image) != MagickFalse))
2754 {
2755 /*
2756 Copy standard input or pipe to temporary file.
2757 */
dirk8f681612015-04-16 21:05:08 +00002758 *component='\0';
2759 status=ImageToFile(image,component,exception);
cristyd965a422010-03-03 17:47:35 +00002760 (void) CloseBlob(image);
2761 if (status == MagickFalse)
2762 {
2763 image=DestroyImage(image);
2764 return(MagickFalse);
2765 }
2766 SetImageInfoFile(image_info,(FILE *) NULL);
dirk8f681612015-04-16 21:05:08 +00002767 (void) CopyMagickString(image->filename,component,MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002768 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2769 if (status == MagickFalse)
2770 {
2771 image=DestroyImage(image);
2772 return(MagickFalse);
2773 }
cristyee2f5d62015-07-28 13:19:43 +00002774 (void) CopyMagickString(image_info->filename,component,
2775 MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002776 image_info->temporary=MagickTrue;
2777 }
dirk8f681612015-04-16 21:05:08 +00002778 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2779 if (magick == (unsigned char *) NULL)
2780 {
2781 (void) CloseBlob(image);
2782 image=DestroyImage(image);
2783 return(MagickFalse);
2784 }
2785 (void) ResetMagickMemory(magick,0,magick_size);
2786 count=ReadBlob(image,magick_size,magick);
cristyae958042013-01-05 15:48:19 +00002787 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
cristyd965a422010-03-03 17:47:35 +00002788 (void) CloseBlob(image);
2789 image=DestroyImage(image);
2790 /*
2791 Check magic.xml configuration file.
2792 */
2793 sans_exception=AcquireExceptionInfo();
2794 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
dirk8f681612015-04-16 21:05:08 +00002795 magick=(unsigned char *) RelinquishMagickMemory(magick);
cristyd965a422010-03-03 17:47:35 +00002796 if ((magic_info != (const MagicInfo *) NULL) &&
2797 (GetMagicName(magic_info) != (char *) NULL))
2798 {
dirkca89a9b2015-02-22 01:19:21 +00002799 /*
2800 Try to use magick_info that was determined earlier by the extension
2801 */
2802 if ((magick_info != (const MagickInfo *) NULL) &&
2803 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2804 (LocaleCompare(magick_info->module,GetMagicName(
2805 magic_info)) == 0))
2806 (void) CopyMagickString(image_info->magick,magick_info->name,
cristy151b66d2015-04-15 10:50:31 +00002807 MagickPathExtent);
dirkca89a9b2015-02-22 01:19:21 +00002808 else
2809 {
2810 (void) CopyMagickString(image_info->magick,GetMagicName(
cristy151b66d2015-04-15 10:50:31 +00002811 magic_info),MagickPathExtent);
dirkca89a9b2015-02-22 01:19:21 +00002812 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2813 }
cristyd965a422010-03-03 17:47:35 +00002814 if ((magick_info == (const MagickInfo *) NULL) ||
2815 (GetMagickEndianSupport(magick_info) == MagickFalse))
2816 image_info->endian=UndefinedEndian;
2817 sans_exception=DestroyExceptionInfo(sans_exception);
2818 return(MagickTrue);
2819 }
cristy3ed852e2009-09-05 21:47:34 +00002820 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2821 if ((magick_info == (const MagickInfo *) NULL) ||
2822 (GetMagickEndianSupport(magick_info) == MagickFalse))
2823 image_info->endian=UndefinedEndian;
2824 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00002825 }
cristy3ed852e2009-09-05 21:47:34 +00002826 return(MagickTrue);
2827}
2828
2829/*
2830%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2831% %
2832% %
2833% %
2834% S e t I m a g e I n f o B l o b %
2835% %
2836% %
2837% %
2838%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2839%
2840% SetImageInfoBlob() sets the image info blob member.
2841%
2842% The format of the SetImageInfoBlob method is:
2843%
2844% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2845% const size_t length)
2846%
2847% A description of each parameter follows:
2848%
2849% o image_info: the image info.
2850%
2851% o blob: the blob.
2852%
2853% o length: the blob length.
2854%
2855*/
2856MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2857 const size_t length)
2858{
2859 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002860 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002861 if (image_info->debug != MagickFalse)
2862 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2863 image_info->filename);
2864 image_info->blob=(void *) blob;
2865 image_info->length=length;
2866}
2867
2868/*
2869%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2870% %
2871% %
2872% %
2873% S e t I m a g e I n f o F i l e %
2874% %
2875% %
2876% %
2877%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2878%
2879% SetImageInfoFile() sets the image info file member.
2880%
2881% The format of the SetImageInfoFile method is:
2882%
2883% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2884%
2885% A description of each parameter follows:
2886%
2887% o image_info: the image info.
2888%
2889% o file: the file.
2890%
2891*/
2892MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2893{
2894 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002895 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002896 if (image_info->debug != MagickFalse)
2897 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2898 image_info->filename);
2899 image_info->file=file;
2900}
2901
2902/*
2903%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2904% %
2905% %
2906% %
2907% S e t I m a g e M a s k %
2908% %
2909% %
2910% %
2911%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2912%
2913% SetImageMask() associates a mask with the image. The mask must be the same
2914% dimensions as the image.
2915%
2916% The format of the SetImageMask method is:
2917%
cristyacd0d4c2015-07-25 16:12:33 +00002918% MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2919% const Image *mask,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002920%
2921% A description of each parameter follows:
2922%
2923% o image: the image.
2924%
cristyacd0d4c2015-07-25 16:12:33 +00002925% o type: the mask type, ReadPixelMask or WritePixelMask.
2926%
cristy3ed852e2009-09-05 21:47:34 +00002927% o mask: the image mask.
2928%
cristy018f07f2011-09-04 21:15:19 +00002929% o exception: return any errors or warnings in this structure.
2930%
cristy3ed852e2009-09-05 21:47:34 +00002931*/
cristyacd0d4c2015-07-25 16:12:33 +00002932MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2933 const Image *mask,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002934{
cristy10a6c612012-01-29 21:41:05 +00002935 CacheView
2936 *mask_view,
2937 *image_view;
2938
2939 MagickBooleanType
2940 status;
2941
2942 ssize_t
2943 y;
2944
2945 /*
2946 Set image mask.
2947 */
cristy3ed852e2009-09-05 21:47:34 +00002948 assert(image != (Image *) NULL);
2949 if (image->debug != MagickFalse)
2950 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002951 assert(image->signature == MagickCoreSignature);
cristy10a6c612012-01-29 21:41:05 +00002952 if (mask == (const Image *) NULL)
2953 {
cristyacd0d4c2015-07-25 16:12:33 +00002954 switch (type)
2955 {
2956 case WritePixelMask: image->write_mask=MagickFalse; break;
2957 default: image->read_mask=MagickFalse; break;
2958 }
cristyd5be1f12013-03-18 23:55:01 +00002959 return(SyncImagePixelCache(image,exception));
cristy10a6c612012-01-29 21:41:05 +00002960 }
cristyacd0d4c2015-07-25 16:12:33 +00002961 switch (type)
2962 {
2963 case WritePixelMask: image->write_mask=MagickTrue; break;
2964 default: image->read_mask=MagickTrue; break;
2965 }
cristyd5be1f12013-03-18 23:55:01 +00002966 if (SyncImagePixelCache(image,exception) == MagickFalse)
2967 return(MagickFalse);
2968 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002969 mask_view=AcquireVirtualCacheView(mask,exception);
2970 image_view=AcquireAuthenticCacheView(image,exception);
cristyd5be1f12013-03-18 23:55:01 +00002971#if defined(MAGICKCORE_OPENMP_SUPPORT)
2972 #pragma omp parallel for schedule(static,4) shared(status) \
2973 magick_threads(mask,image,1,1)
2974#endif
cristy10a6c612012-01-29 21:41:05 +00002975 for (y=0; y < (ssize_t) image->rows; y++)
2976 {
2977 register const Quantum
dirk05d2ff72015-11-18 23:13:43 +01002978 *magick_restrict p;
cristy10a6c612012-01-29 21:41:05 +00002979
2980 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01002981 *magick_restrict q;
cristy10a6c612012-01-29 21:41:05 +00002982
2983 register ssize_t
2984 x;
2985
2986 if (status == MagickFalse)
2987 continue;
2988 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2989 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2990 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2991 {
2992 status=MagickFalse;
2993 continue;
2994 }
2995 for (x=0; x < (ssize_t) image->columns; x++)
2996 {
Cristy0596ce22015-11-20 21:11:22 -05002997 MagickRealType
2998 intensity;
2999
3000 intensity=GetPixelIntensity(mask,p);
cristyacd0d4c2015-07-25 16:12:33 +00003001 switch (type)
3002 {
3003 case WritePixelMask:
3004 {
Cristy0596ce22015-11-20 21:11:22 -05003005 SetPixelWriteMask(image,ClampToQuantum(QuantumRange-intensity),q);
cristyacd0d4c2015-07-25 16:12:33 +00003006 break;
3007 }
3008 default:
3009 {
Cristy0596ce22015-11-20 21:11:22 -05003010 SetPixelReadMask(image,ClampToQuantum(QuantumRange-intensity),q);
cristyacd0d4c2015-07-25 16:12:33 +00003011 break;
3012 }
3013 }
cristy10a6c612012-01-29 21:41:05 +00003014 p+=GetPixelChannels(mask);
3015 q+=GetPixelChannels(image);
3016 }
3017 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3018 status=MagickFalse;
3019 }
3020 mask_view=DestroyCacheView(mask_view);
3021 image_view=DestroyCacheView(image_view);
3022 return(status);
cristy3ed852e2009-09-05 21:47:34 +00003023}
3024
3025/*
3026%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3027% %
3028% %
3029% %
cristyb6a294d2011-10-03 00:55:17 +00003030% S e t I m a g e A l p h a %
cristy3ed852e2009-09-05 21:47:34 +00003031% %
3032% %
3033% %
3034%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3035%
cristye941a752011-10-15 01:52:48 +00003036% SetImageAlpha() sets the alpha levels of the image.
cristy3ed852e2009-09-05 21:47:34 +00003037%
cristyb6a294d2011-10-03 00:55:17 +00003038% The format of the SetImageAlpha method is:
cristy3ed852e2009-09-05 21:47:34 +00003039%
cristye941a752011-10-15 01:52:48 +00003040% MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3041% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003042%
3043% A description of each parameter follows:
3044%
3045% o image: the image.
3046%
cristyb6a294d2011-10-03 00:55:17 +00003047% o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
cristy3ed852e2009-09-05 21:47:34 +00003048% fully transparent.
3049%
3050*/
cristye941a752011-10-15 01:52:48 +00003051MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3052 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003053{
3054 CacheView
3055 *image_view;
3056
cristy3ed852e2009-09-05 21:47:34 +00003057 MagickBooleanType
3058 status;
3059
cristycb6d09b2010-06-19 01:59:36 +00003060 ssize_t
3061 y;
3062
cristy3ed852e2009-09-05 21:47:34 +00003063 assert(image != (Image *) NULL);
3064 if (image->debug != MagickFalse)
3065 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00003066 assert(image->signature == MagickCoreSignature);
cristy8a46d822012-08-28 23:32:39 +00003067 image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00003068 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00003069 image_view=AcquireAuthenticCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003070#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003071 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00003072 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003073#endif
cristybb503372010-05-27 20:51:26 +00003074 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003075 {
cristy4c08aed2011-07-01 19:47:50 +00003076 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01003077 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003078
cristycb6d09b2010-06-19 01:59:36 +00003079 register ssize_t
3080 x;
3081
cristy3ed852e2009-09-05 21:47:34 +00003082 if (status == MagickFalse)
3083 continue;
3084 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00003085 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003086 {
3087 status=MagickFalse;
3088 continue;
3089 }
cristybb503372010-05-27 20:51:26 +00003090 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003091 {
dirk8ce24462015-11-15 16:39:28 +01003092 if (GetPixelReadMask(image,q) != 0)
3093 SetPixelAlpha(image,alpha,q);
cristyed231572011-07-14 02:18:59 +00003094 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00003095 }
3096 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3097 status=MagickFalse;
3098 }
3099 image_view=DestroyCacheView(image_view);
3100 return(status);
3101}
3102
3103/*
3104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3105% %
3106% %
3107% %
cristy3ed852e2009-09-05 21:47:34 +00003108% 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 %
3109% %
3110% %
3111% %
3112%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3113%
3114% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3115% image and returns the previous setting. A virtual pixel is any pixel access
3116% that is outside the boundaries of the image cache.
3117%
3118% The format of the SetImageVirtualPixelMethod() method is:
3119%
cristy387430f2012-02-07 13:09:46 +00003120% VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3121% const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003122%
3123% A description of each parameter follows:
3124%
3125% o image: the image.
3126%
3127% o virtual_pixel_method: choose the type of virtual pixel.
3128%
cristy387430f2012-02-07 13:09:46 +00003129% o exception: return any errors or warnings in this structure.
3130%
cristy3ed852e2009-09-05 21:47:34 +00003131*/
cristy387430f2012-02-07 13:09:46 +00003132MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3133 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003134{
3135 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003136 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00003137 if (image->debug != MagickFalse)
3138 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy387430f2012-02-07 13:09:46 +00003139 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
cristy3ed852e2009-09-05 21:47:34 +00003140}
3141
3142/*
3143%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3144% %
3145% %
3146% %
cristy4285d782011-02-09 20:12:28 +00003147% S m u s h I m a g e s %
3148% %
3149% %
3150% %
3151%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3152%
3153% SmushImages() takes all images from the current image pointer to the end
3154% of the image list and smushes them to each other top-to-bottom if the
3155% stack parameter is true, otherwise left-to-right.
3156%
3157% The current gravity setting now effects how the image is justified in the
3158% final image.
3159%
3160% The format of the SmushImages method is:
3161%
cristy4ca38e22011-02-10 02:57:49 +00003162% Image *SmushImages(const Image *images,const MagickBooleanType stack,
cristy4285d782011-02-09 20:12:28 +00003163% ExceptionInfo *exception)
3164%
3165% A description of each parameter follows:
3166%
cristy4ca38e22011-02-10 02:57:49 +00003167% o images: the image sequence.
cristy4285d782011-02-09 20:12:28 +00003168%
3169% o stack: A value other than 0 stacks the images top-to-bottom.
3170%
3171% o offset: minimum distance in pixels between images.
3172%
3173% o exception: return any errors or warnings in this structure.
3174%
3175*/
cristy4ca38e22011-02-10 02:57:49 +00003176
cristy7c6dc152011-02-11 14:10:55 +00003177static ssize_t SmushXGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003178 const ssize_t offset,ExceptionInfo *exception)
cristy4ca38e22011-02-10 02:57:49 +00003179{
cristy4d727152011-02-10 19:57:21 +00003180 CacheView
3181 *left_view,
3182 *right_view;
3183
3184 const Image
3185 *left_image,
3186 *right_image;
3187
cristy4d727152011-02-10 19:57:21 +00003188 RectangleInfo
3189 left_geometry,
3190 right_geometry;
3191
cristy4c08aed2011-07-01 19:47:50 +00003192 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003193 *p;
3194
cristy4d727152011-02-10 19:57:21 +00003195 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003196 i,
cristy4d727152011-02-10 19:57:21 +00003197 y;
3198
cristy7c6dc152011-02-11 14:10:55 +00003199 size_t
3200 gap;
3201
cristy4d727152011-02-10 19:57:21 +00003202 ssize_t
cristy4d727152011-02-10 19:57:21 +00003203 x;
3204
3205 if (images->previous == (Image *) NULL)
3206 return(0);
3207 right_image=images;
3208 SetGeometry(smush_image,&right_geometry);
3209 GravityAdjustGeometry(right_image->columns,right_image->rows,
3210 right_image->gravity,&right_geometry);
3211 left_image=images->previous;
3212 SetGeometry(smush_image,&left_geometry);
3213 GravityAdjustGeometry(left_image->columns,left_image->rows,
3214 left_image->gravity,&left_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003215 gap=right_image->columns;
cristy46ff2672012-12-14 15:32:26 +00003216 left_view=AcquireVirtualCacheView(left_image,exception);
3217 right_view=AcquireVirtualCacheView(right_image,exception);
cristy4d727152011-02-10 19:57:21 +00003218 for (y=0; y < (ssize_t) smush_image->rows; y++)
3219 {
3220 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3221 {
cristydab7e912011-02-11 18:19:24 +00003222 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003223 if ((p == (const Quantum *) NULL) ||
3224 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
cristy7c6dc152011-02-11 14:10:55 +00003225 ((left_image->columns-x-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003226 break;
3227 }
cristy4ef6f062011-02-10 20:30:22 +00003228 i=(ssize_t) left_image->columns-x-1;
cristy4d727152011-02-10 19:57:21 +00003229 for (x=0; x < (ssize_t) right_image->columns; x++)
3230 {
cristydab7e912011-02-11 18:19:24 +00003231 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
cristy279d8212011-02-10 20:05:02 +00003232 exception);
cristy4c08aed2011-07-01 19:47:50 +00003233 if ((p == (const Quantum *) NULL) ||
3234 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3235 ((x+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003236 break;
3237 }
cristy7c6dc152011-02-11 14:10:55 +00003238 if ((x+i) < (ssize_t) gap)
3239 gap=(size_t) (x+i);
cristy4d727152011-02-10 19:57:21 +00003240 }
3241 right_view=DestroyCacheView(right_view);
3242 left_view=DestroyCacheView(left_view);
cristydab7e912011-02-11 18:19:24 +00003243 if (y < (ssize_t) smush_image->rows)
3244 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003245 return((ssize_t) gap-offset);
cristyad5e6ee2011-02-10 14:26:00 +00003246}
3247
cristy7c6dc152011-02-11 14:10:55 +00003248static ssize_t SmushYGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003249 const ssize_t offset,ExceptionInfo *exception)
cristyad5e6ee2011-02-10 14:26:00 +00003250{
cristy4d727152011-02-10 19:57:21 +00003251 CacheView
3252 *bottom_view,
3253 *top_view;
3254
3255 const Image
3256 *bottom_image,
3257 *top_image;
3258
cristy4d727152011-02-10 19:57:21 +00003259 RectangleInfo
3260 bottom_geometry,
3261 top_geometry;
3262
cristy4c08aed2011-07-01 19:47:50 +00003263 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003264 *p;
3265
cristy4d727152011-02-10 19:57:21 +00003266 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003267 i,
cristy4d727152011-02-10 19:57:21 +00003268 x;
3269
cristy7c6dc152011-02-11 14:10:55 +00003270 size_t
3271 gap;
3272
cristy4d727152011-02-10 19:57:21 +00003273 ssize_t
cristy4d727152011-02-10 19:57:21 +00003274 y;
3275
3276 if (images->previous == (Image *) NULL)
3277 return(0);
3278 bottom_image=images;
3279 SetGeometry(smush_image,&bottom_geometry);
3280 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3281 bottom_image->gravity,&bottom_geometry);
3282 top_image=images->previous;
3283 SetGeometry(smush_image,&top_geometry);
3284 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3285 &top_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003286 gap=bottom_image->rows;
cristy46ff2672012-12-14 15:32:26 +00003287 top_view=AcquireVirtualCacheView(top_image,exception);
3288 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
cristy4d727152011-02-10 19:57:21 +00003289 for (x=0; x < (ssize_t) smush_image->columns; x++)
3290 {
3291 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3292 {
cristydab7e912011-02-11 18:19:24 +00003293 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003294 if ((p == (const Quantum *) NULL) ||
3295 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3296 ((top_image->rows-y-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003297 break;
3298 }
cristy4ef6f062011-02-10 20:30:22 +00003299 i=(ssize_t) top_image->rows-y-1;
cristy4d727152011-02-10 19:57:21 +00003300 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3301 {
cristydab7e912011-02-11 18:19:24 +00003302 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3303 exception);
cristy4c08aed2011-07-01 19:47:50 +00003304 if ((p == (const Quantum *) NULL) ||
3305 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3306 ((y+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003307 break;
3308 }
cristy7c6dc152011-02-11 14:10:55 +00003309 if ((y+i) < (ssize_t) gap)
3310 gap=(size_t) (y+i);
cristy4d727152011-02-10 19:57:21 +00003311 }
3312 bottom_view=DestroyCacheView(bottom_view);
3313 top_view=DestroyCacheView(top_view);
cristydab7e912011-02-11 18:19:24 +00003314 if (x < (ssize_t) smush_image->columns)
3315 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003316 return((ssize_t) gap-offset);
cristy4ca38e22011-02-10 02:57:49 +00003317}
3318
3319MagickExport Image *SmushImages(const Image *images,
cristy4285d782011-02-09 20:12:28 +00003320 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3321{
3322#define SmushImageTag "Smush/Image"
3323
cristy4ca38e22011-02-10 02:57:49 +00003324 const Image
3325 *image;
3326
cristy4285d782011-02-09 20:12:28 +00003327 Image
3328 *smush_image;
3329
3330 MagickBooleanType
cristy4285d782011-02-09 20:12:28 +00003331 proceed,
3332 status;
3333
3334 MagickOffsetType
3335 n;
3336
cristy5a5e4d92012-08-29 00:06:25 +00003337 PixelTrait
3338 alpha_trait;
3339
cristy4285d782011-02-09 20:12:28 +00003340 RectangleInfo
3341 geometry;
3342
3343 register const Image
3344 *next;
3345
3346 size_t
3347 height,
3348 number_images,
3349 width;
3350
3351 ssize_t
3352 x_offset,
cristy4285d782011-02-09 20:12:28 +00003353 y_offset;
3354
3355 /*
cristy7c6dc152011-02-11 14:10:55 +00003356 Compute maximum area of smushed area.
cristy4285d782011-02-09 20:12:28 +00003357 */
cristy4ca38e22011-02-10 02:57:49 +00003358 assert(images != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003359 assert(images->signature == MagickCoreSignature);
cristy4ca38e22011-02-10 02:57:49 +00003360 if (images->debug != MagickFalse)
3361 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy4285d782011-02-09 20:12:28 +00003362 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003363 assert(exception->signature == MagickCoreSignature);
cristy4ca38e22011-02-10 02:57:49 +00003364 image=images;
cristy5a5e4d92012-08-29 00:06:25 +00003365 alpha_trait=image->alpha_trait;
cristy4285d782011-02-09 20:12:28 +00003366 number_images=1;
3367 width=image->columns;
3368 height=image->rows;
3369 next=GetNextImageInList(image);
3370 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3371 {
cristy17f11b02014-12-20 19:37:04 +00003372 if (next->alpha_trait != UndefinedPixelTrait)
cristy5a5e4d92012-08-29 00:06:25 +00003373 alpha_trait=BlendPixelTrait;
cristy4285d782011-02-09 20:12:28 +00003374 number_images++;
3375 if (stack != MagickFalse)
3376 {
3377 if (next->columns > width)
3378 width=next->columns;
3379 height+=next->rows;
cristy4ef6f062011-02-10 20:30:22 +00003380 if (next->previous != (Image *) NULL)
3381 height+=offset;
cristy4285d782011-02-09 20:12:28 +00003382 continue;
3383 }
3384 width+=next->columns;
cristy4ef6f062011-02-10 20:30:22 +00003385 if (next->previous != (Image *) NULL)
3386 width+=offset;
cristy4285d782011-02-09 20:12:28 +00003387 if (next->rows > height)
3388 height=next->rows;
3389 }
3390 /*
cristy7c6dc152011-02-11 14:10:55 +00003391 Smush images.
cristy4285d782011-02-09 20:12:28 +00003392 */
3393 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3394 if (smush_image == (Image *) NULL)
3395 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003396 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
cristy4285d782011-02-09 20:12:28 +00003397 {
cristy4285d782011-02-09 20:12:28 +00003398 smush_image=DestroyImage(smush_image);
3399 return((Image *) NULL);
3400 }
cristy5a5e4d92012-08-29 00:06:25 +00003401 smush_image->alpha_trait=alpha_trait;
cristyea1a8aa2011-10-20 13:24:06 +00003402 (void) SetImageBackgroundColor(smush_image,exception);
cristy4285d782011-02-09 20:12:28 +00003403 status=MagickTrue;
3404 x_offset=0;
3405 y_offset=0;
cristy4285d782011-02-09 20:12:28 +00003406 for (n=0; n < (MagickOffsetType) number_images; n++)
3407 {
3408 SetGeometry(smush_image,&geometry);
3409 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3410 if (stack != MagickFalse)
cristy4ca38e22011-02-10 02:57:49 +00003411 {
3412 x_offset-=geometry.x;
cristy7c6dc152011-02-11 14:10:55 +00003413 y_offset-=SmushYGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003414 }
cristy4285d782011-02-09 20:12:28 +00003415 else
cristy4ca38e22011-02-10 02:57:49 +00003416 {
cristy7c6dc152011-02-11 14:10:55 +00003417 x_offset-=SmushXGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003418 y_offset-=geometry.y;
cristy4ca38e22011-02-10 02:57:49 +00003419 }
cristy39172402012-03-30 13:04:39 +00003420 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3421 y_offset,exception);
cristy4285d782011-02-09 20:12:28 +00003422 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3423 if (proceed == MagickFalse)
3424 break;
3425 if (stack == MagickFalse)
3426 {
3427 x_offset+=(ssize_t) image->columns;
3428 y_offset=0;
3429 }
3430 else
3431 {
3432 x_offset=0;
3433 y_offset+=(ssize_t) image->rows;
3434 }
3435 image=GetNextImageInList(image);
3436 }
cristy4ef6f062011-02-10 20:30:22 +00003437 if (stack == MagickFalse)
3438 smush_image->columns=(size_t) x_offset;
cristy4d727152011-02-10 19:57:21 +00003439 else
cristy4ef6f062011-02-10 20:30:22 +00003440 smush_image->rows=(size_t) y_offset;
cristy4285d782011-02-09 20:12:28 +00003441 if (status == MagickFalse)
3442 smush_image=DestroyImage(smush_image);
3443 return(smush_image);
3444}
3445
3446/*
3447%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3448% %
3449% %
3450% %
cristy3ed852e2009-09-05 21:47:34 +00003451% S t r i p I m a g e %
3452% %
3453% %
3454% %
3455%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3456%
cristy376bda92009-12-22 21:15:23 +00003457% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00003458%
3459% The format of the StripImage method is:
3460%
cristye941a752011-10-15 01:52:48 +00003461% MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003462%
3463% A description of each parameter follows:
3464%
3465% o image: the image.
3466%
cristye941a752011-10-15 01:52:48 +00003467% o exception: return any errors or warnings in this structure.
3468%
cristy3ed852e2009-09-05 21:47:34 +00003469*/
cristye941a752011-10-15 01:52:48 +00003470MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003471{
cristye941a752011-10-15 01:52:48 +00003472 MagickBooleanType
3473 status;
3474
cristy3ed852e2009-09-05 21:47:34 +00003475 assert(image != (Image *) NULL);
3476 if (image->debug != MagickFalse)
3477 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye941a752011-10-15 01:52:48 +00003478 (void) exception;
cristy3ed852e2009-09-05 21:47:34 +00003479 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00003480 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00003481 (void) DeleteImageProperty(image,"date:create");
3482 (void) DeleteImageProperty(image,"date:modify");
cristy42e14902014-05-01 22:40:40 +00003483 status=SetImageArtifact(image,"png:exclude-chunk",
Cristybcd14882016-01-01 16:54:53 -05003484 "cHRM,EXIF,gAMA,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
cristye941a752011-10-15 01:52:48 +00003485 return(status);
cristy3ed852e2009-09-05 21:47:34 +00003486}
3487
3488/*
3489%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3490% %
3491% %
3492% %
3493+ S y n c I m a g e %
3494% %
3495% %
3496% %
3497%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3498%
3499% SyncImage() initializes the red, green, and blue intensities of each pixel
3500% as defined by the colormap index.
3501%
3502% The format of the SyncImage method is:
3503%
cristyea1a8aa2011-10-20 13:24:06 +00003504% MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003505%
3506% A description of each parameter follows:
3507%
3508% o image: the image.
3509%
cristyea1a8aa2011-10-20 13:24:06 +00003510% o exception: return any errors or warnings in this structure.
3511%
cristy3ed852e2009-09-05 21:47:34 +00003512*/
3513
cristyaedc0312012-01-08 01:07:37 +00003514static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3515 MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00003516{
cristyc8d63672012-01-11 13:03:13 +00003517 if ((size_t) index < image->colors)
cristyaedc0312012-01-08 01:07:37 +00003518 return(index);
cristy3ed852e2009-09-05 21:47:34 +00003519 *range_exception=MagickTrue;
cristyd9657d22012-08-23 14:25:31 +00003520 return((Quantum) 0);
cristy3ed852e2009-09-05 21:47:34 +00003521}
3522
cristyea1a8aa2011-10-20 13:24:06 +00003523MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003524{
3525 CacheView
3526 *image_view;
3527
cristy3ed852e2009-09-05 21:47:34 +00003528 MagickBooleanType
3529 range_exception,
dirkf5cb0472014-10-24 20:10:14 +00003530 status,
3531 taint;
cristy3ed852e2009-09-05 21:47:34 +00003532
cristycb6d09b2010-06-19 01:59:36 +00003533 ssize_t
3534 y;
3535
cristy3ed852e2009-09-05 21:47:34 +00003536 assert(image != (Image *) NULL);
3537 if (image->debug != MagickFalse)
3538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00003539 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00003540 if (image->storage_class == DirectClass)
3541 return(MagickFalse);
3542 range_exception=MagickFalse;
3543 status=MagickTrue;
dirkf5cb0472014-10-24 20:10:14 +00003544 taint=image->taint;
cristy46ff2672012-12-14 15:32:26 +00003545 image_view=AcquireAuthenticCacheView(image,exception);
cristy48974b92009-12-19 02:36:06 +00003546#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003547 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
cristy5e6b2592012-12-19 14:08:11 +00003548 magick_threads(image,image,image->rows,1)
cristy48974b92009-12-19 02:36:06 +00003549#endif
cristybb503372010-05-27 20:51:26 +00003550 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003551 {
cristy4c08aed2011-07-01 19:47:50 +00003552 Quantum
cristy3ed852e2009-09-05 21:47:34 +00003553 index;
3554
cristy4c08aed2011-07-01 19:47:50 +00003555 register Quantum
dirk05d2ff72015-11-18 23:13:43 +01003556 *magick_restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003557
cristycb6d09b2010-06-19 01:59:36 +00003558 register ssize_t
3559 x;
3560
cristy48974b92009-12-19 02:36:06 +00003561 if (status == MagickFalse)
3562 continue;
cristy3ed852e2009-09-05 21:47:34 +00003563 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00003564 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003565 {
3566 status=MagickFalse;
3567 continue;
3568 }
cristybb503372010-05-27 20:51:26 +00003569 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003570 {
cristyaedc0312012-01-08 01:07:37 +00003571 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
cristy11a06d32015-01-04 12:03:27 +00003572 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
cristyed231572011-07-14 02:18:59 +00003573 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00003574 }
3575 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3576 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003577 }
3578 image_view=DestroyCacheView(image_view);
dirkf5cb0472014-10-24 20:10:14 +00003579 image->taint=taint;
cristycaf45802012-06-16 18:28:54 +00003580 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
dirkb081bb22016-01-27 12:56:48 +01003581 (void) ThrowMagickException(exception,GetMagickModule(),
3582 CorruptImageWarning,"InvalidColormapIndex","`%s'",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00003583 return(status);
3584}
cristy1626d332009-11-10 16:58:17 +00003585
3586/*
3587%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3588% %
3589% %
3590% %
3591% S y n c I m a g e S e t t i n g s %
3592% %
3593% %
3594% %
3595%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3596%
anthony5f78bca2012-10-05 06:51:00 +00003597% SyncImageSettings() syncs any image_info global options into per-image
3598% attributes.
3599%
anthonyc7994672012-11-17 05:33:27 +00003600% Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
anthony5f78bca2012-10-05 06:51:00 +00003601% that operations and coders can find such settings. In IMv7 if a desired
3602% per-image artifact is not set, then it will directly look for a global
anthonyc7994672012-11-17 05:33:27 +00003603% option as a fallback, as such this copy is no longer needed, only the
3604% link set up.
cristy1626d332009-11-10 16:58:17 +00003605%
3606% The format of the SyncImageSettings method is:
3607%
3608% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003609% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003610% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003611% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003612%
3613% A description of each parameter follows:
3614%
3615% o image_info: the image info.
3616%
3617% o image: the image.
3618%
cristy6fccee12011-10-20 18:43:18 +00003619% o exception: return any errors or warnings in this structure.
3620%
cristy1626d332009-11-10 16:58:17 +00003621*/
3622
3623MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003624 Image *images,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003625{
3626 Image
3627 *image;
3628
3629 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003630 assert(image_info->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003631 assert(images != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003632 assert(images->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003633 if (images->debug != MagickFalse)
3634 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3635 image=images;
3636 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
cristy6fccee12011-10-20 18:43:18 +00003637 (void) SyncImageSettings(image_info,image,exception);
cristy1626d332009-11-10 16:58:17 +00003638 (void) DeleteImageOption(image_info,"page");
3639 return(MagickTrue);
3640}
3641
3642MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003643 Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003644{
cristy1626d332009-11-10 16:58:17 +00003645 const char
cristy202c1482012-10-05 23:47:57 +00003646 *option;
cristy1626d332009-11-10 16:58:17 +00003647
3648 GeometryInfo
3649 geometry_info;
3650
3651 MagickStatusType
3652 flags;
3653
cristy19eb6412010-04-23 14:42:29 +00003654 ResolutionType
3655 units;
3656
cristy1626d332009-11-10 16:58:17 +00003657 /*
3658 Sync image options.
3659 */
3660 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003661 assert(image_info->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003662 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003663 assert(image->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003664 if (image->debug != MagickFalse)
3665 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3666 option=GetImageOption(image_info,"background");
3667 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003668 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
cristy6fccee12011-10-20 18:43:18 +00003669 exception);
cristy1626d332009-11-10 16:58:17 +00003670 option=GetImageOption(image_info,"black-point-compensation");
3671 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003672 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003673 MagickBooleanOptions,MagickFalse,option);
3674 option=GetImageOption(image_info,"blue-primary");
3675 if (option != (const char *) NULL)
3676 {
3677 flags=ParseGeometry(option,&geometry_info);
3678 image->chromaticity.blue_primary.x=geometry_info.rho;
3679 image->chromaticity.blue_primary.y=geometry_info.sigma;
3680 if ((flags & SigmaValue) == 0)
3681 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3682 }
3683 option=GetImageOption(image_info,"bordercolor");
3684 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003685 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
cristy6fccee12011-10-20 18:43:18 +00003686 exception);
anthony72feaa62012-01-17 06:46:23 +00003687 /* FUTURE: do not sync compose to per-image compose setting here */
cristy1626d332009-11-10 16:58:17 +00003688 option=GetImageOption(image_info,"compose");
3689 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003690 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
cristy1626d332009-11-10 16:58:17 +00003691 MagickFalse,option);
anthony72feaa62012-01-17 06:46:23 +00003692 /* -- */
cristy1626d332009-11-10 16:58:17 +00003693 option=GetImageOption(image_info,"compress");
3694 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003695 image->compression=(CompressionType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003696 MagickCompressOptions,MagickFalse,option);
3697 option=GetImageOption(image_info,"debug");
3698 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003699 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00003700 MagickFalse,option);
cristydd5f5912010-07-31 23:37:23 +00003701 option=GetImageOption(image_info,"density");
3702 if (option != (const char *) NULL)
3703 {
3704 GeometryInfo
3705 geometry_info;
3706
cristydd5f5912010-07-31 23:37:23 +00003707 flags=ParseGeometry(option,&geometry_info);
cristy2a11bef2011-10-28 18:33:11 +00003708 image->resolution.x=geometry_info.rho;
3709 image->resolution.y=geometry_info.sigma;
cristydd5f5912010-07-31 23:37:23 +00003710 if ((flags & SigmaValue) == 0)
cristy2a11bef2011-10-28 18:33:11 +00003711 image->resolution.y=image->resolution.x;
cristydd5f5912010-07-31 23:37:23 +00003712 }
cristy1626d332009-11-10 16:58:17 +00003713 option=GetImageOption(image_info,"depth");
3714 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003715 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003716 option=GetImageOption(image_info,"endian");
3717 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003718 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
cristy1626d332009-11-10 16:58:17 +00003719 MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00003720 option=GetImageOption(image_info,"filter");
3721 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003722 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
cristy1626d332009-11-10 16:58:17 +00003723 MagickFalse,option);
3724 option=GetImageOption(image_info,"fuzz");
3725 if (option != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00003726 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
cristy1626d332009-11-10 16:58:17 +00003727 option=GetImageOption(image_info,"gravity");
3728 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003729 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
cristy1626d332009-11-10 16:58:17 +00003730 MagickFalse,option);
3731 option=GetImageOption(image_info,"green-primary");
3732 if (option != (const char *) NULL)
3733 {
3734 flags=ParseGeometry(option,&geometry_info);
3735 image->chromaticity.green_primary.x=geometry_info.rho;
3736 image->chromaticity.green_primary.y=geometry_info.sigma;
3737 if ((flags & SigmaValue) == 0)
3738 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3739 }
3740 option=GetImageOption(image_info,"intent");
3741 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003742 image->rendering_intent=(RenderingIntent) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003743 MagickIntentOptions,MagickFalse,option);
cristy313634e2013-03-26 00:52:19 +00003744 option=GetImageOption(image_info,"intensity");
3745 if (option != (const char *) NULL)
3746 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3747 MagickPixelIntensityOptions,MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00003748 option=GetImageOption(image_info,"interlace");
3749 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003750 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
cristy1626d332009-11-10 16:58:17 +00003751 MagickFalse,option);
3752 option=GetImageOption(image_info,"interpolate");
3753 if (option != (const char *) NULL)
cristy5c4e2582011-09-11 19:21:03 +00003754 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003755 MagickInterpolateOptions,MagickFalse,option);
3756 option=GetImageOption(image_info,"loop");
3757 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003758 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003759 option=GetImageOption(image_info,"mattecolor");
3760 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003761 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
cristy6fccee12011-10-20 18:43:18 +00003762 exception);
cristy1626d332009-11-10 16:58:17 +00003763 option=GetImageOption(image_info,"orient");
3764 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003765 image->orientation=(OrientationType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003766 MagickOrientationOptions,MagickFalse,option);
cristy14ed6a22013-12-28 23:48:05 +00003767 option=GetImageOption(image_info,"page");
3768 if (option != (const char *) NULL)
3769 {
3770 char
3771 *geometry;
3772
3773 geometry=GetPageGeometry(option);
3774 flags=ParseAbsoluteGeometry(geometry,&image->page);
3775 geometry=DestroyString(geometry);
3776 }
cristy1626d332009-11-10 16:58:17 +00003777 option=GetImageOption(image_info,"quality");
3778 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003779 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003780 option=GetImageOption(image_info,"red-primary");
3781 if (option != (const char *) NULL)
3782 {
3783 flags=ParseGeometry(option,&geometry_info);
3784 image->chromaticity.red_primary.x=geometry_info.rho;
3785 image->chromaticity.red_primary.y=geometry_info.sigma;
3786 if ((flags & SigmaValue) == 0)
3787 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3788 }
3789 if (image_info->quality != UndefinedCompressionQuality)
3790 image->quality=image_info->quality;
3791 option=GetImageOption(image_info,"scene");
3792 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003793 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003794 option=GetImageOption(image_info,"taint");
3795 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003796 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00003797 MagickFalse,option);
3798 option=GetImageOption(image_info,"tile-offset");
3799 if (option != (const char *) NULL)
3800 {
3801 char
3802 *geometry;
3803
3804 geometry=GetPageGeometry(option);
3805 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3806 geometry=DestroyString(geometry);
3807 }
3808 option=GetImageOption(image_info,"transparent-color");
3809 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003810 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
cristy6fccee12011-10-20 18:43:18 +00003811 exception);
cristy1626d332009-11-10 16:58:17 +00003812 option=GetImageOption(image_info,"type");
3813 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003814 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
cristy1626d332009-11-10 16:58:17 +00003815 option);
3816 option=GetImageOption(image_info,"units");
cristyc8d63672012-01-11 13:03:13 +00003817 units=image_info->units;
cristy1626d332009-11-10 16:58:17 +00003818 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003819 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00003820 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00003821 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00003822 {
cristy19eb6412010-04-23 14:42:29 +00003823 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00003824 switch (image->units)
3825 {
3826 case PixelsPerInchResolution:
3827 {
cristy19eb6412010-04-23 14:42:29 +00003828 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00003829 {
cristy2a11bef2011-10-28 18:33:11 +00003830 image->resolution.x/=2.54;
3831 image->resolution.y/=2.54;
cristy1626d332009-11-10 16:58:17 +00003832 }
3833 break;
3834 }
3835 case PixelsPerCentimeterResolution:
3836 {
cristy19eb6412010-04-23 14:42:29 +00003837 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00003838 {
cristy2a11bef2011-10-28 18:33:11 +00003839 image->resolution.x=(double) ((size_t) (100.0*2.54*
3840 image->resolution.x+0.5))/100.0;
3841 image->resolution.y=(double) ((size_t) (100.0*2.54*
3842 image->resolution.y+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00003843 }
3844 break;
3845 }
3846 default:
3847 break;
3848 }
cristy19eb6412010-04-23 14:42:29 +00003849 image->units=units;
cristy1626d332009-11-10 16:58:17 +00003850 }
anthonyfd706f92012-01-19 04:22:02 +00003851 option=GetImageOption(image_info,"virtual-pixel");
3852 if (option != (const char *) NULL)
cristy387430f2012-02-07 13:09:46 +00003853 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3854 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3855 exception);
cristy1626d332009-11-10 16:58:17 +00003856 option=GetImageOption(image_info,"white-point");
3857 if (option != (const char *) NULL)
3858 {
3859 flags=ParseGeometry(option,&geometry_info);
3860 image->chromaticity.white_point.x=geometry_info.rho;
3861 image->chromaticity.white_point.y=geometry_info.sigma;
3862 if ((flags & SigmaValue) == 0)
3863 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3864 }
Cristy9c282cc2015-08-29 17:37:22 -04003865 /*
3866 Pointer to allow the lookup of pre-image artifact will fallback to a global
3867 option setting/define. This saves a lot of duplication of global options
3868 into per-image artifacts, while ensuring only specifically set per-image
3869 artifacts are preserved when parenthesis ends.
anthony643c6132012-11-07 14:50:28 +00003870 */
dirk98d3e1c2015-08-28 21:09:11 +02003871 if (image->image_info != (ImageInfo *) NULL)
3872 image->image_info=DestroyImageInfo(image->image_info);
Cristy36421ee2015-08-28 11:58:20 -04003873 image->image_info=CloneImageInfo(image_info);
cristy1626d332009-11-10 16:58:17 +00003874 return(MagickTrue);
3875}