cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 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 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #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" |
cristy | 9b7a4fc | 2012-04-08 22:26:56 +0000 | [diff] [blame] | 51 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 52 | #include "MagickCore/composite.h" |
| 53 | #include "MagickCore/decorate.h" |
cristy | c53413d | 2011-11-17 13:04:26 +0000 | [diff] [blame] | 54 | #include "MagickCore/distort.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 55 | #include "MagickCore/draw.h" |
| 56 | #include "MagickCore/effect.h" |
| 57 | #include "MagickCore/enhance.h" |
| 58 | #include "MagickCore/exception.h" |
| 59 | #include "MagickCore/exception-private.h" |
| 60 | #include "MagickCore/fx.h" |
| 61 | #include "MagickCore/fx-private.h" |
| 62 | #include "MagickCore/gem.h" |
cristy | 8ea8122 | 2011-09-04 10:33:32 +0000 | [diff] [blame] | 63 | #include "MagickCore/gem-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 64 | #include "MagickCore/geometry.h" |
| 65 | #include "MagickCore/layer.h" |
| 66 | #include "MagickCore/list.h" |
| 67 | #include "MagickCore/log.h" |
| 68 | #include "MagickCore/image.h" |
| 69 | #include "MagickCore/image-private.h" |
| 70 | #include "MagickCore/magick.h" |
| 71 | #include "MagickCore/memory_.h" |
| 72 | #include "MagickCore/monitor.h" |
| 73 | #include "MagickCore/monitor-private.h" |
| 74 | #include "MagickCore/option.h" |
| 75 | #include "MagickCore/pixel.h" |
| 76 | #include "MagickCore/pixel-accessor.h" |
| 77 | #include "MagickCore/property.h" |
| 78 | #include "MagickCore/quantum.h" |
| 79 | #include "MagickCore/quantum-private.h" |
| 80 | #include "MagickCore/random_.h" |
| 81 | #include "MagickCore/random-private.h" |
| 82 | #include "MagickCore/resample.h" |
| 83 | #include "MagickCore/resample-private.h" |
| 84 | #include "MagickCore/resize.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 85 | #include "MagickCore/splay-tree.h" |
| 86 | #include "MagickCore/statistic.h" |
| 87 | #include "MagickCore/string_.h" |
| 88 | #include "MagickCore/string-private.h" |
| 89 | #include "MagickCore/thread-private.h" |
| 90 | #include "MagickCore/transform.h" |
| 91 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | Define declarations. |
| 95 | */ |
| 96 | #define LeftShiftOperator 0xf5 |
| 97 | #define RightShiftOperator 0xf6 |
| 98 | #define LessThanEqualOperator 0xf7 |
| 99 | #define GreaterThanEqualOperator 0xf8 |
| 100 | #define EqualOperator 0xf9 |
| 101 | #define NotEqualOperator 0xfa |
| 102 | #define LogicalAndOperator 0xfb |
| 103 | #define LogicalOrOperator 0xfc |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 104 | #define ExponentialNotation 0xfd |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 105 | |
| 106 | struct _FxInfo |
| 107 | { |
| 108 | const Image |
| 109 | *images; |
| 110 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 111 | char |
| 112 | *expression; |
| 113 | |
| 114 | FILE |
| 115 | *file; |
| 116 | |
| 117 | SplayTreeInfo |
| 118 | *colors, |
| 119 | *symbols; |
| 120 | |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 121 | CacheView |
| 122 | **view; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 123 | |
| 124 | RandomInfo |
| 125 | *random_info; |
| 126 | |
| 127 | ExceptionInfo |
| 128 | *exception; |
| 129 | }; |
| 130 | |
| 131 | /* |
| 132 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 133 | % % |
| 134 | % % |
| 135 | % % |
| 136 | + A c q u i r e F x I n f o % |
| 137 | % % |
| 138 | % % |
| 139 | % % |
| 140 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 141 | % |
| 142 | % AcquireFxInfo() allocates the FxInfo structure. |
| 143 | % |
| 144 | % The format of the AcquireFxInfo method is: |
| 145 | % |
| 146 | % FxInfo *AcquireFxInfo(Image *image,const char *expression) |
cristy | 0a9b372 | 2010-10-23 18:45:49 +0000 | [diff] [blame] | 147 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 148 | % A description of each parameter follows: |
| 149 | % |
| 150 | % o image: the image. |
| 151 | % |
| 152 | % o expression: the expression. |
| 153 | % |
| 154 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 155 | MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 156 | { |
| 157 | char |
| 158 | fx_op[2]; |
| 159 | |
cristy | cb18092 | 2011-03-11 14:41:24 +0000 | [diff] [blame] | 160 | const Image |
| 161 | *next; |
| 162 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 163 | FxInfo |
| 164 | *fx_info; |
| 165 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 166 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 167 | i; |
| 168 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 169 | fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 170 | if (fx_info == (FxInfo *) NULL) |
| 171 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 172 | (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info)); |
| 173 | fx_info->exception=AcquireExceptionInfo(); |
anthony | 7d86e17 | 2011-03-23 12:37:06 +0000 | [diff] [blame] | 174 | fx_info->images=image; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
| 176 | RelinquishMagickMemory); |
| 177 | fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
| 178 | RelinquishMagickMemory); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 179 | fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength( |
| 180 | fx_info->images),sizeof(*fx_info->view)); |
| 181 | if (fx_info->view == (CacheView **) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 182 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | a226226 | 2011-03-11 02:50:37 +0000 | [diff] [blame] | 183 | i=0; |
cristy | 0ea377f | 2011-03-24 00:54:19 +0000 | [diff] [blame] | 184 | next=GetFirstImageInList(fx_info->images); |
| 185 | for ( ; next != (Image *) NULL; next=next->next) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | { |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 187 | fx_info->view[i]=AcquireCacheView(next); |
cristy | a226226 | 2011-03-11 02:50:37 +0000 | [diff] [blame] | 188 | i++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 189 | } |
| 190 | fx_info->random_info=AcquireRandomInfo(); |
| 191 | fx_info->expression=ConstantString(expression); |
| 192 | fx_info->file=stderr; |
| 193 | (void) SubstituteString(&fx_info->expression," ",""); /* compact string */ |
cristy | 37af091 | 2011-05-23 16:09:42 +0000 | [diff] [blame] | 194 | /* |
| 195 | Force right-to-left associativity for unary negation. |
| 196 | */ |
| 197 | (void) SubstituteString(&fx_info->expression,"-","-1.0*"); |
cristy | 8b8a3ae | 2010-10-23 18:49:46 +0000 | [diff] [blame] | 198 | /* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 199 | Convert complex to simple operators. |
| 200 | */ |
| 201 | fx_op[1]='\0'; |
| 202 | *fx_op=(char) LeftShiftOperator; |
| 203 | (void) SubstituteString(&fx_info->expression,"<<",fx_op); |
| 204 | *fx_op=(char) RightShiftOperator; |
| 205 | (void) SubstituteString(&fx_info->expression,">>",fx_op); |
| 206 | *fx_op=(char) LessThanEqualOperator; |
| 207 | (void) SubstituteString(&fx_info->expression,"<=",fx_op); |
| 208 | *fx_op=(char) GreaterThanEqualOperator; |
| 209 | (void) SubstituteString(&fx_info->expression,">=",fx_op); |
| 210 | *fx_op=(char) EqualOperator; |
| 211 | (void) SubstituteString(&fx_info->expression,"==",fx_op); |
| 212 | *fx_op=(char) NotEqualOperator; |
| 213 | (void) SubstituteString(&fx_info->expression,"!=",fx_op); |
| 214 | *fx_op=(char) LogicalAndOperator; |
| 215 | (void) SubstituteString(&fx_info->expression,"&&",fx_op); |
| 216 | *fx_op=(char) LogicalOrOperator; |
| 217 | (void) SubstituteString(&fx_info->expression,"||",fx_op); |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 218 | *fx_op=(char) ExponentialNotation; |
| 219 | (void) SubstituteString(&fx_info->expression,"**",fx_op); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 220 | return(fx_info); |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 225 | % % |
| 226 | % % |
| 227 | % % |
| 228 | % A d d N o i s e I m a g e % |
| 229 | % % |
| 230 | % % |
| 231 | % % |
| 232 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 233 | % |
| 234 | % AddNoiseImage() adds random noise to the image. |
| 235 | % |
| 236 | % The format of the AddNoiseImage method is: |
| 237 | % |
| 238 | % Image *AddNoiseImage(const Image *image,const NoiseType noise_type, |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 239 | % const double attenuate,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 240 | % |
| 241 | % A description of each parameter follows: |
| 242 | % |
| 243 | % o image: the image. |
| 244 | % |
| 245 | % o channel: the channel type. |
| 246 | % |
| 247 | % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative, |
| 248 | % Impulse, Laplacian, or Poisson. |
| 249 | % |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 250 | % o attenuate: attenuate the random distribution. |
| 251 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 252 | % o exception: return any errors or warnings in this structure. |
| 253 | % |
| 254 | */ |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 255 | MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type, |
| 256 | const double attenuate,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | { |
| 258 | #define AddNoiseImageTag "AddNoise/Image" |
| 259 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 260 | CacheView |
| 261 | *image_view, |
| 262 | *noise_view; |
| 263 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | Image |
| 265 | *noise_image; |
| 266 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 267 | MagickBooleanType |
| 268 | status; |
| 269 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 270 | MagickOffsetType |
| 271 | progress; |
| 272 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 273 | RandomInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 274 | **restrict random_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 275 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 276 | ssize_t |
| 277 | y; |
| 278 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 279 | /* |
| 280 | Initialize noise image attributes. |
| 281 | */ |
| 282 | assert(image != (const Image *) NULL); |
| 283 | assert(image->signature == MagickSignature); |
| 284 | if (image->debug != MagickFalse) |
| 285 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 286 | assert(exception != (ExceptionInfo *) NULL); |
| 287 | assert(exception->signature == MagickSignature); |
cristy | b214589 | 2011-10-10 00:55:32 +0000 | [diff] [blame] | 288 | noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 289 | if (noise_image == (Image *) NULL) |
| 290 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 291 | if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | noise_image=DestroyImage(noise_image); |
| 294 | return((Image *) NULL); |
| 295 | } |
| 296 | /* |
| 297 | Add noise in each row. |
| 298 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 299 | status=MagickTrue; |
| 300 | progress=0; |
| 301 | random_info=AcquireRandomInfoThreadSet(); |
| 302 | image_view=AcquireCacheView(image); |
| 303 | noise_view=AcquireCacheView(noise_image); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 304 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 305 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 306 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 307 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 308 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 309 | const int |
| 310 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 311 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 312 | MagickBooleanType |
| 313 | sync; |
| 314 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 315 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 316 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 317 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 318 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | x; |
| 320 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 321 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 322 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 323 | |
| 324 | if (status == MagickFalse) |
| 325 | continue; |
| 326 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 327 | q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 329 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | { |
| 331 | status=MagickFalse; |
| 332 | continue; |
| 333 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 334 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | { |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 336 | register ssize_t |
| 337 | i; |
| 338 | |
| 339 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 340 | { |
| 341 | PixelChannel |
| 342 | channel; |
| 343 | |
| 344 | PixelTrait |
| 345 | noise_traits, |
| 346 | traits; |
| 347 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 348 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 349 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 350 | noise_traits=GetPixelChannelMapTraits(noise_image,channel); |
| 351 | if ((traits == UndefinedPixelTrait) || |
| 352 | (noise_traits == UndefinedPixelTrait)) |
| 353 | continue; |
cristy | ec9e3a6 | 2012-02-01 02:09:32 +0000 | [diff] [blame] | 354 | if (((noise_traits & CopyPixelTrait) != 0) || |
| 355 | (GetPixelMask(image,p) != 0)) |
cristy | b214589 | 2011-10-10 00:55:32 +0000 | [diff] [blame] | 356 | { |
| 357 | SetPixelChannel(noise_image,channel,p[i],q); |
| 358 | continue; |
| 359 | } |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 360 | SetPixelChannel(noise_image,channel,ClampToQuantum( |
| 361 | GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)), |
| 362 | q); |
| 363 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 364 | p+=GetPixelChannels(image); |
| 365 | q+=GetPixelChannels(noise_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 366 | } |
| 367 | sync=SyncCacheViewAuthenticPixels(noise_view,exception); |
| 368 | if (sync == MagickFalse) |
| 369 | status=MagickFalse; |
| 370 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 371 | { |
| 372 | MagickBooleanType |
| 373 | proceed; |
| 374 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 375 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 376 | #pragma omp critical (MagickCore_AddNoiseImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 377 | #endif |
| 378 | proceed=SetImageProgress(image,AddNoiseImageTag,progress++, |
| 379 | image->rows); |
| 380 | if (proceed == MagickFalse) |
| 381 | status=MagickFalse; |
| 382 | } |
| 383 | } |
| 384 | noise_view=DestroyCacheView(noise_view); |
| 385 | image_view=DestroyCacheView(image_view); |
| 386 | random_info=DestroyRandomInfoThreadSet(random_info); |
| 387 | if (status == MagickFalse) |
| 388 | noise_image=DestroyImage(noise_image); |
| 389 | return(noise_image); |
| 390 | } |
| 391 | |
| 392 | /* |
| 393 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 394 | % % |
| 395 | % % |
| 396 | % % |
| 397 | % B l u e S h i f t I m a g e % |
| 398 | % % |
| 399 | % % |
| 400 | % % |
| 401 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 402 | % |
| 403 | % BlueShiftImage() mutes the colors of the image to simulate a scene at |
| 404 | % nighttime in the moonlight. |
| 405 | % |
| 406 | % The format of the BlueShiftImage method is: |
| 407 | % |
| 408 | % Image *BlueShiftImage(const Image *image,const double factor, |
| 409 | % ExceptionInfo *exception) |
| 410 | % |
| 411 | % A description of each parameter follows: |
| 412 | % |
| 413 | % o image: the image. |
| 414 | % |
| 415 | % o factor: the shift factor. |
| 416 | % |
| 417 | % o exception: return any errors or warnings in this structure. |
| 418 | % |
| 419 | */ |
| 420 | MagickExport Image *BlueShiftImage(const Image *image,const double factor, |
| 421 | ExceptionInfo *exception) |
| 422 | { |
| 423 | #define BlueShiftImageTag "BlueShift/Image" |
| 424 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 425 | CacheView |
| 426 | *image_view, |
| 427 | *shift_view; |
| 428 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 429 | Image |
| 430 | *shift_image; |
| 431 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 432 | MagickBooleanType |
| 433 | status; |
| 434 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 435 | MagickOffsetType |
| 436 | progress; |
| 437 | |
| 438 | ssize_t |
| 439 | y; |
| 440 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 441 | /* |
| 442 | Allocate blue shift image. |
| 443 | */ |
| 444 | assert(image != (const Image *) NULL); |
| 445 | assert(image->signature == MagickSignature); |
| 446 | if (image->debug != MagickFalse) |
| 447 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 448 | assert(exception != (ExceptionInfo *) NULL); |
| 449 | assert(exception->signature == MagickSignature); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 450 | shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | if (shift_image == (Image *) NULL) |
| 452 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 453 | if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 454 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 455 | shift_image=DestroyImage(shift_image); |
| 456 | return((Image *) NULL); |
| 457 | } |
| 458 | /* |
| 459 | Blue-shift DirectClass image. |
| 460 | */ |
| 461 | status=MagickTrue; |
| 462 | progress=0; |
| 463 | image_view=AcquireCacheView(image); |
| 464 | shift_view=AcquireCacheView(shift_image); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 465 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 466 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 467 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 468 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 469 | { |
| 470 | MagickBooleanType |
| 471 | sync; |
| 472 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 473 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 474 | pixel; |
| 475 | |
| 476 | Quantum |
| 477 | quantum; |
| 478 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 479 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 480 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 481 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 482 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 483 | x; |
| 484 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 485 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 486 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 487 | |
| 488 | if (status == MagickFalse) |
| 489 | continue; |
| 490 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 491 | q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1, |
| 492 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 493 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 494 | { |
| 495 | status=MagickFalse; |
| 496 | continue; |
| 497 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 498 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 499 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 500 | quantum=GetPixelRed(image,p); |
| 501 | if (GetPixelGreen(image,p) < quantum) |
| 502 | quantum=GetPixelGreen(image,p); |
| 503 | if (GetPixelBlue(image,p) < quantum) |
| 504 | quantum=GetPixelBlue(image,p); |
| 505 | pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum); |
| 506 | pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum); |
| 507 | pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum); |
| 508 | quantum=GetPixelRed(image,p); |
| 509 | if (GetPixelGreen(image,p) > quantum) |
| 510 | quantum=GetPixelGreen(image,p); |
| 511 | if (GetPixelBlue(image,p) > quantum) |
| 512 | quantum=GetPixelBlue(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 513 | pixel.red=0.5*(pixel.red+factor*quantum); |
| 514 | pixel.green=0.5*(pixel.green+factor*quantum); |
| 515 | pixel.blue=0.5*(pixel.blue+factor*quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 516 | SetPixelRed(shift_image,ClampToQuantum(pixel.red),q); |
| 517 | SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q); |
| 518 | SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 519 | p+=GetPixelChannels(image); |
| 520 | q+=GetPixelChannels(shift_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 521 | } |
| 522 | sync=SyncCacheViewAuthenticPixels(shift_view,exception); |
| 523 | if (sync == MagickFalse) |
| 524 | status=MagickFalse; |
| 525 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 526 | { |
| 527 | MagickBooleanType |
| 528 | proceed; |
| 529 | |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 530 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 531 | #pragma omp critical (MagickCore_BlueShiftImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 532 | #endif |
| 533 | proceed=SetImageProgress(image,BlueShiftImageTag,progress++, |
| 534 | image->rows); |
| 535 | if (proceed == MagickFalse) |
| 536 | status=MagickFalse; |
| 537 | } |
| 538 | } |
| 539 | image_view=DestroyCacheView(image_view); |
| 540 | shift_view=DestroyCacheView(shift_view); |
| 541 | if (status == MagickFalse) |
| 542 | shift_image=DestroyImage(shift_image); |
| 543 | return(shift_image); |
| 544 | } |
| 545 | |
| 546 | /* |
| 547 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 548 | % % |
| 549 | % % |
| 550 | % % |
| 551 | % C h a r c o a l I m a g e % |
| 552 | % % |
| 553 | % % |
| 554 | % % |
| 555 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 556 | % |
| 557 | % CharcoalImage() creates a new image that is a copy of an existing one with |
| 558 | % the edge highlighted. It allocates the memory necessary for the new Image |
| 559 | % structure and returns a pointer to the new image. |
| 560 | % |
| 561 | % The format of the CharcoalImage method is: |
| 562 | % |
| 563 | % Image *CharcoalImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 564 | % const double sigma,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 565 | % |
| 566 | % A description of each parameter follows: |
| 567 | % |
| 568 | % o image: the image. |
| 569 | % |
| 570 | % o radius: the radius of the pixel neighborhood. |
| 571 | % |
| 572 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 573 | % |
| 574 | % o exception: return any errors or warnings in this structure. |
| 575 | % |
| 576 | */ |
| 577 | MagickExport Image *CharcoalImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 578 | const double sigma,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 579 | { |
| 580 | Image |
| 581 | *charcoal_image, |
| 582 | *clone_image, |
| 583 | *edge_image; |
| 584 | |
| 585 | assert(image != (Image *) NULL); |
| 586 | assert(image->signature == MagickSignature); |
| 587 | if (image->debug != MagickFalse) |
| 588 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 589 | assert(exception != (ExceptionInfo *) NULL); |
| 590 | assert(exception->signature == MagickSignature); |
| 591 | clone_image=CloneImage(image,0,0,MagickTrue,exception); |
| 592 | if (clone_image == (Image *) NULL) |
| 593 | return((Image *) NULL); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 594 | (void) SetImageType(clone_image,GrayscaleType,exception); |
cristy | 8ae632d | 2011-09-05 17:29:53 +0000 | [diff] [blame] | 595 | edge_image=EdgeImage(clone_image,radius,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 596 | clone_image=DestroyImage(clone_image); |
| 597 | if (edge_image == (Image *) NULL) |
| 598 | return((Image *) NULL); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 599 | charcoal_image=BlurImage(edge_image,radius,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 600 | edge_image=DestroyImage(edge_image); |
| 601 | if (charcoal_image == (Image *) NULL) |
| 602 | return((Image *) NULL); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 603 | (void) NormalizeImage(charcoal_image,exception); |
cristy | b3e7c6c | 2011-07-24 01:43:55 +0000 | [diff] [blame] | 604 | (void) NegateImage(charcoal_image,MagickFalse,exception); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 605 | (void) SetImageType(charcoal_image,GrayscaleType,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 606 | return(charcoal_image); |
| 607 | } |
| 608 | |
| 609 | /* |
| 610 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 611 | % % |
| 612 | % % |
| 613 | % % |
| 614 | % C o l o r i z e I m a g e % |
| 615 | % % |
| 616 | % % |
| 617 | % % |
| 618 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 619 | % |
| 620 | % ColorizeImage() blends the fill color with each pixel in the image. |
| 621 | % A percentage blend is specified with opacity. Control the application |
| 622 | % of different color components by specifying a different percentage for |
| 623 | % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue). |
| 624 | % |
| 625 | % The format of the ColorizeImage method is: |
| 626 | % |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 627 | % Image *ColorizeImage(const Image *image,const char *blend, |
| 628 | % const PixelInfo *colorize,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 629 | % |
| 630 | % A description of each parameter follows: |
| 631 | % |
| 632 | % o image: the image. |
| 633 | % |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 634 | % o blend: A character string indicating the level of blending as a |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 635 | % percentage. |
| 636 | % |
| 637 | % o colorize: A color value. |
| 638 | % |
| 639 | % o exception: return any errors or warnings in this structure. |
| 640 | % |
| 641 | */ |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 642 | MagickExport Image *ColorizeImage(const Image *image,const char *blend, |
| 643 | const PixelInfo *colorize,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | { |
| 645 | #define ColorizeImageTag "Colorize/Image" |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 646 | #define Colorize(pixel,blend_percentage,colorize) \ |
| 647 | (pixel)=((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 648 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 649 | CacheView |
| 650 | *colorize_view, |
| 651 | *image_view; |
| 652 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 653 | GeometryInfo |
| 654 | geometry_info; |
| 655 | |
| 656 | Image |
| 657 | *colorize_image; |
| 658 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | MagickBooleanType |
| 660 | status; |
| 661 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 662 | MagickOffsetType |
| 663 | progress; |
| 664 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 665 | MagickStatusType |
| 666 | flags; |
| 667 | |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 668 | PixelInfo |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 669 | blend_percentage; |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 670 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 671 | ssize_t |
| 672 | y; |
| 673 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | /* |
| 675 | Allocate colorized image. |
| 676 | */ |
| 677 | assert(image != (const Image *) NULL); |
| 678 | assert(image->signature == MagickSignature); |
| 679 | if (image->debug != MagickFalse) |
| 680 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 681 | assert(exception != (ExceptionInfo *) NULL); |
| 682 | assert(exception->signature == MagickSignature); |
cristy | 768165d | 2012-04-09 15:01:35 +0000 | [diff] [blame] | 683 | colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
| 684 | exception); |
| 685 | if (colorize_image == (Image *) NULL) |
| 686 | return((Image *) NULL); |
| 687 | if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse) |
| 688 | { |
| 689 | colorize_image=DestroyImage(colorize_image); |
| 690 | return((Image *) NULL); |
| 691 | } |
cristy | 9b7a4fc | 2012-04-08 22:26:56 +0000 | [diff] [blame] | 692 | if ((IsGrayColorspace(image->colorspace) != MagickFalse) && |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 693 | (IsPixelInfoGray(colorize) != MagickFalse)) |
cristy | 52f2e1e | 2012-04-10 00:51:19 +0000 | [diff] [blame] | 694 | (void) SetImageColorspace(colorize_image,sRGBColorspace,exception); |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 695 | if ((colorize_image->matte == MagickFalse) && |
| 696 | (colorize->matte != MagickFalse)) |
cristy | 768165d | 2012-04-09 15:01:35 +0000 | [diff] [blame] | 697 | (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception); |
| 698 | if (blend == (const char *) NULL) |
| 699 | return(colorize_image); |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 700 | GetPixelInfo(image,&blend_percentage); |
| 701 | flags=ParseGeometry(blend,&geometry_info); |
| 702 | blend_percentage.red=geometry_info.rho; |
| 703 | blend_percentage.green=geometry_info.rho; |
| 704 | blend_percentage.blue=geometry_info.rho; |
| 705 | blend_percentage.black=geometry_info.rho; |
| 706 | blend_percentage.alpha=100.0; |
| 707 | if ((flags & SigmaValue) != 0) |
| 708 | blend_percentage.green=geometry_info.sigma; |
| 709 | if ((flags & XiValue) != 0) |
| 710 | blend_percentage.blue=geometry_info.xi; |
| 711 | if ((flags & PsiValue) != 0) |
| 712 | blend_percentage.alpha=geometry_info.psi; |
| 713 | if (blend_percentage.colorspace == CMYKColorspace) |
| 714 | { |
| 715 | if ((flags & PsiValue) != 0) |
| 716 | blend_percentage.black=geometry_info.psi; |
| 717 | if ((flags & ChiValue) != 0) |
| 718 | blend_percentage.alpha=geometry_info.chi; |
| 719 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 720 | /* |
| 721 | Colorize DirectClass image. |
| 722 | */ |
| 723 | status=MagickTrue; |
| 724 | progress=0; |
| 725 | image_view=AcquireCacheView(image); |
| 726 | colorize_view=AcquireCacheView(colorize_image); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 727 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 728 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 729 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 730 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 731 | { |
| 732 | MagickBooleanType |
| 733 | sync; |
| 734 | |
cristy | f9bf43e | 2012-04-07 18:13:07 +0000 | [diff] [blame] | 735 | PixelInfo |
| 736 | pixel; |
| 737 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 738 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 739 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 740 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 741 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 742 | x; |
| 743 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 744 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 745 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 746 | |
| 747 | if (status == MagickFalse) |
| 748 | continue; |
| 749 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 750 | q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1, |
| 751 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 752 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 753 | { |
| 754 | status=MagickFalse; |
| 755 | continue; |
| 756 | } |
cristy | f9bf43e | 2012-04-07 18:13:07 +0000 | [diff] [blame] | 757 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 758 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 759 | { |
cristy | d680338 | 2012-04-10 01:41:25 +0000 | [diff] [blame] | 760 | if (GetPixelMask(colorize_image,q) != 0) |
| 761 | { |
| 762 | p+=GetPixelChannels(image); |
| 763 | q+=GetPixelChannels(colorize_image); |
| 764 | continue; |
| 765 | } |
cristy | f9bf43e | 2012-04-07 18:13:07 +0000 | [diff] [blame] | 766 | GetPixelInfoPixel(image,p,&pixel); |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 767 | Colorize(pixel.red,blend_percentage.red,colorize->red); |
| 768 | Colorize(pixel.green,blend_percentage.green,colorize->green); |
| 769 | Colorize(pixel.blue,blend_percentage.blue,colorize->blue); |
| 770 | Colorize(pixel.black,blend_percentage.black,colorize->black); |
| 771 | Colorize(pixel.alpha,blend_percentage.alpha,colorize->alpha); |
cristy | f9bf43e | 2012-04-07 18:13:07 +0000 | [diff] [blame] | 772 | SetPixelInfoPixel(colorize_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 773 | p+=GetPixelChannels(image); |
| 774 | q+=GetPixelChannels(colorize_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 775 | } |
| 776 | sync=SyncCacheViewAuthenticPixels(colorize_view,exception); |
| 777 | if (sync == MagickFalse) |
| 778 | status=MagickFalse; |
| 779 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 780 | { |
| 781 | MagickBooleanType |
| 782 | proceed; |
| 783 | |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 784 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 785 | #pragma omp critical (MagickCore_ColorizeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 786 | #endif |
| 787 | proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows); |
| 788 | if (proceed == MagickFalse) |
| 789 | status=MagickFalse; |
| 790 | } |
| 791 | } |
| 792 | image_view=DestroyCacheView(image_view); |
| 793 | colorize_view=DestroyCacheView(colorize_view); |
| 794 | if (status == MagickFalse) |
| 795 | colorize_image=DestroyImage(colorize_image); |
| 796 | return(colorize_image); |
| 797 | } |
| 798 | |
| 799 | /* |
| 800 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 801 | % % |
| 802 | % % |
| 803 | % % |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 804 | % C o l o r M a t r i x I m a g e % |
| 805 | % % |
| 806 | % % |
| 807 | % % |
| 808 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 809 | % |
| 810 | % ColorMatrixImage() applies color transformation to an image. This method |
| 811 | % permits saturation changes, hue rotation, luminance to alpha, and various |
| 812 | % other effects. Although variable-sized transformation matrices can be used, |
| 813 | % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA |
| 814 | % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash |
| 815 | % except offsets are in column 6 rather than 5 (in support of CMYKA images) |
| 816 | % and offsets are normalized (divide Flash offset by 255). |
| 817 | % |
| 818 | % The format of the ColorMatrixImage method is: |
| 819 | % |
| 820 | % Image *ColorMatrixImage(const Image *image, |
| 821 | % const KernelInfo *color_matrix,ExceptionInfo *exception) |
| 822 | % |
| 823 | % A description of each parameter follows: |
| 824 | % |
| 825 | % o image: the image. |
| 826 | % |
| 827 | % o color_matrix: the color matrix. |
| 828 | % |
| 829 | % o exception: return any errors or warnings in this structure. |
| 830 | % |
| 831 | */ |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 832 | /* FUTURE: modify to make use of a MagickMatrix Mutliply function |
| 833 | That should be provided in "matrix.c" |
| 834 | (ASIDE: actually distorts should do this too but currently doesn't) |
| 835 | */ |
| 836 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 837 | MagickExport Image *ColorMatrixImage(const Image *image, |
| 838 | const KernelInfo *color_matrix,ExceptionInfo *exception) |
| 839 | { |
| 840 | #define ColorMatrixImageTag "ColorMatrix/Image" |
| 841 | |
| 842 | CacheView |
| 843 | *color_view, |
| 844 | *image_view; |
| 845 | |
| 846 | double |
| 847 | ColorMatrix[6][6] = |
| 848 | { |
| 849 | { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, |
| 850 | { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }, |
| 851 | { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 }, |
| 852 | { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, |
| 853 | { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 }, |
| 854 | { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 } |
| 855 | }; |
| 856 | |
| 857 | Image |
| 858 | *color_image; |
| 859 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 860 | MagickBooleanType |
| 861 | status; |
| 862 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 863 | MagickOffsetType |
| 864 | progress; |
| 865 | |
| 866 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 867 | i; |
| 868 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 869 | ssize_t |
| 870 | u, |
| 871 | v, |
| 872 | y; |
| 873 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 874 | /* |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 875 | Map given color_matrix, into a 6x6 matrix RGBKA and a constant |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 876 | */ |
| 877 | assert(image != (Image *) NULL); |
| 878 | assert(image->signature == MagickSignature); |
| 879 | if (image->debug != MagickFalse) |
| 880 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 881 | assert(exception != (ExceptionInfo *) NULL); |
| 882 | assert(exception->signature == MagickSignature); |
| 883 | i=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 884 | for (v=0; v < (ssize_t) color_matrix->height; v++) |
| 885 | for (u=0; u < (ssize_t) color_matrix->width; u++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 886 | { |
| 887 | if ((v < 6) && (u < 6)) |
| 888 | ColorMatrix[v][u]=color_matrix->values[i]; |
| 889 | i++; |
| 890 | } |
| 891 | /* |
| 892 | Initialize color image. |
| 893 | */ |
cristy | 12550e6 | 2010-06-07 12:46:40 +0000 | [diff] [blame] | 894 | color_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 895 | if (color_image == (Image *) NULL) |
| 896 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 897 | if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 898 | { |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 899 | color_image=DestroyImage(color_image); |
| 900 | return((Image *) NULL); |
| 901 | } |
| 902 | if (image->debug != MagickFalse) |
| 903 | { |
| 904 | char |
| 905 | format[MaxTextExtent], |
| 906 | *message; |
| 907 | |
| 908 | (void) LogMagickEvent(TransformEvent,GetMagickModule(), |
| 909 | " ColorMatrix image with color matrix:"); |
| 910 | message=AcquireString(""); |
| 911 | for (v=0; v < 6; v++) |
| 912 | { |
| 913 | *message='\0'; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 914 | (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 915 | (void) ConcatenateString(&message,format); |
| 916 | for (u=0; u < 6; u++) |
| 917 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 918 | (void) FormatLocaleString(format,MaxTextExtent,"%+f ", |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 919 | ColorMatrix[v][u]); |
| 920 | (void) ConcatenateString(&message,format); |
| 921 | } |
| 922 | (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message); |
| 923 | } |
| 924 | message=DestroyString(message); |
| 925 | } |
| 926 | /* |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 927 | Apply the ColorMatrix to image. |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 928 | */ |
| 929 | status=MagickTrue; |
| 930 | progress=0; |
| 931 | image_view=AcquireCacheView(image); |
| 932 | color_view=AcquireCacheView(color_image); |
| 933 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 934 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 935 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 936 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 937 | { |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 938 | PixelInfo |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 939 | pixel; |
| 940 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 941 | register const Quantum |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 942 | *restrict p; |
| 943 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 944 | register Quantum |
| 945 | *restrict q; |
| 946 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 947 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 948 | x; |
| 949 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 950 | if (status == MagickFalse) |
| 951 | continue; |
| 952 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 953 | q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1, |
| 954 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 955 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 956 | { |
| 957 | status=MagickFalse; |
| 958 | continue; |
| 959 | } |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 960 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 961 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 962 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 963 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 964 | v; |
| 965 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 966 | size_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 967 | height; |
| 968 | |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 969 | GetPixelInfoPixel(image,p,&pixel); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 970 | height=color_matrix->height > 6 ? 6UL : color_matrix->height; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 971 | for (v=0; v < (ssize_t) height; v++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 972 | { |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 973 | MagickRealType |
| 974 | sum; |
| 975 | |
| 976 | sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 977 | GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 978 | if (image->colorspace == CMYKColorspace) |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 979 | sum+=ColorMatrix[v][3]*GetPixelBlack(image,p); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 980 | if (image->matte != MagickFalse) |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 981 | sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p); |
| 982 | sum+=QuantumRange*ColorMatrix[v][5]; |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 983 | switch (v) |
| 984 | { |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 985 | case 0: pixel.red=sum; break; |
| 986 | case 1: pixel.green=sum; break; |
| 987 | case 2: pixel.blue=sum; break; |
| 988 | case 3: pixel.black=sum; break; |
| 989 | case 4: pixel.alpha=sum; break; |
| 990 | default: break; |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 991 | } |
| 992 | } |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 993 | SetPixelInfoPixel(color_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 994 | p+=GetPixelChannels(image); |
| 995 | q+=GetPixelChannels(color_image); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 996 | } |
| 997 | if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse) |
| 998 | status=MagickFalse; |
| 999 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1000 | { |
| 1001 | MagickBooleanType |
| 1002 | proceed; |
| 1003 | |
| 1004 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 1005 | #pragma omp critical (MagickCore_ColorMatrixImage) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 1006 | #endif |
| 1007 | proceed=SetImageProgress(image,ColorMatrixImageTag,progress++, |
| 1008 | image->rows); |
| 1009 | if (proceed == MagickFalse) |
| 1010 | status=MagickFalse; |
| 1011 | } |
| 1012 | } |
| 1013 | color_view=DestroyCacheView(color_view); |
| 1014 | image_view=DestroyCacheView(image_view); |
| 1015 | if (status == MagickFalse) |
| 1016 | color_image=DestroyImage(color_image); |
| 1017 | return(color_image); |
| 1018 | } |
| 1019 | |
| 1020 | /* |
| 1021 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1022 | % % |
| 1023 | % % |
| 1024 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1025 | + D e s t r o y F x I n f o % |
| 1026 | % % |
| 1027 | % % |
| 1028 | % % |
| 1029 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1030 | % |
| 1031 | % DestroyFxInfo() deallocates memory associated with an FxInfo structure. |
| 1032 | % |
| 1033 | % The format of the DestroyFxInfo method is: |
| 1034 | % |
| 1035 | % ImageInfo *DestroyFxInfo(ImageInfo *fx_info) |
| 1036 | % |
| 1037 | % A description of each parameter follows: |
| 1038 | % |
| 1039 | % o fx_info: the fx info. |
| 1040 | % |
| 1041 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1042 | MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1043 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1044 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1045 | i; |
| 1046 | |
| 1047 | fx_info->exception=DestroyExceptionInfo(fx_info->exception); |
| 1048 | fx_info->expression=DestroyString(fx_info->expression); |
| 1049 | fx_info->symbols=DestroySplayTree(fx_info->symbols); |
| 1050 | fx_info->colors=DestroySplayTree(fx_info->colors); |
cristy | 0ea377f | 2011-03-24 00:54:19 +0000 | [diff] [blame] | 1051 | for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--) |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 1052 | fx_info->view[i]=DestroyCacheView(fx_info->view[i]); |
| 1053 | fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1054 | fx_info->random_info=DestroyRandomInfo(fx_info->random_info); |
| 1055 | fx_info=(FxInfo *) RelinquishMagickMemory(fx_info); |
| 1056 | return(fx_info); |
| 1057 | } |
| 1058 | |
| 1059 | /* |
| 1060 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1061 | % % |
| 1062 | % % |
| 1063 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1064 | + 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 % |
| 1065 | % % |
| 1066 | % % |
| 1067 | % % |
| 1068 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1069 | % |
| 1070 | % FxEvaluateChannelExpression() evaluates an expression and returns the |
| 1071 | % results. |
| 1072 | % |
| 1073 | % The format of the FxEvaluateExpression method is: |
| 1074 | % |
| 1075 | % MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1076 | % const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1077 | % MagickRealType *alpha,Exceptioninfo *exception) |
| 1078 | % MagickRealType FxEvaluateExpression(FxInfo *fx_info, |
| 1079 | % MagickRealType *alpha,Exceptioninfo *exception) |
| 1080 | % |
| 1081 | % A description of each parameter follows: |
| 1082 | % |
| 1083 | % o fx_info: the fx info. |
| 1084 | % |
| 1085 | % o channel: the channel. |
| 1086 | % |
| 1087 | % o x,y: the pixel position. |
| 1088 | % |
| 1089 | % o alpha: the result. |
| 1090 | % |
| 1091 | % o exception: return any errors or warnings in this structure. |
| 1092 | % |
| 1093 | */ |
| 1094 | |
cristy | 351842f | 2010-03-07 15:27:38 +0000 | [diff] [blame] | 1095 | static inline double MagickMax(const double x,const double y) |
| 1096 | { |
| 1097 | if (x > y) |
| 1098 | return(x); |
| 1099 | return(y); |
| 1100 | } |
| 1101 | |
| 1102 | static inline double MagickMin(const double x,const double y) |
| 1103 | { |
| 1104 | if (x < y) |
| 1105 | return(x); |
| 1106 | return(y); |
| 1107 | } |
| 1108 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1109 | static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1110 | PixelChannel channel,const char *symbol,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1111 | { |
| 1112 | char |
| 1113 | key[MaxTextExtent], |
| 1114 | statistic[MaxTextExtent]; |
| 1115 | |
| 1116 | const char |
| 1117 | *value; |
| 1118 | |
| 1119 | register const char |
| 1120 | *p; |
| 1121 | |
| 1122 | for (p=symbol; (*p != '.') && (*p != '\0'); p++) ; |
| 1123 | if (*p == '.') |
| 1124 | switch (*++p) /* e.g. depth.r */ |
| 1125 | { |
cristy | 541ae57 | 2011-08-05 19:08:59 +0000 | [diff] [blame] | 1126 | case 'r': channel=RedPixelChannel; break; |
| 1127 | case 'g': channel=GreenPixelChannel; break; |
| 1128 | case 'b': channel=BluePixelChannel; break; |
| 1129 | case 'c': channel=CyanPixelChannel; break; |
| 1130 | case 'm': channel=MagentaPixelChannel; break; |
| 1131 | case 'y': channel=YellowPixelChannel; break; |
| 1132 | case 'k': channel=BlackPixelChannel; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1133 | default: break; |
| 1134 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1135 | (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1136 | (double) channel,symbol); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1137 | value=(const char *) GetValueFromSplayTree(fx_info->symbols,key); |
| 1138 | if (value != (const char *) NULL) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1139 | return(QuantumScale*StringToDouble(value,(char **) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1140 | (void) DeleteNodeFromSplayTree(fx_info->symbols,key); |
| 1141 | if (LocaleNCompare(symbol,"depth",5) == 0) |
| 1142 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1143 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1144 | depth; |
| 1145 | |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 1146 | depth=GetImageDepth(image,exception); |
| 1147 | (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1148 | } |
| 1149 | if (LocaleNCompare(symbol,"kurtosis",8) == 0) |
| 1150 | { |
| 1151 | double |
| 1152 | kurtosis, |
| 1153 | skewness; |
| 1154 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1155 | (void) GetImageKurtosis(image,&kurtosis,&skewness,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1156 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1157 | } |
| 1158 | if (LocaleNCompare(symbol,"maxima",6) == 0) |
| 1159 | { |
| 1160 | double |
| 1161 | maxima, |
| 1162 | minima; |
| 1163 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1164 | (void) GetImageRange(image,&minima,&maxima,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1165 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1166 | } |
| 1167 | if (LocaleNCompare(symbol,"mean",4) == 0) |
| 1168 | { |
| 1169 | double |
| 1170 | mean, |
| 1171 | standard_deviation; |
| 1172 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1173 | (void) GetImageMean(image,&mean,&standard_deviation,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1174 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1175 | } |
| 1176 | if (LocaleNCompare(symbol,"minima",6) == 0) |
| 1177 | { |
| 1178 | double |
| 1179 | maxima, |
| 1180 | minima; |
| 1181 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1182 | (void) GetImageRange(image,&minima,&maxima,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1183 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1184 | } |
| 1185 | if (LocaleNCompare(symbol,"skewness",8) == 0) |
| 1186 | { |
| 1187 | double |
| 1188 | kurtosis, |
| 1189 | skewness; |
| 1190 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1191 | (void) GetImageKurtosis(image,&kurtosis,&skewness,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1192 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1193 | } |
| 1194 | if (LocaleNCompare(symbol,"standard_deviation",18) == 0) |
| 1195 | { |
| 1196 | double |
| 1197 | mean, |
| 1198 | standard_deviation; |
| 1199 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1200 | (void) GetImageMean(image,&mean,&standard_deviation,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1201 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1202 | standard_deviation); |
| 1203 | } |
| 1204 | (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key), |
| 1205 | ConstantString(statistic)); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1206 | return(QuantumScale*StringToDouble(statistic,(char **) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | static MagickRealType |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1210 | FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t, |
cristy | e85007d | 2010-06-06 22:51:36 +0000 | [diff] [blame] | 1211 | const ssize_t,const char *,MagickRealType *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1212 | |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 1213 | static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta) |
| 1214 | { |
| 1215 | if (beta != 0) |
| 1216 | return(FxGCD(beta,alpha % beta)); |
| 1217 | return(alpha); |
| 1218 | } |
| 1219 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | static inline const char *FxSubexpression(const char *expression, |
| 1221 | ExceptionInfo *exception) |
| 1222 | { |
| 1223 | const char |
| 1224 | *subexpression; |
| 1225 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1226 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1227 | level; |
| 1228 | |
| 1229 | level=0; |
| 1230 | subexpression=expression; |
| 1231 | while ((*subexpression != '\0') && |
| 1232 | ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL))) |
| 1233 | { |
| 1234 | if (strchr("(",(int) *subexpression) != (char *) NULL) |
| 1235 | level++; |
| 1236 | else |
| 1237 | if (strchr(")",(int) *subexpression) != (char *) NULL) |
| 1238 | level--; |
| 1239 | subexpression++; |
| 1240 | } |
| 1241 | if (*subexpression == '\0') |
| 1242 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1243 | "UnbalancedParenthesis","`%s'",expression); |
| 1244 | return(subexpression); |
| 1245 | } |
| 1246 | |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1247 | static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel, |
cristy | e85007d | 2010-06-06 22:51:36 +0000 | [diff] [blame] | 1248 | const ssize_t x,const ssize_t y,const char *expression, |
| 1249 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1250 | { |
| 1251 | char |
| 1252 | *q, |
| 1253 | subexpression[MaxTextExtent], |
| 1254 | symbol[MaxTextExtent]; |
| 1255 | |
| 1256 | const char |
| 1257 | *p, |
| 1258 | *value; |
| 1259 | |
| 1260 | Image |
| 1261 | *image; |
| 1262 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1263 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1264 | pixel; |
| 1265 | |
| 1266 | MagickRealType |
| 1267 | alpha, |
| 1268 | beta; |
| 1269 | |
| 1270 | PointInfo |
| 1271 | point; |
| 1272 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1273 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1274 | i; |
| 1275 | |
| 1276 | size_t |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1277 | length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1278 | level; |
| 1279 | |
| 1280 | p=expression; |
| 1281 | i=GetImageIndexInList(fx_info->images); |
| 1282 | level=0; |
| 1283 | point.x=(double) x; |
| 1284 | point.y=(double) y; |
| 1285 | if (isalpha((int) *(p+1)) == 0) |
| 1286 | { |
| 1287 | if (strchr("suv",(int) *p) != (char *) NULL) |
| 1288 | { |
| 1289 | switch (*p) |
| 1290 | { |
| 1291 | case 's': |
| 1292 | default: |
| 1293 | { |
| 1294 | i=GetImageIndexInList(fx_info->images); |
| 1295 | break; |
| 1296 | } |
| 1297 | case 'u': i=0; break; |
| 1298 | case 'v': i=1; break; |
| 1299 | } |
| 1300 | p++; |
| 1301 | if (*p == '[') |
| 1302 | { |
| 1303 | level++; |
| 1304 | q=subexpression; |
| 1305 | for (p++; *p != '\0'; ) |
| 1306 | { |
| 1307 | if (*p == '[') |
| 1308 | level++; |
| 1309 | else |
| 1310 | if (*p == ']') |
| 1311 | { |
| 1312 | level--; |
| 1313 | if (level == 0) |
| 1314 | break; |
| 1315 | } |
| 1316 | *q++=(*p++); |
| 1317 | } |
| 1318 | *q='\0'; |
| 1319 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1320 | &beta,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1321 | i=(ssize_t) (alpha+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1322 | p++; |
| 1323 | } |
| 1324 | if (*p == '.') |
| 1325 | p++; |
| 1326 | } |
| 1327 | if ((isalpha((int) *(p+1)) == 0) && (*p == 'p')) |
| 1328 | { |
| 1329 | p++; |
| 1330 | if (*p == '{') |
| 1331 | { |
| 1332 | level++; |
| 1333 | q=subexpression; |
| 1334 | for (p++; *p != '\0'; ) |
| 1335 | { |
| 1336 | if (*p == '{') |
| 1337 | level++; |
| 1338 | else |
| 1339 | if (*p == '}') |
| 1340 | { |
| 1341 | level--; |
| 1342 | if (level == 0) |
| 1343 | break; |
| 1344 | } |
| 1345 | *q++=(*p++); |
| 1346 | } |
| 1347 | *q='\0'; |
| 1348 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1349 | &beta,exception); |
| 1350 | point.x=alpha; |
| 1351 | point.y=beta; |
| 1352 | p++; |
| 1353 | } |
| 1354 | else |
| 1355 | if (*p == '[') |
| 1356 | { |
| 1357 | level++; |
| 1358 | q=subexpression; |
| 1359 | for (p++; *p != '\0'; ) |
| 1360 | { |
| 1361 | if (*p == '[') |
| 1362 | level++; |
| 1363 | else |
| 1364 | if (*p == ']') |
| 1365 | { |
| 1366 | level--; |
| 1367 | if (level == 0) |
| 1368 | break; |
| 1369 | } |
| 1370 | *q++=(*p++); |
| 1371 | } |
| 1372 | *q='\0'; |
| 1373 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1374 | &beta,exception); |
| 1375 | point.x+=alpha; |
| 1376 | point.y+=beta; |
| 1377 | p++; |
| 1378 | } |
| 1379 | if (*p == '.') |
| 1380 | p++; |
| 1381 | } |
| 1382 | } |
| 1383 | length=GetImageListLength(fx_info->images); |
| 1384 | while (i < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1385 | i+=(ssize_t) length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1386 | i%=length; |
| 1387 | image=GetImageFromList(fx_info->images,i); |
| 1388 | if (image == (Image *) NULL) |
| 1389 | { |
| 1390 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1391 | "NoSuchImage","`%s'",expression); |
| 1392 | return(0.0); |
| 1393 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1394 | GetPixelInfo(image,&pixel); |
| 1395 | (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate, |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 1396 | point.x,point.y,&pixel,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1397 | if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) && |
| 1398 | (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1399 | (LocaleCompare(p,"saturation") != 0) && |
| 1400 | (LocaleCompare(p,"lightness") != 0)) |
| 1401 | { |
| 1402 | char |
| 1403 | name[MaxTextExtent]; |
| 1404 | |
| 1405 | (void) CopyMagickString(name,p,MaxTextExtent); |
| 1406 | for (q=name+(strlen(name)-1); q > name; q--) |
| 1407 | { |
| 1408 | if (*q == ')') |
| 1409 | break; |
| 1410 | if (*q == '.') |
| 1411 | { |
| 1412 | *q='\0'; |
| 1413 | break; |
| 1414 | } |
| 1415 | } |
| 1416 | if ((strlen(name) > 2) && |
| 1417 | (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL)) |
| 1418 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1419 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1420 | *color; |
| 1421 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1422 | color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name); |
| 1423 | if (color != (PixelInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1424 | { |
| 1425 | pixel=(*color); |
| 1426 | p+=strlen(name); |
| 1427 | } |
| 1428 | else |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1429 | { |
| 1430 | MagickBooleanType |
| 1431 | status; |
| 1432 | |
| 1433 | status=QueryColorCompliance(name,AllCompliance,&pixel, |
| 1434 | fx_info->exception); |
| 1435 | if (status != MagickFalse) |
| 1436 | { |
| 1437 | (void) AddValueToSplayTree(fx_info->colors,ConstantString( |
| 1438 | name),ClonePixelInfo(&pixel)); |
| 1439 | p+=strlen(name); |
| 1440 | } |
| 1441 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1442 | } |
| 1443 | } |
| 1444 | (void) CopyMagickString(symbol,p,MaxTextExtent); |
| 1445 | StripString(symbol); |
| 1446 | if (*symbol == '\0') |
| 1447 | { |
| 1448 | switch (channel) |
| 1449 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1450 | case RedPixelChannel: return(QuantumScale*pixel.red); |
| 1451 | case GreenPixelChannel: return(QuantumScale*pixel.green); |
| 1452 | case BluePixelChannel: return(QuantumScale*pixel.blue); |
| 1453 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1454 | { |
| 1455 | if (image->colorspace != CMYKColorspace) |
| 1456 | { |
| 1457 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 1a020e4 | 2011-12-06 18:13:23 +0000 | [diff] [blame] | 1458 | ImageError,"ColorSeparatedImageRequired","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1459 | image->filename); |
| 1460 | return(0.0); |
| 1461 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1462 | return(QuantumScale*pixel.black); |
| 1463 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1464 | case AlphaPixelChannel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1465 | { |
| 1466 | MagickRealType |
| 1467 | alpha; |
| 1468 | |
| 1469 | if (pixel.matte == MagickFalse) |
| 1470 | return(1.0); |
| 1471 | alpha=(MagickRealType) (QuantumScale*pixel.alpha); |
| 1472 | return(alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1473 | } |
cristy | a382aca | 2011-12-06 18:22:48 +0000 | [diff] [blame] | 1474 | case IndexPixelChannel: |
| 1475 | return(0.0); |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 1476 | case IntensityPixelChannel: |
cristy | f364ed4 | 2010-12-15 01:54:43 +0000 | [diff] [blame] | 1477 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1478 | return(QuantumScale*GetPixelInfoIntensity(&pixel)); |
cristy | f364ed4 | 2010-12-15 01:54:43 +0000 | [diff] [blame] | 1479 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1480 | default: |
| 1481 | break; |
| 1482 | } |
| 1483 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1484 | "UnableToParseExpression","`%s'",p); |
| 1485 | return(0.0); |
| 1486 | } |
| 1487 | switch (*symbol) |
| 1488 | { |
| 1489 | case 'A': |
| 1490 | case 'a': |
| 1491 | { |
| 1492 | if (LocaleCompare(symbol,"a") == 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1493 | return((MagickRealType) (QuantumScale*pixel.alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1494 | break; |
| 1495 | } |
| 1496 | case 'B': |
| 1497 | case 'b': |
| 1498 | { |
| 1499 | if (LocaleCompare(symbol,"b") == 0) |
| 1500 | return(QuantumScale*pixel.blue); |
| 1501 | break; |
| 1502 | } |
| 1503 | case 'C': |
| 1504 | case 'c': |
| 1505 | { |
| 1506 | if (LocaleNCompare(symbol,"channel",7) == 0) |
| 1507 | { |
| 1508 | GeometryInfo |
| 1509 | channel_info; |
| 1510 | |
| 1511 | MagickStatusType |
| 1512 | flags; |
| 1513 | |
| 1514 | flags=ParseGeometry(symbol+7,&channel_info); |
| 1515 | if (image->colorspace == CMYKColorspace) |
| 1516 | switch (channel) |
| 1517 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1518 | case CyanPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1519 | { |
| 1520 | if ((flags & RhoValue) == 0) |
| 1521 | return(0.0); |
| 1522 | return(channel_info.rho); |
| 1523 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1524 | case MagentaPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1525 | { |
| 1526 | if ((flags & SigmaValue) == 0) |
| 1527 | return(0.0); |
| 1528 | return(channel_info.sigma); |
| 1529 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1530 | case YellowPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1531 | { |
| 1532 | if ((flags & XiValue) == 0) |
| 1533 | return(0.0); |
| 1534 | return(channel_info.xi); |
| 1535 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1536 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1537 | { |
| 1538 | if ((flags & PsiValue) == 0) |
| 1539 | return(0.0); |
| 1540 | return(channel_info.psi); |
| 1541 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1542 | case AlphaPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1543 | { |
| 1544 | if ((flags & ChiValue) == 0) |
| 1545 | return(0.0); |
| 1546 | return(channel_info.chi); |
| 1547 | } |
| 1548 | default: |
| 1549 | return(0.0); |
| 1550 | } |
| 1551 | switch (channel) |
| 1552 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1553 | case RedPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1554 | { |
| 1555 | if ((flags & RhoValue) == 0) |
| 1556 | return(0.0); |
| 1557 | return(channel_info.rho); |
| 1558 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1559 | case GreenPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1560 | { |
| 1561 | if ((flags & SigmaValue) == 0) |
| 1562 | return(0.0); |
| 1563 | return(channel_info.sigma); |
| 1564 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1565 | case BluePixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1566 | { |
| 1567 | if ((flags & XiValue) == 0) |
| 1568 | return(0.0); |
| 1569 | return(channel_info.xi); |
| 1570 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1571 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1572 | { |
| 1573 | if ((flags & ChiValue) == 0) |
| 1574 | return(0.0); |
| 1575 | return(channel_info.chi); |
| 1576 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1577 | case AlphaPixelChannel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1578 | { |
| 1579 | if ((flags & PsiValue) == 0) |
| 1580 | return(0.0); |
| 1581 | return(channel_info.psi); |
| 1582 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1583 | default: |
| 1584 | return(0.0); |
| 1585 | } |
| 1586 | return(0.0); |
| 1587 | } |
| 1588 | if (LocaleCompare(symbol,"c") == 0) |
| 1589 | return(QuantumScale*pixel.red); |
| 1590 | break; |
| 1591 | } |
| 1592 | case 'D': |
| 1593 | case 'd': |
| 1594 | { |
| 1595 | if (LocaleNCompare(symbol,"depth",5) == 0) |
| 1596 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1597 | break; |
| 1598 | } |
| 1599 | case 'G': |
| 1600 | case 'g': |
| 1601 | { |
| 1602 | if (LocaleCompare(symbol,"g") == 0) |
| 1603 | return(QuantumScale*pixel.green); |
| 1604 | break; |
| 1605 | } |
| 1606 | case 'K': |
| 1607 | case 'k': |
| 1608 | { |
| 1609 | if (LocaleNCompare(symbol,"kurtosis",8) == 0) |
| 1610 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1611 | if (LocaleCompare(symbol,"k") == 0) |
| 1612 | { |
| 1613 | if (image->colorspace != CMYKColorspace) |
| 1614 | { |
| 1615 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1616 | OptionError,"ColorSeparatedImageRequired","`%s'", |
| 1617 | image->filename); |
| 1618 | return(0.0); |
| 1619 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1620 | return(QuantumScale*pixel.black); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1621 | } |
| 1622 | break; |
| 1623 | } |
| 1624 | case 'H': |
| 1625 | case 'h': |
| 1626 | { |
| 1627 | if (LocaleCompare(symbol,"h") == 0) |
| 1628 | return((MagickRealType) image->rows); |
| 1629 | if (LocaleCompare(symbol,"hue") == 0) |
| 1630 | { |
| 1631 | double |
| 1632 | hue, |
| 1633 | lightness, |
| 1634 | saturation; |
| 1635 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1636 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
| 1637 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1638 | return(hue); |
| 1639 | } |
| 1640 | break; |
| 1641 | } |
| 1642 | case 'I': |
| 1643 | case 'i': |
| 1644 | { |
| 1645 | if ((LocaleCompare(symbol,"image.depth") == 0) || |
| 1646 | (LocaleCompare(symbol,"image.minima") == 0) || |
| 1647 | (LocaleCompare(symbol,"image.maxima") == 0) || |
| 1648 | (LocaleCompare(symbol,"image.mean") == 0) || |
| 1649 | (LocaleCompare(symbol,"image.kurtosis") == 0) || |
| 1650 | (LocaleCompare(symbol,"image.skewness") == 0) || |
| 1651 | (LocaleCompare(symbol,"image.standard_deviation") == 0)) |
| 1652 | return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception)); |
| 1653 | if (LocaleCompare(symbol,"image.resolution.x") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1654 | return(image->resolution.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1655 | if (LocaleCompare(symbol,"image.resolution.y") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1656 | return(image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1657 | if (LocaleCompare(symbol,"intensity") == 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1658 | return(QuantumScale*GetPixelInfoIntensity(&pixel)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1659 | if (LocaleCompare(symbol,"i") == 0) |
| 1660 | return((MagickRealType) x); |
| 1661 | break; |
| 1662 | } |
| 1663 | case 'J': |
| 1664 | case 'j': |
| 1665 | { |
| 1666 | if (LocaleCompare(symbol,"j") == 0) |
| 1667 | return((MagickRealType) y); |
| 1668 | break; |
| 1669 | } |
| 1670 | case 'L': |
| 1671 | case 'l': |
| 1672 | { |
| 1673 | if (LocaleCompare(symbol,"lightness") == 0) |
| 1674 | { |
| 1675 | double |
| 1676 | hue, |
| 1677 | lightness, |
| 1678 | saturation; |
| 1679 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1680 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
| 1681 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1682 | return(lightness); |
| 1683 | } |
| 1684 | if (LocaleCompare(symbol,"luminance") == 0) |
| 1685 | { |
| 1686 | double |
| 1687 | luminence; |
| 1688 | |
| 1689 | luminence=0.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue; |
| 1690 | return(QuantumScale*luminence); |
| 1691 | } |
| 1692 | break; |
| 1693 | } |
| 1694 | case 'M': |
| 1695 | case 'm': |
| 1696 | { |
| 1697 | if (LocaleNCompare(symbol,"maxima",6) == 0) |
| 1698 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1699 | if (LocaleNCompare(symbol,"mean",4) == 0) |
| 1700 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1701 | if (LocaleNCompare(symbol,"minima",6) == 0) |
| 1702 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1703 | if (LocaleCompare(symbol,"m") == 0) |
| 1704 | return(QuantumScale*pixel.blue); |
| 1705 | break; |
| 1706 | } |
| 1707 | case 'N': |
| 1708 | case 'n': |
| 1709 | { |
| 1710 | if (LocaleCompare(symbol,"n") == 0) |
anthony | 374f5dd | 2011-03-25 10:08:53 +0000 | [diff] [blame] | 1711 | return((MagickRealType) GetImageListLength(fx_info->images)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1712 | break; |
| 1713 | } |
| 1714 | case 'O': |
| 1715 | case 'o': |
| 1716 | { |
| 1717 | if (LocaleCompare(symbol,"o") == 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1718 | return(QuantumScale*pixel.alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1719 | break; |
| 1720 | } |
| 1721 | case 'P': |
| 1722 | case 'p': |
| 1723 | { |
| 1724 | if (LocaleCompare(symbol,"page.height") == 0) |
| 1725 | return((MagickRealType) image->page.height); |
| 1726 | if (LocaleCompare(symbol,"page.width") == 0) |
| 1727 | return((MagickRealType) image->page.width); |
| 1728 | if (LocaleCompare(symbol,"page.x") == 0) |
| 1729 | return((MagickRealType) image->page.x); |
| 1730 | if (LocaleCompare(symbol,"page.y") == 0) |
| 1731 | return((MagickRealType) image->page.y); |
| 1732 | break; |
| 1733 | } |
| 1734 | case 'R': |
| 1735 | case 'r': |
| 1736 | { |
| 1737 | if (LocaleCompare(symbol,"resolution.x") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1738 | return(image->resolution.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1739 | if (LocaleCompare(symbol,"resolution.y") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1740 | return(image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1741 | if (LocaleCompare(symbol,"r") == 0) |
| 1742 | return(QuantumScale*pixel.red); |
| 1743 | break; |
| 1744 | } |
| 1745 | case 'S': |
| 1746 | case 's': |
| 1747 | { |
| 1748 | if (LocaleCompare(symbol,"saturation") == 0) |
| 1749 | { |
| 1750 | double |
| 1751 | hue, |
| 1752 | lightness, |
| 1753 | saturation; |
| 1754 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1755 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
| 1756 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1757 | return(saturation); |
| 1758 | } |
| 1759 | if (LocaleNCompare(symbol,"skewness",8) == 0) |
| 1760 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1761 | if (LocaleNCompare(symbol,"standard_deviation",18) == 0) |
| 1762 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1763 | break; |
| 1764 | } |
| 1765 | case 'T': |
| 1766 | case 't': |
| 1767 | { |
| 1768 | if (LocaleCompare(symbol,"t") == 0) |
cristy | 5a15b93 | 2011-03-26 12:50:33 +0000 | [diff] [blame] | 1769 | return((MagickRealType) GetImageIndexInList(fx_info->images)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1770 | break; |
| 1771 | } |
| 1772 | case 'W': |
| 1773 | case 'w': |
| 1774 | { |
| 1775 | if (LocaleCompare(symbol,"w") == 0) |
| 1776 | return((MagickRealType) image->columns); |
| 1777 | break; |
| 1778 | } |
| 1779 | case 'Y': |
| 1780 | case 'y': |
| 1781 | { |
| 1782 | if (LocaleCompare(symbol,"y") == 0) |
| 1783 | return(QuantumScale*pixel.green); |
| 1784 | break; |
| 1785 | } |
| 1786 | case 'Z': |
| 1787 | case 'z': |
| 1788 | { |
| 1789 | if (LocaleCompare(symbol,"z") == 0) |
| 1790 | { |
| 1791 | MagickRealType |
| 1792 | depth; |
| 1793 | |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 1794 | depth=(MagickRealType) GetImageDepth(image,fx_info->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1795 | return(depth); |
| 1796 | } |
| 1797 | break; |
| 1798 | } |
| 1799 | default: |
| 1800 | break; |
| 1801 | } |
| 1802 | value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol); |
| 1803 | if (value != (const char *) NULL) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1804 | return((MagickRealType) StringToDouble(value,(char **) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1805 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 1806 | "UnableToParseExpression","`%s'",symbol); |
| 1807 | return(0.0); |
| 1808 | } |
| 1809 | |
| 1810 | static const char *FxOperatorPrecedence(const char *expression, |
| 1811 | ExceptionInfo *exception) |
| 1812 | { |
| 1813 | typedef enum |
| 1814 | { |
| 1815 | UndefinedPrecedence, |
| 1816 | NullPrecedence, |
| 1817 | BitwiseComplementPrecedence, |
| 1818 | ExponentPrecedence, |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 1819 | ExponentialNotationPrecedence, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1820 | MultiplyPrecedence, |
| 1821 | AdditionPrecedence, |
| 1822 | ShiftPrecedence, |
| 1823 | RelationalPrecedence, |
| 1824 | EquivalencyPrecedence, |
| 1825 | BitwiseAndPrecedence, |
| 1826 | BitwiseOrPrecedence, |
| 1827 | LogicalAndPrecedence, |
| 1828 | LogicalOrPrecedence, |
| 1829 | TernaryPrecedence, |
| 1830 | AssignmentPrecedence, |
| 1831 | CommaPrecedence, |
| 1832 | SeparatorPrecedence |
| 1833 | } FxPrecedence; |
| 1834 | |
| 1835 | FxPrecedence |
| 1836 | precedence, |
| 1837 | target; |
| 1838 | |
| 1839 | register const char |
| 1840 | *subexpression; |
| 1841 | |
| 1842 | register int |
| 1843 | c; |
| 1844 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1845 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1846 | level; |
| 1847 | |
| 1848 | c=0; |
| 1849 | level=0; |
| 1850 | subexpression=(const char *) NULL; |
| 1851 | target=NullPrecedence; |
| 1852 | while (*expression != '\0') |
| 1853 | { |
| 1854 | precedence=UndefinedPrecedence; |
| 1855 | if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@')) |
| 1856 | { |
| 1857 | expression++; |
| 1858 | continue; |
| 1859 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1860 | switch (*expression) |
| 1861 | { |
| 1862 | case 'A': |
| 1863 | case 'a': |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1864 | { |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1865 | #if defined(MAGICKCORE_HAVE_ACOSH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1866 | if (LocaleNCompare(expression,"acosh",5) == 0) |
| 1867 | { |
| 1868 | expression+=5; |
| 1869 | break; |
| 1870 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1871 | #endif |
| 1872 | #if defined(MAGICKCORE_HAVE_ASINH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1873 | if (LocaleNCompare(expression,"asinh",5) == 0) |
| 1874 | { |
| 1875 | expression+=5; |
| 1876 | break; |
| 1877 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1878 | #endif |
| 1879 | #if defined(MAGICKCORE_HAVE_ATANH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1880 | if (LocaleNCompare(expression,"atanh",5) == 0) |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1881 | { |
| 1882 | expression+=5; |
| 1883 | break; |
| 1884 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1885 | #endif |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1886 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1887 | } |
cristy | 62d455f | 2011-11-03 11:42:28 +0000 | [diff] [blame] | 1888 | case 'E': |
| 1889 | case 'e': |
| 1890 | { |
| 1891 | if ((LocaleNCompare(expression,"E+",2) == 0) || |
| 1892 | (LocaleNCompare(expression,"E-",2) == 0)) |
| 1893 | { |
| 1894 | expression+=2; /* scientific notation */ |
| 1895 | break; |
| 1896 | } |
| 1897 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1898 | case 'J': |
| 1899 | case 'j': |
| 1900 | { |
| 1901 | if ((LocaleNCompare(expression,"j0",2) == 0) || |
| 1902 | (LocaleNCompare(expression,"j1",2) == 0)) |
| 1903 | { |
| 1904 | expression+=2; |
| 1905 | break; |
| 1906 | } |
| 1907 | break; |
| 1908 | } |
cristy | 2def932 | 2010-06-18 23:59:37 +0000 | [diff] [blame] | 1909 | case '#': |
| 1910 | { |
| 1911 | while (isxdigit((int) ((unsigned char) *(expression+1))) != 0) |
| 1912 | expression++; |
| 1913 | break; |
| 1914 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1915 | default: |
| 1916 | break; |
| 1917 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1918 | if ((c == (int) '{') || (c == (int) '[')) |
| 1919 | level++; |
| 1920 | else |
| 1921 | if ((c == (int) '}') || (c == (int) ']')) |
| 1922 | level--; |
| 1923 | if (level == 0) |
| 1924 | switch ((unsigned char) *expression) |
| 1925 | { |
| 1926 | case '~': |
| 1927 | case '!': |
| 1928 | { |
| 1929 | precedence=BitwiseComplementPrecedence; |
| 1930 | break; |
| 1931 | } |
| 1932 | case '^': |
cristy | 6621e25 | 2010-08-13 00:42:57 +0000 | [diff] [blame] | 1933 | case '@': |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1934 | { |
| 1935 | precedence=ExponentPrecedence; |
| 1936 | break; |
| 1937 | } |
| 1938 | default: |
| 1939 | { |
| 1940 | if (((c != 0) && ((isdigit((int) ((char) c)) != 0) || |
| 1941 | (strchr(")",c) != (char *) NULL))) && |
| 1942 | (((islower((int) ((char) *expression)) != 0) || |
| 1943 | (strchr("(",(int) *expression) != (char *) NULL)) || |
| 1944 | ((isdigit((int) ((char) c)) == 0) && |
| 1945 | (isdigit((int) ((char) *expression)) != 0))) && |
| 1946 | (strchr("xy",(int) *expression) == (char *) NULL)) |
| 1947 | precedence=MultiplyPrecedence; |
| 1948 | break; |
| 1949 | } |
| 1950 | case '*': |
| 1951 | case '/': |
| 1952 | case '%': |
| 1953 | { |
| 1954 | precedence=MultiplyPrecedence; |
| 1955 | break; |
| 1956 | } |
| 1957 | case '+': |
| 1958 | case '-': |
| 1959 | { |
| 1960 | if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) || |
| 1961 | (isalpha(c) != 0)) |
| 1962 | precedence=AdditionPrecedence; |
| 1963 | break; |
| 1964 | } |
| 1965 | case LeftShiftOperator: |
| 1966 | case RightShiftOperator: |
| 1967 | { |
| 1968 | precedence=ShiftPrecedence; |
| 1969 | break; |
| 1970 | } |
| 1971 | case '<': |
| 1972 | case LessThanEqualOperator: |
| 1973 | case GreaterThanEqualOperator: |
| 1974 | case '>': |
| 1975 | { |
| 1976 | precedence=RelationalPrecedence; |
| 1977 | break; |
| 1978 | } |
| 1979 | case EqualOperator: |
| 1980 | case NotEqualOperator: |
| 1981 | { |
| 1982 | precedence=EquivalencyPrecedence; |
| 1983 | break; |
| 1984 | } |
| 1985 | case '&': |
| 1986 | { |
| 1987 | precedence=BitwiseAndPrecedence; |
| 1988 | break; |
| 1989 | } |
| 1990 | case '|': |
| 1991 | { |
| 1992 | precedence=BitwiseOrPrecedence; |
| 1993 | break; |
| 1994 | } |
| 1995 | case LogicalAndOperator: |
| 1996 | { |
| 1997 | precedence=LogicalAndPrecedence; |
| 1998 | break; |
| 1999 | } |
| 2000 | case LogicalOrOperator: |
| 2001 | { |
| 2002 | precedence=LogicalOrPrecedence; |
| 2003 | break; |
| 2004 | } |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 2005 | case ExponentialNotation: |
| 2006 | { |
| 2007 | precedence=ExponentialNotationPrecedence; |
| 2008 | break; |
| 2009 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2010 | case ':': |
| 2011 | case '?': |
| 2012 | { |
| 2013 | precedence=TernaryPrecedence; |
| 2014 | break; |
| 2015 | } |
| 2016 | case '=': |
| 2017 | { |
| 2018 | precedence=AssignmentPrecedence; |
| 2019 | break; |
| 2020 | } |
| 2021 | case ',': |
| 2022 | { |
| 2023 | precedence=CommaPrecedence; |
| 2024 | break; |
| 2025 | } |
| 2026 | case ';': |
| 2027 | { |
| 2028 | precedence=SeparatorPrecedence; |
| 2029 | break; |
| 2030 | } |
| 2031 | } |
| 2032 | if ((precedence == BitwiseComplementPrecedence) || |
| 2033 | (precedence == TernaryPrecedence) || |
| 2034 | (precedence == AssignmentPrecedence)) |
| 2035 | { |
| 2036 | if (precedence > target) |
| 2037 | { |
| 2038 | /* |
| 2039 | Right-to-left associativity. |
| 2040 | */ |
| 2041 | target=precedence; |
| 2042 | subexpression=expression; |
| 2043 | } |
| 2044 | } |
| 2045 | else |
| 2046 | if (precedence >= target) |
| 2047 | { |
| 2048 | /* |
| 2049 | Left-to-right associativity. |
| 2050 | */ |
| 2051 | target=precedence; |
| 2052 | subexpression=expression; |
| 2053 | } |
| 2054 | if (strchr("(",(int) *expression) != (char *) NULL) |
| 2055 | expression=FxSubexpression(expression,exception); |
| 2056 | c=(int) (*expression++); |
| 2057 | } |
| 2058 | return(subexpression); |
| 2059 | } |
| 2060 | |
| 2061 | static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2062 | const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | e85007d | 2010-06-06 22:51:36 +0000 | [diff] [blame] | 2063 | const char *expression,MagickRealType *beta,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2064 | { |
| 2065 | char |
| 2066 | *q, |
| 2067 | subexpression[MaxTextExtent]; |
| 2068 | |
| 2069 | MagickRealType |
| 2070 | alpha, |
| 2071 | gamma; |
| 2072 | |
| 2073 | register const char |
| 2074 | *p; |
| 2075 | |
| 2076 | *beta=0.0; |
| 2077 | if (exception->severity != UndefinedException) |
| 2078 | return(0.0); |
| 2079 | while (isspace((int) *expression) != 0) |
| 2080 | expression++; |
| 2081 | if (*expression == '\0') |
| 2082 | { |
| 2083 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 2084 | "MissingExpression","`%s'",expression); |
| 2085 | return(0.0); |
| 2086 | } |
cristy | 66322f0 | 2010-05-17 11:40:48 +0000 | [diff] [blame] | 2087 | *subexpression='\0'; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2088 | p=FxOperatorPrecedence(expression,exception); |
| 2089 | if (p != (const char *) NULL) |
| 2090 | { |
| 2091 | (void) CopyMagickString(subexpression,expression,(size_t) |
| 2092 | (p-expression+1)); |
| 2093 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta, |
| 2094 | exception); |
| 2095 | switch ((unsigned char) *p) |
| 2096 | { |
| 2097 | case '~': |
| 2098 | { |
| 2099 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2100 | *beta=(MagickRealType) (~(size_t) *beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2101 | return(*beta); |
| 2102 | } |
| 2103 | case '!': |
| 2104 | { |
| 2105 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2106 | return(*beta == 0.0 ? 1.0 : 0.0); |
| 2107 | } |
| 2108 | case '^': |
| 2109 | { |
| 2110 | *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info, |
| 2111 | channel,x,y,++p,beta,exception)); |
| 2112 | return(*beta); |
| 2113 | } |
| 2114 | case '*': |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 2115 | case ExponentialNotation: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2116 | { |
| 2117 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2118 | return(alpha*(*beta)); |
| 2119 | } |
| 2120 | case '/': |
| 2121 | { |
| 2122 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2123 | if (*beta == 0.0) |
| 2124 | { |
| 2125 | if (exception->severity == UndefinedException) |
| 2126 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2127 | OptionError,"DivideByZero","`%s'",expression); |
| 2128 | return(0.0); |
| 2129 | } |
| 2130 | return(alpha/(*beta)); |
| 2131 | } |
| 2132 | case '%': |
| 2133 | { |
| 2134 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2135 | *beta=fabs(floor(((double) *beta)+0.5)); |
| 2136 | if (*beta == 0.0) |
| 2137 | { |
| 2138 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2139 | OptionError,"DivideByZero","`%s'",expression); |
| 2140 | return(0.0); |
| 2141 | } |
| 2142 | return(fmod((double) alpha,(double) *beta)); |
| 2143 | } |
| 2144 | case '+': |
| 2145 | { |
| 2146 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2147 | return(alpha+(*beta)); |
| 2148 | } |
| 2149 | case '-': |
| 2150 | { |
| 2151 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2152 | return(alpha-(*beta)); |
| 2153 | } |
| 2154 | case LeftShiftOperator: |
| 2155 | { |
| 2156 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2157 | *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2158 | return(*beta); |
| 2159 | } |
| 2160 | case RightShiftOperator: |
| 2161 | { |
| 2162 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2163 | *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2164 | return(*beta); |
| 2165 | } |
| 2166 | case '<': |
| 2167 | { |
| 2168 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2169 | return(alpha < *beta ? 1.0 : 0.0); |
| 2170 | } |
| 2171 | case LessThanEqualOperator: |
| 2172 | { |
| 2173 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2174 | return(alpha <= *beta ? 1.0 : 0.0); |
| 2175 | } |
| 2176 | case '>': |
| 2177 | { |
| 2178 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2179 | return(alpha > *beta ? 1.0 : 0.0); |
| 2180 | } |
| 2181 | case GreaterThanEqualOperator: |
| 2182 | { |
| 2183 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2184 | return(alpha >= *beta ? 1.0 : 0.0); |
| 2185 | } |
| 2186 | case EqualOperator: |
| 2187 | { |
| 2188 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2189 | return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0); |
| 2190 | } |
| 2191 | case NotEqualOperator: |
| 2192 | { |
| 2193 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2194 | return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0); |
| 2195 | } |
| 2196 | case '&': |
| 2197 | { |
| 2198 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2199 | *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2200 | return(*beta); |
| 2201 | } |
| 2202 | case '|': |
| 2203 | { |
| 2204 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2205 | *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2206 | return(*beta); |
| 2207 | } |
| 2208 | case LogicalAndOperator: |
| 2209 | { |
| 2210 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2211 | *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0; |
| 2212 | return(*beta); |
| 2213 | } |
| 2214 | case LogicalOrOperator: |
| 2215 | { |
| 2216 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2217 | *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0; |
| 2218 | return(*beta); |
| 2219 | } |
| 2220 | case '?': |
| 2221 | { |
| 2222 | MagickRealType |
| 2223 | gamma; |
| 2224 | |
| 2225 | (void) CopyMagickString(subexpression,++p,MaxTextExtent); |
| 2226 | q=subexpression; |
| 2227 | p=StringToken(":",&q); |
| 2228 | if (q == (char *) NULL) |
| 2229 | { |
| 2230 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2231 | OptionError,"UnableToParseExpression","`%s'",subexpression); |
| 2232 | return(0.0); |
| 2233 | } |
| 2234 | if (fabs((double) alpha) > MagickEpsilon) |
| 2235 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception); |
| 2236 | else |
| 2237 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception); |
| 2238 | return(gamma); |
| 2239 | } |
| 2240 | case '=': |
| 2241 | { |
| 2242 | char |
| 2243 | numeric[MaxTextExtent]; |
| 2244 | |
| 2245 | q=subexpression; |
| 2246 | while (isalpha((int) ((unsigned char) *q)) != 0) |
| 2247 | q++; |
| 2248 | if (*q != '\0') |
| 2249 | { |
| 2250 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2251 | OptionError,"UnableToParseExpression","`%s'",subexpression); |
| 2252 | return(0.0); |
| 2253 | } |
| 2254 | ClearMagickException(exception); |
| 2255 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2256 | (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 2257 | *beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2258 | (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression); |
| 2259 | (void) AddValueToSplayTree(fx_info->symbols,ConstantString( |
| 2260 | subexpression),ConstantString(numeric)); |
| 2261 | return(*beta); |
| 2262 | } |
| 2263 | case ',': |
| 2264 | { |
| 2265 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2266 | return(alpha); |
| 2267 | } |
| 2268 | case ';': |
| 2269 | { |
| 2270 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2271 | return(*beta); |
| 2272 | } |
| 2273 | default: |
| 2274 | { |
| 2275 | gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta, |
| 2276 | exception); |
| 2277 | return(gamma); |
| 2278 | } |
| 2279 | } |
| 2280 | } |
| 2281 | if (strchr("(",(int) *expression) != (char *) NULL) |
| 2282 | { |
| 2283 | (void) CopyMagickString(subexpression,expression+1,MaxTextExtent); |
| 2284 | subexpression[strlen(subexpression)-1]='\0'; |
| 2285 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta, |
| 2286 | exception); |
| 2287 | return(gamma); |
| 2288 | } |
cristy | 8b8a3ae | 2010-10-23 18:49:46 +0000 | [diff] [blame] | 2289 | switch (*expression) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2290 | { |
| 2291 | case '+': |
| 2292 | { |
| 2293 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2294 | exception); |
| 2295 | return(1.0*gamma); |
| 2296 | } |
| 2297 | case '-': |
| 2298 | { |
| 2299 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2300 | exception); |
| 2301 | return(-1.0*gamma); |
| 2302 | } |
| 2303 | case '~': |
| 2304 | { |
| 2305 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2306 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2307 | return((MagickRealType) (~(size_t) (gamma+0.5))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2308 | } |
| 2309 | case 'A': |
| 2310 | case 'a': |
| 2311 | { |
| 2312 | if (LocaleNCompare(expression,"abs",3) == 0) |
| 2313 | { |
| 2314 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2315 | exception); |
| 2316 | return((MagickRealType) fabs((double) alpha)); |
| 2317 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2318 | #if defined(MAGICKCORE_HAVE_ACOSH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2319 | if (LocaleNCompare(expression,"acosh",5) == 0) |
| 2320 | { |
| 2321 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2322 | exception); |
| 2323 | return((MagickRealType) acosh((double) alpha)); |
| 2324 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2325 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2326 | if (LocaleNCompare(expression,"acos",4) == 0) |
| 2327 | { |
| 2328 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2329 | exception); |
| 2330 | return((MagickRealType) acos((double) alpha)); |
| 2331 | } |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2332 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2333 | if (LocaleNCompare(expression,"airy",4) == 0) |
| 2334 | { |
| 2335 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2336 | exception); |
| 2337 | if (alpha == 0.0) |
cristy | 2dd0322 | 2010-03-30 22:12:11 +0000 | [diff] [blame] | 2338 | return(1.0); |
| 2339 | gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha); |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2340 | return(gamma*gamma); |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2341 | } |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2342 | #endif |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2343 | #if defined(MAGICKCORE_HAVE_ASINH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2344 | if (LocaleNCompare(expression,"asinh",5) == 0) |
| 2345 | { |
| 2346 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2347 | exception); |
| 2348 | return((MagickRealType) asinh((double) alpha)); |
| 2349 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2350 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2351 | if (LocaleNCompare(expression,"asin",4) == 0) |
| 2352 | { |
| 2353 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2354 | exception); |
| 2355 | return((MagickRealType) asin((double) alpha)); |
| 2356 | } |
| 2357 | if (LocaleNCompare(expression,"alt",3) == 0) |
| 2358 | { |
| 2359 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2360 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2361 | return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2362 | } |
| 2363 | if (LocaleNCompare(expression,"atan2",5) == 0) |
| 2364 | { |
| 2365 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2366 | exception); |
| 2367 | return((MagickRealType) atan2((double) alpha,(double) *beta)); |
| 2368 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2369 | #if defined(MAGICKCORE_HAVE_ATANH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2370 | if (LocaleNCompare(expression,"atanh",5) == 0) |
| 2371 | { |
| 2372 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2373 | exception); |
| 2374 | return((MagickRealType) atanh((double) alpha)); |
| 2375 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2376 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2377 | if (LocaleNCompare(expression,"atan",4) == 0) |
| 2378 | { |
| 2379 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2380 | exception); |
| 2381 | return((MagickRealType) atan((double) alpha)); |
| 2382 | } |
| 2383 | if (LocaleCompare(expression,"a") == 0) |
| 2384 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2385 | break; |
| 2386 | } |
| 2387 | case 'B': |
| 2388 | case 'b': |
| 2389 | { |
| 2390 | if (LocaleCompare(expression,"b") == 0) |
| 2391 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2392 | break; |
| 2393 | } |
| 2394 | case 'C': |
| 2395 | case 'c': |
| 2396 | { |
| 2397 | if (LocaleNCompare(expression,"ceil",4) == 0) |
| 2398 | { |
| 2399 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2400 | exception); |
| 2401 | return((MagickRealType) ceil((double) alpha)); |
| 2402 | } |
| 2403 | if (LocaleNCompare(expression,"cosh",4) == 0) |
| 2404 | { |
| 2405 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2406 | exception); |
| 2407 | return((MagickRealType) cosh((double) alpha)); |
| 2408 | } |
| 2409 | if (LocaleNCompare(expression,"cos",3) == 0) |
| 2410 | { |
| 2411 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2412 | exception); |
| 2413 | return((MagickRealType) cos((double) alpha)); |
| 2414 | } |
| 2415 | if (LocaleCompare(expression,"c") == 0) |
| 2416 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2417 | break; |
| 2418 | } |
| 2419 | case 'D': |
| 2420 | case 'd': |
| 2421 | { |
| 2422 | if (LocaleNCompare(expression,"debug",5) == 0) |
| 2423 | { |
| 2424 | const char |
| 2425 | *type; |
| 2426 | |
| 2427 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2428 | exception); |
| 2429 | if (fx_info->images->colorspace == CMYKColorspace) |
| 2430 | switch (channel) |
| 2431 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2432 | case CyanPixelChannel: type="cyan"; break; |
| 2433 | case MagentaPixelChannel: type="magenta"; break; |
| 2434 | case YellowPixelChannel: type="yellow"; break; |
| 2435 | case AlphaPixelChannel: type="opacity"; break; |
| 2436 | case BlackPixelChannel: type="black"; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2437 | default: type="unknown"; break; |
| 2438 | } |
| 2439 | else |
| 2440 | switch (channel) |
| 2441 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2442 | case RedPixelChannel: type="red"; break; |
| 2443 | case GreenPixelChannel: type="green"; break; |
| 2444 | case BluePixelChannel: type="blue"; break; |
| 2445 | case AlphaPixelChannel: type="opacity"; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2446 | default: type="unknown"; break; |
| 2447 | } |
| 2448 | (void) CopyMagickString(subexpression,expression+6,MaxTextExtent); |
| 2449 | if (strlen(subexpression) > 1) |
| 2450 | subexpression[strlen(subexpression)-1]='\0'; |
| 2451 | if (fx_info->file != (FILE *) NULL) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2452 | (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: " |
| 2453 | "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type, |
| 2454 | subexpression,GetMagickPrecision(),(double) alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2455 | return(0.0); |
| 2456 | } |
cristy | 5597a8d | 2011-11-04 00:25:32 +0000 | [diff] [blame] | 2457 | if (LocaleNCompare(expression,"drc",3) == 0) |
| 2458 | { |
| 2459 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2460 | exception); |
| 2461 | return((MagickRealType) (alpha/(*beta*(alpha-1.0)+1.0))); |
| 2462 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2463 | break; |
| 2464 | } |
| 2465 | case 'E': |
| 2466 | case 'e': |
| 2467 | { |
| 2468 | if (LocaleCompare(expression,"epsilon") == 0) |
| 2469 | return((MagickRealType) MagickEpsilon); |
| 2470 | if (LocaleNCompare(expression,"exp",3) == 0) |
| 2471 | { |
| 2472 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2473 | exception); |
| 2474 | return((MagickRealType) exp((double) alpha)); |
| 2475 | } |
| 2476 | if (LocaleCompare(expression,"e") == 0) |
| 2477 | return((MagickRealType) 2.7182818284590452354); |
| 2478 | break; |
| 2479 | } |
| 2480 | case 'F': |
| 2481 | case 'f': |
| 2482 | { |
| 2483 | if (LocaleNCompare(expression,"floor",5) == 0) |
| 2484 | { |
| 2485 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2486 | exception); |
| 2487 | return((MagickRealType) floor((double) alpha)); |
| 2488 | } |
| 2489 | break; |
| 2490 | } |
| 2491 | case 'G': |
| 2492 | case 'g': |
| 2493 | { |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2494 | if (LocaleNCompare(expression,"gauss",5) == 0) |
| 2495 | { |
| 2496 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2497 | exception); |
| 2498 | gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI); |
| 2499 | return((MagickRealType) gamma); |
| 2500 | } |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 2501 | if (LocaleNCompare(expression,"gcd",3) == 0) |
| 2502 | { |
| 2503 | MagickOffsetType |
| 2504 | gcd; |
| 2505 | |
| 2506 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2507 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2508 | gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+ |
| 2509 | 0.5)); |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 2510 | return((MagickRealType) gcd); |
| 2511 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2512 | if (LocaleCompare(expression,"g") == 0) |
| 2513 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2514 | break; |
| 2515 | } |
| 2516 | case 'H': |
| 2517 | case 'h': |
| 2518 | { |
| 2519 | if (LocaleCompare(expression,"h") == 0) |
| 2520 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2521 | if (LocaleCompare(expression,"hue") == 0) |
| 2522 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2523 | if (LocaleNCompare(expression,"hypot",5) == 0) |
| 2524 | { |
| 2525 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2526 | exception); |
| 2527 | return((MagickRealType) hypot((double) alpha,(double) *beta)); |
| 2528 | } |
| 2529 | break; |
| 2530 | } |
| 2531 | case 'K': |
| 2532 | case 'k': |
| 2533 | { |
| 2534 | if (LocaleCompare(expression,"k") == 0) |
| 2535 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2536 | break; |
| 2537 | } |
| 2538 | case 'I': |
| 2539 | case 'i': |
| 2540 | { |
| 2541 | if (LocaleCompare(expression,"intensity") == 0) |
| 2542 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2543 | if (LocaleNCompare(expression,"int",3) == 0) |
| 2544 | { |
| 2545 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2546 | exception); |
cristy | 16788e4 | 2010-08-13 13:44:26 +0000 | [diff] [blame] | 2547 | return((MagickRealType) floor(alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2548 | } |
cristy | 82b2072 | 2011-11-05 21:52:36 +0000 | [diff] [blame] | 2549 | #if defined(MAGICKCORE_HAVE_ISNAN) |
cristy | 639399c | 2011-11-02 19:16:15 +0000 | [diff] [blame] | 2550 | if (LocaleNCompare(expression,"isnan",5) == 0) |
| 2551 | { |
| 2552 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2553 | exception); |
cristy | 17a1020 | 2011-11-02 19:17:04 +0000 | [diff] [blame] | 2554 | return((MagickRealType) !!isnan((double) alpha)); |
cristy | 639399c | 2011-11-02 19:16:15 +0000 | [diff] [blame] | 2555 | } |
cristy | 82b2072 | 2011-11-05 21:52:36 +0000 | [diff] [blame] | 2556 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2557 | if (LocaleCompare(expression,"i") == 0) |
| 2558 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2559 | break; |
| 2560 | } |
| 2561 | case 'J': |
| 2562 | case 'j': |
| 2563 | { |
| 2564 | if (LocaleCompare(expression,"j") == 0) |
| 2565 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2566 | #if defined(MAGICKCORE_HAVE_J0) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2567 | if (LocaleNCompare(expression,"j0",2) == 0) |
| 2568 | { |
| 2569 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2570 | exception); |
| 2571 | return((MagickRealType) j0((double) alpha)); |
| 2572 | } |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2573 | #endif |
| 2574 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2575 | if (LocaleNCompare(expression,"j1",2) == 0) |
| 2576 | { |
| 2577 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2578 | exception); |
| 2579 | return((MagickRealType) j1((double) alpha)); |
| 2580 | } |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2581 | #endif |
cristy | aa018fa | 2010-04-08 23:03:54 +0000 | [diff] [blame] | 2582 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2583 | if (LocaleNCompare(expression,"jinc",4) == 0) |
| 2584 | { |
| 2585 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2586 | exception); |
cristy | 0946a82 | 2010-03-12 17:14:58 +0000 | [diff] [blame] | 2587 | if (alpha == 0.0) |
| 2588 | return(1.0); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2589 | gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/(MagickPI* |
| 2590 | alpha)); |
cristy | fce2f7b | 2010-03-12 00:29:49 +0000 | [diff] [blame] | 2591 | return(gamma); |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2592 | } |
cristy | aa018fa | 2010-04-08 23:03:54 +0000 | [diff] [blame] | 2593 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2594 | break; |
| 2595 | } |
| 2596 | case 'L': |
| 2597 | case 'l': |
| 2598 | { |
| 2599 | if (LocaleNCompare(expression,"ln",2) == 0) |
| 2600 | { |
| 2601 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2602 | exception); |
| 2603 | return((MagickRealType) log((double) alpha)); |
| 2604 | } |
cristy | c8ed532 | 2010-08-31 12:07:59 +0000 | [diff] [blame] | 2605 | if (LocaleNCompare(expression,"logtwo",6) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2606 | { |
cristy | c8ed532 | 2010-08-31 12:07:59 +0000 | [diff] [blame] | 2607 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2608 | exception); |
| 2609 | return((MagickRealType) log10((double) alpha))/log10(2.0); |
| 2610 | } |
| 2611 | if (LocaleNCompare(expression,"log",3) == 0) |
| 2612 | { |
| 2613 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2614 | exception); |
| 2615 | return((MagickRealType) log10((double) alpha)); |
| 2616 | } |
| 2617 | if (LocaleCompare(expression,"lightness") == 0) |
| 2618 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2619 | break; |
| 2620 | } |
| 2621 | case 'M': |
| 2622 | case 'm': |
| 2623 | { |
| 2624 | if (LocaleCompare(expression,"MaxRGB") == 0) |
| 2625 | return((MagickRealType) QuantumRange); |
| 2626 | if (LocaleNCompare(expression,"maxima",6) == 0) |
| 2627 | break; |
| 2628 | if (LocaleNCompare(expression,"max",3) == 0) |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2629 | { |
| 2630 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2631 | exception); |
| 2632 | return(alpha > *beta ? alpha : *beta); |
| 2633 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2634 | if (LocaleNCompare(expression,"minima",6) == 0) |
| 2635 | break; |
| 2636 | if (LocaleNCompare(expression,"min",3) == 0) |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2637 | { |
| 2638 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2639 | exception); |
| 2640 | return(alpha < *beta ? alpha : *beta); |
| 2641 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2642 | if (LocaleNCompare(expression,"mod",3) == 0) |
| 2643 | { |
| 2644 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2645 | exception); |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2646 | gamma=alpha-floor((double) (alpha/(*beta)))*(*beta); |
| 2647 | return(gamma); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2648 | } |
| 2649 | if (LocaleCompare(expression,"m") == 0) |
| 2650 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2651 | break; |
| 2652 | } |
| 2653 | case 'N': |
| 2654 | case 'n': |
| 2655 | { |
cristy | ad3502e | 2011-11-02 19:10:45 +0000 | [diff] [blame] | 2656 | if (LocaleNCompare(expression,"not",3) == 0) |
| 2657 | { |
| 2658 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2659 | exception); |
| 2660 | return((MagickRealType) (alpha < MagickEpsilon)); |
| 2661 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2662 | if (LocaleCompare(expression,"n") == 0) |
| 2663 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2664 | break; |
| 2665 | } |
| 2666 | case 'O': |
| 2667 | case 'o': |
| 2668 | { |
| 2669 | if (LocaleCompare(expression,"Opaque") == 0) |
| 2670 | return(1.0); |
| 2671 | if (LocaleCompare(expression,"o") == 0) |
| 2672 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2673 | break; |
| 2674 | } |
| 2675 | case 'P': |
| 2676 | case 'p': |
| 2677 | { |
cristy | 670aa3c | 2011-11-03 00:54:00 +0000 | [diff] [blame] | 2678 | if (LocaleCompare(expression,"phi") == 0) |
| 2679 | return((MagickRealType) MagickPHI); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2680 | if (LocaleCompare(expression,"pi") == 0) |
| 2681 | return((MagickRealType) MagickPI); |
| 2682 | if (LocaleNCompare(expression,"pow",3) == 0) |
| 2683 | { |
| 2684 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2685 | exception); |
| 2686 | return((MagickRealType) pow((double) alpha,(double) *beta)); |
| 2687 | } |
| 2688 | if (LocaleCompare(expression,"p") == 0) |
| 2689 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2690 | break; |
| 2691 | } |
| 2692 | case 'Q': |
| 2693 | case 'q': |
| 2694 | { |
| 2695 | if (LocaleCompare(expression,"QuantumRange") == 0) |
| 2696 | return((MagickRealType) QuantumRange); |
| 2697 | if (LocaleCompare(expression,"QuantumScale") == 0) |
| 2698 | return((MagickRealType) QuantumScale); |
| 2699 | break; |
| 2700 | } |
| 2701 | case 'R': |
| 2702 | case 'r': |
| 2703 | { |
| 2704 | if (LocaleNCompare(expression,"rand",4) == 0) |
| 2705 | return((MagickRealType) GetPseudoRandomValue(fx_info->random_info)); |
| 2706 | if (LocaleNCompare(expression,"round",5) == 0) |
| 2707 | { |
| 2708 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2709 | exception); |
cristy | 16788e4 | 2010-08-13 13:44:26 +0000 | [diff] [blame] | 2710 | return((MagickRealType) floor((double) alpha+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2711 | } |
| 2712 | if (LocaleCompare(expression,"r") == 0) |
| 2713 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2714 | break; |
| 2715 | } |
| 2716 | case 'S': |
| 2717 | case 's': |
| 2718 | { |
| 2719 | if (LocaleCompare(expression,"saturation") == 0) |
| 2720 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2721 | if (LocaleNCompare(expression,"sign",4) == 0) |
| 2722 | { |
| 2723 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2724 | exception); |
| 2725 | return(alpha < 0.0 ? -1.0 : 1.0); |
| 2726 | } |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2727 | if (LocaleNCompare(expression,"sinc",4) == 0) |
| 2728 | { |
| 2729 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2730 | exception); |
| 2731 | if (alpha == 0) |
| 2732 | return(1.0); |
| 2733 | gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/ |
| 2734 | (MagickPI*alpha)); |
| 2735 | return(gamma); |
| 2736 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2737 | if (LocaleNCompare(expression,"sinh",4) == 0) |
| 2738 | { |
| 2739 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2740 | exception); |
| 2741 | return((MagickRealType) sinh((double) alpha)); |
| 2742 | } |
| 2743 | if (LocaleNCompare(expression,"sin",3) == 0) |
| 2744 | { |
| 2745 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2746 | exception); |
| 2747 | return((MagickRealType) sin((double) alpha)); |
| 2748 | } |
| 2749 | if (LocaleNCompare(expression,"sqrt",4) == 0) |
| 2750 | { |
| 2751 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2752 | exception); |
| 2753 | return((MagickRealType) sqrt((double) alpha)); |
| 2754 | } |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2755 | if (LocaleNCompare(expression,"squish",6) == 0) |
| 2756 | { |
| 2757 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta, |
| 2758 | exception); |
| 2759 | return((MagickRealType) (1.0/(1.0+exp((double) (4.0*alpha))))); |
| 2760 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2761 | if (LocaleCompare(expression,"s") == 0) |
| 2762 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2763 | break; |
| 2764 | } |
| 2765 | case 'T': |
| 2766 | case 't': |
| 2767 | { |
| 2768 | if (LocaleNCompare(expression,"tanh",4) == 0) |
| 2769 | { |
| 2770 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2771 | exception); |
| 2772 | return((MagickRealType) tanh((double) alpha)); |
| 2773 | } |
| 2774 | if (LocaleNCompare(expression,"tan",3) == 0) |
| 2775 | { |
| 2776 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2777 | exception); |
| 2778 | return((MagickRealType) tan((double) alpha)); |
| 2779 | } |
| 2780 | if (LocaleCompare(expression,"Transparent") == 0) |
| 2781 | return(0.0); |
cristy | 16788e4 | 2010-08-13 13:44:26 +0000 | [diff] [blame] | 2782 | if (LocaleNCompare(expression,"trunc",5) == 0) |
| 2783 | { |
| 2784 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2785 | exception); |
| 2786 | if (alpha >= 0.0) |
| 2787 | return((MagickRealType) floor((double) alpha)); |
| 2788 | return((MagickRealType) ceil((double) alpha)); |
| 2789 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2790 | if (LocaleCompare(expression,"t") == 0) |
| 2791 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2792 | break; |
| 2793 | } |
| 2794 | case 'U': |
| 2795 | case 'u': |
| 2796 | { |
| 2797 | if (LocaleCompare(expression,"u") == 0) |
| 2798 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2799 | break; |
| 2800 | } |
| 2801 | case 'V': |
| 2802 | case 'v': |
| 2803 | { |
| 2804 | if (LocaleCompare(expression,"v") == 0) |
| 2805 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2806 | break; |
| 2807 | } |
| 2808 | case 'W': |
| 2809 | case 'w': |
| 2810 | { |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2811 | if (LocaleNCompare(expression,"while",5) == 0) |
| 2812 | { |
| 2813 | do |
| 2814 | { |
| 2815 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2816 | exception); |
| 2817 | } while (fabs((double) alpha) >= MagickEpsilon); |
| 2818 | return((MagickRealType) *beta); |
| 2819 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2820 | if (LocaleCompare(expression,"w") == 0) |
| 2821 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2822 | break; |
| 2823 | } |
| 2824 | case 'Y': |
| 2825 | case 'y': |
| 2826 | { |
| 2827 | if (LocaleCompare(expression,"y") == 0) |
| 2828 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2829 | break; |
| 2830 | } |
| 2831 | case 'Z': |
| 2832 | case 'z': |
| 2833 | { |
| 2834 | if (LocaleCompare(expression,"z") == 0) |
| 2835 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2836 | break; |
| 2837 | } |
| 2838 | default: |
| 2839 | break; |
| 2840 | } |
| 2841 | q=(char *) expression; |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2842 | alpha=InterpretSiPrefixValue(expression,&q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2843 | if (q == expression) |
| 2844 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2845 | return(alpha); |
| 2846 | } |
| 2847 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 2848 | MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2849 | MagickRealType *alpha,ExceptionInfo *exception) |
| 2850 | { |
| 2851 | MagickBooleanType |
| 2852 | status; |
| 2853 | |
cristy | 541ae57 | 2011-08-05 19:08:59 +0000 | [diff] [blame] | 2854 | status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha, |
| 2855 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2856 | return(status); |
| 2857 | } |
| 2858 | |
| 2859 | MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info, |
| 2860 | MagickRealType *alpha,ExceptionInfo *exception) |
| 2861 | { |
| 2862 | FILE |
| 2863 | *file; |
| 2864 | |
| 2865 | MagickBooleanType |
| 2866 | status; |
| 2867 | |
| 2868 | file=fx_info->file; |
| 2869 | fx_info->file=(FILE *) NULL; |
cristy | 541ae57 | 2011-08-05 19:08:59 +0000 | [diff] [blame] | 2870 | status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha, |
| 2871 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2872 | fx_info->file=file; |
| 2873 | return(status); |
| 2874 | } |
| 2875 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 2876 | MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2877 | const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | e85007d | 2010-06-06 22:51:36 +0000 | [diff] [blame] | 2878 | MagickRealType *alpha,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2879 | { |
| 2880 | MagickRealType |
| 2881 | beta; |
| 2882 | |
| 2883 | beta=0.0; |
| 2884 | *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta, |
| 2885 | exception); |
| 2886 | return(exception->severity == OptionError ? MagickFalse : MagickTrue); |
| 2887 | } |
| 2888 | |
| 2889 | /* |
| 2890 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2891 | % % |
| 2892 | % % |
| 2893 | % % |
| 2894 | % F x I m a g e % |
| 2895 | % % |
| 2896 | % % |
| 2897 | % % |
| 2898 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2899 | % |
| 2900 | % FxImage() applies a mathematical expression to the specified image. |
| 2901 | % |
| 2902 | % The format of the FxImage method is: |
| 2903 | % |
| 2904 | % Image *FxImage(const Image *image,const char *expression, |
| 2905 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2906 | % |
| 2907 | % A description of each parameter follows: |
| 2908 | % |
| 2909 | % o image: the image. |
| 2910 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2911 | % o expression: A mathematical expression. |
| 2912 | % |
| 2913 | % o exception: return any errors or warnings in this structure. |
| 2914 | % |
| 2915 | */ |
| 2916 | |
| 2917 | static FxInfo **DestroyFxThreadSet(FxInfo **fx_info) |
| 2918 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2919 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2920 | i; |
| 2921 | |
| 2922 | assert(fx_info != (FxInfo **) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2923 | for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2924 | if (fx_info[i] != (FxInfo *) NULL) |
| 2925 | fx_info[i]=DestroyFxInfo(fx_info[i]); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 2926 | fx_info=(FxInfo **) RelinquishMagickMemory(fx_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2927 | return(fx_info); |
| 2928 | } |
| 2929 | |
| 2930 | static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression, |
| 2931 | ExceptionInfo *exception) |
| 2932 | { |
| 2933 | char |
| 2934 | *fx_expression; |
| 2935 | |
| 2936 | FxInfo |
| 2937 | **fx_info; |
| 2938 | |
| 2939 | MagickRealType |
| 2940 | alpha; |
| 2941 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2942 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2943 | i; |
| 2944 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2945 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2946 | number_threads; |
| 2947 | |
| 2948 | number_threads=GetOpenMPMaximumThreads(); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 2949 | fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2950 | if (fx_info == (FxInfo **) NULL) |
| 2951 | return((FxInfo **) NULL); |
| 2952 | (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info)); |
| 2953 | if (*expression != '@') |
| 2954 | fx_expression=ConstantString(expression); |
| 2955 | else |
| 2956 | fx_expression=FileToString(expression+1,~0,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2957 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2958 | { |
| 2959 | fx_info[i]=AcquireFxInfo(image,fx_expression); |
| 2960 | if (fx_info[i] == (FxInfo *) NULL) |
| 2961 | return(DestroyFxThreadSet(fx_info)); |
| 2962 | (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception); |
| 2963 | } |
| 2964 | fx_expression=DestroyString(fx_expression); |
| 2965 | return(fx_info); |
| 2966 | } |
| 2967 | |
| 2968 | MagickExport Image *FxImage(const Image *image,const char *expression, |
| 2969 | ExceptionInfo *exception) |
| 2970 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2971 | #define FxImageTag "Fx/Image" |
| 2972 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 2973 | CacheView |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 2974 | *fx_view, |
| 2975 | *image_view; |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 2976 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2977 | FxInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 2978 | **restrict fx_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2979 | |
| 2980 | Image |
| 2981 | *fx_image; |
| 2982 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2983 | MagickBooleanType |
| 2984 | status; |
| 2985 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2986 | MagickOffsetType |
| 2987 | progress; |
| 2988 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2989 | MagickRealType |
| 2990 | alpha; |
| 2991 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2992 | ssize_t |
| 2993 | y; |
| 2994 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2995 | assert(image != (Image *) NULL); |
| 2996 | assert(image->signature == MagickSignature); |
| 2997 | if (image->debug != MagickFalse) |
| 2998 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 2999 | fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3000 | if (fx_image == (Image *) NULL) |
| 3001 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 3002 | if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3003 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3004 | fx_image=DestroyImage(fx_image); |
| 3005 | return((Image *) NULL); |
| 3006 | } |
| 3007 | fx_info=AcquireFxThreadSet(image,expression,exception); |
| 3008 | if (fx_info == (FxInfo **) NULL) |
| 3009 | { |
| 3010 | fx_image=DestroyImage(fx_image); |
| 3011 | ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); |
| 3012 | } |
| 3013 | status=FxPreprocessExpression(fx_info[0],&alpha,exception); |
| 3014 | if (status == MagickFalse) |
| 3015 | { |
| 3016 | fx_image=DestroyImage(fx_image); |
| 3017 | fx_info=DestroyFxThreadSet(fx_info); |
| 3018 | return((Image *) NULL); |
| 3019 | } |
| 3020 | /* |
| 3021 | Fx image. |
| 3022 | */ |
| 3023 | status=MagickTrue; |
| 3024 | progress=0; |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3025 | image_view=AcquireCacheView(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3026 | fx_view=AcquireCacheView(fx_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3027 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 3028 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3029 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3030 | for (y=0; y < (ssize_t) fx_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3031 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3032 | const int |
| 3033 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3034 | |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3035 | register const Quantum |
| 3036 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3037 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3038 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3039 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3040 | |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3041 | register ssize_t |
| 3042 | x; |
| 3043 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3044 | if (status == MagickFalse) |
| 3045 | continue; |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3046 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3047 | q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3048 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3049 | { |
| 3050 | status=MagickFalse; |
| 3051 | continue; |
| 3052 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3053 | for (x=0; x < (ssize_t) fx_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3054 | { |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3055 | register ssize_t |
| 3056 | i; |
| 3057 | |
| 3058 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3059 | { |
| 3060 | MagickRealType |
| 3061 | alpha; |
| 3062 | |
| 3063 | PixelChannel |
| 3064 | channel; |
| 3065 | |
| 3066 | PixelTrait |
| 3067 | fx_traits, |
| 3068 | traits; |
| 3069 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3070 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 3071 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3072 | fx_traits=GetPixelChannelMapTraits(fx_image,channel); |
cristy | 010d7d1 | 2011-08-31 01:02:48 +0000 | [diff] [blame] | 3073 | if ((traits == UndefinedPixelTrait) || |
| 3074 | (fx_traits == UndefinedPixelTrait)) |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3075 | continue; |
cristy | d09f880 | 2012-02-04 16:44:10 +0000 | [diff] [blame] | 3076 | if (((fx_traits & CopyPixelTrait) != 0) || |
| 3077 | (GetPixelMask(image,p) != 0)) |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3078 | { |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 3079 | SetPixelChannel(fx_image,channel,p[i],q); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3080 | continue; |
| 3081 | } |
| 3082 | alpha=0.0; |
cristy | a382aca | 2011-12-06 18:22:48 +0000 | [diff] [blame] | 3083 | (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha, |
| 3084 | exception); |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 3085 | q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3086 | } |
| 3087 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3088 | q+=GetPixelChannels(fx_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3089 | } |
| 3090 | if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse) |
| 3091 | status=MagickFalse; |
| 3092 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3093 | { |
| 3094 | MagickBooleanType |
| 3095 | proceed; |
| 3096 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3097 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3098 | #pragma omp critical (MagickCore_FxImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3099 | #endif |
| 3100 | proceed=SetImageProgress(image,FxImageTag,progress++,image->rows); |
| 3101 | if (proceed == MagickFalse) |
| 3102 | status=MagickFalse; |
| 3103 | } |
| 3104 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3105 | fx_view=DestroyCacheView(fx_view); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3106 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3107 | fx_info=DestroyFxThreadSet(fx_info); |
| 3108 | if (status == MagickFalse) |
| 3109 | fx_image=DestroyImage(fx_image); |
| 3110 | return(fx_image); |
| 3111 | } |
| 3112 | |
| 3113 | /* |
| 3114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3115 | % % |
| 3116 | % % |
| 3117 | % % |
| 3118 | % I m p l o d e I m a g e % |
| 3119 | % % |
| 3120 | % % |
| 3121 | % % |
| 3122 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3123 | % |
| 3124 | % ImplodeImage() creates a new image that is a copy of an existing |
| 3125 | % one with the image pixels "implode" by the specified percentage. It |
| 3126 | % allocates the memory necessary for the new Image structure and returns a |
| 3127 | % pointer to the new image. |
| 3128 | % |
| 3129 | % The format of the ImplodeImage method is: |
| 3130 | % |
| 3131 | % Image *ImplodeImage(const Image *image,const double amount, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3132 | % const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3133 | % |
| 3134 | % A description of each parameter follows: |
| 3135 | % |
| 3136 | % o implode_image: Method ImplodeImage returns a pointer to the image |
| 3137 | % after it is implode. A null image is returned if there is a memory |
| 3138 | % shortage. |
| 3139 | % |
| 3140 | % o image: the image. |
| 3141 | % |
| 3142 | % o amount: Define the extent of the implosion. |
| 3143 | % |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3144 | % o method: the pixel interpolation method. |
| 3145 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3146 | % o exception: return any errors or warnings in this structure. |
| 3147 | % |
| 3148 | */ |
| 3149 | MagickExport Image *ImplodeImage(const Image *image,const double amount, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3150 | const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3151 | { |
| 3152 | #define ImplodeImageTag "Implode/Image" |
| 3153 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3154 | CacheView |
| 3155 | *image_view, |
| 3156 | *implode_view; |
| 3157 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3158 | Image |
| 3159 | *implode_image; |
| 3160 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3161 | MagickBooleanType |
| 3162 | status; |
| 3163 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3164 | MagickOffsetType |
| 3165 | progress; |
| 3166 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3167 | MagickRealType |
| 3168 | radius; |
| 3169 | |
| 3170 | PointInfo |
| 3171 | center, |
| 3172 | scale; |
| 3173 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3174 | ssize_t |
| 3175 | y; |
| 3176 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3177 | /* |
| 3178 | Initialize implode image attributes. |
| 3179 | */ |
| 3180 | assert(image != (Image *) NULL); |
| 3181 | assert(image->signature == MagickSignature); |
| 3182 | if (image->debug != MagickFalse) |
| 3183 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3184 | assert(exception != (ExceptionInfo *) NULL); |
| 3185 | assert(exception->signature == MagickSignature); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3186 | implode_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
| 3187 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3188 | if (implode_image == (Image *) NULL) |
| 3189 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 3190 | if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3191 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3192 | implode_image=DestroyImage(implode_image); |
| 3193 | return((Image *) NULL); |
| 3194 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3195 | if (implode_image->background_color.alpha != OpaqueAlpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3196 | implode_image->matte=MagickTrue; |
| 3197 | /* |
| 3198 | Compute scaling factor. |
| 3199 | */ |
| 3200 | scale.x=1.0; |
| 3201 | scale.y=1.0; |
| 3202 | center.x=0.5*image->columns; |
| 3203 | center.y=0.5*image->rows; |
| 3204 | radius=center.x; |
| 3205 | if (image->columns > image->rows) |
| 3206 | scale.y=(double) image->columns/(double) image->rows; |
| 3207 | else |
| 3208 | if (image->columns < image->rows) |
| 3209 | { |
| 3210 | scale.x=(double) image->rows/(double) image->columns; |
| 3211 | radius=center.y; |
| 3212 | } |
| 3213 | /* |
| 3214 | Implode image. |
| 3215 | */ |
| 3216 | status=MagickTrue; |
| 3217 | progress=0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3218 | image_view=AcquireCacheView(image); |
| 3219 | implode_view=AcquireCacheView(implode_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3220 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 3221 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3222 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3223 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3224 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3225 | MagickRealType |
| 3226 | distance; |
| 3227 | |
| 3228 | PointInfo |
| 3229 | delta; |
| 3230 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3231 | register const Quantum |
| 3232 | *restrict p; |
| 3233 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3234 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3235 | x; |
| 3236 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3237 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3238 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3239 | |
| 3240 | if (status == MagickFalse) |
| 3241 | continue; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3242 | p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3243 | q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3244 | exception); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3245 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3246 | { |
| 3247 | status=MagickFalse; |
| 3248 | continue; |
| 3249 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3250 | delta.y=scale.y*(double) (y-center.y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3251 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3252 | { |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3253 | register ssize_t |
| 3254 | i; |
| 3255 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3256 | /* |
| 3257 | Determine if the pixel is within an ellipse. |
| 3258 | */ |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 3259 | if (GetPixelMask(image,p) != 0) |
| 3260 | { |
| 3261 | p+=GetPixelChannels(image); |
| 3262 | q+=GetPixelChannels(implode_image); |
| 3263 | continue; |
| 3264 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3265 | delta.x=scale.x*(double) (x-center.x); |
| 3266 | distance=delta.x*delta.x+delta.y*delta.y; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3267 | if (distance >= (radius*radius)) |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3268 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3269 | { |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3270 | PixelChannel |
| 3271 | channel; |
| 3272 | |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3273 | PixelTrait |
| 3274 | implode_traits, |
| 3275 | traits; |
| 3276 | |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3277 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3278 | traits=GetPixelChannelMapTraits(image,channel); |
| 3279 | implode_traits=GetPixelChannelMapTraits(implode_image,channel); |
| 3280 | if ((traits == UndefinedPixelTrait) || |
| 3281 | (implode_traits == UndefinedPixelTrait)) |
| 3282 | continue; |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3283 | SetPixelChannel(implode_image,channel,p[i],q); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3284 | } |
| 3285 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3286 | { |
| 3287 | double |
| 3288 | factor; |
| 3289 | |
| 3290 | /* |
| 3291 | Implode the pixel. |
| 3292 | */ |
| 3293 | factor=1.0; |
| 3294 | if (distance > 0.0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3295 | factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/ |
| 3296 | 2)),-amount); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3297 | status=InterpolatePixelChannels(image,image_view,implode_image,method, |
| 3298 | (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/ |
| 3299 | scale.y+center.y),q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3300 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3301 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3302 | q+=GetPixelChannels(implode_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3303 | } |
| 3304 | if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse) |
| 3305 | status=MagickFalse; |
| 3306 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3307 | { |
| 3308 | MagickBooleanType |
| 3309 | proceed; |
| 3310 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3311 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3312 | #pragma omp critical (MagickCore_ImplodeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3313 | #endif |
| 3314 | proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows); |
| 3315 | if (proceed == MagickFalse) |
| 3316 | status=MagickFalse; |
| 3317 | } |
| 3318 | } |
| 3319 | implode_view=DestroyCacheView(implode_view); |
| 3320 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3321 | if (status == MagickFalse) |
| 3322 | implode_image=DestroyImage(implode_image); |
| 3323 | return(implode_image); |
| 3324 | } |
| 3325 | |
| 3326 | /* |
| 3327 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3328 | % % |
| 3329 | % % |
| 3330 | % % |
| 3331 | % M o r p h I m a g e s % |
| 3332 | % % |
| 3333 | % % |
| 3334 | % % |
| 3335 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3336 | % |
| 3337 | % The MorphImages() method requires a minimum of two images. The first |
| 3338 | % image is transformed into the second by a number of intervening images |
| 3339 | % as specified by frames. |
| 3340 | % |
| 3341 | % The format of the MorphImage method is: |
| 3342 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3343 | % Image *MorphImages(const Image *image,const size_t number_frames, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3344 | % ExceptionInfo *exception) |
| 3345 | % |
| 3346 | % A description of each parameter follows: |
| 3347 | % |
| 3348 | % o image: the image. |
| 3349 | % |
| 3350 | % o number_frames: Define the number of in-between image to generate. |
| 3351 | % The more in-between frames, the smoother the morph. |
| 3352 | % |
| 3353 | % o exception: return any errors or warnings in this structure. |
| 3354 | % |
| 3355 | */ |
| 3356 | MagickExport Image *MorphImages(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3357 | const size_t number_frames,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3358 | { |
| 3359 | #define MorphImageTag "Morph/Image" |
| 3360 | |
| 3361 | Image |
| 3362 | *morph_image, |
| 3363 | *morph_images; |
| 3364 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3365 | MagickBooleanType |
| 3366 | status; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3367 | |
| 3368 | MagickOffsetType |
| 3369 | scene; |
| 3370 | |
| 3371 | MagickRealType |
| 3372 | alpha, |
| 3373 | beta; |
| 3374 | |
| 3375 | register const Image |
| 3376 | *next; |
| 3377 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3378 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3379 | i; |
| 3380 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3381 | ssize_t |
| 3382 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3383 | |
| 3384 | /* |
| 3385 | Clone first frame in sequence. |
| 3386 | */ |
| 3387 | assert(image != (Image *) NULL); |
| 3388 | assert(image->signature == MagickSignature); |
| 3389 | if (image->debug != MagickFalse) |
| 3390 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3391 | assert(exception != (ExceptionInfo *) NULL); |
| 3392 | assert(exception->signature == MagickSignature); |
| 3393 | morph_images=CloneImage(image,0,0,MagickTrue,exception); |
| 3394 | if (morph_images == (Image *) NULL) |
| 3395 | return((Image *) NULL); |
| 3396 | if (GetNextImageInList(image) == (Image *) NULL) |
| 3397 | { |
| 3398 | /* |
| 3399 | Morph single image. |
| 3400 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3401 | for (i=1; i < (ssize_t) number_frames; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3402 | { |
| 3403 | morph_image=CloneImage(image,0,0,MagickTrue,exception); |
| 3404 | if (morph_image == (Image *) NULL) |
| 3405 | { |
| 3406 | morph_images=DestroyImageList(morph_images); |
| 3407 | return((Image *) NULL); |
| 3408 | } |
| 3409 | AppendImageToList(&morph_images,morph_image); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3410 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3411 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3412 | MagickBooleanType |
| 3413 | proceed; |
| 3414 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3415 | proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i, |
| 3416 | number_frames); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3417 | if (proceed == MagickFalse) |
| 3418 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3419 | } |
| 3420 | } |
| 3421 | return(GetFirstImageInList(morph_images)); |
| 3422 | } |
| 3423 | /* |
| 3424 | Morph image sequence. |
| 3425 | */ |
| 3426 | status=MagickTrue; |
| 3427 | scene=0; |
| 3428 | next=image; |
| 3429 | for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next)) |
| 3430 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3431 | for (i=0; i < (ssize_t) number_frames; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3432 | { |
| 3433 | CacheView |
| 3434 | *image_view, |
| 3435 | *morph_view; |
| 3436 | |
| 3437 | beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0); |
| 3438 | alpha=1.0-beta; |
cristy | 15b98cd | 2010-09-12 19:42:50 +0000 | [diff] [blame] | 3439 | morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta* |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 3440 | GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta* |
| 3441 | GetNextImageInList(next)->rows+0.5),next->filter,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3442 | if (morph_image == (Image *) NULL) |
| 3443 | { |
| 3444 | morph_images=DestroyImageList(morph_images); |
| 3445 | return((Image *) NULL); |
| 3446 | } |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3447 | status=SetImageStorageClass(morph_image,DirectClass,exception); |
| 3448 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3449 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3450 | morph_image=DestroyImage(morph_image); |
| 3451 | return((Image *) NULL); |
| 3452 | } |
| 3453 | AppendImageToList(&morph_images,morph_image); |
| 3454 | morph_images=GetLastImageInList(morph_images); |
cristy | 15b98cd | 2010-09-12 19:42:50 +0000 | [diff] [blame] | 3455 | morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 3456 | morph_images->rows,GetNextImageInList(next)->filter,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3457 | if (morph_image == (Image *) NULL) |
| 3458 | { |
| 3459 | morph_images=DestroyImageList(morph_images); |
| 3460 | return((Image *) NULL); |
| 3461 | } |
| 3462 | image_view=AcquireCacheView(morph_image); |
| 3463 | morph_view=AcquireCacheView(morph_images); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3464 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 3465 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3466 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3467 | for (y=0; y < (ssize_t) morph_images->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3468 | { |
| 3469 | MagickBooleanType |
| 3470 | sync; |
| 3471 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3472 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3473 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3474 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3475 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3476 | x; |
| 3477 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3478 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3479 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3480 | |
| 3481 | if (status == MagickFalse) |
| 3482 | continue; |
| 3483 | p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1, |
| 3484 | exception); |
| 3485 | q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1, |
| 3486 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3487 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3488 | { |
| 3489 | status=MagickFalse; |
| 3490 | continue; |
| 3491 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3492 | for (x=0; x < (ssize_t) morph_images->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3493 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3494 | register ssize_t |
| 3495 | i; |
| 3496 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 3497 | for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3498 | { |
| 3499 | PixelChannel |
| 3500 | channel; |
| 3501 | |
| 3502 | PixelTrait |
| 3503 | morph_traits, |
| 3504 | traits; |
| 3505 | |
| 3506 | channel=GetPixelChannelMapChannel(image,i); |
| 3507 | traits=GetPixelChannelMapTraits(image,channel); |
| 3508 | morph_traits=GetPixelChannelMapTraits(morph_image,channel); |
| 3509 | if ((traits == UndefinedPixelTrait) || |
| 3510 | (morph_traits == UndefinedPixelTrait)) |
| 3511 | continue; |
cristy | d09f880 | 2012-02-04 16:44:10 +0000 | [diff] [blame] | 3512 | if (((morph_traits & CopyPixelTrait) != 0) || |
| 3513 | (GetPixelMask(image,p) != 0)) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3514 | { |
| 3515 | SetPixelChannel(morph_image,channel,p[i],q); |
| 3516 | continue; |
| 3517 | } |
| 3518 | SetPixelChannel(morph_image,channel,ClampToQuantum(alpha* |
| 3519 | GetPixelChannel(morph_images,channel,q)+beta*p[i]),q); |
| 3520 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3521 | p+=GetPixelChannels(morph_image); |
| 3522 | q+=GetPixelChannels(morph_images); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3523 | } |
| 3524 | sync=SyncCacheViewAuthenticPixels(morph_view,exception); |
| 3525 | if (sync == MagickFalse) |
| 3526 | status=MagickFalse; |
| 3527 | } |
| 3528 | morph_view=DestroyCacheView(morph_view); |
| 3529 | image_view=DestroyCacheView(image_view); |
| 3530 | morph_image=DestroyImage(morph_image); |
| 3531 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3532 | if (i < (ssize_t) number_frames) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3533 | break; |
| 3534 | /* |
| 3535 | Clone last frame in sequence. |
| 3536 | */ |
| 3537 | morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception); |
| 3538 | if (morph_image == (Image *) NULL) |
| 3539 | { |
| 3540 | morph_images=DestroyImageList(morph_images); |
| 3541 | return((Image *) NULL); |
| 3542 | } |
| 3543 | AppendImageToList(&morph_images,morph_image); |
| 3544 | morph_images=GetLastImageInList(morph_images); |
| 3545 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3546 | { |
| 3547 | MagickBooleanType |
| 3548 | proceed; |
| 3549 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3550 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3551 | #pragma omp critical (MagickCore_MorphImages) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3552 | #endif |
| 3553 | proceed=SetImageProgress(image,MorphImageTag,scene, |
| 3554 | GetImageListLength(image)); |
| 3555 | if (proceed == MagickFalse) |
| 3556 | status=MagickFalse; |
| 3557 | } |
| 3558 | scene++; |
| 3559 | } |
| 3560 | if (GetNextImageInList(next) != (Image *) NULL) |
| 3561 | { |
| 3562 | morph_images=DestroyImageList(morph_images); |
| 3563 | return((Image *) NULL); |
| 3564 | } |
| 3565 | return(GetFirstImageInList(morph_images)); |
| 3566 | } |
| 3567 | |
| 3568 | /* |
| 3569 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3570 | % % |
| 3571 | % % |
| 3572 | % % |
| 3573 | % P l a s m a I m a g e % |
| 3574 | % % |
| 3575 | % % |
| 3576 | % % |
| 3577 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3578 | % |
| 3579 | % PlasmaImage() initializes an image with plasma fractal values. The image |
| 3580 | % must be initialized with a base color and the random number generator |
| 3581 | % seeded before this method is called. |
| 3582 | % |
| 3583 | % The format of the PlasmaImage method is: |
| 3584 | % |
| 3585 | % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3586 | % size_t attenuate,size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3587 | % |
| 3588 | % A description of each parameter follows: |
| 3589 | % |
| 3590 | % o image: the image. |
| 3591 | % |
| 3592 | % o segment: Define the region to apply plasma fractals values. |
| 3593 | % |
glennrp | 7dae1ca | 2010-09-16 12:17:35 +0000 | [diff] [blame] | 3594 | % o attenuate: Define the plasma attenuation factor. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3595 | % |
| 3596 | % o depth: Limit the plasma recursion depth. |
| 3597 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3598 | % o exception: return any errors or warnings in this structure. |
| 3599 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3600 | */ |
| 3601 | |
| 3602 | static inline Quantum PlasmaPixel(RandomInfo *random_info, |
| 3603 | const MagickRealType pixel,const MagickRealType noise) |
| 3604 | { |
| 3605 | Quantum |
| 3606 | plasma; |
| 3607 | |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 3608 | plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3609 | noise/2.0); |
| 3610 | return(plasma); |
| 3611 | } |
| 3612 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3613 | static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view, |
| 3614 | CacheView *u_view,CacheView *v_view,RandomInfo *random_info, |
| 3615 | const SegmentInfo *segment,size_t attenuate,size_t depth, |
| 3616 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3617 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3618 | MagickRealType |
| 3619 | plasma; |
| 3620 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3621 | PixelChannel |
| 3622 | channel; |
| 3623 | |
| 3624 | PixelTrait |
| 3625 | traits; |
| 3626 | |
| 3627 | register const Quantum |
| 3628 | *restrict u, |
| 3629 | *restrict v; |
| 3630 | |
| 3631 | register Quantum |
| 3632 | *restrict q; |
| 3633 | |
| 3634 | register ssize_t |
| 3635 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3636 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3637 | ssize_t |
| 3638 | x, |
| 3639 | x_mid, |
| 3640 | y, |
| 3641 | y_mid; |
| 3642 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3643 | if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0)) |
| 3644 | return(MagickTrue); |
| 3645 | if (depth != 0) |
| 3646 | { |
| 3647 | SegmentInfo |
| 3648 | local_info; |
| 3649 | |
| 3650 | /* |
| 3651 | Divide the area into quadrants and recurse. |
| 3652 | */ |
| 3653 | depth--; |
| 3654 | attenuate++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3655 | x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5); |
| 3656 | y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3657 | local_info=(*segment); |
| 3658 | local_info.x2=(double) x_mid; |
| 3659 | local_info.y2=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3660 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3661 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3662 | local_info=(*segment); |
| 3663 | local_info.y1=(double) y_mid; |
| 3664 | local_info.x2=(double) x_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3665 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3666 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3667 | local_info=(*segment); |
| 3668 | local_info.x1=(double) x_mid; |
| 3669 | local_info.y2=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3670 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3671 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3672 | local_info=(*segment); |
| 3673 | local_info.x1=(double) x_mid; |
| 3674 | local_info.y1=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3675 | return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3676 | &local_info,attenuate,depth,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3677 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3678 | x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5); |
| 3679 | y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3680 | if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) && |
| 3681 | (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid)) |
| 3682 | return(MagickFalse); |
| 3683 | /* |
| 3684 | Average pixels and apply plasma. |
| 3685 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3686 | plasma=(MagickRealType) QuantumRange/(2.0*attenuate); |
| 3687 | if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid)) |
| 3688 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3689 | /* |
| 3690 | Left pixel. |
| 3691 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3692 | x=(ssize_t) ceil(segment->x1-0.5); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3693 | u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1, |
| 3694 | exception); |
| 3695 | v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1, |
| 3696 | exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3697 | q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3698 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3699 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3700 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3701 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3702 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3703 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 3704 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3705 | if (traits == UndefinedPixelTrait) |
| 3706 | continue; |
| 3707 | q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma); |
| 3708 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3709 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3710 | if (segment->x1 != segment->x2) |
| 3711 | { |
| 3712 | /* |
| 3713 | Right pixel. |
| 3714 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3715 | x=(ssize_t) ceil(segment->x2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3716 | u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5), |
| 3717 | 1,1,exception); |
| 3718 | v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5), |
| 3719 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3720 | q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3721 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3722 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3723 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3724 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3725 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3726 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 3727 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3728 | if (traits == UndefinedPixelTrait) |
| 3729 | continue; |
| 3730 | q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma); |
| 3731 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3732 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3733 | } |
| 3734 | } |
| 3735 | if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid)) |
| 3736 | { |
| 3737 | if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid)) |
| 3738 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3739 | /* |
| 3740 | Bottom pixel. |
| 3741 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3742 | y=(ssize_t) ceil(segment->y2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3743 | u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y, |
| 3744 | 1,1,exception); |
| 3745 | v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y, |
| 3746 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3747 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3748 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3749 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3750 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3751 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3752 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3753 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 3754 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3755 | if (traits == UndefinedPixelTrait) |
| 3756 | continue; |
| 3757 | q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma); |
| 3758 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3759 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3760 | } |
| 3761 | if (segment->y1 != segment->y2) |
| 3762 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3763 | /* |
| 3764 | Top pixel. |
| 3765 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3766 | y=(ssize_t) ceil(segment->y1-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3767 | u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y, |
| 3768 | 1,1,exception); |
| 3769 | v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y, |
| 3770 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3771 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3772 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3773 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3774 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3775 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3776 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3777 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 3778 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3779 | if (traits == UndefinedPixelTrait) |
| 3780 | continue; |
| 3781 | q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma); |
| 3782 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3783 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3784 | } |
| 3785 | } |
| 3786 | if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2)) |
| 3787 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3788 | /* |
| 3789 | Middle pixel. |
| 3790 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3791 | x=(ssize_t) ceil(segment->x1-0.5); |
| 3792 | y=(ssize_t) ceil(segment->y1-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3793 | u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3794 | x=(ssize_t) ceil(segment->x2-0.5); |
| 3795 | y=(ssize_t) ceil(segment->y2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3796 | v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3797 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3798 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3799 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3800 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3801 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3802 | { |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 3803 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 3804 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3805 | if (traits == UndefinedPixelTrait) |
| 3806 | continue; |
| 3807 | q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma); |
| 3808 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3809 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3810 | } |
| 3811 | if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0)) |
| 3812 | return(MagickTrue); |
| 3813 | return(MagickFalse); |
| 3814 | } |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3815 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3816 | MagickExport MagickBooleanType PlasmaImage(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3817 | const SegmentInfo *segment,size_t attenuate,size_t depth, |
| 3818 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3819 | { |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3820 | CacheView |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3821 | *image_view, |
| 3822 | *u_view, |
| 3823 | *v_view; |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3824 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3825 | MagickBooleanType |
| 3826 | status; |
| 3827 | |
| 3828 | RandomInfo |
| 3829 | *random_info; |
| 3830 | |
| 3831 | if (image->debug != MagickFalse) |
| 3832 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3833 | assert(image != (Image *) NULL); |
| 3834 | assert(image->signature == MagickSignature); |
| 3835 | if (image->debug != MagickFalse) |
| 3836 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3837 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3838 | return(MagickFalse); |
| 3839 | image_view=AcquireCacheView(image); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3840 | u_view=AcquireCacheView(image); |
| 3841 | v_view=AcquireCacheView(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3842 | random_info=AcquireRandomInfo(); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3843 | status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment, |
| 3844 | attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3845 | random_info=DestroyRandomInfo(random_info); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3846 | v_view=DestroyCacheView(v_view); |
| 3847 | u_view=DestroyCacheView(u_view); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3848 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3849 | return(status); |
| 3850 | } |
| 3851 | |
| 3852 | /* |
| 3853 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3854 | % % |
| 3855 | % % |
| 3856 | % % |
| 3857 | % P o l a r o i d I m a g e % |
| 3858 | % % |
| 3859 | % % |
| 3860 | % % |
| 3861 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3862 | % |
| 3863 | % PolaroidImage() simulates a Polaroid picture. |
| 3864 | % |
| 3865 | % The format of the AnnotateImage method is: |
| 3866 | % |
| 3867 | % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3868 | % const char *caption,const double angle, |
| 3869 | % const PixelInterpolateMethod method,ExceptionInfo exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3870 | % |
| 3871 | % A description of each parameter follows: |
| 3872 | % |
| 3873 | % o image: the image. |
| 3874 | % |
| 3875 | % o draw_info: the draw info. |
| 3876 | % |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3877 | % o caption: the Polaroid caption. |
| 3878 | % |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 3879 | % o angle: Apply the effect along this angle. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3880 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3881 | % o method: the pixel interpolation method. |
| 3882 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3883 | % o exception: return any errors or warnings in this structure. |
| 3884 | % |
| 3885 | */ |
| 3886 | MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3887 | const char *caption,const double angle,const PixelInterpolateMethod method, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3888 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3889 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3890 | Image |
| 3891 | *bend_image, |
| 3892 | *caption_image, |
| 3893 | *flop_image, |
| 3894 | *picture_image, |
| 3895 | *polaroid_image, |
| 3896 | *rotate_image, |
| 3897 | *trim_image; |
| 3898 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3899 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3900 | height; |
| 3901 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3902 | ssize_t |
| 3903 | quantum; |
| 3904 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3905 | /* |
| 3906 | Simulate a Polaroid picture. |
| 3907 | */ |
| 3908 | assert(image != (Image *) NULL); |
| 3909 | assert(image->signature == MagickSignature); |
| 3910 | if (image->debug != MagickFalse) |
| 3911 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3912 | assert(exception != (ExceptionInfo *) NULL); |
| 3913 | assert(exception->signature == MagickSignature); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3914 | quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3915 | image->rows)/25.0,10.0); |
| 3916 | height=image->rows+2*quantum; |
| 3917 | caption_image=(Image *) NULL; |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3918 | if (caption != (const char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3919 | { |
| 3920 | char |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3921 | geometry[MaxTextExtent], |
| 3922 | *text; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3923 | |
| 3924 | DrawInfo |
| 3925 | *annotate_info; |
| 3926 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3927 | MagickBooleanType |
| 3928 | status; |
| 3929 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3930 | ssize_t |
| 3931 | count; |
| 3932 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3933 | TypeMetric |
| 3934 | metrics; |
| 3935 | |
| 3936 | /* |
| 3937 | Generate caption image. |
| 3938 | */ |
| 3939 | caption_image=CloneImage(image,image->columns,1,MagickTrue,exception); |
| 3940 | if (caption_image == (Image *) NULL) |
| 3941 | return((Image *) NULL); |
| 3942 | annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3943 | text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption, |
| 3944 | exception); |
| 3945 | (void) CloneString(&annotate_info->text,text); |
cristy | 6b1d05e | 2010-09-22 19:17:27 +0000 | [diff] [blame] | 3946 | count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3947 | &text,exception); |
| 3948 | status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)* |
| 3949 | (metrics.ascent-metrics.descent)+0.5),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3950 | if (status == MagickFalse) |
| 3951 | caption_image=DestroyImage(caption_image); |
| 3952 | else |
| 3953 | { |
| 3954 | caption_image->background_color=image->border_color; |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3955 | (void) SetImageBackgroundColor(caption_image,exception); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3956 | (void) CloneString(&annotate_info->text,text); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3957 | (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3958 | metrics.ascent); |
| 3959 | if (annotate_info->gravity == UndefinedGravity) |
| 3960 | (void) CloneString(&annotate_info->geometry,AcquireString( |
| 3961 | geometry)); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3962 | (void) AnnotateImage(caption_image,annotate_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3963 | height+=caption_image->rows; |
| 3964 | } |
| 3965 | annotate_info=DestroyDrawInfo(annotate_info); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3966 | text=DestroyString(text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3967 | } |
| 3968 | picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue, |
| 3969 | exception); |
| 3970 | if (picture_image == (Image *) NULL) |
| 3971 | { |
| 3972 | if (caption_image != (Image *) NULL) |
| 3973 | caption_image=DestroyImage(caption_image); |
| 3974 | return((Image *) NULL); |
| 3975 | } |
| 3976 | picture_image->background_color=image->border_color; |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3977 | (void) SetImageBackgroundColor(picture_image,exception); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 3978 | (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 3979 | quantum,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3980 | if (caption_image != (Image *) NULL) |
| 3981 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 3982 | (void) CompositeImage(picture_image,caption_image,OverCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 3983 | MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3984 | caption_image=DestroyImage(caption_image); |
| 3985 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 3986 | (void) QueryColorCompliance("none",AllCompliance, |
| 3987 | &picture_image->background_color,exception); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3988 | (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3989 | rotate_image=RotateImage(picture_image,90.0,exception); |
| 3990 | picture_image=DestroyImage(picture_image); |
| 3991 | if (rotate_image == (Image *) NULL) |
| 3992 | return((Image *) NULL); |
| 3993 | picture_image=rotate_image; |
| 3994 | bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0* |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3995 | picture_image->columns,method,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3996 | picture_image=DestroyImage(picture_image); |
| 3997 | if (bend_image == (Image *) NULL) |
| 3998 | return((Image *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3999 | picture_image=bend_image; |
| 4000 | rotate_image=RotateImage(picture_image,-90.0,exception); |
| 4001 | picture_image=DestroyImage(picture_image); |
| 4002 | if (rotate_image == (Image *) NULL) |
| 4003 | return((Image *) NULL); |
| 4004 | picture_image=rotate_image; |
| 4005 | picture_image->background_color=image->background_color; |
anthony | f46d426 | 2012-03-26 03:30:34 +0000 | [diff] [blame] | 4006 | polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4007 | exception); |
| 4008 | if (polaroid_image == (Image *) NULL) |
| 4009 | { |
| 4010 | picture_image=DestroyImage(picture_image); |
| 4011 | return(picture_image); |
| 4012 | } |
| 4013 | flop_image=FlopImage(polaroid_image,exception); |
| 4014 | polaroid_image=DestroyImage(polaroid_image); |
| 4015 | if (flop_image == (Image *) NULL) |
| 4016 | { |
| 4017 | picture_image=DestroyImage(picture_image); |
| 4018 | return(picture_image); |
| 4019 | } |
| 4020 | polaroid_image=flop_image; |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4021 | (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4022 | MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4023 | picture_image=DestroyImage(picture_image); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4024 | (void) QueryColorCompliance("none",AllCompliance, |
| 4025 | &polaroid_image->background_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4026 | rotate_image=RotateImage(polaroid_image,angle,exception); |
| 4027 | polaroid_image=DestroyImage(polaroid_image); |
| 4028 | if (rotate_image == (Image *) NULL) |
| 4029 | return((Image *) NULL); |
| 4030 | polaroid_image=rotate_image; |
| 4031 | trim_image=TrimImage(polaroid_image,exception); |
| 4032 | polaroid_image=DestroyImage(polaroid_image); |
| 4033 | if (trim_image == (Image *) NULL) |
| 4034 | return((Image *) NULL); |
| 4035 | polaroid_image=trim_image; |
| 4036 | return(polaroid_image); |
| 4037 | } |
| 4038 | |
| 4039 | /* |
| 4040 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4041 | % % |
| 4042 | % % |
| 4043 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4044 | % S e p i a T o n e I m a g e % |
| 4045 | % % |
| 4046 | % % |
| 4047 | % % |
| 4048 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4049 | % |
| 4050 | % MagickSepiaToneImage() applies a special effect to the image, similar to the |
| 4051 | % effect achieved in a photo darkroom by sepia toning. Threshold ranges from |
| 4052 | % 0 to QuantumRange and is a measure of the extent of the sepia toning. A |
| 4053 | % threshold of 80% is a good starting point for a reasonable tone. |
| 4054 | % |
| 4055 | % The format of the SepiaToneImage method is: |
| 4056 | % |
| 4057 | % Image *SepiaToneImage(const Image *image,const double threshold, |
| 4058 | % ExceptionInfo *exception) |
| 4059 | % |
| 4060 | % A description of each parameter follows: |
| 4061 | % |
| 4062 | % o image: the image. |
| 4063 | % |
| 4064 | % o threshold: the tone threshold. |
| 4065 | % |
| 4066 | % o exception: return any errors or warnings in this structure. |
| 4067 | % |
| 4068 | */ |
| 4069 | MagickExport Image *SepiaToneImage(const Image *image,const double threshold, |
| 4070 | ExceptionInfo *exception) |
| 4071 | { |
| 4072 | #define SepiaToneImageTag "SepiaTone/Image" |
| 4073 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4074 | CacheView |
| 4075 | *image_view, |
| 4076 | *sepia_view; |
| 4077 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4078 | Image |
| 4079 | *sepia_image; |
| 4080 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4081 | MagickBooleanType |
| 4082 | status; |
| 4083 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4084 | MagickOffsetType |
| 4085 | progress; |
| 4086 | |
| 4087 | ssize_t |
| 4088 | y; |
| 4089 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4090 | /* |
| 4091 | Initialize sepia-toned image attributes. |
| 4092 | */ |
| 4093 | assert(image != (const Image *) NULL); |
| 4094 | assert(image->signature == MagickSignature); |
| 4095 | if (image->debug != MagickFalse) |
| 4096 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4097 | assert(exception != (ExceptionInfo *) NULL); |
| 4098 | assert(exception->signature == MagickSignature); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4099 | sepia_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4100 | if (sepia_image == (Image *) NULL) |
| 4101 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4102 | if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4103 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4104 | sepia_image=DestroyImage(sepia_image); |
| 4105 | return((Image *) NULL); |
| 4106 | } |
| 4107 | /* |
| 4108 | Tone each row of the image. |
| 4109 | */ |
| 4110 | status=MagickTrue; |
| 4111 | progress=0; |
| 4112 | image_view=AcquireCacheView(image); |
| 4113 | sepia_view=AcquireCacheView(sepia_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4114 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 4115 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4116 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4117 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4118 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4119 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4120 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4121 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4122 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4123 | x; |
| 4124 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4125 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4126 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4127 | |
| 4128 | if (status == MagickFalse) |
| 4129 | continue; |
| 4130 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4131 | q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4132 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4133 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4134 | { |
| 4135 | status=MagickFalse; |
| 4136 | continue; |
| 4137 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4138 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4139 | { |
| 4140 | MagickRealType |
| 4141 | intensity, |
| 4142 | tone; |
| 4143 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4144 | intensity=(MagickRealType) GetPixelIntensity(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4145 | tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+ |
| 4146 | (MagickRealType) QuantumRange-threshold; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4147 | SetPixelRed(sepia_image,ClampToQuantum(tone),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4148 | tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange : |
| 4149 | intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4150 | SetPixelGreen(sepia_image,ClampToQuantum(tone),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4151 | tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4152 | SetPixelBlue(sepia_image,ClampToQuantum(tone),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4153 | tone=threshold/7.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4154 | if ((MagickRealType) GetPixelGreen(image,q) < tone) |
| 4155 | SetPixelGreen(sepia_image,ClampToQuantum(tone),q); |
| 4156 | if ((MagickRealType) GetPixelBlue(image,q) < tone) |
| 4157 | SetPixelBlue(sepia_image,ClampToQuantum(tone),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4158 | p+=GetPixelChannels(image); |
| 4159 | q+=GetPixelChannels(sepia_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4160 | } |
| 4161 | if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse) |
| 4162 | status=MagickFalse; |
| 4163 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 4164 | { |
| 4165 | MagickBooleanType |
| 4166 | proceed; |
| 4167 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4168 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 4169 | #pragma omp critical (MagickCore_SepiaToneImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4170 | #endif |
| 4171 | proceed=SetImageProgress(image,SepiaToneImageTag,progress++, |
| 4172 | image->rows); |
| 4173 | if (proceed == MagickFalse) |
| 4174 | status=MagickFalse; |
| 4175 | } |
| 4176 | } |
| 4177 | sepia_view=DestroyCacheView(sepia_view); |
| 4178 | image_view=DestroyCacheView(image_view); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 4179 | (void) NormalizeImage(sepia_image,exception); |
| 4180 | (void) ContrastImage(sepia_image,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4181 | if (status == MagickFalse) |
| 4182 | sepia_image=DestroyImage(sepia_image); |
| 4183 | return(sepia_image); |
| 4184 | } |
| 4185 | |
| 4186 | /* |
| 4187 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4188 | % % |
| 4189 | % % |
| 4190 | % % |
| 4191 | % S h a d o w I m a g e % |
| 4192 | % % |
| 4193 | % % |
| 4194 | % % |
| 4195 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4196 | % |
| 4197 | % ShadowImage() simulates a shadow from the specified image and returns it. |
| 4198 | % |
| 4199 | % The format of the ShadowImage method is: |
| 4200 | % |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4201 | % Image *ShadowImage(const Image *image,const double alpha, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4202 | % const double sigma,const ssize_t x_offset,const ssize_t y_offset, |
| 4203 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4204 | % |
| 4205 | % A description of each parameter follows: |
| 4206 | % |
| 4207 | % o image: the image. |
| 4208 | % |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4209 | % o alpha: percentage transparency. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4210 | % |
| 4211 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 4212 | % |
| 4213 | % o x_offset: the shadow x-offset. |
| 4214 | % |
| 4215 | % o y_offset: the shadow y-offset. |
| 4216 | % |
| 4217 | % o exception: return any errors or warnings in this structure. |
| 4218 | % |
| 4219 | */ |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4220 | MagickExport Image *ShadowImage(const Image *image,const double alpha, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4221 | const double sigma,const ssize_t x_offset,const ssize_t y_offset, |
| 4222 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4223 | { |
| 4224 | #define ShadowImageTag "Shadow/Image" |
| 4225 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4226 | CacheView |
| 4227 | *image_view; |
| 4228 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4229 | ChannelType |
| 4230 | channel_mask; |
| 4231 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4232 | Image |
| 4233 | *border_image, |
| 4234 | *clone_image, |
| 4235 | *shadow_image; |
| 4236 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4237 | MagickBooleanType |
| 4238 | status; |
| 4239 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4240 | RectangleInfo |
| 4241 | border_info; |
| 4242 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4243 | ssize_t |
| 4244 | y; |
| 4245 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4246 | assert(image != (Image *) NULL); |
| 4247 | assert(image->signature == MagickSignature); |
| 4248 | if (image->debug != MagickFalse) |
| 4249 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4250 | assert(exception != (ExceptionInfo *) NULL); |
| 4251 | assert(exception->signature == MagickSignature); |
| 4252 | clone_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4253 | if (clone_image == (Image *) NULL) |
| 4254 | return((Image *) NULL); |
cristy | 0898eba | 2012-04-09 16:38:29 +0000 | [diff] [blame] | 4255 | if (IsGrayColorspace(image->colorspace) != MagickFalse) |
| 4256 | (void) TransformImageColorspace(clone_image,sRGBColorspace,exception); |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4257 | (void) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod, |
| 4258 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4259 | border_info.width=(size_t) floor(2.0*sigma+0.5); |
| 4260 | border_info.height=(size_t) floor(2.0*sigma+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4261 | border_info.x=0; |
| 4262 | border_info.y=0; |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4263 | (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color, |
| 4264 | exception); |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4265 | clone_image->matte=MagickTrue; |
| 4266 | border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4267 | clone_image=DestroyImage(clone_image); |
| 4268 | if (border_image == (Image *) NULL) |
| 4269 | return((Image *) NULL); |
| 4270 | if (border_image->matte == MagickFalse) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4271 | (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4272 | /* |
| 4273 | Shadow image. |
| 4274 | */ |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4275 | status=MagickTrue; |
| 4276 | image_view=AcquireCacheView(border_image); |
| 4277 | for (y=0; y < (ssize_t) border_image->rows; y++) |
| 4278 | { |
| 4279 | PixelInfo |
| 4280 | background_color; |
| 4281 | |
| 4282 | register Quantum |
| 4283 | *restrict q; |
| 4284 | |
| 4285 | register ssize_t |
| 4286 | x; |
| 4287 | |
| 4288 | if (status == MagickFalse) |
| 4289 | continue; |
| 4290 | q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1, |
| 4291 | exception); |
| 4292 | if (q == (Quantum *) NULL) |
| 4293 | { |
| 4294 | status=MagickFalse; |
| 4295 | continue; |
| 4296 | } |
| 4297 | background_color=border_image->background_color; |
| 4298 | background_color.matte=MagickTrue; |
| 4299 | for (x=0; x < (ssize_t) border_image->columns; x++) |
| 4300 | { |
| 4301 | if (border_image->matte != MagickFalse) |
| 4302 | background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0; |
| 4303 | SetPixelInfoPixel(border_image,&background_color,q); |
| 4304 | q+=GetPixelChannels(border_image); |
| 4305 | } |
| 4306 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 4307 | status=MagickFalse; |
| 4308 | } |
| 4309 | image_view=DestroyCacheView(image_view); |
| 4310 | if (status == MagickFalse) |
| 4311 | { |
| 4312 | border_image=DestroyImage(border_image); |
| 4313 | return((Image *) NULL); |
| 4314 | } |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4315 | channel_mask=SetPixelChannelMask(border_image,AlphaChannel); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4316 | shadow_image=BlurImage(border_image,0.0,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4317 | border_image=DestroyImage(border_image); |
| 4318 | if (shadow_image == (Image *) NULL) |
| 4319 | return((Image *) NULL); |
cristy | ae1969f | 2011-12-10 03:07:36 +0000 | [diff] [blame] | 4320 | (void) SetPixelChannelMapMask(shadow_image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4321 | if (shadow_image->page.width == 0) |
| 4322 | shadow_image->page.width=shadow_image->columns; |
| 4323 | if (shadow_image->page.height == 0) |
| 4324 | shadow_image->page.height=shadow_image->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4325 | shadow_image->page.width+=x_offset-(ssize_t) border_info.width; |
| 4326 | shadow_image->page.height+=y_offset-(ssize_t) border_info.height; |
| 4327 | shadow_image->page.x+=x_offset-(ssize_t) border_info.width; |
| 4328 | shadow_image->page.y+=y_offset-(ssize_t) border_info.height; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4329 | return(shadow_image); |
| 4330 | } |
| 4331 | |
| 4332 | /* |
| 4333 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4334 | % % |
| 4335 | % % |
| 4336 | % % |
| 4337 | % S k e t c h I m a g e % |
| 4338 | % % |
| 4339 | % % |
| 4340 | % % |
| 4341 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4342 | % |
| 4343 | % SketchImage() simulates a pencil sketch. We convolve the image with a |
| 4344 | % Gaussian operator of the given radius and standard deviation (sigma). For |
| 4345 | % reasonable results, radius should be larger than sigma. Use a radius of 0 |
| 4346 | % and SketchImage() selects a suitable radius for you. Angle gives the angle |
| 4347 | % of the sketch. |
| 4348 | % |
| 4349 | % The format of the SketchImage method is: |
| 4350 | % |
| 4351 | % Image *SketchImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4352 | % const double sigma,const double angle,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4353 | % |
| 4354 | % A description of each parameter follows: |
| 4355 | % |
| 4356 | % o image: the image. |
| 4357 | % |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4358 | % o radius: the radius of the Gaussian, in pixels, not counting the |
| 4359 | % center pixel. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4360 | % |
| 4361 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 4362 | % |
cristy | f7ef025 | 2011-09-09 14:50:06 +0000 | [diff] [blame] | 4363 | % o angle: apply the effect along this angle. |
| 4364 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4365 | % o exception: return any errors or warnings in this structure. |
| 4366 | % |
| 4367 | */ |
| 4368 | MagickExport Image *SketchImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4369 | const double sigma,const double angle,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4370 | { |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 4371 | CacheView |
| 4372 | *random_view; |
| 4373 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4374 | Image |
| 4375 | *blend_image, |
| 4376 | *blur_image, |
| 4377 | *dodge_image, |
| 4378 | *random_image, |
| 4379 | *sketch_image; |
| 4380 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4381 | MagickBooleanType |
| 4382 | status; |
| 4383 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4384 | RandomInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 4385 | **restrict random_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4386 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 4387 | ssize_t |
| 4388 | y; |
| 4389 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4390 | /* |
| 4391 | Sketch image. |
| 4392 | */ |
| 4393 | random_image=CloneImage(image,image->columns << 1,image->rows << 1, |
| 4394 | MagickTrue,exception); |
| 4395 | if (random_image == (Image *) NULL) |
| 4396 | return((Image *) NULL); |
| 4397 | status=MagickTrue; |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4398 | random_info=AcquireRandomInfoThreadSet(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4399 | random_view=AcquireCacheView(random_image); |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4400 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 4401 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4402 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4403 | for (y=0; y < (ssize_t) random_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4404 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 4405 | const int |
| 4406 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 4407 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4408 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4409 | x; |
| 4410 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4411 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4412 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4413 | |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4414 | if (status == MagickFalse) |
| 4415 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4416 | q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1, |
| 4417 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4418 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4419 | { |
| 4420 | status=MagickFalse; |
| 4421 | continue; |
| 4422 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4423 | for (x=0; x < (ssize_t) random_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4424 | { |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4425 | MagickRealType |
| 4426 | value; |
| 4427 | |
| 4428 | register ssize_t |
| 4429 | i; |
| 4430 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 4431 | if (GetPixelMask(random_image,q) != 0) |
| 4432 | { |
| 4433 | q+=GetPixelChannels(random_image); |
| 4434 | continue; |
| 4435 | } |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4436 | value=GetPseudoRandomValue(random_info[id]); |
| 4437 | for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++) |
| 4438 | { |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4439 | PixelChannel |
| 4440 | channel; |
| 4441 | |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4442 | PixelTrait |
| 4443 | traits; |
| 4444 | |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4445 | channel=GetPixelChannelMapChannel(image,i); |
| 4446 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4447 | if (traits == UndefinedPixelTrait) |
| 4448 | continue; |
| 4449 | q[i]=ClampToQuantum(QuantumRange*value); |
| 4450 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4451 | q+=GetPixelChannels(random_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4452 | } |
| 4453 | if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse) |
| 4454 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4455 | } |
| 4456 | random_view=DestroyCacheView(random_view); |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4457 | random_info=DestroyRandomInfoThreadSet(random_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4458 | if (status == MagickFalse) |
| 4459 | { |
| 4460 | random_image=DestroyImage(random_image); |
| 4461 | return(random_image); |
| 4462 | } |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4463 | blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4464 | random_image=DestroyImage(random_image); |
| 4465 | if (blur_image == (Image *) NULL) |
| 4466 | return((Image *) NULL); |
cristy | 6bfd690 | 2011-12-09 01:33:45 +0000 | [diff] [blame] | 4467 | dodge_image=EdgeImage(blur_image,radius,1.0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4468 | blur_image=DestroyImage(blur_image); |
| 4469 | if (dodge_image == (Image *) NULL) |
| 4470 | return((Image *) NULL); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 4471 | (void) NormalizeImage(dodge_image,exception); |
cristy | b3e7c6c | 2011-07-24 01:43:55 +0000 | [diff] [blame] | 4472 | (void) NegateImage(dodge_image,MagickFalse,exception); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4473 | (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4474 | 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 | } |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4480 | (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4481 | MagickTrue,0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4482 | 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"); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4490 | (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4491 | 0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4492 | 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 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4514 | % MagickBooleanType SolarizeImage(Image *image,const double threshold, |
| 4515 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4516 | % |
| 4517 | % A description of each parameter follows: |
| 4518 | % |
| 4519 | % o image: the image. |
| 4520 | % |
| 4521 | % o threshold: Define the extent of the solarization. |
| 4522 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4523 | % o exception: return any errors or warnings in this structure. |
| 4524 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4525 | */ |
| 4526 | MagickExport MagickBooleanType SolarizeImage(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4527 | const double threshold,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4528 | { |
| 4529 | #define SolarizeImageTag "Solarize/Image" |
| 4530 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4531 | CacheView |
| 4532 | *image_view; |
| 4533 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4534 | MagickBooleanType |
| 4535 | status; |
| 4536 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4537 | MagickOffsetType |
| 4538 | progress; |
| 4539 | |
| 4540 | ssize_t |
| 4541 | y; |
| 4542 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4543 | 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 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4549 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4550 | i; |
| 4551 | |
| 4552 | /* |
| 4553 | Solarize colormap. |
| 4554 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4555 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4556 | { |
| 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; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4572 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4573 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 4574 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4575 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4576 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4577 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4578 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4579 | x; |
| 4580 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4581 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4582 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4583 | |
| 4584 | if (status == MagickFalse) |
| 4585 | continue; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4586 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4587 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4588 | { |
| 4589 | status=MagickFalse; |
| 4590 | continue; |
| 4591 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4592 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4593 | { |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4594 | register ssize_t |
| 4595 | i; |
| 4596 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 4597 | if (GetPixelMask(image,q) != 0) |
| 4598 | { |
| 4599 | q+=GetPixelChannels(image); |
| 4600 | continue; |
| 4601 | } |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4602 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 4603 | { |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4604 | PixelChannel |
| 4605 | channel; |
| 4606 | |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4607 | PixelTrait |
| 4608 | traits; |
| 4609 | |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 4610 | channel=GetPixelChannelMapChannel(image,i); |
| 4611 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4612 | if ((traits == UndefinedPixelTrait) || |
| 4613 | ((traits & CopyPixelTrait) != 0)) |
| 4614 | continue; |
| 4615 | if ((MagickRealType) q[i] > threshold) |
| 4616 | q[i]=QuantumRange-q[i]; |
| 4617 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4618 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4619 | } |
| 4620 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 4621 | status=MagickFalse; |
| 4622 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 4623 | { |
| 4624 | MagickBooleanType |
| 4625 | proceed; |
| 4626 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4627 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 4628 | #pragma omp critical (MagickCore_SolarizeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4629 | #endif |
| 4630 | proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows); |
| 4631 | if (proceed == MagickFalse) |
| 4632 | status=MagickFalse; |
| 4633 | } |
| 4634 | } |
| 4635 | image_view=DestroyCacheView(image_view); |
| 4636 | return(status); |
| 4637 | } |
| 4638 | |
| 4639 | /* |
| 4640 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4641 | % % |
| 4642 | % % |
| 4643 | % % |
| 4644 | % S t e g a n o I m a g e % |
| 4645 | % % |
| 4646 | % % |
| 4647 | % % |
| 4648 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4649 | % |
| 4650 | % SteganoImage() hides a digital watermark within the image. Recover |
| 4651 | % the hidden watermark later to prove that the authenticity of an image. |
| 4652 | % Offset defines the start position within the image to hide the watermark. |
| 4653 | % |
| 4654 | % The format of the SteganoImage method is: |
| 4655 | % |
| 4656 | % Image *SteganoImage(const Image *image,Image *watermark, |
| 4657 | % ExceptionInfo *exception) |
| 4658 | % |
| 4659 | % A description of each parameter follows: |
| 4660 | % |
| 4661 | % o image: the image. |
| 4662 | % |
| 4663 | % o watermark: the watermark image. |
| 4664 | % |
| 4665 | % o exception: return any errors or warnings in this structure. |
| 4666 | % |
| 4667 | */ |
| 4668 | MagickExport Image *SteganoImage(const Image *image,const Image *watermark, |
| 4669 | ExceptionInfo *exception) |
| 4670 | { |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4671 | #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4672 | #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \ |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4673 | | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4674 | #define SteganoImageTag "Stegano/Image" |
| 4675 | |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4676 | CacheView |
| 4677 | *stegano_view, |
| 4678 | *watermark_view; |
| 4679 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4680 | Image |
| 4681 | *stegano_image; |
| 4682 | |
| 4683 | int |
| 4684 | c; |
| 4685 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4686 | MagickBooleanType |
| 4687 | status; |
| 4688 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4689 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4690 | pixel; |
| 4691 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4692 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4693 | *q; |
| 4694 | |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4695 | register ssize_t |
| 4696 | x; |
| 4697 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4698 | size_t |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4699 | depth, |
| 4700 | one; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4701 | |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4702 | ssize_t |
| 4703 | i, |
| 4704 | j, |
| 4705 | k, |
| 4706 | y; |
| 4707 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4708 | /* |
| 4709 | Initialize steganographic image attributes. |
| 4710 | */ |
| 4711 | assert(image != (const Image *) NULL); |
| 4712 | assert(image->signature == MagickSignature); |
| 4713 | if (image->debug != MagickFalse) |
| 4714 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4715 | assert(watermark != (const Image *) NULL); |
| 4716 | assert(watermark->signature == MagickSignature); |
| 4717 | assert(exception != (ExceptionInfo *) NULL); |
| 4718 | assert(exception->signature == MagickSignature); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4719 | one=1UL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4720 | stegano_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4721 | if (stegano_image == (Image *) NULL) |
| 4722 | return((Image *) NULL); |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4723 | stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH; |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4724 | if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4725 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4726 | stegano_image=DestroyImage(stegano_image); |
| 4727 | return((Image *) NULL); |
| 4728 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4729 | /* |
| 4730 | Hide watermark in low-order bits of image. |
| 4731 | */ |
| 4732 | c=0; |
| 4733 | i=0; |
| 4734 | j=0; |
| 4735 | depth=stegano_image->depth; |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4736 | k=stegano_image->offset; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4737 | status=MagickTrue; |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4738 | watermark_view=AcquireCacheView(watermark); |
| 4739 | stegano_view=AcquireCacheView(stegano_image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4740 | for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4741 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4742 | for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4743 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4744 | for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4745 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4746 | ssize_t |
| 4747 | offset; |
| 4748 | |
cristy | f05d494 | 2012-03-17 16:26:09 +0000 | [diff] [blame] | 4749 | (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4750 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4751 | offset=k/(ssize_t) stegano_image->columns; |
| 4752 | if (offset >= (ssize_t) stegano_image->rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4753 | break; |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4754 | q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t) |
| 4755 | stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1, |
| 4756 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4757 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4758 | break; |
| 4759 | switch (c) |
| 4760 | { |
| 4761 | case 0: |
| 4762 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4763 | SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j, |
| 4764 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4765 | break; |
| 4766 | } |
| 4767 | case 1: |
| 4768 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4769 | SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j, |
| 4770 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4771 | break; |
| 4772 | } |
| 4773 | case 2: |
| 4774 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4775 | SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j, |
| 4776 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4777 | break; |
| 4778 | } |
| 4779 | } |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4780 | if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4781 | break; |
| 4782 | c++; |
| 4783 | if (c == 3) |
| 4784 | c=0; |
| 4785 | k++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4786 | if (k == (ssize_t) (stegano_image->columns*stegano_image->columns)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4787 | k=0; |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4788 | if (k == stegano_image->offset) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4789 | j++; |
| 4790 | } |
| 4791 | } |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4792 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4793 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4794 | MagickBooleanType |
| 4795 | proceed; |
| 4796 | |
| 4797 | proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType) |
| 4798 | (depth-i),depth); |
| 4799 | if (proceed == MagickFalse) |
| 4800 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4801 | } |
| 4802 | } |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4803 | stegano_view=DestroyCacheView(stegano_view); |
| 4804 | watermark_view=DestroyCacheView(watermark_view); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4805 | if (status == MagickFalse) |
| 4806 | { |
| 4807 | stegano_image=DestroyImage(stegano_image); |
| 4808 | return((Image *) NULL); |
| 4809 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4810 | return(stegano_image); |
| 4811 | } |
| 4812 | |
| 4813 | /* |
| 4814 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4815 | % % |
| 4816 | % % |
| 4817 | % % |
| 4818 | % S t e r e o A n a g l y p h I m a g e % |
| 4819 | % % |
| 4820 | % % |
| 4821 | % % |
| 4822 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4823 | % |
| 4824 | % StereoAnaglyphImage() combines two images and produces a single image that |
| 4825 | % is the composite of a left and right image of a stereo pair. Special |
| 4826 | % red-green stereo glasses are required to view this effect. |
| 4827 | % |
| 4828 | % The format of the StereoAnaglyphImage method is: |
| 4829 | % |
| 4830 | % Image *StereoImage(const Image *left_image,const Image *right_image, |
| 4831 | % ExceptionInfo *exception) |
| 4832 | % Image *StereoAnaglyphImage(const Image *left_image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4833 | % const Image *right_image,const ssize_t x_offset,const ssize_t y_offset, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4834 | % ExceptionInfo *exception) |
| 4835 | % |
| 4836 | % A description of each parameter follows: |
| 4837 | % |
| 4838 | % o left_image: the left image. |
| 4839 | % |
| 4840 | % o right_image: the right image. |
| 4841 | % |
| 4842 | % o exception: return any errors or warnings in this structure. |
| 4843 | % |
| 4844 | % o x_offset: amount, in pixels, by which the left image is offset to the |
| 4845 | % right of the right image. |
| 4846 | % |
| 4847 | % o y_offset: amount, in pixels, by which the left image is offset to the |
| 4848 | % bottom of the right image. |
| 4849 | % |
| 4850 | % |
| 4851 | */ |
| 4852 | MagickExport Image *StereoImage(const Image *left_image, |
| 4853 | const Image *right_image,ExceptionInfo *exception) |
| 4854 | { |
| 4855 | return(StereoAnaglyphImage(left_image,right_image,0,0,exception)); |
| 4856 | } |
| 4857 | |
| 4858 | MagickExport Image *StereoAnaglyphImage(const Image *left_image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4859 | const Image *right_image,const ssize_t x_offset,const ssize_t y_offset, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4860 | ExceptionInfo *exception) |
| 4861 | { |
| 4862 | #define StereoImageTag "Stereo/Image" |
| 4863 | |
| 4864 | const Image |
| 4865 | *image; |
| 4866 | |
| 4867 | Image |
| 4868 | *stereo_image; |
| 4869 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4870 | MagickBooleanType |
| 4871 | status; |
| 4872 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 4873 | ssize_t |
| 4874 | y; |
| 4875 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4876 | assert(left_image != (const Image *) NULL); |
| 4877 | assert(left_image->signature == MagickSignature); |
| 4878 | if (left_image->debug != MagickFalse) |
| 4879 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 4880 | left_image->filename); |
| 4881 | assert(right_image != (const Image *) NULL); |
| 4882 | assert(right_image->signature == MagickSignature); |
| 4883 | assert(exception != (ExceptionInfo *) NULL); |
| 4884 | assert(exception->signature == MagickSignature); |
| 4885 | assert(right_image != (const Image *) NULL); |
| 4886 | image=left_image; |
| 4887 | if ((left_image->columns != right_image->columns) || |
| 4888 | (left_image->rows != right_image->rows)) |
| 4889 | ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer"); |
| 4890 | /* |
| 4891 | Initialize stereo image attributes. |
| 4892 | */ |
| 4893 | stereo_image=CloneImage(left_image,left_image->columns,left_image->rows, |
| 4894 | MagickTrue,exception); |
| 4895 | if (stereo_image == (Image *) NULL) |
| 4896 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4897 | if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4898 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4899 | stereo_image=DestroyImage(stereo_image); |
| 4900 | return((Image *) NULL); |
| 4901 | } |
| 4902 | /* |
| 4903 | Copy left image to red channel and right image to blue channel. |
| 4904 | */ |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4905 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4906 | for (y=0; y < (ssize_t) stereo_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4907 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4908 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4909 | *restrict p, |
| 4910 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4911 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4912 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4913 | x; |
| 4914 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4915 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4916 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4917 | |
| 4918 | p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1, |
| 4919 | exception); |
| 4920 | q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception); |
| 4921 | r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4922 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) || |
| 4923 | (r == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4924 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4925 | for (x=0; x < (ssize_t) stereo_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4926 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4927 | SetPixelRed(image,GetPixelRed(left_image,p),r); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4928 | SetPixelGreen(image,GetPixelGreen(right_image,q),r); |
| 4929 | SetPixelBlue(image,GetPixelBlue(right_image,q),r); |
| 4930 | if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0) |
| 4931 | SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+ |
| 4932 | GetPixelAlpha(right_image,q))/2,r); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4933 | p+=GetPixelChannels(left_image); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4934 | q+=GetPixelChannels(right_image); |
| 4935 | r+=GetPixelChannels(stereo_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4936 | } |
| 4937 | if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse) |
| 4938 | break; |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4939 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4940 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4941 | MagickBooleanType |
| 4942 | proceed; |
| 4943 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4944 | proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y, |
| 4945 | stereo_image->rows); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4946 | if (proceed == MagickFalse) |
| 4947 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4948 | } |
| 4949 | } |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4950 | if (status == MagickFalse) |
| 4951 | { |
| 4952 | stereo_image=DestroyImage(stereo_image); |
| 4953 | return((Image *) NULL); |
| 4954 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4955 | return(stereo_image); |
| 4956 | } |
| 4957 | |
| 4958 | /* |
| 4959 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4960 | % % |
| 4961 | % % |
| 4962 | % % |
| 4963 | % S w i r l I m a g e % |
| 4964 | % % |
| 4965 | % % |
| 4966 | % % |
| 4967 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4968 | % |
| 4969 | % SwirlImage() swirls the pixels about the center of the image, where |
| 4970 | % degrees indicates the sweep of the arc through which each pixel is moved. |
| 4971 | % You get a more dramatic effect as the degrees move from 1 to 360. |
| 4972 | % |
| 4973 | % The format of the SwirlImage method is: |
| 4974 | % |
| 4975 | % Image *SwirlImage(const Image *image,double degrees, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4976 | % const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4977 | % |
| 4978 | % A description of each parameter follows: |
| 4979 | % |
| 4980 | % o image: the image. |
| 4981 | % |
| 4982 | % o degrees: Define the tightness of the swirling effect. |
| 4983 | % |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4984 | % o method: the pixel interpolation method. |
| 4985 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4986 | % o exception: return any errors or warnings in this structure. |
| 4987 | % |
| 4988 | */ |
| 4989 | MagickExport Image *SwirlImage(const Image *image,double degrees, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4990 | const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4991 | { |
| 4992 | #define SwirlImageTag "Swirl/Image" |
| 4993 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 4994 | CacheView |
| 4995 | *image_view, |
| 4996 | *swirl_view; |
| 4997 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4998 | Image |
| 4999 | *swirl_image; |
| 5000 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5001 | MagickBooleanType |
| 5002 | status; |
| 5003 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5004 | MagickOffsetType |
| 5005 | progress; |
| 5006 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5007 | MagickRealType |
| 5008 | radius; |
| 5009 | |
| 5010 | PointInfo |
| 5011 | center, |
| 5012 | scale; |
| 5013 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5014 | ssize_t |
| 5015 | y; |
| 5016 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5017 | /* |
| 5018 | Initialize swirl image attributes. |
| 5019 | */ |
| 5020 | assert(image != (const Image *) NULL); |
| 5021 | assert(image->signature == MagickSignature); |
| 5022 | if (image->debug != MagickFalse) |
| 5023 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5024 | assert(exception != (ExceptionInfo *) NULL); |
| 5025 | assert(exception->signature == MagickSignature); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5026 | swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5027 | if (swirl_image == (Image *) NULL) |
| 5028 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5029 | if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5030 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5031 | swirl_image=DestroyImage(swirl_image); |
| 5032 | return((Image *) NULL); |
| 5033 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5034 | if (swirl_image->background_color.alpha != OpaqueAlpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5035 | swirl_image->matte=MagickTrue; |
| 5036 | /* |
| 5037 | Compute scaling factor. |
| 5038 | */ |
| 5039 | center.x=(double) image->columns/2.0; |
| 5040 | center.y=(double) image->rows/2.0; |
| 5041 | radius=MagickMax(center.x,center.y); |
| 5042 | scale.x=1.0; |
| 5043 | scale.y=1.0; |
| 5044 | if (image->columns > image->rows) |
| 5045 | scale.y=(double) image->columns/(double) image->rows; |
| 5046 | else |
| 5047 | if (image->columns < image->rows) |
| 5048 | scale.x=(double) image->rows/(double) image->columns; |
| 5049 | degrees=(double) DegreesToRadians(degrees); |
| 5050 | /* |
| 5051 | Swirl image. |
| 5052 | */ |
| 5053 | status=MagickTrue; |
| 5054 | progress=0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5055 | image_view=AcquireCacheView(image); |
| 5056 | swirl_view=AcquireCacheView(swirl_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5057 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5058 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5059 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5060 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5061 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5062 | MagickRealType |
| 5063 | distance; |
| 5064 | |
| 5065 | PointInfo |
| 5066 | delta; |
| 5067 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5068 | register const Quantum |
| 5069 | *restrict p; |
| 5070 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5071 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5072 | x; |
| 5073 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5074 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5075 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5076 | |
| 5077 | if (status == MagickFalse) |
| 5078 | continue; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5079 | p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5080 | q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5081 | exception); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5082 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5083 | { |
| 5084 | status=MagickFalse; |
| 5085 | continue; |
| 5086 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5087 | delta.y=scale.y*(double) (y-center.y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5088 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5089 | { |
| 5090 | /* |
| 5091 | Determine if the pixel is within an ellipse. |
| 5092 | */ |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 5093 | if (GetPixelMask(image,p) != 0) |
| 5094 | { |
| 5095 | p+=GetPixelChannels(image); |
| 5096 | q+=GetPixelChannels(swirl_image); |
| 5097 | continue; |
| 5098 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5099 | delta.x=scale.x*(double) (x-center.x); |
| 5100 | distance=delta.x*delta.x+delta.y*delta.y; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5101 | if (distance >= (radius*radius)) |
| 5102 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5103 | register ssize_t |
| 5104 | i; |
| 5105 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5106 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5107 | { |
| 5108 | PixelChannel |
| 5109 | channel; |
| 5110 | |
| 5111 | PixelTrait |
| 5112 | swirl_traits, |
| 5113 | traits; |
| 5114 | |
| 5115 | channel=GetPixelChannelMapChannel(image,i); |
| 5116 | traits=GetPixelChannelMapTraits(image,channel); |
| 5117 | swirl_traits=GetPixelChannelMapTraits(swirl_image,channel); |
| 5118 | if ((traits == UndefinedPixelTrait) || |
| 5119 | (swirl_traits == UndefinedPixelTrait)) |
| 5120 | continue; |
| 5121 | SetPixelChannel(swirl_image,channel,p[i],q); |
| 5122 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5123 | } |
| 5124 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5125 | { |
| 5126 | MagickRealType |
| 5127 | cosine, |
| 5128 | factor, |
| 5129 | sine; |
| 5130 | |
| 5131 | /* |
| 5132 | Swirl the pixel. |
| 5133 | */ |
| 5134 | factor=1.0-sqrt((double) distance)/radius; |
| 5135 | sine=sin((double) (degrees*factor*factor)); |
| 5136 | cosine=cos((double) (degrees*factor*factor)); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5137 | status=InterpolatePixelChannels(image,image_view,swirl_image,method, |
| 5138 | ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double) |
| 5139 | ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5140 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5141 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5142 | q+=GetPixelChannels(swirl_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5143 | } |
| 5144 | if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse) |
| 5145 | status=MagickFalse; |
| 5146 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5147 | { |
| 5148 | MagickBooleanType |
| 5149 | proceed; |
| 5150 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5151 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5152 | #pragma omp critical (MagickCore_SwirlImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5153 | #endif |
| 5154 | proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows); |
| 5155 | if (proceed == MagickFalse) |
| 5156 | status=MagickFalse; |
| 5157 | } |
| 5158 | } |
| 5159 | swirl_view=DestroyCacheView(swirl_view); |
| 5160 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5161 | if (status == MagickFalse) |
| 5162 | swirl_image=DestroyImage(swirl_image); |
| 5163 | return(swirl_image); |
| 5164 | } |
| 5165 | |
| 5166 | /* |
| 5167 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5168 | % % |
| 5169 | % % |
| 5170 | % % |
| 5171 | % T i n t I m a g e % |
| 5172 | % % |
| 5173 | % % |
| 5174 | % % |
| 5175 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5176 | % |
| 5177 | % TintImage() applies a color vector to each pixel in the image. The length |
| 5178 | % of the vector is 0 for black and white and at its maximum for the midtones. |
| 5179 | % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5)))) |
| 5180 | % |
| 5181 | % The format of the TintImage method is: |
| 5182 | % |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5183 | % Image *TintImage(const Image *image,const char *blend, |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5184 | % const PixelInfo *tint,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5185 | % |
| 5186 | % A description of each parameter follows: |
| 5187 | % |
| 5188 | % o image: the image. |
| 5189 | % |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5190 | % o blend: A color value used for tinting. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5191 | % |
| 5192 | % o tint: A color value used for tinting. |
| 5193 | % |
| 5194 | % o exception: return any errors or warnings in this structure. |
| 5195 | % |
| 5196 | */ |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5197 | MagickExport Image *TintImage(const Image *image,const char *blend, |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5198 | const PixelInfo *tint,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5199 | { |
| 5200 | #define TintImageTag "Tint/Image" |
| 5201 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 5202 | CacheView |
| 5203 | *image_view, |
| 5204 | *tint_view; |
| 5205 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5206 | GeometryInfo |
| 5207 | geometry_info; |
| 5208 | |
| 5209 | Image |
| 5210 | *tint_image; |
| 5211 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5212 | MagickBooleanType |
| 5213 | status; |
| 5214 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5215 | MagickOffsetType |
| 5216 | progress; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5217 | |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5218 | MagickRealType |
| 5219 | intensity; |
| 5220 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5221 | PixelInfo |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5222 | color_vector; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5223 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5224 | MagickStatusType |
| 5225 | flags; |
| 5226 | |
| 5227 | ssize_t |
| 5228 | y; |
| 5229 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5230 | /* |
| 5231 | Allocate tint image. |
| 5232 | */ |
| 5233 | assert(image != (const Image *) NULL); |
| 5234 | assert(image->signature == MagickSignature); |
| 5235 | if (image->debug != MagickFalse) |
| 5236 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5237 | assert(exception != (ExceptionInfo *) NULL); |
| 5238 | assert(exception->signature == MagickSignature); |
| 5239 | tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
| 5240 | if (tint_image == (Image *) NULL) |
| 5241 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5242 | if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5243 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5244 | tint_image=DestroyImage(tint_image); |
| 5245 | return((Image *) NULL); |
| 5246 | } |
cristy | aed9c38 | 2011-10-03 17:54:21 +0000 | [diff] [blame] | 5247 | if (blend == (const char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5248 | return(tint_image); |
| 5249 | /* |
| 5250 | Determine RGB values of the color. |
| 5251 | */ |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5252 | GetPixelInfo(image,&color_vector); |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5253 | flags=ParseGeometry(blend,&geometry_info); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5254 | color_vector.red=geometry_info.rho; |
| 5255 | color_vector.green=geometry_info.rho; |
| 5256 | color_vector.blue=geometry_info.rho; |
| 5257 | color_vector.alpha=OpaqueAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5258 | if ((flags & SigmaValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5259 | color_vector.green=geometry_info.sigma; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5260 | if ((flags & XiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5261 | color_vector.blue=geometry_info.xi; |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5262 | if ((flags & PsiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5263 | color_vector.alpha=geometry_info.psi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5264 | if (image->colorspace == CMYKColorspace) |
| 5265 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5266 | color_vector.black=geometry_info.rho; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5267 | if ((flags & PsiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5268 | color_vector.black=geometry_info.psi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5269 | if ((flags & ChiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5270 | color_vector.alpha=geometry_info.chi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5271 | } |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5272 | intensity=(MagickRealType) GetPixelInfoIntensity(tint); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5273 | color_vector.red=(MagickRealType) (color_vector.red*tint->red/100.0- |
| 5274 | intensity); |
| 5275 | color_vector.green=(MagickRealType) (color_vector.green*tint->green/100.0- |
| 5276 | intensity); |
| 5277 | color_vector.blue=(MagickRealType) (color_vector.blue*tint->blue/100.0- |
| 5278 | intensity); |
| 5279 | color_vector.black=(MagickRealType) (color_vector.black*tint->black/100.0- |
| 5280 | intensity); |
| 5281 | color_vector.alpha=(MagickRealType) (color_vector.alpha*tint->alpha/100.0- |
| 5282 | intensity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5283 | /* |
| 5284 | Tint image. |
| 5285 | */ |
| 5286 | status=MagickTrue; |
| 5287 | progress=0; |
| 5288 | image_view=AcquireCacheView(image); |
| 5289 | tint_view=AcquireCacheView(tint_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5290 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 5291 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5292 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5293 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5294 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5295 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5296 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5297 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5298 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5299 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5300 | |
cristy | 6b91acb | 2011-04-19 12:23:54 +0000 | [diff] [blame] | 5301 | register ssize_t |
| 5302 | x; |
| 5303 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5304 | if (status == MagickFalse) |
| 5305 | continue; |
| 5306 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 5307 | q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1, |
| 5308 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5309 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5310 | { |
| 5311 | status=MagickFalse; |
| 5312 | continue; |
| 5313 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5314 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5315 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5316 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5317 | pixel; |
| 5318 | |
| 5319 | MagickRealType |
| 5320 | weight; |
| 5321 | |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5322 | register ssize_t |
| 5323 | i; |
| 5324 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 5325 | if (GetPixelMask(image,p) != 0) |
| 5326 | { |
| 5327 | p+=GetPixelChannels(image); |
| 5328 | q+=GetPixelChannels(tint_image); |
| 5329 | continue; |
| 5330 | } |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5331 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 5332 | { |
| 5333 | PixelChannel |
| 5334 | channel; |
| 5335 | |
| 5336 | PixelTrait |
| 5337 | tint_traits, |
| 5338 | traits; |
| 5339 | |
| 5340 | channel=GetPixelChannelMapChannel(image,i); |
| 5341 | traits=GetPixelChannelMapTraits(image,channel); |
| 5342 | tint_traits=GetPixelChannelMapTraits(tint_image,channel); |
| 5343 | if ((traits == UndefinedPixelTrait) || |
| 5344 | (tint_traits == UndefinedPixelTrait)) |
| 5345 | continue; |
| 5346 | if ((tint_traits & CopyPixelTrait) != 0) |
| 5347 | { |
| 5348 | SetPixelChannel(tint_image,channel,p[i],q); |
| 5349 | continue; |
| 5350 | } |
| 5351 | } |
| 5352 | GetPixelInfo(image,&pixel); |
| 5353 | weight=QuantumScale*GetPixelRed(image,p)-0.5; |
| 5354 | pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red* |
| 5355 | (1.0-(4.0*(weight*weight))); |
| 5356 | weight=QuantumScale*GetPixelGreen(image,p)-0.5; |
| 5357 | pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green* |
| 5358 | (1.0-(4.0*(weight*weight))); |
| 5359 | weight=QuantumScale*GetPixelBlue(image,p)-0.5; |
| 5360 | pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue* |
| 5361 | (1.0-(4.0*(weight*weight))); |
| 5362 | weight=QuantumScale*GetPixelBlack(image,p)-0.5; |
| 5363 | pixel.black=(MagickRealType) GetPixelBlack(image,p)+color_vector.black* |
| 5364 | (1.0-(4.0*(weight*weight))); |
| 5365 | SetPixelInfoPixel(tint_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5366 | p+=GetPixelChannels(image); |
| 5367 | q+=GetPixelChannels(tint_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5368 | } |
| 5369 | if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse) |
| 5370 | status=MagickFalse; |
| 5371 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5372 | { |
| 5373 | MagickBooleanType |
| 5374 | proceed; |
| 5375 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5376 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5377 | #pragma omp critical (MagickCore_TintImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5378 | #endif |
| 5379 | proceed=SetImageProgress(image,TintImageTag,progress++,image->rows); |
| 5380 | if (proceed == MagickFalse) |
| 5381 | status=MagickFalse; |
| 5382 | } |
| 5383 | } |
| 5384 | tint_view=DestroyCacheView(tint_view); |
| 5385 | image_view=DestroyCacheView(image_view); |
| 5386 | if (status == MagickFalse) |
| 5387 | tint_image=DestroyImage(tint_image); |
| 5388 | return(tint_image); |
| 5389 | } |
| 5390 | |
| 5391 | /* |
| 5392 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5393 | % % |
| 5394 | % % |
| 5395 | % % |
| 5396 | % V i g n e t t e I m a g e % |
| 5397 | % % |
| 5398 | % % |
| 5399 | % % |
| 5400 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5401 | % |
| 5402 | % VignetteImage() softens the edges of the image in vignette style. |
| 5403 | % |
| 5404 | % The format of the VignetteImage method is: |
| 5405 | % |
| 5406 | % Image *VignetteImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5407 | % const double sigma,const ssize_t x,const ssize_t y, |
cristy | 05c0c9a | 2011-09-05 23:16:13 +0000 | [diff] [blame] | 5408 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5409 | % |
| 5410 | % A description of each parameter follows: |
| 5411 | % |
| 5412 | % o image: the image. |
| 5413 | % |
| 5414 | % o radius: the radius of the pixel neighborhood. |
| 5415 | % |
| 5416 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 5417 | % |
| 5418 | % o x, y: Define the x and y ellipse offset. |
| 5419 | % |
| 5420 | % o exception: return any errors or warnings in this structure. |
| 5421 | % |
| 5422 | */ |
| 5423 | MagickExport Image *VignetteImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5424 | const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5425 | { |
| 5426 | char |
| 5427 | ellipse[MaxTextExtent]; |
| 5428 | |
| 5429 | DrawInfo |
| 5430 | *draw_info; |
| 5431 | |
| 5432 | Image |
| 5433 | *canvas_image, |
| 5434 | *blur_image, |
| 5435 | *oval_image, |
| 5436 | *vignette_image; |
| 5437 | |
| 5438 | assert(image != (Image *) NULL); |
| 5439 | assert(image->signature == MagickSignature); |
| 5440 | if (image->debug != MagickFalse) |
| 5441 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5442 | assert(exception != (ExceptionInfo *) NULL); |
| 5443 | assert(exception->signature == MagickSignature); |
| 5444 | canvas_image=CloneImage(image,0,0,MagickTrue,exception); |
| 5445 | if (canvas_image == (Image *) NULL) |
| 5446 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5447 | if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5448 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5449 | canvas_image=DestroyImage(canvas_image); |
| 5450 | return((Image *) NULL); |
| 5451 | } |
| 5452 | canvas_image->matte=MagickTrue; |
cristy | 9862146 | 2011-12-31 22:31:11 +0000 | [diff] [blame] | 5453 | oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows, |
| 5454 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5455 | if (oval_image == (Image *) NULL) |
| 5456 | { |
| 5457 | canvas_image=DestroyImage(canvas_image); |
| 5458 | return((Image *) NULL); |
| 5459 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 5460 | (void) QueryColorCompliance("#000000",AllCompliance, |
| 5461 | &oval_image->background_color,exception); |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 5462 | (void) SetImageBackgroundColor(oval_image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5463 | draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 5464 | (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill, |
| 5465 | exception); |
| 5466 | (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke, |
| 5467 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5468 | (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g," |
| 5469 | "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x, |
| 5470 | image->rows/2.0-y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5471 | draw_info->primitive=AcquireString(ellipse); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 5472 | (void) DrawImage(oval_image,draw_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5473 | draw_info=DestroyDrawInfo(draw_info); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5474 | blur_image=BlurImage(oval_image,radius,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5475 | oval_image=DestroyImage(oval_image); |
| 5476 | if (blur_image == (Image *) NULL) |
| 5477 | { |
| 5478 | canvas_image=DestroyImage(canvas_image); |
| 5479 | return((Image *) NULL); |
| 5480 | } |
| 5481 | blur_image->matte=MagickFalse; |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 5482 | (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue, |
| 5483 | 0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5484 | blur_image=DestroyImage(blur_image); |
| 5485 | vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception); |
| 5486 | canvas_image=DestroyImage(canvas_image); |
| 5487 | return(vignette_image); |
| 5488 | } |
| 5489 | |
| 5490 | /* |
| 5491 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5492 | % % |
| 5493 | % % |
| 5494 | % % |
| 5495 | % W a v e I m a g e % |
| 5496 | % % |
| 5497 | % % |
| 5498 | % % |
| 5499 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5500 | % |
| 5501 | % WaveImage() creates a "ripple" effect in the image by shifting the pixels |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 5502 | % vertically along a sine wave whose amplitude and wavelength is specified |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5503 | % by the given parameters. |
| 5504 | % |
| 5505 | % The format of the WaveImage method is: |
| 5506 | % |
| 5507 | % Image *WaveImage(const Image *image,const double amplitude, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5508 | % const double wave_length,const PixelInterpolateMethod method, |
| 5509 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5510 | % |
| 5511 | % A description of each parameter follows: |
| 5512 | % |
| 5513 | % o image: the image. |
| 5514 | % |
| 5515 | % o amplitude, wave_length: Define the amplitude and wave length of the |
| 5516 | % sine wave. |
| 5517 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5518 | % o interpolate: the pixel interpolation method. |
| 5519 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5520 | % o exception: return any errors or warnings in this structure. |
| 5521 | % |
| 5522 | */ |
| 5523 | MagickExport Image *WaveImage(const Image *image,const double amplitude, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5524 | const double wave_length,const PixelInterpolateMethod method, |
| 5525 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5526 | { |
| 5527 | #define WaveImageTag "Wave/Image" |
| 5528 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5529 | CacheView |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5530 | *image_view, |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5531 | *wave_view; |
| 5532 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5533 | Image |
| 5534 | *wave_image; |
| 5535 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5536 | MagickBooleanType |
| 5537 | status; |
| 5538 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5539 | MagickOffsetType |
| 5540 | progress; |
| 5541 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5542 | MagickRealType |
| 5543 | *sine_map; |
| 5544 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5545 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5546 | i; |
| 5547 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5548 | ssize_t |
| 5549 | y; |
| 5550 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5551 | /* |
| 5552 | Initialize wave image attributes. |
| 5553 | */ |
| 5554 | assert(image != (Image *) NULL); |
| 5555 | assert(image->signature == MagickSignature); |
| 5556 | if (image->debug != MagickFalse) |
| 5557 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5558 | assert(exception != (ExceptionInfo *) NULL); |
| 5559 | assert(exception->signature == MagickSignature); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5560 | wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5561 | fabs(amplitude)),MagickTrue,exception); |
| 5562 | if (wave_image == (Image *) NULL) |
| 5563 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5564 | if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5565 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5566 | wave_image=DestroyImage(wave_image); |
| 5567 | return((Image *) NULL); |
| 5568 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5569 | if (wave_image->background_color.alpha != OpaqueAlpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5570 | wave_image->matte=MagickTrue; |
| 5571 | /* |
| 5572 | Allocate sine map. |
| 5573 | */ |
| 5574 | sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns, |
| 5575 | sizeof(*sine_map)); |
| 5576 | if (sine_map == (MagickRealType *) NULL) |
| 5577 | { |
| 5578 | wave_image=DestroyImage(wave_image); |
| 5579 | ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); |
| 5580 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5581 | for (i=0; i < (ssize_t) wave_image->columns; i++) |
cristy | 4205a3c | 2010-09-12 20:19:59 +0000 | [diff] [blame] | 5582 | sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/ |
| 5583 | wave_length)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5584 | /* |
| 5585 | Wave image. |
| 5586 | */ |
| 5587 | status=MagickTrue; |
| 5588 | progress=0; |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5589 | image_view=AcquireCacheView(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5590 | wave_view=AcquireCacheView(wave_image); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5591 | (void) SetCacheViewVirtualPixelMethod(image_view, |
| 5592 | BackgroundVirtualPixelMethod); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5593 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 5594 | #pragma omp parallel for schedule(static,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5595 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5596 | for (y=0; y < (ssize_t) wave_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5597 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5598 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5599 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5600 | |
cristy | e97bb92 | 2011-04-03 01:36:52 +0000 | [diff] [blame] | 5601 | register ssize_t |
| 5602 | x; |
| 5603 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5604 | if (status == MagickFalse) |
| 5605 | continue; |
| 5606 | q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1, |
| 5607 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 5608 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5609 | { |
| 5610 | status=MagickFalse; |
| 5611 | continue; |
| 5612 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5613 | for (x=0; x < (ssize_t) wave_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5614 | { |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5615 | status=InterpolatePixelChannels(image,image_view,wave_image,method, |
| 5616 | (double) x,(double) (y-sine_map[x]),q,exception); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5617 | q+=GetPixelChannels(wave_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5618 | } |
| 5619 | if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse) |
| 5620 | status=MagickFalse; |
| 5621 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5622 | { |
| 5623 | MagickBooleanType |
| 5624 | proceed; |
| 5625 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5626 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5627 | #pragma omp critical (MagickCore_WaveImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5628 | #endif |
| 5629 | proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows); |
| 5630 | if (proceed == MagickFalse) |
| 5631 | status=MagickFalse; |
| 5632 | } |
| 5633 | } |
| 5634 | wave_view=DestroyCacheView(wave_view); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5635 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5636 | sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map); |
| 5637 | if (status == MagickFalse) |
| 5638 | wave_image=DestroyImage(wave_image); |
| 5639 | return(wave_image); |
| 5640 | } |