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