blob: f60a7e24f6cc46045c01ce1f9d3853716f09d8c3 [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% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 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"
51#include "MagickCore/composite.h"
52#include "MagickCore/decorate.h"
cristyc53413d2011-11-17 13:04:26 +000053#include "MagickCore/distort.h"
cristy4c08aed2011-07-01 19:47:50 +000054#include "MagickCore/draw.h"
55#include "MagickCore/effect.h"
56#include "MagickCore/enhance.h"
57#include "MagickCore/exception.h"
58#include "MagickCore/exception-private.h"
59#include "MagickCore/fx.h"
60#include "MagickCore/fx-private.h"
61#include "MagickCore/gem.h"
cristy8ea81222011-09-04 10:33:32 +000062#include "MagickCore/gem-private.h"
cristy4c08aed2011-07-01 19:47:50 +000063#include "MagickCore/geometry.h"
64#include "MagickCore/layer.h"
65#include "MagickCore/list.h"
66#include "MagickCore/log.h"
67#include "MagickCore/image.h"
68#include "MagickCore/image-private.h"
69#include "MagickCore/magick.h"
70#include "MagickCore/memory_.h"
71#include "MagickCore/monitor.h"
72#include "MagickCore/monitor-private.h"
73#include "MagickCore/option.h"
74#include "MagickCore/pixel.h"
75#include "MagickCore/pixel-accessor.h"
76#include "MagickCore/property.h"
77#include "MagickCore/quantum.h"
78#include "MagickCore/quantum-private.h"
79#include "MagickCore/random_.h"
80#include "MagickCore/random-private.h"
81#include "MagickCore/resample.h"
82#include "MagickCore/resample-private.h"
83#include "MagickCore/resize.h"
cristy4c08aed2011-07-01 19:47:50 +000084#include "MagickCore/splay-tree.h"
85#include "MagickCore/statistic.h"
86#include "MagickCore/string_.h"
87#include "MagickCore/string-private.h"
88#include "MagickCore/thread-private.h"
89#include "MagickCore/transform.h"
90#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000091
92/*
93 Define declarations.
94*/
95#define LeftShiftOperator 0xf5
96#define RightShiftOperator 0xf6
97#define LessThanEqualOperator 0xf7
98#define GreaterThanEqualOperator 0xf8
99#define EqualOperator 0xf9
100#define NotEqualOperator 0xfa
101#define LogicalAndOperator 0xfb
102#define LogicalOrOperator 0xfc
cristy116af162010-08-13 01:25:47 +0000103#define ExponentialNotation 0xfd
cristy3ed852e2009-09-05 21:47:34 +0000104
105struct _FxInfo
106{
107 const Image
108 *images;
109
cristy3ed852e2009-09-05 21:47:34 +0000110 char
111 *expression;
112
113 FILE
114 *file;
115
116 SplayTreeInfo
117 *colors,
118 *symbols;
119
cristyd76c51e2011-03-26 00:21:26 +0000120 CacheView
121 **view;
cristy3ed852e2009-09-05 21:47:34 +0000122
123 RandomInfo
124 *random_info;
125
126 ExceptionInfo
127 *exception;
128};
129
130/*
131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132% %
133% %
134% %
135+ A c q u i r e F x I n f o %
136% %
137% %
138% %
139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140%
141% AcquireFxInfo() allocates the FxInfo structure.
142%
143% The format of the AcquireFxInfo method is:
144%
145% FxInfo *AcquireFxInfo(Image *image,const char *expression)
cristy0a9b3722010-10-23 18:45:49 +0000146%
cristy3ed852e2009-09-05 21:47:34 +0000147% A description of each parameter follows:
148%
149% o image: the image.
150%
151% o expression: the expression.
152%
153*/
cristy7832dc22011-09-05 01:21:53 +0000154MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression)
cristy3ed852e2009-09-05 21:47:34 +0000155{
156 char
157 fx_op[2];
158
cristycb180922011-03-11 14:41:24 +0000159 const Image
160 *next;
161
cristy3ed852e2009-09-05 21:47:34 +0000162 FxInfo
163 *fx_info;
164
cristybb503372010-05-27 20:51:26 +0000165 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000166 i;
167
cristy73bd4a52010-10-05 11:24:23 +0000168 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +0000169 if (fx_info == (FxInfo *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
172 fx_info->exception=AcquireExceptionInfo();
anthony7d86e172011-03-23 12:37:06 +0000173 fx_info->images=image;
cristy3ed852e2009-09-05 21:47:34 +0000174 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
177 RelinquishMagickMemory);
cristyd76c51e2011-03-26 00:21:26 +0000178 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
179 fx_info->images),sizeof(*fx_info->view));
180 if (fx_info->view == (CacheView **) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000181 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
cristya2262262011-03-11 02:50:37 +0000182 i=0;
cristy0ea377f2011-03-24 00:54:19 +0000183 next=GetFirstImageInList(fx_info->images);
184 for ( ; next != (Image *) NULL; next=next->next)
cristy3ed852e2009-09-05 21:47:34 +0000185 {
cristyd76c51e2011-03-26 00:21:26 +0000186 fx_info->view[i]=AcquireCacheView(next);
cristya2262262011-03-11 02:50:37 +0000187 i++;
cristy3ed852e2009-09-05 21:47:34 +0000188 }
189 fx_info->random_info=AcquireRandomInfo();
190 fx_info->expression=ConstantString(expression);
191 fx_info->file=stderr;
192 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
cristy37af0912011-05-23 16:09:42 +0000193 /*
194 Force right-to-left associativity for unary negation.
195 */
196 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
cristy8b8a3ae2010-10-23 18:49:46 +0000197 /*
cristy3ed852e2009-09-05 21:47:34 +0000198 Convert complex to simple operators.
199 */
200 fx_op[1]='\0';
201 *fx_op=(char) LeftShiftOperator;
202 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
203 *fx_op=(char) RightShiftOperator;
204 (void) SubstituteString(&fx_info->expression,">>",fx_op);
205 *fx_op=(char) LessThanEqualOperator;
206 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
207 *fx_op=(char) GreaterThanEqualOperator;
208 (void) SubstituteString(&fx_info->expression,">=",fx_op);
209 *fx_op=(char) EqualOperator;
210 (void) SubstituteString(&fx_info->expression,"==",fx_op);
211 *fx_op=(char) NotEqualOperator;
212 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
213 *fx_op=(char) LogicalAndOperator;
214 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
215 *fx_op=(char) LogicalOrOperator;
216 (void) SubstituteString(&fx_info->expression,"||",fx_op);
cristy116af162010-08-13 01:25:47 +0000217 *fx_op=(char) ExponentialNotation;
218 (void) SubstituteString(&fx_info->expression,"**",fx_op);
cristy3ed852e2009-09-05 21:47:34 +0000219 return(fx_info);
220}
221
222/*
223%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224% %
225% %
226% %
227% A d d N o i s e I m a g e %
228% %
229% %
230% %
231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232%
233% AddNoiseImage() adds random noise to the image.
234%
235% The format of the AddNoiseImage method is:
236%
237% Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
cristy9ed1f812011-10-08 02:00:08 +0000238% const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000239%
240% A description of each parameter follows:
241%
242% o image: the image.
243%
244% o channel: the channel type.
245%
246% o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
247% Impulse, Laplacian, or Poisson.
248%
cristy9ed1f812011-10-08 02:00:08 +0000249% o attenuate: attenuate the random distribution.
250%
cristy3ed852e2009-09-05 21:47:34 +0000251% o exception: return any errors or warnings in this structure.
252%
253*/
cristy9ed1f812011-10-08 02:00:08 +0000254MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
255 const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000256{
257#define AddNoiseImageTag "AddNoise/Image"
258
cristyfa112112010-01-04 17:48:07 +0000259 CacheView
260 *image_view,
261 *noise_view;
262
cristy3ed852e2009-09-05 21:47:34 +0000263 Image
264 *noise_image;
265
cristy3ed852e2009-09-05 21:47:34 +0000266 MagickBooleanType
267 status;
268
cristybb503372010-05-27 20:51:26 +0000269 MagickOffsetType
270 progress;
271
cristy3ed852e2009-09-05 21:47:34 +0000272 RandomInfo
cristyfa112112010-01-04 17:48:07 +0000273 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +0000274
cristybb503372010-05-27 20:51:26 +0000275 ssize_t
276 y;
277
cristy3ed852e2009-09-05 21:47:34 +0000278 /*
279 Initialize noise image attributes.
280 */
281 assert(image != (const Image *) NULL);
282 assert(image->signature == MagickSignature);
283 if (image->debug != MagickFalse)
284 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
285 assert(exception != (ExceptionInfo *) NULL);
286 assert(exception->signature == MagickSignature);
cristyb2145892011-10-10 00:55:32 +0000287 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000288 if (noise_image == (Image *) NULL)
289 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000290 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000291 {
cristy3ed852e2009-09-05 21:47:34 +0000292 noise_image=DestroyImage(noise_image);
293 return((Image *) NULL);
294 }
295 /*
296 Add noise in each row.
297 */
cristy3ed852e2009-09-05 21:47:34 +0000298 status=MagickTrue;
299 progress=0;
300 random_info=AcquireRandomInfoThreadSet();
301 image_view=AcquireCacheView(image);
302 noise_view=AcquireCacheView(noise_image);
cristy319a1e72010-02-21 15:13:11 +0000303#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000304 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000305#endif
cristybb503372010-05-27 20:51:26 +0000306 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000307 {
cristy5c9e6f22010-09-17 17:31:01 +0000308 const int
309 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +0000310
cristy3ed852e2009-09-05 21:47:34 +0000311 MagickBooleanType
312 sync;
313
cristy4c08aed2011-07-01 19:47:50 +0000314 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000315 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000316
cristybb503372010-05-27 20:51:26 +0000317 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000318 x;
319
cristy4c08aed2011-07-01 19:47:50 +0000320 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000321 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000322
323 if (status == MagickFalse)
324 continue;
325 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
326 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
327 exception);
cristy4c08aed2011-07-01 19:47:50 +0000328 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000329 {
330 status=MagickFalse;
331 continue;
332 }
cristybb503372010-05-27 20:51:26 +0000333 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000334 {
cristy850b3072011-10-08 01:38:05 +0000335 register ssize_t
336 i;
337
338 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
339 {
340 PixelChannel
341 channel;
342
343 PixelTrait
344 noise_traits,
345 traits;
346
cristye2a912b2011-12-05 20:02:07 +0000347 traits=GetPixelChannelMapTraits(image,i);
348 channel=GetPixelChannelMapChannel(image,i);
cristy850b3072011-10-08 01:38:05 +0000349 noise_traits=GetPixelChannelMapTraits(noise_image,channel);
350 if ((traits == UndefinedPixelTrait) ||
351 (noise_traits == UndefinedPixelTrait))
352 continue;
cristy9eeedea2011-11-02 19:04:05 +0000353 if ((noise_traits & CopyPixelTrait) != 0)
cristyb2145892011-10-10 00:55:32 +0000354 {
355 SetPixelChannel(noise_image,channel,p[i],q);
356 continue;
357 }
cristy850b3072011-10-08 01:38:05 +0000358 SetPixelChannel(noise_image,channel,ClampToQuantum(
359 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
360 q);
361 }
cristyed231572011-07-14 02:18:59 +0000362 p+=GetPixelChannels(image);
363 q+=GetPixelChannels(noise_image);
cristy3ed852e2009-09-05 21:47:34 +0000364 }
365 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
366 if (sync == MagickFalse)
367 status=MagickFalse;
368 if (image->progress_monitor != (MagickProgressMonitor) NULL)
369 {
370 MagickBooleanType
371 proceed;
372
cristyb5d5f722009-11-04 03:03:49 +0000373#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy319a1e72010-02-21 15:13:11 +0000374 #pragma omp critical (MagickCore_AddNoiseImage)
cristy3ed852e2009-09-05 21:47:34 +0000375#endif
376 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
377 image->rows);
378 if (proceed == MagickFalse)
379 status=MagickFalse;
380 }
381 }
382 noise_view=DestroyCacheView(noise_view);
383 image_view=DestroyCacheView(image_view);
384 random_info=DestroyRandomInfoThreadSet(random_info);
385 if (status == MagickFalse)
386 noise_image=DestroyImage(noise_image);
387 return(noise_image);
388}
389
390/*
391%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392% %
393% %
394% %
395% B l u e S h i f t I m a g e %
396% %
397% %
398% %
399%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
400%
401% BlueShiftImage() mutes the colors of the image to simulate a scene at
402% nighttime in the moonlight.
403%
404% The format of the BlueShiftImage method is:
405%
406% Image *BlueShiftImage(const Image *image,const double factor,
407% ExceptionInfo *exception)
408%
409% A description of each parameter follows:
410%
411% o image: the image.
412%
413% o factor: the shift factor.
414%
415% o exception: return any errors or warnings in this structure.
416%
417*/
418MagickExport Image *BlueShiftImage(const Image *image,const double factor,
419 ExceptionInfo *exception)
420{
421#define BlueShiftImageTag "BlueShift/Image"
422
cristyc4c8d132010-01-07 01:58:38 +0000423 CacheView
424 *image_view,
425 *shift_view;
426
cristy3ed852e2009-09-05 21:47:34 +0000427 Image
428 *shift_image;
429
cristy3ed852e2009-09-05 21:47:34 +0000430 MagickBooleanType
431 status;
432
cristybb503372010-05-27 20:51:26 +0000433 MagickOffsetType
434 progress;
435
436 ssize_t
437 y;
438
cristy3ed852e2009-09-05 21:47:34 +0000439 /*
440 Allocate blue shift image.
441 */
442 assert(image != (const Image *) NULL);
443 assert(image->signature == MagickSignature);
444 if (image->debug != MagickFalse)
445 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
446 assert(exception != (ExceptionInfo *) NULL);
447 assert(exception->signature == MagickSignature);
448 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
449 exception);
450 if (shift_image == (Image *) NULL)
451 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000452 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000453 {
cristy3ed852e2009-09-05 21:47:34 +0000454 shift_image=DestroyImage(shift_image);
455 return((Image *) NULL);
456 }
457 /*
458 Blue-shift DirectClass image.
459 */
460 status=MagickTrue;
461 progress=0;
462 image_view=AcquireCacheView(image);
463 shift_view=AcquireCacheView(shift_image);
cristy319a1e72010-02-21 15:13:11 +0000464#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000465 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000466#endif
cristybb503372010-05-27 20:51:26 +0000467 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000468 {
469 MagickBooleanType
470 sync;
471
cristy4c08aed2011-07-01 19:47:50 +0000472 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000473 pixel;
474
475 Quantum
476 quantum;
477
cristy4c08aed2011-07-01 19:47:50 +0000478 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000479 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000480
cristybb503372010-05-27 20:51:26 +0000481 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000482 x;
483
cristy4c08aed2011-07-01 19:47:50 +0000484 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000485 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000486
487 if (status == MagickFalse)
488 continue;
489 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
490 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
491 exception);
cristy4c08aed2011-07-01 19:47:50 +0000492 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000493 {
494 status=MagickFalse;
495 continue;
496 }
cristybb503372010-05-27 20:51:26 +0000497 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000498 {
cristy4c08aed2011-07-01 19:47:50 +0000499 quantum=GetPixelRed(image,p);
500 if (GetPixelGreen(image,p) < quantum)
501 quantum=GetPixelGreen(image,p);
502 if (GetPixelBlue(image,p) < quantum)
503 quantum=GetPixelBlue(image,p);
504 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
505 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
506 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
507 quantum=GetPixelRed(image,p);
508 if (GetPixelGreen(image,p) > quantum)
509 quantum=GetPixelGreen(image,p);
510 if (GetPixelBlue(image,p) > quantum)
511 quantum=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000512 pixel.red=0.5*(pixel.red+factor*quantum);
513 pixel.green=0.5*(pixel.green+factor*quantum);
514 pixel.blue=0.5*(pixel.blue+factor*quantum);
cristy4c08aed2011-07-01 19:47:50 +0000515 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
516 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
517 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
cristyed231572011-07-14 02:18:59 +0000518 p+=GetPixelChannels(image);
519 q+=GetPixelChannels(shift_image);
cristy3ed852e2009-09-05 21:47:34 +0000520 }
521 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
522 if (sync == MagickFalse)
523 status=MagickFalse;
524 if (image->progress_monitor != (MagickProgressMonitor) NULL)
525 {
526 MagickBooleanType
527 proceed;
528
cristy319a1e72010-02-21 15:13:11 +0000529#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000530 #pragma omp critical (MagickCore_BlueShiftImage)
531#endif
532 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
533 image->rows);
534 if (proceed == MagickFalse)
535 status=MagickFalse;
536 }
537 }
538 image_view=DestroyCacheView(image_view);
539 shift_view=DestroyCacheView(shift_view);
540 if (status == MagickFalse)
541 shift_image=DestroyImage(shift_image);
542 return(shift_image);
543}
544
545/*
546%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
547% %
548% %
549% %
550% C h a r c o a l I m a g e %
551% %
552% %
553% %
554%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
555%
556% CharcoalImage() creates a new image that is a copy of an existing one with
557% the edge highlighted. It allocates the memory necessary for the new Image
558% structure and returns a pointer to the new image.
559%
560% The format of the CharcoalImage method is:
561%
562% Image *CharcoalImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +0000563% const double sigma,const double bias,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000564%
565% A description of each parameter follows:
566%
567% o image: the image.
568%
569% o radius: the radius of the pixel neighborhood.
570%
571% o sigma: the standard deviation of the Gaussian, in pixels.
572%
cristy05c0c9a2011-09-05 23:16:13 +0000573% o bias: the bias.
574%
cristy3ed852e2009-09-05 21:47:34 +0000575% o exception: return any errors or warnings in this structure.
576%
577*/
578MagickExport Image *CharcoalImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +0000579 const double sigma,const double bias,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000580{
581 Image
582 *charcoal_image,
583 *clone_image,
584 *edge_image;
585
586 assert(image != (Image *) NULL);
587 assert(image->signature == MagickSignature);
588 if (image->debug != MagickFalse)
589 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
590 assert(exception != (ExceptionInfo *) NULL);
591 assert(exception->signature == MagickSignature);
592 clone_image=CloneImage(image,0,0,MagickTrue,exception);
593 if (clone_image == (Image *) NULL)
594 return((Image *) NULL);
cristy018f07f2011-09-04 21:15:19 +0000595 (void) SetImageType(clone_image,GrayscaleType,exception);
cristy8ae632d2011-09-05 17:29:53 +0000596 edge_image=EdgeImage(clone_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000597 clone_image=DestroyImage(clone_image);
598 if (edge_image == (Image *) NULL)
599 return((Image *) NULL);
cristy05c0c9a2011-09-05 23:16:13 +0000600 charcoal_image=BlurImage(edge_image,radius,sigma,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +0000601 edge_image=DestroyImage(edge_image);
602 if (charcoal_image == (Image *) NULL)
603 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +0000604 (void) NormalizeImage(charcoal_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +0000605 (void) NegateImage(charcoal_image,MagickFalse,exception);
cristy018f07f2011-09-04 21:15:19 +0000606 (void) SetImageType(charcoal_image,GrayscaleType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000607 return(charcoal_image);
608}
609
610/*
611%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
612% %
613% %
614% %
615% C o l o r i z e I m a g e %
616% %
617% %
618% %
619%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
620%
621% ColorizeImage() blends the fill color with each pixel in the image.
622% A percentage blend is specified with opacity. Control the application
623% of different color components by specifying a different percentage for
624% each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
625%
626% The format of the ColorizeImage method is:
627%
cristyc7e6ff62011-10-03 13:46:11 +0000628% Image *ColorizeImage(const Image *image,const char *blend,
629% const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000630%
631% A description of each parameter follows:
632%
633% o image: the image.
634%
cristyc7e6ff62011-10-03 13:46:11 +0000635% o blend: A character string indicating the level of blending as a
cristy3ed852e2009-09-05 21:47:34 +0000636% percentage.
637%
638% o colorize: A color value.
639%
640% o exception: return any errors or warnings in this structure.
641%
642*/
cristyc7e6ff62011-10-03 13:46:11 +0000643MagickExport Image *ColorizeImage(const Image *image,const char *blend,
644 const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000645{
646#define ColorizeImageTag "Colorize/Image"
647
cristyc4c8d132010-01-07 01:58:38 +0000648 CacheView
649 *colorize_view,
650 *image_view;
651
cristy3ed852e2009-09-05 21:47:34 +0000652 GeometryInfo
653 geometry_info;
654
655 Image
656 *colorize_image;
657
cristy3ed852e2009-09-05 21:47:34 +0000658 MagickBooleanType
659 status;
660
cristybb503372010-05-27 20:51:26 +0000661 MagickOffsetType
662 progress;
663
cristy3ed852e2009-09-05 21:47:34 +0000664 MagickStatusType
665 flags;
666
cristyc7e6ff62011-10-03 13:46:11 +0000667 PixelInfo
668 pixel;
669
cristybb503372010-05-27 20:51:26 +0000670 ssize_t
671 y;
672
cristy3ed852e2009-09-05 21:47:34 +0000673 /*
674 Allocate colorized image.
675 */
676 assert(image != (const Image *) NULL);
677 assert(image->signature == MagickSignature);
678 if (image->debug != MagickFalse)
679 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
680 assert(exception != (ExceptionInfo *) NULL);
681 assert(exception->signature == MagickSignature);
682 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
683 exception);
684 if (colorize_image == (Image *) NULL)
685 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000686 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000687 {
cristy3ed852e2009-09-05 21:47:34 +0000688 colorize_image=DestroyImage(colorize_image);
689 return((Image *) NULL);
690 }
cristyc7e6ff62011-10-03 13:46:11 +0000691 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000692 return(colorize_image);
693 /*
694 Determine RGB values of the pen color.
695 */
cristyc7e6ff62011-10-03 13:46:11 +0000696 GetPixelInfo(image,&pixel);
cristyb817c3f2011-10-03 14:00:35 +0000697 flags=ParseGeometry(blend,&geometry_info);
cristy3ed852e2009-09-05 21:47:34 +0000698 pixel.red=geometry_info.rho;
699 pixel.green=geometry_info.rho;
700 pixel.blue=geometry_info.rho;
cristyc7e6ff62011-10-03 13:46:11 +0000701 pixel.alpha=100.0;
cristy3ed852e2009-09-05 21:47:34 +0000702 if ((flags & SigmaValue) != 0)
703 pixel.green=geometry_info.sigma;
704 if ((flags & XiValue) != 0)
705 pixel.blue=geometry_info.xi;
706 if ((flags & PsiValue) != 0)
cristy4c08aed2011-07-01 19:47:50 +0000707 pixel.alpha=geometry_info.psi;
cristyc7e6ff62011-10-03 13:46:11 +0000708 if (pixel.colorspace == CMYKColorspace)
709 {
710 pixel.black=geometry_info.rho;
711 if ((flags & PsiValue) != 0)
712 pixel.black=geometry_info.psi;
713 if ((flags & ChiValue) != 0)
714 pixel.alpha=geometry_info.chi;
715 }
cristy3ed852e2009-09-05 21:47:34 +0000716 /*
717 Colorize DirectClass image.
718 */
719 status=MagickTrue;
720 progress=0;
721 image_view=AcquireCacheView(image);
722 colorize_view=AcquireCacheView(colorize_image);
cristy319a1e72010-02-21 15:13:11 +0000723#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000724 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000725#endif
cristybb503372010-05-27 20:51:26 +0000726 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000727 {
728 MagickBooleanType
729 sync;
730
cristy4c08aed2011-07-01 19:47:50 +0000731 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000732 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000733
cristybb503372010-05-27 20:51:26 +0000734 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000735 x;
736
cristy4c08aed2011-07-01 19:47:50 +0000737 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000738 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000739
740 if (status == MagickFalse)
741 continue;
742 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
743 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
744 exception);
cristy4c08aed2011-07-01 19:47:50 +0000745 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000746 {
747 status=MagickFalse;
748 continue;
749 }
cristybb503372010-05-27 20:51:26 +0000750 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000751 {
cristyc7e6ff62011-10-03 13:46:11 +0000752 register ssize_t
753 i;
754
755 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
756 {
757 PixelChannel
758 channel;
759
760 PixelTrait
761 colorize_traits,
762 traits;
763
cristye2a912b2011-12-05 20:02:07 +0000764 traits=GetPixelChannelMapTraits(image,i);
765 channel=GetPixelChannelMapChannel(image,i);
cristyc7e6ff62011-10-03 13:46:11 +0000766 colorize_traits=GetPixelChannelMapTraits(colorize_image,channel);
767 if ((traits == UndefinedPixelTrait) ||
768 (colorize_traits == UndefinedPixelTrait))
769 continue;
770 if ((colorize_traits & CopyPixelTrait) != 0)
771 {
772 SetPixelChannel(colorize_image,channel,p[i],q);
773 continue;
774 }
775 switch (channel)
776 {
777 case RedPixelChannel:
778 {
779 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
780 (100.0-pixel.red)+colorize->red*pixel.red)/100.0),q);
781 break;
782 }
783 case GreenPixelChannel:
784 {
785 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
786 (100.0-pixel.green)+colorize->green*pixel.green)/100.0),q);
787 break;
788 }
789 case BluePixelChannel:
790 {
791 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
792 (100.0-pixel.blue)+colorize->blue*pixel.blue)/100.0),q);
793 break;
794 }
795 case BlackPixelChannel:
796 {
797 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
798 (100.0-pixel.black)+colorize->black*pixel.black)/100.0),q);
799 break;
800 }
801 case AlphaPixelChannel:
802 {
803 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
804 (100.0-pixel.alpha)+colorize->alpha*pixel.alpha)/100.0),q);
805 break;
806 }
807 default:
808 {
809 SetPixelChannel(colorize_image,channel,p[i],q);
810 break;
811 }
812 }
813 }
cristyed231572011-07-14 02:18:59 +0000814 p+=GetPixelChannels(image);
815 q+=GetPixelChannels(colorize_image);
cristy3ed852e2009-09-05 21:47:34 +0000816 }
817 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
818 if (sync == MagickFalse)
819 status=MagickFalse;
820 if (image->progress_monitor != (MagickProgressMonitor) NULL)
821 {
822 MagickBooleanType
823 proceed;
824
cristy319a1e72010-02-21 15:13:11 +0000825#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000826 #pragma omp critical (MagickCore_ColorizeImage)
827#endif
828 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
829 if (proceed == MagickFalse)
830 status=MagickFalse;
831 }
832 }
833 image_view=DestroyCacheView(image_view);
834 colorize_view=DestroyCacheView(colorize_view);
835 if (status == MagickFalse)
836 colorize_image=DestroyImage(colorize_image);
837 return(colorize_image);
838}
839
840/*
841%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
842% %
843% %
844% %
cristye6365592010-04-02 17:31:23 +0000845% C o l o r M a t r i x I m a g e %
846% %
847% %
848% %
849%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
850%
851% ColorMatrixImage() applies color transformation to an image. This method
852% permits saturation changes, hue rotation, luminance to alpha, and various
853% other effects. Although variable-sized transformation matrices can be used,
854% typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
855% (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
856% except offsets are in column 6 rather than 5 (in support of CMYKA images)
857% and offsets are normalized (divide Flash offset by 255).
858%
859% The format of the ColorMatrixImage method is:
860%
861% Image *ColorMatrixImage(const Image *image,
862% const KernelInfo *color_matrix,ExceptionInfo *exception)
863%
864% A description of each parameter follows:
865%
866% o image: the image.
867%
868% o color_matrix: the color matrix.
869%
870% o exception: return any errors or warnings in this structure.
871%
872*/
873MagickExport Image *ColorMatrixImage(const Image *image,
874 const KernelInfo *color_matrix,ExceptionInfo *exception)
875{
876#define ColorMatrixImageTag "ColorMatrix/Image"
877
878 CacheView
879 *color_view,
880 *image_view;
881
882 double
883 ColorMatrix[6][6] =
884 {
885 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
886 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
887 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
888 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
889 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
890 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
891 };
892
893 Image
894 *color_image;
895
cristye6365592010-04-02 17:31:23 +0000896 MagickBooleanType
897 status;
898
cristybb503372010-05-27 20:51:26 +0000899 MagickOffsetType
900 progress;
901
902 register ssize_t
cristye6365592010-04-02 17:31:23 +0000903 i;
904
cristybb503372010-05-27 20:51:26 +0000905 ssize_t
906 u,
907 v,
908 y;
909
cristye6365592010-04-02 17:31:23 +0000910 /*
911 Create color matrix.
912 */
913 assert(image != (Image *) NULL);
914 assert(image->signature == MagickSignature);
915 if (image->debug != MagickFalse)
916 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
917 assert(exception != (ExceptionInfo *) NULL);
918 assert(exception->signature == MagickSignature);
919 i=0;
cristybb503372010-05-27 20:51:26 +0000920 for (v=0; v < (ssize_t) color_matrix->height; v++)
921 for (u=0; u < (ssize_t) color_matrix->width; u++)
cristye6365592010-04-02 17:31:23 +0000922 {
923 if ((v < 6) && (u < 6))
924 ColorMatrix[v][u]=color_matrix->values[i];
925 i++;
926 }
927 /*
928 Initialize color image.
929 */
cristy12550e62010-06-07 12:46:40 +0000930 color_image=CloneImage(image,0,0,MagickTrue,exception);
cristye6365592010-04-02 17:31:23 +0000931 if (color_image == (Image *) NULL)
932 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000933 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
cristye6365592010-04-02 17:31:23 +0000934 {
cristye6365592010-04-02 17:31:23 +0000935 color_image=DestroyImage(color_image);
936 return((Image *) NULL);
937 }
938 if (image->debug != MagickFalse)
939 {
940 char
941 format[MaxTextExtent],
942 *message;
943
944 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
945 " ColorMatrix image with color matrix:");
946 message=AcquireString("");
947 for (v=0; v < 6; v++)
948 {
949 *message='\0';
cristyb51dff52011-05-19 16:55:47 +0000950 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
cristye6365592010-04-02 17:31:23 +0000951 (void) ConcatenateString(&message,format);
952 for (u=0; u < 6; u++)
953 {
cristyb51dff52011-05-19 16:55:47 +0000954 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
cristye6365592010-04-02 17:31:23 +0000955 ColorMatrix[v][u]);
956 (void) ConcatenateString(&message,format);
957 }
958 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
959 }
960 message=DestroyString(message);
961 }
962 /*
963 ColorMatrix image.
964 */
965 status=MagickTrue;
966 progress=0;
967 image_view=AcquireCacheView(image);
968 color_view=AcquireCacheView(color_image);
969#if defined(MAGICKCORE_OPENMP_SUPPORT)
970 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
971#endif
cristybb503372010-05-27 20:51:26 +0000972 for (y=0; y < (ssize_t) image->rows; y++)
cristye6365592010-04-02 17:31:23 +0000973 {
974 MagickRealType
975 pixel;
976
cristy4c08aed2011-07-01 19:47:50 +0000977 register const Quantum
cristye6365592010-04-02 17:31:23 +0000978 *restrict p;
979
cristy4c08aed2011-07-01 19:47:50 +0000980 register Quantum
981 *restrict q;
982
cristybb503372010-05-27 20:51:26 +0000983 register ssize_t
cristye6365592010-04-02 17:31:23 +0000984 x;
985
cristye6365592010-04-02 17:31:23 +0000986 if (status == MagickFalse)
987 continue;
988 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
989 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
990 exception);
cristy4c08aed2011-07-01 19:47:50 +0000991 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristye6365592010-04-02 17:31:23 +0000992 {
993 status=MagickFalse;
994 continue;
995 }
cristybb503372010-05-27 20:51:26 +0000996 for (x=0; x < (ssize_t) image->columns; x++)
cristye6365592010-04-02 17:31:23 +0000997 {
cristybb503372010-05-27 20:51:26 +0000998 register ssize_t
cristye6365592010-04-02 17:31:23 +0000999 v;
1000
cristybb503372010-05-27 20:51:26 +00001001 size_t
cristye6365592010-04-02 17:31:23 +00001002 height;
1003
1004 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
cristybb503372010-05-27 20:51:26 +00001005 for (v=0; v < (ssize_t) height; v++)
cristye6365592010-04-02 17:31:23 +00001006 {
cristy4c08aed2011-07-01 19:47:50 +00001007 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
1008 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
cristye6365592010-04-02 17:31:23 +00001009 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001010 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
1011 if (image->matte != MagickFalse)
1012 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
cristye6365592010-04-02 17:31:23 +00001013 pixel+=QuantumRange*ColorMatrix[v][5];
1014 switch (v)
1015 {
cristy4c08aed2011-07-01 19:47:50 +00001016 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1017 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1018 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
cristye6365592010-04-02 17:31:23 +00001019 case 3:
1020 {
cristy4c08aed2011-07-01 19:47:50 +00001021 if (image->colorspace == CMYKColorspace)
1022 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
cristye6365592010-04-02 17:31:23 +00001023 break;
1024 }
1025 case 4:
1026 {
cristy4c08aed2011-07-01 19:47:50 +00001027 if (image->matte != MagickFalse)
1028 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
cristye6365592010-04-02 17:31:23 +00001029 break;
1030 }
1031 }
1032 }
cristyed231572011-07-14 02:18:59 +00001033 p+=GetPixelChannels(image);
1034 q+=GetPixelChannels(color_image);
cristye6365592010-04-02 17:31:23 +00001035 }
1036 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1037 status=MagickFalse;
1038 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1039 {
1040 MagickBooleanType
1041 proceed;
1042
1043#if defined(MAGICKCORE_OPENMP_SUPPORT)
1044 #pragma omp critical (MagickCore_ColorMatrixImage)
1045#endif
1046 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1047 image->rows);
1048 if (proceed == MagickFalse)
1049 status=MagickFalse;
1050 }
1051 }
1052 color_view=DestroyCacheView(color_view);
1053 image_view=DestroyCacheView(image_view);
1054 if (status == MagickFalse)
1055 color_image=DestroyImage(color_image);
1056 return(color_image);
1057}
1058
1059/*
1060%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1061% %
1062% %
1063% %
cristy3ed852e2009-09-05 21:47:34 +00001064+ D e s t r o y F x I n f o %
1065% %
1066% %
1067% %
1068%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1069%
1070% DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1071%
1072% The format of the DestroyFxInfo method is:
1073%
1074% ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1075%
1076% A description of each parameter follows:
1077%
1078% o fx_info: the fx info.
1079%
1080*/
cristy7832dc22011-09-05 01:21:53 +00001081MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
cristy3ed852e2009-09-05 21:47:34 +00001082{
cristybb503372010-05-27 20:51:26 +00001083 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001084 i;
1085
1086 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1087 fx_info->expression=DestroyString(fx_info->expression);
1088 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1089 fx_info->colors=DestroySplayTree(fx_info->colors);
cristy0ea377f2011-03-24 00:54:19 +00001090 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
cristyd76c51e2011-03-26 00:21:26 +00001091 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1092 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001093 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1094 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1095 return(fx_info);
1096}
1097
1098/*
1099%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1100% %
1101% %
1102% %
cristy3ed852e2009-09-05 21:47:34 +00001103+ 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 %
1104% %
1105% %
1106% %
1107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1108%
1109% FxEvaluateChannelExpression() evaluates an expression and returns the
1110% results.
1111%
1112% The format of the FxEvaluateExpression method is:
1113%
1114% MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00001115% const PixelChannel channel,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +00001116% MagickRealType *alpha,Exceptioninfo *exception)
1117% MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1118% MagickRealType *alpha,Exceptioninfo *exception)
1119%
1120% A description of each parameter follows:
1121%
1122% o fx_info: the fx info.
1123%
1124% o channel: the channel.
1125%
1126% o x,y: the pixel position.
1127%
1128% o alpha: the result.
1129%
1130% o exception: return any errors or warnings in this structure.
1131%
1132*/
1133
cristy351842f2010-03-07 15:27:38 +00001134static inline double MagickMax(const double x,const double y)
1135{
1136 if (x > y)
1137 return(x);
1138 return(y);
1139}
1140
1141static inline double MagickMin(const double x,const double y)
1142{
1143 if (x < y)
1144 return(x);
1145 return(y);
1146}
1147
cristy3ed852e2009-09-05 21:47:34 +00001148static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
cristy0568ffc2011-07-25 16:54:14 +00001149 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001150{
1151 char
1152 key[MaxTextExtent],
1153 statistic[MaxTextExtent];
1154
1155 const char
1156 *value;
1157
1158 register const char
1159 *p;
1160
1161 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1162 if (*p == '.')
1163 switch (*++p) /* e.g. depth.r */
1164 {
cristy541ae572011-08-05 19:08:59 +00001165 case 'r': channel=RedPixelChannel; break;
1166 case 'g': channel=GreenPixelChannel; break;
1167 case 'b': channel=BluePixelChannel; break;
1168 case 'c': channel=CyanPixelChannel; break;
1169 case 'm': channel=MagentaPixelChannel; break;
1170 case 'y': channel=YellowPixelChannel; break;
1171 case 'k': channel=BlackPixelChannel; break;
cristy3ed852e2009-09-05 21:47:34 +00001172 default: break;
1173 }
cristyb51dff52011-05-19 16:55:47 +00001174 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
cristye8c25f92010-06-03 00:53:06 +00001175 (double) channel,symbol);
cristy3ed852e2009-09-05 21:47:34 +00001176 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1177 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001178 return(QuantumScale*StringToDouble(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001179 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1180 if (LocaleNCompare(symbol,"depth",5) == 0)
1181 {
cristybb503372010-05-27 20:51:26 +00001182 size_t
cristy3ed852e2009-09-05 21:47:34 +00001183 depth;
1184
cristyfefab1b2011-07-05 00:33:22 +00001185 depth=GetImageDepth(image,exception);
1186 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
cristy3ed852e2009-09-05 21:47:34 +00001187 }
1188 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1189 {
1190 double
1191 kurtosis,
1192 skewness;
1193
cristyd42d9952011-07-08 14:21:50 +00001194 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001195 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
cristy3ed852e2009-09-05 21:47:34 +00001196 }
1197 if (LocaleNCompare(symbol,"maxima",6) == 0)
1198 {
1199 double
1200 maxima,
1201 minima;
1202
cristyd42d9952011-07-08 14:21:50 +00001203 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001204 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
cristy3ed852e2009-09-05 21:47:34 +00001205 }
1206 if (LocaleNCompare(symbol,"mean",4) == 0)
1207 {
1208 double
1209 mean,
1210 standard_deviation;
1211
cristyd42d9952011-07-08 14:21:50 +00001212 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001213 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
cristy3ed852e2009-09-05 21:47:34 +00001214 }
1215 if (LocaleNCompare(symbol,"minima",6) == 0)
1216 {
1217 double
1218 maxima,
1219 minima;
1220
cristyd42d9952011-07-08 14:21:50 +00001221 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001222 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
cristy3ed852e2009-09-05 21:47:34 +00001223 }
1224 if (LocaleNCompare(symbol,"skewness",8) == 0)
1225 {
1226 double
1227 kurtosis,
1228 skewness;
1229
cristyd42d9952011-07-08 14:21:50 +00001230 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001231 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
cristy3ed852e2009-09-05 21:47:34 +00001232 }
1233 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1234 {
1235 double
1236 mean,
1237 standard_deviation;
1238
cristyd42d9952011-07-08 14:21:50 +00001239 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001240 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
cristy3ed852e2009-09-05 21:47:34 +00001241 standard_deviation);
1242 }
1243 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1244 ConstantString(statistic));
cristydbdd0e32011-11-04 23:29:40 +00001245 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001246}
1247
1248static MagickRealType
cristy0568ffc2011-07-25 16:54:14 +00001249 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
cristye85007d2010-06-06 22:51:36 +00001250 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +00001251
cristyb0aad4c2011-11-02 19:30:35 +00001252static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1253{
1254 if (beta != 0)
1255 return(FxGCD(beta,alpha % beta));
1256 return(alpha);
1257}
1258
cristy3ed852e2009-09-05 21:47:34 +00001259static inline const char *FxSubexpression(const char *expression,
1260 ExceptionInfo *exception)
1261{
1262 const char
1263 *subexpression;
1264
cristybb503372010-05-27 20:51:26 +00001265 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001266 level;
1267
1268 level=0;
1269 subexpression=expression;
1270 while ((*subexpression != '\0') &&
1271 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1272 {
1273 if (strchr("(",(int) *subexpression) != (char *) NULL)
1274 level++;
1275 else
1276 if (strchr(")",(int) *subexpression) != (char *) NULL)
1277 level--;
1278 subexpression++;
1279 }
1280 if (*subexpression == '\0')
1281 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1282 "UnbalancedParenthesis","`%s'",expression);
1283 return(subexpression);
1284}
1285
cristy0568ffc2011-07-25 16:54:14 +00001286static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001287 const ssize_t x,const ssize_t y,const char *expression,
1288 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001289{
1290 char
1291 *q,
1292 subexpression[MaxTextExtent],
1293 symbol[MaxTextExtent];
1294
1295 const char
1296 *p,
1297 *value;
1298
1299 Image
1300 *image;
1301
cristy4c08aed2011-07-01 19:47:50 +00001302 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001303 pixel;
1304
1305 MagickRealType
1306 alpha,
1307 beta;
1308
1309 PointInfo
1310 point;
1311
cristybb503372010-05-27 20:51:26 +00001312 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001313 i;
1314
1315 size_t
1316 length;
1317
cristybb503372010-05-27 20:51:26 +00001318 size_t
cristy3ed852e2009-09-05 21:47:34 +00001319 level;
1320
1321 p=expression;
1322 i=GetImageIndexInList(fx_info->images);
1323 level=0;
1324 point.x=(double) x;
1325 point.y=(double) y;
1326 if (isalpha((int) *(p+1)) == 0)
1327 {
1328 if (strchr("suv",(int) *p) != (char *) NULL)
1329 {
1330 switch (*p)
1331 {
1332 case 's':
1333 default:
1334 {
1335 i=GetImageIndexInList(fx_info->images);
1336 break;
1337 }
1338 case 'u': i=0; break;
1339 case 'v': i=1; break;
1340 }
1341 p++;
1342 if (*p == '[')
1343 {
1344 level++;
1345 q=subexpression;
1346 for (p++; *p != '\0'; )
1347 {
1348 if (*p == '[')
1349 level++;
1350 else
1351 if (*p == ']')
1352 {
1353 level--;
1354 if (level == 0)
1355 break;
1356 }
1357 *q++=(*p++);
1358 }
1359 *q='\0';
1360 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1361 &beta,exception);
cristybb503372010-05-27 20:51:26 +00001362 i=(ssize_t) (alpha+0.5);
cristy3ed852e2009-09-05 21:47:34 +00001363 p++;
1364 }
1365 if (*p == '.')
1366 p++;
1367 }
1368 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1369 {
1370 p++;
1371 if (*p == '{')
1372 {
1373 level++;
1374 q=subexpression;
1375 for (p++; *p != '\0'; )
1376 {
1377 if (*p == '{')
1378 level++;
1379 else
1380 if (*p == '}')
1381 {
1382 level--;
1383 if (level == 0)
1384 break;
1385 }
1386 *q++=(*p++);
1387 }
1388 *q='\0';
1389 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1390 &beta,exception);
1391 point.x=alpha;
1392 point.y=beta;
1393 p++;
1394 }
1395 else
1396 if (*p == '[')
1397 {
1398 level++;
1399 q=subexpression;
1400 for (p++; *p != '\0'; )
1401 {
1402 if (*p == '[')
1403 level++;
1404 else
1405 if (*p == ']')
1406 {
1407 level--;
1408 if (level == 0)
1409 break;
1410 }
1411 *q++=(*p++);
1412 }
1413 *q='\0';
1414 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1415 &beta,exception);
1416 point.x+=alpha;
1417 point.y+=beta;
1418 p++;
1419 }
1420 if (*p == '.')
1421 p++;
1422 }
1423 }
1424 length=GetImageListLength(fx_info->images);
1425 while (i < 0)
cristybb503372010-05-27 20:51:26 +00001426 i+=(ssize_t) length;
cristy3ed852e2009-09-05 21:47:34 +00001427 i%=length;
1428 image=GetImageFromList(fx_info->images,i);
1429 if (image == (Image *) NULL)
1430 {
1431 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1432 "NoSuchImage","`%s'",expression);
1433 return(0.0);
1434 }
cristy4c08aed2011-07-01 19:47:50 +00001435 GetPixelInfo(image,&pixel);
1436 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
cristy4f820712011-04-01 12:35:43 +00001437 point.x,point.y,&pixel,exception);
cristy3ed852e2009-09-05 21:47:34 +00001438 if ((strlen(p) > 2) &&
1439 (LocaleCompare(p,"intensity") != 0) &&
1440 (LocaleCompare(p,"luminance") != 0) &&
1441 (LocaleCompare(p,"hue") != 0) &&
1442 (LocaleCompare(p,"saturation") != 0) &&
1443 (LocaleCompare(p,"lightness") != 0))
1444 {
1445 char
1446 name[MaxTextExtent];
1447
1448 (void) CopyMagickString(name,p,MaxTextExtent);
1449 for (q=name+(strlen(name)-1); q > name; q--)
1450 {
1451 if (*q == ')')
1452 break;
1453 if (*q == '.')
1454 {
1455 *q='\0';
1456 break;
1457 }
1458 }
1459 if ((strlen(name) > 2) &&
1460 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1461 {
cristy4c08aed2011-07-01 19:47:50 +00001462 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001463 *color;
1464
cristy4c08aed2011-07-01 19:47:50 +00001465 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1466 if (color != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001467 {
1468 pixel=(*color);
1469 p+=strlen(name);
1470 }
1471 else
cristy269c9412011-10-13 23:41:15 +00001472 if (QueryColorCompliance(name,AllCompliance,&pixel,fx_info->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001473 {
1474 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
cristy4c08aed2011-07-01 19:47:50 +00001475 ClonePixelInfo(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001476 p+=strlen(name);
1477 }
1478 }
1479 }
1480 (void) CopyMagickString(symbol,p,MaxTextExtent);
1481 StripString(symbol);
1482 if (*symbol == '\0')
1483 {
1484 switch (channel)
1485 {
cristy0568ffc2011-07-25 16:54:14 +00001486 case RedPixelChannel: return(QuantumScale*pixel.red);
1487 case GreenPixelChannel: return(QuantumScale*pixel.green);
1488 case BluePixelChannel: return(QuantumScale*pixel.blue);
1489 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001490 {
1491 if (image->colorspace != CMYKColorspace)
1492 {
1493 (void) ThrowMagickException(exception,GetMagickModule(),
cristy1a020e42011-12-06 18:13:23 +00001494 ImageError,"ColorSeparatedImageRequired","`%s'",
cristy3ed852e2009-09-05 21:47:34 +00001495 image->filename);
1496 return(0.0);
1497 }
cristy4c08aed2011-07-01 19:47:50 +00001498 return(QuantumScale*pixel.black);
1499 }
cristy0568ffc2011-07-25 16:54:14 +00001500 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001501 {
1502 MagickRealType
1503 alpha;
1504
1505 if (pixel.matte == MagickFalse)
1506 return(1.0);
1507 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1508 return(alpha);
cristy3ed852e2009-09-05 21:47:34 +00001509 }
cristya382aca2011-12-06 18:22:48 +00001510 case IndexPixelChannel:
1511 return(0.0);
cristyb3a73b52011-07-26 01:34:43 +00001512 case IntensityPixelChannel:
cristyf364ed42010-12-15 01:54:43 +00001513 {
cristy4c08aed2011-07-01 19:47:50 +00001514 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristyf364ed42010-12-15 01:54:43 +00001515 }
cristy3ed852e2009-09-05 21:47:34 +00001516 default:
1517 break;
1518 }
1519 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1520 "UnableToParseExpression","`%s'",p);
1521 return(0.0);
1522 }
1523 switch (*symbol)
1524 {
1525 case 'A':
1526 case 'a':
1527 {
1528 if (LocaleCompare(symbol,"a") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001529 return((MagickRealType) (QuantumScale*pixel.alpha));
cristy3ed852e2009-09-05 21:47:34 +00001530 break;
1531 }
1532 case 'B':
1533 case 'b':
1534 {
1535 if (LocaleCompare(symbol,"b") == 0)
1536 return(QuantumScale*pixel.blue);
1537 break;
1538 }
1539 case 'C':
1540 case 'c':
1541 {
1542 if (LocaleNCompare(symbol,"channel",7) == 0)
1543 {
1544 GeometryInfo
1545 channel_info;
1546
1547 MagickStatusType
1548 flags;
1549
1550 flags=ParseGeometry(symbol+7,&channel_info);
1551 if (image->colorspace == CMYKColorspace)
1552 switch (channel)
1553 {
cristy0568ffc2011-07-25 16:54:14 +00001554 case CyanPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001555 {
1556 if ((flags & RhoValue) == 0)
1557 return(0.0);
1558 return(channel_info.rho);
1559 }
cristy0568ffc2011-07-25 16:54:14 +00001560 case MagentaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001561 {
1562 if ((flags & SigmaValue) == 0)
1563 return(0.0);
1564 return(channel_info.sigma);
1565 }
cristy0568ffc2011-07-25 16:54:14 +00001566 case YellowPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001567 {
1568 if ((flags & XiValue) == 0)
1569 return(0.0);
1570 return(channel_info.xi);
1571 }
cristy0568ffc2011-07-25 16:54:14 +00001572 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001573 {
1574 if ((flags & PsiValue) == 0)
1575 return(0.0);
1576 return(channel_info.psi);
1577 }
cristy0568ffc2011-07-25 16:54:14 +00001578 case AlphaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001579 {
1580 if ((flags & ChiValue) == 0)
1581 return(0.0);
1582 return(channel_info.chi);
1583 }
1584 default:
1585 return(0.0);
1586 }
1587 switch (channel)
1588 {
cristy0568ffc2011-07-25 16:54:14 +00001589 case RedPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001590 {
1591 if ((flags & RhoValue) == 0)
1592 return(0.0);
1593 return(channel_info.rho);
1594 }
cristy0568ffc2011-07-25 16:54:14 +00001595 case GreenPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001596 {
1597 if ((flags & SigmaValue) == 0)
1598 return(0.0);
1599 return(channel_info.sigma);
1600 }
cristy0568ffc2011-07-25 16:54:14 +00001601 case BluePixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001602 {
1603 if ((flags & XiValue) == 0)
1604 return(0.0);
1605 return(channel_info.xi);
1606 }
cristy0568ffc2011-07-25 16:54:14 +00001607 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001608 {
1609 if ((flags & ChiValue) == 0)
1610 return(0.0);
1611 return(channel_info.chi);
1612 }
cristy0568ffc2011-07-25 16:54:14 +00001613 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001614 {
1615 if ((flags & PsiValue) == 0)
1616 return(0.0);
1617 return(channel_info.psi);
1618 }
cristy3ed852e2009-09-05 21:47:34 +00001619 default:
1620 return(0.0);
1621 }
1622 return(0.0);
1623 }
1624 if (LocaleCompare(symbol,"c") == 0)
1625 return(QuantumScale*pixel.red);
1626 break;
1627 }
1628 case 'D':
1629 case 'd':
1630 {
1631 if (LocaleNCompare(symbol,"depth",5) == 0)
1632 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1633 break;
1634 }
1635 case 'G':
1636 case 'g':
1637 {
1638 if (LocaleCompare(symbol,"g") == 0)
1639 return(QuantumScale*pixel.green);
1640 break;
1641 }
1642 case 'K':
1643 case 'k':
1644 {
1645 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1646 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1647 if (LocaleCompare(symbol,"k") == 0)
1648 {
1649 if (image->colorspace != CMYKColorspace)
1650 {
1651 (void) ThrowMagickException(exception,GetMagickModule(),
1652 OptionError,"ColorSeparatedImageRequired","`%s'",
1653 image->filename);
1654 return(0.0);
1655 }
cristy4c08aed2011-07-01 19:47:50 +00001656 return(QuantumScale*pixel.black);
cristy3ed852e2009-09-05 21:47:34 +00001657 }
1658 break;
1659 }
1660 case 'H':
1661 case 'h':
1662 {
1663 if (LocaleCompare(symbol,"h") == 0)
1664 return((MagickRealType) image->rows);
1665 if (LocaleCompare(symbol,"hue") == 0)
1666 {
1667 double
1668 hue,
1669 lightness,
1670 saturation;
1671
cristyda1f9c12011-10-02 21:39:49 +00001672 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1673 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001674 return(hue);
1675 }
1676 break;
1677 }
1678 case 'I':
1679 case 'i':
1680 {
1681 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1682 (LocaleCompare(symbol,"image.minima") == 0) ||
1683 (LocaleCompare(symbol,"image.maxima") == 0) ||
1684 (LocaleCompare(symbol,"image.mean") == 0) ||
1685 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1686 (LocaleCompare(symbol,"image.skewness") == 0) ||
1687 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1688 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1689 if (LocaleCompare(symbol,"image.resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001690 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001691 if (LocaleCompare(symbol,"image.resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001692 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001693 if (LocaleCompare(symbol,"intensity") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001694 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001695 if (LocaleCompare(symbol,"i") == 0)
1696 return((MagickRealType) x);
1697 break;
1698 }
1699 case 'J':
1700 case 'j':
1701 {
1702 if (LocaleCompare(symbol,"j") == 0)
1703 return((MagickRealType) y);
1704 break;
1705 }
1706 case 'L':
1707 case 'l':
1708 {
1709 if (LocaleCompare(symbol,"lightness") == 0)
1710 {
1711 double
1712 hue,
1713 lightness,
1714 saturation;
1715
cristyda1f9c12011-10-02 21:39:49 +00001716 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1717 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001718 return(lightness);
1719 }
1720 if (LocaleCompare(symbol,"luminance") == 0)
1721 {
1722 double
1723 luminence;
1724
1725 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1726 return(QuantumScale*luminence);
1727 }
1728 break;
1729 }
1730 case 'M':
1731 case 'm':
1732 {
1733 if (LocaleNCompare(symbol,"maxima",6) == 0)
1734 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1735 if (LocaleNCompare(symbol,"mean",4) == 0)
1736 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1737 if (LocaleNCompare(symbol,"minima",6) == 0)
1738 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1739 if (LocaleCompare(symbol,"m") == 0)
1740 return(QuantumScale*pixel.blue);
1741 break;
1742 }
1743 case 'N':
1744 case 'n':
1745 {
1746 if (LocaleCompare(symbol,"n") == 0)
anthony374f5dd2011-03-25 10:08:53 +00001747 return((MagickRealType) GetImageListLength(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001748 break;
1749 }
1750 case 'O':
1751 case 'o':
1752 {
1753 if (LocaleCompare(symbol,"o") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001754 return(QuantumScale*pixel.alpha);
cristy3ed852e2009-09-05 21:47:34 +00001755 break;
1756 }
1757 case 'P':
1758 case 'p':
1759 {
1760 if (LocaleCompare(symbol,"page.height") == 0)
1761 return((MagickRealType) image->page.height);
1762 if (LocaleCompare(symbol,"page.width") == 0)
1763 return((MagickRealType) image->page.width);
1764 if (LocaleCompare(symbol,"page.x") == 0)
1765 return((MagickRealType) image->page.x);
1766 if (LocaleCompare(symbol,"page.y") == 0)
1767 return((MagickRealType) image->page.y);
1768 break;
1769 }
1770 case 'R':
1771 case 'r':
1772 {
1773 if (LocaleCompare(symbol,"resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001774 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001775 if (LocaleCompare(symbol,"resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001776 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001777 if (LocaleCompare(symbol,"r") == 0)
1778 return(QuantumScale*pixel.red);
1779 break;
1780 }
1781 case 'S':
1782 case 's':
1783 {
1784 if (LocaleCompare(symbol,"saturation") == 0)
1785 {
1786 double
1787 hue,
1788 lightness,
1789 saturation;
1790
cristyda1f9c12011-10-02 21:39:49 +00001791 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1792 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001793 return(saturation);
1794 }
1795 if (LocaleNCompare(symbol,"skewness",8) == 0)
1796 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1797 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1798 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1799 break;
1800 }
1801 case 'T':
1802 case 't':
1803 {
1804 if (LocaleCompare(symbol,"t") == 0)
cristy5a15b932011-03-26 12:50:33 +00001805 return((MagickRealType) GetImageIndexInList(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001806 break;
1807 }
1808 case 'W':
1809 case 'w':
1810 {
1811 if (LocaleCompare(symbol,"w") == 0)
1812 return((MagickRealType) image->columns);
1813 break;
1814 }
1815 case 'Y':
1816 case 'y':
1817 {
1818 if (LocaleCompare(symbol,"y") == 0)
1819 return(QuantumScale*pixel.green);
1820 break;
1821 }
1822 case 'Z':
1823 case 'z':
1824 {
1825 if (LocaleCompare(symbol,"z") == 0)
1826 {
1827 MagickRealType
1828 depth;
1829
cristyfefab1b2011-07-05 00:33:22 +00001830 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001831 return(depth);
1832 }
1833 break;
1834 }
1835 default:
1836 break;
1837 }
1838 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1839 if (value != (const char *) NULL)
cristydbdd0e32011-11-04 23:29:40 +00001840 return((MagickRealType) StringToDouble(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001841 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1842 "UnableToParseExpression","`%s'",symbol);
1843 return(0.0);
1844}
1845
1846static const char *FxOperatorPrecedence(const char *expression,
1847 ExceptionInfo *exception)
1848{
1849 typedef enum
1850 {
1851 UndefinedPrecedence,
1852 NullPrecedence,
1853 BitwiseComplementPrecedence,
1854 ExponentPrecedence,
cristy116af162010-08-13 01:25:47 +00001855 ExponentialNotationPrecedence,
cristy3ed852e2009-09-05 21:47:34 +00001856 MultiplyPrecedence,
1857 AdditionPrecedence,
1858 ShiftPrecedence,
1859 RelationalPrecedence,
1860 EquivalencyPrecedence,
1861 BitwiseAndPrecedence,
1862 BitwiseOrPrecedence,
1863 LogicalAndPrecedence,
1864 LogicalOrPrecedence,
1865 TernaryPrecedence,
1866 AssignmentPrecedence,
1867 CommaPrecedence,
1868 SeparatorPrecedence
1869 } FxPrecedence;
1870
1871 FxPrecedence
1872 precedence,
1873 target;
1874
1875 register const char
1876 *subexpression;
1877
1878 register int
1879 c;
1880
cristybb503372010-05-27 20:51:26 +00001881 size_t
cristy3ed852e2009-09-05 21:47:34 +00001882 level;
1883
1884 c=0;
1885 level=0;
1886 subexpression=(const char *) NULL;
1887 target=NullPrecedence;
1888 while (*expression != '\0')
1889 {
1890 precedence=UndefinedPrecedence;
1891 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1892 {
1893 expression++;
1894 continue;
1895 }
cristy488fa882010-03-01 22:34:24 +00001896 switch (*expression)
1897 {
1898 case 'A':
1899 case 'a':
cristy3ed852e2009-09-05 21:47:34 +00001900 {
cristyb33454f2011-08-03 02:10:45 +00001901#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00001902 if (LocaleNCompare(expression,"acosh",5) == 0)
1903 {
1904 expression+=5;
1905 break;
1906 }
cristyb33454f2011-08-03 02:10:45 +00001907#endif
1908#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00001909 if (LocaleNCompare(expression,"asinh",5) == 0)
1910 {
1911 expression+=5;
1912 break;
1913 }
cristyb33454f2011-08-03 02:10:45 +00001914#endif
1915#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00001916 if (LocaleNCompare(expression,"atanh",5) == 0)
cristy488fa882010-03-01 22:34:24 +00001917 {
1918 expression+=5;
1919 break;
1920 }
cristyb33454f2011-08-03 02:10:45 +00001921#endif
cristy488fa882010-03-01 22:34:24 +00001922 break;
cristy3ed852e2009-09-05 21:47:34 +00001923 }
cristy62d455f2011-11-03 11:42:28 +00001924 case 'E':
1925 case 'e':
1926 {
1927 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1928 (LocaleNCompare(expression,"E-",2) == 0))
1929 {
1930 expression+=2; /* scientific notation */
1931 break;
1932 }
1933 }
cristy488fa882010-03-01 22:34:24 +00001934 case 'J':
1935 case 'j':
1936 {
1937 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1938 (LocaleNCompare(expression,"j1",2) == 0))
1939 {
1940 expression+=2;
1941 break;
1942 }
1943 break;
1944 }
cristy2def9322010-06-18 23:59:37 +00001945 case '#':
1946 {
1947 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1948 expression++;
1949 break;
1950 }
cristy488fa882010-03-01 22:34:24 +00001951 default:
1952 break;
1953 }
cristy3ed852e2009-09-05 21:47:34 +00001954 if ((c == (int) '{') || (c == (int) '['))
1955 level++;
1956 else
1957 if ((c == (int) '}') || (c == (int) ']'))
1958 level--;
1959 if (level == 0)
1960 switch ((unsigned char) *expression)
1961 {
1962 case '~':
1963 case '!':
1964 {
1965 precedence=BitwiseComplementPrecedence;
1966 break;
1967 }
1968 case '^':
cristy6621e252010-08-13 00:42:57 +00001969 case '@':
cristy3ed852e2009-09-05 21:47:34 +00001970 {
1971 precedence=ExponentPrecedence;
1972 break;
1973 }
1974 default:
1975 {
1976 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1977 (strchr(")",c) != (char *) NULL))) &&
1978 (((islower((int) ((char) *expression)) != 0) ||
1979 (strchr("(",(int) *expression) != (char *) NULL)) ||
1980 ((isdigit((int) ((char) c)) == 0) &&
1981 (isdigit((int) ((char) *expression)) != 0))) &&
1982 (strchr("xy",(int) *expression) == (char *) NULL))
1983 precedence=MultiplyPrecedence;
1984 break;
1985 }
1986 case '*':
1987 case '/':
1988 case '%':
1989 {
1990 precedence=MultiplyPrecedence;
1991 break;
1992 }
1993 case '+':
1994 case '-':
1995 {
1996 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
1997 (isalpha(c) != 0))
1998 precedence=AdditionPrecedence;
1999 break;
2000 }
2001 case LeftShiftOperator:
2002 case RightShiftOperator:
2003 {
2004 precedence=ShiftPrecedence;
2005 break;
2006 }
2007 case '<':
2008 case LessThanEqualOperator:
2009 case GreaterThanEqualOperator:
2010 case '>':
2011 {
2012 precedence=RelationalPrecedence;
2013 break;
2014 }
2015 case EqualOperator:
2016 case NotEqualOperator:
2017 {
2018 precedence=EquivalencyPrecedence;
2019 break;
2020 }
2021 case '&':
2022 {
2023 precedence=BitwiseAndPrecedence;
2024 break;
2025 }
2026 case '|':
2027 {
2028 precedence=BitwiseOrPrecedence;
2029 break;
2030 }
2031 case LogicalAndOperator:
2032 {
2033 precedence=LogicalAndPrecedence;
2034 break;
2035 }
2036 case LogicalOrOperator:
2037 {
2038 precedence=LogicalOrPrecedence;
2039 break;
2040 }
cristy116af162010-08-13 01:25:47 +00002041 case ExponentialNotation:
2042 {
2043 precedence=ExponentialNotationPrecedence;
2044 break;
2045 }
cristy3ed852e2009-09-05 21:47:34 +00002046 case ':':
2047 case '?':
2048 {
2049 precedence=TernaryPrecedence;
2050 break;
2051 }
2052 case '=':
2053 {
2054 precedence=AssignmentPrecedence;
2055 break;
2056 }
2057 case ',':
2058 {
2059 precedence=CommaPrecedence;
2060 break;
2061 }
2062 case ';':
2063 {
2064 precedence=SeparatorPrecedence;
2065 break;
2066 }
2067 }
2068 if ((precedence == BitwiseComplementPrecedence) ||
2069 (precedence == TernaryPrecedence) ||
2070 (precedence == AssignmentPrecedence))
2071 {
2072 if (precedence > target)
2073 {
2074 /*
2075 Right-to-left associativity.
2076 */
2077 target=precedence;
2078 subexpression=expression;
2079 }
2080 }
2081 else
2082 if (precedence >= target)
2083 {
2084 /*
2085 Left-to-right associativity.
2086 */
2087 target=precedence;
2088 subexpression=expression;
2089 }
2090 if (strchr("(",(int) *expression) != (char *) NULL)
2091 expression=FxSubexpression(expression,exception);
2092 c=(int) (*expression++);
2093 }
2094 return(subexpression);
2095}
2096
2097static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002098 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristye85007d2010-06-06 22:51:36 +00002099 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002100{
2101 char
2102 *q,
2103 subexpression[MaxTextExtent];
2104
2105 MagickRealType
2106 alpha,
2107 gamma;
2108
2109 register const char
2110 *p;
2111
2112 *beta=0.0;
2113 if (exception->severity != UndefinedException)
2114 return(0.0);
2115 while (isspace((int) *expression) != 0)
2116 expression++;
2117 if (*expression == '\0')
2118 {
2119 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2120 "MissingExpression","`%s'",expression);
2121 return(0.0);
2122 }
cristy66322f02010-05-17 11:40:48 +00002123 *subexpression='\0';
cristy3ed852e2009-09-05 21:47:34 +00002124 p=FxOperatorPrecedence(expression,exception);
2125 if (p != (const char *) NULL)
2126 {
2127 (void) CopyMagickString(subexpression,expression,(size_t)
2128 (p-expression+1));
2129 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2130 exception);
2131 switch ((unsigned char) *p)
2132 {
2133 case '~':
2134 {
2135 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002136 *beta=(MagickRealType) (~(size_t) *beta);
cristy3ed852e2009-09-05 21:47:34 +00002137 return(*beta);
2138 }
2139 case '!':
2140 {
2141 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2142 return(*beta == 0.0 ? 1.0 : 0.0);
2143 }
2144 case '^':
2145 {
2146 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2147 channel,x,y,++p,beta,exception));
2148 return(*beta);
2149 }
2150 case '*':
cristy116af162010-08-13 01:25:47 +00002151 case ExponentialNotation:
cristy3ed852e2009-09-05 21:47:34 +00002152 {
2153 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2154 return(alpha*(*beta));
2155 }
2156 case '/':
2157 {
2158 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2159 if (*beta == 0.0)
2160 {
2161 if (exception->severity == UndefinedException)
2162 (void) ThrowMagickException(exception,GetMagickModule(),
2163 OptionError,"DivideByZero","`%s'",expression);
2164 return(0.0);
2165 }
2166 return(alpha/(*beta));
2167 }
2168 case '%':
2169 {
2170 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2171 *beta=fabs(floor(((double) *beta)+0.5));
2172 if (*beta == 0.0)
2173 {
2174 (void) ThrowMagickException(exception,GetMagickModule(),
2175 OptionError,"DivideByZero","`%s'",expression);
2176 return(0.0);
2177 }
2178 return(fmod((double) alpha,(double) *beta));
2179 }
2180 case '+':
2181 {
2182 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2183 return(alpha+(*beta));
2184 }
2185 case '-':
2186 {
2187 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2188 return(alpha-(*beta));
2189 }
2190 case LeftShiftOperator:
2191 {
2192 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002193 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002194 (gamma+0.5));
2195 return(*beta);
2196 }
2197 case RightShiftOperator:
2198 {
2199 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002200 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002201 (gamma+0.5));
2202 return(*beta);
2203 }
2204 case '<':
2205 {
2206 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2207 return(alpha < *beta ? 1.0 : 0.0);
2208 }
2209 case LessThanEqualOperator:
2210 {
2211 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2212 return(alpha <= *beta ? 1.0 : 0.0);
2213 }
2214 case '>':
2215 {
2216 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2217 return(alpha > *beta ? 1.0 : 0.0);
2218 }
2219 case GreaterThanEqualOperator:
2220 {
2221 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2222 return(alpha >= *beta ? 1.0 : 0.0);
2223 }
2224 case EqualOperator:
2225 {
2226 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2227 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2228 }
2229 case NotEqualOperator:
2230 {
2231 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2232 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2233 }
2234 case '&':
2235 {
2236 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002237 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002238 (gamma+0.5));
2239 return(*beta);
2240 }
2241 case '|':
2242 {
2243 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002244 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002245 (gamma+0.5));
2246 return(*beta);
2247 }
2248 case LogicalAndOperator:
2249 {
2250 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2251 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2252 return(*beta);
2253 }
2254 case LogicalOrOperator:
2255 {
2256 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2257 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2258 return(*beta);
2259 }
2260 case '?':
2261 {
2262 MagickRealType
2263 gamma;
2264
2265 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2266 q=subexpression;
2267 p=StringToken(":",&q);
2268 if (q == (char *) NULL)
2269 {
2270 (void) ThrowMagickException(exception,GetMagickModule(),
2271 OptionError,"UnableToParseExpression","`%s'",subexpression);
2272 return(0.0);
2273 }
2274 if (fabs((double) alpha) > MagickEpsilon)
2275 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2276 else
2277 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2278 return(gamma);
2279 }
2280 case '=':
2281 {
2282 char
2283 numeric[MaxTextExtent];
2284
2285 q=subexpression;
2286 while (isalpha((int) ((unsigned char) *q)) != 0)
2287 q++;
2288 if (*q != '\0')
2289 {
2290 (void) ThrowMagickException(exception,GetMagickModule(),
2291 OptionError,"UnableToParseExpression","`%s'",subexpression);
2292 return(0.0);
2293 }
2294 ClearMagickException(exception);
2295 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristyb51dff52011-05-19 16:55:47 +00002296 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
cristy8cd5b312010-01-07 01:10:24 +00002297 *beta);
cristy3ed852e2009-09-05 21:47:34 +00002298 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2299 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2300 subexpression),ConstantString(numeric));
2301 return(*beta);
2302 }
2303 case ',':
2304 {
2305 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2306 return(alpha);
2307 }
2308 case ';':
2309 {
2310 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2311 return(*beta);
2312 }
2313 default:
2314 {
2315 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2316 exception);
2317 return(gamma);
2318 }
2319 }
2320 }
2321 if (strchr("(",(int) *expression) != (char *) NULL)
2322 {
2323 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2324 subexpression[strlen(subexpression)-1]='\0';
2325 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2326 exception);
2327 return(gamma);
2328 }
cristy8b8a3ae2010-10-23 18:49:46 +00002329 switch (*expression)
cristy3ed852e2009-09-05 21:47:34 +00002330 {
2331 case '+':
2332 {
2333 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2334 exception);
2335 return(1.0*gamma);
2336 }
2337 case '-':
2338 {
2339 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2340 exception);
2341 return(-1.0*gamma);
2342 }
2343 case '~':
2344 {
2345 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2346 exception);
cristybb503372010-05-27 20:51:26 +00002347 return((MagickRealType) (~(size_t) (gamma+0.5)));
cristy3ed852e2009-09-05 21:47:34 +00002348 }
2349 case 'A':
2350 case 'a':
2351 {
2352 if (LocaleNCompare(expression,"abs",3) == 0)
2353 {
2354 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2355 exception);
2356 return((MagickRealType) fabs((double) alpha));
2357 }
cristyb33454f2011-08-03 02:10:45 +00002358#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00002359 if (LocaleNCompare(expression,"acosh",5) == 0)
2360 {
2361 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2362 exception);
2363 return((MagickRealType) acosh((double) alpha));
2364 }
cristyb33454f2011-08-03 02:10:45 +00002365#endif
cristy3ed852e2009-09-05 21:47:34 +00002366 if (LocaleNCompare(expression,"acos",4) == 0)
2367 {
2368 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2369 exception);
2370 return((MagickRealType) acos((double) alpha));
2371 }
cristy43c22f42010-03-30 12:34:07 +00002372#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002373 if (LocaleNCompare(expression,"airy",4) == 0)
2374 {
2375 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2376 exception);
2377 if (alpha == 0.0)
cristy2dd03222010-03-30 22:12:11 +00002378 return(1.0);
2379 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
cristy43c22f42010-03-30 12:34:07 +00002380 return(gamma*gamma);
cristyee56cf12010-03-01 22:17:06 +00002381 }
cristy43c22f42010-03-30 12:34:07 +00002382#endif
cristyb33454f2011-08-03 02:10:45 +00002383#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00002384 if (LocaleNCompare(expression,"asinh",5) == 0)
2385 {
2386 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2387 exception);
2388 return((MagickRealType) asinh((double) alpha));
2389 }
cristyb33454f2011-08-03 02:10:45 +00002390#endif
cristy3ed852e2009-09-05 21:47:34 +00002391 if (LocaleNCompare(expression,"asin",4) == 0)
2392 {
2393 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2394 exception);
2395 return((MagickRealType) asin((double) alpha));
2396 }
2397 if (LocaleNCompare(expression,"alt",3) == 0)
2398 {
2399 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2400 exception);
cristybb503372010-05-27 20:51:26 +00002401 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
cristy3ed852e2009-09-05 21:47:34 +00002402 }
2403 if (LocaleNCompare(expression,"atan2",5) == 0)
2404 {
2405 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2406 exception);
2407 return((MagickRealType) atan2((double) alpha,(double) *beta));
2408 }
cristyb33454f2011-08-03 02:10:45 +00002409#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00002410 if (LocaleNCompare(expression,"atanh",5) == 0)
2411 {
2412 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2413 exception);
2414 return((MagickRealType) atanh((double) alpha));
2415 }
cristyb33454f2011-08-03 02:10:45 +00002416#endif
cristy3ed852e2009-09-05 21:47:34 +00002417 if (LocaleNCompare(expression,"atan",4) == 0)
2418 {
2419 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2420 exception);
2421 return((MagickRealType) atan((double) alpha));
2422 }
2423 if (LocaleCompare(expression,"a") == 0)
2424 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2425 break;
2426 }
2427 case 'B':
2428 case 'b':
2429 {
2430 if (LocaleCompare(expression,"b") == 0)
2431 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2432 break;
2433 }
2434 case 'C':
2435 case 'c':
2436 {
2437 if (LocaleNCompare(expression,"ceil",4) == 0)
2438 {
2439 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2440 exception);
2441 return((MagickRealType) ceil((double) alpha));
2442 }
2443 if (LocaleNCompare(expression,"cosh",4) == 0)
2444 {
2445 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2446 exception);
2447 return((MagickRealType) cosh((double) alpha));
2448 }
2449 if (LocaleNCompare(expression,"cos",3) == 0)
2450 {
2451 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2452 exception);
2453 return((MagickRealType) cos((double) alpha));
2454 }
2455 if (LocaleCompare(expression,"c") == 0)
2456 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2457 break;
2458 }
2459 case 'D':
2460 case 'd':
2461 {
2462 if (LocaleNCompare(expression,"debug",5) == 0)
2463 {
2464 const char
2465 *type;
2466
2467 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2468 exception);
2469 if (fx_info->images->colorspace == CMYKColorspace)
2470 switch (channel)
2471 {
cristy0568ffc2011-07-25 16:54:14 +00002472 case CyanPixelChannel: type="cyan"; break;
2473 case MagentaPixelChannel: type="magenta"; break;
2474 case YellowPixelChannel: type="yellow"; break;
2475 case AlphaPixelChannel: type="opacity"; break;
2476 case BlackPixelChannel: type="black"; break;
cristy3ed852e2009-09-05 21:47:34 +00002477 default: type="unknown"; break;
2478 }
2479 else
2480 switch (channel)
2481 {
cristy0568ffc2011-07-25 16:54:14 +00002482 case RedPixelChannel: type="red"; break;
2483 case GreenPixelChannel: type="green"; break;
2484 case BluePixelChannel: type="blue"; break;
2485 case AlphaPixelChannel: type="opacity"; break;
cristy3ed852e2009-09-05 21:47:34 +00002486 default: type="unknown"; break;
2487 }
2488 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2489 if (strlen(subexpression) > 1)
2490 subexpression[strlen(subexpression)-1]='\0';
2491 if (fx_info->file != (FILE *) NULL)
cristy1e604812011-05-19 18:07:50 +00002492 (void) FormatLocaleFile(fx_info->file,
2493 "%s[%.20g,%.20g].%s: %s=%.*g\n",fx_info->images->filename,
2494 (double) x,(double) y,type,subexpression,GetMagickPrecision(),
2495 (double) alpha);
cristy3ed852e2009-09-05 21:47:34 +00002496 return(0.0);
2497 }
cristy5597a8d2011-11-04 00:25:32 +00002498 if (LocaleNCompare(expression,"drc",3) == 0)
2499 {
2500 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2501 exception);
2502 return((MagickRealType) (alpha/(*beta*(alpha-1.0)+1.0)));
2503 }
cristy3ed852e2009-09-05 21:47:34 +00002504 break;
2505 }
2506 case 'E':
2507 case 'e':
2508 {
2509 if (LocaleCompare(expression,"epsilon") == 0)
2510 return((MagickRealType) MagickEpsilon);
2511 if (LocaleNCompare(expression,"exp",3) == 0)
2512 {
2513 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2514 exception);
2515 return((MagickRealType) exp((double) alpha));
2516 }
2517 if (LocaleCompare(expression,"e") == 0)
2518 return((MagickRealType) 2.7182818284590452354);
2519 break;
2520 }
2521 case 'F':
2522 case 'f':
2523 {
2524 if (LocaleNCompare(expression,"floor",5) == 0)
2525 {
2526 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2527 exception);
2528 return((MagickRealType) floor((double) alpha));
2529 }
2530 break;
2531 }
2532 case 'G':
2533 case 'g':
2534 {
cristy9eeedea2011-11-02 19:04:05 +00002535 if (LocaleNCompare(expression,"gauss",5) == 0)
2536 {
2537 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2538 exception);
2539 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
2540 return((MagickRealType) gamma);
2541 }
cristyb0aad4c2011-11-02 19:30:35 +00002542 if (LocaleNCompare(expression,"gcd",3) == 0)
2543 {
2544 MagickOffsetType
2545 gcd;
2546
2547 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2548 exception);
cristy76461162011-11-02 19:32:19 +00002549 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType)
2550 (*beta+0.5));
cristyb0aad4c2011-11-02 19:30:35 +00002551 return((MagickRealType) gcd);
2552 }
cristy3ed852e2009-09-05 21:47:34 +00002553 if (LocaleCompare(expression,"g") == 0)
2554 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2555 break;
2556 }
2557 case 'H':
2558 case 'h':
2559 {
2560 if (LocaleCompare(expression,"h") == 0)
2561 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2562 if (LocaleCompare(expression,"hue") == 0)
2563 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2564 if (LocaleNCompare(expression,"hypot",5) == 0)
2565 {
2566 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2567 exception);
2568 return((MagickRealType) hypot((double) alpha,(double) *beta));
2569 }
2570 break;
2571 }
2572 case 'K':
2573 case 'k':
2574 {
2575 if (LocaleCompare(expression,"k") == 0)
2576 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2577 break;
2578 }
2579 case 'I':
2580 case 'i':
2581 {
2582 if (LocaleCompare(expression,"intensity") == 0)
2583 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2584 if (LocaleNCompare(expression,"int",3) == 0)
2585 {
2586 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2587 exception);
cristy16788e42010-08-13 13:44:26 +00002588 return((MagickRealType) floor(alpha));
cristy3ed852e2009-09-05 21:47:34 +00002589 }
cristy82b20722011-11-05 21:52:36 +00002590#if defined(MAGICKCORE_HAVE_ISNAN)
cristy639399c2011-11-02 19:16:15 +00002591 if (LocaleNCompare(expression,"isnan",5) == 0)
2592 {
2593 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2594 exception);
cristy17a10202011-11-02 19:17:04 +00002595 return((MagickRealType) !!isnan((double) alpha));
cristy639399c2011-11-02 19:16:15 +00002596 }
cristy82b20722011-11-05 21:52:36 +00002597#endif
cristy3ed852e2009-09-05 21:47:34 +00002598 if (LocaleCompare(expression,"i") == 0)
2599 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2600 break;
2601 }
2602 case 'J':
2603 case 'j':
2604 {
2605 if (LocaleCompare(expression,"j") == 0)
2606 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
cristy161b9262010-03-20 19:34:32 +00002607#if defined(MAGICKCORE_HAVE_J0)
cristyee56cf12010-03-01 22:17:06 +00002608 if (LocaleNCompare(expression,"j0",2) == 0)
2609 {
2610 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2611 exception);
2612 return((MagickRealType) j0((double) alpha));
2613 }
cristy161b9262010-03-20 19:34:32 +00002614#endif
2615#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002616 if (LocaleNCompare(expression,"j1",2) == 0)
2617 {
2618 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2619 exception);
2620 return((MagickRealType) j1((double) alpha));
2621 }
cristy161b9262010-03-20 19:34:32 +00002622#endif
cristyaa018fa2010-04-08 23:03:54 +00002623#if defined(MAGICKCORE_HAVE_J1)
cristya6a09e72010-03-02 14:51:02 +00002624 if (LocaleNCompare(expression,"jinc",4) == 0)
2625 {
2626 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2627 exception);
cristy0946a822010-03-12 17:14:58 +00002628 if (alpha == 0.0)
2629 return(1.0);
cristy69928f92010-03-12 13:27:09 +00002630 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
cristyfce2f7b2010-03-12 00:29:49 +00002631 (MagickPI*alpha));
2632 return(gamma);
cristya6a09e72010-03-02 14:51:02 +00002633 }
cristyaa018fa2010-04-08 23:03:54 +00002634#endif
cristy3ed852e2009-09-05 21:47:34 +00002635 break;
2636 }
2637 case 'L':
2638 case 'l':
2639 {
2640 if (LocaleNCompare(expression,"ln",2) == 0)
2641 {
2642 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2643 exception);
2644 return((MagickRealType) log((double) alpha));
2645 }
cristyc8ed5322010-08-31 12:07:59 +00002646 if (LocaleNCompare(expression,"logtwo",6) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002647 {
cristyc8ed5322010-08-31 12:07:59 +00002648 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
cristy3ed852e2009-09-05 21:47:34 +00002649 exception);
2650 return((MagickRealType) log10((double) alpha))/log10(2.0);
2651 }
2652 if (LocaleNCompare(expression,"log",3) == 0)
2653 {
2654 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2655 exception);
2656 return((MagickRealType) log10((double) alpha));
2657 }
2658 if (LocaleCompare(expression,"lightness") == 0)
2659 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2660 break;
2661 }
2662 case 'M':
2663 case 'm':
2664 {
2665 if (LocaleCompare(expression,"MaxRGB") == 0)
2666 return((MagickRealType) QuantumRange);
2667 if (LocaleNCompare(expression,"maxima",6) == 0)
2668 break;
2669 if (LocaleNCompare(expression,"max",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002670 {
2671 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2672 exception);
2673 return(alpha > *beta ? alpha : *beta);
2674 }
cristy3ed852e2009-09-05 21:47:34 +00002675 if (LocaleNCompare(expression,"minima",6) == 0)
2676 break;
2677 if (LocaleNCompare(expression,"min",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002678 {
2679 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2680 exception);
2681 return(alpha < *beta ? alpha : *beta);
2682 }
cristy3ed852e2009-09-05 21:47:34 +00002683 if (LocaleNCompare(expression,"mod",3) == 0)
2684 {
2685 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2686 exception);
cristy984049c2011-11-03 18:34:58 +00002687 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2688 return(gamma);
cristy3ed852e2009-09-05 21:47:34 +00002689 }
2690 if (LocaleCompare(expression,"m") == 0)
2691 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2692 break;
2693 }
2694 case 'N':
2695 case 'n':
2696 {
cristyad3502e2011-11-02 19:10:45 +00002697 if (LocaleNCompare(expression,"not",3) == 0)
2698 {
2699 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2700 exception);
2701 return((MagickRealType) (alpha < MagickEpsilon));
2702 }
cristy3ed852e2009-09-05 21:47:34 +00002703 if (LocaleCompare(expression,"n") == 0)
2704 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2705 break;
2706 }
2707 case 'O':
2708 case 'o':
2709 {
2710 if (LocaleCompare(expression,"Opaque") == 0)
2711 return(1.0);
2712 if (LocaleCompare(expression,"o") == 0)
2713 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2714 break;
2715 }
2716 case 'P':
2717 case 'p':
2718 {
cristy670aa3c2011-11-03 00:54:00 +00002719 if (LocaleCompare(expression,"phi") == 0)
2720 return((MagickRealType) MagickPHI);
cristy3ed852e2009-09-05 21:47:34 +00002721 if (LocaleCompare(expression,"pi") == 0)
2722 return((MagickRealType) MagickPI);
2723 if (LocaleNCompare(expression,"pow",3) == 0)
2724 {
2725 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2726 exception);
2727 return((MagickRealType) pow((double) alpha,(double) *beta));
2728 }
2729 if (LocaleCompare(expression,"p") == 0)
2730 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2731 break;
2732 }
2733 case 'Q':
2734 case 'q':
2735 {
2736 if (LocaleCompare(expression,"QuantumRange") == 0)
2737 return((MagickRealType) QuantumRange);
2738 if (LocaleCompare(expression,"QuantumScale") == 0)
2739 return((MagickRealType) QuantumScale);
2740 break;
2741 }
2742 case 'R':
2743 case 'r':
2744 {
2745 if (LocaleNCompare(expression,"rand",4) == 0)
2746 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2747 if (LocaleNCompare(expression,"round",5) == 0)
2748 {
2749 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2750 exception);
cristy16788e42010-08-13 13:44:26 +00002751 return((MagickRealType) floor((double) alpha+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002752 }
2753 if (LocaleCompare(expression,"r") == 0)
2754 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2755 break;
2756 }
2757 case 'S':
2758 case 's':
2759 {
2760 if (LocaleCompare(expression,"saturation") == 0)
2761 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2762 if (LocaleNCompare(expression,"sign",4) == 0)
2763 {
2764 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2765 exception);
2766 return(alpha < 0.0 ? -1.0 : 1.0);
2767 }
cristya6a09e72010-03-02 14:51:02 +00002768 if (LocaleNCompare(expression,"sinc",4) == 0)
2769 {
2770 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2771 exception);
2772 if (alpha == 0)
2773 return(1.0);
2774 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2775 (MagickPI*alpha));
2776 return(gamma);
2777 }
cristy3ed852e2009-09-05 21:47:34 +00002778 if (LocaleNCompare(expression,"sinh",4) == 0)
2779 {
2780 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2781 exception);
2782 return((MagickRealType) sinh((double) alpha));
2783 }
2784 if (LocaleNCompare(expression,"sin",3) == 0)
2785 {
2786 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2787 exception);
2788 return((MagickRealType) sin((double) alpha));
2789 }
2790 if (LocaleNCompare(expression,"sqrt",4) == 0)
2791 {
2792 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2793 exception);
2794 return((MagickRealType) sqrt((double) alpha));
2795 }
cristy9eeedea2011-11-02 19:04:05 +00002796 if (LocaleNCompare(expression,"squish",6) == 0)
2797 {
2798 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2799 exception);
2800 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2801 }
cristy3ed852e2009-09-05 21:47:34 +00002802 if (LocaleCompare(expression,"s") == 0)
2803 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2804 break;
2805 }
2806 case 'T':
2807 case 't':
2808 {
2809 if (LocaleNCompare(expression,"tanh",4) == 0)
2810 {
2811 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2812 exception);
2813 return((MagickRealType) tanh((double) alpha));
2814 }
2815 if (LocaleNCompare(expression,"tan",3) == 0)
2816 {
2817 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2818 exception);
2819 return((MagickRealType) tan((double) alpha));
2820 }
2821 if (LocaleCompare(expression,"Transparent") == 0)
2822 return(0.0);
cristy16788e42010-08-13 13:44:26 +00002823 if (LocaleNCompare(expression,"trunc",5) == 0)
2824 {
2825 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2826 exception);
2827 if (alpha >= 0.0)
2828 return((MagickRealType) floor((double) alpha));
2829 return((MagickRealType) ceil((double) alpha));
2830 }
cristy3ed852e2009-09-05 21:47:34 +00002831 if (LocaleCompare(expression,"t") == 0)
2832 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2833 break;
2834 }
2835 case 'U':
2836 case 'u':
2837 {
2838 if (LocaleCompare(expression,"u") == 0)
2839 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2840 break;
2841 }
2842 case 'V':
2843 case 'v':
2844 {
2845 if (LocaleCompare(expression,"v") == 0)
2846 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2847 break;
2848 }
2849 case 'W':
2850 case 'w':
2851 {
cristy9eeedea2011-11-02 19:04:05 +00002852 if (LocaleNCompare(expression,"while",5) == 0)
2853 {
2854 do
2855 {
2856 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2857 exception);
2858 } while (fabs((double) alpha) >= MagickEpsilon);
2859 return((MagickRealType) *beta);
2860 }
cristy3ed852e2009-09-05 21:47:34 +00002861 if (LocaleCompare(expression,"w") == 0)
2862 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2863 break;
2864 }
2865 case 'Y':
2866 case 'y':
2867 {
2868 if (LocaleCompare(expression,"y") == 0)
2869 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2870 break;
2871 }
2872 case 'Z':
2873 case 'z':
2874 {
2875 if (LocaleCompare(expression,"z") == 0)
2876 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2877 break;
2878 }
2879 default:
2880 break;
2881 }
2882 q=(char *) expression;
cristydbdd0e32011-11-04 23:29:40 +00002883 alpha=InterpretSiPrefixValue(expression,&q);
cristy3ed852e2009-09-05 21:47:34 +00002884 if (q == expression)
2885 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2886 return(alpha);
2887}
2888
cristy7832dc22011-09-05 01:21:53 +00002889MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
cristy3ed852e2009-09-05 21:47:34 +00002890 MagickRealType *alpha,ExceptionInfo *exception)
2891{
2892 MagickBooleanType
2893 status;
2894
cristy541ae572011-08-05 19:08:59 +00002895 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2896 exception);
cristy3ed852e2009-09-05 21:47:34 +00002897 return(status);
2898}
2899
2900MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2901 MagickRealType *alpha,ExceptionInfo *exception)
2902{
2903 FILE
2904 *file;
2905
2906 MagickBooleanType
2907 status;
2908
2909 file=fx_info->file;
2910 fx_info->file=(FILE *) NULL;
cristy541ae572011-08-05 19:08:59 +00002911 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2912 exception);
cristy3ed852e2009-09-05 21:47:34 +00002913 fx_info->file=file;
2914 return(status);
2915}
2916
cristy7832dc22011-09-05 01:21:53 +00002917MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002918 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristye85007d2010-06-06 22:51:36 +00002919 MagickRealType *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002920{
2921 MagickRealType
2922 beta;
2923
2924 beta=0.0;
2925 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2926 exception);
2927 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2928}
2929
2930/*
2931%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2932% %
2933% %
2934% %
2935% F x I m a g e %
2936% %
2937% %
2938% %
2939%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2940%
2941% FxImage() applies a mathematical expression to the specified image.
2942%
2943% The format of the FxImage method is:
2944%
2945% Image *FxImage(const Image *image,const char *expression,
2946% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002947%
2948% A description of each parameter follows:
2949%
2950% o image: the image.
2951%
cristy3ed852e2009-09-05 21:47:34 +00002952% o expression: A mathematical expression.
2953%
2954% o exception: return any errors or warnings in this structure.
2955%
2956*/
2957
2958static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2959{
cristybb503372010-05-27 20:51:26 +00002960 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002961 i;
2962
2963 assert(fx_info != (FxInfo **) NULL);
cristybb503372010-05-27 20:51:26 +00002964 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
cristy3ed852e2009-09-05 21:47:34 +00002965 if (fx_info[i] != (FxInfo *) NULL)
2966 fx_info[i]=DestroyFxInfo(fx_info[i]);
cristyb41ee102010-10-04 16:46:15 +00002967 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00002968 return(fx_info);
2969}
2970
2971static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2972 ExceptionInfo *exception)
2973{
2974 char
2975 *fx_expression;
2976
2977 FxInfo
2978 **fx_info;
2979
2980 MagickRealType
2981 alpha;
2982
cristybb503372010-05-27 20:51:26 +00002983 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002984 i;
2985
cristybb503372010-05-27 20:51:26 +00002986 size_t
cristy3ed852e2009-09-05 21:47:34 +00002987 number_threads;
2988
2989 number_threads=GetOpenMPMaximumThreads();
cristyb41ee102010-10-04 16:46:15 +00002990 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +00002991 if (fx_info == (FxInfo **) NULL)
2992 return((FxInfo **) NULL);
2993 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
2994 if (*expression != '@')
2995 fx_expression=ConstantString(expression);
2996 else
2997 fx_expression=FileToString(expression+1,~0,exception);
cristybb503372010-05-27 20:51:26 +00002998 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +00002999 {
3000 fx_info[i]=AcquireFxInfo(image,fx_expression);
3001 if (fx_info[i] == (FxInfo *) NULL)
3002 return(DestroyFxThreadSet(fx_info));
3003 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
3004 }
3005 fx_expression=DestroyString(fx_expression);
3006 return(fx_info);
3007}
3008
3009MagickExport Image *FxImage(const Image *image,const char *expression,
3010 ExceptionInfo *exception)
3011{
cristy3ed852e2009-09-05 21:47:34 +00003012#define FxImageTag "Fx/Image"
3013
cristyfa112112010-01-04 17:48:07 +00003014 CacheView
cristy79cedc72011-07-25 00:41:15 +00003015 *fx_view,
3016 *image_view;
cristyfa112112010-01-04 17:48:07 +00003017
cristy3ed852e2009-09-05 21:47:34 +00003018 FxInfo
cristyfa112112010-01-04 17:48:07 +00003019 **restrict fx_info;
cristy3ed852e2009-09-05 21:47:34 +00003020
3021 Image
3022 *fx_image;
3023
cristy3ed852e2009-09-05 21:47:34 +00003024 MagickBooleanType
3025 status;
3026
cristybb503372010-05-27 20:51:26 +00003027 MagickOffsetType
3028 progress;
3029
cristy3ed852e2009-09-05 21:47:34 +00003030 MagickRealType
3031 alpha;
3032
cristybb503372010-05-27 20:51:26 +00003033 ssize_t
3034 y;
3035
cristy3ed852e2009-09-05 21:47:34 +00003036 assert(image != (Image *) NULL);
3037 assert(image->signature == MagickSignature);
3038 if (image->debug != MagickFalse)
3039 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy79cedc72011-07-25 00:41:15 +00003040 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00003041 if (fx_image == (Image *) NULL)
3042 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003043 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003044 {
cristy3ed852e2009-09-05 21:47:34 +00003045 fx_image=DestroyImage(fx_image);
3046 return((Image *) NULL);
3047 }
3048 fx_info=AcquireFxThreadSet(image,expression,exception);
3049 if (fx_info == (FxInfo **) NULL)
3050 {
3051 fx_image=DestroyImage(fx_image);
3052 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3053 }
3054 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3055 if (status == MagickFalse)
3056 {
3057 fx_image=DestroyImage(fx_image);
3058 fx_info=DestroyFxThreadSet(fx_info);
3059 return((Image *) NULL);
3060 }
3061 /*
3062 Fx image.
3063 */
3064 status=MagickTrue;
3065 progress=0;
cristy79cedc72011-07-25 00:41:15 +00003066 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003067 fx_view=AcquireCacheView(fx_image);
cristyb5d5f722009-11-04 03:03:49 +00003068#if defined(MAGICKCORE_OPENMP_SUPPORT)
3069 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003070#endif
cristybb503372010-05-27 20:51:26 +00003071 for (y=0; y < (ssize_t) fx_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003072 {
cristy5c9e6f22010-09-17 17:31:01 +00003073 const int
3074 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00003075
cristy79cedc72011-07-25 00:41:15 +00003076 register const Quantum
3077 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003078
cristy4c08aed2011-07-01 19:47:50 +00003079 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003080 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003081
cristy79cedc72011-07-25 00:41:15 +00003082 register ssize_t
3083 x;
3084
cristy3ed852e2009-09-05 21:47:34 +00003085 if (status == MagickFalse)
3086 continue;
cristy79cedc72011-07-25 00:41:15 +00003087 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003088 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
cristy79cedc72011-07-25 00:41:15 +00003089 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003090 {
3091 status=MagickFalse;
3092 continue;
3093 }
cristybb503372010-05-27 20:51:26 +00003094 for (x=0; x < (ssize_t) fx_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003095 {
cristy79cedc72011-07-25 00:41:15 +00003096 register ssize_t
3097 i;
3098
3099 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3100 {
3101 MagickRealType
3102 alpha;
3103
3104 PixelChannel
3105 channel;
3106
3107 PixelTrait
3108 fx_traits,
3109 traits;
3110
cristye2a912b2011-12-05 20:02:07 +00003111 traits=GetPixelChannelMapTraits(image,i);
3112 channel=GetPixelChannelMapChannel(image,i);
cristy79cedc72011-07-25 00:41:15 +00003113 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
cristy010d7d12011-08-31 01:02:48 +00003114 if ((traits == UndefinedPixelTrait) ||
3115 (fx_traits == UndefinedPixelTrait))
cristy79cedc72011-07-25 00:41:15 +00003116 continue;
3117 if ((fx_traits & CopyPixelTrait) != 0)
3118 {
cristy0beccfa2011-09-25 20:47:53 +00003119 SetPixelChannel(fx_image,channel,p[i],q);
cristy79cedc72011-07-25 00:41:15 +00003120 continue;
3121 }
3122 alpha=0.0;
cristya382aca2011-12-06 18:22:48 +00003123 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3124 exception);
cristyb3a73b52011-07-26 01:34:43 +00003125 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
cristy79cedc72011-07-25 00:41:15 +00003126 }
3127 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003128 q+=GetPixelChannels(fx_image);
cristy3ed852e2009-09-05 21:47:34 +00003129 }
3130 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3131 status=MagickFalse;
3132 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3133 {
3134 MagickBooleanType
3135 proceed;
3136
cristyb5d5f722009-11-04 03:03:49 +00003137#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy490408a2011-07-07 14:42:05 +00003138 #pragma omp critical (MagickCore_FxImage)
cristy3ed852e2009-09-05 21:47:34 +00003139#endif
3140 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3141 if (proceed == MagickFalse)
3142 status=MagickFalse;
3143 }
3144 }
cristy3ed852e2009-09-05 21:47:34 +00003145 fx_view=DestroyCacheView(fx_view);
cristy79cedc72011-07-25 00:41:15 +00003146 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003147 fx_info=DestroyFxThreadSet(fx_info);
3148 if (status == MagickFalse)
3149 fx_image=DestroyImage(fx_image);
3150 return(fx_image);
3151}
3152
3153/*
3154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3155% %
3156% %
3157% %
3158% I m p l o d e I m a g e %
3159% %
3160% %
3161% %
3162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3163%
3164% ImplodeImage() creates a new image that is a copy of an existing
3165% one with the image pixels "implode" by the specified percentage. It
3166% allocates the memory necessary for the new Image structure and returns a
3167% pointer to the new image.
3168%
3169% The format of the ImplodeImage method is:
3170%
3171% Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003172% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003173%
3174% A description of each parameter follows:
3175%
3176% o implode_image: Method ImplodeImage returns a pointer to the image
3177% after it is implode. A null image is returned if there is a memory
3178% shortage.
3179%
3180% o image: the image.
3181%
3182% o amount: Define the extent of the implosion.
3183%
cristy76f512e2011-09-12 01:26:56 +00003184% o method: the pixel interpolation method.
3185%
cristy3ed852e2009-09-05 21:47:34 +00003186% o exception: return any errors or warnings in this structure.
3187%
3188*/
3189MagickExport Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003190 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003191{
3192#define ImplodeImageTag "Implode/Image"
3193
cristyfa112112010-01-04 17:48:07 +00003194 CacheView
3195 *image_view,
3196 *implode_view;
3197
cristy3ed852e2009-09-05 21:47:34 +00003198 Image
3199 *implode_image;
3200
cristy3ed852e2009-09-05 21:47:34 +00003201 MagickBooleanType
3202 status;
3203
cristybb503372010-05-27 20:51:26 +00003204 MagickOffsetType
3205 progress;
3206
cristy3ed852e2009-09-05 21:47:34 +00003207 MagickRealType
3208 radius;
3209
3210 PointInfo
3211 center,
3212 scale;
3213
cristybb503372010-05-27 20:51:26 +00003214 ssize_t
3215 y;
3216
cristy3ed852e2009-09-05 21:47:34 +00003217 /*
3218 Initialize implode image attributes.
3219 */
3220 assert(image != (Image *) NULL);
3221 assert(image->signature == MagickSignature);
3222 if (image->debug != MagickFalse)
3223 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3224 assert(exception != (ExceptionInfo *) NULL);
3225 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00003226 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3227 exception);
cristy3ed852e2009-09-05 21:47:34 +00003228 if (implode_image == (Image *) NULL)
3229 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003230 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003231 {
cristy3ed852e2009-09-05 21:47:34 +00003232 implode_image=DestroyImage(implode_image);
3233 return((Image *) NULL);
3234 }
cristy4c08aed2011-07-01 19:47:50 +00003235 if (implode_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00003236 implode_image->matte=MagickTrue;
3237 /*
3238 Compute scaling factor.
3239 */
3240 scale.x=1.0;
3241 scale.y=1.0;
3242 center.x=0.5*image->columns;
3243 center.y=0.5*image->rows;
3244 radius=center.x;
3245 if (image->columns > image->rows)
3246 scale.y=(double) image->columns/(double) image->rows;
3247 else
3248 if (image->columns < image->rows)
3249 {
3250 scale.x=(double) image->rows/(double) image->columns;
3251 radius=center.y;
3252 }
3253 /*
3254 Implode image.
3255 */
3256 status=MagickTrue;
3257 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00003258 image_view=AcquireCacheView(image);
3259 implode_view=AcquireCacheView(implode_image);
cristyb5d5f722009-11-04 03:03:49 +00003260#if defined(MAGICKCORE_OPENMP_SUPPORT)
3261 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003262#endif
cristybb503372010-05-27 20:51:26 +00003263 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003264 {
cristy3ed852e2009-09-05 21:47:34 +00003265 MagickRealType
3266 distance;
3267
3268 PointInfo
3269 delta;
3270
cristy6d188022011-09-12 13:23:33 +00003271 register const Quantum
3272 *restrict p;
3273
cristybb503372010-05-27 20:51:26 +00003274 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003275 x;
3276
cristy4c08aed2011-07-01 19:47:50 +00003277 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003278 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003279
3280 if (status == MagickFalse)
3281 continue;
cristy6d188022011-09-12 13:23:33 +00003282 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003283 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3284 exception);
cristy6d188022011-09-12 13:23:33 +00003285 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003286 {
3287 status=MagickFalse;
3288 continue;
3289 }
cristy3ed852e2009-09-05 21:47:34 +00003290 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00003291 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003292 {
cristy6d188022011-09-12 13:23:33 +00003293 register ssize_t
3294 i;
3295
cristy3ed852e2009-09-05 21:47:34 +00003296 /*
3297 Determine if the pixel is within an ellipse.
3298 */
3299 delta.x=scale.x*(double) (x-center.x);
3300 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00003301 if (distance >= (radius*radius))
3302 {
3303 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3304 q[i]=p[i];
3305 }
3306 else
cristy3ed852e2009-09-05 21:47:34 +00003307 {
3308 double
3309 factor;
3310
3311 /*
3312 Implode the pixel.
3313 */
3314 factor=1.0;
3315 if (distance > 0.0)
3316 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3317 radius/2)),-amount);
cristy76f512e2011-09-12 01:26:56 +00003318 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3319 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3320 scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00003321 }
cristy6d188022011-09-12 13:23:33 +00003322 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003323 q+=GetPixelChannels(implode_image);
cristy3ed852e2009-09-05 21:47:34 +00003324 }
3325 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3326 status=MagickFalse;
3327 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3328 {
3329 MagickBooleanType
3330 proceed;
3331
cristyb5d5f722009-11-04 03:03:49 +00003332#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003333 #pragma omp critical (MagickCore_ImplodeImage)
3334#endif
3335 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3336 if (proceed == MagickFalse)
3337 status=MagickFalse;
3338 }
3339 }
3340 implode_view=DestroyCacheView(implode_view);
3341 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003342 if (status == MagickFalse)
3343 implode_image=DestroyImage(implode_image);
3344 return(implode_image);
3345}
3346
3347/*
3348%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3349% %
3350% %
3351% %
3352% M o r p h I m a g e s %
3353% %
3354% %
3355% %
3356%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3357%
3358% The MorphImages() method requires a minimum of two images. The first
3359% image is transformed into the second by a number of intervening images
3360% as specified by frames.
3361%
3362% The format of the MorphImage method is:
3363%
cristybb503372010-05-27 20:51:26 +00003364% Image *MorphImages(const Image *image,const size_t number_frames,
cristy3ed852e2009-09-05 21:47:34 +00003365% ExceptionInfo *exception)
3366%
3367% A description of each parameter follows:
3368%
3369% o image: the image.
3370%
3371% o number_frames: Define the number of in-between image to generate.
3372% The more in-between frames, the smoother the morph.
3373%
3374% o exception: return any errors or warnings in this structure.
3375%
3376*/
3377MagickExport Image *MorphImages(const Image *image,
cristybb503372010-05-27 20:51:26 +00003378 const size_t number_frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003379{
3380#define MorphImageTag "Morph/Image"
3381
3382 Image
3383 *morph_image,
3384 *morph_images;
3385
cristy9d314ff2011-03-09 01:30:28 +00003386 MagickBooleanType
3387 status;
cristy3ed852e2009-09-05 21:47:34 +00003388
3389 MagickOffsetType
3390 scene;
3391
3392 MagickRealType
3393 alpha,
3394 beta;
3395
3396 register const Image
3397 *next;
3398
cristybb503372010-05-27 20:51:26 +00003399 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003400 i;
3401
cristy9d314ff2011-03-09 01:30:28 +00003402 ssize_t
3403 y;
cristy3ed852e2009-09-05 21:47:34 +00003404
3405 /*
3406 Clone first frame in sequence.
3407 */
3408 assert(image != (Image *) NULL);
3409 assert(image->signature == MagickSignature);
3410 if (image->debug != MagickFalse)
3411 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3412 assert(exception != (ExceptionInfo *) NULL);
3413 assert(exception->signature == MagickSignature);
3414 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3415 if (morph_images == (Image *) NULL)
3416 return((Image *) NULL);
3417 if (GetNextImageInList(image) == (Image *) NULL)
3418 {
3419 /*
3420 Morph single image.
3421 */
cristybb503372010-05-27 20:51:26 +00003422 for (i=1; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003423 {
3424 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3425 if (morph_image == (Image *) NULL)
3426 {
3427 morph_images=DestroyImageList(morph_images);
3428 return((Image *) NULL);
3429 }
3430 AppendImageToList(&morph_images,morph_image);
cristy8b27a6d2010-02-14 03:31:15 +00003431 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003432 {
cristy8b27a6d2010-02-14 03:31:15 +00003433 MagickBooleanType
3434 proceed;
3435
cristybb503372010-05-27 20:51:26 +00003436 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3437 number_frames);
cristy8b27a6d2010-02-14 03:31:15 +00003438 if (proceed == MagickFalse)
3439 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003440 }
3441 }
3442 return(GetFirstImageInList(morph_images));
3443 }
3444 /*
3445 Morph image sequence.
3446 */
3447 status=MagickTrue;
3448 scene=0;
3449 next=image;
3450 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3451 {
cristybb503372010-05-27 20:51:26 +00003452 for (i=0; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003453 {
3454 CacheView
3455 *image_view,
3456 *morph_view;
3457
3458 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3459 alpha=1.0-beta;
cristy15b98cd2010-09-12 19:42:50 +00003460 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
cristybb503372010-05-27 20:51:26 +00003461 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
cristy15b98cd2010-09-12 19:42:50 +00003462 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3463 next->filter,next->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003464 if (morph_image == (Image *) NULL)
3465 {
3466 morph_images=DestroyImageList(morph_images);
3467 return((Image *) NULL);
3468 }
cristy574cc262011-08-05 01:23:58 +00003469 if (SetImageStorageClass(morph_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003470 {
cristy3ed852e2009-09-05 21:47:34 +00003471 morph_image=DestroyImage(morph_image);
3472 return((Image *) NULL);
3473 }
3474 AppendImageToList(&morph_images,morph_image);
3475 morph_images=GetLastImageInList(morph_images);
cristy15b98cd2010-09-12 19:42:50 +00003476 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3477 morph_images->rows,GetNextImageInList(next)->filter,
3478 GetNextImageInList(next)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003479 if (morph_image == (Image *) NULL)
3480 {
3481 morph_images=DestroyImageList(morph_images);
3482 return((Image *) NULL);
3483 }
3484 image_view=AcquireCacheView(morph_image);
3485 morph_view=AcquireCacheView(morph_images);
cristyb5d5f722009-11-04 03:03:49 +00003486#if defined(MAGICKCORE_OPENMP_SUPPORT)
3487 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003488#endif
cristybb503372010-05-27 20:51:26 +00003489 for (y=0; y < (ssize_t) morph_images->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003490 {
3491 MagickBooleanType
3492 sync;
3493
cristy4c08aed2011-07-01 19:47:50 +00003494 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00003495 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003496
cristybb503372010-05-27 20:51:26 +00003497 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003498 x;
3499
cristy4c08aed2011-07-01 19:47:50 +00003500 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003501 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003502
3503 if (status == MagickFalse)
3504 continue;
3505 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3506 exception);
3507 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3508 exception);
cristy4c08aed2011-07-01 19:47:50 +00003509 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003510 {
3511 status=MagickFalse;
3512 continue;
3513 }
cristybb503372010-05-27 20:51:26 +00003514 for (x=0; x < (ssize_t) morph_images->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003515 {
cristy4c08aed2011-07-01 19:47:50 +00003516 SetPixelRed(morph_images,ClampToQuantum(alpha*
3517 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3518 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3519 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3520 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3521 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3522 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3523 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3524 if ((morph_image->colorspace == CMYKColorspace) &&
3525 (morph_images->colorspace == CMYKColorspace))
3526 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3527 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3528 q);
cristyed231572011-07-14 02:18:59 +00003529 p+=GetPixelChannels(morph_image);
3530 q+=GetPixelChannels(morph_images);
cristy3ed852e2009-09-05 21:47:34 +00003531 }
3532 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3533 if (sync == MagickFalse)
3534 status=MagickFalse;
3535 }
3536 morph_view=DestroyCacheView(morph_view);
3537 image_view=DestroyCacheView(image_view);
3538 morph_image=DestroyImage(morph_image);
3539 }
cristybb503372010-05-27 20:51:26 +00003540 if (i < (ssize_t) number_frames)
cristy3ed852e2009-09-05 21:47:34 +00003541 break;
3542 /*
3543 Clone last frame in sequence.
3544 */
3545 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3546 if (morph_image == (Image *) NULL)
3547 {
3548 morph_images=DestroyImageList(morph_images);
3549 return((Image *) NULL);
3550 }
3551 AppendImageToList(&morph_images,morph_image);
3552 morph_images=GetLastImageInList(morph_images);
3553 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3554 {
3555 MagickBooleanType
3556 proceed;
3557
cristyb5d5f722009-11-04 03:03:49 +00003558#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003559 #pragma omp critical (MagickCore_MorphImages)
3560#endif
3561 proceed=SetImageProgress(image,MorphImageTag,scene,
3562 GetImageListLength(image));
3563 if (proceed == MagickFalse)
3564 status=MagickFalse;
3565 }
3566 scene++;
3567 }
3568 if (GetNextImageInList(next) != (Image *) NULL)
3569 {
3570 morph_images=DestroyImageList(morph_images);
3571 return((Image *) NULL);
3572 }
3573 return(GetFirstImageInList(morph_images));
3574}
3575
3576/*
3577%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3578% %
3579% %
3580% %
3581% P l a s m a I m a g e %
3582% %
3583% %
3584% %
3585%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3586%
3587% PlasmaImage() initializes an image with plasma fractal values. The image
3588% must be initialized with a base color and the random number generator
3589% seeded before this method is called.
3590%
3591% The format of the PlasmaImage method is:
3592%
3593% MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
cristy5cbc0162011-08-29 00:36:28 +00003594% size_t attenuate,size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003595%
3596% A description of each parameter follows:
3597%
3598% o image: the image.
3599%
3600% o segment: Define the region to apply plasma fractals values.
3601%
glennrp7dae1ca2010-09-16 12:17:35 +00003602% o attenuate: Define the plasma attenuation factor.
cristy3ed852e2009-09-05 21:47:34 +00003603%
3604% o depth: Limit the plasma recursion depth.
3605%
cristy5cbc0162011-08-29 00:36:28 +00003606% o exception: return any errors or warnings in this structure.
3607%
cristy3ed852e2009-09-05 21:47:34 +00003608*/
3609
3610static inline Quantum PlasmaPixel(RandomInfo *random_info,
3611 const MagickRealType pixel,const MagickRealType noise)
3612{
3613 Quantum
3614 plasma;
3615
cristyce70c172010-01-07 17:15:30 +00003616 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
cristy3ed852e2009-09-05 21:47:34 +00003617 noise/2.0);
3618 return(plasma);
3619}
3620
cristyda1f9c12011-10-02 21:39:49 +00003621static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3622 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3623 const SegmentInfo *segment,size_t attenuate,size_t depth,
3624 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003625{
cristy3ed852e2009-09-05 21:47:34 +00003626 MagickRealType
3627 plasma;
3628
cristyda1f9c12011-10-02 21:39:49 +00003629 PixelChannel
3630 channel;
3631
3632 PixelTrait
3633 traits;
3634
3635 register const Quantum
3636 *restrict u,
3637 *restrict v;
3638
3639 register Quantum
3640 *restrict q;
3641
3642 register ssize_t
3643 i;
cristy3ed852e2009-09-05 21:47:34 +00003644
cristy9d314ff2011-03-09 01:30:28 +00003645 ssize_t
3646 x,
3647 x_mid,
3648 y,
3649 y_mid;
3650
cristy3ed852e2009-09-05 21:47:34 +00003651 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3652 return(MagickTrue);
3653 if (depth != 0)
3654 {
3655 SegmentInfo
3656 local_info;
3657
3658 /*
3659 Divide the area into quadrants and recurse.
3660 */
3661 depth--;
3662 attenuate++;
cristybb503372010-05-27 20:51:26 +00003663 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3664 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003665 local_info=(*segment);
3666 local_info.x2=(double) x_mid;
3667 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003668 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3669 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003670 local_info=(*segment);
3671 local_info.y1=(double) y_mid;
3672 local_info.x2=(double) x_mid;
cristyda1f9c12011-10-02 21:39:49 +00003673 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3674 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003675 local_info=(*segment);
3676 local_info.x1=(double) x_mid;
3677 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003678 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3679 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003680 local_info=(*segment);
3681 local_info.x1=(double) x_mid;
3682 local_info.y1=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003683 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3684 &local_info,attenuate,depth,exception));
cristy3ed852e2009-09-05 21:47:34 +00003685 }
cristybb503372010-05-27 20:51:26 +00003686 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3687 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003688 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3689 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3690 return(MagickFalse);
3691 /*
3692 Average pixels and apply plasma.
3693 */
cristy3ed852e2009-09-05 21:47:34 +00003694 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3695 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3696 {
cristy3ed852e2009-09-05 21:47:34 +00003697 /*
3698 Left pixel.
3699 */
cristybb503372010-05-27 20:51:26 +00003700 x=(ssize_t) ceil(segment->x1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003701 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3702 1,1,exception);
3703 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3704 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003705 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003706 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3707 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003708 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003709 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3710 {
cristye2a912b2011-12-05 20:02:07 +00003711 traits=GetPixelChannelMapTraits(image,i);
3712 channel=GetPixelChannelMapChannel(image,i);
cristyda1f9c12011-10-02 21:39:49 +00003713 if (traits == UndefinedPixelTrait)
3714 continue;
3715 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3716 }
cristyc5c6f662010-09-22 14:23:02 +00003717 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003718 if (segment->x1 != segment->x2)
3719 {
3720 /*
3721 Right pixel.
3722 */
cristybb503372010-05-27 20:51:26 +00003723 x=(ssize_t) ceil(segment->x2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003724 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3725 1,1,exception);
3726 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3727 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003728 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003729 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3730 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003731 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003732 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3733 {
cristye2a912b2011-12-05 20:02:07 +00003734 traits=GetPixelChannelMapTraits(image,i);
3735 channel=GetPixelChannelMapChannel(image,i);
cristyda1f9c12011-10-02 21:39:49 +00003736 if (traits == UndefinedPixelTrait)
3737 continue;
3738 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3739 }
cristyc5c6f662010-09-22 14:23:02 +00003740 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003741 }
3742 }
3743 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3744 {
3745 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3746 {
cristy3ed852e2009-09-05 21:47:34 +00003747 /*
3748 Bottom pixel.
3749 */
cristybb503372010-05-27 20:51:26 +00003750 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003751 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3752 1,1,exception);
3753 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3754 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003755 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003756 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3757 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003758 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003759 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3760 {
cristye2a912b2011-12-05 20:02:07 +00003761 traits=GetPixelChannelMapTraits(image,i);
3762 channel=GetPixelChannelMapChannel(image,i);
cristyda1f9c12011-10-02 21:39:49 +00003763 if (traits == UndefinedPixelTrait)
3764 continue;
3765 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3766 }
cristyc5c6f662010-09-22 14:23:02 +00003767 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003768 }
3769 if (segment->y1 != segment->y2)
3770 {
cristy3ed852e2009-09-05 21:47:34 +00003771 /*
3772 Top pixel.
3773 */
cristybb503372010-05-27 20:51:26 +00003774 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003775 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3776 1,1,exception);
3777 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3778 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003779 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003780 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3781 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003782 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003783 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3784 {
cristye2a912b2011-12-05 20:02:07 +00003785 traits=GetPixelChannelMapTraits(image,i);
3786 channel=GetPixelChannelMapChannel(image,i);
cristyda1f9c12011-10-02 21:39:49 +00003787 if (traits == UndefinedPixelTrait)
3788 continue;
3789 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3790 }
cristyc5c6f662010-09-22 14:23:02 +00003791 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003792 }
3793 }
3794 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3795 {
cristy3ed852e2009-09-05 21:47:34 +00003796 /*
3797 Middle pixel.
3798 */
cristybb503372010-05-27 20:51:26 +00003799 x=(ssize_t) ceil(segment->x1-0.5);
3800 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003801 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
cristybb503372010-05-27 20:51:26 +00003802 x=(ssize_t) ceil(segment->x2-0.5);
3803 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003804 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003805 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003806 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3807 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003808 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003809 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3810 {
cristye2a912b2011-12-05 20:02:07 +00003811 traits=GetPixelChannelMapTraits(image,i);
3812 channel=GetPixelChannelMapChannel(image,i);
cristyda1f9c12011-10-02 21:39:49 +00003813 if (traits == UndefinedPixelTrait)
3814 continue;
3815 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3816 }
cristyc5c6f662010-09-22 14:23:02 +00003817 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003818 }
3819 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3820 return(MagickTrue);
3821 return(MagickFalse);
3822}
cristyda1f9c12011-10-02 21:39:49 +00003823
cristy3ed852e2009-09-05 21:47:34 +00003824MagickExport MagickBooleanType PlasmaImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00003825 const SegmentInfo *segment,size_t attenuate,size_t depth,
3826 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003827{
cristyc5c6f662010-09-22 14:23:02 +00003828 CacheView
cristyda1f9c12011-10-02 21:39:49 +00003829 *image_view,
3830 *u_view,
3831 *v_view;
cristyc5c6f662010-09-22 14:23:02 +00003832
cristy3ed852e2009-09-05 21:47:34 +00003833 MagickBooleanType
3834 status;
3835
3836 RandomInfo
3837 *random_info;
3838
3839 if (image->debug != MagickFalse)
3840 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3841 assert(image != (Image *) NULL);
3842 assert(image->signature == MagickSignature);
3843 if (image->debug != MagickFalse)
3844 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy5cbc0162011-08-29 00:36:28 +00003845 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristyc5c6f662010-09-22 14:23:02 +00003846 return(MagickFalse);
3847 image_view=AcquireCacheView(image);
cristyda1f9c12011-10-02 21:39:49 +00003848 u_view=AcquireCacheView(image);
3849 v_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003850 random_info=AcquireRandomInfo();
cristyda1f9c12011-10-02 21:39:49 +00003851 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3852 attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003853 random_info=DestroyRandomInfo(random_info);
cristyda1f9c12011-10-02 21:39:49 +00003854 v_view=DestroyCacheView(v_view);
3855 u_view=DestroyCacheView(u_view);
cristyc5c6f662010-09-22 14:23:02 +00003856 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003857 return(status);
3858}
3859
3860/*
3861%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3862% %
3863% %
3864% %
3865% P o l a r o i d I m a g e %
3866% %
3867% %
3868% %
3869%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3870%
3871% PolaroidImage() simulates a Polaroid picture.
3872%
3873% The format of the AnnotateImage method is:
3874%
3875% Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003876% const double angle,const PixelInterpolateMethod method,
3877% ExceptionInfo exception)
cristy3ed852e2009-09-05 21:47:34 +00003878%
3879% A description of each parameter follows:
3880%
3881% o image: the image.
3882%
3883% o draw_info: the draw info.
3884%
cristycee97112010-05-28 00:44:52 +00003885% o angle: Apply the effect along this angle.
cristy3ed852e2009-09-05 21:47:34 +00003886%
cristy5c4e2582011-09-11 19:21:03 +00003887% o method: the pixel interpolation method.
3888%
cristy3ed852e2009-09-05 21:47:34 +00003889% o exception: return any errors or warnings in this structure.
3890%
3891*/
3892MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003893 const double angle,const PixelInterpolateMethod method,
3894 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003895{
3896 const char
3897 *value;
3898
cristy3ed852e2009-09-05 21:47:34 +00003899 Image
3900 *bend_image,
3901 *caption_image,
3902 *flop_image,
3903 *picture_image,
3904 *polaroid_image,
3905 *rotate_image,
3906 *trim_image;
3907
cristybb503372010-05-27 20:51:26 +00003908 size_t
cristy3ed852e2009-09-05 21:47:34 +00003909 height;
3910
cristy9d314ff2011-03-09 01:30:28 +00003911 ssize_t
3912 quantum;
3913
cristy3ed852e2009-09-05 21:47:34 +00003914 /*
3915 Simulate a Polaroid picture.
3916 */
3917 assert(image != (Image *) NULL);
3918 assert(image->signature == MagickSignature);
3919 if (image->debug != MagickFalse)
3920 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3921 assert(exception != (ExceptionInfo *) NULL);
3922 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00003923 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
cristy3ed852e2009-09-05 21:47:34 +00003924 image->rows)/25.0,10.0);
3925 height=image->rows+2*quantum;
3926 caption_image=(Image *) NULL;
cristyd15e6592011-10-15 00:13:06 +00003927 value=GetImageProperty(image,"caption",exception);
cristy3ed852e2009-09-05 21:47:34 +00003928 if (value != (const char *) NULL)
3929 {
3930 char
3931 *caption,
3932 geometry[MaxTextExtent];
3933
3934 DrawInfo
3935 *annotate_info;
3936
cristy3ed852e2009-09-05 21:47:34 +00003937 MagickBooleanType
3938 status;
3939
cristy9d314ff2011-03-09 01:30:28 +00003940 ssize_t
3941 count;
3942
cristy3ed852e2009-09-05 21:47:34 +00003943 TypeMetric
3944 metrics;
3945
3946 /*
3947 Generate caption image.
3948 */
3949 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3950 if (caption_image == (Image *) NULL)
3951 return((Image *) NULL);
3952 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3953 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
cristy018f07f2011-09-04 21:15:19 +00003954 value,exception);
cristy3ed852e2009-09-05 21:47:34 +00003955 (void) CloneString(&annotate_info->text,caption);
cristy6b1d05e2010-09-22 19:17:27 +00003956 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
cristy5cbc0162011-08-29 00:36:28 +00003957 &caption,exception);
cristybb503372010-05-27 20:51:26 +00003958 status=SetImageExtent(caption_image,image->columns,(size_t)
cristy63240882011-08-05 19:05:27 +00003959 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003960 if (status == MagickFalse)
3961 caption_image=DestroyImage(caption_image);
3962 else
3963 {
3964 caption_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00003965 (void) SetImageBackgroundColor(caption_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003966 (void) CloneString(&annotate_info->text,caption);
cristyb51dff52011-05-19 16:55:47 +00003967 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
cristy3ed852e2009-09-05 21:47:34 +00003968 metrics.ascent);
3969 if (annotate_info->gravity == UndefinedGravity)
3970 (void) CloneString(&annotate_info->geometry,AcquireString(
3971 geometry));
cristy5cbc0162011-08-29 00:36:28 +00003972 (void) AnnotateImage(caption_image,annotate_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00003973 height+=caption_image->rows;
3974 }
3975 annotate_info=DestroyDrawInfo(annotate_info);
3976 caption=DestroyString(caption);
3977 }
3978 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3979 exception);
3980 if (picture_image == (Image *) NULL)
3981 {
3982 if (caption_image != (Image *) NULL)
3983 caption_image=DestroyImage(caption_image);
3984 return((Image *) NULL);
3985 }
3986 picture_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00003987 (void) SetImageBackgroundColor(picture_image,exception);
cristye941a752011-10-15 01:52:48 +00003988 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum,
3989 exception);
cristy3ed852e2009-09-05 21:47:34 +00003990 if (caption_image != (Image *) NULL)
3991 {
3992 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
cristye941a752011-10-15 01:52:48 +00003993 quantum,(ssize_t) (image->rows+3*quantum/2),exception);
cristy3ed852e2009-09-05 21:47:34 +00003994 caption_image=DestroyImage(caption_image);
3995 }
cristy9950d572011-10-01 18:22:35 +00003996 (void) QueryColorCompliance("none",AllCompliance,
3997 &picture_image->background_color,exception);
cristy63240882011-08-05 19:05:27 +00003998 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00003999 rotate_image=RotateImage(picture_image,90.0,exception);
4000 picture_image=DestroyImage(picture_image);
4001 if (rotate_image == (Image *) NULL)
4002 return((Image *) NULL);
4003 picture_image=rotate_image;
4004 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
cristy5c4e2582011-09-11 19:21:03 +00004005 picture_image->columns,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00004006 picture_image=DestroyImage(picture_image);
4007 if (bend_image == (Image *) NULL)
4008 return((Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00004009 picture_image=bend_image;
4010 rotate_image=RotateImage(picture_image,-90.0,exception);
4011 picture_image=DestroyImage(picture_image);
4012 if (rotate_image == (Image *) NULL)
4013 return((Image *) NULL);
4014 picture_image=rotate_image;
4015 picture_image->background_color=image->background_color;
cristy78ec1a92011-12-09 09:25:34 +00004016 polaroid_image=ShadowImage(picture_image,80.0,2.0,0.0,quantum/3,quantum/3,
cristy3ed852e2009-09-05 21:47:34 +00004017 exception);
4018 if (polaroid_image == (Image *) NULL)
4019 {
4020 picture_image=DestroyImage(picture_image);
4021 return(picture_image);
4022 }
4023 flop_image=FlopImage(polaroid_image,exception);
4024 polaroid_image=DestroyImage(polaroid_image);
4025 if (flop_image == (Image *) NULL)
4026 {
4027 picture_image=DestroyImage(picture_image);
4028 return(picture_image);
4029 }
4030 polaroid_image=flop_image;
4031 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
cristye941a752011-10-15 01:52:48 +00004032 (ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
cristy3ed852e2009-09-05 21:47:34 +00004033 picture_image=DestroyImage(picture_image);
cristy9950d572011-10-01 18:22:35 +00004034 (void) QueryColorCompliance("none",AllCompliance,
4035 &polaroid_image->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00004036 rotate_image=RotateImage(polaroid_image,angle,exception);
4037 polaroid_image=DestroyImage(polaroid_image);
4038 if (rotate_image == (Image *) NULL)
4039 return((Image *) NULL);
4040 polaroid_image=rotate_image;
4041 trim_image=TrimImage(polaroid_image,exception);
4042 polaroid_image=DestroyImage(polaroid_image);
4043 if (trim_image == (Image *) NULL)
4044 return((Image *) NULL);
4045 polaroid_image=trim_image;
4046 return(polaroid_image);
4047}
4048
4049/*
4050%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4051% %
4052% %
4053% %
cristy3ed852e2009-09-05 21:47:34 +00004054% S e p i a T o n e I m a g e %
4055% %
4056% %
4057% %
4058%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4059%
4060% MagickSepiaToneImage() applies a special effect to the image, similar to the
4061% effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4062% 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4063% threshold of 80% is a good starting point for a reasonable tone.
4064%
4065% The format of the SepiaToneImage method is:
4066%
4067% Image *SepiaToneImage(const Image *image,const double threshold,
4068% ExceptionInfo *exception)
4069%
4070% A description of each parameter follows:
4071%
4072% o image: the image.
4073%
4074% o threshold: the tone threshold.
4075%
4076% o exception: return any errors or warnings in this structure.
4077%
4078*/
4079MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4080 ExceptionInfo *exception)
4081{
4082#define SepiaToneImageTag "SepiaTone/Image"
4083
cristyc4c8d132010-01-07 01:58:38 +00004084 CacheView
4085 *image_view,
4086 *sepia_view;
4087
cristy3ed852e2009-09-05 21:47:34 +00004088 Image
4089 *sepia_image;
4090
cristy3ed852e2009-09-05 21:47:34 +00004091 MagickBooleanType
4092 status;
4093
cristybb503372010-05-27 20:51:26 +00004094 MagickOffsetType
4095 progress;
4096
4097 ssize_t
4098 y;
4099
cristy3ed852e2009-09-05 21:47:34 +00004100 /*
4101 Initialize sepia-toned image attributes.
4102 */
4103 assert(image != (const Image *) NULL);
4104 assert(image->signature == MagickSignature);
4105 if (image->debug != MagickFalse)
4106 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4107 assert(exception != (ExceptionInfo *) NULL);
4108 assert(exception->signature == MagickSignature);
4109 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4110 if (sepia_image == (Image *) NULL)
4111 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004112 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004113 {
cristy3ed852e2009-09-05 21:47:34 +00004114 sepia_image=DestroyImage(sepia_image);
4115 return((Image *) NULL);
4116 }
4117 /*
4118 Tone each row of the image.
4119 */
4120 status=MagickTrue;
4121 progress=0;
4122 image_view=AcquireCacheView(image);
4123 sepia_view=AcquireCacheView(sepia_image);
cristyb5d5f722009-11-04 03:03:49 +00004124#if defined(MAGICKCORE_OPENMP_SUPPORT)
4125 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004126#endif
cristybb503372010-05-27 20:51:26 +00004127 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004128 {
cristy4c08aed2011-07-01 19:47:50 +00004129 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004130 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00004131
cristybb503372010-05-27 20:51:26 +00004132 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004133 x;
4134
cristy4c08aed2011-07-01 19:47:50 +00004135 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004136 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004137
4138 if (status == MagickFalse)
4139 continue;
4140 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4141 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4142 exception);
cristy4c08aed2011-07-01 19:47:50 +00004143 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004144 {
4145 status=MagickFalse;
4146 continue;
4147 }
cristybb503372010-05-27 20:51:26 +00004148 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004149 {
4150 MagickRealType
4151 intensity,
4152 tone;
4153
cristy4c08aed2011-07-01 19:47:50 +00004154 intensity=(MagickRealType) GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00004155 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4156 (MagickRealType) QuantumRange-threshold;
cristy4c08aed2011-07-01 19:47:50 +00004157 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004158 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4159 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004160 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004161 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004162 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004163 tone=threshold/7.0;
cristy4c08aed2011-07-01 19:47:50 +00004164 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4165 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4166 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4167 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristyed231572011-07-14 02:18:59 +00004168 p+=GetPixelChannels(image);
4169 q+=GetPixelChannels(sepia_image);
cristy3ed852e2009-09-05 21:47:34 +00004170 }
4171 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4172 status=MagickFalse;
4173 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4174 {
4175 MagickBooleanType
4176 proceed;
4177
cristyb5d5f722009-11-04 03:03:49 +00004178#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004179 #pragma omp critical (MagickCore_SepiaToneImage)
4180#endif
4181 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4182 image->rows);
4183 if (proceed == MagickFalse)
4184 status=MagickFalse;
4185 }
4186 }
4187 sepia_view=DestroyCacheView(sepia_view);
4188 image_view=DestroyCacheView(image_view);
cristye23ec9d2011-08-16 18:15:40 +00004189 (void) NormalizeImage(sepia_image,exception);
4190 (void) ContrastImage(sepia_image,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004191 if (status == MagickFalse)
4192 sepia_image=DestroyImage(sepia_image);
4193 return(sepia_image);
4194}
4195
4196/*
4197%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4198% %
4199% %
4200% %
4201% S h a d o w I m a g e %
4202% %
4203% %
4204% %
4205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4206%
4207% ShadowImage() simulates a shadow from the specified image and returns it.
4208%
4209% The format of the ShadowImage method is:
4210%
4211% Image *ShadowImage(const Image *image,const double opacity,
cristyeb6e6582011-12-09 09:14:23 +00004212% const double sigma,const double bias,const ssize_t x_offset,
4213% const ssize_t y_offset,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004214%
4215% A description of each parameter follows:
4216%
4217% o image: the image.
4218%
4219% o opacity: percentage transparency.
4220%
4221% o sigma: the standard deviation of the Gaussian, in pixels.
4222%
cristyeb6e6582011-12-09 09:14:23 +00004223% o bias: the bias.
4224%
cristy3ed852e2009-09-05 21:47:34 +00004225% o x_offset: the shadow x-offset.
4226%
4227% o y_offset: the shadow y-offset.
4228%
4229% o exception: return any errors or warnings in this structure.
4230%
4231*/
4232MagickExport Image *ShadowImage(const Image *image,const double opacity,
cristyeb6e6582011-12-09 09:14:23 +00004233 const double sigma,const double bias,const ssize_t x_offset,
4234 const ssize_t y_offset,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004235{
4236#define ShadowImageTag "Shadow/Image"
4237
cristybd5a96c2011-08-21 00:04:26 +00004238 ChannelType
4239 channel_mask;
4240
cristy3ed852e2009-09-05 21:47:34 +00004241 Image
4242 *border_image,
4243 *clone_image,
4244 *shadow_image;
4245
cristy3ed852e2009-09-05 21:47:34 +00004246 RectangleInfo
4247 border_info;
4248
cristy3ed852e2009-09-05 21:47:34 +00004249 assert(image != (Image *) NULL);
4250 assert(image->signature == MagickSignature);
4251 if (image->debug != MagickFalse)
4252 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4253 assert(exception != (ExceptionInfo *) NULL);
4254 assert(exception->signature == MagickSignature);
4255 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4256 if (clone_image == (Image *) NULL)
4257 return((Image *) NULL);
4258 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4259 clone_image->compose=OverCompositeOp;
cristybb503372010-05-27 20:51:26 +00004260 border_info.width=(size_t) floor(2.0*sigma+0.5);
4261 border_info.height=(size_t) floor(2.0*sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00004262 border_info.x=0;
4263 border_info.y=0;
cristy9950d572011-10-01 18:22:35 +00004264 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4265 exception);
cristy633f0c62011-09-15 13:27:36 +00004266 border_image=BorderImage(clone_image,&border_info,image->compose,exception);
cristy3ed852e2009-09-05 21:47:34 +00004267 clone_image=DestroyImage(clone_image);
4268 if (border_image == (Image *) NULL)
4269 return((Image *) NULL);
4270 if (border_image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00004271 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004272 /*
4273 Shadow image.
4274 */
cristyea1a8aa2011-10-20 13:24:06 +00004275 (void) SetImageBackgroundColor(border_image,exception);
cristybd5a96c2011-08-21 00:04:26 +00004276 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
cristyeb6e6582011-12-09 09:14:23 +00004277 shadow_image=BlurImage(border_image,0.0,sigma,bias,exception);
cristye2a912b2011-12-05 20:02:07 +00004278 (void) SetPixelChannelMapMask(border_image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00004279 border_image=DestroyImage(border_image);
4280 if (shadow_image == (Image *) NULL)
4281 return((Image *) NULL);
4282 if (shadow_image->page.width == 0)
4283 shadow_image->page.width=shadow_image->columns;
4284 if (shadow_image->page.height == 0)
4285 shadow_image->page.height=shadow_image->rows;
cristybb503372010-05-27 20:51:26 +00004286 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4287 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4288 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4289 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
cristy3ed852e2009-09-05 21:47:34 +00004290 return(shadow_image);
4291}
4292
4293/*
4294%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4295% %
4296% %
4297% %
4298% S k e t c h I m a g e %
4299% %
4300% %
4301% %
4302%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4303%
4304% SketchImage() simulates a pencil sketch. We convolve the image with a
4305% Gaussian operator of the given radius and standard deviation (sigma). For
4306% reasonable results, radius should be larger than sigma. Use a radius of 0
4307% and SketchImage() selects a suitable radius for you. Angle gives the angle
4308% of the sketch.
4309%
4310% The format of the SketchImage method is:
4311%
4312% Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004313% const double sigma,const double angle,const double bias,
4314% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004315%
4316% A description of each parameter follows:
4317%
4318% o image: the image.
4319%
cristy574cc262011-08-05 01:23:58 +00004320% o radius: the radius of the Gaussian, in pixels, not counting the
4321% center pixel.
cristy3ed852e2009-09-05 21:47:34 +00004322%
4323% o sigma: the standard deviation of the Gaussian, in pixels.
4324%
cristyf7ef0252011-09-09 14:50:06 +00004325% o angle: apply the effect along this angle.
4326%
4327% o bias: the bias.
cristy3ed852e2009-09-05 21:47:34 +00004328%
4329% o exception: return any errors or warnings in this structure.
4330%
4331*/
4332MagickExport Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004333 const double sigma,const double angle,const double bias,
4334 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004335{
cristyfa112112010-01-04 17:48:07 +00004336 CacheView
4337 *random_view;
4338
cristy3ed852e2009-09-05 21:47:34 +00004339 Image
4340 *blend_image,
4341 *blur_image,
4342 *dodge_image,
4343 *random_image,
4344 *sketch_image;
4345
cristy3ed852e2009-09-05 21:47:34 +00004346 MagickBooleanType
4347 status;
4348
cristy3ed852e2009-09-05 21:47:34 +00004349 RandomInfo
cristyfa112112010-01-04 17:48:07 +00004350 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +00004351
cristy9d314ff2011-03-09 01:30:28 +00004352 ssize_t
4353 y;
4354
cristy3ed852e2009-09-05 21:47:34 +00004355 /*
4356 Sketch image.
4357 */
4358 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4359 MagickTrue,exception);
4360 if (random_image == (Image *) NULL)
4361 return((Image *) NULL);
4362 status=MagickTrue;
cristy1b784432009-12-19 02:20:40 +00004363 random_info=AcquireRandomInfoThreadSet();
cristy3ed852e2009-09-05 21:47:34 +00004364 random_view=AcquireCacheView(random_image);
cristy1b784432009-12-19 02:20:40 +00004365#if defined(MAGICKCORE_OPENMP_SUPPORT)
4366 #pragma omp parallel for schedule(dynamic,4) shared(status)
4367#endif
cristybb503372010-05-27 20:51:26 +00004368 for (y=0; y < (ssize_t) random_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004369 {
cristy5c9e6f22010-09-17 17:31:01 +00004370 const int
4371 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00004372
cristybb503372010-05-27 20:51:26 +00004373 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004374 x;
4375
cristy4c08aed2011-07-01 19:47:50 +00004376 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004377 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004378
cristy1b784432009-12-19 02:20:40 +00004379 if (status == MagickFalse)
4380 continue;
cristy3ed852e2009-09-05 21:47:34 +00004381 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4382 exception);
cristyacd2ed22011-08-30 01:44:23 +00004383 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004384 {
4385 status=MagickFalse;
4386 continue;
4387 }
cristybb503372010-05-27 20:51:26 +00004388 for (x=0; x < (ssize_t) random_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004389 {
cristy76f512e2011-09-12 01:26:56 +00004390 MagickRealType
4391 value;
4392
4393 register ssize_t
4394 i;
4395
4396 value=GetPseudoRandomValue(random_info[id]);
4397 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4398 {
4399 PixelTrait
4400 traits;
4401
cristye2a912b2011-12-05 20:02:07 +00004402 traits=GetPixelChannelMapTraits(random_image,i);
cristy76f512e2011-09-12 01:26:56 +00004403 if (traits == UndefinedPixelTrait)
4404 continue;
4405 q[i]=ClampToQuantum(QuantumRange*value);
4406 }
cristyed231572011-07-14 02:18:59 +00004407 q+=GetPixelChannels(random_image);
cristy3ed852e2009-09-05 21:47:34 +00004408 }
4409 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4410 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004411 }
4412 random_view=DestroyCacheView(random_view);
cristy1b784432009-12-19 02:20:40 +00004413 random_info=DestroyRandomInfoThreadSet(random_info);
cristy3ed852e2009-09-05 21:47:34 +00004414 if (status == MagickFalse)
4415 {
4416 random_image=DestroyImage(random_image);
4417 return(random_image);
4418 }
cristyf7ef0252011-09-09 14:50:06 +00004419 blur_image=MotionBlurImage(random_image,radius,sigma,angle,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00004420 random_image=DestroyImage(random_image);
4421 if (blur_image == (Image *) NULL)
4422 return((Image *) NULL);
cristy6bfd6902011-12-09 01:33:45 +00004423 dodge_image=EdgeImage(blur_image,radius,1.0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004424 blur_image=DestroyImage(blur_image);
4425 if (dodge_image == (Image *) NULL)
4426 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +00004427 (void) NormalizeImage(dodge_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +00004428 (void) NegateImage(dodge_image,MagickFalse,exception);
cristye941a752011-10-15 01:52:48 +00004429 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
cristy3ed852e2009-09-05 21:47:34 +00004430 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4431 if (sketch_image == (Image *) NULL)
4432 {
4433 dodge_image=DestroyImage(dodge_image);
4434 return((Image *) NULL);
4435 }
cristye941a752011-10-15 01:52:48 +00004436 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0,
4437 exception);
cristy3ed852e2009-09-05 21:47:34 +00004438 dodge_image=DestroyImage(dodge_image);
4439 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4440 if (blend_image == (Image *) NULL)
4441 {
4442 sketch_image=DestroyImage(sketch_image);
4443 return((Image *) NULL);
4444 }
4445 (void) SetImageArtifact(blend_image,"compose:args","20x80");
cristye941a752011-10-15 01:52:48 +00004446 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0,
4447 exception);
cristy3ed852e2009-09-05 21:47:34 +00004448 blend_image=DestroyImage(blend_image);
4449 return(sketch_image);
4450}
4451
4452/*
4453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4454% %
4455% %
4456% %
4457% S o l a r i z e I m a g e %
4458% %
4459% %
4460% %
4461%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4462%
4463% SolarizeImage() applies a special effect to the image, similar to the effect
4464% achieved in a photo darkroom by selectively exposing areas of photo
4465% sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4466% measure of the extent of the solarization.
4467%
4468% The format of the SolarizeImage method is:
4469%
cristy5cbc0162011-08-29 00:36:28 +00004470% MagickBooleanType SolarizeImage(Image *image,const double threshold,
4471% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004472%
4473% A description of each parameter follows:
4474%
4475% o image: the image.
4476%
4477% o threshold: Define the extent of the solarization.
4478%
cristy5cbc0162011-08-29 00:36:28 +00004479% o exception: return any errors or warnings in this structure.
4480%
cristy3ed852e2009-09-05 21:47:34 +00004481*/
4482MagickExport MagickBooleanType SolarizeImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00004483 const double threshold,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004484{
4485#define SolarizeImageTag "Solarize/Image"
4486
cristyc4c8d132010-01-07 01:58:38 +00004487 CacheView
4488 *image_view;
4489
cristy3ed852e2009-09-05 21:47:34 +00004490 MagickBooleanType
4491 status;
4492
cristybb503372010-05-27 20:51:26 +00004493 MagickOffsetType
4494 progress;
4495
4496 ssize_t
4497 y;
4498
cristy3ed852e2009-09-05 21:47:34 +00004499 assert(image != (Image *) NULL);
4500 assert(image->signature == MagickSignature);
4501 if (image->debug != MagickFalse)
4502 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4503 if (image->storage_class == PseudoClass)
4504 {
cristybb503372010-05-27 20:51:26 +00004505 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004506 i;
4507
4508 /*
4509 Solarize colormap.
4510 */
cristybb503372010-05-27 20:51:26 +00004511 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00004512 {
4513 if ((MagickRealType) image->colormap[i].red > threshold)
4514 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4515 if ((MagickRealType) image->colormap[i].green > threshold)
4516 image->colormap[i].green=(Quantum) QuantumRange-
4517 image->colormap[i].green;
4518 if ((MagickRealType) image->colormap[i].blue > threshold)
4519 image->colormap[i].blue=(Quantum) QuantumRange-
4520 image->colormap[i].blue;
4521 }
4522 }
4523 /*
4524 Solarize image.
4525 */
4526 status=MagickTrue;
4527 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00004528 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00004529#if defined(MAGICKCORE_OPENMP_SUPPORT)
4530 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004531#endif
cristybb503372010-05-27 20:51:26 +00004532 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004533 {
cristybb503372010-05-27 20:51:26 +00004534 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004535 x;
4536
cristy4c08aed2011-07-01 19:47:50 +00004537 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004538 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004539
4540 if (status == MagickFalse)
4541 continue;
cristy5cbc0162011-08-29 00:36:28 +00004542 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004543 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004544 {
4545 status=MagickFalse;
4546 continue;
4547 }
cristybb503372010-05-27 20:51:26 +00004548 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004549 {
cristy76f512e2011-09-12 01:26:56 +00004550 register ssize_t
4551 i;
4552
4553 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4554 {
4555 PixelTrait
4556 traits;
4557
cristye2a912b2011-12-05 20:02:07 +00004558 traits=GetPixelChannelMapTraits(image,i);
cristy76f512e2011-09-12 01:26:56 +00004559 if ((traits == UndefinedPixelTrait) ||
4560 ((traits & CopyPixelTrait) != 0))
4561 continue;
4562 if ((MagickRealType) q[i] > threshold)
4563 q[i]=QuantumRange-q[i];
4564 }
cristyed231572011-07-14 02:18:59 +00004565 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004566 }
4567 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4568 status=MagickFalse;
4569 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4570 {
4571 MagickBooleanType
4572 proceed;
4573
cristyb5d5f722009-11-04 03:03:49 +00004574#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004575 #pragma omp critical (MagickCore_SolarizeImage)
4576#endif
4577 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4578 if (proceed == MagickFalse)
4579 status=MagickFalse;
4580 }
4581 }
4582 image_view=DestroyCacheView(image_view);
4583 return(status);
4584}
4585
4586/*
4587%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4588% %
4589% %
4590% %
4591% S t e g a n o I m a g e %
4592% %
4593% %
4594% %
4595%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4596%
4597% SteganoImage() hides a digital watermark within the image. Recover
4598% the hidden watermark later to prove that the authenticity of an image.
4599% Offset defines the start position within the image to hide the watermark.
4600%
4601% The format of the SteganoImage method is:
4602%
4603% Image *SteganoImage(const Image *image,Image *watermark,
4604% ExceptionInfo *exception)
4605%
4606% A description of each parameter follows:
4607%
4608% o image: the image.
4609%
4610% o watermark: the watermark image.
4611%
4612% o exception: return any errors or warnings in this structure.
4613%
4614*/
4615MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4616 ExceptionInfo *exception)
4617{
cristye1bf8ad2010-09-19 17:07:03 +00004618#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
cristy4c08aed2011-07-01 19:47:50 +00004619#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
cristyeaedf062010-05-29 22:36:02 +00004620 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
cristy3ed852e2009-09-05 21:47:34 +00004621#define SteganoImageTag "Stegano/Image"
4622
cristyb0d3bb92010-09-22 14:37:58 +00004623 CacheView
4624 *stegano_view,
4625 *watermark_view;
4626
cristy3ed852e2009-09-05 21:47:34 +00004627 Image
4628 *stegano_image;
4629
4630 int
4631 c;
4632
cristy3ed852e2009-09-05 21:47:34 +00004633 MagickBooleanType
4634 status;
4635
cristy101ab702011-10-13 13:06:32 +00004636 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00004637 pixel;
4638
cristy4c08aed2011-07-01 19:47:50 +00004639 register Quantum
cristy3ed852e2009-09-05 21:47:34 +00004640 *q;
4641
cristye1bf8ad2010-09-19 17:07:03 +00004642 register ssize_t
4643 x;
4644
cristybb503372010-05-27 20:51:26 +00004645 size_t
cristyeaedf062010-05-29 22:36:02 +00004646 depth,
4647 one;
cristy3ed852e2009-09-05 21:47:34 +00004648
cristye1bf8ad2010-09-19 17:07:03 +00004649 ssize_t
4650 i,
4651 j,
4652 k,
4653 y;
4654
cristy3ed852e2009-09-05 21:47:34 +00004655 /*
4656 Initialize steganographic image attributes.
4657 */
4658 assert(image != (const Image *) NULL);
4659 assert(image->signature == MagickSignature);
4660 if (image->debug != MagickFalse)
4661 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4662 assert(watermark != (const Image *) NULL);
4663 assert(watermark->signature == MagickSignature);
4664 assert(exception != (ExceptionInfo *) NULL);
4665 assert(exception->signature == MagickSignature);
cristyeaedf062010-05-29 22:36:02 +00004666 one=1UL;
cristy3ed852e2009-09-05 21:47:34 +00004667 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4668 if (stegano_image == (Image *) NULL)
4669 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004670 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004671 {
cristy3ed852e2009-09-05 21:47:34 +00004672 stegano_image=DestroyImage(stegano_image);
4673 return((Image *) NULL);
4674 }
4675 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4676 /*
4677 Hide watermark in low-order bits of image.
4678 */
4679 c=0;
4680 i=0;
4681 j=0;
4682 depth=stegano_image->depth;
4683 k=image->offset;
cristyda16f162011-02-19 23:52:17 +00004684 status=MagickTrue;
cristyb0d3bb92010-09-22 14:37:58 +00004685 watermark_view=AcquireCacheView(watermark);
4686 stegano_view=AcquireCacheView(stegano_image);
cristybb503372010-05-27 20:51:26 +00004687 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
cristy3ed852e2009-09-05 21:47:34 +00004688 {
cristybb503372010-05-27 20:51:26 +00004689 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
cristy3ed852e2009-09-05 21:47:34 +00004690 {
cristybb503372010-05-27 20:51:26 +00004691 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
cristy3ed852e2009-09-05 21:47:34 +00004692 {
cristyda1f9c12011-10-02 21:39:49 +00004693 Quantum
cristy5f95f4f2011-10-23 01:01:01 +00004694 virtual_pixel[CompositePixelChannel];
cristyda1f9c12011-10-02 21:39:49 +00004695
4696 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,virtual_pixel,
4697 exception);
4698 pixel.red=(double) virtual_pixel[RedPixelChannel];
4699 pixel.green=(double) virtual_pixel[GreenPixelChannel];
4700 pixel.blue=(double) virtual_pixel[BluePixelChannel];
4701 pixel.alpha=(double) virtual_pixel[AlphaPixelChannel];
cristybb503372010-05-27 20:51:26 +00004702 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
cristy3ed852e2009-09-05 21:47:34 +00004703 break;
cristyb0d3bb92010-09-22 14:37:58 +00004704 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4705 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4706 exception);
cristyacd2ed22011-08-30 01:44:23 +00004707 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004708 break;
4709 switch (c)
4710 {
4711 case 0:
4712 {
cristy4c08aed2011-07-01 19:47:50 +00004713 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004714 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004715 break;
4716 }
4717 case 1:
4718 {
cristy4c08aed2011-07-01 19:47:50 +00004719 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004720 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004721 break;
4722 }
4723 case 2:
4724 {
cristy4c08aed2011-07-01 19:47:50 +00004725 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004726 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004727 break;
4728 }
4729 }
cristyb0d3bb92010-09-22 14:37:58 +00004730 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004731 break;
4732 c++;
4733 if (c == 3)
4734 c=0;
4735 k++;
cristybb503372010-05-27 20:51:26 +00004736 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
cristy3ed852e2009-09-05 21:47:34 +00004737 k=0;
4738 if (k == image->offset)
4739 j++;
4740 }
4741 }
cristy8b27a6d2010-02-14 03:31:15 +00004742 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004743 {
cristy8b27a6d2010-02-14 03:31:15 +00004744 MagickBooleanType
4745 proceed;
4746
4747 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4748 (depth-i),depth);
4749 if (proceed == MagickFalse)
4750 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004751 }
4752 }
cristyb0d3bb92010-09-22 14:37:58 +00004753 stegano_view=DestroyCacheView(stegano_view);
4754 watermark_view=DestroyCacheView(watermark_view);
cristy3ed852e2009-09-05 21:47:34 +00004755 if (stegano_image->storage_class == PseudoClass)
cristyea1a8aa2011-10-20 13:24:06 +00004756 (void) SyncImage(stegano_image,exception);
cristyda16f162011-02-19 23:52:17 +00004757 if (status == MagickFalse)
4758 {
4759 stegano_image=DestroyImage(stegano_image);
4760 return((Image *) NULL);
4761 }
cristy3ed852e2009-09-05 21:47:34 +00004762 return(stegano_image);
4763}
4764
4765/*
4766%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4767% %
4768% %
4769% %
4770% S t e r e o A n a g l y p h I m a g e %
4771% %
4772% %
4773% %
4774%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4775%
4776% StereoAnaglyphImage() combines two images and produces a single image that
4777% is the composite of a left and right image of a stereo pair. Special
4778% red-green stereo glasses are required to view this effect.
4779%
4780% The format of the StereoAnaglyphImage method is:
4781%
4782% Image *StereoImage(const Image *left_image,const Image *right_image,
4783% ExceptionInfo *exception)
4784% Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004785% const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004786% ExceptionInfo *exception)
4787%
4788% A description of each parameter follows:
4789%
4790% o left_image: the left image.
4791%
4792% o right_image: the right image.
4793%
4794% o exception: return any errors or warnings in this structure.
4795%
4796% o x_offset: amount, in pixels, by which the left image is offset to the
4797% right of the right image.
4798%
4799% o y_offset: amount, in pixels, by which the left image is offset to the
4800% bottom of the right image.
4801%
4802%
4803*/
4804MagickExport Image *StereoImage(const Image *left_image,
4805 const Image *right_image,ExceptionInfo *exception)
4806{
4807 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4808}
4809
4810MagickExport Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004811 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004812 ExceptionInfo *exception)
4813{
4814#define StereoImageTag "Stereo/Image"
4815
4816 const Image
4817 *image;
4818
4819 Image
4820 *stereo_image;
4821
cristy3ed852e2009-09-05 21:47:34 +00004822 MagickBooleanType
4823 status;
4824
cristy9d314ff2011-03-09 01:30:28 +00004825 ssize_t
4826 y;
4827
cristy3ed852e2009-09-05 21:47:34 +00004828 assert(left_image != (const Image *) NULL);
4829 assert(left_image->signature == MagickSignature);
4830 if (left_image->debug != MagickFalse)
4831 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4832 left_image->filename);
4833 assert(right_image != (const Image *) NULL);
4834 assert(right_image->signature == MagickSignature);
4835 assert(exception != (ExceptionInfo *) NULL);
4836 assert(exception->signature == MagickSignature);
4837 assert(right_image != (const Image *) NULL);
4838 image=left_image;
4839 if ((left_image->columns != right_image->columns) ||
4840 (left_image->rows != right_image->rows))
4841 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4842 /*
4843 Initialize stereo image attributes.
4844 */
4845 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4846 MagickTrue,exception);
4847 if (stereo_image == (Image *) NULL)
4848 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004849 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004850 {
cristy3ed852e2009-09-05 21:47:34 +00004851 stereo_image=DestroyImage(stereo_image);
4852 return((Image *) NULL);
4853 }
4854 /*
4855 Copy left image to red channel and right image to blue channel.
4856 */
cristyda16f162011-02-19 23:52:17 +00004857 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00004858 for (y=0; y < (ssize_t) stereo_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004859 {
cristy4c08aed2011-07-01 19:47:50 +00004860 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004861 *restrict p,
4862 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004863
cristybb503372010-05-27 20:51:26 +00004864 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004865 x;
4866
cristy4c08aed2011-07-01 19:47:50 +00004867 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004868 *restrict r;
cristy3ed852e2009-09-05 21:47:34 +00004869
4870 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4871 exception);
4872 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4873 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
cristy76f512e2011-09-12 01:26:56 +00004874 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4875 (r == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004876 break;
cristybb503372010-05-27 20:51:26 +00004877 for (x=0; x < (ssize_t) stereo_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004878 {
cristy4c08aed2011-07-01 19:47:50 +00004879 SetPixelRed(image,GetPixelRed(left_image,p),r);
cristy76f512e2011-09-12 01:26:56 +00004880 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4881 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4882 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4883 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4884 GetPixelAlpha(right_image,q))/2,r);
cristyed231572011-07-14 02:18:59 +00004885 p+=GetPixelChannels(left_image);
cristy76f512e2011-09-12 01:26:56 +00004886 q+=GetPixelChannels(right_image);
4887 r+=GetPixelChannels(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004888 }
4889 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4890 break;
cristy8b27a6d2010-02-14 03:31:15 +00004891 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004892 {
cristy8b27a6d2010-02-14 03:31:15 +00004893 MagickBooleanType
4894 proceed;
4895
cristybb503372010-05-27 20:51:26 +00004896 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4897 stereo_image->rows);
cristy8b27a6d2010-02-14 03:31:15 +00004898 if (proceed == MagickFalse)
4899 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004900 }
4901 }
cristyda16f162011-02-19 23:52:17 +00004902 if (status == MagickFalse)
4903 {
4904 stereo_image=DestroyImage(stereo_image);
4905 return((Image *) NULL);
4906 }
cristy3ed852e2009-09-05 21:47:34 +00004907 return(stereo_image);
4908}
4909
4910/*
4911%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4912% %
4913% %
4914% %
4915% S w i r l I m a g e %
4916% %
4917% %
4918% %
4919%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4920%
4921% SwirlImage() swirls the pixels about the center of the image, where
4922% degrees indicates the sweep of the arc through which each pixel is moved.
4923% You get a more dramatic effect as the degrees move from 1 to 360.
4924%
4925% The format of the SwirlImage method is:
4926%
4927% Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004928% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004929%
4930% A description of each parameter follows:
4931%
4932% o image: the image.
4933%
4934% o degrees: Define the tightness of the swirling effect.
4935%
cristy76f512e2011-09-12 01:26:56 +00004936% o method: the pixel interpolation method.
4937%
cristy3ed852e2009-09-05 21:47:34 +00004938% o exception: return any errors or warnings in this structure.
4939%
4940*/
4941MagickExport Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004942 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004943{
4944#define SwirlImageTag "Swirl/Image"
4945
cristyfa112112010-01-04 17:48:07 +00004946 CacheView
4947 *image_view,
4948 *swirl_view;
4949
cristy3ed852e2009-09-05 21:47:34 +00004950 Image
4951 *swirl_image;
4952
cristy3ed852e2009-09-05 21:47:34 +00004953 MagickBooleanType
4954 status;
4955
cristybb503372010-05-27 20:51:26 +00004956 MagickOffsetType
4957 progress;
4958
cristy3ed852e2009-09-05 21:47:34 +00004959 MagickRealType
4960 radius;
4961
4962 PointInfo
4963 center,
4964 scale;
4965
cristybb503372010-05-27 20:51:26 +00004966 ssize_t
4967 y;
4968
cristy3ed852e2009-09-05 21:47:34 +00004969 /*
4970 Initialize swirl image attributes.
4971 */
4972 assert(image != (const Image *) NULL);
4973 assert(image->signature == MagickSignature);
4974 if (image->debug != MagickFalse)
4975 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4976 assert(exception != (ExceptionInfo *) NULL);
4977 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00004978 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004979 if (swirl_image == (Image *) NULL)
4980 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004981 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004982 {
cristy3ed852e2009-09-05 21:47:34 +00004983 swirl_image=DestroyImage(swirl_image);
4984 return((Image *) NULL);
4985 }
cristy4c08aed2011-07-01 19:47:50 +00004986 if (swirl_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00004987 swirl_image->matte=MagickTrue;
4988 /*
4989 Compute scaling factor.
4990 */
4991 center.x=(double) image->columns/2.0;
4992 center.y=(double) image->rows/2.0;
4993 radius=MagickMax(center.x,center.y);
4994 scale.x=1.0;
4995 scale.y=1.0;
4996 if (image->columns > image->rows)
4997 scale.y=(double) image->columns/(double) image->rows;
4998 else
4999 if (image->columns < image->rows)
5000 scale.x=(double) image->rows/(double) image->columns;
5001 degrees=(double) DegreesToRadians(degrees);
5002 /*
5003 Swirl image.
5004 */
5005 status=MagickTrue;
5006 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00005007 image_view=AcquireCacheView(image);
5008 swirl_view=AcquireCacheView(swirl_image);
cristyb5d5f722009-11-04 03:03:49 +00005009#if defined(MAGICKCORE_OPENMP_SUPPORT)
5010 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005011#endif
cristybb503372010-05-27 20:51:26 +00005012 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005013 {
cristy3ed852e2009-09-05 21:47:34 +00005014 MagickRealType
5015 distance;
5016
5017 PointInfo
5018 delta;
5019
cristy6d188022011-09-12 13:23:33 +00005020 register const Quantum
5021 *restrict p;
5022
cristybb503372010-05-27 20:51:26 +00005023 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005024 x;
5025
cristy4c08aed2011-07-01 19:47:50 +00005026 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005027 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005028
5029 if (status == MagickFalse)
5030 continue;
cristy6d188022011-09-12 13:23:33 +00005031 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00005032 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5033 exception);
cristy6d188022011-09-12 13:23:33 +00005034 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005035 {
5036 status=MagickFalse;
5037 continue;
5038 }
cristy3ed852e2009-09-05 21:47:34 +00005039 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00005040 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005041 {
cristy6d188022011-09-12 13:23:33 +00005042 register ssize_t
5043 i;
5044
cristy3ed852e2009-09-05 21:47:34 +00005045 /*
5046 Determine if the pixel is within an ellipse.
5047 */
5048 delta.x=scale.x*(double) (x-center.x);
5049 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00005050 if (distance >= (radius*radius))
5051 {
5052 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5053 q[i]=p[i];
5054 }
5055 else
cristy3ed852e2009-09-05 21:47:34 +00005056 {
5057 MagickRealType
5058 cosine,
5059 factor,
5060 sine;
5061
5062 /*
5063 Swirl the pixel.
5064 */
5065 factor=1.0-sqrt((double) distance)/radius;
5066 sine=sin((double) (degrees*factor*factor));
5067 cosine=cos((double) (degrees*factor*factor));
cristy76f512e2011-09-12 01:26:56 +00005068 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5069 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5070 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00005071 }
cristy6d188022011-09-12 13:23:33 +00005072 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00005073 q+=GetPixelChannels(swirl_image);
cristy3ed852e2009-09-05 21:47:34 +00005074 }
5075 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5076 status=MagickFalse;
5077 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5078 {
5079 MagickBooleanType
5080 proceed;
5081
cristyb5d5f722009-11-04 03:03:49 +00005082#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005083 #pragma omp critical (MagickCore_SwirlImage)
5084#endif
5085 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5086 if (proceed == MagickFalse)
5087 status=MagickFalse;
5088 }
5089 }
5090 swirl_view=DestroyCacheView(swirl_view);
5091 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005092 if (status == MagickFalse)
5093 swirl_image=DestroyImage(swirl_image);
5094 return(swirl_image);
5095}
5096
5097/*
5098%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5099% %
5100% %
5101% %
5102% T i n t I m a g e %
5103% %
5104% %
5105% %
5106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5107%
5108% TintImage() applies a color vector to each pixel in the image. The length
5109% of the vector is 0 for black and white and at its maximum for the midtones.
5110% The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5111%
5112% The format of the TintImage method is:
5113%
cristyb817c3f2011-10-03 14:00:35 +00005114% Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005115% const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005116%
5117% A description of each parameter follows:
5118%
5119% o image: the image.
5120%
cristyb817c3f2011-10-03 14:00:35 +00005121% o blend: A color value used for tinting.
cristy3ed852e2009-09-05 21:47:34 +00005122%
5123% o tint: A color value used for tinting.
5124%
5125% o exception: return any errors or warnings in this structure.
5126%
5127*/
cristyb817c3f2011-10-03 14:00:35 +00005128MagickExport Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005129 const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005130{
5131#define TintImageTag "Tint/Image"
5132
cristyc4c8d132010-01-07 01:58:38 +00005133 CacheView
5134 *image_view,
5135 *tint_view;
5136
cristy3ed852e2009-09-05 21:47:34 +00005137 GeometryInfo
5138 geometry_info;
5139
5140 Image
5141 *tint_image;
5142
cristy3ed852e2009-09-05 21:47:34 +00005143 MagickBooleanType
5144 status;
5145
cristybb503372010-05-27 20:51:26 +00005146 MagickOffsetType
5147 progress;
cristy3ed852e2009-09-05 21:47:34 +00005148
cristy28474bf2011-09-11 23:32:52 +00005149 MagickRealType
5150 intensity;
5151
cristy4c08aed2011-07-01 19:47:50 +00005152 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005153 color_vector,
5154 pixel;
5155
cristybb503372010-05-27 20:51:26 +00005156 MagickStatusType
5157 flags;
5158
5159 ssize_t
5160 y;
5161
cristy3ed852e2009-09-05 21:47:34 +00005162 /*
5163 Allocate tint image.
5164 */
5165 assert(image != (const Image *) NULL);
5166 assert(image->signature == MagickSignature);
5167 if (image->debug != MagickFalse)
5168 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5169 assert(exception != (ExceptionInfo *) NULL);
5170 assert(exception->signature == MagickSignature);
5171 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5172 if (tint_image == (Image *) NULL)
5173 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005174 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005175 {
cristy3ed852e2009-09-05 21:47:34 +00005176 tint_image=DestroyImage(tint_image);
5177 return((Image *) NULL);
5178 }
cristyaed9c382011-10-03 17:54:21 +00005179 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005180 return(tint_image);
5181 /*
5182 Determine RGB values of the color.
5183 */
cristy28474bf2011-09-11 23:32:52 +00005184 GetPixelInfo(image,&pixel);
cristyb817c3f2011-10-03 14:00:35 +00005185 flags=ParseGeometry(blend,&geometry_info);
cristy3ed852e2009-09-05 21:47:34 +00005186 pixel.red=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005187 pixel.green=geometry_info.rho;
5188 pixel.blue=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005189 pixel.alpha=OpaqueAlpha;
cristy3ed852e2009-09-05 21:47:34 +00005190 if ((flags & SigmaValue) != 0)
5191 pixel.green=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00005192 if ((flags & XiValue) != 0)
5193 pixel.blue=geometry_info.xi;
cristyb817c3f2011-10-03 14:00:35 +00005194 if ((flags & PsiValue) != 0)
5195 pixel.alpha=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005196 if (image->colorspace == CMYKColorspace)
5197 {
cristyb817c3f2011-10-03 14:00:35 +00005198 pixel.black=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005199 if ((flags & PsiValue) != 0)
5200 pixel.black=geometry_info.psi;
5201 if ((flags & ChiValue) != 0)
5202 pixel.alpha=geometry_info.chi;
5203 }
cristy28474bf2011-09-11 23:32:52 +00005204 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5205 color_vector.red=(MagickRealType) (pixel.red*tint->red/100.0-intensity);
5206 color_vector.green=(MagickRealType) (pixel.green*tint->green/100.0-intensity);
5207 color_vector.blue=(MagickRealType) (pixel.blue*tint->blue/100.0-intensity);
5208 color_vector.black=(MagickRealType) (pixel.black*tint->black/100.0-intensity);
5209 color_vector.alpha=(MagickRealType) (pixel.alpha*tint->alpha/100.0-intensity);
cristy3ed852e2009-09-05 21:47:34 +00005210 /*
5211 Tint image.
5212 */
5213 status=MagickTrue;
5214 progress=0;
5215 image_view=AcquireCacheView(image);
5216 tint_view=AcquireCacheView(tint_image);
cristyb5d5f722009-11-04 03:03:49 +00005217#if defined(MAGICKCORE_OPENMP_SUPPORT)
5218 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005219#endif
cristybb503372010-05-27 20:51:26 +00005220 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005221 {
cristy4c08aed2011-07-01 19:47:50 +00005222 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00005223 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00005224
cristy4c08aed2011-07-01 19:47:50 +00005225 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005226 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005227
cristy6b91acb2011-04-19 12:23:54 +00005228 register ssize_t
5229 x;
5230
cristy3ed852e2009-09-05 21:47:34 +00005231 if (status == MagickFalse)
5232 continue;
5233 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5234 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5235 exception);
cristy4c08aed2011-07-01 19:47:50 +00005236 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005237 {
5238 status=MagickFalse;
5239 continue;
5240 }
cristybb503372010-05-27 20:51:26 +00005241 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005242 {
cristy4c08aed2011-07-01 19:47:50 +00005243 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005244 pixel;
5245
5246 MagickRealType
5247 weight;
5248
cristy76f512e2011-09-12 01:26:56 +00005249 if ((GetPixelRedTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005250 {
5251 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5252 pixel.red=(MagickRealType) GetPixelRed(image,p)+
5253 color_vector.red*(1.0-(4.0*(weight*weight)));
5254 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5255 }
cristy76f512e2011-09-12 01:26:56 +00005256 if ((GetPixelGreenTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005257 {
5258 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5259 pixel.green=(MagickRealType) GetPixelGreen(image,p)+
5260 color_vector.green*(1.0-(4.0*(weight*weight)));
5261 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5262 }
cristy76f512e2011-09-12 01:26:56 +00005263 if ((GetPixelBlueTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005264 {
5265 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5266 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+
5267 color_vector.blue*(1.0-(4.0*(weight*weight)));
5268 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5269 }
cristy76f512e2011-09-12 01:26:56 +00005270 if ((GetPixelBlackTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005271 {
5272 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5273 pixel.black=(MagickRealType) GetPixelBlack(image,p)+
5274 color_vector.black*(1.0-(4.0*(weight*weight)));
5275 SetPixelBlack(tint_image,ClampToQuantum(pixel.black),q);
5276 }
cristy76f512e2011-09-12 01:26:56 +00005277 if ((GetPixelAlphaTraits(tint_image) & CopyPixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005278 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
cristyed231572011-07-14 02:18:59 +00005279 p+=GetPixelChannels(image);
5280 q+=GetPixelChannels(tint_image);
cristy3ed852e2009-09-05 21:47:34 +00005281 }
5282 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5283 status=MagickFalse;
5284 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5285 {
5286 MagickBooleanType
5287 proceed;
5288
cristyb5d5f722009-11-04 03:03:49 +00005289#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005290 #pragma omp critical (MagickCore_TintImage)
5291#endif
5292 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5293 if (proceed == MagickFalse)
5294 status=MagickFalse;
5295 }
5296 }
5297 tint_view=DestroyCacheView(tint_view);
5298 image_view=DestroyCacheView(image_view);
5299 if (status == MagickFalse)
5300 tint_image=DestroyImage(tint_image);
5301 return(tint_image);
5302}
5303
5304/*
5305%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5306% %
5307% %
5308% %
5309% V i g n e t t e I m a g e %
5310% %
5311% %
5312% %
5313%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5314%
5315% VignetteImage() softens the edges of the image in vignette style.
5316%
5317% The format of the VignetteImage method is:
5318%
5319% Image *VignetteImage(const Image *image,const double radius,
cristyeb6e6582011-12-09 09:14:23 +00005320% const double sigma,const double bias,const ssize_t x,const ssize_t y,
cristy05c0c9a2011-09-05 23:16:13 +00005321% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005322%
5323% A description of each parameter follows:
5324%
5325% o image: the image.
5326%
5327% o radius: the radius of the pixel neighborhood.
5328%
5329% o sigma: the standard deviation of the Gaussian, in pixels.
5330%
cristyeb6e6582011-12-09 09:14:23 +00005331% o bias: the bias.
5332%
cristy3ed852e2009-09-05 21:47:34 +00005333% o x, y: Define the x and y ellipse offset.
5334%
5335% o exception: return any errors or warnings in this structure.
5336%
5337*/
5338MagickExport Image *VignetteImage(const Image *image,const double radius,
cristyeb6e6582011-12-09 09:14:23 +00005339 const double sigma,const double bias,const ssize_t x,const ssize_t y,
5340 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005341{
5342 char
5343 ellipse[MaxTextExtent];
5344
5345 DrawInfo
5346 *draw_info;
5347
5348 Image
5349 *canvas_image,
5350 *blur_image,
5351 *oval_image,
5352 *vignette_image;
5353
5354 assert(image != (Image *) NULL);
5355 assert(image->signature == MagickSignature);
5356 if (image->debug != MagickFalse)
5357 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5358 assert(exception != (ExceptionInfo *) NULL);
5359 assert(exception->signature == MagickSignature);
5360 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5361 if (canvas_image == (Image *) NULL)
5362 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005363 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005364 {
cristy3ed852e2009-09-05 21:47:34 +00005365 canvas_image=DestroyImage(canvas_image);
5366 return((Image *) NULL);
5367 }
5368 canvas_image->matte=MagickTrue;
cristyb3a73b52011-07-26 01:34:43 +00005369 oval_image=CloneImage(canvas_image,canvas_image->columns,
5370 canvas_image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005371 if (oval_image == (Image *) NULL)
5372 {
5373 canvas_image=DestroyImage(canvas_image);
5374 return((Image *) NULL);
5375 }
cristy9950d572011-10-01 18:22:35 +00005376 (void) QueryColorCompliance("#000000",AllCompliance,
5377 &oval_image->background_color,exception);
cristyea1a8aa2011-10-20 13:24:06 +00005378 (void) SetImageBackgroundColor(oval_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00005379 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00005380 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5381 exception);
5382 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5383 exception);
cristyb51dff52011-05-19 16:55:47 +00005384 (void) FormatLocaleString(ellipse,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00005385 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
cristy8cd5b312010-01-07 01:10:24 +00005386 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
cristy3ed852e2009-09-05 21:47:34 +00005387 draw_info->primitive=AcquireString(ellipse);
cristy018f07f2011-09-04 21:15:19 +00005388 (void) DrawImage(oval_image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00005389 draw_info=DestroyDrawInfo(draw_info);
cristyeb6e6582011-12-09 09:14:23 +00005390 blur_image=BlurImage(oval_image,radius,sigma,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00005391 oval_image=DestroyImage(oval_image);
5392 if (blur_image == (Image *) NULL)
5393 {
5394 canvas_image=DestroyImage(canvas_image);
5395 return((Image *) NULL);
5396 }
5397 blur_image->matte=MagickFalse;
cristye941a752011-10-15 01:52:48 +00005398 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0,
5399 exception);
cristy3ed852e2009-09-05 21:47:34 +00005400 blur_image=DestroyImage(blur_image);
5401 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5402 canvas_image=DestroyImage(canvas_image);
5403 return(vignette_image);
5404}
5405
5406/*
5407%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5408% %
5409% %
5410% %
5411% W a v e I m a g e %
5412% %
5413% %
5414% %
5415%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5416%
5417% WaveImage() creates a "ripple" effect in the image by shifting the pixels
cristycee97112010-05-28 00:44:52 +00005418% vertically along a sine wave whose amplitude and wavelength is specified
cristy3ed852e2009-09-05 21:47:34 +00005419% by the given parameters.
5420%
5421% The format of the WaveImage method is:
5422%
5423% Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005424% const double wave_length,const PixelInterpolateMethod method,
5425% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005426%
5427% A description of each parameter follows:
5428%
5429% o image: the image.
5430%
5431% o amplitude, wave_length: Define the amplitude and wave length of the
5432% sine wave.
5433%
cristy5c4e2582011-09-11 19:21:03 +00005434% o interpolate: the pixel interpolation method.
5435%
cristy3ed852e2009-09-05 21:47:34 +00005436% o exception: return any errors or warnings in this structure.
5437%
5438*/
5439MagickExport Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005440 const double wave_length,const PixelInterpolateMethod method,
5441 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005442{
5443#define WaveImageTag "Wave/Image"
5444
cristyfa112112010-01-04 17:48:07 +00005445 CacheView
cristyd76c51e2011-03-26 00:21:26 +00005446 *image_view,
cristyfa112112010-01-04 17:48:07 +00005447 *wave_view;
5448
cristy3ed852e2009-09-05 21:47:34 +00005449 Image
5450 *wave_image;
5451
cristy3ed852e2009-09-05 21:47:34 +00005452 MagickBooleanType
5453 status;
5454
cristybb503372010-05-27 20:51:26 +00005455 MagickOffsetType
5456 progress;
5457
cristy3ed852e2009-09-05 21:47:34 +00005458 MagickRealType
5459 *sine_map;
5460
cristybb503372010-05-27 20:51:26 +00005461 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005462 i;
5463
cristybb503372010-05-27 20:51:26 +00005464 ssize_t
5465 y;
5466
cristy3ed852e2009-09-05 21:47:34 +00005467 /*
5468 Initialize wave image attributes.
5469 */
5470 assert(image != (Image *) NULL);
5471 assert(image->signature == MagickSignature);
5472 if (image->debug != MagickFalse)
5473 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5474 assert(exception != (ExceptionInfo *) NULL);
5475 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00005476 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
cristy3ed852e2009-09-05 21:47:34 +00005477 fabs(amplitude)),MagickTrue,exception);
5478 if (wave_image == (Image *) NULL)
5479 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005480 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005481 {
cristy3ed852e2009-09-05 21:47:34 +00005482 wave_image=DestroyImage(wave_image);
5483 return((Image *) NULL);
5484 }
cristy4c08aed2011-07-01 19:47:50 +00005485 if (wave_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00005486 wave_image->matte=MagickTrue;
5487 /*
5488 Allocate sine map.
5489 */
5490 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5491 sizeof(*sine_map));
5492 if (sine_map == (MagickRealType *) NULL)
5493 {
5494 wave_image=DestroyImage(wave_image);
5495 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5496 }
cristybb503372010-05-27 20:51:26 +00005497 for (i=0; i < (ssize_t) wave_image->columns; i++)
cristy4205a3c2010-09-12 20:19:59 +00005498 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5499 wave_length));
cristy3ed852e2009-09-05 21:47:34 +00005500 /*
5501 Wave image.
5502 */
5503 status=MagickTrue;
5504 progress=0;
cristyd76c51e2011-03-26 00:21:26 +00005505 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00005506 wave_view=AcquireCacheView(wave_image);
cristyd76c51e2011-03-26 00:21:26 +00005507 (void) SetCacheViewVirtualPixelMethod(image_view,
5508 BackgroundVirtualPixelMethod);
cristyb5d5f722009-11-04 03:03:49 +00005509#if defined(MAGICKCORE_OPENMP_SUPPORT)
5510 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005511#endif
cristybb503372010-05-27 20:51:26 +00005512 for (y=0; y < (ssize_t) wave_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005513 {
cristy4c08aed2011-07-01 19:47:50 +00005514 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005515 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005516
cristye97bb922011-04-03 01:36:52 +00005517 register ssize_t
5518 x;
5519
cristy3ed852e2009-09-05 21:47:34 +00005520 if (status == MagickFalse)
5521 continue;
5522 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5523 exception);
cristyacd2ed22011-08-30 01:44:23 +00005524 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005525 {
5526 status=MagickFalse;
5527 continue;
5528 }
cristybb503372010-05-27 20:51:26 +00005529 for (x=0; x < (ssize_t) wave_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005530 {
cristy5c4e2582011-09-11 19:21:03 +00005531 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5532 (double) x,(double) (y-sine_map[x]),q,exception);
cristyed231572011-07-14 02:18:59 +00005533 q+=GetPixelChannels(wave_image);
cristy3ed852e2009-09-05 21:47:34 +00005534 }
5535 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5536 status=MagickFalse;
5537 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5538 {
5539 MagickBooleanType
5540 proceed;
5541
cristyb5d5f722009-11-04 03:03:49 +00005542#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005543 #pragma omp critical (MagickCore_WaveImage)
5544#endif
5545 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5546 if (proceed == MagickFalse)
5547 status=MagickFalse;
5548 }
5549 }
5550 wave_view=DestroyCacheView(wave_view);
cristyd76c51e2011-03-26 00:21:26 +00005551 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005552 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5553 if (status == MagickFalse)
5554 wave_image=DestroyImage(wave_image);
5555 return(wave_image);
5556}