blob: 9957e7cee3faa05bd579bf913baf7b834046124e [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% FFFFF X X %
7% F X X %
8% FFF X %
9% F X X %
10% F X X %
11% %
12% %
13% MagickCore Image Special Effects Methods %
14% %
15% Software Design %
16% John Cristy %
17% October 1996 %
18% %
19% %
cristy7e41fe82010-12-04 23:12:08 +000020% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#include "MagickCore/studio.h"
44#include "MagickCore/annotate.h"
45#include "MagickCore/artifact.h"
46#include "MagickCore/attribute.h"
47#include "MagickCore/cache.h"
48#include "MagickCore/cache-view.h"
49#include "MagickCore/color.h"
50#include "MagickCore/color-private.h"
51#include "MagickCore/composite.h"
52#include "MagickCore/decorate.h"
53#include "MagickCore/draw.h"
54#include "MagickCore/effect.h"
55#include "MagickCore/enhance.h"
56#include "MagickCore/exception.h"
57#include "MagickCore/exception-private.h"
58#include "MagickCore/fx.h"
59#include "MagickCore/fx-private.h"
60#include "MagickCore/gem.h"
cristy8ea81222011-09-04 10:33:32 +000061#include "MagickCore/gem-private.h"
cristy4c08aed2011-07-01 19:47:50 +000062#include "MagickCore/geometry.h"
63#include "MagickCore/layer.h"
64#include "MagickCore/list.h"
65#include "MagickCore/log.h"
66#include "MagickCore/image.h"
67#include "MagickCore/image-private.h"
68#include "MagickCore/magick.h"
69#include "MagickCore/memory_.h"
70#include "MagickCore/monitor.h"
71#include "MagickCore/monitor-private.h"
72#include "MagickCore/option.h"
73#include "MagickCore/pixel.h"
74#include "MagickCore/pixel-accessor.h"
75#include "MagickCore/property.h"
76#include "MagickCore/quantum.h"
77#include "MagickCore/quantum-private.h"
78#include "MagickCore/random_.h"
79#include "MagickCore/random-private.h"
80#include "MagickCore/resample.h"
81#include "MagickCore/resample-private.h"
82#include "MagickCore/resize.h"
83#include "MagickCore/shear.h"
84#include "MagickCore/splay-tree.h"
85#include "MagickCore/statistic.h"
86#include "MagickCore/string_.h"
87#include "MagickCore/string-private.h"
88#include "MagickCore/thread-private.h"
89#include "MagickCore/transform.h"
90#include "MagickCore/utility.h"
cristy3ed852e2009-09-05 21:47:34 +000091
92/*
93 Define declarations.
94*/
95#define LeftShiftOperator 0xf5
96#define RightShiftOperator 0xf6
97#define LessThanEqualOperator 0xf7
98#define GreaterThanEqualOperator 0xf8
99#define EqualOperator 0xf9
100#define NotEqualOperator 0xfa
101#define LogicalAndOperator 0xfb
102#define LogicalOrOperator 0xfc
cristy116af162010-08-13 01:25:47 +0000103#define ExponentialNotation 0xfd
cristy3ed852e2009-09-05 21:47:34 +0000104
105struct _FxInfo
106{
107 const Image
108 *images;
109
cristy3ed852e2009-09-05 21:47:34 +0000110 char
111 *expression;
112
113 FILE
114 *file;
115
116 SplayTreeInfo
117 *colors,
118 *symbols;
119
cristyd76c51e2011-03-26 00:21:26 +0000120 CacheView
121 **view;
cristy3ed852e2009-09-05 21:47:34 +0000122
123 RandomInfo
124 *random_info;
125
126 ExceptionInfo
127 *exception;
128};
129
130/*
131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132% %
133% %
134% %
135+ A c q u i r e F x I n f o %
136% %
137% %
138% %
139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140%
141% AcquireFxInfo() allocates the FxInfo structure.
142%
143% The format of the AcquireFxInfo method is:
144%
145% FxInfo *AcquireFxInfo(Image *image,const char *expression)
cristy0a9b3722010-10-23 18:45:49 +0000146%
cristy3ed852e2009-09-05 21:47:34 +0000147% A description of each parameter follows:
148%
149% o image: the image.
150%
151% o expression: the expression.
152%
153*/
cristy7832dc22011-09-05 01:21:53 +0000154MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression)
cristy3ed852e2009-09-05 21:47:34 +0000155{
156 char
157 fx_op[2];
158
cristycb180922011-03-11 14:41:24 +0000159 const Image
160 *next;
161
cristy3ed852e2009-09-05 21:47:34 +0000162 FxInfo
163 *fx_info;
164
cristybb503372010-05-27 20:51:26 +0000165 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000166 i;
167
cristy73bd4a52010-10-05 11:24:23 +0000168 fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +0000169 if (fx_info == (FxInfo *) NULL)
170 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
171 (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info));
172 fx_info->exception=AcquireExceptionInfo();
anthony7d86e172011-03-23 12:37:06 +0000173 fx_info->images=image;
cristy3ed852e2009-09-05 21:47:34 +0000174 fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
175 RelinquishMagickMemory);
176 fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
177 RelinquishMagickMemory);
cristyd76c51e2011-03-26 00:21:26 +0000178 fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
179 fx_info->images),sizeof(*fx_info->view));
180 if (fx_info->view == (CacheView **) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000181 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
cristya2262262011-03-11 02:50:37 +0000182 i=0;
cristy0ea377f2011-03-24 00:54:19 +0000183 next=GetFirstImageInList(fx_info->images);
184 for ( ; next != (Image *) NULL; next=next->next)
cristy3ed852e2009-09-05 21:47:34 +0000185 {
cristyd76c51e2011-03-26 00:21:26 +0000186 fx_info->view[i]=AcquireCacheView(next);
cristya2262262011-03-11 02:50:37 +0000187 i++;
cristy3ed852e2009-09-05 21:47:34 +0000188 }
189 fx_info->random_info=AcquireRandomInfo();
190 fx_info->expression=ConstantString(expression);
191 fx_info->file=stderr;
192 (void) SubstituteString(&fx_info->expression," ",""); /* compact string */
cristy37af0912011-05-23 16:09:42 +0000193 /*
194 Force right-to-left associativity for unary negation.
195 */
196 (void) SubstituteString(&fx_info->expression,"-","-1.0*");
cristy3ed852e2009-09-05 21:47:34 +0000197 if ((strstr(fx_info->expression,"e+") != (char *) NULL) ||
198 (strstr(fx_info->expression,"e-") != (char *) NULL))
199 {
200 /*
cristy116af162010-08-13 01:25:47 +0000201 Convert scientific notation.
cristy3ed852e2009-09-05 21:47:34 +0000202 */
cristy116af162010-08-13 01:25:47 +0000203 (void) SubstituteString(&fx_info->expression,"0e+","0**10^");
204 (void) SubstituteString(&fx_info->expression,"1e+","1**10^");
205 (void) SubstituteString(&fx_info->expression,"2e+","2**10^");
206 (void) SubstituteString(&fx_info->expression,"3e+","3**10^");
207 (void) SubstituteString(&fx_info->expression,"4e+","4**10^");
208 (void) SubstituteString(&fx_info->expression,"5e+","5**10^");
209 (void) SubstituteString(&fx_info->expression,"6e+","6**10^");
210 (void) SubstituteString(&fx_info->expression,"7e+","7**10^");
211 (void) SubstituteString(&fx_info->expression,"8e+","8**10^");
212 (void) SubstituteString(&fx_info->expression,"9e+","9**10^");
cristy2ffa8cd2011-05-24 12:45:55 +0000213 (void) SubstituteString(&fx_info->expression,"0e-1.0*","0**10^-");
cristy37af0912011-05-23 16:09:42 +0000214 (void) SubstituteString(&fx_info->expression,"1e-1.0*","1**10^-");
215 (void) SubstituteString(&fx_info->expression,"2e-1.0*","2**10^-");
216 (void) SubstituteString(&fx_info->expression,"3e-1.0*","3**10^-");
217 (void) SubstituteString(&fx_info->expression,"4e-1.0*","4**10^-");
218 (void) SubstituteString(&fx_info->expression,"5e-1.0*","5**10^-");
219 (void) SubstituteString(&fx_info->expression,"6e-1.0*","6**10^-");
220 (void) SubstituteString(&fx_info->expression,"7e-1.0*","7**10^-");
221 (void) SubstituteString(&fx_info->expression,"8e-1.0*","8**10^-");
222 (void) SubstituteString(&fx_info->expression,"9e-1.0*","9**10^-");
cristy3ed852e2009-09-05 21:47:34 +0000223 }
cristy37af0912011-05-23 16:09:42 +0000224 if ((strstr(fx_info->expression,"E+") != (char *) NULL) ||
225 (strstr(fx_info->expression,"E-") != (char *) NULL))
226 {
227 /*
228 Convert scientific notation.
229 */
230 (void) SubstituteString(&fx_info->expression,"0E+","0**10^");
231 (void) SubstituteString(&fx_info->expression,"1E+","1**10^");
232 (void) SubstituteString(&fx_info->expression,"2E+","2**10^");
233 (void) SubstituteString(&fx_info->expression,"3E+","3**10^");
234 (void) SubstituteString(&fx_info->expression,"4E+","4**10^");
235 (void) SubstituteString(&fx_info->expression,"5E+","5**10^");
236 (void) SubstituteString(&fx_info->expression,"6E+","6**10^");
237 (void) SubstituteString(&fx_info->expression,"7E+","7**10^");
238 (void) SubstituteString(&fx_info->expression,"8E+","8**10^");
239 (void) SubstituteString(&fx_info->expression,"9E+","9**10^");
cristy2ffa8cd2011-05-24 12:45:55 +0000240 (void) SubstituteString(&fx_info->expression,"0E-1.0*","0**10^-");
cristy37af0912011-05-23 16:09:42 +0000241 (void) SubstituteString(&fx_info->expression,"1E-1.0*","1**10^-");
242 (void) SubstituteString(&fx_info->expression,"2E-1.0*","2**10^-");
243 (void) SubstituteString(&fx_info->expression,"3E-1.0*","3**10^-");
244 (void) SubstituteString(&fx_info->expression,"4E-1.0*","4**10^-");
245 (void) SubstituteString(&fx_info->expression,"5E-1.0*","5**10^-");
246 (void) SubstituteString(&fx_info->expression,"6E-1.0*","6**10^-");
247 (void) SubstituteString(&fx_info->expression,"7E-1.0*","7**10^-");
248 (void) SubstituteString(&fx_info->expression,"8E-1.0*","8**10^-");
249 (void) SubstituteString(&fx_info->expression,"9E-1.0*","9**10^-");
250 }
cristy8b8a3ae2010-10-23 18:49:46 +0000251 /*
cristy3ed852e2009-09-05 21:47:34 +0000252 Convert complex to simple operators.
253 */
254 fx_op[1]='\0';
255 *fx_op=(char) LeftShiftOperator;
256 (void) SubstituteString(&fx_info->expression,"<<",fx_op);
257 *fx_op=(char) RightShiftOperator;
258 (void) SubstituteString(&fx_info->expression,">>",fx_op);
259 *fx_op=(char) LessThanEqualOperator;
260 (void) SubstituteString(&fx_info->expression,"<=",fx_op);
261 *fx_op=(char) GreaterThanEqualOperator;
262 (void) SubstituteString(&fx_info->expression,">=",fx_op);
263 *fx_op=(char) EqualOperator;
264 (void) SubstituteString(&fx_info->expression,"==",fx_op);
265 *fx_op=(char) NotEqualOperator;
266 (void) SubstituteString(&fx_info->expression,"!=",fx_op);
267 *fx_op=(char) LogicalAndOperator;
268 (void) SubstituteString(&fx_info->expression,"&&",fx_op);
269 *fx_op=(char) LogicalOrOperator;
270 (void) SubstituteString(&fx_info->expression,"||",fx_op);
cristy116af162010-08-13 01:25:47 +0000271 *fx_op=(char) ExponentialNotation;
272 (void) SubstituteString(&fx_info->expression,"**",fx_op);
cristy3ed852e2009-09-05 21:47:34 +0000273 return(fx_info);
274}
275
276/*
277%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
278% %
279% %
280% %
281% A d d N o i s e I m a g e %
282% %
283% %
284% %
285%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
286%
287% AddNoiseImage() adds random noise to the image.
288%
289% The format of the AddNoiseImage method is:
290%
291% Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
cristy9ed1f812011-10-08 02:00:08 +0000292% const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000293%
294% A description of each parameter follows:
295%
296% o image: the image.
297%
298% o channel: the channel type.
299%
300% o noise_type: The type of noise: Uniform, Gaussian, Multiplicative,
301% Impulse, Laplacian, or Poisson.
302%
cristy9ed1f812011-10-08 02:00:08 +0000303% o attenuate: attenuate the random distribution.
304%
cristy3ed852e2009-09-05 21:47:34 +0000305% o exception: return any errors or warnings in this structure.
306%
307*/
cristy9ed1f812011-10-08 02:00:08 +0000308MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
309 const double attenuate,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000310{
311#define AddNoiseImageTag "AddNoise/Image"
312
cristyfa112112010-01-04 17:48:07 +0000313 CacheView
314 *image_view,
315 *noise_view;
316
cristy3ed852e2009-09-05 21:47:34 +0000317 Image
318 *noise_image;
319
cristy3ed852e2009-09-05 21:47:34 +0000320 MagickBooleanType
321 status;
322
cristybb503372010-05-27 20:51:26 +0000323 MagickOffsetType
324 progress;
325
cristy3ed852e2009-09-05 21:47:34 +0000326 RandomInfo
cristyfa112112010-01-04 17:48:07 +0000327 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +0000328
cristybb503372010-05-27 20:51:26 +0000329 ssize_t
330 y;
331
cristy3ed852e2009-09-05 21:47:34 +0000332 /*
333 Initialize noise image attributes.
334 */
335 assert(image != (const Image *) NULL);
336 assert(image->signature == MagickSignature);
337 if (image->debug != MagickFalse)
338 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
339 assert(exception != (ExceptionInfo *) NULL);
340 assert(exception->signature == MagickSignature);
cristyb2145892011-10-10 00:55:32 +0000341 noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +0000342 if (noise_image == (Image *) NULL)
343 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000344 if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000345 {
cristy3ed852e2009-09-05 21:47:34 +0000346 noise_image=DestroyImage(noise_image);
347 return((Image *) NULL);
348 }
349 /*
350 Add noise in each row.
351 */
cristy3ed852e2009-09-05 21:47:34 +0000352 status=MagickTrue;
353 progress=0;
354 random_info=AcquireRandomInfoThreadSet();
355 image_view=AcquireCacheView(image);
356 noise_view=AcquireCacheView(noise_image);
cristy319a1e72010-02-21 15:13:11 +0000357#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000358 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000359#endif
cristybb503372010-05-27 20:51:26 +0000360 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000361 {
cristy5c9e6f22010-09-17 17:31:01 +0000362 const int
363 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +0000364
cristy3ed852e2009-09-05 21:47:34 +0000365 MagickBooleanType
366 sync;
367
cristy4c08aed2011-07-01 19:47:50 +0000368 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000369 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000370
cristybb503372010-05-27 20:51:26 +0000371 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000372 x;
373
cristy4c08aed2011-07-01 19:47:50 +0000374 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000375 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000376
377 if (status == MagickFalse)
378 continue;
379 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
380 q=GetCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
381 exception);
cristy4c08aed2011-07-01 19:47:50 +0000382 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000383 {
384 status=MagickFalse;
385 continue;
386 }
cristybb503372010-05-27 20:51:26 +0000387 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000388 {
cristy850b3072011-10-08 01:38:05 +0000389 register ssize_t
390 i;
391
392 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
393 {
394 PixelChannel
395 channel;
396
397 PixelTrait
398 noise_traits,
399 traits;
400
401 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
402 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
403 noise_traits=GetPixelChannelMapTraits(noise_image,channel);
404 if ((traits == UndefinedPixelTrait) ||
405 (noise_traits == UndefinedPixelTrait))
406 continue;
cristy9eeedea2011-11-02 19:04:05 +0000407 if ((noise_traits & CopyPixelTrait) != 0)
cristyb2145892011-10-10 00:55:32 +0000408 {
409 SetPixelChannel(noise_image,channel,p[i],q);
410 continue;
411 }
cristy850b3072011-10-08 01:38:05 +0000412 SetPixelChannel(noise_image,channel,ClampToQuantum(
413 GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)),
414 q);
415 }
cristyed231572011-07-14 02:18:59 +0000416 p+=GetPixelChannels(image);
417 q+=GetPixelChannels(noise_image);
cristy3ed852e2009-09-05 21:47:34 +0000418 }
419 sync=SyncCacheViewAuthenticPixels(noise_view,exception);
420 if (sync == MagickFalse)
421 status=MagickFalse;
422 if (image->progress_monitor != (MagickProgressMonitor) NULL)
423 {
424 MagickBooleanType
425 proceed;
426
cristyb5d5f722009-11-04 03:03:49 +0000427#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy319a1e72010-02-21 15:13:11 +0000428 #pragma omp critical (MagickCore_AddNoiseImage)
cristy3ed852e2009-09-05 21:47:34 +0000429#endif
430 proceed=SetImageProgress(image,AddNoiseImageTag,progress++,
431 image->rows);
432 if (proceed == MagickFalse)
433 status=MagickFalse;
434 }
435 }
436 noise_view=DestroyCacheView(noise_view);
437 image_view=DestroyCacheView(image_view);
438 random_info=DestroyRandomInfoThreadSet(random_info);
439 if (status == MagickFalse)
440 noise_image=DestroyImage(noise_image);
441 return(noise_image);
442}
443
444/*
445%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
446% %
447% %
448% %
449% B l u e S h i f t I m a g e %
450% %
451% %
452% %
453%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
454%
455% BlueShiftImage() mutes the colors of the image to simulate a scene at
456% nighttime in the moonlight.
457%
458% The format of the BlueShiftImage method is:
459%
460% Image *BlueShiftImage(const Image *image,const double factor,
461% ExceptionInfo *exception)
462%
463% A description of each parameter follows:
464%
465% o image: the image.
466%
467% o factor: the shift factor.
468%
469% o exception: return any errors or warnings in this structure.
470%
471*/
472MagickExport Image *BlueShiftImage(const Image *image,const double factor,
473 ExceptionInfo *exception)
474{
475#define BlueShiftImageTag "BlueShift/Image"
476
cristyc4c8d132010-01-07 01:58:38 +0000477 CacheView
478 *image_view,
479 *shift_view;
480
cristy3ed852e2009-09-05 21:47:34 +0000481 Image
482 *shift_image;
483
cristy3ed852e2009-09-05 21:47:34 +0000484 MagickBooleanType
485 status;
486
cristybb503372010-05-27 20:51:26 +0000487 MagickOffsetType
488 progress;
489
490 ssize_t
491 y;
492
cristy3ed852e2009-09-05 21:47:34 +0000493 /*
494 Allocate blue shift image.
495 */
496 assert(image != (const Image *) NULL);
497 assert(image->signature == MagickSignature);
498 if (image->debug != MagickFalse)
499 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
500 assert(exception != (ExceptionInfo *) NULL);
501 assert(exception->signature == MagickSignature);
502 shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,
503 exception);
504 if (shift_image == (Image *) NULL)
505 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000506 if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000507 {
cristy3ed852e2009-09-05 21:47:34 +0000508 shift_image=DestroyImage(shift_image);
509 return((Image *) NULL);
510 }
511 /*
512 Blue-shift DirectClass image.
513 */
514 status=MagickTrue;
515 progress=0;
516 image_view=AcquireCacheView(image);
517 shift_view=AcquireCacheView(shift_image);
cristy319a1e72010-02-21 15:13:11 +0000518#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000519 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000520#endif
cristybb503372010-05-27 20:51:26 +0000521 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000522 {
523 MagickBooleanType
524 sync;
525
cristy4c08aed2011-07-01 19:47:50 +0000526 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +0000527 pixel;
528
529 Quantum
530 quantum;
531
cristy4c08aed2011-07-01 19:47:50 +0000532 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000533 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000534
cristybb503372010-05-27 20:51:26 +0000535 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000536 x;
537
cristy4c08aed2011-07-01 19:47:50 +0000538 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000539 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000540
541 if (status == MagickFalse)
542 continue;
543 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
544 q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1,
545 exception);
cristy4c08aed2011-07-01 19:47:50 +0000546 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000547 {
548 status=MagickFalse;
549 continue;
550 }
cristybb503372010-05-27 20:51:26 +0000551 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000552 {
cristy4c08aed2011-07-01 19:47:50 +0000553 quantum=GetPixelRed(image,p);
554 if (GetPixelGreen(image,p) < quantum)
555 quantum=GetPixelGreen(image,p);
556 if (GetPixelBlue(image,p) < quantum)
557 quantum=GetPixelBlue(image,p);
558 pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum);
559 pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum);
560 pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum);
561 quantum=GetPixelRed(image,p);
562 if (GetPixelGreen(image,p) > quantum)
563 quantum=GetPixelGreen(image,p);
564 if (GetPixelBlue(image,p) > quantum)
565 quantum=GetPixelBlue(image,p);
cristy3ed852e2009-09-05 21:47:34 +0000566 pixel.red=0.5*(pixel.red+factor*quantum);
567 pixel.green=0.5*(pixel.green+factor*quantum);
568 pixel.blue=0.5*(pixel.blue+factor*quantum);
cristy4c08aed2011-07-01 19:47:50 +0000569 SetPixelRed(shift_image,ClampToQuantum(pixel.red),q);
570 SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q);
571 SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q);
cristyed231572011-07-14 02:18:59 +0000572 p+=GetPixelChannels(image);
573 q+=GetPixelChannels(shift_image);
cristy3ed852e2009-09-05 21:47:34 +0000574 }
575 sync=SyncCacheViewAuthenticPixels(shift_view,exception);
576 if (sync == MagickFalse)
577 status=MagickFalse;
578 if (image->progress_monitor != (MagickProgressMonitor) NULL)
579 {
580 MagickBooleanType
581 proceed;
582
cristy319a1e72010-02-21 15:13:11 +0000583#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000584 #pragma omp critical (MagickCore_BlueShiftImage)
585#endif
586 proceed=SetImageProgress(image,BlueShiftImageTag,progress++,
587 image->rows);
588 if (proceed == MagickFalse)
589 status=MagickFalse;
590 }
591 }
592 image_view=DestroyCacheView(image_view);
593 shift_view=DestroyCacheView(shift_view);
594 if (status == MagickFalse)
595 shift_image=DestroyImage(shift_image);
596 return(shift_image);
597}
598
599/*
600%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601% %
602% %
603% %
604% C h a r c o a l I m a g e %
605% %
606% %
607% %
608%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
609%
610% CharcoalImage() creates a new image that is a copy of an existing one with
611% the edge highlighted. It allocates the memory necessary for the new Image
612% structure and returns a pointer to the new image.
613%
614% The format of the CharcoalImage method is:
615%
616% Image *CharcoalImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +0000617% const double sigma,const double bias,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000618%
619% A description of each parameter follows:
620%
621% o image: the image.
622%
623% o radius: the radius of the pixel neighborhood.
624%
625% o sigma: the standard deviation of the Gaussian, in pixels.
626%
cristy05c0c9a2011-09-05 23:16:13 +0000627% o bias: the bias.
628%
cristy3ed852e2009-09-05 21:47:34 +0000629% o exception: return any errors or warnings in this structure.
630%
631*/
632MagickExport Image *CharcoalImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +0000633 const double sigma,const double bias,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000634{
635 Image
636 *charcoal_image,
637 *clone_image,
638 *edge_image;
639
640 assert(image != (Image *) NULL);
641 assert(image->signature == MagickSignature);
642 if (image->debug != MagickFalse)
643 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
644 assert(exception != (ExceptionInfo *) NULL);
645 assert(exception->signature == MagickSignature);
646 clone_image=CloneImage(image,0,0,MagickTrue,exception);
647 if (clone_image == (Image *) NULL)
648 return((Image *) NULL);
cristy018f07f2011-09-04 21:15:19 +0000649 (void) SetImageType(clone_image,GrayscaleType,exception);
cristy8ae632d2011-09-05 17:29:53 +0000650 edge_image=EdgeImage(clone_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +0000651 clone_image=DestroyImage(clone_image);
652 if (edge_image == (Image *) NULL)
653 return((Image *) NULL);
cristy05c0c9a2011-09-05 23:16:13 +0000654 charcoal_image=BlurImage(edge_image,radius,sigma,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +0000655 edge_image=DestroyImage(edge_image);
656 if (charcoal_image == (Image *) NULL)
657 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +0000658 (void) NormalizeImage(charcoal_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +0000659 (void) NegateImage(charcoal_image,MagickFalse,exception);
cristy018f07f2011-09-04 21:15:19 +0000660 (void) SetImageType(charcoal_image,GrayscaleType,exception);
cristy3ed852e2009-09-05 21:47:34 +0000661 return(charcoal_image);
662}
663
664/*
665%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
666% %
667% %
668% %
669% C o l o r i z e I m a g e %
670% %
671% %
672% %
673%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
674%
675% ColorizeImage() blends the fill color with each pixel in the image.
676% A percentage blend is specified with opacity. Control the application
677% of different color components by specifying a different percentage for
678% each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue).
679%
680% The format of the ColorizeImage method is:
681%
cristyc7e6ff62011-10-03 13:46:11 +0000682% Image *ColorizeImage(const Image *image,const char *blend,
683% const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000684%
685% A description of each parameter follows:
686%
687% o image: the image.
688%
cristyc7e6ff62011-10-03 13:46:11 +0000689% o blend: A character string indicating the level of blending as a
cristy3ed852e2009-09-05 21:47:34 +0000690% percentage.
691%
692% o colorize: A color value.
693%
694% o exception: return any errors or warnings in this structure.
695%
696*/
cristyc7e6ff62011-10-03 13:46:11 +0000697MagickExport Image *ColorizeImage(const Image *image,const char *blend,
698 const PixelInfo *colorize,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000699{
700#define ColorizeImageTag "Colorize/Image"
701
cristyc4c8d132010-01-07 01:58:38 +0000702 CacheView
703 *colorize_view,
704 *image_view;
705
cristy3ed852e2009-09-05 21:47:34 +0000706 GeometryInfo
707 geometry_info;
708
709 Image
710 *colorize_image;
711
cristy3ed852e2009-09-05 21:47:34 +0000712 MagickBooleanType
713 status;
714
cristybb503372010-05-27 20:51:26 +0000715 MagickOffsetType
716 progress;
717
cristy3ed852e2009-09-05 21:47:34 +0000718 MagickStatusType
719 flags;
720
cristyc7e6ff62011-10-03 13:46:11 +0000721 PixelInfo
722 pixel;
723
cristybb503372010-05-27 20:51:26 +0000724 ssize_t
725 y;
726
cristy3ed852e2009-09-05 21:47:34 +0000727 /*
728 Allocate colorized image.
729 */
730 assert(image != (const Image *) NULL);
731 assert(image->signature == MagickSignature);
732 if (image->debug != MagickFalse)
733 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
734 assert(exception != (ExceptionInfo *) NULL);
735 assert(exception->signature == MagickSignature);
736 colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
737 exception);
738 if (colorize_image == (Image *) NULL)
739 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000740 if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000741 {
cristy3ed852e2009-09-05 21:47:34 +0000742 colorize_image=DestroyImage(colorize_image);
743 return((Image *) NULL);
744 }
cristyc7e6ff62011-10-03 13:46:11 +0000745 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000746 return(colorize_image);
747 /*
748 Determine RGB values of the pen color.
749 */
cristyc7e6ff62011-10-03 13:46:11 +0000750 GetPixelInfo(image,&pixel);
cristyb817c3f2011-10-03 14:00:35 +0000751 flags=ParseGeometry(blend,&geometry_info);
cristy3ed852e2009-09-05 21:47:34 +0000752 pixel.red=geometry_info.rho;
753 pixel.green=geometry_info.rho;
754 pixel.blue=geometry_info.rho;
cristyc7e6ff62011-10-03 13:46:11 +0000755 pixel.alpha=100.0;
cristy3ed852e2009-09-05 21:47:34 +0000756 if ((flags & SigmaValue) != 0)
757 pixel.green=geometry_info.sigma;
758 if ((flags & XiValue) != 0)
759 pixel.blue=geometry_info.xi;
760 if ((flags & PsiValue) != 0)
cristy4c08aed2011-07-01 19:47:50 +0000761 pixel.alpha=geometry_info.psi;
cristyc7e6ff62011-10-03 13:46:11 +0000762 if (pixel.colorspace == CMYKColorspace)
763 {
764 pixel.black=geometry_info.rho;
765 if ((flags & PsiValue) != 0)
766 pixel.black=geometry_info.psi;
767 if ((flags & ChiValue) != 0)
768 pixel.alpha=geometry_info.chi;
769 }
cristy3ed852e2009-09-05 21:47:34 +0000770 /*
771 Colorize DirectClass image.
772 */
773 status=MagickTrue;
774 progress=0;
775 image_view=AcquireCacheView(image);
776 colorize_view=AcquireCacheView(colorize_image);
cristy319a1e72010-02-21 15:13:11 +0000777#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristyb5d5f722009-11-04 03:03:49 +0000778 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +0000779#endif
cristybb503372010-05-27 20:51:26 +0000780 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +0000781 {
782 MagickBooleanType
783 sync;
784
cristy4c08aed2011-07-01 19:47:50 +0000785 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +0000786 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000787
cristybb503372010-05-27 20:51:26 +0000788 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000789 x;
790
cristy4c08aed2011-07-01 19:47:50 +0000791 register Quantum
cristyc47d1f82009-11-26 01:44:43 +0000792 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000793
794 if (status == MagickFalse)
795 continue;
796 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
797 q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
798 exception);
cristy4c08aed2011-07-01 19:47:50 +0000799 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +0000800 {
801 status=MagickFalse;
802 continue;
803 }
cristybb503372010-05-27 20:51:26 +0000804 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000805 {
cristyc7e6ff62011-10-03 13:46:11 +0000806 register ssize_t
807 i;
808
809 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
810 {
811 PixelChannel
812 channel;
813
814 PixelTrait
815 colorize_traits,
816 traits;
817
818 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
819 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
820 colorize_traits=GetPixelChannelMapTraits(colorize_image,channel);
821 if ((traits == UndefinedPixelTrait) ||
822 (colorize_traits == UndefinedPixelTrait))
823 continue;
824 if ((colorize_traits & CopyPixelTrait) != 0)
825 {
826 SetPixelChannel(colorize_image,channel,p[i],q);
827 continue;
828 }
829 switch (channel)
830 {
831 case RedPixelChannel:
832 {
833 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
834 (100.0-pixel.red)+colorize->red*pixel.red)/100.0),q);
835 break;
836 }
837 case GreenPixelChannel:
838 {
839 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
840 (100.0-pixel.green)+colorize->green*pixel.green)/100.0),q);
841 break;
842 }
843 case BluePixelChannel:
844 {
845 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
846 (100.0-pixel.blue)+colorize->blue*pixel.blue)/100.0),q);
847 break;
848 }
849 case BlackPixelChannel:
850 {
851 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
852 (100.0-pixel.black)+colorize->black*pixel.black)/100.0),q);
853 break;
854 }
855 case AlphaPixelChannel:
856 {
857 SetPixelChannel(colorize_image,channel,ClampToQuantum((p[i]*
858 (100.0-pixel.alpha)+colorize->alpha*pixel.alpha)/100.0),q);
859 break;
860 }
861 default:
862 {
863 SetPixelChannel(colorize_image,channel,p[i],q);
864 break;
865 }
866 }
867 }
cristyed231572011-07-14 02:18:59 +0000868 p+=GetPixelChannels(image);
869 q+=GetPixelChannels(colorize_image);
cristy3ed852e2009-09-05 21:47:34 +0000870 }
871 sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
872 if (sync == MagickFalse)
873 status=MagickFalse;
874 if (image->progress_monitor != (MagickProgressMonitor) NULL)
875 {
876 MagickBooleanType
877 proceed;
878
cristy319a1e72010-02-21 15:13:11 +0000879#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000880 #pragma omp critical (MagickCore_ColorizeImage)
881#endif
882 proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
883 if (proceed == MagickFalse)
884 status=MagickFalse;
885 }
886 }
887 image_view=DestroyCacheView(image_view);
888 colorize_view=DestroyCacheView(colorize_view);
889 if (status == MagickFalse)
890 colorize_image=DestroyImage(colorize_image);
891 return(colorize_image);
892}
893
894/*
895%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896% %
897% %
898% %
cristye6365592010-04-02 17:31:23 +0000899% C o l o r M a t r i x I m a g e %
900% %
901% %
902% %
903%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904%
905% ColorMatrixImage() applies color transformation to an image. This method
906% permits saturation changes, hue rotation, luminance to alpha, and various
907% other effects. Although variable-sized transformation matrices can be used,
908% typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA
909% (or RGBA with offsets). The matrix is similar to those used by Adobe Flash
910% except offsets are in column 6 rather than 5 (in support of CMYKA images)
911% and offsets are normalized (divide Flash offset by 255).
912%
913% The format of the ColorMatrixImage method is:
914%
915% Image *ColorMatrixImage(const Image *image,
916% const KernelInfo *color_matrix,ExceptionInfo *exception)
917%
918% A description of each parameter follows:
919%
920% o image: the image.
921%
922% o color_matrix: the color matrix.
923%
924% o exception: return any errors or warnings in this structure.
925%
926*/
927MagickExport Image *ColorMatrixImage(const Image *image,
928 const KernelInfo *color_matrix,ExceptionInfo *exception)
929{
930#define ColorMatrixImageTag "ColorMatrix/Image"
931
932 CacheView
933 *color_view,
934 *image_view;
935
936 double
937 ColorMatrix[6][6] =
938 {
939 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 },
940 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 },
941 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 },
942 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 },
943 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 },
944 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }
945 };
946
947 Image
948 *color_image;
949
cristye6365592010-04-02 17:31:23 +0000950 MagickBooleanType
951 status;
952
cristybb503372010-05-27 20:51:26 +0000953 MagickOffsetType
954 progress;
955
956 register ssize_t
cristye6365592010-04-02 17:31:23 +0000957 i;
958
cristybb503372010-05-27 20:51:26 +0000959 ssize_t
960 u,
961 v,
962 y;
963
cristye6365592010-04-02 17:31:23 +0000964 /*
965 Create color matrix.
966 */
967 assert(image != (Image *) NULL);
968 assert(image->signature == MagickSignature);
969 if (image->debug != MagickFalse)
970 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
971 assert(exception != (ExceptionInfo *) NULL);
972 assert(exception->signature == MagickSignature);
973 i=0;
cristybb503372010-05-27 20:51:26 +0000974 for (v=0; v < (ssize_t) color_matrix->height; v++)
975 for (u=0; u < (ssize_t) color_matrix->width; u++)
cristye6365592010-04-02 17:31:23 +0000976 {
977 if ((v < 6) && (u < 6))
978 ColorMatrix[v][u]=color_matrix->values[i];
979 i++;
980 }
981 /*
982 Initialize color image.
983 */
cristy12550e62010-06-07 12:46:40 +0000984 color_image=CloneImage(image,0,0,MagickTrue,exception);
cristye6365592010-04-02 17:31:23 +0000985 if (color_image == (Image *) NULL)
986 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +0000987 if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse)
cristye6365592010-04-02 17:31:23 +0000988 {
cristye6365592010-04-02 17:31:23 +0000989 color_image=DestroyImage(color_image);
990 return((Image *) NULL);
991 }
992 if (image->debug != MagickFalse)
993 {
994 char
995 format[MaxTextExtent],
996 *message;
997
998 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
999 " ColorMatrix image with color matrix:");
1000 message=AcquireString("");
1001 for (v=0; v < 6; v++)
1002 {
1003 *message='\0';
cristyb51dff52011-05-19 16:55:47 +00001004 (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
cristye6365592010-04-02 17:31:23 +00001005 (void) ConcatenateString(&message,format);
1006 for (u=0; u < 6; u++)
1007 {
cristyb51dff52011-05-19 16:55:47 +00001008 (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
cristye6365592010-04-02 17:31:23 +00001009 ColorMatrix[v][u]);
1010 (void) ConcatenateString(&message,format);
1011 }
1012 (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
1013 }
1014 message=DestroyString(message);
1015 }
1016 /*
1017 ColorMatrix image.
1018 */
1019 status=MagickTrue;
1020 progress=0;
1021 image_view=AcquireCacheView(image);
1022 color_view=AcquireCacheView(color_image);
1023#if defined(MAGICKCORE_OPENMP_SUPPORT)
1024 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
1025#endif
cristybb503372010-05-27 20:51:26 +00001026 for (y=0; y < (ssize_t) image->rows; y++)
cristye6365592010-04-02 17:31:23 +00001027 {
1028 MagickRealType
1029 pixel;
1030
cristy4c08aed2011-07-01 19:47:50 +00001031 register const Quantum
cristye6365592010-04-02 17:31:23 +00001032 *restrict p;
1033
cristy4c08aed2011-07-01 19:47:50 +00001034 register Quantum
1035 *restrict q;
1036
cristybb503372010-05-27 20:51:26 +00001037 register ssize_t
cristye6365592010-04-02 17:31:23 +00001038 x;
1039
cristye6365592010-04-02 17:31:23 +00001040 if (status == MagickFalse)
1041 continue;
1042 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
1043 q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1,
1044 exception);
cristy4c08aed2011-07-01 19:47:50 +00001045 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristye6365592010-04-02 17:31:23 +00001046 {
1047 status=MagickFalse;
1048 continue;
1049 }
cristybb503372010-05-27 20:51:26 +00001050 for (x=0; x < (ssize_t) image->columns; x++)
cristye6365592010-04-02 17:31:23 +00001051 {
cristybb503372010-05-27 20:51:26 +00001052 register ssize_t
cristye6365592010-04-02 17:31:23 +00001053 v;
1054
cristybb503372010-05-27 20:51:26 +00001055 size_t
cristye6365592010-04-02 17:31:23 +00001056 height;
1057
1058 height=color_matrix->height > 6 ? 6UL : color_matrix->height;
cristybb503372010-05-27 20:51:26 +00001059 for (v=0; v < (ssize_t) height; v++)
cristye6365592010-04-02 17:31:23 +00001060 {
cristy4c08aed2011-07-01 19:47:50 +00001061 pixel=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
1062 GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
cristye6365592010-04-02 17:31:23 +00001063 if (image->colorspace == CMYKColorspace)
cristy4c08aed2011-07-01 19:47:50 +00001064 pixel+=ColorMatrix[v][3]*GetPixelBlack(image,p);
1065 if (image->matte != MagickFalse)
1066 pixel+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
cristye6365592010-04-02 17:31:23 +00001067 pixel+=QuantumRange*ColorMatrix[v][5];
1068 switch (v)
1069 {
cristy4c08aed2011-07-01 19:47:50 +00001070 case 0: SetPixelRed(color_image,ClampToQuantum(pixel),q); break;
1071 case 1: SetPixelGreen(color_image,ClampToQuantum(pixel),q); break;
1072 case 2: SetPixelBlue(color_image,ClampToQuantum(pixel),q); break;
cristye6365592010-04-02 17:31:23 +00001073 case 3:
1074 {
cristy4c08aed2011-07-01 19:47:50 +00001075 if (image->colorspace == CMYKColorspace)
1076 SetPixelBlack(color_image,ClampToQuantum(pixel),q);
cristye6365592010-04-02 17:31:23 +00001077 break;
1078 }
1079 case 4:
1080 {
cristy4c08aed2011-07-01 19:47:50 +00001081 if (image->matte != MagickFalse)
1082 SetPixelAlpha(color_image,ClampToQuantum(pixel),q);
cristye6365592010-04-02 17:31:23 +00001083 break;
1084 }
1085 }
1086 }
cristyed231572011-07-14 02:18:59 +00001087 p+=GetPixelChannels(image);
1088 q+=GetPixelChannels(color_image);
cristye6365592010-04-02 17:31:23 +00001089 }
1090 if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse)
1091 status=MagickFalse;
1092 if (image->progress_monitor != (MagickProgressMonitor) NULL)
1093 {
1094 MagickBooleanType
1095 proceed;
1096
1097#if defined(MAGICKCORE_OPENMP_SUPPORT)
1098 #pragma omp critical (MagickCore_ColorMatrixImage)
1099#endif
1100 proceed=SetImageProgress(image,ColorMatrixImageTag,progress++,
1101 image->rows);
1102 if (proceed == MagickFalse)
1103 status=MagickFalse;
1104 }
1105 }
1106 color_view=DestroyCacheView(color_view);
1107 image_view=DestroyCacheView(image_view);
1108 if (status == MagickFalse)
1109 color_image=DestroyImage(color_image);
1110 return(color_image);
1111}
1112
1113/*
1114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1115% %
1116% %
1117% %
cristy3ed852e2009-09-05 21:47:34 +00001118+ D e s t r o y F x I n f o %
1119% %
1120% %
1121% %
1122%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123%
1124% DestroyFxInfo() deallocates memory associated with an FxInfo structure.
1125%
1126% The format of the DestroyFxInfo method is:
1127%
1128% ImageInfo *DestroyFxInfo(ImageInfo *fx_info)
1129%
1130% A description of each parameter follows:
1131%
1132% o fx_info: the fx info.
1133%
1134*/
cristy7832dc22011-09-05 01:21:53 +00001135MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
cristy3ed852e2009-09-05 21:47:34 +00001136{
cristybb503372010-05-27 20:51:26 +00001137 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001138 i;
1139
1140 fx_info->exception=DestroyExceptionInfo(fx_info->exception);
1141 fx_info->expression=DestroyString(fx_info->expression);
1142 fx_info->symbols=DestroySplayTree(fx_info->symbols);
1143 fx_info->colors=DestroySplayTree(fx_info->colors);
cristy0ea377f2011-03-24 00:54:19 +00001144 for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--)
cristyd76c51e2011-03-26 00:21:26 +00001145 fx_info->view[i]=DestroyCacheView(fx_info->view[i]);
1146 fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view);
cristy3ed852e2009-09-05 21:47:34 +00001147 fx_info->random_info=DestroyRandomInfo(fx_info->random_info);
1148 fx_info=(FxInfo *) RelinquishMagickMemory(fx_info);
1149 return(fx_info);
1150}
1151
1152/*
1153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1154% %
1155% %
1156% %
cristy3ed852e2009-09-05 21:47:34 +00001157+ F x E v a l u a t e C h a n n e l E x p r e s s i o n %
1158% %
1159% %
1160% %
1161%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1162%
1163% FxEvaluateChannelExpression() evaluates an expression and returns the
1164% results.
1165%
1166% The format of the FxEvaluateExpression method is:
1167%
1168% MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00001169% const PixelChannel channel,const ssize_t x,const ssize_t y,
cristy3ed852e2009-09-05 21:47:34 +00001170% MagickRealType *alpha,Exceptioninfo *exception)
1171% MagickRealType FxEvaluateExpression(FxInfo *fx_info,
1172% MagickRealType *alpha,Exceptioninfo *exception)
1173%
1174% A description of each parameter follows:
1175%
1176% o fx_info: the fx info.
1177%
1178% o channel: the channel.
1179%
1180% o x,y: the pixel position.
1181%
1182% o alpha: the result.
1183%
1184% o exception: return any errors or warnings in this structure.
1185%
1186*/
1187
cristy351842f2010-03-07 15:27:38 +00001188static inline double MagickMax(const double x,const double y)
1189{
1190 if (x > y)
1191 return(x);
1192 return(y);
1193}
1194
1195static inline double MagickMin(const double x,const double y)
1196{
1197 if (x < y)
1198 return(x);
1199 return(y);
1200}
1201
cristy3ed852e2009-09-05 21:47:34 +00001202static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
cristy0568ffc2011-07-25 16:54:14 +00001203 PixelChannel channel,const char *symbol,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001204{
1205 char
1206 key[MaxTextExtent],
1207 statistic[MaxTextExtent];
1208
1209 const char
1210 *value;
1211
1212 register const char
1213 *p;
1214
1215 for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
1216 if (*p == '.')
1217 switch (*++p) /* e.g. depth.r */
1218 {
cristy541ae572011-08-05 19:08:59 +00001219 case 'r': channel=RedPixelChannel; break;
1220 case 'g': channel=GreenPixelChannel; break;
1221 case 'b': channel=BluePixelChannel; break;
1222 case 'c': channel=CyanPixelChannel; break;
1223 case 'm': channel=MagentaPixelChannel; break;
1224 case 'y': channel=YellowPixelChannel; break;
1225 case 'k': channel=BlackPixelChannel; break;
cristy3ed852e2009-09-05 21:47:34 +00001226 default: break;
1227 }
cristyb51dff52011-05-19 16:55:47 +00001228 (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
cristye8c25f92010-06-03 00:53:06 +00001229 (double) channel,symbol);
cristy3ed852e2009-09-05 21:47:34 +00001230 value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
1231 if (value != (const char *) NULL)
cristyc1acd842011-05-19 23:05:47 +00001232 return(QuantumScale*InterpretLocaleValue(value,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001233 (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
1234 if (LocaleNCompare(symbol,"depth",5) == 0)
1235 {
cristybb503372010-05-27 20:51:26 +00001236 size_t
cristy3ed852e2009-09-05 21:47:34 +00001237 depth;
1238
cristyfefab1b2011-07-05 00:33:22 +00001239 depth=GetImageDepth(image,exception);
1240 (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
cristy3ed852e2009-09-05 21:47:34 +00001241 }
1242 if (LocaleNCompare(symbol,"kurtosis",8) == 0)
1243 {
1244 double
1245 kurtosis,
1246 skewness;
1247
cristyd42d9952011-07-08 14:21:50 +00001248 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001249 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
cristy3ed852e2009-09-05 21:47:34 +00001250 }
1251 if (LocaleNCompare(symbol,"maxima",6) == 0)
1252 {
1253 double
1254 maxima,
1255 minima;
1256
cristyd42d9952011-07-08 14:21:50 +00001257 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001258 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
cristy3ed852e2009-09-05 21:47:34 +00001259 }
1260 if (LocaleNCompare(symbol,"mean",4) == 0)
1261 {
1262 double
1263 mean,
1264 standard_deviation;
1265
cristyd42d9952011-07-08 14:21:50 +00001266 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001267 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
cristy3ed852e2009-09-05 21:47:34 +00001268 }
1269 if (LocaleNCompare(symbol,"minima",6) == 0)
1270 {
1271 double
1272 maxima,
1273 minima;
1274
cristyd42d9952011-07-08 14:21:50 +00001275 (void) GetImageRange(image,&minima,&maxima,exception);
cristyb51dff52011-05-19 16:55:47 +00001276 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
cristy3ed852e2009-09-05 21:47:34 +00001277 }
1278 if (LocaleNCompare(symbol,"skewness",8) == 0)
1279 {
1280 double
1281 kurtosis,
1282 skewness;
1283
cristyd42d9952011-07-08 14:21:50 +00001284 (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
cristyb51dff52011-05-19 16:55:47 +00001285 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
cristy3ed852e2009-09-05 21:47:34 +00001286 }
1287 if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
1288 {
1289 double
1290 mean,
1291 standard_deviation;
1292
cristyd42d9952011-07-08 14:21:50 +00001293 (void) GetImageMean(image,&mean,&standard_deviation,exception);
cristyb51dff52011-05-19 16:55:47 +00001294 (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
cristy3ed852e2009-09-05 21:47:34 +00001295 standard_deviation);
1296 }
1297 (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
1298 ConstantString(statistic));
cristyc1acd842011-05-19 23:05:47 +00001299 return(QuantumScale*InterpretLocaleValue(statistic,(char **) NULL));
cristy3ed852e2009-09-05 21:47:34 +00001300}
1301
1302static MagickRealType
cristy0568ffc2011-07-25 16:54:14 +00001303 FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
cristye85007d2010-06-06 22:51:36 +00001304 const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
cristy3ed852e2009-09-05 21:47:34 +00001305
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);
2609 gcd=FxGCD((MagickOffsetType) alpha,(MagickOffsetType) *beta);
2610 return((MagickRealType) gcd);
2611 }
cristy3ed852e2009-09-05 21:47:34 +00002612 if (LocaleCompare(expression,"g") == 0)
2613 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2614 break;
2615 }
2616 case 'H':
2617 case 'h':
2618 {
2619 if (LocaleCompare(expression,"h") == 0)
2620 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2621 if (LocaleCompare(expression,"hue") == 0)
2622 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2623 if (LocaleNCompare(expression,"hypot",5) == 0)
2624 {
2625 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2626 exception);
2627 return((MagickRealType) hypot((double) alpha,(double) *beta));
2628 }
2629 break;
2630 }
2631 case 'K':
2632 case 'k':
2633 {
2634 if (LocaleCompare(expression,"k") == 0)
2635 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2636 break;
2637 }
2638 case 'I':
2639 case 'i':
2640 {
2641 if (LocaleCompare(expression,"intensity") == 0)
2642 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2643 if (LocaleNCompare(expression,"int",3) == 0)
2644 {
2645 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2646 exception);
cristy16788e42010-08-13 13:44:26 +00002647 return((MagickRealType) floor(alpha));
cristy3ed852e2009-09-05 21:47:34 +00002648 }
cristy639399c2011-11-02 19:16:15 +00002649 if (LocaleNCompare(expression,"isnan",5) == 0)
2650 {
2651 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2652 exception);
cristy17a10202011-11-02 19:17:04 +00002653 return((MagickRealType) !!isnan((double) alpha));
cristy639399c2011-11-02 19:16:15 +00002654 }
cristy3ed852e2009-09-05 21:47:34 +00002655 if (LocaleCompare(expression,"i") == 0)
2656 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2657 break;
2658 }
2659 case 'J':
2660 case 'j':
2661 {
2662 if (LocaleCompare(expression,"j") == 0)
2663 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
cristy161b9262010-03-20 19:34:32 +00002664#if defined(MAGICKCORE_HAVE_J0)
cristyee56cf12010-03-01 22:17:06 +00002665 if (LocaleNCompare(expression,"j0",2) == 0)
2666 {
2667 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2668 exception);
2669 return((MagickRealType) j0((double) alpha));
2670 }
cristy161b9262010-03-20 19:34:32 +00002671#endif
2672#if defined(MAGICKCORE_HAVE_J1)
cristyee56cf12010-03-01 22:17:06 +00002673 if (LocaleNCompare(expression,"j1",2) == 0)
2674 {
2675 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2676 exception);
2677 return((MagickRealType) j1((double) alpha));
2678 }
cristy161b9262010-03-20 19:34:32 +00002679#endif
cristyaa018fa2010-04-08 23:03:54 +00002680#if defined(MAGICKCORE_HAVE_J1)
cristya6a09e72010-03-02 14:51:02 +00002681 if (LocaleNCompare(expression,"jinc",4) == 0)
2682 {
2683 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2684 exception);
cristy0946a822010-03-12 17:14:58 +00002685 if (alpha == 0.0)
2686 return(1.0);
cristy69928f92010-03-12 13:27:09 +00002687 gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/
cristyfce2f7b2010-03-12 00:29:49 +00002688 (MagickPI*alpha));
2689 return(gamma);
cristya6a09e72010-03-02 14:51:02 +00002690 }
cristyaa018fa2010-04-08 23:03:54 +00002691#endif
cristy3ed852e2009-09-05 21:47:34 +00002692 break;
2693 }
2694 case 'L':
2695 case 'l':
2696 {
2697 if (LocaleNCompare(expression,"ln",2) == 0)
2698 {
2699 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
2700 exception);
2701 return((MagickRealType) log((double) alpha));
2702 }
cristyc8ed5322010-08-31 12:07:59 +00002703 if (LocaleNCompare(expression,"logtwo",6) == 0)
cristy3ed852e2009-09-05 21:47:34 +00002704 {
cristyc8ed5322010-08-31 12:07:59 +00002705 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
cristy3ed852e2009-09-05 21:47:34 +00002706 exception);
2707 return((MagickRealType) log10((double) alpha))/log10(2.0);
2708 }
2709 if (LocaleNCompare(expression,"log",3) == 0)
2710 {
2711 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2712 exception);
2713 return((MagickRealType) log10((double) alpha));
2714 }
2715 if (LocaleCompare(expression,"lightness") == 0)
2716 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2717 break;
2718 }
2719 case 'M':
2720 case 'm':
2721 {
2722 if (LocaleCompare(expression,"MaxRGB") == 0)
2723 return((MagickRealType) QuantumRange);
2724 if (LocaleNCompare(expression,"maxima",6) == 0)
2725 break;
2726 if (LocaleNCompare(expression,"max",3) == 0)
2727 return(FxMax(fx_info,channel,x,y,expression+3,exception));
2728 if (LocaleNCompare(expression,"minima",6) == 0)
2729 break;
2730 if (LocaleNCompare(expression,"min",3) == 0)
2731 return(FxMin(fx_info,channel,x,y,expression+3,exception));
2732 if (LocaleNCompare(expression,"mod",3) == 0)
2733 {
2734 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2735 exception);
2736 return((MagickRealType) fmod((double) alpha,(double) *beta));
2737 }
2738 if (LocaleCompare(expression,"m") == 0)
2739 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2740 break;
2741 }
2742 case 'N':
2743 case 'n':
2744 {
cristyad3502e2011-11-02 19:10:45 +00002745 if (LocaleNCompare(expression,"not",3) == 0)
2746 {
2747 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2748 exception);
2749 return((MagickRealType) (alpha < MagickEpsilon));
2750 }
cristy3ed852e2009-09-05 21:47:34 +00002751 if (LocaleCompare(expression,"n") == 0)
2752 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2753 break;
2754 }
2755 case 'O':
2756 case 'o':
2757 {
2758 if (LocaleCompare(expression,"Opaque") == 0)
2759 return(1.0);
2760 if (LocaleCompare(expression,"o") == 0)
2761 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2762 break;
2763 }
2764 case 'P':
2765 case 'p':
2766 {
2767 if (LocaleCompare(expression,"pi") == 0)
2768 return((MagickRealType) MagickPI);
2769 if (LocaleNCompare(expression,"pow",3) == 0)
2770 {
2771 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2772 exception);
2773 return((MagickRealType) pow((double) alpha,(double) *beta));
2774 }
2775 if (LocaleCompare(expression,"p") == 0)
2776 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2777 break;
2778 }
2779 case 'Q':
2780 case 'q':
2781 {
2782 if (LocaleCompare(expression,"QuantumRange") == 0)
2783 return((MagickRealType) QuantumRange);
2784 if (LocaleCompare(expression,"QuantumScale") == 0)
2785 return((MagickRealType) QuantumScale);
2786 break;
2787 }
2788 case 'R':
2789 case 'r':
2790 {
2791 if (LocaleNCompare(expression,"rand",4) == 0)
2792 return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
2793 if (LocaleNCompare(expression,"round",5) == 0)
2794 {
2795 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2796 exception);
cristy16788e42010-08-13 13:44:26 +00002797 return((MagickRealType) floor((double) alpha+0.5));
cristy3ed852e2009-09-05 21:47:34 +00002798 }
2799 if (LocaleCompare(expression,"r") == 0)
2800 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2801 break;
2802 }
2803 case 'S':
2804 case 's':
2805 {
2806 if (LocaleCompare(expression,"saturation") == 0)
2807 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2808 if (LocaleNCompare(expression,"sign",4) == 0)
2809 {
2810 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2811 exception);
2812 return(alpha < 0.0 ? -1.0 : 1.0);
2813 }
cristya6a09e72010-03-02 14:51:02 +00002814 if (LocaleNCompare(expression,"sinc",4) == 0)
2815 {
2816 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2817 exception);
2818 if (alpha == 0)
2819 return(1.0);
2820 gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
2821 (MagickPI*alpha));
2822 return(gamma);
2823 }
cristy3ed852e2009-09-05 21:47:34 +00002824 if (LocaleNCompare(expression,"sinh",4) == 0)
2825 {
2826 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2827 exception);
2828 return((MagickRealType) sinh((double) alpha));
2829 }
2830 if (LocaleNCompare(expression,"sin",3) == 0)
2831 {
2832 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2833 exception);
2834 return((MagickRealType) sin((double) alpha));
2835 }
2836 if (LocaleNCompare(expression,"sqrt",4) == 0)
2837 {
2838 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2839 exception);
2840 return((MagickRealType) sqrt((double) alpha));
2841 }
cristy9eeedea2011-11-02 19:04:05 +00002842 if (LocaleNCompare(expression,"squish",6) == 0)
2843 {
2844 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
2845 exception);
2846 return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha)))));
2847 }
cristy3ed852e2009-09-05 21:47:34 +00002848 if (LocaleCompare(expression,"s") == 0)
2849 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2850 break;
2851 }
2852 case 'T':
2853 case 't':
2854 {
2855 if (LocaleNCompare(expression,"tanh",4) == 0)
2856 {
2857 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
2858 exception);
2859 return((MagickRealType) tanh((double) alpha));
2860 }
2861 if (LocaleNCompare(expression,"tan",3) == 0)
2862 {
2863 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
2864 exception);
2865 return((MagickRealType) tan((double) alpha));
2866 }
2867 if (LocaleCompare(expression,"Transparent") == 0)
2868 return(0.0);
cristy16788e42010-08-13 13:44:26 +00002869 if (LocaleNCompare(expression,"trunc",5) == 0)
2870 {
2871 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2872 exception);
2873 if (alpha >= 0.0)
2874 return((MagickRealType) floor((double) alpha));
2875 return((MagickRealType) ceil((double) alpha));
2876 }
cristy3ed852e2009-09-05 21:47:34 +00002877 if (LocaleCompare(expression,"t") == 0)
2878 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2879 break;
2880 }
2881 case 'U':
2882 case 'u':
2883 {
2884 if (LocaleCompare(expression,"u") == 0)
2885 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2886 break;
2887 }
2888 case 'V':
2889 case 'v':
2890 {
2891 if (LocaleCompare(expression,"v") == 0)
2892 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2893 break;
2894 }
2895 case 'W':
2896 case 'w':
2897 {
cristy9eeedea2011-11-02 19:04:05 +00002898 if (LocaleNCompare(expression,"while",5) == 0)
2899 {
2900 do
2901 {
2902 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
2903 exception);
2904 } while (fabs((double) alpha) >= MagickEpsilon);
2905 return((MagickRealType) *beta);
2906 }
cristy3ed852e2009-09-05 21:47:34 +00002907 if (LocaleCompare(expression,"w") == 0)
2908 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2909 break;
2910 }
2911 case 'Y':
2912 case 'y':
2913 {
2914 if (LocaleCompare(expression,"y") == 0)
2915 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2916 break;
2917 }
2918 case 'Z':
2919 case 'z':
2920 {
2921 if (LocaleCompare(expression,"z") == 0)
2922 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2923 break;
2924 }
2925 default:
2926 break;
2927 }
2928 q=(char *) expression;
cristyc1acd842011-05-19 23:05:47 +00002929 alpha=InterpretLocaleValue(expression,&q);
cristy3ed852e2009-09-05 21:47:34 +00002930 if (q == expression)
2931 return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
2932 return(alpha);
2933}
2934
cristy7832dc22011-09-05 01:21:53 +00002935MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
cristy3ed852e2009-09-05 21:47:34 +00002936 MagickRealType *alpha,ExceptionInfo *exception)
2937{
2938 MagickBooleanType
2939 status;
2940
cristy541ae572011-08-05 19:08:59 +00002941 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2942 exception);
cristy3ed852e2009-09-05 21:47:34 +00002943 return(status);
2944}
2945
2946MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
2947 MagickRealType *alpha,ExceptionInfo *exception)
2948{
2949 FILE
2950 *file;
2951
2952 MagickBooleanType
2953 status;
2954
2955 file=fx_info->file;
2956 fx_info->file=(FILE *) NULL;
cristy541ae572011-08-05 19:08:59 +00002957 status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha,
2958 exception);
cristy3ed852e2009-09-05 21:47:34 +00002959 fx_info->file=file;
2960 return(status);
2961}
2962
cristy7832dc22011-09-05 01:21:53 +00002963MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
cristy0568ffc2011-07-25 16:54:14 +00002964 const PixelChannel channel,const ssize_t x,const ssize_t y,
cristye85007d2010-06-06 22:51:36 +00002965 MagickRealType *alpha,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002966{
2967 MagickRealType
2968 beta;
2969
2970 beta=0.0;
2971 *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
2972 exception);
2973 return(exception->severity == OptionError ? MagickFalse : MagickTrue);
2974}
2975
2976/*
2977%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2978% %
2979% %
2980% %
2981% F x I m a g e %
2982% %
2983% %
2984% %
2985%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2986%
2987% FxImage() applies a mathematical expression to the specified image.
2988%
2989% The format of the FxImage method is:
2990%
2991% Image *FxImage(const Image *image,const char *expression,
2992% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00002993%
2994% A description of each parameter follows:
2995%
2996% o image: the image.
2997%
cristy3ed852e2009-09-05 21:47:34 +00002998% o expression: A mathematical expression.
2999%
3000% o exception: return any errors or warnings in this structure.
3001%
3002*/
3003
3004static FxInfo **DestroyFxThreadSet(FxInfo **fx_info)
3005{
cristybb503372010-05-27 20:51:26 +00003006 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003007 i;
3008
3009 assert(fx_info != (FxInfo **) NULL);
cristybb503372010-05-27 20:51:26 +00003010 for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
cristy3ed852e2009-09-05 21:47:34 +00003011 if (fx_info[i] != (FxInfo *) NULL)
3012 fx_info[i]=DestroyFxInfo(fx_info[i]);
cristyb41ee102010-10-04 16:46:15 +00003013 fx_info=(FxInfo **) RelinquishMagickMemory(fx_info);
cristy3ed852e2009-09-05 21:47:34 +00003014 return(fx_info);
3015}
3016
3017static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
3018 ExceptionInfo *exception)
3019{
3020 char
3021 *fx_expression;
3022
3023 FxInfo
3024 **fx_info;
3025
3026 MagickRealType
3027 alpha;
3028
cristybb503372010-05-27 20:51:26 +00003029 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003030 i;
3031
cristybb503372010-05-27 20:51:26 +00003032 size_t
cristy3ed852e2009-09-05 21:47:34 +00003033 number_threads;
3034
3035 number_threads=GetOpenMPMaximumThreads();
cristyb41ee102010-10-04 16:46:15 +00003036 fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
cristy3ed852e2009-09-05 21:47:34 +00003037 if (fx_info == (FxInfo **) NULL)
3038 return((FxInfo **) NULL);
3039 (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
3040 if (*expression != '@')
3041 fx_expression=ConstantString(expression);
3042 else
3043 fx_expression=FileToString(expression+1,~0,exception);
cristybb503372010-05-27 20:51:26 +00003044 for (i=0; i < (ssize_t) number_threads; i++)
cristy3ed852e2009-09-05 21:47:34 +00003045 {
3046 fx_info[i]=AcquireFxInfo(image,fx_expression);
3047 if (fx_info[i] == (FxInfo *) NULL)
3048 return(DestroyFxThreadSet(fx_info));
3049 (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
3050 }
3051 fx_expression=DestroyString(fx_expression);
3052 return(fx_info);
3053}
3054
3055MagickExport Image *FxImage(const Image *image,const char *expression,
3056 ExceptionInfo *exception)
3057{
cristy3ed852e2009-09-05 21:47:34 +00003058#define FxImageTag "Fx/Image"
3059
cristyfa112112010-01-04 17:48:07 +00003060 CacheView
cristy79cedc72011-07-25 00:41:15 +00003061 *fx_view,
3062 *image_view;
cristyfa112112010-01-04 17:48:07 +00003063
cristy3ed852e2009-09-05 21:47:34 +00003064 FxInfo
cristyfa112112010-01-04 17:48:07 +00003065 **restrict fx_info;
cristy3ed852e2009-09-05 21:47:34 +00003066
3067 Image
3068 *fx_image;
3069
cristy3ed852e2009-09-05 21:47:34 +00003070 MagickBooleanType
3071 status;
3072
cristybb503372010-05-27 20:51:26 +00003073 MagickOffsetType
3074 progress;
3075
cristy3ed852e2009-09-05 21:47:34 +00003076 MagickRealType
3077 alpha;
3078
cristybb503372010-05-27 20:51:26 +00003079 ssize_t
3080 y;
3081
cristy3ed852e2009-09-05 21:47:34 +00003082 assert(image != (Image *) NULL);
3083 assert(image->signature == MagickSignature);
3084 if (image->debug != MagickFalse)
3085 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cristy79cedc72011-07-25 00:41:15 +00003086 fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00003087 if (fx_image == (Image *) NULL)
3088 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003089 if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003090 {
cristy3ed852e2009-09-05 21:47:34 +00003091 fx_image=DestroyImage(fx_image);
3092 return((Image *) NULL);
3093 }
3094 fx_info=AcquireFxThreadSet(image,expression,exception);
3095 if (fx_info == (FxInfo **) NULL)
3096 {
3097 fx_image=DestroyImage(fx_image);
3098 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
3099 }
3100 status=FxPreprocessExpression(fx_info[0],&alpha,exception);
3101 if (status == MagickFalse)
3102 {
3103 fx_image=DestroyImage(fx_image);
3104 fx_info=DestroyFxThreadSet(fx_info);
3105 return((Image *) NULL);
3106 }
3107 /*
3108 Fx image.
3109 */
3110 status=MagickTrue;
3111 progress=0;
cristy79cedc72011-07-25 00:41:15 +00003112 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003113 fx_view=AcquireCacheView(fx_image);
cristyb5d5f722009-11-04 03:03:49 +00003114#if defined(MAGICKCORE_OPENMP_SUPPORT)
3115 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003116#endif
cristybb503372010-05-27 20:51:26 +00003117 for (y=0; y < (ssize_t) fx_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003118 {
cristy5c9e6f22010-09-17 17:31:01 +00003119 const int
3120 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00003121
cristy79cedc72011-07-25 00:41:15 +00003122 register const Quantum
3123 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003124
cristy4c08aed2011-07-01 19:47:50 +00003125 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003126 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003127
cristy79cedc72011-07-25 00:41:15 +00003128 register ssize_t
3129 x;
3130
cristy3ed852e2009-09-05 21:47:34 +00003131 if (status == MagickFalse)
3132 continue;
cristy79cedc72011-07-25 00:41:15 +00003133 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003134 q=GetCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception);
cristy79cedc72011-07-25 00:41:15 +00003135 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003136 {
3137 status=MagickFalse;
3138 continue;
3139 }
cristybb503372010-05-27 20:51:26 +00003140 for (x=0; x < (ssize_t) fx_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003141 {
cristy79cedc72011-07-25 00:41:15 +00003142 register ssize_t
3143 i;
3144
3145 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3146 {
3147 MagickRealType
3148 alpha;
3149
3150 PixelChannel
3151 channel;
3152
3153 PixelTrait
3154 fx_traits,
3155 traits;
3156
3157 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
cristy79cedc72011-07-25 00:41:15 +00003158 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3159 fx_traits=GetPixelChannelMapTraits(fx_image,channel);
cristy010d7d12011-08-31 01:02:48 +00003160 if ((traits == UndefinedPixelTrait) ||
3161 (fx_traits == UndefinedPixelTrait))
cristy79cedc72011-07-25 00:41:15 +00003162 continue;
3163 if ((fx_traits & CopyPixelTrait) != 0)
3164 {
cristy0beccfa2011-09-25 20:47:53 +00003165 SetPixelChannel(fx_image,channel,p[i],q);
cristy79cedc72011-07-25 00:41:15 +00003166 continue;
3167 }
3168 alpha=0.0;
cristy0568ffc2011-07-25 16:54:14 +00003169 (void) FxEvaluateChannelExpression(fx_info[id],(PixelChannel) i,x,y,
3170 &alpha,exception);
cristyb3a73b52011-07-26 01:34:43 +00003171 q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
cristy79cedc72011-07-25 00:41:15 +00003172 }
3173 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003174 q+=GetPixelChannels(fx_image);
cristy3ed852e2009-09-05 21:47:34 +00003175 }
3176 if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse)
3177 status=MagickFalse;
3178 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3179 {
3180 MagickBooleanType
3181 proceed;
3182
cristyb5d5f722009-11-04 03:03:49 +00003183#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy490408a2011-07-07 14:42:05 +00003184 #pragma omp critical (MagickCore_FxImage)
cristy3ed852e2009-09-05 21:47:34 +00003185#endif
3186 proceed=SetImageProgress(image,FxImageTag,progress++,image->rows);
3187 if (proceed == MagickFalse)
3188 status=MagickFalse;
3189 }
3190 }
cristy3ed852e2009-09-05 21:47:34 +00003191 fx_view=DestroyCacheView(fx_view);
cristy79cedc72011-07-25 00:41:15 +00003192 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003193 fx_info=DestroyFxThreadSet(fx_info);
3194 if (status == MagickFalse)
3195 fx_image=DestroyImage(fx_image);
3196 return(fx_image);
3197}
3198
3199/*
3200%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3201% %
3202% %
3203% %
3204% I m p l o d e I m a g e %
3205% %
3206% %
3207% %
3208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3209%
3210% ImplodeImage() creates a new image that is a copy of an existing
3211% one with the image pixels "implode" by the specified percentage. It
3212% allocates the memory necessary for the new Image structure and returns a
3213% pointer to the new image.
3214%
3215% The format of the ImplodeImage method is:
3216%
3217% Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003218% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003219%
3220% A description of each parameter follows:
3221%
3222% o implode_image: Method ImplodeImage returns a pointer to the image
3223% after it is implode. A null image is returned if there is a memory
3224% shortage.
3225%
3226% o image: the image.
3227%
3228% o amount: Define the extent of the implosion.
3229%
cristy76f512e2011-09-12 01:26:56 +00003230% o method: the pixel interpolation method.
3231%
cristy3ed852e2009-09-05 21:47:34 +00003232% o exception: return any errors or warnings in this structure.
3233%
3234*/
3235MagickExport Image *ImplodeImage(const Image *image,const double amount,
cristy76f512e2011-09-12 01:26:56 +00003236 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003237{
3238#define ImplodeImageTag "Implode/Image"
3239
cristyfa112112010-01-04 17:48:07 +00003240 CacheView
3241 *image_view,
3242 *implode_view;
3243
cristy3ed852e2009-09-05 21:47:34 +00003244 Image
3245 *implode_image;
3246
cristy3ed852e2009-09-05 21:47:34 +00003247 MagickBooleanType
3248 status;
3249
cristybb503372010-05-27 20:51:26 +00003250 MagickOffsetType
3251 progress;
3252
cristy3ed852e2009-09-05 21:47:34 +00003253 MagickRealType
3254 radius;
3255
3256 PointInfo
3257 center,
3258 scale;
3259
cristybb503372010-05-27 20:51:26 +00003260 ssize_t
3261 y;
3262
cristy3ed852e2009-09-05 21:47:34 +00003263 /*
3264 Initialize implode image attributes.
3265 */
3266 assert(image != (Image *) NULL);
3267 assert(image->signature == MagickSignature);
3268 if (image->debug != MagickFalse)
3269 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3270 assert(exception != (ExceptionInfo *) NULL);
3271 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00003272 implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
3273 exception);
cristy3ed852e2009-09-05 21:47:34 +00003274 if (implode_image == (Image *) NULL)
3275 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00003276 if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003277 {
cristy3ed852e2009-09-05 21:47:34 +00003278 implode_image=DestroyImage(implode_image);
3279 return((Image *) NULL);
3280 }
cristy4c08aed2011-07-01 19:47:50 +00003281 if (implode_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00003282 implode_image->matte=MagickTrue;
3283 /*
3284 Compute scaling factor.
3285 */
3286 scale.x=1.0;
3287 scale.y=1.0;
3288 center.x=0.5*image->columns;
3289 center.y=0.5*image->rows;
3290 radius=center.x;
3291 if (image->columns > image->rows)
3292 scale.y=(double) image->columns/(double) image->rows;
3293 else
3294 if (image->columns < image->rows)
3295 {
3296 scale.x=(double) image->rows/(double) image->columns;
3297 radius=center.y;
3298 }
3299 /*
3300 Implode image.
3301 */
3302 status=MagickTrue;
3303 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00003304 image_view=AcquireCacheView(image);
3305 implode_view=AcquireCacheView(implode_image);
cristyb5d5f722009-11-04 03:03:49 +00003306#if defined(MAGICKCORE_OPENMP_SUPPORT)
3307 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00003308#endif
cristybb503372010-05-27 20:51:26 +00003309 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003310 {
cristy3ed852e2009-09-05 21:47:34 +00003311 MagickRealType
3312 distance;
3313
3314 PointInfo
3315 delta;
3316
cristy6d188022011-09-12 13:23:33 +00003317 register const Quantum
3318 *restrict p;
3319
cristybb503372010-05-27 20:51:26 +00003320 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003321 x;
3322
cristy4c08aed2011-07-01 19:47:50 +00003323 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003324 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003325
3326 if (status == MagickFalse)
3327 continue;
cristy6d188022011-09-12 13:23:33 +00003328 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00003329 q=GetCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
3330 exception);
cristy6d188022011-09-12 13:23:33 +00003331 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003332 {
3333 status=MagickFalse;
3334 continue;
3335 }
cristy3ed852e2009-09-05 21:47:34 +00003336 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00003337 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003338 {
cristy6d188022011-09-12 13:23:33 +00003339 register ssize_t
3340 i;
3341
cristy3ed852e2009-09-05 21:47:34 +00003342 /*
3343 Determine if the pixel is within an ellipse.
3344 */
3345 delta.x=scale.x*(double) (x-center.x);
3346 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00003347 if (distance >= (radius*radius))
3348 {
3349 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3350 q[i]=p[i];
3351 }
3352 else
cristy3ed852e2009-09-05 21:47:34 +00003353 {
3354 double
3355 factor;
3356
3357 /*
3358 Implode the pixel.
3359 */
3360 factor=1.0;
3361 if (distance > 0.0)
3362 factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
3363 radius/2)),-amount);
cristy76f512e2011-09-12 01:26:56 +00003364 status=InterpolatePixelChannels(image,image_view,implode_image,method,
3365 (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
3366 scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00003367 }
cristy6d188022011-09-12 13:23:33 +00003368 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00003369 q+=GetPixelChannels(implode_image);
cristy3ed852e2009-09-05 21:47:34 +00003370 }
3371 if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse)
3372 status=MagickFalse;
3373 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3374 {
3375 MagickBooleanType
3376 proceed;
3377
cristyb5d5f722009-11-04 03:03:49 +00003378#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003379 #pragma omp critical (MagickCore_ImplodeImage)
3380#endif
3381 proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows);
3382 if (proceed == MagickFalse)
3383 status=MagickFalse;
3384 }
3385 }
3386 implode_view=DestroyCacheView(implode_view);
3387 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003388 if (status == MagickFalse)
3389 implode_image=DestroyImage(implode_image);
3390 return(implode_image);
3391}
3392
3393/*
3394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3395% %
3396% %
3397% %
3398% M o r p h I m a g e s %
3399% %
3400% %
3401% %
3402%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3403%
3404% The MorphImages() method requires a minimum of two images. The first
3405% image is transformed into the second by a number of intervening images
3406% as specified by frames.
3407%
3408% The format of the MorphImage method is:
3409%
cristybb503372010-05-27 20:51:26 +00003410% Image *MorphImages(const Image *image,const size_t number_frames,
cristy3ed852e2009-09-05 21:47:34 +00003411% ExceptionInfo *exception)
3412%
3413% A description of each parameter follows:
3414%
3415% o image: the image.
3416%
3417% o number_frames: Define the number of in-between image to generate.
3418% The more in-between frames, the smoother the morph.
3419%
3420% o exception: return any errors or warnings in this structure.
3421%
3422*/
3423MagickExport Image *MorphImages(const Image *image,
cristybb503372010-05-27 20:51:26 +00003424 const size_t number_frames,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003425{
3426#define MorphImageTag "Morph/Image"
3427
3428 Image
3429 *morph_image,
3430 *morph_images;
3431
cristy9d314ff2011-03-09 01:30:28 +00003432 MagickBooleanType
3433 status;
cristy3ed852e2009-09-05 21:47:34 +00003434
3435 MagickOffsetType
3436 scene;
3437
3438 MagickRealType
3439 alpha,
3440 beta;
3441
3442 register const Image
3443 *next;
3444
cristybb503372010-05-27 20:51:26 +00003445 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003446 i;
3447
cristy9d314ff2011-03-09 01:30:28 +00003448 ssize_t
3449 y;
cristy3ed852e2009-09-05 21:47:34 +00003450
3451 /*
3452 Clone first frame in sequence.
3453 */
3454 assert(image != (Image *) NULL);
3455 assert(image->signature == MagickSignature);
3456 if (image->debug != MagickFalse)
3457 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3458 assert(exception != (ExceptionInfo *) NULL);
3459 assert(exception->signature == MagickSignature);
3460 morph_images=CloneImage(image,0,0,MagickTrue,exception);
3461 if (morph_images == (Image *) NULL)
3462 return((Image *) NULL);
3463 if (GetNextImageInList(image) == (Image *) NULL)
3464 {
3465 /*
3466 Morph single image.
3467 */
cristybb503372010-05-27 20:51:26 +00003468 for (i=1; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003469 {
3470 morph_image=CloneImage(image,0,0,MagickTrue,exception);
3471 if (morph_image == (Image *) NULL)
3472 {
3473 morph_images=DestroyImageList(morph_images);
3474 return((Image *) NULL);
3475 }
3476 AppendImageToList(&morph_images,morph_image);
cristy8b27a6d2010-02-14 03:31:15 +00003477 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00003478 {
cristy8b27a6d2010-02-14 03:31:15 +00003479 MagickBooleanType
3480 proceed;
3481
cristybb503372010-05-27 20:51:26 +00003482 proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i,
3483 number_frames);
cristy8b27a6d2010-02-14 03:31:15 +00003484 if (proceed == MagickFalse)
3485 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00003486 }
3487 }
3488 return(GetFirstImageInList(morph_images));
3489 }
3490 /*
3491 Morph image sequence.
3492 */
3493 status=MagickTrue;
3494 scene=0;
3495 next=image;
3496 for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next))
3497 {
cristybb503372010-05-27 20:51:26 +00003498 for (i=0; i < (ssize_t) number_frames; i++)
cristy3ed852e2009-09-05 21:47:34 +00003499 {
3500 CacheView
3501 *image_view,
3502 *morph_view;
3503
3504 beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
3505 alpha=1.0-beta;
cristy15b98cd2010-09-12 19:42:50 +00003506 morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
cristybb503372010-05-27 20:51:26 +00003507 GetNextImageInList(next)->columns+0.5),(size_t) (alpha*
cristy15b98cd2010-09-12 19:42:50 +00003508 next->rows+beta*GetNextImageInList(next)->rows+0.5),
3509 next->filter,next->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003510 if (morph_image == (Image *) NULL)
3511 {
3512 morph_images=DestroyImageList(morph_images);
3513 return((Image *) NULL);
3514 }
cristy574cc262011-08-05 01:23:58 +00003515 if (SetImageStorageClass(morph_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00003516 {
cristy3ed852e2009-09-05 21:47:34 +00003517 morph_image=DestroyImage(morph_image);
3518 return((Image *) NULL);
3519 }
3520 AppendImageToList(&morph_images,morph_image);
3521 morph_images=GetLastImageInList(morph_images);
cristy15b98cd2010-09-12 19:42:50 +00003522 morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns,
3523 morph_images->rows,GetNextImageInList(next)->filter,
3524 GetNextImageInList(next)->blur,exception);
cristy3ed852e2009-09-05 21:47:34 +00003525 if (morph_image == (Image *) NULL)
3526 {
3527 morph_images=DestroyImageList(morph_images);
3528 return((Image *) NULL);
3529 }
3530 image_view=AcquireCacheView(morph_image);
3531 morph_view=AcquireCacheView(morph_images);
cristyb5d5f722009-11-04 03:03:49 +00003532#if defined(MAGICKCORE_OPENMP_SUPPORT)
3533 #pragma omp parallel for schedule(dynamic,4) shared(status)
cristy3ed852e2009-09-05 21:47:34 +00003534#endif
cristybb503372010-05-27 20:51:26 +00003535 for (y=0; y < (ssize_t) morph_images->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00003536 {
3537 MagickBooleanType
3538 sync;
3539
cristy4c08aed2011-07-01 19:47:50 +00003540 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00003541 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00003542
cristybb503372010-05-27 20:51:26 +00003543 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003544 x;
3545
cristy4c08aed2011-07-01 19:47:50 +00003546 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00003547 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003548
3549 if (status == MagickFalse)
3550 continue;
3551 p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1,
3552 exception);
3553 q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1,
3554 exception);
cristy4c08aed2011-07-01 19:47:50 +00003555 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003556 {
3557 status=MagickFalse;
3558 continue;
3559 }
cristybb503372010-05-27 20:51:26 +00003560 for (x=0; x < (ssize_t) morph_images->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00003561 {
cristy4c08aed2011-07-01 19:47:50 +00003562 SetPixelRed(morph_images,ClampToQuantum(alpha*
3563 GetPixelRed(morph_images,q)+beta*GetPixelRed(morph_image,p)),q);
3564 SetPixelGreen(morph_images,ClampToQuantum(alpha*
3565 GetPixelGreen(morph_images,q)+beta*GetPixelGreen(morph_image,p)),q);
3566 SetPixelBlue(morph_images,ClampToQuantum(alpha*
3567 GetPixelBlue(morph_images,q)+beta*GetPixelBlue(morph_image,p)),q);
3568 SetPixelAlpha(morph_images,ClampToQuantum(alpha*
3569 GetPixelAlpha(morph_images,q)+beta*GetPixelAlpha(morph_image,p)),q);
3570 if ((morph_image->colorspace == CMYKColorspace) &&
3571 (morph_images->colorspace == CMYKColorspace))
3572 SetPixelBlack(morph_images,ClampToQuantum(alpha*
3573 GetPixelBlack(morph_images,q)+beta*GetPixelBlack(morph_image,p)),
3574 q);
cristyed231572011-07-14 02:18:59 +00003575 p+=GetPixelChannels(morph_image);
3576 q+=GetPixelChannels(morph_images);
cristy3ed852e2009-09-05 21:47:34 +00003577 }
3578 sync=SyncCacheViewAuthenticPixels(morph_view,exception);
3579 if (sync == MagickFalse)
3580 status=MagickFalse;
3581 }
3582 morph_view=DestroyCacheView(morph_view);
3583 image_view=DestroyCacheView(image_view);
3584 morph_image=DestroyImage(morph_image);
3585 }
cristybb503372010-05-27 20:51:26 +00003586 if (i < (ssize_t) number_frames)
cristy3ed852e2009-09-05 21:47:34 +00003587 break;
3588 /*
3589 Clone last frame in sequence.
3590 */
3591 morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception);
3592 if (morph_image == (Image *) NULL)
3593 {
3594 morph_images=DestroyImageList(morph_images);
3595 return((Image *) NULL);
3596 }
3597 AppendImageToList(&morph_images,morph_image);
3598 morph_images=GetLastImageInList(morph_images);
3599 if (image->progress_monitor != (MagickProgressMonitor) NULL)
3600 {
3601 MagickBooleanType
3602 proceed;
3603
cristyb5d5f722009-11-04 03:03:49 +00003604#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00003605 #pragma omp critical (MagickCore_MorphImages)
3606#endif
3607 proceed=SetImageProgress(image,MorphImageTag,scene,
3608 GetImageListLength(image));
3609 if (proceed == MagickFalse)
3610 status=MagickFalse;
3611 }
3612 scene++;
3613 }
3614 if (GetNextImageInList(next) != (Image *) NULL)
3615 {
3616 morph_images=DestroyImageList(morph_images);
3617 return((Image *) NULL);
3618 }
3619 return(GetFirstImageInList(morph_images));
3620}
3621
3622/*
3623%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3624% %
3625% %
3626% %
3627% P l a s m a I m a g e %
3628% %
3629% %
3630% %
3631%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3632%
3633% PlasmaImage() initializes an image with plasma fractal values. The image
3634% must be initialized with a base color and the random number generator
3635% seeded before this method is called.
3636%
3637% The format of the PlasmaImage method is:
3638%
3639% MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment,
cristy5cbc0162011-08-29 00:36:28 +00003640% size_t attenuate,size_t depth,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003641%
3642% A description of each parameter follows:
3643%
3644% o image: the image.
3645%
3646% o segment: Define the region to apply plasma fractals values.
3647%
glennrp7dae1ca2010-09-16 12:17:35 +00003648% o attenuate: Define the plasma attenuation factor.
cristy3ed852e2009-09-05 21:47:34 +00003649%
3650% o depth: Limit the plasma recursion depth.
3651%
cristy5cbc0162011-08-29 00:36:28 +00003652% o exception: return any errors or warnings in this structure.
3653%
cristy3ed852e2009-09-05 21:47:34 +00003654*/
3655
3656static inline Quantum PlasmaPixel(RandomInfo *random_info,
3657 const MagickRealType pixel,const MagickRealType noise)
3658{
3659 Quantum
3660 plasma;
3661
cristyce70c172010-01-07 17:15:30 +00003662 plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
cristy3ed852e2009-09-05 21:47:34 +00003663 noise/2.0);
3664 return(plasma);
3665}
3666
cristyda1f9c12011-10-02 21:39:49 +00003667static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
3668 CacheView *u_view,CacheView *v_view,RandomInfo *random_info,
3669 const SegmentInfo *segment,size_t attenuate,size_t depth,
3670 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003671{
cristy3ed852e2009-09-05 21:47:34 +00003672 MagickRealType
3673 plasma;
3674
cristyda1f9c12011-10-02 21:39:49 +00003675 PixelChannel
3676 channel;
3677
3678 PixelTrait
3679 traits;
3680
3681 register const Quantum
3682 *restrict u,
3683 *restrict v;
3684
3685 register Quantum
3686 *restrict q;
3687
3688 register ssize_t
3689 i;
cristy3ed852e2009-09-05 21:47:34 +00003690
cristy9d314ff2011-03-09 01:30:28 +00003691 ssize_t
3692 x,
3693 x_mid,
3694 y,
3695 y_mid;
3696
cristy3ed852e2009-09-05 21:47:34 +00003697 if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
3698 return(MagickTrue);
3699 if (depth != 0)
3700 {
3701 SegmentInfo
3702 local_info;
3703
3704 /*
3705 Divide the area into quadrants and recurse.
3706 */
3707 depth--;
3708 attenuate++;
cristybb503372010-05-27 20:51:26 +00003709 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3710 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003711 local_info=(*segment);
3712 local_info.x2=(double) x_mid;
3713 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003714 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3715 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003716 local_info=(*segment);
3717 local_info.y1=(double) y_mid;
3718 local_info.x2=(double) x_mid;
cristyda1f9c12011-10-02 21:39:49 +00003719 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3720 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003721 local_info=(*segment);
3722 local_info.x1=(double) x_mid;
3723 local_info.y2=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003724 (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3725 &local_info,attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003726 local_info=(*segment);
3727 local_info.x1=(double) x_mid;
3728 local_info.y1=(double) y_mid;
cristyda1f9c12011-10-02 21:39:49 +00003729 return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
3730 &local_info,attenuate,depth,exception));
cristy3ed852e2009-09-05 21:47:34 +00003731 }
cristybb503372010-05-27 20:51:26 +00003732 x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
3733 y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
cristy3ed852e2009-09-05 21:47:34 +00003734 if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
3735 (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
3736 return(MagickFalse);
3737 /*
3738 Average pixels and apply plasma.
3739 */
cristy3ed852e2009-09-05 21:47:34 +00003740 plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
3741 if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
3742 {
cristy3ed852e2009-09-05 21:47:34 +00003743 /*
3744 Left pixel.
3745 */
cristybb503372010-05-27 20:51:26 +00003746 x=(ssize_t) ceil(segment->x1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003747 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3748 1,1,exception);
3749 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3750 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003751 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003752 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3753 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003754 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003755 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3756 {
3757 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3758 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3759 if (traits == UndefinedPixelTrait)
3760 continue;
3761 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3762 }
cristyc5c6f662010-09-22 14:23:02 +00003763 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003764 if (segment->x1 != segment->x2)
3765 {
3766 /*
3767 Right pixel.
3768 */
cristybb503372010-05-27 20:51:26 +00003769 x=(ssize_t) ceil(segment->x2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003770 u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),
3771 1,1,exception);
3772 v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),
3773 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003774 q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003775 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3776 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003777 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003778 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3779 {
3780 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3781 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3782 if (traits == UndefinedPixelTrait)
3783 continue;
3784 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3785 }
cristyc5c6f662010-09-22 14:23:02 +00003786 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003787 }
3788 }
3789 if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
3790 {
3791 if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
3792 {
cristy3ed852e2009-09-05 21:47:34 +00003793 /*
3794 Bottom pixel.
3795 */
cristybb503372010-05-27 20:51:26 +00003796 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003797 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3798 1,1,exception);
3799 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3800 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003801 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003802 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3803 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003804 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003805 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3806 {
3807 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3808 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3809 if (traits == UndefinedPixelTrait)
3810 continue;
3811 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3812 }
cristyc5c6f662010-09-22 14:23:02 +00003813 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003814 }
3815 if (segment->y1 != segment->y2)
3816 {
cristy3ed852e2009-09-05 21:47:34 +00003817 /*
3818 Top pixel.
3819 */
cristybb503372010-05-27 20:51:26 +00003820 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003821 u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y,
3822 1,1,exception);
3823 v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y,
3824 1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003825 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003826 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3827 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003828 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003829 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3830 {
3831 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3832 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3833 if (traits == UndefinedPixelTrait)
3834 continue;
3835 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3836 }
cristyc5c6f662010-09-22 14:23:02 +00003837 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003838 }
3839 }
3840 if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2))
3841 {
cristy3ed852e2009-09-05 21:47:34 +00003842 /*
3843 Middle pixel.
3844 */
cristybb503372010-05-27 20:51:26 +00003845 x=(ssize_t) ceil(segment->x1-0.5);
3846 y=(ssize_t) ceil(segment->y1-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003847 u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception);
cristybb503372010-05-27 20:51:26 +00003848 x=(ssize_t) ceil(segment->x2-0.5);
3849 y=(ssize_t) ceil(segment->y2-0.5);
cristyda1f9c12011-10-02 21:39:49 +00003850 v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception);
cristyc5c6f662010-09-22 14:23:02 +00003851 q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception);
cristyda1f9c12011-10-02 21:39:49 +00003852 if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) ||
3853 (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00003854 return(MagickTrue);
cristyda1f9c12011-10-02 21:39:49 +00003855 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3856 {
3857 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
3858 channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
3859 if (traits == UndefinedPixelTrait)
3860 continue;
3861 q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
3862 }
cristyc5c6f662010-09-22 14:23:02 +00003863 (void) SyncCacheViewAuthenticPixels(image_view,exception);
cristy3ed852e2009-09-05 21:47:34 +00003864 }
3865 if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
3866 return(MagickTrue);
3867 return(MagickFalse);
3868}
cristyda1f9c12011-10-02 21:39:49 +00003869
cristy3ed852e2009-09-05 21:47:34 +00003870MagickExport MagickBooleanType PlasmaImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00003871 const SegmentInfo *segment,size_t attenuate,size_t depth,
3872 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003873{
cristyc5c6f662010-09-22 14:23:02 +00003874 CacheView
cristyda1f9c12011-10-02 21:39:49 +00003875 *image_view,
3876 *u_view,
3877 *v_view;
cristyc5c6f662010-09-22 14:23:02 +00003878
cristy3ed852e2009-09-05 21:47:34 +00003879 MagickBooleanType
3880 status;
3881
3882 RandomInfo
3883 *random_info;
3884
3885 if (image->debug != MagickFalse)
3886 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3887 assert(image != (Image *) NULL);
3888 assert(image->signature == MagickSignature);
3889 if (image->debug != MagickFalse)
3890 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
cristy5cbc0162011-08-29 00:36:28 +00003891 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
cristyc5c6f662010-09-22 14:23:02 +00003892 return(MagickFalse);
3893 image_view=AcquireCacheView(image);
cristyda1f9c12011-10-02 21:39:49 +00003894 u_view=AcquireCacheView(image);
3895 v_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00003896 random_info=AcquireRandomInfo();
cristyda1f9c12011-10-02 21:39:49 +00003897 status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
3898 attenuate,depth,exception);
cristy3ed852e2009-09-05 21:47:34 +00003899 random_info=DestroyRandomInfo(random_info);
cristyda1f9c12011-10-02 21:39:49 +00003900 v_view=DestroyCacheView(v_view);
3901 u_view=DestroyCacheView(u_view);
cristyc5c6f662010-09-22 14:23:02 +00003902 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00003903 return(status);
3904}
3905
3906/*
3907%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3908% %
3909% %
3910% %
3911% P o l a r o i d I m a g e %
3912% %
3913% %
3914% %
3915%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3916%
3917% PolaroidImage() simulates a Polaroid picture.
3918%
3919% The format of the AnnotateImage method is:
3920%
3921% Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003922% const double angle,const PixelInterpolateMethod method,
3923% ExceptionInfo exception)
cristy3ed852e2009-09-05 21:47:34 +00003924%
3925% A description of each parameter follows:
3926%
3927% o image: the image.
3928%
3929% o draw_info: the draw info.
3930%
cristycee97112010-05-28 00:44:52 +00003931% o angle: Apply the effect along this angle.
cristy3ed852e2009-09-05 21:47:34 +00003932%
cristy5c4e2582011-09-11 19:21:03 +00003933% o method: the pixel interpolation method.
3934%
cristy3ed852e2009-09-05 21:47:34 +00003935% o exception: return any errors or warnings in this structure.
3936%
3937*/
3938MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
cristy5c4e2582011-09-11 19:21:03 +00003939 const double angle,const PixelInterpolateMethod method,
3940 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00003941{
3942 const char
3943 *value;
3944
cristy3ed852e2009-09-05 21:47:34 +00003945 Image
3946 *bend_image,
3947 *caption_image,
3948 *flop_image,
3949 *picture_image,
3950 *polaroid_image,
3951 *rotate_image,
3952 *trim_image;
3953
cristybb503372010-05-27 20:51:26 +00003954 size_t
cristy3ed852e2009-09-05 21:47:34 +00003955 height;
3956
cristy9d314ff2011-03-09 01:30:28 +00003957 ssize_t
3958 quantum;
3959
cristy3ed852e2009-09-05 21:47:34 +00003960 /*
3961 Simulate a Polaroid picture.
3962 */
3963 assert(image != (Image *) NULL);
3964 assert(image->signature == MagickSignature);
3965 if (image->debug != MagickFalse)
3966 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3967 assert(exception != (ExceptionInfo *) NULL);
3968 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00003969 quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
cristy3ed852e2009-09-05 21:47:34 +00003970 image->rows)/25.0,10.0);
3971 height=image->rows+2*quantum;
3972 caption_image=(Image *) NULL;
cristyd15e6592011-10-15 00:13:06 +00003973 value=GetImageProperty(image,"caption",exception);
cristy3ed852e2009-09-05 21:47:34 +00003974 if (value != (const char *) NULL)
3975 {
3976 char
3977 *caption,
3978 geometry[MaxTextExtent];
3979
3980 DrawInfo
3981 *annotate_info;
3982
cristy3ed852e2009-09-05 21:47:34 +00003983 MagickBooleanType
3984 status;
3985
cristy9d314ff2011-03-09 01:30:28 +00003986 ssize_t
3987 count;
3988
cristy3ed852e2009-09-05 21:47:34 +00003989 TypeMetric
3990 metrics;
3991
3992 /*
3993 Generate caption image.
3994 */
3995 caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
3996 if (caption_image == (Image *) NULL)
3997 return((Image *) NULL);
3998 annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
3999 caption=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,
cristy018f07f2011-09-04 21:15:19 +00004000 value,exception);
cristy3ed852e2009-09-05 21:47:34 +00004001 (void) CloneString(&annotate_info->text,caption);
cristy6b1d05e2010-09-22 19:17:27 +00004002 count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
cristy5cbc0162011-08-29 00:36:28 +00004003 &caption,exception);
cristybb503372010-05-27 20:51:26 +00004004 status=SetImageExtent(caption_image,image->columns,(size_t)
cristy63240882011-08-05 19:05:27 +00004005 ((count+1)*(metrics.ascent-metrics.descent)+0.5),exception);
cristy3ed852e2009-09-05 21:47:34 +00004006 if (status == MagickFalse)
4007 caption_image=DestroyImage(caption_image);
4008 else
4009 {
4010 caption_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004011 (void) SetImageBackgroundColor(caption_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00004012 (void) CloneString(&annotate_info->text,caption);
cristyb51dff52011-05-19 16:55:47 +00004013 (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
cristy3ed852e2009-09-05 21:47:34 +00004014 metrics.ascent);
4015 if (annotate_info->gravity == UndefinedGravity)
4016 (void) CloneString(&annotate_info->geometry,AcquireString(
4017 geometry));
cristy5cbc0162011-08-29 00:36:28 +00004018 (void) AnnotateImage(caption_image,annotate_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00004019 height+=caption_image->rows;
4020 }
4021 annotate_info=DestroyDrawInfo(annotate_info);
4022 caption=DestroyString(caption);
4023 }
4024 picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue,
4025 exception);
4026 if (picture_image == (Image *) NULL)
4027 {
4028 if (caption_image != (Image *) NULL)
4029 caption_image=DestroyImage(caption_image);
4030 return((Image *) NULL);
4031 }
4032 picture_image->background_color=image->border_color;
cristyea1a8aa2011-10-20 13:24:06 +00004033 (void) SetImageBackgroundColor(picture_image,exception);
cristye941a752011-10-15 01:52:48 +00004034 (void) CompositeImage(picture_image,OverCompositeOp,image,quantum,quantum,
4035 exception);
cristy3ed852e2009-09-05 21:47:34 +00004036 if (caption_image != (Image *) NULL)
4037 {
4038 (void) CompositeImage(picture_image,OverCompositeOp,caption_image,
cristye941a752011-10-15 01:52:48 +00004039 quantum,(ssize_t) (image->rows+3*quantum/2),exception);
cristy3ed852e2009-09-05 21:47:34 +00004040 caption_image=DestroyImage(caption_image);
4041 }
cristy9950d572011-10-01 18:22:35 +00004042 (void) QueryColorCompliance("none",AllCompliance,
4043 &picture_image->background_color,exception);
cristy63240882011-08-05 19:05:27 +00004044 (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004045 rotate_image=RotateImage(picture_image,90.0,exception);
4046 picture_image=DestroyImage(picture_image);
4047 if (rotate_image == (Image *) NULL)
4048 return((Image *) NULL);
4049 picture_image=rotate_image;
4050 bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0*
cristy5c4e2582011-09-11 19:21:03 +00004051 picture_image->columns,method,exception);
cristy3ed852e2009-09-05 21:47:34 +00004052 picture_image=DestroyImage(picture_image);
4053 if (bend_image == (Image *) NULL)
4054 return((Image *) NULL);
cristy3ed852e2009-09-05 21:47:34 +00004055 picture_image=bend_image;
4056 rotate_image=RotateImage(picture_image,-90.0,exception);
4057 picture_image=DestroyImage(picture_image);
4058 if (rotate_image == (Image *) NULL)
4059 return((Image *) NULL);
4060 picture_image=rotate_image;
4061 picture_image->background_color=image->background_color;
4062 polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3,
4063 exception);
4064 if (polaroid_image == (Image *) NULL)
4065 {
4066 picture_image=DestroyImage(picture_image);
4067 return(picture_image);
4068 }
4069 flop_image=FlopImage(polaroid_image,exception);
4070 polaroid_image=DestroyImage(polaroid_image);
4071 if (flop_image == (Image *) NULL)
4072 {
4073 picture_image=DestroyImage(picture_image);
4074 return(picture_image);
4075 }
4076 polaroid_image=flop_image;
4077 (void) CompositeImage(polaroid_image,OverCompositeOp,picture_image,
cristye941a752011-10-15 01:52:48 +00004078 (ssize_t) (-0.01*picture_image->columns/2.0),0L,exception);
cristy3ed852e2009-09-05 21:47:34 +00004079 picture_image=DestroyImage(picture_image);
cristy9950d572011-10-01 18:22:35 +00004080 (void) QueryColorCompliance("none",AllCompliance,
4081 &polaroid_image->background_color,exception);
cristy3ed852e2009-09-05 21:47:34 +00004082 rotate_image=RotateImage(polaroid_image,angle,exception);
4083 polaroid_image=DestroyImage(polaroid_image);
4084 if (rotate_image == (Image *) NULL)
4085 return((Image *) NULL);
4086 polaroid_image=rotate_image;
4087 trim_image=TrimImage(polaroid_image,exception);
4088 polaroid_image=DestroyImage(polaroid_image);
4089 if (trim_image == (Image *) NULL)
4090 return((Image *) NULL);
4091 polaroid_image=trim_image;
4092 return(polaroid_image);
4093}
4094
4095/*
4096%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4097% %
4098% %
4099% %
cristy3ed852e2009-09-05 21:47:34 +00004100% S e p i a T o n e I m a g e %
4101% %
4102% %
4103% %
4104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4105%
4106% MagickSepiaToneImage() applies a special effect to the image, similar to the
4107% effect achieved in a photo darkroom by sepia toning. Threshold ranges from
4108% 0 to QuantumRange and is a measure of the extent of the sepia toning. A
4109% threshold of 80% is a good starting point for a reasonable tone.
4110%
4111% The format of the SepiaToneImage method is:
4112%
4113% Image *SepiaToneImage(const Image *image,const double threshold,
4114% ExceptionInfo *exception)
4115%
4116% A description of each parameter follows:
4117%
4118% o image: the image.
4119%
4120% o threshold: the tone threshold.
4121%
4122% o exception: return any errors or warnings in this structure.
4123%
4124*/
4125MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
4126 ExceptionInfo *exception)
4127{
4128#define SepiaToneImageTag "SepiaTone/Image"
4129
cristyc4c8d132010-01-07 01:58:38 +00004130 CacheView
4131 *image_view,
4132 *sepia_view;
4133
cristy3ed852e2009-09-05 21:47:34 +00004134 Image
4135 *sepia_image;
4136
cristy3ed852e2009-09-05 21:47:34 +00004137 MagickBooleanType
4138 status;
4139
cristybb503372010-05-27 20:51:26 +00004140 MagickOffsetType
4141 progress;
4142
4143 ssize_t
4144 y;
4145
cristy3ed852e2009-09-05 21:47:34 +00004146 /*
4147 Initialize sepia-toned image attributes.
4148 */
4149 assert(image != (const Image *) NULL);
4150 assert(image->signature == MagickSignature);
4151 if (image->debug != MagickFalse)
4152 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4153 assert(exception != (ExceptionInfo *) NULL);
4154 assert(exception->signature == MagickSignature);
4155 sepia_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
4156 if (sepia_image == (Image *) NULL)
4157 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004158 if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004159 {
cristy3ed852e2009-09-05 21:47:34 +00004160 sepia_image=DestroyImage(sepia_image);
4161 return((Image *) NULL);
4162 }
4163 /*
4164 Tone each row of the image.
4165 */
4166 status=MagickTrue;
4167 progress=0;
4168 image_view=AcquireCacheView(image);
4169 sepia_view=AcquireCacheView(sepia_image);
cristyb5d5f722009-11-04 03:03:49 +00004170#if defined(MAGICKCORE_OPENMP_SUPPORT)
4171 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004172#endif
cristybb503372010-05-27 20:51:26 +00004173 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004174 {
cristy4c08aed2011-07-01 19:47:50 +00004175 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004176 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00004177
cristybb503372010-05-27 20:51:26 +00004178 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004179 x;
4180
cristy4c08aed2011-07-01 19:47:50 +00004181 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004182 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004183
4184 if (status == MagickFalse)
4185 continue;
4186 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
4187 q=QueueCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1,
4188 exception);
cristy4c08aed2011-07-01 19:47:50 +00004189 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004190 {
4191 status=MagickFalse;
4192 continue;
4193 }
cristybb503372010-05-27 20:51:26 +00004194 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004195 {
4196 MagickRealType
4197 intensity,
4198 tone;
4199
cristy4c08aed2011-07-01 19:47:50 +00004200 intensity=(MagickRealType) GetPixelIntensity(image,p);
cristy3ed852e2009-09-05 21:47:34 +00004201 tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
4202 (MagickRealType) QuantumRange-threshold;
cristy4c08aed2011-07-01 19:47:50 +00004203 SetPixelRed(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004204 tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
4205 intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004206 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004207 tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
cristy4c08aed2011-07-01 19:47:50 +00004208 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristy3ed852e2009-09-05 21:47:34 +00004209 tone=threshold/7.0;
cristy4c08aed2011-07-01 19:47:50 +00004210 if ((MagickRealType) GetPixelGreen(image,q) < tone)
4211 SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
4212 if ((MagickRealType) GetPixelBlue(image,q) < tone)
4213 SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
cristyed231572011-07-14 02:18:59 +00004214 p+=GetPixelChannels(image);
4215 q+=GetPixelChannels(sepia_image);
cristy3ed852e2009-09-05 21:47:34 +00004216 }
4217 if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse)
4218 status=MagickFalse;
4219 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4220 {
4221 MagickBooleanType
4222 proceed;
4223
cristyb5d5f722009-11-04 03:03:49 +00004224#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004225 #pragma omp critical (MagickCore_SepiaToneImage)
4226#endif
4227 proceed=SetImageProgress(image,SepiaToneImageTag,progress++,
4228 image->rows);
4229 if (proceed == MagickFalse)
4230 status=MagickFalse;
4231 }
4232 }
4233 sepia_view=DestroyCacheView(sepia_view);
4234 image_view=DestroyCacheView(image_view);
cristye23ec9d2011-08-16 18:15:40 +00004235 (void) NormalizeImage(sepia_image,exception);
4236 (void) ContrastImage(sepia_image,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00004237 if (status == MagickFalse)
4238 sepia_image=DestroyImage(sepia_image);
4239 return(sepia_image);
4240}
4241
4242/*
4243%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4244% %
4245% %
4246% %
4247% S h a d o w I m a g e %
4248% %
4249% %
4250% %
4251%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4252%
4253% ShadowImage() simulates a shadow from the specified image and returns it.
4254%
4255% The format of the ShadowImage method is:
4256%
4257% Image *ShadowImage(const Image *image,const double opacity,
cristybb503372010-05-27 20:51:26 +00004258% const double sigma,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004259% ExceptionInfo *exception)
4260%
4261% A description of each parameter follows:
4262%
4263% o image: the image.
4264%
4265% o opacity: percentage transparency.
4266%
4267% o sigma: the standard deviation of the Gaussian, in pixels.
4268%
4269% o x_offset: the shadow x-offset.
4270%
4271% o y_offset: the shadow y-offset.
4272%
4273% o exception: return any errors or warnings in this structure.
4274%
4275*/
4276MagickExport Image *ShadowImage(const Image *image,const double opacity,
cristybb503372010-05-27 20:51:26 +00004277 const double sigma,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004278 ExceptionInfo *exception)
4279{
4280#define ShadowImageTag "Shadow/Image"
4281
cristybd5a96c2011-08-21 00:04:26 +00004282 ChannelType
4283 channel_mask;
4284
cristy3ed852e2009-09-05 21:47:34 +00004285 Image
4286 *border_image,
4287 *clone_image,
4288 *shadow_image;
4289
cristy3ed852e2009-09-05 21:47:34 +00004290 RectangleInfo
4291 border_info;
4292
cristy3ed852e2009-09-05 21:47:34 +00004293 assert(image != (Image *) NULL);
4294 assert(image->signature == MagickSignature);
4295 if (image->debug != MagickFalse)
4296 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4297 assert(exception != (ExceptionInfo *) NULL);
4298 assert(exception->signature == MagickSignature);
4299 clone_image=CloneImage(image,0,0,MagickTrue,exception);
4300 if (clone_image == (Image *) NULL)
4301 return((Image *) NULL);
4302 (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod);
4303 clone_image->compose=OverCompositeOp;
cristybb503372010-05-27 20:51:26 +00004304 border_info.width=(size_t) floor(2.0*sigma+0.5);
4305 border_info.height=(size_t) floor(2.0*sigma+0.5);
cristy3ed852e2009-09-05 21:47:34 +00004306 border_info.x=0;
4307 border_info.y=0;
cristy9950d572011-10-01 18:22:35 +00004308 (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
4309 exception);
cristy633f0c62011-09-15 13:27:36 +00004310 border_image=BorderImage(clone_image,&border_info,image->compose,exception);
cristy3ed852e2009-09-05 21:47:34 +00004311 clone_image=DestroyImage(clone_image);
4312 if (border_image == (Image *) NULL)
4313 return((Image *) NULL);
4314 if (border_image->matte == MagickFalse)
cristy63240882011-08-05 19:05:27 +00004315 (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
cristy3ed852e2009-09-05 21:47:34 +00004316 /*
4317 Shadow image.
4318 */
cristyea1a8aa2011-10-20 13:24:06 +00004319 (void) SetImageBackgroundColor(border_image,exception);
cristybd5a96c2011-08-21 00:04:26 +00004320 channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
cristy05c0c9a2011-09-05 23:16:13 +00004321 shadow_image=BlurImage(border_image,0.0,sigma,image->bias,exception);
cristybd5a96c2011-08-21 00:04:26 +00004322 (void) SetPixelChannelMap(border_image,channel_mask);
cristy3ed852e2009-09-05 21:47:34 +00004323 border_image=DestroyImage(border_image);
4324 if (shadow_image == (Image *) NULL)
4325 return((Image *) NULL);
4326 if (shadow_image->page.width == 0)
4327 shadow_image->page.width=shadow_image->columns;
4328 if (shadow_image->page.height == 0)
4329 shadow_image->page.height=shadow_image->rows;
cristybb503372010-05-27 20:51:26 +00004330 shadow_image->page.width+=x_offset-(ssize_t) border_info.width;
4331 shadow_image->page.height+=y_offset-(ssize_t) border_info.height;
4332 shadow_image->page.x+=x_offset-(ssize_t) border_info.width;
4333 shadow_image->page.y+=y_offset-(ssize_t) border_info.height;
cristy3ed852e2009-09-05 21:47:34 +00004334 return(shadow_image);
4335}
4336
4337/*
4338%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4339% %
4340% %
4341% %
4342% S k e t c h I m a g e %
4343% %
4344% %
4345% %
4346%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4347%
4348% SketchImage() simulates a pencil sketch. We convolve the image with a
4349% Gaussian operator of the given radius and standard deviation (sigma). For
4350% reasonable results, radius should be larger than sigma. Use a radius of 0
4351% and SketchImage() selects a suitable radius for you. Angle gives the angle
4352% of the sketch.
4353%
4354% The format of the SketchImage method is:
4355%
4356% Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004357% const double sigma,const double angle,const double bias,
4358% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004359%
4360% A description of each parameter follows:
4361%
4362% o image: the image.
4363%
cristy574cc262011-08-05 01:23:58 +00004364% o radius: the radius of the Gaussian, in pixels, not counting the
4365% center pixel.
cristy3ed852e2009-09-05 21:47:34 +00004366%
4367% o sigma: the standard deviation of the Gaussian, in pixels.
4368%
cristyf7ef0252011-09-09 14:50:06 +00004369% o angle: apply the effect along this angle.
4370%
4371% o bias: the bias.
cristy3ed852e2009-09-05 21:47:34 +00004372%
4373% o exception: return any errors or warnings in this structure.
4374%
4375*/
4376MagickExport Image *SketchImage(const Image *image,const double radius,
cristyf7ef0252011-09-09 14:50:06 +00004377 const double sigma,const double angle,const double bias,
4378 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004379{
cristyfa112112010-01-04 17:48:07 +00004380 CacheView
4381 *random_view;
4382
cristy3ed852e2009-09-05 21:47:34 +00004383 Image
4384 *blend_image,
4385 *blur_image,
4386 *dodge_image,
4387 *random_image,
4388 *sketch_image;
4389
cristy3ed852e2009-09-05 21:47:34 +00004390 MagickBooleanType
4391 status;
4392
cristy3ed852e2009-09-05 21:47:34 +00004393 RandomInfo
cristyfa112112010-01-04 17:48:07 +00004394 **restrict random_info;
cristy3ed852e2009-09-05 21:47:34 +00004395
cristy9d314ff2011-03-09 01:30:28 +00004396 ssize_t
4397 y;
4398
cristy3ed852e2009-09-05 21:47:34 +00004399 /*
4400 Sketch image.
4401 */
4402 random_image=CloneImage(image,image->columns << 1,image->rows << 1,
4403 MagickTrue,exception);
4404 if (random_image == (Image *) NULL)
4405 return((Image *) NULL);
4406 status=MagickTrue;
cristy1b784432009-12-19 02:20:40 +00004407 random_info=AcquireRandomInfoThreadSet();
cristy3ed852e2009-09-05 21:47:34 +00004408 random_view=AcquireCacheView(random_image);
cristy1b784432009-12-19 02:20:40 +00004409#if defined(MAGICKCORE_OPENMP_SUPPORT)
4410 #pragma omp parallel for schedule(dynamic,4) shared(status)
4411#endif
cristybb503372010-05-27 20:51:26 +00004412 for (y=0; y < (ssize_t) random_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004413 {
cristy5c9e6f22010-09-17 17:31:01 +00004414 const int
4415 id = GetOpenMPThreadId();
cristy6ebe97c2010-07-03 01:17:28 +00004416
cristybb503372010-05-27 20:51:26 +00004417 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004418 x;
4419
cristy4c08aed2011-07-01 19:47:50 +00004420 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004421 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004422
cristy1b784432009-12-19 02:20:40 +00004423 if (status == MagickFalse)
4424 continue;
cristy3ed852e2009-09-05 21:47:34 +00004425 q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1,
4426 exception);
cristyacd2ed22011-08-30 01:44:23 +00004427 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004428 {
4429 status=MagickFalse;
4430 continue;
4431 }
cristybb503372010-05-27 20:51:26 +00004432 for (x=0; x < (ssize_t) random_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004433 {
cristy76f512e2011-09-12 01:26:56 +00004434 MagickRealType
4435 value;
4436
4437 register ssize_t
4438 i;
4439
4440 value=GetPseudoRandomValue(random_info[id]);
4441 for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
4442 {
4443 PixelTrait
4444 traits;
4445
4446 traits=GetPixelChannelMapTraits(random_image,(PixelChannel) i);
4447 if (traits == UndefinedPixelTrait)
4448 continue;
4449 q[i]=ClampToQuantum(QuantumRange*value);
4450 }
cristyed231572011-07-14 02:18:59 +00004451 q+=GetPixelChannels(random_image);
cristy3ed852e2009-09-05 21:47:34 +00004452 }
4453 if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse)
4454 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004455 }
4456 random_view=DestroyCacheView(random_view);
cristy1b784432009-12-19 02:20:40 +00004457 random_info=DestroyRandomInfoThreadSet(random_info);
cristy3ed852e2009-09-05 21:47:34 +00004458 if (status == MagickFalse)
4459 {
4460 random_image=DestroyImage(random_image);
4461 return(random_image);
4462 }
cristyf7ef0252011-09-09 14:50:06 +00004463 blur_image=MotionBlurImage(random_image,radius,sigma,angle,bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00004464 random_image=DestroyImage(random_image);
4465 if (blur_image == (Image *) NULL)
4466 return((Image *) NULL);
cristy8ae632d2011-09-05 17:29:53 +00004467 dodge_image=EdgeImage(blur_image,radius,sigma,exception);
cristy3ed852e2009-09-05 21:47:34 +00004468 blur_image=DestroyImage(blur_image);
4469 if (dodge_image == (Image *) NULL)
4470 return((Image *) NULL);
cristye23ec9d2011-08-16 18:15:40 +00004471 (void) NormalizeImage(dodge_image,exception);
cristyb3e7c6c2011-07-24 01:43:55 +00004472 (void) NegateImage(dodge_image,MagickFalse,exception);
cristye941a752011-10-15 01:52:48 +00004473 (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception);
cristy3ed852e2009-09-05 21:47:34 +00004474 sketch_image=CloneImage(image,0,0,MagickTrue,exception);
4475 if (sketch_image == (Image *) NULL)
4476 {
4477 dodge_image=DestroyImage(dodge_image);
4478 return((Image *) NULL);
4479 }
cristye941a752011-10-15 01:52:48 +00004480 (void) CompositeImage(sketch_image,ColorDodgeCompositeOp,dodge_image,0,0,
4481 exception);
cristy3ed852e2009-09-05 21:47:34 +00004482 dodge_image=DestroyImage(dodge_image);
4483 blend_image=CloneImage(image,0,0,MagickTrue,exception);
4484 if (blend_image == (Image *) NULL)
4485 {
4486 sketch_image=DestroyImage(sketch_image);
4487 return((Image *) NULL);
4488 }
4489 (void) SetImageArtifact(blend_image,"compose:args","20x80");
cristye941a752011-10-15 01:52:48 +00004490 (void) CompositeImage(sketch_image,BlendCompositeOp,blend_image,0,0,
4491 exception);
cristy3ed852e2009-09-05 21:47:34 +00004492 blend_image=DestroyImage(blend_image);
4493 return(sketch_image);
4494}
4495
4496/*
4497%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4498% %
4499% %
4500% %
4501% S o l a r i z e I m a g e %
4502% %
4503% %
4504% %
4505%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4506%
4507% SolarizeImage() applies a special effect to the image, similar to the effect
4508% achieved in a photo darkroom by selectively exposing areas of photo
4509% sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a
4510% measure of the extent of the solarization.
4511%
4512% The format of the SolarizeImage method is:
4513%
cristy5cbc0162011-08-29 00:36:28 +00004514% MagickBooleanType SolarizeImage(Image *image,const double threshold,
4515% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004516%
4517% A description of each parameter follows:
4518%
4519% o image: the image.
4520%
4521% o threshold: Define the extent of the solarization.
4522%
cristy5cbc0162011-08-29 00:36:28 +00004523% o exception: return any errors or warnings in this structure.
4524%
cristy3ed852e2009-09-05 21:47:34 +00004525*/
4526MagickExport MagickBooleanType SolarizeImage(Image *image,
cristy5cbc0162011-08-29 00:36:28 +00004527 const double threshold,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004528{
4529#define SolarizeImageTag "Solarize/Image"
4530
cristyc4c8d132010-01-07 01:58:38 +00004531 CacheView
4532 *image_view;
4533
cristy3ed852e2009-09-05 21:47:34 +00004534 MagickBooleanType
4535 status;
4536
cristybb503372010-05-27 20:51:26 +00004537 MagickOffsetType
4538 progress;
4539
4540 ssize_t
4541 y;
4542
cristy3ed852e2009-09-05 21:47:34 +00004543 assert(image != (Image *) NULL);
4544 assert(image->signature == MagickSignature);
4545 if (image->debug != MagickFalse)
4546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4547 if (image->storage_class == PseudoClass)
4548 {
cristybb503372010-05-27 20:51:26 +00004549 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004550 i;
4551
4552 /*
4553 Solarize colormap.
4554 */
cristybb503372010-05-27 20:51:26 +00004555 for (i=0; i < (ssize_t) image->colors; i++)
cristy3ed852e2009-09-05 21:47:34 +00004556 {
4557 if ((MagickRealType) image->colormap[i].red > threshold)
4558 image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
4559 if ((MagickRealType) image->colormap[i].green > threshold)
4560 image->colormap[i].green=(Quantum) QuantumRange-
4561 image->colormap[i].green;
4562 if ((MagickRealType) image->colormap[i].blue > threshold)
4563 image->colormap[i].blue=(Quantum) QuantumRange-
4564 image->colormap[i].blue;
4565 }
4566 }
4567 /*
4568 Solarize image.
4569 */
4570 status=MagickTrue;
4571 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00004572 image_view=AcquireCacheView(image);
cristyb5d5f722009-11-04 03:03:49 +00004573#if defined(MAGICKCORE_OPENMP_SUPPORT)
4574 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00004575#endif
cristybb503372010-05-27 20:51:26 +00004576 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004577 {
cristybb503372010-05-27 20:51:26 +00004578 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004579 x;
4580
cristy4c08aed2011-07-01 19:47:50 +00004581 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004582 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004583
4584 if (status == MagickFalse)
4585 continue;
cristy5cbc0162011-08-29 00:36:28 +00004586 q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristyacd2ed22011-08-30 01:44:23 +00004587 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004588 {
4589 status=MagickFalse;
4590 continue;
4591 }
cristybb503372010-05-27 20:51:26 +00004592 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004593 {
cristy76f512e2011-09-12 01:26:56 +00004594 register ssize_t
4595 i;
4596
4597 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4598 {
4599 PixelTrait
4600 traits;
4601
4602 traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
4603 if ((traits == UndefinedPixelTrait) ||
4604 ((traits & CopyPixelTrait) != 0))
4605 continue;
4606 if ((MagickRealType) q[i] > threshold)
4607 q[i]=QuantumRange-q[i];
4608 }
cristyed231572011-07-14 02:18:59 +00004609 q+=GetPixelChannels(image);
cristy3ed852e2009-09-05 21:47:34 +00004610 }
4611 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4612 status=MagickFalse;
4613 if (image->progress_monitor != (MagickProgressMonitor) NULL)
4614 {
4615 MagickBooleanType
4616 proceed;
4617
cristyb5d5f722009-11-04 03:03:49 +00004618#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00004619 #pragma omp critical (MagickCore_SolarizeImage)
4620#endif
4621 proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows);
4622 if (proceed == MagickFalse)
4623 status=MagickFalse;
4624 }
4625 }
4626 image_view=DestroyCacheView(image_view);
4627 return(status);
4628}
4629
4630/*
4631%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4632% %
4633% %
4634% %
4635% S t e g a n o I m a g e %
4636% %
4637% %
4638% %
4639%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4640%
4641% SteganoImage() hides a digital watermark within the image. Recover
4642% the hidden watermark later to prove that the authenticity of an image.
4643% Offset defines the start position within the image to hide the watermark.
4644%
4645% The format of the SteganoImage method is:
4646%
4647% Image *SteganoImage(const Image *image,Image *watermark,
4648% ExceptionInfo *exception)
4649%
4650% A description of each parameter follows:
4651%
4652% o image: the image.
4653%
4654% o watermark: the watermark image.
4655%
4656% o exception: return any errors or warnings in this structure.
4657%
4658*/
4659MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
4660 ExceptionInfo *exception)
4661{
cristye1bf8ad2010-09-19 17:07:03 +00004662#define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0)
cristy4c08aed2011-07-01 19:47:50 +00004663#define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \
cristyeaedf062010-05-29 22:36:02 +00004664 | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i)))
cristy3ed852e2009-09-05 21:47:34 +00004665#define SteganoImageTag "Stegano/Image"
4666
cristyb0d3bb92010-09-22 14:37:58 +00004667 CacheView
4668 *stegano_view,
4669 *watermark_view;
4670
cristy3ed852e2009-09-05 21:47:34 +00004671 Image
4672 *stegano_image;
4673
4674 int
4675 c;
4676
cristy3ed852e2009-09-05 21:47:34 +00004677 MagickBooleanType
4678 status;
4679
cristy101ab702011-10-13 13:06:32 +00004680 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00004681 pixel;
4682
cristy4c08aed2011-07-01 19:47:50 +00004683 register Quantum
cristy3ed852e2009-09-05 21:47:34 +00004684 *q;
4685
cristye1bf8ad2010-09-19 17:07:03 +00004686 register ssize_t
4687 x;
4688
cristybb503372010-05-27 20:51:26 +00004689 size_t
cristyeaedf062010-05-29 22:36:02 +00004690 depth,
4691 one;
cristy3ed852e2009-09-05 21:47:34 +00004692
cristye1bf8ad2010-09-19 17:07:03 +00004693 ssize_t
4694 i,
4695 j,
4696 k,
4697 y;
4698
cristy3ed852e2009-09-05 21:47:34 +00004699 /*
4700 Initialize steganographic image attributes.
4701 */
4702 assert(image != (const Image *) NULL);
4703 assert(image->signature == MagickSignature);
4704 if (image->debug != MagickFalse)
4705 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4706 assert(watermark != (const Image *) NULL);
4707 assert(watermark->signature == MagickSignature);
4708 assert(exception != (ExceptionInfo *) NULL);
4709 assert(exception->signature == MagickSignature);
cristyeaedf062010-05-29 22:36:02 +00004710 one=1UL;
cristy3ed852e2009-09-05 21:47:34 +00004711 stegano_image=CloneImage(image,0,0,MagickTrue,exception);
4712 if (stegano_image == (Image *) NULL)
4713 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004714 if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004715 {
cristy3ed852e2009-09-05 21:47:34 +00004716 stegano_image=DestroyImage(stegano_image);
4717 return((Image *) NULL);
4718 }
4719 stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH;
4720 /*
4721 Hide watermark in low-order bits of image.
4722 */
4723 c=0;
4724 i=0;
4725 j=0;
4726 depth=stegano_image->depth;
4727 k=image->offset;
cristyda16f162011-02-19 23:52:17 +00004728 status=MagickTrue;
cristyb0d3bb92010-09-22 14:37:58 +00004729 watermark_view=AcquireCacheView(watermark);
4730 stegano_view=AcquireCacheView(stegano_image);
cristybb503372010-05-27 20:51:26 +00004731 for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
cristy3ed852e2009-09-05 21:47:34 +00004732 {
cristybb503372010-05-27 20:51:26 +00004733 for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
cristy3ed852e2009-09-05 21:47:34 +00004734 {
cristybb503372010-05-27 20:51:26 +00004735 for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++)
cristy3ed852e2009-09-05 21:47:34 +00004736 {
cristyda1f9c12011-10-02 21:39:49 +00004737 Quantum
cristy5f95f4f2011-10-23 01:01:01 +00004738 virtual_pixel[CompositePixelChannel];
cristyda1f9c12011-10-02 21:39:49 +00004739
4740 (void) GetOneCacheViewVirtualPixel(watermark_view,x,y,virtual_pixel,
4741 exception);
4742 pixel.red=(double) virtual_pixel[RedPixelChannel];
4743 pixel.green=(double) virtual_pixel[GreenPixelChannel];
4744 pixel.blue=(double) virtual_pixel[BluePixelChannel];
4745 pixel.alpha=(double) virtual_pixel[AlphaPixelChannel];
cristybb503372010-05-27 20:51:26 +00004746 if ((k/(ssize_t) stegano_image->columns) >= (ssize_t) stegano_image->rows)
cristy3ed852e2009-09-05 21:47:34 +00004747 break;
cristyb0d3bb92010-09-22 14:37:58 +00004748 q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t)
4749 stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1,
4750 exception);
cristyacd2ed22011-08-30 01:44:23 +00004751 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004752 break;
4753 switch (c)
4754 {
4755 case 0:
4756 {
cristy4c08aed2011-07-01 19:47:50 +00004757 SetPixelRed(image,SetBit(GetPixelRed(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004758 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004759 break;
4760 }
4761 case 1:
4762 {
cristy4c08aed2011-07-01 19:47:50 +00004763 SetPixelGreen(image,SetBit(GetPixelGreen(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004764 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004765 break;
4766 }
4767 case 2:
4768 {
cristy4c08aed2011-07-01 19:47:50 +00004769 SetPixelBlue(image,SetBit(GetPixelBlue(image,q),j,GetBit(
cristy101ab702011-10-13 13:06:32 +00004770 GetPixelInfoIntensity(&pixel),i)),q);
cristy3ed852e2009-09-05 21:47:34 +00004771 break;
4772 }
4773 }
cristyb0d3bb92010-09-22 14:37:58 +00004774 if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004775 break;
4776 c++;
4777 if (c == 3)
4778 c=0;
4779 k++;
cristybb503372010-05-27 20:51:26 +00004780 if (k == (ssize_t) (stegano_image->columns*stegano_image->columns))
cristy3ed852e2009-09-05 21:47:34 +00004781 k=0;
4782 if (k == image->offset)
4783 j++;
4784 }
4785 }
cristy8b27a6d2010-02-14 03:31:15 +00004786 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004787 {
cristy8b27a6d2010-02-14 03:31:15 +00004788 MagickBooleanType
4789 proceed;
4790
4791 proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType)
4792 (depth-i),depth);
4793 if (proceed == MagickFalse)
4794 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004795 }
4796 }
cristyb0d3bb92010-09-22 14:37:58 +00004797 stegano_view=DestroyCacheView(stegano_view);
4798 watermark_view=DestroyCacheView(watermark_view);
cristy3ed852e2009-09-05 21:47:34 +00004799 if (stegano_image->storage_class == PseudoClass)
cristyea1a8aa2011-10-20 13:24:06 +00004800 (void) SyncImage(stegano_image,exception);
cristyda16f162011-02-19 23:52:17 +00004801 if (status == MagickFalse)
4802 {
4803 stegano_image=DestroyImage(stegano_image);
4804 return((Image *) NULL);
4805 }
cristy3ed852e2009-09-05 21:47:34 +00004806 return(stegano_image);
4807}
4808
4809/*
4810%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4811% %
4812% %
4813% %
4814% S t e r e o A n a g l y p h I m a g e %
4815% %
4816% %
4817% %
4818%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4819%
4820% StereoAnaglyphImage() combines two images and produces a single image that
4821% is the composite of a left and right image of a stereo pair. Special
4822% red-green stereo glasses are required to view this effect.
4823%
4824% The format of the StereoAnaglyphImage method is:
4825%
4826% Image *StereoImage(const Image *left_image,const Image *right_image,
4827% ExceptionInfo *exception)
4828% Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004829% const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004830% ExceptionInfo *exception)
4831%
4832% A description of each parameter follows:
4833%
4834% o left_image: the left image.
4835%
4836% o right_image: the right image.
4837%
4838% o exception: return any errors or warnings in this structure.
4839%
4840% o x_offset: amount, in pixels, by which the left image is offset to the
4841% right of the right image.
4842%
4843% o y_offset: amount, in pixels, by which the left image is offset to the
4844% bottom of the right image.
4845%
4846%
4847*/
4848MagickExport Image *StereoImage(const Image *left_image,
4849 const Image *right_image,ExceptionInfo *exception)
4850{
4851 return(StereoAnaglyphImage(left_image,right_image,0,0,exception));
4852}
4853
4854MagickExport Image *StereoAnaglyphImage(const Image *left_image,
cristybb503372010-05-27 20:51:26 +00004855 const Image *right_image,const ssize_t x_offset,const ssize_t y_offset,
cristy3ed852e2009-09-05 21:47:34 +00004856 ExceptionInfo *exception)
4857{
4858#define StereoImageTag "Stereo/Image"
4859
4860 const Image
4861 *image;
4862
4863 Image
4864 *stereo_image;
4865
cristy3ed852e2009-09-05 21:47:34 +00004866 MagickBooleanType
4867 status;
4868
cristy9d314ff2011-03-09 01:30:28 +00004869 ssize_t
4870 y;
4871
cristy3ed852e2009-09-05 21:47:34 +00004872 assert(left_image != (const Image *) NULL);
4873 assert(left_image->signature == MagickSignature);
4874 if (left_image->debug != MagickFalse)
4875 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
4876 left_image->filename);
4877 assert(right_image != (const Image *) NULL);
4878 assert(right_image->signature == MagickSignature);
4879 assert(exception != (ExceptionInfo *) NULL);
4880 assert(exception->signature == MagickSignature);
4881 assert(right_image != (const Image *) NULL);
4882 image=left_image;
4883 if ((left_image->columns != right_image->columns) ||
4884 (left_image->rows != right_image->rows))
4885 ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer");
4886 /*
4887 Initialize stereo image attributes.
4888 */
4889 stereo_image=CloneImage(left_image,left_image->columns,left_image->rows,
4890 MagickTrue,exception);
4891 if (stereo_image == (Image *) NULL)
4892 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00004893 if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00004894 {
cristy3ed852e2009-09-05 21:47:34 +00004895 stereo_image=DestroyImage(stereo_image);
4896 return((Image *) NULL);
4897 }
4898 /*
4899 Copy left image to red channel and right image to blue channel.
4900 */
cristyda16f162011-02-19 23:52:17 +00004901 status=MagickTrue;
cristybb503372010-05-27 20:51:26 +00004902 for (y=0; y < (ssize_t) stereo_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00004903 {
cristy4c08aed2011-07-01 19:47:50 +00004904 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00004905 *restrict p,
4906 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00004907
cristybb503372010-05-27 20:51:26 +00004908 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00004909 x;
4910
cristy4c08aed2011-07-01 19:47:50 +00004911 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00004912 *restrict r;
cristy3ed852e2009-09-05 21:47:34 +00004913
4914 p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1,
4915 exception);
4916 q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception);
4917 r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception);
cristy76f512e2011-09-12 01:26:56 +00004918 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) ||
4919 (r == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00004920 break;
cristybb503372010-05-27 20:51:26 +00004921 for (x=0; x < (ssize_t) stereo_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00004922 {
cristy4c08aed2011-07-01 19:47:50 +00004923 SetPixelRed(image,GetPixelRed(left_image,p),r);
cristy76f512e2011-09-12 01:26:56 +00004924 SetPixelGreen(image,GetPixelGreen(right_image,q),r);
4925 SetPixelBlue(image,GetPixelBlue(right_image,q),r);
4926 if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0)
4927 SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+
4928 GetPixelAlpha(right_image,q))/2,r);
cristyed231572011-07-14 02:18:59 +00004929 p+=GetPixelChannels(left_image);
cristy76f512e2011-09-12 01:26:56 +00004930 q+=GetPixelChannels(right_image);
4931 r+=GetPixelChannels(stereo_image);
cristy3ed852e2009-09-05 21:47:34 +00004932 }
4933 if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse)
4934 break;
cristy8b27a6d2010-02-14 03:31:15 +00004935 if (image->progress_monitor != (MagickProgressMonitor) NULL)
cristy3ed852e2009-09-05 21:47:34 +00004936 {
cristy8b27a6d2010-02-14 03:31:15 +00004937 MagickBooleanType
4938 proceed;
4939
cristybb503372010-05-27 20:51:26 +00004940 proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y,
4941 stereo_image->rows);
cristy8b27a6d2010-02-14 03:31:15 +00004942 if (proceed == MagickFalse)
4943 status=MagickFalse;
cristy3ed852e2009-09-05 21:47:34 +00004944 }
4945 }
cristyda16f162011-02-19 23:52:17 +00004946 if (status == MagickFalse)
4947 {
4948 stereo_image=DestroyImage(stereo_image);
4949 return((Image *) NULL);
4950 }
cristy3ed852e2009-09-05 21:47:34 +00004951 return(stereo_image);
4952}
4953
4954/*
4955%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4956% %
4957% %
4958% %
4959% S w i r l I m a g e %
4960% %
4961% %
4962% %
4963%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4964%
4965% SwirlImage() swirls the pixels about the center of the image, where
4966% degrees indicates the sweep of the arc through which each pixel is moved.
4967% You get a more dramatic effect as the degrees move from 1 to 360.
4968%
4969% The format of the SwirlImage method is:
4970%
4971% Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004972% const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004973%
4974% A description of each parameter follows:
4975%
4976% o image: the image.
4977%
4978% o degrees: Define the tightness of the swirling effect.
4979%
cristy76f512e2011-09-12 01:26:56 +00004980% o method: the pixel interpolation method.
4981%
cristy3ed852e2009-09-05 21:47:34 +00004982% o exception: return any errors or warnings in this structure.
4983%
4984*/
4985MagickExport Image *SwirlImage(const Image *image,double degrees,
cristy76f512e2011-09-12 01:26:56 +00004986 const PixelInterpolateMethod method,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00004987{
4988#define SwirlImageTag "Swirl/Image"
4989
cristyfa112112010-01-04 17:48:07 +00004990 CacheView
4991 *image_view,
4992 *swirl_view;
4993
cristy3ed852e2009-09-05 21:47:34 +00004994 Image
4995 *swirl_image;
4996
cristy3ed852e2009-09-05 21:47:34 +00004997 MagickBooleanType
4998 status;
4999
cristybb503372010-05-27 20:51:26 +00005000 MagickOffsetType
5001 progress;
5002
cristy3ed852e2009-09-05 21:47:34 +00005003 MagickRealType
5004 radius;
5005
5006 PointInfo
5007 center,
5008 scale;
5009
cristybb503372010-05-27 20:51:26 +00005010 ssize_t
5011 y;
5012
cristy3ed852e2009-09-05 21:47:34 +00005013 /*
5014 Initialize swirl image attributes.
5015 */
5016 assert(image != (const Image *) NULL);
5017 assert(image->signature == MagickSignature);
5018 if (image->debug != MagickFalse)
5019 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5020 assert(exception != (ExceptionInfo *) NULL);
5021 assert(exception->signature == MagickSignature);
cristy76f512e2011-09-12 01:26:56 +00005022 swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005023 if (swirl_image == (Image *) NULL)
5024 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005025 if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005026 {
cristy3ed852e2009-09-05 21:47:34 +00005027 swirl_image=DestroyImage(swirl_image);
5028 return((Image *) NULL);
5029 }
cristy4c08aed2011-07-01 19:47:50 +00005030 if (swirl_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00005031 swirl_image->matte=MagickTrue;
5032 /*
5033 Compute scaling factor.
5034 */
5035 center.x=(double) image->columns/2.0;
5036 center.y=(double) image->rows/2.0;
5037 radius=MagickMax(center.x,center.y);
5038 scale.x=1.0;
5039 scale.y=1.0;
5040 if (image->columns > image->rows)
5041 scale.y=(double) image->columns/(double) image->rows;
5042 else
5043 if (image->columns < image->rows)
5044 scale.x=(double) image->rows/(double) image->columns;
5045 degrees=(double) DegreesToRadians(degrees);
5046 /*
5047 Swirl image.
5048 */
5049 status=MagickTrue;
5050 progress=0;
cristy3ed852e2009-09-05 21:47:34 +00005051 image_view=AcquireCacheView(image);
5052 swirl_view=AcquireCacheView(swirl_image);
cristyb5d5f722009-11-04 03:03:49 +00005053#if defined(MAGICKCORE_OPENMP_SUPPORT)
5054 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005055#endif
cristybb503372010-05-27 20:51:26 +00005056 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005057 {
cristy3ed852e2009-09-05 21:47:34 +00005058 MagickRealType
5059 distance;
5060
5061 PointInfo
5062 delta;
5063
cristy6d188022011-09-12 13:23:33 +00005064 register const Quantum
5065 *restrict p;
5066
cristybb503372010-05-27 20:51:26 +00005067 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005068 x;
5069
cristy4c08aed2011-07-01 19:47:50 +00005070 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005071 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005072
5073 if (status == MagickFalse)
5074 continue;
cristy6d188022011-09-12 13:23:33 +00005075 p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
cristy3ed852e2009-09-05 21:47:34 +00005076 q=GetCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
5077 exception);
cristy6d188022011-09-12 13:23:33 +00005078 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005079 {
5080 status=MagickFalse;
5081 continue;
5082 }
cristy3ed852e2009-09-05 21:47:34 +00005083 delta.y=scale.y*(double) (y-center.y);
cristybb503372010-05-27 20:51:26 +00005084 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005085 {
cristy6d188022011-09-12 13:23:33 +00005086 register ssize_t
5087 i;
5088
cristy3ed852e2009-09-05 21:47:34 +00005089 /*
5090 Determine if the pixel is within an ellipse.
5091 */
5092 delta.x=scale.x*(double) (x-center.x);
5093 distance=delta.x*delta.x+delta.y*delta.y;
cristy6d188022011-09-12 13:23:33 +00005094 if (distance >= (radius*radius))
5095 {
5096 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5097 q[i]=p[i];
5098 }
5099 else
cristy3ed852e2009-09-05 21:47:34 +00005100 {
5101 MagickRealType
5102 cosine,
5103 factor,
5104 sine;
5105
5106 /*
5107 Swirl the pixel.
5108 */
5109 factor=1.0-sqrt((double) distance)/radius;
5110 sine=sin((double) (degrees*factor*factor));
5111 cosine=cos((double) (degrees*factor*factor));
cristy76f512e2011-09-12 01:26:56 +00005112 status=InterpolatePixelChannels(image,image_view,swirl_image,method,
5113 ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
5114 ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
cristy3ed852e2009-09-05 21:47:34 +00005115 }
cristy6d188022011-09-12 13:23:33 +00005116 p+=GetPixelChannels(image);
cristyed231572011-07-14 02:18:59 +00005117 q+=GetPixelChannels(swirl_image);
cristy3ed852e2009-09-05 21:47:34 +00005118 }
5119 if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse)
5120 status=MagickFalse;
5121 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5122 {
5123 MagickBooleanType
5124 proceed;
5125
cristyb5d5f722009-11-04 03:03:49 +00005126#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005127 #pragma omp critical (MagickCore_SwirlImage)
5128#endif
5129 proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows);
5130 if (proceed == MagickFalse)
5131 status=MagickFalse;
5132 }
5133 }
5134 swirl_view=DestroyCacheView(swirl_view);
5135 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005136 if (status == MagickFalse)
5137 swirl_image=DestroyImage(swirl_image);
5138 return(swirl_image);
5139}
5140
5141/*
5142%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5143% %
5144% %
5145% %
5146% T i n t I m a g e %
5147% %
5148% %
5149% %
5150%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5151%
5152% TintImage() applies a color vector to each pixel in the image. The length
5153% of the vector is 0 for black and white and at its maximum for the midtones.
5154% The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5))))
5155%
5156% The format of the TintImage method is:
5157%
cristyb817c3f2011-10-03 14:00:35 +00005158% Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005159% const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005160%
5161% A description of each parameter follows:
5162%
5163% o image: the image.
5164%
cristyb817c3f2011-10-03 14:00:35 +00005165% o blend: A color value used for tinting.
cristy3ed852e2009-09-05 21:47:34 +00005166%
5167% o tint: A color value used for tinting.
5168%
5169% o exception: return any errors or warnings in this structure.
5170%
5171*/
cristyb817c3f2011-10-03 14:00:35 +00005172MagickExport Image *TintImage(const Image *image,const char *blend,
cristy28474bf2011-09-11 23:32:52 +00005173 const PixelInfo *tint,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005174{
5175#define TintImageTag "Tint/Image"
5176
cristyc4c8d132010-01-07 01:58:38 +00005177 CacheView
5178 *image_view,
5179 *tint_view;
5180
cristy3ed852e2009-09-05 21:47:34 +00005181 GeometryInfo
5182 geometry_info;
5183
5184 Image
5185 *tint_image;
5186
cristy3ed852e2009-09-05 21:47:34 +00005187 MagickBooleanType
5188 status;
5189
cristybb503372010-05-27 20:51:26 +00005190 MagickOffsetType
5191 progress;
cristy3ed852e2009-09-05 21:47:34 +00005192
cristy28474bf2011-09-11 23:32:52 +00005193 MagickRealType
5194 intensity;
5195
cristy4c08aed2011-07-01 19:47:50 +00005196 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005197 color_vector,
5198 pixel;
5199
cristybb503372010-05-27 20:51:26 +00005200 MagickStatusType
5201 flags;
5202
5203 ssize_t
5204 y;
5205
cristy3ed852e2009-09-05 21:47:34 +00005206 /*
5207 Allocate tint image.
5208 */
5209 assert(image != (const Image *) NULL);
5210 assert(image->signature == MagickSignature);
5211 if (image->debug != MagickFalse)
5212 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5213 assert(exception != (ExceptionInfo *) NULL);
5214 assert(exception->signature == MagickSignature);
5215 tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
5216 if (tint_image == (Image *) NULL)
5217 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005218 if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005219 {
cristy3ed852e2009-09-05 21:47:34 +00005220 tint_image=DestroyImage(tint_image);
5221 return((Image *) NULL);
5222 }
cristyaed9c382011-10-03 17:54:21 +00005223 if (blend == (const char *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005224 return(tint_image);
5225 /*
5226 Determine RGB values of the color.
5227 */
cristy28474bf2011-09-11 23:32:52 +00005228 GetPixelInfo(image,&pixel);
cristyb817c3f2011-10-03 14:00:35 +00005229 flags=ParseGeometry(blend,&geometry_info);
cristy3ed852e2009-09-05 21:47:34 +00005230 pixel.red=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005231 pixel.green=geometry_info.rho;
5232 pixel.blue=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005233 pixel.alpha=OpaqueAlpha;
cristy3ed852e2009-09-05 21:47:34 +00005234 if ((flags & SigmaValue) != 0)
5235 pixel.green=geometry_info.sigma;
cristy3ed852e2009-09-05 21:47:34 +00005236 if ((flags & XiValue) != 0)
5237 pixel.blue=geometry_info.xi;
cristyb817c3f2011-10-03 14:00:35 +00005238 if ((flags & PsiValue) != 0)
5239 pixel.alpha=geometry_info.psi;
cristy76f512e2011-09-12 01:26:56 +00005240 if (image->colorspace == CMYKColorspace)
5241 {
cristyb817c3f2011-10-03 14:00:35 +00005242 pixel.black=geometry_info.rho;
cristy76f512e2011-09-12 01:26:56 +00005243 if ((flags & PsiValue) != 0)
5244 pixel.black=geometry_info.psi;
5245 if ((flags & ChiValue) != 0)
5246 pixel.alpha=geometry_info.chi;
5247 }
cristy28474bf2011-09-11 23:32:52 +00005248 intensity=(MagickRealType) GetPixelInfoIntensity(tint);
5249 color_vector.red=(MagickRealType) (pixel.red*tint->red/100.0-intensity);
5250 color_vector.green=(MagickRealType) (pixel.green*tint->green/100.0-intensity);
5251 color_vector.blue=(MagickRealType) (pixel.blue*tint->blue/100.0-intensity);
5252 color_vector.black=(MagickRealType) (pixel.black*tint->black/100.0-intensity);
5253 color_vector.alpha=(MagickRealType) (pixel.alpha*tint->alpha/100.0-intensity);
cristy3ed852e2009-09-05 21:47:34 +00005254 /*
5255 Tint image.
5256 */
5257 status=MagickTrue;
5258 progress=0;
5259 image_view=AcquireCacheView(image);
5260 tint_view=AcquireCacheView(tint_image);
cristyb5d5f722009-11-04 03:03:49 +00005261#if defined(MAGICKCORE_OPENMP_SUPPORT)
5262 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005263#endif
cristybb503372010-05-27 20:51:26 +00005264 for (y=0; y < (ssize_t) image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005265 {
cristy4c08aed2011-07-01 19:47:50 +00005266 register const Quantum
cristyc47d1f82009-11-26 01:44:43 +00005267 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +00005268
cristy4c08aed2011-07-01 19:47:50 +00005269 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005270 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005271
cristy6b91acb2011-04-19 12:23:54 +00005272 register ssize_t
5273 x;
5274
cristy3ed852e2009-09-05 21:47:34 +00005275 if (status == MagickFalse)
5276 continue;
5277 p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
5278 q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1,
5279 exception);
cristy4c08aed2011-07-01 19:47:50 +00005280 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
cristy3ed852e2009-09-05 21:47:34 +00005281 {
5282 status=MagickFalse;
5283 continue;
5284 }
cristybb503372010-05-27 20:51:26 +00005285 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005286 {
cristy4c08aed2011-07-01 19:47:50 +00005287 PixelInfo
cristy3ed852e2009-09-05 21:47:34 +00005288 pixel;
5289
5290 MagickRealType
5291 weight;
5292
cristy76f512e2011-09-12 01:26:56 +00005293 if ((GetPixelRedTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005294 {
5295 weight=QuantumScale*GetPixelRed(image,p)-0.5;
5296 pixel.red=(MagickRealType) GetPixelRed(image,p)+
5297 color_vector.red*(1.0-(4.0*(weight*weight)));
5298 SetPixelRed(tint_image,ClampToQuantum(pixel.red),q);
5299 }
cristy76f512e2011-09-12 01:26:56 +00005300 if ((GetPixelGreenTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005301 {
5302 weight=QuantumScale*GetPixelGreen(image,p)-0.5;
5303 pixel.green=(MagickRealType) GetPixelGreen(image,p)+
5304 color_vector.green*(1.0-(4.0*(weight*weight)));
5305 SetPixelGreen(tint_image,ClampToQuantum(pixel.green),q);
5306 }
cristy76f512e2011-09-12 01:26:56 +00005307 if ((GetPixelBlueTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005308 {
5309 weight=QuantumScale*GetPixelBlue(image,p)-0.5;
5310 pixel.blue=(MagickRealType) GetPixelBlue(image,p)+
5311 color_vector.blue*(1.0-(4.0*(weight*weight)));
5312 SetPixelBlue(tint_image,ClampToQuantum(pixel.blue),q);
5313 }
cristy76f512e2011-09-12 01:26:56 +00005314 if ((GetPixelBlackTraits(tint_image) & UpdatePixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005315 {
5316 weight=QuantumScale*GetPixelBlack(image,p)-0.5;
5317 pixel.black=(MagickRealType) GetPixelBlack(image,p)+
5318 color_vector.black*(1.0-(4.0*(weight*weight)));
5319 SetPixelBlack(tint_image,ClampToQuantum(pixel.black),q);
5320 }
cristy76f512e2011-09-12 01:26:56 +00005321 if ((GetPixelAlphaTraits(tint_image) & CopyPixelTrait) != 0)
cristy28474bf2011-09-11 23:32:52 +00005322 SetPixelAlpha(tint_image,GetPixelAlpha(image,p),q);
cristyed231572011-07-14 02:18:59 +00005323 p+=GetPixelChannels(image);
5324 q+=GetPixelChannels(tint_image);
cristy3ed852e2009-09-05 21:47:34 +00005325 }
5326 if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse)
5327 status=MagickFalse;
5328 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5329 {
5330 MagickBooleanType
5331 proceed;
5332
cristyb5d5f722009-11-04 03:03:49 +00005333#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005334 #pragma omp critical (MagickCore_TintImage)
5335#endif
5336 proceed=SetImageProgress(image,TintImageTag,progress++,image->rows);
5337 if (proceed == MagickFalse)
5338 status=MagickFalse;
5339 }
5340 }
5341 tint_view=DestroyCacheView(tint_view);
5342 image_view=DestroyCacheView(image_view);
5343 if (status == MagickFalse)
5344 tint_image=DestroyImage(tint_image);
5345 return(tint_image);
5346}
5347
5348/*
5349%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5350% %
5351% %
5352% %
5353% V i g n e t t e I m a g e %
5354% %
5355% %
5356% %
5357%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5358%
5359% VignetteImage() softens the edges of the image in vignette style.
5360%
5361% The format of the VignetteImage method is:
5362%
5363% Image *VignetteImage(const Image *image,const double radius,
cristy05c0c9a2011-09-05 23:16:13 +00005364% const double sigma,const ssize_t x,const ssize_t y,
5365% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005366%
5367% A description of each parameter follows:
5368%
5369% o image: the image.
5370%
5371% o radius: the radius of the pixel neighborhood.
5372%
5373% o sigma: the standard deviation of the Gaussian, in pixels.
5374%
5375% o x, y: Define the x and y ellipse offset.
5376%
5377% o exception: return any errors or warnings in this structure.
5378%
5379*/
5380MagickExport Image *VignetteImage(const Image *image,const double radius,
cristybb503372010-05-27 20:51:26 +00005381 const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005382{
5383 char
5384 ellipse[MaxTextExtent];
5385
5386 DrawInfo
5387 *draw_info;
5388
5389 Image
5390 *canvas_image,
5391 *blur_image,
5392 *oval_image,
5393 *vignette_image;
5394
5395 assert(image != (Image *) NULL);
5396 assert(image->signature == MagickSignature);
5397 if (image->debug != MagickFalse)
5398 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5399 assert(exception != (ExceptionInfo *) NULL);
5400 assert(exception->signature == MagickSignature);
5401 canvas_image=CloneImage(image,0,0,MagickTrue,exception);
5402 if (canvas_image == (Image *) NULL)
5403 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005404 if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005405 {
cristy3ed852e2009-09-05 21:47:34 +00005406 canvas_image=DestroyImage(canvas_image);
5407 return((Image *) NULL);
5408 }
5409 canvas_image->matte=MagickTrue;
cristyb3a73b52011-07-26 01:34:43 +00005410 oval_image=CloneImage(canvas_image,canvas_image->columns,
5411 canvas_image->rows,MagickTrue,exception);
cristy3ed852e2009-09-05 21:47:34 +00005412 if (oval_image == (Image *) NULL)
5413 {
5414 canvas_image=DestroyImage(canvas_image);
5415 return((Image *) NULL);
5416 }
cristy9950d572011-10-01 18:22:35 +00005417 (void) QueryColorCompliance("#000000",AllCompliance,
5418 &oval_image->background_color,exception);
cristyea1a8aa2011-10-20 13:24:06 +00005419 (void) SetImageBackgroundColor(oval_image,exception);
cristy3ed852e2009-09-05 21:47:34 +00005420 draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL);
cristy9950d572011-10-01 18:22:35 +00005421 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill,
5422 exception);
5423 (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
5424 exception);
cristyb51dff52011-05-19 16:55:47 +00005425 (void) FormatLocaleString(ellipse,MaxTextExtent,
cristye7f51092010-01-17 00:39:37 +00005426 "ellipse %g,%g,%g,%g,0.0,360.0",image->columns/2.0,
cristy8cd5b312010-01-07 01:10:24 +00005427 image->rows/2.0,image->columns/2.0-x,image->rows/2.0-y);
cristy3ed852e2009-09-05 21:47:34 +00005428 draw_info->primitive=AcquireString(ellipse);
cristy018f07f2011-09-04 21:15:19 +00005429 (void) DrawImage(oval_image,draw_info,exception);
cristy3ed852e2009-09-05 21:47:34 +00005430 draw_info=DestroyDrawInfo(draw_info);
cristy05c0c9a2011-09-05 23:16:13 +00005431 blur_image=BlurImage(oval_image,radius,sigma,image->bias,exception);
cristy3ed852e2009-09-05 21:47:34 +00005432 oval_image=DestroyImage(oval_image);
5433 if (blur_image == (Image *) NULL)
5434 {
5435 canvas_image=DestroyImage(canvas_image);
5436 return((Image *) NULL);
5437 }
5438 blur_image->matte=MagickFalse;
cristye941a752011-10-15 01:52:48 +00005439 (void) CompositeImage(canvas_image,CopyOpacityCompositeOp,blur_image,0,0,
5440 exception);
cristy3ed852e2009-09-05 21:47:34 +00005441 blur_image=DestroyImage(blur_image);
5442 vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
5443 canvas_image=DestroyImage(canvas_image);
5444 return(vignette_image);
5445}
5446
5447/*
5448%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5449% %
5450% %
5451% %
5452% W a v e I m a g e %
5453% %
5454% %
5455% %
5456%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5457%
5458% WaveImage() creates a "ripple" effect in the image by shifting the pixels
cristycee97112010-05-28 00:44:52 +00005459% vertically along a sine wave whose amplitude and wavelength is specified
cristy3ed852e2009-09-05 21:47:34 +00005460% by the given parameters.
5461%
5462% The format of the WaveImage method is:
5463%
5464% Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005465% const double wave_length,const PixelInterpolateMethod method,
5466% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005467%
5468% A description of each parameter follows:
5469%
5470% o image: the image.
5471%
5472% o amplitude, wave_length: Define the amplitude and wave length of the
5473% sine wave.
5474%
cristy5c4e2582011-09-11 19:21:03 +00005475% o interpolate: the pixel interpolation method.
5476%
cristy3ed852e2009-09-05 21:47:34 +00005477% o exception: return any errors or warnings in this structure.
5478%
5479*/
5480MagickExport Image *WaveImage(const Image *image,const double amplitude,
cristy5c4e2582011-09-11 19:21:03 +00005481 const double wave_length,const PixelInterpolateMethod method,
5482 ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00005483{
5484#define WaveImageTag "Wave/Image"
5485
cristyfa112112010-01-04 17:48:07 +00005486 CacheView
cristyd76c51e2011-03-26 00:21:26 +00005487 *image_view,
cristyfa112112010-01-04 17:48:07 +00005488 *wave_view;
5489
cristy3ed852e2009-09-05 21:47:34 +00005490 Image
5491 *wave_image;
5492
cristy3ed852e2009-09-05 21:47:34 +00005493 MagickBooleanType
5494 status;
5495
cristybb503372010-05-27 20:51:26 +00005496 MagickOffsetType
5497 progress;
5498
cristy3ed852e2009-09-05 21:47:34 +00005499 MagickRealType
5500 *sine_map;
5501
cristybb503372010-05-27 20:51:26 +00005502 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00005503 i;
5504
cristybb503372010-05-27 20:51:26 +00005505 ssize_t
5506 y;
5507
cristy3ed852e2009-09-05 21:47:34 +00005508 /*
5509 Initialize wave image attributes.
5510 */
5511 assert(image != (Image *) NULL);
5512 assert(image->signature == MagickSignature);
5513 if (image->debug != MagickFalse)
5514 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
5515 assert(exception != (ExceptionInfo *) NULL);
5516 assert(exception->signature == MagickSignature);
cristybb503372010-05-27 20:51:26 +00005517 wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
cristy3ed852e2009-09-05 21:47:34 +00005518 fabs(amplitude)),MagickTrue,exception);
5519 if (wave_image == (Image *) NULL)
5520 return((Image *) NULL);
cristy574cc262011-08-05 01:23:58 +00005521 if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00005522 {
cristy3ed852e2009-09-05 21:47:34 +00005523 wave_image=DestroyImage(wave_image);
5524 return((Image *) NULL);
5525 }
cristy4c08aed2011-07-01 19:47:50 +00005526 if (wave_image->background_color.alpha != OpaqueAlpha)
cristy3ed852e2009-09-05 21:47:34 +00005527 wave_image->matte=MagickTrue;
5528 /*
5529 Allocate sine map.
5530 */
5531 sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
5532 sizeof(*sine_map));
5533 if (sine_map == (MagickRealType *) NULL)
5534 {
5535 wave_image=DestroyImage(wave_image);
5536 ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
5537 }
cristybb503372010-05-27 20:51:26 +00005538 for (i=0; i < (ssize_t) wave_image->columns; i++)
cristy4205a3c2010-09-12 20:19:59 +00005539 sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/
5540 wave_length));
cristy3ed852e2009-09-05 21:47:34 +00005541 /*
5542 Wave image.
5543 */
5544 status=MagickTrue;
5545 progress=0;
cristyd76c51e2011-03-26 00:21:26 +00005546 image_view=AcquireCacheView(image);
cristy3ed852e2009-09-05 21:47:34 +00005547 wave_view=AcquireCacheView(wave_image);
cristyd76c51e2011-03-26 00:21:26 +00005548 (void) SetCacheViewVirtualPixelMethod(image_view,
5549 BackgroundVirtualPixelMethod);
cristyb5d5f722009-11-04 03:03:49 +00005550#if defined(MAGICKCORE_OPENMP_SUPPORT)
5551 #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
cristy3ed852e2009-09-05 21:47:34 +00005552#endif
cristybb503372010-05-27 20:51:26 +00005553 for (y=0; y < (ssize_t) wave_image->rows; y++)
cristy3ed852e2009-09-05 21:47:34 +00005554 {
cristy4c08aed2011-07-01 19:47:50 +00005555 register Quantum
cristyc47d1f82009-11-26 01:44:43 +00005556 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00005557
cristye97bb922011-04-03 01:36:52 +00005558 register ssize_t
5559 x;
5560
cristy3ed852e2009-09-05 21:47:34 +00005561 if (status == MagickFalse)
5562 continue;
5563 q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1,
5564 exception);
cristyacd2ed22011-08-30 01:44:23 +00005565 if (q == (Quantum *) NULL)
cristy3ed852e2009-09-05 21:47:34 +00005566 {
5567 status=MagickFalse;
5568 continue;
5569 }
cristybb503372010-05-27 20:51:26 +00005570 for (x=0; x < (ssize_t) wave_image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +00005571 {
cristy5c4e2582011-09-11 19:21:03 +00005572 status=InterpolatePixelChannels(image,image_view,wave_image,method,
5573 (double) x,(double) (y-sine_map[x]),q,exception);
cristyed231572011-07-14 02:18:59 +00005574 q+=GetPixelChannels(wave_image);
cristy3ed852e2009-09-05 21:47:34 +00005575 }
5576 if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse)
5577 status=MagickFalse;
5578 if (image->progress_monitor != (MagickProgressMonitor) NULL)
5579 {
5580 MagickBooleanType
5581 proceed;
5582
cristyb5d5f722009-11-04 03:03:49 +00005583#if defined(MAGICKCORE_OPENMP_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00005584 #pragma omp critical (MagickCore_WaveImage)
5585#endif
5586 proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows);
5587 if (proceed == MagickFalse)
5588 status=MagickFalse;
5589 }
5590 }
5591 wave_view=DestroyCacheView(wave_view);
cristyd76c51e2011-03-26 00:21:26 +00005592 image_view=DestroyCacheView(image_view);
cristy3ed852e2009-09-05 21:47:34 +00005593 sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
5594 if (status == MagickFalse)
5595 wave_image=DestroyImage(wave_image);
5596 return(wave_image);
5597}