blob: c25452c73ca9cbd3882f8f25aef926d5c276a998 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% FFFFF X X %
7% F X X %
8% FFF X %
9% F X X %
10% F X X %
11% %
12% %
13% MagickCore Image Special Effects Methods %
14% %
15% Software Design %
16% John Cristy %
17% October 1996 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/annotate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/cache.h"
48#include "MagickCore/cache-view.h"
49#include "MagickCore/color.h"
50#include "MagickCore/color-private.h"
51#include "MagickCore/composite.h"
52#include "MagickCore/decorate.h"
53#include "MagickCore/draw.h"
54#include "MagickCore/effect.h"
55#include "MagickCore/enhance.h"
56#include "MagickCore/exception.h"
57#include "MagickCore/exception-private.h"
58#include "MagickCore/fx.h"
59#include "MagickCore/fx-private.h"
60#include "MagickCore/gem.h"
cristy8ea81222011-09-04 10:33:32 +000061#include "MagickCore/gem-private.h"
cristy4c08aed2011-07-01 19:47:50 +000062#include "MagickCore/geometry.h"
63#include "MagickCore/layer.h"
64#include "MagickCore/list.h"
65#include "MagickCore/log.h"
66#include "MagickCore/image.h"
67#include "MagickCore/image-private.h"
68#include "MagickCore/magick.h"
69#include "MagickCore/memory_.h"
70#include "MagickCore/monitor.h"
71#include "MagickCore/monitor-private.h"
72#include "MagickCore/option.h"
73#include "MagickCore/pixel.h"
74#include "MagickCore/pixel-accessor.h"
75#include "MagickCore/property.h"
76#include "MagickCore/quantum.h"
77#include "MagickCore/quantum-private.h"
78#include "MagickCore/random_.h"
79#include "MagickCore/random-private.h"
80#include "MagickCore/resample.h"
81#include "MagickCore/resample-private.h"
82#include "MagickCore/resize.h"
83#include "MagickCore/shear.h"
84#include "MagickCore/splay-tree.h"
85#include "MagickCore/statistic.h"
86#include "MagickCore/string_.h"
87#include "MagickCore/string-private.h"
88#include "MagickCore/thread-private.h"
89#include "MagickCore/transform.h"
90#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000091
92/*
93 Define declarations.
94*/
95#define LeftShiftOperator 0xf5
96#define RightShiftOperator 0xf6
97#define LessThanEqualOperator 0xf7
98#define GreaterThanEqualOperator 0xf8
99#define EqualOperator 0xf9
100#define NotEqualOperator 0xfa
101#define LogicalAndOperator 0xfb
102#define LogicalOrOperator 0xfc
cristy116af162010-08-13 01:25:47 +0000103#define ExponentialNotation 0xfd
cristy3ed852e2009-09-05 21:47:34 +0000104
105struct _FxInfo
106{
107 const Image
108 *images;
109
cristy3ed852e2009-09-05 21:47:34 +0000110 char
111 *expression;
112
113 FILE
114 *file;
115
116 SplayTreeInfo
117 *colors,
118 *symbols;
119
cristyd76c51e2011-03-26 00:21:26 +0000120 CacheView
121 **view;
cristy3ed852e2009-09-05 21:47:34 +0000122
123 RandomInfo
124 *random_info;
125
126 ExceptionInfo
127 *exception;
128};
129
130/*
131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132% %
133% %
134% %
135+ A c q u i r e F x I n f o %
136% %
137% %
138% %
139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140%
141% AcquireFxInfo() allocates the FxInfo structure.
142%
143% The format of the AcquireFxInfo method is:
144%
145% FxInfo *AcquireFxInfo(Image *image,const char *expression)
cristy0a9b3722010-10-23 18:45:49 +0000146%
cristy3ed852e2009-09-05 21:47:34 +0000147% A description of each parameter follows:
148%
149% o image: the image.
150%
151% o expression: the expression.
152%
153*/
cristy7832dc22011-09-05 01:21:53 +0000154MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression)
cristy3ed852e2009-09-05 21:47:34 +0000155{
156 char
157 fx_op[2];
158
cristycb180922011-03-11 14:41:24 +0000159 const Image
160 *next;
161
cristy3ed852e2009-09-05 21:47:34 +0000162 FxInfo
163 *fx_info;
164
cristybb503372010-05-27 20:51:26 +0000165 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000166 i;
167
cristy73bd4a52010-10-05 11:24:23 +0000168 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +0000169 if (fx_info == (FxInfo *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
172 fx_info->exception=AcquireExceptionInfo();
anthony7d86e172011-03-23 12:37:06 +0000173 fx_info->images=image;
cristy3ed852e2009-09-05 21:47:34 +0000174 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
177 RelinquishMagickMemory);
cristyd76c51e2011-03-26 00:21:26 +0000178 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
179 fx_info->images),sizeof(*fx_info->view));
180 if (fx_info->view == (CacheView **) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000181 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
cristya2262262011-03-11 02:50:37 +0000182 i=0;
cristy0ea377f2011-03-24 00:54:19 +0000183 next=GetFirstImageInList(fx_info->images);
184 for ( ; next != (Image *) NULL; next=next->next)
cristy3ed852e2009-09-05 21:47:34 +0000185 {
cristyd76c51e2011-03-26 00:21:26 +0000186 fx_info->view[i]=AcquireCacheView(next);
cristya2262262011-03-11 02:50:37 +0000187 i++;
cristy3ed852e2009-09-05 21:47:34 +0000188 }
189 fx_info->random_info=AcquireRandomInfo();
190 fx_info->expression=ConstantString(expression);
191 fx_info->file=stderr;
192 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
cristy37af0912011-05-23 16:09:42 +0000193 /*
194 Force right-to-left associativity for unary negation.
195 */
196 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
cristy3ed852e2009-09-05 21:47:34 +0000197 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
198 (strstr(fx_info->expression,"e-") != (char *) NULL))
199 {
200 /*
cristy116af162010-08-13 01:25:47 +0000201 Convert scientific notation.
cristy3ed852e2009-09-05 21:47:34 +0000202 */
cristy116af162010-08-13 01:25:47 +0000203 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
204 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
205 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
206 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
207 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
208 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
209 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
210 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
211 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
212 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
cristy2ffa8cd2011-05-24 12:45:55 +0000213 (void) SubstituteString(&fx_info->expression,"0e-1.0*","0**10^-");
cristy37af0912011-05-23 16:09:42 +0000214 (void) SubstituteString(&fx_info->expression,"1e-1.0*","1**10^-");
215 (void) SubstituteString(&fx_info->expression,"2e-1.0*","2**10^-");
216 (void) SubstituteString(&fx_info->expression,"3e-1.0*","3**10^-");
217 (void) SubstituteString(&fx_info->expression,"4e-1.0*","4**10^-");
218 (void) SubstituteString(&fx_info->expression,"5e-1.0*","5**10^-");
219 (void) SubstituteString(&fx_info->expression,"6e-1.0*","6**10^-");
220 (void) SubstituteString(&fx_info->expression,"7e-1.0*","7**10^-");
221 (void) SubstituteString(&fx_info->expression,"8e-1.0*","8**10^-");
222 (void) SubstituteString(&fx_info->expression,"9e-1.0*","9**10^-");
cristy3ed852e2009-09-05 21:47:34 +0000223 }
cristy37af0912011-05-23 16:09:42 +0000224 if ((strstr(fx_info->expression,"E+") != (char *) NULL) ||
225 (strstr(fx_info->expression,"E-") != (char *) NULL))
226 {
227 /*
228 Convert scientific notation.
229 */
230 (void) SubstituteString(&fx_info->expression,"0E+","0**10^");
231 (void) SubstituteString(&fx_info->expression,"1E+","1**10^");
232 (void) SubstituteString(&fx_info->expression,"2E+","2**10^");
233 (void) SubstituteString(&fx_info->expression,"3E+","3**10^");
234 (void) SubstituteString(&fx_info->expression,"4E+","4**10^");
235 (void) SubstituteString(&fx_info->expression,"5E+","5**10^");
236 (void) SubstituteString(&fx_info->expression,"6E+","6**10^");
237 (void) SubstituteString(&fx_info->expression,"7E+","7**10^");
238 (void) SubstituteString(&fx_info->expression,"8E+","8**10^");
239 (void) SubstituteString(&fx_info->expression,"9E+","9**10^");
cristy2ffa8cd2011-05-24 12:45:55 +0000240 (void) SubstituteString(&fx_info->expression,"0E-1.0*","0**10^-");
cristy37af0912011-05-23 16:09:42 +0000241 (void) SubstituteString(&fx_info->expression,"1E-1.0*","1**10^-");
242 (void) SubstituteString(&fx_info->expression,"2E-1.0*","2**10^-");
243 (void) SubstituteString(&fx_info->expression,"3E-1.0*","3**10^-");
244 (void) SubstituteString(&fx_info->expression,"4E-1.0*","4**10^-");
245 (void) SubstituteString(&fx_info->expression,"5E-1.0*","5**10^-");
246 (void) SubstituteString(&fx_info->expression,"6E-1.0*","6**10^-");
247 (void) SubstituteString(&fx_info->expression,"7E-1.0*","7**10^-");
248 (void) SubstituteString(&fx_info->expression,"8E-1.0*","8**10^-");
249 (void) SubstituteString(&fx_info->expression,"9E-1.0*","9**10^-");
250 }
cristy8b8a3ae2010-10-23 18:49:46 +0000251 /*
cristy3ed852e2009-09-05 21:47:34 +0000252 Convert complex to simple operators.
253 */
254 fx_op[1]='\0';
255 *fx_op=(char) LeftShiftOperator;
256 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
257 *fx_op=(char) RightShiftOperator;
258 (void) SubstituteString(&fx_info->expression,">>",fx_op);
259 *fx_op=(char) LessThanEqualOperator;
260 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
261 *fx_op=(char) GreaterThanEqualOperator;
262 (void) SubstituteString(&fx_info->expression,">=",fx_op);
263 *fx_op=(char) EqualOperator;
264 (void) SubstituteString(&fx_info->expression,"==",fx_op);
265 *fx_op=(char) NotEqualOperator;
266 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
267 *fx_op=(char) LogicalAndOperator;
268 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
269 *fx_op=(char) LogicalOrOperator;
270 (void) SubstituteString(&fx_info->expression,"||",fx_op);
cristy116af162010-08-13 01:25:47 +0000271 *fx_op=(char) ExponentialNotation;
272 (void) SubstituteString(&fx_info->expression,"**",fx_op);
cristy3ed852e2009-09-05 21:47:34 +0000273 return(fx_info);
274}
275
276/*
277%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278% %
279% %
280% %
281% A d d N o i s e I m a g e %
282% %
283% %
284% %
285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286%
287% AddNoiseImage() adds random noise to the image.
288%
289% The format of the AddNoiseImage method is:
290%
291% Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
cristy9ed1f812011-10-08 02:00:08 +0000292% const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000293%
294% A description of each parameter follows:
295%
296% o image: the image.
297%
298% o channel: the channel type.
299%
300% o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
301% Impulse, Laplacian, or Poisson.
302%
cristy9ed1f812011-10-08 02:00:08 +0000303% o attenuate: attenuate the random distribution.
304%
cristy3ed852e2009-09-05 21:47:34 +0000305% o exception: return any errors or warnings in this structure.
306%
307*/
cristy9ed1f812011-10-08 02:00:08 +0000308MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
309 const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000310{
311#define AddNoiseImageTag "AddNoise/Image"
312
cristyfa112112010-01-04 17:48:07 +0000313 CacheView
314 *image_view,
315 *noise_view;
316
cristy3ed852e2009-09-05 21:47:34 +0000317 Image
318 *noise_image;
319
cristy3ed852e2009-09-05 21:47:34 +0000320 MagickBooleanType
321 status;
322
cristybb503372010-05-27 20:51:26 +0000323 MagickOffsetType
324 progress;
325
cristy3ed852e2009-09-05 21:47:34 +0000326 RandomInfo
cristyfa112112010-01-04 17:48:07 +0000327 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +0000328
cristybb503372010-05-27 20:51:26 +0000329 ssize_t
330 y;
331
cristy3ed852e2009-09-05 21:47:34 +0000332 /*
333 Initialize noise image attributes.
334 */
335 assert(image != (const Image *) NULL);
336 assert(image->signature == MagickSignature);
337 if (image->debug != MagickFalse)
338 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
339 assert(exception != (ExceptionInfo *) NULL);
340 assert(exception->signature == MagickSignature);
cristyb2145892011-10-10 00:55:32 +0000341 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000342 if (noise_image == (Image *) NULL)
343 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000344 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000345 {
cristy3ed852e2009-09-05 21:47:34 +0000346 noise_image=DestroyImage(noise_image);
347 return((Image *) NULL);
348 }
349 /*
350 Add noise in each row.
351 */
cristy3ed852e2009-09-05 21:47:34 +0000352 status=MagickTrue;
353 progress=0;
354 random_info=AcquireRandomInfoThreadSet();
355 image_view=AcquireCacheView(image);
356 noise_view=AcquireCacheView(noise_image);
cristy319a1e72010-02-21 15:13:11 +0000357#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000358 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000359#endif
cristybb503372010-05-27 20:51:26 +0000360 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000361 {
cristy5c9e6f22010-09-17 17:31:01 +0000362 const int
363 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +0000364
cristy3ed852e2009-09-05 21:47:34 +0000365 MagickBooleanType
366 sync;
367
cristy4c08aed2011-07-01 19:47:50 +0000368 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000369 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000370
cristybb503372010-05-27 20:51:26 +0000371 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000372 x;
373
cristy4c08aed2011-07-01 19:47:50 +0000374 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000375 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000376
377 if (status == MagickFalse)
378 continue;
379 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
380 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
381 exception);
cristy4c08aed2011-07-01 19:47:50 +0000382 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000383 {
384 status=MagickFalse;
385 continue;
386 }
cristybb503372010-05-27 20:51:26 +0000387 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000388 {
cristy850b3072011-10-08 01:38:05 +0000389 register ssize_t
390 i;
391
392 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
393 {
394 PixelChannel
395 channel;
396
397 PixelTrait
398 noise_traits,
399 traits;
400
401 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
402 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
403 noise_traits=GetPixelChannelMapTraits(noise_image,channel);
404 if ((traits == UndefinedPixelTrait) ||
405 (noise_traits == UndefinedPixelTrait))
406 continue;
cristy9eeedea2011-11-02 19:04:05 +0000407 if ((noise_traits & CopyPixelTrait) != 0)
cristyb2145892011-10-10 00:55:32 +0000408 {
409 SetPixelChannel(noise_image,channel,p[i],q);
410 continue;
411 }
cristy850b3072011-10-08 01:38:05 +0000412 SetPixelChannel(noise_image,channel,ClampToQuantum(
413 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
414 q);
415 }
cristyed231572011-07-14 02:18:59 +0000416 p+=GetPixelChannels(image);
417 q+=GetPixelChannels(noise_image);
cristy3ed852e2009-09-05 21:47:34 +0000418 }
419 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
420 if (sync == MagickFalse)
421 status=MagickFalse;
422 if (image->progress_monitor != (MagickProgressMonitor) NULL)
423 {
424 MagickBooleanType
425 proceed;
426
cristyb5d5f722009-11-04 03:03:49 +0000427#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy319a1e72010-02-21 15:13:11 +0000428 #pragma omp critical (MagickCore_AddNoiseImage)
cristy3ed852e2009-09-05 21:47:34 +0000429#endif
430 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
431 image->rows);
432 if (proceed == MagickFalse)
433 status=MagickFalse;
434 }
435 }
436 noise_view=DestroyCacheView(noise_view);
437 image_view=DestroyCacheView(image_view);
438 random_info=DestroyRandomInfoThreadSet(random_info);
439 if (status == MagickFalse)
440 noise_image=DestroyImage(noise_image);
441 return(noise_image);
442}
443
444/*
445%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
446% %
447% %
448% %
449% B l u e S h i f t I m a g e %
450% %
451% %
452% %
453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454%
455% BlueShiftImage() mutes the colors of the image to simulate a scene at
456% nighttime in the moonlight.
457%
458% The format of the BlueShiftImage method is:
459%
460% Image *BlueShiftImage(const Image *image,const double factor,
461% ExceptionInfo *exception)
462%
463% A description of each parameter follows:
464%
465% o image: the image.
466%
467% o factor: the shift factor.
468%
469% o exception: return any errors or warnings in this structure.
470%
471*/
472MagickExport Image *BlueShiftImage(const Image *image,const double factor,
473 ExceptionInfo *exception)
474{
475#define BlueShiftImageTag "BlueShift/Image"
476
cristyc4c8d132010-01-07 01:58:38 +0000477 CacheView
478 *image_view,
479 *shift_view;
480
cristy3ed852e2009-09-05 21:47:34 +0000481 Image
482 *shift_image;
483
cristy3ed852e2009-09-05 21:47:34 +0000484 MagickBooleanType
485 status;
486
cristybb503372010-05-27 20:51:26 +0000487 MagickOffsetType
488 progress;
489
490 ssize_t
491 y;
492
cristy3ed852e2009-09-05 21:47:34 +0000493 /*
494 Allocate blue shift image.
495 */
496 assert(image != (const Image *) NULL);
497 assert(image->signature == MagickSignature);
498 if (image->debug != MagickFalse)
499 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
500 assert(exception != (ExceptionInfo *) NULL);
501 assert(exception->signature == MagickSignature);
502 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
503 exception);
504 if (shift_image == (Image *) NULL)
505 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000506 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000507 {
cristy3ed852e2009-09-05 21:47:34 +0000508 shift_image=DestroyImage(shift_image);
509 return((Image *) NULL);
510 }
511 /*
512 Blue-shift DirectClass image.
513 */
514 status=MagickTrue;
515 progress=0;
516 image_view=AcquireCacheView(image);
517 shift_view=AcquireCacheView(shift_image);
cristy319a1e72010-02-21 15:13:11 +0000518#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000519 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000520#endif
cristybb503372010-05-27 20:51:26 +0000521 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000522 {
523 MagickBooleanType
524 sync;
525
cristy4c08aed2011-07-01 19:47:50 +0000526 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000527 pixel;
528
529 Quantum
530 quantum;
531
cristy4c08aed2011-07-01 19:47:50 +0000532 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000533 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000534
cristybb503372010-05-27 20:51:26 +0000535 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000536 x;
537
cristy4c08aed2011-07-01 19:47:50 +0000538 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000539 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000540
541 if (status == MagickFalse)
542 continue;
543 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
544 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
545 exception);
cristy4c08aed2011-07-01 19:47:50 +0000546 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000547 {
548 status=MagickFalse;
549 continue;
550 }
cristybb503372010-05-27 20:51:26 +0000551 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000552 {
cristy4c08aed2011-07-01 19:47:50 +0000553 quantum=GetPixelRed(image,p);
554 if (GetPixelGreen(image,p) < quantum)
555 quantum=GetPixelGreen(image,p);
556 if (GetPixelBlue(image,p) < quantum)
557 quantum=GetPixelBlue(image,p);
558 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
559 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
560 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
561 quantum=GetPixelRed(image,p);
562 if (GetPixelGreen(image,p) > quantum)
563 quantum=GetPixelGreen(image,p);
564 if (GetPixelBlue(image,p) > quantum)
565 quantum=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000566 pixel.red=0.5*(pixel.red+factor*quantum);
567 pixel.green=0.5*(pixel.green+factor*quantum);
568 pixel.blue=0.5*(pixel.blue+factor*quantum);
cristy4c08aed2011-07-01 19:47:50 +0000569 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
570 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
571 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
cristyed231572011-07-14 02:18:59 +0000572 p+=GetPixelChannels(image);
573 q+=GetPixelChannels(shift_image);
cristy3ed852e2009-09-05 21:47:34 +0000574 }
575 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
576 if (sync == MagickFalse)
577 status=MagickFalse;
578 if (image->progress_monitor != (MagickProgressMonitor) NULL)
579 {
580 MagickBooleanType
581 proceed;
582
cristy319a1e72010-02-21 15:13:11 +0000583#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000584 #pragma omp critical (MagickCore_BlueShiftImage)
585#endif
586 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
587 image->rows);
588 if (proceed == MagickFalse)
589 status=MagickFalse;
590 }
591 }
592 image_view=DestroyCacheView(image_view);
593 shift_view=DestroyCacheView(shift_view);
594 if (status == MagickFalse)
595 shift_image=DestroyImage(shift_image);
596 return(shift_image);
597}
598
599/*
600%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601% %
602% %
603% %
604% C h a r c o a l I m a g e %
605% %
606% %
607% %
608%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609%
610% CharcoalImage() creates a new image that is a copy of an existing one with
611% the edge highlighted. It allocates the memory necessary for the new Image
612% structure and returns a pointer to the new image.
613%
614% The format of the CharcoalImage method is:
615%
616% Image *CharcoalImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +0000617% const double sigma,const double bias,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000618%
619% A description of each parameter follows:
620%
621% o image: the image.
622%
623% o radius: the radius of the pixel neighborhood.
624%
625% o sigma: the standard deviation of the Gaussian, in pixels.
626%
cristy05c0c9a2011-09-05 23:16:13 +0000627% o bias: the bias.
628%
cristy3ed852e2009-09-05 21:47:34 +0000629% o exception: return any errors or warnings in this structure.
630%
631*/
632MagickExport Image *CharcoalImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +0000633 const double sigma,const double bias,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000634{
635 Image
636 *charcoal_image,
637 *clone_image,
638 *edge_image;
639
640 assert(image != (Image *) NULL);
641 assert(image->signature == MagickSignature);
642 if (image->debug != MagickFalse)
643 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
644 assert(exception != (ExceptionInfo *) NULL);
645 assert(exception->signature == MagickSignature);
646 clone_image=CloneImage(image,0,0,MagickTrue,exception);
647 if (clone_image == (Image *) NULL)
648 return((Image *) NULL);
cristy018f07f2011-09-04 21:15:19 +0000649 (void) SetImageType(clone_image,GrayscaleType,exception);
cristy8ae632d2011-09-05 17:29:53 +0000650 edge_image=EdgeImage(clone_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000651 clone_image=DestroyImage(clone_image);
652 if (edge_image == (Image *) NULL)
653 return((Image *) NULL);
cristy05c0c9a2011-09-05 23:16:13 +0000654 charcoal_image=BlurImage(edge_image,radius,sigma,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +0000655 edge_image=DestroyImage(edge_image);
656 if (charcoal_image == (Image *) NULL)
657 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +0000658 (void) NormalizeImage(charcoal_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +0000659 (void) NegateImage(charcoal_image,MagickFalse,exception);
cristy018f07f2011-09-04 21:15:19 +0000660 (void) SetImageType(charcoal_image,GrayscaleType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000661 return(charcoal_image);
662}
663
664/*
665%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
666% %
667% %
668% %
669% C o l o r i z e I m a g e %
670% %
671% %
672% %
673%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
674%
675% ColorizeImage() blends the fill color with each pixel in the image.
676% A percentage blend is specified with opacity. Control the application
677% of different color components by specifying a different percentage for
678% each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
679%
680% The format of the ColorizeImage method is:
681%
cristyc7e6ff62011-10-03 13:46:11 +0000682% Image *ColorizeImage(const Image *image,const char *blend,
683% const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000684%
685% A description of each parameter follows:
686%
687% o image: the image.
688%
cristyc7e6ff62011-10-03 13:46:11 +0000689% o blend: A character string indicating the level of blending as a
cristy3ed852e2009-09-05 21:47:34 +0000690% percentage.
691%
692% o colorize: A color value.
693%
694% o exception: return any errors or warnings in this structure.
695%
696*/
cristyc7e6ff62011-10-03 13:46:11 +0000697MagickExport Image *ColorizeImage(const Image *image,const char *blend,
698 const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000699{
700#define ColorizeImageTag "Colorize/Image"
701
cristyc4c8d132010-01-07 01:58:38 +0000702 CacheView
703 *colorize_view,
704 *image_view;
705
cristy3ed852e2009-09-05 21:47:34 +0000706 GeometryInfo
707 geometry_info;
708
709 Image
710 *colorize_image;
711
cristy3ed852e2009-09-05 21:47:34 +0000712 MagickBooleanType
713 status;
714
cristybb503372010-05-27 20:51:26 +0000715 MagickOffsetType
716 progress;
717
cristy3ed852e2009-09-05 21:47:34 +0000718 MagickStatusType
719 flags;
720
cristyc7e6ff62011-10-03 13:46:11 +0000721 PixelInfo
722 pixel;
723
cristybb503372010-05-27 20:51:26 +0000724 ssize_t
725 y;
726
cristy3ed852e2009-09-05 21:47:34 +0000727 /*
728 Allocate colorized image.
729 */
730 assert(image != (const Image *) NULL);
731 assert(image->signature == MagickSignature);
732 if (image->debug != MagickFalse)
733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
734 assert(exception != (ExceptionInfo *) NULL);
735 assert(exception->signature == MagickSignature);
736 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
737 exception);
738 if (colorize_image == (Image *) NULL)
739 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000740 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000741 {
cristy3ed852e2009-09-05 21:47:34 +0000742 colorize_image=DestroyImage(colorize_image);
743 return((Image *) NULL);
744 }
cristyc7e6ff62011-10-03 13:46:11 +0000745 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000746 return(colorize_image);
747 /*
748 Determine RGB values of the pen color.
749 */
cristyc7e6ff62011-10-03 13:46:11 +0000750 GetPixelInfo(image,&pixel);
cristyb817c3f2011-10-03 14:00:35 +0000751 flags=ParseGeometry(blend,&geometry_info);
cristy3ed852e2009-09-05 21:47:34 +0000752 pixel.red=geometry_info.rho;
753 pixel.green=geometry_info.rho;
754 pixel.blue=geometry_info.rho;
cristyc7e6ff62011-10-03 13:46:11 +0000755 pixel.alpha=100.0;
cristy3ed852e2009-09-05 21:47:34 +0000756 if ((flags & SigmaValue) != 0)
757 pixel.green=geometry_info.sigma;
758 if ((flags & XiValue) != 0)
759 pixel.blue=geometry_info.xi;
760 if ((flags & PsiValue) != 0)
cristy4c08aed2011-07-01 19:47:50 +0000761 pixel.alpha=geometry_info.psi;
cristyc7e6ff62011-10-03 13:46:11 +0000762 if (pixel.colorspace == CMYKColorspace)
763 {
764 pixel.black=geometry_info.rho;
765 if ((flags & PsiValue) != 0)
766 pixel.black=geometry_info.psi;
767 if ((flags & ChiValue) != 0)
768 pixel.alpha=geometry_info.chi;
769 }
cristy3ed852e2009-09-05 21:47:34 +0000770 /*
771 Colorize DirectClass image.
772 */
773 status=MagickTrue;
774 progress=0;
775 image_view=AcquireCacheView(image);
776 colorize_view=AcquireCacheView(colorize_image);
cristy319a1e72010-02-21 15:13:11 +0000777#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000778 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000779#endif
cristybb503372010-05-27 20:51:26 +0000780 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000781 {
782 MagickBooleanType
783 sync;
784
cristy4c08aed2011-07-01 19:47:50 +0000785 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000786 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000787
cristybb503372010-05-27 20:51:26 +0000788 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000789 x;
790
cristy4c08aed2011-07-01 19:47:50 +0000791 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000792 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000793
794 if (status == MagickFalse)
795 continue;
796 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
797 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
798 exception);
cristy4c08aed2011-07-01 19:47:50 +0000799 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000800 {
801 status=MagickFalse;
802 continue;
803 }
cristybb503372010-05-27 20:51:26 +0000804 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000805 {
cristyc7e6ff62011-10-03 13:46:11 +0000806 register ssize_t
807 i;
808
809 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
810 {
811 PixelChannel
812 channel;
813
814 PixelTrait
815 colorize_traits,
816 traits;
817
818 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
819 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
820 colorize_traits=GetPixelChannelMapTraits(colorize_image,channel);
821 if ((traits == UndefinedPixelTrait) ||
822 (colorize_traits == UndefinedPixelTrait))
823 continue;
824 if ((colorize_traits & CopyPixelTrait) != 0)
825 {
826 SetPixelChannel(colorize_image,channel,p[i],q);
827 continue;
828 }
829 switch (channel)
830 {
831 case RedPixelChannel:
832 {
833 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
834 (100.0-pixel.red)+colorize->red*pixel.red)/100.0),q);
835 break;
836 }
837 case GreenPixelChannel:
838 {
839 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
840 (100.0-pixel.green)+colorize->green*pixel.green)/100.0),q);
841 break;
842 }
843 case BluePixelChannel:
844 {
845 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
846 (100.0-pixel.blue)+colorize->blue*pixel.blue)/100.0),q);
847 break;
848 }
849 case BlackPixelChannel:
850 {
851 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
852 (100.0-pixel.black)+colorize->black*pixel.black)/100.0),q);
853 break;
854 }
855 case AlphaPixelChannel:
856 {
857 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
858 (100.0-pixel.alpha)+colorize->alpha*pixel.alpha)/100.0),q);
859 break;
860 }
861 default:
862 {
863 SetPixelChannel(colorize_image,channel,p[i],q);
864 break;
865 }
866 }
867 }
cristyed231572011-07-14 02:18:59 +0000868 p+=GetPixelChannels(image);
869 q+=GetPixelChannels(colorize_image);
cristy3ed852e2009-09-05 21:47:34 +0000870 }
871 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
872 if (sync == MagickFalse)
873 status=MagickFalse;
874 if (image->progress_monitor != (MagickProgressMonitor) NULL)
875 {
876 MagickBooleanType
877 proceed;
878
cristy319a1e72010-02-21 15:13:11 +0000879#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000880 #pragma omp critical (MagickCore_ColorizeImage)
881#endif
882 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
883 if (proceed == MagickFalse)
884 status=MagickFalse;
885 }
886 }
887 image_view=DestroyCacheView(image_view);
888 colorize_view=DestroyCacheView(colorize_view);
889 if (status == MagickFalse)
890 colorize_image=DestroyImage(colorize_image);
891 return(colorize_image);
892}
893
894/*
895%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896% %
897% %
898% %
cristye6365592010-04-02 17:31:23 +0000899% C o l o r M a t r i x I m a g e %
900% %
901% %
902% %
903%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904%
905% ColorMatrixImage() applies color transformation to an image. This method
906% permits saturation changes, hue rotation, luminance to alpha, and various
907% other effects. Although variable-sized transformation matrices can be used,
908% typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
909% (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
910% except offsets are in column 6 rather than 5 (in support of CMYKA images)
911% and offsets are normalized (divide Flash offset by 255).
912%
913% The format of the ColorMatrixImage method is:
914%
915% Image *ColorMatrixImage(const Image *image,
916% const KernelInfo *color_matrix,ExceptionInfo *exception)
917%
918% A description of each parameter follows:
919%
920% o image: the image.
921%
922% o color_matrix: the color matrix.
923%
924% o exception: return any errors or warnings in this structure.
925%
926*/
927MagickExport Image *ColorMatrixImage(const Image *image,
928 const KernelInfo *color_matrix,ExceptionInfo *exception)
929{
930#define ColorMatrixImageTag "ColorMatrix/Image"
931
932 CacheView
933 *color_view,
934 *image_view;
935
936 double
937 ColorMatrix[6][6] =
938 {
939 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
940 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
941 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
942 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
943 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
944 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
945 };
946
947 Image
948 *color_image;
949
cristye6365592010-04-02 17:31:23 +0000950 MagickBooleanType
951 status;
952
cristybb503372010-05-27 20:51:26 +0000953 MagickOffsetType
954 progress;
955
956 register ssize_t
cristye6365592010-04-02 17:31:23 +0000957 i;
958
cristybb503372010-05-27 20:51:26 +0000959 ssize_t
960 u,
961 v,
962 y;
963
cristye6365592010-04-02 17:31:23 +0000964 /*
965 Create color matrix.
966 */
967 assert(image != (Image *) NULL);
968 assert(image->signature == MagickSignature);
969 if (image->debug != MagickFalse)
970 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
971 assert(exception != (ExceptionInfo *) NULL);
972 assert(exception->signature == MagickSignature);
973 i=0;
cristybb503372010-05-27 20:51:26 +0000974 for (v=0; v < (ssize_t) color_matrix->height; v++)
975 for (u=0; u < (ssize_t) color_matrix->width; u++)
cristye6365592010-04-02 17:31:23 +0000976 {
977 if ((v < 6) && (u < 6))
978 ColorMatrix[v][u]=color_matrix->values[i];
979 i++;
980 }
981 /*
982 Initialize color image.
983 */
cristy12550e62010-06-07 12:46:40 +0000984 color_image=CloneImage(image,0,0,MagickTrue,exception);
cristye6365592010-04-02 17:31:23 +0000985 if (color_image == (Image *) NULL)
986 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000987 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
cristye6365592010-04-02 17:31:23 +0000988 {
cristye6365592010-04-02 17:31:23 +0000989 color_image=DestroyImage(color_image);
990 return((Image *) NULL);
991 }
992 if (image->debug != MagickFalse)
993 {
994 char
995 format[MaxTextExtent],
996 *message;
997
998 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
999 " ColorMatrix image with color matrix:");
1000 message=AcquireString("");
1001 for (v=0; v < 6; v++)
1002 {
1003 *message='\0';
cristyb51dff52011-05-19 16:55:47 +00001004 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
cristye6365592010-04-02 17:31:23 +00001005 (void) ConcatenateString(&message,format);
1006 for (u=0; u < 6; u++)
1007 {
cristyb51dff52011-05-19 16:55:47 +00001008 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
cristye6365592010-04-02 17:31:23 +00001009 ColorMatrix[v][u]);
1010 (void) ConcatenateString(&message,format);
1011 }
1012 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
1013 }
1014 message=DestroyString(message);
1015 }
1016 /*
1017 ColorMatrix image.
1018 */
1019 status=MagickTrue;
1020 progress=0;
1021 image_view=AcquireCacheView(image);
1022 color_view=AcquireCacheView(color_image);
1023#if defined(MAGICKCORE_OPENMP_SUPPORT)
1024 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1025#endif
cristybb503372010-05-27 20:51:26 +00001026 for (y=0; y < (ssize_t) image->rows; y++)
cristye6365592010-04-02 17:31:23 +00001027 {
1028 MagickRealType
1029 pixel;
1030
cristy4c08aed2011-07-01 19:47:50 +00001031 register const Quantum
cristye6365592010-04-02 17:31:23 +00001032 *restrict p;
1033
cristy4c08aed2011-07-01 19:47:50 +00001034 register Quantum
1035 *restrict q;
1036
cristybb503372010-05-27 20:51:26 +00001037 register ssize_t
cristye6365592010-04-02 17:31:23 +00001038 x;
1039
cristye6365592010-04-02 17:31:23 +00001040 if (status == MagickFalse)
1041 continue;
1042 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1043 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
1044 exception);
cristy4c08aed2011-07-01 19:47:50 +00001045 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristye6365592010-04-02 17:31:23 +00001046 {
1047 status=MagickFalse;
1048 continue;
1049 }
cristybb503372010-05-27 20:51:26 +00001050 for (x=0; x < (ssize_t) image->columns; x++)
cristye6365592010-04-02 17:31:23 +00001051 {
cristybb503372010-05-27 20:51:26 +00001052 register ssize_t
cristye6365592010-04-02 17:31:23 +00001053 v;
1054
cristybb503372010-05-27 20:51:26 +00001055 size_t
cristye6365592010-04-02 17:31:23 +00001056 height;
1057
1058 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
cristybb503372010-05-27 20:51:26 +00001059 for (v=0; v < (ssize_t) height; v++)
cristye6365592010-04-02 17:31:23 +00001060 {
cristy4c08aed2011-07-01 19:47:50 +00001061 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
1062 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
cristye6365592010-04-02 17:31:23 +00001063 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001064 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
1065 if (image->matte != MagickFalse)
1066 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
cristye6365592010-04-02 17:31:23 +00001067 pixel+=QuantumRange*ColorMatrix[v][5];
1068 switch (v)
1069 {
cristy4c08aed2011-07-01 19:47:50 +00001070 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1071 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1072 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
cristye6365592010-04-02 17:31:23 +00001073 case 3:
1074 {
cristy4c08aed2011-07-01 19:47:50 +00001075 if (image->colorspace == CMYKColorspace)
1076 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
cristye6365592010-04-02 17:31:23 +00001077 break;
1078 }
1079 case 4:
1080 {
cristy4c08aed2011-07-01 19:47:50 +00001081 if (image->matte != MagickFalse)
1082 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
cristye6365592010-04-02 17:31:23 +00001083 break;
1084 }
1085 }
1086 }
cristyed231572011-07-14 02:18:59 +00001087 p+=GetPixelChannels(image);
1088 q+=GetPixelChannels(color_image);
cristye6365592010-04-02 17:31:23 +00001089 }
1090 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1091 status=MagickFalse;
1092 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1093 {
1094 MagickBooleanType
1095 proceed;
1096
1097#if defined(MAGICKCORE_OPENMP_SUPPORT)
1098 #pragma omp critical (MagickCore_ColorMatrixImage)
1099#endif
1100 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1101 image->rows);
1102 if (proceed == MagickFalse)
1103 status=MagickFalse;
1104 }
1105 }
1106 color_view=DestroyCacheView(color_view);
1107 image_view=DestroyCacheView(image_view);
1108 if (status == MagickFalse)
1109 color_image=DestroyImage(color_image);
1110 return(color_image);
1111}
1112
1113/*
1114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1115% %
1116% %
1117% %
cristy3ed852e2009-09-05 21:47:34 +00001118+ D e s t r o y F x I n f o %
1119% %
1120% %
1121% %
1122%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123%
1124% DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1125%
1126% The format of the DestroyFxInfo method is:
1127%
1128% ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1129%
1130% A description of each parameter follows:
1131%
1132% o fx_info: the fx info.
1133%
1134*/
cristy7832dc22011-09-05 01:21:53 +00001135MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
cristy3ed852e2009-09-05 21:47:34 +00001136{
cristybb503372010-05-27 20:51:26 +00001137 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001138 i;
1139
1140 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1141 fx_info->expression=DestroyString(fx_info->expression);
1142 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1143 fx_info->colors=DestroySplayTree(fx_info->colors);
cristy0ea377f2011-03-24 00:54:19 +00001144 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
cristyd76c51e2011-03-26 00:21:26 +00001145 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1146 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001147 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1148 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1149 return(fx_info);
1150}
1151
1152/*
1153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1154% %
1155% %
1156% %
cristy3ed852e2009-09-05 21:47:34 +00001157+ 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 %
1158% %
1159% %
1160% %
1161%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1162%
1163% FxEvaluateChannelExpression() evaluates an expression and returns the
1164% results.
1165%
1166% The format of the FxEvaluateExpression method is:
1167%
1168% MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00001169% const PixelChannel channel,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +00001170% MagickRealType *alpha,Exceptioninfo *exception)
1171% MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1172% MagickRealType *alpha,Exceptioninfo *exception)
1173%
1174% A description of each parameter follows:
1175%
1176% o fx_info: the fx info.
1177%
1178% o channel: the channel.
1179%
1180% o x,y: the pixel position.
1181%
1182% o alpha: the result.
1183%
1184% o exception: return any errors or warnings in this structure.
1185%
1186*/
1187
cristy351842f2010-03-07 15:27:38 +00001188static inline double MagickMax(const double x,const double y)
1189{
1190 if (x > y)
1191 return(x);
1192 return(y);
1193}
1194
1195static inline double MagickMin(const double x,const double y)
1196{
1197 if (x < y)
1198 return(x);
1199 return(y);
1200}
1201
cristy3ed852e2009-09-05 21:47:34 +00001202static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
cristy0568ffc2011-07-25 16:54:14 +00001203 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001204{
1205 char
1206 key[MaxTextExtent],
1207 statistic[MaxTextExtent];
1208
1209 const char
1210 *value;
1211
1212 register const char
1213 *p;
1214
1215 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1216 if (*p == '.')
1217 switch (*++p) /* e.g. depth.r */
1218 {
cristy541ae572011-08-05 19:08:59 +00001219 case 'r': channel=RedPixelChannel; break;
1220 case 'g': channel=GreenPixelChannel; break;
1221 case 'b': channel=BluePixelChannel; break;
1222 case 'c': channel=CyanPixelChannel; break;
1223 case 'm': channel=MagentaPixelChannel; break;
1224 case 'y': channel=YellowPixelChannel; break;
1225 case 'k': channel=BlackPixelChannel; break;
cristy3ed852e2009-09-05 21:47:34 +00001226 default: break;
1227 }
cristyb51dff52011-05-19 16:55:47 +00001228 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
cristye8c25f92010-06-03 00:53:06 +00001229 (double) channel,symbol);
cristy3ed852e2009-09-05 21:47:34 +00001230 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1231 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001232 return(QuantumScale*InterpretLocaleValue(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001233 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1234 if (LocaleNCompare(symbol,"depth",5) == 0)
1235 {
cristybb503372010-05-27 20:51:26 +00001236 size_t
cristy3ed852e2009-09-05 21:47:34 +00001237 depth;
1238
cristyfefab1b2011-07-05 00:33:22 +00001239 depth=GetImageDepth(image,exception);
1240 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
cristy3ed852e2009-09-05 21:47:34 +00001241 }
1242 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1243 {
1244 double
1245 kurtosis,
1246 skewness;
1247
cristyd42d9952011-07-08 14:21:50 +00001248 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001249 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
cristy3ed852e2009-09-05 21:47:34 +00001250 }
1251 if (LocaleNCompare(symbol,"maxima",6) == 0)
1252 {
1253 double
1254 maxima,
1255 minima;
1256
cristyd42d9952011-07-08 14:21:50 +00001257 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001258 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
cristy3ed852e2009-09-05 21:47:34 +00001259 }
1260 if (LocaleNCompare(symbol,"mean",4) == 0)
1261 {
1262 double
1263 mean,
1264 standard_deviation;
1265
cristyd42d9952011-07-08 14:21:50 +00001266 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001267 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
cristy3ed852e2009-09-05 21:47:34 +00001268 }
1269 if (LocaleNCompare(symbol,"minima",6) == 0)
1270 {
1271 double
1272 maxima,
1273 minima;
1274
cristyd42d9952011-07-08 14:21:50 +00001275 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001276 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
cristy3ed852e2009-09-05 21:47:34 +00001277 }
1278 if (LocaleNCompare(symbol,"skewness",8) == 0)
1279 {
1280 double
1281 kurtosis,
1282 skewness;
1283
cristyd42d9952011-07-08 14:21:50 +00001284 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001285 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
cristy3ed852e2009-09-05 21:47:34 +00001286 }
1287 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1288 {
1289 double
1290 mean,
1291 standard_deviation;
1292
cristyd42d9952011-07-08 14:21:50 +00001293 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001294 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
cristy3ed852e2009-09-05 21:47:34 +00001295 standard_deviation);
1296 }
1297 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1298 ConstantString(statistic));
cristyc1acd842011-05-19 23:05:47 +00001299 return(QuantumScale*InterpretLocaleValue(statistic,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001300}
1301
1302static MagickRealType
cristy0568ffc2011-07-25 16:54:14 +00001303 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
cristye85007d2010-06-06 22:51:36 +00001304 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +00001305
cristy0568ffc2011-07-25 16:54:14 +00001306static inline MagickRealType FxMax(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001307 const ssize_t x,const ssize_t y,const char *expression,
1308 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001309{
1310 MagickRealType
1311 alpha,
1312 beta;
1313
1314 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1315 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1316}
1317
cristy0568ffc2011-07-25 16:54:14 +00001318static inline MagickRealType FxMin(FxInfo *fx_info,PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001319 const ssize_t x,const ssize_t y,const char *expression,
1320 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001321{
1322 MagickRealType
1323 alpha,
1324 beta;
1325
1326 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1327 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1328}
1329
1330static inline const char *FxSubexpression(const char *expression,
1331 ExceptionInfo *exception)
1332{
1333 const char
1334 *subexpression;
1335
cristybb503372010-05-27 20:51:26 +00001336 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001337 level;
1338
1339 level=0;
1340 subexpression=expression;
1341 while ((*subexpression != '\0') &&
1342 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1343 {
1344 if (strchr("(",(int) *subexpression) != (char *) NULL)
1345 level++;
1346 else
1347 if (strchr(")",(int) *subexpression) != (char *) NULL)
1348 level--;
1349 subexpression++;
1350 }
1351 if (*subexpression == '\0')
1352 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1353 "UnbalancedParenthesis","`%s'",expression);
1354 return(subexpression);
1355}
1356
cristy0568ffc2011-07-25 16:54:14 +00001357static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001358 const ssize_t x,const ssize_t y,const char *expression,
1359 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001360{
1361 char
1362 *q,
1363 subexpression[MaxTextExtent],
1364 symbol[MaxTextExtent];
1365
1366 const char
1367 *p,
1368 *value;
1369
1370 Image
1371 *image;
1372
cristy4c08aed2011-07-01 19:47:50 +00001373 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001374 pixel;
1375
1376 MagickRealType
1377 alpha,
1378 beta;
1379
1380 PointInfo
1381 point;
1382
cristybb503372010-05-27 20:51:26 +00001383 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001384 i;
1385
1386 size_t
1387 length;
1388
cristybb503372010-05-27 20:51:26 +00001389 size_t
cristy3ed852e2009-09-05 21:47:34 +00001390 level;
1391
1392 p=expression;
1393 i=GetImageIndexInList(fx_info->images);
1394 level=0;
1395 point.x=(double) x;
1396 point.y=(double) y;
1397 if (isalpha((int) *(p+1)) == 0)
1398 {
1399 if (strchr("suv",(int) *p) != (char *) NULL)
1400 {
1401 switch (*p)
1402 {
1403 case 's':
1404 default:
1405 {
1406 i=GetImageIndexInList(fx_info->images);
1407 break;
1408 }
1409 case 'u': i=0; break;
1410 case 'v': i=1; break;
1411 }
1412 p++;
1413 if (*p == '[')
1414 {
1415 level++;
1416 q=subexpression;
1417 for (p++; *p != '\0'; )
1418 {
1419 if (*p == '[')
1420 level++;
1421 else
1422 if (*p == ']')
1423 {
1424 level--;
1425 if (level == 0)
1426 break;
1427 }
1428 *q++=(*p++);
1429 }
1430 *q='\0';
1431 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1432 &beta,exception);
cristybb503372010-05-27 20:51:26 +00001433 i=(ssize_t) (alpha+0.5);
cristy3ed852e2009-09-05 21:47:34 +00001434 p++;
1435 }
1436 if (*p == '.')
1437 p++;
1438 }
1439 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1440 {
1441 p++;
1442 if (*p == '{')
1443 {
1444 level++;
1445 q=subexpression;
1446 for (p++; *p != '\0'; )
1447 {
1448 if (*p == '{')
1449 level++;
1450 else
1451 if (*p == '}')
1452 {
1453 level--;
1454 if (level == 0)
1455 break;
1456 }
1457 *q++=(*p++);
1458 }
1459 *q='\0';
1460 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1461 &beta,exception);
1462 point.x=alpha;
1463 point.y=beta;
1464 p++;
1465 }
1466 else
1467 if (*p == '[')
1468 {
1469 level++;
1470 q=subexpression;
1471 for (p++; *p != '\0'; )
1472 {
1473 if (*p == '[')
1474 level++;
1475 else
1476 if (*p == ']')
1477 {
1478 level--;
1479 if (level == 0)
1480 break;
1481 }
1482 *q++=(*p++);
1483 }
1484 *q='\0';
1485 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1486 &beta,exception);
1487 point.x+=alpha;
1488 point.y+=beta;
1489 p++;
1490 }
1491 if (*p == '.')
1492 p++;
1493 }
1494 }
1495 length=GetImageListLength(fx_info->images);
1496 while (i < 0)
cristybb503372010-05-27 20:51:26 +00001497 i+=(ssize_t) length;
cristy3ed852e2009-09-05 21:47:34 +00001498 i%=length;
1499 image=GetImageFromList(fx_info->images,i);
1500 if (image == (Image *) NULL)
1501 {
1502 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1503 "NoSuchImage","`%s'",expression);
1504 return(0.0);
1505 }
cristy4c08aed2011-07-01 19:47:50 +00001506 GetPixelInfo(image,&pixel);
1507 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
cristy4f820712011-04-01 12:35:43 +00001508 point.x,point.y,&pixel,exception);
cristy3ed852e2009-09-05 21:47:34 +00001509 if ((strlen(p) > 2) &&
1510 (LocaleCompare(p,"intensity") != 0) &&
1511 (LocaleCompare(p,"luminance") != 0) &&
1512 (LocaleCompare(p,"hue") != 0) &&
1513 (LocaleCompare(p,"saturation") != 0) &&
1514 (LocaleCompare(p,"lightness") != 0))
1515 {
1516 char
1517 name[MaxTextExtent];
1518
1519 (void) CopyMagickString(name,p,MaxTextExtent);
1520 for (q=name+(strlen(name)-1); q > name; q--)
1521 {
1522 if (*q == ')')
1523 break;
1524 if (*q == '.')
1525 {
1526 *q='\0';
1527 break;
1528 }
1529 }
1530 if ((strlen(name) > 2) &&
1531 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1532 {
cristy4c08aed2011-07-01 19:47:50 +00001533 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001534 *color;
1535
cristy4c08aed2011-07-01 19:47:50 +00001536 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1537 if (color != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001538 {
1539 pixel=(*color);
1540 p+=strlen(name);
1541 }
1542 else
cristy269c9412011-10-13 23:41:15 +00001543 if (QueryColorCompliance(name,AllCompliance,&pixel,fx_info->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001544 {
1545 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
cristy4c08aed2011-07-01 19:47:50 +00001546 ClonePixelInfo(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001547 p+=strlen(name);
1548 }
1549 }
1550 }
1551 (void) CopyMagickString(symbol,p,MaxTextExtent);
1552 StripString(symbol);
1553 if (*symbol == '\0')
1554 {
1555 switch (channel)
1556 {
cristy0568ffc2011-07-25 16:54:14 +00001557 case RedPixelChannel: return(QuantumScale*pixel.red);
1558 case GreenPixelChannel: return(QuantumScale*pixel.green);
1559 case BluePixelChannel: return(QuantumScale*pixel.blue);
1560 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001561 {
1562 if (image->colorspace != CMYKColorspace)
1563 {
1564 (void) ThrowMagickException(exception,GetMagickModule(),
1565 OptionError,"ColorSeparatedImageRequired","`%s'",
1566 image->filename);
1567 return(0.0);
1568 }
cristy4c08aed2011-07-01 19:47:50 +00001569 return(QuantumScale*pixel.black);
1570 }
cristy0568ffc2011-07-25 16:54:14 +00001571 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001572 {
1573 MagickRealType
1574 alpha;
1575
1576 if (pixel.matte == MagickFalse)
1577 return(1.0);
1578 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1579 return(alpha);
cristy3ed852e2009-09-05 21:47:34 +00001580 }
cristyb3a73b52011-07-26 01:34:43 +00001581 case IntensityPixelChannel:
cristyf364ed42010-12-15 01:54:43 +00001582 {
cristy4c08aed2011-07-01 19:47:50 +00001583 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristyf364ed42010-12-15 01:54:43 +00001584 }
cristy3ed852e2009-09-05 21:47:34 +00001585 default:
1586 break;
1587 }
1588 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1589 "UnableToParseExpression","`%s'",p);
1590 return(0.0);
1591 }
1592 switch (*symbol)
1593 {
1594 case 'A':
1595 case 'a':
1596 {
1597 if (LocaleCompare(symbol,"a") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001598 return((MagickRealType) (QuantumScale*pixel.alpha));
cristy3ed852e2009-09-05 21:47:34 +00001599 break;
1600 }
1601 case 'B':
1602 case 'b':
1603 {
1604 if (LocaleCompare(symbol,"b") == 0)
1605 return(QuantumScale*pixel.blue);
1606 break;
1607 }
1608 case 'C':
1609 case 'c':
1610 {
1611 if (LocaleNCompare(symbol,"channel",7) == 0)
1612 {
1613 GeometryInfo
1614 channel_info;
1615
1616 MagickStatusType
1617 flags;
1618
1619 flags=ParseGeometry(symbol+7,&channel_info);
1620 if (image->colorspace == CMYKColorspace)
1621 switch (channel)
1622 {
cristy0568ffc2011-07-25 16:54:14 +00001623 case CyanPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001624 {
1625 if ((flags & RhoValue) == 0)
1626 return(0.0);
1627 return(channel_info.rho);
1628 }
cristy0568ffc2011-07-25 16:54:14 +00001629 case MagentaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001630 {
1631 if ((flags & SigmaValue) == 0)
1632 return(0.0);
1633 return(channel_info.sigma);
1634 }
cristy0568ffc2011-07-25 16:54:14 +00001635 case YellowPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001636 {
1637 if ((flags & XiValue) == 0)
1638 return(0.0);
1639 return(channel_info.xi);
1640 }
cristy0568ffc2011-07-25 16:54:14 +00001641 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001642 {
1643 if ((flags & PsiValue) == 0)
1644 return(0.0);
1645 return(channel_info.psi);
1646 }
cristy0568ffc2011-07-25 16:54:14 +00001647 case AlphaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001648 {
1649 if ((flags & ChiValue) == 0)
1650 return(0.0);
1651 return(channel_info.chi);
1652 }
1653 default:
1654 return(0.0);
1655 }
1656 switch (channel)
1657 {
cristy0568ffc2011-07-25 16:54:14 +00001658 case RedPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001659 {
1660 if ((flags & RhoValue) == 0)
1661 return(0.0);
1662 return(channel_info.rho);
1663 }
cristy0568ffc2011-07-25 16:54:14 +00001664 case GreenPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001665 {
1666 if ((flags & SigmaValue) == 0)
1667 return(0.0);
1668 return(channel_info.sigma);
1669 }
cristy0568ffc2011-07-25 16:54:14 +00001670 case BluePixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001671 {
1672 if ((flags & XiValue) == 0)
1673 return(0.0);
1674 return(channel_info.xi);
1675 }
cristy0568ffc2011-07-25 16:54:14 +00001676 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001677 {
1678 if ((flags & ChiValue) == 0)
1679 return(0.0);
1680 return(channel_info.chi);
1681 }
cristy0568ffc2011-07-25 16:54:14 +00001682 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001683 {
1684 if ((flags & PsiValue) == 0)
1685 return(0.0);
1686 return(channel_info.psi);
1687 }
cristy3ed852e2009-09-05 21:47:34 +00001688 default:
1689 return(0.0);
1690 }
1691 return(0.0);
1692 }
1693 if (LocaleCompare(symbol,"c") == 0)
1694 return(QuantumScale*pixel.red);
1695 break;
1696 }
1697 case 'D':
1698 case 'd':
1699 {
1700 if (LocaleNCompare(symbol,"depth",5) == 0)
1701 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1702 break;
1703 }
1704 case 'G':
1705 case 'g':
1706 {
1707 if (LocaleCompare(symbol,"g") == 0)
1708 return(QuantumScale*pixel.green);
1709 break;
1710 }
1711 case 'K':
1712 case 'k':
1713 {
1714 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1715 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1716 if (LocaleCompare(symbol,"k") == 0)
1717 {
1718 if (image->colorspace != CMYKColorspace)
1719 {
1720 (void) ThrowMagickException(exception,GetMagickModule(),
1721 OptionError,"ColorSeparatedImageRequired","`%s'",
1722 image->filename);
1723 return(0.0);
1724 }
cristy4c08aed2011-07-01 19:47:50 +00001725 return(QuantumScale*pixel.black);
cristy3ed852e2009-09-05 21:47:34 +00001726 }
1727 break;
1728 }
1729 case 'H':
1730 case 'h':
1731 {
1732 if (LocaleCompare(symbol,"h") == 0)
1733 return((MagickRealType) image->rows);
1734 if (LocaleCompare(symbol,"hue") == 0)
1735 {
1736 double
1737 hue,
1738 lightness,
1739 saturation;
1740
cristyda1f9c12011-10-02 21:39:49 +00001741 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1742 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001743 return(hue);
1744 }
1745 break;
1746 }
1747 case 'I':
1748 case 'i':
1749 {
1750 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1751 (LocaleCompare(symbol,"image.minima") == 0) ||
1752 (LocaleCompare(symbol,"image.maxima") == 0) ||
1753 (LocaleCompare(symbol,"image.mean") == 0) ||
1754 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1755 (LocaleCompare(symbol,"image.skewness") == 0) ||
1756 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1757 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1758 if (LocaleCompare(symbol,"image.resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001759 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001760 if (LocaleCompare(symbol,"image.resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001761 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001762 if (LocaleCompare(symbol,"intensity") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001763 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001764 if (LocaleCompare(symbol,"i") == 0)
1765 return((MagickRealType) x);
1766 break;
1767 }
1768 case 'J':
1769 case 'j':
1770 {
1771 if (LocaleCompare(symbol,"j") == 0)
1772 return((MagickRealType) y);
1773 break;
1774 }
1775 case 'L':
1776 case 'l':
1777 {
1778 if (LocaleCompare(symbol,"lightness") == 0)
1779 {
1780 double
1781 hue,
1782 lightness,
1783 saturation;
1784
cristyda1f9c12011-10-02 21:39:49 +00001785 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1786 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001787 return(lightness);
1788 }
1789 if (LocaleCompare(symbol,"luminance") == 0)
1790 {
1791 double
1792 luminence;
1793
1794 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1795 return(QuantumScale*luminence);
1796 }
1797 break;
1798 }
1799 case 'M':
1800 case 'm':
1801 {
1802 if (LocaleNCompare(symbol,"maxima",6) == 0)
1803 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1804 if (LocaleNCompare(symbol,"mean",4) == 0)
1805 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1806 if (LocaleNCompare(symbol,"minima",6) == 0)
1807 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1808 if (LocaleCompare(symbol,"m") == 0)
1809 return(QuantumScale*pixel.blue);
1810 break;
1811 }
1812 case 'N':
1813 case 'n':
1814 {
1815 if (LocaleCompare(symbol,"n") == 0)
anthony374f5dd2011-03-25 10:08:53 +00001816 return((MagickRealType) GetImageListLength(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001817 break;
1818 }
1819 case 'O':
1820 case 'o':
1821 {
1822 if (LocaleCompare(symbol,"o") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001823 return(QuantumScale*pixel.alpha);
cristy3ed852e2009-09-05 21:47:34 +00001824 break;
1825 }
1826 case 'P':
1827 case 'p':
1828 {
1829 if (LocaleCompare(symbol,"page.height") == 0)
1830 return((MagickRealType) image->page.height);
1831 if (LocaleCompare(symbol,"page.width") == 0)
1832 return((MagickRealType) image->page.width);
1833 if (LocaleCompare(symbol,"page.x") == 0)
1834 return((MagickRealType) image->page.x);
1835 if (LocaleCompare(symbol,"page.y") == 0)
1836 return((MagickRealType) image->page.y);
1837 break;
1838 }
1839 case 'R':
1840 case 'r':
1841 {
1842 if (LocaleCompare(symbol,"resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001843 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001844 if (LocaleCompare(symbol,"resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001845 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001846 if (LocaleCompare(symbol,"r") == 0)
1847 return(QuantumScale*pixel.red);
1848 break;
1849 }
1850 case 'S':
1851 case 's':
1852 {
1853 if (LocaleCompare(symbol,"saturation") == 0)
1854 {
1855 double
1856 hue,
1857 lightness,
1858 saturation;
1859
cristyda1f9c12011-10-02 21:39:49 +00001860 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1861 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001862 return(saturation);
1863 }
1864 if (LocaleNCompare(symbol,"skewness",8) == 0)
1865 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1866 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1867 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1868 break;
1869 }
1870 case 'T':
1871 case 't':
1872 {
1873 if (LocaleCompare(symbol,"t") == 0)
cristy5a15b932011-03-26 12:50:33 +00001874 return((MagickRealType) GetImageIndexInList(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001875 break;
1876 }
1877 case 'W':
1878 case 'w':
1879 {
1880 if (LocaleCompare(symbol,"w") == 0)
1881 return((MagickRealType) image->columns);
1882 break;
1883 }
1884 case 'Y':
1885 case 'y':
1886 {
1887 if (LocaleCompare(symbol,"y") == 0)
1888 return(QuantumScale*pixel.green);
1889 break;
1890 }
1891 case 'Z':
1892 case 'z':
1893 {
1894 if (LocaleCompare(symbol,"z") == 0)
1895 {
1896 MagickRealType
1897 depth;
1898
cristyfefab1b2011-07-05 00:33:22 +00001899 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001900 return(depth);
1901 }
1902 break;
1903 }
1904 default:
1905 break;
1906 }
1907 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1908 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001909 return((MagickRealType) InterpretLocaleValue(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001910 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1911 "UnableToParseExpression","`%s'",symbol);
1912 return(0.0);
1913}
1914
1915static const char *FxOperatorPrecedence(const char *expression,
1916 ExceptionInfo *exception)
1917{
1918 typedef enum
1919 {
1920 UndefinedPrecedence,
1921 NullPrecedence,
1922 BitwiseComplementPrecedence,
1923 ExponentPrecedence,
cristy116af162010-08-13 01:25:47 +00001924 ExponentialNotationPrecedence,
cristy3ed852e2009-09-05 21:47:34 +00001925 MultiplyPrecedence,
1926 AdditionPrecedence,
1927 ShiftPrecedence,
1928 RelationalPrecedence,
1929 EquivalencyPrecedence,
1930 BitwiseAndPrecedence,
1931 BitwiseOrPrecedence,
1932 LogicalAndPrecedence,
1933 LogicalOrPrecedence,
1934 TernaryPrecedence,
1935 AssignmentPrecedence,
1936 CommaPrecedence,
1937 SeparatorPrecedence
1938 } FxPrecedence;
1939
1940 FxPrecedence
1941 precedence,
1942 target;
1943
1944 register const char
1945 *subexpression;
1946
1947 register int
1948 c;
1949
cristybb503372010-05-27 20:51:26 +00001950 size_t
cristy3ed852e2009-09-05 21:47:34 +00001951 level;
1952
1953 c=0;
1954 level=0;
1955 subexpression=(const char *) NULL;
1956 target=NullPrecedence;
1957 while (*expression != '\0')
1958 {
1959 precedence=UndefinedPrecedence;
1960 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1961 {
1962 expression++;
1963 continue;
1964 }
cristy488fa882010-03-01 22:34:24 +00001965 switch (*expression)
1966 {
1967 case 'A':
1968 case 'a':
cristy3ed852e2009-09-05 21:47:34 +00001969 {
cristyb33454f2011-08-03 02:10:45 +00001970#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00001971 if (LocaleNCompare(expression,"acosh",5) == 0)
1972 {
1973 expression+=5;
1974 break;
1975 }
cristyb33454f2011-08-03 02:10:45 +00001976#endif
1977#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00001978 if (LocaleNCompare(expression,"asinh",5) == 0)
1979 {
1980 expression+=5;
1981 break;
1982 }
cristyb33454f2011-08-03 02:10:45 +00001983#endif
1984#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00001985 if (LocaleNCompare(expression,"atanh",5) == 0)
cristy488fa882010-03-01 22:34:24 +00001986 {
1987 expression+=5;
1988 break;
1989 }
cristyb33454f2011-08-03 02:10:45 +00001990#endif
cristy488fa882010-03-01 22:34:24 +00001991 break;
cristy3ed852e2009-09-05 21:47:34 +00001992 }
cristy488fa882010-03-01 22:34:24 +00001993 case 'J':
1994 case 'j':
1995 {
1996 if ((LocaleNCompare(expression,"j0",2) == 0) ||
1997 (LocaleNCompare(expression,"j1",2) == 0))
1998 {
1999 expression+=2;
2000 break;
2001 }
2002 break;
2003 }
cristy2def9322010-06-18 23:59:37 +00002004 case '#':
2005 {
2006 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
2007 expression++;
2008 break;
2009 }
cristy488fa882010-03-01 22:34:24 +00002010 default:
2011 break;
2012 }
cristy3ed852e2009-09-05 21:47:34 +00002013 if ((c == (int) '{') || (c == (int) '['))
2014 level++;
2015 else
2016 if ((c == (int) '}') || (c == (int) ']'))
2017 level--;
2018 if (level == 0)
2019 switch ((unsigned char) *expression)
2020 {
2021 case '~':
2022 case '!':
2023 {
2024 precedence=BitwiseComplementPrecedence;
2025 break;
2026 }
2027 case '^':
cristy6621e252010-08-13 00:42:57 +00002028 case '@':
cristy3ed852e2009-09-05 21:47:34 +00002029 {
2030 precedence=ExponentPrecedence;
2031 break;
2032 }
2033 default:
2034 {
2035 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
2036 (strchr(")",c) != (char *) NULL))) &&
2037 (((islower((int) ((char) *expression)) != 0) ||
2038 (strchr("(",(int) *expression) != (char *) NULL)) ||
2039 ((isdigit((int) ((char) c)) == 0) &&
2040 (isdigit((int) ((char) *expression)) != 0))) &&
2041 (strchr("xy",(int) *expression) == (char *) NULL))
2042 precedence=MultiplyPrecedence;
2043 break;
2044 }
2045 case '*':
2046 case '/':
2047 case '%':
2048 {
2049 precedence=MultiplyPrecedence;
2050 break;
2051 }
2052 case '+':
2053 case '-':
2054 {
2055 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
2056 (isalpha(c) != 0))
2057 precedence=AdditionPrecedence;
2058 break;
2059 }
2060 case LeftShiftOperator:
2061 case RightShiftOperator:
2062 {
2063 precedence=ShiftPrecedence;
2064 break;
2065 }
2066 case '<':
2067 case LessThanEqualOperator:
2068 case GreaterThanEqualOperator:
2069 case '>':
2070 {
2071 precedence=RelationalPrecedence;
2072 break;
2073 }
2074 case EqualOperator:
2075 case NotEqualOperator:
2076 {
2077 precedence=EquivalencyPrecedence;
2078 break;
2079 }
2080 case '&':
2081 {
2082 precedence=BitwiseAndPrecedence;
2083 break;
2084 }
2085 case '|':
2086 {
2087 precedence=BitwiseOrPrecedence;
2088 break;
2089 }
2090 case LogicalAndOperator:
2091 {
2092 precedence=LogicalAndPrecedence;
2093 break;
2094 }
2095 case LogicalOrOperator:
2096 {
2097 precedence=LogicalOrPrecedence;
2098 break;
2099 }
cristy116af162010-08-13 01:25:47 +00002100 case ExponentialNotation:
2101 {
2102 precedence=ExponentialNotationPrecedence;
2103 break;
2104 }
cristy3ed852e2009-09-05 21:47:34 +00002105 case ':':
2106 case '?':
2107 {
2108 precedence=TernaryPrecedence;
2109 break;
2110 }
2111 case '=':
2112 {
2113 precedence=AssignmentPrecedence;
2114 break;
2115 }
2116 case ',':
2117 {
2118 precedence=CommaPrecedence;
2119 break;
2120 }
2121 case ';':
2122 {
2123 precedence=SeparatorPrecedence;
2124 break;
2125 }
2126 }
2127 if ((precedence == BitwiseComplementPrecedence) ||
2128 (precedence == TernaryPrecedence) ||
2129 (precedence == AssignmentPrecedence))
2130 {
2131 if (precedence > target)
2132 {
2133 /*
2134 Right-to-left associativity.
2135 */
2136 target=precedence;
2137 subexpression=expression;
2138 }
2139 }
2140 else
2141 if (precedence >= target)
2142 {
2143 /*
2144 Left-to-right associativity.
2145 */
2146 target=precedence;
2147 subexpression=expression;
2148 }
2149 if (strchr("(",(int) *expression) != (char *) NULL)
2150 expression=FxSubexpression(expression,exception);
2151 c=(int) (*expression++);
2152 }
2153 return(subexpression);
2154}
2155
2156static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002157 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristye85007d2010-06-06 22:51:36 +00002158 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002159{
2160 char
2161 *q,
2162 subexpression[MaxTextExtent];
2163
2164 MagickRealType
2165 alpha,
2166 gamma;
2167
2168 register const char
2169 *p;
2170
2171 *beta=0.0;
2172 if (exception->severity != UndefinedException)
2173 return(0.0);
2174 while (isspace((int) *expression) != 0)
2175 expression++;
2176 if (*expression == '\0')
2177 {
2178 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2179 "MissingExpression","`%s'",expression);
2180 return(0.0);
2181 }
cristy66322f02010-05-17 11:40:48 +00002182 *subexpression='\0';
cristy3ed852e2009-09-05 21:47:34 +00002183 p=FxOperatorPrecedence(expression,exception);
2184 if (p != (const char *) NULL)
2185 {
2186 (void) CopyMagickString(subexpression,expression,(size_t)
2187 (p-expression+1));
2188 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2189 exception);
2190 switch ((unsigned char) *p)
2191 {
2192 case '~':
2193 {
2194 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002195 *beta=(MagickRealType) (~(size_t) *beta);
cristy3ed852e2009-09-05 21:47:34 +00002196 return(*beta);
2197 }
2198 case '!':
2199 {
2200 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2201 return(*beta == 0.0 ? 1.0 : 0.0);
2202 }
2203 case '^':
2204 {
2205 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2206 channel,x,y,++p,beta,exception));
2207 return(*beta);
2208 }
2209 case '*':
cristy116af162010-08-13 01:25:47 +00002210 case ExponentialNotation:
cristy3ed852e2009-09-05 21:47:34 +00002211 {
2212 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2213 return(alpha*(*beta));
2214 }
2215 case '/':
2216 {
2217 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2218 if (*beta == 0.0)
2219 {
2220 if (exception->severity == UndefinedException)
2221 (void) ThrowMagickException(exception,GetMagickModule(),
2222 OptionError,"DivideByZero","`%s'",expression);
2223 return(0.0);
2224 }
2225 return(alpha/(*beta));
2226 }
2227 case '%':
2228 {
2229 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2230 *beta=fabs(floor(((double) *beta)+0.5));
2231 if (*beta == 0.0)
2232 {
2233 (void) ThrowMagickException(exception,GetMagickModule(),
2234 OptionError,"DivideByZero","`%s'",expression);
2235 return(0.0);
2236 }
2237 return(fmod((double) alpha,(double) *beta));
2238 }
2239 case '+':
2240 {
2241 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2242 return(alpha+(*beta));
2243 }
2244 case '-':
2245 {
2246 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2247 return(alpha-(*beta));
2248 }
2249 case LeftShiftOperator:
2250 {
2251 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002252 *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002253 (gamma+0.5));
2254 return(*beta);
2255 }
2256 case RightShiftOperator:
2257 {
2258 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002259 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002260 (gamma+0.5));
2261 return(*beta);
2262 }
2263 case '<':
2264 {
2265 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2266 return(alpha < *beta ? 1.0 : 0.0);
2267 }
2268 case LessThanEqualOperator:
2269 {
2270 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2271 return(alpha <= *beta ? 1.0 : 0.0);
2272 }
2273 case '>':
2274 {
2275 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2276 return(alpha > *beta ? 1.0 : 0.0);
2277 }
2278 case GreaterThanEqualOperator:
2279 {
2280 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2281 return(alpha >= *beta ? 1.0 : 0.0);
2282 }
2283 case EqualOperator:
2284 {
2285 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2286 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2287 }
2288 case NotEqualOperator:
2289 {
2290 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2291 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
2292 }
2293 case '&':
2294 {
2295 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002296 *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002297 (gamma+0.5));
2298 return(*beta);
2299 }
2300 case '|':
2301 {
2302 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002303 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002304 (gamma+0.5));
2305 return(*beta);
2306 }
2307 case LogicalAndOperator:
2308 {
2309 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2310 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2311 return(*beta);
2312 }
2313 case LogicalOrOperator:
2314 {
2315 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2316 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2317 return(*beta);
2318 }
2319 case '?':
2320 {
2321 MagickRealType
2322 gamma;
2323
2324 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2325 q=subexpression;
2326 p=StringToken(":",&q);
2327 if (q == (char *) NULL)
2328 {
2329 (void) ThrowMagickException(exception,GetMagickModule(),
2330 OptionError,"UnableToParseExpression","`%s'",subexpression);
2331 return(0.0);
2332 }
2333 if (fabs((double) alpha) > MagickEpsilon)
2334 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2335 else
2336 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2337 return(gamma);
2338 }
2339 case '=':
2340 {
2341 char
2342 numeric[MaxTextExtent];
2343
2344 q=subexpression;
2345 while (isalpha((int) ((unsigned char) *q)) != 0)
2346 q++;
2347 if (*q != '\0')
2348 {
2349 (void) ThrowMagickException(exception,GetMagickModule(),
2350 OptionError,"UnableToParseExpression","`%s'",subexpression);
2351 return(0.0);
2352 }
2353 ClearMagickException(exception);
2354 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristyb51dff52011-05-19 16:55:47 +00002355 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
cristy8cd5b312010-01-07 01:10:24 +00002356 *beta);
cristy3ed852e2009-09-05 21:47:34 +00002357 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2358 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2359 subexpression),ConstantString(numeric));
2360 return(*beta);
2361 }
2362 case ',':
2363 {
2364 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2365 return(alpha);
2366 }
2367 case ';':
2368 {
2369 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2370 return(*beta);
2371 }
2372 default:
2373 {
2374 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2375 exception);
2376 return(gamma);
2377 }
2378 }
2379 }
2380 if (strchr("(",(int) *expression) != (char *) NULL)
2381 {
2382 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2383 subexpression[strlen(subexpression)-1]='\0';
2384 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2385 exception);
2386 return(gamma);
2387 }
cristy8b8a3ae2010-10-23 18:49:46 +00002388 switch (*expression)
cristy3ed852e2009-09-05 21:47:34 +00002389 {
2390 case '+':
2391 {
2392 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2393 exception);
2394 return(1.0*gamma);
2395 }
2396 case '-':
2397 {
2398 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2399 exception);
2400 return(-1.0*gamma);
2401 }
2402 case '~':
2403 {
2404 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2405 exception);
cristybb503372010-05-27 20:51:26 +00002406 return((MagickRealType) (~(size_t) (gamma+0.5)));
cristy3ed852e2009-09-05 21:47:34 +00002407 }
2408 case 'A':
2409 case 'a':
2410 {
2411 if (LocaleNCompare(expression,"abs",3) == 0)
2412 {
2413 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2414 exception);
2415 return((MagickRealType) fabs((double) alpha));
2416 }
cristyb33454f2011-08-03 02:10:45 +00002417#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00002418 if (LocaleNCompare(expression,"acosh",5) == 0)
2419 {
2420 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2421 exception);
2422 return((MagickRealType) acosh((double) alpha));
2423 }
cristyb33454f2011-08-03 02:10:45 +00002424#endif
cristy3ed852e2009-09-05 21:47:34 +00002425 if (LocaleNCompare(expression,"acos",4) == 0)
2426 {
2427 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2428 exception);
2429 return((MagickRealType) acos((double) alpha));
2430 }
cristy43c22f42010-03-30 12:34:07 +00002431#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002432 if (LocaleNCompare(expression,"airy",4) == 0)
2433 {
2434 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2435 exception);
2436 if (alpha == 0.0)
cristy2dd03222010-03-30 22:12:11 +00002437 return(1.0);
2438 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
cristy43c22f42010-03-30 12:34:07 +00002439 return(gamma*gamma);
cristyee56cf12010-03-01 22:17:06 +00002440 }
cristy43c22f42010-03-30 12:34:07 +00002441#endif
cristyb33454f2011-08-03 02:10:45 +00002442#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00002443 if (LocaleNCompare(expression,"asinh",5) == 0)
2444 {
2445 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2446 exception);
2447 return((MagickRealType) asinh((double) alpha));
2448 }
cristyb33454f2011-08-03 02:10:45 +00002449#endif
cristy3ed852e2009-09-05 21:47:34 +00002450 if (LocaleNCompare(expression,"asin",4) == 0)
2451 {
2452 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2453 exception);
2454 return((MagickRealType) asin((double) alpha));
2455 }
2456 if (LocaleNCompare(expression,"alt",3) == 0)
2457 {
2458 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2459 exception);
cristybb503372010-05-27 20:51:26 +00002460 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
cristy3ed852e2009-09-05 21:47:34 +00002461 }
2462 if (LocaleNCompare(expression,"atan2",5) == 0)
2463 {
2464 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2465 exception);
2466 return((MagickRealType) atan2((double) alpha,(double) *beta));
2467 }
cristyb33454f2011-08-03 02:10:45 +00002468#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00002469 if (LocaleNCompare(expression,"atanh",5) == 0)
2470 {
2471 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2472 exception);
2473 return((MagickRealType) atanh((double) alpha));
2474 }
cristyb33454f2011-08-03 02:10:45 +00002475#endif
cristy3ed852e2009-09-05 21:47:34 +00002476 if (LocaleNCompare(expression,"atan",4) == 0)
2477 {
2478 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2479 exception);
2480 return((MagickRealType) atan((double) alpha));
2481 }
2482 if (LocaleCompare(expression,"a") == 0)
2483 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2484 break;
2485 }
2486 case 'B':
2487 case 'b':
2488 {
2489 if (LocaleCompare(expression,"b") == 0)
2490 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2491 break;
2492 }
2493 case 'C':
2494 case 'c':
2495 {
2496 if (LocaleNCompare(expression,"ceil",4) == 0)
2497 {
2498 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2499 exception);
2500 return((MagickRealType) ceil((double) alpha));
2501 }
2502 if (LocaleNCompare(expression,"cosh",4) == 0)
2503 {
2504 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2505 exception);
2506 return((MagickRealType) cosh((double) alpha));
2507 }
2508 if (LocaleNCompare(expression,"cos",3) == 0)
2509 {
2510 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2511 exception);
2512 return((MagickRealType) cos((double) alpha));
2513 }
2514 if (LocaleCompare(expression,"c") == 0)
2515 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2516 break;
2517 }
2518 case 'D':
2519 case 'd':
2520 {
2521 if (LocaleNCompare(expression,"debug",5) == 0)
2522 {
2523 const char
2524 *type;
2525
2526 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2527 exception);
2528 if (fx_info->images->colorspace == CMYKColorspace)
2529 switch (channel)
2530 {
cristy0568ffc2011-07-25 16:54:14 +00002531 case CyanPixelChannel: type="cyan"; break;
2532 case MagentaPixelChannel: type="magenta"; break;
2533 case YellowPixelChannel: type="yellow"; break;
2534 case AlphaPixelChannel: type="opacity"; break;
2535 case BlackPixelChannel: type="black"; break;
cristy3ed852e2009-09-05 21:47:34 +00002536 default: type="unknown"; break;
2537 }
2538 else
2539 switch (channel)
2540 {
cristy0568ffc2011-07-25 16:54:14 +00002541 case RedPixelChannel: type="red"; break;
2542 case GreenPixelChannel: type="green"; break;
2543 case BluePixelChannel: type="blue"; break;
2544 case AlphaPixelChannel: type="opacity"; break;
cristy3ed852e2009-09-05 21:47:34 +00002545 default: type="unknown"; break;
2546 }
2547 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2548 if (strlen(subexpression) > 1)
2549 subexpression[strlen(subexpression)-1]='\0';
2550 if (fx_info->file != (FILE *) NULL)
cristy1e604812011-05-19 18:07:50 +00002551 (void) FormatLocaleFile(fx_info->file,
2552 "%s[%.20g,%.20g].%s: %s=%.*g\n",fx_info->images->filename,
2553 (double) x,(double) y,type,subexpression,GetMagickPrecision(),
2554 (double) alpha);
cristy3ed852e2009-09-05 21:47:34 +00002555 return(0.0);
2556 }
2557 break;
2558 }
2559 case 'E':
2560 case 'e':
2561 {
2562 if (LocaleCompare(expression,"epsilon") == 0)
2563 return((MagickRealType) MagickEpsilon);
2564 if (LocaleNCompare(expression,"exp",3) == 0)
2565 {
2566 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2567 exception);
2568 return((MagickRealType) exp((double) alpha));
2569 }
2570 if (LocaleCompare(expression,"e") == 0)
2571 return((MagickRealType) 2.7182818284590452354);
2572 break;
2573 }
2574 case 'F':
2575 case 'f':
2576 {
2577 if (LocaleNCompare(expression,"floor",5) == 0)
2578 {
2579 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2580 exception);
2581 return((MagickRealType) floor((double) alpha));
2582 }
2583 break;
2584 }
2585 case 'G':
2586 case 'g':
2587 {
cristy9eeedea2011-11-02 19:04:05 +00002588 if (LocaleNCompare(expression,"gauss",5) == 0)
2589 {
2590 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2591 exception);
2592 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
2593 return((MagickRealType) gamma);
2594 }
cristy3ed852e2009-09-05 21:47:34 +00002595 if (LocaleCompare(expression,"g") == 0)
2596 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2597 break;
2598 }
2599 case 'H':
2600 case 'h':
2601 {
2602 if (LocaleCompare(expression,"h") == 0)
2603 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2604 if (LocaleCompare(expression,"hue") == 0)
2605 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2606 if (LocaleNCompare(expression,"hypot",5) == 0)
2607 {
2608 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2609 exception);
2610 return((MagickRealType) hypot((double) alpha,(double) *beta));
2611 }
2612 break;
2613 }
2614 case 'K':
2615 case 'k':
2616 {
2617 if (LocaleCompare(expression,"k") == 0)
2618 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2619 break;
2620 }
2621 case 'I':
2622 case 'i':
2623 {
2624 if (LocaleCompare(expression,"intensity") == 0)
2625 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2626 if (LocaleNCompare(expression,"int",3) == 0)
2627 {
2628 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2629 exception);
cristy16788e42010-08-13 13:44:26 +00002630 return((MagickRealType) floor(alpha));
cristy3ed852e2009-09-05 21:47:34 +00002631 }
2632 if (LocaleCompare(expression,"i") == 0)
2633 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2634 break;
2635 }
2636 case 'J':
2637 case 'j':
2638 {
2639 if (LocaleCompare(expression,"j") == 0)
2640 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
cristy161b9262010-03-20 19:34:32 +00002641#if defined(MAGICKCORE_HAVE_J0)
cristyee56cf12010-03-01 22:17:06 +00002642 if (LocaleNCompare(expression,"j0",2) == 0)
2643 {
2644 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2645 exception);
2646 return((MagickRealType) j0((double) alpha));
2647 }
cristy161b9262010-03-20 19:34:32 +00002648#endif
2649#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002650 if (LocaleNCompare(expression,"j1",2) == 0)
2651 {
2652 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2653 exception);
2654 return((MagickRealType) j1((double) alpha));
2655 }
cristy161b9262010-03-20 19:34:32 +00002656#endif
cristyaa018fa2010-04-08 23:03:54 +00002657#if defined(MAGICKCORE_HAVE_J1)
cristya6a09e72010-03-02 14:51:02 +00002658 if (LocaleNCompare(expression,"jinc",4) == 0)
2659 {
2660 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2661 exception);
cristy0946a822010-03-12 17:14:58 +00002662 if (alpha == 0.0)
2663 return(1.0);
cristy69928f92010-03-12 13:27:09 +00002664 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
cristyfce2f7b2010-03-12 00:29:49 +00002665 (MagickPI*alpha));
2666 return(gamma);
cristya6a09e72010-03-02 14:51:02 +00002667 }
cristyaa018fa2010-04-08 23:03:54 +00002668#endif
cristy3ed852e2009-09-05 21:47:34 +00002669 break;
2670 }
2671 case 'L':
2672 case 'l':
2673 {
2674 if (LocaleNCompare(expression,"ln",2) == 0)
2675 {
2676 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2677 exception);
2678 return((MagickRealType) log((double) alpha));
2679 }
cristyc8ed5322010-08-31 12:07:59 +00002680 if (LocaleNCompare(expression,"logtwo",6) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002681 {
cristyc8ed5322010-08-31 12:07:59 +00002682 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
cristy3ed852e2009-09-05 21:47:34 +00002683 exception);
2684 return((MagickRealType) log10((double) alpha))/log10(2.0);
2685 }
2686 if (LocaleNCompare(expression,"log",3) == 0)
2687 {
2688 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2689 exception);
2690 return((MagickRealType) log10((double) alpha));
2691 }
2692 if (LocaleCompare(expression,"lightness") == 0)
2693 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2694 break;
2695 }
2696 case 'M':
2697 case 'm':
2698 {
2699 if (LocaleCompare(expression,"MaxRGB") == 0)
2700 return((MagickRealType) QuantumRange);
2701 if (LocaleNCompare(expression,"maxima",6) == 0)
2702 break;
2703 if (LocaleNCompare(expression,"max",3) == 0)
2704 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2705 if (LocaleNCompare(expression,"minima",6) == 0)
2706 break;
2707 if (LocaleNCompare(expression,"min",3) == 0)
2708 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2709 if (LocaleNCompare(expression,"mod",3) == 0)
2710 {
2711 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2712 exception);
2713 return((MagickRealType) fmod((double) alpha,(double) *beta));
2714 }
2715 if (LocaleCompare(expression,"m") == 0)
2716 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2717 break;
2718 }
2719 case 'N':
2720 case 'n':
2721 {
2722 if (LocaleCompare(expression,"n") == 0)
2723 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2724 break;
2725 }
2726 case 'O':
2727 case 'o':
2728 {
2729 if (LocaleCompare(expression,"Opaque") == 0)
2730 return(1.0);
2731 if (LocaleCompare(expression,"o") == 0)
2732 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2733 break;
2734 }
2735 case 'P':
2736 case 'p':
2737 {
2738 if (LocaleCompare(expression,"pi") == 0)
2739 return((MagickRealType) MagickPI);
2740 if (LocaleNCompare(expression,"pow",3) == 0)
2741 {
2742 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2743 exception);
2744 return((MagickRealType) pow((double) alpha,(double) *beta));
2745 }
2746 if (LocaleCompare(expression,"p") == 0)
2747 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2748 break;
2749 }
2750 case 'Q':
2751 case 'q':
2752 {
2753 if (LocaleCompare(expression,"QuantumRange") == 0)
2754 return((MagickRealType) QuantumRange);
2755 if (LocaleCompare(expression,"QuantumScale") == 0)
2756 return((MagickRealType) QuantumScale);
2757 break;
2758 }
2759 case 'R':
2760 case 'r':
2761 {
2762 if (LocaleNCompare(expression,"rand",4) == 0)
2763 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2764 if (LocaleNCompare(expression,"round",5) == 0)
2765 {
2766 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2767 exception);
cristy16788e42010-08-13 13:44:26 +00002768 return((MagickRealType) floor((double) alpha+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002769 }
2770 if (LocaleCompare(expression,"r") == 0)
2771 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2772 break;
2773 }
2774 case 'S':
2775 case 's':
2776 {
2777 if (LocaleCompare(expression,"saturation") == 0)
2778 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2779 if (LocaleNCompare(expression,"sign",4) == 0)
2780 {
2781 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2782 exception);
2783 return(alpha < 0.0 ? -1.0 : 1.0);
2784 }
cristya6a09e72010-03-02 14:51:02 +00002785 if (LocaleNCompare(expression,"sinc",4) == 0)
2786 {
2787 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2788 exception);
2789 if (alpha == 0)
2790 return(1.0);
2791 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2792 (MagickPI*alpha));
2793 return(gamma);
2794 }
cristy3ed852e2009-09-05 21:47:34 +00002795 if (LocaleNCompare(expression,"sinh",4) == 0)
2796 {
2797 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2798 exception);
2799 return((MagickRealType) sinh((double) alpha));
2800 }
2801 if (LocaleNCompare(expression,"sin",3) == 0)
2802 {
2803 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2804 exception);
2805 return((MagickRealType) sin((double) alpha));
2806 }
2807 if (LocaleNCompare(expression,"sqrt",4) == 0)
2808 {
2809 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2810 exception);
2811 return((MagickRealType) sqrt((double) alpha));
2812 }
cristy9eeedea2011-11-02 19:04:05 +00002813 if (LocaleNCompare(expression,"squish",6) == 0)
2814 {
2815 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2816 exception);
2817 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2818 }
cristy3ed852e2009-09-05 21:47:34 +00002819 if (LocaleCompare(expression,"s") == 0)
2820 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2821 break;
2822 }
2823 case 'T':
2824 case 't':
2825 {
2826 if (LocaleNCompare(expression,"tanh",4) == 0)
2827 {
2828 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2829 exception);
2830 return((MagickRealType) tanh((double) alpha));
2831 }
2832 if (LocaleNCompare(expression,"tan",3) == 0)
2833 {
2834 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2835 exception);
2836 return((MagickRealType) tan((double) alpha));
2837 }
2838 if (LocaleCompare(expression,"Transparent") == 0)
2839 return(0.0);
cristy16788e42010-08-13 13:44:26 +00002840 if (LocaleNCompare(expression,"trunc",5) == 0)
2841 {
2842 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2843 exception);
2844 if (alpha >= 0.0)
2845 return((MagickRealType) floor((double) alpha));
2846 return((MagickRealType) ceil((double) alpha));
2847 }
cristy3ed852e2009-09-05 21:47:34 +00002848 if (LocaleCompare(expression,"t") == 0)
2849 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2850 break;
2851 }
2852 case 'U':
2853 case 'u':
2854 {
2855 if (LocaleCompare(expression,"u") == 0)
2856 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2857 break;
2858 }
2859 case 'V':
2860 case 'v':
2861 {
2862 if (LocaleCompare(expression,"v") == 0)
2863 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2864 break;
2865 }
2866 case 'W':
2867 case 'w':
2868 {
cristy9eeedea2011-11-02 19:04:05 +00002869 if (LocaleNCompare(expression,"while",5) == 0)
2870 {
2871 do
2872 {
2873 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2874 exception);
2875 } while (fabs((double) alpha) >= MagickEpsilon);
2876 return((MagickRealType) *beta);
2877 }
cristy3ed852e2009-09-05 21:47:34 +00002878 if (LocaleCompare(expression,"w") == 0)
2879 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2880 break;
2881 }
2882 case 'Y':
2883 case 'y':
2884 {
2885 if (LocaleCompare(expression,"y") == 0)
2886 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2887 break;
2888 }
2889 case 'Z':
2890 case 'z':
2891 {
2892 if (LocaleCompare(expression,"z") == 0)
2893 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2894 break;
2895 }
2896 default:
2897 break;
2898 }
2899 q=(char *) expression;
cristyc1acd842011-05-19 23:05:47 +00002900 alpha=InterpretLocaleValue(expression,&q);
cristy3ed852e2009-09-05 21:47:34 +00002901 if (q == expression)
2902 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2903 return(alpha);
2904}
2905
cristy7832dc22011-09-05 01:21:53 +00002906MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
cristy3ed852e2009-09-05 21:47:34 +00002907 MagickRealType *alpha,ExceptionInfo *exception)
2908{
2909 MagickBooleanType
2910 status;
2911
cristy541ae572011-08-05 19:08:59 +00002912 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2913 exception);
cristy3ed852e2009-09-05 21:47:34 +00002914 return(status);
2915}
2916
2917MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2918 MagickRealType *alpha,ExceptionInfo *exception)
2919{
2920 FILE
2921 *file;
2922
2923 MagickBooleanType
2924 status;
2925
2926 file=fx_info->file;
2927 fx_info->file=(FILE *) NULL;
cristy541ae572011-08-05 19:08:59 +00002928 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2929 exception);
cristy3ed852e2009-09-05 21:47:34 +00002930 fx_info->file=file;
2931 return(status);
2932}
2933
cristy7832dc22011-09-05 01:21:53 +00002934MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002935 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristye85007d2010-06-06 22:51:36 +00002936 MagickRealType *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002937{
2938 MagickRealType
2939 beta;
2940
2941 beta=0.0;
2942 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2943 exception);
2944 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2945}
2946
2947/*
2948%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2949% %
2950% %
2951% %
2952% F x I m a g e %
2953% %
2954% %
2955% %
2956%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2957%
2958% FxImage() applies a mathematical expression to the specified image.
2959%
2960% The format of the FxImage method is:
2961%
2962% Image *FxImage(const Image *image,const char *expression,
2963% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002964%
2965% A description of each parameter follows:
2966%
2967% o image: the image.
2968%
cristy3ed852e2009-09-05 21:47:34 +00002969% o expression: A mathematical expression.
2970%
2971% o exception: return any errors or warnings in this structure.
2972%
2973*/
2974
2975static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
2976{
cristybb503372010-05-27 20:51:26 +00002977 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002978 i;
2979
2980 assert(fx_info != (FxInfo **) NULL);
cristybb503372010-05-27 20:51:26 +00002981 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
cristy3ed852e2009-09-05 21:47:34 +00002982 if (fx_info[i] != (FxInfo *) NULL)
2983 fx_info[i]=DestroyFxInfo(fx_info[i]);
cristyb41ee102010-10-04 16:46:15 +00002984 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00002985 return(fx_info);
2986}
2987
2988static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
2989 ExceptionInfo *exception)
2990{
2991 char
2992 *fx_expression;
2993
2994 FxInfo
2995 **fx_info;
2996
2997 MagickRealType
2998 alpha;
2999
cristybb503372010-05-27 20:51:26 +00003000 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003001 i;
3002
cristybb503372010-05-27 20:51:26 +00003003 size_t
cristy3ed852e2009-09-05 21:47:34 +00003004 number_threads;
3005
3006 number_threads=GetOpenMPMaximumThreads();
cristyb41ee102010-10-04 16:46:15 +00003007 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +00003008 if (fx_info == (FxInfo **) NULL)
3009 return((FxInfo **) NULL);
3010 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
3011 if (*expression != '@')
3012 fx_expression=ConstantString(expression);
3013 else
3014 fx_expression=FileToString(expression+1,~0,exception);
cristybb503372010-05-27 20:51:26 +00003015 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +00003016 {
3017 fx_info[i]=AcquireFxInfo(image,fx_expression);
3018 if (fx_info[i] == (FxInfo *) NULL)
3019 return(DestroyFxThreadSet(fx_info));
3020 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
3021 }
3022 fx_expression=DestroyString(fx_expression);
3023 return(fx_info);
3024}
3025
3026MagickExport Image *FxImage(const Image *image,const char *expression,
3027 ExceptionInfo *exception)
3028{
cristy3ed852e2009-09-05 21:47:34 +00003029#define FxImageTag "Fx/Image"
3030
cristyfa112112010-01-04 17:48:07 +00003031 CacheView
cristy79cedc72011-07-25 00:41:15 +00003032 *fx_view,
3033 *image_view;
cristyfa112112010-01-04 17:48:07 +00003034
cristy3ed852e2009-09-05 21:47:34 +00003035 FxInfo
cristyfa112112010-01-04 17:48:07 +00003036 **restrict fx_info;
cristy3ed852e2009-09-05 21:47:34 +00003037
3038 Image
3039 *fx_image;
3040
cristy3ed852e2009-09-05 21:47:34 +00003041 MagickBooleanType
3042 status;
3043
cristybb503372010-05-27 20:51:26 +00003044 MagickOffsetType
3045 progress;
3046
cristy3ed852e2009-09-05 21:47:34 +00003047 MagickRealType
3048 alpha;
3049
cristybb503372010-05-27 20:51:26 +00003050 ssize_t
3051 y;
3052
cristy3ed852e2009-09-05 21:47:34 +00003053 assert(image != (Image *) NULL);
3054 assert(image->signature == MagickSignature);
3055 if (image->debug != MagickFalse)
3056 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy79cedc72011-07-25 00:41:15 +00003057 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00003058 if (fx_image == (Image *) NULL)
3059 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003060 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003061 {
cristy3ed852e2009-09-05 21:47:34 +00003062 fx_image=DestroyImage(fx_image);
3063 return((Image *) NULL);
3064 }
3065 fx_info=AcquireFxThreadSet(image,expression,exception);
3066 if (fx_info == (FxInfo **) NULL)
3067 {
3068 fx_image=DestroyImage(fx_image);
3069 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3070 }
3071 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3072 if (status == MagickFalse)
3073 {
3074 fx_image=DestroyImage(fx_image);
3075 fx_info=DestroyFxThreadSet(fx_info);
3076 return((Image *) NULL);
3077 }
3078 /*
3079 Fx image.
3080 */
3081 status=MagickTrue;
3082 progress=0;
cristy79cedc72011-07-25 00:41:15 +00003083 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003084 fx_view=AcquireCacheView(fx_image);
cristyb5d5f722009-11-04 03:03:49 +00003085#if defined(MAGICKCORE_OPENMP_SUPPORT)
3086 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003087#endif
cristybb503372010-05-27 20:51:26 +00003088 for (y=0; y < (ssize_t) fx_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003089 {
cristy5c9e6f22010-09-17 17:31:01 +00003090 const int
3091 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00003092
cristy79cedc72011-07-25 00:41:15 +00003093 register const Quantum
3094 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003095
cristy4c08aed2011-07-01 19:47:50 +00003096 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003097 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003098
cristy79cedc72011-07-25 00:41:15 +00003099 register ssize_t
3100 x;
3101
cristy3ed852e2009-09-05 21:47:34 +00003102 if (status == MagickFalse)
3103 continue;
cristy79cedc72011-07-25 00:41:15 +00003104 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003105 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
cristy79cedc72011-07-25 00:41:15 +00003106 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003107 {
3108 status=MagickFalse;
3109 continue;
3110 }
cristybb503372010-05-27 20:51:26 +00003111 for (x=0; x < (ssize_t) fx_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003112 {
cristy79cedc72011-07-25 00:41:15 +00003113 register ssize_t
3114 i;
3115
3116 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3117 {
3118 MagickRealType
3119 alpha;
3120
3121 PixelChannel
3122 channel;
3123
3124 PixelTrait
3125 fx_traits,
3126 traits;
3127
3128 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
cristy79cedc72011-07-25 00:41:15 +00003129 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3130 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
cristy010d7d12011-08-31 01:02:48 +00003131 if ((traits == UndefinedPixelTrait) ||
3132 (fx_traits == UndefinedPixelTrait))
cristy79cedc72011-07-25 00:41:15 +00003133 continue;
3134 if ((fx_traits & CopyPixelTrait) != 0)
3135 {
cristy0beccfa2011-09-25 20:47:53 +00003136 SetPixelChannel(fx_image,channel,p[i],q);
cristy79cedc72011-07-25 00:41:15 +00003137 continue;
3138 }
3139 alpha=0.0;
cristy0568ffc2011-07-25 16:54:14 +00003140 (void) FxEvaluateChannelExpression(fx_info[id],(PixelChannel) i,x,y,
3141 &alpha,exception);
cristyb3a73b52011-07-26 01:34:43 +00003142 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
cristy79cedc72011-07-25 00:41:15 +00003143 }
3144 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003145 q+=GetPixelChannels(fx_image);
cristy3ed852e2009-09-05 21:47:34 +00003146 }
3147 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3148 status=MagickFalse;
3149 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3150 {
3151 MagickBooleanType
3152 proceed;
3153
cristyb5d5f722009-11-04 03:03:49 +00003154#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy490408a2011-07-07 14:42:05 +00003155 #pragma omp critical (MagickCore_FxImage)
cristy3ed852e2009-09-05 21:47:34 +00003156#endif
3157 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3158 if (proceed == MagickFalse)
3159 status=MagickFalse;
3160 }
3161 }
cristy3ed852e2009-09-05 21:47:34 +00003162 fx_view=DestroyCacheView(fx_view);
cristy79cedc72011-07-25 00:41:15 +00003163 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003164 fx_info=DestroyFxThreadSet(fx_info);
3165 if (status == MagickFalse)
3166 fx_image=DestroyImage(fx_image);
3167 return(fx_image);
3168}
3169
3170/*
3171%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3172% %
3173% %
3174% %
3175% I m p l o d e I m a g e %
3176% %
3177% %
3178% %
3179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3180%
3181% ImplodeImage() creates a new image that is a copy of an existing
3182% one with the image pixels "implode" by the specified percentage. It
3183% allocates the memory necessary for the new Image structure and returns a
3184% pointer to the new image.
3185%
3186% The format of the ImplodeImage method is:
3187%
3188% Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003189% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003190%
3191% A description of each parameter follows:
3192%
3193% o implode_image: Method ImplodeImage returns a pointer to the image
3194% after it is implode. A null image is returned if there is a memory
3195% shortage.
3196%
3197% o image: the image.
3198%
3199% o amount: Define the extent of the implosion.
3200%
cristy76f512e2011-09-12 01:26:56 +00003201% o method: the pixel interpolation method.
3202%
cristy3ed852e2009-09-05 21:47:34 +00003203% o exception: return any errors or warnings in this structure.
3204%
3205*/
3206MagickExport Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003207 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003208{
3209#define ImplodeImageTag "Implode/Image"
3210
cristyfa112112010-01-04 17:48:07 +00003211 CacheView
3212 *image_view,
3213 *implode_view;
3214
cristy3ed852e2009-09-05 21:47:34 +00003215 Image
3216 *implode_image;
3217
cristy3ed852e2009-09-05 21:47:34 +00003218 MagickBooleanType
3219 status;
3220
cristybb503372010-05-27 20:51:26 +00003221 MagickOffsetType
3222 progress;
3223
cristy3ed852e2009-09-05 21:47:34 +00003224 MagickRealType
3225 radius;
3226
3227 PointInfo
3228 center,
3229 scale;
3230
cristybb503372010-05-27 20:51:26 +00003231 ssize_t
3232 y;
3233
cristy3ed852e2009-09-05 21:47:34 +00003234 /*
3235 Initialize implode image attributes.
3236 */
3237 assert(image != (Image *) NULL);
3238 assert(image->signature == MagickSignature);
3239 if (image->debug != MagickFalse)
3240 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3241 assert(exception != (ExceptionInfo *) NULL);
3242 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00003243 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3244 exception);
cristy3ed852e2009-09-05 21:47:34 +00003245 if (implode_image == (Image *) NULL)
3246 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003247 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003248 {
cristy3ed852e2009-09-05 21:47:34 +00003249 implode_image=DestroyImage(implode_image);
3250 return((Image *) NULL);
3251 }
cristy4c08aed2011-07-01 19:47:50 +00003252 if (implode_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00003253 implode_image->matte=MagickTrue;
3254 /*
3255 Compute scaling factor.
3256 */
3257 scale.x=1.0;
3258 scale.y=1.0;
3259 center.x=0.5*image->columns;
3260 center.y=0.5*image->rows;
3261 radius=center.x;
3262 if (image->columns > image->rows)
3263 scale.y=(double) image->columns/(double) image->rows;
3264 else
3265 if (image->columns < image->rows)
3266 {
3267 scale.x=(double) image->rows/(double) image->columns;
3268 radius=center.y;
3269 }
3270 /*
3271 Implode image.
3272 */
3273 status=MagickTrue;
3274 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00003275 image_view=AcquireCacheView(image);
3276 implode_view=AcquireCacheView(implode_image);
cristyb5d5f722009-11-04 03:03:49 +00003277#if defined(MAGICKCORE_OPENMP_SUPPORT)
3278 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003279#endif
cristybb503372010-05-27 20:51:26 +00003280 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003281 {
cristy3ed852e2009-09-05 21:47:34 +00003282 MagickRealType
3283 distance;
3284
3285 PointInfo
3286 delta;
3287
cristy6d188022011-09-12 13:23:33 +00003288 register const Quantum
3289 *restrict p;
3290
cristybb503372010-05-27 20:51:26 +00003291 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003292 x;
3293
cristy4c08aed2011-07-01 19:47:50 +00003294 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003295 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003296
3297 if (status == MagickFalse)
3298 continue;
cristy6d188022011-09-12 13:23:33 +00003299 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003300 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3301 exception);
cristy6d188022011-09-12 13:23:33 +00003302 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003303 {
3304 status=MagickFalse;
3305 continue;
3306 }
cristy3ed852e2009-09-05 21:47:34 +00003307 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00003308 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003309 {
cristy6d188022011-09-12 13:23:33 +00003310 register ssize_t
3311 i;
3312
cristy3ed852e2009-09-05 21:47:34 +00003313 /*
3314 Determine if the pixel is within an ellipse.
3315 */
3316 delta.x=scale.x*(double) (x-center.x);
3317 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00003318 if (distance >= (radius*radius))
3319 {
3320 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3321 q[i]=p[i];
3322 }
3323 else
cristy3ed852e2009-09-05 21:47:34 +00003324 {
3325 double
3326 factor;
3327
3328 /*
3329 Implode the pixel.
3330 */
3331 factor=1.0;
3332 if (distance > 0.0)
3333 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3334 radius/2)),-amount);
cristy76f512e2011-09-12 01:26:56 +00003335 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3336 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3337 scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00003338 }
cristy6d188022011-09-12 13:23:33 +00003339 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003340 q+=GetPixelChannels(implode_image);
cristy3ed852e2009-09-05 21:47:34 +00003341 }
3342 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3343 status=MagickFalse;
3344 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3345 {
3346 MagickBooleanType
3347 proceed;
3348
cristyb5d5f722009-11-04 03:03:49 +00003349#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003350 #pragma omp critical (MagickCore_ImplodeImage)
3351#endif
3352 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3353 if (proceed == MagickFalse)
3354 status=MagickFalse;
3355 }
3356 }
3357 implode_view=DestroyCacheView(implode_view);
3358 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003359 if (status == MagickFalse)
3360 implode_image=DestroyImage(implode_image);
3361 return(implode_image);
3362}
3363
3364/*
3365%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3366% %
3367% %
3368% %
3369% M o r p h I m a g e s %
3370% %
3371% %
3372% %
3373%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3374%
3375% The MorphImages() method requires a minimum of two images. The first
3376% image is transformed into the second by a number of intervening images
3377% as specified by frames.
3378%
3379% The format of the MorphImage method is:
3380%
cristybb503372010-05-27 20:51:26 +00003381% Image *MorphImages(const Image *image,const size_t number_frames,
cristy3ed852e2009-09-05 21:47:34 +00003382% ExceptionInfo *exception)
3383%
3384% A description of each parameter follows:
3385%
3386% o image: the image.
3387%
3388% o number_frames: Define the number of in-between image to generate.
3389% The more in-between frames, the smoother the morph.
3390%
3391% o exception: return any errors or warnings in this structure.
3392%
3393*/
3394MagickExport Image *MorphImages(const Image *image,
cristybb503372010-05-27 20:51:26 +00003395 const size_t number_frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003396{
3397#define MorphImageTag "Morph/Image"
3398
3399 Image
3400 *morph_image,
3401 *morph_images;
3402
cristy9d314ff2011-03-09 01:30:28 +00003403 MagickBooleanType
3404 status;
cristy3ed852e2009-09-05 21:47:34 +00003405
3406 MagickOffsetType
3407 scene;
3408
3409 MagickRealType
3410 alpha,
3411 beta;
3412
3413 register const Image
3414 *next;
3415
cristybb503372010-05-27 20:51:26 +00003416 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003417 i;
3418
cristy9d314ff2011-03-09 01:30:28 +00003419 ssize_t
3420 y;
cristy3ed852e2009-09-05 21:47:34 +00003421
3422 /*
3423 Clone first frame in sequence.
3424 */
3425 assert(image != (Image *) NULL);
3426 assert(image->signature == MagickSignature);
3427 if (image->debug != MagickFalse)
3428 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3429 assert(exception != (ExceptionInfo *) NULL);
3430 assert(exception->signature == MagickSignature);
3431 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3432 if (morph_images == (Image *) NULL)
3433 return((Image *) NULL);
3434 if (GetNextImageInList(image) == (Image *) NULL)
3435 {
3436 /*
3437 Morph single image.
3438 */
cristybb503372010-05-27 20:51:26 +00003439 for (i=1; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003440 {
3441 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3442 if (morph_image == (Image *) NULL)
3443 {
3444 morph_images=DestroyImageList(morph_images);
3445 return((Image *) NULL);
3446 }
3447 AppendImageToList(&morph_images,morph_image);
cristy8b27a6d2010-02-14 03:31:15 +00003448 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003449 {
cristy8b27a6d2010-02-14 03:31:15 +00003450 MagickBooleanType
3451 proceed;
3452
cristybb503372010-05-27 20:51:26 +00003453 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3454 number_frames);
cristy8b27a6d2010-02-14 03:31:15 +00003455 if (proceed == MagickFalse)
3456 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003457 }
3458 }
3459 return(GetFirstImageInList(morph_images));
3460 }
3461 /*
3462 Morph image sequence.
3463 */
3464 status=MagickTrue;
3465 scene=0;
3466 next=image;
3467 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3468 {
cristybb503372010-05-27 20:51:26 +00003469 for (i=0; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003470 {
3471 CacheView
3472 *image_view,
3473 *morph_view;
3474
3475 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3476 alpha=1.0-beta;
cristy15b98cd2010-09-12 19:42:50 +00003477 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
cristybb503372010-05-27 20:51:26 +00003478 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
cristy15b98cd2010-09-12 19:42:50 +00003479 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3480 next->filter,next->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003481 if (morph_image == (Image *) NULL)
3482 {
3483 morph_images=DestroyImageList(morph_images);
3484 return((Image *) NULL);
3485 }
cristy574cc262011-08-05 01:23:58 +00003486 if (SetImageStorageClass(morph_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003487 {
cristy3ed852e2009-09-05 21:47:34 +00003488 morph_image=DestroyImage(morph_image);
3489 return((Image *) NULL);
3490 }
3491 AppendImageToList(&morph_images,morph_image);
3492 morph_images=GetLastImageInList(morph_images);
cristy15b98cd2010-09-12 19:42:50 +00003493 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3494 morph_images->rows,GetNextImageInList(next)->filter,
3495 GetNextImageInList(next)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003496 if (morph_image == (Image *) NULL)
3497 {
3498 morph_images=DestroyImageList(morph_images);
3499 return((Image *) NULL);
3500 }
3501 image_view=AcquireCacheView(morph_image);
3502 morph_view=AcquireCacheView(morph_images);
cristyb5d5f722009-11-04 03:03:49 +00003503#if defined(MAGICKCORE_OPENMP_SUPPORT)
3504 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003505#endif
cristybb503372010-05-27 20:51:26 +00003506 for (y=0; y < (ssize_t) morph_images->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003507 {
3508 MagickBooleanType
3509 sync;
3510
cristy4c08aed2011-07-01 19:47:50 +00003511 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00003512 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003513
cristybb503372010-05-27 20:51:26 +00003514 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003515 x;
3516
cristy4c08aed2011-07-01 19:47:50 +00003517 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003518 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003519
3520 if (status == MagickFalse)
3521 continue;
3522 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3523 exception);
3524 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3525 exception);
cristy4c08aed2011-07-01 19:47:50 +00003526 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003527 {
3528 status=MagickFalse;
3529 continue;
3530 }
cristybb503372010-05-27 20:51:26 +00003531 for (x=0; x < (ssize_t) morph_images->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003532 {
cristy4c08aed2011-07-01 19:47:50 +00003533 SetPixelRed(morph_images,ClampToQuantum(alpha*
3534 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3535 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3536 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3537 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3538 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3539 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3540 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3541 if ((morph_image->colorspace == CMYKColorspace) &&
3542 (morph_images->colorspace == CMYKColorspace))
3543 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3544 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3545 q);
cristyed231572011-07-14 02:18:59 +00003546 p+=GetPixelChannels(morph_image);
3547 q+=GetPixelChannels(morph_images);
cristy3ed852e2009-09-05 21:47:34 +00003548 }
3549 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3550 if (sync == MagickFalse)
3551 status=MagickFalse;
3552 }
3553 morph_view=DestroyCacheView(morph_view);
3554 image_view=DestroyCacheView(image_view);
3555 morph_image=DestroyImage(morph_image);
3556 }
cristybb503372010-05-27 20:51:26 +00003557 if (i < (ssize_t) number_frames)
cristy3ed852e2009-09-05 21:47:34 +00003558 break;
3559 /*
3560 Clone last frame in sequence.
3561 */
3562 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3563 if (morph_image == (Image *) NULL)
3564 {
3565 morph_images=DestroyImageList(morph_images);
3566 return((Image *) NULL);
3567 }
3568 AppendImageToList(&morph_images,morph_image);
3569 morph_images=GetLastImageInList(morph_images);
3570 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3571 {
3572 MagickBooleanType
3573 proceed;
3574
cristyb5d5f722009-11-04 03:03:49 +00003575#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003576 #pragma omp critical (MagickCore_MorphImages)
3577#endif
3578 proceed=SetImageProgress(image,MorphImageTag,scene,
3579 GetImageListLength(image));
3580 if (proceed == MagickFalse)
3581 status=MagickFalse;
3582 }
3583 scene++;
3584 }
3585 if (GetNextImageInList(next) != (Image *) NULL)
3586 {
3587 morph_images=DestroyImageList(morph_images);
3588 return((Image *) NULL);
3589 }
3590 return(GetFirstImageInList(morph_images));
3591}
3592
3593/*
3594%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3595% %
3596% %
3597% %
3598% P l a s m a I m a g e %
3599% %
3600% %
3601% %
3602%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3603%
3604% PlasmaImage() initializes an image with plasma fractal values. The image
3605% must be initialized with a base color and the random number generator
3606% seeded before this method is called.
3607%
3608% The format of the PlasmaImage method is:
3609%
3610% MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
cristy5cbc0162011-08-29 00:36:28 +00003611% size_t attenuate,size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003612%
3613% A description of each parameter follows:
3614%
3615% o image: the image.
3616%
3617% o segment: Define the region to apply plasma fractals values.
3618%
glennrp7dae1ca2010-09-16 12:17:35 +00003619% o attenuate: Define the plasma attenuation factor.
cristy3ed852e2009-09-05 21:47:34 +00003620%
3621% o depth: Limit the plasma recursion depth.
3622%
cristy5cbc0162011-08-29 00:36:28 +00003623% o exception: return any errors or warnings in this structure.
3624%
cristy3ed852e2009-09-05 21:47:34 +00003625*/
3626
3627static inline Quantum PlasmaPixel(RandomInfo *random_info,
3628 const MagickRealType pixel,const MagickRealType noise)
3629{
3630 Quantum
3631 plasma;
3632
cristyce70c172010-01-07 17:15:30 +00003633 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
cristy3ed852e2009-09-05 21:47:34 +00003634 noise/2.0);
3635 return(plasma);
3636}
3637
cristyda1f9c12011-10-02 21:39:49 +00003638static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3639 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3640 const SegmentInfo *segment,size_t attenuate,size_t depth,
3641 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003642{
cristy3ed852e2009-09-05 21:47:34 +00003643 MagickRealType
3644 plasma;
3645
cristyda1f9c12011-10-02 21:39:49 +00003646 PixelChannel
3647 channel;
3648
3649 PixelTrait
3650 traits;
3651
3652 register const Quantum
3653 *restrict u,
3654 *restrict v;
3655
3656 register Quantum
3657 *restrict q;
3658
3659 register ssize_t
3660 i;
cristy3ed852e2009-09-05 21:47:34 +00003661
cristy9d314ff2011-03-09 01:30:28 +00003662 ssize_t
3663 x,
3664 x_mid,
3665 y,
3666 y_mid;
3667
cristy3ed852e2009-09-05 21:47:34 +00003668 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3669 return(MagickTrue);
3670 if (depth != 0)
3671 {
3672 SegmentInfo
3673 local_info;
3674
3675 /*
3676 Divide the area into quadrants and recurse.
3677 */
3678 depth--;
3679 attenuate++;
cristybb503372010-05-27 20:51:26 +00003680 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3681 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003682 local_info=(*segment);
3683 local_info.x2=(double) x_mid;
3684 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003685 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3686 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003687 local_info=(*segment);
3688 local_info.y1=(double) y_mid;
3689 local_info.x2=(double) x_mid;
cristyda1f9c12011-10-02 21:39:49 +00003690 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3691 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003692 local_info=(*segment);
3693 local_info.x1=(double) x_mid;
3694 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003695 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3696 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003697 local_info=(*segment);
3698 local_info.x1=(double) x_mid;
3699 local_info.y1=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003700 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3701 &local_info,attenuate,depth,exception));
cristy3ed852e2009-09-05 21:47:34 +00003702 }
cristybb503372010-05-27 20:51:26 +00003703 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3704 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003705 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3706 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3707 return(MagickFalse);
3708 /*
3709 Average pixels and apply plasma.
3710 */
cristy3ed852e2009-09-05 21:47:34 +00003711 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3712 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3713 {
cristy3ed852e2009-09-05 21:47:34 +00003714 /*
3715 Left pixel.
3716 */
cristybb503372010-05-27 20:51:26 +00003717 x=(ssize_t) ceil(segment->x1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003718 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3719 1,1,exception);
3720 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3721 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003722 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003723 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3724 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003725 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003726 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3727 {
3728 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3729 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3730 if (traits == UndefinedPixelTrait)
3731 continue;
3732 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3733 }
cristyc5c6f662010-09-22 14:23:02 +00003734 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003735 if (segment->x1 != segment->x2)
3736 {
3737 /*
3738 Right pixel.
3739 */
cristybb503372010-05-27 20:51:26 +00003740 x=(ssize_t) ceil(segment->x2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003741 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3742 1,1,exception);
3743 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3744 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003745 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003746 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3747 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003748 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003749 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3750 {
3751 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3752 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3753 if (traits == UndefinedPixelTrait)
3754 continue;
3755 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3756 }
cristyc5c6f662010-09-22 14:23:02 +00003757 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003758 }
3759 }
3760 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3761 {
3762 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3763 {
cristy3ed852e2009-09-05 21:47:34 +00003764 /*
3765 Bottom pixel.
3766 */
cristybb503372010-05-27 20:51:26 +00003767 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003768 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3769 1,1,exception);
3770 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3771 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003772 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003773 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3774 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003775 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003776 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3777 {
3778 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3779 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3780 if (traits == UndefinedPixelTrait)
3781 continue;
3782 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3783 }
cristyc5c6f662010-09-22 14:23:02 +00003784 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003785 }
3786 if (segment->y1 != segment->y2)
3787 {
cristy3ed852e2009-09-05 21:47:34 +00003788 /*
3789 Top pixel.
3790 */
cristybb503372010-05-27 20:51:26 +00003791 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003792 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3793 1,1,exception);
3794 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3795 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003796 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003797 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3798 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003799 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003800 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3801 {
3802 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3803 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3804 if (traits == UndefinedPixelTrait)
3805 continue;
3806 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3807 }
cristyc5c6f662010-09-22 14:23:02 +00003808 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003809 }
3810 }
3811 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3812 {
cristy3ed852e2009-09-05 21:47:34 +00003813 /*
3814 Middle pixel.
3815 */
cristybb503372010-05-27 20:51:26 +00003816 x=(ssize_t) ceil(segment->x1-0.5);
3817 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003818 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
cristybb503372010-05-27 20:51:26 +00003819 x=(ssize_t) ceil(segment->x2-0.5);
3820 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003821 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003822 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,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 {
3828 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3829 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3830 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 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3837 return(MagickTrue);
3838 return(MagickFalse);
3839}
cristyda1f9c12011-10-02 21:39:49 +00003840
cristy3ed852e2009-09-05 21:47:34 +00003841MagickExport MagickBooleanType PlasmaImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00003842 const SegmentInfo *segment,size_t attenuate,size_t depth,
3843 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003844{
cristyc5c6f662010-09-22 14:23:02 +00003845 CacheView
cristyda1f9c12011-10-02 21:39:49 +00003846 *image_view,
3847 *u_view,
3848 *v_view;
cristyc5c6f662010-09-22 14:23:02 +00003849
cristy3ed852e2009-09-05 21:47:34 +00003850 MagickBooleanType
3851 status;
3852
3853 RandomInfo
3854 *random_info;
3855
3856 if (image->debug != MagickFalse)
3857 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3858 assert(image != (Image *) NULL);
3859 assert(image->signature == MagickSignature);
3860 if (image->debug != MagickFalse)
3861 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy5cbc0162011-08-29 00:36:28 +00003862 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristyc5c6f662010-09-22 14:23:02 +00003863 return(MagickFalse);
3864 image_view=AcquireCacheView(image);
cristyda1f9c12011-10-02 21:39:49 +00003865 u_view=AcquireCacheView(image);
3866 v_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003867 random_info=AcquireRandomInfo();
cristyda1f9c12011-10-02 21:39:49 +00003868 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3869 attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003870 random_info=DestroyRandomInfo(random_info);
cristyda1f9c12011-10-02 21:39:49 +00003871 v_view=DestroyCacheView(v_view);
3872 u_view=DestroyCacheView(u_view);
cristyc5c6f662010-09-22 14:23:02 +00003873 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003874 return(status);
3875}
3876
3877/*
3878%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3879% %
3880% %
3881% %
3882% P o l a r o i d I m a g e %
3883% %
3884% %
3885% %
3886%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3887%
3888% PolaroidImage() simulates a Polaroid picture.
3889%
3890% The format of the AnnotateImage method is:
3891%
3892% Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003893% const double angle,const PixelInterpolateMethod method,
3894% ExceptionInfo exception)
cristy3ed852e2009-09-05 21:47:34 +00003895%
3896% A description of each parameter follows:
3897%
3898% o image: the image.
3899%
3900% o draw_info: the draw info.
3901%
cristycee97112010-05-28 00:44:52 +00003902% o angle: Apply the effect along this angle.
cristy3ed852e2009-09-05 21:47:34 +00003903%
cristy5c4e2582011-09-11 19:21:03 +00003904% o method: the pixel interpolation method.
3905%
cristy3ed852e2009-09-05 21:47:34 +00003906% o exception: return any errors or warnings in this structure.
3907%
3908*/
3909MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003910 const double angle,const PixelInterpolateMethod method,
3911 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003912{
3913 const char
3914 *value;
3915
cristy3ed852e2009-09-05 21:47:34 +00003916 Image
3917 *bend_image,
3918 *caption_image,
3919 *flop_image,
3920 *picture_image,
3921 *polaroid_image,
3922 *rotate_image,
3923 *trim_image;
3924
cristybb503372010-05-27 20:51:26 +00003925 size_t
cristy3ed852e2009-09-05 21:47:34 +00003926 height;
3927
cristy9d314ff2011-03-09 01:30:28 +00003928 ssize_t
3929 quantum;
3930
cristy3ed852e2009-09-05 21:47:34 +00003931 /*
3932 Simulate a Polaroid picture.
3933 */
3934 assert(image != (Image *) NULL);
3935 assert(image->signature == MagickSignature);
3936 if (image->debug != MagickFalse)
3937 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3938 assert(exception != (ExceptionInfo *) NULL);
3939 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00003940 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
cristy3ed852e2009-09-05 21:47:34 +00003941 image->rows)/25.0,10.0);
3942 height=image->rows+2*quantum;
3943 caption_image=(Image *) NULL;
cristyd15e6592011-10-15 00:13:06 +00003944 value=GetImageProperty(image,"caption",exception);
cristy3ed852e2009-09-05 21:47:34 +00003945 if (value != (const char *) NULL)
3946 {
3947 char
3948 *caption,
3949 geometry[MaxTextExtent];
3950
3951 DrawInfo
3952 *annotate_info;
3953
cristy3ed852e2009-09-05 21:47:34 +00003954 MagickBooleanType
3955 status;
3956
cristy9d314ff2011-03-09 01:30:28 +00003957 ssize_t
3958 count;
3959
cristy3ed852e2009-09-05 21:47:34 +00003960 TypeMetric
3961 metrics;
3962
3963 /*
3964 Generate caption image.
3965 */
3966 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3967 if (caption_image == (Image *) NULL)
3968 return((Image *) NULL);
3969 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3970 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
cristy018f07f2011-09-04 21:15:19 +00003971 value,exception);
cristy3ed852e2009-09-05 21:47:34 +00003972 (void) CloneString(&annotate_info->text,caption);
cristy6b1d05e2010-09-22 19:17:27 +00003973 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
cristy5cbc0162011-08-29 00:36:28 +00003974 &caption,exception);
cristybb503372010-05-27 20:51:26 +00003975 status=SetImageExtent(caption_image,image->columns,(size_t)
cristy63240882011-08-05 19:05:27 +00003976 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00003977 if (status == MagickFalse)
3978 caption_image=DestroyImage(caption_image);
3979 else
3980 {
3981 caption_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00003982 (void) SetImageBackgroundColor(caption_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00003983 (void) CloneString(&annotate_info->text,caption);
cristyb51dff52011-05-19 16:55:47 +00003984 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
cristy3ed852e2009-09-05 21:47:34 +00003985 metrics.ascent);
3986 if (annotate_info->gravity == UndefinedGravity)
3987 (void) CloneString(&annotate_info->geometry,AcquireString(
3988 geometry));
cristy5cbc0162011-08-29 00:36:28 +00003989 (void) AnnotateImage(caption_image,annotate_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00003990 height+=caption_image->rows;
3991 }
3992 annotate_info=DestroyDrawInfo(annotate_info);
3993 caption=DestroyString(caption);
3994 }
3995 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
3996 exception);
3997 if (picture_image == (Image *) NULL)
3998 {
3999 if (caption_image != (Image *) NULL)
4000 caption_image=DestroyImage(caption_image);
4001 return((Image *) NULL);
4002 }
4003 picture_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004004 (void) SetImageBackgroundColor(picture_image,exception);
cristye941a752011-10-15 01:52:48 +00004005 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum,
4006 exception);
cristy3ed852e2009-09-05 21:47:34 +00004007 if (caption_image != (Image *) NULL)
4008 {
4009 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
cristye941a752011-10-15 01:52:48 +00004010 quantum,(ssize_t) (image->rows+3*quantum/2),exception);
cristy3ed852e2009-09-05 21:47:34 +00004011 caption_image=DestroyImage(caption_image);
4012 }
cristy9950d572011-10-01 18:22:35 +00004013 (void) QueryColorCompliance("none",AllCompliance,
4014 &picture_image->background_color,exception);
cristy63240882011-08-05 19:05:27 +00004015 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004016 rotate_image=RotateImage(picture_image,90.0,exception);
4017 picture_image=DestroyImage(picture_image);
4018 if (rotate_image == (Image *) NULL)
4019 return((Image *) NULL);
4020 picture_image=rotate_image;
4021 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
cristy5c4e2582011-09-11 19:21:03 +00004022 picture_image->columns,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00004023 picture_image=DestroyImage(picture_image);
4024 if (bend_image == (Image *) NULL)
4025 return((Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00004026 picture_image=bend_image;
4027 rotate_image=RotateImage(picture_image,-90.0,exception);
4028 picture_image=DestroyImage(picture_image);
4029 if (rotate_image == (Image *) NULL)
4030 return((Image *) NULL);
4031 picture_image=rotate_image;
4032 picture_image->background_color=image->background_color;
4033 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
4034 exception);
4035 if (polaroid_image == (Image *) NULL)
4036 {
4037 picture_image=DestroyImage(picture_image);
4038 return(picture_image);
4039 }
4040 flop_image=FlopImage(polaroid_image,exception);
4041 polaroid_image=DestroyImage(polaroid_image);
4042 if (flop_image == (Image *) NULL)
4043 {
4044 picture_image=DestroyImage(picture_image);
4045 return(picture_image);
4046 }
4047 polaroid_image=flop_image;
4048 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
cristye941a752011-10-15 01:52:48 +00004049 (ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
cristy3ed852e2009-09-05 21:47:34 +00004050 picture_image=DestroyImage(picture_image);
cristy9950d572011-10-01 18:22:35 +00004051 (void) QueryColorCompliance("none",AllCompliance,
4052 &polaroid_image->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00004053 rotate_image=RotateImage(polaroid_image,angle,exception);
4054 polaroid_image=DestroyImage(polaroid_image);
4055 if (rotate_image == (Image *) NULL)
4056 return((Image *) NULL);
4057 polaroid_image=rotate_image;
4058 trim_image=TrimImage(polaroid_image,exception);
4059 polaroid_image=DestroyImage(polaroid_image);
4060 if (trim_image == (Image *) NULL)
4061 return((Image *) NULL);
4062 polaroid_image=trim_image;
4063 return(polaroid_image);
4064}
4065
4066/*
4067%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4068% %
4069% %
4070% %
cristy3ed852e2009-09-05 21:47:34 +00004071% S e p i a T o n e I m a g e %
4072% %
4073% %
4074% %
4075%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4076%
4077% MagickSepiaToneImage() applies a special effect to the image, similar to the
4078% effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4079% 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4080% threshold of 80% is a good starting point for a reasonable tone.
4081%
4082% The format of the SepiaToneImage method is:
4083%
4084% Image *SepiaToneImage(const Image *image,const double threshold,
4085% ExceptionInfo *exception)
4086%
4087% A description of each parameter follows:
4088%
4089% o image: the image.
4090%
4091% o threshold: the tone threshold.
4092%
4093% o exception: return any errors or warnings in this structure.
4094%
4095*/
4096MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4097 ExceptionInfo *exception)
4098{
4099#define SepiaToneImageTag "SepiaTone/Image"
4100
cristyc4c8d132010-01-07 01:58:38 +00004101 CacheView
4102 *image_view,
4103 *sepia_view;
4104
cristy3ed852e2009-09-05 21:47:34 +00004105 Image
4106 *sepia_image;
4107
cristy3ed852e2009-09-05 21:47:34 +00004108 MagickBooleanType
4109 status;
4110
cristybb503372010-05-27 20:51:26 +00004111 MagickOffsetType
4112 progress;
4113
4114 ssize_t
4115 y;
4116
cristy3ed852e2009-09-05 21:47:34 +00004117 /*
4118 Initialize sepia-toned image attributes.
4119 */
4120 assert(image != (const Image *) NULL);
4121 assert(image->signature == MagickSignature);
4122 if (image->debug != MagickFalse)
4123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4124 assert(exception != (ExceptionInfo *) NULL);
4125 assert(exception->signature == MagickSignature);
4126 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4127 if (sepia_image == (Image *) NULL)
4128 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004129 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004130 {
cristy3ed852e2009-09-05 21:47:34 +00004131 sepia_image=DestroyImage(sepia_image);
4132 return((Image *) NULL);
4133 }
4134 /*
4135 Tone each row of the image.
4136 */
4137 status=MagickTrue;
4138 progress=0;
4139 image_view=AcquireCacheView(image);
4140 sepia_view=AcquireCacheView(sepia_image);
cristyb5d5f722009-11-04 03:03:49 +00004141#if defined(MAGICKCORE_OPENMP_SUPPORT)
4142 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004143#endif
cristybb503372010-05-27 20:51:26 +00004144 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004145 {
cristy4c08aed2011-07-01 19:47:50 +00004146 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004147 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00004148
cristybb503372010-05-27 20:51:26 +00004149 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004150 x;
4151
cristy4c08aed2011-07-01 19:47:50 +00004152 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004153 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004154
4155 if (status == MagickFalse)
4156 continue;
4157 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4158 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4159 exception);
cristy4c08aed2011-07-01 19:47:50 +00004160 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004161 {
4162 status=MagickFalse;
4163 continue;
4164 }
cristybb503372010-05-27 20:51:26 +00004165 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004166 {
4167 MagickRealType
4168 intensity,
4169 tone;
4170
cristy4c08aed2011-07-01 19:47:50 +00004171 intensity=(MagickRealType) GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00004172 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4173 (MagickRealType) QuantumRange-threshold;
cristy4c08aed2011-07-01 19:47:50 +00004174 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004175 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4176 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004177 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004178 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004179 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004180 tone=threshold/7.0;
cristy4c08aed2011-07-01 19:47:50 +00004181 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4182 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4183 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4184 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristyed231572011-07-14 02:18:59 +00004185 p+=GetPixelChannels(image);
4186 q+=GetPixelChannels(sepia_image);
cristy3ed852e2009-09-05 21:47:34 +00004187 }
4188 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4189 status=MagickFalse;
4190 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4191 {
4192 MagickBooleanType
4193 proceed;
4194
cristyb5d5f722009-11-04 03:03:49 +00004195#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004196 #pragma omp critical (MagickCore_SepiaToneImage)
4197#endif
4198 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4199 image->rows);
4200 if (proceed == MagickFalse)
4201 status=MagickFalse;
4202 }
4203 }
4204 sepia_view=DestroyCacheView(sepia_view);
4205 image_view=DestroyCacheView(image_view);
cristye23ec9d2011-08-16 18:15:40 +00004206 (void) NormalizeImage(sepia_image,exception);
4207 (void) ContrastImage(sepia_image,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004208 if (status == MagickFalse)
4209 sepia_image=DestroyImage(sepia_image);
4210 return(sepia_image);
4211}
4212
4213/*
4214%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4215% %
4216% %
4217% %
4218% S h a d o w I m a g e %
4219% %
4220% %
4221% %
4222%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4223%
4224% ShadowImage() simulates a shadow from the specified image and returns it.
4225%
4226% The format of the ShadowImage method is:
4227%
4228% Image *ShadowImage(const Image *image,const double opacity,
cristybb503372010-05-27 20:51:26 +00004229% const double sigma,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004230% ExceptionInfo *exception)
4231%
4232% A description of each parameter follows:
4233%
4234% o image: the image.
4235%
4236% o opacity: percentage transparency.
4237%
4238% o sigma: the standard deviation of the Gaussian, in pixels.
4239%
4240% o x_offset: the shadow x-offset.
4241%
4242% o y_offset: the shadow y-offset.
4243%
4244% o exception: return any errors or warnings in this structure.
4245%
4246*/
4247MagickExport Image *ShadowImage(const Image *image,const double opacity,
cristybb503372010-05-27 20:51:26 +00004248 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004249 ExceptionInfo *exception)
4250{
4251#define ShadowImageTag "Shadow/Image"
4252
cristybd5a96c2011-08-21 00:04:26 +00004253 ChannelType
4254 channel_mask;
4255
cristy3ed852e2009-09-05 21:47:34 +00004256 Image
4257 *border_image,
4258 *clone_image,
4259 *shadow_image;
4260
cristy3ed852e2009-09-05 21:47:34 +00004261 RectangleInfo
4262 border_info;
4263
cristy3ed852e2009-09-05 21:47:34 +00004264 assert(image != (Image *) NULL);
4265 assert(image->signature == MagickSignature);
4266 if (image->debug != MagickFalse)
4267 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4268 assert(exception != (ExceptionInfo *) NULL);
4269 assert(exception->signature == MagickSignature);
4270 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4271 if (clone_image == (Image *) NULL)
4272 return((Image *) NULL);
4273 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4274 clone_image->compose=OverCompositeOp;
cristybb503372010-05-27 20:51:26 +00004275 border_info.width=(size_t) floor(2.0*sigma+0.5);
4276 border_info.height=(size_t) floor(2.0*sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00004277 border_info.x=0;
4278 border_info.y=0;
cristy9950d572011-10-01 18:22:35 +00004279 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4280 exception);
cristy633f0c62011-09-15 13:27:36 +00004281 border_image=BorderImage(clone_image,&border_info,image->compose,exception);
cristy3ed852e2009-09-05 21:47:34 +00004282 clone_image=DestroyImage(clone_image);
4283 if (border_image == (Image *) NULL)
4284 return((Image *) NULL);
4285 if (border_image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00004286 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004287 /*
4288 Shadow image.
4289 */
cristyea1a8aa2011-10-20 13:24:06 +00004290 (void) SetImageBackgroundColor(border_image,exception);
cristybd5a96c2011-08-21 00:04:26 +00004291 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
cristy05c0c9a2011-09-05 23:16:13 +00004292 shadow_image=BlurImage(border_image,0.0,sigma,image->bias,exception);
cristybd5a96c2011-08-21 00:04:26 +00004293 (void) SetPixelChannelMap(border_image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00004294 border_image=DestroyImage(border_image);
4295 if (shadow_image == (Image *) NULL)
4296 return((Image *) NULL);
4297 if (shadow_image->page.width == 0)
4298 shadow_image->page.width=shadow_image->columns;
4299 if (shadow_image->page.height == 0)
4300 shadow_image->page.height=shadow_image->rows;
cristybb503372010-05-27 20:51:26 +00004301 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4302 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4303 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4304 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
cristy3ed852e2009-09-05 21:47:34 +00004305 return(shadow_image);
4306}
4307
4308/*
4309%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4310% %
4311% %
4312% %
4313% S k e t c h I m a g e %
4314% %
4315% %
4316% %
4317%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4318%
4319% SketchImage() simulates a pencil sketch. We convolve the image with a
4320% Gaussian operator of the given radius and standard deviation (sigma). For
4321% reasonable results, radius should be larger than sigma. Use a radius of 0
4322% and SketchImage() selects a suitable radius for you. Angle gives the angle
4323% of the sketch.
4324%
4325% The format of the SketchImage method is:
4326%
4327% Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004328% const double sigma,const double angle,const double bias,
4329% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004330%
4331% A description of each parameter follows:
4332%
4333% o image: the image.
4334%
cristy574cc262011-08-05 01:23:58 +00004335% o radius: the radius of the Gaussian, in pixels, not counting the
4336% center pixel.
cristy3ed852e2009-09-05 21:47:34 +00004337%
4338% o sigma: the standard deviation of the Gaussian, in pixels.
4339%
cristyf7ef0252011-09-09 14:50:06 +00004340% o angle: apply the effect along this angle.
4341%
4342% o bias: the bias.
cristy3ed852e2009-09-05 21:47:34 +00004343%
4344% o exception: return any errors or warnings in this structure.
4345%
4346*/
4347MagickExport Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004348 const double sigma,const double angle,const double bias,
4349 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004350{
cristyfa112112010-01-04 17:48:07 +00004351 CacheView
4352 *random_view;
4353
cristy3ed852e2009-09-05 21:47:34 +00004354 Image
4355 *blend_image,
4356 *blur_image,
4357 *dodge_image,
4358 *random_image,
4359 *sketch_image;
4360
cristy3ed852e2009-09-05 21:47:34 +00004361 MagickBooleanType
4362 status;
4363
cristy3ed852e2009-09-05 21:47:34 +00004364 RandomInfo
cristyfa112112010-01-04 17:48:07 +00004365 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +00004366
cristy9d314ff2011-03-09 01:30:28 +00004367 ssize_t
4368 y;
4369
cristy3ed852e2009-09-05 21:47:34 +00004370 /*
4371 Sketch image.
4372 */
4373 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4374 MagickTrue,exception);
4375 if (random_image == (Image *) NULL)
4376 return((Image *) NULL);
4377 status=MagickTrue;
cristy1b784432009-12-19 02:20:40 +00004378 random_info=AcquireRandomInfoThreadSet();
cristy3ed852e2009-09-05 21:47:34 +00004379 random_view=AcquireCacheView(random_image);
cristy1b784432009-12-19 02:20:40 +00004380#if defined(MAGICKCORE_OPENMP_SUPPORT)
4381 #pragma omp parallel for schedule(dynamic,4) shared(status)
4382#endif
cristybb503372010-05-27 20:51:26 +00004383 for (y=0; y < (ssize_t) random_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004384 {
cristy5c9e6f22010-09-17 17:31:01 +00004385 const int
4386 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00004387
cristybb503372010-05-27 20:51:26 +00004388 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004389 x;
4390
cristy4c08aed2011-07-01 19:47:50 +00004391 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004392 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004393
cristy1b784432009-12-19 02:20:40 +00004394 if (status == MagickFalse)
4395 continue;
cristy3ed852e2009-09-05 21:47:34 +00004396 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4397 exception);
cristyacd2ed22011-08-30 01:44:23 +00004398 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004399 {
4400 status=MagickFalse;
4401 continue;
4402 }
cristybb503372010-05-27 20:51:26 +00004403 for (x=0; x < (ssize_t) random_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004404 {
cristy76f512e2011-09-12 01:26:56 +00004405 MagickRealType
4406 value;
4407
4408 register ssize_t
4409 i;
4410
4411 value=GetPseudoRandomValue(random_info[id]);
4412 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4413 {
4414 PixelTrait
4415 traits;
4416
4417 traits=GetPixelChannelMapTraits(random_image,(PixelChannel) i);
4418 if (traits == UndefinedPixelTrait)
4419 continue;
4420 q[i]=ClampToQuantum(QuantumRange*value);
4421 }
cristyed231572011-07-14 02:18:59 +00004422 q+=GetPixelChannels(random_image);
cristy3ed852e2009-09-05 21:47:34 +00004423 }
4424 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4425 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004426 }
4427 random_view=DestroyCacheView(random_view);
cristy1b784432009-12-19 02:20:40 +00004428 random_info=DestroyRandomInfoThreadSet(random_info);
cristy3ed852e2009-09-05 21:47:34 +00004429 if (status == MagickFalse)
4430 {
4431 random_image=DestroyImage(random_image);
4432 return(random_image);
4433 }
cristyf7ef0252011-09-09 14:50:06 +00004434 blur_image=MotionBlurImage(random_image,radius,sigma,angle,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00004435 random_image=DestroyImage(random_image);
4436 if (blur_image == (Image *) NULL)
4437 return((Image *) NULL);
cristy8ae632d2011-09-05 17:29:53 +00004438 dodge_image=EdgeImage(blur_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00004439 blur_image=DestroyImage(blur_image);
4440 if (dodge_image == (Image *) NULL)
4441 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +00004442 (void) NormalizeImage(dodge_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +00004443 (void) NegateImage(dodge_image,MagickFalse,exception);
cristye941a752011-10-15 01:52:48 +00004444 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
cristy3ed852e2009-09-05 21:47:34 +00004445 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4446 if (sketch_image == (Image *) NULL)
4447 {
4448 dodge_image=DestroyImage(dodge_image);
4449 return((Image *) NULL);
4450 }
cristye941a752011-10-15 01:52:48 +00004451 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0,
4452 exception);
cristy3ed852e2009-09-05 21:47:34 +00004453 dodge_image=DestroyImage(dodge_image);
4454 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4455 if (blend_image == (Image *) NULL)
4456 {
4457 sketch_image=DestroyImage(sketch_image);
4458 return((Image *) NULL);
4459 }
4460 (void) SetImageArtifact(blend_image,"compose:args","20x80");
cristye941a752011-10-15 01:52:48 +00004461 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0,
4462 exception);
cristy3ed852e2009-09-05 21:47:34 +00004463 blend_image=DestroyImage(blend_image);
4464 return(sketch_image);
4465}
4466
4467/*
4468%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4469% %
4470% %
4471% %
4472% S o l a r i z e I m a g e %
4473% %
4474% %
4475% %
4476%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4477%
4478% SolarizeImage() applies a special effect to the image, similar to the effect
4479% achieved in a photo darkroom by selectively exposing areas of photo
4480% sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4481% measure of the extent of the solarization.
4482%
4483% The format of the SolarizeImage method is:
4484%
cristy5cbc0162011-08-29 00:36:28 +00004485% MagickBooleanType SolarizeImage(Image *image,const double threshold,
4486% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004487%
4488% A description of each parameter follows:
4489%
4490% o image: the image.
4491%
4492% o threshold: Define the extent of the solarization.
4493%
cristy5cbc0162011-08-29 00:36:28 +00004494% o exception: return any errors or warnings in this structure.
4495%
cristy3ed852e2009-09-05 21:47:34 +00004496*/
4497MagickExport MagickBooleanType SolarizeImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00004498 const double threshold,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004499{
4500#define SolarizeImageTag "Solarize/Image"
4501
cristyc4c8d132010-01-07 01:58:38 +00004502 CacheView
4503 *image_view;
4504
cristy3ed852e2009-09-05 21:47:34 +00004505 MagickBooleanType
4506 status;
4507
cristybb503372010-05-27 20:51:26 +00004508 MagickOffsetType
4509 progress;
4510
4511 ssize_t
4512 y;
4513
cristy3ed852e2009-09-05 21:47:34 +00004514 assert(image != (Image *) NULL);
4515 assert(image->signature == MagickSignature);
4516 if (image->debug != MagickFalse)
4517 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4518 if (image->storage_class == PseudoClass)
4519 {
cristybb503372010-05-27 20:51:26 +00004520 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004521 i;
4522
4523 /*
4524 Solarize colormap.
4525 */
cristybb503372010-05-27 20:51:26 +00004526 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00004527 {
4528 if ((MagickRealType) image->colormap[i].red > threshold)
4529 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4530 if ((MagickRealType) image->colormap[i].green > threshold)
4531 image->colormap[i].green=(Quantum) QuantumRange-
4532 image->colormap[i].green;
4533 if ((MagickRealType) image->colormap[i].blue > threshold)
4534 image->colormap[i].blue=(Quantum) QuantumRange-
4535 image->colormap[i].blue;
4536 }
4537 }
4538 /*
4539 Solarize image.
4540 */
4541 status=MagickTrue;
4542 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00004543 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00004544#if defined(MAGICKCORE_OPENMP_SUPPORT)
4545 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004546#endif
cristybb503372010-05-27 20:51:26 +00004547 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004548 {
cristybb503372010-05-27 20:51:26 +00004549 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004550 x;
4551
cristy4c08aed2011-07-01 19:47:50 +00004552 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004553 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004554
4555 if (status == MagickFalse)
4556 continue;
cristy5cbc0162011-08-29 00:36:28 +00004557 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004558 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004559 {
4560 status=MagickFalse;
4561 continue;
4562 }
cristybb503372010-05-27 20:51:26 +00004563 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004564 {
cristy76f512e2011-09-12 01:26:56 +00004565 register ssize_t
4566 i;
4567
4568 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4569 {
4570 PixelTrait
4571 traits;
4572
4573 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
4574 if ((traits == UndefinedPixelTrait) ||
4575 ((traits & CopyPixelTrait) != 0))
4576 continue;
4577 if ((MagickRealType) q[i] > threshold)
4578 q[i]=QuantumRange-q[i];
4579 }
cristyed231572011-07-14 02:18:59 +00004580 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004581 }
4582 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4583 status=MagickFalse;
4584 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4585 {
4586 MagickBooleanType
4587 proceed;
4588
cristyb5d5f722009-11-04 03:03:49 +00004589#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004590 #pragma omp critical (MagickCore_SolarizeImage)
4591#endif
4592 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4593 if (proceed == MagickFalse)
4594 status=MagickFalse;
4595 }
4596 }
4597 image_view=DestroyCacheView(image_view);
4598 return(status);
4599}
4600
4601/*
4602%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4603% %
4604% %
4605% %
4606% S t e g a n o I m a g e %
4607% %
4608% %
4609% %
4610%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4611%
4612% SteganoImage() hides a digital watermark within the image. Recover
4613% the hidden watermark later to prove that the authenticity of an image.
4614% Offset defines the start position within the image to hide the watermark.
4615%
4616% The format of the SteganoImage method is:
4617%
4618% Image *SteganoImage(const Image *image,Image *watermark,
4619% ExceptionInfo *exception)
4620%
4621% A description of each parameter follows:
4622%
4623% o image: the image.
4624%
4625% o watermark: the watermark image.
4626%
4627% o exception: return any errors or warnings in this structure.
4628%
4629*/
4630MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4631 ExceptionInfo *exception)
4632{
cristye1bf8ad2010-09-19 17:07:03 +00004633#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
cristy4c08aed2011-07-01 19:47:50 +00004634#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
cristyeaedf062010-05-29 22:36:02 +00004635 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
cristy3ed852e2009-09-05 21:47:34 +00004636#define SteganoImageTag "Stegano/Image"
4637
cristyb0d3bb92010-09-22 14:37:58 +00004638 CacheView
4639 *stegano_view,
4640 *watermark_view;
4641
cristy3ed852e2009-09-05 21:47:34 +00004642 Image
4643 *stegano_image;
4644
4645 int
4646 c;
4647
cristy3ed852e2009-09-05 21:47:34 +00004648 MagickBooleanType
4649 status;
4650
cristy101ab702011-10-13 13:06:32 +00004651 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00004652 pixel;
4653
cristy4c08aed2011-07-01 19:47:50 +00004654 register Quantum
cristy3ed852e2009-09-05 21:47:34 +00004655 *q;
4656
cristye1bf8ad2010-09-19 17:07:03 +00004657 register ssize_t
4658 x;
4659
cristybb503372010-05-27 20:51:26 +00004660 size_t
cristyeaedf062010-05-29 22:36:02 +00004661 depth,
4662 one;
cristy3ed852e2009-09-05 21:47:34 +00004663
cristye1bf8ad2010-09-19 17:07:03 +00004664 ssize_t
4665 i,
4666 j,
4667 k,
4668 y;
4669
cristy3ed852e2009-09-05 21:47:34 +00004670 /*
4671 Initialize steganographic image attributes.
4672 */
4673 assert(image != (const Image *) NULL);
4674 assert(image->signature == MagickSignature);
4675 if (image->debug != MagickFalse)
4676 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4677 assert(watermark != (const Image *) NULL);
4678 assert(watermark->signature == MagickSignature);
4679 assert(exception != (ExceptionInfo *) NULL);
4680 assert(exception->signature == MagickSignature);
cristyeaedf062010-05-29 22:36:02 +00004681 one=1UL;
cristy3ed852e2009-09-05 21:47:34 +00004682 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4683 if (stegano_image == (Image *) NULL)
4684 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004685 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004686 {
cristy3ed852e2009-09-05 21:47:34 +00004687 stegano_image=DestroyImage(stegano_image);
4688 return((Image *) NULL);
4689 }
4690 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4691 /*
4692 Hide watermark in low-order bits of image.
4693 */
4694 c=0;
4695 i=0;
4696 j=0;
4697 depth=stegano_image->depth;
4698 k=image->offset;
cristyda16f162011-02-19 23:52:17 +00004699 status=MagickTrue;
cristyb0d3bb92010-09-22 14:37:58 +00004700 watermark_view=AcquireCacheView(watermark);
4701 stegano_view=AcquireCacheView(stegano_image);
cristybb503372010-05-27 20:51:26 +00004702 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
cristy3ed852e2009-09-05 21:47:34 +00004703 {
cristybb503372010-05-27 20:51:26 +00004704 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
cristy3ed852e2009-09-05 21:47:34 +00004705 {
cristybb503372010-05-27 20:51:26 +00004706 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
cristy3ed852e2009-09-05 21:47:34 +00004707 {
cristyda1f9c12011-10-02 21:39:49 +00004708 Quantum
cristy5f95f4f2011-10-23 01:01:01 +00004709 virtual_pixel[CompositePixelChannel];
cristyda1f9c12011-10-02 21:39:49 +00004710
4711 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,virtual_pixel,
4712 exception);
4713 pixel.red=(double) virtual_pixel[RedPixelChannel];
4714 pixel.green=(double) virtual_pixel[GreenPixelChannel];
4715 pixel.blue=(double) virtual_pixel[BluePixelChannel];
4716 pixel.alpha=(double) virtual_pixel[AlphaPixelChannel];
cristybb503372010-05-27 20:51:26 +00004717 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
cristy3ed852e2009-09-05 21:47:34 +00004718 break;
cristyb0d3bb92010-09-22 14:37:58 +00004719 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4720 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4721 exception);
cristyacd2ed22011-08-30 01:44:23 +00004722 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004723 break;
4724 switch (c)
4725 {
4726 case 0:
4727 {
cristy4c08aed2011-07-01 19:47:50 +00004728 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004729 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004730 break;
4731 }
4732 case 1:
4733 {
cristy4c08aed2011-07-01 19:47:50 +00004734 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004735 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004736 break;
4737 }
4738 case 2:
4739 {
cristy4c08aed2011-07-01 19:47:50 +00004740 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004741 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004742 break;
4743 }
4744 }
cristyb0d3bb92010-09-22 14:37:58 +00004745 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004746 break;
4747 c++;
4748 if (c == 3)
4749 c=0;
4750 k++;
cristybb503372010-05-27 20:51:26 +00004751 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
cristy3ed852e2009-09-05 21:47:34 +00004752 k=0;
4753 if (k == image->offset)
4754 j++;
4755 }
4756 }
cristy8b27a6d2010-02-14 03:31:15 +00004757 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004758 {
cristy8b27a6d2010-02-14 03:31:15 +00004759 MagickBooleanType
4760 proceed;
4761
4762 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4763 (depth-i),depth);
4764 if (proceed == MagickFalse)
4765 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004766 }
4767 }
cristyb0d3bb92010-09-22 14:37:58 +00004768 stegano_view=DestroyCacheView(stegano_view);
4769 watermark_view=DestroyCacheView(watermark_view);
cristy3ed852e2009-09-05 21:47:34 +00004770 if (stegano_image->storage_class == PseudoClass)
cristyea1a8aa2011-10-20 13:24:06 +00004771 (void) SyncImage(stegano_image,exception);
cristyda16f162011-02-19 23:52:17 +00004772 if (status == MagickFalse)
4773 {
4774 stegano_image=DestroyImage(stegano_image);
4775 return((Image *) NULL);
4776 }
cristy3ed852e2009-09-05 21:47:34 +00004777 return(stegano_image);
4778}
4779
4780/*
4781%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4782% %
4783% %
4784% %
4785% S t e r e o A n a g l y p h I m a g e %
4786% %
4787% %
4788% %
4789%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4790%
4791% StereoAnaglyphImage() combines two images and produces a single image that
4792% is the composite of a left and right image of a stereo pair. Special
4793% red-green stereo glasses are required to view this effect.
4794%
4795% The format of the StereoAnaglyphImage method is:
4796%
4797% Image *StereoImage(const Image *left_image,const Image *right_image,
4798% ExceptionInfo *exception)
4799% Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004800% const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004801% ExceptionInfo *exception)
4802%
4803% A description of each parameter follows:
4804%
4805% o left_image: the left image.
4806%
4807% o right_image: the right image.
4808%
4809% o exception: return any errors or warnings in this structure.
4810%
4811% o x_offset: amount, in pixels, by which the left image is offset to the
4812% right of the right image.
4813%
4814% o y_offset: amount, in pixels, by which the left image is offset to the
4815% bottom of the right image.
4816%
4817%
4818*/
4819MagickExport Image *StereoImage(const Image *left_image,
4820 const Image *right_image,ExceptionInfo *exception)
4821{
4822 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4823}
4824
4825MagickExport Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004826 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004827 ExceptionInfo *exception)
4828{
4829#define StereoImageTag "Stereo/Image"
4830
4831 const Image
4832 *image;
4833
4834 Image
4835 *stereo_image;
4836
cristy3ed852e2009-09-05 21:47:34 +00004837 MagickBooleanType
4838 status;
4839
cristy9d314ff2011-03-09 01:30:28 +00004840 ssize_t
4841 y;
4842
cristy3ed852e2009-09-05 21:47:34 +00004843 assert(left_image != (const Image *) NULL);
4844 assert(left_image->signature == MagickSignature);
4845 if (left_image->debug != MagickFalse)
4846 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4847 left_image->filename);
4848 assert(right_image != (const Image *) NULL);
4849 assert(right_image->signature == MagickSignature);
4850 assert(exception != (ExceptionInfo *) NULL);
4851 assert(exception->signature == MagickSignature);
4852 assert(right_image != (const Image *) NULL);
4853 image=left_image;
4854 if ((left_image->columns != right_image->columns) ||
4855 (left_image->rows != right_image->rows))
4856 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4857 /*
4858 Initialize stereo image attributes.
4859 */
4860 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4861 MagickTrue,exception);
4862 if (stereo_image == (Image *) NULL)
4863 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004864 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004865 {
cristy3ed852e2009-09-05 21:47:34 +00004866 stereo_image=DestroyImage(stereo_image);
4867 return((Image *) NULL);
4868 }
4869 /*
4870 Copy left image to red channel and right image to blue channel.
4871 */
cristyda16f162011-02-19 23:52:17 +00004872 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00004873 for (y=0; y < (ssize_t) stereo_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004874 {
cristy4c08aed2011-07-01 19:47:50 +00004875 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004876 *restrict p,
4877 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004878
cristybb503372010-05-27 20:51:26 +00004879 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004880 x;
4881
cristy4c08aed2011-07-01 19:47:50 +00004882 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004883 *restrict r;
cristy3ed852e2009-09-05 21:47:34 +00004884
4885 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4886 exception);
4887 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4888 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
cristy76f512e2011-09-12 01:26:56 +00004889 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4890 (r == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004891 break;
cristybb503372010-05-27 20:51:26 +00004892 for (x=0; x < (ssize_t) stereo_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004893 {
cristy4c08aed2011-07-01 19:47:50 +00004894 SetPixelRed(image,GetPixelRed(left_image,p),r);
cristy76f512e2011-09-12 01:26:56 +00004895 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4896 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4897 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4898 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4899 GetPixelAlpha(right_image,q))/2,r);
cristyed231572011-07-14 02:18:59 +00004900 p+=GetPixelChannels(left_image);
cristy76f512e2011-09-12 01:26:56 +00004901 q+=GetPixelChannels(right_image);
4902 r+=GetPixelChannels(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004903 }
4904 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4905 break;
cristy8b27a6d2010-02-14 03:31:15 +00004906 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004907 {
cristy8b27a6d2010-02-14 03:31:15 +00004908 MagickBooleanType
4909 proceed;
4910
cristybb503372010-05-27 20:51:26 +00004911 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4912 stereo_image->rows);
cristy8b27a6d2010-02-14 03:31:15 +00004913 if (proceed == MagickFalse)
4914 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004915 }
4916 }
cristyda16f162011-02-19 23:52:17 +00004917 if (status == MagickFalse)
4918 {
4919 stereo_image=DestroyImage(stereo_image);
4920 return((Image *) NULL);
4921 }
cristy3ed852e2009-09-05 21:47:34 +00004922 return(stereo_image);
4923}
4924
4925/*
4926%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4927% %
4928% %
4929% %
4930% S w i r l I m a g e %
4931% %
4932% %
4933% %
4934%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4935%
4936% SwirlImage() swirls the pixels about the center of the image, where
4937% degrees indicates the sweep of the arc through which each pixel is moved.
4938% You get a more dramatic effect as the degrees move from 1 to 360.
4939%
4940% The format of the SwirlImage method is:
4941%
4942% Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004943% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004944%
4945% A description of each parameter follows:
4946%
4947% o image: the image.
4948%
4949% o degrees: Define the tightness of the swirling effect.
4950%
cristy76f512e2011-09-12 01:26:56 +00004951% o method: the pixel interpolation method.
4952%
cristy3ed852e2009-09-05 21:47:34 +00004953% o exception: return any errors or warnings in this structure.
4954%
4955*/
4956MagickExport Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004957 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004958{
4959#define SwirlImageTag "Swirl/Image"
4960
cristyfa112112010-01-04 17:48:07 +00004961 CacheView
4962 *image_view,
4963 *swirl_view;
4964
cristy3ed852e2009-09-05 21:47:34 +00004965 Image
4966 *swirl_image;
4967
cristy3ed852e2009-09-05 21:47:34 +00004968 MagickBooleanType
4969 status;
4970
cristybb503372010-05-27 20:51:26 +00004971 MagickOffsetType
4972 progress;
4973
cristy3ed852e2009-09-05 21:47:34 +00004974 MagickRealType
4975 radius;
4976
4977 PointInfo
4978 center,
4979 scale;
4980
cristybb503372010-05-27 20:51:26 +00004981 ssize_t
4982 y;
4983
cristy3ed852e2009-09-05 21:47:34 +00004984 /*
4985 Initialize swirl image attributes.
4986 */
4987 assert(image != (const Image *) NULL);
4988 assert(image->signature == MagickSignature);
4989 if (image->debug != MagickFalse)
4990 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4991 assert(exception != (ExceptionInfo *) NULL);
4992 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00004993 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004994 if (swirl_image == (Image *) NULL)
4995 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004996 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004997 {
cristy3ed852e2009-09-05 21:47:34 +00004998 swirl_image=DestroyImage(swirl_image);
4999 return((Image *) NULL);
5000 }
cristy4c08aed2011-07-01 19:47:50 +00005001 if (swirl_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00005002 swirl_image->matte=MagickTrue;
5003 /*
5004 Compute scaling factor.
5005 */
5006 center.x=(double) image->columns/2.0;
5007 center.y=(double) image->rows/2.0;
5008 radius=MagickMax(center.x,center.y);
5009 scale.x=1.0;
5010 scale.y=1.0;
5011 if (image->columns > image->rows)
5012 scale.y=(double) image->columns/(double) image->rows;
5013 else
5014 if (image->columns < image->rows)
5015 scale.x=(double) image->rows/(double) image->columns;
5016 degrees=(double) DegreesToRadians(degrees);
5017 /*
5018 Swirl image.
5019 */
5020 status=MagickTrue;
5021 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00005022 image_view=AcquireCacheView(image);
5023 swirl_view=AcquireCacheView(swirl_image);
cristyb5d5f722009-11-04 03:03:49 +00005024#if defined(MAGICKCORE_OPENMP_SUPPORT)
5025 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005026#endif
cristybb503372010-05-27 20:51:26 +00005027 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005028 {
cristy3ed852e2009-09-05 21:47:34 +00005029 MagickRealType
5030 distance;
5031
5032 PointInfo
5033 delta;
5034
cristy6d188022011-09-12 13:23:33 +00005035 register const Quantum
5036 *restrict p;
5037
cristybb503372010-05-27 20:51:26 +00005038 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005039 x;
5040
cristy4c08aed2011-07-01 19:47:50 +00005041 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005042 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005043
5044 if (status == MagickFalse)
5045 continue;
cristy6d188022011-09-12 13:23:33 +00005046 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00005047 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5048 exception);
cristy6d188022011-09-12 13:23:33 +00005049 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005050 {
5051 status=MagickFalse;
5052 continue;
5053 }
cristy3ed852e2009-09-05 21:47:34 +00005054 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00005055 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005056 {
cristy6d188022011-09-12 13:23:33 +00005057 register ssize_t
5058 i;
5059
cristy3ed852e2009-09-05 21:47:34 +00005060 /*
5061 Determine if the pixel is within an ellipse.
5062 */
5063 delta.x=scale.x*(double) (x-center.x);
5064 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00005065 if (distance >= (radius*radius))
5066 {
5067 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5068 q[i]=p[i];
5069 }
5070 else
cristy3ed852e2009-09-05 21:47:34 +00005071 {
5072 MagickRealType
5073 cosine,
5074 factor,
5075 sine;
5076
5077 /*
5078 Swirl the pixel.
5079 */
5080 factor=1.0-sqrt((double) distance)/radius;
5081 sine=sin((double) (degrees*factor*factor));
5082 cosine=cos((double) (degrees*factor*factor));
cristy76f512e2011-09-12 01:26:56 +00005083 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5084 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5085 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00005086 }
cristy6d188022011-09-12 13:23:33 +00005087 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00005088 q+=GetPixelChannels(swirl_image);
cristy3ed852e2009-09-05 21:47:34 +00005089 }
5090 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5091 status=MagickFalse;
5092 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5093 {
5094 MagickBooleanType
5095 proceed;
5096
cristyb5d5f722009-11-04 03:03:49 +00005097#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005098 #pragma omp critical (MagickCore_SwirlImage)
5099#endif
5100 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5101 if (proceed == MagickFalse)
5102 status=MagickFalse;
5103 }
5104 }
5105 swirl_view=DestroyCacheView(swirl_view);
5106 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005107 if (status == MagickFalse)
5108 swirl_image=DestroyImage(swirl_image);
5109 return(swirl_image);
5110}
5111
5112/*
5113%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5114% %
5115% %
5116% %
5117% T i n t I m a g e %
5118% %
5119% %
5120% %
5121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5122%
5123% TintImage() applies a color vector to each pixel in the image. The length
5124% of the vector is 0 for black and white and at its maximum for the midtones.
5125% The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5126%
5127% The format of the TintImage method is:
5128%
cristyb817c3f2011-10-03 14:00:35 +00005129% Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005130% const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005131%
5132% A description of each parameter follows:
5133%
5134% o image: the image.
5135%
cristyb817c3f2011-10-03 14:00:35 +00005136% o blend: A color value used for tinting.
cristy3ed852e2009-09-05 21:47:34 +00005137%
5138% o tint: A color value used for tinting.
5139%
5140% o exception: return any errors or warnings in this structure.
5141%
5142*/
cristyb817c3f2011-10-03 14:00:35 +00005143MagickExport Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005144 const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005145{
5146#define TintImageTag "Tint/Image"
5147
cristyc4c8d132010-01-07 01:58:38 +00005148 CacheView
5149 *image_view,
5150 *tint_view;
5151
cristy3ed852e2009-09-05 21:47:34 +00005152 GeometryInfo
5153 geometry_info;
5154
5155 Image
5156 *tint_image;
5157
cristy3ed852e2009-09-05 21:47:34 +00005158 MagickBooleanType
5159 status;
5160
cristybb503372010-05-27 20:51:26 +00005161 MagickOffsetType
5162 progress;
cristy3ed852e2009-09-05 21:47:34 +00005163
cristy28474bf2011-09-11 23:32:52 +00005164 MagickRealType
5165 intensity;
5166
cristy4c08aed2011-07-01 19:47:50 +00005167 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005168 color_vector,
5169 pixel;
5170
cristybb503372010-05-27 20:51:26 +00005171 MagickStatusType
5172 flags;
5173
5174 ssize_t
5175 y;
5176
cristy3ed852e2009-09-05 21:47:34 +00005177 /*
5178 Allocate tint image.
5179 */
5180 assert(image != (const Image *) NULL);
5181 assert(image->signature == MagickSignature);
5182 if (image->debug != MagickFalse)
5183 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5184 assert(exception != (ExceptionInfo *) NULL);
5185 assert(exception->signature == MagickSignature);
5186 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5187 if (tint_image == (Image *) NULL)
5188 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005189 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005190 {
cristy3ed852e2009-09-05 21:47:34 +00005191 tint_image=DestroyImage(tint_image);
5192 return((Image *) NULL);
5193 }
cristyaed9c382011-10-03 17:54:21 +00005194 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005195 return(tint_image);
5196 /*
5197 Determine RGB values of the color.
5198 */
cristy28474bf2011-09-11 23:32:52 +00005199 GetPixelInfo(image,&pixel);
cristyb817c3f2011-10-03 14:00:35 +00005200 flags=ParseGeometry(blend,&geometry_info);
cristy3ed852e2009-09-05 21:47:34 +00005201 pixel.red=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005202 pixel.green=geometry_info.rho;
5203 pixel.blue=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005204 pixel.alpha=OpaqueAlpha;
cristy3ed852e2009-09-05 21:47:34 +00005205 if ((flags & SigmaValue) != 0)
5206 pixel.green=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00005207 if ((flags & XiValue) != 0)
5208 pixel.blue=geometry_info.xi;
cristyb817c3f2011-10-03 14:00:35 +00005209 if ((flags & PsiValue) != 0)
5210 pixel.alpha=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005211 if (image->colorspace == CMYKColorspace)
5212 {
cristyb817c3f2011-10-03 14:00:35 +00005213 pixel.black=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005214 if ((flags & PsiValue) != 0)
5215 pixel.black=geometry_info.psi;
5216 if ((flags & ChiValue) != 0)
5217 pixel.alpha=geometry_info.chi;
5218 }
cristy28474bf2011-09-11 23:32:52 +00005219 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5220 color_vector.red=(MagickRealType) (pixel.red*tint->red/100.0-intensity);
5221 color_vector.green=(MagickRealType) (pixel.green*tint->green/100.0-intensity);
5222 color_vector.blue=(MagickRealType) (pixel.blue*tint->blue/100.0-intensity);
5223 color_vector.black=(MagickRealType) (pixel.black*tint->black/100.0-intensity);
5224 color_vector.alpha=(MagickRealType) (pixel.alpha*tint->alpha/100.0-intensity);
cristy3ed852e2009-09-05 21:47:34 +00005225 /*
5226 Tint image.
5227 */
5228 status=MagickTrue;
5229 progress=0;
5230 image_view=AcquireCacheView(image);
5231 tint_view=AcquireCacheView(tint_image);
cristyb5d5f722009-11-04 03:03:49 +00005232#if defined(MAGICKCORE_OPENMP_SUPPORT)
5233 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005234#endif
cristybb503372010-05-27 20:51:26 +00005235 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005236 {
cristy4c08aed2011-07-01 19:47:50 +00005237 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00005238 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00005239
cristy4c08aed2011-07-01 19:47:50 +00005240 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005241 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005242
cristy6b91acb2011-04-19 12:23:54 +00005243 register ssize_t
5244 x;
5245
cristy3ed852e2009-09-05 21:47:34 +00005246 if (status == MagickFalse)
5247 continue;
5248 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5249 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5250 exception);
cristy4c08aed2011-07-01 19:47:50 +00005251 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005252 {
5253 status=MagickFalse;
5254 continue;
5255 }
cristybb503372010-05-27 20:51:26 +00005256 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005257 {
cristy4c08aed2011-07-01 19:47:50 +00005258 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005259 pixel;
5260
5261 MagickRealType
5262 weight;
5263
cristy76f512e2011-09-12 01:26:56 +00005264 if ((GetPixelRedTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005265 {
5266 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5267 pixel.red=(MagickRealType) GetPixelRed(image,p)+
5268 color_vector.red*(1.0-(4.0*(weight*weight)));
5269 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5270 }
cristy76f512e2011-09-12 01:26:56 +00005271 if ((GetPixelGreenTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005272 {
5273 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5274 pixel.green=(MagickRealType) GetPixelGreen(image,p)+
5275 color_vector.green*(1.0-(4.0*(weight*weight)));
5276 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5277 }
cristy76f512e2011-09-12 01:26:56 +00005278 if ((GetPixelBlueTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005279 {
5280 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5281 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+
5282 color_vector.blue*(1.0-(4.0*(weight*weight)));
5283 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5284 }
cristy76f512e2011-09-12 01:26:56 +00005285 if ((GetPixelBlackTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005286 {
5287 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5288 pixel.black=(MagickRealType) GetPixelBlack(image,p)+
5289 color_vector.black*(1.0-(4.0*(weight*weight)));
5290 SetPixelBlack(tint_image,ClampToQuantum(pixel.black),q);
5291 }
cristy76f512e2011-09-12 01:26:56 +00005292 if ((GetPixelAlphaTraits(tint_image) & CopyPixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005293 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
cristyed231572011-07-14 02:18:59 +00005294 p+=GetPixelChannels(image);
5295 q+=GetPixelChannels(tint_image);
cristy3ed852e2009-09-05 21:47:34 +00005296 }
5297 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5298 status=MagickFalse;
5299 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5300 {
5301 MagickBooleanType
5302 proceed;
5303
cristyb5d5f722009-11-04 03:03:49 +00005304#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005305 #pragma omp critical (MagickCore_TintImage)
5306#endif
5307 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5308 if (proceed == MagickFalse)
5309 status=MagickFalse;
5310 }
5311 }
5312 tint_view=DestroyCacheView(tint_view);
5313 image_view=DestroyCacheView(image_view);
5314 if (status == MagickFalse)
5315 tint_image=DestroyImage(tint_image);
5316 return(tint_image);
5317}
5318
5319/*
5320%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5321% %
5322% %
5323% %
5324% V i g n e t t e I m a g e %
5325% %
5326% %
5327% %
5328%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5329%
5330% VignetteImage() softens the edges of the image in vignette style.
5331%
5332% The format of the VignetteImage method is:
5333%
5334% Image *VignetteImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +00005335% const double sigma,const ssize_t x,const ssize_t y,
5336% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005337%
5338% A description of each parameter follows:
5339%
5340% o image: the image.
5341%
5342% o radius: the radius of the pixel neighborhood.
5343%
5344% o sigma: the standard deviation of the Gaussian, in pixels.
5345%
5346% o x, y: Define the x and y ellipse offset.
5347%
5348% o exception: return any errors or warnings in this structure.
5349%
5350*/
5351MagickExport Image *VignetteImage(const Image *image,const double radius,
cristybb503372010-05-27 20:51:26 +00005352 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005353{
5354 char
5355 ellipse[MaxTextExtent];
5356
5357 DrawInfo
5358 *draw_info;
5359
5360 Image
5361 *canvas_image,
5362 *blur_image,
5363 *oval_image,
5364 *vignette_image;
5365
5366 assert(image != (Image *) NULL);
5367 assert(image->signature == MagickSignature);
5368 if (image->debug != MagickFalse)
5369 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5370 assert(exception != (ExceptionInfo *) NULL);
5371 assert(exception->signature == MagickSignature);
5372 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5373 if (canvas_image == (Image *) NULL)
5374 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005375 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005376 {
cristy3ed852e2009-09-05 21:47:34 +00005377 canvas_image=DestroyImage(canvas_image);
5378 return((Image *) NULL);
5379 }
5380 canvas_image->matte=MagickTrue;
cristyb3a73b52011-07-26 01:34:43 +00005381 oval_image=CloneImage(canvas_image,canvas_image->columns,
5382 canvas_image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005383 if (oval_image == (Image *) NULL)
5384 {
5385 canvas_image=DestroyImage(canvas_image);
5386 return((Image *) NULL);
5387 }
cristy9950d572011-10-01 18:22:35 +00005388 (void) QueryColorCompliance("#000000",AllCompliance,
5389 &oval_image->background_color,exception);
cristyea1a8aa2011-10-20 13:24:06 +00005390 (void) SetImageBackgroundColor(oval_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00005391 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00005392 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5393 exception);
5394 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5395 exception);
cristyb51dff52011-05-19 16:55:47 +00005396 (void) FormatLocaleString(ellipse,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00005397 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
cristy8cd5b312010-01-07 01:10:24 +00005398 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
cristy3ed852e2009-09-05 21:47:34 +00005399 draw_info->primitive=AcquireString(ellipse);
cristy018f07f2011-09-04 21:15:19 +00005400 (void) DrawImage(oval_image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00005401 draw_info=DestroyDrawInfo(draw_info);
cristy05c0c9a2011-09-05 23:16:13 +00005402 blur_image=BlurImage(oval_image,radius,sigma,image->bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00005403 oval_image=DestroyImage(oval_image);
5404 if (blur_image == (Image *) NULL)
5405 {
5406 canvas_image=DestroyImage(canvas_image);
5407 return((Image *) NULL);
5408 }
5409 blur_image->matte=MagickFalse;
cristye941a752011-10-15 01:52:48 +00005410 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0,
5411 exception);
cristy3ed852e2009-09-05 21:47:34 +00005412 blur_image=DestroyImage(blur_image);
5413 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5414 canvas_image=DestroyImage(canvas_image);
5415 return(vignette_image);
5416}
5417
5418/*
5419%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5420% %
5421% %
5422% %
5423% W a v e I m a g e %
5424% %
5425% %
5426% %
5427%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5428%
5429% WaveImage() creates a "ripple" effect in the image by shifting the pixels
cristycee97112010-05-28 00:44:52 +00005430% vertically along a sine wave whose amplitude and wavelength is specified
cristy3ed852e2009-09-05 21:47:34 +00005431% by the given parameters.
5432%
5433% The format of the WaveImage method is:
5434%
5435% Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005436% const double wave_length,const PixelInterpolateMethod method,
5437% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005438%
5439% A description of each parameter follows:
5440%
5441% o image: the image.
5442%
5443% o amplitude, wave_length: Define the amplitude and wave length of the
5444% sine wave.
5445%
cristy5c4e2582011-09-11 19:21:03 +00005446% o interpolate: the pixel interpolation method.
5447%
cristy3ed852e2009-09-05 21:47:34 +00005448% o exception: return any errors or warnings in this structure.
5449%
5450*/
5451MagickExport Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005452 const double wave_length,const PixelInterpolateMethod method,
5453 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005454{
5455#define WaveImageTag "Wave/Image"
5456
cristyfa112112010-01-04 17:48:07 +00005457 CacheView
cristyd76c51e2011-03-26 00:21:26 +00005458 *image_view,
cristyfa112112010-01-04 17:48:07 +00005459 *wave_view;
5460
cristy3ed852e2009-09-05 21:47:34 +00005461 Image
5462 *wave_image;
5463
cristy3ed852e2009-09-05 21:47:34 +00005464 MagickBooleanType
5465 status;
5466
cristybb503372010-05-27 20:51:26 +00005467 MagickOffsetType
5468 progress;
5469
cristy3ed852e2009-09-05 21:47:34 +00005470 MagickRealType
5471 *sine_map;
5472
cristybb503372010-05-27 20:51:26 +00005473 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005474 i;
5475
cristybb503372010-05-27 20:51:26 +00005476 ssize_t
5477 y;
5478
cristy3ed852e2009-09-05 21:47:34 +00005479 /*
5480 Initialize wave image attributes.
5481 */
5482 assert(image != (Image *) NULL);
5483 assert(image->signature == MagickSignature);
5484 if (image->debug != MagickFalse)
5485 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5486 assert(exception != (ExceptionInfo *) NULL);
5487 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00005488 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
cristy3ed852e2009-09-05 21:47:34 +00005489 fabs(amplitude)),MagickTrue,exception);
5490 if (wave_image == (Image *) NULL)
5491 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005492 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005493 {
cristy3ed852e2009-09-05 21:47:34 +00005494 wave_image=DestroyImage(wave_image);
5495 return((Image *) NULL);
5496 }
cristy4c08aed2011-07-01 19:47:50 +00005497 if (wave_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00005498 wave_image->matte=MagickTrue;
5499 /*
5500 Allocate sine map.
5501 */
5502 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5503 sizeof(*sine_map));
5504 if (sine_map == (MagickRealType *) NULL)
5505 {
5506 wave_image=DestroyImage(wave_image);
5507 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5508 }
cristybb503372010-05-27 20:51:26 +00005509 for (i=0; i < (ssize_t) wave_image->columns; i++)
cristy4205a3c2010-09-12 20:19:59 +00005510 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5511 wave_length));
cristy3ed852e2009-09-05 21:47:34 +00005512 /*
5513 Wave image.
5514 */
5515 status=MagickTrue;
5516 progress=0;
cristyd76c51e2011-03-26 00:21:26 +00005517 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00005518 wave_view=AcquireCacheView(wave_image);
cristyd76c51e2011-03-26 00:21:26 +00005519 (void) SetCacheViewVirtualPixelMethod(image_view,
5520 BackgroundVirtualPixelMethod);
cristyb5d5f722009-11-04 03:03:49 +00005521#if defined(MAGICKCORE_OPENMP_SUPPORT)
5522 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005523#endif
cristybb503372010-05-27 20:51:26 +00005524 for (y=0; y < (ssize_t) wave_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005525 {
cristy4c08aed2011-07-01 19:47:50 +00005526 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005527 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005528
cristye97bb922011-04-03 01:36:52 +00005529 register ssize_t
5530 x;
5531
cristy3ed852e2009-09-05 21:47:34 +00005532 if (status == MagickFalse)
5533 continue;
5534 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5535 exception);
cristyacd2ed22011-08-30 01:44:23 +00005536 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005537 {
5538 status=MagickFalse;
5539 continue;
5540 }
cristybb503372010-05-27 20:51:26 +00005541 for (x=0; x < (ssize_t) wave_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005542 {
cristy5c4e2582011-09-11 19:21:03 +00005543 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5544 (double) x,(double) (y-sine_map[x]),q,exception);
cristyed231572011-07-14 02:18:59 +00005545 q+=GetPixelChannels(wave_image);
cristy3ed852e2009-09-05 21:47:34 +00005546 }
5547 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5548 status=MagickFalse;
5549 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5550 {
5551 MagickBooleanType
5552 proceed;
5553
cristyb5d5f722009-11-04 03:03:49 +00005554#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005555 #pragma omp critical (MagickCore_WaveImage)
5556#endif
5557 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5558 if (proceed == MagickFalse)
5559 status=MagickFalse;
5560 }
5561 }
5562 wave_view=DestroyCacheView(wave_view);
cristyd76c51e2011-03-26 00:21:26 +00005563 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005564 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5565 if (status == MagickFalse)
5566 wave_image=DestroyImage(wave_image);
5567 return(wave_image);
5568}