blob: 12311a818420a39750d3892202994ce7a380dc7a [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*");
cristydee18fa2011-11-03 11:29:17 +0000197 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
198 (strstr(fx_info->expression,"e-") != (char *) NULL))
199 {
200 /*
201 Convert scientific notation.
202 */
203 (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^");
213 (void) SubstituteString(&fx_info->expression,"0e-1.0*","0**10^-");
214 (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^-");
223 }
224 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^");
240 (void) SubstituteString(&fx_info->expression,"0E-1.0*","0**10^-");
241 (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
cristyb0aad4c2011-11-02 19:30:35 +00001306static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
1307{
1308 if (beta != 0)
1309 return(FxGCD(beta,alpha % beta));
1310 return(alpha);
1311}
1312
cristy0568ffc2011-07-25 16:54:14 +00001313static inline MagickRealType FxMax(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001314 const ssize_t x,const ssize_t y,const char *expression,
1315 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001316{
1317 MagickRealType
1318 alpha,
1319 beta;
1320
1321 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1322 return((MagickRealType) MagickMax((double) alpha,(double) beta));
1323}
1324
cristy0568ffc2011-07-25 16:54:14 +00001325static inline MagickRealType FxMin(FxInfo *fx_info,PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001326 const ssize_t x,const ssize_t y,const char *expression,
1327 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001328{
1329 MagickRealType
1330 alpha,
1331 beta;
1332
1333 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression,&beta,exception);
1334 return((MagickRealType) MagickMin((double) alpha,(double) beta));
1335}
1336
1337static inline const char *FxSubexpression(const char *expression,
1338 ExceptionInfo *exception)
1339{
1340 const char
1341 *subexpression;
1342
cristybb503372010-05-27 20:51:26 +00001343 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001344 level;
1345
1346 level=0;
1347 subexpression=expression;
1348 while ((*subexpression != '\0') &&
1349 ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL)))
1350 {
1351 if (strchr("(",(int) *subexpression) != (char *) NULL)
1352 level++;
1353 else
1354 if (strchr(")",(int) *subexpression) != (char *) NULL)
1355 level--;
1356 subexpression++;
1357 }
1358 if (*subexpression == '\0')
1359 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1360 "UnbalancedParenthesis","`%s'",expression);
1361 return(subexpression);
1362}
1363
cristy0568ffc2011-07-25 16:54:14 +00001364static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
cristye85007d2010-06-06 22:51:36 +00001365 const ssize_t x,const ssize_t y,const char *expression,
1366 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001367{
1368 char
1369 *q,
1370 subexpression[MaxTextExtent],
1371 symbol[MaxTextExtent];
1372
1373 const char
1374 *p,
1375 *value;
1376
1377 Image
1378 *image;
1379
cristy4c08aed2011-07-01 19:47:50 +00001380 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001381 pixel;
1382
1383 MagickRealType
1384 alpha,
1385 beta;
1386
1387 PointInfo
1388 point;
1389
cristybb503372010-05-27 20:51:26 +00001390 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001391 i;
1392
1393 size_t
1394 length;
1395
cristybb503372010-05-27 20:51:26 +00001396 size_t
cristy3ed852e2009-09-05 21:47:34 +00001397 level;
1398
1399 p=expression;
1400 i=GetImageIndexInList(fx_info->images);
1401 level=0;
1402 point.x=(double) x;
1403 point.y=(double) y;
1404 if (isalpha((int) *(p+1)) == 0)
1405 {
1406 if (strchr("suv",(int) *p) != (char *) NULL)
1407 {
1408 switch (*p)
1409 {
1410 case 's':
1411 default:
1412 {
1413 i=GetImageIndexInList(fx_info->images);
1414 break;
1415 }
1416 case 'u': i=0; break;
1417 case 'v': i=1; break;
1418 }
1419 p++;
1420 if (*p == '[')
1421 {
1422 level++;
1423 q=subexpression;
1424 for (p++; *p != '\0'; )
1425 {
1426 if (*p == '[')
1427 level++;
1428 else
1429 if (*p == ']')
1430 {
1431 level--;
1432 if (level == 0)
1433 break;
1434 }
1435 *q++=(*p++);
1436 }
1437 *q='\0';
1438 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1439 &beta,exception);
cristybb503372010-05-27 20:51:26 +00001440 i=(ssize_t) (alpha+0.5);
cristy3ed852e2009-09-05 21:47:34 +00001441 p++;
1442 }
1443 if (*p == '.')
1444 p++;
1445 }
1446 if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
1447 {
1448 p++;
1449 if (*p == '{')
1450 {
1451 level++;
1452 q=subexpression;
1453 for (p++; *p != '\0'; )
1454 {
1455 if (*p == '{')
1456 level++;
1457 else
1458 if (*p == '}')
1459 {
1460 level--;
1461 if (level == 0)
1462 break;
1463 }
1464 *q++=(*p++);
1465 }
1466 *q='\0';
1467 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1468 &beta,exception);
1469 point.x=alpha;
1470 point.y=beta;
1471 p++;
1472 }
1473 else
1474 if (*p == '[')
1475 {
1476 level++;
1477 q=subexpression;
1478 for (p++; *p != '\0'; )
1479 {
1480 if (*p == '[')
1481 level++;
1482 else
1483 if (*p == ']')
1484 {
1485 level--;
1486 if (level == 0)
1487 break;
1488 }
1489 *q++=(*p++);
1490 }
1491 *q='\0';
1492 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
1493 &beta,exception);
1494 point.x+=alpha;
1495 point.y+=beta;
1496 p++;
1497 }
1498 if (*p == '.')
1499 p++;
1500 }
1501 }
1502 length=GetImageListLength(fx_info->images);
1503 while (i < 0)
cristybb503372010-05-27 20:51:26 +00001504 i+=(ssize_t) length;
cristy3ed852e2009-09-05 21:47:34 +00001505 i%=length;
1506 image=GetImageFromList(fx_info->images,i);
1507 if (image == (Image *) NULL)
1508 {
1509 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1510 "NoSuchImage","`%s'",expression);
1511 return(0.0);
1512 }
cristy4c08aed2011-07-01 19:47:50 +00001513 GetPixelInfo(image,&pixel);
1514 (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
cristy4f820712011-04-01 12:35:43 +00001515 point.x,point.y,&pixel,exception);
cristy3ed852e2009-09-05 21:47:34 +00001516 if ((strlen(p) > 2) &&
1517 (LocaleCompare(p,"intensity") != 0) &&
1518 (LocaleCompare(p,"luminance") != 0) &&
1519 (LocaleCompare(p,"hue") != 0) &&
1520 (LocaleCompare(p,"saturation") != 0) &&
1521 (LocaleCompare(p,"lightness") != 0))
1522 {
1523 char
1524 name[MaxTextExtent];
1525
1526 (void) CopyMagickString(name,p,MaxTextExtent);
1527 for (q=name+(strlen(name)-1); q > name; q--)
1528 {
1529 if (*q == ')')
1530 break;
1531 if (*q == '.')
1532 {
1533 *q='\0';
1534 break;
1535 }
1536 }
1537 if ((strlen(name) > 2) &&
1538 (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL))
1539 {
cristy4c08aed2011-07-01 19:47:50 +00001540 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00001541 *color;
1542
cristy4c08aed2011-07-01 19:47:50 +00001543 color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name);
1544 if (color != (PixelInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001545 {
1546 pixel=(*color);
1547 p+=strlen(name);
1548 }
1549 else
cristy269c9412011-10-13 23:41:15 +00001550 if (QueryColorCompliance(name,AllCompliance,&pixel,fx_info->exception) != MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001551 {
1552 (void) AddValueToSplayTree(fx_info->colors,ConstantString(name),
cristy4c08aed2011-07-01 19:47:50 +00001553 ClonePixelInfo(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001554 p+=strlen(name);
1555 }
1556 }
1557 }
1558 (void) CopyMagickString(symbol,p,MaxTextExtent);
1559 StripString(symbol);
1560 if (*symbol == '\0')
1561 {
1562 switch (channel)
1563 {
cristy0568ffc2011-07-25 16:54:14 +00001564 case RedPixelChannel: return(QuantumScale*pixel.red);
1565 case GreenPixelChannel: return(QuantumScale*pixel.green);
1566 case BluePixelChannel: return(QuantumScale*pixel.blue);
1567 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001568 {
1569 if (image->colorspace != CMYKColorspace)
1570 {
1571 (void) ThrowMagickException(exception,GetMagickModule(),
1572 OptionError,"ColorSeparatedImageRequired","`%s'",
1573 image->filename);
1574 return(0.0);
1575 }
cristy4c08aed2011-07-01 19:47:50 +00001576 return(QuantumScale*pixel.black);
1577 }
cristy0568ffc2011-07-25 16:54:14 +00001578 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001579 {
1580 MagickRealType
1581 alpha;
1582
1583 if (pixel.matte == MagickFalse)
1584 return(1.0);
1585 alpha=(MagickRealType) (QuantumScale*pixel.alpha);
1586 return(alpha);
cristy3ed852e2009-09-05 21:47:34 +00001587 }
cristyb3a73b52011-07-26 01:34:43 +00001588 case IntensityPixelChannel:
cristyf364ed42010-12-15 01:54:43 +00001589 {
cristy4c08aed2011-07-01 19:47:50 +00001590 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristyf364ed42010-12-15 01:54:43 +00001591 }
cristy3ed852e2009-09-05 21:47:34 +00001592 default:
1593 break;
1594 }
1595 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1596 "UnableToParseExpression","`%s'",p);
1597 return(0.0);
1598 }
1599 switch (*symbol)
1600 {
1601 case 'A':
1602 case 'a':
1603 {
1604 if (LocaleCompare(symbol,"a") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001605 return((MagickRealType) (QuantumScale*pixel.alpha));
cristy3ed852e2009-09-05 21:47:34 +00001606 break;
1607 }
1608 case 'B':
1609 case 'b':
1610 {
1611 if (LocaleCompare(symbol,"b") == 0)
1612 return(QuantumScale*pixel.blue);
1613 break;
1614 }
1615 case 'C':
1616 case 'c':
1617 {
1618 if (LocaleNCompare(symbol,"channel",7) == 0)
1619 {
1620 GeometryInfo
1621 channel_info;
1622
1623 MagickStatusType
1624 flags;
1625
1626 flags=ParseGeometry(symbol+7,&channel_info);
1627 if (image->colorspace == CMYKColorspace)
1628 switch (channel)
1629 {
cristy0568ffc2011-07-25 16:54:14 +00001630 case CyanPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001631 {
1632 if ((flags & RhoValue) == 0)
1633 return(0.0);
1634 return(channel_info.rho);
1635 }
cristy0568ffc2011-07-25 16:54:14 +00001636 case MagentaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001637 {
1638 if ((flags & SigmaValue) == 0)
1639 return(0.0);
1640 return(channel_info.sigma);
1641 }
cristy0568ffc2011-07-25 16:54:14 +00001642 case YellowPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001643 {
1644 if ((flags & XiValue) == 0)
1645 return(0.0);
1646 return(channel_info.xi);
1647 }
cristy0568ffc2011-07-25 16:54:14 +00001648 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001649 {
1650 if ((flags & PsiValue) == 0)
1651 return(0.0);
1652 return(channel_info.psi);
1653 }
cristy0568ffc2011-07-25 16:54:14 +00001654 case AlphaPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001655 {
1656 if ((flags & ChiValue) == 0)
1657 return(0.0);
1658 return(channel_info.chi);
1659 }
1660 default:
1661 return(0.0);
1662 }
1663 switch (channel)
1664 {
cristy0568ffc2011-07-25 16:54:14 +00001665 case RedPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001666 {
1667 if ((flags & RhoValue) == 0)
1668 return(0.0);
1669 return(channel_info.rho);
1670 }
cristy0568ffc2011-07-25 16:54:14 +00001671 case GreenPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001672 {
1673 if ((flags & SigmaValue) == 0)
1674 return(0.0);
1675 return(channel_info.sigma);
1676 }
cristy0568ffc2011-07-25 16:54:14 +00001677 case BluePixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001678 {
1679 if ((flags & XiValue) == 0)
1680 return(0.0);
1681 return(channel_info.xi);
1682 }
cristy0568ffc2011-07-25 16:54:14 +00001683 case BlackPixelChannel:
cristy3ed852e2009-09-05 21:47:34 +00001684 {
1685 if ((flags & ChiValue) == 0)
1686 return(0.0);
1687 return(channel_info.chi);
1688 }
cristy0568ffc2011-07-25 16:54:14 +00001689 case AlphaPixelChannel:
cristy4c08aed2011-07-01 19:47:50 +00001690 {
1691 if ((flags & PsiValue) == 0)
1692 return(0.0);
1693 return(channel_info.psi);
1694 }
cristy3ed852e2009-09-05 21:47:34 +00001695 default:
1696 return(0.0);
1697 }
1698 return(0.0);
1699 }
1700 if (LocaleCompare(symbol,"c") == 0)
1701 return(QuantumScale*pixel.red);
1702 break;
1703 }
1704 case 'D':
1705 case 'd':
1706 {
1707 if (LocaleNCompare(symbol,"depth",5) == 0)
1708 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1709 break;
1710 }
1711 case 'G':
1712 case 'g':
1713 {
1714 if (LocaleCompare(symbol,"g") == 0)
1715 return(QuantumScale*pixel.green);
1716 break;
1717 }
1718 case 'K':
1719 case 'k':
1720 {
1721 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1722 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1723 if (LocaleCompare(symbol,"k") == 0)
1724 {
1725 if (image->colorspace != CMYKColorspace)
1726 {
1727 (void) ThrowMagickException(exception,GetMagickModule(),
1728 OptionError,"ColorSeparatedImageRequired","`%s'",
1729 image->filename);
1730 return(0.0);
1731 }
cristy4c08aed2011-07-01 19:47:50 +00001732 return(QuantumScale*pixel.black);
cristy3ed852e2009-09-05 21:47:34 +00001733 }
1734 break;
1735 }
1736 case 'H':
1737 case 'h':
1738 {
1739 if (LocaleCompare(symbol,"h") == 0)
1740 return((MagickRealType) image->rows);
1741 if (LocaleCompare(symbol,"hue") == 0)
1742 {
1743 double
1744 hue,
1745 lightness,
1746 saturation;
1747
cristyda1f9c12011-10-02 21:39:49 +00001748 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1749 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001750 return(hue);
1751 }
1752 break;
1753 }
1754 case 'I':
1755 case 'i':
1756 {
1757 if ((LocaleCompare(symbol,"image.depth") == 0) ||
1758 (LocaleCompare(symbol,"image.minima") == 0) ||
1759 (LocaleCompare(symbol,"image.maxima") == 0) ||
1760 (LocaleCompare(symbol,"image.mean") == 0) ||
1761 (LocaleCompare(symbol,"image.kurtosis") == 0) ||
1762 (LocaleCompare(symbol,"image.skewness") == 0) ||
1763 (LocaleCompare(symbol,"image.standard_deviation") == 0))
1764 return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception));
1765 if (LocaleCompare(symbol,"image.resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001766 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001767 if (LocaleCompare(symbol,"image.resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001768 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001769 if (LocaleCompare(symbol,"intensity") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001770 return(QuantumScale*GetPixelInfoIntensity(&pixel));
cristy3ed852e2009-09-05 21:47:34 +00001771 if (LocaleCompare(symbol,"i") == 0)
1772 return((MagickRealType) x);
1773 break;
1774 }
1775 case 'J':
1776 case 'j':
1777 {
1778 if (LocaleCompare(symbol,"j") == 0)
1779 return((MagickRealType) y);
1780 break;
1781 }
1782 case 'L':
1783 case 'l':
1784 {
1785 if (LocaleCompare(symbol,"lightness") == 0)
1786 {
1787 double
1788 hue,
1789 lightness,
1790 saturation;
1791
cristyda1f9c12011-10-02 21:39:49 +00001792 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1793 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001794 return(lightness);
1795 }
1796 if (LocaleCompare(symbol,"luminance") == 0)
1797 {
1798 double
1799 luminence;
1800
1801 luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
1802 return(QuantumScale*luminence);
1803 }
1804 break;
1805 }
1806 case 'M':
1807 case 'm':
1808 {
1809 if (LocaleNCompare(symbol,"maxima",6) == 0)
1810 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1811 if (LocaleNCompare(symbol,"mean",4) == 0)
1812 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1813 if (LocaleNCompare(symbol,"minima",6) == 0)
1814 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1815 if (LocaleCompare(symbol,"m") == 0)
1816 return(QuantumScale*pixel.blue);
1817 break;
1818 }
1819 case 'N':
1820 case 'n':
1821 {
1822 if (LocaleCompare(symbol,"n") == 0)
anthony374f5dd2011-03-25 10:08:53 +00001823 return((MagickRealType) GetImageListLength(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001824 break;
1825 }
1826 case 'O':
1827 case 'o':
1828 {
1829 if (LocaleCompare(symbol,"o") == 0)
cristy4c08aed2011-07-01 19:47:50 +00001830 return(QuantumScale*pixel.alpha);
cristy3ed852e2009-09-05 21:47:34 +00001831 break;
1832 }
1833 case 'P':
1834 case 'p':
1835 {
1836 if (LocaleCompare(symbol,"page.height") == 0)
1837 return((MagickRealType) image->page.height);
1838 if (LocaleCompare(symbol,"page.width") == 0)
1839 return((MagickRealType) image->page.width);
1840 if (LocaleCompare(symbol,"page.x") == 0)
1841 return((MagickRealType) image->page.x);
1842 if (LocaleCompare(symbol,"page.y") == 0)
1843 return((MagickRealType) image->page.y);
1844 break;
1845 }
1846 case 'R':
1847 case 'r':
1848 {
1849 if (LocaleCompare(symbol,"resolution.x") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001850 return(image->resolution.x);
cristy3ed852e2009-09-05 21:47:34 +00001851 if (LocaleCompare(symbol,"resolution.y") == 0)
cristy2a11bef2011-10-28 18:33:11 +00001852 return(image->resolution.y);
cristy3ed852e2009-09-05 21:47:34 +00001853 if (LocaleCompare(symbol,"r") == 0)
1854 return(QuantumScale*pixel.red);
1855 break;
1856 }
1857 case 'S':
1858 case 's':
1859 {
1860 if (LocaleCompare(symbol,"saturation") == 0)
1861 {
1862 double
1863 hue,
1864 lightness,
1865 saturation;
1866
cristyda1f9c12011-10-02 21:39:49 +00001867 ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation,
1868 &lightness);
cristy3ed852e2009-09-05 21:47:34 +00001869 return(saturation);
1870 }
1871 if (LocaleNCompare(symbol,"skewness",8) == 0)
1872 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1873 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1874 return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
1875 break;
1876 }
1877 case 'T':
1878 case 't':
1879 {
1880 if (LocaleCompare(symbol,"t") == 0)
cristy5a15b932011-03-26 12:50:33 +00001881 return((MagickRealType) GetImageIndexInList(fx_info->images));
cristy3ed852e2009-09-05 21:47:34 +00001882 break;
1883 }
1884 case 'W':
1885 case 'w':
1886 {
1887 if (LocaleCompare(symbol,"w") == 0)
1888 return((MagickRealType) image->columns);
1889 break;
1890 }
1891 case 'Y':
1892 case 'y':
1893 {
1894 if (LocaleCompare(symbol,"y") == 0)
1895 return(QuantumScale*pixel.green);
1896 break;
1897 }
1898 case 'Z':
1899 case 'z':
1900 {
1901 if (LocaleCompare(symbol,"z") == 0)
1902 {
1903 MagickRealType
1904 depth;
1905
cristyfefab1b2011-07-05 00:33:22 +00001906 depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
cristy3ed852e2009-09-05 21:47:34 +00001907 return(depth);
1908 }
1909 break;
1910 }
1911 default:
1912 break;
1913 }
1914 value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
1915 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001916 return((MagickRealType) InterpretLocaleValue(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001917 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
1918 "UnableToParseExpression","`%s'",symbol);
1919 return(0.0);
1920}
1921
1922static const char *FxOperatorPrecedence(const char *expression,
1923 ExceptionInfo *exception)
1924{
1925 typedef enum
1926 {
1927 UndefinedPrecedence,
1928 NullPrecedence,
1929 BitwiseComplementPrecedence,
1930 ExponentPrecedence,
cristy116af162010-08-13 01:25:47 +00001931 ExponentialNotationPrecedence,
cristy3ed852e2009-09-05 21:47:34 +00001932 MultiplyPrecedence,
1933 AdditionPrecedence,
1934 ShiftPrecedence,
1935 RelationalPrecedence,
1936 EquivalencyPrecedence,
1937 BitwiseAndPrecedence,
1938 BitwiseOrPrecedence,
1939 LogicalAndPrecedence,
1940 LogicalOrPrecedence,
1941 TernaryPrecedence,
1942 AssignmentPrecedence,
1943 CommaPrecedence,
1944 SeparatorPrecedence
1945 } FxPrecedence;
1946
1947 FxPrecedence
1948 precedence,
1949 target;
1950
1951 register const char
1952 *subexpression;
1953
1954 register int
1955 c;
1956
cristybb503372010-05-27 20:51:26 +00001957 size_t
cristy3ed852e2009-09-05 21:47:34 +00001958 level;
1959
1960 c=0;
1961 level=0;
1962 subexpression=(const char *) NULL;
1963 target=NullPrecedence;
1964 while (*expression != '\0')
1965 {
1966 precedence=UndefinedPrecedence;
1967 if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
1968 {
1969 expression++;
1970 continue;
1971 }
cristy488fa882010-03-01 22:34:24 +00001972 switch (*expression)
1973 {
1974 case 'A':
1975 case 'a':
cristy3ed852e2009-09-05 21:47:34 +00001976 {
cristyb33454f2011-08-03 02:10:45 +00001977#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00001978 if (LocaleNCompare(expression,"acosh",5) == 0)
1979 {
1980 expression+=5;
1981 break;
1982 }
cristyb33454f2011-08-03 02:10:45 +00001983#endif
1984#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00001985 if (LocaleNCompare(expression,"asinh",5) == 0)
1986 {
1987 expression+=5;
1988 break;
1989 }
cristyb33454f2011-08-03 02:10:45 +00001990#endif
1991#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00001992 if (LocaleNCompare(expression,"atanh",5) == 0)
cristy488fa882010-03-01 22:34:24 +00001993 {
1994 expression+=5;
1995 break;
1996 }
cristyb33454f2011-08-03 02:10:45 +00001997#endif
cristy488fa882010-03-01 22:34:24 +00001998 break;
cristy3ed852e2009-09-05 21:47:34 +00001999 }
cristy488fa882010-03-01 22:34:24 +00002000 case 'J':
2001 case 'j':
2002 {
2003 if ((LocaleNCompare(expression,"j0",2) == 0) ||
2004 (LocaleNCompare(expression,"j1",2) == 0))
2005 {
2006 expression+=2;
2007 break;
2008 }
2009 break;
2010 }
cristy2def9322010-06-18 23:59:37 +00002011 case '#':
2012 {
2013 while (isxdigit((int) ((unsigned char) *(expression+1))) != 0)
2014 expression++;
2015 break;
2016 }
cristy488fa882010-03-01 22:34:24 +00002017 default:
2018 break;
2019 }
cristy3ed852e2009-09-05 21:47:34 +00002020 if ((c == (int) '{') || (c == (int) '['))
2021 level++;
2022 else
2023 if ((c == (int) '}') || (c == (int) ']'))
2024 level--;
2025 if (level == 0)
2026 switch ((unsigned char) *expression)
2027 {
2028 case '~':
2029 case '!':
2030 {
2031 precedence=BitwiseComplementPrecedence;
2032 break;
2033 }
2034 case '^':
cristy6621e252010-08-13 00:42:57 +00002035 case '@':
cristy3ed852e2009-09-05 21:47:34 +00002036 {
2037 precedence=ExponentPrecedence;
2038 break;
2039 }
2040 default:
2041 {
2042 if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
2043 (strchr(")",c) != (char *) NULL))) &&
2044 (((islower((int) ((char) *expression)) != 0) ||
2045 (strchr("(",(int) *expression) != (char *) NULL)) ||
2046 ((isdigit((int) ((char) c)) == 0) &&
2047 (isdigit((int) ((char) *expression)) != 0))) &&
2048 (strchr("xy",(int) *expression) == (char *) NULL))
2049 precedence=MultiplyPrecedence;
2050 break;
2051 }
2052 case '*':
2053 case '/':
2054 case '%':
2055 {
2056 precedence=MultiplyPrecedence;
2057 break;
2058 }
2059 case '+':
2060 case '-':
2061 {
2062 if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) ||
2063 (isalpha(c) != 0))
2064 precedence=AdditionPrecedence;
2065 break;
2066 }
2067 case LeftShiftOperator:
2068 case RightShiftOperator:
2069 {
2070 precedence=ShiftPrecedence;
2071 break;
2072 }
2073 case '<':
2074 case LessThanEqualOperator:
2075 case GreaterThanEqualOperator:
2076 case '>':
2077 {
2078 precedence=RelationalPrecedence;
2079 break;
2080 }
2081 case EqualOperator:
2082 case NotEqualOperator:
2083 {
2084 precedence=EquivalencyPrecedence;
2085 break;
2086 }
2087 case '&':
2088 {
2089 precedence=BitwiseAndPrecedence;
2090 break;
2091 }
2092 case '|':
2093 {
2094 precedence=BitwiseOrPrecedence;
2095 break;
2096 }
2097 case LogicalAndOperator:
2098 {
2099 precedence=LogicalAndPrecedence;
2100 break;
2101 }
2102 case LogicalOrOperator:
2103 {
2104 precedence=LogicalOrPrecedence;
2105 break;
2106 }
cristy116af162010-08-13 01:25:47 +00002107 case ExponentialNotation:
2108 {
2109 precedence=ExponentialNotationPrecedence;
2110 break;
2111 }
cristy3ed852e2009-09-05 21:47:34 +00002112 case ':':
2113 case '?':
2114 {
2115 precedence=TernaryPrecedence;
2116 break;
2117 }
2118 case '=':
2119 {
2120 precedence=AssignmentPrecedence;
2121 break;
2122 }
2123 case ',':
2124 {
2125 precedence=CommaPrecedence;
2126 break;
2127 }
2128 case ';':
2129 {
2130 precedence=SeparatorPrecedence;
2131 break;
2132 }
2133 }
2134 if ((precedence == BitwiseComplementPrecedence) ||
2135 (precedence == TernaryPrecedence) ||
2136 (precedence == AssignmentPrecedence))
2137 {
2138 if (precedence > target)
2139 {
2140 /*
2141 Right-to-left associativity.
2142 */
2143 target=precedence;
2144 subexpression=expression;
2145 }
2146 }
2147 else
2148 if (precedence >= target)
2149 {
2150 /*
2151 Left-to-right associativity.
2152 */
2153 target=precedence;
2154 subexpression=expression;
2155 }
2156 if (strchr("(",(int) *expression) != (char *) NULL)
2157 expression=FxSubexpression(expression,exception);
2158 c=(int) (*expression++);
2159 }
2160 return(subexpression);
2161}
2162
2163static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002164 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristye85007d2010-06-06 22:51:36 +00002165 const char *expression,MagickRealType *beta,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002166{
2167 char
2168 *q,
2169 subexpression[MaxTextExtent];
2170
2171 MagickRealType
2172 alpha,
2173 gamma;
2174
2175 register const char
2176 *p;
2177
2178 *beta=0.0;
2179 if (exception->severity != UndefinedException)
2180 return(0.0);
2181 while (isspace((int) *expression) != 0)
2182 expression++;
2183 if (*expression == '\0')
2184 {
2185 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
2186 "MissingExpression","`%s'",expression);
2187 return(0.0);
2188 }
cristy66322f02010-05-17 11:40:48 +00002189 *subexpression='\0';
cristy3ed852e2009-09-05 21:47:34 +00002190 p=FxOperatorPrecedence(expression,exception);
2191 if (p != (const char *) NULL)
2192 {
2193 (void) CopyMagickString(subexpression,expression,(size_t)
2194 (p-expression+1));
2195 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2196 exception);
2197 switch ((unsigned char) *p)
2198 {
2199 case '~':
2200 {
2201 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002202 *beta=(MagickRealType) (~(size_t) *beta);
cristy3ed852e2009-09-05 21:47:34 +00002203 return(*beta);
2204 }
2205 case '!':
2206 {
2207 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2208 return(*beta == 0.0 ? 1.0 : 0.0);
2209 }
2210 case '^':
2211 {
2212 *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
2213 channel,x,y,++p,beta,exception));
2214 return(*beta);
2215 }
2216 case '*':
cristy116af162010-08-13 01:25:47 +00002217 case ExponentialNotation:
cristy3ed852e2009-09-05 21:47:34 +00002218 {
2219 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2220 return(alpha*(*beta));
2221 }
2222 case '/':
2223 {
2224 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2225 if (*beta == 0.0)
2226 {
2227 if (exception->severity == UndefinedException)
2228 (void) ThrowMagickException(exception,GetMagickModule(),
2229 OptionError,"DivideByZero","`%s'",expression);
2230 return(0.0);
2231 }
2232 return(alpha/(*beta));
2233 }
2234 case '%':
2235 {
2236 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2237 *beta=fabs(floor(((double) *beta)+0.5));
2238 if (*beta == 0.0)
2239 {
2240 (void) ThrowMagickException(exception,GetMagickModule(),
2241 OptionError,"DivideByZero","`%s'",expression);
2242 return(0.0);
2243 }
2244 return(fmod((double) alpha,(double) *beta));
2245 }
2246 case '+':
2247 {
2248 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2249 return(alpha+(*beta));
2250 }
2251 case '-':
2252 {
2253 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2254 return(alpha-(*beta));
2255 }
2256 case LeftShiftOperator:
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 RightShiftOperator:
2264 {
2265 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002266 *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002267 (gamma+0.5));
2268 return(*beta);
2269 }
2270 case '<':
2271 {
2272 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2273 return(alpha < *beta ? 1.0 : 0.0);
2274 }
2275 case LessThanEqualOperator:
2276 {
2277 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2278 return(alpha <= *beta ? 1.0 : 0.0);
2279 }
2280 case '>':
2281 {
2282 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2283 return(alpha > *beta ? 1.0 : 0.0);
2284 }
2285 case GreaterThanEqualOperator:
2286 {
2287 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2288 return(alpha >= *beta ? 1.0 : 0.0);
2289 }
2290 case EqualOperator:
2291 {
2292 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2293 return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
2294 }
2295 case NotEqualOperator:
2296 {
2297 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2298 return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
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 '|':
2308 {
2309 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristybb503372010-05-27 20:51:26 +00002310 *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t)
cristy3ed852e2009-09-05 21:47:34 +00002311 (gamma+0.5));
2312 return(*beta);
2313 }
2314 case LogicalAndOperator:
2315 {
2316 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2317 *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
2318 return(*beta);
2319 }
2320 case LogicalOrOperator:
2321 {
2322 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2323 *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
2324 return(*beta);
2325 }
2326 case '?':
2327 {
2328 MagickRealType
2329 gamma;
2330
2331 (void) CopyMagickString(subexpression,++p,MaxTextExtent);
2332 q=subexpression;
2333 p=StringToken(":",&q);
2334 if (q == (char *) NULL)
2335 {
2336 (void) ThrowMagickException(exception,GetMagickModule(),
2337 OptionError,"UnableToParseExpression","`%s'",subexpression);
2338 return(0.0);
2339 }
2340 if (fabs((double) alpha) > MagickEpsilon)
2341 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
2342 else
2343 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
2344 return(gamma);
2345 }
2346 case '=':
2347 {
2348 char
2349 numeric[MaxTextExtent];
2350
2351 q=subexpression;
2352 while (isalpha((int) ((unsigned char) *q)) != 0)
2353 q++;
2354 if (*q != '\0')
2355 {
2356 (void) ThrowMagickException(exception,GetMagickModule(),
2357 OptionError,"UnableToParseExpression","`%s'",subexpression);
2358 return(0.0);
2359 }
2360 ClearMagickException(exception);
2361 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
cristyb51dff52011-05-19 16:55:47 +00002362 (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
cristy8cd5b312010-01-07 01:10:24 +00002363 *beta);
cristy3ed852e2009-09-05 21:47:34 +00002364 (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
2365 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
2366 subexpression),ConstantString(numeric));
2367 return(*beta);
2368 }
2369 case ',':
2370 {
2371 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2372 return(alpha);
2373 }
2374 case ';':
2375 {
2376 *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
2377 return(*beta);
2378 }
2379 default:
2380 {
2381 gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
2382 exception);
2383 return(gamma);
2384 }
2385 }
2386 }
2387 if (strchr("(",(int) *expression) != (char *) NULL)
2388 {
2389 (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
2390 subexpression[strlen(subexpression)-1]='\0';
2391 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
2392 exception);
2393 return(gamma);
2394 }
cristy8b8a3ae2010-10-23 18:49:46 +00002395 switch (*expression)
cristy3ed852e2009-09-05 21:47:34 +00002396 {
2397 case '+':
2398 {
2399 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2400 exception);
2401 return(1.0*gamma);
2402 }
2403 case '-':
2404 {
2405 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2406 exception);
2407 return(-1.0*gamma);
2408 }
2409 case '~':
2410 {
2411 gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
2412 exception);
cristybb503372010-05-27 20:51:26 +00002413 return((MagickRealType) (~(size_t) (gamma+0.5)));
cristy3ed852e2009-09-05 21:47:34 +00002414 }
2415 case 'A':
2416 case 'a':
2417 {
2418 if (LocaleNCompare(expression,"abs",3) == 0)
2419 {
2420 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2421 exception);
2422 return((MagickRealType) fabs((double) alpha));
2423 }
cristyb33454f2011-08-03 02:10:45 +00002424#if defined(MAGICKCORE_HAVE_ACOSH)
cristy363772a2011-07-28 23:25:33 +00002425 if (LocaleNCompare(expression,"acosh",5) == 0)
2426 {
2427 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2428 exception);
2429 return((MagickRealType) acosh((double) alpha));
2430 }
cristyb33454f2011-08-03 02:10:45 +00002431#endif
cristy3ed852e2009-09-05 21:47:34 +00002432 if (LocaleNCompare(expression,"acos",4) == 0)
2433 {
2434 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2435 exception);
2436 return((MagickRealType) acos((double) alpha));
2437 }
cristy43c22f42010-03-30 12:34:07 +00002438#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002439 if (LocaleNCompare(expression,"airy",4) == 0)
2440 {
2441 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2442 exception);
2443 if (alpha == 0.0)
cristy2dd03222010-03-30 22:12:11 +00002444 return(1.0);
2445 gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
cristy43c22f42010-03-30 12:34:07 +00002446 return(gamma*gamma);
cristyee56cf12010-03-01 22:17:06 +00002447 }
cristy43c22f42010-03-30 12:34:07 +00002448#endif
cristyb33454f2011-08-03 02:10:45 +00002449#if defined(MAGICKCORE_HAVE_ASINH)
cristy363772a2011-07-28 23:25:33 +00002450 if (LocaleNCompare(expression,"asinh",5) == 0)
2451 {
2452 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2453 exception);
2454 return((MagickRealType) asinh((double) alpha));
2455 }
cristyb33454f2011-08-03 02:10:45 +00002456#endif
cristy3ed852e2009-09-05 21:47:34 +00002457 if (LocaleNCompare(expression,"asin",4) == 0)
2458 {
2459 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2460 exception);
2461 return((MagickRealType) asin((double) alpha));
2462 }
2463 if (LocaleNCompare(expression,"alt",3) == 0)
2464 {
2465 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2466 exception);
cristybb503372010-05-27 20:51:26 +00002467 return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
cristy3ed852e2009-09-05 21:47:34 +00002468 }
2469 if (LocaleNCompare(expression,"atan2",5) == 0)
2470 {
2471 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2472 exception);
2473 return((MagickRealType) atan2((double) alpha,(double) *beta));
2474 }
cristyb33454f2011-08-03 02:10:45 +00002475#if defined(MAGICKCORE_HAVE_ATANH)
cristy363772a2011-07-28 23:25:33 +00002476 if (LocaleNCompare(expression,"atanh",5) == 0)
2477 {
2478 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2479 exception);
2480 return((MagickRealType) atanh((double) alpha));
2481 }
cristyb33454f2011-08-03 02:10:45 +00002482#endif
cristy3ed852e2009-09-05 21:47:34 +00002483 if (LocaleNCompare(expression,"atan",4) == 0)
2484 {
2485 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2486 exception);
2487 return((MagickRealType) atan((double) alpha));
2488 }
2489 if (LocaleCompare(expression,"a") == 0)
2490 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2491 break;
2492 }
2493 case 'B':
2494 case 'b':
2495 {
2496 if (LocaleCompare(expression,"b") == 0)
2497 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2498 break;
2499 }
2500 case 'C':
2501 case 'c':
2502 {
2503 if (LocaleNCompare(expression,"ceil",4) == 0)
2504 {
2505 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2506 exception);
2507 return((MagickRealType) ceil((double) alpha));
2508 }
2509 if (LocaleNCompare(expression,"cosh",4) == 0)
2510 {
2511 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2512 exception);
2513 return((MagickRealType) cosh((double) alpha));
2514 }
2515 if (LocaleNCompare(expression,"cos",3) == 0)
2516 {
2517 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2518 exception);
2519 return((MagickRealType) cos((double) alpha));
2520 }
2521 if (LocaleCompare(expression,"c") == 0)
2522 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2523 break;
2524 }
2525 case 'D':
2526 case 'd':
2527 {
2528 if (LocaleNCompare(expression,"debug",5) == 0)
2529 {
2530 const char
2531 *type;
2532
2533 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2534 exception);
2535 if (fx_info->images->colorspace == CMYKColorspace)
2536 switch (channel)
2537 {
cristy0568ffc2011-07-25 16:54:14 +00002538 case CyanPixelChannel: type="cyan"; break;
2539 case MagentaPixelChannel: type="magenta"; break;
2540 case YellowPixelChannel: type="yellow"; break;
2541 case AlphaPixelChannel: type="opacity"; break;
2542 case BlackPixelChannel: type="black"; break;
cristy3ed852e2009-09-05 21:47:34 +00002543 default: type="unknown"; break;
2544 }
2545 else
2546 switch (channel)
2547 {
cristy0568ffc2011-07-25 16:54:14 +00002548 case RedPixelChannel: type="red"; break;
2549 case GreenPixelChannel: type="green"; break;
2550 case BluePixelChannel: type="blue"; break;
2551 case AlphaPixelChannel: type="opacity"; break;
cristy3ed852e2009-09-05 21:47:34 +00002552 default: type="unknown"; break;
2553 }
2554 (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
2555 if (strlen(subexpression) > 1)
2556 subexpression[strlen(subexpression)-1]='\0';
2557 if (fx_info->file != (FILE *) NULL)
cristy1e604812011-05-19 18:07:50 +00002558 (void) FormatLocaleFile(fx_info->file,
2559 "%s[%.20g,%.20g].%s: %s=%.*g\n",fx_info->images->filename,
2560 (double) x,(double) y,type,subexpression,GetMagickPrecision(),
2561 (double) alpha);
cristy3ed852e2009-09-05 21:47:34 +00002562 return(0.0);
2563 }
2564 break;
2565 }
2566 case 'E':
2567 case 'e':
2568 {
2569 if (LocaleCompare(expression,"epsilon") == 0)
2570 return((MagickRealType) MagickEpsilon);
2571 if (LocaleNCompare(expression,"exp",3) == 0)
2572 {
2573 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2574 exception);
2575 return((MagickRealType) exp((double) alpha));
2576 }
2577 if (LocaleCompare(expression,"e") == 0)
2578 return((MagickRealType) 2.7182818284590452354);
2579 break;
2580 }
2581 case 'F':
2582 case 'f':
2583 {
2584 if (LocaleNCompare(expression,"floor",5) == 0)
2585 {
2586 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2587 exception);
2588 return((MagickRealType) floor((double) alpha));
2589 }
2590 break;
2591 }
2592 case 'G':
2593 case 'g':
2594 {
cristy9eeedea2011-11-02 19:04:05 +00002595 if (LocaleNCompare(expression,"gauss",5) == 0)
2596 {
2597 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2598 exception);
2599 gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
2600 return((MagickRealType) gamma);
2601 }
cristyb0aad4c2011-11-02 19:30:35 +00002602 if (LocaleNCompare(expression,"gcd",3) == 0)
2603 {
2604 MagickOffsetType
2605 gcd;
2606
2607 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2608 exception);
cristy76461162011-11-02 19:32:19 +00002609 gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType)
2610 (*beta+0.5));
cristyb0aad4c2011-11-02 19:30:35 +00002611 return((MagickRealType) gcd);
2612 }
cristy3ed852e2009-09-05 21:47:34 +00002613 if (LocaleCompare(expression,"g") == 0)
2614 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2615 break;
2616 }
2617 case 'H':
2618 case 'h':
2619 {
2620 if (LocaleCompare(expression,"h") == 0)
2621 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2622 if (LocaleCompare(expression,"hue") == 0)
2623 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2624 if (LocaleNCompare(expression,"hypot",5) == 0)
2625 {
2626 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2627 exception);
2628 return((MagickRealType) hypot((double) alpha,(double) *beta));
2629 }
2630 break;
2631 }
2632 case 'K':
2633 case 'k':
2634 {
2635 if (LocaleCompare(expression,"k") == 0)
2636 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2637 break;
2638 }
2639 case 'I':
2640 case 'i':
2641 {
2642 if (LocaleCompare(expression,"intensity") == 0)
2643 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2644 if (LocaleNCompare(expression,"int",3) == 0)
2645 {
2646 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2647 exception);
cristy16788e42010-08-13 13:44:26 +00002648 return((MagickRealType) floor(alpha));
cristy3ed852e2009-09-05 21:47:34 +00002649 }
cristy639399c2011-11-02 19:16:15 +00002650 if (LocaleNCompare(expression,"isnan",5) == 0)
2651 {
2652 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2653 exception);
cristy17a10202011-11-02 19:17:04 +00002654 return((MagickRealType) !!isnan((double) alpha));
cristy639399c2011-11-02 19:16:15 +00002655 }
cristy3ed852e2009-09-05 21:47:34 +00002656 if (LocaleCompare(expression,"i") == 0)
2657 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2658 break;
2659 }
2660 case 'J':
2661 case 'j':
2662 {
2663 if (LocaleCompare(expression,"j") == 0)
2664 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
cristy161b9262010-03-20 19:34:32 +00002665#if defined(MAGICKCORE_HAVE_J0)
cristyee56cf12010-03-01 22:17:06 +00002666 if (LocaleNCompare(expression,"j0",2) == 0)
2667 {
2668 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2669 exception);
2670 return((MagickRealType) j0((double) alpha));
2671 }
cristy161b9262010-03-20 19:34:32 +00002672#endif
2673#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002674 if (LocaleNCompare(expression,"j1",2) == 0)
2675 {
2676 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2677 exception);
2678 return((MagickRealType) j1((double) alpha));
2679 }
cristy161b9262010-03-20 19:34:32 +00002680#endif
cristyaa018fa2010-04-08 23:03:54 +00002681#if defined(MAGICKCORE_HAVE_J1)
cristya6a09e72010-03-02 14:51:02 +00002682 if (LocaleNCompare(expression,"jinc",4) == 0)
2683 {
2684 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2685 exception);
cristy0946a822010-03-12 17:14:58 +00002686 if (alpha == 0.0)
2687 return(1.0);
cristy69928f92010-03-12 13:27:09 +00002688 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
cristyfce2f7b2010-03-12 00:29:49 +00002689 (MagickPI*alpha));
2690 return(gamma);
cristya6a09e72010-03-02 14:51:02 +00002691 }
cristyaa018fa2010-04-08 23:03:54 +00002692#endif
cristy3ed852e2009-09-05 21:47:34 +00002693 break;
2694 }
2695 case 'L':
2696 case 'l':
2697 {
2698 if (LocaleNCompare(expression,"ln",2) == 0)
2699 {
2700 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2701 exception);
2702 return((MagickRealType) log((double) alpha));
2703 }
cristyc8ed5322010-08-31 12:07:59 +00002704 if (LocaleNCompare(expression,"logtwo",6) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002705 {
cristyc8ed5322010-08-31 12:07:59 +00002706 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
cristy3ed852e2009-09-05 21:47:34 +00002707 exception);
2708 return((MagickRealType) log10((double) alpha))/log10(2.0);
2709 }
2710 if (LocaleNCompare(expression,"log",3) == 0)
2711 {
2712 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2713 exception);
2714 return((MagickRealType) log10((double) alpha));
2715 }
2716 if (LocaleCompare(expression,"lightness") == 0)
2717 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2718 break;
2719 }
2720 case 'M':
2721 case 'm':
2722 {
2723 if (LocaleCompare(expression,"MaxRGB") == 0)
2724 return((MagickRealType) QuantumRange);
2725 if (LocaleNCompare(expression,"maxima",6) == 0)
2726 break;
2727 if (LocaleNCompare(expression,"max",3) == 0)
2728 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2729 if (LocaleNCompare(expression,"minima",6) == 0)
2730 break;
2731 if (LocaleNCompare(expression,"min",3) == 0)
2732 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2733 if (LocaleNCompare(expression,"mod",3) == 0)
2734 {
2735 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2736 exception);
2737 return((MagickRealType) fmod((double) alpha,(double) *beta));
2738 }
2739 if (LocaleCompare(expression,"m") == 0)
2740 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2741 break;
2742 }
2743 case 'N':
2744 case 'n':
2745 {
cristyad3502e2011-11-02 19:10:45 +00002746 if (LocaleNCompare(expression,"not",3) == 0)
2747 {
2748 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2749 exception);
2750 return((MagickRealType) (alpha < MagickEpsilon));
2751 }
cristy3ed852e2009-09-05 21:47:34 +00002752 if (LocaleCompare(expression,"n") == 0)
2753 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2754 break;
2755 }
2756 case 'O':
2757 case 'o':
2758 {
2759 if (LocaleCompare(expression,"Opaque") == 0)
2760 return(1.0);
2761 if (LocaleCompare(expression,"o") == 0)
2762 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2763 break;
2764 }
2765 case 'P':
2766 case 'p':
2767 {
cristy670aa3c2011-11-03 00:54:00 +00002768 if (LocaleCompare(expression,"phi") == 0)
2769 return((MagickRealType) MagickPHI);
cristy3ed852e2009-09-05 21:47:34 +00002770 if (LocaleCompare(expression,"pi") == 0)
2771 return((MagickRealType) MagickPI);
2772 if (LocaleNCompare(expression,"pow",3) == 0)
2773 {
2774 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2775 exception);
2776 return((MagickRealType) pow((double) alpha,(double) *beta));
2777 }
2778 if (LocaleCompare(expression,"p") == 0)
2779 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2780 break;
2781 }
2782 case 'Q':
2783 case 'q':
2784 {
2785 if (LocaleCompare(expression,"QuantumRange") == 0)
2786 return((MagickRealType) QuantumRange);
2787 if (LocaleCompare(expression,"QuantumScale") == 0)
2788 return((MagickRealType) QuantumScale);
2789 break;
2790 }
2791 case 'R':
2792 case 'r':
2793 {
2794 if (LocaleNCompare(expression,"rand",4) == 0)
2795 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2796 if (LocaleNCompare(expression,"round",5) == 0)
2797 {
2798 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2799 exception);
cristy16788e42010-08-13 13:44:26 +00002800 return((MagickRealType) floor((double) alpha+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002801 }
2802 if (LocaleCompare(expression,"r") == 0)
2803 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2804 break;
2805 }
2806 case 'S':
2807 case 's':
2808 {
2809 if (LocaleCompare(expression,"saturation") == 0)
2810 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2811 if (LocaleNCompare(expression,"sign",4) == 0)
2812 {
2813 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2814 exception);
2815 return(alpha < 0.0 ? -1.0 : 1.0);
2816 }
cristya6a09e72010-03-02 14:51:02 +00002817 if (LocaleNCompare(expression,"sinc",4) == 0)
2818 {
2819 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2820 exception);
2821 if (alpha == 0)
2822 return(1.0);
2823 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2824 (MagickPI*alpha));
2825 return(gamma);
2826 }
cristy3ed852e2009-09-05 21:47:34 +00002827 if (LocaleNCompare(expression,"sinh",4) == 0)
2828 {
2829 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2830 exception);
2831 return((MagickRealType) sinh((double) alpha));
2832 }
2833 if (LocaleNCompare(expression,"sin",3) == 0)
2834 {
2835 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2836 exception);
2837 return((MagickRealType) sin((double) alpha));
2838 }
2839 if (LocaleNCompare(expression,"sqrt",4) == 0)
2840 {
2841 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2842 exception);
2843 return((MagickRealType) sqrt((double) alpha));
2844 }
cristy9eeedea2011-11-02 19:04:05 +00002845 if (LocaleNCompare(expression,"squish",6) == 0)
2846 {
2847 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2848 exception);
2849 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2850 }
cristy3ed852e2009-09-05 21:47:34 +00002851 if (LocaleCompare(expression,"s") == 0)
2852 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2853 break;
2854 }
2855 case 'T':
2856 case 't':
2857 {
2858 if (LocaleNCompare(expression,"tanh",4) == 0)
2859 {
2860 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2861 exception);
2862 return((MagickRealType) tanh((double) alpha));
2863 }
2864 if (LocaleNCompare(expression,"tan",3) == 0)
2865 {
2866 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2867 exception);
2868 return((MagickRealType) tan((double) alpha));
2869 }
2870 if (LocaleCompare(expression,"Transparent") == 0)
2871 return(0.0);
cristy16788e42010-08-13 13:44:26 +00002872 if (LocaleNCompare(expression,"trunc",5) == 0)
2873 {
2874 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2875 exception);
2876 if (alpha >= 0.0)
2877 return((MagickRealType) floor((double) alpha));
2878 return((MagickRealType) ceil((double) alpha));
2879 }
cristy3ed852e2009-09-05 21:47:34 +00002880 if (LocaleCompare(expression,"t") == 0)
2881 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2882 break;
2883 }
2884 case 'U':
2885 case 'u':
2886 {
2887 if (LocaleCompare(expression,"u") == 0)
2888 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2889 break;
2890 }
2891 case 'V':
2892 case 'v':
2893 {
2894 if (LocaleCompare(expression,"v") == 0)
2895 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2896 break;
2897 }
2898 case 'W':
2899 case 'w':
2900 {
cristy9eeedea2011-11-02 19:04:05 +00002901 if (LocaleNCompare(expression,"while",5) == 0)
2902 {
2903 do
2904 {
2905 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2906 exception);
2907 } while (fabs((double) alpha) >= MagickEpsilon);
2908 return((MagickRealType) *beta);
2909 }
cristy3ed852e2009-09-05 21:47:34 +00002910 if (LocaleCompare(expression,"w") == 0)
2911 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2912 break;
2913 }
2914 case 'Y':
2915 case 'y':
2916 {
2917 if (LocaleCompare(expression,"y") == 0)
2918 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2919 break;
2920 }
2921 case 'Z':
2922 case 'z':
2923 {
2924 if (LocaleCompare(expression,"z") == 0)
2925 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2926 break;
2927 }
2928 default:
2929 break;
2930 }
2931 q=(char *) expression;
cristyc1acd842011-05-19 23:05:47 +00002932 alpha=InterpretLocaleValue(expression,&q);
cristy3ed852e2009-09-05 21:47:34 +00002933 if (q == expression)
2934 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2935 return(alpha);
2936}
2937
cristy7832dc22011-09-05 01:21:53 +00002938MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
cristy3ed852e2009-09-05 21:47:34 +00002939 MagickRealType *alpha,ExceptionInfo *exception)
2940{
2941 MagickBooleanType
2942 status;
2943
cristy541ae572011-08-05 19:08:59 +00002944 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2945 exception);
cristy3ed852e2009-09-05 21:47:34 +00002946 return(status);
2947}
2948
2949MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2950 MagickRealType *alpha,ExceptionInfo *exception)
2951{
2952 FILE
2953 *file;
2954
2955 MagickBooleanType
2956 status;
2957
2958 file=fx_info->file;
2959 fx_info->file=(FILE *) NULL;
cristy541ae572011-08-05 19:08:59 +00002960 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2961 exception);
cristy3ed852e2009-09-05 21:47:34 +00002962 fx_info->file=file;
2963 return(status);
2964}
2965
cristy7832dc22011-09-05 01:21:53 +00002966MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002967 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristye85007d2010-06-06 22:51:36 +00002968 MagickRealType *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002969{
2970 MagickRealType
2971 beta;
2972
2973 beta=0.0;
2974 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2975 exception);
2976 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2977}
2978
2979/*
2980%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2981% %
2982% %
2983% %
2984% F x I m a g e %
2985% %
2986% %
2987% %
2988%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2989%
2990% FxImage() applies a mathematical expression to the specified image.
2991%
2992% The format of the FxImage method is:
2993%
2994% Image *FxImage(const Image *image,const char *expression,
2995% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002996%
2997% A description of each parameter follows:
2998%
2999% o image: the image.
3000%
cristy3ed852e2009-09-05 21:47:34 +00003001% o expression: A mathematical expression.
3002%
3003% o exception: return any errors or warnings in this structure.
3004%
3005*/
3006
3007static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
3008{
cristybb503372010-05-27 20:51:26 +00003009 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003010 i;
3011
3012 assert(fx_info != (FxInfo **) NULL);
cristybb503372010-05-27 20:51:26 +00003013 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
cristy3ed852e2009-09-05 21:47:34 +00003014 if (fx_info[i] != (FxInfo *) NULL)
3015 fx_info[i]=DestroyFxInfo(fx_info[i]);
cristyb41ee102010-10-04 16:46:15 +00003016 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00003017 return(fx_info);
3018}
3019
3020static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
3021 ExceptionInfo *exception)
3022{
3023 char
3024 *fx_expression;
3025
3026 FxInfo
3027 **fx_info;
3028
3029 MagickRealType
3030 alpha;
3031
cristybb503372010-05-27 20:51:26 +00003032 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003033 i;
3034
cristybb503372010-05-27 20:51:26 +00003035 size_t
cristy3ed852e2009-09-05 21:47:34 +00003036 number_threads;
3037
3038 number_threads=GetOpenMPMaximumThreads();
cristyb41ee102010-10-04 16:46:15 +00003039 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +00003040 if (fx_info == (FxInfo **) NULL)
3041 return((FxInfo **) NULL);
3042 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
3043 if (*expression != '@')
3044 fx_expression=ConstantString(expression);
3045 else
3046 fx_expression=FileToString(expression+1,~0,exception);
cristybb503372010-05-27 20:51:26 +00003047 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +00003048 {
3049 fx_info[i]=AcquireFxInfo(image,fx_expression);
3050 if (fx_info[i] == (FxInfo *) NULL)
3051 return(DestroyFxThreadSet(fx_info));
3052 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
3053 }
3054 fx_expression=DestroyString(fx_expression);
3055 return(fx_info);
3056}
3057
3058MagickExport Image *FxImage(const Image *image,const char *expression,
3059 ExceptionInfo *exception)
3060{
cristy3ed852e2009-09-05 21:47:34 +00003061#define FxImageTag "Fx/Image"
3062
cristyfa112112010-01-04 17:48:07 +00003063 CacheView
cristy79cedc72011-07-25 00:41:15 +00003064 *fx_view,
3065 *image_view;
cristyfa112112010-01-04 17:48:07 +00003066
cristy3ed852e2009-09-05 21:47:34 +00003067 FxInfo
cristyfa112112010-01-04 17:48:07 +00003068 **restrict fx_info;
cristy3ed852e2009-09-05 21:47:34 +00003069
3070 Image
3071 *fx_image;
3072
cristy3ed852e2009-09-05 21:47:34 +00003073 MagickBooleanType
3074 status;
3075
cristybb503372010-05-27 20:51:26 +00003076 MagickOffsetType
3077 progress;
3078
cristy3ed852e2009-09-05 21:47:34 +00003079 MagickRealType
3080 alpha;
3081
cristybb503372010-05-27 20:51:26 +00003082 ssize_t
3083 y;
3084
cristy3ed852e2009-09-05 21:47:34 +00003085 assert(image != (Image *) NULL);
3086 assert(image->signature == MagickSignature);
3087 if (image->debug != MagickFalse)
3088 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy79cedc72011-07-25 00:41:15 +00003089 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00003090 if (fx_image == (Image *) NULL)
3091 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003092 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003093 {
cristy3ed852e2009-09-05 21:47:34 +00003094 fx_image=DestroyImage(fx_image);
3095 return((Image *) NULL);
3096 }
3097 fx_info=AcquireFxThreadSet(image,expression,exception);
3098 if (fx_info == (FxInfo **) NULL)
3099 {
3100 fx_image=DestroyImage(fx_image);
3101 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3102 }
3103 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3104 if (status == MagickFalse)
3105 {
3106 fx_image=DestroyImage(fx_image);
3107 fx_info=DestroyFxThreadSet(fx_info);
3108 return((Image *) NULL);
3109 }
3110 /*
3111 Fx image.
3112 */
3113 status=MagickTrue;
3114 progress=0;
cristy79cedc72011-07-25 00:41:15 +00003115 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003116 fx_view=AcquireCacheView(fx_image);
cristyb5d5f722009-11-04 03:03:49 +00003117#if defined(MAGICKCORE_OPENMP_SUPPORT)
3118 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003119#endif
cristybb503372010-05-27 20:51:26 +00003120 for (y=0; y < (ssize_t) fx_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003121 {
cristy5c9e6f22010-09-17 17:31:01 +00003122 const int
3123 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00003124
cristy79cedc72011-07-25 00:41:15 +00003125 register const Quantum
3126 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003127
cristy4c08aed2011-07-01 19:47:50 +00003128 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003129 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003130
cristy79cedc72011-07-25 00:41:15 +00003131 register ssize_t
3132 x;
3133
cristy3ed852e2009-09-05 21:47:34 +00003134 if (status == MagickFalse)
3135 continue;
cristy79cedc72011-07-25 00:41:15 +00003136 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003137 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
cristy79cedc72011-07-25 00:41:15 +00003138 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003139 {
3140 status=MagickFalse;
3141 continue;
3142 }
cristybb503372010-05-27 20:51:26 +00003143 for (x=0; x < (ssize_t) fx_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003144 {
cristy79cedc72011-07-25 00:41:15 +00003145 register ssize_t
3146 i;
3147
3148 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3149 {
3150 MagickRealType
3151 alpha;
3152
3153 PixelChannel
3154 channel;
3155
3156 PixelTrait
3157 fx_traits,
3158 traits;
3159
3160 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
cristy79cedc72011-07-25 00:41:15 +00003161 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3162 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
cristy010d7d12011-08-31 01:02:48 +00003163 if ((traits == UndefinedPixelTrait) ||
3164 (fx_traits == UndefinedPixelTrait))
cristy79cedc72011-07-25 00:41:15 +00003165 continue;
3166 if ((fx_traits & CopyPixelTrait) != 0)
3167 {
cristy0beccfa2011-09-25 20:47:53 +00003168 SetPixelChannel(fx_image,channel,p[i],q);
cristy79cedc72011-07-25 00:41:15 +00003169 continue;
3170 }
3171 alpha=0.0;
cristy0568ffc2011-07-25 16:54:14 +00003172 (void) FxEvaluateChannelExpression(fx_info[id],(PixelChannel) i,x,y,
3173 &alpha,exception);
cristyb3a73b52011-07-26 01:34:43 +00003174 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
cristy79cedc72011-07-25 00:41:15 +00003175 }
3176 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003177 q+=GetPixelChannels(fx_image);
cristy3ed852e2009-09-05 21:47:34 +00003178 }
3179 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3180 status=MagickFalse;
3181 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3182 {
3183 MagickBooleanType
3184 proceed;
3185
cristyb5d5f722009-11-04 03:03:49 +00003186#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy490408a2011-07-07 14:42:05 +00003187 #pragma omp critical (MagickCore_FxImage)
cristy3ed852e2009-09-05 21:47:34 +00003188#endif
3189 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3190 if (proceed == MagickFalse)
3191 status=MagickFalse;
3192 }
3193 }
cristy3ed852e2009-09-05 21:47:34 +00003194 fx_view=DestroyCacheView(fx_view);
cristy79cedc72011-07-25 00:41:15 +00003195 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003196 fx_info=DestroyFxThreadSet(fx_info);
3197 if (status == MagickFalse)
3198 fx_image=DestroyImage(fx_image);
3199 return(fx_image);
3200}
3201
3202/*
3203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3204% %
3205% %
3206% %
3207% I m p l o d e I m a g e %
3208% %
3209% %
3210% %
3211%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3212%
3213% ImplodeImage() creates a new image that is a copy of an existing
3214% one with the image pixels "implode" by the specified percentage. It
3215% allocates the memory necessary for the new Image structure and returns a
3216% pointer to the new image.
3217%
3218% The format of the ImplodeImage method is:
3219%
3220% Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003221% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003222%
3223% A description of each parameter follows:
3224%
3225% o implode_image: Method ImplodeImage returns a pointer to the image
3226% after it is implode. A null image is returned if there is a memory
3227% shortage.
3228%
3229% o image: the image.
3230%
3231% o amount: Define the extent of the implosion.
3232%
cristy76f512e2011-09-12 01:26:56 +00003233% o method: the pixel interpolation method.
3234%
cristy3ed852e2009-09-05 21:47:34 +00003235% o exception: return any errors or warnings in this structure.
3236%
3237*/
3238MagickExport Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003239 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003240{
3241#define ImplodeImageTag "Implode/Image"
3242
cristyfa112112010-01-04 17:48:07 +00003243 CacheView
3244 *image_view,
3245 *implode_view;
3246
cristy3ed852e2009-09-05 21:47:34 +00003247 Image
3248 *implode_image;
3249
cristy3ed852e2009-09-05 21:47:34 +00003250 MagickBooleanType
3251 status;
3252
cristybb503372010-05-27 20:51:26 +00003253 MagickOffsetType
3254 progress;
3255
cristy3ed852e2009-09-05 21:47:34 +00003256 MagickRealType
3257 radius;
3258
3259 PointInfo
3260 center,
3261 scale;
3262
cristybb503372010-05-27 20:51:26 +00003263 ssize_t
3264 y;
3265
cristy3ed852e2009-09-05 21:47:34 +00003266 /*
3267 Initialize implode image attributes.
3268 */
3269 assert(image != (Image *) NULL);
3270 assert(image->signature == MagickSignature);
3271 if (image->debug != MagickFalse)
3272 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3273 assert(exception != (ExceptionInfo *) NULL);
3274 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00003275 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3276 exception);
cristy3ed852e2009-09-05 21:47:34 +00003277 if (implode_image == (Image *) NULL)
3278 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003279 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003280 {
cristy3ed852e2009-09-05 21:47:34 +00003281 implode_image=DestroyImage(implode_image);
3282 return((Image *) NULL);
3283 }
cristy4c08aed2011-07-01 19:47:50 +00003284 if (implode_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00003285 implode_image->matte=MagickTrue;
3286 /*
3287 Compute scaling factor.
3288 */
3289 scale.x=1.0;
3290 scale.y=1.0;
3291 center.x=0.5*image->columns;
3292 center.y=0.5*image->rows;
3293 radius=center.x;
3294 if (image->columns > image->rows)
3295 scale.y=(double) image->columns/(double) image->rows;
3296 else
3297 if (image->columns < image->rows)
3298 {
3299 scale.x=(double) image->rows/(double) image->columns;
3300 radius=center.y;
3301 }
3302 /*
3303 Implode image.
3304 */
3305 status=MagickTrue;
3306 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00003307 image_view=AcquireCacheView(image);
3308 implode_view=AcquireCacheView(implode_image);
cristyb5d5f722009-11-04 03:03:49 +00003309#if defined(MAGICKCORE_OPENMP_SUPPORT)
3310 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003311#endif
cristybb503372010-05-27 20:51:26 +00003312 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003313 {
cristy3ed852e2009-09-05 21:47:34 +00003314 MagickRealType
3315 distance;
3316
3317 PointInfo
3318 delta;
3319
cristy6d188022011-09-12 13:23:33 +00003320 register const Quantum
3321 *restrict p;
3322
cristybb503372010-05-27 20:51:26 +00003323 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003324 x;
3325
cristy4c08aed2011-07-01 19:47:50 +00003326 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003327 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003328
3329 if (status == MagickFalse)
3330 continue;
cristy6d188022011-09-12 13:23:33 +00003331 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003332 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3333 exception);
cristy6d188022011-09-12 13:23:33 +00003334 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003335 {
3336 status=MagickFalse;
3337 continue;
3338 }
cristy3ed852e2009-09-05 21:47:34 +00003339 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00003340 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003341 {
cristy6d188022011-09-12 13:23:33 +00003342 register ssize_t
3343 i;
3344
cristy3ed852e2009-09-05 21:47:34 +00003345 /*
3346 Determine if the pixel is within an ellipse.
3347 */
3348 delta.x=scale.x*(double) (x-center.x);
3349 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00003350 if (distance >= (radius*radius))
3351 {
3352 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3353 q[i]=p[i];
3354 }
3355 else
cristy3ed852e2009-09-05 21:47:34 +00003356 {
3357 double
3358 factor;
3359
3360 /*
3361 Implode the pixel.
3362 */
3363 factor=1.0;
3364 if (distance > 0.0)
3365 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3366 radius/2)),-amount);
cristy76f512e2011-09-12 01:26:56 +00003367 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3368 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3369 scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00003370 }
cristy6d188022011-09-12 13:23:33 +00003371 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003372 q+=GetPixelChannels(implode_image);
cristy3ed852e2009-09-05 21:47:34 +00003373 }
3374 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3375 status=MagickFalse;
3376 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3377 {
3378 MagickBooleanType
3379 proceed;
3380
cristyb5d5f722009-11-04 03:03:49 +00003381#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003382 #pragma omp critical (MagickCore_ImplodeImage)
3383#endif
3384 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3385 if (proceed == MagickFalse)
3386 status=MagickFalse;
3387 }
3388 }
3389 implode_view=DestroyCacheView(implode_view);
3390 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003391 if (status == MagickFalse)
3392 implode_image=DestroyImage(implode_image);
3393 return(implode_image);
3394}
3395
3396/*
3397%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3398% %
3399% %
3400% %
3401% M o r p h I m a g e s %
3402% %
3403% %
3404% %
3405%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3406%
3407% The MorphImages() method requires a minimum of two images. The first
3408% image is transformed into the second by a number of intervening images
3409% as specified by frames.
3410%
3411% The format of the MorphImage method is:
3412%
cristybb503372010-05-27 20:51:26 +00003413% Image *MorphImages(const Image *image,const size_t number_frames,
cristy3ed852e2009-09-05 21:47:34 +00003414% ExceptionInfo *exception)
3415%
3416% A description of each parameter follows:
3417%
3418% o image: the image.
3419%
3420% o number_frames: Define the number of in-between image to generate.
3421% The more in-between frames, the smoother the morph.
3422%
3423% o exception: return any errors or warnings in this structure.
3424%
3425*/
3426MagickExport Image *MorphImages(const Image *image,
cristybb503372010-05-27 20:51:26 +00003427 const size_t number_frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003428{
3429#define MorphImageTag "Morph/Image"
3430
3431 Image
3432 *morph_image,
3433 *morph_images;
3434
cristy9d314ff2011-03-09 01:30:28 +00003435 MagickBooleanType
3436 status;
cristy3ed852e2009-09-05 21:47:34 +00003437
3438 MagickOffsetType
3439 scene;
3440
3441 MagickRealType
3442 alpha,
3443 beta;
3444
3445 register const Image
3446 *next;
3447
cristybb503372010-05-27 20:51:26 +00003448 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003449 i;
3450
cristy9d314ff2011-03-09 01:30:28 +00003451 ssize_t
3452 y;
cristy3ed852e2009-09-05 21:47:34 +00003453
3454 /*
3455 Clone first frame in sequence.
3456 */
3457 assert(image != (Image *) NULL);
3458 assert(image->signature == MagickSignature);
3459 if (image->debug != MagickFalse)
3460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3461 assert(exception != (ExceptionInfo *) NULL);
3462 assert(exception->signature == MagickSignature);
3463 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3464 if (morph_images == (Image *) NULL)
3465 return((Image *) NULL);
3466 if (GetNextImageInList(image) == (Image *) NULL)
3467 {
3468 /*
3469 Morph single image.
3470 */
cristybb503372010-05-27 20:51:26 +00003471 for (i=1; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003472 {
3473 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3474 if (morph_image == (Image *) NULL)
3475 {
3476 morph_images=DestroyImageList(morph_images);
3477 return((Image *) NULL);
3478 }
3479 AppendImageToList(&morph_images,morph_image);
cristy8b27a6d2010-02-14 03:31:15 +00003480 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003481 {
cristy8b27a6d2010-02-14 03:31:15 +00003482 MagickBooleanType
3483 proceed;
3484
cristybb503372010-05-27 20:51:26 +00003485 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3486 number_frames);
cristy8b27a6d2010-02-14 03:31:15 +00003487 if (proceed == MagickFalse)
3488 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003489 }
3490 }
3491 return(GetFirstImageInList(morph_images));
3492 }
3493 /*
3494 Morph image sequence.
3495 */
3496 status=MagickTrue;
3497 scene=0;
3498 next=image;
3499 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3500 {
cristybb503372010-05-27 20:51:26 +00003501 for (i=0; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003502 {
3503 CacheView
3504 *image_view,
3505 *morph_view;
3506
3507 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3508 alpha=1.0-beta;
cristy15b98cd2010-09-12 19:42:50 +00003509 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
cristybb503372010-05-27 20:51:26 +00003510 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
cristy15b98cd2010-09-12 19:42:50 +00003511 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3512 next->filter,next->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003513 if (morph_image == (Image *) NULL)
3514 {
3515 morph_images=DestroyImageList(morph_images);
3516 return((Image *) NULL);
3517 }
cristy574cc262011-08-05 01:23:58 +00003518 if (SetImageStorageClass(morph_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003519 {
cristy3ed852e2009-09-05 21:47:34 +00003520 morph_image=DestroyImage(morph_image);
3521 return((Image *) NULL);
3522 }
3523 AppendImageToList(&morph_images,morph_image);
3524 morph_images=GetLastImageInList(morph_images);
cristy15b98cd2010-09-12 19:42:50 +00003525 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3526 morph_images->rows,GetNextImageInList(next)->filter,
3527 GetNextImageInList(next)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003528 if (morph_image == (Image *) NULL)
3529 {
3530 morph_images=DestroyImageList(morph_images);
3531 return((Image *) NULL);
3532 }
3533 image_view=AcquireCacheView(morph_image);
3534 morph_view=AcquireCacheView(morph_images);
cristyb5d5f722009-11-04 03:03:49 +00003535#if defined(MAGICKCORE_OPENMP_SUPPORT)
3536 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003537#endif
cristybb503372010-05-27 20:51:26 +00003538 for (y=0; y < (ssize_t) morph_images->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003539 {
3540 MagickBooleanType
3541 sync;
3542
cristy4c08aed2011-07-01 19:47:50 +00003543 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00003544 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003545
cristybb503372010-05-27 20:51:26 +00003546 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003547 x;
3548
cristy4c08aed2011-07-01 19:47:50 +00003549 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003550 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003551
3552 if (status == MagickFalse)
3553 continue;
3554 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3555 exception);
3556 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3557 exception);
cristy4c08aed2011-07-01 19:47:50 +00003558 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003559 {
3560 status=MagickFalse;
3561 continue;
3562 }
cristybb503372010-05-27 20:51:26 +00003563 for (x=0; x < (ssize_t) morph_images->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003564 {
cristy4c08aed2011-07-01 19:47:50 +00003565 SetPixelRed(morph_images,ClampToQuantum(alpha*
3566 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3567 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3568 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3569 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3570 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3571 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3572 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3573 if ((morph_image->colorspace == CMYKColorspace) &&
3574 (morph_images->colorspace == CMYKColorspace))
3575 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3576 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3577 q);
cristyed231572011-07-14 02:18:59 +00003578 p+=GetPixelChannels(morph_image);
3579 q+=GetPixelChannels(morph_images);
cristy3ed852e2009-09-05 21:47:34 +00003580 }
3581 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3582 if (sync == MagickFalse)
3583 status=MagickFalse;
3584 }
3585 morph_view=DestroyCacheView(morph_view);
3586 image_view=DestroyCacheView(image_view);
3587 morph_image=DestroyImage(morph_image);
3588 }
cristybb503372010-05-27 20:51:26 +00003589 if (i < (ssize_t) number_frames)
cristy3ed852e2009-09-05 21:47:34 +00003590 break;
3591 /*
3592 Clone last frame in sequence.
3593 */
3594 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3595 if (morph_image == (Image *) NULL)
3596 {
3597 morph_images=DestroyImageList(morph_images);
3598 return((Image *) NULL);
3599 }
3600 AppendImageToList(&morph_images,morph_image);
3601 morph_images=GetLastImageInList(morph_images);
3602 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3603 {
3604 MagickBooleanType
3605 proceed;
3606
cristyb5d5f722009-11-04 03:03:49 +00003607#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003608 #pragma omp critical (MagickCore_MorphImages)
3609#endif
3610 proceed=SetImageProgress(image,MorphImageTag,scene,
3611 GetImageListLength(image));
3612 if (proceed == MagickFalse)
3613 status=MagickFalse;
3614 }
3615 scene++;
3616 }
3617 if (GetNextImageInList(next) != (Image *) NULL)
3618 {
3619 morph_images=DestroyImageList(morph_images);
3620 return((Image *) NULL);
3621 }
3622 return(GetFirstImageInList(morph_images));
3623}
3624
3625/*
3626%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3627% %
3628% %
3629% %
3630% P l a s m a I m a g e %
3631% %
3632% %
3633% %
3634%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3635%
3636% PlasmaImage() initializes an image with plasma fractal values. The image
3637% must be initialized with a base color and the random number generator
3638% seeded before this method is called.
3639%
3640% The format of the PlasmaImage method is:
3641%
3642% MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
cristy5cbc0162011-08-29 00:36:28 +00003643% size_t attenuate,size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003644%
3645% A description of each parameter follows:
3646%
3647% o image: the image.
3648%
3649% o segment: Define the region to apply plasma fractals values.
3650%
glennrp7dae1ca2010-09-16 12:17:35 +00003651% o attenuate: Define the plasma attenuation factor.
cristy3ed852e2009-09-05 21:47:34 +00003652%
3653% o depth: Limit the plasma recursion depth.
3654%
cristy5cbc0162011-08-29 00:36:28 +00003655% o exception: return any errors or warnings in this structure.
3656%
cristy3ed852e2009-09-05 21:47:34 +00003657*/
3658
3659static inline Quantum PlasmaPixel(RandomInfo *random_info,
3660 const MagickRealType pixel,const MagickRealType noise)
3661{
3662 Quantum
3663 plasma;
3664
cristyce70c172010-01-07 17:15:30 +00003665 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
cristy3ed852e2009-09-05 21:47:34 +00003666 noise/2.0);
3667 return(plasma);
3668}
3669
cristyda1f9c12011-10-02 21:39:49 +00003670static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3671 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3672 const SegmentInfo *segment,size_t attenuate,size_t depth,
3673 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003674{
cristy3ed852e2009-09-05 21:47:34 +00003675 MagickRealType
3676 plasma;
3677
cristyda1f9c12011-10-02 21:39:49 +00003678 PixelChannel
3679 channel;
3680
3681 PixelTrait
3682 traits;
3683
3684 register const Quantum
3685 *restrict u,
3686 *restrict v;
3687
3688 register Quantum
3689 *restrict q;
3690
3691 register ssize_t
3692 i;
cristy3ed852e2009-09-05 21:47:34 +00003693
cristy9d314ff2011-03-09 01:30:28 +00003694 ssize_t
3695 x,
3696 x_mid,
3697 y,
3698 y_mid;
3699
cristy3ed852e2009-09-05 21:47:34 +00003700 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3701 return(MagickTrue);
3702 if (depth != 0)
3703 {
3704 SegmentInfo
3705 local_info;
3706
3707 /*
3708 Divide the area into quadrants and recurse.
3709 */
3710 depth--;
3711 attenuate++;
cristybb503372010-05-27 20:51:26 +00003712 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3713 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003714 local_info=(*segment);
3715 local_info.x2=(double) x_mid;
3716 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003717 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3718 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003719 local_info=(*segment);
3720 local_info.y1=(double) y_mid;
3721 local_info.x2=(double) x_mid;
cristyda1f9c12011-10-02 21:39:49 +00003722 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3723 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003724 local_info=(*segment);
3725 local_info.x1=(double) x_mid;
3726 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003727 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3728 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003729 local_info=(*segment);
3730 local_info.x1=(double) x_mid;
3731 local_info.y1=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003732 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3733 &local_info,attenuate,depth,exception));
cristy3ed852e2009-09-05 21:47:34 +00003734 }
cristybb503372010-05-27 20:51:26 +00003735 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3736 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003737 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3738 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3739 return(MagickFalse);
3740 /*
3741 Average pixels and apply plasma.
3742 */
cristy3ed852e2009-09-05 21:47:34 +00003743 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3744 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3745 {
cristy3ed852e2009-09-05 21:47:34 +00003746 /*
3747 Left pixel.
3748 */
cristybb503372010-05-27 20:51:26 +00003749 x=(ssize_t) ceil(segment->x1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003750 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3751 1,1,exception);
3752 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3753 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003754 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003755 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3756 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003757 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003758 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3759 {
3760 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3761 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3762 if (traits == UndefinedPixelTrait)
3763 continue;
3764 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3765 }
cristyc5c6f662010-09-22 14:23:02 +00003766 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003767 if (segment->x1 != segment->x2)
3768 {
3769 /*
3770 Right pixel.
3771 */
cristybb503372010-05-27 20:51:26 +00003772 x=(ssize_t) ceil(segment->x2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003773 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3774 1,1,exception);
3775 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3776 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003777 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003778 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3779 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003780 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003781 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3782 {
3783 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3784 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3785 if (traits == UndefinedPixelTrait)
3786 continue;
3787 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3788 }
cristyc5c6f662010-09-22 14:23:02 +00003789 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003790 }
3791 }
3792 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3793 {
3794 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3795 {
cristy3ed852e2009-09-05 21:47:34 +00003796 /*
3797 Bottom pixel.
3798 */
cristybb503372010-05-27 20:51:26 +00003799 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003800 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3801 1,1,exception);
3802 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3803 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003804 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003805 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3806 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003807 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003808 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3809 {
3810 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3811 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3812 if (traits == UndefinedPixelTrait)
3813 continue;
3814 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3815 }
cristyc5c6f662010-09-22 14:23:02 +00003816 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003817 }
3818 if (segment->y1 != segment->y2)
3819 {
cristy3ed852e2009-09-05 21:47:34 +00003820 /*
3821 Top pixel.
3822 */
cristybb503372010-05-27 20:51:26 +00003823 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003824 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3825 1,1,exception);
3826 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3827 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003828 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003829 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3830 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003831 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003832 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3833 {
3834 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3835 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3836 if (traits == UndefinedPixelTrait)
3837 continue;
3838 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3839 }
cristyc5c6f662010-09-22 14:23:02 +00003840 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003841 }
3842 }
3843 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3844 {
cristy3ed852e2009-09-05 21:47:34 +00003845 /*
3846 Middle pixel.
3847 */
cristybb503372010-05-27 20:51:26 +00003848 x=(ssize_t) ceil(segment->x1-0.5);
3849 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003850 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
cristybb503372010-05-27 20:51:26 +00003851 x=(ssize_t) ceil(segment->x2-0.5);
3852 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003853 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003854 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003855 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3856 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003857 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003858 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3859 {
3860 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3861 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3862 if (traits == UndefinedPixelTrait)
3863 continue;
3864 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3865 }
cristyc5c6f662010-09-22 14:23:02 +00003866 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003867 }
3868 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3869 return(MagickTrue);
3870 return(MagickFalse);
3871}
cristyda1f9c12011-10-02 21:39:49 +00003872
cristy3ed852e2009-09-05 21:47:34 +00003873MagickExport MagickBooleanType PlasmaImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00003874 const SegmentInfo *segment,size_t attenuate,size_t depth,
3875 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003876{
cristyc5c6f662010-09-22 14:23:02 +00003877 CacheView
cristyda1f9c12011-10-02 21:39:49 +00003878 *image_view,
3879 *u_view,
3880 *v_view;
cristyc5c6f662010-09-22 14:23:02 +00003881
cristy3ed852e2009-09-05 21:47:34 +00003882 MagickBooleanType
3883 status;
3884
3885 RandomInfo
3886 *random_info;
3887
3888 if (image->debug != MagickFalse)
3889 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3890 assert(image != (Image *) NULL);
3891 assert(image->signature == MagickSignature);
3892 if (image->debug != MagickFalse)
3893 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy5cbc0162011-08-29 00:36:28 +00003894 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristyc5c6f662010-09-22 14:23:02 +00003895 return(MagickFalse);
3896 image_view=AcquireCacheView(image);
cristyda1f9c12011-10-02 21:39:49 +00003897 u_view=AcquireCacheView(image);
3898 v_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003899 random_info=AcquireRandomInfo();
cristyda1f9c12011-10-02 21:39:49 +00003900 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3901 attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003902 random_info=DestroyRandomInfo(random_info);
cristyda1f9c12011-10-02 21:39:49 +00003903 v_view=DestroyCacheView(v_view);
3904 u_view=DestroyCacheView(u_view);
cristyc5c6f662010-09-22 14:23:02 +00003905 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003906 return(status);
3907}
3908
3909/*
3910%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3911% %
3912% %
3913% %
3914% P o l a r o i d I m a g e %
3915% %
3916% %
3917% %
3918%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3919%
3920% PolaroidImage() simulates a Polaroid picture.
3921%
3922% The format of the AnnotateImage method is:
3923%
3924% Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003925% const double angle,const PixelInterpolateMethod method,
3926% ExceptionInfo exception)
cristy3ed852e2009-09-05 21:47:34 +00003927%
3928% A description of each parameter follows:
3929%
3930% o image: the image.
3931%
3932% o draw_info: the draw info.
3933%
cristycee97112010-05-28 00:44:52 +00003934% o angle: Apply the effect along this angle.
cristy3ed852e2009-09-05 21:47:34 +00003935%
cristy5c4e2582011-09-11 19:21:03 +00003936% o method: the pixel interpolation method.
3937%
cristy3ed852e2009-09-05 21:47:34 +00003938% o exception: return any errors or warnings in this structure.
3939%
3940*/
3941MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003942 const double angle,const PixelInterpolateMethod method,
3943 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003944{
3945 const char
3946 *value;
3947
cristy3ed852e2009-09-05 21:47:34 +00003948 Image
3949 *bend_image,
3950 *caption_image,
3951 *flop_image,
3952 *picture_image,
3953 *polaroid_image,
3954 *rotate_image,
3955 *trim_image;
3956
cristybb503372010-05-27 20:51:26 +00003957 size_t
cristy3ed852e2009-09-05 21:47:34 +00003958 height;
3959
cristy9d314ff2011-03-09 01:30:28 +00003960 ssize_t
3961 quantum;
3962
cristy3ed852e2009-09-05 21:47:34 +00003963 /*
3964 Simulate a Polaroid picture.
3965 */
3966 assert(image != (Image *) NULL);
3967 assert(image->signature == MagickSignature);
3968 if (image->debug != MagickFalse)
3969 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3970 assert(exception != (ExceptionInfo *) NULL);
3971 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00003972 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
cristy3ed852e2009-09-05 21:47:34 +00003973 image->rows)/25.0,10.0);
3974 height=image->rows+2*quantum;
3975 caption_image=(Image *) NULL;
cristyd15e6592011-10-15 00:13:06 +00003976 value=GetImageProperty(image,"caption",exception);
cristy3ed852e2009-09-05 21:47:34 +00003977 if (value != (const char *) NULL)
3978 {
3979 char
3980 *caption,
3981 geometry[MaxTextExtent];
3982
3983 DrawInfo
3984 *annotate_info;
3985
cristy3ed852e2009-09-05 21:47:34 +00003986 MagickBooleanType
3987 status;
3988
cristy9d314ff2011-03-09 01:30:28 +00003989 ssize_t
3990 count;
3991
cristy3ed852e2009-09-05 21:47:34 +00003992 TypeMetric
3993 metrics;
3994
3995 /*
3996 Generate caption image.
3997 */
3998 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3999 if (caption_image == (Image *) NULL)
4000 return((Image *) NULL);
4001 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
4002 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
cristy018f07f2011-09-04 21:15:19 +00004003 value,exception);
cristy3ed852e2009-09-05 21:47:34 +00004004 (void) CloneString(&annotate_info->text,caption);
cristy6b1d05e2010-09-22 19:17:27 +00004005 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
cristy5cbc0162011-08-29 00:36:28 +00004006 &caption,exception);
cristybb503372010-05-27 20:51:26 +00004007 status=SetImageExtent(caption_image,image->columns,(size_t)
cristy63240882011-08-05 19:05:27 +00004008 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00004009 if (status == MagickFalse)
4010 caption_image=DestroyImage(caption_image);
4011 else
4012 {
4013 caption_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004014 (void) SetImageBackgroundColor(caption_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00004015 (void) CloneString(&annotate_info->text,caption);
cristyb51dff52011-05-19 16:55:47 +00004016 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
cristy3ed852e2009-09-05 21:47:34 +00004017 metrics.ascent);
4018 if (annotate_info->gravity == UndefinedGravity)
4019 (void) CloneString(&annotate_info->geometry,AcquireString(
4020 geometry));
cristy5cbc0162011-08-29 00:36:28 +00004021 (void) AnnotateImage(caption_image,annotate_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00004022 height+=caption_image->rows;
4023 }
4024 annotate_info=DestroyDrawInfo(annotate_info);
4025 caption=DestroyString(caption);
4026 }
4027 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
4028 exception);
4029 if (picture_image == (Image *) NULL)
4030 {
4031 if (caption_image != (Image *) NULL)
4032 caption_image=DestroyImage(caption_image);
4033 return((Image *) NULL);
4034 }
4035 picture_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004036 (void) SetImageBackgroundColor(picture_image,exception);
cristye941a752011-10-15 01:52:48 +00004037 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum,
4038 exception);
cristy3ed852e2009-09-05 21:47:34 +00004039 if (caption_image != (Image *) NULL)
4040 {
4041 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
cristye941a752011-10-15 01:52:48 +00004042 quantum,(ssize_t) (image->rows+3*quantum/2),exception);
cristy3ed852e2009-09-05 21:47:34 +00004043 caption_image=DestroyImage(caption_image);
4044 }
cristy9950d572011-10-01 18:22:35 +00004045 (void) QueryColorCompliance("none",AllCompliance,
4046 &picture_image->background_color,exception);
cristy63240882011-08-05 19:05:27 +00004047 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004048 rotate_image=RotateImage(picture_image,90.0,exception);
4049 picture_image=DestroyImage(picture_image);
4050 if (rotate_image == (Image *) NULL)
4051 return((Image *) NULL);
4052 picture_image=rotate_image;
4053 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
cristy5c4e2582011-09-11 19:21:03 +00004054 picture_image->columns,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00004055 picture_image=DestroyImage(picture_image);
4056 if (bend_image == (Image *) NULL)
4057 return((Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00004058 picture_image=bend_image;
4059 rotate_image=RotateImage(picture_image,-90.0,exception);
4060 picture_image=DestroyImage(picture_image);
4061 if (rotate_image == (Image *) NULL)
4062 return((Image *) NULL);
4063 picture_image=rotate_image;
4064 picture_image->background_color=image->background_color;
4065 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
4066 exception);
4067 if (polaroid_image == (Image *) NULL)
4068 {
4069 picture_image=DestroyImage(picture_image);
4070 return(picture_image);
4071 }
4072 flop_image=FlopImage(polaroid_image,exception);
4073 polaroid_image=DestroyImage(polaroid_image);
4074 if (flop_image == (Image *) NULL)
4075 {
4076 picture_image=DestroyImage(picture_image);
4077 return(picture_image);
4078 }
4079 polaroid_image=flop_image;
4080 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
cristye941a752011-10-15 01:52:48 +00004081 (ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
cristy3ed852e2009-09-05 21:47:34 +00004082 picture_image=DestroyImage(picture_image);
cristy9950d572011-10-01 18:22:35 +00004083 (void) QueryColorCompliance("none",AllCompliance,
4084 &polaroid_image->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00004085 rotate_image=RotateImage(polaroid_image,angle,exception);
4086 polaroid_image=DestroyImage(polaroid_image);
4087 if (rotate_image == (Image *) NULL)
4088 return((Image *) NULL);
4089 polaroid_image=rotate_image;
4090 trim_image=TrimImage(polaroid_image,exception);
4091 polaroid_image=DestroyImage(polaroid_image);
4092 if (trim_image == (Image *) NULL)
4093 return((Image *) NULL);
4094 polaroid_image=trim_image;
4095 return(polaroid_image);
4096}
4097
4098/*
4099%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4100% %
4101% %
4102% %
cristy3ed852e2009-09-05 21:47:34 +00004103% S e p i a T o n e I m a g e %
4104% %
4105% %
4106% %
4107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4108%
4109% MagickSepiaToneImage() applies a special effect to the image, similar to the
4110% effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4111% 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4112% threshold of 80% is a good starting point for a reasonable tone.
4113%
4114% The format of the SepiaToneImage method is:
4115%
4116% Image *SepiaToneImage(const Image *image,const double threshold,
4117% ExceptionInfo *exception)
4118%
4119% A description of each parameter follows:
4120%
4121% o image: the image.
4122%
4123% o threshold: the tone threshold.
4124%
4125% o exception: return any errors or warnings in this structure.
4126%
4127*/
4128MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4129 ExceptionInfo *exception)
4130{
4131#define SepiaToneImageTag "SepiaTone/Image"
4132
cristyc4c8d132010-01-07 01:58:38 +00004133 CacheView
4134 *image_view,
4135 *sepia_view;
4136
cristy3ed852e2009-09-05 21:47:34 +00004137 Image
4138 *sepia_image;
4139
cristy3ed852e2009-09-05 21:47:34 +00004140 MagickBooleanType
4141 status;
4142
cristybb503372010-05-27 20:51:26 +00004143 MagickOffsetType
4144 progress;
4145
4146 ssize_t
4147 y;
4148
cristy3ed852e2009-09-05 21:47:34 +00004149 /*
4150 Initialize sepia-toned image attributes.
4151 */
4152 assert(image != (const Image *) NULL);
4153 assert(image->signature == MagickSignature);
4154 if (image->debug != MagickFalse)
4155 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4156 assert(exception != (ExceptionInfo *) NULL);
4157 assert(exception->signature == MagickSignature);
4158 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4159 if (sepia_image == (Image *) NULL)
4160 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004161 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004162 {
cristy3ed852e2009-09-05 21:47:34 +00004163 sepia_image=DestroyImage(sepia_image);
4164 return((Image *) NULL);
4165 }
4166 /*
4167 Tone each row of the image.
4168 */
4169 status=MagickTrue;
4170 progress=0;
4171 image_view=AcquireCacheView(image);
4172 sepia_view=AcquireCacheView(sepia_image);
cristyb5d5f722009-11-04 03:03:49 +00004173#if defined(MAGICKCORE_OPENMP_SUPPORT)
4174 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004175#endif
cristybb503372010-05-27 20:51:26 +00004176 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004177 {
cristy4c08aed2011-07-01 19:47:50 +00004178 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004179 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00004180
cristybb503372010-05-27 20:51:26 +00004181 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004182 x;
4183
cristy4c08aed2011-07-01 19:47:50 +00004184 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004185 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004186
4187 if (status == MagickFalse)
4188 continue;
4189 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4190 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4191 exception);
cristy4c08aed2011-07-01 19:47:50 +00004192 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004193 {
4194 status=MagickFalse;
4195 continue;
4196 }
cristybb503372010-05-27 20:51:26 +00004197 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004198 {
4199 MagickRealType
4200 intensity,
4201 tone;
4202
cristy4c08aed2011-07-01 19:47:50 +00004203 intensity=(MagickRealType) GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00004204 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4205 (MagickRealType) QuantumRange-threshold;
cristy4c08aed2011-07-01 19:47:50 +00004206 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004207 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4208 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004209 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004210 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004211 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004212 tone=threshold/7.0;
cristy4c08aed2011-07-01 19:47:50 +00004213 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4214 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4215 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4216 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristyed231572011-07-14 02:18:59 +00004217 p+=GetPixelChannels(image);
4218 q+=GetPixelChannels(sepia_image);
cristy3ed852e2009-09-05 21:47:34 +00004219 }
4220 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4221 status=MagickFalse;
4222 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4223 {
4224 MagickBooleanType
4225 proceed;
4226
cristyb5d5f722009-11-04 03:03:49 +00004227#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004228 #pragma omp critical (MagickCore_SepiaToneImage)
4229#endif
4230 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4231 image->rows);
4232 if (proceed == MagickFalse)
4233 status=MagickFalse;
4234 }
4235 }
4236 sepia_view=DestroyCacheView(sepia_view);
4237 image_view=DestroyCacheView(image_view);
cristye23ec9d2011-08-16 18:15:40 +00004238 (void) NormalizeImage(sepia_image,exception);
4239 (void) ContrastImage(sepia_image,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004240 if (status == MagickFalse)
4241 sepia_image=DestroyImage(sepia_image);
4242 return(sepia_image);
4243}
4244
4245/*
4246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4247% %
4248% %
4249% %
4250% S h a d o w I m a g e %
4251% %
4252% %
4253% %
4254%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4255%
4256% ShadowImage() simulates a shadow from the specified image and returns it.
4257%
4258% The format of the ShadowImage method is:
4259%
4260% Image *ShadowImage(const Image *image,const double opacity,
cristybb503372010-05-27 20:51:26 +00004261% const double sigma,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004262% ExceptionInfo *exception)
4263%
4264% A description of each parameter follows:
4265%
4266% o image: the image.
4267%
4268% o opacity: percentage transparency.
4269%
4270% o sigma: the standard deviation of the Gaussian, in pixels.
4271%
4272% o x_offset: the shadow x-offset.
4273%
4274% o y_offset: the shadow y-offset.
4275%
4276% o exception: return any errors or warnings in this structure.
4277%
4278*/
4279MagickExport Image *ShadowImage(const Image *image,const double opacity,
cristybb503372010-05-27 20:51:26 +00004280 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004281 ExceptionInfo *exception)
4282{
4283#define ShadowImageTag "Shadow/Image"
4284
cristybd5a96c2011-08-21 00:04:26 +00004285 ChannelType
4286 channel_mask;
4287
cristy3ed852e2009-09-05 21:47:34 +00004288 Image
4289 *border_image,
4290 *clone_image,
4291 *shadow_image;
4292
cristy3ed852e2009-09-05 21:47:34 +00004293 RectangleInfo
4294 border_info;
4295
cristy3ed852e2009-09-05 21:47:34 +00004296 assert(image != (Image *) NULL);
4297 assert(image->signature == MagickSignature);
4298 if (image->debug != MagickFalse)
4299 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4300 assert(exception != (ExceptionInfo *) NULL);
4301 assert(exception->signature == MagickSignature);
4302 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4303 if (clone_image == (Image *) NULL)
4304 return((Image *) NULL);
4305 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4306 clone_image->compose=OverCompositeOp;
cristybb503372010-05-27 20:51:26 +00004307 border_info.width=(size_t) floor(2.0*sigma+0.5);
4308 border_info.height=(size_t) floor(2.0*sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00004309 border_info.x=0;
4310 border_info.y=0;
cristy9950d572011-10-01 18:22:35 +00004311 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4312 exception);
cristy633f0c62011-09-15 13:27:36 +00004313 border_image=BorderImage(clone_image,&border_info,image->compose,exception);
cristy3ed852e2009-09-05 21:47:34 +00004314 clone_image=DestroyImage(clone_image);
4315 if (border_image == (Image *) NULL)
4316 return((Image *) NULL);
4317 if (border_image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00004318 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004319 /*
4320 Shadow image.
4321 */
cristyea1a8aa2011-10-20 13:24:06 +00004322 (void) SetImageBackgroundColor(border_image,exception);
cristybd5a96c2011-08-21 00:04:26 +00004323 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
cristy05c0c9a2011-09-05 23:16:13 +00004324 shadow_image=BlurImage(border_image,0.0,sigma,image->bias,exception);
cristybd5a96c2011-08-21 00:04:26 +00004325 (void) SetPixelChannelMap(border_image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00004326 border_image=DestroyImage(border_image);
4327 if (shadow_image == (Image *) NULL)
4328 return((Image *) NULL);
4329 if (shadow_image->page.width == 0)
4330 shadow_image->page.width=shadow_image->columns;
4331 if (shadow_image->page.height == 0)
4332 shadow_image->page.height=shadow_image->rows;
cristybb503372010-05-27 20:51:26 +00004333 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4334 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4335 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4336 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
cristy3ed852e2009-09-05 21:47:34 +00004337 return(shadow_image);
4338}
4339
4340/*
4341%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4342% %
4343% %
4344% %
4345% S k e t c h I m a g e %
4346% %
4347% %
4348% %
4349%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4350%
4351% SketchImage() simulates a pencil sketch. We convolve the image with a
4352% Gaussian operator of the given radius and standard deviation (sigma). For
4353% reasonable results, radius should be larger than sigma. Use a radius of 0
4354% and SketchImage() selects a suitable radius for you. Angle gives the angle
4355% of the sketch.
4356%
4357% The format of the SketchImage method is:
4358%
4359% Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004360% const double sigma,const double angle,const double bias,
4361% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004362%
4363% A description of each parameter follows:
4364%
4365% o image: the image.
4366%
cristy574cc262011-08-05 01:23:58 +00004367% o radius: the radius of the Gaussian, in pixels, not counting the
4368% center pixel.
cristy3ed852e2009-09-05 21:47:34 +00004369%
4370% o sigma: the standard deviation of the Gaussian, in pixels.
4371%
cristyf7ef0252011-09-09 14:50:06 +00004372% o angle: apply the effect along this angle.
4373%
4374% o bias: the bias.
cristy3ed852e2009-09-05 21:47:34 +00004375%
4376% o exception: return any errors or warnings in this structure.
4377%
4378*/
4379MagickExport Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004380 const double sigma,const double angle,const double bias,
4381 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004382{
cristyfa112112010-01-04 17:48:07 +00004383 CacheView
4384 *random_view;
4385
cristy3ed852e2009-09-05 21:47:34 +00004386 Image
4387 *blend_image,
4388 *blur_image,
4389 *dodge_image,
4390 *random_image,
4391 *sketch_image;
4392
cristy3ed852e2009-09-05 21:47:34 +00004393 MagickBooleanType
4394 status;
4395
cristy3ed852e2009-09-05 21:47:34 +00004396 RandomInfo
cristyfa112112010-01-04 17:48:07 +00004397 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +00004398
cristy9d314ff2011-03-09 01:30:28 +00004399 ssize_t
4400 y;
4401
cristy3ed852e2009-09-05 21:47:34 +00004402 /*
4403 Sketch image.
4404 */
4405 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4406 MagickTrue,exception);
4407 if (random_image == (Image *) NULL)
4408 return((Image *) NULL);
4409 status=MagickTrue;
cristy1b784432009-12-19 02:20:40 +00004410 random_info=AcquireRandomInfoThreadSet();
cristy3ed852e2009-09-05 21:47:34 +00004411 random_view=AcquireCacheView(random_image);
cristy1b784432009-12-19 02:20:40 +00004412#if defined(MAGICKCORE_OPENMP_SUPPORT)
4413 #pragma omp parallel for schedule(dynamic,4) shared(status)
4414#endif
cristybb503372010-05-27 20:51:26 +00004415 for (y=0; y < (ssize_t) random_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004416 {
cristy5c9e6f22010-09-17 17:31:01 +00004417 const int
4418 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00004419
cristybb503372010-05-27 20:51:26 +00004420 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004421 x;
4422
cristy4c08aed2011-07-01 19:47:50 +00004423 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004424 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004425
cristy1b784432009-12-19 02:20:40 +00004426 if (status == MagickFalse)
4427 continue;
cristy3ed852e2009-09-05 21:47:34 +00004428 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4429 exception);
cristyacd2ed22011-08-30 01:44:23 +00004430 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004431 {
4432 status=MagickFalse;
4433 continue;
4434 }
cristybb503372010-05-27 20:51:26 +00004435 for (x=0; x < (ssize_t) random_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004436 {
cristy76f512e2011-09-12 01:26:56 +00004437 MagickRealType
4438 value;
4439
4440 register ssize_t
4441 i;
4442
4443 value=GetPseudoRandomValue(random_info[id]);
4444 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4445 {
4446 PixelTrait
4447 traits;
4448
4449 traits=GetPixelChannelMapTraits(random_image,(PixelChannel) i);
4450 if (traits == UndefinedPixelTrait)
4451 continue;
4452 q[i]=ClampToQuantum(QuantumRange*value);
4453 }
cristyed231572011-07-14 02:18:59 +00004454 q+=GetPixelChannels(random_image);
cristy3ed852e2009-09-05 21:47:34 +00004455 }
4456 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4457 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004458 }
4459 random_view=DestroyCacheView(random_view);
cristy1b784432009-12-19 02:20:40 +00004460 random_info=DestroyRandomInfoThreadSet(random_info);
cristy3ed852e2009-09-05 21:47:34 +00004461 if (status == MagickFalse)
4462 {
4463 random_image=DestroyImage(random_image);
4464 return(random_image);
4465 }
cristyf7ef0252011-09-09 14:50:06 +00004466 blur_image=MotionBlurImage(random_image,radius,sigma,angle,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00004467 random_image=DestroyImage(random_image);
4468 if (blur_image == (Image *) NULL)
4469 return((Image *) NULL);
cristy8ae632d2011-09-05 17:29:53 +00004470 dodge_image=EdgeImage(blur_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00004471 blur_image=DestroyImage(blur_image);
4472 if (dodge_image == (Image *) NULL)
4473 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +00004474 (void) NormalizeImage(dodge_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +00004475 (void) NegateImage(dodge_image,MagickFalse,exception);
cristye941a752011-10-15 01:52:48 +00004476 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
cristy3ed852e2009-09-05 21:47:34 +00004477 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4478 if (sketch_image == (Image *) NULL)
4479 {
4480 dodge_image=DestroyImage(dodge_image);
4481 return((Image *) NULL);
4482 }
cristye941a752011-10-15 01:52:48 +00004483 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0,
4484 exception);
cristy3ed852e2009-09-05 21:47:34 +00004485 dodge_image=DestroyImage(dodge_image);
4486 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4487 if (blend_image == (Image *) NULL)
4488 {
4489 sketch_image=DestroyImage(sketch_image);
4490 return((Image *) NULL);
4491 }
4492 (void) SetImageArtifact(blend_image,"compose:args","20x80");
cristye941a752011-10-15 01:52:48 +00004493 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0,
4494 exception);
cristy3ed852e2009-09-05 21:47:34 +00004495 blend_image=DestroyImage(blend_image);
4496 return(sketch_image);
4497}
4498
4499/*
4500%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4501% %
4502% %
4503% %
4504% S o l a r i z e I m a g e %
4505% %
4506% %
4507% %
4508%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4509%
4510% SolarizeImage() applies a special effect to the image, similar to the effect
4511% achieved in a photo darkroom by selectively exposing areas of photo
4512% sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4513% measure of the extent of the solarization.
4514%
4515% The format of the SolarizeImage method is:
4516%
cristy5cbc0162011-08-29 00:36:28 +00004517% MagickBooleanType SolarizeImage(Image *image,const double threshold,
4518% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004519%
4520% A description of each parameter follows:
4521%
4522% o image: the image.
4523%
4524% o threshold: Define the extent of the solarization.
4525%
cristy5cbc0162011-08-29 00:36:28 +00004526% o exception: return any errors or warnings in this structure.
4527%
cristy3ed852e2009-09-05 21:47:34 +00004528*/
4529MagickExport MagickBooleanType SolarizeImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00004530 const double threshold,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004531{
4532#define SolarizeImageTag "Solarize/Image"
4533
cristyc4c8d132010-01-07 01:58:38 +00004534 CacheView
4535 *image_view;
4536
cristy3ed852e2009-09-05 21:47:34 +00004537 MagickBooleanType
4538 status;
4539
cristybb503372010-05-27 20:51:26 +00004540 MagickOffsetType
4541 progress;
4542
4543 ssize_t
4544 y;
4545
cristy3ed852e2009-09-05 21:47:34 +00004546 assert(image != (Image *) NULL);
4547 assert(image->signature == MagickSignature);
4548 if (image->debug != MagickFalse)
4549 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4550 if (image->storage_class == PseudoClass)
4551 {
cristybb503372010-05-27 20:51:26 +00004552 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004553 i;
4554
4555 /*
4556 Solarize colormap.
4557 */
cristybb503372010-05-27 20:51:26 +00004558 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00004559 {
4560 if ((MagickRealType) image->colormap[i].red > threshold)
4561 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4562 if ((MagickRealType) image->colormap[i].green > threshold)
4563 image->colormap[i].green=(Quantum) QuantumRange-
4564 image->colormap[i].green;
4565 if ((MagickRealType) image->colormap[i].blue > threshold)
4566 image->colormap[i].blue=(Quantum) QuantumRange-
4567 image->colormap[i].blue;
4568 }
4569 }
4570 /*
4571 Solarize image.
4572 */
4573 status=MagickTrue;
4574 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00004575 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00004576#if defined(MAGICKCORE_OPENMP_SUPPORT)
4577 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004578#endif
cristybb503372010-05-27 20:51:26 +00004579 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004580 {
cristybb503372010-05-27 20:51:26 +00004581 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004582 x;
4583
cristy4c08aed2011-07-01 19:47:50 +00004584 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004585 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004586
4587 if (status == MagickFalse)
4588 continue;
cristy5cbc0162011-08-29 00:36:28 +00004589 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004590 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004591 {
4592 status=MagickFalse;
4593 continue;
4594 }
cristybb503372010-05-27 20:51:26 +00004595 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004596 {
cristy76f512e2011-09-12 01:26:56 +00004597 register ssize_t
4598 i;
4599
4600 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4601 {
4602 PixelTrait
4603 traits;
4604
4605 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
4606 if ((traits == UndefinedPixelTrait) ||
4607 ((traits & CopyPixelTrait) != 0))
4608 continue;
4609 if ((MagickRealType) q[i] > threshold)
4610 q[i]=QuantumRange-q[i];
4611 }
cristyed231572011-07-14 02:18:59 +00004612 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004613 }
4614 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4615 status=MagickFalse;
4616 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4617 {
4618 MagickBooleanType
4619 proceed;
4620
cristyb5d5f722009-11-04 03:03:49 +00004621#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004622 #pragma omp critical (MagickCore_SolarizeImage)
4623#endif
4624 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4625 if (proceed == MagickFalse)
4626 status=MagickFalse;
4627 }
4628 }
4629 image_view=DestroyCacheView(image_view);
4630 return(status);
4631}
4632
4633/*
4634%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4635% %
4636% %
4637% %
4638% S t e g a n o I m a g e %
4639% %
4640% %
4641% %
4642%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4643%
4644% SteganoImage() hides a digital watermark within the image. Recover
4645% the hidden watermark later to prove that the authenticity of an image.
4646% Offset defines the start position within the image to hide the watermark.
4647%
4648% The format of the SteganoImage method is:
4649%
4650% Image *SteganoImage(const Image *image,Image *watermark,
4651% ExceptionInfo *exception)
4652%
4653% A description of each parameter follows:
4654%
4655% o image: the image.
4656%
4657% o watermark: the watermark image.
4658%
4659% o exception: return any errors or warnings in this structure.
4660%
4661*/
4662MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4663 ExceptionInfo *exception)
4664{
cristye1bf8ad2010-09-19 17:07:03 +00004665#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
cristy4c08aed2011-07-01 19:47:50 +00004666#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
cristyeaedf062010-05-29 22:36:02 +00004667 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
cristy3ed852e2009-09-05 21:47:34 +00004668#define SteganoImageTag "Stegano/Image"
4669
cristyb0d3bb92010-09-22 14:37:58 +00004670 CacheView
4671 *stegano_view,
4672 *watermark_view;
4673
cristy3ed852e2009-09-05 21:47:34 +00004674 Image
4675 *stegano_image;
4676
4677 int
4678 c;
4679
cristy3ed852e2009-09-05 21:47:34 +00004680 MagickBooleanType
4681 status;
4682
cristy101ab702011-10-13 13:06:32 +00004683 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00004684 pixel;
4685
cristy4c08aed2011-07-01 19:47:50 +00004686 register Quantum
cristy3ed852e2009-09-05 21:47:34 +00004687 *q;
4688
cristye1bf8ad2010-09-19 17:07:03 +00004689 register ssize_t
4690 x;
4691
cristybb503372010-05-27 20:51:26 +00004692 size_t
cristyeaedf062010-05-29 22:36:02 +00004693 depth,
4694 one;
cristy3ed852e2009-09-05 21:47:34 +00004695
cristye1bf8ad2010-09-19 17:07:03 +00004696 ssize_t
4697 i,
4698 j,
4699 k,
4700 y;
4701
cristy3ed852e2009-09-05 21:47:34 +00004702 /*
4703 Initialize steganographic image attributes.
4704 */
4705 assert(image != (const Image *) NULL);
4706 assert(image->signature == MagickSignature);
4707 if (image->debug != MagickFalse)
4708 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4709 assert(watermark != (const Image *) NULL);
4710 assert(watermark->signature == MagickSignature);
4711 assert(exception != (ExceptionInfo *) NULL);
4712 assert(exception->signature == MagickSignature);
cristyeaedf062010-05-29 22:36:02 +00004713 one=1UL;
cristy3ed852e2009-09-05 21:47:34 +00004714 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4715 if (stegano_image == (Image *) NULL)
4716 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004717 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004718 {
cristy3ed852e2009-09-05 21:47:34 +00004719 stegano_image=DestroyImage(stegano_image);
4720 return((Image *) NULL);
4721 }
4722 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4723 /*
4724 Hide watermark in low-order bits of image.
4725 */
4726 c=0;
4727 i=0;
4728 j=0;
4729 depth=stegano_image->depth;
4730 k=image->offset;
cristyda16f162011-02-19 23:52:17 +00004731 status=MagickTrue;
cristyb0d3bb92010-09-22 14:37:58 +00004732 watermark_view=AcquireCacheView(watermark);
4733 stegano_view=AcquireCacheView(stegano_image);
cristybb503372010-05-27 20:51:26 +00004734 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
cristy3ed852e2009-09-05 21:47:34 +00004735 {
cristybb503372010-05-27 20:51:26 +00004736 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
cristy3ed852e2009-09-05 21:47:34 +00004737 {
cristybb503372010-05-27 20:51:26 +00004738 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
cristy3ed852e2009-09-05 21:47:34 +00004739 {
cristyda1f9c12011-10-02 21:39:49 +00004740 Quantum
cristy5f95f4f2011-10-23 01:01:01 +00004741 virtual_pixel[CompositePixelChannel];
cristyda1f9c12011-10-02 21:39:49 +00004742
4743 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,virtual_pixel,
4744 exception);
4745 pixel.red=(double) virtual_pixel[RedPixelChannel];
4746 pixel.green=(double) virtual_pixel[GreenPixelChannel];
4747 pixel.blue=(double) virtual_pixel[BluePixelChannel];
4748 pixel.alpha=(double) virtual_pixel[AlphaPixelChannel];
cristybb503372010-05-27 20:51:26 +00004749 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
cristy3ed852e2009-09-05 21:47:34 +00004750 break;
cristyb0d3bb92010-09-22 14:37:58 +00004751 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4752 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4753 exception);
cristyacd2ed22011-08-30 01:44:23 +00004754 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004755 break;
4756 switch (c)
4757 {
4758 case 0:
4759 {
cristy4c08aed2011-07-01 19:47:50 +00004760 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004761 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004762 break;
4763 }
4764 case 1:
4765 {
cristy4c08aed2011-07-01 19:47:50 +00004766 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004767 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004768 break;
4769 }
4770 case 2:
4771 {
cristy4c08aed2011-07-01 19:47:50 +00004772 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004773 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004774 break;
4775 }
4776 }
cristyb0d3bb92010-09-22 14:37:58 +00004777 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004778 break;
4779 c++;
4780 if (c == 3)
4781 c=0;
4782 k++;
cristybb503372010-05-27 20:51:26 +00004783 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
cristy3ed852e2009-09-05 21:47:34 +00004784 k=0;
4785 if (k == image->offset)
4786 j++;
4787 }
4788 }
cristy8b27a6d2010-02-14 03:31:15 +00004789 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004790 {
cristy8b27a6d2010-02-14 03:31:15 +00004791 MagickBooleanType
4792 proceed;
4793
4794 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4795 (depth-i),depth);
4796 if (proceed == MagickFalse)
4797 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004798 }
4799 }
cristyb0d3bb92010-09-22 14:37:58 +00004800 stegano_view=DestroyCacheView(stegano_view);
4801 watermark_view=DestroyCacheView(watermark_view);
cristy3ed852e2009-09-05 21:47:34 +00004802 if (stegano_image->storage_class == PseudoClass)
cristyea1a8aa2011-10-20 13:24:06 +00004803 (void) SyncImage(stegano_image,exception);
cristyda16f162011-02-19 23:52:17 +00004804 if (status == MagickFalse)
4805 {
4806 stegano_image=DestroyImage(stegano_image);
4807 return((Image *) NULL);
4808 }
cristy3ed852e2009-09-05 21:47:34 +00004809 return(stegano_image);
4810}
4811
4812/*
4813%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4814% %
4815% %
4816% %
4817% S t e r e o A n a g l y p h I m a g e %
4818% %
4819% %
4820% %
4821%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4822%
4823% StereoAnaglyphImage() combines two images and produces a single image that
4824% is the composite of a left and right image of a stereo pair. Special
4825% red-green stereo glasses are required to view this effect.
4826%
4827% The format of the StereoAnaglyphImage method is:
4828%
4829% Image *StereoImage(const Image *left_image,const Image *right_image,
4830% ExceptionInfo *exception)
4831% Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004832% const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004833% ExceptionInfo *exception)
4834%
4835% A description of each parameter follows:
4836%
4837% o left_image: the left image.
4838%
4839% o right_image: the right image.
4840%
4841% o exception: return any errors or warnings in this structure.
4842%
4843% o x_offset: amount, in pixels, by which the left image is offset to the
4844% right of the right image.
4845%
4846% o y_offset: amount, in pixels, by which the left image is offset to the
4847% bottom of the right image.
4848%
4849%
4850*/
4851MagickExport Image *StereoImage(const Image *left_image,
4852 const Image *right_image,ExceptionInfo *exception)
4853{
4854 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4855}
4856
4857MagickExport Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004858 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004859 ExceptionInfo *exception)
4860{
4861#define StereoImageTag "Stereo/Image"
4862
4863 const Image
4864 *image;
4865
4866 Image
4867 *stereo_image;
4868
cristy3ed852e2009-09-05 21:47:34 +00004869 MagickBooleanType
4870 status;
4871
cristy9d314ff2011-03-09 01:30:28 +00004872 ssize_t
4873 y;
4874
cristy3ed852e2009-09-05 21:47:34 +00004875 assert(left_image != (const Image *) NULL);
4876 assert(left_image->signature == MagickSignature);
4877 if (left_image->debug != MagickFalse)
4878 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4879 left_image->filename);
4880 assert(right_image != (const Image *) NULL);
4881 assert(right_image->signature == MagickSignature);
4882 assert(exception != (ExceptionInfo *) NULL);
4883 assert(exception->signature == MagickSignature);
4884 assert(right_image != (const Image *) NULL);
4885 image=left_image;
4886 if ((left_image->columns != right_image->columns) ||
4887 (left_image->rows != right_image->rows))
4888 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4889 /*
4890 Initialize stereo image attributes.
4891 */
4892 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4893 MagickTrue,exception);
4894 if (stereo_image == (Image *) NULL)
4895 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004896 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004897 {
cristy3ed852e2009-09-05 21:47:34 +00004898 stereo_image=DestroyImage(stereo_image);
4899 return((Image *) NULL);
4900 }
4901 /*
4902 Copy left image to red channel and right image to blue channel.
4903 */
cristyda16f162011-02-19 23:52:17 +00004904 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00004905 for (y=0; y < (ssize_t) stereo_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004906 {
cristy4c08aed2011-07-01 19:47:50 +00004907 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004908 *restrict p,
4909 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004910
cristybb503372010-05-27 20:51:26 +00004911 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004912 x;
4913
cristy4c08aed2011-07-01 19:47:50 +00004914 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004915 *restrict r;
cristy3ed852e2009-09-05 21:47:34 +00004916
4917 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4918 exception);
4919 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4920 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
cristy76f512e2011-09-12 01:26:56 +00004921 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4922 (r == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004923 break;
cristybb503372010-05-27 20:51:26 +00004924 for (x=0; x < (ssize_t) stereo_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004925 {
cristy4c08aed2011-07-01 19:47:50 +00004926 SetPixelRed(image,GetPixelRed(left_image,p),r);
cristy76f512e2011-09-12 01:26:56 +00004927 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4928 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4929 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4930 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4931 GetPixelAlpha(right_image,q))/2,r);
cristyed231572011-07-14 02:18:59 +00004932 p+=GetPixelChannels(left_image);
cristy76f512e2011-09-12 01:26:56 +00004933 q+=GetPixelChannels(right_image);
4934 r+=GetPixelChannels(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004935 }
4936 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4937 break;
cristy8b27a6d2010-02-14 03:31:15 +00004938 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004939 {
cristy8b27a6d2010-02-14 03:31:15 +00004940 MagickBooleanType
4941 proceed;
4942
cristybb503372010-05-27 20:51:26 +00004943 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4944 stereo_image->rows);
cristy8b27a6d2010-02-14 03:31:15 +00004945 if (proceed == MagickFalse)
4946 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004947 }
4948 }
cristyda16f162011-02-19 23:52:17 +00004949 if (status == MagickFalse)
4950 {
4951 stereo_image=DestroyImage(stereo_image);
4952 return((Image *) NULL);
4953 }
cristy3ed852e2009-09-05 21:47:34 +00004954 return(stereo_image);
4955}
4956
4957/*
4958%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4959% %
4960% %
4961% %
4962% S w i r l I m a g e %
4963% %
4964% %
4965% %
4966%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4967%
4968% SwirlImage() swirls the pixels about the center of the image, where
4969% degrees indicates the sweep of the arc through which each pixel is moved.
4970% You get a more dramatic effect as the degrees move from 1 to 360.
4971%
4972% The format of the SwirlImage method is:
4973%
4974% Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004975% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004976%
4977% A description of each parameter follows:
4978%
4979% o image: the image.
4980%
4981% o degrees: Define the tightness of the swirling effect.
4982%
cristy76f512e2011-09-12 01:26:56 +00004983% o method: the pixel interpolation method.
4984%
cristy3ed852e2009-09-05 21:47:34 +00004985% o exception: return any errors or warnings in this structure.
4986%
4987*/
4988MagickExport Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004989 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004990{
4991#define SwirlImageTag "Swirl/Image"
4992
cristyfa112112010-01-04 17:48:07 +00004993 CacheView
4994 *image_view,
4995 *swirl_view;
4996
cristy3ed852e2009-09-05 21:47:34 +00004997 Image
4998 *swirl_image;
4999
cristy3ed852e2009-09-05 21:47:34 +00005000 MagickBooleanType
5001 status;
5002
cristybb503372010-05-27 20:51:26 +00005003 MagickOffsetType
5004 progress;
5005
cristy3ed852e2009-09-05 21:47:34 +00005006 MagickRealType
5007 radius;
5008
5009 PointInfo
5010 center,
5011 scale;
5012
cristybb503372010-05-27 20:51:26 +00005013 ssize_t
5014 y;
5015
cristy3ed852e2009-09-05 21:47:34 +00005016 /*
5017 Initialize swirl image attributes.
5018 */
5019 assert(image != (const Image *) NULL);
5020 assert(image->signature == MagickSignature);
5021 if (image->debug != MagickFalse)
5022 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5023 assert(exception != (ExceptionInfo *) NULL);
5024 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00005025 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005026 if (swirl_image == (Image *) NULL)
5027 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005028 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005029 {
cristy3ed852e2009-09-05 21:47:34 +00005030 swirl_image=DestroyImage(swirl_image);
5031 return((Image *) NULL);
5032 }
cristy4c08aed2011-07-01 19:47:50 +00005033 if (swirl_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00005034 swirl_image->matte=MagickTrue;
5035 /*
5036 Compute scaling factor.
5037 */
5038 center.x=(double) image->columns/2.0;
5039 center.y=(double) image->rows/2.0;
5040 radius=MagickMax(center.x,center.y);
5041 scale.x=1.0;
5042 scale.y=1.0;
5043 if (image->columns > image->rows)
5044 scale.y=(double) image->columns/(double) image->rows;
5045 else
5046 if (image->columns < image->rows)
5047 scale.x=(double) image->rows/(double) image->columns;
5048 degrees=(double) DegreesToRadians(degrees);
5049 /*
5050 Swirl image.
5051 */
5052 status=MagickTrue;
5053 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00005054 image_view=AcquireCacheView(image);
5055 swirl_view=AcquireCacheView(swirl_image);
cristyb5d5f722009-11-04 03:03:49 +00005056#if defined(MAGICKCORE_OPENMP_SUPPORT)
5057 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005058#endif
cristybb503372010-05-27 20:51:26 +00005059 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005060 {
cristy3ed852e2009-09-05 21:47:34 +00005061 MagickRealType
5062 distance;
5063
5064 PointInfo
5065 delta;
5066
cristy6d188022011-09-12 13:23:33 +00005067 register const Quantum
5068 *restrict p;
5069
cristybb503372010-05-27 20:51:26 +00005070 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005071 x;
5072
cristy4c08aed2011-07-01 19:47:50 +00005073 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005074 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005075
5076 if (status == MagickFalse)
5077 continue;
cristy6d188022011-09-12 13:23:33 +00005078 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00005079 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5080 exception);
cristy6d188022011-09-12 13:23:33 +00005081 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005082 {
5083 status=MagickFalse;
5084 continue;
5085 }
cristy3ed852e2009-09-05 21:47:34 +00005086 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00005087 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005088 {
cristy6d188022011-09-12 13:23:33 +00005089 register ssize_t
5090 i;
5091
cristy3ed852e2009-09-05 21:47:34 +00005092 /*
5093 Determine if the pixel is within an ellipse.
5094 */
5095 delta.x=scale.x*(double) (x-center.x);
5096 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00005097 if (distance >= (radius*radius))
5098 {
5099 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5100 q[i]=p[i];
5101 }
5102 else
cristy3ed852e2009-09-05 21:47:34 +00005103 {
5104 MagickRealType
5105 cosine,
5106 factor,
5107 sine;
5108
5109 /*
5110 Swirl the pixel.
5111 */
5112 factor=1.0-sqrt((double) distance)/radius;
5113 sine=sin((double) (degrees*factor*factor));
5114 cosine=cos((double) (degrees*factor*factor));
cristy76f512e2011-09-12 01:26:56 +00005115 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5116 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5117 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00005118 }
cristy6d188022011-09-12 13:23:33 +00005119 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00005120 q+=GetPixelChannels(swirl_image);
cristy3ed852e2009-09-05 21:47:34 +00005121 }
5122 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5123 status=MagickFalse;
5124 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5125 {
5126 MagickBooleanType
5127 proceed;
5128
cristyb5d5f722009-11-04 03:03:49 +00005129#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005130 #pragma omp critical (MagickCore_SwirlImage)
5131#endif
5132 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5133 if (proceed == MagickFalse)
5134 status=MagickFalse;
5135 }
5136 }
5137 swirl_view=DestroyCacheView(swirl_view);
5138 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005139 if (status == MagickFalse)
5140 swirl_image=DestroyImage(swirl_image);
5141 return(swirl_image);
5142}
5143
5144/*
5145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5146% %
5147% %
5148% %
5149% T i n t I m a g e %
5150% %
5151% %
5152% %
5153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5154%
5155% TintImage() applies a color vector to each pixel in the image. The length
5156% of the vector is 0 for black and white and at its maximum for the midtones.
5157% The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5158%
5159% The format of the TintImage method is:
5160%
cristyb817c3f2011-10-03 14:00:35 +00005161% Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005162% const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005163%
5164% A description of each parameter follows:
5165%
5166% o image: the image.
5167%
cristyb817c3f2011-10-03 14:00:35 +00005168% o blend: A color value used for tinting.
cristy3ed852e2009-09-05 21:47:34 +00005169%
5170% o tint: A color value used for tinting.
5171%
5172% o exception: return any errors or warnings in this structure.
5173%
5174*/
cristyb817c3f2011-10-03 14:00:35 +00005175MagickExport Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005176 const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005177{
5178#define TintImageTag "Tint/Image"
5179
cristyc4c8d132010-01-07 01:58:38 +00005180 CacheView
5181 *image_view,
5182 *tint_view;
5183
cristy3ed852e2009-09-05 21:47:34 +00005184 GeometryInfo
5185 geometry_info;
5186
5187 Image
5188 *tint_image;
5189
cristy3ed852e2009-09-05 21:47:34 +00005190 MagickBooleanType
5191 status;
5192
cristybb503372010-05-27 20:51:26 +00005193 MagickOffsetType
5194 progress;
cristy3ed852e2009-09-05 21:47:34 +00005195
cristy28474bf2011-09-11 23:32:52 +00005196 MagickRealType
5197 intensity;
5198
cristy4c08aed2011-07-01 19:47:50 +00005199 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005200 color_vector,
5201 pixel;
5202
cristybb503372010-05-27 20:51:26 +00005203 MagickStatusType
5204 flags;
5205
5206 ssize_t
5207 y;
5208
cristy3ed852e2009-09-05 21:47:34 +00005209 /*
5210 Allocate tint image.
5211 */
5212 assert(image != (const Image *) NULL);
5213 assert(image->signature == MagickSignature);
5214 if (image->debug != MagickFalse)
5215 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5216 assert(exception != (ExceptionInfo *) NULL);
5217 assert(exception->signature == MagickSignature);
5218 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5219 if (tint_image == (Image *) NULL)
5220 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005221 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005222 {
cristy3ed852e2009-09-05 21:47:34 +00005223 tint_image=DestroyImage(tint_image);
5224 return((Image *) NULL);
5225 }
cristyaed9c382011-10-03 17:54:21 +00005226 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005227 return(tint_image);
5228 /*
5229 Determine RGB values of the color.
5230 */
cristy28474bf2011-09-11 23:32:52 +00005231 GetPixelInfo(image,&pixel);
cristyb817c3f2011-10-03 14:00:35 +00005232 flags=ParseGeometry(blend,&geometry_info);
cristy3ed852e2009-09-05 21:47:34 +00005233 pixel.red=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005234 pixel.green=geometry_info.rho;
5235 pixel.blue=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005236 pixel.alpha=OpaqueAlpha;
cristy3ed852e2009-09-05 21:47:34 +00005237 if ((flags & SigmaValue) != 0)
5238 pixel.green=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00005239 if ((flags & XiValue) != 0)
5240 pixel.blue=geometry_info.xi;
cristyb817c3f2011-10-03 14:00:35 +00005241 if ((flags & PsiValue) != 0)
5242 pixel.alpha=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005243 if (image->colorspace == CMYKColorspace)
5244 {
cristyb817c3f2011-10-03 14:00:35 +00005245 pixel.black=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005246 if ((flags & PsiValue) != 0)
5247 pixel.black=geometry_info.psi;
5248 if ((flags & ChiValue) != 0)
5249 pixel.alpha=geometry_info.chi;
5250 }
cristy28474bf2011-09-11 23:32:52 +00005251 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5252 color_vector.red=(MagickRealType) (pixel.red*tint->red/100.0-intensity);
5253 color_vector.green=(MagickRealType) (pixel.green*tint->green/100.0-intensity);
5254 color_vector.blue=(MagickRealType) (pixel.blue*tint->blue/100.0-intensity);
5255 color_vector.black=(MagickRealType) (pixel.black*tint->black/100.0-intensity);
5256 color_vector.alpha=(MagickRealType) (pixel.alpha*tint->alpha/100.0-intensity);
cristy3ed852e2009-09-05 21:47:34 +00005257 /*
5258 Tint image.
5259 */
5260 status=MagickTrue;
5261 progress=0;
5262 image_view=AcquireCacheView(image);
5263 tint_view=AcquireCacheView(tint_image);
cristyb5d5f722009-11-04 03:03:49 +00005264#if defined(MAGICKCORE_OPENMP_SUPPORT)
5265 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005266#endif
cristybb503372010-05-27 20:51:26 +00005267 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005268 {
cristy4c08aed2011-07-01 19:47:50 +00005269 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00005270 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00005271
cristy4c08aed2011-07-01 19:47:50 +00005272 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005273 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005274
cristy6b91acb2011-04-19 12:23:54 +00005275 register ssize_t
5276 x;
5277
cristy3ed852e2009-09-05 21:47:34 +00005278 if (status == MagickFalse)
5279 continue;
5280 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5281 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5282 exception);
cristy4c08aed2011-07-01 19:47:50 +00005283 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005284 {
5285 status=MagickFalse;
5286 continue;
5287 }
cristybb503372010-05-27 20:51:26 +00005288 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005289 {
cristy4c08aed2011-07-01 19:47:50 +00005290 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005291 pixel;
5292
5293 MagickRealType
5294 weight;
5295
cristy76f512e2011-09-12 01:26:56 +00005296 if ((GetPixelRedTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005297 {
5298 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5299 pixel.red=(MagickRealType) GetPixelRed(image,p)+
5300 color_vector.red*(1.0-(4.0*(weight*weight)));
5301 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5302 }
cristy76f512e2011-09-12 01:26:56 +00005303 if ((GetPixelGreenTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005304 {
5305 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5306 pixel.green=(MagickRealType) GetPixelGreen(image,p)+
5307 color_vector.green*(1.0-(4.0*(weight*weight)));
5308 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5309 }
cristy76f512e2011-09-12 01:26:56 +00005310 if ((GetPixelBlueTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005311 {
5312 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5313 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+
5314 color_vector.blue*(1.0-(4.0*(weight*weight)));
5315 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5316 }
cristy76f512e2011-09-12 01:26:56 +00005317 if ((GetPixelBlackTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005318 {
5319 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5320 pixel.black=(MagickRealType) GetPixelBlack(image,p)+
5321 color_vector.black*(1.0-(4.0*(weight*weight)));
5322 SetPixelBlack(tint_image,ClampToQuantum(pixel.black),q);
5323 }
cristy76f512e2011-09-12 01:26:56 +00005324 if ((GetPixelAlphaTraits(tint_image) & CopyPixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005325 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
cristyed231572011-07-14 02:18:59 +00005326 p+=GetPixelChannels(image);
5327 q+=GetPixelChannels(tint_image);
cristy3ed852e2009-09-05 21:47:34 +00005328 }
5329 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5330 status=MagickFalse;
5331 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5332 {
5333 MagickBooleanType
5334 proceed;
5335
cristyb5d5f722009-11-04 03:03:49 +00005336#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005337 #pragma omp critical (MagickCore_TintImage)
5338#endif
5339 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5340 if (proceed == MagickFalse)
5341 status=MagickFalse;
5342 }
5343 }
5344 tint_view=DestroyCacheView(tint_view);
5345 image_view=DestroyCacheView(image_view);
5346 if (status == MagickFalse)
5347 tint_image=DestroyImage(tint_image);
5348 return(tint_image);
5349}
5350
5351/*
5352%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5353% %
5354% %
5355% %
5356% V i g n e t t e I m a g e %
5357% %
5358% %
5359% %
5360%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5361%
5362% VignetteImage() softens the edges of the image in vignette style.
5363%
5364% The format of the VignetteImage method is:
5365%
5366% Image *VignetteImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +00005367% const double sigma,const ssize_t x,const ssize_t y,
5368% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005369%
5370% A description of each parameter follows:
5371%
5372% o image: the image.
5373%
5374% o radius: the radius of the pixel neighborhood.
5375%
5376% o sigma: the standard deviation of the Gaussian, in pixels.
5377%
5378% o x, y: Define the x and y ellipse offset.
5379%
5380% o exception: return any errors or warnings in this structure.
5381%
5382*/
5383MagickExport Image *VignetteImage(const Image *image,const double radius,
cristybb503372010-05-27 20:51:26 +00005384 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005385{
5386 char
5387 ellipse[MaxTextExtent];
5388
5389 DrawInfo
5390 *draw_info;
5391
5392 Image
5393 *canvas_image,
5394 *blur_image,
5395 *oval_image,
5396 *vignette_image;
5397
5398 assert(image != (Image *) NULL);
5399 assert(image->signature == MagickSignature);
5400 if (image->debug != MagickFalse)
5401 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5402 assert(exception != (ExceptionInfo *) NULL);
5403 assert(exception->signature == MagickSignature);
5404 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5405 if (canvas_image == (Image *) NULL)
5406 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005407 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005408 {
cristy3ed852e2009-09-05 21:47:34 +00005409 canvas_image=DestroyImage(canvas_image);
5410 return((Image *) NULL);
5411 }
5412 canvas_image->matte=MagickTrue;
cristyb3a73b52011-07-26 01:34:43 +00005413 oval_image=CloneImage(canvas_image,canvas_image->columns,
5414 canvas_image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005415 if (oval_image == (Image *) NULL)
5416 {
5417 canvas_image=DestroyImage(canvas_image);
5418 return((Image *) NULL);
5419 }
cristy9950d572011-10-01 18:22:35 +00005420 (void) QueryColorCompliance("#000000",AllCompliance,
5421 &oval_image->background_color,exception);
cristyea1a8aa2011-10-20 13:24:06 +00005422 (void) SetImageBackgroundColor(oval_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00005423 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00005424 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5425 exception);
5426 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5427 exception);
cristyb51dff52011-05-19 16:55:47 +00005428 (void) FormatLocaleString(ellipse,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00005429 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
cristy8cd5b312010-01-07 01:10:24 +00005430 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
cristy3ed852e2009-09-05 21:47:34 +00005431 draw_info->primitive=AcquireString(ellipse);
cristy018f07f2011-09-04 21:15:19 +00005432 (void) DrawImage(oval_image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00005433 draw_info=DestroyDrawInfo(draw_info);
cristy05c0c9a2011-09-05 23:16:13 +00005434 blur_image=BlurImage(oval_image,radius,sigma,image->bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00005435 oval_image=DestroyImage(oval_image);
5436 if (blur_image == (Image *) NULL)
5437 {
5438 canvas_image=DestroyImage(canvas_image);
5439 return((Image *) NULL);
5440 }
5441 blur_image->matte=MagickFalse;
cristye941a752011-10-15 01:52:48 +00005442 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0,
5443 exception);
cristy3ed852e2009-09-05 21:47:34 +00005444 blur_image=DestroyImage(blur_image);
5445 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5446 canvas_image=DestroyImage(canvas_image);
5447 return(vignette_image);
5448}
5449
5450/*
5451%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5452% %
5453% %
5454% %
5455% W a v e I m a g e %
5456% %
5457% %
5458% %
5459%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5460%
5461% WaveImage() creates a "ripple" effect in the image by shifting the pixels
cristycee97112010-05-28 00:44:52 +00005462% vertically along a sine wave whose amplitude and wavelength is specified
cristy3ed852e2009-09-05 21:47:34 +00005463% by the given parameters.
5464%
5465% The format of the WaveImage method is:
5466%
5467% Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005468% const double wave_length,const PixelInterpolateMethod method,
5469% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005470%
5471% A description of each parameter follows:
5472%
5473% o image: the image.
5474%
5475% o amplitude, wave_length: Define the amplitude and wave length of the
5476% sine wave.
5477%
cristy5c4e2582011-09-11 19:21:03 +00005478% o interpolate: the pixel interpolation method.
5479%
cristy3ed852e2009-09-05 21:47:34 +00005480% o exception: return any errors or warnings in this structure.
5481%
5482*/
5483MagickExport Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005484 const double wave_length,const PixelInterpolateMethod method,
5485 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005486{
5487#define WaveImageTag "Wave/Image"
5488
cristyfa112112010-01-04 17:48:07 +00005489 CacheView
cristyd76c51e2011-03-26 00:21:26 +00005490 *image_view,
cristyfa112112010-01-04 17:48:07 +00005491 *wave_view;
5492
cristy3ed852e2009-09-05 21:47:34 +00005493 Image
5494 *wave_image;
5495
cristy3ed852e2009-09-05 21:47:34 +00005496 MagickBooleanType
5497 status;
5498
cristybb503372010-05-27 20:51:26 +00005499 MagickOffsetType
5500 progress;
5501
cristy3ed852e2009-09-05 21:47:34 +00005502 MagickRealType
5503 *sine_map;
5504
cristybb503372010-05-27 20:51:26 +00005505 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005506 i;
5507
cristybb503372010-05-27 20:51:26 +00005508 ssize_t
5509 y;
5510
cristy3ed852e2009-09-05 21:47:34 +00005511 /*
5512 Initialize wave image attributes.
5513 */
5514 assert(image != (Image *) NULL);
5515 assert(image->signature == MagickSignature);
5516 if (image->debug != MagickFalse)
5517 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5518 assert(exception != (ExceptionInfo *) NULL);
5519 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00005520 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
cristy3ed852e2009-09-05 21:47:34 +00005521 fabs(amplitude)),MagickTrue,exception);
5522 if (wave_image == (Image *) NULL)
5523 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005524 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005525 {
cristy3ed852e2009-09-05 21:47:34 +00005526 wave_image=DestroyImage(wave_image);
5527 return((Image *) NULL);
5528 }
cristy4c08aed2011-07-01 19:47:50 +00005529 if (wave_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00005530 wave_image->matte=MagickTrue;
5531 /*
5532 Allocate sine map.
5533 */
5534 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5535 sizeof(*sine_map));
5536 if (sine_map == (MagickRealType *) NULL)
5537 {
5538 wave_image=DestroyImage(wave_image);
5539 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5540 }
cristybb503372010-05-27 20:51:26 +00005541 for (i=0; i < (ssize_t) wave_image->columns; i++)
cristy4205a3c2010-09-12 20:19:59 +00005542 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5543 wave_length));
cristy3ed852e2009-09-05 21:47:34 +00005544 /*
5545 Wave image.
5546 */
5547 status=MagickTrue;
5548 progress=0;
cristyd76c51e2011-03-26 00:21:26 +00005549 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00005550 wave_view=AcquireCacheView(wave_image);
cristyd76c51e2011-03-26 00:21:26 +00005551 (void) SetCacheViewVirtualPixelMethod(image_view,
5552 BackgroundVirtualPixelMethod);
cristyb5d5f722009-11-04 03:03:49 +00005553#if defined(MAGICKCORE_OPENMP_SUPPORT)
5554 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005555#endif
cristybb503372010-05-27 20:51:26 +00005556 for (y=0; y < (ssize_t) wave_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005557 {
cristy4c08aed2011-07-01 19:47:50 +00005558 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005559 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005560
cristye97bb922011-04-03 01:36:52 +00005561 register ssize_t
5562 x;
5563
cristy3ed852e2009-09-05 21:47:34 +00005564 if (status == MagickFalse)
5565 continue;
5566 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5567 exception);
cristyacd2ed22011-08-30 01:44:23 +00005568 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005569 {
5570 status=MagickFalse;
5571 continue;
5572 }
cristybb503372010-05-27 20:51:26 +00005573 for (x=0; x < (ssize_t) wave_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005574 {
cristy5c4e2582011-09-11 19:21:03 +00005575 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5576 (double) x,(double) (y-sine_map[x]),q,exception);
cristyed231572011-07-14 02:18:59 +00005577 q+=GetPixelChannels(wave_image);
cristy3ed852e2009-09-05 21:47:34 +00005578 }
5579 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5580 status=MagickFalse;
5581 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5582 {
5583 MagickBooleanType
5584 proceed;
5585
cristyb5d5f722009-11-04 03:03:49 +00005586#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005587 #pragma omp critical (MagickCore_WaveImage)
5588#endif
5589 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5590 if (proceed == MagickFalse)
5591 status=MagickFalse;
5592 }
5593 }
5594 wave_view=DestroyCacheView(wave_view);
cristyd76c51e2011-03-26 00:21:26 +00005595 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005596 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5597 if (status == MagickFalse)
5598 wave_image=DestroyImage(wave_image);
5599 return(wave_image);
5600}