blob: c71a84e567526dbc21761e8d42199ba833114560 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% IIIII M M AAA GGGG EEEEE %
7% I MM MM A A G E %
8% I M M M AAAAA G GG EEE %
9% I M M A A G G E %
10% IIIII M M A A GGGG EEEEE %
11% %
12% %
13% MagickCore Image Methods %
14% %
15% Software Design %
cristyde984cd2013-12-01 14:49:27 +000016% Cristy %
cristy3ed852e2009-09-05 21:47:34 +000017% July 1992 %
18% %
19% %
cristyb56bb242014-11-25 17:12:48 +000020% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/animate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/blob.h"
48#include "MagickCore/blob-private.h"
49#include "MagickCore/cache.h"
50#include "MagickCore/cache-private.h"
51#include "MagickCore/cache-view.h"
52#include "MagickCore/client.h"
53#include "MagickCore/color.h"
54#include "MagickCore/color-private.h"
55#include "MagickCore/colormap.h"
56#include "MagickCore/colorspace.h"
57#include "MagickCore/colorspace-private.h"
58#include "MagickCore/composite.h"
59#include "MagickCore/composite-private.h"
60#include "MagickCore/compress.h"
61#include "MagickCore/constitute.h"
62#include "MagickCore/display.h"
63#include "MagickCore/draw.h"
64#include "MagickCore/enhance.h"
65#include "MagickCore/exception.h"
66#include "MagickCore/exception-private.h"
67#include "MagickCore/gem.h"
68#include "MagickCore/geometry.h"
69#include "MagickCore/histogram.h"
70#include "MagickCore/image-private.h"
71#include "MagickCore/list.h"
72#include "MagickCore/magic.h"
73#include "MagickCore/magick.h"
cristy7832dc22011-09-05 01:21:53 +000074#include "MagickCore/magick-private.h"
cristy4c08aed2011-07-01 19:47:50 +000075#include "MagickCore/memory_.h"
76#include "MagickCore/module.h"
77#include "MagickCore/monitor.h"
78#include "MagickCore/monitor-private.h"
79#include "MagickCore/option.h"
80#include "MagickCore/paint.h"
81#include "MagickCore/pixel-accessor.h"
82#include "MagickCore/profile.h"
83#include "MagickCore/property.h"
84#include "MagickCore/quantize.h"
85#include "MagickCore/random_.h"
cristyac245f82012-05-05 17:13:57 +000086#include "MagickCore/resource_.h"
cristy4c08aed2011-07-01 19:47:50 +000087#include "MagickCore/segment.h"
88#include "MagickCore/semaphore.h"
89#include "MagickCore/signature-private.h"
90#include "MagickCore/statistic.h"
91#include "MagickCore/string_.h"
92#include "MagickCore/string-private.h"
93#include "MagickCore/thread-private.h"
94#include "MagickCore/threshold.h"
95#include "MagickCore/timer.h"
cristy63a81872012-03-22 15:52:52 +000096#include "MagickCore/token.h"
cristy4c08aed2011-07-01 19:47:50 +000097#include "MagickCore/utility.h"
cristyd1dd6e42011-09-04 01:46:08 +000098#include "MagickCore/utility-private.h"
cristy4c08aed2011-07-01 19:47:50 +000099#include "MagickCore/version.h"
100#include "MagickCore/xwindow-private.h"
cristy3ed852e2009-09-05 21:47:34 +0000101
102/*
103 Constant declaration.
104*/
cristy94b11832011-09-08 19:46:03 +0000105const char
cristy7138c592009-09-08 13:58:52 +0000106 BackgroundColor[] = "#ffffff", /* white */
107 BorderColor[] = "#dfdfdf", /* gray */
cristy9639ba32011-09-05 15:09:42 +0000108 DefaultTileFrame[] = "15x15+3+3",
cristy7138c592009-09-08 13:58:52 +0000109 DefaultTileGeometry[] = "120x120+4+3>",
110 DefaultTileLabel[] = "%f\n%G\n%b",
cristy94b11832011-09-08 19:46:03 +0000111 ForegroundColor[] = "#000", /* black */
cristy7138c592009-09-08 13:58:52 +0000112 LoadImageTag[] = "Load/Image",
113 LoadImagesTag[] = "Load/Images",
cristy94b11832011-09-08 19:46:03 +0000114 MatteColor[] = "#bdbdbd", /* gray */
cristy7138c592009-09-08 13:58:52 +0000115 PSDensityGeometry[] = "72.0x72.0",
116 PSPageGeometry[] = "612x792",
117 SaveImageTag[] = "Save/Image",
118 SaveImagesTag[] = "Save/Images",
119 TransparentColor[] = "#00000000"; /* transparent black */
cristy3ed852e2009-09-05 21:47:34 +0000120
cristy94b11832011-09-08 19:46:03 +0000121const double
cristy3ed852e2009-09-05 21:47:34 +0000122 DefaultResolution = 72.0;
123
124/*
125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126% %
127% %
128% %
129% A c q u i r e I m a g e %
130% %
131% %
132% %
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134%
135% AcquireImage() returns a pointer to an image structure initialized to
136% default values.
137%
138% The format of the AcquireImage method is:
139%
cristy9950d572011-10-01 18:22:35 +0000140% Image *AcquireImage(const ImageInfo *image_info,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000141%
142% A description of each parameter follows:
143%
144% o image_info: Many of the image default values are set from this
145% structure. For example, filename, compression, depth, background color,
146% and others.
147%
cristy9950d572011-10-01 18:22:35 +0000148% o exception: return any errors or warnings in this structure.
149%
cristy3ed852e2009-09-05 21:47:34 +0000150*/
cristy9950d572011-10-01 18:22:35 +0000151MagickExport Image *AcquireImage(const ImageInfo *image_info,
152 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000153{
cristye412c892010-07-26 12:31:36 +0000154 const char
cristyf3a660a2010-07-26 14:17:52 +0000155 *option;
cristye412c892010-07-26 12:31:36 +0000156
cristy3ed852e2009-09-05 21:47:34 +0000157 Image
158 *image;
159
160 MagickStatusType
161 flags;
162
163 /*
164 Allocate image structure.
165 */
166 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy73bd4a52010-10-05 11:24:23 +0000167 image=(Image *) AcquireMagickMemory(sizeof(*image));
cristy3ed852e2009-09-05 21:47:34 +0000168 if (image == (Image *) NULL)
169 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
170 (void) ResetMagickMemory(image,0,sizeof(*image));
171 /*
172 Initialize Image structure.
173 */
cristy151b66d2015-04-15 10:50:31 +0000174 (void) CopyMagickString(image->magick,"MIFF",MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000175 image->storage_class=DirectClass;
176 image->depth=MAGICKCORE_QUANTUM_DEPTH;
cristy8d951092012-02-08 18:54:56 +0000177 image->colorspace=sRGBColorspace;
cristye540eb42012-04-16 12:50:34 +0000178 image->rendering_intent=PerceptualIntent;
cristy6b221892012-05-03 01:21:35 +0000179 image->gamma=1.000f/2.200f;
180 image->chromaticity.red_primary.x=0.6400f;
181 image->chromaticity.red_primary.y=0.3300f;
cristyf767ec92012-05-03 01:27:21 +0000182 image->chromaticity.red_primary.z=0.0300f;
cristy6b221892012-05-03 01:21:35 +0000183 image->chromaticity.green_primary.x=0.3000f;
184 image->chromaticity.green_primary.y=0.6000f;
cristyf767ec92012-05-03 01:27:21 +0000185 image->chromaticity.green_primary.z=0.1000f;
cristy6b221892012-05-03 01:21:35 +0000186 image->chromaticity.blue_primary.x=0.1500f;
187 image->chromaticity.blue_primary.y=0.0600f;
cristyf767ec92012-05-03 01:27:21 +0000188 image->chromaticity.blue_primary.z=0.7900f;
cristy6b221892012-05-03 01:21:35 +0000189 image->chromaticity.white_point.x=0.3127f;
190 image->chromaticity.white_point.y=0.3290f;
cristyf767ec92012-05-03 01:27:21 +0000191 image->chromaticity.white_point.z=0.3583f;
cristy3ed852e2009-09-05 21:47:34 +0000192 image->interlace=NoInterlace;
193 image->ticks_per_second=UndefinedTicksPerSecond;
194 image->compose=OverCompositeOp;
cristy9950d572011-10-01 18:22:35 +0000195 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
196 &image->background_color,exception);
197 (void) QueryColorCompliance(BorderColor,AllCompliance,&image->border_color,
198 exception);
199 (void) QueryColorCompliance(MatteColor,AllCompliance,&image->matte_color,
200 exception);
201 (void) QueryColorCompliance(TransparentColor,AllCompliance,
202 &image->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +0000203 GetTimerInfo(&image->timer);
204 image->cache=AcquirePixelCache(0);
cristybd5a96c2011-08-21 00:04:26 +0000205 image->channel_mask=DefaultChannels;
cristyed231572011-07-14 02:18:59 +0000206 image->channel_map=AcquirePixelChannelMap();
cristy3ed852e2009-09-05 21:47:34 +0000207 image->blob=CloneBlobInfo((BlobInfo *) NULL);
cristybd686c62013-02-03 19:01:05 +0000208 image->timestamp=time((time_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000209 image->debug=IsEventLogging();
210 image->reference_count=1;
cristy3d162a92014-02-16 14:05:06 +0000211 image->semaphore=AcquireSemaphoreInfo();
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
cristy3ed852e2009-09-05 21:47:34 +0000467 height,
468 number_images,
469 width;
470
cristybb503372010-05-27 20:51:26 +0000471 ssize_t
472 x_offset,
473 y,
474 y_offset;
475
cristy3ed852e2009-09-05 21:47:34 +0000476 /*
cristy7c6dc152011-02-11 14:10:55 +0000477 Compute maximum area of appended area.
cristy3ed852e2009-09-05 21:47:34 +0000478 */
cristy4ca38e22011-02-10 02:57:49 +0000479 assert(images != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000480 assert(images->signature == MagickCoreSignature);
cristy4ca38e22011-02-10 02:57:49 +0000481 if (images->debug != MagickFalse)
482 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy3ed852e2009-09-05 21:47:34 +0000483 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000484 assert(exception->signature == MagickCoreSignature);
cristy5a5e4d92012-08-29 00:06:25 +0000485 alpha_trait=images->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +0000486 number_images=1;
cristyeeebdde2012-04-14 16:29:34 +0000487 width=images->columns;
488 height=images->rows;
489 next=GetNextImageInList(images);
cristy3ed852e2009-09-05 21:47:34 +0000490 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
491 {
cristy17f11b02014-12-20 19:37:04 +0000492 if (next->alpha_trait != UndefinedPixelTrait)
cristy5a5e4d92012-08-29 00:06:25 +0000493 alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +0000494 number_images++;
495 if (stack != MagickFalse)
496 {
497 if (next->columns > width)
498 width=next->columns;
499 height+=next->rows;
500 continue;
501 }
502 width+=next->columns;
503 if (next->rows > height)
504 height=next->rows;
505 }
506 /*
cristy7c6dc152011-02-11 14:10:55 +0000507 Append images.
cristy3ed852e2009-09-05 21:47:34 +0000508 */
cristyeeebdde2012-04-14 16:29:34 +0000509 append_image=CloneImage(images,width,height,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000510 if (append_image == (Image *) NULL)
511 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000512 if (SetImageStorageClass(append_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000513 {
cristy3ed852e2009-09-05 21:47:34 +0000514 append_image=DestroyImage(append_image);
515 return((Image *) NULL);
516 }
cristy5a5e4d92012-08-29 00:06:25 +0000517 append_image->alpha_trait=alpha_trait;
cristyea1a8aa2011-10-20 13:24:06 +0000518 (void) SetImageBackgroundColor(append_image,exception);
cristy3ed852e2009-09-05 21:47:34 +0000519 status=MagickTrue;
520 x_offset=0;
521 y_offset=0;
cristyeeebdde2012-04-14 16:29:34 +0000522 next=images;
cristy46ff2672012-12-14 15:32:26 +0000523 append_view=AcquireAuthenticCacheView(append_image,exception);
cristybb503372010-05-27 20:51:26 +0000524 for (n=0; n < (MagickOffsetType) number_images; n++)
cristy3ed852e2009-09-05 21:47:34 +0000525 {
cristyeeebdde2012-04-14 16:29:34 +0000526 CacheView
527 *image_view;
528
529 Image
530 *image;
531
cristy9eed59f2013-02-19 15:26:48 +0000532 MagickBooleanType
533 proceed;
534
cristyeeebdde2012-04-14 16:29:34 +0000535 image=CloneImage(next,0,0,MagickTrue,exception);
536 if (image == (Image *) NULL)
537 break;
538 (void) TransformImageColorspace(image,append_image->colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000539 SetGeometry(append_image,&geometry);
540 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
541 if (stack != MagickFalse)
542 x_offset-=geometry.x;
543 else
544 y_offset-=geometry.y;
cristy46ff2672012-12-14 15:32:26 +0000545 image_view=AcquireVirtualCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +0000546#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy9a5a52f2012-10-09 14:40:31 +0000547 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +0000548 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000549#endif
cristybb503372010-05-27 20:51:26 +0000550 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000551 {
552 MagickBooleanType
553 sync;
554
cristye14e3202012-04-11 18:48:17 +0000555 PixelInfo
556 pixel;
557
cristy4c08aed2011-07-01 19:47:50 +0000558 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000559 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000560
cristy4c08aed2011-07-01 19:47:50 +0000561 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000562 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000563
cristycb6d09b2010-06-19 01:59:36 +0000564 register ssize_t
565 x;
566
cristy3ed852e2009-09-05 21:47:34 +0000567 if (status == MagickFalse)
568 continue;
569 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
570 q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset,
571 image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +0000572 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000573 {
574 status=MagickFalse;
575 continue;
576 }
cristye14e3202012-04-11 18:48:17 +0000577 GetPixelInfo(image,&pixel);
cristybb503372010-05-27 20:51:26 +0000578 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000579 {
cristy883fde12013-04-08 00:50:13 +0000580 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +0000581 {
cristyc3a58022013-10-09 23:22:42 +0000582 SetPixelBackgoundColor(append_image,q);
cristy10a6c612012-01-29 21:41:05 +0000583 p+=GetPixelChannels(image);
584 q+=GetPixelChannels(append_image);
585 continue;
586 }
cristye14e3202012-04-11 18:48:17 +0000587 GetPixelInfoPixel(image,p,&pixel);
cristy11a06d32015-01-04 12:03:27 +0000588 SetPixelViaPixelInfo(append_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +0000589 p+=GetPixelChannels(image);
590 q+=GetPixelChannels(append_image);
cristy3ed852e2009-09-05 21:47:34 +0000591 }
592 sync=SyncCacheViewAuthenticPixels(append_view,exception);
593 if (sync == MagickFalse)
cristya65f35b2010-04-20 01:10:41 +0000594 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +0000595 }
596 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +0000597 if (stack == MagickFalse)
598 {
cristyeaedf062010-05-29 22:36:02 +0000599 x_offset+=(ssize_t) image->columns;
cristy3ed852e2009-09-05 21:47:34 +0000600 y_offset=0;
601 }
602 else
603 {
604 x_offset=0;
cristyeaedf062010-05-29 22:36:02 +0000605 y_offset+=(ssize_t) image->rows;
cristy3ed852e2009-09-05 21:47:34 +0000606 }
cristyeeebdde2012-04-14 16:29:34 +0000607 image=DestroyImage(image);
608 proceed=SetImageProgress(append_image,AppendImageTag,n,number_images);
609 if (proceed == MagickFalse)
610 break;
611 next=GetNextImageInList(next);
cristy3ed852e2009-09-05 21:47:34 +0000612 }
613 append_view=DestroyCacheView(append_view);
614 if (status == MagickFalse)
615 append_image=DestroyImage(append_image);
616 return(append_image);
617}
618
619/*
620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621% %
622% %
623% %
cristy3ed852e2009-09-05 21:47:34 +0000624% C a t c h I m a g e E x c e p t i o n %
625% %
626% %
627% %
628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629%
630% CatchImageException() returns if no exceptions are found in the image
631% sequence, otherwise it determines the most severe exception and reports
632% it as a warning or error depending on the severity.
633%
634% The format of the CatchImageException method is:
635%
636% ExceptionType CatchImageException(Image *image)
637%
638% A description of each parameter follows:
639%
640% o image: An image sequence.
641%
642*/
643MagickExport ExceptionType CatchImageException(Image *image)
644{
645 ExceptionInfo
646 *exception;
647
648 ExceptionType
649 severity;
650
651 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000652 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000653 if (image->debug != MagickFalse)
654 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
655 exception=AcquireExceptionInfo();
cristy3ed852e2009-09-05 21:47:34 +0000656 CatchException(exception);
657 severity=exception->severity;
658 exception=DestroyExceptionInfo(exception);
659 return(severity);
660}
661
662/*
663%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
664% %
665% %
666% %
667% C l i p I m a g e P a t h %
668% %
669% %
670% %
671%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
672%
673% ClipImagePath() sets the image clip mask based any clipping path information
674% if it exists.
675%
676% The format of the ClipImagePath method is:
677%
678% MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000679% const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000680%
681% A description of each parameter follows:
682%
683% o image: the image.
684%
685% o pathname: name of clipping path resource. If name is preceded by #, use
686% clipping path numbered by name.
687%
688% o inside: if non-zero, later operations take effect inside clipping path.
689% Otherwise later operations take effect outside clipping path.
690%
cristy018f07f2011-09-04 21:15:19 +0000691% o exception: return any errors or warnings in this structure.
692%
cristy3ed852e2009-09-05 21:47:34 +0000693*/
694
cristy018f07f2011-09-04 21:15:19 +0000695MagickExport MagickBooleanType ClipImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000696{
cristy018f07f2011-09-04 21:15:19 +0000697 return(ClipImagePath(image,"#1",MagickTrue,exception));
cristy3ed852e2009-09-05 21:47:34 +0000698}
699
700MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname,
cristy018f07f2011-09-04 21:15:19 +0000701 const MagickBooleanType inside,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000702{
703#define ClipImagePathTag "ClipPath/Image"
704
705 char
706 *property;
707
708 const char
709 *value;
710
711 Image
712 *clip_mask;
713
714 ImageInfo
715 *image_info;
716
717 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000718 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000719 if (image->debug != MagickFalse)
720 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
721 assert(pathname != NULL);
722 property=AcquireString(pathname);
cristy151b66d2015-04-15 10:50:31 +0000723 (void) FormatLocaleString(property,MagickPathExtent,"8BIM:1999,2998:%s",
cristy3ed852e2009-09-05 21:47:34 +0000724 pathname);
cristyd15e6592011-10-15 00:13:06 +0000725 value=GetImageProperty(image,property,exception);
cristy3ed852e2009-09-05 21:47:34 +0000726 property=DestroyString(property);
727 if (value == (const char *) NULL)
728 {
cristy6fccee12011-10-20 18:43:18 +0000729 ThrowFileException(exception,OptionError,"NoClipPathDefined",
cristy3ed852e2009-09-05 21:47:34 +0000730 image->filename);
731 return(MagickFalse);
732 }
733 image_info=AcquireImageInfo();
cristyee2f5d62015-07-28 13:19:43 +0000734 (void) CopyMagickString(image_info->filename,image->filename,
735 MagickPathExtent);
736 (void) ConcatenateMagickString(image_info->filename,pathname,
737 MagickPathExtent);
cristy6fccee12011-10-20 18:43:18 +0000738 clip_mask=BlobToImage(image_info,value,strlen(value),exception);
cristy3ed852e2009-09-05 21:47:34 +0000739 image_info=DestroyImageInfo(image_info);
740 if (clip_mask == (Image *) NULL)
741 return(MagickFalse);
742 if (clip_mask->storage_class == PseudoClass)
743 {
cristyea1a8aa2011-10-20 13:24:06 +0000744 (void) SyncImage(clip_mask,exception);
cristy6fccee12011-10-20 18:43:18 +0000745 if (SetImageStorageClass(clip_mask,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000746 return(MagickFalse);
747 }
748 if (inside == MagickFalse)
cristy6fccee12011-10-20 18:43:18 +0000749 (void) NegateImage(clip_mask,MagickFalse,exception);
cristy151b66d2015-04-15 10:50:31 +0000750 (void) FormatLocaleString(clip_mask->magick_filename,MagickPathExtent,
cristy3ed852e2009-09-05 21:47:34 +0000751 "8BIM:1999,2998:%s\nPS",pathname);
cristyacd0d4c2015-07-25 16:12:33 +0000752 (void) SetImageMask(image,ReadPixelMask,clip_mask,exception);
cristy3ed852e2009-09-05 21:47:34 +0000753 clip_mask=DestroyImage(clip_mask);
754 return(MagickTrue);
755}
756
757/*
758%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
759% %
760% %
761% %
762% C l o n e I m a g e %
763% %
764% %
765% %
766%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
767%
768% CloneImage() copies an image and returns the copy as a new image object.
anthony96f11ee2011-03-23 08:22:54 +0000769%
cristy3ed852e2009-09-05 21:47:34 +0000770% If the specified columns and rows is 0, an exact copy of the image is
771% returned, otherwise the pixel data is undefined and must be initialized
772% with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On
773% failure, a NULL image is returned and exception describes the reason for the
774% failure.
775%
776% The format of the CloneImage method is:
777%
cristybb503372010-05-27 20:51:26 +0000778% Image *CloneImage(const Image *image,const size_t columns,
779% const size_t rows,const MagickBooleanType orphan,
cristy3ed852e2009-09-05 21:47:34 +0000780% ExceptionInfo *exception)
781%
782% A description of each parameter follows:
783%
784% o image: the image.
785%
786% o columns: the number of columns in the cloned image.
787%
788% o rows: the number of rows in the cloned image.
789%
790% o detach: With a value other than 0, the cloned image is detached from
791% its parent I/O stream.
792%
793% o exception: return any errors or warnings in this structure.
794%
795*/
cristybb503372010-05-27 20:51:26 +0000796MagickExport Image *CloneImage(const Image *image,const size_t columns,
cristybee00932011-01-15 20:28:27 +0000797 const size_t rows,const MagickBooleanType detach,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000798{
799 Image
800 *clone_image;
801
cristya19f1d72012-08-07 18:24:38 +0000802 double
cristy3ed852e2009-09-05 21:47:34 +0000803 scale;
804
805 size_t
806 length;
807
808 /*
809 Clone the image.
810 */
811 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000812 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000813 if (image->debug != MagickFalse)
814 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
815 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +0000816 assert(exception->signature == MagickCoreSignature);
cristybe1cfca2014-10-21 14:00:29 +0000817 if ((image->columns == 0) || (image->rows == 0))
818 {
819 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
820 "NegativeOrZeroImageSize","`%s'",image->filename);
821 return((Image *) NULL);
822 }
cristy73bd4a52010-10-05 11:24:23 +0000823 clone_image=(Image *) AcquireMagickMemory(sizeof(*clone_image));
cristy3ed852e2009-09-05 21:47:34 +0000824 if (clone_image == (Image *) NULL)
825 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
826 (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image));
cristye1c94d92015-06-28 12:16:33 +0000827 clone_image->signature=MagickCoreSignature;
cristy3ed852e2009-09-05 21:47:34 +0000828 clone_image->storage_class=image->storage_class;
cristyed231572011-07-14 02:18:59 +0000829 clone_image->number_channels=image->number_channels;
cristyb3a73b52011-07-26 01:34:43 +0000830 clone_image->number_meta_channels=image->number_meta_channels;
cristy4c08aed2011-07-01 19:47:50 +0000831 clone_image->metacontent_extent=image->metacontent_extent;
cristy3ed852e2009-09-05 21:47:34 +0000832 clone_image->colorspace=image->colorspace;
cristy883fde12013-04-08 00:50:13 +0000833 clone_image->read_mask=image->read_mask;
834 clone_image->write_mask=image->write_mask;
cristy8a46d822012-08-28 23:32:39 +0000835 clone_image->alpha_trait=image->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +0000836 clone_image->columns=image->columns;
837 clone_image->rows=image->rows;
838 clone_image->dither=image->dither;
cristy101ab702011-10-13 13:06:32 +0000839 if (image->colormap != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000840 {
841 /*
842 Allocate and copy the image colormap.
843 */
844 clone_image->colors=image->colors;
845 length=(size_t) image->colors;
cristy101ab702011-10-13 13:06:32 +0000846 clone_image->colormap=(PixelInfo *) AcquireQuantumMemory(length,
cristy3ed852e2009-09-05 21:47:34 +0000847 sizeof(*clone_image->colormap));
cristy101ab702011-10-13 13:06:32 +0000848 if (clone_image->colormap == (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000849 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
850 (void) CopyMagickMemory(clone_image->colormap,image->colormap,length*
851 sizeof(*clone_image->colormap));
852 }
Cristy36421ee2015-08-28 11:58:20 -0400853 clone_image->image_info=CloneImageInfo(image->image_info);
cristy3ed852e2009-09-05 21:47:34 +0000854 (void) CloneImageProfiles(clone_image,image);
855 (void) CloneImageProperties(clone_image,image);
856 (void) CloneImageArtifacts(clone_image,image);
857 GetTimerInfo(&clone_image->timer);
cristy3ed852e2009-09-05 21:47:34 +0000858 if (image->ascii85 != (void *) NULL)
859 Ascii85Initialize(clone_image);
860 clone_image->magick_columns=image->magick_columns;
861 clone_image->magick_rows=image->magick_rows;
862 clone_image->type=image->type;
cristy636dcb52011-08-26 13:23:49 +0000863 clone_image->channel_mask=image->channel_mask;
cristyed231572011-07-14 02:18:59 +0000864 clone_image->channel_map=ClonePixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +0000865 (void) CopyMagickString(clone_image->magick_filename,image->magick_filename,
cristy151b66d2015-04-15 10:50:31 +0000866 MagickPathExtent);
867 (void) CopyMagickString(clone_image->magick,image->magick,MagickPathExtent);
cristy25baba02015-07-28 00:36:29 +0000868 (void) CopyMagickString(clone_image->filename,image->filename,
869 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000870 clone_image->progress_monitor=image->progress_monitor;
871 clone_image->client_data=image->client_data;
872 clone_image->reference_count=1;
cristybee00932011-01-15 20:28:27 +0000873 clone_image->next=image->next;
874 clone_image->previous=image->previous;
cristy3ed852e2009-09-05 21:47:34 +0000875 clone_image->list=NewImageList();
cristy3ed852e2009-09-05 21:47:34 +0000876 if (detach == MagickFalse)
877 clone_image->blob=ReferenceBlob(image->blob);
878 else
cristybee00932011-01-15 20:28:27 +0000879 {
880 clone_image->next=NewImageList();
881 clone_image->previous=NewImageList();
882 clone_image->blob=CloneBlobInfo((BlobInfo *) NULL);
883 }
cristy73724512010-04-12 14:43:14 +0000884 clone_image->ping=image->ping;
cristy3ed852e2009-09-05 21:47:34 +0000885 clone_image->debug=IsEventLogging();
cristy3d162a92014-02-16 14:05:06 +0000886 clone_image->semaphore=AcquireSemaphoreInfo();
cristy58a749e2014-05-25 17:36:53 +0000887 if ((columns == 0) || (rows == 0))
cristy3ed852e2009-09-05 21:47:34 +0000888 {
889 if (image->montage != (char *) NULL)
890 (void) CloneString(&clone_image->montage,image->montage);
891 if (image->directory != (char *) NULL)
892 (void) CloneString(&clone_image->directory,image->directory);
cristy3ed852e2009-09-05 21:47:34 +0000893 clone_image->cache=ReferencePixelCache(image->cache);
894 return(clone_image);
895 }
cristy51d26762014-05-26 01:29:41 +0000896 scale=1.0;
897 if (image->columns != 0)
898 scale=(double) columns/(double) image->columns;
cristybb503372010-05-27 20:51:26 +0000899 clone_image->page.width=(size_t) floor(scale*image->page.width+0.5);
900 clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5);
901 clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5);
cristy51d26762014-05-26 01:29:41 +0000902 scale=1.0;
903 if (image->rows != 0)
cristyee2f5d62015-07-28 13:19:43 +0000904 scale=(double) rows/(double) image->rows;
cristybb503372010-05-27 20:51:26 +0000905 clone_image->page.height=(size_t) floor(scale*image->page.height+0.5);
906 clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5);
907 clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5);
cristy3ed852e2009-09-05 21:47:34 +0000908 clone_image->columns=columns;
909 clone_image->rows=rows;
910 clone_image->cache=ClonePixelCache(image->cache);
911 return(clone_image);
912}
913
914/*
915%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
916% %
917% %
918% %
919% C l o n e I m a g e I n f o %
920% %
921% %
922% %
923%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
924%
925% CloneImageInfo() makes a copy of the given image info structure. If
926% NULL is specified, a new image info structure is created initialized to
927% default values.
928%
929% The format of the CloneImageInfo method is:
930%
931% ImageInfo *CloneImageInfo(const ImageInfo *image_info)
932%
933% A description of each parameter follows:
934%
935% o image_info: the image info.
936%
937*/
938MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info)
939{
940 ImageInfo
941 *clone_info;
942
943 clone_info=AcquireImageInfo();
944 if (image_info == (ImageInfo *) NULL)
945 return(clone_info);
946 clone_info->compression=image_info->compression;
947 clone_info->temporary=image_info->temporary;
948 clone_info->adjoin=image_info->adjoin;
949 clone_info->antialias=image_info->antialias;
950 clone_info->scene=image_info->scene;
951 clone_info->number_scenes=image_info->number_scenes;
952 clone_info->depth=image_info->depth;
anthony72feaa62012-01-17 06:46:23 +0000953 (void) CloneString(&clone_info->size,image_info->size);
954 (void) CloneString(&clone_info->extract,image_info->extract);
955 (void) CloneString(&clone_info->scenes,image_info->scenes);
956 (void) CloneString(&clone_info->page,image_info->page);
cristy3ed852e2009-09-05 21:47:34 +0000957 clone_info->interlace=image_info->interlace;
958 clone_info->endian=image_info->endian;
959 clone_info->units=image_info->units;
960 clone_info->quality=image_info->quality;
anthony72feaa62012-01-17 06:46:23 +0000961 (void) CloneString(&clone_info->sampling_factor,image_info->sampling_factor);
962 (void) CloneString(&clone_info->server_name,image_info->server_name);
963 (void) CloneString(&clone_info->font,image_info->font);
964 (void) CloneString(&clone_info->texture,image_info->texture);
965 (void) CloneString(&clone_info->density,image_info->density);
cristy3ed852e2009-09-05 21:47:34 +0000966 clone_info->pointsize=image_info->pointsize;
967 clone_info->fuzz=image_info->fuzz;
cristy3ed852e2009-09-05 21:47:34 +0000968 clone_info->background_color=image_info->background_color;
969 clone_info->border_color=image_info->border_color;
970 clone_info->matte_color=image_info->matte_color;
971 clone_info->transparent_color=image_info->transparent_color;
972 clone_info->dither=image_info->dither;
973 clone_info->monochrome=image_info->monochrome;
cristy3ed852e2009-09-05 21:47:34 +0000974 clone_info->colorspace=image_info->colorspace;
975 clone_info->type=image_info->type;
976 clone_info->orientation=image_info->orientation;
977 clone_info->preview_type=image_info->preview_type;
978 clone_info->group=image_info->group;
979 clone_info->ping=image_info->ping;
980 clone_info->verbose=image_info->verbose;
anthony72feaa62012-01-17 06:46:23 +0000981 (void) CloneString(&clone_info->view,image_info->view);
cristy3ed852e2009-09-05 21:47:34 +0000982 clone_info->progress_monitor=image_info->progress_monitor;
983 clone_info->client_data=image_info->client_data;
984 clone_info->cache=image_info->cache;
985 if (image_info->cache != (void *) NULL)
986 clone_info->cache=ReferencePixelCache(image_info->cache);
987 if (image_info->profile != (void *) NULL)
988 clone_info->profile=(void *) CloneStringInfo((StringInfo *)
989 image_info->profile);
990 SetImageInfoFile(clone_info,image_info->file);
991 SetImageInfoBlob(clone_info,image_info->blob,image_info->length);
992 clone_info->stream=image_info->stream;
cristy957f2612015-06-21 23:51:58 +0000993 (void) CopyMagickString(clone_info->magick,image_info->magick,
994 MagickPathExtent);
995 (void) CopyMagickString(clone_info->unique,image_info->unique,
996 MagickPathExtent);
cristy151b66d2015-04-15 10:50:31 +0000997 (void) CopyMagickString(clone_info->zero,image_info->zero,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000998 (void) CopyMagickString(clone_info->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +0000999 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001000 clone_info->channel=image_info->channel;
anthony1afdc7a2011-10-05 11:54:28 +00001001 (void) CloneImageOptions(clone_info,image_info);
cristy3ed852e2009-09-05 21:47:34 +00001002 clone_info->debug=IsEventLogging();
1003 clone_info->signature=image_info->signature;
1004 return(clone_info);
1005}
1006
1007/*
1008%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1009% %
1010% %
1011% %
cristy957f2612015-06-21 23:51:58 +00001012% C o p y I m a g e P i x e l s %
1013% %
1014% %
1015% %
1016%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1017%
1018% CopyImagePixels() copies pixels from the source image as defined by the
1019% geometry the destination image at the specified offset.
1020%
1021% The format of the CopyImagePixels method is:
1022%
1023% MagickBooleanType CopyImagePixels(Image *image,const Image *source_image,
cristy17fbd722015-06-22 00:46:58 +00001024% const RectangleInfo *geometry,const OffsetInfo *offset,
1025% ExceptionInfo *exception);
cristy957f2612015-06-21 23:51:58 +00001026%
1027% A description of each parameter follows:
1028%
1029% o image: the destination image.
1030%
1031% o source_image: the source image.
1032%
1033% o geometry: define the dimensions of the source pixel rectangle.
1034%
1035% o offset: define the offset in the destination image.
1036%
cristy17fbd722015-06-22 00:46:58 +00001037% o exception: return any errors or warnings in this structure.
1038%
cristy957f2612015-06-21 23:51:58 +00001039*/
1040MagickExport MagickBooleanType CopyImagePixels(Image *image,
1041 const Image *source_image,const RectangleInfo *geometry,
cristy17fbd722015-06-22 00:46:58 +00001042 const OffsetInfo *offset,ExceptionInfo *exception)
cristy957f2612015-06-21 23:51:58 +00001043{
cristy17fbd722015-06-22 00:46:58 +00001044#define CopyImageTag "Copy/Image"
1045
1046 CacheView
1047 *image_view,
1048 *source_view;
1049
1050 MagickBooleanType
1051 status;
1052
1053 MagickOffsetType
1054 progress;
1055
1056 ssize_t
1057 y;
1058
cristy957f2612015-06-21 23:51:58 +00001059 assert(image != (Image *) NULL);
1060 if (image->debug != MagickFalse)
1061 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1062 assert(source_image != (Image *) NULL);
1063 assert(geometry != (RectangleInfo *) NULL);
1064 assert(offset != (OffsetInfo *) NULL);
cristy8c4c1c42015-06-22 23:51:22 +00001065 if ((offset->x < 0) || (offset->y < 0) ||
Cristy7d049b72015-09-26 20:50:55 -04001066 ((ssize_t) (offset->x+geometry->width) > (ssize_t) image->columns) ||
1067 ((ssize_t) (offset->y+geometry->height) > (ssize_t) image->rows))
cristye742cae2015-06-22 19:40:29 +00001068 ThrowBinaryException(OptionError,"GeometryDoesNotContainImage",
1069 image->filename);
cristy8c4c1c42015-06-22 23:51:22 +00001070 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
1071 return(MagickFalse);
cristy17fbd722015-06-22 00:46:58 +00001072 /*
1073 Copy image pixels.
1074 */
1075 status=MagickTrue;
1076 progress=0;
1077 source_view=AcquireVirtualCacheView(source_image,exception);
1078 image_view=AcquireAuthenticCacheView(image,exception);
1079#if defined(MAGICKCORE_OPENMP_SUPPORT)
1080 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristye742cae2015-06-22 19:40:29 +00001081 magick_threads(image,source_image,geometry->height,1)
cristy17fbd722015-06-22 00:46:58 +00001082#endif
cristye742cae2015-06-22 19:40:29 +00001083 for (y=0; y < (ssize_t) geometry->height; y++)
cristy17fbd722015-06-22 00:46:58 +00001084 {
1085 MagickBooleanType
1086 sync;
1087
1088 register const Quantum
1089 *restrict p;
1090
1091 register ssize_t
1092 x;
1093
1094 register Quantum
1095 *restrict q;
1096
1097 if (status == MagickFalse)
1098 continue;
cristye742cae2015-06-22 19:40:29 +00001099 p=GetCacheViewVirtualPixels(source_view,geometry->x,y+geometry->y,
1100 geometry->width,1,exception);
1101 q=QueueCacheViewAuthenticPixels(image_view,offset->x,y+offset->y,
1102 geometry->width,1,exception);
cristy17fbd722015-06-22 00:46:58 +00001103 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1104 {
1105 status=MagickFalse;
1106 continue;
1107 }
cristye742cae2015-06-22 19:40:29 +00001108 for (x=0; x < (ssize_t) geometry->width; x++)
cristy17fbd722015-06-22 00:46:58 +00001109 {
1110 register ssize_t
1111 i;
1112
1113 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1114 {
1115 PixelChannel channel=GetPixelChannelChannel(image,i);
1116 PixelTrait traits=GetPixelChannelTraits(image,channel);
1117 PixelTrait source_traits=GetPixelChannelTraits(source_image,channel);
1118 if ((traits == UndefinedPixelTrait) ||
1119 (source_traits == UndefinedPixelTrait))
1120 continue;
dirkd00a0022015-07-05 09:54:39 +00001121 SetPixelChannel(image,channel,p[i],q);
cristy17fbd722015-06-22 00:46:58 +00001122 }
dirkd00a0022015-07-05 09:54:39 +00001123 p+=GetPixelChannels(source_image);
1124 q+=GetPixelChannels(image);
cristy17fbd722015-06-22 00:46:58 +00001125 }
dirkd00a0022015-07-05 09:54:39 +00001126 sync=SyncCacheViewAuthenticPixels(image_view,exception);
cristy17fbd722015-06-22 00:46:58 +00001127 if (sync == MagickFalse)
1128 status=MagickFalse;
1129 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1130 {
1131 MagickBooleanType
1132 proceed;
1133
1134#if defined(MAGICKCORE_OPENMP_SUPPORT)
1135 #pragma omp critical (MagickCore_CopyImage)
1136#endif
1137 proceed=SetImageProgress(image,CopyImageTag,progress++,image->rows);
1138 if (proceed == MagickFalse)
1139 status=MagickFalse;
1140 }
1141 }
1142 source_view=DestroyCacheView(source_view);
1143 image_view=DestroyCacheView(image_view);
1144 return(status);
cristy957f2612015-06-21 23:51:58 +00001145}
1146
1147/*
1148%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1149% %
1150% %
1151% %
cristy3ed852e2009-09-05 21:47:34 +00001152% D e s t r o y I m a g e %
1153% %
1154% %
1155% %
1156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1157%
1158% DestroyImage() dereferences an image, deallocating memory associated with
1159% the image if the reference count becomes zero.
1160%
1161% The format of the DestroyImage method is:
1162%
1163% Image *DestroyImage(Image *image)
1164%
1165% A description of each parameter follows:
1166%
1167% o image: the image.
1168%
1169*/
1170MagickExport Image *DestroyImage(Image *image)
1171{
1172 MagickBooleanType
1173 destroy;
1174
1175 /*
1176 Dereference image.
1177 */
1178 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001179 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001180 if (image->debug != MagickFalse)
1181 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1182 destroy=MagickFalse;
cristyf84a1932010-01-03 18:00:18 +00001183 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001184 image->reference_count--;
1185 if (image->reference_count == 0)
1186 destroy=MagickTrue;
cristyf84a1932010-01-03 18:00:18 +00001187 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001188 if (destroy == MagickFalse)
1189 return((Image *) NULL);
1190 /*
1191 Destroy image.
1192 */
1193 DestroyImagePixels(image);
cristyed231572011-07-14 02:18:59 +00001194 image->channel_map=DestroyPixelChannelMap(image->channel_map);
cristy3ed852e2009-09-05 21:47:34 +00001195 if (image->montage != (char *) NULL)
1196 image->montage=DestroyString(image->montage);
1197 if (image->directory != (char *) NULL)
1198 image->directory=DestroyString(image->directory);
cristy101ab702011-10-13 13:06:32 +00001199 if (image->colormap != (PixelInfo *) NULL)
1200 image->colormap=(PixelInfo *) RelinquishMagickMemory(image->colormap);
cristy3ed852e2009-09-05 21:47:34 +00001201 if (image->geometry != (char *) NULL)
1202 image->geometry=DestroyString(image->geometry);
cristy3ed852e2009-09-05 21:47:34 +00001203 DestroyImageProfiles(image);
1204 DestroyImageProperties(image);
1205 DestroyImageArtifacts(image);
Cristy36421ee2015-08-28 11:58:20 -04001206 if (image->ascii85 != (Ascii85Info *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001207 image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85);
Cristy36421ee2015-08-28 11:58:20 -04001208 if (image->image_info != (ImageInfo *) NULL)
1209 image->image_info=DestroyImageInfo(image->image_info);
cristy3ed852e2009-09-05 21:47:34 +00001210 DestroyBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001211 if (image->semaphore != (SemaphoreInfo *) NULL)
cristy3d162a92014-02-16 14:05:06 +00001212 RelinquishSemaphoreInfo(&image->semaphore);
cristye1c94d92015-06-28 12:16:33 +00001213 image->signature=(~MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001214 image=(Image *) RelinquishMagickMemory(image);
1215 return(image);
1216}
1217
1218/*
1219%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1220% %
1221% %
1222% %
1223% D e s t r o y I m a g e I n f o %
1224% %
1225% %
1226% %
1227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1228%
1229% DestroyImageInfo() deallocates memory associated with an ImageInfo
1230% structure.
1231%
1232% The format of the DestroyImageInfo method is:
1233%
1234% ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1235%
1236% A description of each parameter follows:
1237%
1238% o image_info: the image info.
1239%
1240*/
1241MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info)
1242{
1243 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001244 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001245 if (image_info->debug != MagickFalse)
1246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
1247 image_info->filename);
1248 if (image_info->size != (char *) NULL)
1249 image_info->size=DestroyString(image_info->size);
1250 if (image_info->extract != (char *) NULL)
1251 image_info->extract=DestroyString(image_info->extract);
1252 if (image_info->scenes != (char *) NULL)
1253 image_info->scenes=DestroyString(image_info->scenes);
1254 if (image_info->page != (char *) NULL)
1255 image_info->page=DestroyString(image_info->page);
1256 if (image_info->sampling_factor != (char *) NULL)
1257 image_info->sampling_factor=DestroyString(
1258 image_info->sampling_factor);
1259 if (image_info->server_name != (char *) NULL)
1260 image_info->server_name=DestroyString(
1261 image_info->server_name);
1262 if (image_info->font != (char *) NULL)
1263 image_info->font=DestroyString(image_info->font);
1264 if (image_info->texture != (char *) NULL)
1265 image_info->texture=DestroyString(image_info->texture);
1266 if (image_info->density != (char *) NULL)
1267 image_info->density=DestroyString(image_info->density);
1268 if (image_info->view != (char *) NULL)
1269 image_info->view=DestroyString(image_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001270 if (image_info->cache != (void *) NULL)
1271 image_info->cache=DestroyPixelCache(image_info->cache);
1272 if (image_info->profile != (StringInfo *) NULL)
1273 image_info->profile=(void *) DestroyStringInfo((StringInfo *)
1274 image_info->profile);
anthony1afdc7a2011-10-05 11:54:28 +00001275 DestroyImageOptions(image_info);
cristye1c94d92015-06-28 12:16:33 +00001276 image_info->signature=(~MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001277 image_info=(ImageInfo *) RelinquishMagickMemory(image_info);
1278 return(image_info);
1279}
1280
1281/*
1282%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283% %
1284% %
1285% %
1286+ D i s a s s o c i a t e I m a g e S t r e a m %
1287% %
1288% %
1289% %
1290%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291%
cristy4916cb42014-09-20 00:44:37 +00001292% DisassociateImageStream() disassociates the image stream. It checks if the
1293% blob of the specified image is referenced by other images. If the reference
1294% count is higher then 1 a new blob is assigned to the specified image.
cristy3ed852e2009-09-05 21:47:34 +00001295%
1296% The format of the DisassociateImageStream method is:
1297%
dirkcfe4c1c2014-09-20 07:38:59 +00001298% void DisassociateImageStream(const Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001299%
1300% A description of each parameter follows:
1301%
1302% o image: the image.
1303%
1304*/
1305MagickExport void DisassociateImageStream(Image *image)
1306{
cristy4916cb42014-09-20 00:44:37 +00001307 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001308 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001309 if (image->debug != MagickFalse)
1310 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy10f10ec2014-09-20 01:00:50 +00001311 DisassociateBlob(image);
cristy3ed852e2009-09-05 21:47:34 +00001312}
1313
1314/*
1315%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1316% %
1317% %
1318% %
cristy3ed852e2009-09-05 21:47:34 +00001319% G e t I m a g e I n f o %
1320% %
1321% %
1322% %
1323%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1324%
1325% GetImageInfo() initializes image_info to default values.
1326%
1327% The format of the GetImageInfo method is:
1328%
1329% void GetImageInfo(ImageInfo *image_info)
1330%
1331% A description of each parameter follows:
1332%
1333% o image_info: the image info.
1334%
1335*/
1336MagickExport void GetImageInfo(ImageInfo *image_info)
1337{
cristyfa0ea942012-12-21 02:42:29 +00001338 char
1339 *synchronize;
1340
cristy3ed852e2009-09-05 21:47:34 +00001341 ExceptionInfo
1342 *exception;
1343
1344 /*
1345 File and image dimension members.
1346 */
1347 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1348 assert(image_info != (ImageInfo *) NULL);
1349 (void) ResetMagickMemory(image_info,0,sizeof(*image_info));
1350 image_info->adjoin=MagickTrue;
1351 image_info->interlace=NoInterlace;
1352 image_info->channel=DefaultChannels;
1353 image_info->quality=UndefinedCompressionQuality;
1354 image_info->antialias=MagickTrue;
1355 image_info->dither=MagickTrue;
cristyfa0ea942012-12-21 02:42:29 +00001356 synchronize=GetEnvironmentValue("MAGICK_SYNCHRONIZE");
1357 if (synchronize != (const char *) NULL)
1358 {
1359 image_info->synchronize=IsStringTrue(synchronize);
1360 synchronize=DestroyString(synchronize);
1361 }
cristy3ed852e2009-09-05 21:47:34 +00001362 exception=AcquireExceptionInfo();
cristy9950d572011-10-01 18:22:35 +00001363 (void) QueryColorCompliance(BackgroundColor,AllCompliance,
1364 &image_info->background_color,exception);
1365 (void) QueryColorCompliance(BorderColor,AllCompliance,
1366 &image_info->border_color,exception);
1367 (void) QueryColorCompliance(MatteColor,AllCompliance,&image_info->matte_color,
cristy3ed852e2009-09-05 21:47:34 +00001368 exception);
cristy9950d572011-10-01 18:22:35 +00001369 (void) QueryColorCompliance(TransparentColor,AllCompliance,
1370 &image_info->transparent_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00001371 exception=DestroyExceptionInfo(exception);
1372 image_info->debug=IsEventLogging();
cristye1c94d92015-06-28 12:16:33 +00001373 image_info->signature=MagickCoreSignature;
cristy3ed852e2009-09-05 21:47:34 +00001374}
1375
1376/*
1377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1378% %
1379% %
1380% %
cristy15781e52009-12-05 23:05:27 +00001381% G e t I m a g e I n f o F i l e %
1382% %
1383% %
1384% %
1385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1386%
1387% GetImageInfoFile() returns the image info file member.
1388%
1389% The format of the GetImageInfoFile method is:
1390%
1391% FILE *GetImageInfoFile(const ImageInfo *image_info)
1392%
1393% A description of each parameter follows:
1394%
1395% o image_info: the image info.
1396%
1397*/
1398MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info)
1399{
1400 return(image_info->file);
1401}
1402
1403/*
1404%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405% %
1406% %
1407% %
cristy3ed852e2009-09-05 21:47:34 +00001408% G e t I m a g e M a s k %
1409% %
1410% %
1411% %
1412%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1413%
1414% GetImageMask() returns the mask associated with the image.
1415%
1416% The format of the GetImageMask method is:
1417%
1418% Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1419%
1420% A description of each parameter follows:
1421%
1422% o image: the image.
1423%
1424*/
1425MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception)
1426{
cristy10a6c612012-01-29 21:41:05 +00001427 CacheView
1428 *mask_view,
1429 *image_view;
1430
1431 Image
1432 *mask_image;
1433
1434 MagickBooleanType
1435 status;
1436
1437 ssize_t
1438 y;
1439
1440 /*
1441 Get image mask.
1442 */
1443 assert(image != (Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00001444 if (image->debug != MagickFalse)
1445 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00001446 assert(image->signature == MagickCoreSignature);
cristy10a6c612012-01-29 21:41:05 +00001447 mask_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
1448 if (mask_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001449 return((Image *) NULL);
cristy10a6c612012-01-29 21:41:05 +00001450 status=MagickTrue;
cristy5ccdd122012-06-13 22:29:02 +00001451 (void) SetImageColorspace(mask_image,GRAYColorspace,exception);
cristy883fde12013-04-08 00:50:13 +00001452 mask_image->read_mask=MagickFalse;
cristy46ff2672012-12-14 15:32:26 +00001453 image_view=AcquireVirtualCacheView(image,exception);
1454 mask_view=AcquireAuthenticCacheView(mask_image,exception);
cristy10a6c612012-01-29 21:41:05 +00001455 for (y=0; y < (ssize_t) image->rows; y++)
1456 {
1457 register const Quantum
1458 *restrict p;
1459
1460 register Quantum
1461 *restrict q;
1462
1463 register ssize_t
1464 x;
1465
1466 if (status == MagickFalse)
1467 continue;
1468 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1469 q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1470 exception);
1471 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
1472 {
1473 status=MagickFalse;
1474 continue;
1475 }
1476 for (x=0; x < (ssize_t) image->columns; x++)
1477 {
cristy883fde12013-04-08 00:50:13 +00001478 SetPixelGray(mask_image,GetPixelReadMask(image,p),q);
cristy10a6c612012-01-29 21:41:05 +00001479 p+=GetPixelChannels(image);
1480 q+=GetPixelChannels(mask_image);
1481 }
1482 if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1483 status=MagickFalse;
1484 }
1485 mask_view=DestroyCacheView(mask_view);
1486 image_view=DestroyCacheView(image_view);
cristy1c2f48d2012-12-14 01:20:55 +00001487 if (status == MagickFalse)
1488 mask_image=DestroyImage(mask_image);
cristy10a6c612012-01-29 21:41:05 +00001489 return(mask_image);
cristy3ed852e2009-09-05 21:47:34 +00001490}
1491
1492/*
1493%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1494% %
1495% %
1496% %
1497+ G e t I m a g e R e f e r e n c e C o u n t %
1498% %
1499% %
1500% %
1501%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1502%
1503% GetImageReferenceCount() returns the image reference count.
1504%
1505% The format of the GetReferenceCount method is:
1506%
cristybb503372010-05-27 20:51:26 +00001507% ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001508%
1509% A description of each parameter follows:
1510%
1511% o image: the image.
1512%
1513*/
cristybb503372010-05-27 20:51:26 +00001514MagickExport ssize_t GetImageReferenceCount(Image *image)
cristy3ed852e2009-09-05 21:47:34 +00001515{
cristybb503372010-05-27 20:51:26 +00001516 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001517 reference_count;
1518
1519 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001520 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001521 if (image->debug != MagickFalse)
1522 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristyf84a1932010-01-03 18:00:18 +00001523 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001524 reference_count=image->reference_count;
cristyf84a1932010-01-03 18:00:18 +00001525 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001526 return(reference_count);
1527}
1528
1529/*
1530%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1531% %
1532% %
1533% %
cristy3ed852e2009-09-05 21:47:34 +00001534% 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 %
1535% %
1536% %
1537% %
1538%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1539%
1540% GetImageVirtualPixelMethod() gets the "virtual pixels" method for the
1541% image. A virtual pixel is any pixel access that is outside the boundaries
1542% of the image cache.
1543%
1544% The format of the GetImageVirtualPixelMethod() method is:
1545%
1546% VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1547%
1548% A description of each parameter follows:
1549%
1550% o image: the image.
1551%
1552*/
1553MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image)
1554{
1555 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001556 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001557 if (image->debug != MagickFalse)
1558 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1559 return(GetPixelCacheVirtualMethod(image));
1560}
1561
1562/*
1563%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1564% %
1565% %
1566% %
1567% I n t e r p r e t I m a g e F i l e n a m e %
1568% %
1569% %
1570% %
1571%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1572%
1573% InterpretImageFilename() interprets embedded characters in an image filename.
1574% The filename length is returned.
1575%
1576% The format of the InterpretImageFilename method is:
1577%
cristyee2b1232012-03-04 02:58:28 +00001578% size_t InterpretImageFilename(const ImageInfo *image_info,Image *image,
1579% const char *format,int value,char *filename,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001580%
1581% A description of each parameter follows.
1582%
1583% o image_info: the image info..
1584%
1585% o image: the image.
1586%
1587% o format: A filename describing the format to use to write the numeric
1588% argument. Only the first numeric format identifier is replaced.
1589%
1590% o value: Numeric value to substitute into format filename.
1591%
1592% o filename: return the formatted filename in this character buffer.
1593%
cristy6fccee12011-10-20 18:43:18 +00001594% o exception: return any errors or warnings in this structure.
1595%
cristy3ed852e2009-09-05 21:47:34 +00001596*/
1597MagickExport size_t InterpretImageFilename(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00001598 Image *image,const char *format,int value,char *filename,
1599 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001600{
1601 char
1602 *q;
1603
1604 int
1605 c;
1606
1607 MagickBooleanType
1608 canonical;
1609
1610 register const char
1611 *p;
1612
cristyad785752011-07-27 23:13:03 +00001613 size_t
1614 length;
1615
cristy3ed852e2009-09-05 21:47:34 +00001616 canonical=MagickFalse;
cristyc7b79fc2011-07-28 00:24:17 +00001617 length=0;
cristy151b66d2015-04-15 10:50:31 +00001618 (void) CopyMagickString(filename,format,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001619 for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%'))
1620 {
1621 q=(char *) p+1;
1622 if (*q == '%')
1623 {
1624 p=q+1;
1625 continue;
1626 }
1627 if (*q == '0')
1628 {
cristybb503372010-05-27 20:51:26 +00001629 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001630 value;
1631
cristybb503372010-05-27 20:51:26 +00001632 value=(ssize_t) strtol(q,&q,10);
cristyda16f162011-02-19 23:52:17 +00001633 (void) value;
cristy3ed852e2009-09-05 21:47:34 +00001634 }
1635 switch (*q)
1636 {
1637 case 'd':
1638 case 'o':
1639 case 'x':
1640 {
1641 q++;
1642 c=(*q);
1643 *q='\0';
cristyee2f5d62015-07-28 13:19:43 +00001644 (void) FormatLocaleString(filename+(p-format),(size_t)
1645 (MagickPathExtent-(p-format)),p,value);
cristy3ed852e2009-09-05 21:47:34 +00001646 *q=c;
cristy151b66d2015-04-15 10:50:31 +00001647 (void) ConcatenateMagickString(filename,q,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001648 canonical=MagickTrue;
1649 if (*(q-1) != '%')
1650 break;
1651 p++;
1652 break;
1653 }
1654 case '[':
1655 {
1656 char
cristy151b66d2015-04-15 10:50:31 +00001657 pattern[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001658
1659 const char
1660 *value;
1661
cristy3ed852e2009-09-05 21:47:34 +00001662 register char
1663 *r;
1664
cristybb503372010-05-27 20:51:26 +00001665 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001666 i;
1667
cristycb6d09b2010-06-19 01:59:36 +00001668 ssize_t
1669 depth;
1670
cristy3ed852e2009-09-05 21:47:34 +00001671 /*
1672 Image option.
1673 */
anthony2cfa1a12012-05-12 05:18:07 +00001674 /* FUTURE: Compare update with code from InterpretImageProperties()
cristy97fc9f32012-06-13 21:04:44 +00001675 Note that a 'filename:' property should not need depth recursion.
anthony2cfa1a12012-05-12 05:18:07 +00001676 */
cristy3ed852e2009-09-05 21:47:34 +00001677 if (strchr(p,']') == (char *) NULL)
1678 break;
1679 depth=1;
1680 r=q+1;
cristy151b66d2015-04-15 10:50:31 +00001681 for (i=0; (i < (MagickPathExtent-1L)) && (*r != '\0'); i++)
cristy3ed852e2009-09-05 21:47:34 +00001682 {
1683 if (*r == '[')
1684 depth++;
1685 if (*r == ']')
1686 depth--;
1687 if (depth <= 0)
1688 break;
1689 pattern[i]=(*r++);
1690 }
1691 pattern[i]='\0';
1692 if (LocaleNCompare(pattern,"filename:",9) != 0)
1693 break;
1694 value=(const char *) NULL;
anthony06762232012-04-29 11:45:40 +00001695 if (image != (Image *) NULL)
1696 value=GetImageProperty(image,pattern,exception);
cristy1a780952013-02-10 17:15:30 +00001697 if ((value == (const char *) NULL) && (image != (Image *) NULL))
anthony06762232012-04-29 11:45:40 +00001698 value=GetImageArtifact(image,pattern);
1699 if ((value == (const char *) NULL) &&
1700 (image_info != (ImageInfo *) NULL))
1701 value=GetImageOption(image_info,pattern);
cristy3ed852e2009-09-05 21:47:34 +00001702 if (value == (const char *) NULL)
1703 break;
1704 q--;
1705 c=(*q);
1706 *q='\0';
cristyad785752011-07-27 23:13:03 +00001707 (void) CopyMagickString(filename+(p-format-length),value,(size_t)
cristy151b66d2015-04-15 10:50:31 +00001708 (MagickPathExtent-(p-format-length)));
cristyad785752011-07-27 23:13:03 +00001709 length+=strlen(pattern)-1;
cristy3ed852e2009-09-05 21:47:34 +00001710 *q=c;
cristy151b66d2015-04-15 10:50:31 +00001711 (void) ConcatenateMagickString(filename,r+1,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001712 canonical=MagickTrue;
1713 if (*(q-1) != '%')
1714 break;
1715 p++;
1716 break;
1717 }
1718 default:
1719 break;
1720 }
1721 }
1722 for (q=filename; *q != '\0'; q++)
1723 if ((*q == '%') && (*(q+1) == '%'))
cristy27bf23e2011-01-10 13:35:22 +00001724 {
cristy151b66d2015-04-15 10:50:31 +00001725 (void) CopyMagickString(q,q+1,(size_t) (MagickPathExtent-(q-filename)));
cristy27bf23e2011-01-10 13:35:22 +00001726 canonical=MagickTrue;
1727 }
cristy3ed852e2009-09-05 21:47:34 +00001728 if (canonical == MagickFalse)
cristy151b66d2015-04-15 10:50:31 +00001729 (void) CopyMagickString(filename,format,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001730 return(strlen(filename));
1731}
1732
1733/*
1734%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1735% %
1736% %
1737% %
1738% I s H i g h D y n a m i c R a n g e I m a g e %
1739% %
1740% %
1741% %
1742%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1743%
1744% IsHighDynamicRangeImage() returns MagickTrue if any pixel component is
1745% non-integer or exceeds the bounds of the quantum depth (e.g. for Q16
1746% 0..65535.
1747%
1748% The format of the IsHighDynamicRangeImage method is:
1749%
1750% MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1751% ExceptionInfo *exception)
1752%
1753% A description of each parameter follows:
1754%
1755% o image: the image.
1756%
1757% o exception: return any errors or warnings in this structure.
1758%
1759*/
1760MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image,
1761 ExceptionInfo *exception)
1762{
1763#if !defined(MAGICKCORE_HDRI_SUPPORT)
1764 (void) image;
1765 (void) exception;
1766 return(MagickFalse);
1767#else
1768 CacheView
1769 *image_view;
1770
cristy3ed852e2009-09-05 21:47:34 +00001771 MagickBooleanType
1772 status;
1773
cristycb6d09b2010-06-19 01:59:36 +00001774 ssize_t
1775 y;
1776
cristy3ed852e2009-09-05 21:47:34 +00001777 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001778 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001779 if (image->debug != MagickFalse)
1780 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1781 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00001782 image_view=AcquireVirtualCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00001783#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00001784 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00001785 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00001786#endif
cristybb503372010-05-27 20:51:26 +00001787 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00001788 {
cristy4c08aed2011-07-01 19:47:50 +00001789 register const Quantum
cristy3ed852e2009-09-05 21:47:34 +00001790 *p;
1791
cristybb503372010-05-27 20:51:26 +00001792 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001793 x;
1794
1795 if (status == MagickFalse)
1796 continue;
1797 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00001798 if (p == (const Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001799 {
1800 status=MagickFalse;
1801 continue;
1802 }
cristybb503372010-05-27 20:51:26 +00001803 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00001804 {
cristya905c052011-09-17 22:37:55 +00001805 register ssize_t
1806 i;
1807
cristy883fde12013-04-08 00:50:13 +00001808 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +00001809 {
1810 p+=GetPixelChannels(image);
1811 continue;
1812 }
cristya905c052011-09-17 22:37:55 +00001813 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
1814 {
cristya19f1d72012-08-07 18:24:38 +00001815 double
cristya905c052011-09-17 22:37:55 +00001816 pixel;
1817
cristyb0a657e2012-08-29 00:45:37 +00001818 PixelTrait
1819 traits;
1820
1821 traits=GetPixelChannelTraits(image,(PixelChannel) i);
cristya905c052011-09-17 22:37:55 +00001822 if (traits == UndefinedPixelTrait)
1823 continue;
cristya19f1d72012-08-07 18:24:38 +00001824 pixel=(double) p[i];
cristya905c052011-09-17 22:37:55 +00001825 if ((pixel < 0.0) || (pixel > QuantumRange) ||
cristy569b0e32013-08-15 16:07:35 +00001826 (pixel != (double) ((QuantumAny) pixel)))
cristya905c052011-09-17 22:37:55 +00001827 break;
1828 }
cristyed231572011-07-14 02:18:59 +00001829 p+=GetPixelChannels(image);
cristya905c052011-09-17 22:37:55 +00001830 if (i < (ssize_t) GetPixelChannels(image))
1831 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00001832 }
cristybb503372010-05-27 20:51:26 +00001833 if (x < (ssize_t) image->columns)
cristy3ed852e2009-09-05 21:47:34 +00001834 status=MagickFalse;
1835 }
1836 image_view=DestroyCacheView(image_view);
1837 return(status != MagickFalse ? MagickFalse : MagickTrue);
1838#endif
1839}
1840
1841/*
1842%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1843% %
1844% %
1845% %
1846% I s I m a g e O b j e c t %
1847% %
1848% %
1849% %
1850%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1851%
1852% IsImageObject() returns MagickTrue if the image sequence contains a valid
1853% set of image objects.
1854%
1855% The format of the IsImageObject method is:
1856%
1857% MagickBooleanType IsImageObject(const Image *image)
1858%
1859% A description of each parameter follows:
1860%
1861% o image: the image.
1862%
1863*/
1864MagickExport MagickBooleanType IsImageObject(const Image *image)
1865{
1866 register const Image
1867 *p;
1868
1869 assert(image != (Image *) NULL);
1870 if (image->debug != MagickFalse)
1871 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1872 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
cristye1c94d92015-06-28 12:16:33 +00001873 if (p->signature != MagickCoreSignature)
cristy3ed852e2009-09-05 21:47:34 +00001874 return(MagickFalse);
1875 return(MagickTrue);
1876}
1877
1878/*
1879%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1880% %
1881% %
1882% %
1883% I s T a i n t I m a g e %
1884% %
1885% %
1886% %
1887%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1888%
1889% IsTaintImage() returns MagickTrue any pixel in the image has been altered
1890% since it was first constituted.
1891%
1892% The format of the IsTaintImage method is:
1893%
1894% MagickBooleanType IsTaintImage(const Image *image)
1895%
1896% A description of each parameter follows:
1897%
1898% o image: the image.
1899%
1900*/
1901MagickExport MagickBooleanType IsTaintImage(const Image *image)
1902{
1903 char
cristy151b66d2015-04-15 10:50:31 +00001904 magick[MagickPathExtent],
1905 filename[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001906
1907 register const Image
1908 *p;
1909
1910 assert(image != (Image *) NULL);
1911 if (image->debug != MagickFalse)
1912 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00001913 assert(image->signature == MagickCoreSignature);
cristy151b66d2015-04-15 10:50:31 +00001914 (void) CopyMagickString(magick,image->magick,MagickPathExtent);
1915 (void) CopyMagickString(filename,image->filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001916 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1917 {
1918 if (p->taint != MagickFalse)
1919 return(MagickTrue);
1920 if (LocaleCompare(p->magick,magick) != 0)
1921 return(MagickTrue);
1922 if (LocaleCompare(p->filename,filename) != 0)
1923 return(MagickTrue);
1924 }
1925 return(MagickFalse);
1926}
1927
1928/*
1929%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1930% %
1931% %
1932% %
1933% M o d i f y I m a g e %
1934% %
1935% %
1936% %
1937%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1938%
1939% ModifyImage() ensures that there is only a single reference to the image
1940% to be modified, updating the provided image pointer to point to a clone of
1941% the original image if necessary.
1942%
1943% The format of the ModifyImage method is:
1944%
1945% MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception)
1946%
1947% A description of each parameter follows:
1948%
1949% o image: the image.
1950%
1951% o exception: return any errors or warnings in this structure.
1952%
1953*/
1954MagickExport MagickBooleanType ModifyImage(Image **image,
1955 ExceptionInfo *exception)
1956{
1957 Image
1958 *clone_image;
1959
1960 assert(image != (Image **) NULL);
1961 assert(*image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001962 assert((*image)->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001963 if ((*image)->debug != MagickFalse)
1964 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1965 if (GetImageReferenceCount(*image) <= 1)
1966 return(MagickTrue);
1967 clone_image=CloneImage(*image,0,0,MagickTrue,exception);
cristyf84a1932010-01-03 18:00:18 +00001968 LockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001969 (*image)->reference_count--;
cristyf84a1932010-01-03 18:00:18 +00001970 UnlockSemaphoreInfo((*image)->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00001971 *image=clone_image;
1972 return(MagickTrue);
1973}
1974
1975/*
1976%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1977% %
1978% %
1979% %
1980% N e w M a g i c k I m a g e %
1981% %
1982% %
1983% %
1984%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1985%
1986% NewMagickImage() creates a blank image canvas of the specified size and
1987% background color.
1988%
1989% The format of the NewMagickImage method is:
1990%
cristy44410ab2014-05-25 20:39:43 +00001991% Image *NewMagickImage(const ImageInfo *image_info,const size_t width,
1992% const size_t height,const PixelInfo *background,
cristy0740a982011-10-13 15:01:01 +00001993% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001994%
1995% A description of each parameter follows:
1996%
1997% o image: the image.
1998%
1999% o width: the image width.
2000%
2001% o height: the image height.
2002%
2003% o background: the image color.
2004%
cristy0740a982011-10-13 15:01:01 +00002005% o exception: return any errors or warnings in this structure.
2006%
cristy3ed852e2009-09-05 21:47:34 +00002007*/
2008MagickExport Image *NewMagickImage(const ImageInfo *image_info,
cristy0740a982011-10-13 15:01:01 +00002009 const size_t width,const size_t height,const PixelInfo *background,
2010 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002011{
2012 CacheView
2013 *image_view;
2014
cristy3ed852e2009-09-05 21:47:34 +00002015 Image
2016 *image;
2017
cristy3ed852e2009-09-05 21:47:34 +00002018 MagickBooleanType
2019 status;
2020
cristya905c052011-09-17 22:37:55 +00002021 ssize_t
2022 y;
2023
cristy3ed852e2009-09-05 21:47:34 +00002024 assert(image_info != (const ImageInfo *) NULL);
2025 if (image_info->debug != MagickFalse)
2026 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002027 assert(image_info->signature == MagickCoreSignature);
cristy4c08aed2011-07-01 19:47:50 +00002028 assert(background != (const PixelInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00002029 image=AcquireImage(image_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00002030 image->columns=width;
2031 image->rows=height;
2032 image->colorspace=background->colorspace;
cristy8a46d822012-08-28 23:32:39 +00002033 image->alpha_trait=background->alpha_trait;
cristy3ed852e2009-09-05 21:47:34 +00002034 image->fuzz=background->fuzz;
2035 image->depth=background->depth;
2036 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002037 image_view=AcquireAuthenticCacheView(image,exception);
cristy48974b92009-12-19 02:36:06 +00002038#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00002039 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00002040 magick_threads(image,image,image->rows,1)
cristy48974b92009-12-19 02:36:06 +00002041#endif
cristybb503372010-05-27 20:51:26 +00002042 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002043 {
cristy4c08aed2011-07-01 19:47:50 +00002044 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002045 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002046
cristycb6d09b2010-06-19 01:59:36 +00002047 register ssize_t
2048 x;
2049
cristy48974b92009-12-19 02:36:06 +00002050 if (status == MagickFalse)
2051 continue;
cristy3ed852e2009-09-05 21:47:34 +00002052 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002053 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002054 {
2055 status=MagickFalse;
2056 continue;
2057 }
cristybb503372010-05-27 20:51:26 +00002058 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00002059 {
cristy11a06d32015-01-04 12:03:27 +00002060 SetPixelViaPixelInfo(image,background,q);
cristyed231572011-07-14 02:18:59 +00002061 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00002062 }
2063 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2064 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002065 }
2066 image_view=DestroyCacheView(image_view);
2067 if (status == MagickFalse)
2068 image=DestroyImage(image);
2069 return(image);
2070}
2071
2072/*
2073%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2074% %
2075% %
2076% %
2077% R e f e r e n c e I m a g e %
2078% %
2079% %
2080% %
2081%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2082%
2083% ReferenceImage() increments the reference count associated with an image
2084% returning a pointer to the image.
2085%
2086% The format of the ReferenceImage method is:
2087%
2088% Image *ReferenceImage(Image *image)
2089%
2090% A description of each parameter follows:
2091%
2092% o image: the image.
2093%
2094*/
2095MagickExport Image *ReferenceImage(Image *image)
2096{
2097 assert(image != (Image *) NULL);
2098 if (image->debug != MagickFalse)
2099 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002100 assert(image->signature == MagickCoreSignature);
cristyf84a1932010-01-03 18:00:18 +00002101 LockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002102 image->reference_count++;
cristyf84a1932010-01-03 18:00:18 +00002103 UnlockSemaphoreInfo(image->semaphore);
cristy3ed852e2009-09-05 21:47:34 +00002104 return(image);
2105}
2106
2107/*
2108%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2109% %
2110% %
2111% %
2112% R e s e t I m a g e P a g e %
2113% %
2114% %
2115% %
2116%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2117%
2118% ResetImagePage() resets the image page canvas and position.
2119%
2120% The format of the ResetImagePage method is:
2121%
2122% MagickBooleanType ResetImagePage(Image *image,const char *page)
2123%
2124% A description of each parameter follows:
2125%
2126% o image: the image.
2127%
2128% o page: the relative page specification.
2129%
2130*/
2131MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page)
2132{
2133 MagickStatusType
2134 flags;
2135
2136 RectangleInfo
2137 geometry;
2138
2139 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002140 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002141 if (image->debug != MagickFalse)
2142 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
2143 flags=ParseAbsoluteGeometry(page,&geometry);
2144 if ((flags & WidthValue) != 0)
2145 {
2146 if ((flags & HeightValue) == 0)
2147 geometry.height=geometry.width;
2148 image->page.width=geometry.width;
2149 image->page.height=geometry.height;
2150 }
2151 if ((flags & AspectValue) != 0)
2152 {
2153 if ((flags & XValue) != 0)
2154 image->page.x+=geometry.x;
2155 if ((flags & YValue) != 0)
2156 image->page.y+=geometry.y;
2157 }
2158 else
2159 {
2160 if ((flags & XValue) != 0)
2161 {
2162 image->page.x=geometry.x;
2163 if ((image->page.width == 0) && (geometry.x > 0))
2164 image->page.width=image->columns+geometry.x;
2165 }
2166 if ((flags & YValue) != 0)
2167 {
2168 image->page.y=geometry.y;
2169 if ((image->page.height == 0) && (geometry.y > 0))
2170 image->page.height=image->rows+geometry.y;
2171 }
2172 }
2173 return(MagickTrue);
2174}
2175
2176/*
2177%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2178% %
2179% %
2180% %
cristy3ed852e2009-09-05 21:47:34 +00002181% S e t I m a g e B a c k g r o u n d C o l o r %
2182% %
2183% %
2184% %
2185%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2186%
2187% SetImageBackgroundColor() initializes the image pixels to the image
2188% background color. The background color is defined by the background_color
2189% member of the image structure.
2190%
2191% The format of the SetImage method is:
2192%
cristyea1a8aa2011-10-20 13:24:06 +00002193% MagickBooleanType SetImageBackgroundColor(Image *image,
2194% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002195%
2196% A description of each parameter follows:
2197%
2198% o image: the image.
2199%
cristyea1a8aa2011-10-20 13:24:06 +00002200% o exception: return any errors or warnings in this structure.
2201%
cristy3ed852e2009-09-05 21:47:34 +00002202*/
cristyea1a8aa2011-10-20 13:24:06 +00002203MagickExport MagickBooleanType SetImageBackgroundColor(Image *image,
2204 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002205{
2206 CacheView
2207 *image_view;
2208
cristy3ed852e2009-09-05 21:47:34 +00002209 MagickBooleanType
2210 status;
2211
dirkdc896c12014-10-15 16:28:15 +00002212 PixelInfo
2213 background;
2214
cristycb6d09b2010-06-19 01:59:36 +00002215 ssize_t
2216 y;
2217
cristy3ed852e2009-09-05 21:47:34 +00002218 assert(image != (Image *) NULL);
2219 if (image->debug != MagickFalse)
2220 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002221 assert(image->signature == MagickCoreSignature);
cristy574cc262011-08-05 01:23:58 +00002222 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002223 return(MagickFalse);
dirkbfdd5bc2014-11-04 19:47:44 +00002224 ConformPixelInfo(image,&image->background_color,&background,exception);
cristy3ed852e2009-09-05 21:47:34 +00002225 /*
2226 Set image background color.
2227 */
2228 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002229 image_view=AcquireAuthenticCacheView(image,exception);
cristybb503372010-05-27 20:51:26 +00002230 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00002231 {
cristy4c08aed2011-07-01 19:47:50 +00002232 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00002233 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002234
cristycb6d09b2010-06-19 01:59:36 +00002235 register ssize_t
2236 x;
2237
cristy3ed852e2009-09-05 21:47:34 +00002238 if (status == MagickFalse)
2239 continue;
2240 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002241 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00002242 {
2243 status=MagickFalse;
2244 continue;
2245 }
cristybb503372010-05-27 20:51:26 +00002246 for (x=0; x < (ssize_t) image->columns; x++)
cristy4c08aed2011-07-01 19:47:50 +00002247 {
cristy11a06d32015-01-04 12:03:27 +00002248 SetPixelViaPixelInfo(image,&background,q);
cristyed231572011-07-14 02:18:59 +00002249 q+=GetPixelChannels(image);
cristy4c08aed2011-07-01 19:47:50 +00002250 }
cristy3ed852e2009-09-05 21:47:34 +00002251 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2252 status=MagickFalse;
2253 }
2254 image_view=DestroyCacheView(image_view);
2255 return(status);
2256}
2257
2258/*
2259%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2260% %
2261% %
2262% %
cristycf1296e2012-08-26 23:40:49 +00002263% S e t I m a g e C h a n n e l M a s k %
2264% %
2265% %
2266% %
2267%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2268%
2269% SetImageChannelMask() sets the image channel mask from the specified channel
2270% mask.
2271%
2272% The format of the SetImageChannelMask method is:
2273%
2274% ChannelType SetImageChannelMask(Image *image,
2275% const ChannelType channel_mask)
2276%
2277% A description of each parameter follows:
2278%
2279% o image: the image.
2280%
2281% o channel_mask: the channel mask.
2282%
2283*/
2284MagickExport ChannelType SetImageChannelMask(Image *image,
2285 const ChannelType channel_mask)
2286{
cristybcd59342015-06-07 14:07:19 +00002287 return(SetPixelChannelMask(image,channel_mask));
cristycf1296e2012-08-26 23:40:49 +00002288}
2289
2290/*
2291%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2292% %
2293% %
2294% %
cristya5b77cb2010-05-07 19:34:48 +00002295% S e t I m a g e C o l o r %
2296% %
2297% %
2298% %
2299%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2300%
2301% SetImageColor() set the entire image canvas to the specified color.
2302%
2303% The format of the SetImageColor method is:
2304%
cristye941a752011-10-15 01:52:48 +00002305% MagickBooleanType SetImageColor(Image *image,const PixelInfo *color,
2306% ExeptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002307%
2308% A description of each parameter follows:
2309%
2310% o image: the image.
2311%
2312% o background: the image color.
2313%
cristye941a752011-10-15 01:52:48 +00002314% o exception: return any errors or warnings in this structure.
2315%
cristya5b77cb2010-05-07 19:34:48 +00002316*/
2317MagickExport MagickBooleanType SetImageColor(Image *image,
cristye941a752011-10-15 01:52:48 +00002318 const PixelInfo *color,ExceptionInfo *exception)
cristya5b77cb2010-05-07 19:34:48 +00002319{
2320 CacheView
2321 *image_view;
2322
cristya5b77cb2010-05-07 19:34:48 +00002323 MagickBooleanType
2324 status;
2325
cristycb6d09b2010-06-19 01:59:36 +00002326 ssize_t
2327 y;
2328
cristya5b77cb2010-05-07 19:34:48 +00002329 assert(image != (Image *) NULL);
2330 if (image->debug != MagickFalse)
2331 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002332 assert(image->signature == MagickCoreSignature);
cristy4c08aed2011-07-01 19:47:50 +00002333 assert(color != (const PixelInfo *) NULL);
cristya5b77cb2010-05-07 19:34:48 +00002334 image->colorspace=color->colorspace;
cristy8a46d822012-08-28 23:32:39 +00002335 image->alpha_trait=color->alpha_trait;
cristya5b77cb2010-05-07 19:34:48 +00002336 image->fuzz=color->fuzz;
2337 image->depth=color->depth;
2338 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002339 image_view=AcquireAuthenticCacheView(image,exception);
cristya5b77cb2010-05-07 19:34:48 +00002340#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00002341 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00002342 magick_threads(image,image,image->rows,1)
cristya5b77cb2010-05-07 19:34:48 +00002343#endif
cristybb503372010-05-27 20:51:26 +00002344 for (y=0; y < (ssize_t) image->rows; y++)
cristya5b77cb2010-05-07 19:34:48 +00002345 {
cristy4c08aed2011-07-01 19:47:50 +00002346 register Quantum
cristya5b77cb2010-05-07 19:34:48 +00002347 *restrict q;
2348
cristycb6d09b2010-06-19 01:59:36 +00002349 register ssize_t
2350 x;
2351
cristya5b77cb2010-05-07 19:34:48 +00002352 if (status == MagickFalse)
2353 continue;
2354 q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00002355 if (q == (Quantum *) NULL)
cristya5b77cb2010-05-07 19:34:48 +00002356 {
2357 status=MagickFalse;
2358 continue;
2359 }
cristybb503372010-05-27 20:51:26 +00002360 for (x=0; x < (ssize_t) image->columns; x++)
cristya5b77cb2010-05-07 19:34:48 +00002361 {
cristy11a06d32015-01-04 12:03:27 +00002362 SetPixelViaPixelInfo(image,color,q);
cristyed231572011-07-14 02:18:59 +00002363 q+=GetPixelChannels(image);
cristya5b77cb2010-05-07 19:34:48 +00002364 }
2365 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2366 status=MagickFalse;
2367 }
2368 image_view=DestroyCacheView(image_view);
2369 return(status);
2370}
2371
2372/*
2373%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2374% %
2375% %
2376% %
cristy3ed852e2009-09-05 21:47:34 +00002377% S e t I m a g e S t o r a g e C l a s s %
2378% %
2379% %
2380% %
2381%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2382%
2383% SetImageStorageClass() sets the image class: DirectClass for true color
2384% images or PseudoClass for colormapped images.
2385%
2386% The format of the SetImageStorageClass method is:
2387%
2388% MagickBooleanType SetImageStorageClass(Image *image,
cristy63240882011-08-05 19:05:27 +00002389% const ClassType storage_class,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002390%
2391% A description of each parameter follows:
2392%
2393% o image: the image.
2394%
2395% o storage_class: The image class.
2396%
cristy574cc262011-08-05 01:23:58 +00002397% o exception: return any errors or warnings in this structure.
2398%
cristy3ed852e2009-09-05 21:47:34 +00002399*/
2400MagickExport MagickBooleanType SetImageStorageClass(Image *image,
cristy574cc262011-08-05 01:23:58 +00002401 const ClassType storage_class,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002402{
cristy3ed852e2009-09-05 21:47:34 +00002403 image->storage_class=storage_class;
cristy6e437132011-08-12 13:02:19 +00002404 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002405}
2406
2407/*
2408%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2409% %
2410% %
2411% %
cristy3ed852e2009-09-05 21:47:34 +00002412% S e t I m a g e E x t e n t %
2413% %
2414% %
2415% %
2416%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2417%
2418% SetImageExtent() sets the image size (i.e. columns & rows).
2419%
2420% The format of the SetImageExtent method is:
2421%
cristy08429172011-07-14 17:18:16 +00002422% MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002423% const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002424%
2425% A description of each parameter follows:
2426%
2427% o image: the image.
2428%
2429% o columns: The image width in pixels.
2430%
2431% o rows: The image height in pixels.
2432%
cristy63240882011-08-05 19:05:27 +00002433% o exception: return any errors or warnings in this structure.
2434%
cristy3ed852e2009-09-05 21:47:34 +00002435*/
cristy08429172011-07-14 17:18:16 +00002436MagickExport MagickBooleanType SetImageExtent(Image *image,const size_t columns,
cristy63240882011-08-05 19:05:27 +00002437 const size_t rows,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002438{
cristy537e2722010-09-21 15:30:59 +00002439 if ((columns == 0) || (rows == 0))
2440 return(MagickFalse);
2441 image->columns=columns;
2442 image->rows=rows;
cristyda950bb2015-07-18 23:17:28 +00002443 if (image->depth > (8*sizeof(MagickSizeType)))
2444 ThrowBinaryException(ImageError,"ImageDepthNotSupported",image->filename);
cristy6e437132011-08-12 13:02:19 +00002445 return(SyncImagePixelCache(image,exception));
cristy3ed852e2009-09-05 21:47:34 +00002446}
2447
2448/*
2449%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2450% %
2451% %
2452% %
2453+ S e t I m a g e I n f o %
2454% %
2455% %
2456% %
2457%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2458%
anthonye5b39652012-04-21 05:37:29 +00002459% SetImageInfo() initializes the 'magick' field of the ImageInfo structure.
cristy3ed852e2009-09-05 21:47:34 +00002460% It is set to a type of image format based on the prefix or suffix of the
anthonye5b39652012-04-21 05:37:29 +00002461% filename. For example, 'ps:image' returns PS indicating a Postscript image.
2462% JPEG is returned for this filename: 'image.jpg'. The filename prefix has
cristy3ed852e2009-09-05 21:47:34 +00002463% precendence over the suffix. Use an optional index enclosed in brackets
2464% after a file name to specify a desired scene of a multi-resolution image
2465% format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value
2466% indicates success.
2467%
2468% The format of the SetImageInfo method is:
2469%
2470% MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002471% const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002472%
2473% A description of each parameter follows:
2474%
cristyd965a422010-03-03 17:47:35 +00002475% o image_info: the image info.
cristy3ed852e2009-09-05 21:47:34 +00002476%
cristyd965a422010-03-03 17:47:35 +00002477% o frames: the number of images you intend to write.
cristy3ed852e2009-09-05 21:47:34 +00002478%
2479% o exception: return any errors or warnings in this structure.
2480%
2481*/
2482MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info,
cristyd965a422010-03-03 17:47:35 +00002483 const unsigned int frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002484{
2485 char
dirk8f681612015-04-16 21:05:08 +00002486 component[MagickPathExtent],
cristy151b66d2015-04-15 10:50:31 +00002487 magic[MagickPathExtent],
dirk8f681612015-04-16 21:05:08 +00002488 *q;
cristy3ed852e2009-09-05 21:47:34 +00002489
2490 const MagicInfo
2491 *magic_info;
2492
2493 const MagickInfo
2494 *magick_info;
2495
2496 ExceptionInfo
2497 *sans_exception;
2498
2499 Image
2500 *image;
2501
2502 MagickBooleanType
2503 status;
2504
2505 register const char
2506 *p;
2507
2508 ssize_t
2509 count;
2510
cristy3ed852e2009-09-05 21:47:34 +00002511 /*
2512 Look for 'image.format' in filename.
2513 */
2514 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002515 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002516 if (image_info->debug != MagickFalse)
2517 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2518 image_info->filename);
dirk8f681612015-04-16 21:05:08 +00002519 *component='\0';
2520 GetPathComponent(image_info->filename,SubimagePath,component);
2521 if (*component != '\0')
cristy3ed852e2009-09-05 21:47:34 +00002522 {
cristy4f96a1d2014-01-04 15:31:36 +00002523 /*
2524 Look for scene specification (e.g. img0001.pcd[4]).
2525 */
dirk8f681612015-04-16 21:05:08 +00002526 if (IsSceneGeometry(component,MagickFalse) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00002527 {
dirk8f681612015-04-16 21:05:08 +00002528 if (IsGeometry(component) != MagickFalse)
2529 (void) CloneString(&image_info->extract,component);
cristy4f96a1d2014-01-04 15:31:36 +00002530 }
2531 else
2532 {
2533 size_t
2534 first,
2535 last;
cristy3ed852e2009-09-05 21:47:34 +00002536
dirk8f681612015-04-16 21:05:08 +00002537 (void) CloneString(&image_info->scenes,component);
cristy4f96a1d2014-01-04 15:31:36 +00002538 image_info->scene=StringToUnsignedLong(image_info->scenes);
2539 image_info->number_scenes=image_info->scene;
2540 p=image_info->scenes;
2541 for (q=(char *) image_info->scenes; *q != '\0'; p++)
2542 {
2543 while ((isspace((int) ((unsigned char) *p)) != 0) || (*p == ','))
2544 p++;
2545 first=(size_t) strtol(p,&q,10);
2546 last=first;
2547 while (isspace((int) ((unsigned char) *q)) != 0)
2548 q++;
2549 if (*q == '-')
2550 last=(size_t) strtol(q+1,&q,10);
2551 if (first > last)
2552 Swap(first,last);
2553 if (first < image_info->scene)
2554 image_info->scene=first;
2555 if (last > image_info->number_scenes)
2556 image_info->number_scenes=last;
2557 p=q;
2558 }
2559 image_info->number_scenes-=image_info->scene-1;
cristy3ed852e2009-09-05 21:47:34 +00002560 }
2561 }
dirk8f681612015-04-16 21:05:08 +00002562 *component='\0';
cristy6f7cebf2014-12-27 12:10:39 +00002563 if (*image_info->magick == '\0')
dirk8f681612015-04-16 21:05:08 +00002564 GetPathComponent(image_info->filename,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002565#if defined(MAGICKCORE_ZLIB_DELEGATE)
dirk8f681612015-04-16 21:05:08 +00002566 if (*component != '\0')
2567 if ((LocaleCompare(component,"gz") == 0) ||
2568 (LocaleCompare(component,"Z") == 0) ||
2569 (LocaleCompare(component,"svgz") == 0) ||
2570 (LocaleCompare(component,"wmz") == 0))
cristy3ed852e2009-09-05 21:47:34 +00002571 {
2572 char
cristy151b66d2015-04-15 10:50:31 +00002573 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002574
cristy151b66d2015-04-15 10:50:31 +00002575 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
dirk8f681612015-04-16 21:05:08 +00002576 path[strlen(path)-strlen(component)-1]='\0';
2577 GetPathComponent(path,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002578 }
2579#endif
2580#if defined(MAGICKCORE_BZLIB_DELEGATE)
dirk8f681612015-04-16 21:05:08 +00002581 if (*component != '\0')
2582 if (LocaleCompare(component,"bz2") == 0)
cristy3ed852e2009-09-05 21:47:34 +00002583 {
2584 char
cristy151b66d2015-04-15 10:50:31 +00002585 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00002586
cristy151b66d2015-04-15 10:50:31 +00002587 (void) CopyMagickString(path,image_info->filename,MagickPathExtent);
dirk8f681612015-04-16 21:05:08 +00002588 path[strlen(path)-strlen(component)-1]='\0';
2589 GetPathComponent(path,ExtensionPath,component);
cristy3ed852e2009-09-05 21:47:34 +00002590 }
2591#endif
2592 image_info->affirm=MagickFalse;
2593 sans_exception=AcquireExceptionInfo();
dirk8f681612015-04-16 21:05:08 +00002594 if (*component != '\0')
cristy3ed852e2009-09-05 21:47:34 +00002595 {
2596 MagickFormatType
2597 format_type;
2598
cristybb503372010-05-27 20:51:26 +00002599 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002600 i;
2601
2602 static const char
2603 *format_type_formats[] =
2604 {
2605 "AUTOTRACE",
2606 "BROWSE",
2607 "DCRAW",
2608 "EDIT",
2609 "EPHEMERAL",
2610 "LAUNCH",
2611 "MPEG:DECODE",
2612 "MPEG:ENCODE",
2613 "PRINT",
2614 "PS:ALPHA",
2615 "PS:CMYK",
2616 "PS:COLOR",
2617 "PS:GRAY",
2618 "PS:MONO",
2619 "SCAN",
2620 "SHOW",
2621 "WIN",
2622 (char *) NULL
2623 };
2624
2625 /*
2626 User specified image format.
2627 */
dirk8f681612015-04-16 21:05:08 +00002628 (void) CopyMagickString(magic,component,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002629 LocaleUpper(magic);
2630 /*
2631 Look for explicit image formats.
2632 */
2633 format_type=UndefinedFormatType;
dirk80fd8af2015-02-22 00:45:51 +00002634 magick_info=GetMagickInfo(magic,sans_exception);
2635 if ((magick_info != (const MagickInfo *) NULL) &&
2636 (magick_info->format_type != UndefinedFormatType))
2637 format_type=magick_info->format_type;
cristy3ed852e2009-09-05 21:47:34 +00002638 i=0;
cristydd9a2532010-02-20 19:26:46 +00002639 while ((format_type == UndefinedFormatType) &&
cristy3ed852e2009-09-05 21:47:34 +00002640 (format_type_formats[i] != (char *) NULL))
2641 {
2642 if ((*magic == *format_type_formats[i]) &&
2643 (LocaleCompare(magic,format_type_formats[i]) == 0))
2644 format_type=ExplicitFormatType;
2645 i++;
2646 }
cristy3ed852e2009-09-05 21:47:34 +00002647 if (format_type == UndefinedFormatType)
cristy151b66d2015-04-15 10:50:31 +00002648 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002649 else
2650 if (format_type == ExplicitFormatType)
2651 {
2652 image_info->affirm=MagickTrue;
cristy151b66d2015-04-15 10:50:31 +00002653 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002654 }
2655 if (LocaleCompare(magic,"RGB") == 0)
2656 image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */
2657 }
2658 /*
2659 Look for explicit 'format:image' in filename.
2660 */
2661 *magic='\0';
2662 GetPathComponent(image_info->filename,MagickPath,magic);
2663 if (*magic == '\0')
cristy151b66d2015-04-15 10:50:31 +00002664 (void) CopyMagickString(magic,image_info->magick,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002665 else
2666 {
2667 /*
2668 User specified image format.
2669 */
2670 LocaleUpper(magic);
2671 if (IsMagickConflict(magic) == MagickFalse)
2672 {
cristy151b66d2015-04-15 10:50:31 +00002673 (void) CopyMagickString(image_info->magick,magic,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002674 if (LocaleCompare(magic,"EPHEMERAL") != 0)
2675 image_info->affirm=MagickTrue;
2676 else
2677 image_info->temporary=MagickTrue;
2678 }
2679 }
2680 magick_info=GetMagickInfo(magic,sans_exception);
2681 sans_exception=DestroyExceptionInfo(sans_exception);
2682 if ((magick_info == (const MagickInfo *) NULL) ||
2683 (GetMagickEndianSupport(magick_info) == MagickFalse))
2684 image_info->endian=UndefinedEndian;
dirk8f681612015-04-16 21:05:08 +00002685 GetPathComponent(image_info->filename,CanonicalPath,component);
2686 (void) CopyMagickString(image_info->filename,component,MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002687 if ((image_info->adjoin != MagickFalse) && (frames > 1))
cristy3ed852e2009-09-05 21:47:34 +00002688 {
2689 /*
cristyd965a422010-03-03 17:47:35 +00002690 Test for multiple image support (e.g. image%02d.png).
cristy3ed852e2009-09-05 21:47:34 +00002691 */
cristyd965a422010-03-03 17:47:35 +00002692 (void) InterpretImageFilename(image_info,(Image *) NULL,
dirk8f681612015-04-16 21:05:08 +00002693 image_info->filename,(int) image_info->scene,component,exception);
2694 if ((LocaleCompare(component,image_info->filename) != 0) &&
2695 (strchr(component,'%') == (char *) NULL))
cristyd965a422010-03-03 17:47:35 +00002696 image_info->adjoin=MagickFalse;
2697 }
2698 if ((image_info->adjoin != MagickFalse) && (frames > 0))
2699 {
2700 /*
2701 Some image formats do not support multiple frames per file.
2702 */
cristy3ed852e2009-09-05 21:47:34 +00002703 magick_info=GetMagickInfo(magic,exception);
2704 if (magick_info != (const MagickInfo *) NULL)
2705 if (GetMagickAdjoin(magick_info) == MagickFalse)
2706 image_info->adjoin=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00002707 }
2708 if (image_info->affirm != MagickFalse)
2709 return(MagickTrue);
cristyd965a422010-03-03 17:47:35 +00002710 if (frames == 0)
cristy3ed852e2009-09-05 21:47:34 +00002711 {
dirk8f681612015-04-16 21:05:08 +00002712 unsigned char
2713 *magick;
2714
2715 size_t
2716 magick_size;
2717
cristy3ed852e2009-09-05 21:47:34 +00002718 /*
cristyd965a422010-03-03 17:47:35 +00002719 Determine the image format from the first few bytes of the file.
cristy3ed852e2009-09-05 21:47:34 +00002720 */
cristy4f06b882015-04-17 00:16:45 +00002721 magick_size=GetMagicPatternExtent(exception);
dirk8f681612015-04-16 21:05:08 +00002722 if (magick_size == 0)
2723 return(MagickFalse);
cristy9950d572011-10-01 18:22:35 +00002724 image=AcquireImage(image_info,exception);
cristyd965a422010-03-03 17:47:35 +00002725 (void) CopyMagickString(image->filename,image_info->filename,
cristy151b66d2015-04-15 10:50:31 +00002726 MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00002727 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2728 if (status == MagickFalse)
2729 {
2730 image=DestroyImage(image);
2731 return(MagickFalse);
2732 }
cristyd965a422010-03-03 17:47:35 +00002733 if ((IsBlobSeekable(image) == MagickFalse) ||
2734 (IsBlobExempt(image) != MagickFalse))
2735 {
2736 /*
2737 Copy standard input or pipe to temporary file.
2738 */
dirk8f681612015-04-16 21:05:08 +00002739 *component='\0';
2740 status=ImageToFile(image,component,exception);
cristyd965a422010-03-03 17:47:35 +00002741 (void) CloseBlob(image);
2742 if (status == MagickFalse)
2743 {
2744 image=DestroyImage(image);
2745 return(MagickFalse);
2746 }
2747 SetImageInfoFile(image_info,(FILE *) NULL);
dirk8f681612015-04-16 21:05:08 +00002748 (void) CopyMagickString(image->filename,component,MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002749 status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
2750 if (status == MagickFalse)
2751 {
2752 image=DestroyImage(image);
2753 return(MagickFalse);
2754 }
cristyee2f5d62015-07-28 13:19:43 +00002755 (void) CopyMagickString(image_info->filename,component,
2756 MagickPathExtent);
cristyd965a422010-03-03 17:47:35 +00002757 image_info->temporary=MagickTrue;
2758 }
dirk8f681612015-04-16 21:05:08 +00002759 magick=(unsigned char *) AcquireMagickMemory(magick_size);
2760 if (magick == (unsigned char *) NULL)
2761 {
2762 (void) CloseBlob(image);
2763 image=DestroyImage(image);
2764 return(MagickFalse);
2765 }
2766 (void) ResetMagickMemory(magick,0,magick_size);
2767 count=ReadBlob(image,magick_size,magick);
cristyae958042013-01-05 15:48:19 +00002768 (void) SeekBlob(image,-((MagickOffsetType) count),SEEK_CUR);
cristyd965a422010-03-03 17:47:35 +00002769 (void) CloseBlob(image);
2770 image=DestroyImage(image);
2771 /*
2772 Check magic.xml configuration file.
2773 */
2774 sans_exception=AcquireExceptionInfo();
2775 magic_info=GetMagicInfo(magick,(size_t) count,sans_exception);
dirk8f681612015-04-16 21:05:08 +00002776 magick=(unsigned char *) RelinquishMagickMemory(magick);
cristyd965a422010-03-03 17:47:35 +00002777 if ((magic_info != (const MagicInfo *) NULL) &&
2778 (GetMagicName(magic_info) != (char *) NULL))
2779 {
dirkca89a9b2015-02-22 01:19:21 +00002780 /*
2781 Try to use magick_info that was determined earlier by the extension
2782 */
2783 if ((magick_info != (const MagickInfo *) NULL) &&
2784 (GetMagickUseExtension(magick_info) != MagickFalse) &&
2785 (LocaleCompare(magick_info->module,GetMagicName(
2786 magic_info)) == 0))
2787 (void) CopyMagickString(image_info->magick,magick_info->name,
cristy151b66d2015-04-15 10:50:31 +00002788 MagickPathExtent);
dirkca89a9b2015-02-22 01:19:21 +00002789 else
2790 {
2791 (void) CopyMagickString(image_info->magick,GetMagicName(
cristy151b66d2015-04-15 10:50:31 +00002792 magic_info),MagickPathExtent);
dirkca89a9b2015-02-22 01:19:21 +00002793 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2794 }
cristyd965a422010-03-03 17:47:35 +00002795 if ((magick_info == (const MagickInfo *) NULL) ||
2796 (GetMagickEndianSupport(magick_info) == MagickFalse))
2797 image_info->endian=UndefinedEndian;
2798 sans_exception=DestroyExceptionInfo(sans_exception);
2799 return(MagickTrue);
2800 }
cristy3ed852e2009-09-05 21:47:34 +00002801 magick_info=GetMagickInfo(image_info->magick,sans_exception);
2802 if ((magick_info == (const MagickInfo *) NULL) ||
2803 (GetMagickEndianSupport(magick_info) == MagickFalse))
2804 image_info->endian=UndefinedEndian;
2805 sans_exception=DestroyExceptionInfo(sans_exception);
cristy3ed852e2009-09-05 21:47:34 +00002806 }
cristy3ed852e2009-09-05 21:47:34 +00002807 return(MagickTrue);
2808}
2809
2810/*
2811%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2812% %
2813% %
2814% %
2815% S e t I m a g e I n f o B l o b %
2816% %
2817% %
2818% %
2819%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2820%
2821% SetImageInfoBlob() sets the image info blob member.
2822%
2823% The format of the SetImageInfoBlob method is:
2824%
2825% void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2826% const size_t length)
2827%
2828% A description of each parameter follows:
2829%
2830% o image_info: the image info.
2831%
2832% o blob: the blob.
2833%
2834% o length: the blob length.
2835%
2836*/
2837MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob,
2838 const size_t length)
2839{
2840 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002841 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002842 if (image_info->debug != MagickFalse)
2843 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2844 image_info->filename);
2845 image_info->blob=(void *) blob;
2846 image_info->length=length;
2847}
2848
2849/*
2850%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2851% %
2852% %
2853% %
2854% S e t I m a g e I n f o F i l e %
2855% %
2856% %
2857% %
2858%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2859%
2860% SetImageInfoFile() sets the image info file member.
2861%
2862% The format of the SetImageInfoFile method is:
2863%
2864% void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2865%
2866% A description of each parameter follows:
2867%
2868% o image_info: the image info.
2869%
2870% o file: the file.
2871%
2872*/
2873MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file)
2874{
2875 assert(image_info != (ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00002876 assert(image_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00002877 if (image_info->debug != MagickFalse)
2878 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
2879 image_info->filename);
2880 image_info->file=file;
2881}
2882
2883/*
2884%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2885% %
2886% %
2887% %
2888% S e t I m a g e M a s k %
2889% %
2890% %
2891% %
2892%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2893%
2894% SetImageMask() associates a mask with the image. The mask must be the same
2895% dimensions as the image.
2896%
2897% The format of the SetImageMask method is:
2898%
cristyacd0d4c2015-07-25 16:12:33 +00002899% MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2900% const Image *mask,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002901%
2902% A description of each parameter follows:
2903%
2904% o image: the image.
2905%
cristyacd0d4c2015-07-25 16:12:33 +00002906% o type: the mask type, ReadPixelMask or WritePixelMask.
2907%
cristy3ed852e2009-09-05 21:47:34 +00002908% o mask: the image mask.
2909%
cristy018f07f2011-09-04 21:15:19 +00002910% o exception: return any errors or warnings in this structure.
2911%
cristy3ed852e2009-09-05 21:47:34 +00002912*/
cristyacd0d4c2015-07-25 16:12:33 +00002913MagickExport MagickBooleanType SetImageMask(Image *image,const PixelMask type,
2914 const Image *mask,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002915{
cristy10a6c612012-01-29 21:41:05 +00002916 CacheView
2917 *mask_view,
2918 *image_view;
2919
2920 MagickBooleanType
2921 status;
2922
2923 ssize_t
2924 y;
2925
2926 /*
2927 Set image mask.
2928 */
cristy3ed852e2009-09-05 21:47:34 +00002929 assert(image != (Image *) NULL);
2930 if (image->debug != MagickFalse)
2931 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00002932 assert(image->signature == MagickCoreSignature);
cristy10a6c612012-01-29 21:41:05 +00002933 if (mask == (const Image *) NULL)
2934 {
cristyacd0d4c2015-07-25 16:12:33 +00002935 switch (type)
2936 {
2937 case WritePixelMask: image->write_mask=MagickFalse; break;
2938 default: image->read_mask=MagickFalse; break;
2939 }
cristyd5be1f12013-03-18 23:55:01 +00002940 return(SyncImagePixelCache(image,exception));
cristy10a6c612012-01-29 21:41:05 +00002941 }
cristyacd0d4c2015-07-25 16:12:33 +00002942 switch (type)
2943 {
2944 case WritePixelMask: image->write_mask=MagickTrue; break;
2945 default: image->read_mask=MagickTrue; break;
2946 }
cristyd5be1f12013-03-18 23:55:01 +00002947 if (SyncImagePixelCache(image,exception) == MagickFalse)
2948 return(MagickFalse);
2949 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00002950 mask_view=AcquireVirtualCacheView(mask,exception);
2951 image_view=AcquireAuthenticCacheView(image,exception);
cristyd5be1f12013-03-18 23:55:01 +00002952#if defined(MAGICKCORE_OPENMP_SUPPORT)
2953 #pragma omp parallel for schedule(static,4) shared(status) \
2954 magick_threads(mask,image,1,1)
2955#endif
cristy10a6c612012-01-29 21:41:05 +00002956 for (y=0; y < (ssize_t) image->rows; y++)
2957 {
2958 register const Quantum
2959 *restrict p;
2960
2961 register Quantum
2962 *restrict q;
2963
2964 register ssize_t
2965 x;
2966
2967 if (status == MagickFalse)
2968 continue;
2969 p=GetCacheViewVirtualPixels(mask_view,0,y,mask->columns,1,exception);
2970 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
2971 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
2972 {
2973 status=MagickFalse;
2974 continue;
2975 }
2976 for (x=0; x < (ssize_t) image->columns; x++)
2977 {
cristyacd0d4c2015-07-25 16:12:33 +00002978 switch (type)
2979 {
2980 case WritePixelMask:
2981 {
2982 SetPixelWriteMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
2983 break;
2984 }
2985 default:
2986 {
2987 SetPixelReadMask(image,ClampToQuantum(GetPixelIntensity(mask,p)),q);
2988 break;
2989 }
2990 }
cristy10a6c612012-01-29 21:41:05 +00002991 p+=GetPixelChannels(mask);
2992 q+=GetPixelChannels(image);
2993 }
2994 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
2995 status=MagickFalse;
2996 }
2997 mask_view=DestroyCacheView(mask_view);
2998 image_view=DestroyCacheView(image_view);
2999 return(status);
cristy3ed852e2009-09-05 21:47:34 +00003000}
3001
3002/*
3003%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3004% %
3005% %
3006% %
cristyb6a294d2011-10-03 00:55:17 +00003007% S e t I m a g e A l p h a %
cristy3ed852e2009-09-05 21:47:34 +00003008% %
3009% %
3010% %
3011%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3012%
cristye941a752011-10-15 01:52:48 +00003013% SetImageAlpha() sets the alpha levels of the image.
cristy3ed852e2009-09-05 21:47:34 +00003014%
cristyb6a294d2011-10-03 00:55:17 +00003015% The format of the SetImageAlpha method is:
cristy3ed852e2009-09-05 21:47:34 +00003016%
cristye941a752011-10-15 01:52:48 +00003017% MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3018% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003019%
3020% A description of each parameter follows:
3021%
3022% o image: the image.
3023%
cristyb6a294d2011-10-03 00:55:17 +00003024% o Alpha: the level of transparency: 0 is fully opaque and QuantumRange is
cristy3ed852e2009-09-05 21:47:34 +00003025% fully transparent.
3026%
3027*/
cristye941a752011-10-15 01:52:48 +00003028MagickExport MagickBooleanType SetImageAlpha(Image *image,const Quantum alpha,
3029 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003030{
3031 CacheView
3032 *image_view;
3033
cristy3ed852e2009-09-05 21:47:34 +00003034 MagickBooleanType
3035 status;
3036
cristycb6d09b2010-06-19 01:59:36 +00003037 ssize_t
3038 y;
3039
cristy3ed852e2009-09-05 21:47:34 +00003040 assert(image != (Image *) NULL);
3041 if (image->debug != MagickFalse)
3042 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00003043 assert(image->signature == MagickCoreSignature);
cristy8a46d822012-08-28 23:32:39 +00003044 image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00003045 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00003046 image_view=AcquireAuthenticCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003047#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003048 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00003049 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003050#endif
cristybb503372010-05-27 20:51:26 +00003051 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003052 {
cristy4c08aed2011-07-01 19:47:50 +00003053 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003054 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003055
cristycb6d09b2010-06-19 01:59:36 +00003056 register ssize_t
3057 x;
3058
cristy3ed852e2009-09-05 21:47:34 +00003059 if (status == MagickFalse)
3060 continue;
3061 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00003062 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003063 {
3064 status=MagickFalse;
3065 continue;
3066 }
cristybb503372010-05-27 20:51:26 +00003067 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003068 {
dirk8ce24462015-11-15 16:39:28 +01003069 if (GetPixelReadMask(image,q) != 0)
3070 SetPixelAlpha(image,alpha,q);
cristyed231572011-07-14 02:18:59 +00003071 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00003072 }
3073 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3074 status=MagickFalse;
3075 }
3076 image_view=DestroyCacheView(image_view);
3077 return(status);
3078}
3079
3080/*
3081%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3082% %
3083% %
3084% %
cristy3ed852e2009-09-05 21:47:34 +00003085% 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 %
3086% %
3087% %
3088% %
3089%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3090%
3091% SetImageVirtualPixelMethod() sets the "virtual pixels" method for the
3092% image and returns the previous setting. A virtual pixel is any pixel access
3093% that is outside the boundaries of the image cache.
3094%
3095% The format of the SetImageVirtualPixelMethod() method is:
3096%
cristy387430f2012-02-07 13:09:46 +00003097% VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3098% const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003099%
3100% A description of each parameter follows:
3101%
3102% o image: the image.
3103%
3104% o virtual_pixel_method: choose the type of virtual pixel.
3105%
cristy387430f2012-02-07 13:09:46 +00003106% o exception: return any errors or warnings in this structure.
3107%
cristy3ed852e2009-09-05 21:47:34 +00003108*/
cristy387430f2012-02-07 13:09:46 +00003109MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(Image *image,
3110 const VirtualPixelMethod virtual_pixel_method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003111{
3112 assert(image != (const Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003113 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00003114 if (image->debug != MagickFalse)
3115 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy387430f2012-02-07 13:09:46 +00003116 return(SetPixelCacheVirtualMethod(image,virtual_pixel_method,exception));
cristy3ed852e2009-09-05 21:47:34 +00003117}
3118
3119/*
3120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3121% %
3122% %
3123% %
cristy4285d782011-02-09 20:12:28 +00003124% S m u s h I m a g e s %
3125% %
3126% %
3127% %
3128%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3129%
3130% SmushImages() takes all images from the current image pointer to the end
3131% of the image list and smushes them to each other top-to-bottom if the
3132% stack parameter is true, otherwise left-to-right.
3133%
3134% The current gravity setting now effects how the image is justified in the
3135% final image.
3136%
3137% The format of the SmushImages method is:
3138%
cristy4ca38e22011-02-10 02:57:49 +00003139% Image *SmushImages(const Image *images,const MagickBooleanType stack,
cristy4285d782011-02-09 20:12:28 +00003140% ExceptionInfo *exception)
3141%
3142% A description of each parameter follows:
3143%
cristy4ca38e22011-02-10 02:57:49 +00003144% o images: the image sequence.
cristy4285d782011-02-09 20:12:28 +00003145%
3146% o stack: A value other than 0 stacks the images top-to-bottom.
3147%
3148% o offset: minimum distance in pixels between images.
3149%
3150% o exception: return any errors or warnings in this structure.
3151%
3152*/
cristy4ca38e22011-02-10 02:57:49 +00003153
cristy7c6dc152011-02-11 14:10:55 +00003154static ssize_t SmushXGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003155 const ssize_t offset,ExceptionInfo *exception)
cristy4ca38e22011-02-10 02:57:49 +00003156{
cristy4d727152011-02-10 19:57:21 +00003157 CacheView
3158 *left_view,
3159 *right_view;
3160
3161 const Image
3162 *left_image,
3163 *right_image;
3164
cristy4d727152011-02-10 19:57:21 +00003165 RectangleInfo
3166 left_geometry,
3167 right_geometry;
3168
cristy4c08aed2011-07-01 19:47:50 +00003169 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003170 *p;
3171
cristy4d727152011-02-10 19:57:21 +00003172 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003173 i,
cristy4d727152011-02-10 19:57:21 +00003174 y;
3175
cristy7c6dc152011-02-11 14:10:55 +00003176 size_t
3177 gap;
3178
cristy4d727152011-02-10 19:57:21 +00003179 ssize_t
cristy4d727152011-02-10 19:57:21 +00003180 x;
3181
3182 if (images->previous == (Image *) NULL)
3183 return(0);
3184 right_image=images;
3185 SetGeometry(smush_image,&right_geometry);
3186 GravityAdjustGeometry(right_image->columns,right_image->rows,
3187 right_image->gravity,&right_geometry);
3188 left_image=images->previous;
3189 SetGeometry(smush_image,&left_geometry);
3190 GravityAdjustGeometry(left_image->columns,left_image->rows,
3191 left_image->gravity,&left_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003192 gap=right_image->columns;
cristy46ff2672012-12-14 15:32:26 +00003193 left_view=AcquireVirtualCacheView(left_image,exception);
3194 right_view=AcquireVirtualCacheView(right_image,exception);
cristy4d727152011-02-10 19:57:21 +00003195 for (y=0; y < (ssize_t) smush_image->rows; y++)
3196 {
3197 for (x=(ssize_t) left_image->columns-1; x > 0; x--)
3198 {
cristydab7e912011-02-11 18:19:24 +00003199 p=GetCacheViewVirtualPixels(left_view,x,left_geometry.y+y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003200 if ((p == (const Quantum *) NULL) ||
3201 (GetPixelAlpha(left_image,p) != TransparentAlpha) ||
cristy7c6dc152011-02-11 14:10:55 +00003202 ((left_image->columns-x-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003203 break;
3204 }
cristy4ef6f062011-02-10 20:30:22 +00003205 i=(ssize_t) left_image->columns-x-1;
cristy4d727152011-02-10 19:57:21 +00003206 for (x=0; x < (ssize_t) right_image->columns; x++)
3207 {
cristydab7e912011-02-11 18:19:24 +00003208 p=GetCacheViewVirtualPixels(right_view,x,right_geometry.y+y,1,1,
cristy279d8212011-02-10 20:05:02 +00003209 exception);
cristy4c08aed2011-07-01 19:47:50 +00003210 if ((p == (const Quantum *) NULL) ||
3211 (GetPixelAlpha(right_image,p) != TransparentAlpha) ||
3212 ((x+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003213 break;
3214 }
cristy7c6dc152011-02-11 14:10:55 +00003215 if ((x+i) < (ssize_t) gap)
3216 gap=(size_t) (x+i);
cristy4d727152011-02-10 19:57:21 +00003217 }
3218 right_view=DestroyCacheView(right_view);
3219 left_view=DestroyCacheView(left_view);
cristydab7e912011-02-11 18:19:24 +00003220 if (y < (ssize_t) smush_image->rows)
3221 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003222 return((ssize_t) gap-offset);
cristyad5e6ee2011-02-10 14:26:00 +00003223}
3224
cristy7c6dc152011-02-11 14:10:55 +00003225static ssize_t SmushYGap(const Image *smush_image,const Image *images,
cristy4ef6f062011-02-10 20:30:22 +00003226 const ssize_t offset,ExceptionInfo *exception)
cristyad5e6ee2011-02-10 14:26:00 +00003227{
cristy4d727152011-02-10 19:57:21 +00003228 CacheView
3229 *bottom_view,
3230 *top_view;
3231
3232 const Image
3233 *bottom_image,
3234 *top_image;
3235
cristy4d727152011-02-10 19:57:21 +00003236 RectangleInfo
3237 bottom_geometry,
3238 top_geometry;
3239
cristy4c08aed2011-07-01 19:47:50 +00003240 register const Quantum
cristydab7e912011-02-11 18:19:24 +00003241 *p;
3242
cristy4d727152011-02-10 19:57:21 +00003243 register ssize_t
cristy4ef6f062011-02-10 20:30:22 +00003244 i,
cristy4d727152011-02-10 19:57:21 +00003245 x;
3246
cristy7c6dc152011-02-11 14:10:55 +00003247 size_t
3248 gap;
3249
cristy4d727152011-02-10 19:57:21 +00003250 ssize_t
cristy4d727152011-02-10 19:57:21 +00003251 y;
3252
3253 if (images->previous == (Image *) NULL)
3254 return(0);
3255 bottom_image=images;
3256 SetGeometry(smush_image,&bottom_geometry);
3257 GravityAdjustGeometry(bottom_image->columns,bottom_image->rows,
3258 bottom_image->gravity,&bottom_geometry);
3259 top_image=images->previous;
3260 SetGeometry(smush_image,&top_geometry);
3261 GravityAdjustGeometry(top_image->columns,top_image->rows,top_image->gravity,
3262 &top_geometry);
cristy7c6dc152011-02-11 14:10:55 +00003263 gap=bottom_image->rows;
cristy46ff2672012-12-14 15:32:26 +00003264 top_view=AcquireVirtualCacheView(top_image,exception);
3265 bottom_view=AcquireVirtualCacheView(bottom_image,exception);
cristy4d727152011-02-10 19:57:21 +00003266 for (x=0; x < (ssize_t) smush_image->columns; x++)
3267 {
3268 for (y=(ssize_t) top_image->rows-1; y > 0; y--)
3269 {
cristydab7e912011-02-11 18:19:24 +00003270 p=GetCacheViewVirtualPixels(top_view,top_geometry.x+x,y,1,1,exception);
cristy4c08aed2011-07-01 19:47:50 +00003271 if ((p == (const Quantum *) NULL) ||
3272 (GetPixelAlpha(top_image,p) != TransparentAlpha) ||
3273 ((top_image->rows-y-1) >= gap))
cristy4d727152011-02-10 19:57:21 +00003274 break;
3275 }
cristy4ef6f062011-02-10 20:30:22 +00003276 i=(ssize_t) top_image->rows-y-1;
cristy4d727152011-02-10 19:57:21 +00003277 for (y=0; y < (ssize_t) bottom_image->rows; y++)
3278 {
cristydab7e912011-02-11 18:19:24 +00003279 p=GetCacheViewVirtualPixels(bottom_view,bottom_geometry.x+x,y,1,1,
3280 exception);
cristy4c08aed2011-07-01 19:47:50 +00003281 if ((p == (const Quantum *) NULL) ||
3282 (GetPixelAlpha(bottom_image,p) != TransparentAlpha) ||
3283 ((y+i) >= (ssize_t) gap))
cristy4d727152011-02-10 19:57:21 +00003284 break;
3285 }
cristy7c6dc152011-02-11 14:10:55 +00003286 if ((y+i) < (ssize_t) gap)
3287 gap=(size_t) (y+i);
cristy4d727152011-02-10 19:57:21 +00003288 }
3289 bottom_view=DestroyCacheView(bottom_view);
3290 top_view=DestroyCacheView(top_view);
cristydab7e912011-02-11 18:19:24 +00003291 if (x < (ssize_t) smush_image->columns)
3292 return(offset);
cristy7c6dc152011-02-11 14:10:55 +00003293 return((ssize_t) gap-offset);
cristy4ca38e22011-02-10 02:57:49 +00003294}
3295
3296MagickExport Image *SmushImages(const Image *images,
cristy4285d782011-02-09 20:12:28 +00003297 const MagickBooleanType stack,const ssize_t offset,ExceptionInfo *exception)
3298{
3299#define SmushImageTag "Smush/Image"
3300
cristy4ca38e22011-02-10 02:57:49 +00003301 const Image
3302 *image;
3303
cristy4285d782011-02-09 20:12:28 +00003304 Image
3305 *smush_image;
3306
3307 MagickBooleanType
cristy4285d782011-02-09 20:12:28 +00003308 proceed,
3309 status;
3310
3311 MagickOffsetType
3312 n;
3313
cristy5a5e4d92012-08-29 00:06:25 +00003314 PixelTrait
3315 alpha_trait;
3316
cristy4285d782011-02-09 20:12:28 +00003317 RectangleInfo
3318 geometry;
3319
3320 register const Image
3321 *next;
3322
3323 size_t
3324 height,
3325 number_images,
3326 width;
3327
3328 ssize_t
3329 x_offset,
cristy4285d782011-02-09 20:12:28 +00003330 y_offset;
3331
3332 /*
cristy7c6dc152011-02-11 14:10:55 +00003333 Compute maximum area of smushed area.
cristy4285d782011-02-09 20:12:28 +00003334 */
cristy4ca38e22011-02-10 02:57:49 +00003335 assert(images != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003336 assert(images->signature == MagickCoreSignature);
cristy4ca38e22011-02-10 02:57:49 +00003337 if (images->debug != MagickFalse)
3338 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
cristy4285d782011-02-09 20:12:28 +00003339 assert(exception != (ExceptionInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003340 assert(exception->signature == MagickCoreSignature);
cristy4ca38e22011-02-10 02:57:49 +00003341 image=images;
cristy5a5e4d92012-08-29 00:06:25 +00003342 alpha_trait=image->alpha_trait;
cristy4285d782011-02-09 20:12:28 +00003343 number_images=1;
3344 width=image->columns;
3345 height=image->rows;
3346 next=GetNextImageInList(image);
3347 for ( ; next != (Image *) NULL; next=GetNextImageInList(next))
3348 {
cristy17f11b02014-12-20 19:37:04 +00003349 if (next->alpha_trait != UndefinedPixelTrait)
cristy5a5e4d92012-08-29 00:06:25 +00003350 alpha_trait=BlendPixelTrait;
cristy4285d782011-02-09 20:12:28 +00003351 number_images++;
3352 if (stack != MagickFalse)
3353 {
3354 if (next->columns > width)
3355 width=next->columns;
3356 height+=next->rows;
cristy4ef6f062011-02-10 20:30:22 +00003357 if (next->previous != (Image *) NULL)
3358 height+=offset;
cristy4285d782011-02-09 20:12:28 +00003359 continue;
3360 }
3361 width+=next->columns;
cristy4ef6f062011-02-10 20:30:22 +00003362 if (next->previous != (Image *) NULL)
3363 width+=offset;
cristy4285d782011-02-09 20:12:28 +00003364 if (next->rows > height)
3365 height=next->rows;
3366 }
3367 /*
cristy7c6dc152011-02-11 14:10:55 +00003368 Smush images.
cristy4285d782011-02-09 20:12:28 +00003369 */
3370 smush_image=CloneImage(image,width,height,MagickTrue,exception);
3371 if (smush_image == (Image *) NULL)
3372 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003373 if (SetImageStorageClass(smush_image,DirectClass,exception) == MagickFalse)
cristy4285d782011-02-09 20:12:28 +00003374 {
cristy4285d782011-02-09 20:12:28 +00003375 smush_image=DestroyImage(smush_image);
3376 return((Image *) NULL);
3377 }
cristy5a5e4d92012-08-29 00:06:25 +00003378 smush_image->alpha_trait=alpha_trait;
cristyea1a8aa2011-10-20 13:24:06 +00003379 (void) SetImageBackgroundColor(smush_image,exception);
cristy4285d782011-02-09 20:12:28 +00003380 status=MagickTrue;
3381 x_offset=0;
3382 y_offset=0;
cristy4285d782011-02-09 20:12:28 +00003383 for (n=0; n < (MagickOffsetType) number_images; n++)
3384 {
3385 SetGeometry(smush_image,&geometry);
3386 GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry);
3387 if (stack != MagickFalse)
cristy4ca38e22011-02-10 02:57:49 +00003388 {
3389 x_offset-=geometry.x;
cristy7c6dc152011-02-11 14:10:55 +00003390 y_offset-=SmushYGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003391 }
cristy4285d782011-02-09 20:12:28 +00003392 else
cristy4ca38e22011-02-10 02:57:49 +00003393 {
cristy7c6dc152011-02-11 14:10:55 +00003394 x_offset-=SmushXGap(smush_image,image,offset,exception);
cristy4ca38e22011-02-10 02:57:49 +00003395 y_offset-=geometry.y;
cristy4ca38e22011-02-10 02:57:49 +00003396 }
cristy39172402012-03-30 13:04:39 +00003397 status=CompositeImage(smush_image,image,OverCompositeOp,MagickTrue,x_offset,
3398 y_offset,exception);
cristy4285d782011-02-09 20:12:28 +00003399 proceed=SetImageProgress(image,SmushImageTag,n,number_images);
3400 if (proceed == MagickFalse)
3401 break;
3402 if (stack == MagickFalse)
3403 {
3404 x_offset+=(ssize_t) image->columns;
3405 y_offset=0;
3406 }
3407 else
3408 {
3409 x_offset=0;
3410 y_offset+=(ssize_t) image->rows;
3411 }
3412 image=GetNextImageInList(image);
3413 }
cristy4ef6f062011-02-10 20:30:22 +00003414 if (stack == MagickFalse)
3415 smush_image->columns=(size_t) x_offset;
cristy4d727152011-02-10 19:57:21 +00003416 else
cristy4ef6f062011-02-10 20:30:22 +00003417 smush_image->rows=(size_t) y_offset;
cristy4285d782011-02-09 20:12:28 +00003418 if (status == MagickFalse)
3419 smush_image=DestroyImage(smush_image);
3420 return(smush_image);
3421}
3422
3423/*
3424%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3425% %
3426% %
3427% %
cristy3ed852e2009-09-05 21:47:34 +00003428% S t r i p I m a g e %
3429% %
3430% %
3431% %
3432%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3433%
cristy376bda92009-12-22 21:15:23 +00003434% StripImage() strips an image of all profiles and comments.
cristy3ed852e2009-09-05 21:47:34 +00003435%
3436% The format of the StripImage method is:
3437%
cristye941a752011-10-15 01:52:48 +00003438% MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003439%
3440% A description of each parameter follows:
3441%
3442% o image: the image.
3443%
cristye941a752011-10-15 01:52:48 +00003444% o exception: return any errors or warnings in this structure.
3445%
cristy3ed852e2009-09-05 21:47:34 +00003446*/
cristye941a752011-10-15 01:52:48 +00003447MagickExport MagickBooleanType StripImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003448{
cristye941a752011-10-15 01:52:48 +00003449 MagickBooleanType
3450 status;
3451
cristy3ed852e2009-09-05 21:47:34 +00003452 assert(image != (Image *) NULL);
3453 if (image->debug != MagickFalse)
3454 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye941a752011-10-15 01:52:48 +00003455 (void) exception;
cristy3ed852e2009-09-05 21:47:34 +00003456 DestroyImageProfiles(image);
cristy6b9aca12010-02-21 01:50:11 +00003457 (void) DeleteImageProperty(image,"comment");
cristy7c99caa2010-09-13 17:19:54 +00003458 (void) DeleteImageProperty(image,"date:create");
3459 (void) DeleteImageProperty(image,"date:modify");
cristy42e14902014-05-01 22:40:40 +00003460 status=SetImageArtifact(image,"png:exclude-chunk",
3461 "EXIF,iCCP,iTXt,sRGB,tEXt,zCCP,zTXt,date");
cristye941a752011-10-15 01:52:48 +00003462 return(status);
cristy3ed852e2009-09-05 21:47:34 +00003463}
3464
3465/*
3466%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3467% %
3468% %
3469% %
3470+ S y n c I m a g e %
3471% %
3472% %
3473% %
3474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3475%
3476% SyncImage() initializes the red, green, and blue intensities of each pixel
3477% as defined by the colormap index.
3478%
3479% The format of the SyncImage method is:
3480%
cristyea1a8aa2011-10-20 13:24:06 +00003481% MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003482%
3483% A description of each parameter follows:
3484%
3485% o image: the image.
3486%
cristyea1a8aa2011-10-20 13:24:06 +00003487% o exception: return any errors or warnings in this structure.
3488%
cristy3ed852e2009-09-05 21:47:34 +00003489*/
3490
cristyaedc0312012-01-08 01:07:37 +00003491static inline Quantum PushColormapIndex(Image *image,const Quantum index,
3492 MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +00003493{
cristyc8d63672012-01-11 13:03:13 +00003494 if ((size_t) index < image->colors)
cristyaedc0312012-01-08 01:07:37 +00003495 return(index);
cristy3ed852e2009-09-05 21:47:34 +00003496 *range_exception=MagickTrue;
cristyd9657d22012-08-23 14:25:31 +00003497 return((Quantum) 0);
cristy3ed852e2009-09-05 21:47:34 +00003498}
3499
cristyea1a8aa2011-10-20 13:24:06 +00003500MagickExport MagickBooleanType SyncImage(Image *image,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003501{
3502 CacheView
3503 *image_view;
3504
cristy3ed852e2009-09-05 21:47:34 +00003505 MagickBooleanType
3506 range_exception,
dirkf5cb0472014-10-24 20:10:14 +00003507 status,
3508 taint;
cristy3ed852e2009-09-05 21:47:34 +00003509
cristycb6d09b2010-06-19 01:59:36 +00003510 ssize_t
3511 y;
3512
cristy3ed852e2009-09-05 21:47:34 +00003513 assert(image != (Image *) NULL);
3514 if (image->debug != MagickFalse)
3515 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristye1c94d92015-06-28 12:16:33 +00003516 assert(image->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00003517 if (image->storage_class == DirectClass)
3518 return(MagickFalse);
3519 range_exception=MagickFalse;
3520 status=MagickTrue;
dirkf5cb0472014-10-24 20:10:14 +00003521 taint=image->taint;
cristy46ff2672012-12-14 15:32:26 +00003522 image_view=AcquireAuthenticCacheView(image,exception);
cristy48974b92009-12-19 02:36:06 +00003523#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003524 #pragma omp parallel for schedule(static,4) shared(range_exception,status) \
cristy5e6b2592012-12-19 14:08:11 +00003525 magick_threads(image,image,image->rows,1)
cristy48974b92009-12-19 02:36:06 +00003526#endif
cristybb503372010-05-27 20:51:26 +00003527 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003528 {
cristy4c08aed2011-07-01 19:47:50 +00003529 Quantum
cristy3ed852e2009-09-05 21:47:34 +00003530 index;
3531
cristy4c08aed2011-07-01 19:47:50 +00003532 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003533 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003534
cristycb6d09b2010-06-19 01:59:36 +00003535 register ssize_t
3536 x;
3537
cristy48974b92009-12-19 02:36:06 +00003538 if (status == MagickFalse)
3539 continue;
cristy3ed852e2009-09-05 21:47:34 +00003540 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00003541 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003542 {
3543 status=MagickFalse;
3544 continue;
3545 }
cristybb503372010-05-27 20:51:26 +00003546 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003547 {
cristyaedc0312012-01-08 01:07:37 +00003548 index=PushColormapIndex(image,GetPixelIndex(image,q),&range_exception);
cristy11a06d32015-01-04 12:03:27 +00003549 SetPixelViaPixelInfo(image,image->colormap+(ssize_t) index,q);
cristyed231572011-07-14 02:18:59 +00003550 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00003551 }
3552 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3553 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003554 }
3555 image_view=DestroyCacheView(image_view);
dirkf5cb0472014-10-24 20:10:14 +00003556 image->taint=taint;
cristycaf45802012-06-16 18:28:54 +00003557 if ((image->ping == MagickFalse) && (range_exception != MagickFalse))
cristy6fccee12011-10-20 18:43:18 +00003558 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
cristyefe601c2013-01-05 17:51:12 +00003559 "InvalidColormapIndex","`%s'",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00003560 return(status);
3561}
cristy1626d332009-11-10 16:58:17 +00003562
3563/*
3564%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3565% %
3566% %
3567% %
3568% S y n c I m a g e S e t t i n g s %
3569% %
3570% %
3571% %
3572%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3573%
anthony5f78bca2012-10-05 06:51:00 +00003574% SyncImageSettings() syncs any image_info global options into per-image
3575% attributes.
3576%
anthonyc7994672012-11-17 05:33:27 +00003577% Note: in IMv6 free form 'options' were always mapped into 'artifacts', so
anthony5f78bca2012-10-05 06:51:00 +00003578% that operations and coders can find such settings. In IMv7 if a desired
3579% per-image artifact is not set, then it will directly look for a global
anthonyc7994672012-11-17 05:33:27 +00003580% option as a fallback, as such this copy is no longer needed, only the
3581% link set up.
cristy1626d332009-11-10 16:58:17 +00003582%
3583% The format of the SyncImageSettings method is:
3584%
3585% MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003586% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003587% MagickBooleanType SyncImagesSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003588% Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003589%
3590% A description of each parameter follows:
3591%
3592% o image_info: the image info.
3593%
3594% o image: the image.
3595%
cristy6fccee12011-10-20 18:43:18 +00003596% o exception: return any errors or warnings in this structure.
3597%
cristy1626d332009-11-10 16:58:17 +00003598*/
3599
3600MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003601 Image *images,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003602{
3603 Image
3604 *image;
3605
3606 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003607 assert(image_info->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003608 assert(images != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003609 assert(images->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003610 if (images->debug != MagickFalse)
3611 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
3612 image=images;
3613 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
cristy6fccee12011-10-20 18:43:18 +00003614 (void) SyncImageSettings(image_info,image,exception);
cristy1626d332009-11-10 16:58:17 +00003615 (void) DeleteImageOption(image_info,"page");
3616 return(MagickTrue);
3617}
3618
3619MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info,
cristy6fccee12011-10-20 18:43:18 +00003620 Image *image,ExceptionInfo *exception)
cristy1626d332009-11-10 16:58:17 +00003621{
cristy1626d332009-11-10 16:58:17 +00003622 const char
cristy202c1482012-10-05 23:47:57 +00003623 *option;
cristy1626d332009-11-10 16:58:17 +00003624
3625 GeometryInfo
3626 geometry_info;
3627
3628 MagickStatusType
3629 flags;
3630
cristy19eb6412010-04-23 14:42:29 +00003631 ResolutionType
3632 units;
3633
cristy1626d332009-11-10 16:58:17 +00003634 /*
3635 Sync image options.
3636 */
3637 assert(image_info != (const ImageInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003638 assert(image_info->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003639 assert(image != (Image *) NULL);
cristye1c94d92015-06-28 12:16:33 +00003640 assert(image->signature == MagickCoreSignature);
cristy1626d332009-11-10 16:58:17 +00003641 if (image->debug != MagickFalse)
3642 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3643 option=GetImageOption(image_info,"background");
3644 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003645 (void) QueryColorCompliance(option,AllCompliance,&image->background_color,
cristy6fccee12011-10-20 18:43:18 +00003646 exception);
cristy1626d332009-11-10 16:58:17 +00003647 option=GetImageOption(image_info,"black-point-compensation");
3648 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003649 image->black_point_compensation=(MagickBooleanType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003650 MagickBooleanOptions,MagickFalse,option);
3651 option=GetImageOption(image_info,"blue-primary");
3652 if (option != (const char *) NULL)
3653 {
3654 flags=ParseGeometry(option,&geometry_info);
3655 image->chromaticity.blue_primary.x=geometry_info.rho;
3656 image->chromaticity.blue_primary.y=geometry_info.sigma;
3657 if ((flags & SigmaValue) == 0)
3658 image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x;
3659 }
3660 option=GetImageOption(image_info,"bordercolor");
3661 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003662 (void) QueryColorCompliance(option,AllCompliance,&image->border_color,
cristy6fccee12011-10-20 18:43:18 +00003663 exception);
anthony72feaa62012-01-17 06:46:23 +00003664 /* FUTURE: do not sync compose to per-image compose setting here */
cristy1626d332009-11-10 16:58:17 +00003665 option=GetImageOption(image_info,"compose");
3666 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003667 image->compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
cristy1626d332009-11-10 16:58:17 +00003668 MagickFalse,option);
anthony72feaa62012-01-17 06:46:23 +00003669 /* -- */
cristy1626d332009-11-10 16:58:17 +00003670 option=GetImageOption(image_info,"compress");
3671 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003672 image->compression=(CompressionType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003673 MagickCompressOptions,MagickFalse,option);
3674 option=GetImageOption(image_info,"debug");
3675 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003676 image->debug=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00003677 MagickFalse,option);
cristydd5f5912010-07-31 23:37:23 +00003678 option=GetImageOption(image_info,"density");
3679 if (option != (const char *) NULL)
3680 {
3681 GeometryInfo
3682 geometry_info;
3683
cristydd5f5912010-07-31 23:37:23 +00003684 flags=ParseGeometry(option,&geometry_info);
cristy2a11bef2011-10-28 18:33:11 +00003685 image->resolution.x=geometry_info.rho;
3686 image->resolution.y=geometry_info.sigma;
cristydd5f5912010-07-31 23:37:23 +00003687 if ((flags & SigmaValue) == 0)
cristy2a11bef2011-10-28 18:33:11 +00003688 image->resolution.y=image->resolution.x;
cristydd5f5912010-07-31 23:37:23 +00003689 }
cristy1626d332009-11-10 16:58:17 +00003690 option=GetImageOption(image_info,"depth");
3691 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003692 image->depth=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003693 option=GetImageOption(image_info,"endian");
3694 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003695 image->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
cristy1626d332009-11-10 16:58:17 +00003696 MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00003697 option=GetImageOption(image_info,"filter");
3698 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003699 image->filter=(FilterTypes) ParseCommandOption(MagickFilterOptions,
cristy1626d332009-11-10 16:58:17 +00003700 MagickFalse,option);
3701 option=GetImageOption(image_info,"fuzz");
3702 if (option != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00003703 image->fuzz=StringToDoubleInterval(option,(double) QuantumRange+1.0);
cristy1626d332009-11-10 16:58:17 +00003704 option=GetImageOption(image_info,"gravity");
3705 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003706 image->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
cristy1626d332009-11-10 16:58:17 +00003707 MagickFalse,option);
3708 option=GetImageOption(image_info,"green-primary");
3709 if (option != (const char *) NULL)
3710 {
3711 flags=ParseGeometry(option,&geometry_info);
3712 image->chromaticity.green_primary.x=geometry_info.rho;
3713 image->chromaticity.green_primary.y=geometry_info.sigma;
3714 if ((flags & SigmaValue) == 0)
3715 image->chromaticity.green_primary.y=image->chromaticity.green_primary.x;
3716 }
3717 option=GetImageOption(image_info,"intent");
3718 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003719 image->rendering_intent=(RenderingIntent) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003720 MagickIntentOptions,MagickFalse,option);
cristy313634e2013-03-26 00:52:19 +00003721 option=GetImageOption(image_info,"intensity");
3722 if (option != (const char *) NULL)
3723 image->intensity=(PixelIntensityMethod) ParseCommandOption(
3724 MagickPixelIntensityOptions,MagickFalse,option);
cristy1626d332009-11-10 16:58:17 +00003725 option=GetImageOption(image_info,"interlace");
3726 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003727 image->interlace=(InterlaceType) ParseCommandOption(MagickInterlaceOptions,
cristy1626d332009-11-10 16:58:17 +00003728 MagickFalse,option);
3729 option=GetImageOption(image_info,"interpolate");
3730 if (option != (const char *) NULL)
cristy5c4e2582011-09-11 19:21:03 +00003731 image->interpolate=(PixelInterpolateMethod) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003732 MagickInterpolateOptions,MagickFalse,option);
3733 option=GetImageOption(image_info,"loop");
3734 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003735 image->iterations=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003736 option=GetImageOption(image_info,"mattecolor");
3737 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003738 (void) QueryColorCompliance(option,AllCompliance,&image->matte_color,
cristy6fccee12011-10-20 18:43:18 +00003739 exception);
cristy1626d332009-11-10 16:58:17 +00003740 option=GetImageOption(image_info,"orient");
3741 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003742 image->orientation=(OrientationType) ParseCommandOption(
cristy1626d332009-11-10 16:58:17 +00003743 MagickOrientationOptions,MagickFalse,option);
cristy14ed6a22013-12-28 23:48:05 +00003744 option=GetImageOption(image_info,"page");
3745 if (option != (const char *) NULL)
3746 {
3747 char
3748 *geometry;
3749
3750 geometry=GetPageGeometry(option);
3751 flags=ParseAbsoluteGeometry(geometry,&image->page);
3752 geometry=DestroyString(geometry);
3753 }
cristy1626d332009-11-10 16:58:17 +00003754 option=GetImageOption(image_info,"quality");
3755 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003756 image->quality=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003757 option=GetImageOption(image_info,"red-primary");
3758 if (option != (const char *) NULL)
3759 {
3760 flags=ParseGeometry(option,&geometry_info);
3761 image->chromaticity.red_primary.x=geometry_info.rho;
3762 image->chromaticity.red_primary.y=geometry_info.sigma;
3763 if ((flags & SigmaValue) == 0)
3764 image->chromaticity.red_primary.y=image->chromaticity.red_primary.x;
3765 }
3766 if (image_info->quality != UndefinedCompressionQuality)
3767 image->quality=image_info->quality;
3768 option=GetImageOption(image_info,"scene");
3769 if (option != (const char *) NULL)
cristye27293e2009-12-18 02:53:20 +00003770 image->scene=StringToUnsignedLong(option);
cristy1626d332009-11-10 16:58:17 +00003771 option=GetImageOption(image_info,"taint");
3772 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003773 image->taint=(MagickBooleanType) ParseCommandOption(MagickBooleanOptions,
cristy1626d332009-11-10 16:58:17 +00003774 MagickFalse,option);
3775 option=GetImageOption(image_info,"tile-offset");
3776 if (option != (const char *) NULL)
3777 {
3778 char
3779 *geometry;
3780
3781 geometry=GetPageGeometry(option);
3782 flags=ParseAbsoluteGeometry(geometry,&image->tile_offset);
3783 geometry=DestroyString(geometry);
3784 }
3785 option=GetImageOption(image_info,"transparent-color");
3786 if (option != (const char *) NULL)
cristy9950d572011-10-01 18:22:35 +00003787 (void) QueryColorCompliance(option,AllCompliance,&image->transparent_color,
cristy6fccee12011-10-20 18:43:18 +00003788 exception);
cristy1626d332009-11-10 16:58:17 +00003789 option=GetImageOption(image_info,"type");
3790 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003791 image->type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
cristy1626d332009-11-10 16:58:17 +00003792 option);
3793 option=GetImageOption(image_info,"units");
cristyc8d63672012-01-11 13:03:13 +00003794 units=image_info->units;
cristy1626d332009-11-10 16:58:17 +00003795 if (option != (const char *) NULL)
cristy042ee782011-04-22 18:48:30 +00003796 units=(ResolutionType) ParseCommandOption(MagickResolutionOptions,
cristy1626d332009-11-10 16:58:17 +00003797 MagickFalse,option);
cristy19eb6412010-04-23 14:42:29 +00003798 if (units != UndefinedResolution)
cristy1626d332009-11-10 16:58:17 +00003799 {
cristy19eb6412010-04-23 14:42:29 +00003800 if (image->units != units)
cristy1626d332009-11-10 16:58:17 +00003801 switch (image->units)
3802 {
3803 case PixelsPerInchResolution:
3804 {
cristy19eb6412010-04-23 14:42:29 +00003805 if (units == PixelsPerCentimeterResolution)
cristy1626d332009-11-10 16:58:17 +00003806 {
cristy2a11bef2011-10-28 18:33:11 +00003807 image->resolution.x/=2.54;
3808 image->resolution.y/=2.54;
cristy1626d332009-11-10 16:58:17 +00003809 }
3810 break;
3811 }
3812 case PixelsPerCentimeterResolution:
3813 {
cristy19eb6412010-04-23 14:42:29 +00003814 if (units == PixelsPerInchResolution)
cristy1626d332009-11-10 16:58:17 +00003815 {
cristy2a11bef2011-10-28 18:33:11 +00003816 image->resolution.x=(double) ((size_t) (100.0*2.54*
3817 image->resolution.x+0.5))/100.0;
3818 image->resolution.y=(double) ((size_t) (100.0*2.54*
3819 image->resolution.y+0.5))/100.0;
cristy1626d332009-11-10 16:58:17 +00003820 }
3821 break;
3822 }
3823 default:
3824 break;
3825 }
cristy19eb6412010-04-23 14:42:29 +00003826 image->units=units;
cristy1626d332009-11-10 16:58:17 +00003827 }
anthonyfd706f92012-01-19 04:22:02 +00003828 option=GetImageOption(image_info,"virtual-pixel");
3829 if (option != (const char *) NULL)
cristy387430f2012-02-07 13:09:46 +00003830 (void) SetImageVirtualPixelMethod(image,(VirtualPixelMethod)
3831 ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,option),
3832 exception);
cristy1626d332009-11-10 16:58:17 +00003833 option=GetImageOption(image_info,"white-point");
3834 if (option != (const char *) NULL)
3835 {
3836 flags=ParseGeometry(option,&geometry_info);
3837 image->chromaticity.white_point.x=geometry_info.rho;
3838 image->chromaticity.white_point.y=geometry_info.sigma;
3839 if ((flags & SigmaValue) == 0)
3840 image->chromaticity.white_point.y=image->chromaticity.white_point.x;
3841 }
Cristy9c282cc2015-08-29 17:37:22 -04003842 /*
3843 Pointer to allow the lookup of pre-image artifact will fallback to a global
3844 option setting/define. This saves a lot of duplication of global options
3845 into per-image artifacts, while ensuring only specifically set per-image
3846 artifacts are preserved when parenthesis ends.
anthony643c6132012-11-07 14:50:28 +00003847 */
dirk98d3e1c2015-08-28 21:09:11 +02003848 if (image->image_info != (ImageInfo *) NULL)
3849 image->image_info=DestroyImageInfo(image->image_info);
Cristy36421ee2015-08-28 11:58:20 -04003850 image->image_info=CloneImageInfo(image_info);
cristy1626d332009-11-10 16:58:17 +00003851 return(MagickTrue);
3852}