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