blob: 653319e5604233c978304743ed77c4fce8360061 [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 }
cristy98ccd782012-07-09 11:22:59 +0000309 if (IsGrayColorspace(image->colorspace) != MagickFalse)
cristyb09db112012-07-11 12:04:31 +0000310 (void) TransformImageColorspace(noise_image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000311 /*
312 Add noise in each row.
313 */
cristy3ed852e2009-09-05 21:47:34 +0000314 status=MagickTrue;
315 progress=0;
316 random_info=AcquireRandomInfoThreadSet();
cristy46ff2672012-12-14 15:32:26 +0000317 image_view=AcquireVirtualCacheView(image,exception);
318 noise_view=AcquireAuthenticCacheView(noise_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000319#if defined(MAGICKCORE_OPENMP_SUPPORT)
glennrpf7659d72012-09-24 18:14:56 +0000320 key=GetRandomSecretKey(random_info[0]);
cristy57340e02012-05-05 00:53:23 +0000321 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000322 magick_threads(image,noise_image,image->rows,key == ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000323#endif
cristybb503372010-05-27 20:51:26 +0000324 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000325 {
cristy5c9e6f22010-09-17 17:31:01 +0000326 const int
327 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +0000328
cristy3ed852e2009-09-05 21:47:34 +0000329 MagickBooleanType
330 sync;
331
cristy4c08aed2011-07-01 19:47:50 +0000332 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000333 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000334
cristybb503372010-05-27 20:51:26 +0000335 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000336 x;
337
cristy4c08aed2011-07-01 19:47:50 +0000338 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000339 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000340
341 if (status == MagickFalse)
342 continue;
343 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +0000344 q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +0000345 exception);
cristy4c08aed2011-07-01 19:47:50 +0000346 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000347 {
348 status=MagickFalse;
349 continue;
350 }
cristybb503372010-05-27 20:51:26 +0000351 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000352 {
cristy850b3072011-10-08 01:38:05 +0000353 register ssize_t
354 i;
355
356 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
357 {
358 PixelChannel
359 channel;
360
361 PixelTrait
362 noise_traits,
363 traits;
364
cristycf1296e2012-08-26 23:40:49 +0000365 channel=GetPixelChannelChannel(image,i);
366 traits=GetPixelChannelTraits(image,channel);
367 noise_traits=GetPixelChannelTraits(noise_image,channel);
cristy850b3072011-10-08 01:38:05 +0000368 if ((traits == UndefinedPixelTrait) ||
369 (noise_traits == UndefinedPixelTrait))
370 continue;
cristy1eced092012-08-10 23:10:56 +0000371 if (((noise_traits & CopyPixelTrait) != 0) ||
372 (GetPixelMask(image,p) != 0))
cristyb2145892011-10-10 00:55:32 +0000373 {
374 SetPixelChannel(noise_image,channel,p[i],q);
375 continue;
376 }
cristy850b3072011-10-08 01:38:05 +0000377 SetPixelChannel(noise_image,channel,ClampToQuantum(
378 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
379 q);
380 }
cristyed231572011-07-14 02:18:59 +0000381 p+=GetPixelChannels(image);
382 q+=GetPixelChannels(noise_image);
cristy3ed852e2009-09-05 21:47:34 +0000383 }
384 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
385 if (sync == MagickFalse)
386 status=MagickFalse;
387 if (image->progress_monitor != (MagickProgressMonitor) NULL)
388 {
389 MagickBooleanType
390 proceed;
391
cristyb5d5f722009-11-04 03:03:49 +0000392#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy319a1e72010-02-21 15:13:11 +0000393 #pragma omp critical (MagickCore_AddNoiseImage)
cristy3ed852e2009-09-05 21:47:34 +0000394#endif
395 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
396 image->rows);
397 if (proceed == MagickFalse)
398 status=MagickFalse;
399 }
400 }
401 noise_view=DestroyCacheView(noise_view);
402 image_view=DestroyCacheView(image_view);
403 random_info=DestroyRandomInfoThreadSet(random_info);
404 if (status == MagickFalse)
405 noise_image=DestroyImage(noise_image);
406 return(noise_image);
407}
408
409/*
410%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411% %
412% %
413% %
414% B l u e S h i f t I m a g e %
415% %
416% %
417% %
418%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
419%
420% BlueShiftImage() mutes the colors of the image to simulate a scene at
421% nighttime in the moonlight.
422%
423% The format of the BlueShiftImage method is:
424%
425% Image *BlueShiftImage(const Image *image,const double factor,
426% ExceptionInfo *exception)
427%
428% A description of each parameter follows:
429%
430% o image: the image.
431%
432% o factor: the shift factor.
433%
434% o exception: return any errors or warnings in this structure.
435%
436*/
437MagickExport Image *BlueShiftImage(const Image *image,const double factor,
438 ExceptionInfo *exception)
439{
440#define BlueShiftImageTag "BlueShift/Image"
441
cristyc4c8d132010-01-07 01:58:38 +0000442 CacheView
443 *image_view,
444 *shift_view;
445
cristy3ed852e2009-09-05 21:47:34 +0000446 Image
447 *shift_image;
448
cristy3ed852e2009-09-05 21:47:34 +0000449 MagickBooleanType
450 status;
451
cristybb503372010-05-27 20:51:26 +0000452 MagickOffsetType
453 progress;
454
455 ssize_t
456 y;
457
cristy3ed852e2009-09-05 21:47:34 +0000458 /*
459 Allocate blue shift image.
460 */
461 assert(image != (const Image *) NULL);
462 assert(image->signature == MagickSignature);
463 if (image->debug != MagickFalse)
464 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
465 assert(exception != (ExceptionInfo *) NULL);
466 assert(exception->signature == MagickSignature);
cristya6d7a9b2012-01-18 20:04:48 +0000467 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000468 if (shift_image == (Image *) NULL)
469 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000470 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000471 {
cristy3ed852e2009-09-05 21:47:34 +0000472 shift_image=DestroyImage(shift_image);
473 return((Image *) NULL);
474 }
475 /*
476 Blue-shift DirectClass image.
477 */
478 status=MagickTrue;
479 progress=0;
cristy46ff2672012-12-14 15:32:26 +0000480 image_view=AcquireVirtualCacheView(image,exception);
481 shift_view=AcquireAuthenticCacheView(shift_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000482#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000483 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000484 magick_threads(image,shift_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000485#endif
cristybb503372010-05-27 20:51:26 +0000486 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000487 {
488 MagickBooleanType
489 sync;
490
cristy4c08aed2011-07-01 19:47:50 +0000491 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000492 pixel;
493
494 Quantum
495 quantum;
496
cristy4c08aed2011-07-01 19:47:50 +0000497 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000498 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000499
cristybb503372010-05-27 20:51:26 +0000500 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000501 x;
502
cristy4c08aed2011-07-01 19:47:50 +0000503 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000504 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000505
506 if (status == MagickFalse)
507 continue;
508 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
509 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
510 exception);
cristy4c08aed2011-07-01 19:47:50 +0000511 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000512 {
513 status=MagickFalse;
514 continue;
515 }
cristybb503372010-05-27 20:51:26 +0000516 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000517 {
cristy4c08aed2011-07-01 19:47:50 +0000518 quantum=GetPixelRed(image,p);
519 if (GetPixelGreen(image,p) < quantum)
520 quantum=GetPixelGreen(image,p);
521 if (GetPixelBlue(image,p) < quantum)
522 quantum=GetPixelBlue(image,p);
523 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
524 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
525 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
526 quantum=GetPixelRed(image,p);
527 if (GetPixelGreen(image,p) > quantum)
528 quantum=GetPixelGreen(image,p);
529 if (GetPixelBlue(image,p) > quantum)
530 quantum=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000531 pixel.red=0.5*(pixel.red+factor*quantum);
532 pixel.green=0.5*(pixel.green+factor*quantum);
533 pixel.blue=0.5*(pixel.blue+factor*quantum);
cristy4c08aed2011-07-01 19:47:50 +0000534 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
535 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
536 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
cristyed231572011-07-14 02:18:59 +0000537 p+=GetPixelChannels(image);
538 q+=GetPixelChannels(shift_image);
cristy3ed852e2009-09-05 21:47:34 +0000539 }
540 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
541 if (sync == MagickFalse)
542 status=MagickFalse;
543 if (image->progress_monitor != (MagickProgressMonitor) NULL)
544 {
545 MagickBooleanType
546 proceed;
547
cristy319a1e72010-02-21 15:13:11 +0000548#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +0000549 #pragma omp critical (MagickCore_BlueShiftImage)
cristy3ed852e2009-09-05 21:47:34 +0000550#endif
551 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
552 image->rows);
553 if (proceed == MagickFalse)
554 status=MagickFalse;
555 }
556 }
557 image_view=DestroyCacheView(image_view);
558 shift_view=DestroyCacheView(shift_view);
559 if (status == MagickFalse)
560 shift_image=DestroyImage(shift_image);
561 return(shift_image);
562}
563
564/*
565%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
566% %
567% %
568% %
569% C h a r c o a l I m a g e %
570% %
571% %
572% %
573%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
574%
575% CharcoalImage() creates a new image that is a copy of an existing one with
576% the edge highlighted. It allocates the memory necessary for the new Image
577% structure and returns a pointer to the new image.
578%
579% The format of the CharcoalImage method is:
580%
581% Image *CharcoalImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +0000582% const double sigma,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000583%
584% A description of each parameter follows:
585%
586% o image: the image.
587%
588% o radius: the radius of the pixel neighborhood.
589%
590% o sigma: the standard deviation of the Gaussian, in pixels.
591%
592% o exception: return any errors or warnings in this structure.
593%
594*/
595MagickExport Image *CharcoalImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +0000596 const double sigma,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000597{
598 Image
599 *charcoal_image,
600 *clone_image,
601 *edge_image;
602
603 assert(image != (Image *) NULL);
604 assert(image->signature == MagickSignature);
605 if (image->debug != MagickFalse)
606 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
607 assert(exception != (ExceptionInfo *) NULL);
608 assert(exception->signature == MagickSignature);
609 clone_image=CloneImage(image,0,0,MagickTrue,exception);
610 if (clone_image == (Image *) NULL)
611 return((Image *) NULL);
cristy018f07f2011-09-04 21:15:19 +0000612 (void) SetImageType(clone_image,GrayscaleType,exception);
cristy8ae632d2011-09-05 17:29:53 +0000613 edge_image=EdgeImage(clone_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000614 clone_image=DestroyImage(clone_image);
615 if (edge_image == (Image *) NULL)
616 return((Image *) NULL);
cristyaa2c16c2012-03-25 22:21:35 +0000617 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000618 edge_image=DestroyImage(edge_image);
619 if (charcoal_image == (Image *) NULL)
620 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +0000621 (void) NormalizeImage(charcoal_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +0000622 (void) NegateImage(charcoal_image,MagickFalse,exception);
cristy018f07f2011-09-04 21:15:19 +0000623 (void) SetImageType(charcoal_image,GrayscaleType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000624 return(charcoal_image);
625}
626
627/*
628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
629% %
630% %
631% %
632% C o l o r i z e I m a g e %
633% %
634% %
635% %
636%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
637%
638% ColorizeImage() blends the fill color with each pixel in the image.
639% A percentage blend is specified with opacity. Control the application
640% of different color components by specifying a different percentage for
641% each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
642%
643% The format of the ColorizeImage method is:
644%
cristyc7e6ff62011-10-03 13:46:11 +0000645% Image *ColorizeImage(const Image *image,const char *blend,
646% const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000647%
648% A description of each parameter follows:
649%
650% o image: the image.
651%
cristyc7e6ff62011-10-03 13:46:11 +0000652% o blend: A character string indicating the level of blending as a
cristy3ed852e2009-09-05 21:47:34 +0000653% percentage.
654%
655% o colorize: A color value.
656%
657% o exception: return any errors or warnings in this structure.
658%
659*/
cristyc7e6ff62011-10-03 13:46:11 +0000660MagickExport Image *ColorizeImage(const Image *image,const char *blend,
661 const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000662{
663#define ColorizeImageTag "Colorize/Image"
cristy0cf6da52012-08-25 00:35:24 +0000664#define Colorize(pixel,blend_percentage,colorize) \
665 (((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0)
cristy3ed852e2009-09-05 21:47:34 +0000666
cristyc4c8d132010-01-07 01:58:38 +0000667 CacheView
668 *colorize_view,
669 *image_view;
670
cristy3ed852e2009-09-05 21:47:34 +0000671 GeometryInfo
672 geometry_info;
673
674 Image
675 *colorize_image;
676
cristy3ed852e2009-09-05 21:47:34 +0000677 MagickBooleanType
678 status;
679
cristybb503372010-05-27 20:51:26 +0000680 MagickOffsetType
681 progress;
682
cristy3ed852e2009-09-05 21:47:34 +0000683 MagickStatusType
684 flags;
685
cristyc7e6ff62011-10-03 13:46:11 +0000686 PixelInfo
cristy20c3aed2012-04-10 01:06:21 +0000687 blend_percentage;
cristyc7e6ff62011-10-03 13:46:11 +0000688
cristybb503372010-05-27 20:51:26 +0000689 ssize_t
690 y;
691
cristy3ed852e2009-09-05 21:47:34 +0000692 /*
693 Allocate colorized image.
694 */
695 assert(image != (const Image *) NULL);
696 assert(image->signature == MagickSignature);
697 if (image->debug != MagickFalse)
698 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
699 assert(exception != (ExceptionInfo *) NULL);
700 assert(exception->signature == MagickSignature);
cristy768165d2012-04-09 15:01:35 +0000701 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
702 exception);
703 if (colorize_image == (Image *) NULL)
704 return((Image *) NULL);
705 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
706 {
707 colorize_image=DestroyImage(colorize_image);
708 return((Image *) NULL);
709 }
cristy9b7a4fc2012-04-08 22:26:56 +0000710 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
cristy20c3aed2012-04-10 01:06:21 +0000711 (IsPixelInfoGray(colorize) != MagickFalse))
cristyb09db112012-07-11 12:04:31 +0000712 (void) SetImageColorspace(colorize_image,RGBColorspace,exception);
cristy8a46d822012-08-28 23:32:39 +0000713 if ((colorize_image->alpha_trait != BlendPixelTrait) &&
714 (colorize->alpha_trait == BlendPixelTrait))
cristy768165d2012-04-09 15:01:35 +0000715 (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
716 if (blend == (const char *) NULL)
717 return(colorize_image);
cristy20c3aed2012-04-10 01:06:21 +0000718 GetPixelInfo(image,&blend_percentage);
719 flags=ParseGeometry(blend,&geometry_info);
720 blend_percentage.red=geometry_info.rho;
721 blend_percentage.green=geometry_info.rho;
722 blend_percentage.blue=geometry_info.rho;
723 blend_percentage.black=geometry_info.rho;
cristy3ee7de52012-04-14 23:40:47 +0000724 blend_percentage.alpha=geometry_info.rho;
cristy20c3aed2012-04-10 01:06:21 +0000725 if ((flags & SigmaValue) != 0)
726 blend_percentage.green=geometry_info.sigma;
727 if ((flags & XiValue) != 0)
728 blend_percentage.blue=geometry_info.xi;
729 if ((flags & PsiValue) != 0)
730 blend_percentage.alpha=geometry_info.psi;
731 if (blend_percentage.colorspace == CMYKColorspace)
732 {
733 if ((flags & PsiValue) != 0)
734 blend_percentage.black=geometry_info.psi;
735 if ((flags & ChiValue) != 0)
736 blend_percentage.alpha=geometry_info.chi;
737 }
cristy3ed852e2009-09-05 21:47:34 +0000738 /*
739 Colorize DirectClass image.
740 */
741 status=MagickTrue;
742 progress=0;
cristy46ff2672012-12-14 15:32:26 +0000743 image_view=AcquireVirtualCacheView(image,exception);
744 colorize_view=AcquireAuthenticCacheView(colorize_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000745#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000746 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000747 magick_threads(image,colorize_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000748#endif
cristybb503372010-05-27 20:51:26 +0000749 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000750 {
751 MagickBooleanType
752 sync;
753
cristy4c08aed2011-07-01 19:47:50 +0000754 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000755 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000756
cristy4c08aed2011-07-01 19:47:50 +0000757 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000758 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000759
cristy4a37c622012-08-23 18:47:56 +0000760 register ssize_t
761 x;
762
cristy3ed852e2009-09-05 21:47:34 +0000763 if (status == MagickFalse)
764 continue;
765 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
766 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
767 exception);
cristy4c08aed2011-07-01 19:47:50 +0000768 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000769 {
770 status=MagickFalse;
771 continue;
772 }
cristybb503372010-05-27 20:51:26 +0000773 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000774 {
cristy0cf6da52012-08-25 00:35:24 +0000775 register ssize_t
776 i;
777
778 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
779 {
780 PixelChannel
781 channel;
782
783 PixelTrait
784 colorize_traits,
785 traits;
786
cristycf1296e2012-08-26 23:40:49 +0000787 channel=GetPixelChannelChannel(image,i);
788 traits=GetPixelChannelTraits(image,channel);
789 colorize_traits=GetPixelChannelTraits(colorize_image,channel);
cristy0cf6da52012-08-25 00:35:24 +0000790 if ((traits == UndefinedPixelTrait) ||
791 (colorize_traits == UndefinedPixelTrait))
cristyd6803382012-04-10 01:41:25 +0000792 continue;
cristy0cf6da52012-08-25 00:35:24 +0000793 if (((colorize_traits & CopyPixelTrait) != 0) ||
794 (GetPixelMask(image,p) != 0))
795 {
796 SetPixelChannel(colorize_image,channel,p[i],q);
797 continue;
798 }
cristycf1296e2012-08-26 23:40:49 +0000799 SetPixelChannel(colorize_image,channel,
800 ClampToQuantum(Colorize(p[i],GetPixelInfoChannel(&blend_percentage,
801 channel),GetPixelInfoChannel(colorize,channel))),q);
cristy0cf6da52012-08-25 00:35:24 +0000802 }
cristyed231572011-07-14 02:18:59 +0000803 p+=GetPixelChannels(image);
804 q+=GetPixelChannels(colorize_image);
cristy3ed852e2009-09-05 21:47:34 +0000805 }
806 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
807 if (sync == MagickFalse)
808 status=MagickFalse;
809 if (image->progress_monitor != (MagickProgressMonitor) NULL)
810 {
811 MagickBooleanType
812 proceed;
813
cristy319a1e72010-02-21 15:13:11 +0000814#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +0000815 #pragma omp critical (MagickCore_ColorizeImage)
cristy3ed852e2009-09-05 21:47:34 +0000816#endif
817 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
818 if (proceed == MagickFalse)
819 status=MagickFalse;
820 }
821 }
822 image_view=DestroyCacheView(image_view);
823 colorize_view=DestroyCacheView(colorize_view);
824 if (status == MagickFalse)
825 colorize_image=DestroyImage(colorize_image);
826 return(colorize_image);
827}
828
829/*
830%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
831% %
832% %
833% %
cristye6365592010-04-02 17:31:23 +0000834% C o l o r M a t r i x I m a g e %
835% %
836% %
837% %
838%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
839%
840% ColorMatrixImage() applies color transformation to an image. This method
841% permits saturation changes, hue rotation, luminance to alpha, and various
842% other effects. Although variable-sized transformation matrices can be used,
843% typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
844% (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
845% except offsets are in column 6 rather than 5 (in support of CMYKA images)
846% and offsets are normalized (divide Flash offset by 255).
847%
848% The format of the ColorMatrixImage method is:
849%
850% Image *ColorMatrixImage(const Image *image,
851% const KernelInfo *color_matrix,ExceptionInfo *exception)
852%
853% A description of each parameter follows:
854%
855% o image: the image.
856%
857% o color_matrix: the color matrix.
858%
859% o exception: return any errors or warnings in this structure.
860%
861*/
anthonyfd706f92012-01-19 04:22:02 +0000862/* FUTURE: modify to make use of a MagickMatrix Mutliply function
863 That should be provided in "matrix.c"
864 (ASIDE: actually distorts should do this too but currently doesn't)
865*/
866
cristye6365592010-04-02 17:31:23 +0000867MagickExport Image *ColorMatrixImage(const Image *image,
868 const KernelInfo *color_matrix,ExceptionInfo *exception)
869{
870#define ColorMatrixImageTag "ColorMatrix/Image"
871
872 CacheView
873 *color_view,
874 *image_view;
875
876 double
877 ColorMatrix[6][6] =
878 {
879 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
880 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
881 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
882 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
883 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
884 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
885 };
886
887 Image
888 *color_image;
889
cristye6365592010-04-02 17:31:23 +0000890 MagickBooleanType
891 status;
892
cristybb503372010-05-27 20:51:26 +0000893 MagickOffsetType
894 progress;
895
896 register ssize_t
cristye6365592010-04-02 17:31:23 +0000897 i;
898
cristybb503372010-05-27 20:51:26 +0000899 ssize_t
900 u,
901 v,
902 y;
903
cristye6365592010-04-02 17:31:23 +0000904 /*
anthonyfd706f92012-01-19 04:22:02 +0000905 Map given color_matrix, into a 6x6 matrix RGBKA and a constant
cristye6365592010-04-02 17:31:23 +0000906 */
907 assert(image != (Image *) NULL);
908 assert(image->signature == MagickSignature);
909 if (image->debug != MagickFalse)
910 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
911 assert(exception != (ExceptionInfo *) NULL);
912 assert(exception->signature == MagickSignature);
913 i=0;
cristybb503372010-05-27 20:51:26 +0000914 for (v=0; v < (ssize_t) color_matrix->height; v++)
915 for (u=0; u < (ssize_t) color_matrix->width; u++)
cristye6365592010-04-02 17:31:23 +0000916 {
917 if ((v < 6) && (u < 6))
918 ColorMatrix[v][u]=color_matrix->values[i];
919 i++;
920 }
921 /*
922 Initialize color image.
923 */
cristy12550e62010-06-07 12:46:40 +0000924 color_image=CloneImage(image,0,0,MagickTrue,exception);
cristye6365592010-04-02 17:31:23 +0000925 if (color_image == (Image *) NULL)
926 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000927 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
cristye6365592010-04-02 17:31:23 +0000928 {
cristye6365592010-04-02 17:31:23 +0000929 color_image=DestroyImage(color_image);
930 return((Image *) NULL);
931 }
932 if (image->debug != MagickFalse)
933 {
934 char
935 format[MaxTextExtent],
936 *message;
937
938 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
939 " ColorMatrix image with color matrix:");
940 message=AcquireString("");
941 for (v=0; v < 6; v++)
942 {
943 *message='\0';
cristyb51dff52011-05-19 16:55:47 +0000944 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
cristye6365592010-04-02 17:31:23 +0000945 (void) ConcatenateString(&message,format);
946 for (u=0; u < 6; u++)
947 {
cristyb51dff52011-05-19 16:55:47 +0000948 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
cristye6365592010-04-02 17:31:23 +0000949 ColorMatrix[v][u]);
950 (void) ConcatenateString(&message,format);
951 }
952 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
953 }
954 message=DestroyString(message);
955 }
956 /*
anthonyfd706f92012-01-19 04:22:02 +0000957 Apply the ColorMatrix to image.
cristye6365592010-04-02 17:31:23 +0000958 */
959 status=MagickTrue;
960 progress=0;
cristy46ff2672012-12-14 15:32:26 +0000961 image_view=AcquireVirtualCacheView(image,exception);
962 color_view=AcquireAuthenticCacheView(color_image,exception);
cristye6365592010-04-02 17:31:23 +0000963#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000964 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +0000965 magick_threads(image,color_image,image->rows,1)
cristye6365592010-04-02 17:31:23 +0000966#endif
cristybb503372010-05-27 20:51:26 +0000967 for (y=0; y < (ssize_t) image->rows; y++)
cristye6365592010-04-02 17:31:23 +0000968 {
cristyfcc25d92012-02-19 23:06:48 +0000969 PixelInfo
cristye6365592010-04-02 17:31:23 +0000970 pixel;
971
cristy4c08aed2011-07-01 19:47:50 +0000972 register const Quantum
cristye6365592010-04-02 17:31:23 +0000973 *restrict p;
974
cristy4c08aed2011-07-01 19:47:50 +0000975 register Quantum
976 *restrict q;
977
cristybb503372010-05-27 20:51:26 +0000978 register ssize_t
cristye6365592010-04-02 17:31:23 +0000979 x;
980
cristye6365592010-04-02 17:31:23 +0000981 if (status == MagickFalse)
982 continue;
983 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
984 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
985 exception);
cristy4c08aed2011-07-01 19:47:50 +0000986 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristye6365592010-04-02 17:31:23 +0000987 {
988 status=MagickFalse;
989 continue;
990 }
cristyfcc25d92012-02-19 23:06:48 +0000991 GetPixelInfo(image,&pixel);
cristybb503372010-05-27 20:51:26 +0000992 for (x=0; x < (ssize_t) image->columns; x++)
cristye6365592010-04-02 17:31:23 +0000993 {
cristybb503372010-05-27 20:51:26 +0000994 register ssize_t
cristye6365592010-04-02 17:31:23 +0000995 v;
996
cristybb503372010-05-27 20:51:26 +0000997 size_t
cristye6365592010-04-02 17:31:23 +0000998 height;
999
cristyfcc25d92012-02-19 23:06:48 +00001000 GetPixelInfoPixel(image,p,&pixel);
cristye6365592010-04-02 17:31:23 +00001001 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
cristybb503372010-05-27 20:51:26 +00001002 for (v=0; v < (ssize_t) height; v++)
cristye6365592010-04-02 17:31:23 +00001003 {
cristya19f1d72012-08-07 18:24:38 +00001004 double
cristyfcc25d92012-02-19 23:06:48 +00001005 sum;
1006
1007 sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
cristy4c08aed2011-07-01 19:47:50 +00001008 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
cristye6365592010-04-02 17:31:23 +00001009 if (image->colorspace == CMYKColorspace)
cristyfcc25d92012-02-19 23:06:48 +00001010 sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
cristy8a46d822012-08-28 23:32:39 +00001011 if (image->alpha_trait == BlendPixelTrait)
cristyfcc25d92012-02-19 23:06:48 +00001012 sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
1013 sum+=QuantumRange*ColorMatrix[v][5];
cristye6365592010-04-02 17:31:23 +00001014 switch (v)
1015 {
cristyfcc25d92012-02-19 23:06:48 +00001016 case 0: pixel.red=sum; break;
1017 case 1: pixel.green=sum; break;
1018 case 2: pixel.blue=sum; break;
1019 case 3: pixel.black=sum; break;
1020 case 4: pixel.alpha=sum; break;
1021 default: break;
cristye6365592010-04-02 17:31:23 +00001022 }
1023 }
cristyfcc25d92012-02-19 23:06:48 +00001024 SetPixelInfoPixel(color_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +00001025 p+=GetPixelChannels(image);
1026 q+=GetPixelChannels(color_image);
cristye6365592010-04-02 17:31:23 +00001027 }
1028 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1029 status=MagickFalse;
1030 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1031 {
1032 MagickBooleanType
1033 proceed;
1034
1035#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00001036 #pragma omp critical (MagickCore_ColorMatrixImage)
cristye6365592010-04-02 17:31:23 +00001037#endif
1038 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1039 image->rows);
1040 if (proceed == MagickFalse)
1041 status=MagickFalse;
1042 }
1043 }
1044 color_view=DestroyCacheView(color_view);
1045 image_view=DestroyCacheView(image_view);
1046 if (status == MagickFalse)
1047 color_image=DestroyImage(color_image);
1048 return(color_image);
1049}
1050
1051/*
1052%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1053% %
1054% %
1055% %
cristy3ed852e2009-09-05 21:47:34 +00001056+ D e s t r o y F x I n f o %
1057% %
1058% %
1059% %
1060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061%
1062% DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1063%
1064% The format of the DestroyFxInfo method is:
1065%
1066% ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1067%
1068% A description of each parameter follows:
1069%
1070% o fx_info: the fx info.
1071%
1072*/
cristy7832dc22011-09-05 01:21:53 +00001073MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
cristy3ed852e2009-09-05 21:47:34 +00001074{
cristybb503372010-05-27 20:51:26 +00001075 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001076 i;
1077
1078 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1079 fx_info->expression=DestroyString(fx_info->expression);
1080 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1081 fx_info->colors=DestroySplayTree(fx_info->colors);
cristy0ea377f2011-03-24 00:54:19 +00001082 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
cristyd76c51e2011-03-26 00:21:26 +00001083 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1084 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001085 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1086 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1087 return(fx_info);
1088}
1089
1090/*
1091%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1092% %
1093% %
1094% %
cristy3ed852e2009-09-05 21:47:34 +00001095+ 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 %
1096% %
1097% %
1098% %
1099%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1100%
1101% FxEvaluateChannelExpression() evaluates an expression and returns the
1102% results.
1103%
1104% The format of the FxEvaluateExpression method is:
1105%
cristya19f1d72012-08-07 18:24:38 +00001106% double FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00001107% const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00001108% double *alpha,Exceptioninfo *exception)
1109% double FxEvaluateExpression(FxInfo *fx_info,
1110% double *alpha,Exceptioninfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001111%
1112% A description of each parameter follows:
1113%
1114% o fx_info: the fx info.
1115%
1116% o channel: the channel.
1117%
1118% o x,y: the pixel position.
1119%
1120% o alpha: the result.
1121%
1122% o exception: return any errors or warnings in this structure.
1123%
1124*/
1125
cristy351842f2010-03-07 15:27:38 +00001126static inline double MagickMax(const double x,const double y)
1127{
1128 if (x > y)
1129 return(x);
1130 return(y);
1131}
1132
1133static inline double MagickMin(const double x,const double y)
1134{
1135 if (x < y)
1136 return(x);
1137 return(y);
1138}
1139
cristya19f1d72012-08-07 18:24:38 +00001140static double FxChannelStatistics(FxInfo *fx_info,Image *image,
cristy0568ffc2011-07-25 16:54:14 +00001141 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001142{
cristy5048d302012-08-07 01:05:16 +00001143 ChannelType
1144 channel_mask;
1145
cristy3ed852e2009-09-05 21:47:34 +00001146 char
1147 key[MaxTextExtent],
1148 statistic[MaxTextExtent];
1149
1150 const char
1151 *value;
1152
1153 register const char
1154 *p;
1155
cristy5048d302012-08-07 01:05:16 +00001156 channel_mask=UndefinedChannel;
cristy3ed852e2009-09-05 21:47:34 +00001157 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1158 if (*p == '.')
cristy3ed852e2009-09-05 21:47:34 +00001159 {
cristy5048d302012-08-07 01:05:16 +00001160 ssize_t
1161 option;
1162
1163 option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1);
1164 if (option >= 0)
1165 {
1166 channel=(PixelChannel) option;
1167 channel_mask=(ChannelType) (channel_mask | (1 << channel));
cristycf1296e2012-08-26 23:40:49 +00001168 SetPixelChannelMask(image,channel_mask);
cristy5048d302012-08-07 01:05:16 +00001169 }
cristy3ed852e2009-09-05 21:47:34 +00001170 }
cristyb51dff52011-05-19 16:55:47 +00001171 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
cristye8c25f92010-06-03 00:53:06 +00001172 (double) channel,symbol);
cristy3ed852e2009-09-05 21:47:34 +00001173 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1174 if (value != (const char *) NULL)
cristy5048d302012-08-07 01:05:16 +00001175 {
1176 if (channel_mask != UndefinedChannel)
cristycf1296e2012-08-26 23:40:49 +00001177 SetPixelChannelMask(image,channel_mask);
cristy5048d302012-08-07 01:05:16 +00001178 return(QuantumScale*StringToDouble(value,(char **) NULL));
1179 }
cristy3ed852e2009-09-05 21:47:34 +00001180 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1181 if (LocaleNCompare(symbol,"depth",5) == 0)
1182 {
cristybb503372010-05-27 20:51:26 +00001183 size_t
cristy3ed852e2009-09-05 21:47:34 +00001184 depth;
1185
cristyfefab1b2011-07-05 00:33:22 +00001186 depth=GetImageDepth(image,exception);
1187 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
cristy3ed852e2009-09-05 21:47:34 +00001188 }
1189 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1190 {
1191 double
1192 kurtosis,
1193 skewness;
1194
cristyd42d9952011-07-08 14:21:50 +00001195 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001196 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
cristy3ed852e2009-09-05 21:47:34 +00001197 }
1198 if (LocaleNCompare(symbol,"maxima",6) == 0)
1199 {
1200 double
1201 maxima,
1202 minima;
1203
cristyd42d9952011-07-08 14:21:50 +00001204 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001205 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
cristy3ed852e2009-09-05 21:47:34 +00001206 }
1207 if (LocaleNCompare(symbol,"mean",4) == 0)
1208 {
1209 double
1210 mean,
1211 standard_deviation;
1212
cristyd42d9952011-07-08 14:21:50 +00001213 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001214 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
cristy3ed852e2009-09-05 21:47:34 +00001215 }
1216 if (LocaleNCompare(symbol,"minima",6) == 0)
1217 {
1218 double
1219 maxima,
1220 minima;
1221
cristyd42d9952011-07-08 14:21:50 +00001222 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001223 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
cristy3ed852e2009-09-05 21:47:34 +00001224 }
1225 if (LocaleNCompare(symbol,"skewness",8) == 0)
1226 {
1227 double
1228 kurtosis,
1229 skewness;
1230
cristyd42d9952011-07-08 14:21:50 +00001231 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001232 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
cristy3ed852e2009-09-05 21:47:34 +00001233 }
1234 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1235 {
1236 double
1237 mean,
1238 standard_deviation;
1239
cristyd42d9952011-07-08 14:21:50 +00001240 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001241 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
cristy3ed852e2009-09-05 21:47:34 +00001242 standard_deviation);
1243 }
cristy5048d302012-08-07 01:05:16 +00001244 if (channel_mask != UndefinedChannel)
cristycf1296e2012-08-26 23:40:49 +00001245 SetPixelChannelMask(image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00001246 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1247 ConstantString(statistic));
cristydbdd0e32011-11-04 23:29:40 +00001248 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001249}
1250
cristya19f1d72012-08-07 18:24:38 +00001251static double
cristy0568ffc2011-07-25 16:54:14 +00001252 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
cristya19f1d72012-08-07 18:24:38 +00001253 const ssize_t,const char *,double *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +00001254
cristyb0aad4c2011-11-02 19:30:35 +00001255static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1256{
1257 if (beta != 0)
1258 return(FxGCD(beta,alpha % beta));
1259 return(alpha);
1260}
1261
cristy3ed852e2009-09-05 21:47:34 +00001262static inline const char *FxSubexpression(const char *expression,
1263 ExceptionInfo *exception)
1264{
1265 const char
1266 *subexpression;
1267
cristybb503372010-05-27 20:51:26 +00001268 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001269 level;
1270
1271 level=0;
1272 subexpression=expression;
1273 while ((*subexpression != '\0') &&
1274 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1275 {
1276 if (strchr("(",(int) *subexpression) != (char *) NULL)
1277 level++;
1278 else
1279 if (strchr(")",(int) *subexpression) != (char *) NULL)
1280 level--;
1281 subexpression++;
1282 }
1283 if (*subexpression == '\0')
1284 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001285 "UnbalancedParenthesis","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00001286 return(subexpression);
1287}
1288
cristya19f1d72012-08-07 18:24:38 +00001289static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001290 const ssize_t x,const ssize_t y,const char *expression,
1291 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001292{
1293 char
1294 *q,
1295 subexpression[MaxTextExtent],
1296 symbol[MaxTextExtent];
1297
1298 const char
1299 *p,
1300 *value;
1301
1302 Image
1303 *image;
1304
cristy4c08aed2011-07-01 19:47:50 +00001305 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001306 pixel;
1307
cristya19f1d72012-08-07 18:24:38 +00001308 double
cristy3ed852e2009-09-05 21:47:34 +00001309 alpha,
1310 beta;
1311
1312 PointInfo
1313 point;
1314
cristybb503372010-05-27 20:51:26 +00001315 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001316 i;
1317
1318 size_t
cristy1707c6c2012-01-18 23:30:54 +00001319 length,
cristy3ed852e2009-09-05 21:47:34 +00001320 level;
1321
1322 p=expression;
1323 i=GetImageIndexInList(fx_info->images);
1324 level=0;
1325 point.x=(double) x;
1326 point.y=(double) y;
1327 if (isalpha((int) *(p+1)) == 0)
1328 {
1329 if (strchr("suv",(int) *p) != (char *) NULL)
1330 {
1331 switch (*p)
1332 {
1333 case 's':
1334 default:
1335 {
1336 i=GetImageIndexInList(fx_info->images);
1337 break;
1338 }
1339 case 'u': i=0; break;
1340 case 'v': i=1; break;
1341 }
1342 p++;
1343 if (*p == '[')
1344 {
1345 level++;
1346 q=subexpression;
1347 for (p++; *p != '\0'; )
1348 {
1349 if (*p == '[')
1350 level++;
1351 else
1352 if (*p == ']')
1353 {
1354 level--;
1355 if (level == 0)
1356 break;
1357 }
1358 *q++=(*p++);
1359 }
1360 *q='\0';
1361 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1362 &beta,exception);
cristybb503372010-05-27 20:51:26 +00001363 i=(ssize_t) (alpha+0.5);
cristy3ed852e2009-09-05 21:47:34 +00001364 p++;
1365 }
1366 if (*p == '.')
1367 p++;
1368 }
1369 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1370 {
1371 p++;
1372 if (*p == '{')
1373 {
1374 level++;
1375 q=subexpression;
1376 for (p++; *p != '\0'; )
1377 {
1378 if (*p == '{')
1379 level++;
1380 else
1381 if (*p == '}')
1382 {
1383 level--;
1384 if (level == 0)
1385 break;
1386 }
1387 *q++=(*p++);
1388 }
1389 *q='\0';
1390 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1391 &beta,exception);
1392 point.x=alpha;
1393 point.y=beta;
1394 p++;
1395 }
1396 else
1397 if (*p == '[')
1398 {
1399 level++;
1400 q=subexpression;
1401 for (p++; *p != '\0'; )
1402 {
1403 if (*p == '[')
1404 level++;
1405 else
1406 if (*p == ']')
1407 {
1408 level--;
1409 if (level == 0)
1410 break;
1411 }
1412 *q++=(*p++);
1413 }
1414 *q='\0';
1415 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1416 &beta,exception);
1417 point.x+=alpha;
1418 point.y+=beta;
1419 p++;
1420 }
1421 if (*p == '.')
1422 p++;
1423 }
1424 }
1425 length=GetImageListLength(fx_info->images);
1426 while (i < 0)
cristybb503372010-05-27 20:51:26 +00001427 i+=(ssize_t) length;
cristy3ed852e2009-09-05 21:47:34 +00001428 i%=length;
1429 image=GetImageFromList(fx_info->images,i);
1430 if (image == (Image *) NULL)
1431 {
1432 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001433 "NoSuchImage","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00001434 return(0.0);
1435 }
cristy4c08aed2011-07-01 19:47:50 +00001436 GetPixelInfo(image,&pixel);
1437 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
cristy4f820712011-04-01 12:35:43 +00001438 point.x,point.y,&pixel,exception);
cristy1707c6c2012-01-18 23:30:54 +00001439 if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
1440 (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
cristy3ed852e2009-09-05 21:47:34 +00001441 (LocaleCompare(p,"saturation") != 0) &&
1442 (LocaleCompare(p,"lightness") != 0))
1443 {
1444 char
1445 name[MaxTextExtent];
1446
1447 (void) CopyMagickString(name,p,MaxTextExtent);
1448 for (q=name+(strlen(name)-1); q > name; q--)
1449 {
1450 if (*q == ')')
1451 break;
1452 if (*q == '.')
1453 {
1454 *q='\0';
1455 break;
1456 }
1457 }
1458 if ((strlen(name) > 2) &&
1459 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1460 {
cristy4c08aed2011-07-01 19:47:50 +00001461 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001462 *color;
1463
cristy4c08aed2011-07-01 19:47:50 +00001464 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1465 if (color != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001466 {
1467 pixel=(*color);
1468 p+=strlen(name);
1469 }
1470 else
cristy1707c6c2012-01-18 23:30:54 +00001471 {
1472 MagickBooleanType
1473 status;
1474
1475 status=QueryColorCompliance(name,AllCompliance,&pixel,
1476 fx_info->exception);
1477 if (status != MagickFalse)
1478 {
1479 (void) AddValueToSplayTree(fx_info->colors,ConstantString(
1480 name),ClonePixelInfo(&pixel));
1481 p+=strlen(name);
1482 }
1483 }
cristy3ed852e2009-09-05 21:47:34 +00001484 }
1485 }
1486 (void) CopyMagickString(symbol,p,MaxTextExtent);
1487 StripString(symbol);
1488 if (*symbol == '\0')
1489 {
1490 switch (channel)
1491 {
cristy0568ffc2011-07-25 16:54:14 +00001492 case RedPixelChannel: return(QuantumScale*pixel.red);
1493 case GreenPixelChannel: return(QuantumScale*pixel.green);
1494 case BluePixelChannel: return(QuantumScale*pixel.blue);
1495 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001496 {
1497 if (image->colorspace != CMYKColorspace)
1498 {
1499 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00001500 ImageError,"ColorSeparatedImageRequired","`%s'",
cristy3ed852e2009-09-05 21:47:34 +00001501 image->filename);
1502 return(0.0);
1503 }
cristy4c08aed2011-07-01 19:47:50 +00001504 return(QuantumScale*pixel.black);
1505 }
cristy0568ffc2011-07-25 16:54:14 +00001506 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001507 {
cristya19f1d72012-08-07 18:24:38 +00001508 double
cristy4c08aed2011-07-01 19:47:50 +00001509 alpha;
1510
cristy8a46d822012-08-28 23:32:39 +00001511 if (pixel.alpha_trait != BlendPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +00001512 return(1.0);
cristya19f1d72012-08-07 18:24:38 +00001513 alpha=(double) (QuantumScale*pixel.alpha);
cristy4c08aed2011-07-01 19:47:50 +00001514 return(alpha);
cristy3ed852e2009-09-05 21:47:34 +00001515 }
cristya382aca2011-12-06 18:22:48 +00001516 case IndexPixelChannel:
1517 return(0.0);
cristyb3a73b52011-07-26 01:34:43 +00001518 case IntensityPixelChannel:
cristyf364ed42010-12-15 01:54:43 +00001519 {
cristy4c08aed2011-07-01 19:47:50 +00001520 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristyf364ed42010-12-15 01:54:43 +00001521 }
cristy3ed852e2009-09-05 21:47:34 +00001522 default:
1523 break;
1524 }
1525 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001526 "UnableToParseExpression","`%s'",p);
cristy3ed852e2009-09-05 21:47:34 +00001527 return(0.0);
1528 }
1529 switch (*symbol)
1530 {
1531 case 'A':
1532 case 'a':
1533 {
1534 if (LocaleCompare(symbol,"a") == 0)
cristya19f1d72012-08-07 18:24:38 +00001535 return((double) (QuantumScale*pixel.alpha));
cristy3ed852e2009-09-05 21:47:34 +00001536 break;
1537 }
1538 case 'B':
1539 case 'b':
1540 {
1541 if (LocaleCompare(symbol,"b") == 0)
1542 return(QuantumScale*pixel.blue);
1543 break;
1544 }
1545 case 'C':
1546 case 'c':
1547 {
1548 if (LocaleNCompare(symbol,"channel",7) == 0)
1549 {
1550 GeometryInfo
1551 channel_info;
1552
1553 MagickStatusType
1554 flags;
1555
1556 flags=ParseGeometry(symbol+7,&channel_info);
1557 if (image->colorspace == CMYKColorspace)
1558 switch (channel)
1559 {
cristy0568ffc2011-07-25 16:54:14 +00001560 case CyanPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001561 {
1562 if ((flags & RhoValue) == 0)
1563 return(0.0);
1564 return(channel_info.rho);
1565 }
cristy0568ffc2011-07-25 16:54:14 +00001566 case MagentaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001567 {
1568 if ((flags & SigmaValue) == 0)
1569 return(0.0);
1570 return(channel_info.sigma);
1571 }
cristy0568ffc2011-07-25 16:54:14 +00001572 case YellowPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001573 {
1574 if ((flags & XiValue) == 0)
1575 return(0.0);
1576 return(channel_info.xi);
1577 }
cristy0568ffc2011-07-25 16:54:14 +00001578 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001579 {
1580 if ((flags & PsiValue) == 0)
1581 return(0.0);
1582 return(channel_info.psi);
1583 }
cristy0568ffc2011-07-25 16:54:14 +00001584 case AlphaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001585 {
1586 if ((flags & ChiValue) == 0)
1587 return(0.0);
1588 return(channel_info.chi);
1589 }
1590 default:
1591 return(0.0);
1592 }
1593 switch (channel)
1594 {
cristy0568ffc2011-07-25 16:54:14 +00001595 case RedPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001596 {
1597 if ((flags & RhoValue) == 0)
1598 return(0.0);
1599 return(channel_info.rho);
1600 }
cristy0568ffc2011-07-25 16:54:14 +00001601 case GreenPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001602 {
1603 if ((flags & SigmaValue) == 0)
1604 return(0.0);
1605 return(channel_info.sigma);
1606 }
cristy0568ffc2011-07-25 16:54:14 +00001607 case BluePixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001608 {
1609 if ((flags & XiValue) == 0)
1610 return(0.0);
1611 return(channel_info.xi);
1612 }
cristy0568ffc2011-07-25 16:54:14 +00001613 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001614 {
1615 if ((flags & ChiValue) == 0)
1616 return(0.0);
1617 return(channel_info.chi);
1618 }
cristy0568ffc2011-07-25 16:54:14 +00001619 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001620 {
1621 if ((flags & PsiValue) == 0)
1622 return(0.0);
1623 return(channel_info.psi);
1624 }
cristy3ed852e2009-09-05 21:47:34 +00001625 default:
1626 return(0.0);
1627 }
1628 return(0.0);
1629 }
1630 if (LocaleCompare(symbol,"c") == 0)
1631 return(QuantumScale*pixel.red);
1632 break;
1633 }
1634 case 'D':
1635 case 'd':
1636 {
1637 if (LocaleNCompare(symbol,"depth",5) == 0)
1638 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1639 break;
1640 }
1641 case 'G':
1642 case 'g':
1643 {
1644 if (LocaleCompare(symbol,"g") == 0)
1645 return(QuantumScale*pixel.green);
1646 break;
1647 }
1648 case 'K':
1649 case 'k':
1650 {
1651 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1652 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1653 if (LocaleCompare(symbol,"k") == 0)
1654 {
1655 if (image->colorspace != CMYKColorspace)
1656 {
1657 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00001658 OptionError,"ColorSeparatedImageRequired","`%s'",
cristy3ed852e2009-09-05 21:47:34 +00001659 image->filename);
1660 return(0.0);
1661 }
cristy4c08aed2011-07-01 19:47:50 +00001662 return(QuantumScale*pixel.black);
cristy3ed852e2009-09-05 21:47:34 +00001663 }
1664 break;
1665 }
1666 case 'H':
1667 case 'h':
1668 {
1669 if (LocaleCompare(symbol,"h") == 0)
cristya19f1d72012-08-07 18:24:38 +00001670 return((double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001671 if (LocaleCompare(symbol,"hue") == 0)
1672 {
1673 double
1674 hue,
1675 lightness,
1676 saturation;
1677
cristy0a39a5c2012-06-27 12:51:45 +00001678 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001679 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001680 return(hue);
1681 }
1682 break;
1683 }
1684 case 'I':
1685 case 'i':
1686 {
1687 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1688 (LocaleCompare(symbol,"image.minima") == 0) ||
1689 (LocaleCompare(symbol,"image.maxima") == 0) ||
1690 (LocaleCompare(symbol,"image.mean") == 0) ||
1691 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1692 (LocaleCompare(symbol,"image.skewness") == 0) ||
1693 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1694 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1695 if (LocaleCompare(symbol,"image.resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001696 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001697 if (LocaleCompare(symbol,"image.resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001698 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001699 if (LocaleCompare(symbol,"intensity") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001700 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001701 if (LocaleCompare(symbol,"i") == 0)
cristya19f1d72012-08-07 18:24:38 +00001702 return((double) x);
cristy3ed852e2009-09-05 21:47:34 +00001703 break;
1704 }
1705 case 'J':
1706 case 'j':
1707 {
1708 if (LocaleCompare(symbol,"j") == 0)
cristya19f1d72012-08-07 18:24:38 +00001709 return((double) y);
cristy3ed852e2009-09-05 21:47:34 +00001710 break;
1711 }
1712 case 'L':
1713 case 'l':
1714 {
1715 if (LocaleCompare(symbol,"lightness") == 0)
1716 {
1717 double
1718 hue,
1719 lightness,
1720 saturation;
1721
cristy0a39a5c2012-06-27 12:51:45 +00001722 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001723 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001724 return(lightness);
1725 }
1726 if (LocaleCompare(symbol,"luminance") == 0)
1727 {
1728 double
1729 luminence;
1730
cristya86a5cb2012-10-14 13:40:33 +00001731 luminence=0.21267f*pixel.red+0.71516f*pixel.green+0.07217f*pixel.blue;
cristy3ed852e2009-09-05 21:47:34 +00001732 return(QuantumScale*luminence);
1733 }
1734 break;
1735 }
1736 case 'M':
1737 case 'm':
1738 {
1739 if (LocaleNCompare(symbol,"maxima",6) == 0)
1740 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1741 if (LocaleNCompare(symbol,"mean",4) == 0)
1742 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1743 if (LocaleNCompare(symbol,"minima",6) == 0)
1744 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1745 if (LocaleCompare(symbol,"m") == 0)
1746 return(QuantumScale*pixel.blue);
1747 break;
1748 }
1749 case 'N':
1750 case 'n':
1751 {
1752 if (LocaleCompare(symbol,"n") == 0)
cristya19f1d72012-08-07 18:24:38 +00001753 return((double) GetImageListLength(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001754 break;
1755 }
1756 case 'O':
1757 case 'o':
1758 {
1759 if (LocaleCompare(symbol,"o") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001760 return(QuantumScale*pixel.alpha);
cristy3ed852e2009-09-05 21:47:34 +00001761 break;
1762 }
1763 case 'P':
1764 case 'p':
1765 {
1766 if (LocaleCompare(symbol,"page.height") == 0)
cristya19f1d72012-08-07 18:24:38 +00001767 return((double) image->page.height);
cristy3ed852e2009-09-05 21:47:34 +00001768 if (LocaleCompare(symbol,"page.width") == 0)
cristya19f1d72012-08-07 18:24:38 +00001769 return((double) image->page.width);
cristy3ed852e2009-09-05 21:47:34 +00001770 if (LocaleCompare(symbol,"page.x") == 0)
cristya19f1d72012-08-07 18:24:38 +00001771 return((double) image->page.x);
cristy3ed852e2009-09-05 21:47:34 +00001772 if (LocaleCompare(symbol,"page.y") == 0)
cristya19f1d72012-08-07 18:24:38 +00001773 return((double) image->page.y);
cristy3ed852e2009-09-05 21:47:34 +00001774 break;
1775 }
1776 case 'R':
1777 case 'r':
1778 {
1779 if (LocaleCompare(symbol,"resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001780 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001781 if (LocaleCompare(symbol,"resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001782 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001783 if (LocaleCompare(symbol,"r") == 0)
1784 return(QuantumScale*pixel.red);
1785 break;
1786 }
1787 case 'S':
1788 case 's':
1789 {
1790 if (LocaleCompare(symbol,"saturation") == 0)
1791 {
1792 double
1793 hue,
1794 lightness,
1795 saturation;
1796
cristy0a39a5c2012-06-27 12:51:45 +00001797 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001798 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001799 return(saturation);
1800 }
1801 if (LocaleNCompare(symbol,"skewness",8) == 0)
1802 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1803 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1804 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1805 break;
1806 }
1807 case 'T':
1808 case 't':
1809 {
1810 if (LocaleCompare(symbol,"t") == 0)
cristya19f1d72012-08-07 18:24:38 +00001811 return((double) GetImageIndexInList(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001812 break;
1813 }
1814 case 'W':
1815 case 'w':
1816 {
1817 if (LocaleCompare(symbol,"w") == 0)
cristya19f1d72012-08-07 18:24:38 +00001818 return((double) image->columns);
cristy3ed852e2009-09-05 21:47:34 +00001819 break;
1820 }
1821 case 'Y':
1822 case 'y':
1823 {
1824 if (LocaleCompare(symbol,"y") == 0)
1825 return(QuantumScale*pixel.green);
1826 break;
1827 }
1828 case 'Z':
1829 case 'z':
1830 {
1831 if (LocaleCompare(symbol,"z") == 0)
1832 {
cristya19f1d72012-08-07 18:24:38 +00001833 double
cristy3ed852e2009-09-05 21:47:34 +00001834 depth;
1835
cristya19f1d72012-08-07 18:24:38 +00001836 depth=(double) GetImageDepth(image,fx_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001837 return(depth);
1838 }
1839 break;
1840 }
1841 default:
1842 break;
1843 }
1844 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1845 if (value != (const char *) NULL)
cristya19f1d72012-08-07 18:24:38 +00001846 return((double) StringToDouble(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001847 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00001848 "UnableToParseExpression","`%s'",symbol);
cristy3ed852e2009-09-05 21:47:34 +00001849 return(0.0);
1850}
1851
1852static const char *FxOperatorPrecedence(const char *expression,
1853 ExceptionInfo *exception)
1854{
1855 typedef enum
1856 {
1857 UndefinedPrecedence,
1858 NullPrecedence,
1859 BitwiseComplementPrecedence,
1860 ExponentPrecedence,
cristy116af162010-08-13 01:25:47 +00001861 ExponentialNotationPrecedence,
cristy3ed852e2009-09-05 21:47:34 +00001862 MultiplyPrecedence,
1863 AdditionPrecedence,
1864 ShiftPrecedence,
1865 RelationalPrecedence,
1866 EquivalencyPrecedence,
1867 BitwiseAndPrecedence,
1868 BitwiseOrPrecedence,
1869 LogicalAndPrecedence,
1870 LogicalOrPrecedence,
1871 TernaryPrecedence,
1872 AssignmentPrecedence,
1873 CommaPrecedence,
1874 SeparatorPrecedence
1875 } FxPrecedence;
1876
1877 FxPrecedence
1878 precedence,
1879 target;
1880
1881 register const char
1882 *subexpression;
1883
1884 register int
1885 c;
1886
cristybb503372010-05-27 20:51:26 +00001887 size_t
cristy3ed852e2009-09-05 21:47:34 +00001888 level;
1889
1890 c=0;
1891 level=0;
1892 subexpression=(const char *) NULL;
1893 target=NullPrecedence;
1894 while (*expression != '\0')
1895 {
1896 precedence=UndefinedPrecedence;
1897 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1898 {
1899 expression++;
1900 continue;
1901 }
cristy488fa882010-03-01 22:34:24 +00001902 switch (*expression)
1903 {
1904 case 'A':
1905 case 'a':
cristy3ed852e2009-09-05 21:47:34 +00001906 {
cristyb33454f2011-08-03 02:10:45 +00001907#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00001908 if (LocaleNCompare(expression,"acosh",5) == 0)
1909 {
1910 expression+=5;
1911 break;
1912 }
cristyb33454f2011-08-03 02:10:45 +00001913#endif
1914#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00001915 if (LocaleNCompare(expression,"asinh",5) == 0)
1916 {
1917 expression+=5;
1918 break;
1919 }
cristyb33454f2011-08-03 02:10:45 +00001920#endif
1921#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00001922 if (LocaleNCompare(expression,"atanh",5) == 0)
cristy488fa882010-03-01 22:34:24 +00001923 {
1924 expression+=5;
1925 break;
1926 }
cristyb33454f2011-08-03 02:10:45 +00001927#endif
anthony62838e52012-05-24 12:41:54 +00001928 if (LocaleNCompare(expression,"atan2",5) == 0)
1929 {
1930 expression+=5;
1931 break;
1932 }
cristy488fa882010-03-01 22:34:24 +00001933 break;
cristy3ed852e2009-09-05 21:47:34 +00001934 }
cristy62d455f2011-11-03 11:42:28 +00001935 case 'E':
1936 case 'e':
1937 {
1938 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1939 (LocaleNCompare(expression,"E-",2) == 0))
1940 {
1941 expression+=2; /* scientific notation */
1942 break;
1943 }
1944 }
cristy488fa882010-03-01 22:34:24 +00001945 case 'J':
1946 case 'j':
1947 {
1948 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1949 (LocaleNCompare(expression,"j1",2) == 0))
1950 {
1951 expression+=2;
1952 break;
1953 }
1954 break;
1955 }
cristy2def9322010-06-18 23:59:37 +00001956 case '#':
1957 {
1958 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1959 expression++;
1960 break;
1961 }
cristy488fa882010-03-01 22:34:24 +00001962 default:
1963 break;
1964 }
cristy3ed852e2009-09-05 21:47:34 +00001965 if ((c == (int) '{') || (c == (int) '['))
1966 level++;
1967 else
1968 if ((c == (int) '}') || (c == (int) ']'))
1969 level--;
1970 if (level == 0)
1971 switch ((unsigned char) *expression)
1972 {
1973 case '~':
1974 case '!':
1975 {
1976 precedence=BitwiseComplementPrecedence;
1977 break;
1978 }
1979 case '^':
cristy6621e252010-08-13 00:42:57 +00001980 case '@':
cristy3ed852e2009-09-05 21:47:34 +00001981 {
1982 precedence=ExponentPrecedence;
1983 break;
1984 }
1985 default:
1986 {
1987 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1988 (strchr(")",c) != (char *) NULL))) &&
1989 (((islower((int) ((char) *expression)) != 0) ||
1990 (strchr("(",(int) *expression) != (char *) NULL)) ||
1991 ((isdigit((int) ((char) c)) == 0) &&
1992 (isdigit((int) ((char) *expression)) != 0))) &&
1993 (strchr("xy",(int) *expression) == (char *) NULL))
1994 precedence=MultiplyPrecedence;
1995 break;
1996 }
1997 case '*':
1998 case '/':
1999 case '%':
2000 {
2001 precedence=MultiplyPrecedence;
2002 break;
2003 }
2004 case '+':
2005 case '-':
2006 {
2007 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
2008 (isalpha(c) != 0))
2009 precedence=AdditionPrecedence;
2010 break;
2011 }
2012 case LeftShiftOperator:
2013 case RightShiftOperator:
2014 {
2015 precedence=ShiftPrecedence;
2016 break;
2017 }
2018 case '<':
2019 case LessThanEqualOperator:
2020 case GreaterThanEqualOperator:
2021 case '>':
2022 {
2023 precedence=RelationalPrecedence;
2024 break;
2025 }
2026 case EqualOperator:
2027 case NotEqualOperator:
2028 {
2029 precedence=EquivalencyPrecedence;
2030 break;
2031 }
2032 case '&':
2033 {
2034 precedence=BitwiseAndPrecedence;
2035 break;
2036 }
2037 case '|':
2038 {
2039 precedence=BitwiseOrPrecedence;
2040 break;
2041 }
2042 case LogicalAndOperator:
2043 {
2044 precedence=LogicalAndPrecedence;
2045 break;
2046 }
2047 case LogicalOrOperator:
2048 {
2049 precedence=LogicalOrPrecedence;
2050 break;
2051 }
cristy116af162010-08-13 01:25:47 +00002052 case ExponentialNotation:
2053 {
2054 precedence=ExponentialNotationPrecedence;
2055 break;
2056 }
cristy3ed852e2009-09-05 21:47:34 +00002057 case ':':
2058 case '?':
2059 {
2060 precedence=TernaryPrecedence;
2061 break;
2062 }
2063 case '=':
2064 {
2065 precedence=AssignmentPrecedence;
2066 break;
2067 }
2068 case ',':
2069 {
2070 precedence=CommaPrecedence;
2071 break;
2072 }
2073 case ';':
2074 {
2075 precedence=SeparatorPrecedence;
2076 break;
2077 }
2078 }
2079 if ((precedence == BitwiseComplementPrecedence) ||
2080 (precedence == TernaryPrecedence) ||
2081 (precedence == AssignmentPrecedence))
2082 {
2083 if (precedence > target)
2084 {
2085 /*
2086 Right-to-left associativity.
2087 */
2088 target=precedence;
2089 subexpression=expression;
2090 }
2091 }
2092 else
2093 if (precedence >= target)
2094 {
2095 /*
2096 Left-to-right associativity.
2097 */
2098 target=precedence;
2099 subexpression=expression;
2100 }
2101 if (strchr("(",(int) *expression) != (char *) NULL)
2102 expression=FxSubexpression(expression,exception);
2103 c=(int) (*expression++);
2104 }
2105 return(subexpression);
2106}
2107
cristya19f1d72012-08-07 18:24:38 +00002108static double FxEvaluateSubexpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002109 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00002110 const char *expression,double *beta,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002111{
2112 char
2113 *q,
2114 subexpression[MaxTextExtent];
2115
cristya19f1d72012-08-07 18:24:38 +00002116 double
cristy3ed852e2009-09-05 21:47:34 +00002117 alpha,
2118 gamma;
2119
2120 register const char
2121 *p;
2122
2123 *beta=0.0;
2124 if (exception->severity != UndefinedException)
2125 return(0.0);
2126 while (isspace((int) *expression) != 0)
2127 expression++;
2128 if (*expression == '\0')
2129 {
2130 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
cristyefe601c2013-01-05 17:51:12 +00002131 "MissingExpression","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002132 return(0.0);
2133 }
cristy66322f02010-05-17 11:40:48 +00002134 *subexpression='\0';
cristy3ed852e2009-09-05 21:47:34 +00002135 p=FxOperatorPrecedence(expression,exception);
2136 if (p != (const char *) NULL)
2137 {
2138 (void) CopyMagickString(subexpression,expression,(size_t)
2139 (p-expression+1));
2140 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2141 exception);
2142 switch ((unsigned char) *p)
2143 {
2144 case '~':
2145 {
2146 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002147 *beta=(double) (~(size_t) *beta);
cristy3ed852e2009-09-05 21:47:34 +00002148 return(*beta);
2149 }
2150 case '!':
2151 {
2152 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2153 return(*beta == 0.0 ? 1.0 : 0.0);
2154 }
2155 case '^':
2156 {
2157 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2158 channel,x,y,++p,beta,exception));
2159 return(*beta);
2160 }
2161 case '*':
cristy116af162010-08-13 01:25:47 +00002162 case ExponentialNotation:
cristy3ed852e2009-09-05 21:47:34 +00002163 {
2164 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2165 return(alpha*(*beta));
2166 }
2167 case '/':
2168 {
2169 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2170 if (*beta == 0.0)
2171 {
2172 if (exception->severity == UndefinedException)
2173 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002174 OptionError,"DivideByZero","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002175 return(0.0);
2176 }
2177 return(alpha/(*beta));
2178 }
2179 case '%':
2180 {
2181 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2182 *beta=fabs(floor(((double) *beta)+0.5));
2183 if (*beta == 0.0)
2184 {
2185 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002186 OptionError,"DivideByZero","`%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002187 return(0.0);
2188 }
2189 return(fmod((double) alpha,(double) *beta));
2190 }
2191 case '+':
2192 {
2193 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2194 return(alpha+(*beta));
2195 }
2196 case '-':
2197 {
2198 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2199 return(alpha-(*beta));
2200 }
2201 case LeftShiftOperator:
2202 {
2203 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002204 *beta=(double) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002205 return(*beta);
2206 }
2207 case RightShiftOperator:
2208 {
2209 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002210 *beta=(double) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002211 return(*beta);
2212 }
2213 case '<':
2214 {
2215 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2216 return(alpha < *beta ? 1.0 : 0.0);
2217 }
2218 case LessThanEqualOperator:
2219 {
2220 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2221 return(alpha <= *beta ? 1.0 : 0.0);
2222 }
2223 case '>':
2224 {
2225 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2226 return(alpha > *beta ? 1.0 : 0.0);
2227 }
2228 case GreaterThanEqualOperator:
2229 {
2230 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2231 return(alpha >= *beta ? 1.0 : 0.0);
2232 }
2233 case EqualOperator:
2234 {
2235 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristy9b528342012-06-02 00:59:20 +00002236 return(fabs(alpha-(*beta)) < MagickEpsilon ? MagickEpsilon : 0.0);
cristy3ed852e2009-09-05 21:47:34 +00002237 }
2238 case NotEqualOperator:
2239 {
2240 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristy972050b2012-06-04 22:09:17 +00002241 return(fabs(alpha-(*beta)) >= MagickEpsilon ? 1.0 : 0.0);
cristy3ed852e2009-09-05 21:47:34 +00002242 }
2243 case '&':
2244 {
2245 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002246 *beta=(double) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002247 return(*beta);
2248 }
2249 case '|':
2250 {
2251 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002252 *beta=(double) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002253 return(*beta);
2254 }
2255 case LogicalAndOperator:
2256 {
2257 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2258 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2259 return(*beta);
2260 }
2261 case LogicalOrOperator:
2262 {
2263 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2264 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2265 return(*beta);
2266 }
2267 case '?':
2268 {
cristya19f1d72012-08-07 18:24:38 +00002269 double
cristy3ed852e2009-09-05 21:47:34 +00002270 gamma;
2271
2272 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2273 q=subexpression;
2274 p=StringToken(":",&q);
2275 if (q == (char *) NULL)
2276 {
2277 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002278 OptionError,"UnableToParseExpression","`%s'",subexpression);
cristy3ed852e2009-09-05 21:47:34 +00002279 return(0.0);
2280 }
cristy972050b2012-06-04 22:09:17 +00002281 if (fabs((double) alpha) >= MagickEpsilon)
cristy3ed852e2009-09-05 21:47:34 +00002282 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2283 else
2284 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2285 return(gamma);
2286 }
2287 case '=':
2288 {
2289 char
2290 numeric[MaxTextExtent];
2291
2292 q=subexpression;
2293 while (isalpha((int) ((unsigned char) *q)) != 0)
2294 q++;
2295 if (*q != '\0')
2296 {
2297 (void) ThrowMagickException(exception,GetMagickModule(),
cristyefe601c2013-01-05 17:51:12 +00002298 OptionError,"UnableToParseExpression","`%s'",subexpression);
cristy3ed852e2009-09-05 21:47:34 +00002299 return(0.0);
2300 }
2301 ClearMagickException(exception);
2302 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristyb51dff52011-05-19 16:55:47 +00002303 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
cristy8cd5b312010-01-07 01:10:24 +00002304 *beta);
cristy3ed852e2009-09-05 21:47:34 +00002305 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2306 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2307 subexpression),ConstantString(numeric));
2308 return(*beta);
2309 }
2310 case ',':
2311 {
2312 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2313 return(alpha);
2314 }
2315 case ';':
2316 {
2317 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2318 return(*beta);
2319 }
2320 default:
2321 {
2322 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2323 exception);
2324 return(gamma);
2325 }
2326 }
2327 }
2328 if (strchr("(",(int) *expression) != (char *) NULL)
2329 {
2330 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2331 subexpression[strlen(subexpression)-1]='\0';
2332 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2333 exception);
2334 return(gamma);
2335 }
cristy8b8a3ae2010-10-23 18:49:46 +00002336 switch (*expression)
cristy3ed852e2009-09-05 21:47:34 +00002337 {
2338 case '+':
2339 {
2340 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2341 exception);
2342 return(1.0*gamma);
2343 }
2344 case '-':
2345 {
2346 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2347 exception);
2348 return(-1.0*gamma);
2349 }
2350 case '~':
2351 {
2352 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2353 exception);
cristya19f1d72012-08-07 18:24:38 +00002354 return((double) (~(size_t) (gamma+0.5)));
cristy3ed852e2009-09-05 21:47:34 +00002355 }
2356 case 'A':
2357 case 'a':
2358 {
2359 if (LocaleNCompare(expression,"abs",3) == 0)
2360 {
2361 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2362 exception);
cristya19f1d72012-08-07 18:24:38 +00002363 return((double) fabs((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002364 }
cristyb33454f2011-08-03 02:10:45 +00002365#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00002366 if (LocaleNCompare(expression,"acosh",5) == 0)
2367 {
2368 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2369 exception);
cristya19f1d72012-08-07 18:24:38 +00002370 return((double) acosh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002371 }
cristyb33454f2011-08-03 02:10:45 +00002372#endif
cristy3ed852e2009-09-05 21:47:34 +00002373 if (LocaleNCompare(expression,"acos",4) == 0)
2374 {
2375 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2376 exception);
cristya19f1d72012-08-07 18:24:38 +00002377 return((double) acos((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002378 }
cristy43c22f42010-03-30 12:34:07 +00002379#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002380 if (LocaleNCompare(expression,"airy",4) == 0)
2381 {
2382 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2383 exception);
2384 if (alpha == 0.0)
cristy2dd03222010-03-30 22:12:11 +00002385 return(1.0);
2386 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
cristy43c22f42010-03-30 12:34:07 +00002387 return(gamma*gamma);
cristyee56cf12010-03-01 22:17:06 +00002388 }
cristy43c22f42010-03-30 12:34:07 +00002389#endif
cristyb33454f2011-08-03 02:10:45 +00002390#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00002391 if (LocaleNCompare(expression,"asinh",5) == 0)
2392 {
2393 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2394 exception);
cristya19f1d72012-08-07 18:24:38 +00002395 return((double) asinh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002396 }
cristyb33454f2011-08-03 02:10:45 +00002397#endif
cristy3ed852e2009-09-05 21:47:34 +00002398 if (LocaleNCompare(expression,"asin",4) == 0)
2399 {
2400 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2401 exception);
cristya19f1d72012-08-07 18:24:38 +00002402 return((double) asin((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002403 }
2404 if (LocaleNCompare(expression,"alt",3) == 0)
2405 {
2406 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2407 exception);
cristybb503372010-05-27 20:51:26 +00002408 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
cristy3ed852e2009-09-05 21:47:34 +00002409 }
2410 if (LocaleNCompare(expression,"atan2",5) == 0)
2411 {
2412 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2413 exception);
cristya19f1d72012-08-07 18:24:38 +00002414 return((double) atan2((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002415 }
cristyb33454f2011-08-03 02:10:45 +00002416#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00002417 if (LocaleNCompare(expression,"atanh",5) == 0)
2418 {
2419 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2420 exception);
cristya19f1d72012-08-07 18:24:38 +00002421 return((double) atanh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002422 }
cristyb33454f2011-08-03 02:10:45 +00002423#endif
cristy3ed852e2009-09-05 21:47:34 +00002424 if (LocaleNCompare(expression,"atan",4) == 0)
2425 {
2426 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2427 exception);
cristya19f1d72012-08-07 18:24:38 +00002428 return((double) atan((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002429 }
2430 if (LocaleCompare(expression,"a") == 0)
2431 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2432 break;
2433 }
2434 case 'B':
2435 case 'b':
2436 {
2437 if (LocaleCompare(expression,"b") == 0)
2438 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2439 break;
2440 }
2441 case 'C':
2442 case 'c':
2443 {
2444 if (LocaleNCompare(expression,"ceil",4) == 0)
2445 {
2446 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2447 exception);
cristya19f1d72012-08-07 18:24:38 +00002448 return((double) ceil((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002449 }
2450 if (LocaleNCompare(expression,"cosh",4) == 0)
2451 {
2452 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2453 exception);
cristya19f1d72012-08-07 18:24:38 +00002454 return((double) cosh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002455 }
2456 if (LocaleNCompare(expression,"cos",3) == 0)
2457 {
2458 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2459 exception);
cristya19f1d72012-08-07 18:24:38 +00002460 return((double) cos((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002461 }
2462 if (LocaleCompare(expression,"c") == 0)
2463 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2464 break;
2465 }
2466 case 'D':
2467 case 'd':
2468 {
2469 if (LocaleNCompare(expression,"debug",5) == 0)
2470 {
2471 const char
2472 *type;
2473
2474 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2475 exception);
2476 if (fx_info->images->colorspace == CMYKColorspace)
2477 switch (channel)
2478 {
cristy0568ffc2011-07-25 16:54:14 +00002479 case CyanPixelChannel: type="cyan"; break;
2480 case MagentaPixelChannel: type="magenta"; break;
2481 case YellowPixelChannel: type="yellow"; break;
2482 case AlphaPixelChannel: type="opacity"; break;
2483 case BlackPixelChannel: type="black"; break;
cristy3ed852e2009-09-05 21:47:34 +00002484 default: type="unknown"; break;
2485 }
2486 else
2487 switch (channel)
2488 {
cristy0568ffc2011-07-25 16:54:14 +00002489 case RedPixelChannel: type="red"; break;
2490 case GreenPixelChannel: type="green"; break;
2491 case BluePixelChannel: type="blue"; break;
2492 case AlphaPixelChannel: type="opacity"; break;
cristy3ed852e2009-09-05 21:47:34 +00002493 default: type="unknown"; break;
2494 }
2495 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2496 if (strlen(subexpression) > 1)
2497 subexpression[strlen(subexpression)-1]='\0';
2498 if (fx_info->file != (FILE *) NULL)
cristy1707c6c2012-01-18 23:30:54 +00002499 (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: "
2500 "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type,
2501 subexpression,GetMagickPrecision(),(double) alpha);
cristy3ed852e2009-09-05 21:47:34 +00002502 return(0.0);
2503 }
cristy5597a8d2011-11-04 00:25:32 +00002504 if (LocaleNCompare(expression,"drc",3) == 0)
2505 {
2506 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2507 exception);
cristya19f1d72012-08-07 18:24:38 +00002508 return((double) (alpha/(*beta*(alpha-1.0)+1.0)));
cristy5597a8d2011-11-04 00:25:32 +00002509 }
cristy3ed852e2009-09-05 21:47:34 +00002510 break;
2511 }
2512 case 'E':
2513 case 'e':
2514 {
2515 if (LocaleCompare(expression,"epsilon") == 0)
cristya19f1d72012-08-07 18:24:38 +00002516 return((double) MagickEpsilon);
cristy3ed852e2009-09-05 21:47:34 +00002517 if (LocaleNCompare(expression,"exp",3) == 0)
2518 {
2519 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2520 exception);
cristya19f1d72012-08-07 18:24:38 +00002521 return((double) exp((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002522 }
2523 if (LocaleCompare(expression,"e") == 0)
cristya19f1d72012-08-07 18:24:38 +00002524 return((double) 2.7182818284590452354);
cristy3ed852e2009-09-05 21:47:34 +00002525 break;
2526 }
2527 case 'F':
2528 case 'f':
2529 {
2530 if (LocaleNCompare(expression,"floor",5) == 0)
2531 {
2532 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2533 exception);
cristya19f1d72012-08-07 18:24:38 +00002534 return((double) floor((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002535 }
2536 break;
2537 }
2538 case 'G':
2539 case 'g':
2540 {
cristy9eeedea2011-11-02 19:04:05 +00002541 if (LocaleNCompare(expression,"gauss",5) == 0)
2542 {
2543 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2544 exception);
2545 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
cristya19f1d72012-08-07 18:24:38 +00002546 return((double) gamma);
cristy9eeedea2011-11-02 19:04:05 +00002547 }
cristyb0aad4c2011-11-02 19:30:35 +00002548 if (LocaleNCompare(expression,"gcd",3) == 0)
2549 {
2550 MagickOffsetType
2551 gcd;
2552
2553 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2554 exception);
cristy1707c6c2012-01-18 23:30:54 +00002555 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
2556 0.5));
cristya19f1d72012-08-07 18:24:38 +00002557 return((double) gcd);
cristyb0aad4c2011-11-02 19:30:35 +00002558 }
cristy3ed852e2009-09-05 21:47:34 +00002559 if (LocaleCompare(expression,"g") == 0)
2560 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2561 break;
2562 }
2563 case 'H':
2564 case 'h':
2565 {
2566 if (LocaleCompare(expression,"h") == 0)
2567 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2568 if (LocaleCompare(expression,"hue") == 0)
2569 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2570 if (LocaleNCompare(expression,"hypot",5) == 0)
2571 {
2572 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2573 exception);
cristya19f1d72012-08-07 18:24:38 +00002574 return((double) hypot((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002575 }
2576 break;
2577 }
2578 case 'K':
2579 case 'k':
2580 {
2581 if (LocaleCompare(expression,"k") == 0)
2582 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2583 break;
2584 }
2585 case 'I':
2586 case 'i':
2587 {
2588 if (LocaleCompare(expression,"intensity") == 0)
2589 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2590 if (LocaleNCompare(expression,"int",3) == 0)
2591 {
2592 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2593 exception);
cristya19f1d72012-08-07 18:24:38 +00002594 return((double) floor(alpha));
cristy3ed852e2009-09-05 21:47:34 +00002595 }
cristy82b20722011-11-05 21:52:36 +00002596#if defined(MAGICKCORE_HAVE_ISNAN)
cristy639399c2011-11-02 19:16:15 +00002597 if (LocaleNCompare(expression,"isnan",5) == 0)
2598 {
2599 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2600 exception);
cristya19f1d72012-08-07 18:24:38 +00002601 return((double) !!isnan((double) alpha));
cristy639399c2011-11-02 19:16:15 +00002602 }
cristy82b20722011-11-05 21:52:36 +00002603#endif
cristy3ed852e2009-09-05 21:47:34 +00002604 if (LocaleCompare(expression,"i") == 0)
2605 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2606 break;
2607 }
2608 case 'J':
2609 case 'j':
2610 {
2611 if (LocaleCompare(expression,"j") == 0)
2612 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
cristy161b9262010-03-20 19:34:32 +00002613#if defined(MAGICKCORE_HAVE_J0)
cristyee56cf12010-03-01 22:17:06 +00002614 if (LocaleNCompare(expression,"j0",2) == 0)
2615 {
2616 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2617 exception);
cristya19f1d72012-08-07 18:24:38 +00002618 return((double) j0((double) alpha));
cristyee56cf12010-03-01 22:17:06 +00002619 }
cristy161b9262010-03-20 19:34:32 +00002620#endif
2621#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002622 if (LocaleNCompare(expression,"j1",2) == 0)
2623 {
2624 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2625 exception);
cristya19f1d72012-08-07 18:24:38 +00002626 return((double) j1((double) alpha));
cristyee56cf12010-03-01 22:17:06 +00002627 }
cristy161b9262010-03-20 19:34:32 +00002628#endif
cristyaa018fa2010-04-08 23:03:54 +00002629#if defined(MAGICKCORE_HAVE_J1)
cristya6a09e72010-03-02 14:51:02 +00002630 if (LocaleNCompare(expression,"jinc",4) == 0)
2631 {
2632 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2633 exception);
cristy0946a822010-03-12 17:14:58 +00002634 if (alpha == 0.0)
2635 return(1.0);
cristyc90d70d2012-11-03 23:53:13 +00002636 gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha));
cristyfce2f7b2010-03-12 00:29:49 +00002637 return(gamma);
cristya6a09e72010-03-02 14:51:02 +00002638 }
cristyaa018fa2010-04-08 23:03:54 +00002639#endif
cristy3ed852e2009-09-05 21:47:34 +00002640 break;
2641 }
2642 case 'L':
2643 case 'l':
2644 {
2645 if (LocaleNCompare(expression,"ln",2) == 0)
2646 {
2647 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2648 exception);
cristya19f1d72012-08-07 18:24:38 +00002649 return((double) log((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002650 }
cristyc8ed5322010-08-31 12:07:59 +00002651 if (LocaleNCompare(expression,"logtwo",6) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002652 {
cristyc8ed5322010-08-31 12:07:59 +00002653 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
cristy3ed852e2009-09-05 21:47:34 +00002654 exception);
cristya19f1d72012-08-07 18:24:38 +00002655 return((double) log10((double) alpha))/log10(2.0);
cristy3ed852e2009-09-05 21:47:34 +00002656 }
2657 if (LocaleNCompare(expression,"log",3) == 0)
2658 {
2659 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2660 exception);
cristya19f1d72012-08-07 18:24:38 +00002661 return((double) log10((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002662 }
2663 if (LocaleCompare(expression,"lightness") == 0)
2664 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2665 break;
2666 }
2667 case 'M':
2668 case 'm':
2669 {
2670 if (LocaleCompare(expression,"MaxRGB") == 0)
cristya19f1d72012-08-07 18:24:38 +00002671 return((double) QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002672 if (LocaleNCompare(expression,"maxima",6) == 0)
2673 break;
2674 if (LocaleNCompare(expression,"max",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002675 {
2676 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2677 exception);
2678 return(alpha > *beta ? alpha : *beta);
2679 }
cristy3ed852e2009-09-05 21:47:34 +00002680 if (LocaleNCompare(expression,"minima",6) == 0)
2681 break;
2682 if (LocaleNCompare(expression,"min",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002683 {
2684 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2685 exception);
2686 return(alpha < *beta ? alpha : *beta);
2687 }
cristy3ed852e2009-09-05 21:47:34 +00002688 if (LocaleNCompare(expression,"mod",3) == 0)
2689 {
2690 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2691 exception);
cristy984049c2011-11-03 18:34:58 +00002692 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2693 return(gamma);
cristy3ed852e2009-09-05 21:47:34 +00002694 }
2695 if (LocaleCompare(expression,"m") == 0)
2696 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2697 break;
2698 }
2699 case 'N':
2700 case 'n':
2701 {
cristyad3502e2011-11-02 19:10:45 +00002702 if (LocaleNCompare(expression,"not",3) == 0)
2703 {
2704 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2705 exception);
cristya19f1d72012-08-07 18:24:38 +00002706 return((double) (alpha < MagickEpsilon));
cristyad3502e2011-11-02 19:10:45 +00002707 }
cristy3ed852e2009-09-05 21:47:34 +00002708 if (LocaleCompare(expression,"n") == 0)
2709 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2710 break;
2711 }
2712 case 'O':
2713 case 'o':
2714 {
2715 if (LocaleCompare(expression,"Opaque") == 0)
2716 return(1.0);
2717 if (LocaleCompare(expression,"o") == 0)
2718 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2719 break;
2720 }
2721 case 'P':
2722 case 'p':
2723 {
cristy670aa3c2011-11-03 00:54:00 +00002724 if (LocaleCompare(expression,"phi") == 0)
cristya19f1d72012-08-07 18:24:38 +00002725 return((double) MagickPHI);
cristy3ed852e2009-09-05 21:47:34 +00002726 if (LocaleCompare(expression,"pi") == 0)
cristya19f1d72012-08-07 18:24:38 +00002727 return((double) MagickPI);
cristy3ed852e2009-09-05 21:47:34 +00002728 if (LocaleNCompare(expression,"pow",3) == 0)
2729 {
2730 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2731 exception);
cristya19f1d72012-08-07 18:24:38 +00002732 return((double) pow((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002733 }
2734 if (LocaleCompare(expression,"p") == 0)
2735 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2736 break;
2737 }
2738 case 'Q':
2739 case 'q':
2740 {
2741 if (LocaleCompare(expression,"QuantumRange") == 0)
cristya19f1d72012-08-07 18:24:38 +00002742 return((double) QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002743 if (LocaleCompare(expression,"QuantumScale") == 0)
cristya19f1d72012-08-07 18:24:38 +00002744 return((double) QuantumScale);
cristy3ed852e2009-09-05 21:47:34 +00002745 break;
2746 }
2747 case 'R':
2748 case 'r':
2749 {
2750 if (LocaleNCompare(expression,"rand",4) == 0)
cristya19f1d72012-08-07 18:24:38 +00002751 return((double) GetPseudoRandomValue(fx_info->random_info));
cristy3ed852e2009-09-05 21:47:34 +00002752 if (LocaleNCompare(expression,"round",5) == 0)
2753 {
2754 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2755 exception);
cristya19f1d72012-08-07 18:24:38 +00002756 return((double) floor((double) alpha+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002757 }
2758 if (LocaleCompare(expression,"r") == 0)
2759 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2760 break;
2761 }
2762 case 'S':
2763 case 's':
2764 {
2765 if (LocaleCompare(expression,"saturation") == 0)
2766 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2767 if (LocaleNCompare(expression,"sign",4) == 0)
2768 {
2769 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2770 exception);
2771 return(alpha < 0.0 ? -1.0 : 1.0);
2772 }
cristya6a09e72010-03-02 14:51:02 +00002773 if (LocaleNCompare(expression,"sinc",4) == 0)
2774 {
2775 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2776 exception);
2777 if (alpha == 0)
2778 return(1.0);
cristya19f1d72012-08-07 18:24:38 +00002779 gamma=(double) (sin((double) (MagickPI*alpha))/
cristya6a09e72010-03-02 14:51:02 +00002780 (MagickPI*alpha));
2781 return(gamma);
2782 }
cristy3ed852e2009-09-05 21:47:34 +00002783 if (LocaleNCompare(expression,"sinh",4) == 0)
2784 {
2785 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2786 exception);
cristya19f1d72012-08-07 18:24:38 +00002787 return((double) sinh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002788 }
2789 if (LocaleNCompare(expression,"sin",3) == 0)
2790 {
2791 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2792 exception);
cristya19f1d72012-08-07 18:24:38 +00002793 return((double) sin((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002794 }
2795 if (LocaleNCompare(expression,"sqrt",4) == 0)
2796 {
2797 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2798 exception);
cristya19f1d72012-08-07 18:24:38 +00002799 return((double) sqrt((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002800 }
cristy9eeedea2011-11-02 19:04:05 +00002801 if (LocaleNCompare(expression,"squish",6) == 0)
2802 {
2803 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2804 exception);
cristya19f1d72012-08-07 18:24:38 +00002805 return((double) (1.0/(1.0+exp((double) (-alpha)))));
cristy9eeedea2011-11-02 19:04:05 +00002806 }
cristy3ed852e2009-09-05 21:47:34 +00002807 if (LocaleCompare(expression,"s") == 0)
2808 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2809 break;
2810 }
2811 case 'T':
2812 case 't':
2813 {
2814 if (LocaleNCompare(expression,"tanh",4) == 0)
2815 {
2816 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2817 exception);
cristya19f1d72012-08-07 18:24:38 +00002818 return((double) tanh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002819 }
2820 if (LocaleNCompare(expression,"tan",3) == 0)
2821 {
2822 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2823 exception);
cristya19f1d72012-08-07 18:24:38 +00002824 return((double) tan((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002825 }
2826 if (LocaleCompare(expression,"Transparent") == 0)
2827 return(0.0);
cristy16788e42010-08-13 13:44:26 +00002828 if (LocaleNCompare(expression,"trunc",5) == 0)
2829 {
2830 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2831 exception);
2832 if (alpha >= 0.0)
cristya19f1d72012-08-07 18:24:38 +00002833 return((double) floor((double) alpha));
2834 return((double) ceil((double) alpha));
cristy16788e42010-08-13 13:44:26 +00002835 }
cristy3ed852e2009-09-05 21:47:34 +00002836 if (LocaleCompare(expression,"t") == 0)
2837 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2838 break;
2839 }
2840 case 'U':
2841 case 'u':
2842 {
2843 if (LocaleCompare(expression,"u") == 0)
2844 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2845 break;
2846 }
2847 case 'V':
2848 case 'v':
2849 {
2850 if (LocaleCompare(expression,"v") == 0)
2851 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2852 break;
2853 }
2854 case 'W':
2855 case 'w':
2856 {
cristy9eeedea2011-11-02 19:04:05 +00002857 if (LocaleNCompare(expression,"while",5) == 0)
2858 {
2859 do
2860 {
2861 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2862 exception);
2863 } while (fabs((double) alpha) >= MagickEpsilon);
cristya19f1d72012-08-07 18:24:38 +00002864 return((double) *beta);
cristy9eeedea2011-11-02 19:04:05 +00002865 }
cristy3ed852e2009-09-05 21:47:34 +00002866 if (LocaleCompare(expression,"w") == 0)
2867 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2868 break;
2869 }
2870 case 'Y':
2871 case 'y':
2872 {
2873 if (LocaleCompare(expression,"y") == 0)
2874 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2875 break;
2876 }
2877 case 'Z':
2878 case 'z':
2879 {
2880 if (LocaleCompare(expression,"z") == 0)
2881 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2882 break;
2883 }
2884 default:
2885 break;
2886 }
2887 q=(char *) expression;
cristydbdd0e32011-11-04 23:29:40 +00002888 alpha=InterpretSiPrefixValue(expression,&q);
cristy3ed852e2009-09-05 21:47:34 +00002889 if (q == expression)
2890 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2891 return(alpha);
2892}
2893
cristy7832dc22011-09-05 01:21:53 +00002894MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
cristya19f1d72012-08-07 18:24:38 +00002895 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002896{
2897 MagickBooleanType
2898 status;
2899
cristy541ae572011-08-05 19:08:59 +00002900 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2901 exception);
cristy3ed852e2009-09-05 21:47:34 +00002902 return(status);
2903}
2904
2905MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
cristya19f1d72012-08-07 18:24:38 +00002906 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002907{
2908 FILE
2909 *file;
2910
2911 MagickBooleanType
2912 status;
2913
2914 file=fx_info->file;
2915 fx_info->file=(FILE *) NULL;
cristy541ae572011-08-05 19:08:59 +00002916 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2917 exception);
cristy3ed852e2009-09-05 21:47:34 +00002918 fx_info->file=file;
2919 return(status);
2920}
2921
cristy7832dc22011-09-05 01:21:53 +00002922MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002923 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00002924 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002925{
cristya19f1d72012-08-07 18:24:38 +00002926 double
cristy3ed852e2009-09-05 21:47:34 +00002927 beta;
2928
2929 beta=0.0;
2930 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2931 exception);
2932 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2933}
2934
2935/*
2936%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2937% %
2938% %
2939% %
2940% F x I m a g e %
2941% %
2942% %
2943% %
2944%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2945%
2946% FxImage() applies a mathematical expression to the specified image.
2947%
2948% The format of the FxImage method is:
2949%
2950% Image *FxImage(const Image *image,const char *expression,
2951% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002952%
2953% A description of each parameter follows:
2954%
2955% o image: the image.
2956%
cristy3ed852e2009-09-05 21:47:34 +00002957% o expression: A mathematical expression.
2958%
2959% o exception: return any errors or warnings in this structure.
2960%
2961*/
2962
2963static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2964{
cristybb503372010-05-27 20:51:26 +00002965 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002966 i;
2967
2968 assert(fx_info != (FxInfo **) NULL);
cristyac245f82012-05-05 17:13:57 +00002969 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
cristy3ed852e2009-09-05 21:47:34 +00002970 if (fx_info[i] != (FxInfo *) NULL)
2971 fx_info[i]=DestroyFxInfo(fx_info[i]);
cristyb41ee102010-10-04 16:46:15 +00002972 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00002973 return(fx_info);
2974}
2975
2976static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2977 ExceptionInfo *exception)
2978{
2979 char
2980 *fx_expression;
2981
2982 FxInfo
2983 **fx_info;
2984
cristya19f1d72012-08-07 18:24:38 +00002985 double
cristy3ed852e2009-09-05 21:47:34 +00002986 alpha;
2987
cristybb503372010-05-27 20:51:26 +00002988 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002989 i;
2990
cristybb503372010-05-27 20:51:26 +00002991 size_t
cristy3ed852e2009-09-05 21:47:34 +00002992 number_threads;
2993
cristy9357bdd2012-07-30 12:28:34 +00002994 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
cristyb41ee102010-10-04 16:46:15 +00002995 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +00002996 if (fx_info == (FxInfo **) NULL)
cristy65d161b2012-10-07 20:39:52 +00002997 {
2998 (void) ThrowMagickException(exception,GetMagickModule(),
2999 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
3000 return((FxInfo **) NULL);
3001 }
cristy3ed852e2009-09-05 21:47:34 +00003002 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
3003 if (*expression != '@')
3004 fx_expression=ConstantString(expression);
3005 else
3006 fx_expression=FileToString(expression+1,~0,exception);
cristybb503372010-05-27 20:51:26 +00003007 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +00003008 {
cristy65d161b2012-10-07 20:39:52 +00003009 MagickBooleanType
3010 status;
3011
cristydb070952012-04-20 14:33:00 +00003012 fx_info[i]=AcquireFxInfo(image,fx_expression,exception);
cristy3ed852e2009-09-05 21:47:34 +00003013 if (fx_info[i] == (FxInfo *) NULL)
cristy65d161b2012-10-07 20:39:52 +00003014 break;
3015 status=FxPreprocessExpression(fx_info[i],&alpha,exception);
3016 if (status == MagickFalse)
3017 break;
cristy3ed852e2009-09-05 21:47:34 +00003018 }
3019 fx_expression=DestroyString(fx_expression);
cristy65d161b2012-10-07 20:39:52 +00003020 if (i < (ssize_t) number_threads)
3021 fx_info=DestroyFxThreadSet(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00003022 return(fx_info);
3023}
3024
3025MagickExport Image *FxImage(const Image *image,const char *expression,
3026 ExceptionInfo *exception)
3027{
cristy3ed852e2009-09-05 21:47:34 +00003028#define FxImageTag "Fx/Image"
3029
cristyfa112112010-01-04 17:48:07 +00003030 CacheView
cristy79cedc72011-07-25 00:41:15 +00003031 *fx_view,
3032 *image_view;
cristyfa112112010-01-04 17:48:07 +00003033
cristy3ed852e2009-09-05 21:47:34 +00003034 FxInfo
cristyfa112112010-01-04 17:48:07 +00003035 **restrict fx_info;
cristy3ed852e2009-09-05 21:47:34 +00003036
3037 Image
3038 *fx_image;
3039
cristy3ed852e2009-09-05 21:47:34 +00003040 MagickBooleanType
3041 status;
3042
cristybb503372010-05-27 20:51:26 +00003043 MagickOffsetType
3044 progress;
3045
cristybb503372010-05-27 20:51:26 +00003046 ssize_t
3047 y;
3048
cristy3ed852e2009-09-05 21:47:34 +00003049 assert(image != (Image *) NULL);
3050 assert(image->signature == MagickSignature);
3051 if (image->debug != MagickFalse)
3052 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00003053 fx_info=AcquireFxThreadSet(image,expression,exception);
3054 if (fx_info == (FxInfo **) NULL)
cristy65d161b2012-10-07 20:39:52 +00003055 return((Image *) NULL);
3056 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3057 if (fx_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003058 {
cristy3ed852e2009-09-05 21:47:34 +00003059 fx_info=DestroyFxThreadSet(fx_info);
3060 return((Image *) NULL);
3061 }
cristy65d161b2012-10-07 20:39:52 +00003062 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
3063 {
3064 fx_info=DestroyFxThreadSet(fx_info);
3065 fx_image=DestroyImage(fx_image);
3066 return((Image *) NULL);
3067 }
cristy3ed852e2009-09-05 21:47:34 +00003068 /*
3069 Fx image.
3070 */
3071 status=MagickTrue;
3072 progress=0;
cristy46ff2672012-12-14 15:32:26 +00003073 image_view=AcquireVirtualCacheView(image,exception);
3074 fx_view=AcquireAuthenticCacheView(fx_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003075#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003076 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00003077 magick_threads(image,fx_image,fx_image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003078#endif
cristybb503372010-05-27 20:51:26 +00003079 for (y=0; y < (ssize_t) fx_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003080 {
cristy5c9e6f22010-09-17 17:31:01 +00003081 const int
3082 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00003083
cristy79cedc72011-07-25 00:41:15 +00003084 register const Quantum
3085 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003086
cristy4c08aed2011-07-01 19:47:50 +00003087 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003088 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003089
cristy79cedc72011-07-25 00:41:15 +00003090 register ssize_t
3091 x;
3092
cristy3ed852e2009-09-05 21:47:34 +00003093 if (status == MagickFalse)
3094 continue;
cristy79cedc72011-07-25 00:41:15 +00003095 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +00003096 q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
cristy79cedc72011-07-25 00:41:15 +00003097 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003098 {
3099 status=MagickFalse;
3100 continue;
3101 }
cristybb503372010-05-27 20:51:26 +00003102 for (x=0; x < (ssize_t) fx_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003103 {
cristy79cedc72011-07-25 00:41:15 +00003104 register ssize_t
3105 i;
3106
3107 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3108 {
cristya19f1d72012-08-07 18:24:38 +00003109 double
cristy79cedc72011-07-25 00:41:15 +00003110 alpha;
3111
3112 PixelChannel
3113 channel;
3114
3115 PixelTrait
3116 fx_traits,
3117 traits;
3118
cristycf1296e2012-08-26 23:40:49 +00003119 channel=GetPixelChannelChannel(image,i);
3120 traits=GetPixelChannelTraits(image,channel);
3121 fx_traits=GetPixelChannelTraits(fx_image,channel);
cristy010d7d12011-08-31 01:02:48 +00003122 if ((traits == UndefinedPixelTrait) ||
3123 (fx_traits == UndefinedPixelTrait))
cristy79cedc72011-07-25 00:41:15 +00003124 continue;
cristy1eced092012-08-10 23:10:56 +00003125 if (((fx_traits & CopyPixelTrait) != 0) ||
3126 (GetPixelMask(image,p) != 0))
cristy79cedc72011-07-25 00:41:15 +00003127 {
cristy0beccfa2011-09-25 20:47:53 +00003128 SetPixelChannel(fx_image,channel,p[i],q);
cristy79cedc72011-07-25 00:41:15 +00003129 continue;
3130 }
3131 alpha=0.0;
cristya382aca2011-12-06 18:22:48 +00003132 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3133 exception);
cristy8cd03c32012-07-07 18:57:59 +00003134 q[i]=ClampToQuantum(QuantumRange*alpha);
cristy79cedc72011-07-25 00:41:15 +00003135 }
3136 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003137 q+=GetPixelChannels(fx_image);
cristy3ed852e2009-09-05 21:47:34 +00003138 }
3139 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3140 status=MagickFalse;
3141 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3142 {
3143 MagickBooleanType
3144 proceed;
3145
cristyb5d5f722009-11-04 03:03:49 +00003146#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003147 #pragma omp critical (MagickCore_FxImage)
cristy3ed852e2009-09-05 21:47:34 +00003148#endif
3149 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3150 if (proceed == MagickFalse)
3151 status=MagickFalse;
3152 }
3153 }
cristy3ed852e2009-09-05 21:47:34 +00003154 fx_view=DestroyCacheView(fx_view);
cristy79cedc72011-07-25 00:41:15 +00003155 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003156 fx_info=DestroyFxThreadSet(fx_info);
3157 if (status == MagickFalse)
3158 fx_image=DestroyImage(fx_image);
3159 return(fx_image);
3160}
3161
3162/*
3163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3164% %
3165% %
3166% %
3167% I m p l o d e I m a g e %
3168% %
3169% %
3170% %
3171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3172%
3173% ImplodeImage() creates a new image that is a copy of an existing
3174% one with the image pixels "implode" by the specified percentage. It
3175% allocates the memory necessary for the new Image structure and returns a
3176% pointer to the new image.
3177%
3178% The format of the ImplodeImage method is:
3179%
3180% Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003181% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003182%
3183% A description of each parameter follows:
3184%
3185% o implode_image: Method ImplodeImage returns a pointer to the image
3186% after it is implode. A null image is returned if there is a memory
3187% shortage.
3188%
3189% o image: the image.
3190%
3191% o amount: Define the extent of the implosion.
3192%
cristy76f512e2011-09-12 01:26:56 +00003193% o method: the pixel interpolation method.
3194%
cristy3ed852e2009-09-05 21:47:34 +00003195% o exception: return any errors or warnings in this structure.
3196%
3197*/
3198MagickExport Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003199 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003200{
3201#define ImplodeImageTag "Implode/Image"
3202
cristyfa112112010-01-04 17:48:07 +00003203 CacheView
3204 *image_view,
3205 *implode_view;
3206
cristy3ed852e2009-09-05 21:47:34 +00003207 Image
3208 *implode_image;
3209
cristy3ed852e2009-09-05 21:47:34 +00003210 MagickBooleanType
3211 status;
3212
cristybb503372010-05-27 20:51:26 +00003213 MagickOffsetType
3214 progress;
3215
cristya19f1d72012-08-07 18:24:38 +00003216 double
cristy3ed852e2009-09-05 21:47:34 +00003217 radius;
3218
3219 PointInfo
3220 center,
3221 scale;
3222
cristybb503372010-05-27 20:51:26 +00003223 ssize_t
3224 y;
3225
cristy3ed852e2009-09-05 21:47:34 +00003226 /*
3227 Initialize implode image attributes.
3228 */
3229 assert(image != (Image *) NULL);
3230 assert(image->signature == MagickSignature);
3231 if (image->debug != MagickFalse)
3232 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3233 assert(exception != (ExceptionInfo *) NULL);
3234 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00003235 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3236 exception);
cristy3ed852e2009-09-05 21:47:34 +00003237 if (implode_image == (Image *) NULL)
3238 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003239 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003240 {
cristy3ed852e2009-09-05 21:47:34 +00003241 implode_image=DestroyImage(implode_image);
3242 return((Image *) NULL);
3243 }
cristy4c08aed2011-07-01 19:47:50 +00003244 if (implode_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00003245 implode_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00003246 /*
3247 Compute scaling factor.
3248 */
3249 scale.x=1.0;
3250 scale.y=1.0;
3251 center.x=0.5*image->columns;
3252 center.y=0.5*image->rows;
3253 radius=center.x;
3254 if (image->columns > image->rows)
3255 scale.y=(double) image->columns/(double) image->rows;
3256 else
3257 if (image->columns < image->rows)
3258 {
3259 scale.x=(double) image->rows/(double) image->columns;
3260 radius=center.y;
3261 }
3262 /*
3263 Implode image.
3264 */
3265 status=MagickTrue;
3266 progress=0;
cristy46ff2672012-12-14 15:32:26 +00003267 image_view=AcquireVirtualCacheView(image,exception);
3268 implode_view=AcquireAuthenticCacheView(implode_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003269#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003270 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00003271 magick_threads(image,implode_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003272#endif
cristybb503372010-05-27 20:51:26 +00003273 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003274 {
cristya19f1d72012-08-07 18:24:38 +00003275 double
cristy3ed852e2009-09-05 21:47:34 +00003276 distance;
3277
3278 PointInfo
3279 delta;
3280
cristy6d188022011-09-12 13:23:33 +00003281 register const Quantum
3282 *restrict p;
3283
cristybb503372010-05-27 20:51:26 +00003284 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003285 x;
3286
cristy4c08aed2011-07-01 19:47:50 +00003287 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003288 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003289
3290 if (status == MagickFalse)
3291 continue;
cristy6d188022011-09-12 13:23:33 +00003292 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +00003293 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00003294 exception);
cristy6d188022011-09-12 13:23:33 +00003295 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003296 {
3297 status=MagickFalse;
3298 continue;
3299 }
cristy3ed852e2009-09-05 21:47:34 +00003300 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00003301 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003302 {
cristy6d188022011-09-12 13:23:33 +00003303 register ssize_t
3304 i;
3305
cristy3ed852e2009-09-05 21:47:34 +00003306 /*
3307 Determine if the pixel is within an ellipse.
3308 */
cristy10a6c612012-01-29 21:41:05 +00003309 if (GetPixelMask(image,p) != 0)
3310 {
3311 p+=GetPixelChannels(image);
3312 q+=GetPixelChannels(implode_image);
3313 continue;
3314 }
cristy3ed852e2009-09-05 21:47:34 +00003315 delta.x=scale.x*(double) (x-center.x);
3316 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00003317 if (distance >= (radius*radius))
cristya6d7a9b2012-01-18 20:04:48 +00003318 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristy6d188022011-09-12 13:23:33 +00003319 {
cristya6d7a9b2012-01-18 20:04:48 +00003320 PixelChannel
3321 channel;
3322
cristy1707c6c2012-01-18 23:30:54 +00003323 PixelTrait
3324 implode_traits,
3325 traits;
3326
cristycf1296e2012-08-26 23:40:49 +00003327 channel=GetPixelChannelChannel(image,i);
3328 traits=GetPixelChannelTraits(image,channel);
3329 implode_traits=GetPixelChannelTraits(implode_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00003330 if ((traits == UndefinedPixelTrait) ||
3331 (implode_traits == UndefinedPixelTrait))
3332 continue;
cristya6d7a9b2012-01-18 20:04:48 +00003333 SetPixelChannel(implode_image,channel,p[i],q);
cristy6d188022011-09-12 13:23:33 +00003334 }
3335 else
cristy3ed852e2009-09-05 21:47:34 +00003336 {
3337 double
3338 factor;
3339
3340 /*
3341 Implode the pixel.
3342 */
3343 factor=1.0;
3344 if (distance > 0.0)
cristy1707c6c2012-01-18 23:30:54 +00003345 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
3346 2)),-amount);
cristy76f512e2011-09-12 01:26:56 +00003347 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3348 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3349 scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00003350 }
cristy6d188022011-09-12 13:23:33 +00003351 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003352 q+=GetPixelChannels(implode_image);
cristy3ed852e2009-09-05 21:47:34 +00003353 }
3354 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3355 status=MagickFalse;
3356 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3357 {
3358 MagickBooleanType
3359 proceed;
3360
cristyb5d5f722009-11-04 03:03:49 +00003361#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003362 #pragma omp critical (MagickCore_ImplodeImage)
cristy3ed852e2009-09-05 21:47:34 +00003363#endif
3364 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3365 if (proceed == MagickFalse)
3366 status=MagickFalse;
3367 }
3368 }
3369 implode_view=DestroyCacheView(implode_view);
3370 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003371 if (status == MagickFalse)
3372 implode_image=DestroyImage(implode_image);
3373 return(implode_image);
3374}
3375
3376/*
3377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3378% %
3379% %
3380% %
3381% M o r p h I m a g e s %
3382% %
3383% %
3384% %
3385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3386%
3387% The MorphImages() method requires a minimum of two images. The first
3388% image is transformed into the second by a number of intervening images
3389% as specified by frames.
3390%
3391% The format of the MorphImage method is:
3392%
cristybb503372010-05-27 20:51:26 +00003393% Image *MorphImages(const Image *image,const size_t number_frames,
cristy3ed852e2009-09-05 21:47:34 +00003394% ExceptionInfo *exception)
3395%
3396% A description of each parameter follows:
3397%
3398% o image: the image.
3399%
3400% o number_frames: Define the number of in-between image to generate.
3401% The more in-between frames, the smoother the morph.
3402%
3403% o exception: return any errors or warnings in this structure.
3404%
3405*/
cristy7de7f742012-12-14 00:28:27 +00003406MagickExport Image *MorphImages(const Image *image,const size_t number_frames,
3407 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003408{
3409#define MorphImageTag "Morph/Image"
3410
cristyfab83642012-12-14 00:31:38 +00003411 double
3412 alpha,
3413 beta;
3414
cristy3ed852e2009-09-05 21:47:34 +00003415 Image
3416 *morph_image,
3417 *morph_images;
3418
cristy9d314ff2011-03-09 01:30:28 +00003419 MagickBooleanType
3420 status;
cristy3ed852e2009-09-05 21:47:34 +00003421
3422 MagickOffsetType
3423 scene;
3424
cristy3ed852e2009-09-05 21:47:34 +00003425 register const Image
3426 *next;
3427
cristybb503372010-05-27 20:51:26 +00003428 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003429 i;
3430
cristy9d314ff2011-03-09 01:30:28 +00003431 ssize_t
3432 y;
cristy3ed852e2009-09-05 21:47:34 +00003433
3434 /*
3435 Clone first frame in sequence.
3436 */
3437 assert(image != (Image *) NULL);
3438 assert(image->signature == MagickSignature);
3439 if (image->debug != MagickFalse)
3440 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3441 assert(exception != (ExceptionInfo *) NULL);
3442 assert(exception->signature == MagickSignature);
3443 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3444 if (morph_images == (Image *) NULL)
3445 return((Image *) NULL);
3446 if (GetNextImageInList(image) == (Image *) NULL)
3447 {
3448 /*
3449 Morph single image.
3450 */
cristybb503372010-05-27 20:51:26 +00003451 for (i=1; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003452 {
3453 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3454 if (morph_image == (Image *) NULL)
3455 {
3456 morph_images=DestroyImageList(morph_images);
3457 return((Image *) NULL);
3458 }
3459 AppendImageToList(&morph_images,morph_image);
cristy8b27a6d2010-02-14 03:31:15 +00003460 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003461 {
cristy8b27a6d2010-02-14 03:31:15 +00003462 MagickBooleanType
3463 proceed;
3464
cristybb503372010-05-27 20:51:26 +00003465 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3466 number_frames);
cristy8b27a6d2010-02-14 03:31:15 +00003467 if (proceed == MagickFalse)
3468 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003469 }
3470 }
3471 return(GetFirstImageInList(morph_images));
3472 }
3473 /*
3474 Morph image sequence.
3475 */
3476 status=MagickTrue;
3477 scene=0;
3478 next=image;
3479 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3480 {
cristybb503372010-05-27 20:51:26 +00003481 for (i=0; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003482 {
3483 CacheView
3484 *image_view,
3485 *morph_view;
3486
cristya19f1d72012-08-07 18:24:38 +00003487 beta=(double) (i+1.0)/(double) (number_frames+1.0);
cristy3ed852e2009-09-05 21:47:34 +00003488 alpha=1.0-beta;
cristy15b98cd2010-09-12 19:42:50 +00003489 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
cristyaa2c16c2012-03-25 22:21:35 +00003490 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta*
3491 GetNextImageInList(next)->rows+0.5),next->filter,exception);
cristy3ed852e2009-09-05 21:47:34 +00003492 if (morph_image == (Image *) NULL)
3493 {
3494 morph_images=DestroyImageList(morph_images);
3495 return((Image *) NULL);
3496 }
cristy1707c6c2012-01-18 23:30:54 +00003497 status=SetImageStorageClass(morph_image,DirectClass,exception);
3498 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003499 {
cristy3ed852e2009-09-05 21:47:34 +00003500 morph_image=DestroyImage(morph_image);
3501 return((Image *) NULL);
3502 }
3503 AppendImageToList(&morph_images,morph_image);
3504 morph_images=GetLastImageInList(morph_images);
cristy15b98cd2010-09-12 19:42:50 +00003505 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
cristyaa2c16c2012-03-25 22:21:35 +00003506 morph_images->rows,GetNextImageInList(next)->filter,exception);
cristy3ed852e2009-09-05 21:47:34 +00003507 if (morph_image == (Image *) NULL)
3508 {
3509 morph_images=DestroyImageList(morph_images);
3510 return((Image *) NULL);
3511 }
cristy46ff2672012-12-14 15:32:26 +00003512 image_view=AcquireVirtualCacheView(morph_image,exception);
3513 morph_view=AcquireAuthenticCacheView(morph_images,exception);
cristyb5d5f722009-11-04 03:03:49 +00003514#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003515 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00003516 magick_threads(morph_image,morph_image,morph_image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003517#endif
cristybb503372010-05-27 20:51:26 +00003518 for (y=0; y < (ssize_t) morph_images->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003519 {
3520 MagickBooleanType
3521 sync;
3522
cristy4c08aed2011-07-01 19:47:50 +00003523 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00003524 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003525
cristybb503372010-05-27 20:51:26 +00003526 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003527 x;
3528
cristy4c08aed2011-07-01 19:47:50 +00003529 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003530 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003531
3532 if (status == MagickFalse)
3533 continue;
3534 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3535 exception);
3536 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3537 exception);
cristy4c08aed2011-07-01 19:47:50 +00003538 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003539 {
3540 status=MagickFalse;
3541 continue;
3542 }
cristybb503372010-05-27 20:51:26 +00003543 for (x=0; x < (ssize_t) morph_images->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003544 {
cristy1707c6c2012-01-18 23:30:54 +00003545 register ssize_t
3546 i;
3547
cristy10a6c612012-01-29 21:41:05 +00003548 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
cristy1707c6c2012-01-18 23:30:54 +00003549 {
3550 PixelChannel
3551 channel;
3552
3553 PixelTrait
3554 morph_traits,
3555 traits;
3556
cristycf1296e2012-08-26 23:40:49 +00003557 channel=GetPixelChannelChannel(image,i);
3558 traits=GetPixelChannelTraits(image,channel);
3559 morph_traits=GetPixelChannelTraits(morph_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00003560 if ((traits == UndefinedPixelTrait) ||
3561 (morph_traits == UndefinedPixelTrait))
3562 continue;
cristy1eced092012-08-10 23:10:56 +00003563 if (((morph_traits & CopyPixelTrait) != 0) ||
3564 (GetPixelMask(image,p) != 0))
cristy1707c6c2012-01-18 23:30:54 +00003565 {
3566 SetPixelChannel(morph_image,channel,p[i],q);
3567 continue;
3568 }
3569 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*
3570 GetPixelChannel(morph_images,channel,q)+beta*p[i]),q);
3571 }
cristyed231572011-07-14 02:18:59 +00003572 p+=GetPixelChannels(morph_image);
3573 q+=GetPixelChannels(morph_images);
cristy3ed852e2009-09-05 21:47:34 +00003574 }
3575 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3576 if (sync == MagickFalse)
3577 status=MagickFalse;
3578 }
3579 morph_view=DestroyCacheView(morph_view);
3580 image_view=DestroyCacheView(image_view);
3581 morph_image=DestroyImage(morph_image);
3582 }
cristybb503372010-05-27 20:51:26 +00003583 if (i < (ssize_t) number_frames)
cristy3ed852e2009-09-05 21:47:34 +00003584 break;
3585 /*
3586 Clone last frame in sequence.
3587 */
3588 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3589 if (morph_image == (Image *) NULL)
3590 {
3591 morph_images=DestroyImageList(morph_images);
3592 return((Image *) NULL);
3593 }
3594 AppendImageToList(&morph_images,morph_image);
3595 morph_images=GetLastImageInList(morph_images);
3596 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3597 {
3598 MagickBooleanType
3599 proceed;
3600
cristyb5d5f722009-11-04 03:03:49 +00003601#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003602 #pragma omp critical (MagickCore_MorphImages)
cristy3ed852e2009-09-05 21:47:34 +00003603#endif
3604 proceed=SetImageProgress(image,MorphImageTag,scene,
3605 GetImageListLength(image));
3606 if (proceed == MagickFalse)
3607 status=MagickFalse;
3608 }
3609 scene++;
3610 }
3611 if (GetNextImageInList(next) != (Image *) NULL)
3612 {
3613 morph_images=DestroyImageList(morph_images);
3614 return((Image *) NULL);
3615 }
3616 return(GetFirstImageInList(morph_images));
3617}
3618
3619/*
3620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3621% %
3622% %
3623% %
3624% P l a s m a I m a g e %
3625% %
3626% %
3627% %
3628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3629%
3630% PlasmaImage() initializes an image with plasma fractal values. The image
3631% must be initialized with a base color and the random number generator
3632% seeded before this method is called.
3633%
3634% The format of the PlasmaImage method is:
3635%
3636% MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
cristy5cbc0162011-08-29 00:36:28 +00003637% size_t attenuate,size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003638%
3639% A description of each parameter follows:
3640%
3641% o image: the image.
3642%
3643% o segment: Define the region to apply plasma fractals values.
3644%
glennrp7dae1ca2010-09-16 12:17:35 +00003645% o attenuate: Define the plasma attenuation factor.
cristy3ed852e2009-09-05 21:47:34 +00003646%
3647% o depth: Limit the plasma recursion depth.
3648%
cristy5cbc0162011-08-29 00:36:28 +00003649% o exception: return any errors or warnings in this structure.
3650%
cristy3ed852e2009-09-05 21:47:34 +00003651*/
3652
3653static inline Quantum PlasmaPixel(RandomInfo *random_info,
cristya19f1d72012-08-07 18:24:38 +00003654 const double pixel,const double noise)
cristy3ed852e2009-09-05 21:47:34 +00003655{
3656 Quantum
3657 plasma;
3658
cristyce70c172010-01-07 17:15:30 +00003659 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
cristy3ed852e2009-09-05 21:47:34 +00003660 noise/2.0);
3661 return(plasma);
3662}
3663
cristyda1f9c12011-10-02 21:39:49 +00003664static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3665 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3666 const SegmentInfo *segment,size_t attenuate,size_t depth,
3667 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003668{
cristya19f1d72012-08-07 18:24:38 +00003669 double
cristy3ed852e2009-09-05 21:47:34 +00003670 plasma;
3671
cristyda1f9c12011-10-02 21:39:49 +00003672 PixelChannel
3673 channel;
3674
3675 PixelTrait
3676 traits;
3677
3678 register const Quantum
3679 *restrict u,
3680 *restrict v;
3681
3682 register Quantum
3683 *restrict q;
3684
3685 register ssize_t
3686 i;
cristy3ed852e2009-09-05 21:47:34 +00003687
cristy9d314ff2011-03-09 01:30:28 +00003688 ssize_t
3689 x,
3690 x_mid,
3691 y,
3692 y_mid;
3693
cristy3ed852e2009-09-05 21:47:34 +00003694 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3695 return(MagickTrue);
3696 if (depth != 0)
3697 {
3698 SegmentInfo
3699 local_info;
3700
3701 /*
3702 Divide the area into quadrants and recurse.
3703 */
3704 depth--;
3705 attenuate++;
cristybb503372010-05-27 20:51:26 +00003706 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3707 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003708 local_info=(*segment);
3709 local_info.x2=(double) x_mid;
3710 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003711 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3712 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003713 local_info=(*segment);
3714 local_info.y1=(double) y_mid;
3715 local_info.x2=(double) x_mid;
cristyda1f9c12011-10-02 21:39:49 +00003716 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3717 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003718 local_info=(*segment);
3719 local_info.x1=(double) x_mid;
3720 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003721 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3722 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003723 local_info=(*segment);
3724 local_info.x1=(double) x_mid;
3725 local_info.y1=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003726 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3727 &local_info,attenuate,depth,exception));
cristy3ed852e2009-09-05 21:47:34 +00003728 }
cristybb503372010-05-27 20:51:26 +00003729 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3730 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003731 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3732 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3733 return(MagickFalse);
3734 /*
3735 Average pixels and apply plasma.
3736 */
cristya19f1d72012-08-07 18:24:38 +00003737 plasma=(double) QuantumRange/(2.0*attenuate);
cristy3ed852e2009-09-05 21:47:34 +00003738 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3739 {
cristy3ed852e2009-09-05 21:47:34 +00003740 /*
3741 Left pixel.
3742 */
cristybb503372010-05-27 20:51:26 +00003743 x=(ssize_t) ceil(segment->x1-0.5);
cristy1707c6c2012-01-18 23:30:54 +00003744 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1,
3745 exception);
3746 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1,
3747 exception);
cristyc5c6f662010-09-22 14:23:02 +00003748 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003749 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3750 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003751 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003752 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3753 {
cristycf1296e2012-08-26 23:40:49 +00003754 channel=GetPixelChannelChannel(image,i);
3755 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003756 if (traits == UndefinedPixelTrait)
3757 continue;
3758 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3759 }
cristyc5c6f662010-09-22 14:23:02 +00003760 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003761 if (segment->x1 != segment->x2)
3762 {
3763 /*
3764 Right pixel.
3765 */
cristybb503372010-05-27 20:51:26 +00003766 x=(ssize_t) ceil(segment->x2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003767 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3768 1,1,exception);
3769 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3770 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003771 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003772 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3773 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003774 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003775 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3776 {
cristycf1296e2012-08-26 23:40:49 +00003777 channel=GetPixelChannelChannel(image,i);
3778 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003779 if (traits == UndefinedPixelTrait)
3780 continue;
3781 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3782 }
cristyc5c6f662010-09-22 14:23:02 +00003783 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003784 }
3785 }
3786 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3787 {
3788 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3789 {
cristy3ed852e2009-09-05 21:47:34 +00003790 /*
3791 Bottom pixel.
3792 */
cristybb503372010-05-27 20:51:26 +00003793 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003794 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3795 1,1,exception);
3796 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3797 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003798 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003799 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3800 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003801 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003802 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3803 {
cristycf1296e2012-08-26 23:40:49 +00003804 channel=GetPixelChannelChannel(image,i);
3805 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003806 if (traits == UndefinedPixelTrait)
3807 continue;
3808 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3809 }
cristyc5c6f662010-09-22 14:23:02 +00003810 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003811 }
3812 if (segment->y1 != segment->y2)
3813 {
cristy3ed852e2009-09-05 21:47:34 +00003814 /*
3815 Top pixel.
3816 */
cristybb503372010-05-27 20:51:26 +00003817 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003818 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3819 1,1,exception);
3820 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3821 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003822 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003823 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3824 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003825 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003826 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3827 {
cristycf1296e2012-08-26 23:40:49 +00003828 channel=GetPixelChannelChannel(image,i);
3829 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003830 if (traits == UndefinedPixelTrait)
3831 continue;
3832 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3833 }
cristyc5c6f662010-09-22 14:23:02 +00003834 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003835 }
3836 }
3837 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3838 {
cristy3ed852e2009-09-05 21:47:34 +00003839 /*
3840 Middle pixel.
3841 */
cristybb503372010-05-27 20:51:26 +00003842 x=(ssize_t) ceil(segment->x1-0.5);
3843 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003844 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
cristybb503372010-05-27 20:51:26 +00003845 x=(ssize_t) ceil(segment->x2-0.5);
3846 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003847 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003848 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003849 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3850 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003851 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003852 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3853 {
cristycf1296e2012-08-26 23:40:49 +00003854 channel=GetPixelChannelChannel(image,i);
3855 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003856 if (traits == UndefinedPixelTrait)
3857 continue;
3858 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3859 }
cristyc5c6f662010-09-22 14:23:02 +00003860 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003861 }
3862 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3863 return(MagickTrue);
3864 return(MagickFalse);
3865}
cristyda1f9c12011-10-02 21:39:49 +00003866
cristy3ed852e2009-09-05 21:47:34 +00003867MagickExport MagickBooleanType PlasmaImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00003868 const SegmentInfo *segment,size_t attenuate,size_t depth,
3869 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003870{
cristyc5c6f662010-09-22 14:23:02 +00003871 CacheView
cristyda1f9c12011-10-02 21:39:49 +00003872 *image_view,
3873 *u_view,
3874 *v_view;
cristyc5c6f662010-09-22 14:23:02 +00003875
cristy3ed852e2009-09-05 21:47:34 +00003876 MagickBooleanType
3877 status;
3878
3879 RandomInfo
3880 *random_info;
3881
3882 if (image->debug != MagickFalse)
3883 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3884 assert(image != (Image *) NULL);
3885 assert(image->signature == MagickSignature);
3886 if (image->debug != MagickFalse)
3887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy5cbc0162011-08-29 00:36:28 +00003888 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristyc5c6f662010-09-22 14:23:02 +00003889 return(MagickFalse);
cristy46ff2672012-12-14 15:32:26 +00003890 image_view=AcquireAuthenticCacheView(image,exception);
3891 u_view=AcquireVirtualCacheView(image,exception);
3892 v_view=AcquireVirtualCacheView(image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003893 random_info=AcquireRandomInfo();
cristyda1f9c12011-10-02 21:39:49 +00003894 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3895 attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003896 random_info=DestroyRandomInfo(random_info);
cristyda1f9c12011-10-02 21:39:49 +00003897 v_view=DestroyCacheView(v_view);
3898 u_view=DestroyCacheView(u_view);
cristyc5c6f662010-09-22 14:23:02 +00003899 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003900 return(status);
3901}
3902
3903/*
3904%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3905% %
3906% %
3907% %
3908% P o l a r o i d I m a g e %
3909% %
3910% %
3911% %
3912%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3913%
3914% PolaroidImage() simulates a Polaroid picture.
3915%
3916% The format of the AnnotateImage method is:
3917%
3918% Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristye9e3d382011-12-14 01:50:13 +00003919% const char *caption,const double angle,
3920% const PixelInterpolateMethod method,ExceptionInfo exception)
cristy3ed852e2009-09-05 21:47:34 +00003921%
3922% A description of each parameter follows:
3923%
3924% o image: the image.
3925%
3926% o draw_info: the draw info.
3927%
cristye9e3d382011-12-14 01:50:13 +00003928% o caption: the Polaroid caption.
3929%
cristycee97112010-05-28 00:44:52 +00003930% o angle: Apply the effect along this angle.
cristy3ed852e2009-09-05 21:47:34 +00003931%
cristy5c4e2582011-09-11 19:21:03 +00003932% o method: the pixel interpolation method.
3933%
cristy3ed852e2009-09-05 21:47:34 +00003934% o exception: return any errors or warnings in this structure.
3935%
3936*/
3937MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristye9e3d382011-12-14 01:50:13 +00003938 const char *caption,const double angle,const PixelInterpolateMethod method,
cristy5c4e2582011-09-11 19:21:03 +00003939 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003940{
cristy3ed852e2009-09-05 21:47:34 +00003941 Image
3942 *bend_image,
3943 *caption_image,
3944 *flop_image,
3945 *picture_image,
3946 *polaroid_image,
3947 *rotate_image,
3948 *trim_image;
3949
cristybb503372010-05-27 20:51:26 +00003950 size_t
cristy3ed852e2009-09-05 21:47:34 +00003951 height;
3952
cristy9d314ff2011-03-09 01:30:28 +00003953 ssize_t
3954 quantum;
3955
cristy3ed852e2009-09-05 21:47:34 +00003956 /*
3957 Simulate a Polaroid picture.
3958 */
3959 assert(image != (Image *) NULL);
3960 assert(image->signature == MagickSignature);
3961 if (image->debug != MagickFalse)
3962 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3963 assert(exception != (ExceptionInfo *) NULL);
3964 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00003965 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
cristy3ed852e2009-09-05 21:47:34 +00003966 image->rows)/25.0,10.0);
3967 height=image->rows+2*quantum;
3968 caption_image=(Image *) NULL;
cristye9e3d382011-12-14 01:50:13 +00003969 if (caption != (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003970 {
3971 char
cristye9e3d382011-12-14 01:50:13 +00003972 geometry[MaxTextExtent],
3973 *text;
cristy3ed852e2009-09-05 21:47:34 +00003974
3975 DrawInfo
3976 *annotate_info;
3977
cristy3ed852e2009-09-05 21:47:34 +00003978 MagickBooleanType
3979 status;
3980
cristy9d314ff2011-03-09 01:30:28 +00003981 ssize_t
3982 count;
3983
cristy3ed852e2009-09-05 21:47:34 +00003984 TypeMetric
3985 metrics;
3986
3987 /*
3988 Generate caption image.
3989 */
3990 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3991 if (caption_image == (Image *) NULL)
3992 return((Image *) NULL);
3993 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
cristye9e3d382011-12-14 01:50:13 +00003994 text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
3995 exception);
3996 (void) CloneString(&annotate_info->text,text);
cristy6b1d05e2010-09-22 19:17:27 +00003997 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
cristye9e3d382011-12-14 01:50:13 +00003998 &text,exception);
3999 status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)*
4000 (metrics.ascent-metrics.descent)+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00004001 if (status == MagickFalse)
4002 caption_image=DestroyImage(caption_image);
4003 else
4004 {
4005 caption_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004006 (void) SetImageBackgroundColor(caption_image,exception);
cristye9e3d382011-12-14 01:50:13 +00004007 (void) CloneString(&annotate_info->text,text);
cristyb51dff52011-05-19 16:55:47 +00004008 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
cristy3ed852e2009-09-05 21:47:34 +00004009 metrics.ascent);
4010 if (annotate_info->gravity == UndefinedGravity)
4011 (void) CloneString(&annotate_info->geometry,AcquireString(
4012 geometry));
cristy5cbc0162011-08-29 00:36:28 +00004013 (void) AnnotateImage(caption_image,annotate_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00004014 height+=caption_image->rows;
4015 }
4016 annotate_info=DestroyDrawInfo(annotate_info);
cristye9e3d382011-12-14 01:50:13 +00004017 text=DestroyString(text);
cristy3ed852e2009-09-05 21:47:34 +00004018 }
4019 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
4020 exception);
4021 if (picture_image == (Image *) NULL)
4022 {
4023 if (caption_image != (Image *) NULL)
4024 caption_image=DestroyImage(caption_image);
4025 return((Image *) NULL);
4026 }
4027 picture_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004028 (void) SetImageBackgroundColor(picture_image,exception);
cristy39172402012-03-30 13:04:39 +00004029 (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum,
cristyfeb3e962012-03-29 17:25:55 +00004030 quantum,exception);
cristy3ed852e2009-09-05 21:47:34 +00004031 if (caption_image != (Image *) NULL)
4032 {
cristyfeb3e962012-03-29 17:25:55 +00004033 (void) CompositeImage(picture_image,caption_image,OverCompositeOp,
cristy39172402012-03-30 13:04:39 +00004034 MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception);
cristy3ed852e2009-09-05 21:47:34 +00004035 caption_image=DestroyImage(caption_image);
4036 }
cristy9950d572011-10-01 18:22:35 +00004037 (void) QueryColorCompliance("none",AllCompliance,
4038 &picture_image->background_color,exception);
cristy63240882011-08-05 19:05:27 +00004039 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004040 rotate_image=RotateImage(picture_image,90.0,exception);
4041 picture_image=DestroyImage(picture_image);
4042 if (rotate_image == (Image *) NULL)
4043 return((Image *) NULL);
4044 picture_image=rotate_image;
4045 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
cristy5c4e2582011-09-11 19:21:03 +00004046 picture_image->columns,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00004047 picture_image=DestroyImage(picture_image);
4048 if (bend_image == (Image *) NULL)
4049 return((Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00004050 picture_image=bend_image;
4051 rotate_image=RotateImage(picture_image,-90.0,exception);
4052 picture_image=DestroyImage(picture_image);
4053 if (rotate_image == (Image *) NULL)
4054 return((Image *) NULL);
4055 picture_image=rotate_image;
4056 picture_image->background_color=image->background_color;
anthonyf46d4262012-03-26 03:30:34 +00004057 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
cristy3ed852e2009-09-05 21:47:34 +00004058 exception);
4059 if (polaroid_image == (Image *) NULL)
4060 {
4061 picture_image=DestroyImage(picture_image);
4062 return(picture_image);
4063 }
4064 flop_image=FlopImage(polaroid_image,exception);
4065 polaroid_image=DestroyImage(polaroid_image);
4066 if (flop_image == (Image *) NULL)
4067 {
4068 picture_image=DestroyImage(picture_image);
4069 return(picture_image);
4070 }
4071 polaroid_image=flop_image;
cristyfeb3e962012-03-29 17:25:55 +00004072 (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp,
cristy39172402012-03-30 13:04:39 +00004073 MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
cristy3ed852e2009-09-05 21:47:34 +00004074 picture_image=DestroyImage(picture_image);
cristy9950d572011-10-01 18:22:35 +00004075 (void) QueryColorCompliance("none",AllCompliance,
4076 &polaroid_image->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00004077 rotate_image=RotateImage(polaroid_image,angle,exception);
4078 polaroid_image=DestroyImage(polaroid_image);
4079 if (rotate_image == (Image *) NULL)
4080 return((Image *) NULL);
4081 polaroid_image=rotate_image;
4082 trim_image=TrimImage(polaroid_image,exception);
4083 polaroid_image=DestroyImage(polaroid_image);
4084 if (trim_image == (Image *) NULL)
4085 return((Image *) NULL);
4086 polaroid_image=trim_image;
4087 return(polaroid_image);
4088}
4089
4090/*
4091%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4092% %
4093% %
4094% %
cristy3ed852e2009-09-05 21:47:34 +00004095% S e p i a T o n e I m a g e %
4096% %
4097% %
4098% %
4099%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4100%
4101% MagickSepiaToneImage() applies a special effect to the image, similar to the
4102% effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4103% 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4104% threshold of 80% is a good starting point for a reasonable tone.
4105%
4106% The format of the SepiaToneImage method is:
4107%
4108% Image *SepiaToneImage(const Image *image,const double threshold,
4109% ExceptionInfo *exception)
4110%
4111% A description of each parameter follows:
4112%
4113% o image: the image.
4114%
4115% o threshold: the tone threshold.
4116%
4117% o exception: return any errors or warnings in this structure.
4118%
4119*/
4120MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4121 ExceptionInfo *exception)
4122{
4123#define SepiaToneImageTag "SepiaTone/Image"
4124
cristyc4c8d132010-01-07 01:58:38 +00004125 CacheView
4126 *image_view,
4127 *sepia_view;
4128
cristy3ed852e2009-09-05 21:47:34 +00004129 Image
4130 *sepia_image;
4131
cristy3ed852e2009-09-05 21:47:34 +00004132 MagickBooleanType
4133 status;
4134
cristybb503372010-05-27 20:51:26 +00004135 MagickOffsetType
4136 progress;
4137
4138 ssize_t
4139 y;
4140
cristy3ed852e2009-09-05 21:47:34 +00004141 /*
4142 Initialize sepia-toned image attributes.
4143 */
4144 assert(image != (const Image *) NULL);
4145 assert(image->signature == MagickSignature);
4146 if (image->debug != MagickFalse)
4147 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4148 assert(exception != (ExceptionInfo *) NULL);
4149 assert(exception->signature == MagickSignature);
cristy1707c6c2012-01-18 23:30:54 +00004150 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004151 if (sepia_image == (Image *) NULL)
4152 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004153 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004154 {
cristy3ed852e2009-09-05 21:47:34 +00004155 sepia_image=DestroyImage(sepia_image);
4156 return((Image *) NULL);
4157 }
4158 /*
4159 Tone each row of the image.
4160 */
4161 status=MagickTrue;
4162 progress=0;
cristy46ff2672012-12-14 15:32:26 +00004163 image_view=AcquireVirtualCacheView(image,exception);
4164 sepia_view=AcquireAuthenticCacheView(sepia_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00004165#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00004166 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00004167 magick_threads(image,sepia_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00004168#endif
cristybb503372010-05-27 20:51:26 +00004169 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004170 {
cristy4c08aed2011-07-01 19:47:50 +00004171 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004172 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00004173
cristybb503372010-05-27 20:51:26 +00004174 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004175 x;
4176
cristy4c08aed2011-07-01 19:47:50 +00004177 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004178 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004179
4180 if (status == MagickFalse)
4181 continue;
4182 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy1707c6c2012-01-18 23:30:54 +00004183 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00004184 exception);
cristy4c08aed2011-07-01 19:47:50 +00004185 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004186 {
4187 status=MagickFalse;
4188 continue;
4189 }
cristybb503372010-05-27 20:51:26 +00004190 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004191 {
cristya19f1d72012-08-07 18:24:38 +00004192 double
cristy3ed852e2009-09-05 21:47:34 +00004193 intensity,
4194 tone;
4195
cristyf13c5942012-08-08 23:50:11 +00004196 intensity=GetPixelIntensity(image,p);
cristya19f1d72012-08-07 18:24:38 +00004197 tone=intensity > threshold ? (double) QuantumRange : intensity+
4198 (double) QuantumRange-threshold;
cristy4c08aed2011-07-01 19:47:50 +00004199 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
cristya19f1d72012-08-07 18:24:38 +00004200 tone=intensity > (7.0*threshold/6.0) ? (double) QuantumRange :
4201 intensity+(double) QuantumRange-7.0*threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004202 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004203 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004204 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004205 tone=threshold/7.0;
cristya19f1d72012-08-07 18:24:38 +00004206 if ((double) GetPixelGreen(image,q) < tone)
cristy4c08aed2011-07-01 19:47:50 +00004207 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristya19f1d72012-08-07 18:24:38 +00004208 if ((double) GetPixelBlue(image,q) < tone)
cristy4c08aed2011-07-01 19:47:50 +00004209 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristyed231572011-07-14 02:18:59 +00004210 p+=GetPixelChannels(image);
4211 q+=GetPixelChannels(sepia_image);
cristy3ed852e2009-09-05 21:47:34 +00004212 }
4213 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4214 status=MagickFalse;
4215 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4216 {
4217 MagickBooleanType
4218 proceed;
4219
cristyb5d5f722009-11-04 03:03:49 +00004220#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00004221 #pragma omp critical (MagickCore_SepiaToneImage)
cristy3ed852e2009-09-05 21:47:34 +00004222#endif
4223 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4224 image->rows);
4225 if (proceed == MagickFalse)
4226 status=MagickFalse;
4227 }
4228 }
4229 sepia_view=DestroyCacheView(sepia_view);
4230 image_view=DestroyCacheView(image_view);
cristye23ec9d2011-08-16 18:15:40 +00004231 (void) NormalizeImage(sepia_image,exception);
4232 (void) ContrastImage(sepia_image,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004233 if (status == MagickFalse)
4234 sepia_image=DestroyImage(sepia_image);
4235 return(sepia_image);
4236}
4237
4238/*
4239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4240% %
4241% %
4242% %
4243% S h a d o w I m a g e %
4244% %
4245% %
4246% %
4247%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4248%
4249% ShadowImage() simulates a shadow from the specified image and returns it.
4250%
4251% The format of the ShadowImage method is:
4252%
cristy70cddf72011-12-10 22:42:42 +00004253% Image *ShadowImage(const Image *image,const double alpha,
cristyaa2c16c2012-03-25 22:21:35 +00004254% const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4255% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004256%
4257% A description of each parameter follows:
4258%
4259% o image: the image.
4260%
cristy70cddf72011-12-10 22:42:42 +00004261% o alpha: percentage transparency.
cristy3ed852e2009-09-05 21:47:34 +00004262%
4263% o sigma: the standard deviation of the Gaussian, in pixels.
4264%
4265% o x_offset: the shadow x-offset.
4266%
4267% o y_offset: the shadow y-offset.
4268%
4269% o exception: return any errors or warnings in this structure.
4270%
4271*/
cristy70cddf72011-12-10 22:42:42 +00004272MagickExport Image *ShadowImage(const Image *image,const double alpha,
cristyaa2c16c2012-03-25 22:21:35 +00004273 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4274 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004275{
4276#define ShadowImageTag "Shadow/Image"
4277
cristy70cddf72011-12-10 22:42:42 +00004278 CacheView
4279 *image_view;
4280
cristybd5a96c2011-08-21 00:04:26 +00004281 ChannelType
4282 channel_mask;
4283
cristy3ed852e2009-09-05 21:47:34 +00004284 Image
4285 *border_image,
4286 *clone_image,
4287 *shadow_image;
4288
cristy70cddf72011-12-10 22:42:42 +00004289 MagickBooleanType
4290 status;
4291
cristy3ed852e2009-09-05 21:47:34 +00004292 RectangleInfo
4293 border_info;
4294
cristy70cddf72011-12-10 22:42:42 +00004295 ssize_t
4296 y;
4297
cristy3ed852e2009-09-05 21:47:34 +00004298 assert(image != (Image *) NULL);
4299 assert(image->signature == MagickSignature);
4300 if (image->debug != MagickFalse)
4301 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4302 assert(exception != (ExceptionInfo *) NULL);
4303 assert(exception->signature == MagickSignature);
4304 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4305 if (clone_image == (Image *) NULL)
4306 return((Image *) NULL);
cristy0898eba2012-04-09 16:38:29 +00004307 if (IsGrayColorspace(image->colorspace) != MagickFalse)
cristyb09db112012-07-11 12:04:31 +00004308 (void) TransformImageColorspace(clone_image,RGBColorspace,exception);
cristy0ce08762012-06-30 01:33:18 +00004309 (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod,
cristy387430f2012-02-07 13:09:46 +00004310 exception);
cristybb503372010-05-27 20:51:26 +00004311 border_info.width=(size_t) floor(2.0*sigma+0.5);
4312 border_info.height=(size_t) floor(2.0*sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00004313 border_info.x=0;
4314 border_info.y=0;
cristy9950d572011-10-01 18:22:35 +00004315 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4316 exception);
cristy8a46d822012-08-28 23:32:39 +00004317 clone_image->alpha_trait=BlendPixelTrait;
cristy70cddf72011-12-10 22:42:42 +00004318 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
cristy3ed852e2009-09-05 21:47:34 +00004319 clone_image=DestroyImage(clone_image);
4320 if (border_image == (Image *) NULL)
4321 return((Image *) NULL);
cristy8a46d822012-08-28 23:32:39 +00004322 if (border_image->alpha_trait != BlendPixelTrait)
cristy63240882011-08-05 19:05:27 +00004323 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004324 /*
4325 Shadow image.
4326 */
cristy70cddf72011-12-10 22:42:42 +00004327 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00004328 image_view=AcquireAuthenticCacheView(border_image,exception);
cristy70cddf72011-12-10 22:42:42 +00004329 for (y=0; y < (ssize_t) border_image->rows; y++)
4330 {
4331 PixelInfo
4332 background_color;
4333
4334 register Quantum
4335 *restrict q;
4336
4337 register ssize_t
4338 x;
4339
4340 if (status == MagickFalse)
4341 continue;
4342 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4343 exception);
4344 if (q == (Quantum *) NULL)
4345 {
4346 status=MagickFalse;
4347 continue;
4348 }
4349 background_color=border_image->background_color;
cristy8a46d822012-08-28 23:32:39 +00004350 background_color.alpha_trait=BlendPixelTrait;
cristy70cddf72011-12-10 22:42:42 +00004351 for (x=0; x < (ssize_t) border_image->columns; x++)
4352 {
cristy8a46d822012-08-28 23:32:39 +00004353 if (border_image->alpha_trait == BlendPixelTrait)
cristy70cddf72011-12-10 22:42:42 +00004354 background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
4355 SetPixelInfoPixel(border_image,&background_color,q);
4356 q+=GetPixelChannels(border_image);
4357 }
4358 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4359 status=MagickFalse;
4360 }
4361 image_view=DestroyCacheView(image_view);
4362 if (status == MagickFalse)
4363 {
4364 border_image=DestroyImage(border_image);
4365 return((Image *) NULL);
4366 }
cristycf1296e2012-08-26 23:40:49 +00004367 channel_mask=SetImageChannelMask(border_image,AlphaChannel);
cristyaa2c16c2012-03-25 22:21:35 +00004368 shadow_image=BlurImage(border_image,0.0,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00004369 border_image=DestroyImage(border_image);
4370 if (shadow_image == (Image *) NULL)
4371 return((Image *) NULL);
cristycf1296e2012-08-26 23:40:49 +00004372 (void) SetPixelChannelMask(shadow_image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00004373 if (shadow_image->page.width == 0)
4374 shadow_image->page.width=shadow_image->columns;
4375 if (shadow_image->page.height == 0)
4376 shadow_image->page.height=shadow_image->rows;
cristybb503372010-05-27 20:51:26 +00004377 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4378 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4379 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4380 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
cristy3ed852e2009-09-05 21:47:34 +00004381 return(shadow_image);
4382}
4383
4384/*
4385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4386% %
4387% %
4388% %
4389% S k e t c h I m a g e %
4390% %
4391% %
4392% %
4393%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4394%
4395% SketchImage() simulates a pencil sketch. We convolve the image with a
4396% Gaussian operator of the given radius and standard deviation (sigma). For
4397% reasonable results, radius should be larger than sigma. Use a radius of 0
4398% and SketchImage() selects a suitable radius for you. Angle gives the angle
4399% of the sketch.
4400%
4401% The format of the SketchImage method is:
4402%
4403% Image *SketchImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00004404% const double sigma,const double angle,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004405%
4406% A description of each parameter follows:
4407%
4408% o image: the image.
4409%
cristy574cc262011-08-05 01:23:58 +00004410% o radius: the radius of the Gaussian, in pixels, not counting the
4411% center pixel.
cristy3ed852e2009-09-05 21:47:34 +00004412%
4413% o sigma: the standard deviation of the Gaussian, in pixels.
4414%
cristyf7ef0252011-09-09 14:50:06 +00004415% o angle: apply the effect along this angle.
4416%
cristy3ed852e2009-09-05 21:47:34 +00004417% o exception: return any errors or warnings in this structure.
4418%
4419*/
4420MagickExport Image *SketchImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00004421 const double sigma,const double angle,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004422{
cristyfa112112010-01-04 17:48:07 +00004423 CacheView
4424 *random_view;
4425
cristy3ed852e2009-09-05 21:47:34 +00004426 Image
4427 *blend_image,
4428 *blur_image,
4429 *dodge_image,
4430 *random_image,
4431 *sketch_image;
4432
cristy3ed852e2009-09-05 21:47:34 +00004433 MagickBooleanType
4434 status;
4435
cristy3ed852e2009-09-05 21:47:34 +00004436 RandomInfo
cristyfa112112010-01-04 17:48:07 +00004437 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +00004438
cristy9d314ff2011-03-09 01:30:28 +00004439 ssize_t
4440 y;
4441
glennrpf7659d72012-09-24 18:14:56 +00004442#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004443 unsigned long
4444 key;
glennrpf7659d72012-09-24 18:14:56 +00004445#endif
cristy57340e02012-05-05 00:53:23 +00004446
cristy3ed852e2009-09-05 21:47:34 +00004447 /*
4448 Sketch image.
4449 */
4450 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4451 MagickTrue,exception);
4452 if (random_image == (Image *) NULL)
4453 return((Image *) NULL);
4454 status=MagickTrue;
cristy1b784432009-12-19 02:20:40 +00004455 random_info=AcquireRandomInfoThreadSet();
glennrpf7659d72012-09-24 18:14:56 +00004456#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004457 key=GetRandomSecretKey(random_info[0]);
glennrpf7659d72012-09-24 18:14:56 +00004458#endif
cristy46ff2672012-12-14 15:32:26 +00004459 random_view=AcquireAuthenticCacheView(random_image,exception);
cristy1b784432009-12-19 02:20:40 +00004460#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004461 #pragma omp parallel for schedule(static,4) shared(status) \
cristy5e6b2592012-12-19 14:08:11 +00004462 magick_threads(random_image,random_image,random_image->rows,key == ~0UL)
cristy1b784432009-12-19 02:20:40 +00004463#endif
cristybb503372010-05-27 20:51:26 +00004464 for (y=0; y < (ssize_t) random_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004465 {
cristy5c9e6f22010-09-17 17:31:01 +00004466 const int
4467 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00004468
cristybb503372010-05-27 20:51:26 +00004469 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004470 x;
4471
cristy4c08aed2011-07-01 19:47:50 +00004472 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004473 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004474
cristy1b784432009-12-19 02:20:40 +00004475 if (status == MagickFalse)
4476 continue;
cristy3ed852e2009-09-05 21:47:34 +00004477 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4478 exception);
cristyacd2ed22011-08-30 01:44:23 +00004479 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004480 {
4481 status=MagickFalse;
4482 continue;
4483 }
cristybb503372010-05-27 20:51:26 +00004484 for (x=0; x < (ssize_t) random_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004485 {
cristya19f1d72012-08-07 18:24:38 +00004486 double
cristy76f512e2011-09-12 01:26:56 +00004487 value;
4488
4489 register ssize_t
4490 i;
4491
cristy10a6c612012-01-29 21:41:05 +00004492 if (GetPixelMask(random_image,q) != 0)
4493 {
4494 q+=GetPixelChannels(random_image);
4495 continue;
4496 }
cristy76f512e2011-09-12 01:26:56 +00004497 value=GetPseudoRandomValue(random_info[id]);
4498 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4499 {
cristyabace412011-12-11 15:56:53 +00004500 PixelChannel
4501 channel;
4502
cristy76f512e2011-09-12 01:26:56 +00004503 PixelTrait
4504 traits;
4505
cristycf1296e2012-08-26 23:40:49 +00004506 channel=GetPixelChannelChannel(image,i);
4507 traits=GetPixelChannelTraits(image,channel);
cristy76f512e2011-09-12 01:26:56 +00004508 if (traits == UndefinedPixelTrait)
4509 continue;
4510 q[i]=ClampToQuantum(QuantumRange*value);
4511 }
cristyed231572011-07-14 02:18:59 +00004512 q+=GetPixelChannels(random_image);
cristy3ed852e2009-09-05 21:47:34 +00004513 }
4514 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4515 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004516 }
4517 random_view=DestroyCacheView(random_view);
cristy1b784432009-12-19 02:20:40 +00004518 random_info=DestroyRandomInfoThreadSet(random_info);
cristy3ed852e2009-09-05 21:47:34 +00004519 if (status == MagickFalse)
4520 {
4521 random_image=DestroyImage(random_image);
4522 return(random_image);
4523 }
cristyaa2c16c2012-03-25 22:21:35 +00004524 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00004525 random_image=DestroyImage(random_image);
4526 if (blur_image == (Image *) NULL)
4527 return((Image *) NULL);
cristy6bfd6902011-12-09 01:33:45 +00004528 dodge_image=EdgeImage(blur_image,radius,1.0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004529 blur_image=DestroyImage(blur_image);
4530 if (dodge_image == (Image *) NULL)
4531 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +00004532 (void) NormalizeImage(dodge_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +00004533 (void) NegateImage(dodge_image,MagickFalse,exception);
cristye941a752011-10-15 01:52:48 +00004534 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
cristy3ed852e2009-09-05 21:47:34 +00004535 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4536 if (sketch_image == (Image *) NULL)
4537 {
4538 dodge_image=DestroyImage(dodge_image);
4539 return((Image *) NULL);
4540 }
cristyfeb3e962012-03-29 17:25:55 +00004541 (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp,
cristy39172402012-03-30 13:04:39 +00004542 MagickTrue,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004543 dodge_image=DestroyImage(dodge_image);
4544 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4545 if (blend_image == (Image *) NULL)
4546 {
4547 sketch_image=DestroyImage(sketch_image);
4548 return((Image *) NULL);
4549 }
4550 (void) SetImageArtifact(blend_image,"compose:args","20x80");
cristy39172402012-03-30 13:04:39 +00004551 (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue,
cristyfeb3e962012-03-29 17:25:55 +00004552 0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004553 blend_image=DestroyImage(blend_image);
4554 return(sketch_image);
4555}
4556
4557/*
4558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4559% %
4560% %
4561% %
4562% S o l a r i z e I m a g e %
4563% %
4564% %
4565% %
4566%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4567%
4568% SolarizeImage() applies a special effect to the image, similar to the effect
4569% achieved in a photo darkroom by selectively exposing areas of photo
4570% sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4571% measure of the extent of the solarization.
4572%
4573% The format of the SolarizeImage method is:
4574%
cristy5cbc0162011-08-29 00:36:28 +00004575% MagickBooleanType SolarizeImage(Image *image,const double threshold,
4576% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004577%
4578% A description of each parameter follows:
4579%
4580% o image: the image.
4581%
4582% o threshold: Define the extent of the solarization.
4583%
cristy5cbc0162011-08-29 00:36:28 +00004584% o exception: return any errors or warnings in this structure.
4585%
cristy3ed852e2009-09-05 21:47:34 +00004586*/
4587MagickExport MagickBooleanType SolarizeImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00004588 const double threshold,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004589{
4590#define SolarizeImageTag "Solarize/Image"
4591
cristyc4c8d132010-01-07 01:58:38 +00004592 CacheView
4593 *image_view;
4594
cristy3ed852e2009-09-05 21:47:34 +00004595 MagickBooleanType
4596 status;
4597
cristybb503372010-05-27 20:51:26 +00004598 MagickOffsetType
4599 progress;
4600
4601 ssize_t
4602 y;
4603
cristy3ed852e2009-09-05 21:47:34 +00004604 assert(image != (Image *) NULL);
4605 assert(image->signature == MagickSignature);
4606 if (image->debug != MagickFalse)
4607 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4608 if (image->storage_class == PseudoClass)
4609 {
cristybb503372010-05-27 20:51:26 +00004610 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004611 i;
4612
4613 /*
4614 Solarize colormap.
4615 */
cristybb503372010-05-27 20:51:26 +00004616 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00004617 {
cristya19f1d72012-08-07 18:24:38 +00004618 if ((double) image->colormap[i].red > threshold)
cristy6e963d82012-06-19 15:23:24 +00004619 image->colormap[i].red=QuantumRange-image->colormap[i].red;
cristya19f1d72012-08-07 18:24:38 +00004620 if ((double) image->colormap[i].green > threshold)
cristy6e963d82012-06-19 15:23:24 +00004621 image->colormap[i].green=QuantumRange-
cristy3ed852e2009-09-05 21:47:34 +00004622 image->colormap[i].green;
cristya19f1d72012-08-07 18:24:38 +00004623 if ((double) image->colormap[i].blue > threshold)
cristy6e963d82012-06-19 15:23:24 +00004624 image->colormap[i].blue=QuantumRange-
cristy3ed852e2009-09-05 21:47:34 +00004625 image->colormap[i].blue;
4626 }
4627 }
4628 /*
4629 Solarize image.
4630 */
4631 status=MagickTrue;
4632 progress=0;
cristy46ff2672012-12-14 15:32:26 +00004633 image_view=AcquireAuthenticCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00004634#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00004635 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00004636 magick_threads(image,image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00004637#endif
cristybb503372010-05-27 20:51:26 +00004638 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004639 {
cristybb503372010-05-27 20:51:26 +00004640 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004641 x;
4642
cristy4c08aed2011-07-01 19:47:50 +00004643 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004644 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004645
4646 if (status == MagickFalse)
4647 continue;
cristy5cbc0162011-08-29 00:36:28 +00004648 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004649 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004650 {
4651 status=MagickFalse;
4652 continue;
4653 }
cristybb503372010-05-27 20:51:26 +00004654 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004655 {
cristy76f512e2011-09-12 01:26:56 +00004656 register ssize_t
4657 i;
4658
cristy10a6c612012-01-29 21:41:05 +00004659 if (GetPixelMask(image,q) != 0)
4660 {
4661 q+=GetPixelChannels(image);
4662 continue;
4663 }
cristy76f512e2011-09-12 01:26:56 +00004664 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4665 {
cristyabace412011-12-11 15:56:53 +00004666 PixelChannel
4667 channel;
4668
cristy76f512e2011-09-12 01:26:56 +00004669 PixelTrait
4670 traits;
4671
cristycf1296e2012-08-26 23:40:49 +00004672 channel=GetPixelChannelChannel(image,i);
4673 traits=GetPixelChannelTraits(image,channel);
cristy76f512e2011-09-12 01:26:56 +00004674 if ((traits == UndefinedPixelTrait) ||
4675 ((traits & CopyPixelTrait) != 0))
4676 continue;
cristya19f1d72012-08-07 18:24:38 +00004677 if ((double) q[i] > threshold)
cristy76f512e2011-09-12 01:26:56 +00004678 q[i]=QuantumRange-q[i];
4679 }
cristyed231572011-07-14 02:18:59 +00004680 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004681 }
4682 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4683 status=MagickFalse;
4684 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4685 {
4686 MagickBooleanType
4687 proceed;
4688
cristyb5d5f722009-11-04 03:03:49 +00004689#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00004690 #pragma omp critical (MagickCore_SolarizeImage)
cristy3ed852e2009-09-05 21:47:34 +00004691#endif
4692 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4693 if (proceed == MagickFalse)
4694 status=MagickFalse;
4695 }
4696 }
4697 image_view=DestroyCacheView(image_view);
4698 return(status);
4699}
4700
4701/*
4702%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4703% %
4704% %
4705% %
4706% S t e g a n o I m a g e %
4707% %
4708% %
4709% %
4710%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4711%
4712% SteganoImage() hides a digital watermark within the image. Recover
4713% the hidden watermark later to prove that the authenticity of an image.
4714% Offset defines the start position within the image to hide the watermark.
4715%
4716% The format of the SteganoImage method is:
4717%
4718% Image *SteganoImage(const Image *image,Image *watermark,
4719% ExceptionInfo *exception)
4720%
4721% A description of each parameter follows:
4722%
4723% o image: the image.
4724%
4725% o watermark: the watermark image.
4726%
4727% o exception: return any errors or warnings in this structure.
4728%
4729*/
4730MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4731 ExceptionInfo *exception)
4732{
cristye1bf8ad2010-09-19 17:07:03 +00004733#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
cristy4c08aed2011-07-01 19:47:50 +00004734#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
cristyeaedf062010-05-29 22:36:02 +00004735 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
cristy3ed852e2009-09-05 21:47:34 +00004736#define SteganoImageTag "Stegano/Image"
4737
cristyb0d3bb92010-09-22 14:37:58 +00004738 CacheView
4739 *stegano_view,
4740 *watermark_view;
4741
cristy3ed852e2009-09-05 21:47:34 +00004742 Image
4743 *stegano_image;
4744
4745 int
4746 c;
4747
cristy3ed852e2009-09-05 21:47:34 +00004748 MagickBooleanType
4749 status;
4750
cristy101ab702011-10-13 13:06:32 +00004751 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00004752 pixel;
4753
cristy4c08aed2011-07-01 19:47:50 +00004754 register Quantum
cristy3ed852e2009-09-05 21:47:34 +00004755 *q;
4756
cristye1bf8ad2010-09-19 17:07:03 +00004757 register ssize_t
4758 x;
4759
cristybb503372010-05-27 20:51:26 +00004760 size_t
cristyeaedf062010-05-29 22:36:02 +00004761 depth,
4762 one;
cristy3ed852e2009-09-05 21:47:34 +00004763
cristye1bf8ad2010-09-19 17:07:03 +00004764 ssize_t
4765 i,
4766 j,
4767 k,
4768 y;
4769
cristy3ed852e2009-09-05 21:47:34 +00004770 /*
4771 Initialize steganographic image attributes.
4772 */
4773 assert(image != (const Image *) NULL);
4774 assert(image->signature == MagickSignature);
4775 if (image->debug != MagickFalse)
4776 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4777 assert(watermark != (const Image *) NULL);
4778 assert(watermark->signature == MagickSignature);
4779 assert(exception != (ExceptionInfo *) NULL);
4780 assert(exception->signature == MagickSignature);
cristyeaedf062010-05-29 22:36:02 +00004781 one=1UL;
cristy3ed852e2009-09-05 21:47:34 +00004782 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4783 if (stegano_image == (Image *) NULL)
4784 return((Image *) NULL);
cristyf61b1832012-04-01 01:38:19 +00004785 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
cristy574cc262011-08-05 01:23:58 +00004786 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004787 {
cristy3ed852e2009-09-05 21:47:34 +00004788 stegano_image=DestroyImage(stegano_image);
4789 return((Image *) NULL);
4790 }
cristy3ed852e2009-09-05 21:47:34 +00004791 /*
4792 Hide watermark in low-order bits of image.
4793 */
4794 c=0;
4795 i=0;
4796 j=0;
4797 depth=stegano_image->depth;
cristyf61b1832012-04-01 01:38:19 +00004798 k=stegano_image->offset;
cristyda16f162011-02-19 23:52:17 +00004799 status=MagickTrue;
cristy46ff2672012-12-14 15:32:26 +00004800 watermark_view=AcquireVirtualCacheView(watermark,exception);
4801 stegano_view=AcquireAuthenticCacheView(stegano_image,exception);
cristybb503372010-05-27 20:51:26 +00004802 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
cristy3ed852e2009-09-05 21:47:34 +00004803 {
cristybb503372010-05-27 20:51:26 +00004804 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
cristy3ed852e2009-09-05 21:47:34 +00004805 {
cristybb503372010-05-27 20:51:26 +00004806 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
cristy3ed852e2009-09-05 21:47:34 +00004807 {
cristy1707c6c2012-01-18 23:30:54 +00004808 ssize_t
4809 offset;
4810
cristyf05d4942012-03-17 16:26:09 +00004811 (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel,
cristyda1f9c12011-10-02 21:39:49 +00004812 exception);
cristy1707c6c2012-01-18 23:30:54 +00004813 offset=k/(ssize_t) stegano_image->columns;
4814 if (offset >= (ssize_t) stegano_image->rows)
cristy3ed852e2009-09-05 21:47:34 +00004815 break;
cristyb0d3bb92010-09-22 14:37:58 +00004816 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4817 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4818 exception);
cristyacd2ed22011-08-30 01:44:23 +00004819 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004820 break;
4821 switch (c)
4822 {
4823 case 0:
4824 {
cristyf61b1832012-04-01 01:38:19 +00004825 SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j,
4826 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004827 break;
4828 }
4829 case 1:
4830 {
cristyf61b1832012-04-01 01:38:19 +00004831 SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j,
4832 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004833 break;
4834 }
4835 case 2:
4836 {
cristyf61b1832012-04-01 01:38:19 +00004837 SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j,
4838 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004839 break;
4840 }
4841 }
cristyb0d3bb92010-09-22 14:37:58 +00004842 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004843 break;
4844 c++;
4845 if (c == 3)
4846 c=0;
4847 k++;
cristybb503372010-05-27 20:51:26 +00004848 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
cristy3ed852e2009-09-05 21:47:34 +00004849 k=0;
cristyf61b1832012-04-01 01:38:19 +00004850 if (k == stegano_image->offset)
cristy3ed852e2009-09-05 21:47:34 +00004851 j++;
4852 }
4853 }
cristy8b27a6d2010-02-14 03:31:15 +00004854 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004855 {
cristy8b27a6d2010-02-14 03:31:15 +00004856 MagickBooleanType
4857 proceed;
4858
4859 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4860 (depth-i),depth);
4861 if (proceed == MagickFalse)
4862 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004863 }
4864 }
cristyb0d3bb92010-09-22 14:37:58 +00004865 stegano_view=DestroyCacheView(stegano_view);
4866 watermark_view=DestroyCacheView(watermark_view);
cristyda16f162011-02-19 23:52:17 +00004867 if (status == MagickFalse)
cristyfab83642012-12-14 00:31:38 +00004868 stegano_image=DestroyImage(stegano_image);
cristy3ed852e2009-09-05 21:47:34 +00004869 return(stegano_image);
4870}
4871
4872/*
4873%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4874% %
4875% %
4876% %
4877% S t e r e o A n a g l y p h I m a g e %
4878% %
4879% %
4880% %
4881%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4882%
4883% StereoAnaglyphImage() combines two images and produces a single image that
4884% is the composite of a left and right image of a stereo pair. Special
4885% red-green stereo glasses are required to view this effect.
4886%
4887% The format of the StereoAnaglyphImage method is:
4888%
4889% Image *StereoImage(const Image *left_image,const Image *right_image,
4890% ExceptionInfo *exception)
4891% Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004892% const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004893% ExceptionInfo *exception)
4894%
4895% A description of each parameter follows:
4896%
4897% o left_image: the left image.
4898%
4899% o right_image: the right image.
4900%
4901% o exception: return any errors or warnings in this structure.
4902%
4903% o x_offset: amount, in pixels, by which the left image is offset to the
4904% right of the right image.
4905%
4906% o y_offset: amount, in pixels, by which the left image is offset to the
4907% bottom of the right image.
4908%
4909%
4910*/
4911MagickExport Image *StereoImage(const Image *left_image,
4912 const Image *right_image,ExceptionInfo *exception)
4913{
4914 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4915}
4916
4917MagickExport Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004918 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004919 ExceptionInfo *exception)
4920{
4921#define StereoImageTag "Stereo/Image"
4922
4923 const Image
4924 *image;
4925
4926 Image
4927 *stereo_image;
4928
cristy3ed852e2009-09-05 21:47:34 +00004929 MagickBooleanType
4930 status;
4931
cristy9d314ff2011-03-09 01:30:28 +00004932 ssize_t
4933 y;
4934
cristy3ed852e2009-09-05 21:47:34 +00004935 assert(left_image != (const Image *) NULL);
4936 assert(left_image->signature == MagickSignature);
4937 if (left_image->debug != MagickFalse)
4938 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4939 left_image->filename);
4940 assert(right_image != (const Image *) NULL);
4941 assert(right_image->signature == MagickSignature);
4942 assert(exception != (ExceptionInfo *) NULL);
4943 assert(exception->signature == MagickSignature);
4944 assert(right_image != (const Image *) NULL);
4945 image=left_image;
4946 if ((left_image->columns != right_image->columns) ||
4947 (left_image->rows != right_image->rows))
4948 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4949 /*
4950 Initialize stereo image attributes.
4951 */
4952 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4953 MagickTrue,exception);
4954 if (stereo_image == (Image *) NULL)
4955 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004956 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004957 {
cristy3ed852e2009-09-05 21:47:34 +00004958 stereo_image=DestroyImage(stereo_image);
4959 return((Image *) NULL);
4960 }
cristy079c78d2012-07-03 11:53:48 +00004961 (void) SetImageColorspace(stereo_image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00004962 /*
4963 Copy left image to red channel and right image to blue channel.
4964 */
cristyda16f162011-02-19 23:52:17 +00004965 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00004966 for (y=0; y < (ssize_t) stereo_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004967 {
cristy4c08aed2011-07-01 19:47:50 +00004968 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004969 *restrict p,
4970 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004971
cristybb503372010-05-27 20:51:26 +00004972 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004973 x;
4974
cristy4c08aed2011-07-01 19:47:50 +00004975 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004976 *restrict r;
cristy3ed852e2009-09-05 21:47:34 +00004977
4978 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4979 exception);
4980 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4981 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
cristy76f512e2011-09-12 01:26:56 +00004982 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4983 (r == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004984 break;
cristybb503372010-05-27 20:51:26 +00004985 for (x=0; x < (ssize_t) stereo_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004986 {
cristy4c08aed2011-07-01 19:47:50 +00004987 SetPixelRed(image,GetPixelRed(left_image,p),r);
cristy76f512e2011-09-12 01:26:56 +00004988 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4989 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4990 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4991 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4992 GetPixelAlpha(right_image,q))/2,r);
cristyed231572011-07-14 02:18:59 +00004993 p+=GetPixelChannels(left_image);
cristy76f512e2011-09-12 01:26:56 +00004994 q+=GetPixelChannels(right_image);
4995 r+=GetPixelChannels(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004996 }
4997 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4998 break;
cristy8b27a6d2010-02-14 03:31:15 +00004999 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005000 {
cristy8b27a6d2010-02-14 03:31:15 +00005001 MagickBooleanType
5002 proceed;
5003
cristybb503372010-05-27 20:51:26 +00005004 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
5005 stereo_image->rows);
cristy8b27a6d2010-02-14 03:31:15 +00005006 if (proceed == MagickFalse)
5007 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00005008 }
5009 }
cristyda16f162011-02-19 23:52:17 +00005010 if (status == MagickFalse)
cristyfab83642012-12-14 00:31:38 +00005011 stereo_image=DestroyImage(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00005012 return(stereo_image);
5013}
5014
5015/*
5016%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5017% %
5018% %
5019% %
5020% S w i r l I m a g e %
5021% %
5022% %
5023% %
5024%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5025%
5026% SwirlImage() swirls the pixels about the center of the image, where
5027% degrees indicates the sweep of the arc through which each pixel is moved.
5028% You get a more dramatic effect as the degrees move from 1 to 360.
5029%
5030% The format of the SwirlImage method is:
5031%
5032% Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00005033% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005034%
5035% A description of each parameter follows:
5036%
5037% o image: the image.
5038%
5039% o degrees: Define the tightness of the swirling effect.
5040%
cristy76f512e2011-09-12 01:26:56 +00005041% o method: the pixel interpolation method.
5042%
cristy3ed852e2009-09-05 21:47:34 +00005043% o exception: return any errors or warnings in this structure.
5044%
5045*/
5046MagickExport Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00005047 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005048{
5049#define SwirlImageTag "Swirl/Image"
5050
cristyfa112112010-01-04 17:48:07 +00005051 CacheView
5052 *image_view,
5053 *swirl_view;
5054
cristy3ed852e2009-09-05 21:47:34 +00005055 Image
5056 *swirl_image;
5057
cristy3ed852e2009-09-05 21:47:34 +00005058 MagickBooleanType
5059 status;
5060
cristybb503372010-05-27 20:51:26 +00005061 MagickOffsetType
5062 progress;
5063
cristya19f1d72012-08-07 18:24:38 +00005064 double
cristy3ed852e2009-09-05 21:47:34 +00005065 radius;
5066
5067 PointInfo
5068 center,
5069 scale;
5070
cristybb503372010-05-27 20:51:26 +00005071 ssize_t
5072 y;
5073
cristy3ed852e2009-09-05 21:47:34 +00005074 /*
5075 Initialize swirl image attributes.
5076 */
5077 assert(image != (const Image *) NULL);
5078 assert(image->signature == MagickSignature);
5079 if (image->debug != MagickFalse)
5080 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5081 assert(exception != (ExceptionInfo *) NULL);
5082 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00005083 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005084 if (swirl_image == (Image *) NULL)
5085 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005086 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005087 {
cristy3ed852e2009-09-05 21:47:34 +00005088 swirl_image=DestroyImage(swirl_image);
5089 return((Image *) NULL);
5090 }
cristy4c08aed2011-07-01 19:47:50 +00005091 if (swirl_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00005092 swirl_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00005093 /*
5094 Compute scaling factor.
5095 */
5096 center.x=(double) image->columns/2.0;
5097 center.y=(double) image->rows/2.0;
5098 radius=MagickMax(center.x,center.y);
5099 scale.x=1.0;
5100 scale.y=1.0;
5101 if (image->columns > image->rows)
5102 scale.y=(double) image->columns/(double) image->rows;
5103 else
5104 if (image->columns < image->rows)
5105 scale.x=(double) image->rows/(double) image->columns;
5106 degrees=(double) DegreesToRadians(degrees);
5107 /*
5108 Swirl image.
5109 */
5110 status=MagickTrue;
5111 progress=0;
cristy46ff2672012-12-14 15:32:26 +00005112 image_view=AcquireVirtualCacheView(image,exception);
5113 swirl_view=AcquireAuthenticCacheView(swirl_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00005114#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005115 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00005116 magick_threads(image,swirl_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005117#endif
cristybb503372010-05-27 20:51:26 +00005118 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005119 {
cristya19f1d72012-08-07 18:24:38 +00005120 double
cristy3ed852e2009-09-05 21:47:34 +00005121 distance;
5122
5123 PointInfo
5124 delta;
5125
cristy6d188022011-09-12 13:23:33 +00005126 register const Quantum
5127 *restrict p;
5128
cristybb503372010-05-27 20:51:26 +00005129 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005130 x;
5131
cristy4c08aed2011-07-01 19:47:50 +00005132 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005133 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005134
5135 if (status == MagickFalse)
5136 continue;
cristy6d188022011-09-12 13:23:33 +00005137 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy1707c6c2012-01-18 23:30:54 +00005138 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00005139 exception);
cristy6d188022011-09-12 13:23:33 +00005140 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005141 {
5142 status=MagickFalse;
5143 continue;
5144 }
cristy3ed852e2009-09-05 21:47:34 +00005145 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00005146 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005147 {
5148 /*
5149 Determine if the pixel is within an ellipse.
5150 */
cristy10a6c612012-01-29 21:41:05 +00005151 if (GetPixelMask(image,p) != 0)
5152 {
5153 p+=GetPixelChannels(image);
5154 q+=GetPixelChannels(swirl_image);
5155 continue;
5156 }
cristy3ed852e2009-09-05 21:47:34 +00005157 delta.x=scale.x*(double) (x-center.x);
5158 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00005159 if (distance >= (radius*radius))
5160 {
cristy1707c6c2012-01-18 23:30:54 +00005161 register ssize_t
5162 i;
5163
cristy6d188022011-09-12 13:23:33 +00005164 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristy1707c6c2012-01-18 23:30:54 +00005165 {
5166 PixelChannel
5167 channel;
5168
5169 PixelTrait
5170 swirl_traits,
5171 traits;
5172
cristycf1296e2012-08-26 23:40:49 +00005173 channel=GetPixelChannelChannel(image,i);
5174 traits=GetPixelChannelTraits(image,channel);
5175 swirl_traits=GetPixelChannelTraits(swirl_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00005176 if ((traits == UndefinedPixelTrait) ||
5177 (swirl_traits == UndefinedPixelTrait))
5178 continue;
5179 SetPixelChannel(swirl_image,channel,p[i],q);
5180 }
cristy6d188022011-09-12 13:23:33 +00005181 }
5182 else
cristy3ed852e2009-09-05 21:47:34 +00005183 {
cristya19f1d72012-08-07 18:24:38 +00005184 double
cristy3ed852e2009-09-05 21:47:34 +00005185 cosine,
5186 factor,
5187 sine;
5188
5189 /*
5190 Swirl the pixel.
5191 */
5192 factor=1.0-sqrt((double) distance)/radius;
5193 sine=sin((double) (degrees*factor*factor));
5194 cosine=cos((double) (degrees*factor*factor));
cristy76f512e2011-09-12 01:26:56 +00005195 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5196 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5197 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00005198 }
cristy6d188022011-09-12 13:23:33 +00005199 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00005200 q+=GetPixelChannels(swirl_image);
cristy3ed852e2009-09-05 21:47:34 +00005201 }
5202 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5203 status=MagickFalse;
5204 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5205 {
5206 MagickBooleanType
5207 proceed;
5208
cristyb5d5f722009-11-04 03:03:49 +00005209#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005210 #pragma omp critical (MagickCore_SwirlImage)
cristy3ed852e2009-09-05 21:47:34 +00005211#endif
5212 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5213 if (proceed == MagickFalse)
5214 status=MagickFalse;
5215 }
5216 }
5217 swirl_view=DestroyCacheView(swirl_view);
5218 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005219 if (status == MagickFalse)
5220 swirl_image=DestroyImage(swirl_image);
5221 return(swirl_image);
5222}
5223
5224/*
5225%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5226% %
5227% %
5228% %
5229% T i n t I m a g e %
5230% %
5231% %
5232% %
5233%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5234%
5235% TintImage() applies a color vector to each pixel in the image. The length
5236% of the vector is 0 for black and white and at its maximum for the midtones.
5237% The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5238%
5239% The format of the TintImage method is:
5240%
cristyb817c3f2011-10-03 14:00:35 +00005241% Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005242% const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005243%
5244% A description of each parameter follows:
5245%
5246% o image: the image.
5247%
cristyb817c3f2011-10-03 14:00:35 +00005248% o blend: A color value used for tinting.
cristy3ed852e2009-09-05 21:47:34 +00005249%
5250% o tint: A color value used for tinting.
5251%
5252% o exception: return any errors or warnings in this structure.
5253%
5254*/
cristyb817c3f2011-10-03 14:00:35 +00005255MagickExport Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005256 const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005257{
5258#define TintImageTag "Tint/Image"
5259
cristyc4c8d132010-01-07 01:58:38 +00005260 CacheView
5261 *image_view,
5262 *tint_view;
5263
cristy3ed852e2009-09-05 21:47:34 +00005264 GeometryInfo
5265 geometry_info;
5266
5267 Image
5268 *tint_image;
5269
cristy3ed852e2009-09-05 21:47:34 +00005270 MagickBooleanType
5271 status;
5272
cristybb503372010-05-27 20:51:26 +00005273 MagickOffsetType
5274 progress;
cristy3ed852e2009-09-05 21:47:34 +00005275
cristya19f1d72012-08-07 18:24:38 +00005276 double
cristy28474bf2011-09-11 23:32:52 +00005277 intensity;
5278
cristy4c08aed2011-07-01 19:47:50 +00005279 PixelInfo
cristy1707c6c2012-01-18 23:30:54 +00005280 color_vector;
cristy3ed852e2009-09-05 21:47:34 +00005281
cristybb503372010-05-27 20:51:26 +00005282 MagickStatusType
5283 flags;
5284
5285 ssize_t
5286 y;
5287
cristy3ed852e2009-09-05 21:47:34 +00005288 /*
5289 Allocate tint image.
5290 */
5291 assert(image != (const Image *) NULL);
5292 assert(image->signature == MagickSignature);
5293 if (image->debug != MagickFalse)
5294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5295 assert(exception != (ExceptionInfo *) NULL);
5296 assert(exception->signature == MagickSignature);
5297 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5298 if (tint_image == (Image *) NULL)
5299 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005300 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005301 {
cristy3ed852e2009-09-05 21:47:34 +00005302 tint_image=DestroyImage(tint_image);
5303 return((Image *) NULL);
5304 }
cristy71aac542012-05-18 12:06:35 +00005305 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5306 (IsPixelInfoGray(tint) == MagickFalse))
cristyb09db112012-07-11 12:04:31 +00005307 (void) SetImageColorspace(tint_image,RGBColorspace,exception);
cristyaed9c382011-10-03 17:54:21 +00005308 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005309 return(tint_image);
5310 /*
5311 Determine RGB values of the color.
5312 */
cristy1707c6c2012-01-18 23:30:54 +00005313 GetPixelInfo(image,&color_vector);
cristyb817c3f2011-10-03 14:00:35 +00005314 flags=ParseGeometry(blend,&geometry_info);
cristy1707c6c2012-01-18 23:30:54 +00005315 color_vector.red=geometry_info.rho;
5316 color_vector.green=geometry_info.rho;
5317 color_vector.blue=geometry_info.rho;
5318 color_vector.alpha=OpaqueAlpha;
cristy3ed852e2009-09-05 21:47:34 +00005319 if ((flags & SigmaValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005320 color_vector.green=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00005321 if ((flags & XiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005322 color_vector.blue=geometry_info.xi;
cristyb817c3f2011-10-03 14:00:35 +00005323 if ((flags & PsiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005324 color_vector.alpha=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005325 if (image->colorspace == CMYKColorspace)
5326 {
cristy1707c6c2012-01-18 23:30:54 +00005327 color_vector.black=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005328 if ((flags & PsiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005329 color_vector.black=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005330 if ((flags & ChiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005331 color_vector.alpha=geometry_info.chi;
cristy76f512e2011-09-12 01:26:56 +00005332 }
cristya19f1d72012-08-07 18:24:38 +00005333 intensity=(double) GetPixelInfoIntensity(tint);
5334 color_vector.red=(double) (color_vector.red*tint->red/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005335 intensity);
cristya19f1d72012-08-07 18:24:38 +00005336 color_vector.green=(double) (color_vector.green*tint->green/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005337 intensity);
cristya19f1d72012-08-07 18:24:38 +00005338 color_vector.blue=(double) (color_vector.blue*tint->blue/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005339 intensity);
cristya19f1d72012-08-07 18:24:38 +00005340 color_vector.black=(double) (color_vector.black*tint->black/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005341 intensity);
cristya19f1d72012-08-07 18:24:38 +00005342 color_vector.alpha=(double) (color_vector.alpha*tint->alpha/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005343 intensity);
cristy3ed852e2009-09-05 21:47:34 +00005344 /*
5345 Tint image.
5346 */
5347 status=MagickTrue;
5348 progress=0;
cristy46ff2672012-12-14 15:32:26 +00005349 image_view=AcquireVirtualCacheView(image,exception);
5350 tint_view=AcquireAuthenticCacheView(tint_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00005351#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005352 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00005353 magick_threads(image,tint_image,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005354#endif
cristybb503372010-05-27 20:51:26 +00005355 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005356 {
cristy4c08aed2011-07-01 19:47:50 +00005357 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00005358 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00005359
cristy4c08aed2011-07-01 19:47:50 +00005360 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005361 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005362
cristy6b91acb2011-04-19 12:23:54 +00005363 register ssize_t
5364 x;
5365
cristy3ed852e2009-09-05 21:47:34 +00005366 if (status == MagickFalse)
5367 continue;
5368 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5369 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5370 exception);
cristy4c08aed2011-07-01 19:47:50 +00005371 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005372 {
5373 status=MagickFalse;
5374 continue;
5375 }
cristybb503372010-05-27 20:51:26 +00005376 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005377 {
cristy4c08aed2011-07-01 19:47:50 +00005378 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005379 pixel;
5380
cristya19f1d72012-08-07 18:24:38 +00005381 double
cristy3ed852e2009-09-05 21:47:34 +00005382 weight;
5383
cristy1707c6c2012-01-18 23:30:54 +00005384 register ssize_t
5385 i;
5386
5387 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5388 {
5389 PixelChannel
5390 channel;
5391
5392 PixelTrait
5393 tint_traits,
5394 traits;
5395
cristycf1296e2012-08-26 23:40:49 +00005396 channel=GetPixelChannelChannel(image,i);
5397 traits=GetPixelChannelTraits(image,channel);
5398 tint_traits=GetPixelChannelTraits(tint_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00005399 if ((traits == UndefinedPixelTrait) ||
5400 (tint_traits == UndefinedPixelTrait))
5401 continue;
cristy1eced092012-08-10 23:10:56 +00005402 if (((tint_traits & CopyPixelTrait) != 0) ||
5403 (GetPixelMask(image,p) != 0))
cristy1707c6c2012-01-18 23:30:54 +00005404 {
5405 SetPixelChannel(tint_image,channel,p[i],q);
5406 continue;
5407 }
5408 }
5409 GetPixelInfo(image,&pixel);
5410 weight=QuantumScale*GetPixelRed(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005411 pixel.red=(double) GetPixelRed(image,p)+color_vector.red*(1.0-(4.0*
5412 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005413 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005414 pixel.green=(double) GetPixelGreen(image,p)+color_vector.green*(1.0-(4.0*
5415 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005416 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005417 pixel.blue=(double) GetPixelBlue(image,p)+color_vector.blue*(1.0-(4.0*
5418 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005419 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005420 pixel.black=(double) GetPixelBlack(image,p)+color_vector.black*(1.0-(4.0*
5421 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005422 SetPixelInfoPixel(tint_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +00005423 p+=GetPixelChannels(image);
5424 q+=GetPixelChannels(tint_image);
cristy3ed852e2009-09-05 21:47:34 +00005425 }
5426 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5427 status=MagickFalse;
5428 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5429 {
5430 MagickBooleanType
5431 proceed;
5432
cristyb5d5f722009-11-04 03:03:49 +00005433#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005434 #pragma omp critical (MagickCore_TintImage)
cristy3ed852e2009-09-05 21:47:34 +00005435#endif
5436 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5437 if (proceed == MagickFalse)
5438 status=MagickFalse;
5439 }
5440 }
5441 tint_view=DestroyCacheView(tint_view);
5442 image_view=DestroyCacheView(image_view);
5443 if (status == MagickFalse)
5444 tint_image=DestroyImage(tint_image);
5445 return(tint_image);
5446}
5447
5448/*
5449%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5450% %
5451% %
5452% %
5453% V i g n e t t e I m a g e %
5454% %
5455% %
5456% %
5457%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5458%
5459% VignetteImage() softens the edges of the image in vignette style.
5460%
5461% The format of the VignetteImage method is:
5462%
5463% Image *VignetteImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00005464% const double sigma,const ssize_t x,const ssize_t y,
cristy05c0c9a2011-09-05 23:16:13 +00005465% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005466%
5467% A description of each parameter follows:
5468%
5469% o image: the image.
5470%
5471% o radius: the radius of the pixel neighborhood.
5472%
5473% o sigma: the standard deviation of the Gaussian, in pixels.
5474%
5475% o x, y: Define the x and y ellipse offset.
5476%
5477% o exception: return any errors or warnings in this structure.
5478%
5479*/
5480MagickExport Image *VignetteImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00005481 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005482{
5483 char
5484 ellipse[MaxTextExtent];
5485
5486 DrawInfo
5487 *draw_info;
5488
5489 Image
5490 *canvas_image,
5491 *blur_image,
5492 *oval_image,
5493 *vignette_image;
5494
5495 assert(image != (Image *) NULL);
5496 assert(image->signature == MagickSignature);
5497 if (image->debug != MagickFalse)
5498 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5499 assert(exception != (ExceptionInfo *) NULL);
5500 assert(exception->signature == MagickSignature);
5501 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5502 if (canvas_image == (Image *) NULL)
5503 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005504 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005505 {
cristy3ed852e2009-09-05 21:47:34 +00005506 canvas_image=DestroyImage(canvas_image);
5507 return((Image *) NULL);
5508 }
cristy8a46d822012-08-28 23:32:39 +00005509 canvas_image->alpha_trait=BlendPixelTrait;
cristy98621462011-12-31 22:31:11 +00005510 oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
5511 MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005512 if (oval_image == (Image *) NULL)
5513 {
5514 canvas_image=DestroyImage(canvas_image);
5515 return((Image *) NULL);
5516 }
cristy9950d572011-10-01 18:22:35 +00005517 (void) QueryColorCompliance("#000000",AllCompliance,
5518 &oval_image->background_color,exception);
cristyea1a8aa2011-10-20 13:24:06 +00005519 (void) SetImageBackgroundColor(oval_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00005520 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00005521 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5522 exception);
5523 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5524 exception);
cristy1707c6c2012-01-18 23:30:54 +00005525 (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
5526 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
5527 image->rows/2.0-y);
cristy3ed852e2009-09-05 21:47:34 +00005528 draw_info->primitive=AcquireString(ellipse);
cristy018f07f2011-09-04 21:15:19 +00005529 (void) DrawImage(oval_image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00005530 draw_info=DestroyDrawInfo(draw_info);
cristyaa2c16c2012-03-25 22:21:35 +00005531 blur_image=BlurImage(oval_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00005532 oval_image=DestroyImage(oval_image);
5533 if (blur_image == (Image *) NULL)
5534 {
5535 canvas_image=DestroyImage(canvas_image);
5536 return((Image *) NULL);
5537 }
cristy8a46d822012-08-28 23:32:39 +00005538 blur_image->alpha_trait=UndefinedPixelTrait;
cristy39172402012-03-30 13:04:39 +00005539 (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue,
5540 0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00005541 blur_image=DestroyImage(blur_image);
5542 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5543 canvas_image=DestroyImage(canvas_image);
cristy66d26122012-06-23 21:56:40 +00005544 if (vignette_image != (Image *) NULL)
5545 (void) TransformImageColorspace(vignette_image,image->colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00005546 return(vignette_image);
5547}
5548
5549/*
5550%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5551% %
5552% %
5553% %
5554% W a v e I m a g e %
5555% %
5556% %
5557% %
5558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5559%
5560% WaveImage() creates a "ripple" effect in the image by shifting the pixels
cristycee97112010-05-28 00:44:52 +00005561% vertically along a sine wave whose amplitude and wavelength is specified
cristy3ed852e2009-09-05 21:47:34 +00005562% by the given parameters.
5563%
5564% The format of the WaveImage method is:
5565%
5566% Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005567% const double wave_length,const PixelInterpolateMethod method,
5568% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005569%
5570% A description of each parameter follows:
5571%
5572% o image: the image.
5573%
5574% o amplitude, wave_length: Define the amplitude and wave length of the
5575% sine wave.
5576%
cristy5c4e2582011-09-11 19:21:03 +00005577% o interpolate: the pixel interpolation method.
5578%
cristy3ed852e2009-09-05 21:47:34 +00005579% o exception: return any errors or warnings in this structure.
5580%
5581*/
5582MagickExport Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005583 const double wave_length,const PixelInterpolateMethod method,
5584 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005585{
5586#define WaveImageTag "Wave/Image"
5587
cristyfa112112010-01-04 17:48:07 +00005588 CacheView
cristyd76c51e2011-03-26 00:21:26 +00005589 *image_view,
cristyfa112112010-01-04 17:48:07 +00005590 *wave_view;
5591
cristy3ed852e2009-09-05 21:47:34 +00005592 Image
5593 *wave_image;
5594
cristy3ed852e2009-09-05 21:47:34 +00005595 MagickBooleanType
5596 status;
5597
cristybb503372010-05-27 20:51:26 +00005598 MagickOffsetType
5599 progress;
5600
cristya19f1d72012-08-07 18:24:38 +00005601 double
cristy3ed852e2009-09-05 21:47:34 +00005602 *sine_map;
5603
cristybb503372010-05-27 20:51:26 +00005604 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005605 i;
5606
cristybb503372010-05-27 20:51:26 +00005607 ssize_t
5608 y;
5609
cristy3ed852e2009-09-05 21:47:34 +00005610 /*
5611 Initialize wave image attributes.
5612 */
5613 assert(image != (Image *) NULL);
5614 assert(image->signature == MagickSignature);
5615 if (image->debug != MagickFalse)
5616 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5617 assert(exception != (ExceptionInfo *) NULL);
5618 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00005619 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
cristy3ed852e2009-09-05 21:47:34 +00005620 fabs(amplitude)),MagickTrue,exception);
5621 if (wave_image == (Image *) NULL)
5622 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005623 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005624 {
cristy3ed852e2009-09-05 21:47:34 +00005625 wave_image=DestroyImage(wave_image);
5626 return((Image *) NULL);
5627 }
cristy4c08aed2011-07-01 19:47:50 +00005628 if (wave_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00005629 wave_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00005630 /*
5631 Allocate sine map.
5632 */
cristya19f1d72012-08-07 18:24:38 +00005633 sine_map=(double *) AcquireQuantumMemory((size_t) wave_image->columns,
cristy3ed852e2009-09-05 21:47:34 +00005634 sizeof(*sine_map));
cristya19f1d72012-08-07 18:24:38 +00005635 if (sine_map == (double *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005636 {
5637 wave_image=DestroyImage(wave_image);
5638 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5639 }
cristybb503372010-05-27 20:51:26 +00005640 for (i=0; i < (ssize_t) wave_image->columns; i++)
cristy4205a3c2010-09-12 20:19:59 +00005641 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5642 wave_length));
cristy3ed852e2009-09-05 21:47:34 +00005643 /*
5644 Wave image.
5645 */
5646 status=MagickTrue;
5647 progress=0;
cristy46ff2672012-12-14 15:32:26 +00005648 image_view=AcquireVirtualCacheView(image,exception);
5649 wave_view=AcquireAuthenticCacheView(wave_image,exception);
cristyd76c51e2011-03-26 00:21:26 +00005650 (void) SetCacheViewVirtualPixelMethod(image_view,
5651 BackgroundVirtualPixelMethod);
cristyb5d5f722009-11-04 03:03:49 +00005652#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005653 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy5e6b2592012-12-19 14:08:11 +00005654 magick_threads(image,wave_image,wave_image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005655#endif
cristybb503372010-05-27 20:51:26 +00005656 for (y=0; y < (ssize_t) wave_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005657 {
cristy4c08aed2011-07-01 19:47:50 +00005658 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005659 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005660
cristye97bb922011-04-03 01:36:52 +00005661 register ssize_t
5662 x;
5663
cristy3ed852e2009-09-05 21:47:34 +00005664 if (status == MagickFalse)
5665 continue;
5666 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5667 exception);
cristyacd2ed22011-08-30 01:44:23 +00005668 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005669 {
5670 status=MagickFalse;
5671 continue;
5672 }
cristybb503372010-05-27 20:51:26 +00005673 for (x=0; x < (ssize_t) wave_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005674 {
cristy5c4e2582011-09-11 19:21:03 +00005675 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5676 (double) x,(double) (y-sine_map[x]),q,exception);
cristyed231572011-07-14 02:18:59 +00005677 q+=GetPixelChannels(wave_image);
cristy3ed852e2009-09-05 21:47:34 +00005678 }
5679 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5680 status=MagickFalse;
5681 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5682 {
5683 MagickBooleanType
5684 proceed;
5685
cristyb5d5f722009-11-04 03:03:49 +00005686#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005687 #pragma omp critical (MagickCore_WaveImage)
cristy3ed852e2009-09-05 21:47:34 +00005688#endif
5689 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5690 if (proceed == MagickFalse)
5691 status=MagickFalse;
5692 }
5693 }
5694 wave_view=DestroyCacheView(wave_view);
cristyd76c51e2011-03-26 00:21:26 +00005695 image_view=DestroyCacheView(image_view);
cristya19f1d72012-08-07 18:24:38 +00005696 sine_map=(double *) RelinquishMagickMemory(sine_map);
cristy3ed852e2009-09-05 21:47:34 +00005697 if (status == MagickFalse)
5698 wave_image=DestroyImage(wave_image);
5699 return(wave_image);
5700}