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