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