blob: bfddc3dbb1ce4d40859e0457718d1fdf8ab98cd7 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% FFFFF X X %
7% F X X %
8% FFF X %
9% F X X %
10% F X X %
11% %
12% %
13% MagickCore Image Special Effects Methods %
14% %
15% Software Design %
16% John Cristy %
17% October 1996 %
18% %
19% %
cristy45ef08f2012-12-07 13:13:34 +000020% Copyright 1999-2013 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/annotate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/cache.h"
48#include "MagickCore/cache-view.h"
49#include "MagickCore/color.h"
50#include "MagickCore/color-private.h"
cristy9b7a4fc2012-04-08 22:26:56 +000051#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000052#include "MagickCore/composite.h"
53#include "MagickCore/decorate.h"
cristyc53413d2011-11-17 13:04:26 +000054#include "MagickCore/distort.h"
cristy4c08aed2011-07-01 19:47:50 +000055#include "MagickCore/draw.h"
56#include "MagickCore/effect.h"
57#include "MagickCore/enhance.h"
58#include "MagickCore/exception.h"
59#include "MagickCore/exception-private.h"
60#include "MagickCore/fx.h"
61#include "MagickCore/fx-private.h"
62#include "MagickCore/gem.h"
cristy8ea81222011-09-04 10:33:32 +000063#include "MagickCore/gem-private.h"
cristy4c08aed2011-07-01 19:47:50 +000064#include "MagickCore/geometry.h"
65#include "MagickCore/layer.h"
66#include "MagickCore/list.h"
67#include "MagickCore/log.h"
68#include "MagickCore/image.h"
69#include "MagickCore/image-private.h"
70#include "MagickCore/magick.h"
71#include "MagickCore/memory_.h"
72#include "MagickCore/monitor.h"
73#include "MagickCore/monitor-private.h"
74#include "MagickCore/option.h"
75#include "MagickCore/pixel.h"
76#include "MagickCore/pixel-accessor.h"
77#include "MagickCore/property.h"
78#include "MagickCore/quantum.h"
79#include "MagickCore/quantum-private.h"
80#include "MagickCore/random_.h"
81#include "MagickCore/random-private.h"
82#include "MagickCore/resample.h"
83#include "MagickCore/resample-private.h"
84#include "MagickCore/resize.h"
cristy57340e02012-05-05 00:53:23 +000085#include "MagickCore/resource_.h"
cristy4c08aed2011-07-01 19:47:50 +000086#include "MagickCore/splay-tree.h"
87#include "MagickCore/statistic.h"
88#include "MagickCore/string_.h"
89#include "MagickCore/string-private.h"
90#include "MagickCore/thread-private.h"
91#include "MagickCore/transform.h"
92#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000093
94/*
95 Define declarations.
96*/
97#define LeftShiftOperator 0xf5
98#define RightShiftOperator 0xf6
99#define LessThanEqualOperator 0xf7
100#define GreaterThanEqualOperator 0xf8
101#define EqualOperator 0xf9
102#define NotEqualOperator 0xfa
103#define LogicalAndOperator 0xfb
104#define LogicalOrOperator 0xfc
cristy116af162010-08-13 01:25:47 +0000105#define ExponentialNotation 0xfd
cristy3ed852e2009-09-05 21:47:34 +0000106
107struct _FxInfo
108{
109 const Image
110 *images;
111
cristy3ed852e2009-09-05 21:47:34 +0000112 char
113 *expression;
114
115 FILE
116 *file;
117
118 SplayTreeInfo
119 *colors,
120 *symbols;
121
cristyd76c51e2011-03-26 00:21:26 +0000122 CacheView
123 **view;
cristy3ed852e2009-09-05 21:47:34 +0000124
125 RandomInfo
126 *random_info;
127
128 ExceptionInfo
129 *exception;
130};
131
132/*
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134% %
135% %
136% %
137+ A c q u i r e F x I n f o %
138% %
139% %
140% %
141%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142%
143% AcquireFxInfo() allocates the FxInfo structure.
144%
145% The format of the AcquireFxInfo method is:
146%
cristydb070952012-04-20 14:33:00 +0000147% FxInfo *AcquireFxInfo(Image *image,const char *expression,
148% ExceptionInfo *exception)
cristy0a9b3722010-10-23 18:45:49 +0000149%
cristy3ed852e2009-09-05 21:47:34 +0000150% A description of each parameter follows:
151%
152% o image: the image.
153%
154% o expression: the expression.
155%
cristydb070952012-04-20 14:33:00 +0000156% o exception: return any errors or warnings in this structure.
157%
cristy3ed852e2009-09-05 21:47:34 +0000158*/
cristydb070952012-04-20 14:33:00 +0000159MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression,
160 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000161{
162 char
163 fx_op[2];
164
cristycb180922011-03-11 14:41:24 +0000165 const Image
166 *next;
167
cristy3ed852e2009-09-05 21:47:34 +0000168 FxInfo
169 *fx_info;
170
cristybb503372010-05-27 20:51:26 +0000171 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000172 i;
173
cristy73bd4a52010-10-05 11:24:23 +0000174 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +0000175 if (fx_info == (FxInfo *) NULL)
176 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
177 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
178 fx_info->exception=AcquireExceptionInfo();
anthony7d86e172011-03-23 12:37:06 +0000179 fx_info->images=image;
cristy3ed852e2009-09-05 21:47:34 +0000180 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
181 RelinquishMagickMemory);
182 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
183 RelinquishMagickMemory);
cristyd76c51e2011-03-26 00:21:26 +0000184 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
185 fx_info->images),sizeof(*fx_info->view));
186 if (fx_info->view == (CacheView **) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000187 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
cristya2262262011-03-11 02:50:37 +0000188 i=0;
cristy0ea377f2011-03-24 00:54:19 +0000189 next=GetFirstImageInList(fx_info->images);
190 for ( ; next != (Image *) NULL; next=next->next)
cristy3ed852e2009-09-05 21:47:34 +0000191 {
cristy46ff2672012-12-14 15:32:26 +0000192 fx_info->view[i]=AcquireVirtualCacheView(next,exception);
cristya2262262011-03-11 02:50:37 +0000193 i++;
cristy3ed852e2009-09-05 21:47:34 +0000194 }
195 fx_info->random_info=AcquireRandomInfo();
196 fx_info->expression=ConstantString(expression);
197 fx_info->file=stderr;
198 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
cristy37af0912011-05-23 16:09:42 +0000199 /*
200 Force right-to-left associativity for unary negation.
201 */
202 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
cristy422d5502012-12-22 22:20:57 +0000203 (void) SubstituteString(&fx_info->expression,"^-1.0*","^-");
cristy8fbb96d2012-07-18 01:18:52 +0000204 (void) SubstituteString(&fx_info->expression,"E-1.0*","E-");
205 (void) SubstituteString(&fx_info->expression,"e-1.0*","e-");
cristy8b8a3ae2010-10-23 18:49:46 +0000206 /*
cristy3ed852e2009-09-05 21:47:34 +0000207 Convert complex to simple operators.
208 */
209 fx_op[1]='\0';
210 *fx_op=(char) LeftShiftOperator;
211 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
212 *fx_op=(char) RightShiftOperator;
213 (void) SubstituteString(&fx_info->expression,">>",fx_op);
214 *fx_op=(char) LessThanEqualOperator;
215 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
216 *fx_op=(char) GreaterThanEqualOperator;
217 (void) SubstituteString(&fx_info->expression,">=",fx_op);
218 *fx_op=(char) EqualOperator;
219 (void) SubstituteString(&fx_info->expression,"==",fx_op);
220 *fx_op=(char) NotEqualOperator;
221 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
222 *fx_op=(char) LogicalAndOperator;
223 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
224 *fx_op=(char) LogicalOrOperator;
225 (void) SubstituteString(&fx_info->expression,"||",fx_op);
cristy116af162010-08-13 01:25:47 +0000226 *fx_op=(char) ExponentialNotation;
227 (void) SubstituteString(&fx_info->expression,"**",fx_op);
cristy3ed852e2009-09-05 21:47:34 +0000228 return(fx_info);
229}
230
231/*
232%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233% %
234% %
235% %
236% A d d N o i s e I m a g e %
237% %
238% %
239% %
240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241%
242% AddNoiseImage() adds random noise to the image.
243%
244% The format of the AddNoiseImage method is:
245%
246% Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
cristy9ed1f812011-10-08 02:00:08 +0000247% const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000248%
249% A description of each parameter follows:
250%
251% o image: the image.
252%
253% o channel: the channel type.
254%
255% o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
256% Impulse, Laplacian, or Poisson.
257%
cristy9ed1f812011-10-08 02:00:08 +0000258% o attenuate: attenuate the random distribution.
259%
cristy3ed852e2009-09-05 21:47:34 +0000260% o exception: return any errors or warnings in this structure.
261%
262*/
cristy9ed1f812011-10-08 02:00:08 +0000263MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
264 const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000265{
266#define AddNoiseImageTag "AddNoise/Image"
267
cristyfa112112010-01-04 17:48:07 +0000268 CacheView
269 *image_view,
270 *noise_view;
271
cristy3ed852e2009-09-05 21:47:34 +0000272 Image
273 *noise_image;
274
cristy3ed852e2009-09-05 21:47:34 +0000275 MagickBooleanType
276 status;
277
cristybb503372010-05-27 20:51:26 +0000278 MagickOffsetType
279 progress;
280
cristy3ed852e2009-09-05 21:47:34 +0000281 RandomInfo
cristyfa112112010-01-04 17:48:07 +0000282 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +0000283
cristybb503372010-05-27 20:51:26 +0000284 ssize_t
285 y;
286
glennrpf7659d72012-09-24 18:14:56 +0000287#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +0000288 unsigned long
289 key;
glennrpf7659d72012-09-24 18:14:56 +0000290#endif
cristy57340e02012-05-05 00:53:23 +0000291
cristy3ed852e2009-09-05 21:47:34 +0000292 /*
293 Initialize noise image attributes.
294 */
295 assert(image != (const Image *) NULL);
296 assert(image->signature == MagickSignature);
297 if (image->debug != MagickFalse)
298 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
299 assert(exception != (ExceptionInfo *) NULL);
300 assert(exception->signature == MagickSignature);
cristyb2145892011-10-10 00:55:32 +0000301 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000302 if (noise_image == (Image *) NULL)
303 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000304 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000305 {
cristy3ed852e2009-09-05 21:47:34 +0000306 noise_image=DestroyImage(noise_image);
307 return((Image *) NULL);
308 }
309 /*
310 Add noise in each row.
311 */
cristy3ed852e2009-09-05 21:47:34 +0000312 status=MagickTrue;
313 progress=0;
314 random_info=AcquireRandomInfoThreadSet();
cristy46ff2672012-12-14 15:32:26 +0000315 image_view=AcquireVirtualCacheView(image,exception);
316 noise_view=AcquireAuthenticCacheView(noise_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000317#if defined(MAGICKCORE_OPENMP_SUPPORT)
glennrpf7659d72012-09-24 18:14:56 +0000318 key=GetRandomSecretKey(random_info[0]);
cristy57340e02012-05-05 00:53:23 +0000319 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000320 magick_threads(image,noise_image,image->rows,key == ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000321#endif
cristybb503372010-05-27 20:51:26 +0000322 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000323 {
cristy5c9e6f22010-09-17 17:31:01 +0000324 const int
325 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +0000326
cristy3ed852e2009-09-05 21:47:34 +0000327 MagickBooleanType
328 sync;
329
cristy4c08aed2011-07-01 19:47:50 +0000330 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000331 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000332
cristybb503372010-05-27 20:51:26 +0000333 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000334 x;
335
cristy4c08aed2011-07-01 19:47:50 +0000336 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000337 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000338
339 if (status == MagickFalse)
340 continue;
341 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +0000342 q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +0000343 exception);
cristy4c08aed2011-07-01 19:47:50 +0000344 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000345 {
346 status=MagickFalse;
347 continue;
348 }
cristybb503372010-05-27 20:51:26 +0000349 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000350 {
cristy850b3072011-10-08 01:38:05 +0000351 register ssize_t
352 i;
353
354 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
355 {
cristy5a23c552013-02-13 14:34:28 +0000356 PixelChannel channel=GetPixelChannelChannel(image,i);
357 PixelTrait traits=GetPixelChannelTraits(image,channel);
358 PixelTrait noise_traits=GetPixelChannelTraits(noise_image,channel);
cristy850b3072011-10-08 01:38:05 +0000359 if ((traits == UndefinedPixelTrait) ||
360 (noise_traits == UndefinedPixelTrait))
361 continue;
cristy1eced092012-08-10 23:10:56 +0000362 if (((noise_traits & CopyPixelTrait) != 0) ||
cristy883fde12013-04-08 00:50:13 +0000363 (GetPixelReadMask(image,p) == 0))
cristyb2145892011-10-10 00:55:32 +0000364 {
365 SetPixelChannel(noise_image,channel,p[i],q);
366 continue;
367 }
cristy850b3072011-10-08 01:38:05 +0000368 SetPixelChannel(noise_image,channel,ClampToQuantum(
369 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
370 q);
371 }
cristyed231572011-07-14 02:18:59 +0000372 p+=GetPixelChannels(image);
373 q+=GetPixelChannels(noise_image);
cristy3ed852e2009-09-05 21:47:34 +0000374 }
375 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
376 if (sync == MagickFalse)
377 status=MagickFalse;
378 if (image->progress_monitor != (MagickProgressMonitor) NULL)
379 {
380 MagickBooleanType
381 proceed;
382
cristyb5d5f722009-11-04 03:03:49 +0000383#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy319a1e72010-02-21 15:13:11 +0000384 #pragma omp critical (MagickCore_AddNoiseImage)
cristy3ed852e2009-09-05 21:47:34 +0000385#endif
386 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
387 image->rows);
388 if (proceed == MagickFalse)
389 status=MagickFalse;
390 }
391 }
392 noise_view=DestroyCacheView(noise_view);
393 image_view=DestroyCacheView(image_view);
394 random_info=DestroyRandomInfoThreadSet(random_info);
395 if (status == MagickFalse)
396 noise_image=DestroyImage(noise_image);
397 return(noise_image);
398}
399
400/*
401%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402% %
403% %
404% %
405% B l u e S h i f t I m a g e %
406% %
407% %
408% %
409%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410%
411% BlueShiftImage() mutes the colors of the image to simulate a scene at
412% nighttime in the moonlight.
413%
414% The format of the BlueShiftImage method is:
415%
416% Image *BlueShiftImage(const Image *image,const double factor,
417% ExceptionInfo *exception)
418%
419% A description of each parameter follows:
420%
421% o image: the image.
422%
423% o factor: the shift factor.
424%
425% o exception: return any errors or warnings in this structure.
426%
427*/
428MagickExport Image *BlueShiftImage(const Image *image,const double factor,
429 ExceptionInfo *exception)
430{
431#define BlueShiftImageTag "BlueShift/Image"
432
cristyc4c8d132010-01-07 01:58:38 +0000433 CacheView
434 *image_view,
435 *shift_view;
436
cristy3ed852e2009-09-05 21:47:34 +0000437 Image
438 *shift_image;
439
cristy3ed852e2009-09-05 21:47:34 +0000440 MagickBooleanType
441 status;
442
cristybb503372010-05-27 20:51:26 +0000443 MagickOffsetType
444 progress;
445
446 ssize_t
447 y;
448
cristy3ed852e2009-09-05 21:47:34 +0000449 /*
450 Allocate blue shift image.
451 */
452 assert(image != (const Image *) NULL);
453 assert(image->signature == MagickSignature);
454 if (image->debug != MagickFalse)
455 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
456 assert(exception != (ExceptionInfo *) NULL);
457 assert(exception->signature == MagickSignature);
cristya6d7a9b2012-01-18 20:04:48 +0000458 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000459 if (shift_image == (Image *) NULL)
460 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000461 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000462 {
cristy3ed852e2009-09-05 21:47:34 +0000463 shift_image=DestroyImage(shift_image);
464 return((Image *) NULL);
465 }
466 /*
467 Blue-shift DirectClass image.
468 */
469 status=MagickTrue;
470 progress=0;
cristy46ff2672012-12-14 15:32:26 +0000471 image_view=AcquireVirtualCacheView(image,exception);
472 shift_view=AcquireAuthenticCacheView(shift_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000473#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000474 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000475 magick_threads(image,shift_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000476#endif
cristybb503372010-05-27 20:51:26 +0000477 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000478 {
479 MagickBooleanType
480 sync;
481
cristy4c08aed2011-07-01 19:47:50 +0000482 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000483 pixel;
484
485 Quantum
486 quantum;
487
cristy4c08aed2011-07-01 19:47:50 +0000488 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000489 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000490
cristybb503372010-05-27 20:51:26 +0000491 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000492 x;
493
cristy4c08aed2011-07-01 19:47:50 +0000494 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000495 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000496
497 if (status == MagickFalse)
498 continue;
499 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
500 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
501 exception);
cristy4c08aed2011-07-01 19:47:50 +0000502 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000503 {
504 status=MagickFalse;
505 continue;
506 }
cristybb503372010-05-27 20:51:26 +0000507 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000508 {
cristy4c08aed2011-07-01 19:47:50 +0000509 quantum=GetPixelRed(image,p);
510 if (GetPixelGreen(image,p) < quantum)
511 quantum=GetPixelGreen(image,p);
512 if (GetPixelBlue(image,p) < quantum)
513 quantum=GetPixelBlue(image,p);
514 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
515 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
516 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
517 quantum=GetPixelRed(image,p);
518 if (GetPixelGreen(image,p) > quantum)
519 quantum=GetPixelGreen(image,p);
520 if (GetPixelBlue(image,p) > quantum)
521 quantum=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000522 pixel.red=0.5*(pixel.red+factor*quantum);
523 pixel.green=0.5*(pixel.green+factor*quantum);
524 pixel.blue=0.5*(pixel.blue+factor*quantum);
cristy4c08aed2011-07-01 19:47:50 +0000525 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
526 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
527 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
cristyed231572011-07-14 02:18:59 +0000528 p+=GetPixelChannels(image);
529 q+=GetPixelChannels(shift_image);
cristy3ed852e2009-09-05 21:47:34 +0000530 }
531 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
532 if (sync == MagickFalse)
533 status=MagickFalse;
534 if (image->progress_monitor != (MagickProgressMonitor) NULL)
535 {
536 MagickBooleanType
537 proceed;
538
cristy319a1e72010-02-21 15:13:11 +0000539#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +0000540 #pragma omp critical (MagickCore_BlueShiftImage)
cristy3ed852e2009-09-05 21:47:34 +0000541#endif
542 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
543 image->rows);
544 if (proceed == MagickFalse)
545 status=MagickFalse;
546 }
547 }
548 image_view=DestroyCacheView(image_view);
549 shift_view=DestroyCacheView(shift_view);
550 if (status == MagickFalse)
551 shift_image=DestroyImage(shift_image);
552 return(shift_image);
553}
554
555/*
556%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557% %
558% %
559% %
560% C h a r c o a l I m a g e %
561% %
562% %
563% %
564%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565%
566% CharcoalImage() creates a new image that is a copy of an existing one with
567% the edge highlighted. It allocates the memory necessary for the new Image
568% structure and returns a pointer to the new image.
569%
570% The format of the CharcoalImage method is:
571%
572% Image *CharcoalImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +0000573% const double sigma,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000574%
575% A description of each parameter follows:
576%
577% o image: the image.
578%
579% o radius: the radius of the pixel neighborhood.
580%
581% o sigma: the standard deviation of the Gaussian, in pixels.
582%
583% o exception: return any errors or warnings in this structure.
584%
585*/
586MagickExport Image *CharcoalImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +0000587 const double sigma,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000588{
589 Image
590 *charcoal_image,
591 *clone_image,
592 *edge_image;
593
594 assert(image != (Image *) NULL);
595 assert(image->signature == MagickSignature);
596 if (image->debug != MagickFalse)
597 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
598 assert(exception != (ExceptionInfo *) NULL);
599 assert(exception->signature == MagickSignature);
600 clone_image=CloneImage(image,0,0,MagickTrue,exception);
601 if (clone_image == (Image *) NULL)
602 return((Image *) NULL);
cristy018f07f2011-09-04 21:15:19 +0000603 (void) SetImageType(clone_image,GrayscaleType,exception);
cristya31d1a02013-03-25 14:38:56 +0000604 edge_image=EdgeImage(clone_image,GetOptimalKernelWidth1D(radius,1.0),
cristy8a1278a2013-03-24 13:33:29 +0000605 exception);
cristy3ed852e2009-09-05 21:47:34 +0000606 clone_image=DestroyImage(clone_image);
607 if (edge_image == (Image *) NULL)
608 return((Image *) NULL);
cristyaa2c16c2012-03-25 22:21:35 +0000609 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000610 edge_image=DestroyImage(edge_image);
611 if (charcoal_image == (Image *) NULL)
612 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +0000613 (void) NormalizeImage(charcoal_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +0000614 (void) NegateImage(charcoal_image,MagickFalse,exception);
cristy018f07f2011-09-04 21:15:19 +0000615 (void) SetImageType(charcoal_image,GrayscaleType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000616 return(charcoal_image);
617}
618
619/*
620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
621% %
622% %
623% %
624% C o l o r i z e I m a g e %
625% %
626% %
627% %
628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629%
630% ColorizeImage() blends the fill color with each pixel in the image.
631% A percentage blend is specified with opacity. Control the application
632% of different color components by specifying a different percentage for
633% each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
634%
635% The format of the ColorizeImage method is:
636%
cristyc7e6ff62011-10-03 13:46:11 +0000637% Image *ColorizeImage(const Image *image,const char *blend,
638% const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000639%
640% A description of each parameter follows:
641%
642% o image: the image.
643%
cristyc7e6ff62011-10-03 13:46:11 +0000644% o blend: A character string indicating the level of blending as a
cristy3ed852e2009-09-05 21:47:34 +0000645% percentage.
646%
647% o colorize: A color value.
648%
649% o exception: return any errors or warnings in this structure.
650%
651*/
cristyc7e6ff62011-10-03 13:46:11 +0000652MagickExport Image *ColorizeImage(const Image *image,const char *blend,
653 const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000654{
655#define ColorizeImageTag "Colorize/Image"
cristy0cf6da52012-08-25 00:35:24 +0000656#define Colorize(pixel,blend_percentage,colorize) \
657 (((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0)
cristy3ed852e2009-09-05 21:47:34 +0000658
cristyc4c8d132010-01-07 01:58:38 +0000659 CacheView
660 *colorize_view,
661 *image_view;
662
cristy3ed852e2009-09-05 21:47:34 +0000663 GeometryInfo
664 geometry_info;
665
666 Image
667 *colorize_image;
668
cristy3ed852e2009-09-05 21:47:34 +0000669 MagickBooleanType
670 status;
671
cristybb503372010-05-27 20:51:26 +0000672 MagickOffsetType
673 progress;
674
cristy3ed852e2009-09-05 21:47:34 +0000675 MagickStatusType
676 flags;
677
cristyc7e6ff62011-10-03 13:46:11 +0000678 PixelInfo
cristy20c3aed2012-04-10 01:06:21 +0000679 blend_percentage;
cristyc7e6ff62011-10-03 13:46:11 +0000680
cristybb503372010-05-27 20:51:26 +0000681 ssize_t
682 y;
683
cristy3ed852e2009-09-05 21:47:34 +0000684 /*
685 Allocate colorized image.
686 */
687 assert(image != (const Image *) NULL);
688 assert(image->signature == MagickSignature);
689 if (image->debug != MagickFalse)
690 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
691 assert(exception != (ExceptionInfo *) NULL);
692 assert(exception->signature == MagickSignature);
cristy768165d2012-04-09 15:01:35 +0000693 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
694 exception);
695 if (colorize_image == (Image *) NULL)
696 return((Image *) NULL);
697 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
698 {
699 colorize_image=DestroyImage(colorize_image);
700 return((Image *) NULL);
701 }
cristya6400b12013-03-15 12:20:18 +0000702 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
cristy4dab3802013-03-15 22:08:15 +0000703 (IsPixelInfoGray(colorize) != MagickFalse))
cristya6400b12013-03-15 12:20:18 +0000704 (void) SetImageColorspace(colorize_image,sRGBColorspace,exception);
cristy8a46d822012-08-28 23:32:39 +0000705 if ((colorize_image->alpha_trait != BlendPixelTrait) &&
706 (colorize->alpha_trait == BlendPixelTrait))
cristy768165d2012-04-09 15:01:35 +0000707 (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
708 if (blend == (const char *) NULL)
709 return(colorize_image);
cristy20c3aed2012-04-10 01:06:21 +0000710 GetPixelInfo(image,&blend_percentage);
711 flags=ParseGeometry(blend,&geometry_info);
712 blend_percentage.red=geometry_info.rho;
713 blend_percentage.green=geometry_info.rho;
714 blend_percentage.blue=geometry_info.rho;
715 blend_percentage.black=geometry_info.rho;
cristy3ee7de52012-04-14 23:40:47 +0000716 blend_percentage.alpha=geometry_info.rho;
cristy20c3aed2012-04-10 01:06:21 +0000717 if ((flags & SigmaValue) != 0)
718 blend_percentage.green=geometry_info.sigma;
719 if ((flags & XiValue) != 0)
720 blend_percentage.blue=geometry_info.xi;
721 if ((flags & PsiValue) != 0)
722 blend_percentage.alpha=geometry_info.psi;
723 if (blend_percentage.colorspace == CMYKColorspace)
724 {
725 if ((flags & PsiValue) != 0)
726 blend_percentage.black=geometry_info.psi;
727 if ((flags & ChiValue) != 0)
728 blend_percentage.alpha=geometry_info.chi;
729 }
cristy3ed852e2009-09-05 21:47:34 +0000730 /*
731 Colorize DirectClass image.
732 */
733 status=MagickTrue;
734 progress=0;
cristy46ff2672012-12-14 15:32:26 +0000735 image_view=AcquireVirtualCacheView(image,exception);
736 colorize_view=AcquireAuthenticCacheView(colorize_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000737#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000738 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000739 magick_threads(image,colorize_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000740#endif
cristybb503372010-05-27 20:51:26 +0000741 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000742 {
743 MagickBooleanType
744 sync;
745
cristy4c08aed2011-07-01 19:47:50 +0000746 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000747 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000748
cristy4c08aed2011-07-01 19:47:50 +0000749 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000750 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000751
cristy4a37c622012-08-23 18:47:56 +0000752 register ssize_t
753 x;
754
cristy3ed852e2009-09-05 21:47:34 +0000755 if (status == MagickFalse)
756 continue;
757 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
758 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
759 exception);
cristy4c08aed2011-07-01 19:47:50 +0000760 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000761 {
762 status=MagickFalse;
763 continue;
764 }
cristybb503372010-05-27 20:51:26 +0000765 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000766 {
cristy0cf6da52012-08-25 00:35:24 +0000767 register ssize_t
768 i;
769
770 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
771 {
cristy5a23c552013-02-13 14:34:28 +0000772 PixelChannel channel=GetPixelChannelChannel(image,i);
773 PixelTrait traits=GetPixelChannelTraits(image,channel);
774 PixelTrait colorize_traits=GetPixelChannelTraits(colorize_image,
775 channel);
cristy0cf6da52012-08-25 00:35:24 +0000776 if ((traits == UndefinedPixelTrait) ||
777 (colorize_traits == UndefinedPixelTrait))
cristyd6803382012-04-10 01:41:25 +0000778 continue;
cristy0cf6da52012-08-25 00:35:24 +0000779 if (((colorize_traits & CopyPixelTrait) != 0) ||
cristy883fde12013-04-08 00:50:13 +0000780 (GetPixelReadMask(image,p) == 0))
cristy0cf6da52012-08-25 00:35:24 +0000781 {
782 SetPixelChannel(colorize_image,channel,p[i],q);
783 continue;
784 }
cristyb7113232013-02-15 00:35:19 +0000785 SetPixelChannel(colorize_image,channel,ClampToQuantum(Colorize(p[i],
786 GetPixelInfoChannel(&blend_percentage,channel),GetPixelInfoChannel(
787 colorize,channel))),q);
cristy0cf6da52012-08-25 00:35:24 +0000788 }
cristyed231572011-07-14 02:18:59 +0000789 p+=GetPixelChannels(image);
790 q+=GetPixelChannels(colorize_image);
cristy3ed852e2009-09-05 21:47:34 +0000791 }
792 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
793 if (sync == MagickFalse)
794 status=MagickFalse;
795 if (image->progress_monitor != (MagickProgressMonitor) NULL)
796 {
797 MagickBooleanType
798 proceed;
799
cristy319a1e72010-02-21 15:13:11 +0000800#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +0000801 #pragma omp critical (MagickCore_ColorizeImage)
cristy3ed852e2009-09-05 21:47:34 +0000802#endif
803 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
804 if (proceed == MagickFalse)
805 status=MagickFalse;
806 }
807 }
808 image_view=DestroyCacheView(image_view);
809 colorize_view=DestroyCacheView(colorize_view);
810 if (status == MagickFalse)
811 colorize_image=DestroyImage(colorize_image);
812 return(colorize_image);
813}
814
815/*
816%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
817% %
818% %
819% %
cristye6365592010-04-02 17:31:23 +0000820% C o l o r M a t r i x I m a g e %
821% %
822% %
823% %
824%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
825%
826% ColorMatrixImage() applies color transformation to an image. This method
827% permits saturation changes, hue rotation, luminance to alpha, and various
828% other effects. Although variable-sized transformation matrices can be used,
829% typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
830% (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
831% except offsets are in column 6 rather than 5 (in support of CMYKA images)
832% and offsets are normalized (divide Flash offset by 255).
833%
834% The format of the ColorMatrixImage method is:
835%
836% Image *ColorMatrixImage(const Image *image,
837% const KernelInfo *color_matrix,ExceptionInfo *exception)
838%
839% A description of each parameter follows:
840%
841% o image: the image.
842%
843% o color_matrix: the color matrix.
844%
845% o exception: return any errors or warnings in this structure.
846%
847*/
anthonyfd706f92012-01-19 04:22:02 +0000848/* FUTURE: modify to make use of a MagickMatrix Mutliply function
849 That should be provided in "matrix.c"
850 (ASIDE: actually distorts should do this too but currently doesn't)
851*/
852
cristye6365592010-04-02 17:31:23 +0000853MagickExport Image *ColorMatrixImage(const Image *image,
854 const KernelInfo *color_matrix,ExceptionInfo *exception)
855{
856#define ColorMatrixImageTag "ColorMatrix/Image"
857
858 CacheView
859 *color_view,
860 *image_view;
861
862 double
863 ColorMatrix[6][6] =
864 {
865 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
866 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
867 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
868 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
869 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
870 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
871 };
872
873 Image
874 *color_image;
875
cristye6365592010-04-02 17:31:23 +0000876 MagickBooleanType
877 status;
878
cristybb503372010-05-27 20:51:26 +0000879 MagickOffsetType
880 progress;
881
882 register ssize_t
cristye6365592010-04-02 17:31:23 +0000883 i;
884
cristybb503372010-05-27 20:51:26 +0000885 ssize_t
886 u,
887 v,
888 y;
889
cristye6365592010-04-02 17:31:23 +0000890 /*
anthonyfd706f92012-01-19 04:22:02 +0000891 Map given color_matrix, into a 6x6 matrix RGBKA and a constant
cristye6365592010-04-02 17:31:23 +0000892 */
893 assert(image != (Image *) NULL);
894 assert(image->signature == MagickSignature);
895 if (image->debug != MagickFalse)
896 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
897 assert(exception != (ExceptionInfo *) NULL);
898 assert(exception->signature == MagickSignature);
899 i=0;
cristybb503372010-05-27 20:51:26 +0000900 for (v=0; v < (ssize_t) color_matrix->height; v++)
901 for (u=0; u < (ssize_t) color_matrix->width; u++)
cristye6365592010-04-02 17:31:23 +0000902 {
903 if ((v < 6) && (u < 6))
904 ColorMatrix[v][u]=color_matrix->values[i];
905 i++;
906 }
907 /*
908 Initialize color image.
909 */
cristy12550e62010-06-07 12:46:40 +0000910 color_image=CloneImage(image,0,0,MagickTrue,exception);
cristye6365592010-04-02 17:31:23 +0000911 if (color_image == (Image *) NULL)
912 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000913 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
cristye6365592010-04-02 17:31:23 +0000914 {
cristye6365592010-04-02 17:31:23 +0000915 color_image=DestroyImage(color_image);
916 return((Image *) NULL);
917 }
918 if (image->debug != MagickFalse)
919 {
920 char
921 format[MaxTextExtent],
922 *message;
923
924 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
925 " ColorMatrix image with color matrix:");
926 message=AcquireString("");
927 for (v=0; v < 6; v++)
928 {
929 *message='\0';
cristyb51dff52011-05-19 16:55:47 +0000930 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
cristye6365592010-04-02 17:31:23 +0000931 (void) ConcatenateString(&message,format);
932 for (u=0; u < 6; u++)
933 {
cristyb51dff52011-05-19 16:55:47 +0000934 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
cristye6365592010-04-02 17:31:23 +0000935 ColorMatrix[v][u]);
936 (void) ConcatenateString(&message,format);
937 }
938 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
939 }
940 message=DestroyString(message);
941 }
942 /*
anthonyfd706f92012-01-19 04:22:02 +0000943 Apply the ColorMatrix to image.
cristye6365592010-04-02 17:31:23 +0000944 */
945 status=MagickTrue;
946 progress=0;
cristy46ff2672012-12-14 15:32:26 +0000947 image_view=AcquireVirtualCacheView(image,exception);
948 color_view=AcquireAuthenticCacheView(color_image,exception);
cristye6365592010-04-02 17:31:23 +0000949#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000950 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000951 magick_threads(image,color_image,image->rows,1)
cristye6365592010-04-02 17:31:23 +0000952#endif
cristybb503372010-05-27 20:51:26 +0000953 for (y=0; y < (ssize_t) image->rows; y++)
cristye6365592010-04-02 17:31:23 +0000954 {
cristyfcc25d92012-02-19 23:06:48 +0000955 PixelInfo
cristye6365592010-04-02 17:31:23 +0000956 pixel;
957
cristy4c08aed2011-07-01 19:47:50 +0000958 register const Quantum
cristye6365592010-04-02 17:31:23 +0000959 *restrict p;
960
cristy4c08aed2011-07-01 19:47:50 +0000961 register Quantum
962 *restrict q;
963
cristybb503372010-05-27 20:51:26 +0000964 register ssize_t
cristye6365592010-04-02 17:31:23 +0000965 x;
966
cristye6365592010-04-02 17:31:23 +0000967 if (status == MagickFalse)
968 continue;
969 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
970 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
971 exception);
cristy4c08aed2011-07-01 19:47:50 +0000972 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristye6365592010-04-02 17:31:23 +0000973 {
974 status=MagickFalse;
975 continue;
976 }
cristyfcc25d92012-02-19 23:06:48 +0000977 GetPixelInfo(image,&pixel);
cristybb503372010-05-27 20:51:26 +0000978 for (x=0; x < (ssize_t) image->columns; x++)
cristye6365592010-04-02 17:31:23 +0000979 {
cristybb503372010-05-27 20:51:26 +0000980 register ssize_t
cristye6365592010-04-02 17:31:23 +0000981 v;
982
cristybb503372010-05-27 20:51:26 +0000983 size_t
cristye6365592010-04-02 17:31:23 +0000984 height;
985
cristyfcc25d92012-02-19 23:06:48 +0000986 GetPixelInfoPixel(image,p,&pixel);
cristye6365592010-04-02 17:31:23 +0000987 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
cristybb503372010-05-27 20:51:26 +0000988 for (v=0; v < (ssize_t) height; v++)
cristye6365592010-04-02 17:31:23 +0000989 {
cristya19f1d72012-08-07 18:24:38 +0000990 double
cristyfcc25d92012-02-19 23:06:48 +0000991 sum;
992
993 sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
cristy4c08aed2011-07-01 19:47:50 +0000994 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
cristye6365592010-04-02 17:31:23 +0000995 if (image->colorspace == CMYKColorspace)
cristyfcc25d92012-02-19 23:06:48 +0000996 sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
cristy8a46d822012-08-28 23:32:39 +0000997 if (image->alpha_trait == BlendPixelTrait)
cristyfcc25d92012-02-19 23:06:48 +0000998 sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
999 sum+=QuantumRange*ColorMatrix[v][5];
cristye6365592010-04-02 17:31:23 +00001000 switch (v)
1001 {
cristyfcc25d92012-02-19 23:06:48 +00001002 case 0: pixel.red=sum; break;
1003 case 1: pixel.green=sum; break;
1004 case 2: pixel.blue=sum; break;
1005 case 3: pixel.black=sum; break;
1006 case 4: pixel.alpha=sum; break;
1007 default: break;
cristye6365592010-04-02 17:31:23 +00001008 }
1009 }
cristyfcc25d92012-02-19 23:06:48 +00001010 SetPixelInfoPixel(color_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +00001011 p+=GetPixelChannels(image);
1012 q+=GetPixelChannels(color_image);
cristye6365592010-04-02 17:31:23 +00001013 }
1014 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1015 status=MagickFalse;
1016 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1017 {
1018 MagickBooleanType
1019 proceed;
1020
1021#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00001022 #pragma omp critical (MagickCore_ColorMatrixImage)
cristye6365592010-04-02 17:31:23 +00001023#endif
1024 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1025 image->rows);
1026 if (proceed == MagickFalse)
1027 status=MagickFalse;
1028 }
1029 }
1030 color_view=DestroyCacheView(color_view);
1031 image_view=DestroyCacheView(image_view);
1032 if (status == MagickFalse)
1033 color_image=DestroyImage(color_image);
1034 return(color_image);
1035}
1036
1037/*
1038%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039% %
1040% %
1041% %
cristy3ed852e2009-09-05 21:47:34 +00001042+ D e s t r o y F x I n f o %
1043% %
1044% %
1045% %
1046%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1047%
1048% DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1049%
1050% The format of the DestroyFxInfo method is:
1051%
1052% ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1053%
1054% A description of each parameter follows:
1055%
1056% o fx_info: the fx info.
1057%
1058*/
cristy7832dc22011-09-05 01:21:53 +00001059MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
cristy3ed852e2009-09-05 21:47:34 +00001060{
cristybb503372010-05-27 20:51:26 +00001061 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001062 i;
1063
1064 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1065 fx_info->expression=DestroyString(fx_info->expression);
1066 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1067 fx_info->colors=DestroySplayTree(fx_info->colors);
cristy0ea377f2011-03-24 00:54:19 +00001068 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
cristyd76c51e2011-03-26 00:21:26 +00001069 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1070 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001071 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1072 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1073 return(fx_info);
1074}
1075
1076/*
1077%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1078% %
1079% %
1080% %
cristy3ed852e2009-09-05 21:47:34 +00001081+ F x E v a l u a t e C h a n n e l E x p r e s s i o n %
1082% %
1083% %
1084% %
1085%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1086%
1087% FxEvaluateChannelExpression() evaluates an expression and returns the
1088% results.
1089%
1090% The format of the FxEvaluateExpression method is:
1091%
cristya19f1d72012-08-07 18:24:38 +00001092% double FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00001093% const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00001094% double *alpha,Exceptioninfo *exception)
1095% double FxEvaluateExpression(FxInfo *fx_info,
1096% double *alpha,Exceptioninfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001097%
1098% A description of each parameter follows:
1099%
1100% o fx_info: the fx info.
1101%
1102% o channel: the channel.
1103%
1104% o x,y: the pixel position.
1105%
1106% o alpha: the result.
1107%
1108% o exception: return any errors or warnings in this structure.
1109%
1110*/
1111
cristy351842f2010-03-07 15:27:38 +00001112static inline double MagickMax(const double x,const double y)
1113{
1114 if (x > y)
1115 return(x);
1116 return(y);
1117}
1118
1119static inline double MagickMin(const double x,const double y)
1120{
1121 if (x < y)
1122 return(x);
1123 return(y);
1124}
1125
cristya19f1d72012-08-07 18:24:38 +00001126static double FxChannelStatistics(FxInfo *fx_info,Image *image,
cristy0568ffc2011-07-25 16:54:14 +00001127 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001128{
cristy5048d302012-08-07 01:05:16 +00001129 ChannelType
1130 channel_mask;
1131
cristy3ed852e2009-09-05 21:47:34 +00001132 char
1133 key[MaxTextExtent],
1134 statistic[MaxTextExtent];
1135
1136 const char
1137 *value;
1138
1139 register const char
1140 *p;
1141
cristy5048d302012-08-07 01:05:16 +00001142 channel_mask=UndefinedChannel;
cristy3ed852e2009-09-05 21:47:34 +00001143 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1144 if (*p == '.')
cristy3ed852e2009-09-05 21:47:34 +00001145 {
cristy5048d302012-08-07 01:05:16 +00001146 ssize_t
1147 option;
1148
1149 option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1);
1150 if (option >= 0)
1151 {
1152 channel=(PixelChannel) option;
1153 channel_mask=(ChannelType) (channel_mask | (1 << channel));
cristycf1296e2012-08-26 23:40:49 +00001154 SetPixelChannelMask(image,channel_mask);
cristy5048d302012-08-07 01:05:16 +00001155 }
cristy3ed852e2009-09-05 21:47:34 +00001156 }
cristyb51dff52011-05-19 16:55:47 +00001157 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
cristye8c25f92010-06-03 00:53:06 +00001158 (double) channel,symbol);
cristy3ed852e2009-09-05 21:47:34 +00001159 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1160 if (value != (const char *) NULL)
cristy5048d302012-08-07 01:05:16 +00001161 {
1162 if (channel_mask != UndefinedChannel)
cristycf1296e2012-08-26 23:40:49 +00001163 SetPixelChannelMask(image,channel_mask);
cristy5048d302012-08-07 01:05:16 +00001164 return(QuantumScale*StringToDouble(value,(char **) NULL));
1165 }
cristy3ed852e2009-09-05 21:47:34 +00001166 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1167 if (LocaleNCompare(symbol,"depth",5) == 0)
1168 {
cristybb503372010-05-27 20:51:26 +00001169 size_t
cristy3ed852e2009-09-05 21:47:34 +00001170 depth;
1171
cristyfefab1b2011-07-05 00:33:22 +00001172 depth=GetImageDepth(image,exception);
1173 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
cristy3ed852e2009-09-05 21:47:34 +00001174 }
1175 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1176 {
1177 double
1178 kurtosis,
1179 skewness;
1180
cristyd42d9952011-07-08 14:21:50 +00001181 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001182 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
cristy3ed852e2009-09-05 21:47:34 +00001183 }
1184 if (LocaleNCompare(symbol,"maxima",6) == 0)
1185 {
1186 double
1187 maxima,
1188 minima;
1189
cristyd42d9952011-07-08 14:21:50 +00001190 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001191 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
cristy3ed852e2009-09-05 21:47:34 +00001192 }
1193 if (LocaleNCompare(symbol,"mean",4) == 0)
1194 {
1195 double
1196 mean,
1197 standard_deviation;
1198
cristyd42d9952011-07-08 14:21:50 +00001199 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001200 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
cristy3ed852e2009-09-05 21:47:34 +00001201 }
1202 if (LocaleNCompare(symbol,"minima",6) == 0)
1203 {
1204 double
1205 maxima,
1206 minima;
1207
cristyd42d9952011-07-08 14:21:50 +00001208 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001209 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
cristy3ed852e2009-09-05 21:47:34 +00001210 }
1211 if (LocaleNCompare(symbol,"skewness",8) == 0)
1212 {
1213 double
1214 kurtosis,
1215 skewness;
1216
cristyd42d9952011-07-08 14:21:50 +00001217 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001218 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
cristy3ed852e2009-09-05 21:47:34 +00001219 }
1220 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1221 {
1222 double
1223 mean,
1224 standard_deviation;
1225
cristyd42d9952011-07-08 14:21:50 +00001226 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001227 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
cristy3ed852e2009-09-05 21:47:34 +00001228 standard_deviation);
1229 }
cristy5048d302012-08-07 01:05:16 +00001230 if (channel_mask != UndefinedChannel)
cristycf1296e2012-08-26 23:40:49 +00001231 SetPixelChannelMask(image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00001232 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1233 ConstantString(statistic));
cristydbdd0e32011-11-04 23:29:40 +00001234 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001235}
1236
cristya19f1d72012-08-07 18:24:38 +00001237static double
cristy0568ffc2011-07-25 16:54:14 +00001238 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
cristya19f1d72012-08-07 18:24:38 +00001239 const ssize_t,const char *,double *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +00001240
cristyb0aad4c2011-11-02 19:30:35 +00001241static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1242{
1243 if (beta != 0)
1244 return(FxGCD(beta,alpha % beta));
1245 return(alpha);
1246}
1247
cristy3ed852e2009-09-05 21:47:34 +00001248static inline const char *FxSubexpression(const char *expression,
1249 ExceptionInfo *exception)
1250{
1251 const char
1252 *subexpression;
1253
cristybb503372010-05-27 20:51:26 +00001254 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001255 level;
1256
1257 level=0;
1258 subexpression=expression;
1259 while ((*subexpression != '\0') &&
1260 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1261 {
1262 if (strchr("(",(int) *subexpression) != (char *) NULL)
1263 level++;
1264 else
1265 if (strchr(")",(int) *subexpression) != (char *) NULL)
1266 level--;
1267 subexpression++;
1268 }
1269 if (*subexpression == '\0')
1270 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001271 "UnbalancedParenthesis","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00001272 return(subexpression);
1273}
1274
cristya19f1d72012-08-07 18:24:38 +00001275static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001276 const ssize_t x,const ssize_t y,const char *expression,
1277 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001278{
1279 char
1280 *q,
1281 subexpression[MaxTextExtent],
1282 symbol[MaxTextExtent];
1283
1284 const char
1285 *p,
1286 *value;
1287
1288 Image
1289 *image;
1290
cristy4c08aed2011-07-01 19:47:50 +00001291 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001292 pixel;
1293
cristya19f1d72012-08-07 18:24:38 +00001294 double
cristy3ed852e2009-09-05 21:47:34 +00001295 alpha,
1296 beta;
1297
1298 PointInfo
1299 point;
1300
cristybb503372010-05-27 20:51:26 +00001301 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001302 i;
1303
1304 size_t
cristy1707c6c2012-01-18 23:30:54 +00001305 length,
cristy3ed852e2009-09-05 21:47:34 +00001306 level;
1307
1308 p=expression;
1309 i=GetImageIndexInList(fx_info->images);
1310 level=0;
1311 point.x=(double) x;
1312 point.y=(double) y;
1313 if (isalpha((int) *(p+1)) == 0)
1314 {
1315 if (strchr("suv",(int) *p) != (char *) NULL)
1316 {
1317 switch (*p)
1318 {
1319 case 's':
1320 default:
1321 {
1322 i=GetImageIndexInList(fx_info->images);
1323 break;
1324 }
1325 case 'u': i=0; break;
1326 case 'v': i=1; break;
1327 }
1328 p++;
1329 if (*p == '[')
1330 {
1331 level++;
1332 q=subexpression;
1333 for (p++; *p != '\0'; )
1334 {
1335 if (*p == '[')
1336 level++;
1337 else
1338 if (*p == ']')
1339 {
1340 level--;
1341 if (level == 0)
1342 break;
1343 }
1344 *q++=(*p++);
1345 }
1346 *q='\0';
1347 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1348 &beta,exception);
cristybb503372010-05-27 20:51:26 +00001349 i=(ssize_t) (alpha+0.5);
cristy3ed852e2009-09-05 21:47:34 +00001350 p++;
1351 }
1352 if (*p == '.')
1353 p++;
1354 }
1355 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1356 {
1357 p++;
1358 if (*p == '{')
1359 {
1360 level++;
1361 q=subexpression;
1362 for (p++; *p != '\0'; )
1363 {
1364 if (*p == '{')
1365 level++;
1366 else
1367 if (*p == '}')
1368 {
1369 level--;
1370 if (level == 0)
1371 break;
1372 }
1373 *q++=(*p++);
1374 }
1375 *q='\0';
1376 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1377 &beta,exception);
1378 point.x=alpha;
1379 point.y=beta;
1380 p++;
1381 }
1382 else
1383 if (*p == '[')
1384 {
1385 level++;
1386 q=subexpression;
1387 for (p++; *p != '\0'; )
1388 {
1389 if (*p == '[')
1390 level++;
1391 else
1392 if (*p == ']')
1393 {
1394 level--;
1395 if (level == 0)
1396 break;
1397 }
1398 *q++=(*p++);
1399 }
1400 *q='\0';
1401 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1402 &beta,exception);
1403 point.x+=alpha;
1404 point.y+=beta;
1405 p++;
1406 }
1407 if (*p == '.')
1408 p++;
1409 }
1410 }
1411 length=GetImageListLength(fx_info->images);
1412 while (i < 0)
cristybb503372010-05-27 20:51:26 +00001413 i+=(ssize_t) length;
cristy3ed852e2009-09-05 21:47:34 +00001414 i%=length;
1415 image=GetImageFromList(fx_info->images,i);
1416 if (image == (Image *) NULL)
1417 {
1418 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001419 "NoSuchImage","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00001420 return(0.0);
1421 }
cristy4c08aed2011-07-01 19:47:50 +00001422 GetPixelInfo(image,&pixel);
1423 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
cristy4f820712011-04-01 12:35:43 +00001424 point.x,point.y,&pixel,exception);
cristy1707c6c2012-01-18 23:30:54 +00001425 if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
1426 (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
cristy3ed852e2009-09-05 21:47:34 +00001427 (LocaleCompare(p,"saturation") != 0) &&
1428 (LocaleCompare(p,"lightness") != 0))
1429 {
1430 char
1431 name[MaxTextExtent];
1432
1433 (void) CopyMagickString(name,p,MaxTextExtent);
1434 for (q=name+(strlen(name)-1); q > name; q--)
1435 {
1436 if (*q == ')')
1437 break;
1438 if (*q == '.')
1439 {
1440 *q='\0';
1441 break;
1442 }
1443 }
1444 if ((strlen(name) > 2) &&
1445 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1446 {
cristy4c08aed2011-07-01 19:47:50 +00001447 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001448 *color;
1449
cristy4c08aed2011-07-01 19:47:50 +00001450 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1451 if (color != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001452 {
1453 pixel=(*color);
1454 p+=strlen(name);
1455 }
1456 else
cristy1707c6c2012-01-18 23:30:54 +00001457 {
1458 MagickBooleanType
1459 status;
1460
1461 status=QueryColorCompliance(name,AllCompliance,&pixel,
1462 fx_info->exception);
1463 if (status != MagickFalse)
1464 {
1465 (void) AddValueToSplayTree(fx_info->colors,ConstantString(
1466 name),ClonePixelInfo(&pixel));
1467 p+=strlen(name);
1468 }
1469 }
cristy3ed852e2009-09-05 21:47:34 +00001470 }
1471 }
1472 (void) CopyMagickString(symbol,p,MaxTextExtent);
1473 StripString(symbol);
1474 if (*symbol == '\0')
1475 {
1476 switch (channel)
1477 {
cristy0568ffc2011-07-25 16:54:14 +00001478 case RedPixelChannel: return(QuantumScale*pixel.red);
1479 case GreenPixelChannel: return(QuantumScale*pixel.green);
1480 case BluePixelChannel: return(QuantumScale*pixel.blue);
1481 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001482 {
1483 if (image->colorspace != CMYKColorspace)
1484 {
1485 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00001486 ImageError,"ColorSeparatedImageRequired","`%s'",
cristy3ed852e2009-09-05 21:47:34 +00001487 image->filename);
1488 return(0.0);
1489 }
cristy4c08aed2011-07-01 19:47:50 +00001490 return(QuantumScale*pixel.black);
1491 }
cristy0568ffc2011-07-25 16:54:14 +00001492 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001493 {
cristya19f1d72012-08-07 18:24:38 +00001494 double
cristy4c08aed2011-07-01 19:47:50 +00001495 alpha;
1496
cristy8a46d822012-08-28 23:32:39 +00001497 if (pixel.alpha_trait != BlendPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +00001498 return(1.0);
cristya19f1d72012-08-07 18:24:38 +00001499 alpha=(double) (QuantumScale*pixel.alpha);
cristy4c08aed2011-07-01 19:47:50 +00001500 return(alpha);
cristy3ed852e2009-09-05 21:47:34 +00001501 }
cristya382aca2011-12-06 18:22:48 +00001502 case IndexPixelChannel:
1503 return(0.0);
cristyb3a73b52011-07-26 01:34:43 +00001504 case IntensityPixelChannel:
cristyf364ed42010-12-15 01:54:43 +00001505 {
cristy4c08aed2011-07-01 19:47:50 +00001506 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristyf364ed42010-12-15 01:54:43 +00001507 }
cristy3ed852e2009-09-05 21:47:34 +00001508 default:
1509 break;
1510 }
1511 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001512 "UnableToParseExpression","`%s'",p);
cristy3ed852e2009-09-05 21:47:34 +00001513 return(0.0);
1514 }
1515 switch (*symbol)
1516 {
1517 case 'A':
1518 case 'a':
1519 {
1520 if (LocaleCompare(symbol,"a") == 0)
cristya19f1d72012-08-07 18:24:38 +00001521 return((double) (QuantumScale*pixel.alpha));
cristy3ed852e2009-09-05 21:47:34 +00001522 break;
1523 }
1524 case 'B':
1525 case 'b':
1526 {
1527 if (LocaleCompare(symbol,"b") == 0)
1528 return(QuantumScale*pixel.blue);
1529 break;
1530 }
1531 case 'C':
1532 case 'c':
1533 {
1534 if (LocaleNCompare(symbol,"channel",7) == 0)
1535 {
1536 GeometryInfo
1537 channel_info;
1538
1539 MagickStatusType
1540 flags;
1541
1542 flags=ParseGeometry(symbol+7,&channel_info);
1543 if (image->colorspace == CMYKColorspace)
1544 switch (channel)
1545 {
cristy0568ffc2011-07-25 16:54:14 +00001546 case CyanPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001547 {
1548 if ((flags & RhoValue) == 0)
1549 return(0.0);
1550 return(channel_info.rho);
1551 }
cristy0568ffc2011-07-25 16:54:14 +00001552 case MagentaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001553 {
1554 if ((flags & SigmaValue) == 0)
1555 return(0.0);
1556 return(channel_info.sigma);
1557 }
cristy0568ffc2011-07-25 16:54:14 +00001558 case YellowPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001559 {
1560 if ((flags & XiValue) == 0)
1561 return(0.0);
1562 return(channel_info.xi);
1563 }
cristy0568ffc2011-07-25 16:54:14 +00001564 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001565 {
1566 if ((flags & PsiValue) == 0)
1567 return(0.0);
1568 return(channel_info.psi);
1569 }
cristy0568ffc2011-07-25 16:54:14 +00001570 case AlphaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001571 {
1572 if ((flags & ChiValue) == 0)
1573 return(0.0);
1574 return(channel_info.chi);
1575 }
1576 default:
1577 return(0.0);
1578 }
1579 switch (channel)
1580 {
cristy0568ffc2011-07-25 16:54:14 +00001581 case RedPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001582 {
1583 if ((flags & RhoValue) == 0)
1584 return(0.0);
1585 return(channel_info.rho);
1586 }
cristy0568ffc2011-07-25 16:54:14 +00001587 case GreenPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001588 {
1589 if ((flags & SigmaValue) == 0)
1590 return(0.0);
1591 return(channel_info.sigma);
1592 }
cristy0568ffc2011-07-25 16:54:14 +00001593 case BluePixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001594 {
1595 if ((flags & XiValue) == 0)
1596 return(0.0);
1597 return(channel_info.xi);
1598 }
cristy0568ffc2011-07-25 16:54:14 +00001599 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001600 {
1601 if ((flags & ChiValue) == 0)
1602 return(0.0);
1603 return(channel_info.chi);
1604 }
cristy0568ffc2011-07-25 16:54:14 +00001605 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001606 {
1607 if ((flags & PsiValue) == 0)
1608 return(0.0);
1609 return(channel_info.psi);
1610 }
cristy3ed852e2009-09-05 21:47:34 +00001611 default:
1612 return(0.0);
1613 }
1614 return(0.0);
1615 }
1616 if (LocaleCompare(symbol,"c") == 0)
1617 return(QuantumScale*pixel.red);
1618 break;
1619 }
1620 case 'D':
1621 case 'd':
1622 {
1623 if (LocaleNCompare(symbol,"depth",5) == 0)
1624 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1625 break;
1626 }
1627 case 'G':
1628 case 'g':
1629 {
1630 if (LocaleCompare(symbol,"g") == 0)
1631 return(QuantumScale*pixel.green);
1632 break;
1633 }
1634 case 'K':
1635 case 'k':
1636 {
1637 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1638 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1639 if (LocaleCompare(symbol,"k") == 0)
1640 {
1641 if (image->colorspace != CMYKColorspace)
1642 {
1643 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00001644 OptionError,"ColorSeparatedImageRequired","`%s'",
cristy3ed852e2009-09-05 21:47:34 +00001645 image->filename);
1646 return(0.0);
1647 }
cristy4c08aed2011-07-01 19:47:50 +00001648 return(QuantumScale*pixel.black);
cristy3ed852e2009-09-05 21:47:34 +00001649 }
1650 break;
1651 }
1652 case 'H':
1653 case 'h':
1654 {
1655 if (LocaleCompare(symbol,"h") == 0)
cristya19f1d72012-08-07 18:24:38 +00001656 return((double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001657 if (LocaleCompare(symbol,"hue") == 0)
1658 {
1659 double
1660 hue,
1661 lightness,
1662 saturation;
1663
cristy0a39a5c2012-06-27 12:51:45 +00001664 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001665 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001666 return(hue);
1667 }
1668 break;
1669 }
1670 case 'I':
1671 case 'i':
1672 {
1673 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1674 (LocaleCompare(symbol,"image.minima") == 0) ||
1675 (LocaleCompare(symbol,"image.maxima") == 0) ||
1676 (LocaleCompare(symbol,"image.mean") == 0) ||
1677 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1678 (LocaleCompare(symbol,"image.skewness") == 0) ||
1679 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1680 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1681 if (LocaleCompare(symbol,"image.resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001682 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001683 if (LocaleCompare(symbol,"image.resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001684 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001685 if (LocaleCompare(symbol,"intensity") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001686 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001687 if (LocaleCompare(symbol,"i") == 0)
cristya19f1d72012-08-07 18:24:38 +00001688 return((double) x);
cristy3ed852e2009-09-05 21:47:34 +00001689 break;
1690 }
1691 case 'J':
1692 case 'j':
1693 {
1694 if (LocaleCompare(symbol,"j") == 0)
cristya19f1d72012-08-07 18:24:38 +00001695 return((double) y);
cristy3ed852e2009-09-05 21:47:34 +00001696 break;
1697 }
1698 case 'L':
1699 case 'l':
1700 {
1701 if (LocaleCompare(symbol,"lightness") == 0)
1702 {
1703 double
1704 hue,
1705 lightness,
1706 saturation;
1707
cristy0a39a5c2012-06-27 12:51:45 +00001708 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001709 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001710 return(lightness);
1711 }
1712 if (LocaleCompare(symbol,"luminance") == 0)
1713 {
1714 double
1715 luminence;
1716
cristya86a5cb2012-10-14 13:40:33 +00001717 luminence=0.21267f*pixel.red+0.71516f*pixel.green+0.07217f*pixel.blue;
cristy3ed852e2009-09-05 21:47:34 +00001718 return(QuantumScale*luminence);
1719 }
1720 break;
1721 }
1722 case 'M':
1723 case 'm':
1724 {
1725 if (LocaleNCompare(symbol,"maxima",6) == 0)
1726 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1727 if (LocaleNCompare(symbol,"mean",4) == 0)
1728 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1729 if (LocaleNCompare(symbol,"minima",6) == 0)
1730 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1731 if (LocaleCompare(symbol,"m") == 0)
1732 return(QuantumScale*pixel.blue);
1733 break;
1734 }
1735 case 'N':
1736 case 'n':
1737 {
1738 if (LocaleCompare(symbol,"n") == 0)
cristya19f1d72012-08-07 18:24:38 +00001739 return((double) GetImageListLength(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001740 break;
1741 }
1742 case 'O':
1743 case 'o':
1744 {
1745 if (LocaleCompare(symbol,"o") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001746 return(QuantumScale*pixel.alpha);
cristy3ed852e2009-09-05 21:47:34 +00001747 break;
1748 }
1749 case 'P':
1750 case 'p':
1751 {
1752 if (LocaleCompare(symbol,"page.height") == 0)
cristya19f1d72012-08-07 18:24:38 +00001753 return((double) image->page.height);
cristy3ed852e2009-09-05 21:47:34 +00001754 if (LocaleCompare(symbol,"page.width") == 0)
cristya19f1d72012-08-07 18:24:38 +00001755 return((double) image->page.width);
cristy3ed852e2009-09-05 21:47:34 +00001756 if (LocaleCompare(symbol,"page.x") == 0)
cristya19f1d72012-08-07 18:24:38 +00001757 return((double) image->page.x);
cristy3ed852e2009-09-05 21:47:34 +00001758 if (LocaleCompare(symbol,"page.y") == 0)
cristya19f1d72012-08-07 18:24:38 +00001759 return((double) image->page.y);
cristy3ed852e2009-09-05 21:47:34 +00001760 break;
1761 }
1762 case 'R':
1763 case 'r':
1764 {
1765 if (LocaleCompare(symbol,"resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001766 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001767 if (LocaleCompare(symbol,"resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001768 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001769 if (LocaleCompare(symbol,"r") == 0)
1770 return(QuantumScale*pixel.red);
1771 break;
1772 }
1773 case 'S':
1774 case 's':
1775 {
1776 if (LocaleCompare(symbol,"saturation") == 0)
1777 {
1778 double
1779 hue,
1780 lightness,
1781 saturation;
1782
cristy0a39a5c2012-06-27 12:51:45 +00001783 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001784 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001785 return(saturation);
1786 }
1787 if (LocaleNCompare(symbol,"skewness",8) == 0)
1788 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1789 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1790 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1791 break;
1792 }
1793 case 'T':
1794 case 't':
1795 {
1796 if (LocaleCompare(symbol,"t") == 0)
cristya19f1d72012-08-07 18:24:38 +00001797 return((double) GetImageIndexInList(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001798 break;
1799 }
1800 case 'W':
1801 case 'w':
1802 {
1803 if (LocaleCompare(symbol,"w") == 0)
cristya19f1d72012-08-07 18:24:38 +00001804 return((double) image->columns);
cristy3ed852e2009-09-05 21:47:34 +00001805 break;
1806 }
1807 case 'Y':
1808 case 'y':
1809 {
1810 if (LocaleCompare(symbol,"y") == 0)
1811 return(QuantumScale*pixel.green);
1812 break;
1813 }
1814 case 'Z':
1815 case 'z':
1816 {
1817 if (LocaleCompare(symbol,"z") == 0)
1818 {
cristya19f1d72012-08-07 18:24:38 +00001819 double
cristy3ed852e2009-09-05 21:47:34 +00001820 depth;
1821
cristya19f1d72012-08-07 18:24:38 +00001822 depth=(double) GetImageDepth(image,fx_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001823 return(depth);
1824 }
1825 break;
1826 }
1827 default:
1828 break;
1829 }
1830 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1831 if (value != (const char *) NULL)
cristya19f1d72012-08-07 18:24:38 +00001832 return((double) StringToDouble(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001833 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001834 "UnableToParseExpression","`%s'",symbol);
cristy3ed852e2009-09-05 21:47:34 +00001835 return(0.0);
1836}
1837
1838static const char *FxOperatorPrecedence(const char *expression,
1839 ExceptionInfo *exception)
1840{
1841 typedef enum
1842 {
1843 UndefinedPrecedence,
1844 NullPrecedence,
1845 BitwiseComplementPrecedence,
1846 ExponentPrecedence,
cristy116af162010-08-13 01:25:47 +00001847 ExponentialNotationPrecedence,
cristy3ed852e2009-09-05 21:47:34 +00001848 MultiplyPrecedence,
1849 AdditionPrecedence,
1850 ShiftPrecedence,
1851 RelationalPrecedence,
1852 EquivalencyPrecedence,
1853 BitwiseAndPrecedence,
1854 BitwiseOrPrecedence,
1855 LogicalAndPrecedence,
1856 LogicalOrPrecedence,
1857 TernaryPrecedence,
1858 AssignmentPrecedence,
1859 CommaPrecedence,
1860 SeparatorPrecedence
1861 } FxPrecedence;
1862
1863 FxPrecedence
1864 precedence,
1865 target;
1866
1867 register const char
1868 *subexpression;
1869
1870 register int
1871 c;
1872
cristybb503372010-05-27 20:51:26 +00001873 size_t
cristy3ed852e2009-09-05 21:47:34 +00001874 level;
1875
1876 c=0;
1877 level=0;
1878 subexpression=(const char *) NULL;
1879 target=NullPrecedence;
1880 while (*expression != '\0')
1881 {
1882 precedence=UndefinedPrecedence;
1883 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1884 {
1885 expression++;
1886 continue;
1887 }
cristy488fa882010-03-01 22:34:24 +00001888 switch (*expression)
1889 {
1890 case 'A':
1891 case 'a':
cristy3ed852e2009-09-05 21:47:34 +00001892 {
cristyb33454f2011-08-03 02:10:45 +00001893#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00001894 if (LocaleNCompare(expression,"acosh",5) == 0)
1895 {
1896 expression+=5;
1897 break;
1898 }
cristyb33454f2011-08-03 02:10:45 +00001899#endif
1900#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00001901 if (LocaleNCompare(expression,"asinh",5) == 0)
1902 {
1903 expression+=5;
1904 break;
1905 }
cristyb33454f2011-08-03 02:10:45 +00001906#endif
1907#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00001908 if (LocaleNCompare(expression,"atanh",5) == 0)
cristy488fa882010-03-01 22:34:24 +00001909 {
1910 expression+=5;
1911 break;
1912 }
cristyb33454f2011-08-03 02:10:45 +00001913#endif
anthony62838e52012-05-24 12:41:54 +00001914 if (LocaleNCompare(expression,"atan2",5) == 0)
1915 {
1916 expression+=5;
1917 break;
1918 }
cristy488fa882010-03-01 22:34:24 +00001919 break;
cristy3ed852e2009-09-05 21:47:34 +00001920 }
cristy62d455f2011-11-03 11:42:28 +00001921 case 'E':
1922 case 'e':
1923 {
1924 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1925 (LocaleNCompare(expression,"E-",2) == 0))
1926 {
1927 expression+=2; /* scientific notation */
1928 break;
1929 }
1930 }
cristy488fa882010-03-01 22:34:24 +00001931 case 'J':
1932 case 'j':
1933 {
1934 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1935 (LocaleNCompare(expression,"j1",2) == 0))
1936 {
1937 expression+=2;
1938 break;
1939 }
1940 break;
1941 }
cristy2def9322010-06-18 23:59:37 +00001942 case '#':
1943 {
1944 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1945 expression++;
1946 break;
1947 }
cristy488fa882010-03-01 22:34:24 +00001948 default:
1949 break;
1950 }
cristy3ed852e2009-09-05 21:47:34 +00001951 if ((c == (int) '{') || (c == (int) '['))
1952 level++;
1953 else
1954 if ((c == (int) '}') || (c == (int) ']'))
1955 level--;
1956 if (level == 0)
1957 switch ((unsigned char) *expression)
1958 {
1959 case '~':
1960 case '!':
1961 {
1962 precedence=BitwiseComplementPrecedence;
1963 break;
1964 }
1965 case '^':
cristy6621e252010-08-13 00:42:57 +00001966 case '@':
cristy3ed852e2009-09-05 21:47:34 +00001967 {
1968 precedence=ExponentPrecedence;
1969 break;
1970 }
1971 default:
1972 {
1973 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1974 (strchr(")",c) != (char *) NULL))) &&
1975 (((islower((int) ((char) *expression)) != 0) ||
1976 (strchr("(",(int) *expression) != (char *) NULL)) ||
1977 ((isdigit((int) ((char) c)) == 0) &&
1978 (isdigit((int) ((char) *expression)) != 0))) &&
1979 (strchr("xy",(int) *expression) == (char *) NULL))
1980 precedence=MultiplyPrecedence;
1981 break;
1982 }
1983 case '*':
1984 case '/':
1985 case '%':
1986 {
1987 precedence=MultiplyPrecedence;
1988 break;
1989 }
1990 case '+':
1991 case '-':
1992 {
1993 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1994 (isalpha(c) != 0))
1995 precedence=AdditionPrecedence;
1996 break;
1997 }
1998 case LeftShiftOperator:
1999 case RightShiftOperator:
2000 {
2001 precedence=ShiftPrecedence;
2002 break;
2003 }
2004 case '<':
2005 case LessThanEqualOperator:
2006 case GreaterThanEqualOperator:
2007 case '>':
2008 {
2009 precedence=RelationalPrecedence;
2010 break;
2011 }
2012 case EqualOperator:
2013 case NotEqualOperator:
2014 {
2015 precedence=EquivalencyPrecedence;
2016 break;
2017 }
2018 case '&':
2019 {
2020 precedence=BitwiseAndPrecedence;
2021 break;
2022 }
2023 case '|':
2024 {
2025 precedence=BitwiseOrPrecedence;
2026 break;
2027 }
2028 case LogicalAndOperator:
2029 {
2030 precedence=LogicalAndPrecedence;
2031 break;
2032 }
2033 case LogicalOrOperator:
2034 {
2035 precedence=LogicalOrPrecedence;
2036 break;
2037 }
cristy116af162010-08-13 01:25:47 +00002038 case ExponentialNotation:
2039 {
2040 precedence=ExponentialNotationPrecedence;
2041 break;
2042 }
cristy3ed852e2009-09-05 21:47:34 +00002043 case ':':
2044 case '?':
2045 {
2046 precedence=TernaryPrecedence;
2047 break;
2048 }
2049 case '=':
2050 {
2051 precedence=AssignmentPrecedence;
2052 break;
2053 }
2054 case ',':
2055 {
2056 precedence=CommaPrecedence;
2057 break;
2058 }
2059 case ';':
2060 {
2061 precedence=SeparatorPrecedence;
2062 break;
2063 }
2064 }
2065 if ((precedence == BitwiseComplementPrecedence) ||
2066 (precedence == TernaryPrecedence) ||
2067 (precedence == AssignmentPrecedence))
2068 {
2069 if (precedence > target)
2070 {
2071 /*
2072 Right-to-left associativity.
2073 */
2074 target=precedence;
2075 subexpression=expression;
2076 }
2077 }
2078 else
2079 if (precedence >= target)
2080 {
2081 /*
2082 Left-to-right associativity.
2083 */
2084 target=precedence;
2085 subexpression=expression;
2086 }
2087 if (strchr("(",(int) *expression) != (char *) NULL)
2088 expression=FxSubexpression(expression,exception);
2089 c=(int) (*expression++);
2090 }
2091 return(subexpression);
2092}
2093
cristya19f1d72012-08-07 18:24:38 +00002094static double FxEvaluateSubexpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002095 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00002096 const char *expression,double *beta,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002097{
2098 char
2099 *q,
2100 subexpression[MaxTextExtent];
2101
cristya19f1d72012-08-07 18:24:38 +00002102 double
cristy3ed852e2009-09-05 21:47:34 +00002103 alpha,
2104 gamma;
2105
2106 register const char
2107 *p;
2108
2109 *beta=0.0;
2110 if (exception->severity != UndefinedException)
2111 return(0.0);
2112 while (isspace((int) *expression) != 0)
2113 expression++;
2114 if (*expression == '\0')
2115 {
2116 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00002117 "MissingExpression","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002118 return(0.0);
2119 }
cristy66322f02010-05-17 11:40:48 +00002120 *subexpression='\0';
cristy3ed852e2009-09-05 21:47:34 +00002121 p=FxOperatorPrecedence(expression,exception);
2122 if (p != (const char *) NULL)
2123 {
2124 (void) CopyMagickString(subexpression,expression,(size_t)
2125 (p-expression+1));
2126 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2127 exception);
2128 switch ((unsigned char) *p)
2129 {
2130 case '~':
2131 {
2132 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002133 *beta=(double) (~(size_t) *beta);
cristy3ed852e2009-09-05 21:47:34 +00002134 return(*beta);
2135 }
2136 case '!':
2137 {
2138 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2139 return(*beta == 0.0 ? 1.0 : 0.0);
2140 }
2141 case '^':
2142 {
2143 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2144 channel,x,y,++p,beta,exception));
2145 return(*beta);
2146 }
2147 case '*':
cristy116af162010-08-13 01:25:47 +00002148 case ExponentialNotation:
cristy3ed852e2009-09-05 21:47:34 +00002149 {
2150 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2151 return(alpha*(*beta));
2152 }
2153 case '/':
2154 {
2155 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2156 if (*beta == 0.0)
2157 {
2158 if (exception->severity == UndefinedException)
2159 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002160 OptionError,"DivideByZero","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002161 return(0.0);
2162 }
2163 return(alpha/(*beta));
2164 }
2165 case '%':
2166 {
2167 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2168 *beta=fabs(floor(((double) *beta)+0.5));
2169 if (*beta == 0.0)
2170 {
2171 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002172 OptionError,"DivideByZero","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002173 return(0.0);
2174 }
2175 return(fmod((double) alpha,(double) *beta));
2176 }
2177 case '+':
2178 {
2179 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2180 return(alpha+(*beta));
2181 }
2182 case '-':
2183 {
2184 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2185 return(alpha-(*beta));
2186 }
2187 case LeftShiftOperator:
2188 {
2189 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002190 *beta=(double) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002191 return(*beta);
2192 }
2193 case RightShiftOperator:
2194 {
2195 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002196 *beta=(double) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002197 return(*beta);
2198 }
2199 case '<':
2200 {
2201 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2202 return(alpha < *beta ? 1.0 : 0.0);
2203 }
2204 case LessThanEqualOperator:
2205 {
2206 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2207 return(alpha <= *beta ? 1.0 : 0.0);
2208 }
2209 case '>':
2210 {
2211 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2212 return(alpha > *beta ? 1.0 : 0.0);
2213 }
2214 case GreaterThanEqualOperator:
2215 {
2216 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2217 return(alpha >= *beta ? 1.0 : 0.0);
2218 }
2219 case EqualOperator:
2220 {
2221 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristy9b528342012-06-02 00:59:20 +00002222 return(fabs(alpha-(*beta)) < MagickEpsilon ? MagickEpsilon : 0.0);
cristy3ed852e2009-09-05 21:47:34 +00002223 }
2224 case NotEqualOperator:
2225 {
2226 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristy972050b2012-06-04 22:09:17 +00002227 return(fabs(alpha-(*beta)) >= MagickEpsilon ? 1.0 : 0.0);
cristy3ed852e2009-09-05 21:47:34 +00002228 }
2229 case '&':
2230 {
2231 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002232 *beta=(double) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002233 return(*beta);
2234 }
2235 case '|':
2236 {
2237 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002238 *beta=(double) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002239 return(*beta);
2240 }
2241 case LogicalAndOperator:
2242 {
2243 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2244 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2245 return(*beta);
2246 }
2247 case LogicalOrOperator:
2248 {
2249 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2250 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2251 return(*beta);
2252 }
2253 case '?':
2254 {
cristya19f1d72012-08-07 18:24:38 +00002255 double
cristy3ed852e2009-09-05 21:47:34 +00002256 gamma;
2257
2258 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2259 q=subexpression;
2260 p=StringToken(":",&q);
2261 if (q == (char *) NULL)
2262 {
2263 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002264 OptionError,"UnableToParseExpression","`%s'",subexpression);
cristy3ed852e2009-09-05 21:47:34 +00002265 return(0.0);
2266 }
cristy972050b2012-06-04 22:09:17 +00002267 if (fabs((double) alpha) >= MagickEpsilon)
cristy3ed852e2009-09-05 21:47:34 +00002268 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2269 else
2270 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2271 return(gamma);
2272 }
2273 case '=':
2274 {
2275 char
2276 numeric[MaxTextExtent];
2277
2278 q=subexpression;
2279 while (isalpha((int) ((unsigned char) *q)) != 0)
2280 q++;
2281 if (*q != '\0')
2282 {
2283 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002284 OptionError,"UnableToParseExpression","`%s'",subexpression);
cristy3ed852e2009-09-05 21:47:34 +00002285 return(0.0);
2286 }
2287 ClearMagickException(exception);
2288 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristyb51dff52011-05-19 16:55:47 +00002289 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
cristy8cd5b312010-01-07 01:10:24 +00002290 *beta);
cristy3ed852e2009-09-05 21:47:34 +00002291 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2292 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2293 subexpression),ConstantString(numeric));
2294 return(*beta);
2295 }
2296 case ',':
2297 {
2298 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2299 return(alpha);
2300 }
2301 case ';':
2302 {
2303 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2304 return(*beta);
2305 }
2306 default:
2307 {
2308 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2309 exception);
2310 return(gamma);
2311 }
2312 }
2313 }
2314 if (strchr("(",(int) *expression) != (char *) NULL)
2315 {
2316 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2317 subexpression[strlen(subexpression)-1]='\0';
2318 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2319 exception);
2320 return(gamma);
2321 }
cristy8b8a3ae2010-10-23 18:49:46 +00002322 switch (*expression)
cristy3ed852e2009-09-05 21:47:34 +00002323 {
2324 case '+':
2325 {
2326 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2327 exception);
2328 return(1.0*gamma);
2329 }
2330 case '-':
2331 {
2332 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2333 exception);
2334 return(-1.0*gamma);
2335 }
2336 case '~':
2337 {
2338 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2339 exception);
cristya19f1d72012-08-07 18:24:38 +00002340 return((double) (~(size_t) (gamma+0.5)));
cristy3ed852e2009-09-05 21:47:34 +00002341 }
2342 case 'A':
2343 case 'a':
2344 {
2345 if (LocaleNCompare(expression,"abs",3) == 0)
2346 {
2347 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2348 exception);
cristya19f1d72012-08-07 18:24:38 +00002349 return((double) fabs((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002350 }
cristyb33454f2011-08-03 02:10:45 +00002351#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00002352 if (LocaleNCompare(expression,"acosh",5) == 0)
2353 {
2354 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2355 exception);
cristya19f1d72012-08-07 18:24:38 +00002356 return((double) acosh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002357 }
cristyb33454f2011-08-03 02:10:45 +00002358#endif
cristy3ed852e2009-09-05 21:47:34 +00002359 if (LocaleNCompare(expression,"acos",4) == 0)
2360 {
2361 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2362 exception);
cristya19f1d72012-08-07 18:24:38 +00002363 return((double) acos((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002364 }
cristy43c22f42010-03-30 12:34:07 +00002365#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002366 if (LocaleNCompare(expression,"airy",4) == 0)
2367 {
2368 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2369 exception);
2370 if (alpha == 0.0)
cristy2dd03222010-03-30 22:12:11 +00002371 return(1.0);
2372 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
cristy43c22f42010-03-30 12:34:07 +00002373 return(gamma*gamma);
cristyee56cf12010-03-01 22:17:06 +00002374 }
cristy43c22f42010-03-30 12:34:07 +00002375#endif
cristyb33454f2011-08-03 02:10:45 +00002376#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00002377 if (LocaleNCompare(expression,"asinh",5) == 0)
2378 {
2379 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2380 exception);
cristya19f1d72012-08-07 18:24:38 +00002381 return((double) asinh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002382 }
cristyb33454f2011-08-03 02:10:45 +00002383#endif
cristy3ed852e2009-09-05 21:47:34 +00002384 if (LocaleNCompare(expression,"asin",4) == 0)
2385 {
2386 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2387 exception);
cristya19f1d72012-08-07 18:24:38 +00002388 return((double) asin((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002389 }
2390 if (LocaleNCompare(expression,"alt",3) == 0)
2391 {
2392 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2393 exception);
cristybb503372010-05-27 20:51:26 +00002394 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
cristy3ed852e2009-09-05 21:47:34 +00002395 }
2396 if (LocaleNCompare(expression,"atan2",5) == 0)
2397 {
2398 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2399 exception);
cristya19f1d72012-08-07 18:24:38 +00002400 return((double) atan2((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002401 }
cristyb33454f2011-08-03 02:10:45 +00002402#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00002403 if (LocaleNCompare(expression,"atanh",5) == 0)
2404 {
2405 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2406 exception);
cristya19f1d72012-08-07 18:24:38 +00002407 return((double) atanh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002408 }
cristyb33454f2011-08-03 02:10:45 +00002409#endif
cristy3ed852e2009-09-05 21:47:34 +00002410 if (LocaleNCompare(expression,"atan",4) == 0)
2411 {
2412 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2413 exception);
cristya19f1d72012-08-07 18:24:38 +00002414 return((double) atan((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002415 }
2416 if (LocaleCompare(expression,"a") == 0)
2417 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2418 break;
2419 }
2420 case 'B':
2421 case 'b':
2422 {
2423 if (LocaleCompare(expression,"b") == 0)
2424 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2425 break;
2426 }
2427 case 'C':
2428 case 'c':
2429 {
2430 if (LocaleNCompare(expression,"ceil",4) == 0)
2431 {
2432 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2433 exception);
cristya19f1d72012-08-07 18:24:38 +00002434 return((double) ceil((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002435 }
2436 if (LocaleNCompare(expression,"cosh",4) == 0)
2437 {
2438 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2439 exception);
cristya19f1d72012-08-07 18:24:38 +00002440 return((double) cosh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002441 }
2442 if (LocaleNCompare(expression,"cos",3) == 0)
2443 {
2444 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2445 exception);
cristya19f1d72012-08-07 18:24:38 +00002446 return((double) cos((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002447 }
2448 if (LocaleCompare(expression,"c") == 0)
2449 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2450 break;
2451 }
2452 case 'D':
2453 case 'd':
2454 {
2455 if (LocaleNCompare(expression,"debug",5) == 0)
2456 {
2457 const char
2458 *type;
2459
2460 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2461 exception);
2462 if (fx_info->images->colorspace == CMYKColorspace)
2463 switch (channel)
2464 {
cristy0568ffc2011-07-25 16:54:14 +00002465 case CyanPixelChannel: type="cyan"; break;
2466 case MagentaPixelChannel: type="magenta"; break;
2467 case YellowPixelChannel: type="yellow"; break;
2468 case AlphaPixelChannel: type="opacity"; break;
2469 case BlackPixelChannel: type="black"; break;
cristy3ed852e2009-09-05 21:47:34 +00002470 default: type="unknown"; break;
2471 }
2472 else
2473 switch (channel)
2474 {
cristy0568ffc2011-07-25 16:54:14 +00002475 case RedPixelChannel: type="red"; break;
2476 case GreenPixelChannel: type="green"; break;
2477 case BluePixelChannel: type="blue"; break;
2478 case AlphaPixelChannel: type="opacity"; break;
cristy3ed852e2009-09-05 21:47:34 +00002479 default: type="unknown"; break;
2480 }
2481 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2482 if (strlen(subexpression) > 1)
2483 subexpression[strlen(subexpression)-1]='\0';
2484 if (fx_info->file != (FILE *) NULL)
cristy1707c6c2012-01-18 23:30:54 +00002485 (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: "
2486 "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type,
2487 subexpression,GetMagickPrecision(),(double) alpha);
cristy3ed852e2009-09-05 21:47:34 +00002488 return(0.0);
2489 }
cristy5597a8d2011-11-04 00:25:32 +00002490 if (LocaleNCompare(expression,"drc",3) == 0)
2491 {
2492 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2493 exception);
cristya19f1d72012-08-07 18:24:38 +00002494 return((double) (alpha/(*beta*(alpha-1.0)+1.0)));
cristy5597a8d2011-11-04 00:25:32 +00002495 }
cristy3ed852e2009-09-05 21:47:34 +00002496 break;
2497 }
2498 case 'E':
2499 case 'e':
2500 {
2501 if (LocaleCompare(expression,"epsilon") == 0)
cristya19f1d72012-08-07 18:24:38 +00002502 return((double) MagickEpsilon);
cristy3ed852e2009-09-05 21:47:34 +00002503 if (LocaleNCompare(expression,"exp",3) == 0)
2504 {
2505 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2506 exception);
cristya19f1d72012-08-07 18:24:38 +00002507 return((double) exp((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002508 }
2509 if (LocaleCompare(expression,"e") == 0)
cristya19f1d72012-08-07 18:24:38 +00002510 return((double) 2.7182818284590452354);
cristy3ed852e2009-09-05 21:47:34 +00002511 break;
2512 }
2513 case 'F':
2514 case 'f':
2515 {
2516 if (LocaleNCompare(expression,"floor",5) == 0)
2517 {
2518 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2519 exception);
cristya19f1d72012-08-07 18:24:38 +00002520 return((double) floor((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002521 }
2522 break;
2523 }
2524 case 'G':
2525 case 'g':
2526 {
cristy9eeedea2011-11-02 19:04:05 +00002527 if (LocaleNCompare(expression,"gauss",5) == 0)
2528 {
2529 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2530 exception);
2531 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
cristya19f1d72012-08-07 18:24:38 +00002532 return((double) gamma);
cristy9eeedea2011-11-02 19:04:05 +00002533 }
cristyb0aad4c2011-11-02 19:30:35 +00002534 if (LocaleNCompare(expression,"gcd",3) == 0)
2535 {
2536 MagickOffsetType
2537 gcd;
2538
2539 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2540 exception);
cristy1707c6c2012-01-18 23:30:54 +00002541 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
2542 0.5));
cristya19f1d72012-08-07 18:24:38 +00002543 return((double) gcd);
cristyb0aad4c2011-11-02 19:30:35 +00002544 }
cristy3ed852e2009-09-05 21:47:34 +00002545 if (LocaleCompare(expression,"g") == 0)
2546 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2547 break;
2548 }
2549 case 'H':
2550 case 'h':
2551 {
2552 if (LocaleCompare(expression,"h") == 0)
2553 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2554 if (LocaleCompare(expression,"hue") == 0)
2555 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2556 if (LocaleNCompare(expression,"hypot",5) == 0)
2557 {
2558 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2559 exception);
cristya19f1d72012-08-07 18:24:38 +00002560 return((double) hypot((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002561 }
2562 break;
2563 }
2564 case 'K':
2565 case 'k':
2566 {
2567 if (LocaleCompare(expression,"k") == 0)
2568 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2569 break;
2570 }
2571 case 'I':
2572 case 'i':
2573 {
2574 if (LocaleCompare(expression,"intensity") == 0)
2575 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2576 if (LocaleNCompare(expression,"int",3) == 0)
2577 {
2578 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2579 exception);
cristya19f1d72012-08-07 18:24:38 +00002580 return((double) floor(alpha));
cristy3ed852e2009-09-05 21:47:34 +00002581 }
cristy82b20722011-11-05 21:52:36 +00002582#if defined(MAGICKCORE_HAVE_ISNAN)
cristy639399c2011-11-02 19:16:15 +00002583 if (LocaleNCompare(expression,"isnan",5) == 0)
2584 {
2585 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2586 exception);
cristya19f1d72012-08-07 18:24:38 +00002587 return((double) !!isnan((double) alpha));
cristy639399c2011-11-02 19:16:15 +00002588 }
cristy82b20722011-11-05 21:52:36 +00002589#endif
cristy3ed852e2009-09-05 21:47:34 +00002590 if (LocaleCompare(expression,"i") == 0)
2591 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2592 break;
2593 }
2594 case 'J':
2595 case 'j':
2596 {
2597 if (LocaleCompare(expression,"j") == 0)
2598 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
cristy161b9262010-03-20 19:34:32 +00002599#if defined(MAGICKCORE_HAVE_J0)
cristyee56cf12010-03-01 22:17:06 +00002600 if (LocaleNCompare(expression,"j0",2) == 0)
2601 {
2602 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2603 exception);
cristya19f1d72012-08-07 18:24:38 +00002604 return((double) j0((double) alpha));
cristyee56cf12010-03-01 22:17:06 +00002605 }
cristy161b9262010-03-20 19:34:32 +00002606#endif
2607#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002608 if (LocaleNCompare(expression,"j1",2) == 0)
2609 {
2610 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2611 exception);
cristya19f1d72012-08-07 18:24:38 +00002612 return((double) j1((double) alpha));
cristyee56cf12010-03-01 22:17:06 +00002613 }
cristy161b9262010-03-20 19:34:32 +00002614#endif
cristyaa018fa2010-04-08 23:03:54 +00002615#if defined(MAGICKCORE_HAVE_J1)
cristya6a09e72010-03-02 14:51:02 +00002616 if (LocaleNCompare(expression,"jinc",4) == 0)
2617 {
2618 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2619 exception);
cristy0946a822010-03-12 17:14:58 +00002620 if (alpha == 0.0)
2621 return(1.0);
cristyc90d70d2012-11-03 23:53:13 +00002622 gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha));
cristyfce2f7b2010-03-12 00:29:49 +00002623 return(gamma);
cristya6a09e72010-03-02 14:51:02 +00002624 }
cristyaa018fa2010-04-08 23:03:54 +00002625#endif
cristy3ed852e2009-09-05 21:47:34 +00002626 break;
2627 }
2628 case 'L':
2629 case 'l':
2630 {
2631 if (LocaleNCompare(expression,"ln",2) == 0)
2632 {
2633 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2634 exception);
cristya19f1d72012-08-07 18:24:38 +00002635 return((double) log((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002636 }
cristyc8ed5322010-08-31 12:07:59 +00002637 if (LocaleNCompare(expression,"logtwo",6) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002638 {
cristyc8ed5322010-08-31 12:07:59 +00002639 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
cristy3ed852e2009-09-05 21:47:34 +00002640 exception);
cristya19f1d72012-08-07 18:24:38 +00002641 return((double) log10((double) alpha))/log10(2.0);
cristy3ed852e2009-09-05 21:47:34 +00002642 }
2643 if (LocaleNCompare(expression,"log",3) == 0)
2644 {
2645 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2646 exception);
cristya19f1d72012-08-07 18:24:38 +00002647 return((double) log10((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002648 }
2649 if (LocaleCompare(expression,"lightness") == 0)
2650 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2651 break;
2652 }
2653 case 'M':
2654 case 'm':
2655 {
2656 if (LocaleCompare(expression,"MaxRGB") == 0)
cristya19f1d72012-08-07 18:24:38 +00002657 return((double) QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002658 if (LocaleNCompare(expression,"maxima",6) == 0)
2659 break;
2660 if (LocaleNCompare(expression,"max",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002661 {
2662 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2663 exception);
2664 return(alpha > *beta ? alpha : *beta);
2665 }
cristy3ed852e2009-09-05 21:47:34 +00002666 if (LocaleNCompare(expression,"minima",6) == 0)
2667 break;
2668 if (LocaleNCompare(expression,"min",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002669 {
2670 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2671 exception);
2672 return(alpha < *beta ? alpha : *beta);
2673 }
cristy3ed852e2009-09-05 21:47:34 +00002674 if (LocaleNCompare(expression,"mod",3) == 0)
2675 {
2676 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2677 exception);
cristy984049c2011-11-03 18:34:58 +00002678 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2679 return(gamma);
cristy3ed852e2009-09-05 21:47:34 +00002680 }
2681 if (LocaleCompare(expression,"m") == 0)
2682 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2683 break;
2684 }
2685 case 'N':
2686 case 'n':
2687 {
cristyad3502e2011-11-02 19:10:45 +00002688 if (LocaleNCompare(expression,"not",3) == 0)
2689 {
2690 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2691 exception);
cristya19f1d72012-08-07 18:24:38 +00002692 return((double) (alpha < MagickEpsilon));
cristyad3502e2011-11-02 19:10:45 +00002693 }
cristy3ed852e2009-09-05 21:47:34 +00002694 if (LocaleCompare(expression,"n") == 0)
2695 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2696 break;
2697 }
2698 case 'O':
2699 case 'o':
2700 {
2701 if (LocaleCompare(expression,"Opaque") == 0)
2702 return(1.0);
2703 if (LocaleCompare(expression,"o") == 0)
2704 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2705 break;
2706 }
2707 case 'P':
2708 case 'p':
2709 {
cristy670aa3c2011-11-03 00:54:00 +00002710 if (LocaleCompare(expression,"phi") == 0)
cristya19f1d72012-08-07 18:24:38 +00002711 return((double) MagickPHI);
cristy3ed852e2009-09-05 21:47:34 +00002712 if (LocaleCompare(expression,"pi") == 0)
cristya19f1d72012-08-07 18:24:38 +00002713 return((double) MagickPI);
cristy3ed852e2009-09-05 21:47:34 +00002714 if (LocaleNCompare(expression,"pow",3) == 0)
2715 {
2716 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2717 exception);
cristya19f1d72012-08-07 18:24:38 +00002718 return((double) pow((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002719 }
2720 if (LocaleCompare(expression,"p") == 0)
2721 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2722 break;
2723 }
2724 case 'Q':
2725 case 'q':
2726 {
2727 if (LocaleCompare(expression,"QuantumRange") == 0)
cristya19f1d72012-08-07 18:24:38 +00002728 return((double) QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002729 if (LocaleCompare(expression,"QuantumScale") == 0)
cristya19f1d72012-08-07 18:24:38 +00002730 return((double) QuantumScale);
cristy3ed852e2009-09-05 21:47:34 +00002731 break;
2732 }
2733 case 'R':
2734 case 'r':
2735 {
2736 if (LocaleNCompare(expression,"rand",4) == 0)
cristya19f1d72012-08-07 18:24:38 +00002737 return((double) GetPseudoRandomValue(fx_info->random_info));
cristy3ed852e2009-09-05 21:47:34 +00002738 if (LocaleNCompare(expression,"round",5) == 0)
2739 {
2740 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2741 exception);
cristya19f1d72012-08-07 18:24:38 +00002742 return((double) floor((double) alpha+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002743 }
2744 if (LocaleCompare(expression,"r") == 0)
2745 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2746 break;
2747 }
2748 case 'S':
2749 case 's':
2750 {
2751 if (LocaleCompare(expression,"saturation") == 0)
2752 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2753 if (LocaleNCompare(expression,"sign",4) == 0)
2754 {
2755 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2756 exception);
2757 return(alpha < 0.0 ? -1.0 : 1.0);
2758 }
cristya6a09e72010-03-02 14:51:02 +00002759 if (LocaleNCompare(expression,"sinc",4) == 0)
2760 {
2761 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2762 exception);
2763 if (alpha == 0)
2764 return(1.0);
cristya19f1d72012-08-07 18:24:38 +00002765 gamma=(double) (sin((double) (MagickPI*alpha))/
cristya6a09e72010-03-02 14:51:02 +00002766 (MagickPI*alpha));
2767 return(gamma);
2768 }
cristy3ed852e2009-09-05 21:47:34 +00002769 if (LocaleNCompare(expression,"sinh",4) == 0)
2770 {
2771 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2772 exception);
cristya19f1d72012-08-07 18:24:38 +00002773 return((double) sinh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002774 }
2775 if (LocaleNCompare(expression,"sin",3) == 0)
2776 {
2777 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2778 exception);
cristya19f1d72012-08-07 18:24:38 +00002779 return((double) sin((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002780 }
2781 if (LocaleNCompare(expression,"sqrt",4) == 0)
2782 {
2783 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2784 exception);
cristya19f1d72012-08-07 18:24:38 +00002785 return((double) sqrt((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002786 }
cristy9eeedea2011-11-02 19:04:05 +00002787 if (LocaleNCompare(expression,"squish",6) == 0)
2788 {
2789 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2790 exception);
cristya19f1d72012-08-07 18:24:38 +00002791 return((double) (1.0/(1.0+exp((double) (-alpha)))));
cristy9eeedea2011-11-02 19:04:05 +00002792 }
cristy3ed852e2009-09-05 21:47:34 +00002793 if (LocaleCompare(expression,"s") == 0)
2794 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2795 break;
2796 }
2797 case 'T':
2798 case 't':
2799 {
2800 if (LocaleNCompare(expression,"tanh",4) == 0)
2801 {
2802 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2803 exception);
cristya19f1d72012-08-07 18:24:38 +00002804 return((double) tanh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002805 }
2806 if (LocaleNCompare(expression,"tan",3) == 0)
2807 {
2808 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2809 exception);
cristya19f1d72012-08-07 18:24:38 +00002810 return((double) tan((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002811 }
2812 if (LocaleCompare(expression,"Transparent") == 0)
2813 return(0.0);
cristy16788e42010-08-13 13:44:26 +00002814 if (LocaleNCompare(expression,"trunc",5) == 0)
2815 {
2816 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2817 exception);
2818 if (alpha >= 0.0)
cristya19f1d72012-08-07 18:24:38 +00002819 return((double) floor((double) alpha));
2820 return((double) ceil((double) alpha));
cristy16788e42010-08-13 13:44:26 +00002821 }
cristy3ed852e2009-09-05 21:47:34 +00002822 if (LocaleCompare(expression,"t") == 0)
2823 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2824 break;
2825 }
2826 case 'U':
2827 case 'u':
2828 {
2829 if (LocaleCompare(expression,"u") == 0)
2830 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2831 break;
2832 }
2833 case 'V':
2834 case 'v':
2835 {
2836 if (LocaleCompare(expression,"v") == 0)
2837 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2838 break;
2839 }
2840 case 'W':
2841 case 'w':
2842 {
cristy9eeedea2011-11-02 19:04:05 +00002843 if (LocaleNCompare(expression,"while",5) == 0)
2844 {
2845 do
2846 {
2847 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2848 exception);
2849 } while (fabs((double) alpha) >= MagickEpsilon);
cristya19f1d72012-08-07 18:24:38 +00002850 return((double) *beta);
cristy9eeedea2011-11-02 19:04:05 +00002851 }
cristy3ed852e2009-09-05 21:47:34 +00002852 if (LocaleCompare(expression,"w") == 0)
2853 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2854 break;
2855 }
2856 case 'Y':
2857 case 'y':
2858 {
2859 if (LocaleCompare(expression,"y") == 0)
2860 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2861 break;
2862 }
2863 case 'Z':
2864 case 'z':
2865 {
2866 if (LocaleCompare(expression,"z") == 0)
2867 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2868 break;
2869 }
2870 default:
2871 break;
2872 }
2873 q=(char *) expression;
cristydbdd0e32011-11-04 23:29:40 +00002874 alpha=InterpretSiPrefixValue(expression,&q);
cristy3ed852e2009-09-05 21:47:34 +00002875 if (q == expression)
2876 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2877 return(alpha);
2878}
2879
cristy7832dc22011-09-05 01:21:53 +00002880MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
cristya19f1d72012-08-07 18:24:38 +00002881 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002882{
2883 MagickBooleanType
2884 status;
2885
cristy541ae572011-08-05 19:08:59 +00002886 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2887 exception);
cristy3ed852e2009-09-05 21:47:34 +00002888 return(status);
2889}
2890
2891MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
cristya19f1d72012-08-07 18:24:38 +00002892 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002893{
2894 FILE
2895 *file;
2896
2897 MagickBooleanType
2898 status;
2899
2900 file=fx_info->file;
2901 fx_info->file=(FILE *) NULL;
cristy541ae572011-08-05 19:08:59 +00002902 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2903 exception);
cristy3ed852e2009-09-05 21:47:34 +00002904 fx_info->file=file;
2905 return(status);
2906}
2907
cristy7832dc22011-09-05 01:21:53 +00002908MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002909 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00002910 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002911{
cristya19f1d72012-08-07 18:24:38 +00002912 double
cristy3ed852e2009-09-05 21:47:34 +00002913 beta;
2914
2915 beta=0.0;
2916 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2917 exception);
2918 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2919}
2920
2921/*
2922%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2923% %
2924% %
2925% %
2926% F x I m a g e %
2927% %
2928% %
2929% %
2930%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2931%
2932% FxImage() applies a mathematical expression to the specified image.
2933%
2934% The format of the FxImage method is:
2935%
2936% Image *FxImage(const Image *image,const char *expression,
2937% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002938%
2939% A description of each parameter follows:
2940%
2941% o image: the image.
2942%
cristy3ed852e2009-09-05 21:47:34 +00002943% o expression: A mathematical expression.
2944%
2945% o exception: return any errors or warnings in this structure.
2946%
2947*/
2948
2949static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2950{
cristybb503372010-05-27 20:51:26 +00002951 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002952 i;
2953
2954 assert(fx_info != (FxInfo **) NULL);
cristyac245f82012-05-05 17:13:57 +00002955 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
cristy3ed852e2009-09-05 21:47:34 +00002956 if (fx_info[i] != (FxInfo *) NULL)
2957 fx_info[i]=DestroyFxInfo(fx_info[i]);
cristyb41ee102010-10-04 16:46:15 +00002958 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00002959 return(fx_info);
2960}
2961
2962static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2963 ExceptionInfo *exception)
2964{
2965 char
2966 *fx_expression;
2967
2968 FxInfo
2969 **fx_info;
2970
cristya19f1d72012-08-07 18:24:38 +00002971 double
cristy3ed852e2009-09-05 21:47:34 +00002972 alpha;
2973
cristybb503372010-05-27 20:51:26 +00002974 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002975 i;
2976
cristybb503372010-05-27 20:51:26 +00002977 size_t
cristy3ed852e2009-09-05 21:47:34 +00002978 number_threads;
2979
cristy9357bdd2012-07-30 12:28:34 +00002980 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
cristyb41ee102010-10-04 16:46:15 +00002981 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +00002982 if (fx_info == (FxInfo **) NULL)
cristy65d161b2012-10-07 20:39:52 +00002983 {
2984 (void) ThrowMagickException(exception,GetMagickModule(),
2985 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
2986 return((FxInfo **) NULL);
2987 }
cristy3ed852e2009-09-05 21:47:34 +00002988 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2989 if (*expression != '@')
2990 fx_expression=ConstantString(expression);
2991 else
2992 fx_expression=FileToString(expression+1,~0,exception);
cristybb503372010-05-27 20:51:26 +00002993 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +00002994 {
cristy65d161b2012-10-07 20:39:52 +00002995 MagickBooleanType
2996 status;
2997
cristydb070952012-04-20 14:33:00 +00002998 fx_info[i]=AcquireFxInfo(image,fx_expression,exception);
cristy3ed852e2009-09-05 21:47:34 +00002999 if (fx_info[i] == (FxInfo *) NULL)
cristy65d161b2012-10-07 20:39:52 +00003000 break;
3001 status=FxPreprocessExpression(fx_info[i],&alpha,exception);
3002 if (status == MagickFalse)
3003 break;
cristy3ed852e2009-09-05 21:47:34 +00003004 }
3005 fx_expression=DestroyString(fx_expression);
cristy65d161b2012-10-07 20:39:52 +00003006 if (i < (ssize_t) number_threads)
3007 fx_info=DestroyFxThreadSet(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00003008 return(fx_info);
3009}
3010
3011MagickExport Image *FxImage(const Image *image,const char *expression,
3012 ExceptionInfo *exception)
3013{
cristy3ed852e2009-09-05 21:47:34 +00003014#define FxImageTag "Fx/Image"
3015
cristyfa112112010-01-04 17:48:07 +00003016 CacheView
cristy79cedc72011-07-25 00:41:15 +00003017 *fx_view,
3018 *image_view;
cristyfa112112010-01-04 17:48:07 +00003019
cristy3ed852e2009-09-05 21:47:34 +00003020 FxInfo
cristyfa112112010-01-04 17:48:07 +00003021 **restrict fx_info;
cristy3ed852e2009-09-05 21:47:34 +00003022
3023 Image
3024 *fx_image;
3025
cristy3ed852e2009-09-05 21:47:34 +00003026 MagickBooleanType
3027 status;
3028
cristybb503372010-05-27 20:51:26 +00003029 MagickOffsetType
3030 progress;
3031
cristybb503372010-05-27 20:51:26 +00003032 ssize_t
3033 y;
3034
cristy3ed852e2009-09-05 21:47:34 +00003035 assert(image != (Image *) NULL);
3036 assert(image->signature == MagickSignature);
3037 if (image->debug != MagickFalse)
3038 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00003039 fx_info=AcquireFxThreadSet(image,expression,exception);
3040 if (fx_info == (FxInfo **) NULL)
cristy65d161b2012-10-07 20:39:52 +00003041 return((Image *) NULL);
3042 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3043 if (fx_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003044 {
cristy3ed852e2009-09-05 21:47:34 +00003045 fx_info=DestroyFxThreadSet(fx_info);
3046 return((Image *) NULL);
3047 }
cristy65d161b2012-10-07 20:39:52 +00003048 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
3049 {
3050 fx_info=DestroyFxThreadSet(fx_info);
3051 fx_image=DestroyImage(fx_image);
3052 return((Image *) NULL);
3053 }
cristy3ed852e2009-09-05 21:47:34 +00003054 /*
3055 Fx image.
3056 */
3057 status=MagickTrue;
3058 progress=0;
cristy46ff2672012-12-14 15:32:26 +00003059 image_view=AcquireVirtualCacheView(image,exception);
3060 fx_view=AcquireAuthenticCacheView(fx_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003061#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003062 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00003063 magick_threads(image,fx_image,fx_image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003064#endif
cristybb503372010-05-27 20:51:26 +00003065 for (y=0; y < (ssize_t) fx_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003066 {
cristy5c9e6f22010-09-17 17:31:01 +00003067 const int
3068 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00003069
cristy79cedc72011-07-25 00:41:15 +00003070 register const Quantum
3071 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003072
cristy4c08aed2011-07-01 19:47:50 +00003073 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003074 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003075
cristy79cedc72011-07-25 00:41:15 +00003076 register ssize_t
3077 x;
3078
cristy3ed852e2009-09-05 21:47:34 +00003079 if (status == MagickFalse)
3080 continue;
cristy79cedc72011-07-25 00:41:15 +00003081 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +00003082 q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
cristy79cedc72011-07-25 00:41:15 +00003083 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003084 {
3085 status=MagickFalse;
3086 continue;
3087 }
cristybb503372010-05-27 20:51:26 +00003088 for (x=0; x < (ssize_t) fx_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003089 {
cristy79cedc72011-07-25 00:41:15 +00003090 register ssize_t
3091 i;
3092
3093 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3094 {
cristya19f1d72012-08-07 18:24:38 +00003095 double
cristy79cedc72011-07-25 00:41:15 +00003096 alpha;
3097
cristy5a23c552013-02-13 14:34:28 +00003098 PixelChannel channel=GetPixelChannelChannel(image,i);
3099 PixelTrait traits=GetPixelChannelTraits(image,channel);
3100 PixelTrait fx_traits=GetPixelChannelTraits(fx_image,channel);
cristy010d7d12011-08-31 01:02:48 +00003101 if ((traits == UndefinedPixelTrait) ||
3102 (fx_traits == UndefinedPixelTrait))
cristy79cedc72011-07-25 00:41:15 +00003103 continue;
cristy1eced092012-08-10 23:10:56 +00003104 if (((fx_traits & CopyPixelTrait) != 0) ||
cristy883fde12013-04-08 00:50:13 +00003105 (GetPixelReadMask(image,p) == 0))
cristy79cedc72011-07-25 00:41:15 +00003106 {
cristy0beccfa2011-09-25 20:47:53 +00003107 SetPixelChannel(fx_image,channel,p[i],q);
cristy79cedc72011-07-25 00:41:15 +00003108 continue;
3109 }
3110 alpha=0.0;
cristya382aca2011-12-06 18:22:48 +00003111 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3112 exception);
cristy8cd03c32012-07-07 18:57:59 +00003113 q[i]=ClampToQuantum(QuantumRange*alpha);
cristy79cedc72011-07-25 00:41:15 +00003114 }
3115 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003116 q+=GetPixelChannels(fx_image);
cristy3ed852e2009-09-05 21:47:34 +00003117 }
3118 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3119 status=MagickFalse;
3120 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3121 {
3122 MagickBooleanType
3123 proceed;
3124
cristyb5d5f722009-11-04 03:03:49 +00003125#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003126 #pragma omp critical (MagickCore_FxImage)
cristy3ed852e2009-09-05 21:47:34 +00003127#endif
3128 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3129 if (proceed == MagickFalse)
3130 status=MagickFalse;
3131 }
3132 }
cristy3ed852e2009-09-05 21:47:34 +00003133 fx_view=DestroyCacheView(fx_view);
cristy79cedc72011-07-25 00:41:15 +00003134 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003135 fx_info=DestroyFxThreadSet(fx_info);
3136 if (status == MagickFalse)
3137 fx_image=DestroyImage(fx_image);
3138 return(fx_image);
3139}
3140
3141/*
3142%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3143% %
3144% %
3145% %
3146% I m p l o d e I m a g e %
3147% %
3148% %
3149% %
3150%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3151%
3152% ImplodeImage() creates a new image that is a copy of an existing
3153% one with the image pixels "implode" by the specified percentage. It
3154% allocates the memory necessary for the new Image structure and returns a
3155% pointer to the new image.
3156%
3157% The format of the ImplodeImage method is:
3158%
3159% Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003160% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003161%
3162% A description of each parameter follows:
3163%
3164% o implode_image: Method ImplodeImage returns a pointer to the image
3165% after it is implode. A null image is returned if there is a memory
3166% shortage.
3167%
3168% o image: the image.
3169%
3170% o amount: Define the extent of the implosion.
3171%
cristy76f512e2011-09-12 01:26:56 +00003172% o method: the pixel interpolation method.
3173%
cristy3ed852e2009-09-05 21:47:34 +00003174% o exception: return any errors or warnings in this structure.
3175%
3176*/
3177MagickExport Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003178 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003179{
3180#define ImplodeImageTag "Implode/Image"
3181
cristyfa112112010-01-04 17:48:07 +00003182 CacheView
3183 *image_view,
3184 *implode_view;
3185
cristy3ed852e2009-09-05 21:47:34 +00003186 Image
3187 *implode_image;
3188
cristy3ed852e2009-09-05 21:47:34 +00003189 MagickBooleanType
3190 status;
3191
cristybb503372010-05-27 20:51:26 +00003192 MagickOffsetType
3193 progress;
3194
cristya19f1d72012-08-07 18:24:38 +00003195 double
cristy3ed852e2009-09-05 21:47:34 +00003196 radius;
3197
3198 PointInfo
3199 center,
3200 scale;
3201
cristybb503372010-05-27 20:51:26 +00003202 ssize_t
3203 y;
3204
cristy3ed852e2009-09-05 21:47:34 +00003205 /*
3206 Initialize implode image attributes.
3207 */
3208 assert(image != (Image *) NULL);
3209 assert(image->signature == MagickSignature);
3210 if (image->debug != MagickFalse)
3211 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3212 assert(exception != (ExceptionInfo *) NULL);
3213 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00003214 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3215 exception);
cristy3ed852e2009-09-05 21:47:34 +00003216 if (implode_image == (Image *) NULL)
3217 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003218 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003219 {
cristy3ed852e2009-09-05 21:47:34 +00003220 implode_image=DestroyImage(implode_image);
3221 return((Image *) NULL);
3222 }
cristy4c08aed2011-07-01 19:47:50 +00003223 if (implode_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00003224 implode_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00003225 /*
3226 Compute scaling factor.
3227 */
3228 scale.x=1.0;
3229 scale.y=1.0;
3230 center.x=0.5*image->columns;
3231 center.y=0.5*image->rows;
3232 radius=center.x;
3233 if (image->columns > image->rows)
3234 scale.y=(double) image->columns/(double) image->rows;
3235 else
3236 if (image->columns < image->rows)
3237 {
3238 scale.x=(double) image->rows/(double) image->columns;
3239 radius=center.y;
3240 }
3241 /*
3242 Implode image.
3243 */
3244 status=MagickTrue;
3245 progress=0;
cristy46ff2672012-12-14 15:32:26 +00003246 image_view=AcquireVirtualCacheView(image,exception);
3247 implode_view=AcquireAuthenticCacheView(implode_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003248#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003249 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00003250 magick_threads(image,implode_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003251#endif
cristybb503372010-05-27 20:51:26 +00003252 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003253 {
cristya19f1d72012-08-07 18:24:38 +00003254 double
cristy3ed852e2009-09-05 21:47:34 +00003255 distance;
3256
3257 PointInfo
3258 delta;
3259
cristy6d188022011-09-12 13:23:33 +00003260 register const Quantum
3261 *restrict p;
3262
cristybb503372010-05-27 20:51:26 +00003263 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003264 x;
3265
cristy4c08aed2011-07-01 19:47:50 +00003266 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003267 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003268
3269 if (status == MagickFalse)
3270 continue;
cristy6d188022011-09-12 13:23:33 +00003271 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +00003272 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00003273 exception);
cristy6d188022011-09-12 13:23:33 +00003274 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003275 {
3276 status=MagickFalse;
3277 continue;
3278 }
cristy3ed852e2009-09-05 21:47:34 +00003279 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00003280 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003281 {
cristy6d188022011-09-12 13:23:33 +00003282 register ssize_t
3283 i;
3284
cristy3ed852e2009-09-05 21:47:34 +00003285 /*
3286 Determine if the pixel is within an ellipse.
3287 */
cristy883fde12013-04-08 00:50:13 +00003288 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +00003289 {
3290 p+=GetPixelChannels(image);
3291 q+=GetPixelChannels(implode_image);
3292 continue;
3293 }
cristy3ed852e2009-09-05 21:47:34 +00003294 delta.x=scale.x*(double) (x-center.x);
3295 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00003296 if (distance >= (radius*radius))
cristya6d7a9b2012-01-18 20:04:48 +00003297 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristy6d188022011-09-12 13:23:33 +00003298 {
cristy5a23c552013-02-13 14:34:28 +00003299 PixelChannel channel=GetPixelChannelChannel(image,i);
3300 PixelTrait traits=GetPixelChannelTraits(image,channel);
3301 PixelTrait implode_traits=GetPixelChannelTraits(implode_image,
3302 channel);
cristy1707c6c2012-01-18 23:30:54 +00003303 if ((traits == UndefinedPixelTrait) ||
3304 (implode_traits == UndefinedPixelTrait))
3305 continue;
cristya6d7a9b2012-01-18 20:04:48 +00003306 SetPixelChannel(implode_image,channel,p[i],q);
cristy6d188022011-09-12 13:23:33 +00003307 }
3308 else
cristy3ed852e2009-09-05 21:47:34 +00003309 {
3310 double
3311 factor;
3312
3313 /*
3314 Implode the pixel.
3315 */
3316 factor=1.0;
3317 if (distance > 0.0)
cristy1707c6c2012-01-18 23:30:54 +00003318 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
3319 2)),-amount);
cristy76f512e2011-09-12 01:26:56 +00003320 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3321 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3322 scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00003323 }
cristy6d188022011-09-12 13:23:33 +00003324 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003325 q+=GetPixelChannels(implode_image);
cristy3ed852e2009-09-05 21:47:34 +00003326 }
3327 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3328 status=MagickFalse;
3329 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3330 {
3331 MagickBooleanType
3332 proceed;
3333
cristyb5d5f722009-11-04 03:03:49 +00003334#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003335 #pragma omp critical (MagickCore_ImplodeImage)
cristy3ed852e2009-09-05 21:47:34 +00003336#endif
3337 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3338 if (proceed == MagickFalse)
3339 status=MagickFalse;
3340 }
3341 }
3342 implode_view=DestroyCacheView(implode_view);
3343 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003344 if (status == MagickFalse)
3345 implode_image=DestroyImage(implode_image);
3346 return(implode_image);
3347}
3348
3349/*
3350%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3351% %
3352% %
3353% %
3354% M o r p h I m a g e s %
3355% %
3356% %
3357% %
3358%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3359%
3360% The MorphImages() method requires a minimum of two images. The first
3361% image is transformed into the second by a number of intervening images
3362% as specified by frames.
3363%
3364% The format of the MorphImage method is:
3365%
cristybb503372010-05-27 20:51:26 +00003366% Image *MorphImages(const Image *image,const size_t number_frames,
cristy3ed852e2009-09-05 21:47:34 +00003367% ExceptionInfo *exception)
3368%
3369% A description of each parameter follows:
3370%
3371% o image: the image.
3372%
3373% o number_frames: Define the number of in-between image to generate.
3374% The more in-between frames, the smoother the morph.
3375%
3376% o exception: return any errors or warnings in this structure.
3377%
3378*/
cristy7de7f742012-12-14 00:28:27 +00003379MagickExport Image *MorphImages(const Image *image,const size_t number_frames,
3380 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003381{
3382#define MorphImageTag "Morph/Image"
3383
cristyfab83642012-12-14 00:31:38 +00003384 double
3385 alpha,
3386 beta;
3387
cristy3ed852e2009-09-05 21:47:34 +00003388 Image
3389 *morph_image,
3390 *morph_images;
3391
cristy9d314ff2011-03-09 01:30:28 +00003392 MagickBooleanType
3393 status;
cristy3ed852e2009-09-05 21:47:34 +00003394
3395 MagickOffsetType
3396 scene;
3397
cristy3ed852e2009-09-05 21:47:34 +00003398 register const Image
3399 *next;
3400
cristybb503372010-05-27 20:51:26 +00003401 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003402 i;
3403
cristy9d314ff2011-03-09 01:30:28 +00003404 ssize_t
3405 y;
cristy3ed852e2009-09-05 21:47:34 +00003406
3407 /*
3408 Clone first frame in sequence.
3409 */
3410 assert(image != (Image *) NULL);
3411 assert(image->signature == MagickSignature);
3412 if (image->debug != MagickFalse)
3413 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3414 assert(exception != (ExceptionInfo *) NULL);
3415 assert(exception->signature == MagickSignature);
3416 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3417 if (morph_images == (Image *) NULL)
3418 return((Image *) NULL);
3419 if (GetNextImageInList(image) == (Image *) NULL)
3420 {
3421 /*
3422 Morph single image.
3423 */
cristybb503372010-05-27 20:51:26 +00003424 for (i=1; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003425 {
3426 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3427 if (morph_image == (Image *) NULL)
3428 {
3429 morph_images=DestroyImageList(morph_images);
3430 return((Image *) NULL);
3431 }
3432 AppendImageToList(&morph_images,morph_image);
cristy8b27a6d2010-02-14 03:31:15 +00003433 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003434 {
cristy8b27a6d2010-02-14 03:31:15 +00003435 MagickBooleanType
3436 proceed;
3437
cristybb503372010-05-27 20:51:26 +00003438 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3439 number_frames);
cristy8b27a6d2010-02-14 03:31:15 +00003440 if (proceed == MagickFalse)
3441 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003442 }
3443 }
3444 return(GetFirstImageInList(morph_images));
3445 }
3446 /*
3447 Morph image sequence.
3448 */
3449 status=MagickTrue;
3450 scene=0;
3451 next=image;
3452 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3453 {
cristybb503372010-05-27 20:51:26 +00003454 for (i=0; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003455 {
3456 CacheView
3457 *image_view,
3458 *morph_view;
3459
cristya19f1d72012-08-07 18:24:38 +00003460 beta=(double) (i+1.0)/(double) (number_frames+1.0);
cristy3ed852e2009-09-05 21:47:34 +00003461 alpha=1.0-beta;
cristy15b98cd2010-09-12 19:42:50 +00003462 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
cristyaa2c16c2012-03-25 22:21:35 +00003463 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta*
3464 GetNextImageInList(next)->rows+0.5),next->filter,exception);
cristy3ed852e2009-09-05 21:47:34 +00003465 if (morph_image == (Image *) NULL)
3466 {
3467 morph_images=DestroyImageList(morph_images);
3468 return((Image *) NULL);
3469 }
cristy1707c6c2012-01-18 23:30:54 +00003470 status=SetImageStorageClass(morph_image,DirectClass,exception);
3471 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003472 {
cristy3ed852e2009-09-05 21:47:34 +00003473 morph_image=DestroyImage(morph_image);
3474 return((Image *) NULL);
3475 }
3476 AppendImageToList(&morph_images,morph_image);
3477 morph_images=GetLastImageInList(morph_images);
cristy15b98cd2010-09-12 19:42:50 +00003478 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
cristyaa2c16c2012-03-25 22:21:35 +00003479 morph_images->rows,GetNextImageInList(next)->filter,exception);
cristy3ed852e2009-09-05 21:47:34 +00003480 if (morph_image == (Image *) NULL)
3481 {
3482 morph_images=DestroyImageList(morph_images);
3483 return((Image *) NULL);
3484 }
cristy46ff2672012-12-14 15:32:26 +00003485 image_view=AcquireVirtualCacheView(morph_image,exception);
3486 morph_view=AcquireAuthenticCacheView(morph_images,exception);
cristyb5d5f722009-11-04 03:03:49 +00003487#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003488 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00003489 magick_threads(morph_image,morph_image,morph_image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003490#endif
cristybb503372010-05-27 20:51:26 +00003491 for (y=0; y < (ssize_t) morph_images->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003492 {
3493 MagickBooleanType
3494 sync;
3495
cristy4c08aed2011-07-01 19:47:50 +00003496 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00003497 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003498
cristybb503372010-05-27 20:51:26 +00003499 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003500 x;
3501
cristy4c08aed2011-07-01 19:47:50 +00003502 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003503 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003504
3505 if (status == MagickFalse)
3506 continue;
3507 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3508 exception);
3509 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3510 exception);
cristy4c08aed2011-07-01 19:47:50 +00003511 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003512 {
3513 status=MagickFalse;
3514 continue;
3515 }
cristybb503372010-05-27 20:51:26 +00003516 for (x=0; x < (ssize_t) morph_images->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003517 {
cristy1707c6c2012-01-18 23:30:54 +00003518 register ssize_t
3519 i;
3520
cristy10a6c612012-01-29 21:41:05 +00003521 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
cristy1707c6c2012-01-18 23:30:54 +00003522 {
cristy5a23c552013-02-13 14:34:28 +00003523 PixelChannel channel=GetPixelChannelChannel(image,i);
3524 PixelTrait traits=GetPixelChannelTraits(image,channel);
3525 PixelTrait morph_traits=GetPixelChannelTraits(morph_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00003526 if ((traits == UndefinedPixelTrait) ||
3527 (morph_traits == UndefinedPixelTrait))
3528 continue;
cristy1eced092012-08-10 23:10:56 +00003529 if (((morph_traits & CopyPixelTrait) != 0) ||
cristy883fde12013-04-08 00:50:13 +00003530 (GetPixelReadMask(image,p) == 0))
cristy1707c6c2012-01-18 23:30:54 +00003531 {
3532 SetPixelChannel(morph_image,channel,p[i],q);
3533 continue;
3534 }
3535 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*
3536 GetPixelChannel(morph_images,channel,q)+beta*p[i]),q);
3537 }
cristyed231572011-07-14 02:18:59 +00003538 p+=GetPixelChannels(morph_image);
3539 q+=GetPixelChannels(morph_images);
cristy3ed852e2009-09-05 21:47:34 +00003540 }
3541 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3542 if (sync == MagickFalse)
3543 status=MagickFalse;
3544 }
3545 morph_view=DestroyCacheView(morph_view);
3546 image_view=DestroyCacheView(image_view);
3547 morph_image=DestroyImage(morph_image);
3548 }
cristybb503372010-05-27 20:51:26 +00003549 if (i < (ssize_t) number_frames)
cristy3ed852e2009-09-05 21:47:34 +00003550 break;
3551 /*
3552 Clone last frame in sequence.
3553 */
3554 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3555 if (morph_image == (Image *) NULL)
3556 {
3557 morph_images=DestroyImageList(morph_images);
3558 return((Image *) NULL);
3559 }
3560 AppendImageToList(&morph_images,morph_image);
3561 morph_images=GetLastImageInList(morph_images);
3562 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3563 {
3564 MagickBooleanType
3565 proceed;
3566
cristyb5d5f722009-11-04 03:03:49 +00003567#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003568 #pragma omp critical (MagickCore_MorphImages)
cristy3ed852e2009-09-05 21:47:34 +00003569#endif
3570 proceed=SetImageProgress(image,MorphImageTag,scene,
3571 GetImageListLength(image));
3572 if (proceed == MagickFalse)
3573 status=MagickFalse;
3574 }
3575 scene++;
3576 }
3577 if (GetNextImageInList(next) != (Image *) NULL)
3578 {
3579 morph_images=DestroyImageList(morph_images);
3580 return((Image *) NULL);
3581 }
3582 return(GetFirstImageInList(morph_images));
3583}
3584
3585/*
3586%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3587% %
3588% %
3589% %
3590% P l a s m a I m a g e %
3591% %
3592% %
3593% %
3594%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3595%
3596% PlasmaImage() initializes an image with plasma fractal values. The image
3597% must be initialized with a base color and the random number generator
3598% seeded before this method is called.
3599%
3600% The format of the PlasmaImage method is:
3601%
3602% MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
cristy5cbc0162011-08-29 00:36:28 +00003603% size_t attenuate,size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003604%
3605% A description of each parameter follows:
3606%
3607% o image: the image.
3608%
3609% o segment: Define the region to apply plasma fractals values.
3610%
glennrp7dae1ca2010-09-16 12:17:35 +00003611% o attenuate: Define the plasma attenuation factor.
cristy3ed852e2009-09-05 21:47:34 +00003612%
3613% o depth: Limit the plasma recursion depth.
3614%
cristy5cbc0162011-08-29 00:36:28 +00003615% o exception: return any errors or warnings in this structure.
3616%
cristy3ed852e2009-09-05 21:47:34 +00003617*/
3618
3619static inline Quantum PlasmaPixel(RandomInfo *random_info,
cristya19f1d72012-08-07 18:24:38 +00003620 const double pixel,const double noise)
cristy3ed852e2009-09-05 21:47:34 +00003621{
3622 Quantum
3623 plasma;
3624
cristyce70c172010-01-07 17:15:30 +00003625 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
cristy3ed852e2009-09-05 21:47:34 +00003626 noise/2.0);
3627 return(plasma);
3628}
3629
cristyda1f9c12011-10-02 21:39:49 +00003630static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3631 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3632 const SegmentInfo *segment,size_t attenuate,size_t depth,
3633 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003634{
cristya19f1d72012-08-07 18:24:38 +00003635 double
cristy3ed852e2009-09-05 21:47:34 +00003636 plasma;
3637
cristyda1f9c12011-10-02 21:39:49 +00003638 register const Quantum
3639 *restrict u,
3640 *restrict v;
3641
3642 register Quantum
3643 *restrict q;
3644
3645 register ssize_t
3646 i;
cristy3ed852e2009-09-05 21:47:34 +00003647
cristy9d314ff2011-03-09 01:30:28 +00003648 ssize_t
3649 x,
3650 x_mid,
3651 y,
3652 y_mid;
3653
cristy3ed852e2009-09-05 21:47:34 +00003654 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3655 return(MagickTrue);
3656 if (depth != 0)
3657 {
3658 SegmentInfo
3659 local_info;
3660
3661 /*
3662 Divide the area into quadrants and recurse.
3663 */
3664 depth--;
3665 attenuate++;
cristybb503372010-05-27 20:51:26 +00003666 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3667 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003668 local_info=(*segment);
3669 local_info.x2=(double) x_mid;
3670 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003671 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3672 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003673 local_info=(*segment);
3674 local_info.y1=(double) y_mid;
3675 local_info.x2=(double) x_mid;
cristyda1f9c12011-10-02 21:39:49 +00003676 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3677 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003678 local_info=(*segment);
3679 local_info.x1=(double) x_mid;
3680 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003681 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3682 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003683 local_info=(*segment);
3684 local_info.x1=(double) x_mid;
3685 local_info.y1=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003686 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3687 &local_info,attenuate,depth,exception));
cristy3ed852e2009-09-05 21:47:34 +00003688 }
cristybb503372010-05-27 20:51:26 +00003689 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3690 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003691 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3692 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3693 return(MagickFalse);
3694 /*
3695 Average pixels and apply plasma.
3696 */
cristya19f1d72012-08-07 18:24:38 +00003697 plasma=(double) QuantumRange/(2.0*attenuate);
cristy3ed852e2009-09-05 21:47:34 +00003698 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3699 {
cristy3ed852e2009-09-05 21:47:34 +00003700 /*
3701 Left pixel.
3702 */
cristybb503372010-05-27 20:51:26 +00003703 x=(ssize_t) ceil(segment->x1-0.5);
cristy1707c6c2012-01-18 23:30:54 +00003704 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1,
3705 exception);
3706 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1,
3707 exception);
cristyc5c6f662010-09-22 14:23:02 +00003708 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003709 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3710 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003711 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003712 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3713 {
cristy5a23c552013-02-13 14:34:28 +00003714 PixelChannel channel=GetPixelChannelChannel(image,i);
3715 PixelTrait traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003716 if (traits == UndefinedPixelTrait)
3717 continue;
3718 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3719 }
cristyc5c6f662010-09-22 14:23:02 +00003720 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003721 if (segment->x1 != segment->x2)
3722 {
3723 /*
3724 Right pixel.
3725 */
cristybb503372010-05-27 20:51:26 +00003726 x=(ssize_t) ceil(segment->x2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003727 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3728 1,1,exception);
3729 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3730 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003731 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003732 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3733 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003734 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003735 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3736 {
cristy5a23c552013-02-13 14:34:28 +00003737 PixelChannel channel=GetPixelChannelChannel(image,i);
3738 PixelTrait traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003739 if (traits == UndefinedPixelTrait)
3740 continue;
3741 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3742 }
cristyc5c6f662010-09-22 14:23:02 +00003743 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003744 }
3745 }
3746 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3747 {
3748 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3749 {
cristy3ed852e2009-09-05 21:47:34 +00003750 /*
3751 Bottom pixel.
3752 */
cristybb503372010-05-27 20:51:26 +00003753 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003754 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3755 1,1,exception);
3756 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3757 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003758 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003759 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3760 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003761 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003762 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3763 {
cristy5a23c552013-02-13 14:34:28 +00003764 PixelChannel channel=GetPixelChannelChannel(image,i);
3765 PixelTrait traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003766 if (traits == UndefinedPixelTrait)
3767 continue;
3768 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3769 }
cristyc5c6f662010-09-22 14:23:02 +00003770 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003771 }
3772 if (segment->y1 != segment->y2)
3773 {
cristy3ed852e2009-09-05 21:47:34 +00003774 /*
3775 Top pixel.
3776 */
cristybb503372010-05-27 20:51:26 +00003777 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003778 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3779 1,1,exception);
3780 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3781 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003782 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003783 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3784 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003785 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003786 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3787 {
cristy5a23c552013-02-13 14:34:28 +00003788 PixelChannel channel=GetPixelChannelChannel(image,i);
3789 PixelTrait traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003790 if (traits == UndefinedPixelTrait)
3791 continue;
3792 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3793 }
cristyc5c6f662010-09-22 14:23:02 +00003794 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003795 }
3796 }
3797 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3798 {
cristy3ed852e2009-09-05 21:47:34 +00003799 /*
3800 Middle pixel.
3801 */
cristybb503372010-05-27 20:51:26 +00003802 x=(ssize_t) ceil(segment->x1-0.5);
3803 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003804 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
cristybb503372010-05-27 20:51:26 +00003805 x=(ssize_t) ceil(segment->x2-0.5);
3806 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003807 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003808 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003809 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3810 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003811 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003812 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3813 {
cristy5a23c552013-02-13 14:34:28 +00003814 PixelChannel channel=GetPixelChannelChannel(image,i);
3815 PixelTrait traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003816 if (traits == UndefinedPixelTrait)
3817 continue;
3818 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3819 }
cristyc5c6f662010-09-22 14:23:02 +00003820 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003821 }
3822 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3823 return(MagickTrue);
3824 return(MagickFalse);
3825}
cristyda1f9c12011-10-02 21:39:49 +00003826
cristy3ed852e2009-09-05 21:47:34 +00003827MagickExport MagickBooleanType PlasmaImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00003828 const SegmentInfo *segment,size_t attenuate,size_t depth,
3829 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003830{
cristyc5c6f662010-09-22 14:23:02 +00003831 CacheView
cristyda1f9c12011-10-02 21:39:49 +00003832 *image_view,
3833 *u_view,
3834 *v_view;
cristyc5c6f662010-09-22 14:23:02 +00003835
cristy3ed852e2009-09-05 21:47:34 +00003836 MagickBooleanType
3837 status;
3838
3839 RandomInfo
3840 *random_info;
3841
3842 if (image->debug != MagickFalse)
3843 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3844 assert(image != (Image *) NULL);
3845 assert(image->signature == MagickSignature);
3846 if (image->debug != MagickFalse)
3847 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy5cbc0162011-08-29 00:36:28 +00003848 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristyc5c6f662010-09-22 14:23:02 +00003849 return(MagickFalse);
cristy46ff2672012-12-14 15:32:26 +00003850 image_view=AcquireAuthenticCacheView(image,exception);
3851 u_view=AcquireVirtualCacheView(image,exception);
3852 v_view=AcquireVirtualCacheView(image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003853 random_info=AcquireRandomInfo();
cristyda1f9c12011-10-02 21:39:49 +00003854 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3855 attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003856 random_info=DestroyRandomInfo(random_info);
cristyda1f9c12011-10-02 21:39:49 +00003857 v_view=DestroyCacheView(v_view);
3858 u_view=DestroyCacheView(u_view);
cristyc5c6f662010-09-22 14:23:02 +00003859 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003860 return(status);
3861}
3862
3863/*
3864%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3865% %
3866% %
3867% %
3868% P o l a r o i d I m a g e %
3869% %
3870% %
3871% %
3872%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3873%
3874% PolaroidImage() simulates a Polaroid picture.
3875%
3876% The format of the AnnotateImage method is:
3877%
3878% Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristye9e3d382011-12-14 01:50:13 +00003879% const char *caption,const double angle,
3880% const PixelInterpolateMethod method,ExceptionInfo exception)
cristy3ed852e2009-09-05 21:47:34 +00003881%
3882% A description of each parameter follows:
3883%
3884% o image: the image.
3885%
3886% o draw_info: the draw info.
3887%
cristye9e3d382011-12-14 01:50:13 +00003888% o caption: the Polaroid caption.
3889%
cristycee97112010-05-28 00:44:52 +00003890% o angle: Apply the effect along this angle.
cristy3ed852e2009-09-05 21:47:34 +00003891%
cristy5c4e2582011-09-11 19:21:03 +00003892% o method: the pixel interpolation method.
3893%
cristy3ed852e2009-09-05 21:47:34 +00003894% o exception: return any errors or warnings in this structure.
3895%
3896*/
3897MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristye9e3d382011-12-14 01:50:13 +00003898 const char *caption,const double angle,const PixelInterpolateMethod method,
cristy5c4e2582011-09-11 19:21:03 +00003899 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003900{
cristy3ed852e2009-09-05 21:47:34 +00003901 Image
3902 *bend_image,
3903 *caption_image,
3904 *flop_image,
3905 *picture_image,
3906 *polaroid_image,
3907 *rotate_image,
3908 *trim_image;
3909
cristybb503372010-05-27 20:51:26 +00003910 size_t
cristy3ed852e2009-09-05 21:47:34 +00003911 height;
3912
cristy9d314ff2011-03-09 01:30:28 +00003913 ssize_t
3914 quantum;
3915
cristy3ed852e2009-09-05 21:47:34 +00003916 /*
3917 Simulate a Polaroid picture.
3918 */
3919 assert(image != (Image *) NULL);
3920 assert(image->signature == MagickSignature);
3921 if (image->debug != MagickFalse)
3922 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3923 assert(exception != (ExceptionInfo *) NULL);
3924 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00003925 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
cristy3ed852e2009-09-05 21:47:34 +00003926 image->rows)/25.0,10.0);
3927 height=image->rows+2*quantum;
3928 caption_image=(Image *) NULL;
cristye9e3d382011-12-14 01:50:13 +00003929 if (caption != (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003930 {
3931 char
cristye9e3d382011-12-14 01:50:13 +00003932 geometry[MaxTextExtent],
3933 *text;
cristy3ed852e2009-09-05 21:47:34 +00003934
3935 DrawInfo
3936 *annotate_info;
3937
cristy3ed852e2009-09-05 21:47:34 +00003938 MagickBooleanType
3939 status;
3940
cristy9d314ff2011-03-09 01:30:28 +00003941 ssize_t
3942 count;
3943
cristy3ed852e2009-09-05 21:47:34 +00003944 TypeMetric
3945 metrics;
3946
3947 /*
3948 Generate caption image.
3949 */
3950 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3951 if (caption_image == (Image *) NULL)
3952 return((Image *) NULL);
3953 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
cristye9e3d382011-12-14 01:50:13 +00003954 text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
3955 exception);
3956 (void) CloneString(&annotate_info->text,text);
cristy6b1d05e2010-09-22 19:17:27 +00003957 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
cristye9e3d382011-12-14 01:50:13 +00003958 &text,exception);
3959 status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)*
3960 (metrics.ascent-metrics.descent)+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003961 if (status == MagickFalse)
3962 caption_image=DestroyImage(caption_image);
3963 else
3964 {
3965 caption_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00003966 (void) SetImageBackgroundColor(caption_image,exception);
cristye9e3d382011-12-14 01:50:13 +00003967 (void) CloneString(&annotate_info->text,text);
cristyb51dff52011-05-19 16:55:47 +00003968 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
cristy3ed852e2009-09-05 21:47:34 +00003969 metrics.ascent);
3970 if (annotate_info->gravity == UndefinedGravity)
3971 (void) CloneString(&annotate_info->geometry,AcquireString(
3972 geometry));
cristy5cbc0162011-08-29 00:36:28 +00003973 (void) AnnotateImage(caption_image,annotate_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00003974 height+=caption_image->rows;
3975 }
3976 annotate_info=DestroyDrawInfo(annotate_info);
cristye9e3d382011-12-14 01:50:13 +00003977 text=DestroyString(text);
cristy3ed852e2009-09-05 21:47:34 +00003978 }
3979 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3980 exception);
3981 if (picture_image == (Image *) NULL)
3982 {
3983 if (caption_image != (Image *) NULL)
3984 caption_image=DestroyImage(caption_image);
3985 return((Image *) NULL);
3986 }
3987 picture_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00003988 (void) SetImageBackgroundColor(picture_image,exception);
cristy39172402012-03-30 13:04:39 +00003989 (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum,
cristyfeb3e962012-03-29 17:25:55 +00003990 quantum,exception);
cristy3ed852e2009-09-05 21:47:34 +00003991 if (caption_image != (Image *) NULL)
3992 {
cristyfeb3e962012-03-29 17:25:55 +00003993 (void) CompositeImage(picture_image,caption_image,OverCompositeOp,
cristy39172402012-03-30 13:04:39 +00003994 MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception);
cristy3ed852e2009-09-05 21:47:34 +00003995 caption_image=DestroyImage(caption_image);
3996 }
cristy9950d572011-10-01 18:22:35 +00003997 (void) QueryColorCompliance("none",AllCompliance,
3998 &picture_image->background_color,exception);
cristy63240882011-08-05 19:05:27 +00003999 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004000 rotate_image=RotateImage(picture_image,90.0,exception);
4001 picture_image=DestroyImage(picture_image);
4002 if (rotate_image == (Image *) NULL)
4003 return((Image *) NULL);
4004 picture_image=rotate_image;
4005 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
cristy5c4e2582011-09-11 19:21:03 +00004006 picture_image->columns,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00004007 picture_image=DestroyImage(picture_image);
4008 if (bend_image == (Image *) NULL)
4009 return((Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00004010 picture_image=bend_image;
4011 rotate_image=RotateImage(picture_image,-90.0,exception);
4012 picture_image=DestroyImage(picture_image);
4013 if (rotate_image == (Image *) NULL)
4014 return((Image *) NULL);
4015 picture_image=rotate_image;
4016 picture_image->background_color=image->background_color;
anthonyf46d4262012-03-26 03:30:34 +00004017 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
cristy3ed852e2009-09-05 21:47:34 +00004018 exception);
4019 if (polaroid_image == (Image *) NULL)
4020 {
4021 picture_image=DestroyImage(picture_image);
4022 return(picture_image);
4023 }
4024 flop_image=FlopImage(polaroid_image,exception);
4025 polaroid_image=DestroyImage(polaroid_image);
4026 if (flop_image == (Image *) NULL)
4027 {
4028 picture_image=DestroyImage(picture_image);
4029 return(picture_image);
4030 }
4031 polaroid_image=flop_image;
cristyfeb3e962012-03-29 17:25:55 +00004032 (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp,
cristy39172402012-03-30 13:04:39 +00004033 MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
cristy3ed852e2009-09-05 21:47:34 +00004034 picture_image=DestroyImage(picture_image);
cristy9950d572011-10-01 18:22:35 +00004035 (void) QueryColorCompliance("none",AllCompliance,
4036 &polaroid_image->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00004037 rotate_image=RotateImage(polaroid_image,angle,exception);
4038 polaroid_image=DestroyImage(polaroid_image);
4039 if (rotate_image == (Image *) NULL)
4040 return((Image *) NULL);
4041 polaroid_image=rotate_image;
4042 trim_image=TrimImage(polaroid_image,exception);
4043 polaroid_image=DestroyImage(polaroid_image);
4044 if (trim_image == (Image *) NULL)
4045 return((Image *) NULL);
4046 polaroid_image=trim_image;
4047 return(polaroid_image);
4048}
4049
4050/*
4051%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4052% %
4053% %
4054% %
cristy3ed852e2009-09-05 21:47:34 +00004055% S e p i a T o n e I m a g e %
4056% %
4057% %
4058% %
4059%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4060%
4061% MagickSepiaToneImage() applies a special effect to the image, similar to the
4062% effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4063% 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4064% threshold of 80% is a good starting point for a reasonable tone.
4065%
4066% The format of the SepiaToneImage method is:
4067%
4068% Image *SepiaToneImage(const Image *image,const double threshold,
4069% ExceptionInfo *exception)
4070%
4071% A description of each parameter follows:
4072%
4073% o image: the image.
4074%
4075% o threshold: the tone threshold.
4076%
4077% o exception: return any errors or warnings in this structure.
4078%
4079*/
4080MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4081 ExceptionInfo *exception)
4082{
4083#define SepiaToneImageTag "SepiaTone/Image"
4084
cristyc4c8d132010-01-07 01:58:38 +00004085 CacheView
4086 *image_view,
4087 *sepia_view;
4088
cristy3ed852e2009-09-05 21:47:34 +00004089 Image
4090 *sepia_image;
4091
cristy3ed852e2009-09-05 21:47:34 +00004092 MagickBooleanType
4093 status;
4094
cristybb503372010-05-27 20:51:26 +00004095 MagickOffsetType
4096 progress;
4097
4098 ssize_t
4099 y;
4100
cristy3ed852e2009-09-05 21:47:34 +00004101 /*
4102 Initialize sepia-toned image attributes.
4103 */
4104 assert(image != (const Image *) NULL);
4105 assert(image->signature == MagickSignature);
4106 if (image->debug != MagickFalse)
4107 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4108 assert(exception != (ExceptionInfo *) NULL);
4109 assert(exception->signature == MagickSignature);
cristy1707c6c2012-01-18 23:30:54 +00004110 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004111 if (sepia_image == (Image *) NULL)
4112 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004113 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004114 {
cristy3ed852e2009-09-05 21:47:34 +00004115 sepia_image=DestroyImage(sepia_image);
4116 return((Image *) NULL);
4117 }
4118 /*
4119 Tone each row of the image.
4120 */
4121 status=MagickTrue;
4122 progress=0;
cristy46ff2672012-12-14 15:32:26 +00004123 image_view=AcquireVirtualCacheView(image,exception);
4124 sepia_view=AcquireAuthenticCacheView(sepia_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00004125#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00004126 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00004127 magick_threads(image,sepia_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00004128#endif
cristybb503372010-05-27 20:51:26 +00004129 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004130 {
cristy4c08aed2011-07-01 19:47:50 +00004131 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004132 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00004133
cristybb503372010-05-27 20:51:26 +00004134 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004135 x;
4136
cristy4c08aed2011-07-01 19:47:50 +00004137 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004138 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004139
4140 if (status == MagickFalse)
4141 continue;
4142 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy1707c6c2012-01-18 23:30:54 +00004143 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00004144 exception);
cristy4c08aed2011-07-01 19:47:50 +00004145 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004146 {
4147 status=MagickFalse;
4148 continue;
4149 }
cristybb503372010-05-27 20:51:26 +00004150 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004151 {
cristya19f1d72012-08-07 18:24:38 +00004152 double
cristy3ed852e2009-09-05 21:47:34 +00004153 intensity,
4154 tone;
4155
cristyf13c5942012-08-08 23:50:11 +00004156 intensity=GetPixelIntensity(image,p);
cristya19f1d72012-08-07 18:24:38 +00004157 tone=intensity > threshold ? (double) QuantumRange : intensity+
4158 (double) QuantumRange-threshold;
cristy4c08aed2011-07-01 19:47:50 +00004159 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
cristya19f1d72012-08-07 18:24:38 +00004160 tone=intensity > (7.0*threshold/6.0) ? (double) QuantumRange :
4161 intensity+(double) QuantumRange-7.0*threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004162 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004163 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004164 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004165 tone=threshold/7.0;
cristya19f1d72012-08-07 18:24:38 +00004166 if ((double) GetPixelGreen(image,q) < tone)
cristy4c08aed2011-07-01 19:47:50 +00004167 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristya19f1d72012-08-07 18:24:38 +00004168 if ((double) GetPixelBlue(image,q) < tone)
cristy4c08aed2011-07-01 19:47:50 +00004169 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristyed231572011-07-14 02:18:59 +00004170 p+=GetPixelChannels(image);
4171 q+=GetPixelChannels(sepia_image);
cristy3ed852e2009-09-05 21:47:34 +00004172 }
4173 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4174 status=MagickFalse;
4175 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4176 {
4177 MagickBooleanType
4178 proceed;
4179
cristyb5d5f722009-11-04 03:03:49 +00004180#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00004181 #pragma omp critical (MagickCore_SepiaToneImage)
cristy3ed852e2009-09-05 21:47:34 +00004182#endif
4183 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4184 image->rows);
4185 if (proceed == MagickFalse)
4186 status=MagickFalse;
4187 }
4188 }
4189 sepia_view=DestroyCacheView(sepia_view);
4190 image_view=DestroyCacheView(image_view);
cristye23ec9d2011-08-16 18:15:40 +00004191 (void) NormalizeImage(sepia_image,exception);
4192 (void) ContrastImage(sepia_image,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004193 if (status == MagickFalse)
4194 sepia_image=DestroyImage(sepia_image);
4195 return(sepia_image);
4196}
4197
4198/*
4199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4200% %
4201% %
4202% %
4203% S h a d o w I m a g e %
4204% %
4205% %
4206% %
4207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4208%
4209% ShadowImage() simulates a shadow from the specified image and returns it.
4210%
4211% The format of the ShadowImage method is:
4212%
cristy70cddf72011-12-10 22:42:42 +00004213% Image *ShadowImage(const Image *image,const double alpha,
cristyaa2c16c2012-03-25 22:21:35 +00004214% const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4215% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004216%
4217% A description of each parameter follows:
4218%
4219% o image: the image.
4220%
cristy70cddf72011-12-10 22:42:42 +00004221% o alpha: percentage transparency.
cristy3ed852e2009-09-05 21:47:34 +00004222%
4223% o sigma: the standard deviation of the Gaussian, in pixels.
4224%
4225% o x_offset: the shadow x-offset.
4226%
4227% o y_offset: the shadow y-offset.
4228%
4229% o exception: return any errors or warnings in this structure.
4230%
4231*/
cristy70cddf72011-12-10 22:42:42 +00004232MagickExport Image *ShadowImage(const Image *image,const double alpha,
cristyaa2c16c2012-03-25 22:21:35 +00004233 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4234 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004235{
4236#define ShadowImageTag "Shadow/Image"
4237
cristy70cddf72011-12-10 22:42:42 +00004238 CacheView
4239 *image_view;
4240
cristybd5a96c2011-08-21 00:04:26 +00004241 ChannelType
4242 channel_mask;
4243
cristy3ed852e2009-09-05 21:47:34 +00004244 Image
4245 *border_image,
4246 *clone_image,
4247 *shadow_image;
4248
cristy70cddf72011-12-10 22:42:42 +00004249 MagickBooleanType
4250 status;
4251
cristy3ed852e2009-09-05 21:47:34 +00004252 RectangleInfo
4253 border_info;
4254
cristy70cddf72011-12-10 22:42:42 +00004255 ssize_t
4256 y;
4257
cristy3ed852e2009-09-05 21:47:34 +00004258 assert(image != (Image *) NULL);
4259 assert(image->signature == MagickSignature);
4260 if (image->debug != MagickFalse)
4261 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4262 assert(exception != (ExceptionInfo *) NULL);
4263 assert(exception->signature == MagickSignature);
4264 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4265 if (clone_image == (Image *) NULL)
4266 return((Image *) NULL);
cristya6400b12013-03-15 12:20:18 +00004267 if (IsGrayColorspace(image->colorspace) != MagickFalse)
4268 (void) TransformImageColorspace(clone_image,sRGBColorspace,exception);
cristy0ce08762012-06-30 01:33:18 +00004269 (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod,
cristy387430f2012-02-07 13:09:46 +00004270 exception);
cristybb503372010-05-27 20:51:26 +00004271 border_info.width=(size_t) floor(2.0*sigma+0.5);
4272 border_info.height=(size_t) floor(2.0*sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00004273 border_info.x=0;
4274 border_info.y=0;
cristy9950d572011-10-01 18:22:35 +00004275 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4276 exception);
cristy8a46d822012-08-28 23:32:39 +00004277 clone_image->alpha_trait=BlendPixelTrait;
cristy70cddf72011-12-10 22:42:42 +00004278 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
cristy3ed852e2009-09-05 21:47:34 +00004279 clone_image=DestroyImage(clone_image);
4280 if (border_image == (Image *) NULL)
4281 return((Image *) NULL);
cristy8a46d822012-08-28 23:32:39 +00004282 if (border_image->alpha_trait != BlendPixelTrait)
cristy63240882011-08-05 19:05:27 +00004283 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004284 /*
4285 Shadow image.
4286 */
cristy70cddf72011-12-10 22:42:42 +00004287 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00004288 image_view=AcquireAuthenticCacheView(border_image,exception);
cristy70cddf72011-12-10 22:42:42 +00004289 for (y=0; y < (ssize_t) border_image->rows; y++)
4290 {
4291 PixelInfo
4292 background_color;
4293
4294 register Quantum
4295 *restrict q;
4296
4297 register ssize_t
4298 x;
4299
4300 if (status == MagickFalse)
4301 continue;
4302 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4303 exception);
4304 if (q == (Quantum *) NULL)
4305 {
4306 status=MagickFalse;
4307 continue;
4308 }
4309 background_color=border_image->background_color;
cristy8a46d822012-08-28 23:32:39 +00004310 background_color.alpha_trait=BlendPixelTrait;
cristy70cddf72011-12-10 22:42:42 +00004311 for (x=0; x < (ssize_t) border_image->columns; x++)
4312 {
cristy8a46d822012-08-28 23:32:39 +00004313 if (border_image->alpha_trait == BlendPixelTrait)
cristy70cddf72011-12-10 22:42:42 +00004314 background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
4315 SetPixelInfoPixel(border_image,&background_color,q);
4316 q+=GetPixelChannels(border_image);
4317 }
4318 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4319 status=MagickFalse;
4320 }
4321 image_view=DestroyCacheView(image_view);
4322 if (status == MagickFalse)
4323 {
4324 border_image=DestroyImage(border_image);
4325 return((Image *) NULL);
4326 }
cristycf1296e2012-08-26 23:40:49 +00004327 channel_mask=SetImageChannelMask(border_image,AlphaChannel);
cristyaa2c16c2012-03-25 22:21:35 +00004328 shadow_image=BlurImage(border_image,0.0,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00004329 border_image=DestroyImage(border_image);
4330 if (shadow_image == (Image *) NULL)
4331 return((Image *) NULL);
cristycf1296e2012-08-26 23:40:49 +00004332 (void) SetPixelChannelMask(shadow_image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00004333 if (shadow_image->page.width == 0)
4334 shadow_image->page.width=shadow_image->columns;
4335 if (shadow_image->page.height == 0)
4336 shadow_image->page.height=shadow_image->rows;
cristybb503372010-05-27 20:51:26 +00004337 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4338 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4339 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4340 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
cristy3ed852e2009-09-05 21:47:34 +00004341 return(shadow_image);
4342}
4343
4344/*
4345%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4346% %
4347% %
4348% %
4349% S k e t c h I m a g e %
4350% %
4351% %
4352% %
4353%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4354%
4355% SketchImage() simulates a pencil sketch. We convolve the image with a
4356% Gaussian operator of the given radius and standard deviation (sigma). For
4357% reasonable results, radius should be larger than sigma. Use a radius of 0
4358% and SketchImage() selects a suitable radius for you. Angle gives the angle
4359% of the sketch.
4360%
4361% The format of the SketchImage method is:
4362%
4363% Image *SketchImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00004364% const double sigma,const double angle,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004365%
4366% A description of each parameter follows:
4367%
4368% o image: the image.
4369%
cristy574cc262011-08-05 01:23:58 +00004370% o radius: the radius of the Gaussian, in pixels, not counting the
4371% center pixel.
cristy3ed852e2009-09-05 21:47:34 +00004372%
4373% o sigma: the standard deviation of the Gaussian, in pixels.
4374%
cristyf7ef0252011-09-09 14:50:06 +00004375% o angle: apply the effect along this angle.
4376%
cristy3ed852e2009-09-05 21:47:34 +00004377% o exception: return any errors or warnings in this structure.
4378%
4379*/
4380MagickExport Image *SketchImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00004381 const double sigma,const double angle,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004382{
cristyfa112112010-01-04 17:48:07 +00004383 CacheView
4384 *random_view;
4385
cristy3ed852e2009-09-05 21:47:34 +00004386 Image
4387 *blend_image,
4388 *blur_image,
4389 *dodge_image,
4390 *random_image,
4391 *sketch_image;
4392
cristy3ed852e2009-09-05 21:47:34 +00004393 MagickBooleanType
4394 status;
4395
cristy3ed852e2009-09-05 21:47:34 +00004396 RandomInfo
cristyfa112112010-01-04 17:48:07 +00004397 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +00004398
cristy9d314ff2011-03-09 01:30:28 +00004399 ssize_t
4400 y;
4401
glennrpf7659d72012-09-24 18:14:56 +00004402#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004403 unsigned long
4404 key;
glennrpf7659d72012-09-24 18:14:56 +00004405#endif
cristy57340e02012-05-05 00:53:23 +00004406
cristy3ed852e2009-09-05 21:47:34 +00004407 /*
4408 Sketch image.
4409 */
4410 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4411 MagickTrue,exception);
4412 if (random_image == (Image *) NULL)
4413 return((Image *) NULL);
4414 status=MagickTrue;
cristy1b784432009-12-19 02:20:40 +00004415 random_info=AcquireRandomInfoThreadSet();
glennrpf7659d72012-09-24 18:14:56 +00004416#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004417 key=GetRandomSecretKey(random_info[0]);
glennrpf7659d72012-09-24 18:14:56 +00004418#endif
cristy46ff2672012-12-14 15:32:26 +00004419 random_view=AcquireAuthenticCacheView(random_image,exception);
cristy1b784432009-12-19 02:20:40 +00004420#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004421 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00004422 magick_threads(random_image,random_image,random_image->rows,key == ~0UL)
cristy1b784432009-12-19 02:20:40 +00004423#endif
cristybb503372010-05-27 20:51:26 +00004424 for (y=0; y < (ssize_t) random_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004425 {
cristy5c9e6f22010-09-17 17:31:01 +00004426 const int
4427 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00004428
cristybb503372010-05-27 20:51:26 +00004429 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004430 x;
4431
cristy4c08aed2011-07-01 19:47:50 +00004432 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004433 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004434
cristy1b784432009-12-19 02:20:40 +00004435 if (status == MagickFalse)
4436 continue;
cristy3ed852e2009-09-05 21:47:34 +00004437 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4438 exception);
cristyacd2ed22011-08-30 01:44:23 +00004439 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004440 {
4441 status=MagickFalse;
4442 continue;
4443 }
cristybb503372010-05-27 20:51:26 +00004444 for (x=0; x < (ssize_t) random_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004445 {
cristya19f1d72012-08-07 18:24:38 +00004446 double
cristy76f512e2011-09-12 01:26:56 +00004447 value;
4448
4449 register ssize_t
4450 i;
4451
cristy883fde12013-04-08 00:50:13 +00004452 if (GetPixelReadMask(random_image,q) == 0)
cristy10a6c612012-01-29 21:41:05 +00004453 {
4454 q+=GetPixelChannels(random_image);
4455 continue;
4456 }
cristy76f512e2011-09-12 01:26:56 +00004457 value=GetPseudoRandomValue(random_info[id]);
4458 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4459 {
cristy5a23c552013-02-13 14:34:28 +00004460 PixelChannel channel=GetPixelChannelChannel(image,i);
4461 PixelTrait traits=GetPixelChannelTraits(image,channel);
cristy76f512e2011-09-12 01:26:56 +00004462 if (traits == UndefinedPixelTrait)
4463 continue;
4464 q[i]=ClampToQuantum(QuantumRange*value);
4465 }
cristyed231572011-07-14 02:18:59 +00004466 q+=GetPixelChannels(random_image);
cristy3ed852e2009-09-05 21:47:34 +00004467 }
4468 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4469 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004470 }
4471 random_view=DestroyCacheView(random_view);
cristy1b784432009-12-19 02:20:40 +00004472 random_info=DestroyRandomInfoThreadSet(random_info);
cristy3ed852e2009-09-05 21:47:34 +00004473 if (status == MagickFalse)
4474 {
4475 random_image=DestroyImage(random_image);
4476 return(random_image);
4477 }
cristyaa2c16c2012-03-25 22:21:35 +00004478 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00004479 random_image=DestroyImage(random_image);
4480 if (blur_image == (Image *) NULL)
4481 return((Image *) NULL);
cristy32d746f2013-03-25 18:33:17 +00004482 dodge_image=EdgeImage(blur_image,GetOptimalKernelWidth1D(radius,0.5),
cristyfe249712013-03-25 18:28:48 +00004483 exception);
cristy3ed852e2009-09-05 21:47:34 +00004484 blur_image=DestroyImage(blur_image);
4485 if (dodge_image == (Image *) NULL)
4486 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +00004487 (void) NormalizeImage(dodge_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +00004488 (void) NegateImage(dodge_image,MagickFalse,exception);
cristye941a752011-10-15 01:52:48 +00004489 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
cristy3ed852e2009-09-05 21:47:34 +00004490 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4491 if (sketch_image == (Image *) NULL)
4492 {
4493 dodge_image=DestroyImage(dodge_image);
4494 return((Image *) NULL);
4495 }
cristyfeb3e962012-03-29 17:25:55 +00004496 (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp,
cristy39172402012-03-30 13:04:39 +00004497 MagickTrue,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004498 dodge_image=DestroyImage(dodge_image);
4499 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4500 if (blend_image == (Image *) NULL)
4501 {
4502 sketch_image=DestroyImage(sketch_image);
4503 return((Image *) NULL);
4504 }
4505 (void) SetImageArtifact(blend_image,"compose:args","20x80");
cristy39172402012-03-30 13:04:39 +00004506 (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue,
cristyfeb3e962012-03-29 17:25:55 +00004507 0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004508 blend_image=DestroyImage(blend_image);
4509 return(sketch_image);
4510}
4511
4512/*
4513%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4514% %
4515% %
4516% %
4517% S o l a r i z e I m a g e %
4518% %
4519% %
4520% %
4521%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4522%
4523% SolarizeImage() applies a special effect to the image, similar to the effect
4524% achieved in a photo darkroom by selectively exposing areas of photo
4525% sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4526% measure of the extent of the solarization.
4527%
4528% The format of the SolarizeImage method is:
4529%
cristy5cbc0162011-08-29 00:36:28 +00004530% MagickBooleanType SolarizeImage(Image *image,const double threshold,
4531% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004532%
4533% A description of each parameter follows:
4534%
4535% o image: the image.
4536%
4537% o threshold: Define the extent of the solarization.
4538%
cristy5cbc0162011-08-29 00:36:28 +00004539% o exception: return any errors or warnings in this structure.
4540%
cristy3ed852e2009-09-05 21:47:34 +00004541*/
4542MagickExport MagickBooleanType SolarizeImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00004543 const double threshold,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004544{
4545#define SolarizeImageTag "Solarize/Image"
4546
cristyc4c8d132010-01-07 01:58:38 +00004547 CacheView
4548 *image_view;
4549
cristy3ed852e2009-09-05 21:47:34 +00004550 MagickBooleanType
4551 status;
4552
cristybb503372010-05-27 20:51:26 +00004553 MagickOffsetType
4554 progress;
4555
4556 ssize_t
4557 y;
4558
cristy3ed852e2009-09-05 21:47:34 +00004559 assert(image != (Image *) NULL);
4560 assert(image->signature == MagickSignature);
4561 if (image->debug != MagickFalse)
4562 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristya6400b12013-03-15 12:20:18 +00004563 if (IsGrayColorspace(image->colorspace) != MagickFalse)
4564 (void) TransformImageColorspace(image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00004565 if (image->storage_class == PseudoClass)
4566 {
cristybb503372010-05-27 20:51:26 +00004567 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004568 i;
4569
4570 /*
4571 Solarize colormap.
4572 */
cristybb503372010-05-27 20:51:26 +00004573 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00004574 {
cristya19f1d72012-08-07 18:24:38 +00004575 if ((double) image->colormap[i].red > threshold)
cristy6e963d82012-06-19 15:23:24 +00004576 image->colormap[i].red=QuantumRange-image->colormap[i].red;
cristya19f1d72012-08-07 18:24:38 +00004577 if ((double) image->colormap[i].green > threshold)
cristy6e963d82012-06-19 15:23:24 +00004578 image->colormap[i].green=QuantumRange-
cristy3ed852e2009-09-05 21:47:34 +00004579 image->colormap[i].green;
cristya19f1d72012-08-07 18:24:38 +00004580 if ((double) image->colormap[i].blue > threshold)
cristy6e963d82012-06-19 15:23:24 +00004581 image->colormap[i].blue=QuantumRange-
cristy3ed852e2009-09-05 21:47:34 +00004582 image->colormap[i].blue;
4583 }
4584 }
4585 /*
4586 Solarize image.
4587 */
4588 status=MagickTrue;
4589 progress=0;
cristy46ff2672012-12-14 15:32:26 +00004590 image_view=AcquireAuthenticCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00004591#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00004592 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00004593 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00004594#endif
cristybb503372010-05-27 20:51:26 +00004595 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004596 {
cristybb503372010-05-27 20:51:26 +00004597 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004598 x;
4599
cristy4c08aed2011-07-01 19:47:50 +00004600 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004601 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004602
4603 if (status == MagickFalse)
4604 continue;
cristy5cbc0162011-08-29 00:36:28 +00004605 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004606 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004607 {
4608 status=MagickFalse;
4609 continue;
4610 }
cristybb503372010-05-27 20:51:26 +00004611 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004612 {
cristy76f512e2011-09-12 01:26:56 +00004613 register ssize_t
4614 i;
4615
cristy883fde12013-04-08 00:50:13 +00004616 if (GetPixelReadMask(image,q) == 0)
cristy10a6c612012-01-29 21:41:05 +00004617 {
4618 q+=GetPixelChannels(image);
4619 continue;
4620 }
cristy76f512e2011-09-12 01:26:56 +00004621 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4622 {
cristy5a23c552013-02-13 14:34:28 +00004623 PixelChannel channel=GetPixelChannelChannel(image,i);
4624 PixelTrait traits=GetPixelChannelTraits(image,channel);
cristy76f512e2011-09-12 01:26:56 +00004625 if ((traits == UndefinedPixelTrait) ||
4626 ((traits & CopyPixelTrait) != 0))
4627 continue;
cristya19f1d72012-08-07 18:24:38 +00004628 if ((double) q[i] > threshold)
cristy76f512e2011-09-12 01:26:56 +00004629 q[i]=QuantumRange-q[i];
4630 }
cristyed231572011-07-14 02:18:59 +00004631 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004632 }
4633 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4634 status=MagickFalse;
4635 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4636 {
4637 MagickBooleanType
4638 proceed;
4639
cristyb5d5f722009-11-04 03:03:49 +00004640#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00004641 #pragma omp critical (MagickCore_SolarizeImage)
cristy3ed852e2009-09-05 21:47:34 +00004642#endif
4643 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4644 if (proceed == MagickFalse)
4645 status=MagickFalse;
4646 }
4647 }
4648 image_view=DestroyCacheView(image_view);
4649 return(status);
4650}
4651
4652/*
4653%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4654% %
4655% %
4656% %
4657% S t e g a n o I m a g e %
4658% %
4659% %
4660% %
4661%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4662%
4663% SteganoImage() hides a digital watermark within the image. Recover
4664% the hidden watermark later to prove that the authenticity of an image.
4665% Offset defines the start position within the image to hide the watermark.
4666%
4667% The format of the SteganoImage method is:
4668%
4669% Image *SteganoImage(const Image *image,Image *watermark,
4670% ExceptionInfo *exception)
4671%
4672% A description of each parameter follows:
4673%
4674% o image: the image.
4675%
4676% o watermark: the watermark image.
4677%
4678% o exception: return any errors or warnings in this structure.
4679%
4680*/
4681MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4682 ExceptionInfo *exception)
4683{
cristye1bf8ad2010-09-19 17:07:03 +00004684#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
cristy4c08aed2011-07-01 19:47:50 +00004685#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
cristyeaedf062010-05-29 22:36:02 +00004686 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
cristy3ed852e2009-09-05 21:47:34 +00004687#define SteganoImageTag "Stegano/Image"
4688
cristyb0d3bb92010-09-22 14:37:58 +00004689 CacheView
4690 *stegano_view,
4691 *watermark_view;
4692
cristy3ed852e2009-09-05 21:47:34 +00004693 Image
4694 *stegano_image;
4695
4696 int
4697 c;
4698
cristy3ed852e2009-09-05 21:47:34 +00004699 MagickBooleanType
4700 status;
4701
cristy101ab702011-10-13 13:06:32 +00004702 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00004703 pixel;
4704
cristy4c08aed2011-07-01 19:47:50 +00004705 register Quantum
cristy3ed852e2009-09-05 21:47:34 +00004706 *q;
4707
cristye1bf8ad2010-09-19 17:07:03 +00004708 register ssize_t
4709 x;
4710
cristybb503372010-05-27 20:51:26 +00004711 size_t
cristyeaedf062010-05-29 22:36:02 +00004712 depth,
4713 one;
cristy3ed852e2009-09-05 21:47:34 +00004714
cristye1bf8ad2010-09-19 17:07:03 +00004715 ssize_t
4716 i,
4717 j,
4718 k,
4719 y;
4720
cristy3ed852e2009-09-05 21:47:34 +00004721 /*
4722 Initialize steganographic image attributes.
4723 */
4724 assert(image != (const Image *) NULL);
4725 assert(image->signature == MagickSignature);
4726 if (image->debug != MagickFalse)
4727 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4728 assert(watermark != (const Image *) NULL);
4729 assert(watermark->signature == MagickSignature);
4730 assert(exception != (ExceptionInfo *) NULL);
4731 assert(exception->signature == MagickSignature);
cristyeaedf062010-05-29 22:36:02 +00004732 one=1UL;
cristy3ed852e2009-09-05 21:47:34 +00004733 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4734 if (stegano_image == (Image *) NULL)
4735 return((Image *) NULL);
cristyf61b1832012-04-01 01:38:19 +00004736 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
cristy574cc262011-08-05 01:23:58 +00004737 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004738 {
cristy3ed852e2009-09-05 21:47:34 +00004739 stegano_image=DestroyImage(stegano_image);
4740 return((Image *) NULL);
4741 }
cristy3ed852e2009-09-05 21:47:34 +00004742 /*
4743 Hide watermark in low-order bits of image.
4744 */
4745 c=0;
4746 i=0;
4747 j=0;
4748 depth=stegano_image->depth;
cristyf61b1832012-04-01 01:38:19 +00004749 k=stegano_image->offset;
cristyda16f162011-02-19 23:52:17 +00004750 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00004751 watermark_view=AcquireVirtualCacheView(watermark,exception);
4752 stegano_view=AcquireAuthenticCacheView(stegano_image,exception);
cristybb503372010-05-27 20:51:26 +00004753 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
cristy3ed852e2009-09-05 21:47:34 +00004754 {
cristybb503372010-05-27 20:51:26 +00004755 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
cristy3ed852e2009-09-05 21:47:34 +00004756 {
cristybb503372010-05-27 20:51:26 +00004757 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
cristy3ed852e2009-09-05 21:47:34 +00004758 {
cristy1707c6c2012-01-18 23:30:54 +00004759 ssize_t
4760 offset;
4761
cristyf05d4942012-03-17 16:26:09 +00004762 (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel,
cristyda1f9c12011-10-02 21:39:49 +00004763 exception);
cristy1707c6c2012-01-18 23:30:54 +00004764 offset=k/(ssize_t) stegano_image->columns;
4765 if (offset >= (ssize_t) stegano_image->rows)
cristy3ed852e2009-09-05 21:47:34 +00004766 break;
cristyb0d3bb92010-09-22 14:37:58 +00004767 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4768 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4769 exception);
cristyacd2ed22011-08-30 01:44:23 +00004770 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004771 break;
4772 switch (c)
4773 {
4774 case 0:
4775 {
cristyf61b1832012-04-01 01:38:19 +00004776 SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j,
4777 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004778 break;
4779 }
4780 case 1:
4781 {
cristyf61b1832012-04-01 01:38:19 +00004782 SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j,
4783 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004784 break;
4785 }
4786 case 2:
4787 {
cristyf61b1832012-04-01 01:38:19 +00004788 SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j,
4789 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004790 break;
4791 }
4792 }
cristyb0d3bb92010-09-22 14:37:58 +00004793 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004794 break;
4795 c++;
4796 if (c == 3)
4797 c=0;
4798 k++;
cristybb503372010-05-27 20:51:26 +00004799 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
cristy3ed852e2009-09-05 21:47:34 +00004800 k=0;
cristyf61b1832012-04-01 01:38:19 +00004801 if (k == stegano_image->offset)
cristy3ed852e2009-09-05 21:47:34 +00004802 j++;
4803 }
4804 }
cristy8b27a6d2010-02-14 03:31:15 +00004805 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004806 {
cristy8b27a6d2010-02-14 03:31:15 +00004807 MagickBooleanType
4808 proceed;
4809
4810 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4811 (depth-i),depth);
4812 if (proceed == MagickFalse)
4813 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004814 }
4815 }
cristyb0d3bb92010-09-22 14:37:58 +00004816 stegano_view=DestroyCacheView(stegano_view);
4817 watermark_view=DestroyCacheView(watermark_view);
cristyda16f162011-02-19 23:52:17 +00004818 if (status == MagickFalse)
cristyfab83642012-12-14 00:31:38 +00004819 stegano_image=DestroyImage(stegano_image);
cristy3ed852e2009-09-05 21:47:34 +00004820 return(stegano_image);
4821}
4822
4823/*
4824%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4825% %
4826% %
4827% %
4828% S t e r e o A n a g l y p h I m a g e %
4829% %
4830% %
4831% %
4832%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4833%
4834% StereoAnaglyphImage() combines two images and produces a single image that
4835% is the composite of a left and right image of a stereo pair. Special
4836% red-green stereo glasses are required to view this effect.
4837%
4838% The format of the StereoAnaglyphImage method is:
4839%
4840% Image *StereoImage(const Image *left_image,const Image *right_image,
4841% ExceptionInfo *exception)
4842% Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004843% const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004844% ExceptionInfo *exception)
4845%
4846% A description of each parameter follows:
4847%
4848% o left_image: the left image.
4849%
4850% o right_image: the right image.
4851%
4852% o exception: return any errors or warnings in this structure.
4853%
4854% o x_offset: amount, in pixels, by which the left image is offset to the
4855% right of the right image.
4856%
4857% o y_offset: amount, in pixels, by which the left image is offset to the
4858% bottom of the right image.
4859%
4860%
4861*/
4862MagickExport Image *StereoImage(const Image *left_image,
4863 const Image *right_image,ExceptionInfo *exception)
4864{
4865 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4866}
4867
4868MagickExport Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004869 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004870 ExceptionInfo *exception)
4871{
4872#define StereoImageTag "Stereo/Image"
4873
4874 const Image
4875 *image;
4876
4877 Image
4878 *stereo_image;
4879
cristy3ed852e2009-09-05 21:47:34 +00004880 MagickBooleanType
4881 status;
4882
cristy9d314ff2011-03-09 01:30:28 +00004883 ssize_t
4884 y;
4885
cristy3ed852e2009-09-05 21:47:34 +00004886 assert(left_image != (const Image *) NULL);
4887 assert(left_image->signature == MagickSignature);
4888 if (left_image->debug != MagickFalse)
4889 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4890 left_image->filename);
4891 assert(right_image != (const Image *) NULL);
4892 assert(right_image->signature == MagickSignature);
4893 assert(exception != (ExceptionInfo *) NULL);
4894 assert(exception->signature == MagickSignature);
4895 assert(right_image != (const Image *) NULL);
4896 image=left_image;
4897 if ((left_image->columns != right_image->columns) ||
4898 (left_image->rows != right_image->rows))
4899 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4900 /*
4901 Initialize stereo image attributes.
4902 */
4903 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4904 MagickTrue,exception);
4905 if (stereo_image == (Image *) NULL)
4906 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004907 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004908 {
cristy3ed852e2009-09-05 21:47:34 +00004909 stereo_image=DestroyImage(stereo_image);
4910 return((Image *) NULL);
4911 }
cristy079c78d2012-07-03 11:53:48 +00004912 (void) SetImageColorspace(stereo_image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00004913 /*
4914 Copy left image to red channel and right image to blue channel.
4915 */
cristyda16f162011-02-19 23:52:17 +00004916 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00004917 for (y=0; y < (ssize_t) stereo_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004918 {
cristy4c08aed2011-07-01 19:47:50 +00004919 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004920 *restrict p,
4921 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004922
cristybb503372010-05-27 20:51:26 +00004923 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004924 x;
4925
cristy4c08aed2011-07-01 19:47:50 +00004926 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004927 *restrict r;
cristy3ed852e2009-09-05 21:47:34 +00004928
4929 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4930 exception);
4931 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4932 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
cristy76f512e2011-09-12 01:26:56 +00004933 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4934 (r == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004935 break;
cristybb503372010-05-27 20:51:26 +00004936 for (x=0; x < (ssize_t) stereo_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004937 {
cristy4c08aed2011-07-01 19:47:50 +00004938 SetPixelRed(image,GetPixelRed(left_image,p),r);
cristy76f512e2011-09-12 01:26:56 +00004939 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4940 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4941 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4942 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4943 GetPixelAlpha(right_image,q))/2,r);
cristyed231572011-07-14 02:18:59 +00004944 p+=GetPixelChannels(left_image);
cristy76f512e2011-09-12 01:26:56 +00004945 q+=GetPixelChannels(right_image);
4946 r+=GetPixelChannels(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004947 }
4948 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4949 break;
cristy8b27a6d2010-02-14 03:31:15 +00004950 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004951 {
cristy8b27a6d2010-02-14 03:31:15 +00004952 MagickBooleanType
4953 proceed;
4954
cristybb503372010-05-27 20:51:26 +00004955 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4956 stereo_image->rows);
cristy8b27a6d2010-02-14 03:31:15 +00004957 if (proceed == MagickFalse)
4958 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004959 }
4960 }
cristyda16f162011-02-19 23:52:17 +00004961 if (status == MagickFalse)
cristyfab83642012-12-14 00:31:38 +00004962 stereo_image=DestroyImage(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004963 return(stereo_image);
4964}
4965
4966/*
4967%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4968% %
4969% %
4970% %
4971% S w i r l I m a g e %
4972% %
4973% %
4974% %
4975%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4976%
4977% SwirlImage() swirls the pixels about the center of the image, where
4978% degrees indicates the sweep of the arc through which each pixel is moved.
4979% You get a more dramatic effect as the degrees move from 1 to 360.
4980%
4981% The format of the SwirlImage method is:
4982%
4983% Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004984% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004985%
4986% A description of each parameter follows:
4987%
4988% o image: the image.
4989%
4990% o degrees: Define the tightness of the swirling effect.
4991%
cristy76f512e2011-09-12 01:26:56 +00004992% o method: the pixel interpolation method.
4993%
cristy3ed852e2009-09-05 21:47:34 +00004994% o exception: return any errors or warnings in this structure.
4995%
4996*/
4997MagickExport Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004998 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004999{
5000#define SwirlImageTag "Swirl/Image"
5001
cristyfa112112010-01-04 17:48:07 +00005002 CacheView
5003 *image_view,
5004 *swirl_view;
5005
cristy3ed852e2009-09-05 21:47:34 +00005006 Image
5007 *swirl_image;
5008
cristy3ed852e2009-09-05 21:47:34 +00005009 MagickBooleanType
5010 status;
5011
cristybb503372010-05-27 20:51:26 +00005012 MagickOffsetType
5013 progress;
5014
cristya19f1d72012-08-07 18:24:38 +00005015 double
cristy3ed852e2009-09-05 21:47:34 +00005016 radius;
5017
5018 PointInfo
5019 center,
5020 scale;
5021
cristybb503372010-05-27 20:51:26 +00005022 ssize_t
5023 y;
5024
cristy3ed852e2009-09-05 21:47:34 +00005025 /*
5026 Initialize swirl image attributes.
5027 */
5028 assert(image != (const Image *) NULL);
5029 assert(image->signature == MagickSignature);
5030 if (image->debug != MagickFalse)
5031 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5032 assert(exception != (ExceptionInfo *) NULL);
5033 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00005034 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005035 if (swirl_image == (Image *) NULL)
5036 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005037 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005038 {
cristy3ed852e2009-09-05 21:47:34 +00005039 swirl_image=DestroyImage(swirl_image);
5040 return((Image *) NULL);
5041 }
cristy4c08aed2011-07-01 19:47:50 +00005042 if (swirl_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00005043 swirl_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00005044 /*
5045 Compute scaling factor.
5046 */
5047 center.x=(double) image->columns/2.0;
5048 center.y=(double) image->rows/2.0;
5049 radius=MagickMax(center.x,center.y);
5050 scale.x=1.0;
5051 scale.y=1.0;
5052 if (image->columns > image->rows)
5053 scale.y=(double) image->columns/(double) image->rows;
5054 else
5055 if (image->columns < image->rows)
5056 scale.x=(double) image->rows/(double) image->columns;
5057 degrees=(double) DegreesToRadians(degrees);
5058 /*
5059 Swirl image.
5060 */
5061 status=MagickTrue;
5062 progress=0;
cristy46ff2672012-12-14 15:32:26 +00005063 image_view=AcquireVirtualCacheView(image,exception);
5064 swirl_view=AcquireAuthenticCacheView(swirl_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00005065#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005066 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00005067 magick_threads(image,swirl_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005068#endif
cristybb503372010-05-27 20:51:26 +00005069 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005070 {
cristya19f1d72012-08-07 18:24:38 +00005071 double
cristy3ed852e2009-09-05 21:47:34 +00005072 distance;
5073
5074 PointInfo
5075 delta;
5076
cristy6d188022011-09-12 13:23:33 +00005077 register const Quantum
5078 *restrict p;
5079
cristybb503372010-05-27 20:51:26 +00005080 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005081 x;
5082
cristy4c08aed2011-07-01 19:47:50 +00005083 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005084 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005085
5086 if (status == MagickFalse)
5087 continue;
cristy6d188022011-09-12 13:23:33 +00005088 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy1707c6c2012-01-18 23:30:54 +00005089 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00005090 exception);
cristy6d188022011-09-12 13:23:33 +00005091 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005092 {
5093 status=MagickFalse;
5094 continue;
5095 }
cristy3ed852e2009-09-05 21:47:34 +00005096 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00005097 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005098 {
5099 /*
5100 Determine if the pixel is within an ellipse.
5101 */
cristy883fde12013-04-08 00:50:13 +00005102 if (GetPixelReadMask(image,p) == 0)
cristy10a6c612012-01-29 21:41:05 +00005103 {
5104 p+=GetPixelChannels(image);
5105 q+=GetPixelChannels(swirl_image);
5106 continue;
5107 }
cristy3ed852e2009-09-05 21:47:34 +00005108 delta.x=scale.x*(double) (x-center.x);
5109 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00005110 if (distance >= (radius*radius))
5111 {
cristy1707c6c2012-01-18 23:30:54 +00005112 register ssize_t
5113 i;
5114
cristy6d188022011-09-12 13:23:33 +00005115 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristy1707c6c2012-01-18 23:30:54 +00005116 {
cristy5a23c552013-02-13 14:34:28 +00005117 PixelChannel channel=GetPixelChannelChannel(image,i);
5118 PixelTrait traits=GetPixelChannelTraits(image,channel);
5119 PixelTrait swirl_traits=GetPixelChannelTraits(swirl_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00005120 if ((traits == UndefinedPixelTrait) ||
5121 (swirl_traits == UndefinedPixelTrait))
5122 continue;
5123 SetPixelChannel(swirl_image,channel,p[i],q);
5124 }
cristy6d188022011-09-12 13:23:33 +00005125 }
5126 else
cristy3ed852e2009-09-05 21:47:34 +00005127 {
cristya19f1d72012-08-07 18:24:38 +00005128 double
cristy3ed852e2009-09-05 21:47:34 +00005129 cosine,
5130 factor,
5131 sine;
5132
5133 /*
5134 Swirl the pixel.
5135 */
5136 factor=1.0-sqrt((double) distance)/radius;
5137 sine=sin((double) (degrees*factor*factor));
5138 cosine=cos((double) (degrees*factor*factor));
cristy76f512e2011-09-12 01:26:56 +00005139 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5140 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5141 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00005142 }
cristy6d188022011-09-12 13:23:33 +00005143 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00005144 q+=GetPixelChannels(swirl_image);
cristy3ed852e2009-09-05 21:47:34 +00005145 }
5146 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5147 status=MagickFalse;
5148 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5149 {
5150 MagickBooleanType
5151 proceed;
5152
cristyb5d5f722009-11-04 03:03:49 +00005153#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005154 #pragma omp critical (MagickCore_SwirlImage)
cristy3ed852e2009-09-05 21:47:34 +00005155#endif
5156 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5157 if (proceed == MagickFalse)
5158 status=MagickFalse;
5159 }
5160 }
5161 swirl_view=DestroyCacheView(swirl_view);
5162 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005163 if (status == MagickFalse)
5164 swirl_image=DestroyImage(swirl_image);
5165 return(swirl_image);
5166}
5167
5168/*
5169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5170% %
5171% %
5172% %
5173% T i n t I m a g e %
5174% %
5175% %
5176% %
5177%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5178%
5179% TintImage() applies a color vector to each pixel in the image. The length
5180% of the vector is 0 for black and white and at its maximum for the midtones.
5181% The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5182%
5183% The format of the TintImage method is:
5184%
cristyb817c3f2011-10-03 14:00:35 +00005185% Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005186% const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005187%
5188% A description of each parameter follows:
5189%
5190% o image: the image.
5191%
cristyb817c3f2011-10-03 14:00:35 +00005192% o blend: A color value used for tinting.
cristy3ed852e2009-09-05 21:47:34 +00005193%
5194% o tint: A color value used for tinting.
5195%
5196% o exception: return any errors or warnings in this structure.
5197%
5198*/
cristyb817c3f2011-10-03 14:00:35 +00005199MagickExport Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005200 const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005201{
5202#define TintImageTag "Tint/Image"
5203
cristyc4c8d132010-01-07 01:58:38 +00005204 CacheView
5205 *image_view,
5206 *tint_view;
5207
cristy3ed852e2009-09-05 21:47:34 +00005208 GeometryInfo
5209 geometry_info;
5210
5211 Image
5212 *tint_image;
5213
cristy3ed852e2009-09-05 21:47:34 +00005214 MagickBooleanType
5215 status;
5216
cristybb503372010-05-27 20:51:26 +00005217 MagickOffsetType
5218 progress;
cristy3ed852e2009-09-05 21:47:34 +00005219
cristya19f1d72012-08-07 18:24:38 +00005220 double
cristy28474bf2011-09-11 23:32:52 +00005221 intensity;
5222
cristy4c08aed2011-07-01 19:47:50 +00005223 PixelInfo
cristy1707c6c2012-01-18 23:30:54 +00005224 color_vector;
cristy3ed852e2009-09-05 21:47:34 +00005225
cristybb503372010-05-27 20:51:26 +00005226 MagickStatusType
5227 flags;
5228
5229 ssize_t
5230 y;
5231
cristy3ed852e2009-09-05 21:47:34 +00005232 /*
5233 Allocate tint image.
5234 */
5235 assert(image != (const Image *) NULL);
5236 assert(image->signature == MagickSignature);
5237 if (image->debug != MagickFalse)
5238 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5239 assert(exception != (ExceptionInfo *) NULL);
5240 assert(exception->signature == MagickSignature);
5241 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5242 if (tint_image == (Image *) NULL)
5243 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005244 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005245 {
cristy3ed852e2009-09-05 21:47:34 +00005246 tint_image=DestroyImage(tint_image);
5247 return((Image *) NULL);
5248 }
cristya6400b12013-03-15 12:20:18 +00005249 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
cristy4dab3802013-03-15 22:08:15 +00005250 (IsPixelInfoGray(tint) == MagickFalse))
cristya6400b12013-03-15 12:20:18 +00005251 (void) SetImageColorspace(tint_image,sRGBColorspace,exception);
cristyaed9c382011-10-03 17:54:21 +00005252 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005253 return(tint_image);
5254 /*
5255 Determine RGB values of the color.
5256 */
cristy1707c6c2012-01-18 23:30:54 +00005257 GetPixelInfo(image,&color_vector);
cristyb817c3f2011-10-03 14:00:35 +00005258 flags=ParseGeometry(blend,&geometry_info);
cristy1707c6c2012-01-18 23:30:54 +00005259 color_vector.red=geometry_info.rho;
5260 color_vector.green=geometry_info.rho;
5261 color_vector.blue=geometry_info.rho;
cristy92ac5722013-03-09 15:09:38 +00005262 color_vector.alpha=(MagickRealType) OpaqueAlpha;
cristy3ed852e2009-09-05 21:47:34 +00005263 if ((flags & SigmaValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005264 color_vector.green=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00005265 if ((flags & XiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005266 color_vector.blue=geometry_info.xi;
cristyb817c3f2011-10-03 14:00:35 +00005267 if ((flags & PsiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005268 color_vector.alpha=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005269 if (image->colorspace == CMYKColorspace)
5270 {
cristy1707c6c2012-01-18 23:30:54 +00005271 color_vector.black=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005272 if ((flags & PsiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005273 color_vector.black=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005274 if ((flags & ChiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005275 color_vector.alpha=geometry_info.chi;
cristy76f512e2011-09-12 01:26:56 +00005276 }
cristya19f1d72012-08-07 18:24:38 +00005277 intensity=(double) GetPixelInfoIntensity(tint);
5278 color_vector.red=(double) (color_vector.red*tint->red/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005279 intensity);
cristya19f1d72012-08-07 18:24:38 +00005280 color_vector.green=(double) (color_vector.green*tint->green/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005281 intensity);
cristya19f1d72012-08-07 18:24:38 +00005282 color_vector.blue=(double) (color_vector.blue*tint->blue/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005283 intensity);
cristya19f1d72012-08-07 18:24:38 +00005284 color_vector.black=(double) (color_vector.black*tint->black/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005285 intensity);
cristya19f1d72012-08-07 18:24:38 +00005286 color_vector.alpha=(double) (color_vector.alpha*tint->alpha/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005287 intensity);
cristy3ed852e2009-09-05 21:47:34 +00005288 /*
5289 Tint image.
5290 */
5291 status=MagickTrue;
5292 progress=0;
cristy46ff2672012-12-14 15:32:26 +00005293 image_view=AcquireVirtualCacheView(image,exception);
5294 tint_view=AcquireAuthenticCacheView(tint_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00005295#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005296 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00005297 magick_threads(image,tint_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005298#endif
cristybb503372010-05-27 20:51:26 +00005299 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005300 {
cristy4c08aed2011-07-01 19:47:50 +00005301 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00005302 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00005303
cristy4c08aed2011-07-01 19:47:50 +00005304 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005305 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005306
cristy6b91acb2011-04-19 12:23:54 +00005307 register ssize_t
5308 x;
5309
cristy3ed852e2009-09-05 21:47:34 +00005310 if (status == MagickFalse)
5311 continue;
5312 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5313 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5314 exception);
cristy4c08aed2011-07-01 19:47:50 +00005315 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005316 {
5317 status=MagickFalse;
5318 continue;
5319 }
cristybb503372010-05-27 20:51:26 +00005320 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005321 {
cristy4c08aed2011-07-01 19:47:50 +00005322 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005323 pixel;
5324
cristya19f1d72012-08-07 18:24:38 +00005325 double
cristy3ed852e2009-09-05 21:47:34 +00005326 weight;
5327
cristy1707c6c2012-01-18 23:30:54 +00005328 register ssize_t
5329 i;
5330
5331 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5332 {
cristy5a23c552013-02-13 14:34:28 +00005333 PixelChannel channel=GetPixelChannelChannel(image,i);
5334 PixelTrait traits=GetPixelChannelTraits(image,channel);
5335 PixelTrait tint_traits=GetPixelChannelTraits(tint_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00005336 if ((traits == UndefinedPixelTrait) ||
5337 (tint_traits == UndefinedPixelTrait))
5338 continue;
cristy1eced092012-08-10 23:10:56 +00005339 if (((tint_traits & CopyPixelTrait) != 0) ||
cristy883fde12013-04-08 00:50:13 +00005340 (GetPixelReadMask(image,p) == 0))
cristy1707c6c2012-01-18 23:30:54 +00005341 {
5342 SetPixelChannel(tint_image,channel,p[i],q);
5343 continue;
5344 }
5345 }
5346 GetPixelInfo(image,&pixel);
5347 weight=QuantumScale*GetPixelRed(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005348 pixel.red=(double) GetPixelRed(image,p)+color_vector.red*(1.0-(4.0*
5349 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005350 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005351 pixel.green=(double) GetPixelGreen(image,p)+color_vector.green*(1.0-(4.0*
5352 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005353 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005354 pixel.blue=(double) GetPixelBlue(image,p)+color_vector.blue*(1.0-(4.0*
5355 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005356 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005357 pixel.black=(double) GetPixelBlack(image,p)+color_vector.black*(1.0-(4.0*
5358 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005359 SetPixelInfoPixel(tint_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +00005360 p+=GetPixelChannels(image);
5361 q+=GetPixelChannels(tint_image);
cristy3ed852e2009-09-05 21:47:34 +00005362 }
5363 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5364 status=MagickFalse;
5365 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5366 {
5367 MagickBooleanType
5368 proceed;
5369
cristyb5d5f722009-11-04 03:03:49 +00005370#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005371 #pragma omp critical (MagickCore_TintImage)
cristy3ed852e2009-09-05 21:47:34 +00005372#endif
5373 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5374 if (proceed == MagickFalse)
5375 status=MagickFalse;
5376 }
5377 }
5378 tint_view=DestroyCacheView(tint_view);
5379 image_view=DestroyCacheView(image_view);
5380 if (status == MagickFalse)
5381 tint_image=DestroyImage(tint_image);
5382 return(tint_image);
5383}
5384
5385/*
5386%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5387% %
5388% %
5389% %
5390% V i g n e t t e I m a g e %
5391% %
5392% %
5393% %
5394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5395%
5396% VignetteImage() softens the edges of the image in vignette style.
5397%
5398% The format of the VignetteImage method is:
5399%
5400% Image *VignetteImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00005401% const double sigma,const ssize_t x,const ssize_t y,
cristy05c0c9a2011-09-05 23:16:13 +00005402% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005403%
5404% A description of each parameter follows:
5405%
5406% o image: the image.
5407%
5408% o radius: the radius of the pixel neighborhood.
5409%
5410% o sigma: the standard deviation of the Gaussian, in pixels.
5411%
5412% o x, y: Define the x and y ellipse offset.
5413%
5414% o exception: return any errors or warnings in this structure.
5415%
5416*/
5417MagickExport Image *VignetteImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00005418 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005419{
5420 char
5421 ellipse[MaxTextExtent];
5422
5423 DrawInfo
5424 *draw_info;
5425
5426 Image
5427 *canvas_image,
5428 *blur_image,
5429 *oval_image,
5430 *vignette_image;
5431
5432 assert(image != (Image *) NULL);
5433 assert(image->signature == MagickSignature);
5434 if (image->debug != MagickFalse)
5435 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5436 assert(exception != (ExceptionInfo *) NULL);
5437 assert(exception->signature == MagickSignature);
5438 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5439 if (canvas_image == (Image *) NULL)
5440 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005441 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005442 {
cristy3ed852e2009-09-05 21:47:34 +00005443 canvas_image=DestroyImage(canvas_image);
5444 return((Image *) NULL);
5445 }
cristy8a46d822012-08-28 23:32:39 +00005446 canvas_image->alpha_trait=BlendPixelTrait;
cristy98621462011-12-31 22:31:11 +00005447 oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
5448 MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005449 if (oval_image == (Image *) NULL)
5450 {
5451 canvas_image=DestroyImage(canvas_image);
5452 return((Image *) NULL);
5453 }
cristy9950d572011-10-01 18:22:35 +00005454 (void) QueryColorCompliance("#000000",AllCompliance,
5455 &oval_image->background_color,exception);
cristyea1a8aa2011-10-20 13:24:06 +00005456 (void) SetImageBackgroundColor(oval_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00005457 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00005458 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5459 exception);
5460 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5461 exception);
cristy1707c6c2012-01-18 23:30:54 +00005462 (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
5463 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
5464 image->rows/2.0-y);
cristy3ed852e2009-09-05 21:47:34 +00005465 draw_info->primitive=AcquireString(ellipse);
cristy018f07f2011-09-04 21:15:19 +00005466 (void) DrawImage(oval_image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00005467 draw_info=DestroyDrawInfo(draw_info);
cristyaa2c16c2012-03-25 22:21:35 +00005468 blur_image=BlurImage(oval_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00005469 oval_image=DestroyImage(oval_image);
5470 if (blur_image == (Image *) NULL)
5471 {
5472 canvas_image=DestroyImage(canvas_image);
5473 return((Image *) NULL);
5474 }
cristy8a46d822012-08-28 23:32:39 +00005475 blur_image->alpha_trait=UndefinedPixelTrait;
cristy39172402012-03-30 13:04:39 +00005476 (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue,
5477 0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00005478 blur_image=DestroyImage(blur_image);
5479 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5480 canvas_image=DestroyImage(canvas_image);
cristy66d26122012-06-23 21:56:40 +00005481 if (vignette_image != (Image *) NULL)
5482 (void) TransformImageColorspace(vignette_image,image->colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00005483 return(vignette_image);
5484}
5485
5486/*
5487%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5488% %
5489% %
5490% %
5491% W a v e I m a g e %
5492% %
5493% %
5494% %
5495%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5496%
5497% WaveImage() creates a "ripple" effect in the image by shifting the pixels
cristycee97112010-05-28 00:44:52 +00005498% vertically along a sine wave whose amplitude and wavelength is specified
cristy3ed852e2009-09-05 21:47:34 +00005499% by the given parameters.
5500%
5501% The format of the WaveImage method is:
5502%
5503% Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005504% const double wave_length,const PixelInterpolateMethod method,
5505% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005506%
5507% A description of each parameter follows:
5508%
5509% o image: the image.
5510%
5511% o amplitude, wave_length: Define the amplitude and wave length of the
5512% sine wave.
5513%
cristy5c4e2582011-09-11 19:21:03 +00005514% o interpolate: the pixel interpolation method.
5515%
cristy3ed852e2009-09-05 21:47:34 +00005516% o exception: return any errors or warnings in this structure.
5517%
5518*/
5519MagickExport Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005520 const double wave_length,const PixelInterpolateMethod method,
5521 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005522{
5523#define WaveImageTag "Wave/Image"
5524
cristyfa112112010-01-04 17:48:07 +00005525 CacheView
cristyd76c51e2011-03-26 00:21:26 +00005526 *image_view,
cristyfa112112010-01-04 17:48:07 +00005527 *wave_view;
5528
cristy3ed852e2009-09-05 21:47:34 +00005529 Image
5530 *wave_image;
5531
cristy3ed852e2009-09-05 21:47:34 +00005532 MagickBooleanType
5533 status;
5534
cristybb503372010-05-27 20:51:26 +00005535 MagickOffsetType
5536 progress;
5537
cristya19f1d72012-08-07 18:24:38 +00005538 double
cristy3ed852e2009-09-05 21:47:34 +00005539 *sine_map;
5540
cristybb503372010-05-27 20:51:26 +00005541 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005542 i;
5543
cristybb503372010-05-27 20:51:26 +00005544 ssize_t
5545 y;
5546
cristy3ed852e2009-09-05 21:47:34 +00005547 /*
5548 Initialize wave image attributes.
5549 */
5550 assert(image != (Image *) NULL);
5551 assert(image->signature == MagickSignature);
5552 if (image->debug != MagickFalse)
5553 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5554 assert(exception != (ExceptionInfo *) NULL);
5555 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00005556 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
cristy3ed852e2009-09-05 21:47:34 +00005557 fabs(amplitude)),MagickTrue,exception);
5558 if (wave_image == (Image *) NULL)
5559 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005560 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005561 {
cristy3ed852e2009-09-05 21:47:34 +00005562 wave_image=DestroyImage(wave_image);
5563 return((Image *) NULL);
5564 }
cristy4c08aed2011-07-01 19:47:50 +00005565 if (wave_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00005566 wave_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00005567 /*
5568 Allocate sine map.
5569 */
cristya19f1d72012-08-07 18:24:38 +00005570 sine_map=(double *) AcquireQuantumMemory((size_t) wave_image->columns,
cristy3ed852e2009-09-05 21:47:34 +00005571 sizeof(*sine_map));
cristya19f1d72012-08-07 18:24:38 +00005572 if (sine_map == (double *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005573 {
5574 wave_image=DestroyImage(wave_image);
5575 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5576 }
cristybb503372010-05-27 20:51:26 +00005577 for (i=0; i < (ssize_t) wave_image->columns; i++)
cristy4205a3c2010-09-12 20:19:59 +00005578 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5579 wave_length));
cristy3ed852e2009-09-05 21:47:34 +00005580 /*
5581 Wave image.
5582 */
5583 status=MagickTrue;
5584 progress=0;
cristy46ff2672012-12-14 15:32:26 +00005585 image_view=AcquireVirtualCacheView(image,exception);
5586 wave_view=AcquireAuthenticCacheView(wave_image,exception);
cristyd76c51e2011-03-26 00:21:26 +00005587 (void) SetCacheViewVirtualPixelMethod(image_view,
5588 BackgroundVirtualPixelMethod);
cristyb5d5f722009-11-04 03:03:49 +00005589#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005590 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00005591 magick_threads(image,wave_image,wave_image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005592#endif
cristybb503372010-05-27 20:51:26 +00005593 for (y=0; y < (ssize_t) wave_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005594 {
cristy4c08aed2011-07-01 19:47:50 +00005595 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005596 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005597
cristye97bb922011-04-03 01:36:52 +00005598 register ssize_t
5599 x;
5600
cristy3ed852e2009-09-05 21:47:34 +00005601 if (status == MagickFalse)
5602 continue;
5603 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5604 exception);
cristyacd2ed22011-08-30 01:44:23 +00005605 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005606 {
5607 status=MagickFalse;
5608 continue;
5609 }
cristybb503372010-05-27 20:51:26 +00005610 for (x=0; x < (ssize_t) wave_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005611 {
cristy5c4e2582011-09-11 19:21:03 +00005612 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5613 (double) x,(double) (y-sine_map[x]),q,exception);
cristyed231572011-07-14 02:18:59 +00005614 q+=GetPixelChannels(wave_image);
cristy3ed852e2009-09-05 21:47:34 +00005615 }
5616 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5617 status=MagickFalse;
5618 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5619 {
5620 MagickBooleanType
5621 proceed;
5622
cristyb5d5f722009-11-04 03:03:49 +00005623#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005624 #pragma omp critical (MagickCore_WaveImage)
cristy3ed852e2009-09-05 21:47:34 +00005625#endif
5626 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5627 if (proceed == MagickFalse)
5628 status=MagickFalse;
5629 }
5630 }
5631 wave_view=DestroyCacheView(wave_view);
cristyd76c51e2011-03-26 00:21:26 +00005632 image_view=DestroyCacheView(image_view);
cristya19f1d72012-08-07 18:24:38 +00005633 sine_map=(double *) RelinquishMagickMemory(sine_map);
cristy3ed852e2009-09-05 21:47:34 +00005634 if (status == MagickFalse)
5635 wave_image=DestroyImage(wave_image);
5636 return(wave_image);
5637}