blob: aa9fc31aef698adfb7495d23f6e524590fde5ca9 [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% %
cristy1454be72011-12-19 01:52:48 +000020% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/annotate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/cache.h"
48#include "MagickCore/cache-view.h"
49#include "MagickCore/color.h"
50#include "MagickCore/color-private.h"
cristy9b7a4fc2012-04-08 22:26:56 +000051#include "MagickCore/colorspace-private.h"
cristy4c08aed2011-07-01 19:47:50 +000052#include "MagickCore/composite.h"
53#include "MagickCore/decorate.h"
cristyc53413d2011-11-17 13:04:26 +000054#include "MagickCore/distort.h"
cristy4c08aed2011-07-01 19:47:50 +000055#include "MagickCore/draw.h"
56#include "MagickCore/effect.h"
57#include "MagickCore/enhance.h"
58#include "MagickCore/exception.h"
59#include "MagickCore/exception-private.h"
60#include "MagickCore/fx.h"
61#include "MagickCore/fx-private.h"
62#include "MagickCore/gem.h"
cristy8ea81222011-09-04 10:33:32 +000063#include "MagickCore/gem-private.h"
cristy4c08aed2011-07-01 19:47:50 +000064#include "MagickCore/geometry.h"
65#include "MagickCore/layer.h"
66#include "MagickCore/list.h"
67#include "MagickCore/log.h"
68#include "MagickCore/image.h"
69#include "MagickCore/image-private.h"
70#include "MagickCore/magick.h"
71#include "MagickCore/memory_.h"
72#include "MagickCore/monitor.h"
73#include "MagickCore/monitor-private.h"
74#include "MagickCore/option.h"
75#include "MagickCore/pixel.h"
76#include "MagickCore/pixel-accessor.h"
77#include "MagickCore/property.h"
78#include "MagickCore/quantum.h"
79#include "MagickCore/quantum-private.h"
80#include "MagickCore/random_.h"
81#include "MagickCore/random-private.h"
82#include "MagickCore/resample.h"
83#include "MagickCore/resample-private.h"
84#include "MagickCore/resize.h"
cristy57340e02012-05-05 00:53:23 +000085#include "MagickCore/resource_.h"
cristy4c08aed2011-07-01 19:47:50 +000086#include "MagickCore/splay-tree.h"
87#include "MagickCore/statistic.h"
88#include "MagickCore/string_.h"
89#include "MagickCore/string-private.h"
90#include "MagickCore/thread-private.h"
91#include "MagickCore/transform.h"
92#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000093
94/*
95 Define declarations.
96*/
97#define LeftShiftOperator 0xf5
98#define RightShiftOperator 0xf6
99#define LessThanEqualOperator 0xf7
100#define GreaterThanEqualOperator 0xf8
101#define EqualOperator 0xf9
102#define NotEqualOperator 0xfa
103#define LogicalAndOperator 0xfb
104#define LogicalOrOperator 0xfc
cristy116af162010-08-13 01:25:47 +0000105#define ExponentialNotation 0xfd
cristy3ed852e2009-09-05 21:47:34 +0000106
107struct _FxInfo
108{
109 const Image
110 *images;
111
cristy3ed852e2009-09-05 21:47:34 +0000112 char
113 *expression;
114
115 FILE
116 *file;
117
118 SplayTreeInfo
119 *colors,
120 *symbols;
121
cristyd76c51e2011-03-26 00:21:26 +0000122 CacheView
123 **view;
cristy3ed852e2009-09-05 21:47:34 +0000124
125 RandomInfo
126 *random_info;
127
128 ExceptionInfo
129 *exception;
130};
131
132/*
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134% %
135% %
136% %
137+ A c q u i r e F x I n f o %
138% %
139% %
140% %
141%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142%
143% AcquireFxInfo() allocates the FxInfo structure.
144%
145% The format of the AcquireFxInfo method is:
146%
cristydb070952012-04-20 14:33:00 +0000147% FxInfo *AcquireFxInfo(Image *image,const char *expression,
148% ExceptionInfo *exception)
cristy0a9b3722010-10-23 18:45:49 +0000149%
cristy3ed852e2009-09-05 21:47:34 +0000150% A description of each parameter follows:
151%
152% o image: the image.
153%
154% o expression: the expression.
155%
cristydb070952012-04-20 14:33:00 +0000156% o exception: return any errors or warnings in this structure.
157%
cristy3ed852e2009-09-05 21:47:34 +0000158*/
cristydb070952012-04-20 14:33:00 +0000159MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression,
160 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000161{
162 char
163 fx_op[2];
164
cristycb180922011-03-11 14:41:24 +0000165 const Image
166 *next;
167
cristy3ed852e2009-09-05 21:47:34 +0000168 FxInfo
169 *fx_info;
170
cristybb503372010-05-27 20:51:26 +0000171 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000172 i;
173
cristy73bd4a52010-10-05 11:24:23 +0000174 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +0000175 if (fx_info == (FxInfo *) NULL)
176 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
177 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
178 fx_info->exception=AcquireExceptionInfo();
anthony7d86e172011-03-23 12:37:06 +0000179 fx_info->images=image;
cristy3ed852e2009-09-05 21:47:34 +0000180 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
181 RelinquishMagickMemory);
182 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
183 RelinquishMagickMemory);
cristyd76c51e2011-03-26 00:21:26 +0000184 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
185 fx_info->images),sizeof(*fx_info->view));
186 if (fx_info->view == (CacheView **) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000187 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
cristya2262262011-03-11 02:50:37 +0000188 i=0;
cristy0ea377f2011-03-24 00:54:19 +0000189 next=GetFirstImageInList(fx_info->images);
190 for ( ; next != (Image *) NULL; next=next->next)
cristy3ed852e2009-09-05 21:47:34 +0000191 {
cristydb070952012-04-20 14:33:00 +0000192 fx_info->view[i]=AcquireVirtualCacheView(next,exception);
cristya2262262011-03-11 02:50:37 +0000193 i++;
cristy3ed852e2009-09-05 21:47:34 +0000194 }
195 fx_info->random_info=AcquireRandomInfo();
196 fx_info->expression=ConstantString(expression);
197 fx_info->file=stderr;
198 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
cristy37af0912011-05-23 16:09:42 +0000199 /*
200 Force right-to-left associativity for unary negation.
201 */
202 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
cristy8fbb96d2012-07-18 01:18:52 +0000203 (void) SubstituteString(&fx_info->expression,"E-1.0*","E-");
204 (void) SubstituteString(&fx_info->expression,"e-1.0*","e-");
cristy8b8a3ae2010-10-23 18:49:46 +0000205 /*
cristy3ed852e2009-09-05 21:47:34 +0000206 Convert complex to simple operators.
207 */
208 fx_op[1]='\0';
209 *fx_op=(char) LeftShiftOperator;
210 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
211 *fx_op=(char) RightShiftOperator;
212 (void) SubstituteString(&fx_info->expression,">>",fx_op);
213 *fx_op=(char) LessThanEqualOperator;
214 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
215 *fx_op=(char) GreaterThanEqualOperator;
216 (void) SubstituteString(&fx_info->expression,">=",fx_op);
217 *fx_op=(char) EqualOperator;
218 (void) SubstituteString(&fx_info->expression,"==",fx_op);
219 *fx_op=(char) NotEqualOperator;
220 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
221 *fx_op=(char) LogicalAndOperator;
222 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
223 *fx_op=(char) LogicalOrOperator;
224 (void) SubstituteString(&fx_info->expression,"||",fx_op);
cristy116af162010-08-13 01:25:47 +0000225 *fx_op=(char) ExponentialNotation;
226 (void) SubstituteString(&fx_info->expression,"**",fx_op);
cristy3ed852e2009-09-05 21:47:34 +0000227 return(fx_info);
228}
229
230/*
231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
232% %
233% %
234% %
235% A d d N o i s e I m a g e %
236% %
237% %
238% %
239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240%
241% AddNoiseImage() adds random noise to the image.
242%
243% The format of the AddNoiseImage method is:
244%
245% Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
cristy9ed1f812011-10-08 02:00:08 +0000246% const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000247%
248% A description of each parameter follows:
249%
250% o image: the image.
251%
252% o channel: the channel type.
253%
254% o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
255% Impulse, Laplacian, or Poisson.
256%
cristy9ed1f812011-10-08 02:00:08 +0000257% o attenuate: attenuate the random distribution.
258%
cristy3ed852e2009-09-05 21:47:34 +0000259% o exception: return any errors or warnings in this structure.
260%
261*/
cristy9ed1f812011-10-08 02:00:08 +0000262MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
263 const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000264{
265#define AddNoiseImageTag "AddNoise/Image"
266
cristyfa112112010-01-04 17:48:07 +0000267 CacheView
268 *image_view,
269 *noise_view;
270
cristy3ed852e2009-09-05 21:47:34 +0000271 Image
272 *noise_image;
273
cristy3ed852e2009-09-05 21:47:34 +0000274 MagickBooleanType
275 status;
276
cristybb503372010-05-27 20:51:26 +0000277 MagickOffsetType
278 progress;
279
cristy3ed852e2009-09-05 21:47:34 +0000280 RandomInfo
cristyfa112112010-01-04 17:48:07 +0000281 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +0000282
cristybb503372010-05-27 20:51:26 +0000283 ssize_t
284 y;
285
glennrpf7659d72012-09-24 18:14:56 +0000286#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +0000287 unsigned long
288 key;
glennrpf7659d72012-09-24 18:14:56 +0000289#endif
cristy57340e02012-05-05 00:53:23 +0000290
cristy3ed852e2009-09-05 21:47:34 +0000291 /*
292 Initialize noise image attributes.
293 */
294 assert(image != (const Image *) NULL);
295 assert(image->signature == MagickSignature);
296 if (image->debug != MagickFalse)
297 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
298 assert(exception != (ExceptionInfo *) NULL);
299 assert(exception->signature == MagickSignature);
cristyb2145892011-10-10 00:55:32 +0000300 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000301 if (noise_image == (Image *) NULL)
302 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000303 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000304 {
cristy3ed852e2009-09-05 21:47:34 +0000305 noise_image=DestroyImage(noise_image);
306 return((Image *) NULL);
307 }
cristy98ccd782012-07-09 11:22:59 +0000308 if (IsGrayColorspace(image->colorspace) != MagickFalse)
cristyb09db112012-07-11 12:04:31 +0000309 (void) TransformImageColorspace(noise_image,RGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +0000310 /*
311 Add noise in each row.
312 */
cristy3ed852e2009-09-05 21:47:34 +0000313 status=MagickTrue;
314 progress=0;
315 random_info=AcquireRandomInfoThreadSet();
cristydb070952012-04-20 14:33:00 +0000316 image_view=AcquireVirtualCacheView(image,exception);
317 noise_view=AcquireAuthenticCacheView(noise_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000318#if defined(MAGICKCORE_OPENMP_SUPPORT)
glennrpf7659d72012-09-24 18:14:56 +0000319 key=GetRandomSecretKey(random_info[0]);
cristy57340e02012-05-05 00:53:23 +0000320 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +0000321 dynamic_number_threads(image,image->columns,image->rows,key == ~0UL)
cristy3ed852e2009-09-05 21:47:34 +0000322#endif
cristybb503372010-05-27 20:51:26 +0000323 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000324 {
cristy5c9e6f22010-09-17 17:31:01 +0000325 const int
326 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +0000327
cristy3ed852e2009-09-05 21:47:34 +0000328 MagickBooleanType
329 sync;
330
cristy4c08aed2011-07-01 19:47:50 +0000331 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000332 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000333
cristybb503372010-05-27 20:51:26 +0000334 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000335 x;
336
cristy4c08aed2011-07-01 19:47:50 +0000337 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000338 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000339
340 if (status == MagickFalse)
341 continue;
342 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +0000343 q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +0000344 exception);
cristy4c08aed2011-07-01 19:47:50 +0000345 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000346 {
347 status=MagickFalse;
348 continue;
349 }
cristybb503372010-05-27 20:51:26 +0000350 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000351 {
cristy850b3072011-10-08 01:38:05 +0000352 register ssize_t
353 i;
354
355 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
356 {
357 PixelChannel
358 channel;
359
360 PixelTrait
361 noise_traits,
362 traits;
363
cristycf1296e2012-08-26 23:40:49 +0000364 channel=GetPixelChannelChannel(image,i);
365 traits=GetPixelChannelTraits(image,channel);
366 noise_traits=GetPixelChannelTraits(noise_image,channel);
cristy850b3072011-10-08 01:38:05 +0000367 if ((traits == UndefinedPixelTrait) ||
368 (noise_traits == UndefinedPixelTrait))
369 continue;
cristy1eced092012-08-10 23:10:56 +0000370 if (((noise_traits & CopyPixelTrait) != 0) ||
371 (GetPixelMask(image,p) != 0))
cristyb2145892011-10-10 00:55:32 +0000372 {
373 SetPixelChannel(noise_image,channel,p[i],q);
374 continue;
375 }
cristy850b3072011-10-08 01:38:05 +0000376 SetPixelChannel(noise_image,channel,ClampToQuantum(
377 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
378 q);
379 }
cristyed231572011-07-14 02:18:59 +0000380 p+=GetPixelChannels(image);
381 q+=GetPixelChannels(noise_image);
cristy3ed852e2009-09-05 21:47:34 +0000382 }
383 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
384 if (sync == MagickFalse)
385 status=MagickFalse;
386 if (image->progress_monitor != (MagickProgressMonitor) NULL)
387 {
388 MagickBooleanType
389 proceed;
390
cristyb5d5f722009-11-04 03:03:49 +0000391#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy319a1e72010-02-21 15:13:11 +0000392 #pragma omp critical (MagickCore_AddNoiseImage)
cristy3ed852e2009-09-05 21:47:34 +0000393#endif
394 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
395 image->rows);
396 if (proceed == MagickFalse)
397 status=MagickFalse;
398 }
399 }
400 noise_view=DestroyCacheView(noise_view);
401 image_view=DestroyCacheView(image_view);
402 random_info=DestroyRandomInfoThreadSet(random_info);
403 if (status == MagickFalse)
404 noise_image=DestroyImage(noise_image);
405 return(noise_image);
406}
407
408/*
409%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
410% %
411% %
412% %
413% B l u e S h i f t I m a g e %
414% %
415% %
416% %
417%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
418%
419% BlueShiftImage() mutes the colors of the image to simulate a scene at
420% nighttime in the moonlight.
421%
422% The format of the BlueShiftImage method is:
423%
424% Image *BlueShiftImage(const Image *image,const double factor,
425% ExceptionInfo *exception)
426%
427% A description of each parameter follows:
428%
429% o image: the image.
430%
431% o factor: the shift factor.
432%
433% o exception: return any errors or warnings in this structure.
434%
435*/
436MagickExport Image *BlueShiftImage(const Image *image,const double factor,
437 ExceptionInfo *exception)
438{
439#define BlueShiftImageTag "BlueShift/Image"
440
cristyc4c8d132010-01-07 01:58:38 +0000441 CacheView
442 *image_view,
443 *shift_view;
444
cristy3ed852e2009-09-05 21:47:34 +0000445 Image
446 *shift_image;
447
cristy3ed852e2009-09-05 21:47:34 +0000448 MagickBooleanType
449 status;
450
cristybb503372010-05-27 20:51:26 +0000451 MagickOffsetType
452 progress;
453
454 ssize_t
455 y;
456
cristy3ed852e2009-09-05 21:47:34 +0000457 /*
458 Allocate blue shift image.
459 */
460 assert(image != (const Image *) NULL);
461 assert(image->signature == MagickSignature);
462 if (image->debug != MagickFalse)
463 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
464 assert(exception != (ExceptionInfo *) NULL);
465 assert(exception->signature == MagickSignature);
cristya6d7a9b2012-01-18 20:04:48 +0000466 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000467 if (shift_image == (Image *) NULL)
468 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000469 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000470 {
cristy3ed852e2009-09-05 21:47:34 +0000471 shift_image=DestroyImage(shift_image);
472 return((Image *) NULL);
473 }
474 /*
475 Blue-shift DirectClass image.
476 */
477 status=MagickTrue;
478 progress=0;
cristydb070952012-04-20 14:33:00 +0000479 image_view=AcquireVirtualCacheView(image,exception);
480 shift_view=AcquireAuthenticCacheView(shift_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000481#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000482 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +0000483 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000484#endif
cristybb503372010-05-27 20:51:26 +0000485 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000486 {
487 MagickBooleanType
488 sync;
489
cristy4c08aed2011-07-01 19:47:50 +0000490 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000491 pixel;
492
493 Quantum
494 quantum;
495
cristy4c08aed2011-07-01 19:47:50 +0000496 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000497 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000498
cristybb503372010-05-27 20:51:26 +0000499 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000500 x;
501
cristy4c08aed2011-07-01 19:47:50 +0000502 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000503 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000504
505 if (status == MagickFalse)
506 continue;
507 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
508 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
509 exception);
cristy4c08aed2011-07-01 19:47:50 +0000510 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000511 {
512 status=MagickFalse;
513 continue;
514 }
cristybb503372010-05-27 20:51:26 +0000515 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000516 {
cristy4c08aed2011-07-01 19:47:50 +0000517 quantum=GetPixelRed(image,p);
518 if (GetPixelGreen(image,p) < quantum)
519 quantum=GetPixelGreen(image,p);
520 if (GetPixelBlue(image,p) < quantum)
521 quantum=GetPixelBlue(image,p);
522 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
523 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
524 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
525 quantum=GetPixelRed(image,p);
526 if (GetPixelGreen(image,p) > quantum)
527 quantum=GetPixelGreen(image,p);
528 if (GetPixelBlue(image,p) > quantum)
529 quantum=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000530 pixel.red=0.5*(pixel.red+factor*quantum);
531 pixel.green=0.5*(pixel.green+factor*quantum);
532 pixel.blue=0.5*(pixel.blue+factor*quantum);
cristy4c08aed2011-07-01 19:47:50 +0000533 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
534 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
535 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
cristyed231572011-07-14 02:18:59 +0000536 p+=GetPixelChannels(image);
537 q+=GetPixelChannels(shift_image);
cristy3ed852e2009-09-05 21:47:34 +0000538 }
539 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
540 if (sync == MagickFalse)
541 status=MagickFalse;
542 if (image->progress_monitor != (MagickProgressMonitor) NULL)
543 {
544 MagickBooleanType
545 proceed;
546
cristy319a1e72010-02-21 15:13:11 +0000547#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +0000548 #pragma omp critical (MagickCore_BlueShiftImage)
cristy3ed852e2009-09-05 21:47:34 +0000549#endif
550 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
551 image->rows);
552 if (proceed == MagickFalse)
553 status=MagickFalse;
554 }
555 }
556 image_view=DestroyCacheView(image_view);
557 shift_view=DestroyCacheView(shift_view);
558 if (status == MagickFalse)
559 shift_image=DestroyImage(shift_image);
560 return(shift_image);
561}
562
563/*
564%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
565% %
566% %
567% %
568% C h a r c o a l I m a g e %
569% %
570% %
571% %
572%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573%
574% CharcoalImage() creates a new image that is a copy of an existing one with
575% the edge highlighted. It allocates the memory necessary for the new Image
576% structure and returns a pointer to the new image.
577%
578% The format of the CharcoalImage method is:
579%
580% Image *CharcoalImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +0000581% const double sigma,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000582%
583% A description of each parameter follows:
584%
585% o image: the image.
586%
587% o radius: the radius of the pixel neighborhood.
588%
589% o sigma: the standard deviation of the Gaussian, in pixels.
590%
591% o exception: return any errors or warnings in this structure.
592%
593*/
594MagickExport Image *CharcoalImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +0000595 const double sigma,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000596{
597 Image
598 *charcoal_image,
599 *clone_image,
600 *edge_image;
601
602 assert(image != (Image *) NULL);
603 assert(image->signature == MagickSignature);
604 if (image->debug != MagickFalse)
605 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
606 assert(exception != (ExceptionInfo *) NULL);
607 assert(exception->signature == MagickSignature);
608 clone_image=CloneImage(image,0,0,MagickTrue,exception);
609 if (clone_image == (Image *) NULL)
610 return((Image *) NULL);
cristy018f07f2011-09-04 21:15:19 +0000611 (void) SetImageType(clone_image,GrayscaleType,exception);
cristy8ae632d2011-09-05 17:29:53 +0000612 edge_image=EdgeImage(clone_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000613 clone_image=DestroyImage(clone_image);
614 if (edge_image == (Image *) NULL)
615 return((Image *) NULL);
cristyaa2c16c2012-03-25 22:21:35 +0000616 charcoal_image=BlurImage(edge_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000617 edge_image=DestroyImage(edge_image);
618 if (charcoal_image == (Image *) NULL)
619 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +0000620 (void) NormalizeImage(charcoal_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +0000621 (void) NegateImage(charcoal_image,MagickFalse,exception);
cristy018f07f2011-09-04 21:15:19 +0000622 (void) SetImageType(charcoal_image,GrayscaleType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000623 return(charcoal_image);
624}
625
626/*
627%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628% %
629% %
630% %
631% C o l o r i z e I m a g e %
632% %
633% %
634% %
635%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636%
637% ColorizeImage() blends the fill color with each pixel in the image.
638% A percentage blend is specified with opacity. Control the application
639% of different color components by specifying a different percentage for
640% each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
641%
642% The format of the ColorizeImage method is:
643%
cristyc7e6ff62011-10-03 13:46:11 +0000644% Image *ColorizeImage(const Image *image,const char *blend,
645% const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000646%
647% A description of each parameter follows:
648%
649% o image: the image.
650%
cristyc7e6ff62011-10-03 13:46:11 +0000651% o blend: A character string indicating the level of blending as a
cristy3ed852e2009-09-05 21:47:34 +0000652% percentage.
653%
654% o colorize: A color value.
655%
656% o exception: return any errors or warnings in this structure.
657%
658*/
cristyc7e6ff62011-10-03 13:46:11 +0000659MagickExport Image *ColorizeImage(const Image *image,const char *blend,
660 const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000661{
662#define ColorizeImageTag "Colorize/Image"
cristy0cf6da52012-08-25 00:35:24 +0000663#define Colorize(pixel,blend_percentage,colorize) \
664 (((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0)
cristy3ed852e2009-09-05 21:47:34 +0000665
cristyc4c8d132010-01-07 01:58:38 +0000666 CacheView
667 *colorize_view,
668 *image_view;
669
cristy3ed852e2009-09-05 21:47:34 +0000670 GeometryInfo
671 geometry_info;
672
673 Image
674 *colorize_image;
675
cristy3ed852e2009-09-05 21:47:34 +0000676 MagickBooleanType
677 status;
678
cristybb503372010-05-27 20:51:26 +0000679 MagickOffsetType
680 progress;
681
cristy3ed852e2009-09-05 21:47:34 +0000682 MagickStatusType
683 flags;
684
cristyc7e6ff62011-10-03 13:46:11 +0000685 PixelInfo
cristy20c3aed2012-04-10 01:06:21 +0000686 blend_percentage;
cristyc7e6ff62011-10-03 13:46:11 +0000687
cristybb503372010-05-27 20:51:26 +0000688 ssize_t
689 y;
690
cristy3ed852e2009-09-05 21:47:34 +0000691 /*
692 Allocate colorized image.
693 */
694 assert(image != (const Image *) NULL);
695 assert(image->signature == MagickSignature);
696 if (image->debug != MagickFalse)
697 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
698 assert(exception != (ExceptionInfo *) NULL);
699 assert(exception->signature == MagickSignature);
cristy768165d2012-04-09 15:01:35 +0000700 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
701 exception);
702 if (colorize_image == (Image *) NULL)
703 return((Image *) NULL);
704 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
705 {
706 colorize_image=DestroyImage(colorize_image);
707 return((Image *) NULL);
708 }
cristy9b7a4fc2012-04-08 22:26:56 +0000709 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
cristy20c3aed2012-04-10 01:06:21 +0000710 (IsPixelInfoGray(colorize) != MagickFalse))
cristyb09db112012-07-11 12:04:31 +0000711 (void) SetImageColorspace(colorize_image,RGBColorspace,exception);
cristy8a46d822012-08-28 23:32:39 +0000712 if ((colorize_image->alpha_trait != BlendPixelTrait) &&
713 (colorize->alpha_trait == BlendPixelTrait))
cristy768165d2012-04-09 15:01:35 +0000714 (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
715 if (blend == (const char *) NULL)
716 return(colorize_image);
cristy20c3aed2012-04-10 01:06:21 +0000717 GetPixelInfo(image,&blend_percentage);
718 flags=ParseGeometry(blend,&geometry_info);
719 blend_percentage.red=geometry_info.rho;
720 blend_percentage.green=geometry_info.rho;
721 blend_percentage.blue=geometry_info.rho;
722 blend_percentage.black=geometry_info.rho;
cristy3ee7de52012-04-14 23:40:47 +0000723 blend_percentage.alpha=geometry_info.rho;
cristy20c3aed2012-04-10 01:06:21 +0000724 if ((flags & SigmaValue) != 0)
725 blend_percentage.green=geometry_info.sigma;
726 if ((flags & XiValue) != 0)
727 blend_percentage.blue=geometry_info.xi;
728 if ((flags & PsiValue) != 0)
729 blend_percentage.alpha=geometry_info.psi;
730 if (blend_percentage.colorspace == CMYKColorspace)
731 {
732 if ((flags & PsiValue) != 0)
733 blend_percentage.black=geometry_info.psi;
734 if ((flags & ChiValue) != 0)
735 blend_percentage.alpha=geometry_info.chi;
736 }
cristy3ed852e2009-09-05 21:47:34 +0000737 /*
738 Colorize DirectClass image.
739 */
740 status=MagickTrue;
741 progress=0;
cristydb070952012-04-20 14:33:00 +0000742 image_view=AcquireVirtualCacheView(image,exception);
743 colorize_view=AcquireAuthenticCacheView(colorize_image,exception);
cristy319a1e72010-02-21 15:13:11 +0000744#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000745 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +0000746 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +0000747#endif
cristybb503372010-05-27 20:51:26 +0000748 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000749 {
750 MagickBooleanType
751 sync;
752
cristy4c08aed2011-07-01 19:47:50 +0000753 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000754 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000755
cristy4c08aed2011-07-01 19:47:50 +0000756 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000757 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000758
cristy4a37c622012-08-23 18:47:56 +0000759 register ssize_t
760 x;
761
cristy3ed852e2009-09-05 21:47:34 +0000762 if (status == MagickFalse)
763 continue;
764 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
765 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
766 exception);
cristy4c08aed2011-07-01 19:47:50 +0000767 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000768 {
769 status=MagickFalse;
770 continue;
771 }
cristybb503372010-05-27 20:51:26 +0000772 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000773 {
cristy0cf6da52012-08-25 00:35:24 +0000774 register ssize_t
775 i;
776
777 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
778 {
779 PixelChannel
780 channel;
781
782 PixelTrait
783 colorize_traits,
784 traits;
785
cristycf1296e2012-08-26 23:40:49 +0000786 channel=GetPixelChannelChannel(image,i);
787 traits=GetPixelChannelTraits(image,channel);
788 colorize_traits=GetPixelChannelTraits(colorize_image,channel);
cristy0cf6da52012-08-25 00:35:24 +0000789 if ((traits == UndefinedPixelTrait) ||
790 (colorize_traits == UndefinedPixelTrait))
cristyd6803382012-04-10 01:41:25 +0000791 continue;
cristy0cf6da52012-08-25 00:35:24 +0000792 if (((colorize_traits & CopyPixelTrait) != 0) ||
793 (GetPixelMask(image,p) != 0))
794 {
795 SetPixelChannel(colorize_image,channel,p[i],q);
796 continue;
797 }
cristycf1296e2012-08-26 23:40:49 +0000798 SetPixelChannel(colorize_image,channel,
799 ClampToQuantum(Colorize(p[i],GetPixelInfoChannel(&blend_percentage,
800 channel),GetPixelInfoChannel(colorize,channel))),q);
cristy0cf6da52012-08-25 00:35:24 +0000801 }
cristyed231572011-07-14 02:18:59 +0000802 p+=GetPixelChannels(image);
803 q+=GetPixelChannels(colorize_image);
cristy3ed852e2009-09-05 21:47:34 +0000804 }
805 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
806 if (sync == MagickFalse)
807 status=MagickFalse;
808 if (image->progress_monitor != (MagickProgressMonitor) NULL)
809 {
810 MagickBooleanType
811 proceed;
812
cristy319a1e72010-02-21 15:13:11 +0000813#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +0000814 #pragma omp critical (MagickCore_ColorizeImage)
cristy3ed852e2009-09-05 21:47:34 +0000815#endif
816 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
817 if (proceed == MagickFalse)
818 status=MagickFalse;
819 }
820 }
821 image_view=DestroyCacheView(image_view);
822 colorize_view=DestroyCacheView(colorize_view);
823 if (status == MagickFalse)
824 colorize_image=DestroyImage(colorize_image);
825 return(colorize_image);
826}
827
828/*
829%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
830% %
831% %
832% %
cristye6365592010-04-02 17:31:23 +0000833% C o l o r M a t r i x I m a g e %
834% %
835% %
836% %
837%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
838%
839% ColorMatrixImage() applies color transformation to an image. This method
840% permits saturation changes, hue rotation, luminance to alpha, and various
841% other effects. Although variable-sized transformation matrices can be used,
842% typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
843% (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
844% except offsets are in column 6 rather than 5 (in support of CMYKA images)
845% and offsets are normalized (divide Flash offset by 255).
846%
847% The format of the ColorMatrixImage method is:
848%
849% Image *ColorMatrixImage(const Image *image,
850% const KernelInfo *color_matrix,ExceptionInfo *exception)
851%
852% A description of each parameter follows:
853%
854% o image: the image.
855%
856% o color_matrix: the color matrix.
857%
858% o exception: return any errors or warnings in this structure.
859%
860*/
anthonyfd706f92012-01-19 04:22:02 +0000861/* FUTURE: modify to make use of a MagickMatrix Mutliply function
862 That should be provided in "matrix.c"
863 (ASIDE: actually distorts should do this too but currently doesn't)
864*/
865
cristye6365592010-04-02 17:31:23 +0000866MagickExport Image *ColorMatrixImage(const Image *image,
867 const KernelInfo *color_matrix,ExceptionInfo *exception)
868{
869#define ColorMatrixImageTag "ColorMatrix/Image"
870
871 CacheView
872 *color_view,
873 *image_view;
874
875 double
876 ColorMatrix[6][6] =
877 {
878 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
879 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
880 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
881 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
882 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
883 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
884 };
885
886 Image
887 *color_image;
888
cristye6365592010-04-02 17:31:23 +0000889 MagickBooleanType
890 status;
891
cristybb503372010-05-27 20:51:26 +0000892 MagickOffsetType
893 progress;
894
895 register ssize_t
cristye6365592010-04-02 17:31:23 +0000896 i;
897
cristybb503372010-05-27 20:51:26 +0000898 ssize_t
899 u,
900 v,
901 y;
902
cristye6365592010-04-02 17:31:23 +0000903 /*
anthonyfd706f92012-01-19 04:22:02 +0000904 Map given color_matrix, into a 6x6 matrix RGBKA and a constant
cristye6365592010-04-02 17:31:23 +0000905 */
906 assert(image != (Image *) NULL);
907 assert(image->signature == MagickSignature);
908 if (image->debug != MagickFalse)
909 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
910 assert(exception != (ExceptionInfo *) NULL);
911 assert(exception->signature == MagickSignature);
912 i=0;
cristybb503372010-05-27 20:51:26 +0000913 for (v=0; v < (ssize_t) color_matrix->height; v++)
914 for (u=0; u < (ssize_t) color_matrix->width; u++)
cristye6365592010-04-02 17:31:23 +0000915 {
916 if ((v < 6) && (u < 6))
917 ColorMatrix[v][u]=color_matrix->values[i];
918 i++;
919 }
920 /*
921 Initialize color image.
922 */
cristy12550e62010-06-07 12:46:40 +0000923 color_image=CloneImage(image,0,0,MagickTrue,exception);
cristye6365592010-04-02 17:31:23 +0000924 if (color_image == (Image *) NULL)
925 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000926 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
cristye6365592010-04-02 17:31:23 +0000927 {
cristye6365592010-04-02 17:31:23 +0000928 color_image=DestroyImage(color_image);
929 return((Image *) NULL);
930 }
931 if (image->debug != MagickFalse)
932 {
933 char
934 format[MaxTextExtent],
935 *message;
936
937 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
938 " ColorMatrix image with color matrix:");
939 message=AcquireString("");
940 for (v=0; v < 6; v++)
941 {
942 *message='\0';
cristyb51dff52011-05-19 16:55:47 +0000943 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
cristye6365592010-04-02 17:31:23 +0000944 (void) ConcatenateString(&message,format);
945 for (u=0; u < 6; u++)
946 {
cristyb51dff52011-05-19 16:55:47 +0000947 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
cristye6365592010-04-02 17:31:23 +0000948 ColorMatrix[v][u]);
949 (void) ConcatenateString(&message,format);
950 }
951 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
952 }
953 message=DestroyString(message);
954 }
955 /*
anthonyfd706f92012-01-19 04:22:02 +0000956 Apply the ColorMatrix to image.
cristye6365592010-04-02 17:31:23 +0000957 */
958 status=MagickTrue;
959 progress=0;
cristydb070952012-04-20 14:33:00 +0000960 image_view=AcquireVirtualCacheView(image,exception);
961 color_view=AcquireAuthenticCacheView(color_image,exception);
cristye6365592010-04-02 17:31:23 +0000962#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +0000963 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +0000964 dynamic_number_threads(image,image->columns,image->rows,1)
cristye6365592010-04-02 17:31:23 +0000965#endif
cristybb503372010-05-27 20:51:26 +0000966 for (y=0; y < (ssize_t) image->rows; y++)
cristye6365592010-04-02 17:31:23 +0000967 {
cristyfcc25d92012-02-19 23:06:48 +0000968 PixelInfo
cristye6365592010-04-02 17:31:23 +0000969 pixel;
970
cristy4c08aed2011-07-01 19:47:50 +0000971 register const Quantum
cristye6365592010-04-02 17:31:23 +0000972 *restrict p;
973
cristy4c08aed2011-07-01 19:47:50 +0000974 register Quantum
975 *restrict q;
976
cristybb503372010-05-27 20:51:26 +0000977 register ssize_t
cristye6365592010-04-02 17:31:23 +0000978 x;
979
cristye6365592010-04-02 17:31:23 +0000980 if (status == MagickFalse)
981 continue;
982 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
983 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
984 exception);
cristy4c08aed2011-07-01 19:47:50 +0000985 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristye6365592010-04-02 17:31:23 +0000986 {
987 status=MagickFalse;
988 continue;
989 }
cristyfcc25d92012-02-19 23:06:48 +0000990 GetPixelInfo(image,&pixel);
cristybb503372010-05-27 20:51:26 +0000991 for (x=0; x < (ssize_t) image->columns; x++)
cristye6365592010-04-02 17:31:23 +0000992 {
cristybb503372010-05-27 20:51:26 +0000993 register ssize_t
cristye6365592010-04-02 17:31:23 +0000994 v;
995
cristybb503372010-05-27 20:51:26 +0000996 size_t
cristye6365592010-04-02 17:31:23 +0000997 height;
998
cristyfcc25d92012-02-19 23:06:48 +0000999 GetPixelInfoPixel(image,p,&pixel);
cristye6365592010-04-02 17:31:23 +00001000 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
cristybb503372010-05-27 20:51:26 +00001001 for (v=0; v < (ssize_t) height; v++)
cristye6365592010-04-02 17:31:23 +00001002 {
cristya19f1d72012-08-07 18:24:38 +00001003 double
cristyfcc25d92012-02-19 23:06:48 +00001004 sum;
1005
1006 sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
cristy4c08aed2011-07-01 19:47:50 +00001007 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
cristye6365592010-04-02 17:31:23 +00001008 if (image->colorspace == CMYKColorspace)
cristyfcc25d92012-02-19 23:06:48 +00001009 sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
cristy8a46d822012-08-28 23:32:39 +00001010 if (image->alpha_trait == BlendPixelTrait)
cristyfcc25d92012-02-19 23:06:48 +00001011 sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
1012 sum+=QuantumRange*ColorMatrix[v][5];
cristye6365592010-04-02 17:31:23 +00001013 switch (v)
1014 {
cristyfcc25d92012-02-19 23:06:48 +00001015 case 0: pixel.red=sum; break;
1016 case 1: pixel.green=sum; break;
1017 case 2: pixel.blue=sum; break;
1018 case 3: pixel.black=sum; break;
1019 case 4: pixel.alpha=sum; break;
1020 default: break;
cristye6365592010-04-02 17:31:23 +00001021 }
1022 }
cristyfcc25d92012-02-19 23:06:48 +00001023 SetPixelInfoPixel(color_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +00001024 p+=GetPixelChannels(image);
1025 q+=GetPixelChannels(color_image);
cristye6365592010-04-02 17:31:23 +00001026 }
1027 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1028 status=MagickFalse;
1029 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1030 {
1031 MagickBooleanType
1032 proceed;
1033
1034#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00001035 #pragma omp critical (MagickCore_ColorMatrixImage)
cristye6365592010-04-02 17:31:23 +00001036#endif
1037 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1038 image->rows);
1039 if (proceed == MagickFalse)
1040 status=MagickFalse;
1041 }
1042 }
1043 color_view=DestroyCacheView(color_view);
1044 image_view=DestroyCacheView(image_view);
1045 if (status == MagickFalse)
1046 color_image=DestroyImage(color_image);
1047 return(color_image);
1048}
1049
1050/*
1051%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1052% %
1053% %
1054% %
cristy3ed852e2009-09-05 21:47:34 +00001055+ D e s t r o y F x I n f o %
1056% %
1057% %
1058% %
1059%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1060%
1061% DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1062%
1063% The format of the DestroyFxInfo method is:
1064%
1065% ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1066%
1067% A description of each parameter follows:
1068%
1069% o fx_info: the fx info.
1070%
1071*/
cristy7832dc22011-09-05 01:21:53 +00001072MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
cristy3ed852e2009-09-05 21:47:34 +00001073{
cristybb503372010-05-27 20:51:26 +00001074 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001075 i;
1076
1077 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1078 fx_info->expression=DestroyString(fx_info->expression);
1079 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1080 fx_info->colors=DestroySplayTree(fx_info->colors);
cristy0ea377f2011-03-24 00:54:19 +00001081 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
cristyd76c51e2011-03-26 00:21:26 +00001082 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1083 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001084 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1085 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1086 return(fx_info);
1087}
1088
1089/*
1090%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1091% %
1092% %
1093% %
cristy3ed852e2009-09-05 21:47:34 +00001094+ 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 %
1095% %
1096% %
1097% %
1098%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1099%
1100% FxEvaluateChannelExpression() evaluates an expression and returns the
1101% results.
1102%
1103% The format of the FxEvaluateExpression method is:
1104%
cristya19f1d72012-08-07 18:24:38 +00001105% double FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00001106% const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00001107% double *alpha,Exceptioninfo *exception)
1108% double FxEvaluateExpression(FxInfo *fx_info,
1109% double *alpha,Exceptioninfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001110%
1111% A description of each parameter follows:
1112%
1113% o fx_info: the fx info.
1114%
1115% o channel: the channel.
1116%
1117% o x,y: the pixel position.
1118%
1119% o alpha: the result.
1120%
1121% o exception: return any errors or warnings in this structure.
1122%
1123*/
1124
cristy351842f2010-03-07 15:27:38 +00001125static inline double MagickMax(const double x,const double y)
1126{
1127 if (x > y)
1128 return(x);
1129 return(y);
1130}
1131
1132static inline double MagickMin(const double x,const double y)
1133{
1134 if (x < y)
1135 return(x);
1136 return(y);
1137}
1138
cristya19f1d72012-08-07 18:24:38 +00001139static double FxChannelStatistics(FxInfo *fx_info,Image *image,
cristy0568ffc2011-07-25 16:54:14 +00001140 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001141{
cristy5048d302012-08-07 01:05:16 +00001142 ChannelType
1143 channel_mask;
1144
cristy3ed852e2009-09-05 21:47:34 +00001145 char
1146 key[MaxTextExtent],
1147 statistic[MaxTextExtent];
1148
1149 const char
1150 *value;
1151
1152 register const char
1153 *p;
1154
cristy5048d302012-08-07 01:05:16 +00001155 channel_mask=UndefinedChannel;
cristy3ed852e2009-09-05 21:47:34 +00001156 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1157 if (*p == '.')
cristy3ed852e2009-09-05 21:47:34 +00001158 {
cristy5048d302012-08-07 01:05:16 +00001159 ssize_t
1160 option;
1161
1162 option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1);
1163 if (option >= 0)
1164 {
1165 channel=(PixelChannel) option;
1166 channel_mask=(ChannelType) (channel_mask | (1 << channel));
cristycf1296e2012-08-26 23:40:49 +00001167 SetPixelChannelMask(image,channel_mask);
cristy5048d302012-08-07 01:05:16 +00001168 }
cristy3ed852e2009-09-05 21:47:34 +00001169 }
cristyb51dff52011-05-19 16:55:47 +00001170 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
cristye8c25f92010-06-03 00:53:06 +00001171 (double) channel,symbol);
cristy3ed852e2009-09-05 21:47:34 +00001172 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1173 if (value != (const char *) NULL)
cristy5048d302012-08-07 01:05:16 +00001174 {
1175 if (channel_mask != UndefinedChannel)
cristycf1296e2012-08-26 23:40:49 +00001176 SetPixelChannelMask(image,channel_mask);
cristy5048d302012-08-07 01:05:16 +00001177 return(QuantumScale*StringToDouble(value,(char **) NULL));
1178 }
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 }
cristy5048d302012-08-07 01:05:16 +00001243 if (channel_mask != UndefinedChannel)
cristycf1296e2012-08-26 23:40:49 +00001244 SetPixelChannelMask(image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00001245 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1246 ConstantString(statistic));
cristydbdd0e32011-11-04 23:29:40 +00001247 return(QuantumScale*StringToDouble(statistic,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001248}
1249
cristya19f1d72012-08-07 18:24:38 +00001250static double
cristy0568ffc2011-07-25 16:54:14 +00001251 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
cristya19f1d72012-08-07 18:24:38 +00001252 const ssize_t,const char *,double *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +00001253
cristyb0aad4c2011-11-02 19:30:35 +00001254static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1255{
1256 if (beta != 0)
1257 return(FxGCD(beta,alpha % beta));
1258 return(alpha);
1259}
1260
cristy3ed852e2009-09-05 21:47:34 +00001261static inline const char *FxSubexpression(const char *expression,
1262 ExceptionInfo *exception)
1263{
1264 const char
1265 *subexpression;
1266
cristybb503372010-05-27 20:51:26 +00001267 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001268 level;
1269
1270 level=0;
1271 subexpression=expression;
1272 while ((*subexpression != '\0') &&
1273 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1274 {
1275 if (strchr("(",(int) *subexpression) != (char *) NULL)
1276 level++;
1277 else
1278 if (strchr(")",(int) *subexpression) != (char *) NULL)
1279 level--;
1280 subexpression++;
1281 }
1282 if (*subexpression == '\0')
1283 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
anthonye5b39652012-04-21 05:37:29 +00001284 "UnbalancedParenthesis","'%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00001285 return(subexpression);
1286}
1287
cristya19f1d72012-08-07 18:24:38 +00001288static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001289 const ssize_t x,const ssize_t y,const char *expression,
1290 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001291{
1292 char
1293 *q,
1294 subexpression[MaxTextExtent],
1295 symbol[MaxTextExtent];
1296
1297 const char
1298 *p,
1299 *value;
1300
1301 Image
1302 *image;
1303
cristy4c08aed2011-07-01 19:47:50 +00001304 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001305 pixel;
1306
cristya19f1d72012-08-07 18:24:38 +00001307 double
cristy3ed852e2009-09-05 21:47:34 +00001308 alpha,
1309 beta;
1310
1311 PointInfo
1312 point;
1313
cristybb503372010-05-27 20:51:26 +00001314 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001315 i;
1316
1317 size_t
cristy1707c6c2012-01-18 23:30:54 +00001318 length,
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,
anthonye5b39652012-04-21 05:37:29 +00001432 "NoSuchImage","'%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00001433 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);
cristy1707c6c2012-01-18 23:30:54 +00001438 if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
1439 (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
cristy3ed852e2009-09-05 21:47:34 +00001440 (LocaleCompare(p,"saturation") != 0) &&
1441 (LocaleCompare(p,"lightness") != 0))
1442 {
1443 char
1444 name[MaxTextExtent];
1445
1446 (void) CopyMagickString(name,p,MaxTextExtent);
1447 for (q=name+(strlen(name)-1); q > name; q--)
1448 {
1449 if (*q == ')')
1450 break;
1451 if (*q == '.')
1452 {
1453 *q='\0';
1454 break;
1455 }
1456 }
1457 if ((strlen(name) > 2) &&
1458 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1459 {
cristy4c08aed2011-07-01 19:47:50 +00001460 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001461 *color;
1462
cristy4c08aed2011-07-01 19:47:50 +00001463 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1464 if (color != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001465 {
1466 pixel=(*color);
1467 p+=strlen(name);
1468 }
1469 else
cristy1707c6c2012-01-18 23:30:54 +00001470 {
1471 MagickBooleanType
1472 status;
1473
1474 status=QueryColorCompliance(name,AllCompliance,&pixel,
1475 fx_info->exception);
1476 if (status != MagickFalse)
1477 {
1478 (void) AddValueToSplayTree(fx_info->colors,ConstantString(
1479 name),ClonePixelInfo(&pixel));
1480 p+=strlen(name);
1481 }
1482 }
cristy3ed852e2009-09-05 21:47:34 +00001483 }
1484 }
1485 (void) CopyMagickString(symbol,p,MaxTextExtent);
1486 StripString(symbol);
1487 if (*symbol == '\0')
1488 {
1489 switch (channel)
1490 {
cristy0568ffc2011-07-25 16:54:14 +00001491 case RedPixelChannel: return(QuantumScale*pixel.red);
1492 case GreenPixelChannel: return(QuantumScale*pixel.green);
1493 case BluePixelChannel: return(QuantumScale*pixel.blue);
1494 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001495 {
1496 if (image->colorspace != CMYKColorspace)
1497 {
1498 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +00001499 ImageError,"ColorSeparatedImageRequired","'%s'",
cristy3ed852e2009-09-05 21:47:34 +00001500 image->filename);
1501 return(0.0);
1502 }
cristy4c08aed2011-07-01 19:47:50 +00001503 return(QuantumScale*pixel.black);
1504 }
cristy0568ffc2011-07-25 16:54:14 +00001505 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001506 {
cristya19f1d72012-08-07 18:24:38 +00001507 double
cristy4c08aed2011-07-01 19:47:50 +00001508 alpha;
1509
cristy8a46d822012-08-28 23:32:39 +00001510 if (pixel.alpha_trait != BlendPixelTrait)
cristy4c08aed2011-07-01 19:47:50 +00001511 return(1.0);
cristya19f1d72012-08-07 18:24:38 +00001512 alpha=(double) (QuantumScale*pixel.alpha);
cristy4c08aed2011-07-01 19:47:50 +00001513 return(alpha);
cristy3ed852e2009-09-05 21:47:34 +00001514 }
cristya382aca2011-12-06 18:22:48 +00001515 case IndexPixelChannel:
1516 return(0.0);
cristyb3a73b52011-07-26 01:34:43 +00001517 case IntensityPixelChannel:
cristyf364ed42010-12-15 01:54:43 +00001518 {
cristy4c08aed2011-07-01 19:47:50 +00001519 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristyf364ed42010-12-15 01:54:43 +00001520 }
cristy3ed852e2009-09-05 21:47:34 +00001521 default:
1522 break;
1523 }
1524 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
anthonye5b39652012-04-21 05:37:29 +00001525 "UnableToParseExpression","'%s'",p);
cristy3ed852e2009-09-05 21:47:34 +00001526 return(0.0);
1527 }
1528 switch (*symbol)
1529 {
1530 case 'A':
1531 case 'a':
1532 {
1533 if (LocaleCompare(symbol,"a") == 0)
cristya19f1d72012-08-07 18:24:38 +00001534 return((double) (QuantumScale*pixel.alpha));
cristy3ed852e2009-09-05 21:47:34 +00001535 break;
1536 }
1537 case 'B':
1538 case 'b':
1539 {
1540 if (LocaleCompare(symbol,"b") == 0)
1541 return(QuantumScale*pixel.blue);
1542 break;
1543 }
1544 case 'C':
1545 case 'c':
1546 {
1547 if (LocaleNCompare(symbol,"channel",7) == 0)
1548 {
1549 GeometryInfo
1550 channel_info;
1551
1552 MagickStatusType
1553 flags;
1554
1555 flags=ParseGeometry(symbol+7,&channel_info);
1556 if (image->colorspace == CMYKColorspace)
1557 switch (channel)
1558 {
cristy0568ffc2011-07-25 16:54:14 +00001559 case CyanPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001560 {
1561 if ((flags & RhoValue) == 0)
1562 return(0.0);
1563 return(channel_info.rho);
1564 }
cristy0568ffc2011-07-25 16:54:14 +00001565 case MagentaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001566 {
1567 if ((flags & SigmaValue) == 0)
1568 return(0.0);
1569 return(channel_info.sigma);
1570 }
cristy0568ffc2011-07-25 16:54:14 +00001571 case YellowPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001572 {
1573 if ((flags & XiValue) == 0)
1574 return(0.0);
1575 return(channel_info.xi);
1576 }
cristy0568ffc2011-07-25 16:54:14 +00001577 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001578 {
1579 if ((flags & PsiValue) == 0)
1580 return(0.0);
1581 return(channel_info.psi);
1582 }
cristy0568ffc2011-07-25 16:54:14 +00001583 case AlphaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001584 {
1585 if ((flags & ChiValue) == 0)
1586 return(0.0);
1587 return(channel_info.chi);
1588 }
1589 default:
1590 return(0.0);
1591 }
1592 switch (channel)
1593 {
cristy0568ffc2011-07-25 16:54:14 +00001594 case RedPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001595 {
1596 if ((flags & RhoValue) == 0)
1597 return(0.0);
1598 return(channel_info.rho);
1599 }
cristy0568ffc2011-07-25 16:54:14 +00001600 case GreenPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001601 {
1602 if ((flags & SigmaValue) == 0)
1603 return(0.0);
1604 return(channel_info.sigma);
1605 }
cristy0568ffc2011-07-25 16:54:14 +00001606 case BluePixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001607 {
1608 if ((flags & XiValue) == 0)
1609 return(0.0);
1610 return(channel_info.xi);
1611 }
cristy0568ffc2011-07-25 16:54:14 +00001612 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001613 {
1614 if ((flags & ChiValue) == 0)
1615 return(0.0);
1616 return(channel_info.chi);
1617 }
cristy0568ffc2011-07-25 16:54:14 +00001618 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001619 {
1620 if ((flags & PsiValue) == 0)
1621 return(0.0);
1622 return(channel_info.psi);
1623 }
cristy3ed852e2009-09-05 21:47:34 +00001624 default:
1625 return(0.0);
1626 }
1627 return(0.0);
1628 }
1629 if (LocaleCompare(symbol,"c") == 0)
1630 return(QuantumScale*pixel.red);
1631 break;
1632 }
1633 case 'D':
1634 case 'd':
1635 {
1636 if (LocaleNCompare(symbol,"depth",5) == 0)
1637 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1638 break;
1639 }
1640 case 'G':
1641 case 'g':
1642 {
1643 if (LocaleCompare(symbol,"g") == 0)
1644 return(QuantumScale*pixel.green);
1645 break;
1646 }
1647 case 'K':
1648 case 'k':
1649 {
1650 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1651 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1652 if (LocaleCompare(symbol,"k") == 0)
1653 {
1654 if (image->colorspace != CMYKColorspace)
1655 {
1656 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +00001657 OptionError,"ColorSeparatedImageRequired","'%s'",
cristy3ed852e2009-09-05 21:47:34 +00001658 image->filename);
1659 return(0.0);
1660 }
cristy4c08aed2011-07-01 19:47:50 +00001661 return(QuantumScale*pixel.black);
cristy3ed852e2009-09-05 21:47:34 +00001662 }
1663 break;
1664 }
1665 case 'H':
1666 case 'h':
1667 {
1668 if (LocaleCompare(symbol,"h") == 0)
cristya19f1d72012-08-07 18:24:38 +00001669 return((double) image->rows);
cristy3ed852e2009-09-05 21:47:34 +00001670 if (LocaleCompare(symbol,"hue") == 0)
1671 {
1672 double
1673 hue,
1674 lightness,
1675 saturation;
1676
cristy0a39a5c2012-06-27 12:51:45 +00001677 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001678 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001679 return(hue);
1680 }
1681 break;
1682 }
1683 case 'I':
1684 case 'i':
1685 {
1686 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1687 (LocaleCompare(symbol,"image.minima") == 0) ||
1688 (LocaleCompare(symbol,"image.maxima") == 0) ||
1689 (LocaleCompare(symbol,"image.mean") == 0) ||
1690 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1691 (LocaleCompare(symbol,"image.skewness") == 0) ||
1692 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1693 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1694 if (LocaleCompare(symbol,"image.resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001695 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001696 if (LocaleCompare(symbol,"image.resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001697 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001698 if (LocaleCompare(symbol,"intensity") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001699 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001700 if (LocaleCompare(symbol,"i") == 0)
cristya19f1d72012-08-07 18:24:38 +00001701 return((double) x);
cristy3ed852e2009-09-05 21:47:34 +00001702 break;
1703 }
1704 case 'J':
1705 case 'j':
1706 {
1707 if (LocaleCompare(symbol,"j") == 0)
cristya19f1d72012-08-07 18:24:38 +00001708 return((double) y);
cristy3ed852e2009-09-05 21:47:34 +00001709 break;
1710 }
1711 case 'L':
1712 case 'l':
1713 {
1714 if (LocaleCompare(symbol,"lightness") == 0)
1715 {
1716 double
1717 hue,
1718 lightness,
1719 saturation;
1720
cristy0a39a5c2012-06-27 12:51:45 +00001721 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001722 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001723 return(lightness);
1724 }
1725 if (LocaleCompare(symbol,"luminance") == 0)
1726 {
1727 double
1728 luminence;
1729
cristy94d535d2012-08-17 17:39:40 +00001730 luminence=0.21267*pixel.red+0.71516*pixel.green+0.07217*pixel.blue;
cristy3ed852e2009-09-05 21:47:34 +00001731 return(QuantumScale*luminence);
1732 }
1733 break;
1734 }
1735 case 'M':
1736 case 'm':
1737 {
1738 if (LocaleNCompare(symbol,"maxima",6) == 0)
1739 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1740 if (LocaleNCompare(symbol,"mean",4) == 0)
1741 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1742 if (LocaleNCompare(symbol,"minima",6) == 0)
1743 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1744 if (LocaleCompare(symbol,"m") == 0)
1745 return(QuantumScale*pixel.blue);
1746 break;
1747 }
1748 case 'N':
1749 case 'n':
1750 {
1751 if (LocaleCompare(symbol,"n") == 0)
cristya19f1d72012-08-07 18:24:38 +00001752 return((double) GetImageListLength(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001753 break;
1754 }
1755 case 'O':
1756 case 'o':
1757 {
1758 if (LocaleCompare(symbol,"o") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001759 return(QuantumScale*pixel.alpha);
cristy3ed852e2009-09-05 21:47:34 +00001760 break;
1761 }
1762 case 'P':
1763 case 'p':
1764 {
1765 if (LocaleCompare(symbol,"page.height") == 0)
cristya19f1d72012-08-07 18:24:38 +00001766 return((double) image->page.height);
cristy3ed852e2009-09-05 21:47:34 +00001767 if (LocaleCompare(symbol,"page.width") == 0)
cristya19f1d72012-08-07 18:24:38 +00001768 return((double) image->page.width);
cristy3ed852e2009-09-05 21:47:34 +00001769 if (LocaleCompare(symbol,"page.x") == 0)
cristya19f1d72012-08-07 18:24:38 +00001770 return((double) image->page.x);
cristy3ed852e2009-09-05 21:47:34 +00001771 if (LocaleCompare(symbol,"page.y") == 0)
cristya19f1d72012-08-07 18:24:38 +00001772 return((double) image->page.y);
cristy3ed852e2009-09-05 21:47:34 +00001773 break;
1774 }
1775 case 'R':
1776 case 'r':
1777 {
1778 if (LocaleCompare(symbol,"resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001779 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001780 if (LocaleCompare(symbol,"resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001781 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001782 if (LocaleCompare(symbol,"r") == 0)
1783 return(QuantumScale*pixel.red);
1784 break;
1785 }
1786 case 'S':
1787 case 's':
1788 {
1789 if (LocaleCompare(symbol,"saturation") == 0)
1790 {
1791 double
1792 hue,
1793 lightness,
1794 saturation;
1795
cristy0a39a5c2012-06-27 12:51:45 +00001796 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
cristyda1f9c12011-10-02 21:39:49 +00001797 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001798 return(saturation);
1799 }
1800 if (LocaleNCompare(symbol,"skewness",8) == 0)
1801 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1802 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1803 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1804 break;
1805 }
1806 case 'T':
1807 case 't':
1808 {
1809 if (LocaleCompare(symbol,"t") == 0)
cristya19f1d72012-08-07 18:24:38 +00001810 return((double) GetImageIndexInList(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001811 break;
1812 }
1813 case 'W':
1814 case 'w':
1815 {
1816 if (LocaleCompare(symbol,"w") == 0)
cristya19f1d72012-08-07 18:24:38 +00001817 return((double) image->columns);
cristy3ed852e2009-09-05 21:47:34 +00001818 break;
1819 }
1820 case 'Y':
1821 case 'y':
1822 {
1823 if (LocaleCompare(symbol,"y") == 0)
1824 return(QuantumScale*pixel.green);
1825 break;
1826 }
1827 case 'Z':
1828 case 'z':
1829 {
1830 if (LocaleCompare(symbol,"z") == 0)
1831 {
cristya19f1d72012-08-07 18:24:38 +00001832 double
cristy3ed852e2009-09-05 21:47:34 +00001833 depth;
1834
cristya19f1d72012-08-07 18:24:38 +00001835 depth=(double) GetImageDepth(image,fx_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001836 return(depth);
1837 }
1838 break;
1839 }
1840 default:
1841 break;
1842 }
1843 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1844 if (value != (const char *) NULL)
cristya19f1d72012-08-07 18:24:38 +00001845 return((double) StringToDouble(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001846 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
anthonye5b39652012-04-21 05:37:29 +00001847 "UnableToParseExpression","'%s'",symbol);
cristy3ed852e2009-09-05 21:47:34 +00001848 return(0.0);
1849}
1850
1851static const char *FxOperatorPrecedence(const char *expression,
1852 ExceptionInfo *exception)
1853{
1854 typedef enum
1855 {
1856 UndefinedPrecedence,
1857 NullPrecedence,
1858 BitwiseComplementPrecedence,
1859 ExponentPrecedence,
cristy116af162010-08-13 01:25:47 +00001860 ExponentialNotationPrecedence,
cristy3ed852e2009-09-05 21:47:34 +00001861 MultiplyPrecedence,
1862 AdditionPrecedence,
1863 ShiftPrecedence,
1864 RelationalPrecedence,
1865 EquivalencyPrecedence,
1866 BitwiseAndPrecedence,
1867 BitwiseOrPrecedence,
1868 LogicalAndPrecedence,
1869 LogicalOrPrecedence,
1870 TernaryPrecedence,
1871 AssignmentPrecedence,
1872 CommaPrecedence,
1873 SeparatorPrecedence
1874 } FxPrecedence;
1875
1876 FxPrecedence
1877 precedence,
1878 target;
1879
1880 register const char
1881 *subexpression;
1882
1883 register int
1884 c;
1885
cristybb503372010-05-27 20:51:26 +00001886 size_t
cristy3ed852e2009-09-05 21:47:34 +00001887 level;
1888
1889 c=0;
1890 level=0;
1891 subexpression=(const char *) NULL;
1892 target=NullPrecedence;
1893 while (*expression != '\0')
1894 {
1895 precedence=UndefinedPrecedence;
1896 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1897 {
1898 expression++;
1899 continue;
1900 }
cristy488fa882010-03-01 22:34:24 +00001901 switch (*expression)
1902 {
1903 case 'A':
1904 case 'a':
cristy3ed852e2009-09-05 21:47:34 +00001905 {
cristyb33454f2011-08-03 02:10:45 +00001906#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00001907 if (LocaleNCompare(expression,"acosh",5) == 0)
1908 {
1909 expression+=5;
1910 break;
1911 }
cristyb33454f2011-08-03 02:10:45 +00001912#endif
1913#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00001914 if (LocaleNCompare(expression,"asinh",5) == 0)
1915 {
1916 expression+=5;
1917 break;
1918 }
cristyb33454f2011-08-03 02:10:45 +00001919#endif
1920#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00001921 if (LocaleNCompare(expression,"atanh",5) == 0)
cristy488fa882010-03-01 22:34:24 +00001922 {
1923 expression+=5;
1924 break;
1925 }
cristyb33454f2011-08-03 02:10:45 +00001926#endif
anthony62838e52012-05-24 12:41:54 +00001927 if (LocaleNCompare(expression,"atan2",5) == 0)
1928 {
1929 expression+=5;
1930 break;
1931 }
cristy488fa882010-03-01 22:34:24 +00001932 break;
cristy3ed852e2009-09-05 21:47:34 +00001933 }
cristy62d455f2011-11-03 11:42:28 +00001934 case 'E':
1935 case 'e':
1936 {
1937 if ((LocaleNCompare(expression,"E+",2) == 0) ||
1938 (LocaleNCompare(expression,"E-",2) == 0))
1939 {
1940 expression+=2; /* scientific notation */
1941 break;
1942 }
1943 }
cristy488fa882010-03-01 22:34:24 +00001944 case 'J':
1945 case 'j':
1946 {
1947 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1948 (LocaleNCompare(expression,"j1",2) == 0))
1949 {
1950 expression+=2;
1951 break;
1952 }
1953 break;
1954 }
cristy2def9322010-06-18 23:59:37 +00001955 case '#':
1956 {
1957 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
1958 expression++;
1959 break;
1960 }
cristy488fa882010-03-01 22:34:24 +00001961 default:
1962 break;
1963 }
cristy3ed852e2009-09-05 21:47:34 +00001964 if ((c == (int) '{') || (c == (int) '['))
1965 level++;
1966 else
1967 if ((c == (int) '}') || (c == (int) ']'))
1968 level--;
1969 if (level == 0)
1970 switch ((unsigned char) *expression)
1971 {
1972 case '~':
1973 case '!':
1974 {
1975 precedence=BitwiseComplementPrecedence;
1976 break;
1977 }
1978 case '^':
cristy6621e252010-08-13 00:42:57 +00001979 case '@':
cristy3ed852e2009-09-05 21:47:34 +00001980 {
1981 precedence=ExponentPrecedence;
1982 break;
1983 }
1984 default:
1985 {
1986 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
1987 (strchr(")",c) != (char *) NULL))) &&
1988 (((islower((int) ((char) *expression)) != 0) ||
1989 (strchr("(",(int) *expression) != (char *) NULL)) ||
1990 ((isdigit((int) ((char) c)) == 0) &&
1991 (isdigit((int) ((char) *expression)) != 0))) &&
1992 (strchr("xy",(int) *expression) == (char *) NULL))
1993 precedence=MultiplyPrecedence;
1994 break;
1995 }
1996 case '*':
1997 case '/':
1998 case '%':
1999 {
2000 precedence=MultiplyPrecedence;
2001 break;
2002 }
2003 case '+':
2004 case '-':
2005 {
2006 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
2007 (isalpha(c) != 0))
2008 precedence=AdditionPrecedence;
2009 break;
2010 }
2011 case LeftShiftOperator:
2012 case RightShiftOperator:
2013 {
2014 precedence=ShiftPrecedence;
2015 break;
2016 }
2017 case '<':
2018 case LessThanEqualOperator:
2019 case GreaterThanEqualOperator:
2020 case '>':
2021 {
2022 precedence=RelationalPrecedence;
2023 break;
2024 }
2025 case EqualOperator:
2026 case NotEqualOperator:
2027 {
2028 precedence=EquivalencyPrecedence;
2029 break;
2030 }
2031 case '&':
2032 {
2033 precedence=BitwiseAndPrecedence;
2034 break;
2035 }
2036 case '|':
2037 {
2038 precedence=BitwiseOrPrecedence;
2039 break;
2040 }
2041 case LogicalAndOperator:
2042 {
2043 precedence=LogicalAndPrecedence;
2044 break;
2045 }
2046 case LogicalOrOperator:
2047 {
2048 precedence=LogicalOrPrecedence;
2049 break;
2050 }
cristy116af162010-08-13 01:25:47 +00002051 case ExponentialNotation:
2052 {
2053 precedence=ExponentialNotationPrecedence;
2054 break;
2055 }
cristy3ed852e2009-09-05 21:47:34 +00002056 case ':':
2057 case '?':
2058 {
2059 precedence=TernaryPrecedence;
2060 break;
2061 }
2062 case '=':
2063 {
2064 precedence=AssignmentPrecedence;
2065 break;
2066 }
2067 case ',':
2068 {
2069 precedence=CommaPrecedence;
2070 break;
2071 }
2072 case ';':
2073 {
2074 precedence=SeparatorPrecedence;
2075 break;
2076 }
2077 }
2078 if ((precedence == BitwiseComplementPrecedence) ||
2079 (precedence == TernaryPrecedence) ||
2080 (precedence == AssignmentPrecedence))
2081 {
2082 if (precedence > target)
2083 {
2084 /*
2085 Right-to-left associativity.
2086 */
2087 target=precedence;
2088 subexpression=expression;
2089 }
2090 }
2091 else
2092 if (precedence >= target)
2093 {
2094 /*
2095 Left-to-right associativity.
2096 */
2097 target=precedence;
2098 subexpression=expression;
2099 }
2100 if (strchr("(",(int) *expression) != (char *) NULL)
2101 expression=FxSubexpression(expression,exception);
2102 c=(int) (*expression++);
2103 }
2104 return(subexpression);
2105}
2106
cristya19f1d72012-08-07 18:24:38 +00002107static double FxEvaluateSubexpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002108 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00002109 const char *expression,double *beta,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002110{
2111 char
2112 *q,
2113 subexpression[MaxTextExtent];
2114
cristya19f1d72012-08-07 18:24:38 +00002115 double
cristy3ed852e2009-09-05 21:47:34 +00002116 alpha,
2117 gamma;
2118
2119 register const char
2120 *p;
2121
2122 *beta=0.0;
2123 if (exception->severity != UndefinedException)
2124 return(0.0);
2125 while (isspace((int) *expression) != 0)
2126 expression++;
2127 if (*expression == '\0')
2128 {
2129 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
anthonye5b39652012-04-21 05:37:29 +00002130 "MissingExpression","'%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002131 return(0.0);
2132 }
cristy66322f02010-05-17 11:40:48 +00002133 *subexpression='\0';
cristy3ed852e2009-09-05 21:47:34 +00002134 p=FxOperatorPrecedence(expression,exception);
2135 if (p != (const char *) NULL)
2136 {
2137 (void) CopyMagickString(subexpression,expression,(size_t)
2138 (p-expression+1));
2139 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2140 exception);
2141 switch ((unsigned char) *p)
2142 {
2143 case '~':
2144 {
2145 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002146 *beta=(double) (~(size_t) *beta);
cristy3ed852e2009-09-05 21:47:34 +00002147 return(*beta);
2148 }
2149 case '!':
2150 {
2151 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2152 return(*beta == 0.0 ? 1.0 : 0.0);
2153 }
2154 case '^':
2155 {
2156 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2157 channel,x,y,++p,beta,exception));
2158 return(*beta);
2159 }
2160 case '*':
cristy116af162010-08-13 01:25:47 +00002161 case ExponentialNotation:
cristy3ed852e2009-09-05 21:47:34 +00002162 {
2163 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2164 return(alpha*(*beta));
2165 }
2166 case '/':
2167 {
2168 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2169 if (*beta == 0.0)
2170 {
2171 if (exception->severity == UndefinedException)
2172 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +00002173 OptionError,"DivideByZero","'%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002174 return(0.0);
2175 }
2176 return(alpha/(*beta));
2177 }
2178 case '%':
2179 {
2180 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2181 *beta=fabs(floor(((double) *beta)+0.5));
2182 if (*beta == 0.0)
2183 {
2184 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +00002185 OptionError,"DivideByZero","'%s'",expression);
cristy3ed852e2009-09-05 21:47:34 +00002186 return(0.0);
2187 }
2188 return(fmod((double) alpha,(double) *beta));
2189 }
2190 case '+':
2191 {
2192 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2193 return(alpha+(*beta));
2194 }
2195 case '-':
2196 {
2197 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2198 return(alpha-(*beta));
2199 }
2200 case LeftShiftOperator:
2201 {
2202 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002203 *beta=(double) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002204 return(*beta);
2205 }
2206 case RightShiftOperator:
2207 {
2208 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002209 *beta=(double) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002210 return(*beta);
2211 }
2212 case '<':
2213 {
2214 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2215 return(alpha < *beta ? 1.0 : 0.0);
2216 }
2217 case LessThanEqualOperator:
2218 {
2219 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2220 return(alpha <= *beta ? 1.0 : 0.0);
2221 }
2222 case '>':
2223 {
2224 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2225 return(alpha > *beta ? 1.0 : 0.0);
2226 }
2227 case GreaterThanEqualOperator:
2228 {
2229 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2230 return(alpha >= *beta ? 1.0 : 0.0);
2231 }
2232 case EqualOperator:
2233 {
2234 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristy9b528342012-06-02 00:59:20 +00002235 return(fabs(alpha-(*beta)) < MagickEpsilon ? MagickEpsilon : 0.0);
cristy3ed852e2009-09-05 21:47:34 +00002236 }
2237 case NotEqualOperator:
2238 {
2239 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristy972050b2012-06-04 22:09:17 +00002240 return(fabs(alpha-(*beta)) >= MagickEpsilon ? 1.0 : 0.0);
cristy3ed852e2009-09-05 21:47:34 +00002241 }
2242 case '&':
2243 {
2244 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002245 *beta=(double) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002246 return(*beta);
2247 }
2248 case '|':
2249 {
2250 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristya19f1d72012-08-07 18:24:38 +00002251 *beta=(double) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002252 return(*beta);
2253 }
2254 case LogicalAndOperator:
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 LogicalOrOperator:
2261 {
2262 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2263 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2264 return(*beta);
2265 }
2266 case '?':
2267 {
cristya19f1d72012-08-07 18:24:38 +00002268 double
cristy3ed852e2009-09-05 21:47:34 +00002269 gamma;
2270
2271 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2272 q=subexpression;
2273 p=StringToken(":",&q);
2274 if (q == (char *) NULL)
2275 {
2276 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +00002277 OptionError,"UnableToParseExpression","'%s'",subexpression);
cristy3ed852e2009-09-05 21:47:34 +00002278 return(0.0);
2279 }
cristy972050b2012-06-04 22:09:17 +00002280 if (fabs((double) alpha) >= MagickEpsilon)
cristy3ed852e2009-09-05 21:47:34 +00002281 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2282 else
2283 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2284 return(gamma);
2285 }
2286 case '=':
2287 {
2288 char
2289 numeric[MaxTextExtent];
2290
2291 q=subexpression;
2292 while (isalpha((int) ((unsigned char) *q)) != 0)
2293 q++;
2294 if (*q != '\0')
2295 {
2296 (void) ThrowMagickException(exception,GetMagickModule(),
anthonye5b39652012-04-21 05:37:29 +00002297 OptionError,"UnableToParseExpression","'%s'",subexpression);
cristy3ed852e2009-09-05 21:47:34 +00002298 return(0.0);
2299 }
2300 ClearMagickException(exception);
2301 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristyb51dff52011-05-19 16:55:47 +00002302 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
cristy8cd5b312010-01-07 01:10:24 +00002303 *beta);
cristy3ed852e2009-09-05 21:47:34 +00002304 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2305 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2306 subexpression),ConstantString(numeric));
2307 return(*beta);
2308 }
2309 case ',':
2310 {
2311 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2312 return(alpha);
2313 }
2314 case ';':
2315 {
2316 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2317 return(*beta);
2318 }
2319 default:
2320 {
2321 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2322 exception);
2323 return(gamma);
2324 }
2325 }
2326 }
2327 if (strchr("(",(int) *expression) != (char *) NULL)
2328 {
2329 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2330 subexpression[strlen(subexpression)-1]='\0';
2331 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2332 exception);
2333 return(gamma);
2334 }
cristy8b8a3ae2010-10-23 18:49:46 +00002335 switch (*expression)
cristy3ed852e2009-09-05 21:47:34 +00002336 {
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);
2347 return(-1.0*gamma);
2348 }
2349 case '~':
2350 {
2351 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2352 exception);
cristya19f1d72012-08-07 18:24:38 +00002353 return((double) (~(size_t) (gamma+0.5)));
cristy3ed852e2009-09-05 21:47:34 +00002354 }
2355 case 'A':
2356 case 'a':
2357 {
2358 if (LocaleNCompare(expression,"abs",3) == 0)
2359 {
2360 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2361 exception);
cristya19f1d72012-08-07 18:24:38 +00002362 return((double) fabs((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002363 }
cristyb33454f2011-08-03 02:10:45 +00002364#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00002365 if (LocaleNCompare(expression,"acosh",5) == 0)
2366 {
2367 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2368 exception);
cristya19f1d72012-08-07 18:24:38 +00002369 return((double) acosh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002370 }
cristyb33454f2011-08-03 02:10:45 +00002371#endif
cristy3ed852e2009-09-05 21:47:34 +00002372 if (LocaleNCompare(expression,"acos",4) == 0)
2373 {
2374 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2375 exception);
cristya19f1d72012-08-07 18:24:38 +00002376 return((double) acos((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002377 }
cristy43c22f42010-03-30 12:34:07 +00002378#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002379 if (LocaleNCompare(expression,"airy",4) == 0)
2380 {
2381 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2382 exception);
2383 if (alpha == 0.0)
cristy2dd03222010-03-30 22:12:11 +00002384 return(1.0);
2385 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
cristy43c22f42010-03-30 12:34:07 +00002386 return(gamma*gamma);
cristyee56cf12010-03-01 22:17:06 +00002387 }
cristy43c22f42010-03-30 12:34:07 +00002388#endif
cristyb33454f2011-08-03 02:10:45 +00002389#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00002390 if (LocaleNCompare(expression,"asinh",5) == 0)
2391 {
2392 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2393 exception);
cristya19f1d72012-08-07 18:24:38 +00002394 return((double) asinh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002395 }
cristyb33454f2011-08-03 02:10:45 +00002396#endif
cristy3ed852e2009-09-05 21:47:34 +00002397 if (LocaleNCompare(expression,"asin",4) == 0)
2398 {
2399 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2400 exception);
cristya19f1d72012-08-07 18:24:38 +00002401 return((double) asin((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002402 }
2403 if (LocaleNCompare(expression,"alt",3) == 0)
2404 {
2405 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2406 exception);
cristybb503372010-05-27 20:51:26 +00002407 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
cristy3ed852e2009-09-05 21:47:34 +00002408 }
2409 if (LocaleNCompare(expression,"atan2",5) == 0)
2410 {
2411 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2412 exception);
cristya19f1d72012-08-07 18:24:38 +00002413 return((double) atan2((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002414 }
cristyb33454f2011-08-03 02:10:45 +00002415#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00002416 if (LocaleNCompare(expression,"atanh",5) == 0)
2417 {
2418 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2419 exception);
cristya19f1d72012-08-07 18:24:38 +00002420 return((double) atanh((double) alpha));
cristy363772a2011-07-28 23:25:33 +00002421 }
cristyb33454f2011-08-03 02:10:45 +00002422#endif
cristy3ed852e2009-09-05 21:47:34 +00002423 if (LocaleNCompare(expression,"atan",4) == 0)
2424 {
2425 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2426 exception);
cristya19f1d72012-08-07 18:24:38 +00002427 return((double) atan((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002428 }
2429 if (LocaleCompare(expression,"a") == 0)
2430 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2431 break;
2432 }
2433 case 'B':
2434 case 'b':
2435 {
2436 if (LocaleCompare(expression,"b") == 0)
2437 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2438 break;
2439 }
2440 case 'C':
2441 case 'c':
2442 {
2443 if (LocaleNCompare(expression,"ceil",4) == 0)
2444 {
2445 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2446 exception);
cristya19f1d72012-08-07 18:24:38 +00002447 return((double) ceil((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002448 }
2449 if (LocaleNCompare(expression,"cosh",4) == 0)
2450 {
2451 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2452 exception);
cristya19f1d72012-08-07 18:24:38 +00002453 return((double) cosh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002454 }
2455 if (LocaleNCompare(expression,"cos",3) == 0)
2456 {
2457 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2458 exception);
cristya19f1d72012-08-07 18:24:38 +00002459 return((double) cos((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002460 }
2461 if (LocaleCompare(expression,"c") == 0)
2462 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2463 break;
2464 }
2465 case 'D':
2466 case 'd':
2467 {
2468 if (LocaleNCompare(expression,"debug",5) == 0)
2469 {
2470 const char
2471 *type;
2472
2473 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2474 exception);
2475 if (fx_info->images->colorspace == CMYKColorspace)
2476 switch (channel)
2477 {
cristy0568ffc2011-07-25 16:54:14 +00002478 case CyanPixelChannel: type="cyan"; break;
2479 case MagentaPixelChannel: type="magenta"; break;
2480 case YellowPixelChannel: type="yellow"; break;
2481 case AlphaPixelChannel: type="opacity"; break;
2482 case BlackPixelChannel: type="black"; break;
cristy3ed852e2009-09-05 21:47:34 +00002483 default: type="unknown"; break;
2484 }
2485 else
2486 switch (channel)
2487 {
cristy0568ffc2011-07-25 16:54:14 +00002488 case RedPixelChannel: type="red"; break;
2489 case GreenPixelChannel: type="green"; break;
2490 case BluePixelChannel: type="blue"; break;
2491 case AlphaPixelChannel: type="opacity"; break;
cristy3ed852e2009-09-05 21:47:34 +00002492 default: type="unknown"; break;
2493 }
2494 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2495 if (strlen(subexpression) > 1)
2496 subexpression[strlen(subexpression)-1]='\0';
2497 if (fx_info->file != (FILE *) NULL)
cristy1707c6c2012-01-18 23:30:54 +00002498 (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: "
2499 "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type,
2500 subexpression,GetMagickPrecision(),(double) alpha);
cristy3ed852e2009-09-05 21:47:34 +00002501 return(0.0);
2502 }
cristy5597a8d2011-11-04 00:25:32 +00002503 if (LocaleNCompare(expression,"drc",3) == 0)
2504 {
2505 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2506 exception);
cristya19f1d72012-08-07 18:24:38 +00002507 return((double) (alpha/(*beta*(alpha-1.0)+1.0)));
cristy5597a8d2011-11-04 00:25:32 +00002508 }
cristy3ed852e2009-09-05 21:47:34 +00002509 break;
2510 }
2511 case 'E':
2512 case 'e':
2513 {
2514 if (LocaleCompare(expression,"epsilon") == 0)
cristya19f1d72012-08-07 18:24:38 +00002515 return((double) MagickEpsilon);
cristy3ed852e2009-09-05 21:47:34 +00002516 if (LocaleNCompare(expression,"exp",3) == 0)
2517 {
2518 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2519 exception);
cristya19f1d72012-08-07 18:24:38 +00002520 return((double) exp((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002521 }
2522 if (LocaleCompare(expression,"e") == 0)
cristya19f1d72012-08-07 18:24:38 +00002523 return((double) 2.7182818284590452354);
cristy3ed852e2009-09-05 21:47:34 +00002524 break;
2525 }
2526 case 'F':
2527 case 'f':
2528 {
2529 if (LocaleNCompare(expression,"floor",5) == 0)
2530 {
2531 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2532 exception);
cristya19f1d72012-08-07 18:24:38 +00002533 return((double) floor((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002534 }
2535 break;
2536 }
2537 case 'G':
2538 case 'g':
2539 {
cristy9eeedea2011-11-02 19:04:05 +00002540 if (LocaleNCompare(expression,"gauss",5) == 0)
2541 {
2542 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2543 exception);
2544 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
cristya19f1d72012-08-07 18:24:38 +00002545 return((double) gamma);
cristy9eeedea2011-11-02 19:04:05 +00002546 }
cristyb0aad4c2011-11-02 19:30:35 +00002547 if (LocaleNCompare(expression,"gcd",3) == 0)
2548 {
2549 MagickOffsetType
2550 gcd;
2551
2552 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2553 exception);
cristy1707c6c2012-01-18 23:30:54 +00002554 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
2555 0.5));
cristya19f1d72012-08-07 18:24:38 +00002556 return((double) gcd);
cristyb0aad4c2011-11-02 19:30:35 +00002557 }
cristy3ed852e2009-09-05 21:47:34 +00002558 if (LocaleCompare(expression,"g") == 0)
2559 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2560 break;
2561 }
2562 case 'H':
2563 case 'h':
2564 {
2565 if (LocaleCompare(expression,"h") == 0)
2566 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2567 if (LocaleCompare(expression,"hue") == 0)
2568 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2569 if (LocaleNCompare(expression,"hypot",5) == 0)
2570 {
2571 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2572 exception);
cristya19f1d72012-08-07 18:24:38 +00002573 return((double) hypot((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002574 }
2575 break;
2576 }
2577 case 'K':
2578 case 'k':
2579 {
2580 if (LocaleCompare(expression,"k") == 0)
2581 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2582 break;
2583 }
2584 case 'I':
2585 case 'i':
2586 {
2587 if (LocaleCompare(expression,"intensity") == 0)
2588 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2589 if (LocaleNCompare(expression,"int",3) == 0)
2590 {
2591 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2592 exception);
cristya19f1d72012-08-07 18:24:38 +00002593 return((double) floor(alpha));
cristy3ed852e2009-09-05 21:47:34 +00002594 }
cristy82b20722011-11-05 21:52:36 +00002595#if defined(MAGICKCORE_HAVE_ISNAN)
cristy639399c2011-11-02 19:16:15 +00002596 if (LocaleNCompare(expression,"isnan",5) == 0)
2597 {
2598 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2599 exception);
cristya19f1d72012-08-07 18:24:38 +00002600 return((double) !!isnan((double) alpha));
cristy639399c2011-11-02 19:16:15 +00002601 }
cristy82b20722011-11-05 21:52:36 +00002602#endif
cristy3ed852e2009-09-05 21:47:34 +00002603 if (LocaleCompare(expression,"i") == 0)
2604 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2605 break;
2606 }
2607 case 'J':
2608 case 'j':
2609 {
2610 if (LocaleCompare(expression,"j") == 0)
2611 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
cristy161b9262010-03-20 19:34:32 +00002612#if defined(MAGICKCORE_HAVE_J0)
cristyee56cf12010-03-01 22:17:06 +00002613 if (LocaleNCompare(expression,"j0",2) == 0)
2614 {
2615 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2616 exception);
cristya19f1d72012-08-07 18:24:38 +00002617 return((double) j0((double) alpha));
cristyee56cf12010-03-01 22:17:06 +00002618 }
cristy161b9262010-03-20 19:34:32 +00002619#endif
2620#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002621 if (LocaleNCompare(expression,"j1",2) == 0)
2622 {
2623 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2624 exception);
cristya19f1d72012-08-07 18:24:38 +00002625 return((double) j1((double) alpha));
cristyee56cf12010-03-01 22:17:06 +00002626 }
cristy161b9262010-03-20 19:34:32 +00002627#endif
cristyaa018fa2010-04-08 23:03:54 +00002628#if defined(MAGICKCORE_HAVE_J1)
cristya6a09e72010-03-02 14:51:02 +00002629 if (LocaleNCompare(expression,"jinc",4) == 0)
2630 {
2631 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2632 exception);
cristy0946a822010-03-12 17:14:58 +00002633 if (alpha == 0.0)
2634 return(1.0);
cristya19f1d72012-08-07 18:24:38 +00002635 gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*
cristy1707c6c2012-01-18 23:30:54 +00002636 alpha));
cristyfce2f7b2010-03-12 00:29:49 +00002637 return(gamma);
cristya6a09e72010-03-02 14:51:02 +00002638 }
cristyaa018fa2010-04-08 23:03:54 +00002639#endif
cristy3ed852e2009-09-05 21:47:34 +00002640 break;
2641 }
2642 case 'L':
2643 case 'l':
2644 {
2645 if (LocaleNCompare(expression,"ln",2) == 0)
2646 {
2647 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2648 exception);
cristya19f1d72012-08-07 18:24:38 +00002649 return((double) log((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002650 }
cristyc8ed5322010-08-31 12:07:59 +00002651 if (LocaleNCompare(expression,"logtwo",6) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002652 {
cristyc8ed5322010-08-31 12:07:59 +00002653 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
cristy3ed852e2009-09-05 21:47:34 +00002654 exception);
cristya19f1d72012-08-07 18:24:38 +00002655 return((double) log10((double) alpha))/log10(2.0);
cristy3ed852e2009-09-05 21:47:34 +00002656 }
2657 if (LocaleNCompare(expression,"log",3) == 0)
2658 {
2659 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2660 exception);
cristya19f1d72012-08-07 18:24:38 +00002661 return((double) log10((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002662 }
2663 if (LocaleCompare(expression,"lightness") == 0)
2664 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2665 break;
2666 }
2667 case 'M':
2668 case 'm':
2669 {
2670 if (LocaleCompare(expression,"MaxRGB") == 0)
cristya19f1d72012-08-07 18:24:38 +00002671 return((double) QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002672 if (LocaleNCompare(expression,"maxima",6) == 0)
2673 break;
2674 if (LocaleNCompare(expression,"max",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002675 {
2676 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2677 exception);
2678 return(alpha > *beta ? alpha : *beta);
2679 }
cristy3ed852e2009-09-05 21:47:34 +00002680 if (LocaleNCompare(expression,"minima",6) == 0)
2681 break;
2682 if (LocaleNCompare(expression,"min",3) == 0)
cristy984049c2011-11-03 18:34:58 +00002683 {
2684 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2685 exception);
2686 return(alpha < *beta ? alpha : *beta);
2687 }
cristy3ed852e2009-09-05 21:47:34 +00002688 if (LocaleNCompare(expression,"mod",3) == 0)
2689 {
2690 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2691 exception);
cristy984049c2011-11-03 18:34:58 +00002692 gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
2693 return(gamma);
cristy3ed852e2009-09-05 21:47:34 +00002694 }
2695 if (LocaleCompare(expression,"m") == 0)
2696 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2697 break;
2698 }
2699 case 'N':
2700 case 'n':
2701 {
cristyad3502e2011-11-02 19:10:45 +00002702 if (LocaleNCompare(expression,"not",3) == 0)
2703 {
2704 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2705 exception);
cristya19f1d72012-08-07 18:24:38 +00002706 return((double) (alpha < MagickEpsilon));
cristyad3502e2011-11-02 19:10:45 +00002707 }
cristy3ed852e2009-09-05 21:47:34 +00002708 if (LocaleCompare(expression,"n") == 0)
2709 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2710 break;
2711 }
2712 case 'O':
2713 case 'o':
2714 {
2715 if (LocaleCompare(expression,"Opaque") == 0)
2716 return(1.0);
2717 if (LocaleCompare(expression,"o") == 0)
2718 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2719 break;
2720 }
2721 case 'P':
2722 case 'p':
2723 {
cristy670aa3c2011-11-03 00:54:00 +00002724 if (LocaleCompare(expression,"phi") == 0)
cristya19f1d72012-08-07 18:24:38 +00002725 return((double) MagickPHI);
cristy3ed852e2009-09-05 21:47:34 +00002726 if (LocaleCompare(expression,"pi") == 0)
cristya19f1d72012-08-07 18:24:38 +00002727 return((double) MagickPI);
cristy3ed852e2009-09-05 21:47:34 +00002728 if (LocaleNCompare(expression,"pow",3) == 0)
2729 {
2730 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2731 exception);
cristya19f1d72012-08-07 18:24:38 +00002732 return((double) pow((double) alpha,(double) *beta));
cristy3ed852e2009-09-05 21:47:34 +00002733 }
2734 if (LocaleCompare(expression,"p") == 0)
2735 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2736 break;
2737 }
2738 case 'Q':
2739 case 'q':
2740 {
2741 if (LocaleCompare(expression,"QuantumRange") == 0)
cristya19f1d72012-08-07 18:24:38 +00002742 return((double) QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00002743 if (LocaleCompare(expression,"QuantumScale") == 0)
cristya19f1d72012-08-07 18:24:38 +00002744 return((double) QuantumScale);
cristy3ed852e2009-09-05 21:47:34 +00002745 break;
2746 }
2747 case 'R':
2748 case 'r':
2749 {
2750 if (LocaleNCompare(expression,"rand",4) == 0)
cristya19f1d72012-08-07 18:24:38 +00002751 return((double) GetPseudoRandomValue(fx_info->random_info));
cristy3ed852e2009-09-05 21:47:34 +00002752 if (LocaleNCompare(expression,"round",5) == 0)
2753 {
2754 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2755 exception);
cristya19f1d72012-08-07 18:24:38 +00002756 return((double) floor((double) alpha+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002757 }
2758 if (LocaleCompare(expression,"r") == 0)
2759 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2760 break;
2761 }
2762 case 'S':
2763 case 's':
2764 {
2765 if (LocaleCompare(expression,"saturation") == 0)
2766 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2767 if (LocaleNCompare(expression,"sign",4) == 0)
2768 {
2769 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2770 exception);
2771 return(alpha < 0.0 ? -1.0 : 1.0);
2772 }
cristya6a09e72010-03-02 14:51:02 +00002773 if (LocaleNCompare(expression,"sinc",4) == 0)
2774 {
2775 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2776 exception);
2777 if (alpha == 0)
2778 return(1.0);
cristya19f1d72012-08-07 18:24:38 +00002779 gamma=(double) (sin((double) (MagickPI*alpha))/
cristya6a09e72010-03-02 14:51:02 +00002780 (MagickPI*alpha));
2781 return(gamma);
2782 }
cristy3ed852e2009-09-05 21:47:34 +00002783 if (LocaleNCompare(expression,"sinh",4) == 0)
2784 {
2785 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2786 exception);
cristya19f1d72012-08-07 18:24:38 +00002787 return((double) sinh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002788 }
2789 if (LocaleNCompare(expression,"sin",3) == 0)
2790 {
2791 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2792 exception);
cristya19f1d72012-08-07 18:24:38 +00002793 return((double) sin((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002794 }
2795 if (LocaleNCompare(expression,"sqrt",4) == 0)
2796 {
2797 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2798 exception);
cristya19f1d72012-08-07 18:24:38 +00002799 return((double) sqrt((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002800 }
cristy9eeedea2011-11-02 19:04:05 +00002801 if (LocaleNCompare(expression,"squish",6) == 0)
2802 {
2803 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2804 exception);
cristya19f1d72012-08-07 18:24:38 +00002805 return((double) (1.0/(1.0+exp((double) (-alpha)))));
cristy9eeedea2011-11-02 19:04:05 +00002806 }
cristy3ed852e2009-09-05 21:47:34 +00002807 if (LocaleCompare(expression,"s") == 0)
2808 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2809 break;
2810 }
2811 case 'T':
2812 case 't':
2813 {
2814 if (LocaleNCompare(expression,"tanh",4) == 0)
2815 {
2816 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2817 exception);
cristya19f1d72012-08-07 18:24:38 +00002818 return((double) tanh((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002819 }
2820 if (LocaleNCompare(expression,"tan",3) == 0)
2821 {
2822 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2823 exception);
cristya19f1d72012-08-07 18:24:38 +00002824 return((double) tan((double) alpha));
cristy3ed852e2009-09-05 21:47:34 +00002825 }
2826 if (LocaleCompare(expression,"Transparent") == 0)
2827 return(0.0);
cristy16788e42010-08-13 13:44:26 +00002828 if (LocaleNCompare(expression,"trunc",5) == 0)
2829 {
2830 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2831 exception);
2832 if (alpha >= 0.0)
cristya19f1d72012-08-07 18:24:38 +00002833 return((double) floor((double) alpha));
2834 return((double) ceil((double) alpha));
cristy16788e42010-08-13 13:44:26 +00002835 }
cristy3ed852e2009-09-05 21:47:34 +00002836 if (LocaleCompare(expression,"t") == 0)
2837 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2838 break;
2839 }
2840 case 'U':
2841 case 'u':
2842 {
2843 if (LocaleCompare(expression,"u") == 0)
2844 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2845 break;
2846 }
2847 case 'V':
2848 case 'v':
2849 {
2850 if (LocaleCompare(expression,"v") == 0)
2851 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2852 break;
2853 }
2854 case 'W':
2855 case 'w':
2856 {
cristy9eeedea2011-11-02 19:04:05 +00002857 if (LocaleNCompare(expression,"while",5) == 0)
2858 {
2859 do
2860 {
2861 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2862 exception);
2863 } while (fabs((double) alpha) >= MagickEpsilon);
cristya19f1d72012-08-07 18:24:38 +00002864 return((double) *beta);
cristy9eeedea2011-11-02 19:04:05 +00002865 }
cristy3ed852e2009-09-05 21:47:34 +00002866 if (LocaleCompare(expression,"w") == 0)
2867 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2868 break;
2869 }
2870 case 'Y':
2871 case 'y':
2872 {
2873 if (LocaleCompare(expression,"y") == 0)
2874 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2875 break;
2876 }
2877 case 'Z':
2878 case 'z':
2879 {
2880 if (LocaleCompare(expression,"z") == 0)
2881 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2882 break;
2883 }
2884 default:
2885 break;
2886 }
2887 q=(char *) expression;
cristydbdd0e32011-11-04 23:29:40 +00002888 alpha=InterpretSiPrefixValue(expression,&q);
cristy3ed852e2009-09-05 21:47:34 +00002889 if (q == expression)
2890 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2891 return(alpha);
2892}
2893
cristy7832dc22011-09-05 01:21:53 +00002894MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
cristya19f1d72012-08-07 18:24:38 +00002895 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002896{
2897 MagickBooleanType
2898 status;
2899
cristy541ae572011-08-05 19:08:59 +00002900 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2901 exception);
cristy3ed852e2009-09-05 21:47:34 +00002902 return(status);
2903}
2904
2905MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
cristya19f1d72012-08-07 18:24:38 +00002906 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002907{
2908 FILE
2909 *file;
2910
2911 MagickBooleanType
2912 status;
2913
2914 file=fx_info->file;
2915 fx_info->file=(FILE *) NULL;
cristy541ae572011-08-05 19:08:59 +00002916 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2917 exception);
cristy3ed852e2009-09-05 21:47:34 +00002918 fx_info->file=file;
2919 return(status);
2920}
2921
cristy7832dc22011-09-05 01:21:53 +00002922MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002923 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristya19f1d72012-08-07 18:24:38 +00002924 double *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002925{
cristya19f1d72012-08-07 18:24:38 +00002926 double
cristy3ed852e2009-09-05 21:47:34 +00002927 beta;
2928
2929 beta=0.0;
2930 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2931 exception);
2932 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2933}
2934
2935/*
2936%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2937% %
2938% %
2939% %
2940% F x I m a g e %
2941% %
2942% %
2943% %
2944%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2945%
2946% FxImage() applies a mathematical expression to the specified image.
2947%
2948% The format of the FxImage method is:
2949%
2950% Image *FxImage(const Image *image,const char *expression,
2951% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002952%
2953% A description of each parameter follows:
2954%
2955% o image: the image.
2956%
cristy3ed852e2009-09-05 21:47:34 +00002957% o expression: A mathematical expression.
2958%
2959% o exception: return any errors or warnings in this structure.
2960%
2961*/
2962
2963static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2964{
cristybb503372010-05-27 20:51:26 +00002965 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002966 i;
2967
2968 assert(fx_info != (FxInfo **) NULL);
cristyac245f82012-05-05 17:13:57 +00002969 for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++)
cristy3ed852e2009-09-05 21:47:34 +00002970 if (fx_info[i] != (FxInfo *) NULL)
2971 fx_info[i]=DestroyFxInfo(fx_info[i]);
cristyb41ee102010-10-04 16:46:15 +00002972 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00002973 return(fx_info);
2974}
2975
2976static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2977 ExceptionInfo *exception)
2978{
2979 char
2980 *fx_expression;
2981
2982 FxInfo
2983 **fx_info;
2984
cristya19f1d72012-08-07 18:24:38 +00002985 double
cristy3ed852e2009-09-05 21:47:34 +00002986 alpha;
2987
cristybb503372010-05-27 20:51:26 +00002988 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002989 i;
2990
cristybb503372010-05-27 20:51:26 +00002991 size_t
cristy3ed852e2009-09-05 21:47:34 +00002992 number_threads;
2993
cristy9357bdd2012-07-30 12:28:34 +00002994 number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
cristyb41ee102010-10-04 16:46:15 +00002995 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +00002996 if (fx_info == (FxInfo **) NULL)
cristy65d161b2012-10-07 20:39:52 +00002997 {
2998 (void) ThrowMagickException(exception,GetMagickModule(),
2999 ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
3000 return((FxInfo **) NULL);
3001 }
cristy3ed852e2009-09-05 21:47:34 +00003002 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
3003 if (*expression != '@')
3004 fx_expression=ConstantString(expression);
3005 else
3006 fx_expression=FileToString(expression+1,~0,exception);
cristybb503372010-05-27 20:51:26 +00003007 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +00003008 {
cristy65d161b2012-10-07 20:39:52 +00003009 MagickBooleanType
3010 status;
3011
cristydb070952012-04-20 14:33:00 +00003012 fx_info[i]=AcquireFxInfo(image,fx_expression,exception);
cristy3ed852e2009-09-05 21:47:34 +00003013 if (fx_info[i] == (FxInfo *) NULL)
cristy65d161b2012-10-07 20:39:52 +00003014 break;
3015 status=FxPreprocessExpression(fx_info[i],&alpha,exception);
3016 if (status == MagickFalse)
3017 break;
cristy3ed852e2009-09-05 21:47:34 +00003018 }
3019 fx_expression=DestroyString(fx_expression);
cristy65d161b2012-10-07 20:39:52 +00003020 if (i < (ssize_t) number_threads)
3021 fx_info=DestroyFxThreadSet(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00003022 return(fx_info);
3023}
3024
3025MagickExport Image *FxImage(const Image *image,const char *expression,
3026 ExceptionInfo *exception)
3027{
cristy3ed852e2009-09-05 21:47:34 +00003028#define FxImageTag "Fx/Image"
3029
cristyfa112112010-01-04 17:48:07 +00003030 CacheView
cristy79cedc72011-07-25 00:41:15 +00003031 *fx_view,
3032 *image_view;
cristyfa112112010-01-04 17:48:07 +00003033
cristy3ed852e2009-09-05 21:47:34 +00003034 FxInfo
cristyfa112112010-01-04 17:48:07 +00003035 **restrict fx_info;
cristy3ed852e2009-09-05 21:47:34 +00003036
3037 Image
3038 *fx_image;
3039
cristy3ed852e2009-09-05 21:47:34 +00003040 MagickBooleanType
3041 status;
3042
cristybb503372010-05-27 20:51:26 +00003043 MagickOffsetType
3044 progress;
3045
cristybb503372010-05-27 20:51:26 +00003046 ssize_t
3047 y;
3048
cristy3ed852e2009-09-05 21:47:34 +00003049 assert(image != (Image *) NULL);
3050 assert(image->signature == MagickSignature);
3051 if (image->debug != MagickFalse)
3052 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy3ed852e2009-09-05 21:47:34 +00003053 fx_info=AcquireFxThreadSet(image,expression,exception);
3054 if (fx_info == (FxInfo **) NULL)
cristy65d161b2012-10-07 20:39:52 +00003055 return((Image *) NULL);
3056 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
3057 if (fx_image == (Image *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003058 {
cristy3ed852e2009-09-05 21:47:34 +00003059 fx_info=DestroyFxThreadSet(fx_info);
3060 return((Image *) NULL);
3061 }
cristy65d161b2012-10-07 20:39:52 +00003062 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
3063 {
3064 fx_info=DestroyFxThreadSet(fx_info);
3065 fx_image=DestroyImage(fx_image);
3066 return((Image *) NULL);
3067 }
cristy3ed852e2009-09-05 21:47:34 +00003068 /*
3069 Fx image.
3070 */
3071 status=MagickTrue;
3072 progress=0;
cristydb070952012-04-20 14:33:00 +00003073 image_view=AcquireVirtualCacheView(image,exception);
3074 fx_view=AcquireAuthenticCacheView(fx_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003075#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003076 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +00003077 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003078#endif
cristybb503372010-05-27 20:51:26 +00003079 for (y=0; y < (ssize_t) fx_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003080 {
cristy5c9e6f22010-09-17 17:31:01 +00003081 const int
3082 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00003083
cristy79cedc72011-07-25 00:41:15 +00003084 register const Quantum
3085 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003086
cristy4c08aed2011-07-01 19:47:50 +00003087 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003088 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003089
cristy79cedc72011-07-25 00:41:15 +00003090 register ssize_t
3091 x;
3092
cristy3ed852e2009-09-05 21:47:34 +00003093 if (status == MagickFalse)
3094 continue;
cristy79cedc72011-07-25 00:41:15 +00003095 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +00003096 q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
cristy79cedc72011-07-25 00:41:15 +00003097 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003098 {
3099 status=MagickFalse;
3100 continue;
3101 }
cristybb503372010-05-27 20:51:26 +00003102 for (x=0; x < (ssize_t) fx_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003103 {
cristy79cedc72011-07-25 00:41:15 +00003104 register ssize_t
3105 i;
3106
3107 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3108 {
cristya19f1d72012-08-07 18:24:38 +00003109 double
cristy79cedc72011-07-25 00:41:15 +00003110 alpha;
3111
3112 PixelChannel
3113 channel;
3114
3115 PixelTrait
3116 fx_traits,
3117 traits;
3118
cristycf1296e2012-08-26 23:40:49 +00003119 channel=GetPixelChannelChannel(image,i);
3120 traits=GetPixelChannelTraits(image,channel);
3121 fx_traits=GetPixelChannelTraits(fx_image,channel);
cristy010d7d12011-08-31 01:02:48 +00003122 if ((traits == UndefinedPixelTrait) ||
3123 (fx_traits == UndefinedPixelTrait))
cristy79cedc72011-07-25 00:41:15 +00003124 continue;
cristy1eced092012-08-10 23:10:56 +00003125 if (((fx_traits & CopyPixelTrait) != 0) ||
3126 (GetPixelMask(image,p) != 0))
cristy79cedc72011-07-25 00:41:15 +00003127 {
cristy0beccfa2011-09-25 20:47:53 +00003128 SetPixelChannel(fx_image,channel,p[i],q);
cristy79cedc72011-07-25 00:41:15 +00003129 continue;
3130 }
3131 alpha=0.0;
cristya382aca2011-12-06 18:22:48 +00003132 (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
3133 exception);
cristy8cd03c32012-07-07 18:57:59 +00003134 q[i]=ClampToQuantum(QuantumRange*alpha);
cristy79cedc72011-07-25 00:41:15 +00003135 }
3136 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003137 q+=GetPixelChannels(fx_image);
cristy3ed852e2009-09-05 21:47:34 +00003138 }
3139 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3140 status=MagickFalse;
3141 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3142 {
3143 MagickBooleanType
3144 proceed;
3145
cristyb5d5f722009-11-04 03:03:49 +00003146#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003147 #pragma omp critical (MagickCore_FxImage)
cristy3ed852e2009-09-05 21:47:34 +00003148#endif
3149 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3150 if (proceed == MagickFalse)
3151 status=MagickFalse;
3152 }
3153 }
cristy3ed852e2009-09-05 21:47:34 +00003154 fx_view=DestroyCacheView(fx_view);
cristy79cedc72011-07-25 00:41:15 +00003155 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003156 fx_info=DestroyFxThreadSet(fx_info);
3157 if (status == MagickFalse)
3158 fx_image=DestroyImage(fx_image);
3159 return(fx_image);
3160}
3161
3162/*
3163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3164% %
3165% %
3166% %
3167% I m p l o d e I m a g e %
3168% %
3169% %
3170% %
3171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3172%
3173% ImplodeImage() creates a new image that is a copy of an existing
3174% one with the image pixels "implode" by the specified percentage. It
3175% allocates the memory necessary for the new Image structure and returns a
3176% pointer to the new image.
3177%
3178% The format of the ImplodeImage method is:
3179%
3180% Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003181% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003182%
3183% A description of each parameter follows:
3184%
3185% o implode_image: Method ImplodeImage returns a pointer to the image
3186% after it is implode. A null image is returned if there is a memory
3187% shortage.
3188%
3189% o image: the image.
3190%
3191% o amount: Define the extent of the implosion.
3192%
cristy76f512e2011-09-12 01:26:56 +00003193% o method: the pixel interpolation method.
3194%
cristy3ed852e2009-09-05 21:47:34 +00003195% o exception: return any errors or warnings in this structure.
3196%
3197*/
3198MagickExport Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003199 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003200{
3201#define ImplodeImageTag "Implode/Image"
3202
cristyfa112112010-01-04 17:48:07 +00003203 CacheView
3204 *image_view,
3205 *implode_view;
3206
cristy3ed852e2009-09-05 21:47:34 +00003207 Image
3208 *implode_image;
3209
cristy3ed852e2009-09-05 21:47:34 +00003210 MagickBooleanType
3211 status;
3212
cristybb503372010-05-27 20:51:26 +00003213 MagickOffsetType
3214 progress;
3215
cristya19f1d72012-08-07 18:24:38 +00003216 double
cristy3ed852e2009-09-05 21:47:34 +00003217 radius;
3218
3219 PointInfo
3220 center,
3221 scale;
3222
cristybb503372010-05-27 20:51:26 +00003223 ssize_t
3224 y;
3225
cristy3ed852e2009-09-05 21:47:34 +00003226 /*
3227 Initialize implode image attributes.
3228 */
3229 assert(image != (Image *) NULL);
3230 assert(image->signature == MagickSignature);
3231 if (image->debug != MagickFalse)
3232 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3233 assert(exception != (ExceptionInfo *) NULL);
3234 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00003235 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3236 exception);
cristy3ed852e2009-09-05 21:47:34 +00003237 if (implode_image == (Image *) NULL)
3238 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003239 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003240 {
cristy3ed852e2009-09-05 21:47:34 +00003241 implode_image=DestroyImage(implode_image);
3242 return((Image *) NULL);
3243 }
cristy4c08aed2011-07-01 19:47:50 +00003244 if (implode_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00003245 implode_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00003246 /*
3247 Compute scaling factor.
3248 */
3249 scale.x=1.0;
3250 scale.y=1.0;
3251 center.x=0.5*image->columns;
3252 center.y=0.5*image->rows;
3253 radius=center.x;
3254 if (image->columns > image->rows)
3255 scale.y=(double) image->columns/(double) image->rows;
3256 else
3257 if (image->columns < image->rows)
3258 {
3259 scale.x=(double) image->rows/(double) image->columns;
3260 radius=center.y;
3261 }
3262 /*
3263 Implode image.
3264 */
3265 status=MagickTrue;
3266 progress=0;
cristydb070952012-04-20 14:33:00 +00003267 image_view=AcquireVirtualCacheView(image,exception);
3268 implode_view=AcquireAuthenticCacheView(implode_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00003269#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003270 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +00003271 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003272#endif
cristybb503372010-05-27 20:51:26 +00003273 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003274 {
cristya19f1d72012-08-07 18:24:38 +00003275 double
cristy3ed852e2009-09-05 21:47:34 +00003276 distance;
3277
3278 PointInfo
3279 delta;
3280
cristy6d188022011-09-12 13:23:33 +00003281 register const Quantum
3282 *restrict p;
3283
cristybb503372010-05-27 20:51:26 +00003284 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003285 x;
3286
cristy4c08aed2011-07-01 19:47:50 +00003287 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003288 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003289
3290 if (status == MagickFalse)
3291 continue;
cristy6d188022011-09-12 13:23:33 +00003292 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristya6d7a9b2012-01-18 20:04:48 +00003293 q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00003294 exception);
cristy6d188022011-09-12 13:23:33 +00003295 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003296 {
3297 status=MagickFalse;
3298 continue;
3299 }
cristy3ed852e2009-09-05 21:47:34 +00003300 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00003301 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003302 {
cristy6d188022011-09-12 13:23:33 +00003303 register ssize_t
3304 i;
3305
cristy3ed852e2009-09-05 21:47:34 +00003306 /*
3307 Determine if the pixel is within an ellipse.
3308 */
cristy10a6c612012-01-29 21:41:05 +00003309 if (GetPixelMask(image,p) != 0)
3310 {
3311 p+=GetPixelChannels(image);
3312 q+=GetPixelChannels(implode_image);
3313 continue;
3314 }
cristy3ed852e2009-09-05 21:47:34 +00003315 delta.x=scale.x*(double) (x-center.x);
3316 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00003317 if (distance >= (radius*radius))
cristya6d7a9b2012-01-18 20:04:48 +00003318 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristy6d188022011-09-12 13:23:33 +00003319 {
cristya6d7a9b2012-01-18 20:04:48 +00003320 PixelChannel
3321 channel;
3322
cristy1707c6c2012-01-18 23:30:54 +00003323 PixelTrait
3324 implode_traits,
3325 traits;
3326
cristycf1296e2012-08-26 23:40:49 +00003327 channel=GetPixelChannelChannel(image,i);
3328 traits=GetPixelChannelTraits(image,channel);
3329 implode_traits=GetPixelChannelTraits(implode_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00003330 if ((traits == UndefinedPixelTrait) ||
3331 (implode_traits == UndefinedPixelTrait))
3332 continue;
cristya6d7a9b2012-01-18 20:04:48 +00003333 SetPixelChannel(implode_image,channel,p[i],q);
cristy6d188022011-09-12 13:23:33 +00003334 }
3335 else
cristy3ed852e2009-09-05 21:47:34 +00003336 {
3337 double
3338 factor;
3339
3340 /*
3341 Implode the pixel.
3342 */
3343 factor=1.0;
3344 if (distance > 0.0)
cristy1707c6c2012-01-18 23:30:54 +00003345 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
3346 2)),-amount);
cristy76f512e2011-09-12 01:26:56 +00003347 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3348 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3349 scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00003350 }
cristy6d188022011-09-12 13:23:33 +00003351 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003352 q+=GetPixelChannels(implode_image);
cristy3ed852e2009-09-05 21:47:34 +00003353 }
3354 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3355 status=MagickFalse;
3356 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3357 {
3358 MagickBooleanType
3359 proceed;
3360
cristyb5d5f722009-11-04 03:03:49 +00003361#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003362 #pragma omp critical (MagickCore_ImplodeImage)
cristy3ed852e2009-09-05 21:47:34 +00003363#endif
3364 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3365 if (proceed == MagickFalse)
3366 status=MagickFalse;
3367 }
3368 }
3369 implode_view=DestroyCacheView(implode_view);
3370 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003371 if (status == MagickFalse)
3372 implode_image=DestroyImage(implode_image);
3373 return(implode_image);
3374}
3375
3376/*
3377%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3378% %
3379% %
3380% %
3381% M o r p h I m a g e s %
3382% %
3383% %
3384% %
3385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3386%
3387% The MorphImages() method requires a minimum of two images. The first
3388% image is transformed into the second by a number of intervening images
3389% as specified by frames.
3390%
3391% The format of the MorphImage method is:
3392%
cristybb503372010-05-27 20:51:26 +00003393% Image *MorphImages(const Image *image,const size_t number_frames,
cristy3ed852e2009-09-05 21:47:34 +00003394% ExceptionInfo *exception)
3395%
3396% A description of each parameter follows:
3397%
3398% o image: the image.
3399%
3400% o number_frames: Define the number of in-between image to generate.
3401% The more in-between frames, the smoother the morph.
3402%
3403% o exception: return any errors or warnings in this structure.
3404%
3405*/
3406MagickExport Image *MorphImages(const Image *image,
cristybb503372010-05-27 20:51:26 +00003407 const size_t number_frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003408{
3409#define MorphImageTag "Morph/Image"
3410
3411 Image
3412 *morph_image,
3413 *morph_images;
3414
cristy9d314ff2011-03-09 01:30:28 +00003415 MagickBooleanType
3416 status;
cristy3ed852e2009-09-05 21:47:34 +00003417
3418 MagickOffsetType
3419 scene;
3420
cristya19f1d72012-08-07 18:24:38 +00003421 double
cristy3ed852e2009-09-05 21:47:34 +00003422 alpha,
3423 beta;
3424
3425 register const Image
3426 *next;
3427
cristybb503372010-05-27 20:51:26 +00003428 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003429 i;
3430
cristy9d314ff2011-03-09 01:30:28 +00003431 ssize_t
3432 y;
cristy3ed852e2009-09-05 21:47:34 +00003433
3434 /*
3435 Clone first frame in sequence.
3436 */
3437 assert(image != (Image *) NULL);
3438 assert(image->signature == MagickSignature);
3439 if (image->debug != MagickFalse)
3440 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3441 assert(exception != (ExceptionInfo *) NULL);
3442 assert(exception->signature == MagickSignature);
3443 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3444 if (morph_images == (Image *) NULL)
3445 return((Image *) NULL);
3446 if (GetNextImageInList(image) == (Image *) NULL)
3447 {
3448 /*
3449 Morph single image.
3450 */
cristybb503372010-05-27 20:51:26 +00003451 for (i=1; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003452 {
3453 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3454 if (morph_image == (Image *) NULL)
3455 {
3456 morph_images=DestroyImageList(morph_images);
3457 return((Image *) NULL);
3458 }
3459 AppendImageToList(&morph_images,morph_image);
cristy8b27a6d2010-02-14 03:31:15 +00003460 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003461 {
cristy8b27a6d2010-02-14 03:31:15 +00003462 MagickBooleanType
3463 proceed;
3464
cristybb503372010-05-27 20:51:26 +00003465 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3466 number_frames);
cristy8b27a6d2010-02-14 03:31:15 +00003467 if (proceed == MagickFalse)
3468 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003469 }
3470 }
3471 return(GetFirstImageInList(morph_images));
3472 }
3473 /*
3474 Morph image sequence.
3475 */
3476 status=MagickTrue;
3477 scene=0;
3478 next=image;
3479 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3480 {
cristybb503372010-05-27 20:51:26 +00003481 for (i=0; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003482 {
3483 CacheView
3484 *image_view,
3485 *morph_view;
3486
cristya19f1d72012-08-07 18:24:38 +00003487 beta=(double) (i+1.0)/(double) (number_frames+1.0);
cristy3ed852e2009-09-05 21:47:34 +00003488 alpha=1.0-beta;
cristy15b98cd2010-09-12 19:42:50 +00003489 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
cristyaa2c16c2012-03-25 22:21:35 +00003490 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta*
3491 GetNextImageInList(next)->rows+0.5),next->filter,exception);
cristy3ed852e2009-09-05 21:47:34 +00003492 if (morph_image == (Image *) NULL)
3493 {
3494 morph_images=DestroyImageList(morph_images);
3495 return((Image *) NULL);
3496 }
cristy1707c6c2012-01-18 23:30:54 +00003497 status=SetImageStorageClass(morph_image,DirectClass,exception);
3498 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003499 {
cristy3ed852e2009-09-05 21:47:34 +00003500 morph_image=DestroyImage(morph_image);
3501 return((Image *) NULL);
3502 }
3503 AppendImageToList(&morph_images,morph_image);
3504 morph_images=GetLastImageInList(morph_images);
cristy15b98cd2010-09-12 19:42:50 +00003505 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
cristyaa2c16c2012-03-25 22:21:35 +00003506 morph_images->rows,GetNextImageInList(next)->filter,exception);
cristy3ed852e2009-09-05 21:47:34 +00003507 if (morph_image == (Image *) NULL)
3508 {
3509 morph_images=DestroyImageList(morph_images);
3510 return((Image *) NULL);
3511 }
cristydb070952012-04-20 14:33:00 +00003512 image_view=AcquireVirtualCacheView(morph_image,exception);
3513 morph_view=AcquireAuthenticCacheView(morph_images,exception);
cristyb5d5f722009-11-04 03:03:49 +00003514#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00003515 #pragma omp parallel for schedule(static,4) shared(status) \
cristy4ee2b0c2012-05-15 00:30:35 +00003516 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00003517#endif
cristybb503372010-05-27 20:51:26 +00003518 for (y=0; y < (ssize_t) morph_images->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003519 {
3520 MagickBooleanType
3521 sync;
3522
cristy4c08aed2011-07-01 19:47:50 +00003523 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00003524 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003525
cristybb503372010-05-27 20:51:26 +00003526 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003527 x;
3528
cristy4c08aed2011-07-01 19:47:50 +00003529 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003530 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003531
3532 if (status == MagickFalse)
3533 continue;
3534 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3535 exception);
3536 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3537 exception);
cristy4c08aed2011-07-01 19:47:50 +00003538 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003539 {
3540 status=MagickFalse;
3541 continue;
3542 }
cristybb503372010-05-27 20:51:26 +00003543 for (x=0; x < (ssize_t) morph_images->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003544 {
cristy1707c6c2012-01-18 23:30:54 +00003545 register ssize_t
3546 i;
3547
cristy10a6c612012-01-29 21:41:05 +00003548 for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
cristy1707c6c2012-01-18 23:30:54 +00003549 {
3550 PixelChannel
3551 channel;
3552
3553 PixelTrait
3554 morph_traits,
3555 traits;
3556
cristycf1296e2012-08-26 23:40:49 +00003557 channel=GetPixelChannelChannel(image,i);
3558 traits=GetPixelChannelTraits(image,channel);
3559 morph_traits=GetPixelChannelTraits(morph_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00003560 if ((traits == UndefinedPixelTrait) ||
3561 (morph_traits == UndefinedPixelTrait))
3562 continue;
cristy1eced092012-08-10 23:10:56 +00003563 if (((morph_traits & CopyPixelTrait) != 0) ||
3564 (GetPixelMask(image,p) != 0))
cristy1707c6c2012-01-18 23:30:54 +00003565 {
3566 SetPixelChannel(morph_image,channel,p[i],q);
3567 continue;
3568 }
3569 SetPixelChannel(morph_image,channel,ClampToQuantum(alpha*
3570 GetPixelChannel(morph_images,channel,q)+beta*p[i]),q);
3571 }
cristyed231572011-07-14 02:18:59 +00003572 p+=GetPixelChannels(morph_image);
3573 q+=GetPixelChannels(morph_images);
cristy3ed852e2009-09-05 21:47:34 +00003574 }
3575 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3576 if (sync == MagickFalse)
3577 status=MagickFalse;
3578 }
3579 morph_view=DestroyCacheView(morph_view);
3580 image_view=DestroyCacheView(image_view);
3581 morph_image=DestroyImage(morph_image);
3582 }
cristybb503372010-05-27 20:51:26 +00003583 if (i < (ssize_t) number_frames)
cristy3ed852e2009-09-05 21:47:34 +00003584 break;
3585 /*
3586 Clone last frame in sequence.
3587 */
3588 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3589 if (morph_image == (Image *) NULL)
3590 {
3591 morph_images=DestroyImageList(morph_images);
3592 return((Image *) NULL);
3593 }
3594 AppendImageToList(&morph_images,morph_image);
3595 morph_images=GetLastImageInList(morph_images);
3596 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3597 {
3598 MagickBooleanType
3599 proceed;
3600
cristyb5d5f722009-11-04 03:03:49 +00003601#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00003602 #pragma omp critical (MagickCore_MorphImages)
cristy3ed852e2009-09-05 21:47:34 +00003603#endif
3604 proceed=SetImageProgress(image,MorphImageTag,scene,
3605 GetImageListLength(image));
3606 if (proceed == MagickFalse)
3607 status=MagickFalse;
3608 }
3609 scene++;
3610 }
3611 if (GetNextImageInList(next) != (Image *) NULL)
3612 {
3613 morph_images=DestroyImageList(morph_images);
3614 return((Image *) NULL);
3615 }
3616 return(GetFirstImageInList(morph_images));
3617}
3618
3619/*
3620%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3621% %
3622% %
3623% %
3624% P l a s m a I m a g e %
3625% %
3626% %
3627% %
3628%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3629%
3630% PlasmaImage() initializes an image with plasma fractal values. The image
3631% must be initialized with a base color and the random number generator
3632% seeded before this method is called.
3633%
3634% The format of the PlasmaImage method is:
3635%
3636% MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
cristy5cbc0162011-08-29 00:36:28 +00003637% size_t attenuate,size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003638%
3639% A description of each parameter follows:
3640%
3641% o image: the image.
3642%
3643% o segment: Define the region to apply plasma fractals values.
3644%
glennrp7dae1ca2010-09-16 12:17:35 +00003645% o attenuate: Define the plasma attenuation factor.
cristy3ed852e2009-09-05 21:47:34 +00003646%
3647% o depth: Limit the plasma recursion depth.
3648%
cristy5cbc0162011-08-29 00:36:28 +00003649% o exception: return any errors or warnings in this structure.
3650%
cristy3ed852e2009-09-05 21:47:34 +00003651*/
3652
3653static inline Quantum PlasmaPixel(RandomInfo *random_info,
cristya19f1d72012-08-07 18:24:38 +00003654 const double pixel,const double noise)
cristy3ed852e2009-09-05 21:47:34 +00003655{
3656 Quantum
3657 plasma;
3658
cristyce70c172010-01-07 17:15:30 +00003659 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
cristy3ed852e2009-09-05 21:47:34 +00003660 noise/2.0);
3661 return(plasma);
3662}
3663
cristyda1f9c12011-10-02 21:39:49 +00003664static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3665 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3666 const SegmentInfo *segment,size_t attenuate,size_t depth,
3667 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003668{
cristya19f1d72012-08-07 18:24:38 +00003669 double
cristy3ed852e2009-09-05 21:47:34 +00003670 plasma;
3671
cristyda1f9c12011-10-02 21:39:49 +00003672 PixelChannel
3673 channel;
3674
3675 PixelTrait
3676 traits;
3677
3678 register const Quantum
3679 *restrict u,
3680 *restrict v;
3681
3682 register Quantum
3683 *restrict q;
3684
3685 register ssize_t
3686 i;
cristy3ed852e2009-09-05 21:47:34 +00003687
cristy9d314ff2011-03-09 01:30:28 +00003688 ssize_t
3689 x,
3690 x_mid,
3691 y,
3692 y_mid;
3693
cristy3ed852e2009-09-05 21:47:34 +00003694 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3695 return(MagickTrue);
3696 if (depth != 0)
3697 {
3698 SegmentInfo
3699 local_info;
3700
3701 /*
3702 Divide the area into quadrants and recurse.
3703 */
3704 depth--;
3705 attenuate++;
cristybb503372010-05-27 20:51:26 +00003706 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3707 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003708 local_info=(*segment);
3709 local_info.x2=(double) x_mid;
3710 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003711 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3712 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003713 local_info=(*segment);
3714 local_info.y1=(double) y_mid;
3715 local_info.x2=(double) x_mid;
cristyda1f9c12011-10-02 21:39:49 +00003716 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3717 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003718 local_info=(*segment);
3719 local_info.x1=(double) x_mid;
3720 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003721 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3722 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003723 local_info=(*segment);
3724 local_info.x1=(double) x_mid;
3725 local_info.y1=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003726 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3727 &local_info,attenuate,depth,exception));
cristy3ed852e2009-09-05 21:47:34 +00003728 }
cristybb503372010-05-27 20:51:26 +00003729 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3730 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003731 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3732 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3733 return(MagickFalse);
3734 /*
3735 Average pixels and apply plasma.
3736 */
cristya19f1d72012-08-07 18:24:38 +00003737 plasma=(double) QuantumRange/(2.0*attenuate);
cristy3ed852e2009-09-05 21:47:34 +00003738 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3739 {
cristy3ed852e2009-09-05 21:47:34 +00003740 /*
3741 Left pixel.
3742 */
cristybb503372010-05-27 20:51:26 +00003743 x=(ssize_t) ceil(segment->x1-0.5);
cristy1707c6c2012-01-18 23:30:54 +00003744 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1,
3745 exception);
3746 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1,
3747 exception);
cristyc5c6f662010-09-22 14:23:02 +00003748 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003749 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3750 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003751 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003752 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3753 {
cristycf1296e2012-08-26 23:40:49 +00003754 channel=GetPixelChannelChannel(image,i);
3755 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003756 if (traits == UndefinedPixelTrait)
3757 continue;
3758 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3759 }
cristyc5c6f662010-09-22 14:23:02 +00003760 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003761 if (segment->x1 != segment->x2)
3762 {
3763 /*
3764 Right pixel.
3765 */
cristybb503372010-05-27 20:51:26 +00003766 x=(ssize_t) ceil(segment->x2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003767 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3768 1,1,exception);
3769 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3770 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003771 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003772 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3773 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003774 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003775 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3776 {
cristycf1296e2012-08-26 23:40:49 +00003777 channel=GetPixelChannelChannel(image,i);
3778 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003779 if (traits == UndefinedPixelTrait)
3780 continue;
3781 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3782 }
cristyc5c6f662010-09-22 14:23:02 +00003783 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003784 }
3785 }
3786 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3787 {
3788 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3789 {
cristy3ed852e2009-09-05 21:47:34 +00003790 /*
3791 Bottom pixel.
3792 */
cristybb503372010-05-27 20:51:26 +00003793 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003794 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3795 1,1,exception);
3796 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3797 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003798 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003799 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3800 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003801 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003802 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3803 {
cristycf1296e2012-08-26 23:40:49 +00003804 channel=GetPixelChannelChannel(image,i);
3805 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003806 if (traits == UndefinedPixelTrait)
3807 continue;
3808 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3809 }
cristyc5c6f662010-09-22 14:23:02 +00003810 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003811 }
3812 if (segment->y1 != segment->y2)
3813 {
cristy3ed852e2009-09-05 21:47:34 +00003814 /*
3815 Top pixel.
3816 */
cristybb503372010-05-27 20:51:26 +00003817 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003818 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3819 1,1,exception);
3820 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3821 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003822 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003823 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3824 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003825 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003826 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3827 {
cristycf1296e2012-08-26 23:40:49 +00003828 channel=GetPixelChannelChannel(image,i);
3829 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003830 if (traits == UndefinedPixelTrait)
3831 continue;
3832 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3833 }
cristyc5c6f662010-09-22 14:23:02 +00003834 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003835 }
3836 }
3837 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3838 {
cristy3ed852e2009-09-05 21:47:34 +00003839 /*
3840 Middle pixel.
3841 */
cristybb503372010-05-27 20:51:26 +00003842 x=(ssize_t) ceil(segment->x1-0.5);
3843 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003844 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
cristybb503372010-05-27 20:51:26 +00003845 x=(ssize_t) ceil(segment->x2-0.5);
3846 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003847 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003848 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003849 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3850 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003851 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003852 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3853 {
cristycf1296e2012-08-26 23:40:49 +00003854 channel=GetPixelChannelChannel(image,i);
3855 traits=GetPixelChannelTraits(image,channel);
cristyda1f9c12011-10-02 21:39:49 +00003856 if (traits == UndefinedPixelTrait)
3857 continue;
3858 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3859 }
cristyc5c6f662010-09-22 14:23:02 +00003860 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003861 }
3862 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3863 return(MagickTrue);
3864 return(MagickFalse);
3865}
cristyda1f9c12011-10-02 21:39:49 +00003866
cristy3ed852e2009-09-05 21:47:34 +00003867MagickExport MagickBooleanType PlasmaImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00003868 const SegmentInfo *segment,size_t attenuate,size_t depth,
3869 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003870{
cristyc5c6f662010-09-22 14:23:02 +00003871 CacheView
cristyda1f9c12011-10-02 21:39:49 +00003872 *image_view,
3873 *u_view,
3874 *v_view;
cristyc5c6f662010-09-22 14:23:02 +00003875
cristy3ed852e2009-09-05 21:47:34 +00003876 MagickBooleanType
3877 status;
3878
3879 RandomInfo
3880 *random_info;
3881
3882 if (image->debug != MagickFalse)
3883 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3884 assert(image != (Image *) NULL);
3885 assert(image->signature == MagickSignature);
3886 if (image->debug != MagickFalse)
3887 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy5cbc0162011-08-29 00:36:28 +00003888 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristyc5c6f662010-09-22 14:23:02 +00003889 return(MagickFalse);
cristydb070952012-04-20 14:33:00 +00003890 image_view=AcquireAuthenticCacheView(image,exception);
3891 u_view=AcquireVirtualCacheView(image,exception);
3892 v_view=AcquireVirtualCacheView(image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003893 random_info=AcquireRandomInfo();
cristyda1f9c12011-10-02 21:39:49 +00003894 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3895 attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003896 random_info=DestroyRandomInfo(random_info);
cristyda1f9c12011-10-02 21:39:49 +00003897 v_view=DestroyCacheView(v_view);
3898 u_view=DestroyCacheView(u_view);
cristyc5c6f662010-09-22 14:23:02 +00003899 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003900 return(status);
3901}
3902
3903/*
3904%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3905% %
3906% %
3907% %
3908% P o l a r o i d I m a g e %
3909% %
3910% %
3911% %
3912%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3913%
3914% PolaroidImage() simulates a Polaroid picture.
3915%
3916% The format of the AnnotateImage method is:
3917%
3918% Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristye9e3d382011-12-14 01:50:13 +00003919% const char *caption,const double angle,
3920% const PixelInterpolateMethod method,ExceptionInfo exception)
cristy3ed852e2009-09-05 21:47:34 +00003921%
3922% A description of each parameter follows:
3923%
3924% o image: the image.
3925%
3926% o draw_info: the draw info.
3927%
cristye9e3d382011-12-14 01:50:13 +00003928% o caption: the Polaroid caption.
3929%
cristycee97112010-05-28 00:44:52 +00003930% o angle: Apply the effect along this angle.
cristy3ed852e2009-09-05 21:47:34 +00003931%
cristy5c4e2582011-09-11 19:21:03 +00003932% o method: the pixel interpolation method.
3933%
cristy3ed852e2009-09-05 21:47:34 +00003934% o exception: return any errors or warnings in this structure.
3935%
3936*/
3937MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristye9e3d382011-12-14 01:50:13 +00003938 const char *caption,const double angle,const PixelInterpolateMethod method,
cristy5c4e2582011-09-11 19:21:03 +00003939 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003940{
cristy3ed852e2009-09-05 21:47:34 +00003941 Image
3942 *bend_image,
3943 *caption_image,
3944 *flop_image,
3945 *picture_image,
3946 *polaroid_image,
3947 *rotate_image,
3948 *trim_image;
3949
cristybb503372010-05-27 20:51:26 +00003950 size_t
cristy3ed852e2009-09-05 21:47:34 +00003951 height;
3952
cristy9d314ff2011-03-09 01:30:28 +00003953 ssize_t
3954 quantum;
3955
cristy3ed852e2009-09-05 21:47:34 +00003956 /*
3957 Simulate a Polaroid picture.
3958 */
3959 assert(image != (Image *) NULL);
3960 assert(image->signature == MagickSignature);
3961 if (image->debug != MagickFalse)
3962 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3963 assert(exception != (ExceptionInfo *) NULL);
3964 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00003965 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
cristy3ed852e2009-09-05 21:47:34 +00003966 image->rows)/25.0,10.0);
3967 height=image->rows+2*quantum;
3968 caption_image=(Image *) NULL;
cristye9e3d382011-12-14 01:50:13 +00003969 if (caption != (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003970 {
3971 char
cristye9e3d382011-12-14 01:50:13 +00003972 geometry[MaxTextExtent],
3973 *text;
cristy3ed852e2009-09-05 21:47:34 +00003974
3975 DrawInfo
3976 *annotate_info;
3977
cristy3ed852e2009-09-05 21:47:34 +00003978 MagickBooleanType
3979 status;
3980
cristy9d314ff2011-03-09 01:30:28 +00003981 ssize_t
3982 count;
3983
cristy3ed852e2009-09-05 21:47:34 +00003984 TypeMetric
3985 metrics;
3986
3987 /*
3988 Generate caption image.
3989 */
3990 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3991 if (caption_image == (Image *) NULL)
3992 return((Image *) NULL);
3993 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
cristye9e3d382011-12-14 01:50:13 +00003994 text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
3995 exception);
3996 (void) CloneString(&annotate_info->text,text);
cristy6b1d05e2010-09-22 19:17:27 +00003997 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
cristye9e3d382011-12-14 01:50:13 +00003998 &text,exception);
3999 status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)*
4000 (metrics.ascent-metrics.descent)+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00004001 if (status == MagickFalse)
4002 caption_image=DestroyImage(caption_image);
4003 else
4004 {
4005 caption_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004006 (void) SetImageBackgroundColor(caption_image,exception);
cristye9e3d382011-12-14 01:50:13 +00004007 (void) CloneString(&annotate_info->text,text);
cristyb51dff52011-05-19 16:55:47 +00004008 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
cristy3ed852e2009-09-05 21:47:34 +00004009 metrics.ascent);
4010 if (annotate_info->gravity == UndefinedGravity)
4011 (void) CloneString(&annotate_info->geometry,AcquireString(
4012 geometry));
cristy5cbc0162011-08-29 00:36:28 +00004013 (void) AnnotateImage(caption_image,annotate_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00004014 height+=caption_image->rows;
4015 }
4016 annotate_info=DestroyDrawInfo(annotate_info);
cristye9e3d382011-12-14 01:50:13 +00004017 text=DestroyString(text);
cristy3ed852e2009-09-05 21:47:34 +00004018 }
4019 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
4020 exception);
4021 if (picture_image == (Image *) NULL)
4022 {
4023 if (caption_image != (Image *) NULL)
4024 caption_image=DestroyImage(caption_image);
4025 return((Image *) NULL);
4026 }
4027 picture_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004028 (void) SetImageBackgroundColor(picture_image,exception);
cristy39172402012-03-30 13:04:39 +00004029 (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum,
cristyfeb3e962012-03-29 17:25:55 +00004030 quantum,exception);
cristy3ed852e2009-09-05 21:47:34 +00004031 if (caption_image != (Image *) NULL)
4032 {
cristyfeb3e962012-03-29 17:25:55 +00004033 (void) CompositeImage(picture_image,caption_image,OverCompositeOp,
cristy39172402012-03-30 13:04:39 +00004034 MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception);
cristy3ed852e2009-09-05 21:47:34 +00004035 caption_image=DestroyImage(caption_image);
4036 }
cristy9950d572011-10-01 18:22:35 +00004037 (void) QueryColorCompliance("none",AllCompliance,
4038 &picture_image->background_color,exception);
cristy63240882011-08-05 19:05:27 +00004039 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004040 rotate_image=RotateImage(picture_image,90.0,exception);
4041 picture_image=DestroyImage(picture_image);
4042 if (rotate_image == (Image *) NULL)
4043 return((Image *) NULL);
4044 picture_image=rotate_image;
4045 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
cristy5c4e2582011-09-11 19:21:03 +00004046 picture_image->columns,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00004047 picture_image=DestroyImage(picture_image);
4048 if (bend_image == (Image *) NULL)
4049 return((Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00004050 picture_image=bend_image;
4051 rotate_image=RotateImage(picture_image,-90.0,exception);
4052 picture_image=DestroyImage(picture_image);
4053 if (rotate_image == (Image *) NULL)
4054 return((Image *) NULL);
4055 picture_image=rotate_image;
4056 picture_image->background_color=image->background_color;
anthonyf46d4262012-03-26 03:30:34 +00004057 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
cristy3ed852e2009-09-05 21:47:34 +00004058 exception);
4059 if (polaroid_image == (Image *) NULL)
4060 {
4061 picture_image=DestroyImage(picture_image);
4062 return(picture_image);
4063 }
4064 flop_image=FlopImage(polaroid_image,exception);
4065 polaroid_image=DestroyImage(polaroid_image);
4066 if (flop_image == (Image *) NULL)
4067 {
4068 picture_image=DestroyImage(picture_image);
4069 return(picture_image);
4070 }
4071 polaroid_image=flop_image;
cristyfeb3e962012-03-29 17:25:55 +00004072 (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp,
cristy39172402012-03-30 13:04:39 +00004073 MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
cristy3ed852e2009-09-05 21:47:34 +00004074 picture_image=DestroyImage(picture_image);
cristy9950d572011-10-01 18:22:35 +00004075 (void) QueryColorCompliance("none",AllCompliance,
4076 &polaroid_image->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00004077 rotate_image=RotateImage(polaroid_image,angle,exception);
4078 polaroid_image=DestroyImage(polaroid_image);
4079 if (rotate_image == (Image *) NULL)
4080 return((Image *) NULL);
4081 polaroid_image=rotate_image;
4082 trim_image=TrimImage(polaroid_image,exception);
4083 polaroid_image=DestroyImage(polaroid_image);
4084 if (trim_image == (Image *) NULL)
4085 return((Image *) NULL);
4086 polaroid_image=trim_image;
4087 return(polaroid_image);
4088}
4089
4090/*
4091%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4092% %
4093% %
4094% %
cristy3ed852e2009-09-05 21:47:34 +00004095% S e p i a T o n e I m a g e %
4096% %
4097% %
4098% %
4099%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4100%
4101% MagickSepiaToneImage() applies a special effect to the image, similar to the
4102% effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4103% 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4104% threshold of 80% is a good starting point for a reasonable tone.
4105%
4106% The format of the SepiaToneImage method is:
4107%
4108% Image *SepiaToneImage(const Image *image,const double threshold,
4109% ExceptionInfo *exception)
4110%
4111% A description of each parameter follows:
4112%
4113% o image: the image.
4114%
4115% o threshold: the tone threshold.
4116%
4117% o exception: return any errors or warnings in this structure.
4118%
4119*/
4120MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4121 ExceptionInfo *exception)
4122{
4123#define SepiaToneImageTag "SepiaTone/Image"
4124
cristyc4c8d132010-01-07 01:58:38 +00004125 CacheView
4126 *image_view,
4127 *sepia_view;
4128
cristy3ed852e2009-09-05 21:47:34 +00004129 Image
4130 *sepia_image;
4131
cristy3ed852e2009-09-05 21:47:34 +00004132 MagickBooleanType
4133 status;
4134
cristybb503372010-05-27 20:51:26 +00004135 MagickOffsetType
4136 progress;
4137
4138 ssize_t
4139 y;
4140
cristy3ed852e2009-09-05 21:47:34 +00004141 /*
4142 Initialize sepia-toned image attributes.
4143 */
4144 assert(image != (const Image *) NULL);
4145 assert(image->signature == MagickSignature);
4146 if (image->debug != MagickFalse)
4147 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4148 assert(exception != (ExceptionInfo *) NULL);
4149 assert(exception->signature == MagickSignature);
cristy1707c6c2012-01-18 23:30:54 +00004150 sepia_image=CloneImage(image,0,0,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004151 if (sepia_image == (Image *) NULL)
4152 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004153 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004154 {
cristy3ed852e2009-09-05 21:47:34 +00004155 sepia_image=DestroyImage(sepia_image);
4156 return((Image *) NULL);
4157 }
4158 /*
4159 Tone each row of the image.
4160 */
4161 status=MagickTrue;
4162 progress=0;
cristydb070952012-04-20 14:33:00 +00004163 image_view=AcquireVirtualCacheView(image,exception);
4164 sepia_view=AcquireAuthenticCacheView(sepia_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00004165#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00004166 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +00004167 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00004168#endif
cristybb503372010-05-27 20:51:26 +00004169 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004170 {
cristy4c08aed2011-07-01 19:47:50 +00004171 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004172 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00004173
cristybb503372010-05-27 20:51:26 +00004174 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004175 x;
4176
cristy4c08aed2011-07-01 19:47:50 +00004177 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004178 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004179
4180 if (status == MagickFalse)
4181 continue;
4182 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy1707c6c2012-01-18 23:30:54 +00004183 q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00004184 exception);
cristy4c08aed2011-07-01 19:47:50 +00004185 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004186 {
4187 status=MagickFalse;
4188 continue;
4189 }
cristybb503372010-05-27 20:51:26 +00004190 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004191 {
cristya19f1d72012-08-07 18:24:38 +00004192 double
cristy3ed852e2009-09-05 21:47:34 +00004193 intensity,
4194 tone;
4195
cristyf13c5942012-08-08 23:50:11 +00004196 intensity=GetPixelIntensity(image,p);
cristya19f1d72012-08-07 18:24:38 +00004197 tone=intensity > threshold ? (double) QuantumRange : intensity+
4198 (double) QuantumRange-threshold;
cristy4c08aed2011-07-01 19:47:50 +00004199 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
cristya19f1d72012-08-07 18:24:38 +00004200 tone=intensity > (7.0*threshold/6.0) ? (double) QuantumRange :
4201 intensity+(double) QuantumRange-7.0*threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004202 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004203 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004204 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004205 tone=threshold/7.0;
cristya19f1d72012-08-07 18:24:38 +00004206 if ((double) GetPixelGreen(image,q) < tone)
cristy4c08aed2011-07-01 19:47:50 +00004207 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristya19f1d72012-08-07 18:24:38 +00004208 if ((double) GetPixelBlue(image,q) < tone)
cristy4c08aed2011-07-01 19:47:50 +00004209 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristyed231572011-07-14 02:18:59 +00004210 p+=GetPixelChannels(image);
4211 q+=GetPixelChannels(sepia_image);
cristy3ed852e2009-09-05 21:47:34 +00004212 }
4213 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4214 status=MagickFalse;
4215 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4216 {
4217 MagickBooleanType
4218 proceed;
4219
cristyb5d5f722009-11-04 03:03:49 +00004220#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00004221 #pragma omp critical (MagickCore_SepiaToneImage)
cristy3ed852e2009-09-05 21:47:34 +00004222#endif
4223 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4224 image->rows);
4225 if (proceed == MagickFalse)
4226 status=MagickFalse;
4227 }
4228 }
4229 sepia_view=DestroyCacheView(sepia_view);
4230 image_view=DestroyCacheView(image_view);
cristye23ec9d2011-08-16 18:15:40 +00004231 (void) NormalizeImage(sepia_image,exception);
4232 (void) ContrastImage(sepia_image,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004233 if (status == MagickFalse)
4234 sepia_image=DestroyImage(sepia_image);
4235 return(sepia_image);
4236}
4237
4238/*
4239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4240% %
4241% %
4242% %
4243% S h a d o w I m a g e %
4244% %
4245% %
4246% %
4247%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4248%
4249% ShadowImage() simulates a shadow from the specified image and returns it.
4250%
4251% The format of the ShadowImage method is:
4252%
cristy70cddf72011-12-10 22:42:42 +00004253% Image *ShadowImage(const Image *image,const double alpha,
cristyaa2c16c2012-03-25 22:21:35 +00004254% const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4255% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004256%
4257% A description of each parameter follows:
4258%
4259% o image: the image.
4260%
cristy70cddf72011-12-10 22:42:42 +00004261% o alpha: percentage transparency.
cristy3ed852e2009-09-05 21:47:34 +00004262%
4263% o sigma: the standard deviation of the Gaussian, in pixels.
4264%
4265% o x_offset: the shadow x-offset.
4266%
4267% o y_offset: the shadow y-offset.
4268%
4269% o exception: return any errors or warnings in this structure.
4270%
4271*/
cristy70cddf72011-12-10 22:42:42 +00004272MagickExport Image *ShadowImage(const Image *image,const double alpha,
cristyaa2c16c2012-03-25 22:21:35 +00004273 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
4274 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004275{
4276#define ShadowImageTag "Shadow/Image"
4277
cristy70cddf72011-12-10 22:42:42 +00004278 CacheView
4279 *image_view;
4280
cristybd5a96c2011-08-21 00:04:26 +00004281 ChannelType
4282 channel_mask;
4283
cristy3ed852e2009-09-05 21:47:34 +00004284 Image
4285 *border_image,
4286 *clone_image,
4287 *shadow_image;
4288
cristy70cddf72011-12-10 22:42:42 +00004289 MagickBooleanType
4290 status;
4291
cristy3ed852e2009-09-05 21:47:34 +00004292 RectangleInfo
4293 border_info;
4294
cristy70cddf72011-12-10 22:42:42 +00004295 ssize_t
4296 y;
4297
cristy3ed852e2009-09-05 21:47:34 +00004298 assert(image != (Image *) NULL);
4299 assert(image->signature == MagickSignature);
4300 if (image->debug != MagickFalse)
4301 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4302 assert(exception != (ExceptionInfo *) NULL);
4303 assert(exception->signature == MagickSignature);
4304 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4305 if (clone_image == (Image *) NULL)
4306 return((Image *) NULL);
cristy0898eba2012-04-09 16:38:29 +00004307 if (IsGrayColorspace(image->colorspace) != MagickFalse)
cristyb09db112012-07-11 12:04:31 +00004308 (void) TransformImageColorspace(clone_image,RGBColorspace,exception);
cristy0ce08762012-06-30 01:33:18 +00004309 (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod,
cristy387430f2012-02-07 13:09:46 +00004310 exception);
cristybb503372010-05-27 20:51:26 +00004311 border_info.width=(size_t) floor(2.0*sigma+0.5);
4312 border_info.height=(size_t) floor(2.0*sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00004313 border_info.x=0;
4314 border_info.y=0;
cristy9950d572011-10-01 18:22:35 +00004315 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4316 exception);
cristy8a46d822012-08-28 23:32:39 +00004317 clone_image->alpha_trait=BlendPixelTrait;
cristy70cddf72011-12-10 22:42:42 +00004318 border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
cristy3ed852e2009-09-05 21:47:34 +00004319 clone_image=DestroyImage(clone_image);
4320 if (border_image == (Image *) NULL)
4321 return((Image *) NULL);
cristy8a46d822012-08-28 23:32:39 +00004322 if (border_image->alpha_trait != BlendPixelTrait)
cristy63240882011-08-05 19:05:27 +00004323 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004324 /*
4325 Shadow image.
4326 */
cristy70cddf72011-12-10 22:42:42 +00004327 status=MagickTrue;
cristydb070952012-04-20 14:33:00 +00004328 image_view=AcquireAuthenticCacheView(border_image,exception);
cristy70cddf72011-12-10 22:42:42 +00004329 for (y=0; y < (ssize_t) border_image->rows; y++)
4330 {
4331 PixelInfo
4332 background_color;
4333
4334 register Quantum
4335 *restrict q;
4336
4337 register ssize_t
4338 x;
4339
4340 if (status == MagickFalse)
4341 continue;
4342 q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1,
4343 exception);
4344 if (q == (Quantum *) NULL)
4345 {
4346 status=MagickFalse;
4347 continue;
4348 }
4349 background_color=border_image->background_color;
cristy8a46d822012-08-28 23:32:39 +00004350 background_color.alpha_trait=BlendPixelTrait;
cristy70cddf72011-12-10 22:42:42 +00004351 for (x=0; x < (ssize_t) border_image->columns; x++)
4352 {
cristy8a46d822012-08-28 23:32:39 +00004353 if (border_image->alpha_trait == BlendPixelTrait)
cristy70cddf72011-12-10 22:42:42 +00004354 background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
4355 SetPixelInfoPixel(border_image,&background_color,q);
4356 q+=GetPixelChannels(border_image);
4357 }
4358 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4359 status=MagickFalse;
4360 }
4361 image_view=DestroyCacheView(image_view);
4362 if (status == MagickFalse)
4363 {
4364 border_image=DestroyImage(border_image);
4365 return((Image *) NULL);
4366 }
cristycf1296e2012-08-26 23:40:49 +00004367 channel_mask=SetImageChannelMask(border_image,AlphaChannel);
cristyaa2c16c2012-03-25 22:21:35 +00004368 shadow_image=BlurImage(border_image,0.0,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00004369 border_image=DestroyImage(border_image);
4370 if (shadow_image == (Image *) NULL)
4371 return((Image *) NULL);
cristycf1296e2012-08-26 23:40:49 +00004372 (void) SetPixelChannelMask(shadow_image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00004373 if (shadow_image->page.width == 0)
4374 shadow_image->page.width=shadow_image->columns;
4375 if (shadow_image->page.height == 0)
4376 shadow_image->page.height=shadow_image->rows;
cristybb503372010-05-27 20:51:26 +00004377 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4378 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4379 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4380 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
cristy3ed852e2009-09-05 21:47:34 +00004381 return(shadow_image);
4382}
4383
4384/*
4385%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4386% %
4387% %
4388% %
4389% S k e t c h I m a g e %
4390% %
4391% %
4392% %
4393%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4394%
4395% SketchImage() simulates a pencil sketch. We convolve the image with a
4396% Gaussian operator of the given radius and standard deviation (sigma). For
4397% reasonable results, radius should be larger than sigma. Use a radius of 0
4398% and SketchImage() selects a suitable radius for you. Angle gives the angle
4399% of the sketch.
4400%
4401% The format of the SketchImage method is:
4402%
4403% Image *SketchImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00004404% const double sigma,const double angle,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004405%
4406% A description of each parameter follows:
4407%
4408% o image: the image.
4409%
cristy574cc262011-08-05 01:23:58 +00004410% o radius: the radius of the Gaussian, in pixels, not counting the
4411% center pixel.
cristy3ed852e2009-09-05 21:47:34 +00004412%
4413% o sigma: the standard deviation of the Gaussian, in pixels.
4414%
cristyf7ef0252011-09-09 14:50:06 +00004415% o angle: apply the effect along this angle.
4416%
cristy3ed852e2009-09-05 21:47:34 +00004417% o exception: return any errors or warnings in this structure.
4418%
4419*/
4420MagickExport Image *SketchImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00004421 const double sigma,const double angle,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004422{
cristyfa112112010-01-04 17:48:07 +00004423 CacheView
4424 *random_view;
4425
cristy3ed852e2009-09-05 21:47:34 +00004426 Image
4427 *blend_image,
4428 *blur_image,
4429 *dodge_image,
4430 *random_image,
4431 *sketch_image;
4432
cristy3ed852e2009-09-05 21:47:34 +00004433 MagickBooleanType
4434 status;
4435
cristy3ed852e2009-09-05 21:47:34 +00004436 RandomInfo
cristyfa112112010-01-04 17:48:07 +00004437 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +00004438
cristy9d314ff2011-03-09 01:30:28 +00004439 ssize_t
4440 y;
4441
glennrpf7659d72012-09-24 18:14:56 +00004442#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004443 unsigned long
4444 key;
glennrpf7659d72012-09-24 18:14:56 +00004445#endif
cristy57340e02012-05-05 00:53:23 +00004446
cristy3ed852e2009-09-05 21:47:34 +00004447 /*
4448 Sketch image.
4449 */
4450 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4451 MagickTrue,exception);
4452 if (random_image == (Image *) NULL)
4453 return((Image *) NULL);
4454 status=MagickTrue;
cristy1b784432009-12-19 02:20:40 +00004455 random_info=AcquireRandomInfoThreadSet();
glennrpf7659d72012-09-24 18:14:56 +00004456#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004457 key=GetRandomSecretKey(random_info[0]);
glennrpf7659d72012-09-24 18:14:56 +00004458#endif
cristydb070952012-04-20 14:33:00 +00004459 random_view=AcquireAuthenticCacheView(random_image,exception);
cristy1b784432009-12-19 02:20:40 +00004460#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy57340e02012-05-05 00:53:23 +00004461 #pragma omp parallel for schedule(static,4) shared(status) \
cristy4ee2b0c2012-05-15 00:30:35 +00004462 dynamic_number_threads(image,image->columns,image->rows,key == ~0UL)
cristy1b784432009-12-19 02:20:40 +00004463#endif
cristybb503372010-05-27 20:51:26 +00004464 for (y=0; y < (ssize_t) random_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004465 {
cristy5c9e6f22010-09-17 17:31:01 +00004466 const int
4467 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00004468
cristybb503372010-05-27 20:51:26 +00004469 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004470 x;
4471
cristy4c08aed2011-07-01 19:47:50 +00004472 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004473 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004474
cristy1b784432009-12-19 02:20:40 +00004475 if (status == MagickFalse)
4476 continue;
cristy3ed852e2009-09-05 21:47:34 +00004477 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4478 exception);
cristyacd2ed22011-08-30 01:44:23 +00004479 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004480 {
4481 status=MagickFalse;
4482 continue;
4483 }
cristybb503372010-05-27 20:51:26 +00004484 for (x=0; x < (ssize_t) random_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004485 {
cristya19f1d72012-08-07 18:24:38 +00004486 double
cristy76f512e2011-09-12 01:26:56 +00004487 value;
4488
4489 register ssize_t
4490 i;
4491
cristy10a6c612012-01-29 21:41:05 +00004492 if (GetPixelMask(random_image,q) != 0)
4493 {
4494 q+=GetPixelChannels(random_image);
4495 continue;
4496 }
cristy76f512e2011-09-12 01:26:56 +00004497 value=GetPseudoRandomValue(random_info[id]);
4498 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4499 {
cristyabace412011-12-11 15:56:53 +00004500 PixelChannel
4501 channel;
4502
cristy76f512e2011-09-12 01:26:56 +00004503 PixelTrait
4504 traits;
4505
cristycf1296e2012-08-26 23:40:49 +00004506 channel=GetPixelChannelChannel(image,i);
4507 traits=GetPixelChannelTraits(image,channel);
cristy76f512e2011-09-12 01:26:56 +00004508 if (traits == UndefinedPixelTrait)
4509 continue;
4510 q[i]=ClampToQuantum(QuantumRange*value);
4511 }
cristyed231572011-07-14 02:18:59 +00004512 q+=GetPixelChannels(random_image);
cristy3ed852e2009-09-05 21:47:34 +00004513 }
4514 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4515 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004516 }
4517 random_view=DestroyCacheView(random_view);
cristy1b784432009-12-19 02:20:40 +00004518 random_info=DestroyRandomInfoThreadSet(random_info);
cristy3ed852e2009-09-05 21:47:34 +00004519 if (status == MagickFalse)
4520 {
4521 random_image=DestroyImage(random_image);
4522 return(random_image);
4523 }
cristyaa2c16c2012-03-25 22:21:35 +00004524 blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception);
cristy3ed852e2009-09-05 21:47:34 +00004525 random_image=DestroyImage(random_image);
4526 if (blur_image == (Image *) NULL)
4527 return((Image *) NULL);
cristy6bfd6902011-12-09 01:33:45 +00004528 dodge_image=EdgeImage(blur_image,radius,1.0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004529 blur_image=DestroyImage(blur_image);
4530 if (dodge_image == (Image *) NULL)
4531 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +00004532 (void) NormalizeImage(dodge_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +00004533 (void) NegateImage(dodge_image,MagickFalse,exception);
cristye941a752011-10-15 01:52:48 +00004534 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
cristy3ed852e2009-09-05 21:47:34 +00004535 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4536 if (sketch_image == (Image *) NULL)
4537 {
4538 dodge_image=DestroyImage(dodge_image);
4539 return((Image *) NULL);
4540 }
cristyfeb3e962012-03-29 17:25:55 +00004541 (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp,
cristy39172402012-03-30 13:04:39 +00004542 MagickTrue,0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004543 dodge_image=DestroyImage(dodge_image);
4544 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4545 if (blend_image == (Image *) NULL)
4546 {
4547 sketch_image=DestroyImage(sketch_image);
4548 return((Image *) NULL);
4549 }
4550 (void) SetImageArtifact(blend_image,"compose:args","20x80");
cristy39172402012-03-30 13:04:39 +00004551 (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue,
cristyfeb3e962012-03-29 17:25:55 +00004552 0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00004553 blend_image=DestroyImage(blend_image);
4554 return(sketch_image);
4555}
4556
4557/*
4558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4559% %
4560% %
4561% %
4562% S o l a r i z e I m a g e %
4563% %
4564% %
4565% %
4566%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4567%
4568% SolarizeImage() applies a special effect to the image, similar to the effect
4569% achieved in a photo darkroom by selectively exposing areas of photo
4570% sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4571% measure of the extent of the solarization.
4572%
4573% The format of the SolarizeImage method is:
4574%
cristy5cbc0162011-08-29 00:36:28 +00004575% MagickBooleanType SolarizeImage(Image *image,const double threshold,
4576% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004577%
4578% A description of each parameter follows:
4579%
4580% o image: the image.
4581%
4582% o threshold: Define the extent of the solarization.
4583%
cristy5cbc0162011-08-29 00:36:28 +00004584% o exception: return any errors or warnings in this structure.
4585%
cristy3ed852e2009-09-05 21:47:34 +00004586*/
4587MagickExport MagickBooleanType SolarizeImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00004588 const double threshold,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004589{
4590#define SolarizeImageTag "Solarize/Image"
4591
cristyc4c8d132010-01-07 01:58:38 +00004592 CacheView
4593 *image_view;
4594
cristy3ed852e2009-09-05 21:47:34 +00004595 MagickBooleanType
4596 status;
4597
cristybb503372010-05-27 20:51:26 +00004598 MagickOffsetType
4599 progress;
4600
4601 ssize_t
4602 y;
4603
cristy3ed852e2009-09-05 21:47:34 +00004604 assert(image != (Image *) NULL);
4605 assert(image->signature == MagickSignature);
4606 if (image->debug != MagickFalse)
4607 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4608 if (image->storage_class == PseudoClass)
4609 {
cristybb503372010-05-27 20:51:26 +00004610 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004611 i;
4612
4613 /*
4614 Solarize colormap.
4615 */
cristybb503372010-05-27 20:51:26 +00004616 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00004617 {
cristya19f1d72012-08-07 18:24:38 +00004618 if ((double) image->colormap[i].red > threshold)
cristy6e963d82012-06-19 15:23:24 +00004619 image->colormap[i].red=QuantumRange-image->colormap[i].red;
cristya19f1d72012-08-07 18:24:38 +00004620 if ((double) image->colormap[i].green > threshold)
cristy6e963d82012-06-19 15:23:24 +00004621 image->colormap[i].green=QuantumRange-
cristy3ed852e2009-09-05 21:47:34 +00004622 image->colormap[i].green;
cristya19f1d72012-08-07 18:24:38 +00004623 if ((double) image->colormap[i].blue > threshold)
cristy6e963d82012-06-19 15:23:24 +00004624 image->colormap[i].blue=QuantumRange-
cristy3ed852e2009-09-05 21:47:34 +00004625 image->colormap[i].blue;
4626 }
4627 }
4628 /*
4629 Solarize image.
4630 */
4631 status=MagickTrue;
4632 progress=0;
cristydb070952012-04-20 14:33:00 +00004633 image_view=AcquireAuthenticCacheView(image,exception);
cristyb5d5f722009-11-04 03:03:49 +00004634#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00004635 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +00004636 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00004637#endif
cristybb503372010-05-27 20:51:26 +00004638 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004639 {
cristybb503372010-05-27 20:51:26 +00004640 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004641 x;
4642
cristy4c08aed2011-07-01 19:47:50 +00004643 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004644 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004645
4646 if (status == MagickFalse)
4647 continue;
cristy5cbc0162011-08-29 00:36:28 +00004648 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004649 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004650 {
4651 status=MagickFalse;
4652 continue;
4653 }
cristybb503372010-05-27 20:51:26 +00004654 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004655 {
cristy76f512e2011-09-12 01:26:56 +00004656 register ssize_t
4657 i;
4658
cristy10a6c612012-01-29 21:41:05 +00004659 if (GetPixelMask(image,q) != 0)
4660 {
4661 q+=GetPixelChannels(image);
4662 continue;
4663 }
cristy76f512e2011-09-12 01:26:56 +00004664 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4665 {
cristyabace412011-12-11 15:56:53 +00004666 PixelChannel
4667 channel;
4668
cristy76f512e2011-09-12 01:26:56 +00004669 PixelTrait
4670 traits;
4671
cristycf1296e2012-08-26 23:40:49 +00004672 channel=GetPixelChannelChannel(image,i);
4673 traits=GetPixelChannelTraits(image,channel);
cristy76f512e2011-09-12 01:26:56 +00004674 if ((traits == UndefinedPixelTrait) ||
4675 ((traits & CopyPixelTrait) != 0))
4676 continue;
cristya19f1d72012-08-07 18:24:38 +00004677 if ((double) q[i] > threshold)
cristy76f512e2011-09-12 01:26:56 +00004678 q[i]=QuantumRange-q[i];
4679 }
cristyed231572011-07-14 02:18:59 +00004680 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004681 }
4682 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4683 status=MagickFalse;
4684 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4685 {
4686 MagickBooleanType
4687 proceed;
4688
cristyb5d5f722009-11-04 03:03:49 +00004689#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00004690 #pragma omp critical (MagickCore_SolarizeImage)
cristy3ed852e2009-09-05 21:47:34 +00004691#endif
4692 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4693 if (proceed == MagickFalse)
4694 status=MagickFalse;
4695 }
4696 }
4697 image_view=DestroyCacheView(image_view);
4698 return(status);
4699}
4700
4701/*
4702%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4703% %
4704% %
4705% %
4706% S t e g a n o I m a g e %
4707% %
4708% %
4709% %
4710%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4711%
4712% SteganoImage() hides a digital watermark within the image. Recover
4713% the hidden watermark later to prove that the authenticity of an image.
4714% Offset defines the start position within the image to hide the watermark.
4715%
4716% The format of the SteganoImage method is:
4717%
4718% Image *SteganoImage(const Image *image,Image *watermark,
4719% ExceptionInfo *exception)
4720%
4721% A description of each parameter follows:
4722%
4723% o image: the image.
4724%
4725% o watermark: the watermark image.
4726%
4727% o exception: return any errors or warnings in this structure.
4728%
4729*/
4730MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4731 ExceptionInfo *exception)
4732{
cristye1bf8ad2010-09-19 17:07:03 +00004733#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
cristy4c08aed2011-07-01 19:47:50 +00004734#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
cristyeaedf062010-05-29 22:36:02 +00004735 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
cristy3ed852e2009-09-05 21:47:34 +00004736#define SteganoImageTag "Stegano/Image"
4737
cristyb0d3bb92010-09-22 14:37:58 +00004738 CacheView
4739 *stegano_view,
4740 *watermark_view;
4741
cristy3ed852e2009-09-05 21:47:34 +00004742 Image
4743 *stegano_image;
4744
4745 int
4746 c;
4747
cristy3ed852e2009-09-05 21:47:34 +00004748 MagickBooleanType
4749 status;
4750
cristy101ab702011-10-13 13:06:32 +00004751 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00004752 pixel;
4753
cristy4c08aed2011-07-01 19:47:50 +00004754 register Quantum
cristy3ed852e2009-09-05 21:47:34 +00004755 *q;
4756
cristye1bf8ad2010-09-19 17:07:03 +00004757 register ssize_t
4758 x;
4759
cristybb503372010-05-27 20:51:26 +00004760 size_t
cristyeaedf062010-05-29 22:36:02 +00004761 depth,
4762 one;
cristy3ed852e2009-09-05 21:47:34 +00004763
cristye1bf8ad2010-09-19 17:07:03 +00004764 ssize_t
4765 i,
4766 j,
4767 k,
4768 y;
4769
cristy3ed852e2009-09-05 21:47:34 +00004770 /*
4771 Initialize steganographic image attributes.
4772 */
4773 assert(image != (const Image *) NULL);
4774 assert(image->signature == MagickSignature);
4775 if (image->debug != MagickFalse)
4776 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4777 assert(watermark != (const Image *) NULL);
4778 assert(watermark->signature == MagickSignature);
4779 assert(exception != (ExceptionInfo *) NULL);
4780 assert(exception->signature == MagickSignature);
cristyeaedf062010-05-29 22:36:02 +00004781 one=1UL;
cristy3ed852e2009-09-05 21:47:34 +00004782 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4783 if (stegano_image == (Image *) NULL)
4784 return((Image *) NULL);
cristyf61b1832012-04-01 01:38:19 +00004785 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
cristy574cc262011-08-05 01:23:58 +00004786 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004787 {
cristy3ed852e2009-09-05 21:47:34 +00004788 stegano_image=DestroyImage(stegano_image);
4789 return((Image *) NULL);
4790 }
cristy3ed852e2009-09-05 21:47:34 +00004791 /*
4792 Hide watermark in low-order bits of image.
4793 */
4794 c=0;
4795 i=0;
4796 j=0;
4797 depth=stegano_image->depth;
cristyf61b1832012-04-01 01:38:19 +00004798 k=stegano_image->offset;
cristyda16f162011-02-19 23:52:17 +00004799 status=MagickTrue;
cristydb070952012-04-20 14:33:00 +00004800 watermark_view=AcquireVirtualCacheView(watermark,exception);
4801 stegano_view=AcquireAuthenticCacheView(stegano_image,exception);
cristybb503372010-05-27 20:51:26 +00004802 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
cristy3ed852e2009-09-05 21:47:34 +00004803 {
cristybb503372010-05-27 20:51:26 +00004804 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
cristy3ed852e2009-09-05 21:47:34 +00004805 {
cristybb503372010-05-27 20:51:26 +00004806 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
cristy3ed852e2009-09-05 21:47:34 +00004807 {
cristy1707c6c2012-01-18 23:30:54 +00004808 ssize_t
4809 offset;
4810
cristyf05d4942012-03-17 16:26:09 +00004811 (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel,
cristyda1f9c12011-10-02 21:39:49 +00004812 exception);
cristy1707c6c2012-01-18 23:30:54 +00004813 offset=k/(ssize_t) stegano_image->columns;
4814 if (offset >= (ssize_t) stegano_image->rows)
cristy3ed852e2009-09-05 21:47:34 +00004815 break;
cristyb0d3bb92010-09-22 14:37:58 +00004816 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4817 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4818 exception);
cristyacd2ed22011-08-30 01:44:23 +00004819 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004820 break;
4821 switch (c)
4822 {
4823 case 0:
4824 {
cristyf61b1832012-04-01 01:38:19 +00004825 SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j,
4826 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004827 break;
4828 }
4829 case 1:
4830 {
cristyf61b1832012-04-01 01:38:19 +00004831 SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j,
4832 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004833 break;
4834 }
4835 case 2:
4836 {
cristyf61b1832012-04-01 01:38:19 +00004837 SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j,
4838 GetBit(GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004839 break;
4840 }
4841 }
cristyb0d3bb92010-09-22 14:37:58 +00004842 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004843 break;
4844 c++;
4845 if (c == 3)
4846 c=0;
4847 k++;
cristybb503372010-05-27 20:51:26 +00004848 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
cristy3ed852e2009-09-05 21:47:34 +00004849 k=0;
cristyf61b1832012-04-01 01:38:19 +00004850 if (k == stegano_image->offset)
cristy3ed852e2009-09-05 21:47:34 +00004851 j++;
4852 }
4853 }
cristy8b27a6d2010-02-14 03:31:15 +00004854 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004855 {
cristy8b27a6d2010-02-14 03:31:15 +00004856 MagickBooleanType
4857 proceed;
4858
4859 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4860 (depth-i),depth);
4861 if (proceed == MagickFalse)
4862 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004863 }
4864 }
cristyb0d3bb92010-09-22 14:37:58 +00004865 stegano_view=DestroyCacheView(stegano_view);
4866 watermark_view=DestroyCacheView(watermark_view);
cristyda16f162011-02-19 23:52:17 +00004867 if (status == MagickFalse)
4868 {
4869 stegano_image=DestroyImage(stegano_image);
4870 return((Image *) NULL);
4871 }
cristy3ed852e2009-09-05 21:47:34 +00004872 return(stegano_image);
4873}
4874
4875/*
4876%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4877% %
4878% %
4879% %
4880% S t e r e o A n a g l y p h I m a g e %
4881% %
4882% %
4883% %
4884%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4885%
4886% StereoAnaglyphImage() combines two images and produces a single image that
4887% is the composite of a left and right image of a stereo pair. Special
4888% red-green stereo glasses are required to view this effect.
4889%
4890% The format of the StereoAnaglyphImage method is:
4891%
4892% Image *StereoImage(const Image *left_image,const Image *right_image,
4893% ExceptionInfo *exception)
4894% Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004895% const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004896% ExceptionInfo *exception)
4897%
4898% A description of each parameter follows:
4899%
4900% o left_image: the left image.
4901%
4902% o right_image: the right image.
4903%
4904% o exception: return any errors or warnings in this structure.
4905%
4906% o x_offset: amount, in pixels, by which the left image is offset to the
4907% right of the right image.
4908%
4909% o y_offset: amount, in pixels, by which the left image is offset to the
4910% bottom of the right image.
4911%
4912%
4913*/
4914MagickExport Image *StereoImage(const Image *left_image,
4915 const Image *right_image,ExceptionInfo *exception)
4916{
4917 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4918}
4919
4920MagickExport Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004921 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004922 ExceptionInfo *exception)
4923{
4924#define StereoImageTag "Stereo/Image"
4925
4926 const Image
4927 *image;
4928
4929 Image
4930 *stereo_image;
4931
cristy3ed852e2009-09-05 21:47:34 +00004932 MagickBooleanType
4933 status;
4934
cristy9d314ff2011-03-09 01:30:28 +00004935 ssize_t
4936 y;
4937
cristy3ed852e2009-09-05 21:47:34 +00004938 assert(left_image != (const Image *) NULL);
4939 assert(left_image->signature == MagickSignature);
4940 if (left_image->debug != MagickFalse)
4941 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4942 left_image->filename);
4943 assert(right_image != (const Image *) NULL);
4944 assert(right_image->signature == MagickSignature);
4945 assert(exception != (ExceptionInfo *) NULL);
4946 assert(exception->signature == MagickSignature);
4947 assert(right_image != (const Image *) NULL);
4948 image=left_image;
4949 if ((left_image->columns != right_image->columns) ||
4950 (left_image->rows != right_image->rows))
4951 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4952 /*
4953 Initialize stereo image attributes.
4954 */
4955 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4956 MagickTrue,exception);
4957 if (stereo_image == (Image *) NULL)
4958 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004959 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004960 {
cristy3ed852e2009-09-05 21:47:34 +00004961 stereo_image=DestroyImage(stereo_image);
4962 return((Image *) NULL);
4963 }
cristy079c78d2012-07-03 11:53:48 +00004964 (void) SetImageColorspace(stereo_image,sRGBColorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00004965 /*
4966 Copy left image to red channel and right image to blue channel.
4967 */
cristyda16f162011-02-19 23:52:17 +00004968 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00004969 for (y=0; y < (ssize_t) stereo_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004970 {
cristy4c08aed2011-07-01 19:47:50 +00004971 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004972 *restrict p,
4973 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004974
cristybb503372010-05-27 20:51:26 +00004975 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004976 x;
4977
cristy4c08aed2011-07-01 19:47:50 +00004978 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004979 *restrict r;
cristy3ed852e2009-09-05 21:47:34 +00004980
4981 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4982 exception);
4983 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4984 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
cristy76f512e2011-09-12 01:26:56 +00004985 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4986 (r == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004987 break;
cristybb503372010-05-27 20:51:26 +00004988 for (x=0; x < (ssize_t) stereo_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004989 {
cristy4c08aed2011-07-01 19:47:50 +00004990 SetPixelRed(image,GetPixelRed(left_image,p),r);
cristy76f512e2011-09-12 01:26:56 +00004991 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4992 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4993 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4994 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4995 GetPixelAlpha(right_image,q))/2,r);
cristyed231572011-07-14 02:18:59 +00004996 p+=GetPixelChannels(left_image);
cristy76f512e2011-09-12 01:26:56 +00004997 q+=GetPixelChannels(right_image);
4998 r+=GetPixelChannels(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004999 }
5000 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
5001 break;
cristy8b27a6d2010-02-14 03:31:15 +00005002 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005003 {
cristy8b27a6d2010-02-14 03:31:15 +00005004 MagickBooleanType
5005 proceed;
5006
cristybb503372010-05-27 20:51:26 +00005007 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
5008 stereo_image->rows);
cristy8b27a6d2010-02-14 03:31:15 +00005009 if (proceed == MagickFalse)
5010 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00005011 }
5012 }
cristyda16f162011-02-19 23:52:17 +00005013 if (status == MagickFalse)
5014 {
5015 stereo_image=DestroyImage(stereo_image);
5016 return((Image *) NULL);
5017 }
cristy3ed852e2009-09-05 21:47:34 +00005018 return(stereo_image);
5019}
5020
5021/*
5022%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5023% %
5024% %
5025% %
5026% S w i r l I m a g e %
5027% %
5028% %
5029% %
5030%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5031%
5032% SwirlImage() swirls the pixels about the center of the image, where
5033% degrees indicates the sweep of the arc through which each pixel is moved.
5034% You get a more dramatic effect as the degrees move from 1 to 360.
5035%
5036% The format of the SwirlImage method is:
5037%
5038% Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00005039% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005040%
5041% A description of each parameter follows:
5042%
5043% o image: the image.
5044%
5045% o degrees: Define the tightness of the swirling effect.
5046%
cristy76f512e2011-09-12 01:26:56 +00005047% o method: the pixel interpolation method.
5048%
cristy3ed852e2009-09-05 21:47:34 +00005049% o exception: return any errors or warnings in this structure.
5050%
5051*/
5052MagickExport Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00005053 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005054{
5055#define SwirlImageTag "Swirl/Image"
5056
cristyfa112112010-01-04 17:48:07 +00005057 CacheView
5058 *image_view,
5059 *swirl_view;
5060
cristy3ed852e2009-09-05 21:47:34 +00005061 Image
5062 *swirl_image;
5063
cristy3ed852e2009-09-05 21:47:34 +00005064 MagickBooleanType
5065 status;
5066
cristybb503372010-05-27 20:51:26 +00005067 MagickOffsetType
5068 progress;
5069
cristya19f1d72012-08-07 18:24:38 +00005070 double
cristy3ed852e2009-09-05 21:47:34 +00005071 radius;
5072
5073 PointInfo
5074 center,
5075 scale;
5076
cristybb503372010-05-27 20:51:26 +00005077 ssize_t
5078 y;
5079
cristy3ed852e2009-09-05 21:47:34 +00005080 /*
5081 Initialize swirl image attributes.
5082 */
5083 assert(image != (const Image *) NULL);
5084 assert(image->signature == MagickSignature);
5085 if (image->debug != MagickFalse)
5086 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5087 assert(exception != (ExceptionInfo *) NULL);
5088 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00005089 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005090 if (swirl_image == (Image *) NULL)
5091 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005092 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005093 {
cristy3ed852e2009-09-05 21:47:34 +00005094 swirl_image=DestroyImage(swirl_image);
5095 return((Image *) NULL);
5096 }
cristy4c08aed2011-07-01 19:47:50 +00005097 if (swirl_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00005098 swirl_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00005099 /*
5100 Compute scaling factor.
5101 */
5102 center.x=(double) image->columns/2.0;
5103 center.y=(double) image->rows/2.0;
5104 radius=MagickMax(center.x,center.y);
5105 scale.x=1.0;
5106 scale.y=1.0;
5107 if (image->columns > image->rows)
5108 scale.y=(double) image->columns/(double) image->rows;
5109 else
5110 if (image->columns < image->rows)
5111 scale.x=(double) image->rows/(double) image->columns;
5112 degrees=(double) DegreesToRadians(degrees);
5113 /*
5114 Swirl image.
5115 */
5116 status=MagickTrue;
5117 progress=0;
cristydb070952012-04-20 14:33:00 +00005118 image_view=AcquireVirtualCacheView(image,exception);
5119 swirl_view=AcquireAuthenticCacheView(swirl_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00005120#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005121 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +00005122 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005123#endif
cristybb503372010-05-27 20:51:26 +00005124 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005125 {
cristya19f1d72012-08-07 18:24:38 +00005126 double
cristy3ed852e2009-09-05 21:47:34 +00005127 distance;
5128
5129 PointInfo
5130 delta;
5131
cristy6d188022011-09-12 13:23:33 +00005132 register const Quantum
5133 *restrict p;
5134
cristybb503372010-05-27 20:51:26 +00005135 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005136 x;
5137
cristy4c08aed2011-07-01 19:47:50 +00005138 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005139 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005140
5141 if (status == MagickFalse)
5142 continue;
cristy6d188022011-09-12 13:23:33 +00005143 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy1707c6c2012-01-18 23:30:54 +00005144 q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
cristy3ed852e2009-09-05 21:47:34 +00005145 exception);
cristy6d188022011-09-12 13:23:33 +00005146 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005147 {
5148 status=MagickFalse;
5149 continue;
5150 }
cristy3ed852e2009-09-05 21:47:34 +00005151 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00005152 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005153 {
5154 /*
5155 Determine if the pixel is within an ellipse.
5156 */
cristy10a6c612012-01-29 21:41:05 +00005157 if (GetPixelMask(image,p) != 0)
5158 {
5159 p+=GetPixelChannels(image);
5160 q+=GetPixelChannels(swirl_image);
5161 continue;
5162 }
cristy3ed852e2009-09-05 21:47:34 +00005163 delta.x=scale.x*(double) (x-center.x);
5164 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00005165 if (distance >= (radius*radius))
5166 {
cristy1707c6c2012-01-18 23:30:54 +00005167 register ssize_t
5168 i;
5169
cristy6d188022011-09-12 13:23:33 +00005170 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
cristy1707c6c2012-01-18 23:30:54 +00005171 {
5172 PixelChannel
5173 channel;
5174
5175 PixelTrait
5176 swirl_traits,
5177 traits;
5178
cristycf1296e2012-08-26 23:40:49 +00005179 channel=GetPixelChannelChannel(image,i);
5180 traits=GetPixelChannelTraits(image,channel);
5181 swirl_traits=GetPixelChannelTraits(swirl_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00005182 if ((traits == UndefinedPixelTrait) ||
5183 (swirl_traits == UndefinedPixelTrait))
5184 continue;
5185 SetPixelChannel(swirl_image,channel,p[i],q);
5186 }
cristy6d188022011-09-12 13:23:33 +00005187 }
5188 else
cristy3ed852e2009-09-05 21:47:34 +00005189 {
cristya19f1d72012-08-07 18:24:38 +00005190 double
cristy3ed852e2009-09-05 21:47:34 +00005191 cosine,
5192 factor,
5193 sine;
5194
5195 /*
5196 Swirl the pixel.
5197 */
5198 factor=1.0-sqrt((double) distance)/radius;
5199 sine=sin((double) (degrees*factor*factor));
5200 cosine=cos((double) (degrees*factor*factor));
cristy76f512e2011-09-12 01:26:56 +00005201 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5202 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5203 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00005204 }
cristy6d188022011-09-12 13:23:33 +00005205 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00005206 q+=GetPixelChannels(swirl_image);
cristy3ed852e2009-09-05 21:47:34 +00005207 }
5208 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5209 status=MagickFalse;
5210 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5211 {
5212 MagickBooleanType
5213 proceed;
5214
cristyb5d5f722009-11-04 03:03:49 +00005215#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005216 #pragma omp critical (MagickCore_SwirlImage)
cristy3ed852e2009-09-05 21:47:34 +00005217#endif
5218 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5219 if (proceed == MagickFalse)
5220 status=MagickFalse;
5221 }
5222 }
5223 swirl_view=DestroyCacheView(swirl_view);
5224 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005225 if (status == MagickFalse)
5226 swirl_image=DestroyImage(swirl_image);
5227 return(swirl_image);
5228}
5229
5230/*
5231%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5232% %
5233% %
5234% %
5235% T i n t I m a g e %
5236% %
5237% %
5238% %
5239%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5240%
5241% TintImage() applies a color vector to each pixel in the image. The length
5242% of the vector is 0 for black and white and at its maximum for the midtones.
5243% The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5244%
5245% The format of the TintImage method is:
5246%
cristyb817c3f2011-10-03 14:00:35 +00005247% Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005248% const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005249%
5250% A description of each parameter follows:
5251%
5252% o image: the image.
5253%
cristyb817c3f2011-10-03 14:00:35 +00005254% o blend: A color value used for tinting.
cristy3ed852e2009-09-05 21:47:34 +00005255%
5256% o tint: A color value used for tinting.
5257%
5258% o exception: return any errors or warnings in this structure.
5259%
5260*/
cristyb817c3f2011-10-03 14:00:35 +00005261MagickExport Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005262 const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005263{
5264#define TintImageTag "Tint/Image"
5265
cristyc4c8d132010-01-07 01:58:38 +00005266 CacheView
5267 *image_view,
5268 *tint_view;
5269
cristy3ed852e2009-09-05 21:47:34 +00005270 GeometryInfo
5271 geometry_info;
5272
5273 Image
5274 *tint_image;
5275
cristy3ed852e2009-09-05 21:47:34 +00005276 MagickBooleanType
5277 status;
5278
cristybb503372010-05-27 20:51:26 +00005279 MagickOffsetType
5280 progress;
cristy3ed852e2009-09-05 21:47:34 +00005281
cristya19f1d72012-08-07 18:24:38 +00005282 double
cristy28474bf2011-09-11 23:32:52 +00005283 intensity;
5284
cristy4c08aed2011-07-01 19:47:50 +00005285 PixelInfo
cristy1707c6c2012-01-18 23:30:54 +00005286 color_vector;
cristy3ed852e2009-09-05 21:47:34 +00005287
cristybb503372010-05-27 20:51:26 +00005288 MagickStatusType
5289 flags;
5290
5291 ssize_t
5292 y;
5293
cristy3ed852e2009-09-05 21:47:34 +00005294 /*
5295 Allocate tint image.
5296 */
5297 assert(image != (const Image *) NULL);
5298 assert(image->signature == MagickSignature);
5299 if (image->debug != MagickFalse)
5300 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5301 assert(exception != (ExceptionInfo *) NULL);
5302 assert(exception->signature == MagickSignature);
5303 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5304 if (tint_image == (Image *) NULL)
5305 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005306 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005307 {
cristy3ed852e2009-09-05 21:47:34 +00005308 tint_image=DestroyImage(tint_image);
5309 return((Image *) NULL);
5310 }
cristy71aac542012-05-18 12:06:35 +00005311 if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
5312 (IsPixelInfoGray(tint) == MagickFalse))
cristyb09db112012-07-11 12:04:31 +00005313 (void) SetImageColorspace(tint_image,RGBColorspace,exception);
cristyaed9c382011-10-03 17:54:21 +00005314 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005315 return(tint_image);
5316 /*
5317 Determine RGB values of the color.
5318 */
cristy1707c6c2012-01-18 23:30:54 +00005319 GetPixelInfo(image,&color_vector);
cristyb817c3f2011-10-03 14:00:35 +00005320 flags=ParseGeometry(blend,&geometry_info);
cristy1707c6c2012-01-18 23:30:54 +00005321 color_vector.red=geometry_info.rho;
5322 color_vector.green=geometry_info.rho;
5323 color_vector.blue=geometry_info.rho;
5324 color_vector.alpha=OpaqueAlpha;
cristy3ed852e2009-09-05 21:47:34 +00005325 if ((flags & SigmaValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005326 color_vector.green=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00005327 if ((flags & XiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005328 color_vector.blue=geometry_info.xi;
cristyb817c3f2011-10-03 14:00:35 +00005329 if ((flags & PsiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005330 color_vector.alpha=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005331 if (image->colorspace == CMYKColorspace)
5332 {
cristy1707c6c2012-01-18 23:30:54 +00005333 color_vector.black=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005334 if ((flags & PsiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005335 color_vector.black=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005336 if ((flags & ChiValue) != 0)
cristy1707c6c2012-01-18 23:30:54 +00005337 color_vector.alpha=geometry_info.chi;
cristy76f512e2011-09-12 01:26:56 +00005338 }
cristya19f1d72012-08-07 18:24:38 +00005339 intensity=(double) GetPixelInfoIntensity(tint);
5340 color_vector.red=(double) (color_vector.red*tint->red/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005341 intensity);
cristya19f1d72012-08-07 18:24:38 +00005342 color_vector.green=(double) (color_vector.green*tint->green/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005343 intensity);
cristya19f1d72012-08-07 18:24:38 +00005344 color_vector.blue=(double) (color_vector.blue*tint->blue/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005345 intensity);
cristya19f1d72012-08-07 18:24:38 +00005346 color_vector.black=(double) (color_vector.black*tint->black/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005347 intensity);
cristya19f1d72012-08-07 18:24:38 +00005348 color_vector.alpha=(double) (color_vector.alpha*tint->alpha/100.0-
cristy1707c6c2012-01-18 23:30:54 +00005349 intensity);
cristy3ed852e2009-09-05 21:47:34 +00005350 /*
5351 Tint image.
5352 */
5353 status=MagickTrue;
5354 progress=0;
cristydb070952012-04-20 14:33:00 +00005355 image_view=AcquireVirtualCacheView(image,exception);
5356 tint_view=AcquireAuthenticCacheView(tint_image,exception);
cristyb5d5f722009-11-04 03:03:49 +00005357#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005358 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +00005359 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005360#endif
cristybb503372010-05-27 20:51:26 +00005361 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005362 {
cristy4c08aed2011-07-01 19:47:50 +00005363 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00005364 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00005365
cristy4c08aed2011-07-01 19:47:50 +00005366 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005367 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005368
cristy6b91acb2011-04-19 12:23:54 +00005369 register ssize_t
5370 x;
5371
cristy3ed852e2009-09-05 21:47:34 +00005372 if (status == MagickFalse)
5373 continue;
5374 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5375 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5376 exception);
cristy4c08aed2011-07-01 19:47:50 +00005377 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005378 {
5379 status=MagickFalse;
5380 continue;
5381 }
cristybb503372010-05-27 20:51:26 +00005382 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005383 {
cristy4c08aed2011-07-01 19:47:50 +00005384 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005385 pixel;
5386
cristya19f1d72012-08-07 18:24:38 +00005387 double
cristy3ed852e2009-09-05 21:47:34 +00005388 weight;
5389
cristy1707c6c2012-01-18 23:30:54 +00005390 register ssize_t
5391 i;
5392
5393 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5394 {
5395 PixelChannel
5396 channel;
5397
5398 PixelTrait
5399 tint_traits,
5400 traits;
5401
cristycf1296e2012-08-26 23:40:49 +00005402 channel=GetPixelChannelChannel(image,i);
5403 traits=GetPixelChannelTraits(image,channel);
5404 tint_traits=GetPixelChannelTraits(tint_image,channel);
cristy1707c6c2012-01-18 23:30:54 +00005405 if ((traits == UndefinedPixelTrait) ||
5406 (tint_traits == UndefinedPixelTrait))
5407 continue;
cristy1eced092012-08-10 23:10:56 +00005408 if (((tint_traits & CopyPixelTrait) != 0) ||
5409 (GetPixelMask(image,p) != 0))
cristy1707c6c2012-01-18 23:30:54 +00005410 {
5411 SetPixelChannel(tint_image,channel,p[i],q);
5412 continue;
5413 }
5414 }
5415 GetPixelInfo(image,&pixel);
5416 weight=QuantumScale*GetPixelRed(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005417 pixel.red=(double) GetPixelRed(image,p)+color_vector.red*(1.0-(4.0*
5418 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005419 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005420 pixel.green=(double) GetPixelGreen(image,p)+color_vector.green*(1.0-(4.0*
5421 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005422 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005423 pixel.blue=(double) GetPixelBlue(image,p)+color_vector.blue*(1.0-(4.0*
5424 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005425 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
cristy1eced092012-08-10 23:10:56 +00005426 pixel.black=(double) GetPixelBlack(image,p)+color_vector.black*(1.0-(4.0*
5427 (weight*weight)));
cristy1707c6c2012-01-18 23:30:54 +00005428 SetPixelInfoPixel(tint_image,&pixel,q);
cristyed231572011-07-14 02:18:59 +00005429 p+=GetPixelChannels(image);
5430 q+=GetPixelChannels(tint_image);
cristy3ed852e2009-09-05 21:47:34 +00005431 }
5432 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5433 status=MagickFalse;
5434 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5435 {
5436 MagickBooleanType
5437 proceed;
5438
cristyb5d5f722009-11-04 03:03:49 +00005439#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005440 #pragma omp critical (MagickCore_TintImage)
cristy3ed852e2009-09-05 21:47:34 +00005441#endif
5442 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5443 if (proceed == MagickFalse)
5444 status=MagickFalse;
5445 }
5446 }
5447 tint_view=DestroyCacheView(tint_view);
5448 image_view=DestroyCacheView(image_view);
5449 if (status == MagickFalse)
5450 tint_image=DestroyImage(tint_image);
5451 return(tint_image);
5452}
5453
5454/*
5455%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5456% %
5457% %
5458% %
5459% V i g n e t t e I m a g e %
5460% %
5461% %
5462% %
5463%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5464%
5465% VignetteImage() softens the edges of the image in vignette style.
5466%
5467% The format of the VignetteImage method is:
5468%
5469% Image *VignetteImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00005470% const double sigma,const ssize_t x,const ssize_t y,
cristy05c0c9a2011-09-05 23:16:13 +00005471% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005472%
5473% A description of each parameter follows:
5474%
5475% o image: the image.
5476%
5477% o radius: the radius of the pixel neighborhood.
5478%
5479% o sigma: the standard deviation of the Gaussian, in pixels.
5480%
5481% o x, y: Define the x and y ellipse offset.
5482%
5483% o exception: return any errors or warnings in this structure.
5484%
5485*/
5486MagickExport Image *VignetteImage(const Image *image,const double radius,
cristyaa2c16c2012-03-25 22:21:35 +00005487 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005488{
5489 char
5490 ellipse[MaxTextExtent];
5491
5492 DrawInfo
5493 *draw_info;
5494
5495 Image
5496 *canvas_image,
5497 *blur_image,
5498 *oval_image,
5499 *vignette_image;
5500
5501 assert(image != (Image *) NULL);
5502 assert(image->signature == MagickSignature);
5503 if (image->debug != MagickFalse)
5504 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5505 assert(exception != (ExceptionInfo *) NULL);
5506 assert(exception->signature == MagickSignature);
5507 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5508 if (canvas_image == (Image *) NULL)
5509 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005510 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005511 {
cristy3ed852e2009-09-05 21:47:34 +00005512 canvas_image=DestroyImage(canvas_image);
5513 return((Image *) NULL);
5514 }
cristy8a46d822012-08-28 23:32:39 +00005515 canvas_image->alpha_trait=BlendPixelTrait;
cristy98621462011-12-31 22:31:11 +00005516 oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
5517 MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005518 if (oval_image == (Image *) NULL)
5519 {
5520 canvas_image=DestroyImage(canvas_image);
5521 return((Image *) NULL);
5522 }
cristy9950d572011-10-01 18:22:35 +00005523 (void) QueryColorCompliance("#000000",AllCompliance,
5524 &oval_image->background_color,exception);
cristyea1a8aa2011-10-20 13:24:06 +00005525 (void) SetImageBackgroundColor(oval_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00005526 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00005527 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5528 exception);
5529 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5530 exception);
cristy1707c6c2012-01-18 23:30:54 +00005531 (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
5532 "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
5533 image->rows/2.0-y);
cristy3ed852e2009-09-05 21:47:34 +00005534 draw_info->primitive=AcquireString(ellipse);
cristy018f07f2011-09-04 21:15:19 +00005535 (void) DrawImage(oval_image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00005536 draw_info=DestroyDrawInfo(draw_info);
cristyaa2c16c2012-03-25 22:21:35 +00005537 blur_image=BlurImage(oval_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00005538 oval_image=DestroyImage(oval_image);
5539 if (blur_image == (Image *) NULL)
5540 {
5541 canvas_image=DestroyImage(canvas_image);
5542 return((Image *) NULL);
5543 }
cristy8a46d822012-08-28 23:32:39 +00005544 blur_image->alpha_trait=UndefinedPixelTrait;
cristy39172402012-03-30 13:04:39 +00005545 (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue,
5546 0,0,exception);
cristy3ed852e2009-09-05 21:47:34 +00005547 blur_image=DestroyImage(blur_image);
5548 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5549 canvas_image=DestroyImage(canvas_image);
cristy66d26122012-06-23 21:56:40 +00005550 if (vignette_image != (Image *) NULL)
5551 (void) TransformImageColorspace(vignette_image,image->colorspace,exception);
cristy3ed852e2009-09-05 21:47:34 +00005552 return(vignette_image);
5553}
5554
5555/*
5556%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5557% %
5558% %
5559% %
5560% W a v e I m a g e %
5561% %
5562% %
5563% %
5564%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5565%
5566% WaveImage() creates a "ripple" effect in the image by shifting the pixels
cristycee97112010-05-28 00:44:52 +00005567% vertically along a sine wave whose amplitude and wavelength is specified
cristy3ed852e2009-09-05 21:47:34 +00005568% by the given parameters.
5569%
5570% The format of the WaveImage method is:
5571%
5572% Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005573% const double wave_length,const PixelInterpolateMethod method,
5574% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005575%
5576% A description of each parameter follows:
5577%
5578% o image: the image.
5579%
5580% o amplitude, wave_length: Define the amplitude and wave length of the
5581% sine wave.
5582%
cristy5c4e2582011-09-11 19:21:03 +00005583% o interpolate: the pixel interpolation method.
5584%
cristy3ed852e2009-09-05 21:47:34 +00005585% o exception: return any errors or warnings in this structure.
5586%
5587*/
5588MagickExport Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005589 const double wave_length,const PixelInterpolateMethod method,
5590 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005591{
5592#define WaveImageTag "Wave/Image"
5593
cristyfa112112010-01-04 17:48:07 +00005594 CacheView
cristyd76c51e2011-03-26 00:21:26 +00005595 *image_view,
cristyfa112112010-01-04 17:48:07 +00005596 *wave_view;
5597
cristy3ed852e2009-09-05 21:47:34 +00005598 Image
5599 *wave_image;
5600
cristy3ed852e2009-09-05 21:47:34 +00005601 MagickBooleanType
5602 status;
5603
cristybb503372010-05-27 20:51:26 +00005604 MagickOffsetType
5605 progress;
5606
cristya19f1d72012-08-07 18:24:38 +00005607 double
cristy3ed852e2009-09-05 21:47:34 +00005608 *sine_map;
5609
cristybb503372010-05-27 20:51:26 +00005610 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005611 i;
5612
cristybb503372010-05-27 20:51:26 +00005613 ssize_t
5614 y;
5615
cristy3ed852e2009-09-05 21:47:34 +00005616 /*
5617 Initialize wave image attributes.
5618 */
5619 assert(image != (Image *) NULL);
5620 assert(image->signature == MagickSignature);
5621 if (image->debug != MagickFalse)
5622 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5623 assert(exception != (ExceptionInfo *) NULL);
5624 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00005625 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
cristy3ed852e2009-09-05 21:47:34 +00005626 fabs(amplitude)),MagickTrue,exception);
5627 if (wave_image == (Image *) NULL)
5628 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005629 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005630 {
cristy3ed852e2009-09-05 21:47:34 +00005631 wave_image=DestroyImage(wave_image);
5632 return((Image *) NULL);
5633 }
cristy4c08aed2011-07-01 19:47:50 +00005634 if (wave_image->background_color.alpha != OpaqueAlpha)
cristy8a46d822012-08-28 23:32:39 +00005635 wave_image->alpha_trait=BlendPixelTrait;
cristy3ed852e2009-09-05 21:47:34 +00005636 /*
5637 Allocate sine map.
5638 */
cristya19f1d72012-08-07 18:24:38 +00005639 sine_map=(double *) AcquireQuantumMemory((size_t) wave_image->columns,
cristy3ed852e2009-09-05 21:47:34 +00005640 sizeof(*sine_map));
cristya19f1d72012-08-07 18:24:38 +00005641 if (sine_map == (double *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005642 {
5643 wave_image=DestroyImage(wave_image);
5644 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5645 }
cristybb503372010-05-27 20:51:26 +00005646 for (i=0; i < (ssize_t) wave_image->columns; i++)
cristy4205a3c2010-09-12 20:19:59 +00005647 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5648 wave_length));
cristy3ed852e2009-09-05 21:47:34 +00005649 /*
5650 Wave image.
5651 */
5652 status=MagickTrue;
5653 progress=0;
cristydb070952012-04-20 14:33:00 +00005654 image_view=AcquireVirtualCacheView(image,exception);
5655 wave_view=AcquireAuthenticCacheView(wave_image,exception);
cristyd76c51e2011-03-26 00:21:26 +00005656 (void) SetCacheViewVirtualPixelMethod(image_view,
5657 BackgroundVirtualPixelMethod);
cristyb5d5f722009-11-04 03:03:49 +00005658#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyac245f82012-05-05 17:13:57 +00005659 #pragma omp parallel for schedule(static,4) shared(progress,status) \
cristy4ee2b0c2012-05-15 00:30:35 +00005660 dynamic_number_threads(image,image->columns,image->rows,1)
cristy3ed852e2009-09-05 21:47:34 +00005661#endif
cristybb503372010-05-27 20:51:26 +00005662 for (y=0; y < (ssize_t) wave_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005663 {
cristy4c08aed2011-07-01 19:47:50 +00005664 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005665 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005666
cristye97bb922011-04-03 01:36:52 +00005667 register ssize_t
5668 x;
5669
cristy3ed852e2009-09-05 21:47:34 +00005670 if (status == MagickFalse)
5671 continue;
5672 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5673 exception);
cristyacd2ed22011-08-30 01:44:23 +00005674 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005675 {
5676 status=MagickFalse;
5677 continue;
5678 }
cristybb503372010-05-27 20:51:26 +00005679 for (x=0; x < (ssize_t) wave_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005680 {
cristy5c4e2582011-09-11 19:21:03 +00005681 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5682 (double) x,(double) (y-sine_map[x]),q,exception);
cristyed231572011-07-14 02:18:59 +00005683 q+=GetPixelChannels(wave_image);
cristy3ed852e2009-09-05 21:47:34 +00005684 }
5685 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5686 status=MagickFalse;
5687 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5688 {
5689 MagickBooleanType
5690 proceed;
5691
cristyb5d5f722009-11-04 03:03:49 +00005692#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy69cfa022012-01-23 12:47:29 +00005693 #pragma omp critical (MagickCore_WaveImage)
cristy3ed852e2009-09-05 21:47:34 +00005694#endif
5695 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5696 if (proceed == MagickFalse)
5697 status=MagickFalse;
5698 }
5699 }
5700 wave_view=DestroyCacheView(wave_view);
cristyd76c51e2011-03-26 00:21:26 +00005701 image_view=DestroyCacheView(image_view);
cristya19f1d72012-08-07 18:24:38 +00005702 sine_map=(double *) RelinquishMagickMemory(sine_map);
cristy3ed852e2009-09-05 21:47:34 +00005703 if (status == MagickFalse)
5704 wave_image=DestroyImage(wave_image);
5705 return(wave_image);
5706}