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