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" |
cristy | 6a2180c | 2013-05-27 10:28:36 +0000 | [diff] [blame] | 49 | #include "MagickCore/channel.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/color.h" |
| 51 | #include "MagickCore/color-private.h" |
cristy | 9b7a4fc | 2012-04-08 22:26:56 +0000 | [diff] [blame] | 52 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 53 | #include "MagickCore/composite.h" |
| 54 | #include "MagickCore/decorate.h" |
cristy | c53413d | 2011-11-17 13:04:26 +0000 | [diff] [blame] | 55 | #include "MagickCore/distort.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 56 | #include "MagickCore/draw.h" |
| 57 | #include "MagickCore/effect.h" |
| 58 | #include "MagickCore/enhance.h" |
| 59 | #include "MagickCore/exception.h" |
| 60 | #include "MagickCore/exception-private.h" |
| 61 | #include "MagickCore/fx.h" |
| 62 | #include "MagickCore/fx-private.h" |
| 63 | #include "MagickCore/gem.h" |
cristy | 8ea8122 | 2011-09-04 10:33:32 +0000 | [diff] [blame] | 64 | #include "MagickCore/gem-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 65 | #include "MagickCore/geometry.h" |
| 66 | #include "MagickCore/layer.h" |
| 67 | #include "MagickCore/list.h" |
| 68 | #include "MagickCore/log.h" |
| 69 | #include "MagickCore/image.h" |
| 70 | #include "MagickCore/image-private.h" |
| 71 | #include "MagickCore/magick.h" |
| 72 | #include "MagickCore/memory_.h" |
| 73 | #include "MagickCore/monitor.h" |
| 74 | #include "MagickCore/monitor-private.h" |
| 75 | #include "MagickCore/option.h" |
| 76 | #include "MagickCore/pixel.h" |
| 77 | #include "MagickCore/pixel-accessor.h" |
| 78 | #include "MagickCore/property.h" |
| 79 | #include "MagickCore/quantum.h" |
| 80 | #include "MagickCore/quantum-private.h" |
| 81 | #include "MagickCore/random_.h" |
| 82 | #include "MagickCore/random-private.h" |
| 83 | #include "MagickCore/resample.h" |
| 84 | #include "MagickCore/resample-private.h" |
| 85 | #include "MagickCore/resize.h" |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 86 | #include "MagickCore/resource_.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 87 | #include "MagickCore/splay-tree.h" |
| 88 | #include "MagickCore/statistic.h" |
| 89 | #include "MagickCore/string_.h" |
| 90 | #include "MagickCore/string-private.h" |
| 91 | #include "MagickCore/thread-private.h" |
| 92 | #include "MagickCore/transform.h" |
| 93 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | Define declarations. |
| 97 | */ |
| 98 | #define LeftShiftOperator 0xf5 |
| 99 | #define RightShiftOperator 0xf6 |
| 100 | #define LessThanEqualOperator 0xf7 |
| 101 | #define GreaterThanEqualOperator 0xf8 |
| 102 | #define EqualOperator 0xf9 |
| 103 | #define NotEqualOperator 0xfa |
| 104 | #define LogicalAndOperator 0xfb |
| 105 | #define LogicalOrOperator 0xfc |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 106 | #define ExponentialNotation 0xfd |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 107 | |
| 108 | struct _FxInfo |
| 109 | { |
| 110 | const Image |
| 111 | *images; |
| 112 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | char |
| 114 | *expression; |
| 115 | |
| 116 | FILE |
| 117 | *file; |
| 118 | |
| 119 | SplayTreeInfo |
| 120 | *colors, |
| 121 | *symbols; |
| 122 | |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 123 | CacheView |
| 124 | **view; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | |
| 126 | RandomInfo |
| 127 | *random_info; |
| 128 | |
| 129 | ExceptionInfo |
| 130 | *exception; |
| 131 | }; |
| 132 | |
| 133 | /* |
| 134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 135 | % % |
| 136 | % % |
| 137 | % % |
| 138 | + A c q u i r e F x I n f o % |
| 139 | % % |
| 140 | % % |
| 141 | % % |
| 142 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 143 | % |
| 144 | % AcquireFxInfo() allocates the FxInfo structure. |
| 145 | % |
| 146 | % The format of the AcquireFxInfo method is: |
| 147 | % |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 148 | % FxInfo *AcquireFxInfo(Image *image,const char *expression, |
| 149 | % ExceptionInfo *exception) |
cristy | 0a9b372 | 2010-10-23 18:45:49 +0000 | [diff] [blame] | 150 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 151 | % A description of each parameter follows: |
| 152 | % |
| 153 | % o image: the image. |
| 154 | % |
| 155 | % o expression: the expression. |
| 156 | % |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 157 | % o exception: return any errors or warnings in this structure. |
| 158 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | */ |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 160 | MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression, |
| 161 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 162 | { |
| 163 | char |
| 164 | fx_op[2]; |
| 165 | |
cristy | cb18092 | 2011-03-11 14:41:24 +0000 | [diff] [blame] | 166 | const Image |
| 167 | *next; |
| 168 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | FxInfo |
| 170 | *fx_info; |
| 171 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 172 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | i; |
| 174 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 175 | fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | if (fx_info == (FxInfo *) NULL) |
| 177 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 178 | (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info)); |
| 179 | fx_info->exception=AcquireExceptionInfo(); |
anthony | 7d86e17 | 2011-03-23 12:37:06 +0000 | [diff] [blame] | 180 | fx_info->images=image; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 181 | fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
cristy | 1e12eb4 | 2013-08-17 16:19:01 +0000 | [diff] [blame^] | 182 | RelinquishAlignedMemory); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
| 184 | RelinquishMagickMemory); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 185 | fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength( |
| 186 | fx_info->images),sizeof(*fx_info->view)); |
| 187 | if (fx_info->view == (CacheView **) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 188 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | a226226 | 2011-03-11 02:50:37 +0000 | [diff] [blame] | 189 | i=0; |
cristy | 0ea377f | 2011-03-24 00:54:19 +0000 | [diff] [blame] | 190 | next=GetFirstImageInList(fx_info->images); |
| 191 | for ( ; next != (Image *) NULL; next=next->next) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 192 | { |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 193 | fx_info->view[i]=AcquireVirtualCacheView(next,exception); |
cristy | a226226 | 2011-03-11 02:50:37 +0000 | [diff] [blame] | 194 | i++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 195 | } |
| 196 | fx_info->random_info=AcquireRandomInfo(); |
| 197 | fx_info->expression=ConstantString(expression); |
| 198 | fx_info->file=stderr; |
| 199 | (void) SubstituteString(&fx_info->expression," ",""); /* compact string */ |
cristy | 37af091 | 2011-05-23 16:09:42 +0000 | [diff] [blame] | 200 | /* |
| 201 | Force right-to-left associativity for unary negation. |
| 202 | */ |
| 203 | (void) SubstituteString(&fx_info->expression,"-","-1.0*"); |
cristy | 422d550 | 2012-12-22 22:20:57 +0000 | [diff] [blame] | 204 | (void) SubstituteString(&fx_info->expression,"^-1.0*","^-"); |
cristy | 8fbb96d | 2012-07-18 01:18:52 +0000 | [diff] [blame] | 205 | (void) SubstituteString(&fx_info->expression,"E-1.0*","E-"); |
| 206 | (void) SubstituteString(&fx_info->expression,"e-1.0*","e-"); |
cristy | 8b8a3ae | 2010-10-23 18:49:46 +0000 | [diff] [blame] | 207 | /* |
cristy | df75151 | 2013-08-17 14:19:12 +0000 | [diff] [blame] | 208 | Convert compound to simple operators. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | */ |
| 210 | fx_op[1]='\0'; |
| 211 | *fx_op=(char) LeftShiftOperator; |
| 212 | (void) SubstituteString(&fx_info->expression,"<<",fx_op); |
| 213 | *fx_op=(char) RightShiftOperator; |
| 214 | (void) SubstituteString(&fx_info->expression,">>",fx_op); |
| 215 | *fx_op=(char) LessThanEqualOperator; |
| 216 | (void) SubstituteString(&fx_info->expression,"<=",fx_op); |
| 217 | *fx_op=(char) GreaterThanEqualOperator; |
| 218 | (void) SubstituteString(&fx_info->expression,">=",fx_op); |
| 219 | *fx_op=(char) EqualOperator; |
| 220 | (void) SubstituteString(&fx_info->expression,"==",fx_op); |
| 221 | *fx_op=(char) NotEqualOperator; |
| 222 | (void) SubstituteString(&fx_info->expression,"!=",fx_op); |
| 223 | *fx_op=(char) LogicalAndOperator; |
| 224 | (void) SubstituteString(&fx_info->expression,"&&",fx_op); |
| 225 | *fx_op=(char) LogicalOrOperator; |
| 226 | (void) SubstituteString(&fx_info->expression,"||",fx_op); |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 227 | *fx_op=(char) ExponentialNotation; |
| 228 | (void) SubstituteString(&fx_info->expression,"**",fx_op); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 229 | return(fx_info); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 234 | % % |
| 235 | % % |
| 236 | % % |
| 237 | % A d d N o i s e I m a g e % |
| 238 | % % |
| 239 | % % |
| 240 | % % |
| 241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 242 | % |
| 243 | % AddNoiseImage() adds random noise to the image. |
| 244 | % |
| 245 | % The format of the AddNoiseImage method is: |
| 246 | % |
| 247 | % Image *AddNoiseImage(const Image *image,const NoiseType noise_type, |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 248 | % const double attenuate,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 249 | % |
| 250 | % A description of each parameter follows: |
| 251 | % |
| 252 | % o image: the image. |
| 253 | % |
| 254 | % o channel: the channel type. |
| 255 | % |
| 256 | % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative, |
| 257 | % Impulse, Laplacian, or Poisson. |
| 258 | % |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 259 | % o attenuate: attenuate the random distribution. |
| 260 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 261 | % o exception: return any errors or warnings in this structure. |
| 262 | % |
| 263 | */ |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 264 | MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type, |
| 265 | const double attenuate,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 266 | { |
| 267 | #define AddNoiseImageTag "AddNoise/Image" |
| 268 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 269 | CacheView |
| 270 | *image_view, |
| 271 | *noise_view; |
| 272 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 273 | Image |
| 274 | *noise_image; |
| 275 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 276 | MagickBooleanType |
| 277 | status; |
| 278 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 279 | MagickOffsetType |
| 280 | progress; |
| 281 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 282 | RandomInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 283 | **restrict random_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 284 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 285 | ssize_t |
| 286 | y; |
| 287 | |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 288 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 289 | unsigned long |
| 290 | key; |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 291 | #endif |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 292 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | /* |
| 294 | Initialize noise image attributes. |
| 295 | */ |
| 296 | assert(image != (const Image *) NULL); |
| 297 | assert(image->signature == MagickSignature); |
| 298 | if (image->debug != MagickFalse) |
| 299 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 300 | assert(exception != (ExceptionInfo *) NULL); |
| 301 | assert(exception->signature == MagickSignature); |
cristy | b214589 | 2011-10-10 00:55:32 +0000 | [diff] [blame] | 302 | noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 303 | if (noise_image == (Image *) NULL) |
| 304 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 305 | if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 306 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 307 | noise_image=DestroyImage(noise_image); |
| 308 | return((Image *) NULL); |
| 309 | } |
| 310 | /* |
| 311 | Add noise in each row. |
| 312 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | status=MagickTrue; |
| 314 | progress=0; |
| 315 | random_info=AcquireRandomInfoThreadSet(); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 316 | image_view=AcquireVirtualCacheView(image,exception); |
| 317 | noise_view=AcquireAuthenticCacheView(noise_image,exception); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 318 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 319 | key=GetRandomSecretKey(random_info[0]); |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 320 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 321 | magick_threads(image,noise_image,image->rows,key == ~0UL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 322 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 323 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 324 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 325 | const int |
| 326 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 327 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | MagickBooleanType |
| 329 | sync; |
| 330 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 331 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 332 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 333 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 334 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | x; |
| 336 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 337 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 338 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 339 | |
| 340 | if (status == MagickFalse) |
| 341 | continue; |
| 342 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 343 | q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 345 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 346 | { |
| 347 | status=MagickFalse; |
| 348 | continue; |
| 349 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 350 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 351 | { |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 352 | register ssize_t |
| 353 | i; |
| 354 | |
| 355 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 356 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 357 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 358 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 359 | PixelTrait noise_traits=GetPixelChannelTraits(noise_image,channel); |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 360 | if ((traits == UndefinedPixelTrait) || |
| 361 | (noise_traits == UndefinedPixelTrait)) |
| 362 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 363 | if (((noise_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 364 | (GetPixelReadMask(image,p) == 0)) |
cristy | b214589 | 2011-10-10 00:55:32 +0000 | [diff] [blame] | 365 | { |
| 366 | SetPixelChannel(noise_image,channel,p[i],q); |
| 367 | continue; |
| 368 | } |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 369 | SetPixelChannel(noise_image,channel,ClampToQuantum( |
| 370 | GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)), |
| 371 | q); |
| 372 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 373 | p+=GetPixelChannels(image); |
| 374 | q+=GetPixelChannels(noise_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | } |
| 376 | sync=SyncCacheViewAuthenticPixels(noise_view,exception); |
| 377 | if (sync == MagickFalse) |
| 378 | status=MagickFalse; |
| 379 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 380 | { |
| 381 | MagickBooleanType |
| 382 | proceed; |
| 383 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 384 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 385 | #pragma omp critical (MagickCore_AddNoiseImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 386 | #endif |
| 387 | proceed=SetImageProgress(image,AddNoiseImageTag,progress++, |
| 388 | image->rows); |
| 389 | if (proceed == MagickFalse) |
| 390 | status=MagickFalse; |
| 391 | } |
| 392 | } |
| 393 | noise_view=DestroyCacheView(noise_view); |
| 394 | image_view=DestroyCacheView(image_view); |
| 395 | random_info=DestroyRandomInfoThreadSet(random_info); |
| 396 | if (status == MagickFalse) |
| 397 | noise_image=DestroyImage(noise_image); |
| 398 | return(noise_image); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 403 | % % |
| 404 | % % |
| 405 | % % |
| 406 | % B l u e S h i f t I m a g e % |
| 407 | % % |
| 408 | % % |
| 409 | % % |
| 410 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 411 | % |
| 412 | % BlueShiftImage() mutes the colors of the image to simulate a scene at |
| 413 | % nighttime in the moonlight. |
| 414 | % |
| 415 | % The format of the BlueShiftImage method is: |
| 416 | % |
| 417 | % Image *BlueShiftImage(const Image *image,const double factor, |
| 418 | % ExceptionInfo *exception) |
| 419 | % |
| 420 | % A description of each parameter follows: |
| 421 | % |
| 422 | % o image: the image. |
| 423 | % |
| 424 | % o factor: the shift factor. |
| 425 | % |
| 426 | % o exception: return any errors or warnings in this structure. |
| 427 | % |
| 428 | */ |
| 429 | MagickExport Image *BlueShiftImage(const Image *image,const double factor, |
| 430 | ExceptionInfo *exception) |
| 431 | { |
| 432 | #define BlueShiftImageTag "BlueShift/Image" |
| 433 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 434 | CacheView |
| 435 | *image_view, |
| 436 | *shift_view; |
| 437 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 438 | Image |
| 439 | *shift_image; |
| 440 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 441 | MagickBooleanType |
| 442 | status; |
| 443 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 444 | MagickOffsetType |
| 445 | progress; |
| 446 | |
| 447 | ssize_t |
| 448 | y; |
| 449 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 450 | /* |
| 451 | Allocate blue shift image. |
| 452 | */ |
| 453 | assert(image != (const Image *) NULL); |
| 454 | assert(image->signature == MagickSignature); |
| 455 | if (image->debug != MagickFalse) |
| 456 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 457 | assert(exception != (ExceptionInfo *) NULL); |
| 458 | assert(exception->signature == MagickSignature); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 459 | shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 460 | if (shift_image == (Image *) NULL) |
| 461 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 462 | if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 463 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 464 | shift_image=DestroyImage(shift_image); |
| 465 | return((Image *) NULL); |
| 466 | } |
| 467 | /* |
| 468 | Blue-shift DirectClass image. |
| 469 | */ |
| 470 | status=MagickTrue; |
| 471 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 472 | image_view=AcquireVirtualCacheView(image,exception); |
| 473 | shift_view=AcquireAuthenticCacheView(shift_image,exception); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 474 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 475 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 476 | magick_threads(image,shift_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 477 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 478 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 479 | { |
| 480 | MagickBooleanType |
| 481 | sync; |
| 482 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 483 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 484 | pixel; |
| 485 | |
| 486 | Quantum |
| 487 | quantum; |
| 488 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 489 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 490 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 491 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 492 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 493 | x; |
| 494 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 495 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 496 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 497 | |
| 498 | if (status == MagickFalse) |
| 499 | continue; |
| 500 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 501 | q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1, |
| 502 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 503 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 504 | { |
| 505 | status=MagickFalse; |
| 506 | continue; |
| 507 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 508 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 509 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 510 | quantum=GetPixelRed(image,p); |
| 511 | if (GetPixelGreen(image,p) < quantum) |
| 512 | quantum=GetPixelGreen(image,p); |
| 513 | if (GetPixelBlue(image,p) < quantum) |
| 514 | quantum=GetPixelBlue(image,p); |
| 515 | pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum); |
| 516 | pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum); |
| 517 | pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum); |
| 518 | quantum=GetPixelRed(image,p); |
| 519 | if (GetPixelGreen(image,p) > quantum) |
| 520 | quantum=GetPixelGreen(image,p); |
| 521 | if (GetPixelBlue(image,p) > quantum) |
| 522 | quantum=GetPixelBlue(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 523 | pixel.red=0.5*(pixel.red+factor*quantum); |
| 524 | pixel.green=0.5*(pixel.green+factor*quantum); |
| 525 | pixel.blue=0.5*(pixel.blue+factor*quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 526 | SetPixelRed(shift_image,ClampToQuantum(pixel.red),q); |
| 527 | SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q); |
| 528 | SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 529 | p+=GetPixelChannels(image); |
| 530 | q+=GetPixelChannels(shift_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | } |
| 532 | sync=SyncCacheViewAuthenticPixels(shift_view,exception); |
| 533 | if (sync == MagickFalse) |
| 534 | status=MagickFalse; |
| 535 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 536 | { |
| 537 | MagickBooleanType |
| 538 | proceed; |
| 539 | |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 540 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 541 | #pragma omp critical (MagickCore_BlueShiftImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 542 | #endif |
| 543 | proceed=SetImageProgress(image,BlueShiftImageTag,progress++, |
| 544 | image->rows); |
| 545 | if (proceed == MagickFalse) |
| 546 | status=MagickFalse; |
| 547 | } |
| 548 | } |
| 549 | image_view=DestroyCacheView(image_view); |
| 550 | shift_view=DestroyCacheView(shift_view); |
| 551 | if (status == MagickFalse) |
| 552 | shift_image=DestroyImage(shift_image); |
| 553 | return(shift_image); |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 558 | % % |
| 559 | % % |
| 560 | % % |
| 561 | % C h a r c o a l I m a g e % |
| 562 | % % |
| 563 | % % |
| 564 | % % |
| 565 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 566 | % |
| 567 | % CharcoalImage() creates a new image that is a copy of an existing one with |
| 568 | % the edge highlighted. It allocates the memory necessary for the new Image |
| 569 | % structure and returns a pointer to the new image. |
| 570 | % |
| 571 | % The format of the CharcoalImage method is: |
| 572 | % |
| 573 | % Image *CharcoalImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 574 | % const double sigma,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 575 | % |
| 576 | % A description of each parameter follows: |
| 577 | % |
| 578 | % o image: the image. |
| 579 | % |
| 580 | % o radius: the radius of the pixel neighborhood. |
| 581 | % |
| 582 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 583 | % |
| 584 | % o exception: return any errors or warnings in this structure. |
| 585 | % |
| 586 | */ |
| 587 | MagickExport Image *CharcoalImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 588 | const double sigma,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 589 | { |
| 590 | Image |
| 591 | *charcoal_image, |
| 592 | *clone_image, |
| 593 | *edge_image; |
| 594 | |
| 595 | assert(image != (Image *) NULL); |
| 596 | assert(image->signature == MagickSignature); |
| 597 | if (image->debug != MagickFalse) |
| 598 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 599 | assert(exception != (ExceptionInfo *) NULL); |
| 600 | assert(exception->signature == MagickSignature); |
| 601 | clone_image=CloneImage(image,0,0,MagickTrue,exception); |
| 602 | if (clone_image == (Image *) NULL) |
| 603 | return((Image *) NULL); |
cristy | b2f4d5d | 2013-05-20 20:10:33 +0000 | [diff] [blame] | 604 | edge_image=EdgeImage(clone_image,radius,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | clone_image=DestroyImage(clone_image); |
| 606 | if (edge_image == (Image *) NULL) |
| 607 | return((Image *) NULL); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 608 | charcoal_image=BlurImage(edge_image,radius,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 609 | edge_image=DestroyImage(edge_image); |
| 610 | if (charcoal_image == (Image *) NULL) |
| 611 | return((Image *) NULL); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 612 | (void) NormalizeImage(charcoal_image,exception); |
cristy | b3e7c6c | 2011-07-24 01:43:55 +0000 | [diff] [blame] | 613 | (void) NegateImage(charcoal_image,MagickFalse,exception); |
cristy | e247eff | 2013-04-15 11:50:40 +0000 | [diff] [blame] | 614 | (void) GrayscaleImage(charcoal_image,image->intensity,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 615 | return(charcoal_image); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 620 | % % |
| 621 | % % |
| 622 | % % |
| 623 | % C o l o r i z e I m a g e % |
| 624 | % % |
| 625 | % % |
| 626 | % % |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 628 | % |
| 629 | % ColorizeImage() blends the fill color with each pixel in the image. |
| 630 | % A percentage blend is specified with opacity. Control the application |
| 631 | % of different color components by specifying a different percentage for |
| 632 | % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue). |
| 633 | % |
| 634 | % The format of the ColorizeImage method is: |
| 635 | % |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 636 | % Image *ColorizeImage(const Image *image,const char *blend, |
| 637 | % const PixelInfo *colorize,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 638 | % |
| 639 | % A description of each parameter follows: |
| 640 | % |
| 641 | % o image: the image. |
| 642 | % |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 643 | % o blend: A character string indicating the level of blending as a |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | % percentage. |
| 645 | % |
| 646 | % o colorize: A color value. |
| 647 | % |
| 648 | % o exception: return any errors or warnings in this structure. |
| 649 | % |
| 650 | */ |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 651 | MagickExport Image *ColorizeImage(const Image *image,const char *blend, |
| 652 | const PixelInfo *colorize,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 653 | { |
| 654 | #define ColorizeImageTag "Colorize/Image" |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 655 | #define Colorize(pixel,blend_percentage,colorize) \ |
| 656 | (((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 657 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 658 | CacheView |
| 659 | *colorize_view, |
| 660 | *image_view; |
| 661 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | GeometryInfo |
| 663 | geometry_info; |
| 664 | |
| 665 | Image |
| 666 | *colorize_image; |
| 667 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | MagickBooleanType |
| 669 | status; |
| 670 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 671 | MagickOffsetType |
| 672 | progress; |
| 673 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | MagickStatusType |
| 675 | flags; |
| 676 | |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 677 | PixelInfo |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 678 | blend_percentage; |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 679 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 680 | ssize_t |
| 681 | y; |
| 682 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 683 | /* |
| 684 | Allocate colorized image. |
| 685 | */ |
| 686 | assert(image != (const Image *) NULL); |
| 687 | assert(image->signature == MagickSignature); |
| 688 | if (image->debug != MagickFalse) |
| 689 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 690 | assert(exception != (ExceptionInfo *) NULL); |
| 691 | assert(exception->signature == MagickSignature); |
cristy | 768165d | 2012-04-09 15:01:35 +0000 | [diff] [blame] | 692 | colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
| 693 | exception); |
| 694 | if (colorize_image == (Image *) NULL) |
| 695 | return((Image *) NULL); |
| 696 | if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse) |
| 697 | { |
| 698 | colorize_image=DestroyImage(colorize_image); |
| 699 | return((Image *) NULL); |
| 700 | } |
cristy | f8da9f9 | 2013-04-16 19:52:28 +0000 | [diff] [blame] | 701 | if ((IsGrayColorspace(image->colorspace) != MagickFalse) || |
cristy | 4dab380 | 2013-03-15 22:08:15 +0000 | [diff] [blame] | 702 | (IsPixelInfoGray(colorize) != MagickFalse)) |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 703 | (void) SetImageColorspace(colorize_image,sRGBColorspace,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 704 | if ((colorize_image->alpha_trait != BlendPixelTrait) && |
| 705 | (colorize->alpha_trait == BlendPixelTrait)) |
cristy | 768165d | 2012-04-09 15:01:35 +0000 | [diff] [blame] | 706 | (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception); |
| 707 | if (blend == (const char *) NULL) |
| 708 | return(colorize_image); |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 709 | GetPixelInfo(image,&blend_percentage); |
| 710 | flags=ParseGeometry(blend,&geometry_info); |
| 711 | blend_percentage.red=geometry_info.rho; |
| 712 | blend_percentage.green=geometry_info.rho; |
| 713 | blend_percentage.blue=geometry_info.rho; |
| 714 | blend_percentage.black=geometry_info.rho; |
cristy | 3ee7de5 | 2012-04-14 23:40:47 +0000 | [diff] [blame] | 715 | blend_percentage.alpha=geometry_info.rho; |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 716 | if ((flags & SigmaValue) != 0) |
| 717 | blend_percentage.green=geometry_info.sigma; |
| 718 | if ((flags & XiValue) != 0) |
| 719 | blend_percentage.blue=geometry_info.xi; |
| 720 | if ((flags & PsiValue) != 0) |
| 721 | blend_percentage.alpha=geometry_info.psi; |
| 722 | if (blend_percentage.colorspace == CMYKColorspace) |
| 723 | { |
| 724 | if ((flags & PsiValue) != 0) |
| 725 | blend_percentage.black=geometry_info.psi; |
| 726 | if ((flags & ChiValue) != 0) |
| 727 | blend_percentage.alpha=geometry_info.chi; |
| 728 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 729 | /* |
| 730 | Colorize DirectClass image. |
| 731 | */ |
| 732 | status=MagickTrue; |
| 733 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 734 | image_view=AcquireVirtualCacheView(image,exception); |
| 735 | colorize_view=AcquireAuthenticCacheView(colorize_image,exception); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 736 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 737 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 738 | magick_threads(image,colorize_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 739 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 740 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 741 | { |
| 742 | MagickBooleanType |
| 743 | sync; |
| 744 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 745 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 746 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 748 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 749 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 750 | |
cristy | 4a37c62 | 2012-08-23 18:47:56 +0000 | [diff] [blame] | 751 | register ssize_t |
| 752 | x; |
| 753 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 754 | if (status == MagickFalse) |
| 755 | continue; |
| 756 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 757 | q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1, |
| 758 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 759 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 760 | { |
| 761 | status=MagickFalse; |
| 762 | continue; |
| 763 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 764 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 765 | { |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 766 | register ssize_t |
| 767 | i; |
| 768 | |
| 769 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 770 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 771 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 772 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 773 | PixelTrait colorize_traits=GetPixelChannelTraits(colorize_image, |
| 774 | channel); |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 775 | if ((traits == UndefinedPixelTrait) || |
| 776 | (colorize_traits == UndefinedPixelTrait)) |
cristy | d680338 | 2012-04-10 01:41:25 +0000 | [diff] [blame] | 777 | continue; |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 778 | if (((colorize_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 779 | (GetPixelReadMask(image,p) == 0)) |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 780 | { |
| 781 | SetPixelChannel(colorize_image,channel,p[i],q); |
| 782 | continue; |
| 783 | } |
cristy | b711323 | 2013-02-15 00:35:19 +0000 | [diff] [blame] | 784 | SetPixelChannel(colorize_image,channel,ClampToQuantum(Colorize(p[i], |
| 785 | GetPixelInfoChannel(&blend_percentage,channel),GetPixelInfoChannel( |
| 786 | colorize,channel))),q); |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 787 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 788 | p+=GetPixelChannels(image); |
| 789 | q+=GetPixelChannels(colorize_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 790 | } |
| 791 | sync=SyncCacheViewAuthenticPixels(colorize_view,exception); |
| 792 | if (sync == MagickFalse) |
| 793 | status=MagickFalse; |
| 794 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 795 | { |
| 796 | MagickBooleanType |
| 797 | proceed; |
| 798 | |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 799 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 800 | #pragma omp critical (MagickCore_ColorizeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 801 | #endif |
| 802 | proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows); |
| 803 | if (proceed == MagickFalse) |
| 804 | status=MagickFalse; |
| 805 | } |
| 806 | } |
| 807 | image_view=DestroyCacheView(image_view); |
| 808 | colorize_view=DestroyCacheView(colorize_view); |
| 809 | if (status == MagickFalse) |
| 810 | colorize_image=DestroyImage(colorize_image); |
| 811 | return(colorize_image); |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 816 | % % |
| 817 | % % |
| 818 | % % |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 819 | % C o l o r M a t r i x I m a g e % |
| 820 | % % |
| 821 | % % |
| 822 | % % |
| 823 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 824 | % |
| 825 | % ColorMatrixImage() applies color transformation to an image. This method |
| 826 | % permits saturation changes, hue rotation, luminance to alpha, and various |
| 827 | % other effects. Although variable-sized transformation matrices can be used, |
| 828 | % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA |
| 829 | % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash |
| 830 | % except offsets are in column 6 rather than 5 (in support of CMYKA images) |
| 831 | % and offsets are normalized (divide Flash offset by 255). |
| 832 | % |
| 833 | % The format of the ColorMatrixImage method is: |
| 834 | % |
| 835 | % Image *ColorMatrixImage(const Image *image, |
| 836 | % const KernelInfo *color_matrix,ExceptionInfo *exception) |
| 837 | % |
| 838 | % A description of each parameter follows: |
| 839 | % |
| 840 | % o image: the image. |
| 841 | % |
| 842 | % o color_matrix: the color matrix. |
| 843 | % |
| 844 | % o exception: return any errors or warnings in this structure. |
| 845 | % |
| 846 | */ |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 847 | /* FUTURE: modify to make use of a MagickMatrix Mutliply function |
| 848 | That should be provided in "matrix.c" |
| 849 | (ASIDE: actually distorts should do this too but currently doesn't) |
| 850 | */ |
| 851 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 852 | MagickExport Image *ColorMatrixImage(const Image *image, |
| 853 | const KernelInfo *color_matrix,ExceptionInfo *exception) |
| 854 | { |
| 855 | #define ColorMatrixImageTag "ColorMatrix/Image" |
| 856 | |
| 857 | CacheView |
| 858 | *color_view, |
| 859 | *image_view; |
| 860 | |
| 861 | double |
| 862 | ColorMatrix[6][6] = |
| 863 | { |
| 864 | { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, |
| 865 | { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }, |
| 866 | { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 }, |
| 867 | { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, |
| 868 | { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 }, |
| 869 | { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 } |
| 870 | }; |
| 871 | |
| 872 | Image |
| 873 | *color_image; |
| 874 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 875 | MagickBooleanType |
| 876 | status; |
| 877 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 878 | MagickOffsetType |
| 879 | progress; |
| 880 | |
| 881 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 882 | i; |
| 883 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 884 | ssize_t |
| 885 | u, |
| 886 | v, |
| 887 | y; |
| 888 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 889 | /* |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 890 | Map given color_matrix, into a 6x6 matrix RGBKA and a constant |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 891 | */ |
| 892 | assert(image != (Image *) NULL); |
| 893 | assert(image->signature == MagickSignature); |
| 894 | if (image->debug != MagickFalse) |
| 895 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 896 | assert(exception != (ExceptionInfo *) NULL); |
| 897 | assert(exception->signature == MagickSignature); |
| 898 | i=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 899 | for (v=0; v < (ssize_t) color_matrix->height; v++) |
| 900 | for (u=0; u < (ssize_t) color_matrix->width; u++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 901 | { |
| 902 | if ((v < 6) && (u < 6)) |
| 903 | ColorMatrix[v][u]=color_matrix->values[i]; |
| 904 | i++; |
| 905 | } |
| 906 | /* |
| 907 | Initialize color image. |
| 908 | */ |
cristy | 12550e6 | 2010-06-07 12:46:40 +0000 | [diff] [blame] | 909 | color_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 910 | if (color_image == (Image *) NULL) |
| 911 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 912 | if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 913 | { |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 914 | color_image=DestroyImage(color_image); |
| 915 | return((Image *) NULL); |
| 916 | } |
| 917 | if (image->debug != MagickFalse) |
| 918 | { |
| 919 | char |
| 920 | format[MaxTextExtent], |
| 921 | *message; |
| 922 | |
| 923 | (void) LogMagickEvent(TransformEvent,GetMagickModule(), |
| 924 | " ColorMatrix image with color matrix:"); |
| 925 | message=AcquireString(""); |
| 926 | for (v=0; v < 6; v++) |
| 927 | { |
| 928 | *message='\0'; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 929 | (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 930 | (void) ConcatenateString(&message,format); |
| 931 | for (u=0; u < 6; u++) |
| 932 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 933 | (void) FormatLocaleString(format,MaxTextExtent,"%+f ", |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 934 | ColorMatrix[v][u]); |
| 935 | (void) ConcatenateString(&message,format); |
| 936 | } |
| 937 | (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message); |
| 938 | } |
| 939 | message=DestroyString(message); |
| 940 | } |
| 941 | /* |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 942 | Apply the ColorMatrix to image. |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 943 | */ |
| 944 | status=MagickTrue; |
| 945 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 946 | image_view=AcquireVirtualCacheView(image,exception); |
| 947 | color_view=AcquireAuthenticCacheView(color_image,exception); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 948 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 949 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 950 | magick_threads(image,color_image,image->rows,1) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 951 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 952 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 953 | { |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 954 | PixelInfo |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 955 | pixel; |
| 956 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 957 | register const Quantum |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 958 | *restrict p; |
| 959 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 960 | register Quantum |
| 961 | *restrict q; |
| 962 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 963 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 964 | x; |
| 965 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 966 | if (status == MagickFalse) |
| 967 | continue; |
| 968 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 969 | q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1, |
| 970 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 971 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 972 | { |
| 973 | status=MagickFalse; |
| 974 | continue; |
| 975 | } |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 976 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 977 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 978 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 979 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 980 | v; |
| 981 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 982 | size_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 983 | height; |
| 984 | |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 985 | GetPixelInfoPixel(image,p,&pixel); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 986 | height=color_matrix->height > 6 ? 6UL : color_matrix->height; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 987 | for (v=0; v < (ssize_t) height; v++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 988 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 989 | double |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 990 | sum; |
| 991 | |
| 992 | sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 993 | GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 994 | if (image->colorspace == CMYKColorspace) |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 995 | sum+=ColorMatrix[v][3]*GetPixelBlack(image,p); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 996 | if (image->alpha_trait == BlendPixelTrait) |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 997 | sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p); |
| 998 | sum+=QuantumRange*ColorMatrix[v][5]; |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 999 | switch (v) |
| 1000 | { |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 1001 | case 0: pixel.red=sum; break; |
| 1002 | case 1: pixel.green=sum; break; |
| 1003 | case 2: pixel.blue=sum; break; |
| 1004 | case 3: pixel.black=sum; break; |
| 1005 | case 4: pixel.alpha=sum; break; |
| 1006 | default: break; |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 1007 | } |
| 1008 | } |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 1009 | SetPixelInfoPixel(color_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1010 | p+=GetPixelChannels(image); |
| 1011 | q+=GetPixelChannels(color_image); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 1012 | } |
| 1013 | if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse) |
| 1014 | status=MagickFalse; |
| 1015 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1016 | { |
| 1017 | MagickBooleanType |
| 1018 | proceed; |
| 1019 | |
| 1020 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 1021 | #pragma omp critical (MagickCore_ColorMatrixImage) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 1022 | #endif |
| 1023 | proceed=SetImageProgress(image,ColorMatrixImageTag,progress++, |
| 1024 | image->rows); |
| 1025 | if (proceed == MagickFalse) |
| 1026 | status=MagickFalse; |
| 1027 | } |
| 1028 | } |
| 1029 | color_view=DestroyCacheView(color_view); |
| 1030 | image_view=DestroyCacheView(image_view); |
| 1031 | if (status == MagickFalse) |
| 1032 | color_image=DestroyImage(color_image); |
| 1033 | return(color_image); |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1038 | % % |
| 1039 | % % |
| 1040 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1041 | + D e s t r o y F x I n f o % |
| 1042 | % % |
| 1043 | % % |
| 1044 | % % |
| 1045 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1046 | % |
| 1047 | % DestroyFxInfo() deallocates memory associated with an FxInfo structure. |
| 1048 | % |
| 1049 | % The format of the DestroyFxInfo method is: |
| 1050 | % |
| 1051 | % ImageInfo *DestroyFxInfo(ImageInfo *fx_info) |
| 1052 | % |
| 1053 | % A description of each parameter follows: |
| 1054 | % |
| 1055 | % o fx_info: the fx info. |
| 1056 | % |
| 1057 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1058 | MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1059 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1060 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1061 | i; |
| 1062 | |
| 1063 | fx_info->exception=DestroyExceptionInfo(fx_info->exception); |
| 1064 | fx_info->expression=DestroyString(fx_info->expression); |
| 1065 | fx_info->symbols=DestroySplayTree(fx_info->symbols); |
| 1066 | fx_info->colors=DestroySplayTree(fx_info->colors); |
cristy | 0ea377f | 2011-03-24 00:54:19 +0000 | [diff] [blame] | 1067 | for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--) |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 1068 | fx_info->view[i]=DestroyCacheView(fx_info->view[i]); |
| 1069 | fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1070 | fx_info->random_info=DestroyRandomInfo(fx_info->random_info); |
| 1071 | fx_info=(FxInfo *) RelinquishMagickMemory(fx_info); |
| 1072 | return(fx_info); |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1077 | % % |
| 1078 | % % |
| 1079 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1080 | + 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 % |
| 1081 | % % |
| 1082 | % % |
| 1083 | % % |
| 1084 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1085 | % |
| 1086 | % FxEvaluateChannelExpression() evaluates an expression and returns the |
| 1087 | % results. |
| 1088 | % |
| 1089 | % The format of the FxEvaluateExpression method is: |
| 1090 | % |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1091 | % double FxEvaluateChannelExpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1092 | % const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1093 | % double *alpha,Exceptioninfo *exception) |
| 1094 | % double FxEvaluateExpression(FxInfo *fx_info, |
| 1095 | % double *alpha,Exceptioninfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1096 | % |
| 1097 | % A description of each parameter follows: |
| 1098 | % |
| 1099 | % o fx_info: the fx info. |
| 1100 | % |
| 1101 | % o channel: the channel. |
| 1102 | % |
| 1103 | % o x,y: the pixel position. |
| 1104 | % |
| 1105 | % o alpha: the result. |
| 1106 | % |
| 1107 | % o exception: return any errors or warnings in this structure. |
| 1108 | % |
| 1109 | */ |
| 1110 | |
cristy | 351842f | 2010-03-07 15:27:38 +0000 | [diff] [blame] | 1111 | static inline double MagickMax(const double x,const double y) |
| 1112 | { |
| 1113 | if (x > y) |
| 1114 | return(x); |
| 1115 | return(y); |
| 1116 | } |
| 1117 | |
| 1118 | static inline double MagickMin(const double x,const double y) |
| 1119 | { |
| 1120 | if (x < y) |
| 1121 | return(x); |
| 1122 | return(y); |
| 1123 | } |
| 1124 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1125 | static double FxChannelStatistics(FxInfo *fx_info,Image *image, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1126 | PixelChannel channel,const char *symbol,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1127 | { |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1128 | ChannelType |
| 1129 | channel_mask; |
| 1130 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1131 | char |
| 1132 | key[MaxTextExtent], |
| 1133 | statistic[MaxTextExtent]; |
| 1134 | |
| 1135 | const char |
| 1136 | *value; |
| 1137 | |
| 1138 | register const char |
| 1139 | *p; |
| 1140 | |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1141 | channel_mask=UndefinedChannel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1142 | for (p=symbol; (*p != '.') && (*p != '\0'); p++) ; |
| 1143 | if (*p == '.') |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1144 | { |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1145 | ssize_t |
| 1146 | option; |
| 1147 | |
| 1148 | option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1); |
| 1149 | if (option >= 0) |
| 1150 | { |
| 1151 | channel=(PixelChannel) option; |
| 1152 | channel_mask=(ChannelType) (channel_mask | (1 << channel)); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 1153 | SetPixelChannelMask(image,channel_mask); |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1154 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1155 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1156 | (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1157 | (double) channel,symbol); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1158 | value=(const char *) GetValueFromSplayTree(fx_info->symbols,key); |
| 1159 | if (value != (const char *) NULL) |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1160 | { |
| 1161 | if (channel_mask != UndefinedChannel) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 1162 | SetPixelChannelMask(image,channel_mask); |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1163 | return(QuantumScale*StringToDouble(value,(char **) NULL)); |
| 1164 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1165 | (void) DeleteNodeFromSplayTree(fx_info->symbols,key); |
| 1166 | if (LocaleNCompare(symbol,"depth",5) == 0) |
| 1167 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1168 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1169 | depth; |
| 1170 | |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 1171 | depth=GetImageDepth(image,exception); |
| 1172 | (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1173 | } |
| 1174 | if (LocaleNCompare(symbol,"kurtosis",8) == 0) |
| 1175 | { |
| 1176 | double |
| 1177 | kurtosis, |
| 1178 | skewness; |
| 1179 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1180 | (void) GetImageKurtosis(image,&kurtosis,&skewness,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1181 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1182 | } |
| 1183 | if (LocaleNCompare(symbol,"maxima",6) == 0) |
| 1184 | { |
| 1185 | double |
| 1186 | maxima, |
| 1187 | minima; |
| 1188 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1189 | (void) GetImageRange(image,&minima,&maxima,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1190 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1191 | } |
| 1192 | if (LocaleNCompare(symbol,"mean",4) == 0) |
| 1193 | { |
| 1194 | double |
| 1195 | mean, |
| 1196 | standard_deviation; |
| 1197 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1198 | (void) GetImageMean(image,&mean,&standard_deviation,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1199 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1200 | } |
| 1201 | if (LocaleNCompare(symbol,"minima",6) == 0) |
| 1202 | { |
| 1203 | double |
| 1204 | maxima, |
| 1205 | minima; |
| 1206 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1207 | (void) GetImageRange(image,&minima,&maxima,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1208 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1209 | } |
| 1210 | if (LocaleNCompare(symbol,"skewness",8) == 0) |
| 1211 | { |
| 1212 | double |
| 1213 | kurtosis, |
| 1214 | skewness; |
| 1215 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1216 | (void) GetImageKurtosis(image,&kurtosis,&skewness,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1217 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1218 | } |
| 1219 | if (LocaleNCompare(symbol,"standard_deviation",18) == 0) |
| 1220 | { |
| 1221 | double |
| 1222 | mean, |
| 1223 | standard_deviation; |
| 1224 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1225 | (void) GetImageMean(image,&mean,&standard_deviation,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1226 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1227 | standard_deviation); |
| 1228 | } |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1229 | if (channel_mask != UndefinedChannel) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 1230 | SetPixelChannelMask(image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1231 | (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key), |
| 1232 | ConstantString(statistic)); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1233 | return(QuantumScale*StringToDouble(statistic,(char **) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1236 | static double |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1237 | FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1238 | const ssize_t,const char *,double *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1239 | |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 1240 | static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta) |
| 1241 | { |
| 1242 | if (beta != 0) |
| 1243 | return(FxGCD(beta,alpha % beta)); |
| 1244 | return(alpha); |
| 1245 | } |
| 1246 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1247 | static inline const char *FxSubexpression(const char *expression, |
| 1248 | ExceptionInfo *exception) |
| 1249 | { |
| 1250 | const char |
| 1251 | *subexpression; |
| 1252 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1253 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1254 | level; |
| 1255 | |
| 1256 | level=0; |
| 1257 | subexpression=expression; |
| 1258 | while ((*subexpression != '\0') && |
| 1259 | ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL))) |
| 1260 | { |
| 1261 | if (strchr("(",(int) *subexpression) != (char *) NULL) |
| 1262 | level++; |
| 1263 | else |
| 1264 | if (strchr(")",(int) *subexpression) != (char *) NULL) |
| 1265 | level--; |
| 1266 | subexpression++; |
| 1267 | } |
| 1268 | if (*subexpression == '\0') |
| 1269 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1270 | "UnbalancedParenthesis","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1271 | return(subexpression); |
| 1272 | } |
| 1273 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1274 | static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel, |
cristy | e85007d | 2010-06-06 22:51:36 +0000 | [diff] [blame] | 1275 | const ssize_t x,const ssize_t y,const char *expression, |
| 1276 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1277 | { |
| 1278 | char |
| 1279 | *q, |
| 1280 | subexpression[MaxTextExtent], |
| 1281 | symbol[MaxTextExtent]; |
| 1282 | |
| 1283 | const char |
| 1284 | *p, |
| 1285 | *value; |
| 1286 | |
| 1287 | Image |
| 1288 | *image; |
| 1289 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1290 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1291 | pixel; |
| 1292 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1293 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1294 | alpha, |
| 1295 | beta; |
| 1296 | |
| 1297 | PointInfo |
| 1298 | point; |
| 1299 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1300 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1301 | i; |
| 1302 | |
| 1303 | size_t |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1304 | length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1305 | level; |
| 1306 | |
| 1307 | p=expression; |
| 1308 | i=GetImageIndexInList(fx_info->images); |
| 1309 | level=0; |
| 1310 | point.x=(double) x; |
| 1311 | point.y=(double) y; |
| 1312 | if (isalpha((int) *(p+1)) == 0) |
| 1313 | { |
| 1314 | if (strchr("suv",(int) *p) != (char *) NULL) |
| 1315 | { |
| 1316 | switch (*p) |
| 1317 | { |
| 1318 | case 's': |
| 1319 | default: |
| 1320 | { |
| 1321 | i=GetImageIndexInList(fx_info->images); |
| 1322 | break; |
| 1323 | } |
| 1324 | case 'u': i=0; break; |
| 1325 | case 'v': i=1; break; |
| 1326 | } |
| 1327 | p++; |
| 1328 | if (*p == '[') |
| 1329 | { |
| 1330 | level++; |
| 1331 | q=subexpression; |
| 1332 | for (p++; *p != '\0'; ) |
| 1333 | { |
| 1334 | if (*p == '[') |
| 1335 | level++; |
| 1336 | else |
| 1337 | if (*p == ']') |
| 1338 | { |
| 1339 | level--; |
| 1340 | if (level == 0) |
| 1341 | break; |
| 1342 | } |
| 1343 | *q++=(*p++); |
| 1344 | } |
| 1345 | *q='\0'; |
| 1346 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1347 | &beta,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1348 | i=(ssize_t) (alpha+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1349 | p++; |
| 1350 | } |
| 1351 | if (*p == '.') |
| 1352 | p++; |
| 1353 | } |
cristy | ea20ca8 | 2013-05-29 11:39:57 +0000 | [diff] [blame] | 1354 | if ((*p == 'p') && (isalpha((int) *(p+1)) == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1355 | { |
| 1356 | p++; |
| 1357 | if (*p == '{') |
| 1358 | { |
| 1359 | level++; |
| 1360 | q=subexpression; |
| 1361 | for (p++; *p != '\0'; ) |
| 1362 | { |
| 1363 | if (*p == '{') |
| 1364 | level++; |
| 1365 | else |
| 1366 | if (*p == '}') |
| 1367 | { |
| 1368 | level--; |
| 1369 | if (level == 0) |
| 1370 | break; |
| 1371 | } |
| 1372 | *q++=(*p++); |
| 1373 | } |
| 1374 | *q='\0'; |
| 1375 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1376 | &beta,exception); |
| 1377 | point.x=alpha; |
| 1378 | point.y=beta; |
| 1379 | p++; |
| 1380 | } |
| 1381 | else |
| 1382 | if (*p == '[') |
| 1383 | { |
| 1384 | level++; |
| 1385 | q=subexpression; |
| 1386 | for (p++; *p != '\0'; ) |
| 1387 | { |
| 1388 | if (*p == '[') |
| 1389 | level++; |
| 1390 | else |
| 1391 | if (*p == ']') |
| 1392 | { |
| 1393 | level--; |
| 1394 | if (level == 0) |
| 1395 | break; |
| 1396 | } |
| 1397 | *q++=(*p++); |
| 1398 | } |
| 1399 | *q='\0'; |
| 1400 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1401 | &beta,exception); |
| 1402 | point.x+=alpha; |
| 1403 | point.y+=beta; |
| 1404 | p++; |
| 1405 | } |
| 1406 | if (*p == '.') |
| 1407 | p++; |
| 1408 | } |
| 1409 | } |
| 1410 | length=GetImageListLength(fx_info->images); |
| 1411 | while (i < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1412 | i+=(ssize_t) length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1413 | i%=length; |
| 1414 | image=GetImageFromList(fx_info->images,i); |
| 1415 | if (image == (Image *) NULL) |
| 1416 | { |
| 1417 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1418 | "NoSuchImage","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1419 | return(0.0); |
| 1420 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1421 | GetPixelInfo(image,&pixel); |
| 1422 | (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate, |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 1423 | point.x,point.y,&pixel,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1424 | if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) && |
cristy | ba21340 | 2013-06-28 14:05:12 +0000 | [diff] [blame] | 1425 | (LocaleCompare(p,"luma") != 0) && (LocaleCompare(p,"luminance") != 0) && |
| 1426 | (LocaleCompare(p,"hue") != 0) && (LocaleCompare(p,"saturation") != 0) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1427 | (LocaleCompare(p,"lightness") != 0)) |
| 1428 | { |
| 1429 | char |
| 1430 | name[MaxTextExtent]; |
| 1431 | |
| 1432 | (void) CopyMagickString(name,p,MaxTextExtent); |
| 1433 | for (q=name+(strlen(name)-1); q > name; q--) |
| 1434 | { |
| 1435 | if (*q == ')') |
| 1436 | break; |
| 1437 | if (*q == '.') |
| 1438 | { |
| 1439 | *q='\0'; |
| 1440 | break; |
| 1441 | } |
| 1442 | } |
| 1443 | if ((strlen(name) > 2) && |
| 1444 | (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL)) |
| 1445 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1446 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1447 | *color; |
| 1448 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1449 | color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name); |
| 1450 | if (color != (PixelInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1451 | { |
| 1452 | pixel=(*color); |
| 1453 | p+=strlen(name); |
| 1454 | } |
| 1455 | else |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1456 | { |
| 1457 | MagickBooleanType |
| 1458 | status; |
| 1459 | |
| 1460 | status=QueryColorCompliance(name,AllCompliance,&pixel, |
| 1461 | fx_info->exception); |
| 1462 | if (status != MagickFalse) |
| 1463 | { |
| 1464 | (void) AddValueToSplayTree(fx_info->colors,ConstantString( |
| 1465 | name),ClonePixelInfo(&pixel)); |
| 1466 | p+=strlen(name); |
| 1467 | } |
| 1468 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | (void) CopyMagickString(symbol,p,MaxTextExtent); |
| 1472 | StripString(symbol); |
| 1473 | if (*symbol == '\0') |
| 1474 | { |
| 1475 | switch (channel) |
| 1476 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1477 | case RedPixelChannel: return(QuantumScale*pixel.red); |
| 1478 | case GreenPixelChannel: return(QuantumScale*pixel.green); |
| 1479 | case BluePixelChannel: return(QuantumScale*pixel.blue); |
| 1480 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1481 | { |
| 1482 | if (image->colorspace != CMYKColorspace) |
| 1483 | { |
| 1484 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1485 | ImageError,"ColorSeparatedImageRequired","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1486 | image->filename); |
| 1487 | return(0.0); |
| 1488 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1489 | return(QuantumScale*pixel.black); |
| 1490 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1491 | case AlphaPixelChannel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1492 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1493 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1494 | alpha; |
| 1495 | |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 1496 | if (pixel.alpha_trait != BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1497 | return(1.0); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1498 | alpha=(double) (QuantumScale*pixel.alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1499 | return(alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1500 | } |
cristy | a382aca | 2011-12-06 18:22:48 +0000 | [diff] [blame] | 1501 | case IndexPixelChannel: |
| 1502 | return(0.0); |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 1503 | case IntensityPixelChannel: |
cristy | f364ed4 | 2010-12-15 01:54:43 +0000 | [diff] [blame] | 1504 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1505 | return(QuantumScale*GetPixelInfoIntensity(&pixel)); |
cristy | f364ed4 | 2010-12-15 01:54:43 +0000 | [diff] [blame] | 1506 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1507 | default: |
| 1508 | break; |
| 1509 | } |
| 1510 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1511 | "UnableToParseExpression","`%s'",p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1512 | return(0.0); |
| 1513 | } |
| 1514 | switch (*symbol) |
| 1515 | { |
| 1516 | case 'A': |
| 1517 | case 'a': |
| 1518 | { |
| 1519 | if (LocaleCompare(symbol,"a") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1520 | return((double) (QuantumScale*pixel.alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1521 | break; |
| 1522 | } |
| 1523 | case 'B': |
| 1524 | case 'b': |
| 1525 | { |
| 1526 | if (LocaleCompare(symbol,"b") == 0) |
| 1527 | return(QuantumScale*pixel.blue); |
| 1528 | break; |
| 1529 | } |
| 1530 | case 'C': |
| 1531 | case 'c': |
| 1532 | { |
| 1533 | if (LocaleNCompare(symbol,"channel",7) == 0) |
| 1534 | { |
| 1535 | GeometryInfo |
| 1536 | channel_info; |
| 1537 | |
| 1538 | MagickStatusType |
| 1539 | flags; |
| 1540 | |
| 1541 | flags=ParseGeometry(symbol+7,&channel_info); |
| 1542 | if (image->colorspace == CMYKColorspace) |
| 1543 | switch (channel) |
| 1544 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1545 | case CyanPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1546 | { |
| 1547 | if ((flags & RhoValue) == 0) |
| 1548 | return(0.0); |
| 1549 | return(channel_info.rho); |
| 1550 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1551 | case MagentaPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1552 | { |
| 1553 | if ((flags & SigmaValue) == 0) |
| 1554 | return(0.0); |
| 1555 | return(channel_info.sigma); |
| 1556 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1557 | case YellowPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1558 | { |
| 1559 | if ((flags & XiValue) == 0) |
| 1560 | return(0.0); |
| 1561 | return(channel_info.xi); |
| 1562 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1563 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1564 | { |
| 1565 | if ((flags & PsiValue) == 0) |
| 1566 | return(0.0); |
| 1567 | return(channel_info.psi); |
| 1568 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1569 | case AlphaPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1570 | { |
| 1571 | if ((flags & ChiValue) == 0) |
| 1572 | return(0.0); |
| 1573 | return(channel_info.chi); |
| 1574 | } |
| 1575 | default: |
| 1576 | return(0.0); |
| 1577 | } |
| 1578 | switch (channel) |
| 1579 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1580 | case RedPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1581 | { |
| 1582 | if ((flags & RhoValue) == 0) |
| 1583 | return(0.0); |
| 1584 | return(channel_info.rho); |
| 1585 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1586 | case GreenPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1587 | { |
| 1588 | if ((flags & SigmaValue) == 0) |
| 1589 | return(0.0); |
| 1590 | return(channel_info.sigma); |
| 1591 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1592 | case BluePixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1593 | { |
| 1594 | if ((flags & XiValue) == 0) |
| 1595 | return(0.0); |
| 1596 | return(channel_info.xi); |
| 1597 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1598 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1599 | { |
| 1600 | if ((flags & ChiValue) == 0) |
| 1601 | return(0.0); |
| 1602 | return(channel_info.chi); |
| 1603 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1604 | case AlphaPixelChannel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1605 | { |
| 1606 | if ((flags & PsiValue) == 0) |
| 1607 | return(0.0); |
| 1608 | return(channel_info.psi); |
| 1609 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1610 | default: |
| 1611 | return(0.0); |
| 1612 | } |
| 1613 | return(0.0); |
| 1614 | } |
| 1615 | if (LocaleCompare(symbol,"c") == 0) |
| 1616 | return(QuantumScale*pixel.red); |
| 1617 | break; |
| 1618 | } |
| 1619 | case 'D': |
| 1620 | case 'd': |
| 1621 | { |
| 1622 | if (LocaleNCompare(symbol,"depth",5) == 0) |
| 1623 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1624 | break; |
| 1625 | } |
| 1626 | case 'G': |
| 1627 | case 'g': |
| 1628 | { |
| 1629 | if (LocaleCompare(symbol,"g") == 0) |
| 1630 | return(QuantumScale*pixel.green); |
| 1631 | break; |
| 1632 | } |
| 1633 | case 'K': |
| 1634 | case 'k': |
| 1635 | { |
| 1636 | if (LocaleNCompare(symbol,"kurtosis",8) == 0) |
| 1637 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1638 | if (LocaleCompare(symbol,"k") == 0) |
| 1639 | { |
| 1640 | if (image->colorspace != CMYKColorspace) |
| 1641 | { |
| 1642 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1643 | OptionError,"ColorSeparatedImageRequired","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1644 | image->filename); |
| 1645 | return(0.0); |
| 1646 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1647 | return(QuantumScale*pixel.black); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1648 | } |
| 1649 | break; |
| 1650 | } |
| 1651 | case 'H': |
| 1652 | case 'h': |
| 1653 | { |
| 1654 | if (LocaleCompare(symbol,"h") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1655 | return((double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1656 | if (LocaleCompare(symbol,"hue") == 0) |
| 1657 | { |
| 1658 | double |
| 1659 | hue, |
| 1660 | lightness, |
| 1661 | saturation; |
| 1662 | |
cristy | 0a39a5c | 2012-06-27 12:51:45 +0000 | [diff] [blame] | 1663 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1664 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1665 | return(hue); |
| 1666 | } |
| 1667 | break; |
| 1668 | } |
| 1669 | case 'I': |
| 1670 | case 'i': |
| 1671 | { |
| 1672 | if ((LocaleCompare(symbol,"image.depth") == 0) || |
| 1673 | (LocaleCompare(symbol,"image.minima") == 0) || |
| 1674 | (LocaleCompare(symbol,"image.maxima") == 0) || |
| 1675 | (LocaleCompare(symbol,"image.mean") == 0) || |
| 1676 | (LocaleCompare(symbol,"image.kurtosis") == 0) || |
| 1677 | (LocaleCompare(symbol,"image.skewness") == 0) || |
| 1678 | (LocaleCompare(symbol,"image.standard_deviation") == 0)) |
| 1679 | return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception)); |
| 1680 | if (LocaleCompare(symbol,"image.resolution.x") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1681 | return(image->resolution.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1682 | if (LocaleCompare(symbol,"image.resolution.y") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1683 | return(image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1684 | if (LocaleCompare(symbol,"intensity") == 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1685 | return(QuantumScale*GetPixelInfoIntensity(&pixel)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1686 | if (LocaleCompare(symbol,"i") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1687 | return((double) x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1688 | break; |
| 1689 | } |
| 1690 | case 'J': |
| 1691 | case 'j': |
| 1692 | { |
| 1693 | if (LocaleCompare(symbol,"j") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1694 | return((double) y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1695 | break; |
| 1696 | } |
| 1697 | case 'L': |
| 1698 | case 'l': |
| 1699 | { |
| 1700 | if (LocaleCompare(symbol,"lightness") == 0) |
| 1701 | { |
| 1702 | double |
| 1703 | hue, |
| 1704 | lightness, |
| 1705 | saturation; |
| 1706 | |
cristy | 0a39a5c | 2012-06-27 12:51:45 +0000 | [diff] [blame] | 1707 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1708 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1709 | return(lightness); |
| 1710 | } |
cristy | d3d2a27 | 2013-06-24 16:09:41 +0000 | [diff] [blame] | 1711 | if (LocaleCompare(symbol,"luma") == 0) |
| 1712 | { |
| 1713 | double |
| 1714 | luma; |
| 1715 | |
| 1716 | luma=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue; |
| 1717 | return(QuantumScale*luma); |
| 1718 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1719 | if (LocaleCompare(symbol,"luminance") == 0) |
| 1720 | { |
| 1721 | double |
| 1722 | luminence; |
| 1723 | |
cristy | d3d2a27 | 2013-06-24 16:09:41 +0000 | [diff] [blame] | 1724 | luminence=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1725 | return(QuantumScale*luminence); |
| 1726 | } |
| 1727 | break; |
| 1728 | } |
| 1729 | case 'M': |
| 1730 | case 'm': |
| 1731 | { |
| 1732 | if (LocaleNCompare(symbol,"maxima",6) == 0) |
| 1733 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1734 | if (LocaleNCompare(symbol,"mean",4) == 0) |
| 1735 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1736 | if (LocaleNCompare(symbol,"minima",6) == 0) |
| 1737 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1738 | if (LocaleCompare(symbol,"m") == 0) |
| 1739 | return(QuantumScale*pixel.blue); |
| 1740 | break; |
| 1741 | } |
| 1742 | case 'N': |
| 1743 | case 'n': |
| 1744 | { |
| 1745 | if (LocaleCompare(symbol,"n") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1746 | return((double) GetImageListLength(fx_info->images)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1747 | break; |
| 1748 | } |
| 1749 | case 'O': |
| 1750 | case 'o': |
| 1751 | { |
| 1752 | if (LocaleCompare(symbol,"o") == 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1753 | return(QuantumScale*pixel.alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1754 | break; |
| 1755 | } |
| 1756 | case 'P': |
| 1757 | case 'p': |
| 1758 | { |
| 1759 | if (LocaleCompare(symbol,"page.height") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1760 | return((double) image->page.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1761 | if (LocaleCompare(symbol,"page.width") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1762 | return((double) image->page.width); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1763 | if (LocaleCompare(symbol,"page.x") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1764 | return((double) image->page.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1765 | if (LocaleCompare(symbol,"page.y") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1766 | return((double) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1767 | break; |
| 1768 | } |
| 1769 | case 'R': |
| 1770 | case 'r': |
| 1771 | { |
| 1772 | if (LocaleCompare(symbol,"resolution.x") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1773 | return(image->resolution.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1774 | if (LocaleCompare(symbol,"resolution.y") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1775 | return(image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1776 | if (LocaleCompare(symbol,"r") == 0) |
| 1777 | return(QuantumScale*pixel.red); |
| 1778 | break; |
| 1779 | } |
| 1780 | case 'S': |
| 1781 | case 's': |
| 1782 | { |
| 1783 | if (LocaleCompare(symbol,"saturation") == 0) |
| 1784 | { |
| 1785 | double |
| 1786 | hue, |
| 1787 | lightness, |
| 1788 | saturation; |
| 1789 | |
cristy | 0a39a5c | 2012-06-27 12:51:45 +0000 | [diff] [blame] | 1790 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1791 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1792 | return(saturation); |
| 1793 | } |
| 1794 | if (LocaleNCompare(symbol,"skewness",8) == 0) |
| 1795 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1796 | if (LocaleNCompare(symbol,"standard_deviation",18) == 0) |
| 1797 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1798 | break; |
| 1799 | } |
| 1800 | case 'T': |
| 1801 | case 't': |
| 1802 | { |
| 1803 | if (LocaleCompare(symbol,"t") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1804 | return((double) GetImageIndexInList(fx_info->images)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1805 | break; |
| 1806 | } |
| 1807 | case 'W': |
| 1808 | case 'w': |
| 1809 | { |
| 1810 | if (LocaleCompare(symbol,"w") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1811 | return((double) image->columns); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | } |
| 1814 | case 'Y': |
| 1815 | case 'y': |
| 1816 | { |
| 1817 | if (LocaleCompare(symbol,"y") == 0) |
| 1818 | return(QuantumScale*pixel.green); |
| 1819 | break; |
| 1820 | } |
| 1821 | case 'Z': |
| 1822 | case 'z': |
| 1823 | { |
| 1824 | if (LocaleCompare(symbol,"z") == 0) |
| 1825 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1826 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1827 | depth; |
| 1828 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1829 | depth=(double) GetImageDepth(image,fx_info->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1830 | return(depth); |
| 1831 | } |
| 1832 | break; |
| 1833 | } |
| 1834 | default: |
| 1835 | break; |
| 1836 | } |
| 1837 | value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol); |
| 1838 | if (value != (const char *) NULL) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1839 | return((double) StringToDouble(value,(char **) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1840 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1841 | "UnableToParseExpression","`%s'",symbol); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1842 | return(0.0); |
| 1843 | } |
| 1844 | |
| 1845 | static const char *FxOperatorPrecedence(const char *expression, |
| 1846 | ExceptionInfo *exception) |
| 1847 | { |
| 1848 | typedef enum |
| 1849 | { |
| 1850 | UndefinedPrecedence, |
| 1851 | NullPrecedence, |
| 1852 | BitwiseComplementPrecedence, |
| 1853 | ExponentPrecedence, |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 1854 | ExponentialNotationPrecedence, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1855 | MultiplyPrecedence, |
| 1856 | AdditionPrecedence, |
| 1857 | ShiftPrecedence, |
| 1858 | RelationalPrecedence, |
| 1859 | EquivalencyPrecedence, |
| 1860 | BitwiseAndPrecedence, |
| 1861 | BitwiseOrPrecedence, |
| 1862 | LogicalAndPrecedence, |
| 1863 | LogicalOrPrecedence, |
| 1864 | TernaryPrecedence, |
| 1865 | AssignmentPrecedence, |
| 1866 | CommaPrecedence, |
| 1867 | SeparatorPrecedence |
| 1868 | } FxPrecedence; |
| 1869 | |
| 1870 | FxPrecedence |
| 1871 | precedence, |
| 1872 | target; |
| 1873 | |
| 1874 | register const char |
| 1875 | *subexpression; |
| 1876 | |
| 1877 | register int |
| 1878 | c; |
| 1879 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1880 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1881 | level; |
| 1882 | |
| 1883 | c=0; |
| 1884 | level=0; |
| 1885 | subexpression=(const char *) NULL; |
| 1886 | target=NullPrecedence; |
| 1887 | while (*expression != '\0') |
| 1888 | { |
| 1889 | precedence=UndefinedPrecedence; |
| 1890 | if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@')) |
| 1891 | { |
| 1892 | expression++; |
| 1893 | continue; |
| 1894 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1895 | switch (*expression) |
| 1896 | { |
| 1897 | case 'A': |
| 1898 | case 'a': |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1899 | { |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1900 | #if defined(MAGICKCORE_HAVE_ACOSH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1901 | if (LocaleNCompare(expression,"acosh",5) == 0) |
| 1902 | { |
| 1903 | expression+=5; |
| 1904 | break; |
| 1905 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1906 | #endif |
| 1907 | #if defined(MAGICKCORE_HAVE_ASINH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1908 | if (LocaleNCompare(expression,"asinh",5) == 0) |
| 1909 | { |
| 1910 | expression+=5; |
| 1911 | break; |
| 1912 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1913 | #endif |
| 1914 | #if defined(MAGICKCORE_HAVE_ATANH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1915 | if (LocaleNCompare(expression,"atanh",5) == 0) |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1916 | { |
| 1917 | expression+=5; |
| 1918 | break; |
| 1919 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1920 | #endif |
anthony | 62838e5 | 2012-05-24 12:41:54 +0000 | [diff] [blame] | 1921 | if (LocaleNCompare(expression,"atan2",5) == 0) |
| 1922 | { |
| 1923 | expression+=5; |
| 1924 | break; |
| 1925 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1926 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1927 | } |
cristy | 62d455f | 2011-11-03 11:42:28 +0000 | [diff] [blame] | 1928 | case 'E': |
| 1929 | case 'e': |
| 1930 | { |
| 1931 | if ((LocaleNCompare(expression,"E+",2) == 0) || |
| 1932 | (LocaleNCompare(expression,"E-",2) == 0)) |
| 1933 | { |
| 1934 | expression+=2; /* scientific notation */ |
| 1935 | break; |
| 1936 | } |
| 1937 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1938 | case 'J': |
| 1939 | case 'j': |
| 1940 | { |
| 1941 | if ((LocaleNCompare(expression,"j0",2) == 0) || |
| 1942 | (LocaleNCompare(expression,"j1",2) == 0)) |
| 1943 | { |
| 1944 | expression+=2; |
| 1945 | break; |
| 1946 | } |
| 1947 | break; |
| 1948 | } |
cristy | 2def932 | 2010-06-18 23:59:37 +0000 | [diff] [blame] | 1949 | case '#': |
| 1950 | { |
| 1951 | while (isxdigit((int) ((unsigned char) *(expression+1))) != 0) |
| 1952 | expression++; |
| 1953 | break; |
| 1954 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1955 | default: |
| 1956 | break; |
| 1957 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1958 | if ((c == (int) '{') || (c == (int) '[')) |
| 1959 | level++; |
| 1960 | else |
| 1961 | if ((c == (int) '}') || (c == (int) ']')) |
| 1962 | level--; |
| 1963 | if (level == 0) |
| 1964 | switch ((unsigned char) *expression) |
| 1965 | { |
| 1966 | case '~': |
| 1967 | case '!': |
| 1968 | { |
| 1969 | precedence=BitwiseComplementPrecedence; |
| 1970 | break; |
| 1971 | } |
| 1972 | case '^': |
cristy | 6621e25 | 2010-08-13 00:42:57 +0000 | [diff] [blame] | 1973 | case '@': |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1974 | { |
| 1975 | precedence=ExponentPrecedence; |
| 1976 | break; |
| 1977 | } |
| 1978 | default: |
| 1979 | { |
| 1980 | if (((c != 0) && ((isdigit((int) ((char) c)) != 0) || |
| 1981 | (strchr(")",c) != (char *) NULL))) && |
| 1982 | (((islower((int) ((char) *expression)) != 0) || |
| 1983 | (strchr("(",(int) *expression) != (char *) NULL)) || |
| 1984 | ((isdigit((int) ((char) c)) == 0) && |
| 1985 | (isdigit((int) ((char) *expression)) != 0))) && |
| 1986 | (strchr("xy",(int) *expression) == (char *) NULL)) |
| 1987 | precedence=MultiplyPrecedence; |
| 1988 | break; |
| 1989 | } |
| 1990 | case '*': |
| 1991 | case '/': |
| 1992 | case '%': |
| 1993 | { |
| 1994 | precedence=MultiplyPrecedence; |
| 1995 | break; |
| 1996 | } |
| 1997 | case '+': |
| 1998 | case '-': |
| 1999 | { |
| 2000 | if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) || |
| 2001 | (isalpha(c) != 0)) |
| 2002 | precedence=AdditionPrecedence; |
| 2003 | break; |
| 2004 | } |
| 2005 | case LeftShiftOperator: |
| 2006 | case RightShiftOperator: |
| 2007 | { |
| 2008 | precedence=ShiftPrecedence; |
| 2009 | break; |
| 2010 | } |
| 2011 | case '<': |
| 2012 | case LessThanEqualOperator: |
| 2013 | case GreaterThanEqualOperator: |
| 2014 | case '>': |
| 2015 | { |
| 2016 | precedence=RelationalPrecedence; |
| 2017 | break; |
| 2018 | } |
| 2019 | case EqualOperator: |
| 2020 | case NotEqualOperator: |
| 2021 | { |
| 2022 | precedence=EquivalencyPrecedence; |
| 2023 | break; |
| 2024 | } |
| 2025 | case '&': |
| 2026 | { |
| 2027 | precedence=BitwiseAndPrecedence; |
| 2028 | break; |
| 2029 | } |
| 2030 | case '|': |
| 2031 | { |
| 2032 | precedence=BitwiseOrPrecedence; |
| 2033 | break; |
| 2034 | } |
| 2035 | case LogicalAndOperator: |
| 2036 | { |
| 2037 | precedence=LogicalAndPrecedence; |
| 2038 | break; |
| 2039 | } |
| 2040 | case LogicalOrOperator: |
| 2041 | { |
| 2042 | precedence=LogicalOrPrecedence; |
| 2043 | break; |
| 2044 | } |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 2045 | case ExponentialNotation: |
| 2046 | { |
| 2047 | precedence=ExponentialNotationPrecedence; |
| 2048 | break; |
| 2049 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2050 | case ':': |
| 2051 | case '?': |
| 2052 | { |
| 2053 | precedence=TernaryPrecedence; |
| 2054 | break; |
| 2055 | } |
| 2056 | case '=': |
| 2057 | { |
| 2058 | precedence=AssignmentPrecedence; |
| 2059 | break; |
| 2060 | } |
| 2061 | case ',': |
| 2062 | { |
| 2063 | precedence=CommaPrecedence; |
| 2064 | break; |
| 2065 | } |
| 2066 | case ';': |
| 2067 | { |
| 2068 | precedence=SeparatorPrecedence; |
| 2069 | break; |
| 2070 | } |
| 2071 | } |
| 2072 | if ((precedence == BitwiseComplementPrecedence) || |
| 2073 | (precedence == TernaryPrecedence) || |
| 2074 | (precedence == AssignmentPrecedence)) |
| 2075 | { |
| 2076 | if (precedence > target) |
| 2077 | { |
| 2078 | /* |
| 2079 | Right-to-left associativity. |
| 2080 | */ |
| 2081 | target=precedence; |
| 2082 | subexpression=expression; |
| 2083 | } |
| 2084 | } |
| 2085 | else |
| 2086 | if (precedence >= target) |
| 2087 | { |
| 2088 | /* |
| 2089 | Left-to-right associativity. |
| 2090 | */ |
| 2091 | target=precedence; |
| 2092 | subexpression=expression; |
| 2093 | } |
| 2094 | if (strchr("(",(int) *expression) != (char *) NULL) |
| 2095 | expression=FxSubexpression(expression,exception); |
| 2096 | c=(int) (*expression++); |
| 2097 | } |
| 2098 | return(subexpression); |
| 2099 | } |
| 2100 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2101 | static double FxEvaluateSubexpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2102 | const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2103 | const char *expression,double *beta,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2104 | { |
| 2105 | char |
| 2106 | *q, |
| 2107 | subexpression[MaxTextExtent]; |
| 2108 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2109 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2110 | alpha, |
| 2111 | gamma; |
| 2112 | |
| 2113 | register const char |
| 2114 | *p; |
| 2115 | |
| 2116 | *beta=0.0; |
| 2117 | if (exception->severity != UndefinedException) |
| 2118 | return(0.0); |
| 2119 | while (isspace((int) *expression) != 0) |
| 2120 | expression++; |
| 2121 | if (*expression == '\0') |
| 2122 | { |
| 2123 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2124 | "MissingExpression","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2125 | return(0.0); |
| 2126 | } |
cristy | 66322f0 | 2010-05-17 11:40:48 +0000 | [diff] [blame] | 2127 | *subexpression='\0'; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2128 | p=FxOperatorPrecedence(expression,exception); |
| 2129 | if (p != (const char *) NULL) |
| 2130 | { |
| 2131 | (void) CopyMagickString(subexpression,expression,(size_t) |
| 2132 | (p-expression+1)); |
| 2133 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta, |
| 2134 | exception); |
| 2135 | switch ((unsigned char) *p) |
| 2136 | { |
| 2137 | case '~': |
| 2138 | { |
| 2139 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2140 | *beta=(double) (~(size_t) *beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2141 | return(*beta); |
| 2142 | } |
| 2143 | case '!': |
| 2144 | { |
| 2145 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2146 | return(*beta == 0.0 ? 1.0 : 0.0); |
| 2147 | } |
| 2148 | case '^': |
| 2149 | { |
| 2150 | *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info, |
| 2151 | channel,x,y,++p,beta,exception)); |
| 2152 | return(*beta); |
| 2153 | } |
| 2154 | case '*': |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 2155 | case ExponentialNotation: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2156 | { |
| 2157 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2158 | return(alpha*(*beta)); |
| 2159 | } |
| 2160 | case '/': |
| 2161 | { |
| 2162 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2163 | if (*beta == 0.0) |
| 2164 | { |
| 2165 | if (exception->severity == UndefinedException) |
| 2166 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2167 | OptionError,"DivideByZero","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2168 | return(0.0); |
| 2169 | } |
| 2170 | return(alpha/(*beta)); |
| 2171 | } |
| 2172 | case '%': |
| 2173 | { |
| 2174 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2175 | *beta=fabs(floor(((double) *beta)+0.5)); |
| 2176 | if (*beta == 0.0) |
| 2177 | { |
| 2178 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2179 | OptionError,"DivideByZero","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2180 | return(0.0); |
| 2181 | } |
| 2182 | return(fmod((double) alpha,(double) *beta)); |
| 2183 | } |
| 2184 | case '+': |
| 2185 | { |
| 2186 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2187 | return(alpha+(*beta)); |
| 2188 | } |
| 2189 | case '-': |
| 2190 | { |
| 2191 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2192 | return(alpha-(*beta)); |
| 2193 | } |
| 2194 | case LeftShiftOperator: |
| 2195 | { |
| 2196 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2197 | *beta=(double) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2198 | return(*beta); |
| 2199 | } |
| 2200 | case RightShiftOperator: |
| 2201 | { |
| 2202 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2203 | *beta=(double) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2204 | return(*beta); |
| 2205 | } |
| 2206 | case '<': |
| 2207 | { |
| 2208 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2209 | return(alpha < *beta ? 1.0 : 0.0); |
| 2210 | } |
| 2211 | case LessThanEqualOperator: |
| 2212 | { |
| 2213 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2214 | return(alpha <= *beta ? 1.0 : 0.0); |
| 2215 | } |
| 2216 | case '>': |
| 2217 | { |
| 2218 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2219 | return(alpha > *beta ? 1.0 : 0.0); |
| 2220 | } |
| 2221 | case GreaterThanEqualOperator: |
| 2222 | { |
| 2223 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2224 | return(alpha >= *beta ? 1.0 : 0.0); |
| 2225 | } |
| 2226 | case EqualOperator: |
| 2227 | { |
| 2228 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | 9b52834 | 2012-06-02 00:59:20 +0000 | [diff] [blame] | 2229 | return(fabs(alpha-(*beta)) < MagickEpsilon ? MagickEpsilon : 0.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2230 | } |
| 2231 | case NotEqualOperator: |
| 2232 | { |
| 2233 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | 972050b | 2012-06-04 22:09:17 +0000 | [diff] [blame] | 2234 | return(fabs(alpha-(*beta)) >= MagickEpsilon ? 1.0 : 0.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2235 | } |
| 2236 | case '&': |
| 2237 | { |
| 2238 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2239 | *beta=(double) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2240 | return(*beta); |
| 2241 | } |
| 2242 | case '|': |
| 2243 | { |
| 2244 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2245 | *beta=(double) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2246 | return(*beta); |
| 2247 | } |
| 2248 | case LogicalAndOperator: |
| 2249 | { |
| 2250 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2251 | *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0; |
| 2252 | return(*beta); |
| 2253 | } |
| 2254 | case LogicalOrOperator: |
| 2255 | { |
| 2256 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2257 | *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0; |
| 2258 | return(*beta); |
| 2259 | } |
| 2260 | case '?': |
| 2261 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2262 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2263 | gamma; |
| 2264 | |
| 2265 | (void) CopyMagickString(subexpression,++p,MaxTextExtent); |
| 2266 | q=subexpression; |
| 2267 | p=StringToken(":",&q); |
| 2268 | if (q == (char *) NULL) |
| 2269 | { |
| 2270 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2271 | OptionError,"UnableToParseExpression","`%s'",subexpression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2272 | return(0.0); |
| 2273 | } |
cristy | 972050b | 2012-06-04 22:09:17 +0000 | [diff] [blame] | 2274 | if (fabs((double) alpha) >= MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2275 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception); |
| 2276 | else |
| 2277 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception); |
| 2278 | return(gamma); |
| 2279 | } |
| 2280 | case '=': |
| 2281 | { |
| 2282 | char |
| 2283 | numeric[MaxTextExtent]; |
| 2284 | |
| 2285 | q=subexpression; |
| 2286 | while (isalpha((int) ((unsigned char) *q)) != 0) |
| 2287 | q++; |
| 2288 | if (*q != '\0') |
| 2289 | { |
| 2290 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2291 | OptionError,"UnableToParseExpression","`%s'",subexpression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2292 | return(0.0); |
| 2293 | } |
| 2294 | ClearMagickException(exception); |
| 2295 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2296 | (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 2297 | *beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2298 | (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression); |
| 2299 | (void) AddValueToSplayTree(fx_info->symbols,ConstantString( |
| 2300 | subexpression),ConstantString(numeric)); |
| 2301 | return(*beta); |
| 2302 | } |
| 2303 | case ',': |
| 2304 | { |
| 2305 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2306 | return(alpha); |
| 2307 | } |
| 2308 | case ';': |
| 2309 | { |
| 2310 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2311 | return(*beta); |
| 2312 | } |
| 2313 | default: |
| 2314 | { |
| 2315 | gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta, |
| 2316 | exception); |
| 2317 | return(gamma); |
| 2318 | } |
| 2319 | } |
| 2320 | } |
| 2321 | if (strchr("(",(int) *expression) != (char *) NULL) |
| 2322 | { |
| 2323 | (void) CopyMagickString(subexpression,expression+1,MaxTextExtent); |
| 2324 | subexpression[strlen(subexpression)-1]='\0'; |
| 2325 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta, |
| 2326 | exception); |
| 2327 | return(gamma); |
| 2328 | } |
cristy | 8b8a3ae | 2010-10-23 18:49:46 +0000 | [diff] [blame] | 2329 | switch (*expression) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2330 | { |
| 2331 | case '+': |
| 2332 | { |
| 2333 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2334 | exception); |
| 2335 | return(1.0*gamma); |
| 2336 | } |
| 2337 | case '-': |
| 2338 | { |
| 2339 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2340 | exception); |
| 2341 | return(-1.0*gamma); |
| 2342 | } |
| 2343 | case '~': |
| 2344 | { |
| 2345 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2346 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2347 | return((double) (~(size_t) (gamma+0.5))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2348 | } |
| 2349 | case 'A': |
| 2350 | case 'a': |
| 2351 | { |
| 2352 | if (LocaleNCompare(expression,"abs",3) == 0) |
| 2353 | { |
| 2354 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2355 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2356 | return((double) fabs((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2357 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2358 | #if defined(MAGICKCORE_HAVE_ACOSH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2359 | if (LocaleNCompare(expression,"acosh",5) == 0) |
| 2360 | { |
| 2361 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2362 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2363 | return((double) acosh((double) alpha)); |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2364 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2365 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2366 | if (LocaleNCompare(expression,"acos",4) == 0) |
| 2367 | { |
| 2368 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2369 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2370 | return((double) acos((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2371 | } |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2372 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2373 | if (LocaleNCompare(expression,"airy",4) == 0) |
| 2374 | { |
| 2375 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2376 | exception); |
| 2377 | if (alpha == 0.0) |
cristy | 2dd0322 | 2010-03-30 22:12:11 +0000 | [diff] [blame] | 2378 | return(1.0); |
| 2379 | gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha); |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2380 | return(gamma*gamma); |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2381 | } |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2382 | #endif |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2383 | #if defined(MAGICKCORE_HAVE_ASINH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2384 | if (LocaleNCompare(expression,"asinh",5) == 0) |
| 2385 | { |
| 2386 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2387 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2388 | return((double) asinh((double) alpha)); |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2389 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2390 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2391 | if (LocaleNCompare(expression,"asin",4) == 0) |
| 2392 | { |
| 2393 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2394 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2395 | return((double) asin((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2396 | } |
| 2397 | if (LocaleNCompare(expression,"alt",3) == 0) |
| 2398 | { |
| 2399 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2400 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2401 | return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2402 | } |
| 2403 | if (LocaleNCompare(expression,"atan2",5) == 0) |
| 2404 | { |
| 2405 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2406 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2407 | return((double) atan2((double) alpha,(double) *beta)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2408 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2409 | #if defined(MAGICKCORE_HAVE_ATANH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2410 | if (LocaleNCompare(expression,"atanh",5) == 0) |
| 2411 | { |
| 2412 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2413 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2414 | return((double) atanh((double) alpha)); |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2415 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2416 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2417 | if (LocaleNCompare(expression,"atan",4) == 0) |
| 2418 | { |
| 2419 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2420 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2421 | return((double) atan((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2422 | } |
| 2423 | if (LocaleCompare(expression,"a") == 0) |
| 2424 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2425 | break; |
| 2426 | } |
| 2427 | case 'B': |
| 2428 | case 'b': |
| 2429 | { |
| 2430 | if (LocaleCompare(expression,"b") == 0) |
| 2431 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2432 | break; |
| 2433 | } |
| 2434 | case 'C': |
| 2435 | case 'c': |
| 2436 | { |
| 2437 | if (LocaleNCompare(expression,"ceil",4) == 0) |
| 2438 | { |
| 2439 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2440 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2441 | return((double) ceil((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2442 | } |
| 2443 | if (LocaleNCompare(expression,"cosh",4) == 0) |
| 2444 | { |
| 2445 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2446 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2447 | return((double) cosh((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2448 | } |
| 2449 | if (LocaleNCompare(expression,"cos",3) == 0) |
| 2450 | { |
| 2451 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2452 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2453 | return((double) cos((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2454 | } |
| 2455 | if (LocaleCompare(expression,"c") == 0) |
| 2456 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2457 | break; |
| 2458 | } |
| 2459 | case 'D': |
| 2460 | case 'd': |
| 2461 | { |
| 2462 | if (LocaleNCompare(expression,"debug",5) == 0) |
| 2463 | { |
| 2464 | const char |
| 2465 | *type; |
| 2466 | |
| 2467 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2468 | exception); |
| 2469 | if (fx_info->images->colorspace == CMYKColorspace) |
| 2470 | switch (channel) |
| 2471 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2472 | case CyanPixelChannel: type="cyan"; break; |
| 2473 | case MagentaPixelChannel: type="magenta"; break; |
| 2474 | case YellowPixelChannel: type="yellow"; break; |
| 2475 | case AlphaPixelChannel: type="opacity"; break; |
| 2476 | case BlackPixelChannel: type="black"; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2477 | default: type="unknown"; break; |
| 2478 | } |
| 2479 | else |
| 2480 | switch (channel) |
| 2481 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2482 | case RedPixelChannel: type="red"; break; |
| 2483 | case GreenPixelChannel: type="green"; break; |
| 2484 | case BluePixelChannel: type="blue"; break; |
| 2485 | case AlphaPixelChannel: type="opacity"; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2486 | default: type="unknown"; break; |
| 2487 | } |
| 2488 | (void) CopyMagickString(subexpression,expression+6,MaxTextExtent); |
| 2489 | if (strlen(subexpression) > 1) |
| 2490 | subexpression[strlen(subexpression)-1]='\0'; |
| 2491 | if (fx_info->file != (FILE *) NULL) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2492 | (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: " |
| 2493 | "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type, |
| 2494 | subexpression,GetMagickPrecision(),(double) alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2495 | return(0.0); |
| 2496 | } |
cristy | 5597a8d | 2011-11-04 00:25:32 +0000 | [diff] [blame] | 2497 | if (LocaleNCompare(expression,"drc",3) == 0) |
| 2498 | { |
| 2499 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2500 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2501 | return((double) (alpha/(*beta*(alpha-1.0)+1.0))); |
cristy | 5597a8d | 2011-11-04 00:25:32 +0000 | [diff] [blame] | 2502 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2503 | break; |
| 2504 | } |
| 2505 | case 'E': |
| 2506 | case 'e': |
| 2507 | { |
| 2508 | if (LocaleCompare(expression,"epsilon") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2509 | return((double) MagickEpsilon); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2510 | if (LocaleNCompare(expression,"exp",3) == 0) |
| 2511 | { |
| 2512 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2513 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2514 | return((double) exp((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2515 | } |
| 2516 | if (LocaleCompare(expression,"e") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2517 | return((double) 2.7182818284590452354); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2518 | break; |
| 2519 | } |
| 2520 | case 'F': |
| 2521 | case 'f': |
| 2522 | { |
| 2523 | if (LocaleNCompare(expression,"floor",5) == 0) |
| 2524 | { |
| 2525 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2526 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2527 | return((double) floor((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2528 | } |
| 2529 | break; |
| 2530 | } |
| 2531 | case 'G': |
| 2532 | case 'g': |
| 2533 | { |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2534 | if (LocaleNCompare(expression,"gauss",5) == 0) |
| 2535 | { |
| 2536 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2537 | exception); |
| 2538 | gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2539 | return((double) gamma); |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2540 | } |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 2541 | if (LocaleNCompare(expression,"gcd",3) == 0) |
| 2542 | { |
| 2543 | MagickOffsetType |
| 2544 | gcd; |
| 2545 | |
| 2546 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2547 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2548 | gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+ |
| 2549 | 0.5)); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2550 | return((double) gcd); |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 2551 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2552 | if (LocaleCompare(expression,"g") == 0) |
| 2553 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2554 | break; |
| 2555 | } |
| 2556 | case 'H': |
| 2557 | case 'h': |
| 2558 | { |
| 2559 | if (LocaleCompare(expression,"h") == 0) |
| 2560 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2561 | if (LocaleCompare(expression,"hue") == 0) |
| 2562 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2563 | if (LocaleNCompare(expression,"hypot",5) == 0) |
| 2564 | { |
| 2565 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2566 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2567 | return((double) hypot((double) alpha,(double) *beta)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2568 | } |
| 2569 | break; |
| 2570 | } |
| 2571 | case 'K': |
| 2572 | case 'k': |
| 2573 | { |
| 2574 | if (LocaleCompare(expression,"k") == 0) |
| 2575 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2576 | break; |
| 2577 | } |
| 2578 | case 'I': |
| 2579 | case 'i': |
| 2580 | { |
| 2581 | if (LocaleCompare(expression,"intensity") == 0) |
| 2582 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2583 | if (LocaleNCompare(expression,"int",3) == 0) |
| 2584 | { |
| 2585 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2586 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2587 | return((double) floor(alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2588 | } |
cristy | 82b2072 | 2011-11-05 21:52:36 +0000 | [diff] [blame] | 2589 | #if defined(MAGICKCORE_HAVE_ISNAN) |
cristy | 639399c | 2011-11-02 19:16:15 +0000 | [diff] [blame] | 2590 | if (LocaleNCompare(expression,"isnan",5) == 0) |
| 2591 | { |
| 2592 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2593 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2594 | return((double) !!isnan((double) alpha)); |
cristy | 639399c | 2011-11-02 19:16:15 +0000 | [diff] [blame] | 2595 | } |
cristy | 82b2072 | 2011-11-05 21:52:36 +0000 | [diff] [blame] | 2596 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2597 | if (LocaleCompare(expression,"i") == 0) |
| 2598 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2599 | break; |
| 2600 | } |
| 2601 | case 'J': |
| 2602 | case 'j': |
| 2603 | { |
| 2604 | if (LocaleCompare(expression,"j") == 0) |
| 2605 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2606 | #if defined(MAGICKCORE_HAVE_J0) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2607 | if (LocaleNCompare(expression,"j0",2) == 0) |
| 2608 | { |
| 2609 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2610 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2611 | return((double) j0((double) alpha)); |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2612 | } |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2613 | #endif |
| 2614 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2615 | if (LocaleNCompare(expression,"j1",2) == 0) |
| 2616 | { |
| 2617 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2618 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2619 | return((double) j1((double) alpha)); |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2620 | } |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2621 | #endif |
cristy | aa018fa | 2010-04-08 23:03:54 +0000 | [diff] [blame] | 2622 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2623 | if (LocaleNCompare(expression,"jinc",4) == 0) |
| 2624 | { |
| 2625 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2626 | exception); |
cristy | 0946a82 | 2010-03-12 17:14:58 +0000 | [diff] [blame] | 2627 | if (alpha == 0.0) |
| 2628 | return(1.0); |
cristy | c90d70d | 2012-11-03 23:53:13 +0000 | [diff] [blame] | 2629 | gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha)); |
cristy | fce2f7b | 2010-03-12 00:29:49 +0000 | [diff] [blame] | 2630 | return(gamma); |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2631 | } |
cristy | aa018fa | 2010-04-08 23:03:54 +0000 | [diff] [blame] | 2632 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2633 | break; |
| 2634 | } |
| 2635 | case 'L': |
| 2636 | case 'l': |
| 2637 | { |
| 2638 | if (LocaleNCompare(expression,"ln",2) == 0) |
| 2639 | { |
| 2640 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2641 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2642 | return((double) log((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2643 | } |
cristy | c8ed532 | 2010-08-31 12:07:59 +0000 | [diff] [blame] | 2644 | if (LocaleNCompare(expression,"logtwo",6) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2645 | { |
cristy | c8ed532 | 2010-08-31 12:07:59 +0000 | [diff] [blame] | 2646 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2647 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2648 | return((double) log10((double) alpha))/log10(2.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2649 | } |
| 2650 | if (LocaleNCompare(expression,"log",3) == 0) |
| 2651 | { |
| 2652 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2653 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2654 | return((double) log10((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2655 | } |
| 2656 | if (LocaleCompare(expression,"lightness") == 0) |
| 2657 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2658 | break; |
| 2659 | } |
| 2660 | case 'M': |
| 2661 | case 'm': |
| 2662 | { |
| 2663 | if (LocaleCompare(expression,"MaxRGB") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2664 | return((double) QuantumRange); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2665 | if (LocaleNCompare(expression,"maxima",6) == 0) |
| 2666 | break; |
| 2667 | if (LocaleNCompare(expression,"max",3) == 0) |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2668 | { |
| 2669 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2670 | exception); |
| 2671 | return(alpha > *beta ? alpha : *beta); |
| 2672 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2673 | if (LocaleNCompare(expression,"minima",6) == 0) |
| 2674 | break; |
| 2675 | if (LocaleNCompare(expression,"min",3) == 0) |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2676 | { |
| 2677 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2678 | exception); |
| 2679 | return(alpha < *beta ? alpha : *beta); |
| 2680 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2681 | if (LocaleNCompare(expression,"mod",3) == 0) |
| 2682 | { |
| 2683 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2684 | exception); |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2685 | gamma=alpha-floor((double) (alpha/(*beta)))*(*beta); |
| 2686 | return(gamma); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2687 | } |
| 2688 | if (LocaleCompare(expression,"m") == 0) |
| 2689 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2690 | break; |
| 2691 | } |
| 2692 | case 'N': |
| 2693 | case 'n': |
| 2694 | { |
cristy | ad3502e | 2011-11-02 19:10:45 +0000 | [diff] [blame] | 2695 | if (LocaleNCompare(expression,"not",3) == 0) |
| 2696 | { |
| 2697 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2698 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2699 | return((double) (alpha < MagickEpsilon)); |
cristy | ad3502e | 2011-11-02 19:10:45 +0000 | [diff] [blame] | 2700 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2701 | if (LocaleCompare(expression,"n") == 0) |
| 2702 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2703 | break; |
| 2704 | } |
| 2705 | case 'O': |
| 2706 | case 'o': |
| 2707 | { |
| 2708 | if (LocaleCompare(expression,"Opaque") == 0) |
| 2709 | return(1.0); |
| 2710 | if (LocaleCompare(expression,"o") == 0) |
| 2711 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2712 | break; |
| 2713 | } |
| 2714 | case 'P': |
| 2715 | case 'p': |
| 2716 | { |
cristy | 670aa3c | 2011-11-03 00:54:00 +0000 | [diff] [blame] | 2717 | if (LocaleCompare(expression,"phi") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2718 | return((double) MagickPHI); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2719 | if (LocaleCompare(expression,"pi") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2720 | return((double) MagickPI); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2721 | if (LocaleNCompare(expression,"pow",3) == 0) |
| 2722 | { |
| 2723 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2724 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2725 | return((double) pow((double) alpha,(double) *beta)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2726 | } |
| 2727 | if (LocaleCompare(expression,"p") == 0) |
| 2728 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2729 | break; |
| 2730 | } |
| 2731 | case 'Q': |
| 2732 | case 'q': |
| 2733 | { |
| 2734 | if (LocaleCompare(expression,"QuantumRange") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2735 | return((double) QuantumRange); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2736 | if (LocaleCompare(expression,"QuantumScale") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2737 | return((double) QuantumScale); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2738 | break; |
| 2739 | } |
| 2740 | case 'R': |
| 2741 | case 'r': |
| 2742 | { |
| 2743 | if (LocaleNCompare(expression,"rand",4) == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2744 | return((double) GetPseudoRandomValue(fx_info->random_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2745 | if (LocaleNCompare(expression,"round",5) == 0) |
| 2746 | { |
| 2747 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2748 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2749 | return((double) floor((double) alpha+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2750 | } |
| 2751 | if (LocaleCompare(expression,"r") == 0) |
| 2752 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2753 | break; |
| 2754 | } |
| 2755 | case 'S': |
| 2756 | case 's': |
| 2757 | { |
| 2758 | if (LocaleCompare(expression,"saturation") == 0) |
| 2759 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2760 | if (LocaleNCompare(expression,"sign",4) == 0) |
| 2761 | { |
| 2762 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2763 | exception); |
| 2764 | return(alpha < 0.0 ? -1.0 : 1.0); |
| 2765 | } |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2766 | if (LocaleNCompare(expression,"sinc",4) == 0) |
| 2767 | { |
| 2768 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2769 | exception); |
| 2770 | if (alpha == 0) |
| 2771 | return(1.0); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2772 | gamma=(double) (sin((double) (MagickPI*alpha))/ |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2773 | (MagickPI*alpha)); |
| 2774 | return(gamma); |
| 2775 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2776 | if (LocaleNCompare(expression,"sinh",4) == 0) |
| 2777 | { |
| 2778 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2779 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2780 | return((double) sinh((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2781 | } |
| 2782 | if (LocaleNCompare(expression,"sin",3) == 0) |
| 2783 | { |
| 2784 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2785 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2786 | return((double) sin((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2787 | } |
| 2788 | if (LocaleNCompare(expression,"sqrt",4) == 0) |
| 2789 | { |
| 2790 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2791 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2792 | return((double) sqrt((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2793 | } |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2794 | if (LocaleNCompare(expression,"squish",6) == 0) |
| 2795 | { |
| 2796 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta, |
| 2797 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2798 | return((double) (1.0/(1.0+exp((double) (-alpha))))); |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2799 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2800 | if (LocaleCompare(expression,"s") == 0) |
| 2801 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2802 | break; |
| 2803 | } |
| 2804 | case 'T': |
| 2805 | case 't': |
| 2806 | { |
| 2807 | if (LocaleNCompare(expression,"tanh",4) == 0) |
| 2808 | { |
| 2809 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2810 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2811 | return((double) tanh((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2812 | } |
| 2813 | if (LocaleNCompare(expression,"tan",3) == 0) |
| 2814 | { |
| 2815 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2816 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2817 | return((double) tan((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2818 | } |
| 2819 | if (LocaleCompare(expression,"Transparent") == 0) |
| 2820 | return(0.0); |
cristy | 16788e4 | 2010-08-13 13:44:26 +0000 | [diff] [blame] | 2821 | if (LocaleNCompare(expression,"trunc",5) == 0) |
| 2822 | { |
| 2823 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2824 | exception); |
| 2825 | if (alpha >= 0.0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2826 | return((double) floor((double) alpha)); |
| 2827 | return((double) ceil((double) alpha)); |
cristy | 16788e4 | 2010-08-13 13:44:26 +0000 | [diff] [blame] | 2828 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2829 | if (LocaleCompare(expression,"t") == 0) |
| 2830 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2831 | break; |
| 2832 | } |
| 2833 | case 'U': |
| 2834 | case 'u': |
| 2835 | { |
| 2836 | if (LocaleCompare(expression,"u") == 0) |
| 2837 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2838 | break; |
| 2839 | } |
| 2840 | case 'V': |
| 2841 | case 'v': |
| 2842 | { |
| 2843 | if (LocaleCompare(expression,"v") == 0) |
| 2844 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2845 | break; |
| 2846 | } |
| 2847 | case 'W': |
| 2848 | case 'w': |
| 2849 | { |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2850 | if (LocaleNCompare(expression,"while",5) == 0) |
| 2851 | { |
| 2852 | do |
| 2853 | { |
| 2854 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2855 | exception); |
| 2856 | } while (fabs((double) alpha) >= MagickEpsilon); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2857 | return((double) *beta); |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2858 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2859 | if (LocaleCompare(expression,"w") == 0) |
| 2860 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2861 | break; |
| 2862 | } |
| 2863 | case 'Y': |
| 2864 | case 'y': |
| 2865 | { |
| 2866 | if (LocaleCompare(expression,"y") == 0) |
| 2867 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2868 | break; |
| 2869 | } |
| 2870 | case 'Z': |
| 2871 | case 'z': |
| 2872 | { |
| 2873 | if (LocaleCompare(expression,"z") == 0) |
| 2874 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2875 | break; |
| 2876 | } |
| 2877 | default: |
| 2878 | break; |
| 2879 | } |
| 2880 | q=(char *) expression; |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2881 | alpha=InterpretSiPrefixValue(expression,&q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2882 | if (q == expression) |
| 2883 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2884 | return(alpha); |
| 2885 | } |
| 2886 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 2887 | MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2888 | double *alpha,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2889 | { |
| 2890 | MagickBooleanType |
| 2891 | status; |
| 2892 | |
cristy | 541ae57 | 2011-08-05 19:08:59 +0000 | [diff] [blame] | 2893 | status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha, |
| 2894 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2895 | return(status); |
| 2896 | } |
| 2897 | |
| 2898 | MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2899 | double *alpha,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2900 | { |
| 2901 | FILE |
| 2902 | *file; |
| 2903 | |
| 2904 | MagickBooleanType |
| 2905 | status; |
| 2906 | |
| 2907 | file=fx_info->file; |
| 2908 | fx_info->file=(FILE *) NULL; |
cristy | 541ae57 | 2011-08-05 19:08:59 +0000 | [diff] [blame] | 2909 | status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha, |
| 2910 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2911 | fx_info->file=file; |
| 2912 | return(status); |
| 2913 | } |
| 2914 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 2915 | MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2916 | const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2917 | double *alpha,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2918 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2919 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2920 | beta; |
| 2921 | |
| 2922 | beta=0.0; |
| 2923 | *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta, |
| 2924 | exception); |
| 2925 | return(exception->severity == OptionError ? MagickFalse : MagickTrue); |
| 2926 | } |
| 2927 | |
| 2928 | /* |
| 2929 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2930 | % % |
| 2931 | % % |
| 2932 | % % |
| 2933 | % F x I m a g e % |
| 2934 | % % |
| 2935 | % % |
| 2936 | % % |
| 2937 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2938 | % |
| 2939 | % FxImage() applies a mathematical expression to the specified image. |
| 2940 | % |
| 2941 | % The format of the FxImage method is: |
| 2942 | % |
| 2943 | % Image *FxImage(const Image *image,const char *expression, |
| 2944 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2945 | % |
| 2946 | % A description of each parameter follows: |
| 2947 | % |
| 2948 | % o image: the image. |
| 2949 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2950 | % o expression: A mathematical expression. |
| 2951 | % |
| 2952 | % o exception: return any errors or warnings in this structure. |
| 2953 | % |
| 2954 | */ |
| 2955 | |
| 2956 | static FxInfo **DestroyFxThreadSet(FxInfo **fx_info) |
| 2957 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2958 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2959 | i; |
| 2960 | |
| 2961 | assert(fx_info != (FxInfo **) NULL); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 2962 | for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2963 | if (fx_info[i] != (FxInfo *) NULL) |
| 2964 | fx_info[i]=DestroyFxInfo(fx_info[i]); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 2965 | fx_info=(FxInfo **) RelinquishMagickMemory(fx_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2966 | return(fx_info); |
| 2967 | } |
| 2968 | |
| 2969 | static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression, |
| 2970 | ExceptionInfo *exception) |
| 2971 | { |
| 2972 | char |
| 2973 | *fx_expression; |
| 2974 | |
| 2975 | FxInfo |
| 2976 | **fx_info; |
| 2977 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2978 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2979 | alpha; |
| 2980 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2981 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2982 | i; |
| 2983 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2984 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2985 | number_threads; |
| 2986 | |
cristy | 9357bdd | 2012-07-30 12:28:34 +0000 | [diff] [blame] | 2987 | number_threads=(size_t) GetMagickResourceLimit(ThreadResource); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 2988 | fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2989 | if (fx_info == (FxInfo **) NULL) |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 2990 | { |
| 2991 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2992 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
| 2993 | return((FxInfo **) NULL); |
| 2994 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2995 | (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info)); |
| 2996 | if (*expression != '@') |
| 2997 | fx_expression=ConstantString(expression); |
| 2998 | else |
| 2999 | fx_expression=FileToString(expression+1,~0,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3000 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3001 | { |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3002 | MagickBooleanType |
| 3003 | status; |
| 3004 | |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 3005 | fx_info[i]=AcquireFxInfo(image,fx_expression,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3006 | if (fx_info[i] == (FxInfo *) NULL) |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3007 | break; |
| 3008 | status=FxPreprocessExpression(fx_info[i],&alpha,exception); |
| 3009 | if (status == MagickFalse) |
| 3010 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3011 | } |
| 3012 | fx_expression=DestroyString(fx_expression); |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3013 | if (i < (ssize_t) number_threads) |
| 3014 | fx_info=DestroyFxThreadSet(fx_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3015 | return(fx_info); |
| 3016 | } |
| 3017 | |
| 3018 | MagickExport Image *FxImage(const Image *image,const char *expression, |
| 3019 | ExceptionInfo *exception) |
| 3020 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3021 | #define FxImageTag "Fx/Image" |
| 3022 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3023 | CacheView |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3024 | *fx_view, |
| 3025 | *image_view; |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3026 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3027 | FxInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3028 | **restrict fx_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3029 | |
| 3030 | Image |
| 3031 | *fx_image; |
| 3032 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3033 | MagickBooleanType |
| 3034 | status; |
| 3035 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3036 | MagickOffsetType |
| 3037 | progress; |
| 3038 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3039 | ssize_t |
| 3040 | y; |
| 3041 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3042 | assert(image != (Image *) NULL); |
| 3043 | assert(image->signature == MagickSignature); |
| 3044 | if (image->debug != MagickFalse) |
| 3045 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3046 | fx_info=AcquireFxThreadSet(image,expression,exception); |
| 3047 | if (fx_info == (FxInfo **) NULL) |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3048 | return((Image *) NULL); |
| 3049 | fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
| 3050 | if (fx_image == (Image *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3051 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3052 | fx_info=DestroyFxThreadSet(fx_info); |
| 3053 | return((Image *) NULL); |
| 3054 | } |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3055 | if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse) |
| 3056 | { |
| 3057 | fx_info=DestroyFxThreadSet(fx_info); |
| 3058 | fx_image=DestroyImage(fx_image); |
| 3059 | return((Image *) NULL); |
| 3060 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3061 | /* |
| 3062 | Fx image. |
| 3063 | */ |
| 3064 | status=MagickTrue; |
| 3065 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3066 | image_view=AcquireVirtualCacheView(image,exception); |
| 3067 | fx_view=AcquireAuthenticCacheView(fx_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3068 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3069 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 3070 | magick_threads(image,fx_image,fx_image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3071 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3072 | for (y=0; y < (ssize_t) fx_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3073 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3074 | const int |
| 3075 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3076 | |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3077 | register const Quantum |
| 3078 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3079 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3080 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3081 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3082 | |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3083 | register ssize_t |
| 3084 | x; |
| 3085 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3086 | if (status == MagickFalse) |
| 3087 | continue; |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3088 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3089 | q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3090 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3091 | { |
| 3092 | status=MagickFalse; |
| 3093 | continue; |
| 3094 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3095 | for (x=0; x < (ssize_t) fx_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3096 | { |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3097 | register ssize_t |
| 3098 | i; |
| 3099 | |
| 3100 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3101 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3102 | double |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3103 | alpha; |
| 3104 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3105 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3106 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 3107 | PixelTrait fx_traits=GetPixelChannelTraits(fx_image,channel); |
cristy | 010d7d1 | 2011-08-31 01:02:48 +0000 | [diff] [blame] | 3108 | if ((traits == UndefinedPixelTrait) || |
| 3109 | (fx_traits == UndefinedPixelTrait)) |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3110 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 3111 | if (((fx_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 3112 | (GetPixelReadMask(image,p) == 0)) |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3113 | { |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 3114 | SetPixelChannel(fx_image,channel,p[i],q); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3115 | continue; |
| 3116 | } |
| 3117 | alpha=0.0; |
cristy | a382aca | 2011-12-06 18:22:48 +0000 | [diff] [blame] | 3118 | (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha, |
| 3119 | exception); |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3120 | q[i]=ClampToQuantum(QuantumRange*alpha); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3121 | } |
| 3122 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3123 | q+=GetPixelChannels(fx_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3124 | } |
| 3125 | if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse) |
| 3126 | status=MagickFalse; |
| 3127 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3128 | { |
| 3129 | MagickBooleanType |
| 3130 | proceed; |
| 3131 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3132 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3133 | #pragma omp critical (MagickCore_FxImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3134 | #endif |
| 3135 | proceed=SetImageProgress(image,FxImageTag,progress++,image->rows); |
| 3136 | if (proceed == MagickFalse) |
| 3137 | status=MagickFalse; |
| 3138 | } |
| 3139 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3140 | fx_view=DestroyCacheView(fx_view); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3141 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3142 | fx_info=DestroyFxThreadSet(fx_info); |
| 3143 | if (status == MagickFalse) |
| 3144 | fx_image=DestroyImage(fx_image); |
| 3145 | return(fx_image); |
| 3146 | } |
| 3147 | |
| 3148 | /* |
| 3149 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3150 | % % |
| 3151 | % % |
| 3152 | % % |
| 3153 | % I m p l o d e I m a g e % |
| 3154 | % % |
| 3155 | % % |
| 3156 | % % |
| 3157 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3158 | % |
| 3159 | % ImplodeImage() creates a new image that is a copy of an existing |
| 3160 | % one with the image pixels "implode" by the specified percentage. It |
| 3161 | % allocates the memory necessary for the new Image structure and returns a |
| 3162 | % pointer to the new image. |
| 3163 | % |
| 3164 | % The format of the ImplodeImage method is: |
| 3165 | % |
| 3166 | % Image *ImplodeImage(const Image *image,const double amount, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3167 | % const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3168 | % |
| 3169 | % A description of each parameter follows: |
| 3170 | % |
| 3171 | % o implode_image: Method ImplodeImage returns a pointer to the image |
| 3172 | % after it is implode. A null image is returned if there is a memory |
| 3173 | % shortage. |
| 3174 | % |
| 3175 | % o image: the image. |
| 3176 | % |
| 3177 | % o amount: Define the extent of the implosion. |
| 3178 | % |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3179 | % o method: the pixel interpolation method. |
| 3180 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3181 | % o exception: return any errors or warnings in this structure. |
| 3182 | % |
| 3183 | */ |
| 3184 | MagickExport Image *ImplodeImage(const Image *image,const double amount, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3185 | const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3186 | { |
| 3187 | #define ImplodeImageTag "Implode/Image" |
| 3188 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3189 | CacheView |
| 3190 | *image_view, |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3191 | *implode_view, |
| 3192 | *interpolate_view; |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3193 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3194 | Image |
| 3195 | *implode_image; |
| 3196 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3197 | MagickBooleanType |
| 3198 | status; |
| 3199 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3200 | MagickOffsetType |
| 3201 | progress; |
| 3202 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3203 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3204 | radius; |
| 3205 | |
| 3206 | PointInfo |
| 3207 | center, |
| 3208 | scale; |
| 3209 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3210 | ssize_t |
| 3211 | y; |
| 3212 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3213 | /* |
| 3214 | Initialize implode image attributes. |
| 3215 | */ |
| 3216 | assert(image != (Image *) NULL); |
| 3217 | assert(image->signature == MagickSignature); |
| 3218 | if (image->debug != MagickFalse) |
| 3219 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3220 | assert(exception != (ExceptionInfo *) NULL); |
| 3221 | assert(exception->signature == MagickSignature); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3222 | implode_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
| 3223 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3224 | if (implode_image == (Image *) NULL) |
| 3225 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 3226 | if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3227 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3228 | implode_image=DestroyImage(implode_image); |
| 3229 | return((Image *) NULL); |
| 3230 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3231 | if (implode_image->background_color.alpha != OpaqueAlpha) |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3232 | implode_image->alpha_trait=BlendPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3233 | /* |
| 3234 | Compute scaling factor. |
| 3235 | */ |
| 3236 | scale.x=1.0; |
| 3237 | scale.y=1.0; |
| 3238 | center.x=0.5*image->columns; |
| 3239 | center.y=0.5*image->rows; |
| 3240 | radius=center.x; |
| 3241 | if (image->columns > image->rows) |
| 3242 | scale.y=(double) image->columns/(double) image->rows; |
| 3243 | else |
| 3244 | if (image->columns < image->rows) |
| 3245 | { |
| 3246 | scale.x=(double) image->rows/(double) image->columns; |
| 3247 | radius=center.y; |
| 3248 | } |
| 3249 | /* |
| 3250 | Implode image. |
| 3251 | */ |
| 3252 | status=MagickTrue; |
| 3253 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3254 | image_view=AcquireVirtualCacheView(image,exception); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3255 | interpolate_view=AcquireVirtualCacheView(image,exception); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3256 | implode_view=AcquireAuthenticCacheView(implode_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3257 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3258 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 3259 | magick_threads(image,implode_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3260 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3261 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3262 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3263 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3264 | distance; |
| 3265 | |
| 3266 | PointInfo |
| 3267 | delta; |
| 3268 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3269 | register const Quantum |
| 3270 | *restrict p; |
| 3271 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3272 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3273 | x; |
| 3274 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3275 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3276 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3277 | |
| 3278 | if (status == MagickFalse) |
| 3279 | continue; |
cristy | 1665ce1 | 2013-04-19 12:18:43 +0000 | [diff] [blame] | 3280 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3281 | q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3282 | exception); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3283 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3284 | { |
| 3285 | status=MagickFalse; |
| 3286 | continue; |
| 3287 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3288 | delta.y=scale.y*(double) (y-center.y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3289 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3290 | { |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3291 | register ssize_t |
| 3292 | i; |
| 3293 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3294 | /* |
| 3295 | Determine if the pixel is within an ellipse. |
| 3296 | */ |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 3297 | if (GetPixelReadMask(image,p) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 3298 | { |
| 3299 | p+=GetPixelChannels(image); |
| 3300 | q+=GetPixelChannels(implode_image); |
| 3301 | continue; |
| 3302 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3303 | delta.x=scale.x*(double) (x-center.x); |
| 3304 | distance=delta.x*delta.x+delta.y*delta.y; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3305 | if (distance >= (radius*radius)) |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3306 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3307 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3308 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3309 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 3310 | PixelTrait implode_traits=GetPixelChannelTraits(implode_image, |
| 3311 | channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3312 | if ((traits == UndefinedPixelTrait) || |
| 3313 | (implode_traits == UndefinedPixelTrait)) |
| 3314 | continue; |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3315 | SetPixelChannel(implode_image,channel,p[i],q); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3316 | } |
| 3317 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3318 | { |
| 3319 | double |
| 3320 | factor; |
| 3321 | |
| 3322 | /* |
| 3323 | Implode the pixel. |
| 3324 | */ |
| 3325 | factor=1.0; |
| 3326 | if (distance > 0.0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3327 | factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/ |
| 3328 | 2)),-amount); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3329 | status=InterpolatePixelChannels(image,interpolate_view,implode_image, |
| 3330 | method,(double) (factor*delta.x/scale.x+center.x),(double) (factor* |
| 3331 | delta.y/scale.y+center.y),q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3332 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3333 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3334 | q+=GetPixelChannels(implode_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3335 | } |
| 3336 | if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse) |
| 3337 | status=MagickFalse; |
| 3338 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3339 | { |
| 3340 | MagickBooleanType |
| 3341 | proceed; |
| 3342 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3343 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3344 | #pragma omp critical (MagickCore_ImplodeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3345 | #endif |
| 3346 | proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows); |
| 3347 | if (proceed == MagickFalse) |
| 3348 | status=MagickFalse; |
| 3349 | } |
| 3350 | } |
| 3351 | implode_view=DestroyCacheView(implode_view); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3352 | interpolate_view=DestroyCacheView(interpolate_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3353 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3354 | if (status == MagickFalse) |
| 3355 | implode_image=DestroyImage(implode_image); |
| 3356 | return(implode_image); |
| 3357 | } |
| 3358 | |
| 3359 | /* |
| 3360 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3361 | % % |
| 3362 | % % |
| 3363 | % % |
| 3364 | % M o r p h I m a g e s % |
| 3365 | % % |
| 3366 | % % |
| 3367 | % % |
| 3368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3369 | % |
| 3370 | % The MorphImages() method requires a minimum of two images. The first |
| 3371 | % image is transformed into the second by a number of intervening images |
| 3372 | % as specified by frames. |
| 3373 | % |
| 3374 | % The format of the MorphImage method is: |
| 3375 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3376 | % Image *MorphImages(const Image *image,const size_t number_frames, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3377 | % ExceptionInfo *exception) |
| 3378 | % |
| 3379 | % A description of each parameter follows: |
| 3380 | % |
| 3381 | % o image: the image. |
| 3382 | % |
| 3383 | % o number_frames: Define the number of in-between image to generate. |
| 3384 | % The more in-between frames, the smoother the morph. |
| 3385 | % |
| 3386 | % o exception: return any errors or warnings in this structure. |
| 3387 | % |
| 3388 | */ |
cristy | 7de7f74 | 2012-12-14 00:28:27 +0000 | [diff] [blame] | 3389 | MagickExport Image *MorphImages(const Image *image,const size_t number_frames, |
| 3390 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3391 | { |
| 3392 | #define MorphImageTag "Morph/Image" |
| 3393 | |
cristy | fab8364 | 2012-12-14 00:31:38 +0000 | [diff] [blame] | 3394 | double |
| 3395 | alpha, |
| 3396 | beta; |
| 3397 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3398 | Image |
| 3399 | *morph_image, |
| 3400 | *morph_images; |
| 3401 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3402 | MagickBooleanType |
| 3403 | status; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3404 | |
| 3405 | MagickOffsetType |
| 3406 | scene; |
| 3407 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3408 | register const Image |
| 3409 | *next; |
| 3410 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3411 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3412 | i; |
| 3413 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3414 | ssize_t |
| 3415 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3416 | |
| 3417 | /* |
| 3418 | Clone first frame in sequence. |
| 3419 | */ |
| 3420 | assert(image != (Image *) NULL); |
| 3421 | assert(image->signature == MagickSignature); |
| 3422 | if (image->debug != MagickFalse) |
| 3423 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3424 | assert(exception != (ExceptionInfo *) NULL); |
| 3425 | assert(exception->signature == MagickSignature); |
| 3426 | morph_images=CloneImage(image,0,0,MagickTrue,exception); |
| 3427 | if (morph_images == (Image *) NULL) |
| 3428 | return((Image *) NULL); |
| 3429 | if (GetNextImageInList(image) == (Image *) NULL) |
| 3430 | { |
| 3431 | /* |
| 3432 | Morph single image. |
| 3433 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3434 | for (i=1; i < (ssize_t) number_frames; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3435 | { |
| 3436 | morph_image=CloneImage(image,0,0,MagickTrue,exception); |
| 3437 | if (morph_image == (Image *) NULL) |
| 3438 | { |
| 3439 | morph_images=DestroyImageList(morph_images); |
| 3440 | return((Image *) NULL); |
| 3441 | } |
| 3442 | AppendImageToList(&morph_images,morph_image); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3443 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3444 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3445 | MagickBooleanType |
| 3446 | proceed; |
| 3447 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3448 | proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i, |
| 3449 | number_frames); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3450 | if (proceed == MagickFalse) |
| 3451 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3452 | } |
| 3453 | } |
| 3454 | return(GetFirstImageInList(morph_images)); |
| 3455 | } |
| 3456 | /* |
| 3457 | Morph image sequence. |
| 3458 | */ |
| 3459 | status=MagickTrue; |
| 3460 | scene=0; |
| 3461 | next=image; |
| 3462 | for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next)) |
| 3463 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3464 | for (i=0; i < (ssize_t) number_frames; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3465 | { |
| 3466 | CacheView |
| 3467 | *image_view, |
| 3468 | *morph_view; |
| 3469 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3470 | beta=(double) (i+1.0)/(double) (number_frames+1.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3471 | alpha=1.0-beta; |
cristy | 15b98cd | 2010-09-12 19:42:50 +0000 | [diff] [blame] | 3472 | morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta* |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 3473 | GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta* |
| 3474 | GetNextImageInList(next)->rows+0.5),next->filter,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3475 | if (morph_image == (Image *) NULL) |
| 3476 | { |
| 3477 | morph_images=DestroyImageList(morph_images); |
| 3478 | return((Image *) NULL); |
| 3479 | } |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3480 | status=SetImageStorageClass(morph_image,DirectClass,exception); |
| 3481 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3482 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3483 | morph_image=DestroyImage(morph_image); |
| 3484 | return((Image *) NULL); |
| 3485 | } |
| 3486 | AppendImageToList(&morph_images,morph_image); |
| 3487 | morph_images=GetLastImageInList(morph_images); |
cristy | 15b98cd | 2010-09-12 19:42:50 +0000 | [diff] [blame] | 3488 | morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 3489 | morph_images->rows,GetNextImageInList(next)->filter,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3490 | if (morph_image == (Image *) NULL) |
| 3491 | { |
| 3492 | morph_images=DestroyImageList(morph_images); |
| 3493 | return((Image *) NULL); |
| 3494 | } |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3495 | image_view=AcquireVirtualCacheView(morph_image,exception); |
| 3496 | morph_view=AcquireAuthenticCacheView(morph_images,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3497 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3498 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 3499 | magick_threads(morph_image,morph_image,morph_image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3500 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3501 | for (y=0; y < (ssize_t) morph_images->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3502 | { |
| 3503 | MagickBooleanType |
| 3504 | sync; |
| 3505 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3506 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3507 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3508 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3509 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3510 | x; |
| 3511 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3512 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3513 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3514 | |
| 3515 | if (status == MagickFalse) |
| 3516 | continue; |
| 3517 | p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1, |
| 3518 | exception); |
| 3519 | q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1, |
| 3520 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3521 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3522 | { |
| 3523 | status=MagickFalse; |
| 3524 | continue; |
| 3525 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3526 | for (x=0; x < (ssize_t) morph_images->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3527 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3528 | register ssize_t |
| 3529 | i; |
| 3530 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 3531 | for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3532 | { |
cristy | 031a246 | 2013-05-24 13:29:27 +0000 | [diff] [blame] | 3533 | PixelChannel channel=GetPixelChannelChannel(morph_image,i); |
| 3534 | PixelTrait traits=GetPixelChannelTraits(morph_image,channel); |
| 3535 | PixelTrait morph_traits=GetPixelChannelTraits(morph_images,channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3536 | if ((traits == UndefinedPixelTrait) || |
| 3537 | (morph_traits == UndefinedPixelTrait)) |
| 3538 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 3539 | if (((morph_traits & CopyPixelTrait) != 0) || |
cristy | 031a246 | 2013-05-24 13:29:27 +0000 | [diff] [blame] | 3540 | (GetPixelReadMask(morph_images,p) == 0)) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3541 | { |
| 3542 | SetPixelChannel(morph_image,channel,p[i],q); |
| 3543 | continue; |
| 3544 | } |
| 3545 | SetPixelChannel(morph_image,channel,ClampToQuantum(alpha* |
| 3546 | GetPixelChannel(morph_images,channel,q)+beta*p[i]),q); |
| 3547 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3548 | p+=GetPixelChannels(morph_image); |
| 3549 | q+=GetPixelChannels(morph_images); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3550 | } |
| 3551 | sync=SyncCacheViewAuthenticPixels(morph_view,exception); |
| 3552 | if (sync == MagickFalse) |
| 3553 | status=MagickFalse; |
| 3554 | } |
| 3555 | morph_view=DestroyCacheView(morph_view); |
| 3556 | image_view=DestroyCacheView(image_view); |
| 3557 | morph_image=DestroyImage(morph_image); |
| 3558 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3559 | if (i < (ssize_t) number_frames) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3560 | break; |
| 3561 | /* |
| 3562 | Clone last frame in sequence. |
| 3563 | */ |
| 3564 | morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception); |
| 3565 | if (morph_image == (Image *) NULL) |
| 3566 | { |
| 3567 | morph_images=DestroyImageList(morph_images); |
| 3568 | return((Image *) NULL); |
| 3569 | } |
| 3570 | AppendImageToList(&morph_images,morph_image); |
| 3571 | morph_images=GetLastImageInList(morph_images); |
| 3572 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3573 | { |
| 3574 | MagickBooleanType |
| 3575 | proceed; |
| 3576 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3577 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3578 | #pragma omp critical (MagickCore_MorphImages) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3579 | #endif |
| 3580 | proceed=SetImageProgress(image,MorphImageTag,scene, |
| 3581 | GetImageListLength(image)); |
| 3582 | if (proceed == MagickFalse) |
| 3583 | status=MagickFalse; |
| 3584 | } |
| 3585 | scene++; |
| 3586 | } |
| 3587 | if (GetNextImageInList(next) != (Image *) NULL) |
| 3588 | { |
| 3589 | morph_images=DestroyImageList(morph_images); |
| 3590 | return((Image *) NULL); |
| 3591 | } |
| 3592 | return(GetFirstImageInList(morph_images)); |
| 3593 | } |
| 3594 | |
| 3595 | /* |
| 3596 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3597 | % % |
| 3598 | % % |
| 3599 | % % |
| 3600 | % P l a s m a I m a g e % |
| 3601 | % % |
| 3602 | % % |
| 3603 | % % |
| 3604 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3605 | % |
| 3606 | % PlasmaImage() initializes an image with plasma fractal values. The image |
| 3607 | % must be initialized with a base color and the random number generator |
| 3608 | % seeded before this method is called. |
| 3609 | % |
| 3610 | % The format of the PlasmaImage method is: |
| 3611 | % |
| 3612 | % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3613 | % size_t attenuate,size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3614 | % |
| 3615 | % A description of each parameter follows: |
| 3616 | % |
| 3617 | % o image: the image. |
| 3618 | % |
| 3619 | % o segment: Define the region to apply plasma fractals values. |
| 3620 | % |
glennrp | 7dae1ca | 2010-09-16 12:17:35 +0000 | [diff] [blame] | 3621 | % o attenuate: Define the plasma attenuation factor. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3622 | % |
| 3623 | % o depth: Limit the plasma recursion depth. |
| 3624 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3625 | % o exception: return any errors or warnings in this structure. |
| 3626 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3627 | */ |
| 3628 | |
| 3629 | static inline Quantum PlasmaPixel(RandomInfo *random_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3630 | const double pixel,const double noise) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3631 | { |
| 3632 | Quantum |
| 3633 | plasma; |
| 3634 | |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 3635 | plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3636 | noise/2.0); |
| 3637 | return(plasma); |
| 3638 | } |
| 3639 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3640 | static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view, |
| 3641 | CacheView *u_view,CacheView *v_view,RandomInfo *random_info, |
| 3642 | const SegmentInfo *segment,size_t attenuate,size_t depth, |
| 3643 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3644 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3645 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3646 | plasma; |
| 3647 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3648 | register const Quantum |
| 3649 | *restrict u, |
| 3650 | *restrict v; |
| 3651 | |
| 3652 | register Quantum |
| 3653 | *restrict q; |
| 3654 | |
| 3655 | register ssize_t |
| 3656 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3657 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3658 | ssize_t |
| 3659 | x, |
| 3660 | x_mid, |
| 3661 | y, |
| 3662 | y_mid; |
| 3663 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3664 | if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0)) |
| 3665 | return(MagickTrue); |
| 3666 | if (depth != 0) |
| 3667 | { |
| 3668 | SegmentInfo |
| 3669 | local_info; |
| 3670 | |
| 3671 | /* |
| 3672 | Divide the area into quadrants and recurse. |
| 3673 | */ |
| 3674 | depth--; |
| 3675 | attenuate++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3676 | x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5); |
| 3677 | y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3678 | local_info=(*segment); |
| 3679 | local_info.x2=(double) x_mid; |
| 3680 | local_info.y2=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3681 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3682 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3683 | local_info=(*segment); |
| 3684 | local_info.y1=(double) y_mid; |
| 3685 | local_info.x2=(double) x_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3686 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3687 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3688 | local_info=(*segment); |
| 3689 | local_info.x1=(double) x_mid; |
| 3690 | local_info.y2=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3691 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3692 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3693 | local_info=(*segment); |
| 3694 | local_info.x1=(double) x_mid; |
| 3695 | local_info.y1=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3696 | return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3697 | &local_info,attenuate,depth,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3698 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3699 | x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5); |
| 3700 | y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3701 | if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) && |
| 3702 | (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid)) |
| 3703 | return(MagickFalse); |
| 3704 | /* |
| 3705 | Average pixels and apply plasma. |
| 3706 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3707 | plasma=(double) QuantumRange/(2.0*attenuate); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3708 | if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid)) |
| 3709 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3710 | /* |
| 3711 | Left pixel. |
| 3712 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3713 | x=(ssize_t) ceil(segment->x1-0.5); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3714 | u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1, |
| 3715 | exception); |
| 3716 | v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1, |
| 3717 | exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3718 | q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3719 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3720 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3721 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3722 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3723 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3724 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3725 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3726 | if (traits == UndefinedPixelTrait) |
| 3727 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3728 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3729 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3730 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3731 | if (segment->x1 != segment->x2) |
| 3732 | { |
| 3733 | /* |
| 3734 | Right pixel. |
| 3735 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3736 | x=(ssize_t) ceil(segment->x2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3737 | u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5), |
| 3738 | 1,1,exception); |
| 3739 | v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5), |
| 3740 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3741 | q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3742 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3743 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3744 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3745 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3746 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3747 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3748 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3749 | if (traits == UndefinedPixelTrait) |
| 3750 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3751 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3752 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3753 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3754 | } |
| 3755 | } |
| 3756 | if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid)) |
| 3757 | { |
| 3758 | if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid)) |
| 3759 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3760 | /* |
| 3761 | Bottom pixel. |
| 3762 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3763 | y=(ssize_t) ceil(segment->y2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3764 | u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y, |
| 3765 | 1,1,exception); |
| 3766 | v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y, |
| 3767 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3768 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3769 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3770 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3771 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3772 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3773 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3774 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3775 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3776 | if (traits == UndefinedPixelTrait) |
| 3777 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3778 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3779 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3780 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3781 | } |
| 3782 | if (segment->y1 != segment->y2) |
| 3783 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3784 | /* |
| 3785 | Top pixel. |
| 3786 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3787 | y=(ssize_t) ceil(segment->y1-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3788 | u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y, |
| 3789 | 1,1,exception); |
| 3790 | v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y, |
| 3791 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3792 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3793 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3794 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3795 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3796 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3797 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3798 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3799 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3800 | if (traits == UndefinedPixelTrait) |
| 3801 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3802 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3803 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3804 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3805 | } |
| 3806 | } |
| 3807 | if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2)) |
| 3808 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3809 | /* |
| 3810 | Middle pixel. |
| 3811 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3812 | x=(ssize_t) ceil(segment->x1-0.5); |
| 3813 | y=(ssize_t) ceil(segment->y1-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3814 | u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3815 | x=(ssize_t) ceil(segment->x2-0.5); |
| 3816 | y=(ssize_t) ceil(segment->y2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3817 | v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3818 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3819 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3820 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3821 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3822 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3823 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3824 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3825 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3826 | if (traits == UndefinedPixelTrait) |
| 3827 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3828 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3829 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3830 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3831 | } |
| 3832 | if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0)) |
| 3833 | return(MagickTrue); |
| 3834 | return(MagickFalse); |
| 3835 | } |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3836 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3837 | MagickExport MagickBooleanType PlasmaImage(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3838 | const SegmentInfo *segment,size_t attenuate,size_t depth, |
| 3839 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3840 | { |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3841 | CacheView |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3842 | *image_view, |
| 3843 | *u_view, |
| 3844 | *v_view; |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3845 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3846 | MagickBooleanType |
| 3847 | status; |
| 3848 | |
| 3849 | RandomInfo |
| 3850 | *random_info; |
| 3851 | |
| 3852 | if (image->debug != MagickFalse) |
| 3853 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3854 | assert(image != (Image *) NULL); |
| 3855 | assert(image->signature == MagickSignature); |
| 3856 | if (image->debug != MagickFalse) |
| 3857 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3858 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3859 | return(MagickFalse); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3860 | image_view=AcquireAuthenticCacheView(image,exception); |
| 3861 | u_view=AcquireVirtualCacheView(image,exception); |
| 3862 | v_view=AcquireVirtualCacheView(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3863 | random_info=AcquireRandomInfo(); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3864 | status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment, |
| 3865 | attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3866 | random_info=DestroyRandomInfo(random_info); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3867 | v_view=DestroyCacheView(v_view); |
| 3868 | u_view=DestroyCacheView(u_view); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3869 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3870 | return(status); |
| 3871 | } |
| 3872 | |
| 3873 | /* |
| 3874 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3875 | % % |
| 3876 | % % |
| 3877 | % % |
| 3878 | % P o l a r o i d I m a g e % |
| 3879 | % % |
| 3880 | % % |
| 3881 | % % |
| 3882 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3883 | % |
| 3884 | % PolaroidImage() simulates a Polaroid picture. |
| 3885 | % |
| 3886 | % The format of the AnnotateImage method is: |
| 3887 | % |
| 3888 | % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3889 | % const char *caption,const double angle, |
| 3890 | % const PixelInterpolateMethod method,ExceptionInfo exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3891 | % |
| 3892 | % A description of each parameter follows: |
| 3893 | % |
| 3894 | % o image: the image. |
| 3895 | % |
| 3896 | % o draw_info: the draw info. |
| 3897 | % |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3898 | % o caption: the Polaroid caption. |
| 3899 | % |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 3900 | % o angle: Apply the effect along this angle. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3901 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3902 | % o method: the pixel interpolation method. |
| 3903 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3904 | % o exception: return any errors or warnings in this structure. |
| 3905 | % |
| 3906 | */ |
| 3907 | MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3908 | const char *caption,const double angle,const PixelInterpolateMethod method, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3909 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3910 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3911 | Image |
| 3912 | *bend_image, |
| 3913 | *caption_image, |
| 3914 | *flop_image, |
| 3915 | *picture_image, |
| 3916 | *polaroid_image, |
| 3917 | *rotate_image, |
| 3918 | *trim_image; |
| 3919 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3920 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3921 | height; |
| 3922 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3923 | ssize_t |
| 3924 | quantum; |
| 3925 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3926 | /* |
| 3927 | Simulate a Polaroid picture. |
| 3928 | */ |
| 3929 | assert(image != (Image *) NULL); |
| 3930 | assert(image->signature == MagickSignature); |
| 3931 | if (image->debug != MagickFalse) |
| 3932 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3933 | assert(exception != (ExceptionInfo *) NULL); |
| 3934 | assert(exception->signature == MagickSignature); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3935 | quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3936 | image->rows)/25.0,10.0); |
| 3937 | height=image->rows+2*quantum; |
| 3938 | caption_image=(Image *) NULL; |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3939 | if (caption != (const char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3940 | { |
| 3941 | char |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3942 | geometry[MaxTextExtent], |
| 3943 | *text; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3944 | |
| 3945 | DrawInfo |
| 3946 | *annotate_info; |
| 3947 | |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3948 | ImageInfo |
| 3949 | *image_info; |
| 3950 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3951 | MagickBooleanType |
| 3952 | status; |
| 3953 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3954 | ssize_t |
| 3955 | count; |
| 3956 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3957 | TypeMetric |
| 3958 | metrics; |
| 3959 | |
| 3960 | /* |
| 3961 | Generate caption image. |
| 3962 | */ |
| 3963 | caption_image=CloneImage(image,image->columns,1,MagickTrue,exception); |
| 3964 | if (caption_image == (Image *) NULL) |
| 3965 | return((Image *) NULL); |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3966 | image_info=AcquireImageInfo(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3967 | annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info); |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3968 | text=InterpretImageProperties(image_info,(Image *) image,caption, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3969 | exception); |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3970 | image_info=DestroyImageInfo(image_info); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3971 | (void) CloneString(&annotate_info->text,text); |
cristy | 6b1d05e | 2010-09-22 19:17:27 +0000 | [diff] [blame] | 3972 | count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3973 | &text,exception); |
| 3974 | status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)* |
| 3975 | (metrics.ascent-metrics.descent)+0.5),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3976 | if (status == MagickFalse) |
| 3977 | caption_image=DestroyImage(caption_image); |
| 3978 | else |
| 3979 | { |
| 3980 | caption_image->background_color=image->border_color; |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3981 | (void) SetImageBackgroundColor(caption_image,exception); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3982 | (void) CloneString(&annotate_info->text,text); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3983 | (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3984 | metrics.ascent); |
| 3985 | if (annotate_info->gravity == UndefinedGravity) |
| 3986 | (void) CloneString(&annotate_info->geometry,AcquireString( |
| 3987 | geometry)); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3988 | (void) AnnotateImage(caption_image,annotate_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3989 | height+=caption_image->rows; |
| 3990 | } |
| 3991 | annotate_info=DestroyDrawInfo(annotate_info); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3992 | text=DestroyString(text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3993 | } |
| 3994 | picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue, |
| 3995 | exception); |
| 3996 | if (picture_image == (Image *) NULL) |
| 3997 | { |
| 3998 | if (caption_image != (Image *) NULL) |
| 3999 | caption_image=DestroyImage(caption_image); |
| 4000 | return((Image *) NULL); |
| 4001 | } |
| 4002 | picture_image->background_color=image->border_color; |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 4003 | (void) SetImageBackgroundColor(picture_image,exception); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4004 | (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4005 | quantum,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4006 | if (caption_image != (Image *) NULL) |
| 4007 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4008 | (void) CompositeImage(picture_image,caption_image,OverCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4009 | MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4010 | caption_image=DestroyImage(caption_image); |
| 4011 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4012 | (void) QueryColorCompliance("none",AllCompliance, |
| 4013 | &picture_image->background_color,exception); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4014 | (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4015 | rotate_image=RotateImage(picture_image,90.0,exception); |
| 4016 | picture_image=DestroyImage(picture_image); |
| 4017 | if (rotate_image == (Image *) NULL) |
| 4018 | return((Image *) NULL); |
| 4019 | picture_image=rotate_image; |
| 4020 | bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0* |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4021 | picture_image->columns,method,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4022 | picture_image=DestroyImage(picture_image); |
| 4023 | if (bend_image == (Image *) NULL) |
| 4024 | return((Image *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4025 | picture_image=bend_image; |
| 4026 | rotate_image=RotateImage(picture_image,-90.0,exception); |
| 4027 | picture_image=DestroyImage(picture_image); |
| 4028 | if (rotate_image == (Image *) NULL) |
| 4029 | return((Image *) NULL); |
| 4030 | picture_image=rotate_image; |
| 4031 | picture_image->background_color=image->background_color; |
anthony | f46d426 | 2012-03-26 03:30:34 +0000 | [diff] [blame] | 4032 | polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4033 | exception); |
| 4034 | if (polaroid_image == (Image *) NULL) |
| 4035 | { |
| 4036 | picture_image=DestroyImage(picture_image); |
| 4037 | return(picture_image); |
| 4038 | } |
| 4039 | flop_image=FlopImage(polaroid_image,exception); |
| 4040 | polaroid_image=DestroyImage(polaroid_image); |
| 4041 | if (flop_image == (Image *) NULL) |
| 4042 | { |
| 4043 | picture_image=DestroyImage(picture_image); |
| 4044 | return(picture_image); |
| 4045 | } |
| 4046 | polaroid_image=flop_image; |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4047 | (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4048 | MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4049 | picture_image=DestroyImage(picture_image); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4050 | (void) QueryColorCompliance("none",AllCompliance, |
| 4051 | &polaroid_image->background_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4052 | rotate_image=RotateImage(polaroid_image,angle,exception); |
| 4053 | polaroid_image=DestroyImage(polaroid_image); |
| 4054 | if (rotate_image == (Image *) NULL) |
| 4055 | return((Image *) NULL); |
| 4056 | polaroid_image=rotate_image; |
| 4057 | trim_image=TrimImage(polaroid_image,exception); |
| 4058 | polaroid_image=DestroyImage(polaroid_image); |
| 4059 | if (trim_image == (Image *) NULL) |
| 4060 | return((Image *) NULL); |
| 4061 | polaroid_image=trim_image; |
| 4062 | return(polaroid_image); |
| 4063 | } |
| 4064 | |
| 4065 | /* |
| 4066 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4067 | % % |
| 4068 | % % |
| 4069 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4070 | % S e p i a T o n e I m a g e % |
| 4071 | % % |
| 4072 | % % |
| 4073 | % % |
| 4074 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4075 | % |
| 4076 | % MagickSepiaToneImage() applies a special effect to the image, similar to the |
| 4077 | % effect achieved in a photo darkroom by sepia toning. Threshold ranges from |
| 4078 | % 0 to QuantumRange and is a measure of the extent of the sepia toning. A |
| 4079 | % threshold of 80% is a good starting point for a reasonable tone. |
| 4080 | % |
| 4081 | % The format of the SepiaToneImage method is: |
| 4082 | % |
| 4083 | % Image *SepiaToneImage(const Image *image,const double threshold, |
| 4084 | % ExceptionInfo *exception) |
| 4085 | % |
| 4086 | % A description of each parameter follows: |
| 4087 | % |
| 4088 | % o image: the image. |
| 4089 | % |
| 4090 | % o threshold: the tone threshold. |
| 4091 | % |
| 4092 | % o exception: return any errors or warnings in this structure. |
| 4093 | % |
| 4094 | */ |
| 4095 | MagickExport Image *SepiaToneImage(const Image *image,const double threshold, |
| 4096 | ExceptionInfo *exception) |
| 4097 | { |
| 4098 | #define SepiaToneImageTag "SepiaTone/Image" |
| 4099 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4100 | CacheView |
| 4101 | *image_view, |
| 4102 | *sepia_view; |
| 4103 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4104 | Image |
| 4105 | *sepia_image; |
| 4106 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4107 | MagickBooleanType |
| 4108 | status; |
| 4109 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4110 | MagickOffsetType |
| 4111 | progress; |
| 4112 | |
| 4113 | ssize_t |
| 4114 | y; |
| 4115 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4116 | /* |
| 4117 | Initialize sepia-toned image attributes. |
| 4118 | */ |
| 4119 | assert(image != (const Image *) NULL); |
| 4120 | assert(image->signature == MagickSignature); |
| 4121 | if (image->debug != MagickFalse) |
| 4122 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4123 | assert(exception != (ExceptionInfo *) NULL); |
| 4124 | assert(exception->signature == MagickSignature); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4125 | sepia_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4126 | if (sepia_image == (Image *) NULL) |
| 4127 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4128 | if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4129 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4130 | sepia_image=DestroyImage(sepia_image); |
| 4131 | return((Image *) NULL); |
| 4132 | } |
| 4133 | /* |
| 4134 | Tone each row of the image. |
| 4135 | */ |
| 4136 | status=MagickTrue; |
| 4137 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4138 | image_view=AcquireVirtualCacheView(image,exception); |
| 4139 | sepia_view=AcquireAuthenticCacheView(sepia_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4140 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 4141 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 4142 | magick_threads(image,sepia_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4143 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4144 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4145 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4146 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4147 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4148 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4149 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4150 | x; |
| 4151 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4152 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4153 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4154 | |
| 4155 | if (status == MagickFalse) |
| 4156 | continue; |
| 4157 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4158 | q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4159 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4160 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4161 | { |
| 4162 | status=MagickFalse; |
| 4163 | continue; |
| 4164 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4165 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4166 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4167 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4168 | intensity, |
| 4169 | tone; |
| 4170 | |
cristy | f13c594 | 2012-08-08 23:50:11 +0000 | [diff] [blame] | 4171 | intensity=GetPixelIntensity(image,p); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4172 | tone=intensity > threshold ? (double) QuantumRange : intensity+ |
| 4173 | (double) QuantumRange-threshold; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4174 | SetPixelRed(sepia_image,ClampToQuantum(tone),q); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4175 | tone=intensity > (7.0*threshold/6.0) ? (double) QuantumRange : |
| 4176 | intensity+(double) QuantumRange-7.0*threshold/6.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4177 | SetPixelGreen(sepia_image,ClampToQuantum(tone),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4178 | tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4179 | SetPixelBlue(sepia_image,ClampToQuantum(tone),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4180 | tone=threshold/7.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4181 | if ((double) GetPixelGreen(image,q) < tone) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4182 | SetPixelGreen(sepia_image,ClampToQuantum(tone),q); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4183 | if ((double) GetPixelBlue(image,q) < tone) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4184 | SetPixelBlue(sepia_image,ClampToQuantum(tone),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4185 | p+=GetPixelChannels(image); |
| 4186 | q+=GetPixelChannels(sepia_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4187 | } |
| 4188 | if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse) |
| 4189 | status=MagickFalse; |
| 4190 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 4191 | { |
| 4192 | MagickBooleanType |
| 4193 | proceed; |
| 4194 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4195 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 4196 | #pragma omp critical (MagickCore_SepiaToneImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4197 | #endif |
| 4198 | proceed=SetImageProgress(image,SepiaToneImageTag,progress++, |
| 4199 | image->rows); |
| 4200 | if (proceed == MagickFalse) |
| 4201 | status=MagickFalse; |
| 4202 | } |
| 4203 | } |
| 4204 | sepia_view=DestroyCacheView(sepia_view); |
| 4205 | image_view=DestroyCacheView(image_view); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 4206 | (void) NormalizeImage(sepia_image,exception); |
| 4207 | (void) ContrastImage(sepia_image,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4208 | if (status == MagickFalse) |
| 4209 | sepia_image=DestroyImage(sepia_image); |
| 4210 | return(sepia_image); |
| 4211 | } |
| 4212 | |
| 4213 | /* |
| 4214 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4215 | % % |
| 4216 | % % |
| 4217 | % % |
| 4218 | % S h a d o w I m a g e % |
| 4219 | % % |
| 4220 | % % |
| 4221 | % % |
| 4222 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4223 | % |
| 4224 | % ShadowImage() simulates a shadow from the specified image and returns it. |
| 4225 | % |
| 4226 | % The format of the ShadowImage method is: |
| 4227 | % |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4228 | % Image *ShadowImage(const Image *image,const double alpha, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4229 | % const double sigma,const ssize_t x_offset,const ssize_t y_offset, |
| 4230 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4231 | % |
| 4232 | % A description of each parameter follows: |
| 4233 | % |
| 4234 | % o image: the image. |
| 4235 | % |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4236 | % o alpha: percentage transparency. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4237 | % |
| 4238 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 4239 | % |
| 4240 | % o x_offset: the shadow x-offset. |
| 4241 | % |
| 4242 | % o y_offset: the shadow y-offset. |
| 4243 | % |
| 4244 | % o exception: return any errors or warnings in this structure. |
| 4245 | % |
| 4246 | */ |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4247 | MagickExport Image *ShadowImage(const Image *image,const double alpha, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4248 | const double sigma,const ssize_t x_offset,const ssize_t y_offset, |
| 4249 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4250 | { |
| 4251 | #define ShadowImageTag "Shadow/Image" |
| 4252 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4253 | CacheView |
| 4254 | *image_view; |
| 4255 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4256 | ChannelType |
| 4257 | channel_mask; |
| 4258 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4259 | Image |
| 4260 | *border_image, |
| 4261 | *clone_image, |
| 4262 | *shadow_image; |
| 4263 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4264 | MagickBooleanType |
| 4265 | status; |
| 4266 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4267 | RectangleInfo |
| 4268 | border_info; |
| 4269 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4270 | ssize_t |
| 4271 | y; |
| 4272 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4273 | assert(image != (Image *) NULL); |
| 4274 | assert(image->signature == MagickSignature); |
| 4275 | if (image->debug != MagickFalse) |
| 4276 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4277 | assert(exception != (ExceptionInfo *) NULL); |
| 4278 | assert(exception->signature == MagickSignature); |
| 4279 | clone_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4280 | if (clone_image == (Image *) NULL) |
| 4281 | return((Image *) NULL); |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 4282 | if (IsGrayColorspace(image->colorspace) != MagickFalse) |
cristy | 0c81d06 | 2013-04-21 15:22:02 +0000 | [diff] [blame] | 4283 | (void) SetImageColorspace(clone_image,sRGBColorspace,exception); |
cristy | 0ce0876 | 2012-06-30 01:33:18 +0000 | [diff] [blame] | 4284 | (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod, |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4285 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4286 | border_info.width=(size_t) floor(2.0*sigma+0.5); |
| 4287 | border_info.height=(size_t) floor(2.0*sigma+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4288 | border_info.x=0; |
| 4289 | border_info.y=0; |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4290 | (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color, |
| 4291 | exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4292 | clone_image->alpha_trait=BlendPixelTrait; |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4293 | border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4294 | clone_image=DestroyImage(clone_image); |
| 4295 | if (border_image == (Image *) NULL) |
| 4296 | return((Image *) NULL); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4297 | if (border_image->alpha_trait != BlendPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4298 | (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4299 | /* |
| 4300 | Shadow image. |
| 4301 | */ |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4302 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4303 | image_view=AcquireAuthenticCacheView(border_image,exception); |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4304 | for (y=0; y < (ssize_t) border_image->rows; y++) |
| 4305 | { |
| 4306 | PixelInfo |
| 4307 | background_color; |
| 4308 | |
| 4309 | register Quantum |
| 4310 | *restrict q; |
| 4311 | |
| 4312 | register ssize_t |
| 4313 | x; |
| 4314 | |
| 4315 | if (status == MagickFalse) |
| 4316 | continue; |
| 4317 | q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1, |
| 4318 | exception); |
| 4319 | if (q == (Quantum *) NULL) |
| 4320 | { |
| 4321 | status=MagickFalse; |
| 4322 | continue; |
| 4323 | } |
| 4324 | background_color=border_image->background_color; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4325 | background_color.alpha_trait=BlendPixelTrait; |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4326 | for (x=0; x < (ssize_t) border_image->columns; x++) |
| 4327 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4328 | if (border_image->alpha_trait == BlendPixelTrait) |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4329 | background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0; |
| 4330 | SetPixelInfoPixel(border_image,&background_color,q); |
| 4331 | q+=GetPixelChannels(border_image); |
| 4332 | } |
| 4333 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 4334 | status=MagickFalse; |
| 4335 | } |
| 4336 | image_view=DestroyCacheView(image_view); |
| 4337 | if (status == MagickFalse) |
| 4338 | { |
| 4339 | border_image=DestroyImage(border_image); |
| 4340 | return((Image *) NULL); |
| 4341 | } |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4342 | channel_mask=SetImageChannelMask(border_image,AlphaChannel); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4343 | shadow_image=BlurImage(border_image,0.0,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4344 | border_image=DestroyImage(border_image); |
| 4345 | if (shadow_image == (Image *) NULL) |
| 4346 | return((Image *) NULL); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4347 | (void) SetPixelChannelMask(shadow_image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4348 | if (shadow_image->page.width == 0) |
| 4349 | shadow_image->page.width=shadow_image->columns; |
| 4350 | if (shadow_image->page.height == 0) |
| 4351 | shadow_image->page.height=shadow_image->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4352 | shadow_image->page.width+=x_offset-(ssize_t) border_info.width; |
| 4353 | shadow_image->page.height+=y_offset-(ssize_t) border_info.height; |
| 4354 | shadow_image->page.x+=x_offset-(ssize_t) border_info.width; |
| 4355 | shadow_image->page.y+=y_offset-(ssize_t) border_info.height; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4356 | return(shadow_image); |
| 4357 | } |
| 4358 | |
| 4359 | /* |
| 4360 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4361 | % % |
| 4362 | % % |
| 4363 | % % |
| 4364 | % S k e t c h I m a g e % |
| 4365 | % % |
| 4366 | % % |
| 4367 | % % |
| 4368 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4369 | % |
| 4370 | % SketchImage() simulates a pencil sketch. We convolve the image with a |
| 4371 | % Gaussian operator of the given radius and standard deviation (sigma). For |
| 4372 | % reasonable results, radius should be larger than sigma. Use a radius of 0 |
| 4373 | % and SketchImage() selects a suitable radius for you. Angle gives the angle |
| 4374 | % of the sketch. |
| 4375 | % |
| 4376 | % The format of the SketchImage method is: |
| 4377 | % |
| 4378 | % Image *SketchImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4379 | % const double sigma,const double angle,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4380 | % |
| 4381 | % A description of each parameter follows: |
| 4382 | % |
| 4383 | % o image: the image. |
| 4384 | % |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4385 | % o radius: the radius of the Gaussian, in pixels, not counting the |
| 4386 | % center pixel. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4387 | % |
| 4388 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 4389 | % |
cristy | f7ef025 | 2011-09-09 14:50:06 +0000 | [diff] [blame] | 4390 | % o angle: apply the effect along this angle. |
| 4391 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4392 | % o exception: return any errors or warnings in this structure. |
| 4393 | % |
| 4394 | */ |
| 4395 | MagickExport Image *SketchImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4396 | const double sigma,const double angle,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4397 | { |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 4398 | CacheView |
| 4399 | *random_view; |
| 4400 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4401 | Image |
| 4402 | *blend_image, |
| 4403 | *blur_image, |
| 4404 | *dodge_image, |
| 4405 | *random_image, |
| 4406 | *sketch_image; |
| 4407 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4408 | MagickBooleanType |
| 4409 | status; |
| 4410 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4411 | RandomInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 4412 | **restrict random_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4413 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 4414 | ssize_t |
| 4415 | y; |
| 4416 | |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4417 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4418 | unsigned long |
| 4419 | key; |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4420 | #endif |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4421 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4422 | /* |
| 4423 | Sketch image. |
| 4424 | */ |
| 4425 | random_image=CloneImage(image,image->columns << 1,image->rows << 1, |
| 4426 | MagickTrue,exception); |
| 4427 | if (random_image == (Image *) NULL) |
| 4428 | return((Image *) NULL); |
| 4429 | status=MagickTrue; |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4430 | random_info=AcquireRandomInfoThreadSet(); |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4431 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4432 | key=GetRandomSecretKey(random_info[0]); |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4433 | #endif |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4434 | random_view=AcquireAuthenticCacheView(random_image,exception); |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4435 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4436 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 4437 | magick_threads(random_image,random_image,random_image->rows,key == ~0UL) |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4438 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4439 | for (y=0; y < (ssize_t) random_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4440 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 4441 | const int |
| 4442 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 4443 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4444 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4445 | x; |
| 4446 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4447 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4448 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4449 | |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4450 | if (status == MagickFalse) |
| 4451 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4452 | q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1, |
| 4453 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4454 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4455 | { |
| 4456 | status=MagickFalse; |
| 4457 | continue; |
| 4458 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4459 | for (x=0; x < (ssize_t) random_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4460 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4461 | double |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4462 | value; |
| 4463 | |
| 4464 | register ssize_t |
| 4465 | i; |
| 4466 | |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 4467 | if (GetPixelReadMask(random_image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 4468 | { |
| 4469 | q+=GetPixelChannels(random_image); |
| 4470 | continue; |
| 4471 | } |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4472 | value=GetPseudoRandomValue(random_info[id]); |
| 4473 | for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++) |
| 4474 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 4475 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 4476 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4477 | if (traits == UndefinedPixelTrait) |
| 4478 | continue; |
| 4479 | q[i]=ClampToQuantum(QuantumRange*value); |
| 4480 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4481 | q+=GetPixelChannels(random_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4482 | } |
| 4483 | if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse) |
| 4484 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4485 | } |
| 4486 | random_view=DestroyCacheView(random_view); |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4487 | random_info=DestroyRandomInfoThreadSet(random_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4488 | if (status == MagickFalse) |
| 4489 | { |
| 4490 | random_image=DestroyImage(random_image); |
| 4491 | return(random_image); |
| 4492 | } |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4493 | blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4494 | random_image=DestroyImage(random_image); |
| 4495 | if (blur_image == (Image *) NULL) |
| 4496 | return((Image *) NULL); |
cristy | 800446a | 2013-05-20 20:15:38 +0000 | [diff] [blame] | 4497 | dodge_image=EdgeImage(blur_image,radius,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4498 | blur_image=DestroyImage(blur_image); |
| 4499 | if (dodge_image == (Image *) NULL) |
| 4500 | return((Image *) NULL); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 4501 | (void) NormalizeImage(dodge_image,exception); |
cristy | b3e7c6c | 2011-07-24 01:43:55 +0000 | [diff] [blame] | 4502 | (void) NegateImage(dodge_image,MagickFalse,exception); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4503 | (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4504 | sketch_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4505 | if (sketch_image == (Image *) NULL) |
| 4506 | { |
| 4507 | dodge_image=DestroyImage(dodge_image); |
| 4508 | return((Image *) NULL); |
| 4509 | } |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4510 | (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4511 | MagickTrue,0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4512 | dodge_image=DestroyImage(dodge_image); |
| 4513 | blend_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4514 | if (blend_image == (Image *) NULL) |
| 4515 | { |
| 4516 | sketch_image=DestroyImage(sketch_image); |
| 4517 | return((Image *) NULL); |
| 4518 | } |
| 4519 | (void) SetImageArtifact(blend_image,"compose:args","20x80"); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4520 | (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4521 | 0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4522 | blend_image=DestroyImage(blend_image); |
| 4523 | return(sketch_image); |
| 4524 | } |
| 4525 | |
| 4526 | /* |
| 4527 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4528 | % % |
| 4529 | % % |
| 4530 | % % |
| 4531 | % S o l a r i z e I m a g e % |
| 4532 | % % |
| 4533 | % % |
| 4534 | % % |
| 4535 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4536 | % |
| 4537 | % SolarizeImage() applies a special effect to the image, similar to the effect |
| 4538 | % achieved in a photo darkroom by selectively exposing areas of photo |
| 4539 | % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a |
| 4540 | % measure of the extent of the solarization. |
| 4541 | % |
| 4542 | % The format of the SolarizeImage method is: |
| 4543 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4544 | % MagickBooleanType SolarizeImage(Image *image,const double threshold, |
| 4545 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4546 | % |
| 4547 | % A description of each parameter follows: |
| 4548 | % |
| 4549 | % o image: the image. |
| 4550 | % |
| 4551 | % o threshold: Define the extent of the solarization. |
| 4552 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4553 | % o exception: return any errors or warnings in this structure. |
| 4554 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4555 | */ |
| 4556 | MagickExport MagickBooleanType SolarizeImage(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4557 | const double threshold,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4558 | { |
| 4559 | #define SolarizeImageTag "Solarize/Image" |
| 4560 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4561 | CacheView |
| 4562 | *image_view; |
| 4563 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4564 | MagickBooleanType |
| 4565 | status; |
| 4566 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4567 | MagickOffsetType |
| 4568 | progress; |
| 4569 | |
| 4570 | ssize_t |
| 4571 | y; |
| 4572 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4573 | assert(image != (Image *) NULL); |
| 4574 | assert(image->signature == MagickSignature); |
| 4575 | if (image->debug != MagickFalse) |
| 4576 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 4577 | if (IsGrayColorspace(image->colorspace) != MagickFalse) |
cristy | 0c81d06 | 2013-04-21 15:22:02 +0000 | [diff] [blame] | 4578 | (void) SetImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4579 | if (image->storage_class == PseudoClass) |
| 4580 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4581 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4582 | i; |
| 4583 | |
| 4584 | /* |
| 4585 | Solarize colormap. |
| 4586 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4587 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4588 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4589 | if ((double) image->colormap[i].red > threshold) |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame] | 4590 | image->colormap[i].red=QuantumRange-image->colormap[i].red; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4591 | if ((double) image->colormap[i].green > threshold) |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame] | 4592 | image->colormap[i].green=QuantumRange- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4593 | image->colormap[i].green; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4594 | if ((double) image->colormap[i].blue > threshold) |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame] | 4595 | image->colormap[i].blue=QuantumRange- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4596 | image->colormap[i].blue; |
| 4597 | } |
| 4598 | } |
| 4599 | /* |
| 4600 | Solarize image. |
| 4601 | */ |
| 4602 | status=MagickTrue; |
| 4603 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4604 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4605 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 4606 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 4607 | magick_threads(image,image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4608 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4609 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4610 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4611 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4612 | x; |
| 4613 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4614 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4615 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4616 | |
| 4617 | if (status == MagickFalse) |
| 4618 | continue; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4619 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4620 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4621 | { |
| 4622 | status=MagickFalse; |
| 4623 | continue; |
| 4624 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4625 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4626 | { |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4627 | register ssize_t |
| 4628 | i; |
| 4629 | |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 4630 | if (GetPixelReadMask(image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 4631 | { |
| 4632 | q+=GetPixelChannels(image); |
| 4633 | continue; |
| 4634 | } |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4635 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 4636 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 4637 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 4638 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4639 | if ((traits == UndefinedPixelTrait) || |
| 4640 | ((traits & CopyPixelTrait) != 0)) |
| 4641 | continue; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4642 | if ((double) q[i] > threshold) |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4643 | q[i]=QuantumRange-q[i]; |
| 4644 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4645 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4646 | } |
| 4647 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 4648 | status=MagickFalse; |
| 4649 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 4650 | { |
| 4651 | MagickBooleanType |
| 4652 | proceed; |
| 4653 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4654 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 4655 | #pragma omp critical (MagickCore_SolarizeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4656 | #endif |
| 4657 | proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows); |
| 4658 | if (proceed == MagickFalse) |
| 4659 | status=MagickFalse; |
| 4660 | } |
| 4661 | } |
| 4662 | image_view=DestroyCacheView(image_view); |
| 4663 | return(status); |
| 4664 | } |
| 4665 | |
| 4666 | /* |
| 4667 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4668 | % % |
| 4669 | % % |
| 4670 | % % |
| 4671 | % S t e g a n o I m a g e % |
| 4672 | % % |
| 4673 | % % |
| 4674 | % % |
| 4675 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4676 | % |
| 4677 | % SteganoImage() hides a digital watermark within the image. Recover |
| 4678 | % the hidden watermark later to prove that the authenticity of an image. |
| 4679 | % Offset defines the start position within the image to hide the watermark. |
| 4680 | % |
| 4681 | % The format of the SteganoImage method is: |
| 4682 | % |
| 4683 | % Image *SteganoImage(const Image *image,Image *watermark, |
| 4684 | % ExceptionInfo *exception) |
| 4685 | % |
| 4686 | % A description of each parameter follows: |
| 4687 | % |
| 4688 | % o image: the image. |
| 4689 | % |
| 4690 | % o watermark: the watermark image. |
| 4691 | % |
| 4692 | % o exception: return any errors or warnings in this structure. |
| 4693 | % |
| 4694 | */ |
| 4695 | MagickExport Image *SteganoImage(const Image *image,const Image *watermark, |
| 4696 | ExceptionInfo *exception) |
| 4697 | { |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4698 | #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4699 | #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \ |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4700 | | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4701 | #define SteganoImageTag "Stegano/Image" |
| 4702 | |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4703 | CacheView |
| 4704 | *stegano_view, |
| 4705 | *watermark_view; |
| 4706 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4707 | Image |
| 4708 | *stegano_image; |
| 4709 | |
| 4710 | int |
| 4711 | c; |
| 4712 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4713 | MagickBooleanType |
| 4714 | status; |
| 4715 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4716 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4717 | pixel; |
| 4718 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4719 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4720 | *q; |
| 4721 | |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4722 | register ssize_t |
| 4723 | x; |
| 4724 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4725 | size_t |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4726 | depth, |
| 4727 | one; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4728 | |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4729 | ssize_t |
| 4730 | i, |
| 4731 | j, |
| 4732 | k, |
| 4733 | y; |
| 4734 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4735 | /* |
| 4736 | Initialize steganographic image attributes. |
| 4737 | */ |
| 4738 | assert(image != (const Image *) NULL); |
| 4739 | assert(image->signature == MagickSignature); |
| 4740 | if (image->debug != MagickFalse) |
| 4741 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4742 | assert(watermark != (const Image *) NULL); |
| 4743 | assert(watermark->signature == MagickSignature); |
| 4744 | assert(exception != (ExceptionInfo *) NULL); |
| 4745 | assert(exception->signature == MagickSignature); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4746 | one=1UL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4747 | stegano_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4748 | if (stegano_image == (Image *) NULL) |
| 4749 | return((Image *) NULL); |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4750 | stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH; |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4751 | if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4752 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4753 | stegano_image=DestroyImage(stegano_image); |
| 4754 | return((Image *) NULL); |
| 4755 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4756 | /* |
| 4757 | Hide watermark in low-order bits of image. |
| 4758 | */ |
| 4759 | c=0; |
| 4760 | i=0; |
| 4761 | j=0; |
| 4762 | depth=stegano_image->depth; |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4763 | k=stegano_image->offset; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4764 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4765 | watermark_view=AcquireVirtualCacheView(watermark,exception); |
| 4766 | stegano_view=AcquireAuthenticCacheView(stegano_image,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4767 | for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4768 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4769 | for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4770 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4771 | for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4772 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4773 | ssize_t |
| 4774 | offset; |
| 4775 | |
cristy | f05d494 | 2012-03-17 16:26:09 +0000 | [diff] [blame] | 4776 | (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4777 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4778 | offset=k/(ssize_t) stegano_image->columns; |
| 4779 | if (offset >= (ssize_t) stegano_image->rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4780 | break; |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4781 | q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t) |
| 4782 | stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1, |
| 4783 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4784 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4785 | break; |
| 4786 | switch (c) |
| 4787 | { |
| 4788 | case 0: |
| 4789 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4790 | SetPixelRed(stegano_image,SetBit(GetPixelRed(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 | case 1: |
| 4795 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4796 | SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j, |
| 4797 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4798 | break; |
| 4799 | } |
| 4800 | case 2: |
| 4801 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4802 | SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j, |
| 4803 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4804 | break; |
| 4805 | } |
| 4806 | } |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4807 | if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4808 | break; |
| 4809 | c++; |
| 4810 | if (c == 3) |
| 4811 | c=0; |
| 4812 | k++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4813 | if (k == (ssize_t) (stegano_image->columns*stegano_image->columns)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4814 | k=0; |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4815 | if (k == stegano_image->offset) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4816 | j++; |
| 4817 | } |
| 4818 | } |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4819 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4820 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4821 | MagickBooleanType |
| 4822 | proceed; |
| 4823 | |
| 4824 | proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType) |
| 4825 | (depth-i),depth); |
| 4826 | if (proceed == MagickFalse) |
| 4827 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4828 | } |
| 4829 | } |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4830 | stegano_view=DestroyCacheView(stegano_view); |
| 4831 | watermark_view=DestroyCacheView(watermark_view); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4832 | if (status == MagickFalse) |
cristy | fab8364 | 2012-12-14 00:31:38 +0000 | [diff] [blame] | 4833 | stegano_image=DestroyImage(stegano_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4834 | return(stegano_image); |
| 4835 | } |
| 4836 | |
| 4837 | /* |
| 4838 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4839 | % % |
| 4840 | % % |
| 4841 | % % |
| 4842 | % S t e r e o A n a g l y p h I m a g e % |
| 4843 | % % |
| 4844 | % % |
| 4845 | % % |
| 4846 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4847 | % |
| 4848 | % StereoAnaglyphImage() combines two images and produces a single image that |
| 4849 | % is the composite of a left and right image of a stereo pair. Special |
| 4850 | % red-green stereo glasses are required to view this effect. |
| 4851 | % |
| 4852 | % The format of the StereoAnaglyphImage method is: |
| 4853 | % |
| 4854 | % Image *StereoImage(const Image *left_image,const Image *right_image, |
| 4855 | % ExceptionInfo *exception) |
| 4856 | % Image *StereoAnaglyphImage(const Image *left_image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4857 | % 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] | 4858 | % ExceptionInfo *exception) |
| 4859 | % |
| 4860 | % A description of each parameter follows: |
| 4861 | % |
| 4862 | % o left_image: the left image. |
| 4863 | % |
| 4864 | % o right_image: the right image. |
| 4865 | % |
| 4866 | % o exception: return any errors or warnings in this structure. |
| 4867 | % |
| 4868 | % o x_offset: amount, in pixels, by which the left image is offset to the |
| 4869 | % right of the right image. |
| 4870 | % |
| 4871 | % o y_offset: amount, in pixels, by which the left image is offset to the |
| 4872 | % bottom of the right image. |
| 4873 | % |
| 4874 | % |
| 4875 | */ |
| 4876 | MagickExport Image *StereoImage(const Image *left_image, |
| 4877 | const Image *right_image,ExceptionInfo *exception) |
| 4878 | { |
| 4879 | return(StereoAnaglyphImage(left_image,right_image,0,0,exception)); |
| 4880 | } |
| 4881 | |
| 4882 | MagickExport Image *StereoAnaglyphImage(const Image *left_image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4883 | 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] | 4884 | ExceptionInfo *exception) |
| 4885 | { |
| 4886 | #define StereoImageTag "Stereo/Image" |
| 4887 | |
| 4888 | const Image |
| 4889 | *image; |
| 4890 | |
| 4891 | Image |
| 4892 | *stereo_image; |
| 4893 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4894 | MagickBooleanType |
| 4895 | status; |
| 4896 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 4897 | ssize_t |
| 4898 | y; |
| 4899 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4900 | assert(left_image != (const Image *) NULL); |
| 4901 | assert(left_image->signature == MagickSignature); |
| 4902 | if (left_image->debug != MagickFalse) |
| 4903 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 4904 | left_image->filename); |
| 4905 | assert(right_image != (const Image *) NULL); |
| 4906 | assert(right_image->signature == MagickSignature); |
| 4907 | assert(exception != (ExceptionInfo *) NULL); |
| 4908 | assert(exception->signature == MagickSignature); |
| 4909 | assert(right_image != (const Image *) NULL); |
| 4910 | image=left_image; |
| 4911 | if ((left_image->columns != right_image->columns) || |
| 4912 | (left_image->rows != right_image->rows)) |
| 4913 | ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer"); |
| 4914 | /* |
| 4915 | Initialize stereo image attributes. |
| 4916 | */ |
| 4917 | stereo_image=CloneImage(left_image,left_image->columns,left_image->rows, |
| 4918 | MagickTrue,exception); |
| 4919 | if (stereo_image == (Image *) NULL) |
| 4920 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4921 | if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4922 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4923 | stereo_image=DestroyImage(stereo_image); |
| 4924 | return((Image *) NULL); |
| 4925 | } |
cristy | 079c78d | 2012-07-03 11:53:48 +0000 | [diff] [blame] | 4926 | (void) SetImageColorspace(stereo_image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4927 | /* |
| 4928 | Copy left image to red channel and right image to blue channel. |
| 4929 | */ |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4930 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4931 | for (y=0; y < (ssize_t) stereo_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4932 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4933 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4934 | *restrict p, |
| 4935 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4936 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4937 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4938 | x; |
| 4939 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4940 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4941 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4942 | |
| 4943 | p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1, |
| 4944 | exception); |
| 4945 | q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception); |
| 4946 | r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4947 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) || |
| 4948 | (r == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4949 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4950 | for (x=0; x < (ssize_t) stereo_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4951 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4952 | SetPixelRed(image,GetPixelRed(left_image,p),r); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4953 | SetPixelGreen(image,GetPixelGreen(right_image,q),r); |
| 4954 | SetPixelBlue(image,GetPixelBlue(right_image,q),r); |
| 4955 | if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0) |
| 4956 | SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+ |
| 4957 | GetPixelAlpha(right_image,q))/2,r); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4958 | p+=GetPixelChannels(left_image); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4959 | q+=GetPixelChannels(right_image); |
| 4960 | r+=GetPixelChannels(stereo_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4961 | } |
| 4962 | if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse) |
| 4963 | break; |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4964 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4965 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4966 | MagickBooleanType |
| 4967 | proceed; |
| 4968 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4969 | proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y, |
| 4970 | stereo_image->rows); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4971 | if (proceed == MagickFalse) |
| 4972 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4973 | } |
| 4974 | } |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4975 | if (status == MagickFalse) |
cristy | fab8364 | 2012-12-14 00:31:38 +0000 | [diff] [blame] | 4976 | stereo_image=DestroyImage(stereo_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4977 | return(stereo_image); |
| 4978 | } |
| 4979 | |
| 4980 | /* |
| 4981 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4982 | % % |
| 4983 | % % |
| 4984 | % % |
| 4985 | % S w i r l I m a g e % |
| 4986 | % % |
| 4987 | % % |
| 4988 | % % |
| 4989 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4990 | % |
| 4991 | % SwirlImage() swirls the pixels about the center of the image, where |
| 4992 | % degrees indicates the sweep of the arc through which each pixel is moved. |
| 4993 | % You get a more dramatic effect as the degrees move from 1 to 360. |
| 4994 | % |
| 4995 | % The format of the SwirlImage method is: |
| 4996 | % |
| 4997 | % Image *SwirlImage(const Image *image,double degrees, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4998 | % const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4999 | % |
| 5000 | % A description of each parameter follows: |
| 5001 | % |
| 5002 | % o image: the image. |
| 5003 | % |
| 5004 | % o degrees: Define the tightness of the swirling effect. |
| 5005 | % |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5006 | % o method: the pixel interpolation method. |
| 5007 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5008 | % o exception: return any errors or warnings in this structure. |
| 5009 | % |
| 5010 | */ |
| 5011 | MagickExport Image *SwirlImage(const Image *image,double degrees, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5012 | const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5013 | { |
| 5014 | #define SwirlImageTag "Swirl/Image" |
| 5015 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5016 | CacheView |
| 5017 | *image_view, |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5018 | *interpolate_view, |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5019 | *swirl_view; |
| 5020 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5021 | Image |
| 5022 | *swirl_image; |
| 5023 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5024 | MagickBooleanType |
| 5025 | status; |
| 5026 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5027 | MagickOffsetType |
| 5028 | progress; |
| 5029 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5030 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5031 | radius; |
| 5032 | |
| 5033 | PointInfo |
| 5034 | center, |
| 5035 | scale; |
| 5036 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5037 | ssize_t |
| 5038 | y; |
| 5039 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5040 | /* |
| 5041 | Initialize swirl image attributes. |
| 5042 | */ |
| 5043 | assert(image != (const Image *) NULL); |
| 5044 | assert(image->signature == MagickSignature); |
| 5045 | if (image->debug != MagickFalse) |
| 5046 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5047 | assert(exception != (ExceptionInfo *) NULL); |
| 5048 | assert(exception->signature == MagickSignature); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5049 | swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5050 | if (swirl_image == (Image *) NULL) |
| 5051 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5052 | if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5053 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5054 | swirl_image=DestroyImage(swirl_image); |
| 5055 | return((Image *) NULL); |
| 5056 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5057 | if (swirl_image->background_color.alpha != OpaqueAlpha) |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5058 | swirl_image->alpha_trait=BlendPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5059 | /* |
| 5060 | Compute scaling factor. |
| 5061 | */ |
| 5062 | center.x=(double) image->columns/2.0; |
| 5063 | center.y=(double) image->rows/2.0; |
| 5064 | radius=MagickMax(center.x,center.y); |
| 5065 | scale.x=1.0; |
| 5066 | scale.y=1.0; |
| 5067 | if (image->columns > image->rows) |
| 5068 | scale.y=(double) image->columns/(double) image->rows; |
| 5069 | else |
| 5070 | if (image->columns < image->rows) |
| 5071 | scale.x=(double) image->rows/(double) image->columns; |
| 5072 | degrees=(double) DegreesToRadians(degrees); |
| 5073 | /* |
| 5074 | Swirl image. |
| 5075 | */ |
| 5076 | status=MagickTrue; |
| 5077 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5078 | image_view=AcquireVirtualCacheView(image,exception); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5079 | interpolate_view=AcquireVirtualCacheView(image,exception); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5080 | swirl_view=AcquireAuthenticCacheView(swirl_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5081 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 5082 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 5083 | magick_threads(image,swirl_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5084 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5085 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5086 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5087 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5088 | distance; |
| 5089 | |
| 5090 | PointInfo |
| 5091 | delta; |
| 5092 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5093 | register const Quantum |
| 5094 | *restrict p; |
| 5095 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5096 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5097 | x; |
| 5098 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5099 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5100 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5101 | |
| 5102 | if (status == MagickFalse) |
| 5103 | continue; |
cristy | 1665ce1 | 2013-04-19 12:18:43 +0000 | [diff] [blame] | 5104 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5105 | q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5106 | exception); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5107 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5108 | { |
| 5109 | status=MagickFalse; |
| 5110 | continue; |
| 5111 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5112 | delta.y=scale.y*(double) (y-center.y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5113 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5114 | { |
| 5115 | /* |
| 5116 | Determine if the pixel is within an ellipse. |
| 5117 | */ |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 5118 | if (GetPixelReadMask(image,p) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 5119 | { |
| 5120 | p+=GetPixelChannels(image); |
| 5121 | q+=GetPixelChannels(swirl_image); |
| 5122 | continue; |
| 5123 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5124 | delta.x=scale.x*(double) (x-center.x); |
| 5125 | distance=delta.x*delta.x+delta.y*delta.y; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5126 | if (distance >= (radius*radius)) |
| 5127 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5128 | register ssize_t |
| 5129 | i; |
| 5130 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5131 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5132 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5133 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 5134 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 5135 | PixelTrait swirl_traits=GetPixelChannelTraits(swirl_image,channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5136 | if ((traits == UndefinedPixelTrait) || |
| 5137 | (swirl_traits == UndefinedPixelTrait)) |
| 5138 | continue; |
| 5139 | SetPixelChannel(swirl_image,channel,p[i],q); |
| 5140 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5141 | } |
| 5142 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5143 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5144 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5145 | cosine, |
| 5146 | factor, |
| 5147 | sine; |
| 5148 | |
| 5149 | /* |
| 5150 | Swirl the pixel. |
| 5151 | */ |
| 5152 | factor=1.0-sqrt((double) distance)/radius; |
| 5153 | sine=sin((double) (degrees*factor*factor)); |
| 5154 | cosine=cos((double) (degrees*factor*factor)); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5155 | status=InterpolatePixelChannels(image,interpolate_view,swirl_image, |
| 5156 | method,((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double) |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5157 | ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5158 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5159 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5160 | q+=GetPixelChannels(swirl_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5161 | } |
| 5162 | if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse) |
| 5163 | status=MagickFalse; |
| 5164 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5165 | { |
| 5166 | MagickBooleanType |
| 5167 | proceed; |
| 5168 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5169 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5170 | #pragma omp critical (MagickCore_SwirlImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5171 | #endif |
| 5172 | proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows); |
| 5173 | if (proceed == MagickFalse) |
| 5174 | status=MagickFalse; |
| 5175 | } |
| 5176 | } |
| 5177 | swirl_view=DestroyCacheView(swirl_view); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5178 | interpolate_view=DestroyCacheView(interpolate_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5179 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5180 | if (status == MagickFalse) |
| 5181 | swirl_image=DestroyImage(swirl_image); |
| 5182 | return(swirl_image); |
| 5183 | } |
| 5184 | |
| 5185 | /* |
| 5186 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5187 | % % |
| 5188 | % % |
| 5189 | % % |
| 5190 | % T i n t I m a g e % |
| 5191 | % % |
| 5192 | % % |
| 5193 | % % |
| 5194 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5195 | % |
| 5196 | % TintImage() applies a color vector to each pixel in the image. The length |
| 5197 | % of the vector is 0 for black and white and at its maximum for the midtones. |
| 5198 | % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5)))) |
| 5199 | % |
| 5200 | % The format of the TintImage method is: |
| 5201 | % |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5202 | % Image *TintImage(const Image *image,const char *blend, |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5203 | % const PixelInfo *tint,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5204 | % |
| 5205 | % A description of each parameter follows: |
| 5206 | % |
| 5207 | % o image: the image. |
| 5208 | % |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5209 | % o blend: A color value used for tinting. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5210 | % |
| 5211 | % o tint: A color value used for tinting. |
| 5212 | % |
| 5213 | % o exception: return any errors or warnings in this structure. |
| 5214 | % |
| 5215 | */ |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5216 | MagickExport Image *TintImage(const Image *image,const char *blend, |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5217 | const PixelInfo *tint,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5218 | { |
| 5219 | #define TintImageTag "Tint/Image" |
| 5220 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 5221 | CacheView |
| 5222 | *image_view, |
| 5223 | *tint_view; |
| 5224 | |
cristy | f54150e | 2013-04-11 01:25:47 +0000 | [diff] [blame] | 5225 | double |
| 5226 | intensity; |
| 5227 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5228 | GeometryInfo |
| 5229 | geometry_info; |
| 5230 | |
| 5231 | Image |
| 5232 | *tint_image; |
| 5233 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5234 | MagickBooleanType |
| 5235 | status; |
| 5236 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5237 | MagickOffsetType |
| 5238 | progress; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5239 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5240 | PixelInfo |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5241 | color_vector; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5242 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5243 | MagickStatusType |
| 5244 | flags; |
| 5245 | |
| 5246 | ssize_t |
| 5247 | y; |
| 5248 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5249 | /* |
| 5250 | Allocate tint image. |
| 5251 | */ |
| 5252 | assert(image != (const Image *) NULL); |
| 5253 | assert(image->signature == MagickSignature); |
| 5254 | if (image->debug != MagickFalse) |
| 5255 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5256 | assert(exception != (ExceptionInfo *) NULL); |
| 5257 | assert(exception->signature == MagickSignature); |
| 5258 | tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
| 5259 | if (tint_image == (Image *) NULL) |
| 5260 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5261 | if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5262 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5263 | tint_image=DestroyImage(tint_image); |
| 5264 | return((Image *) NULL); |
| 5265 | } |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 5266 | if ((IsGrayColorspace(image->colorspace) != MagickFalse) && |
cristy | 4dab380 | 2013-03-15 22:08:15 +0000 | [diff] [blame] | 5267 | (IsPixelInfoGray(tint) == MagickFalse)) |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 5268 | (void) SetImageColorspace(tint_image,sRGBColorspace,exception); |
cristy | aed9c38 | 2011-10-03 17:54:21 +0000 | [diff] [blame] | 5269 | if (blend == (const char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5270 | return(tint_image); |
| 5271 | /* |
| 5272 | Determine RGB values of the color. |
| 5273 | */ |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5274 | GetPixelInfo(image,&color_vector); |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5275 | flags=ParseGeometry(blend,&geometry_info); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5276 | color_vector.red=geometry_info.rho; |
| 5277 | color_vector.green=geometry_info.rho; |
| 5278 | color_vector.blue=geometry_info.rho; |
cristy | 92ac572 | 2013-03-09 15:09:38 +0000 | [diff] [blame] | 5279 | color_vector.alpha=(MagickRealType) OpaqueAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5280 | if ((flags & SigmaValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5281 | color_vector.green=geometry_info.sigma; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5282 | if ((flags & XiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5283 | color_vector.blue=geometry_info.xi; |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5284 | if ((flags & PsiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5285 | color_vector.alpha=geometry_info.psi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5286 | if (image->colorspace == CMYKColorspace) |
| 5287 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5288 | color_vector.black=geometry_info.rho; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5289 | if ((flags & PsiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5290 | color_vector.black=geometry_info.psi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5291 | if ((flags & ChiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5292 | color_vector.alpha=geometry_info.chi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5293 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5294 | intensity=(double) GetPixelInfoIntensity(tint); |
cristy | f54150e | 2013-04-11 01:25:47 +0000 | [diff] [blame] | 5295 | color_vector.red=(double) (color_vector.red*tint->red/100.0-intensity); |
| 5296 | color_vector.green=(double) (color_vector.green*tint->green/100.0-intensity); |
| 5297 | color_vector.blue=(double) (color_vector.blue*tint->blue/100.0-intensity); |
| 5298 | color_vector.black=(double) (color_vector.black*tint->black/100.0-intensity); |
| 5299 | color_vector.alpha=(double) (color_vector.alpha*tint->alpha/100.0-intensity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5300 | /* |
| 5301 | Tint image. |
| 5302 | */ |
| 5303 | status=MagickTrue; |
| 5304 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5305 | image_view=AcquireVirtualCacheView(image,exception); |
| 5306 | tint_view=AcquireAuthenticCacheView(tint_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5307 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 5308 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 5309 | magick_threads(image,tint_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5310 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5311 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5312 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5313 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5314 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5315 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5316 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5317 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5318 | |
cristy | 6b91acb | 2011-04-19 12:23:54 +0000 | [diff] [blame] | 5319 | register ssize_t |
| 5320 | x; |
| 5321 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5322 | if (status == MagickFalse) |
| 5323 | continue; |
| 5324 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 5325 | q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1, |
| 5326 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5327 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5328 | { |
| 5329 | status=MagickFalse; |
| 5330 | continue; |
| 5331 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5332 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5333 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5334 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5335 | pixel; |
| 5336 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5337 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5338 | weight; |
| 5339 | |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5340 | register ssize_t |
| 5341 | i; |
| 5342 | |
| 5343 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 5344 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5345 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 5346 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 5347 | PixelTrait tint_traits=GetPixelChannelTraits(tint_image,channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5348 | if ((traits == UndefinedPixelTrait) || |
| 5349 | (tint_traits == UndefinedPixelTrait)) |
| 5350 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5351 | if (((tint_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 5352 | (GetPixelReadMask(image,p) == 0)) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5353 | { |
| 5354 | SetPixelChannel(tint_image,channel,p[i],q); |
| 5355 | continue; |
| 5356 | } |
| 5357 | } |
| 5358 | GetPixelInfo(image,&pixel); |
| 5359 | weight=QuantumScale*GetPixelRed(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5360 | pixel.red=(double) GetPixelRed(image,p)+color_vector.red*(1.0-(4.0* |
| 5361 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5362 | weight=QuantumScale*GetPixelGreen(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5363 | pixel.green=(double) GetPixelGreen(image,p)+color_vector.green*(1.0-(4.0* |
| 5364 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5365 | weight=QuantumScale*GetPixelBlue(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5366 | pixel.blue=(double) GetPixelBlue(image,p)+color_vector.blue*(1.0-(4.0* |
| 5367 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5368 | weight=QuantumScale*GetPixelBlack(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5369 | pixel.black=(double) GetPixelBlack(image,p)+color_vector.black*(1.0-(4.0* |
| 5370 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5371 | SetPixelInfoPixel(tint_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5372 | p+=GetPixelChannels(image); |
| 5373 | q+=GetPixelChannels(tint_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5374 | } |
| 5375 | if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse) |
| 5376 | status=MagickFalse; |
| 5377 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5378 | { |
| 5379 | MagickBooleanType |
| 5380 | proceed; |
| 5381 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5382 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5383 | #pragma omp critical (MagickCore_TintImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5384 | #endif |
| 5385 | proceed=SetImageProgress(image,TintImageTag,progress++,image->rows); |
| 5386 | if (proceed == MagickFalse) |
| 5387 | status=MagickFalse; |
| 5388 | } |
| 5389 | } |
| 5390 | tint_view=DestroyCacheView(tint_view); |
| 5391 | image_view=DestroyCacheView(image_view); |
| 5392 | if (status == MagickFalse) |
| 5393 | tint_image=DestroyImage(tint_image); |
| 5394 | return(tint_image); |
| 5395 | } |
| 5396 | |
| 5397 | /* |
| 5398 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5399 | % % |
| 5400 | % % |
| 5401 | % % |
| 5402 | % V i g n e t t e I m a g e % |
| 5403 | % % |
| 5404 | % % |
| 5405 | % % |
| 5406 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5407 | % |
| 5408 | % VignetteImage() softens the edges of the image in vignette style. |
| 5409 | % |
| 5410 | % The format of the VignetteImage method is: |
| 5411 | % |
| 5412 | % Image *VignetteImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5413 | % const double sigma,const ssize_t x,const ssize_t y, |
cristy | 05c0c9a | 2011-09-05 23:16:13 +0000 | [diff] [blame] | 5414 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5415 | % |
| 5416 | % A description of each parameter follows: |
| 5417 | % |
| 5418 | % o image: the image. |
| 5419 | % |
| 5420 | % o radius: the radius of the pixel neighborhood. |
| 5421 | % |
| 5422 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 5423 | % |
| 5424 | % o x, y: Define the x and y ellipse offset. |
| 5425 | % |
| 5426 | % o exception: return any errors or warnings in this structure. |
| 5427 | % |
| 5428 | */ |
| 5429 | MagickExport Image *VignetteImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5430 | const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5431 | { |
| 5432 | char |
| 5433 | ellipse[MaxTextExtent]; |
| 5434 | |
| 5435 | DrawInfo |
| 5436 | *draw_info; |
| 5437 | |
| 5438 | Image |
| 5439 | *canvas_image, |
| 5440 | *blur_image, |
| 5441 | *oval_image, |
| 5442 | *vignette_image; |
| 5443 | |
| 5444 | assert(image != (Image *) NULL); |
| 5445 | assert(image->signature == MagickSignature); |
| 5446 | if (image->debug != MagickFalse) |
| 5447 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5448 | assert(exception != (ExceptionInfo *) NULL); |
| 5449 | assert(exception->signature == MagickSignature); |
| 5450 | canvas_image=CloneImage(image,0,0,MagickTrue,exception); |
| 5451 | if (canvas_image == (Image *) NULL) |
| 5452 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5453 | if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5454 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5455 | canvas_image=DestroyImage(canvas_image); |
| 5456 | return((Image *) NULL); |
| 5457 | } |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5458 | canvas_image->alpha_trait=BlendPixelTrait; |
cristy | 9862146 | 2011-12-31 22:31:11 +0000 | [diff] [blame] | 5459 | oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows, |
| 5460 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5461 | if (oval_image == (Image *) NULL) |
| 5462 | { |
| 5463 | canvas_image=DestroyImage(canvas_image); |
| 5464 | return((Image *) NULL); |
| 5465 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 5466 | (void) QueryColorCompliance("#000000",AllCompliance, |
| 5467 | &oval_image->background_color,exception); |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 5468 | (void) SetImageBackgroundColor(oval_image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5469 | draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 5470 | (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill, |
| 5471 | exception); |
| 5472 | (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke, |
| 5473 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5474 | (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g," |
| 5475 | "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x, |
| 5476 | image->rows/2.0-y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5477 | draw_info->primitive=AcquireString(ellipse); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 5478 | (void) DrawImage(oval_image,draw_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5479 | draw_info=DestroyDrawInfo(draw_info); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5480 | blur_image=BlurImage(oval_image,radius,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5481 | oval_image=DestroyImage(oval_image); |
| 5482 | if (blur_image == (Image *) NULL) |
| 5483 | { |
| 5484 | canvas_image=DestroyImage(canvas_image); |
| 5485 | return((Image *) NULL); |
| 5486 | } |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5487 | blur_image->alpha_trait=UndefinedPixelTrait; |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 5488 | (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue, |
| 5489 | 0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5490 | blur_image=DestroyImage(blur_image); |
| 5491 | vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception); |
| 5492 | canvas_image=DestroyImage(canvas_image); |
cristy | 66d2612 | 2012-06-23 21:56:40 +0000 | [diff] [blame] | 5493 | if (vignette_image != (Image *) NULL) |
| 5494 | (void) TransformImageColorspace(vignette_image,image->colorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5495 | return(vignette_image); |
| 5496 | } |
| 5497 | |
| 5498 | /* |
| 5499 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5500 | % % |
| 5501 | % % |
| 5502 | % % |
| 5503 | % W a v e I m a g e % |
| 5504 | % % |
| 5505 | % % |
| 5506 | % % |
| 5507 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5508 | % |
| 5509 | % WaveImage() creates a "ripple" effect in the image by shifting the pixels |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 5510 | % vertically along a sine wave whose amplitude and wavelength is specified |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5511 | % by the given parameters. |
| 5512 | % |
| 5513 | % The format of the WaveImage method is: |
| 5514 | % |
| 5515 | % Image *WaveImage(const Image *image,const double amplitude, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5516 | % const double wave_length,const PixelInterpolateMethod method, |
| 5517 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5518 | % |
| 5519 | % A description of each parameter follows: |
| 5520 | % |
| 5521 | % o image: the image. |
| 5522 | % |
| 5523 | % o amplitude, wave_length: Define the amplitude and wave length of the |
| 5524 | % sine wave. |
| 5525 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5526 | % o interpolate: the pixel interpolation method. |
| 5527 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5528 | % o exception: return any errors or warnings in this structure. |
| 5529 | % |
| 5530 | */ |
| 5531 | MagickExport Image *WaveImage(const Image *image,const double amplitude, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5532 | const double wave_length,const PixelInterpolateMethod method, |
| 5533 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5534 | { |
| 5535 | #define WaveImageTag "Wave/Image" |
| 5536 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5537 | CacheView |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5538 | *image_view, |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5539 | *wave_view; |
| 5540 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5541 | Image |
| 5542 | *wave_image; |
| 5543 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5544 | MagickBooleanType |
| 5545 | status; |
| 5546 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5547 | MagickOffsetType |
| 5548 | progress; |
| 5549 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5550 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5551 | *sine_map; |
| 5552 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5553 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5554 | i; |
| 5555 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5556 | ssize_t |
| 5557 | y; |
| 5558 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5559 | /* |
| 5560 | Initialize wave image attributes. |
| 5561 | */ |
| 5562 | assert(image != (Image *) NULL); |
| 5563 | assert(image->signature == MagickSignature); |
| 5564 | if (image->debug != MagickFalse) |
| 5565 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5566 | assert(exception != (ExceptionInfo *) NULL); |
| 5567 | assert(exception->signature == MagickSignature); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5568 | wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5569 | fabs(amplitude)),MagickTrue,exception); |
| 5570 | if (wave_image == (Image *) NULL) |
| 5571 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5572 | if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5573 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5574 | wave_image=DestroyImage(wave_image); |
| 5575 | return((Image *) NULL); |
| 5576 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5577 | if (wave_image->background_color.alpha != OpaqueAlpha) |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5578 | wave_image->alpha_trait=BlendPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5579 | /* |
| 5580 | Allocate sine map. |
| 5581 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5582 | sine_map=(double *) AcquireQuantumMemory((size_t) wave_image->columns, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5583 | sizeof(*sine_map)); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5584 | if (sine_map == (double *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5585 | { |
| 5586 | wave_image=DestroyImage(wave_image); |
| 5587 | ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); |
| 5588 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5589 | for (i=0; i < (ssize_t) wave_image->columns; i++) |
cristy | 4205a3c | 2010-09-12 20:19:59 +0000 | [diff] [blame] | 5590 | sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/ |
| 5591 | wave_length)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5592 | /* |
| 5593 | Wave image. |
| 5594 | */ |
| 5595 | status=MagickTrue; |
| 5596 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5597 | image_view=AcquireVirtualCacheView(image,exception); |
| 5598 | wave_view=AcquireAuthenticCacheView(wave_image,exception); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5599 | (void) SetCacheViewVirtualPixelMethod(image_view, |
| 5600 | BackgroundVirtualPixelMethod); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5601 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 5602 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 5603 | magick_threads(image,wave_image,wave_image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5604 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5605 | for (y=0; y < (ssize_t) wave_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5606 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5607 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5608 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5609 | |
cristy | e97bb92 | 2011-04-03 01:36:52 +0000 | [diff] [blame] | 5610 | register ssize_t |
| 5611 | x; |
| 5612 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5613 | if (status == MagickFalse) |
| 5614 | continue; |
| 5615 | q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1, |
| 5616 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 5617 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5618 | { |
| 5619 | status=MagickFalse; |
| 5620 | continue; |
| 5621 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5622 | for (x=0; x < (ssize_t) wave_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5623 | { |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5624 | status=InterpolatePixelChannels(image,image_view,wave_image,method, |
| 5625 | (double) x,(double) (y-sine_map[x]),q,exception); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5626 | q+=GetPixelChannels(wave_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5627 | } |
| 5628 | if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse) |
| 5629 | status=MagickFalse; |
| 5630 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5631 | { |
| 5632 | MagickBooleanType |
| 5633 | proceed; |
| 5634 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5635 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5636 | #pragma omp critical (MagickCore_WaveImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5637 | #endif |
| 5638 | proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows); |
| 5639 | if (proceed == MagickFalse) |
| 5640 | status=MagickFalse; |
| 5641 | } |
| 5642 | } |
| 5643 | wave_view=DestroyCacheView(wave_view); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5644 | image_view=DestroyCacheView(image_view); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5645 | sine_map=(double *) RelinquishMagickMemory(sine_map); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5646 | if (status == MagickFalse) |
| 5647 | wave_image=DestroyImage(wave_image); |
| 5648 | return(wave_image); |
| 5649 | } |