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