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 % |
cristy | de984cd | 2013-12-01 14:49:27 +0000 | [diff] [blame] | 16 | % Cristy % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 17 | % October 1996 % |
| 18 | % % |
| 19 | % % |
cristy | fe676ee | 2013-11-18 13:03:38 +0000 | [diff] [blame] | 20 | % Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 28 | % Unless required by applicable law or agreed to in writing, software % |
| 29 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 30 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 31 | % See the License for the specific language governing permissions and % |
| 32 | % limitations under the License. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/annotate.h" |
| 45 | #include "MagickCore/artifact.h" |
| 46 | #include "MagickCore/attribute.h" |
| 47 | #include "MagickCore/cache.h" |
| 48 | #include "MagickCore/cache-view.h" |
cristy | 6a2180c | 2013-05-27 10:28:36 +0000 | [diff] [blame] | 49 | #include "MagickCore/channel.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 50 | #include "MagickCore/color.h" |
| 51 | #include "MagickCore/color-private.h" |
cristy | 9b7a4fc | 2012-04-08 22:26:56 +0000 | [diff] [blame] | 52 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 53 | #include "MagickCore/composite.h" |
| 54 | #include "MagickCore/decorate.h" |
cristy | c53413d | 2011-11-17 13:04:26 +0000 | [diff] [blame] | 55 | #include "MagickCore/distort.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 56 | #include "MagickCore/draw.h" |
| 57 | #include "MagickCore/effect.h" |
| 58 | #include "MagickCore/enhance.h" |
| 59 | #include "MagickCore/exception.h" |
| 60 | #include "MagickCore/exception-private.h" |
| 61 | #include "MagickCore/fx.h" |
| 62 | #include "MagickCore/fx-private.h" |
| 63 | #include "MagickCore/gem.h" |
cristy | 8ea8122 | 2011-09-04 10:33:32 +0000 | [diff] [blame] | 64 | #include "MagickCore/gem-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 65 | #include "MagickCore/geometry.h" |
| 66 | #include "MagickCore/layer.h" |
| 67 | #include "MagickCore/list.h" |
| 68 | #include "MagickCore/log.h" |
| 69 | #include "MagickCore/image.h" |
| 70 | #include "MagickCore/image-private.h" |
| 71 | #include "MagickCore/magick.h" |
| 72 | #include "MagickCore/memory_.h" |
| 73 | #include "MagickCore/monitor.h" |
| 74 | #include "MagickCore/monitor-private.h" |
| 75 | #include "MagickCore/option.h" |
| 76 | #include "MagickCore/pixel.h" |
| 77 | #include "MagickCore/pixel-accessor.h" |
| 78 | #include "MagickCore/property.h" |
| 79 | #include "MagickCore/quantum.h" |
| 80 | #include "MagickCore/quantum-private.h" |
| 81 | #include "MagickCore/random_.h" |
| 82 | #include "MagickCore/random-private.h" |
| 83 | #include "MagickCore/resample.h" |
| 84 | #include "MagickCore/resample-private.h" |
| 85 | #include "MagickCore/resize.h" |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 86 | #include "MagickCore/resource_.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 87 | #include "MagickCore/splay-tree.h" |
| 88 | #include "MagickCore/statistic.h" |
| 89 | #include "MagickCore/string_.h" |
| 90 | #include "MagickCore/string-private.h" |
| 91 | #include "MagickCore/thread-private.h" |
| 92 | #include "MagickCore/transform.h" |
| 93 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | Define declarations. |
| 97 | */ |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 98 | #define LeftShiftOperator 0xf5U |
| 99 | #define RightShiftOperator 0xf6U |
| 100 | #define LessThanEqualOperator 0xf7U |
| 101 | #define GreaterThanEqualOperator 0xf8U |
| 102 | #define EqualOperator 0xf9U |
| 103 | #define NotEqualOperator 0xfaU |
| 104 | #define LogicalAndOperator 0xfbU |
| 105 | #define LogicalOrOperator 0xfcU |
| 106 | #define ExponentialNotation 0xfdU |
| 107 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 108 | struct _FxInfo |
| 109 | { |
| 110 | const Image |
| 111 | *images; |
| 112 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 113 | char |
| 114 | *expression; |
| 115 | |
| 116 | FILE |
| 117 | *file; |
| 118 | |
| 119 | SplayTreeInfo |
| 120 | *colors, |
| 121 | *symbols; |
| 122 | |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 123 | CacheView |
| 124 | **view; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 125 | |
| 126 | RandomInfo |
| 127 | *random_info; |
| 128 | |
| 129 | ExceptionInfo |
| 130 | *exception; |
| 131 | }; |
| 132 | |
| 133 | /* |
| 134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 135 | % % |
| 136 | % % |
| 137 | % % |
| 138 | + A c q u i r e F x I n f o % |
| 139 | % % |
| 140 | % % |
| 141 | % % |
| 142 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 143 | % |
| 144 | % AcquireFxInfo() allocates the FxInfo structure. |
| 145 | % |
| 146 | % The format of the AcquireFxInfo method is: |
| 147 | % |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 148 | % FxInfo *AcquireFxInfo(Image *image,const char *expression, |
| 149 | % ExceptionInfo *exception) |
cristy | 0a9b372 | 2010-10-23 18:45:49 +0000 | [diff] [blame] | 150 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 151 | % A description of each parameter follows: |
| 152 | % |
| 153 | % o image: the image. |
| 154 | % |
| 155 | % o expression: the expression. |
| 156 | % |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 157 | % o exception: return any errors or warnings in this structure. |
| 158 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | */ |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 160 | MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression, |
| 161 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 162 | { |
| 163 | char |
| 164 | fx_op[2]; |
| 165 | |
cristy | cb18092 | 2011-03-11 14:41:24 +0000 | [diff] [blame] | 166 | const Image |
| 167 | *next; |
| 168 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 169 | FxInfo |
| 170 | *fx_info; |
| 171 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 172 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 173 | i; |
| 174 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 175 | fx_info=(FxInfo *) AcquireMagickMemory(sizeof(*fx_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 176 | if (fx_info == (FxInfo *) NULL) |
| 177 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 178 | (void) ResetMagickMemory(fx_info,0,sizeof(*fx_info)); |
| 179 | fx_info->exception=AcquireExceptionInfo(); |
anthony | 7d86e17 | 2011-03-23 12:37:06 +0000 | [diff] [blame] | 180 | fx_info->images=image; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 181 | fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
cristy | 1e12eb4 | 2013-08-17 16:19:01 +0000 | [diff] [blame] | 182 | RelinquishAlignedMemory); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 183 | fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, |
| 184 | RelinquishMagickMemory); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 185 | fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength( |
| 186 | fx_info->images),sizeof(*fx_info->view)); |
| 187 | if (fx_info->view == (CacheView **) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 188 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | a226226 | 2011-03-11 02:50:37 +0000 | [diff] [blame] | 189 | i=0; |
cristy | 0ea377f | 2011-03-24 00:54:19 +0000 | [diff] [blame] | 190 | next=GetFirstImageInList(fx_info->images); |
| 191 | for ( ; next != (Image *) NULL; next=next->next) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 192 | { |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 193 | fx_info->view[i]=AcquireVirtualCacheView(next,exception); |
cristy | a226226 | 2011-03-11 02:50:37 +0000 | [diff] [blame] | 194 | i++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 195 | } |
| 196 | fx_info->random_info=AcquireRandomInfo(); |
| 197 | fx_info->expression=ConstantString(expression); |
| 198 | fx_info->file=stderr; |
| 199 | (void) SubstituteString(&fx_info->expression," ",""); /* compact string */ |
cristy | 37af091 | 2011-05-23 16:09:42 +0000 | [diff] [blame] | 200 | /* |
| 201 | Force right-to-left associativity for unary negation. |
| 202 | */ |
| 203 | (void) SubstituteString(&fx_info->expression,"-","-1.0*"); |
cristy | 422d550 | 2012-12-22 22:20:57 +0000 | [diff] [blame] | 204 | (void) SubstituteString(&fx_info->expression,"^-1.0*","^-"); |
cristy | 8fbb96d | 2012-07-18 01:18:52 +0000 | [diff] [blame] | 205 | (void) SubstituteString(&fx_info->expression,"E-1.0*","E-"); |
| 206 | (void) SubstituteString(&fx_info->expression,"e-1.0*","e-"); |
cristy | 8b8a3ae | 2010-10-23 18:49:46 +0000 | [diff] [blame] | 207 | /* |
cristy | df75151 | 2013-08-17 14:19:12 +0000 | [diff] [blame] | 208 | Convert compound to simple operators. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | */ |
| 210 | fx_op[1]='\0'; |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 211 | *fx_op=(char) LeftShiftOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 212 | (void) SubstituteString(&fx_info->expression,"<<",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 213 | *fx_op=(char) RightShiftOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 214 | (void) SubstituteString(&fx_info->expression,">>",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 215 | *fx_op=(char) LessThanEqualOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 216 | (void) SubstituteString(&fx_info->expression,"<=",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 217 | *fx_op=(char) GreaterThanEqualOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 218 | (void) SubstituteString(&fx_info->expression,">=",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 219 | *fx_op=(char) EqualOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 220 | (void) SubstituteString(&fx_info->expression,"==",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 221 | *fx_op=(char) NotEqualOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 222 | (void) SubstituteString(&fx_info->expression,"!=",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 223 | *fx_op=(char) LogicalAndOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 224 | (void) SubstituteString(&fx_info->expression,"&&",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 225 | *fx_op=(char) LogicalOrOperator; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 226 | (void) SubstituteString(&fx_info->expression,"||",fx_op); |
cristy | 41acfc7 | 2013-11-14 16:47:53 +0000 | [diff] [blame] | 227 | *fx_op=(char) ExponentialNotation; |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 228 | (void) SubstituteString(&fx_info->expression,"**",fx_op); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 229 | return(fx_info); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 234 | % % |
| 235 | % % |
| 236 | % % |
| 237 | % A d d N o i s e I m a g e % |
| 238 | % % |
| 239 | % % |
| 240 | % % |
| 241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 242 | % |
| 243 | % AddNoiseImage() adds random noise to the image. |
| 244 | % |
| 245 | % The format of the AddNoiseImage method is: |
| 246 | % |
| 247 | % Image *AddNoiseImage(const Image *image,const NoiseType noise_type, |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 248 | % const double attenuate,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 249 | % |
| 250 | % A description of each parameter follows: |
| 251 | % |
| 252 | % o image: the image. |
| 253 | % |
| 254 | % o channel: the channel type. |
| 255 | % |
| 256 | % o noise_type: The type of noise: Uniform, Gaussian, Multiplicative, |
| 257 | % Impulse, Laplacian, or Poisson. |
| 258 | % |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 259 | % o attenuate: attenuate the random distribution. |
| 260 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 261 | % o exception: return any errors or warnings in this structure. |
| 262 | % |
| 263 | */ |
cristy | 9ed1f81 | 2011-10-08 02:00:08 +0000 | [diff] [blame] | 264 | MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type, |
| 265 | const double attenuate,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 266 | { |
| 267 | #define AddNoiseImageTag "AddNoise/Image" |
| 268 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 269 | CacheView |
| 270 | *image_view, |
| 271 | *noise_view; |
| 272 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 273 | Image |
| 274 | *noise_image; |
| 275 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 276 | MagickBooleanType |
| 277 | status; |
| 278 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 279 | MagickOffsetType |
| 280 | progress; |
| 281 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 282 | RandomInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 283 | **restrict random_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 284 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 285 | ssize_t |
| 286 | y; |
| 287 | |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 288 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 289 | unsigned long |
| 290 | key; |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 291 | #endif |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 292 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 293 | /* |
| 294 | Initialize noise image attributes. |
| 295 | */ |
| 296 | assert(image != (const Image *) NULL); |
| 297 | assert(image->signature == MagickSignature); |
| 298 | if (image->debug != MagickFalse) |
| 299 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 300 | assert(exception != (ExceptionInfo *) NULL); |
| 301 | assert(exception->signature == MagickSignature); |
cristy | b214589 | 2011-10-10 00:55:32 +0000 | [diff] [blame] | 302 | noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 303 | if (noise_image == (Image *) NULL) |
| 304 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 305 | if (SetImageStorageClass(noise_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 306 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 307 | noise_image=DestroyImage(noise_image); |
| 308 | return((Image *) NULL); |
| 309 | } |
| 310 | /* |
| 311 | Add noise in each row. |
| 312 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 313 | status=MagickTrue; |
| 314 | progress=0; |
| 315 | random_info=AcquireRandomInfoThreadSet(); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 316 | image_view=AcquireVirtualCacheView(image,exception); |
| 317 | noise_view=AcquireAuthenticCacheView(noise_image,exception); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 318 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 319 | key=GetRandomSecretKey(random_info[0]); |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 320 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 321 | magick_threads(image,noise_image,image->rows,key == ~0UL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 322 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 323 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 324 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 325 | const int |
| 326 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 327 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 328 | MagickBooleanType |
| 329 | sync; |
| 330 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 331 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 332 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 333 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 334 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 335 | x; |
| 336 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 337 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 338 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 339 | |
| 340 | if (status == MagickFalse) |
| 341 | continue; |
| 342 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 343 | q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 344 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 345 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 346 | { |
| 347 | status=MagickFalse; |
| 348 | continue; |
| 349 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 350 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 351 | { |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 352 | register ssize_t |
| 353 | i; |
| 354 | |
| 355 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 356 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 357 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 358 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 359 | PixelTrait noise_traits=GetPixelChannelTraits(noise_image,channel); |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 360 | if ((traits == UndefinedPixelTrait) || |
| 361 | (noise_traits == UndefinedPixelTrait)) |
| 362 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 363 | if (((noise_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 364 | (GetPixelReadMask(image,p) == 0)) |
cristy | b214589 | 2011-10-10 00:55:32 +0000 | [diff] [blame] | 365 | { |
| 366 | SetPixelChannel(noise_image,channel,p[i],q); |
| 367 | continue; |
| 368 | } |
cristy | 850b307 | 2011-10-08 01:38:05 +0000 | [diff] [blame] | 369 | SetPixelChannel(noise_image,channel,ClampToQuantum( |
| 370 | GenerateDifferentialNoise(random_info[id],p[i],noise_type,attenuate)), |
| 371 | q); |
| 372 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 373 | p+=GetPixelChannels(image); |
| 374 | q+=GetPixelChannels(noise_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | } |
| 376 | sync=SyncCacheViewAuthenticPixels(noise_view,exception); |
| 377 | if (sync == MagickFalse) |
| 378 | status=MagickFalse; |
| 379 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 380 | { |
| 381 | MagickBooleanType |
| 382 | proceed; |
| 383 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 384 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 385 | #pragma omp critical (MagickCore_AddNoiseImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 386 | #endif |
| 387 | proceed=SetImageProgress(image,AddNoiseImageTag,progress++, |
| 388 | image->rows); |
| 389 | if (proceed == MagickFalse) |
| 390 | status=MagickFalse; |
| 391 | } |
| 392 | } |
| 393 | noise_view=DestroyCacheView(noise_view); |
| 394 | image_view=DestroyCacheView(image_view); |
| 395 | random_info=DestroyRandomInfoThreadSet(random_info); |
| 396 | if (status == MagickFalse) |
| 397 | noise_image=DestroyImage(noise_image); |
| 398 | return(noise_image); |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 403 | % % |
| 404 | % % |
| 405 | % % |
| 406 | % B l u e S h i f t I m a g e % |
| 407 | % % |
| 408 | % % |
| 409 | % % |
| 410 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 411 | % |
| 412 | % BlueShiftImage() mutes the colors of the image to simulate a scene at |
| 413 | % nighttime in the moonlight. |
| 414 | % |
| 415 | % The format of the BlueShiftImage method is: |
| 416 | % |
| 417 | % Image *BlueShiftImage(const Image *image,const double factor, |
| 418 | % ExceptionInfo *exception) |
| 419 | % |
| 420 | % A description of each parameter follows: |
| 421 | % |
| 422 | % o image: the image. |
| 423 | % |
| 424 | % o factor: the shift factor. |
| 425 | % |
| 426 | % o exception: return any errors or warnings in this structure. |
| 427 | % |
| 428 | */ |
| 429 | MagickExport Image *BlueShiftImage(const Image *image,const double factor, |
| 430 | ExceptionInfo *exception) |
| 431 | { |
| 432 | #define BlueShiftImageTag "BlueShift/Image" |
| 433 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 434 | CacheView |
| 435 | *image_view, |
| 436 | *shift_view; |
| 437 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 438 | Image |
| 439 | *shift_image; |
| 440 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 441 | MagickBooleanType |
| 442 | status; |
| 443 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 444 | MagickOffsetType |
| 445 | progress; |
| 446 | |
| 447 | ssize_t |
| 448 | y; |
| 449 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 450 | /* |
| 451 | Allocate blue shift image. |
| 452 | */ |
| 453 | assert(image != (const Image *) NULL); |
| 454 | assert(image->signature == MagickSignature); |
| 455 | if (image->debug != MagickFalse) |
| 456 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 457 | assert(exception != (ExceptionInfo *) NULL); |
| 458 | assert(exception->signature == MagickSignature); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 459 | shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 460 | if (shift_image == (Image *) NULL) |
| 461 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 462 | if (SetImageStorageClass(shift_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 463 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 464 | shift_image=DestroyImage(shift_image); |
| 465 | return((Image *) NULL); |
| 466 | } |
| 467 | /* |
| 468 | Blue-shift DirectClass image. |
| 469 | */ |
| 470 | status=MagickTrue; |
| 471 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 472 | image_view=AcquireVirtualCacheView(image,exception); |
| 473 | shift_view=AcquireAuthenticCacheView(shift_image,exception); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 474 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 475 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 476 | magick_threads(image,shift_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 477 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 478 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 479 | { |
| 480 | MagickBooleanType |
| 481 | sync; |
| 482 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 483 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 484 | pixel; |
| 485 | |
| 486 | Quantum |
| 487 | quantum; |
| 488 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 489 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 490 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 491 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 492 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 493 | x; |
| 494 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 495 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 496 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 497 | |
| 498 | if (status == MagickFalse) |
| 499 | continue; |
| 500 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 501 | q=QueueCacheViewAuthenticPixels(shift_view,0,y,shift_image->columns,1, |
| 502 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 503 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 504 | { |
| 505 | status=MagickFalse; |
| 506 | continue; |
| 507 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 508 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 509 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 510 | quantum=GetPixelRed(image,p); |
| 511 | if (GetPixelGreen(image,p) < quantum) |
| 512 | quantum=GetPixelGreen(image,p); |
| 513 | if (GetPixelBlue(image,p) < quantum) |
| 514 | quantum=GetPixelBlue(image,p); |
| 515 | pixel.red=0.5*(GetPixelRed(image,p)+factor*quantum); |
| 516 | pixel.green=0.5*(GetPixelGreen(image,p)+factor*quantum); |
| 517 | pixel.blue=0.5*(GetPixelBlue(image,p)+factor*quantum); |
| 518 | quantum=GetPixelRed(image,p); |
| 519 | if (GetPixelGreen(image,p) > quantum) |
| 520 | quantum=GetPixelGreen(image,p); |
| 521 | if (GetPixelBlue(image,p) > quantum) |
| 522 | quantum=GetPixelBlue(image,p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 523 | pixel.red=0.5*(pixel.red+factor*quantum); |
| 524 | pixel.green=0.5*(pixel.green+factor*quantum); |
| 525 | pixel.blue=0.5*(pixel.blue+factor*quantum); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 526 | SetPixelRed(shift_image,ClampToQuantum(pixel.red),q); |
| 527 | SetPixelGreen(shift_image,ClampToQuantum(pixel.green),q); |
| 528 | SetPixelBlue(shift_image,ClampToQuantum(pixel.blue),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 529 | p+=GetPixelChannels(image); |
| 530 | q+=GetPixelChannels(shift_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 531 | } |
| 532 | sync=SyncCacheViewAuthenticPixels(shift_view,exception); |
| 533 | if (sync == MagickFalse) |
| 534 | status=MagickFalse; |
| 535 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 536 | { |
| 537 | MagickBooleanType |
| 538 | proceed; |
| 539 | |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 540 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 541 | #pragma omp critical (MagickCore_BlueShiftImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 542 | #endif |
| 543 | proceed=SetImageProgress(image,BlueShiftImageTag,progress++, |
| 544 | image->rows); |
| 545 | if (proceed == MagickFalse) |
| 546 | status=MagickFalse; |
| 547 | } |
| 548 | } |
| 549 | image_view=DestroyCacheView(image_view); |
| 550 | shift_view=DestroyCacheView(shift_view); |
| 551 | if (status == MagickFalse) |
| 552 | shift_image=DestroyImage(shift_image); |
| 553 | return(shift_image); |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 558 | % % |
| 559 | % % |
| 560 | % % |
| 561 | % C h a r c o a l I m a g e % |
| 562 | % % |
| 563 | % % |
| 564 | % % |
| 565 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 566 | % |
| 567 | % CharcoalImage() creates a new image that is a copy of an existing one with |
| 568 | % the edge highlighted. It allocates the memory necessary for the new Image |
| 569 | % structure and returns a pointer to the new image. |
| 570 | % |
| 571 | % The format of the CharcoalImage method is: |
| 572 | % |
| 573 | % Image *CharcoalImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 574 | % const double sigma,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 575 | % |
| 576 | % A description of each parameter follows: |
| 577 | % |
| 578 | % o image: the image. |
| 579 | % |
| 580 | % o radius: the radius of the pixel neighborhood. |
| 581 | % |
| 582 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 583 | % |
| 584 | % o exception: return any errors or warnings in this structure. |
| 585 | % |
| 586 | */ |
| 587 | MagickExport Image *CharcoalImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 588 | const double sigma,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 589 | { |
| 590 | Image |
| 591 | *charcoal_image, |
| 592 | *clone_image, |
| 593 | *edge_image; |
| 594 | |
| 595 | assert(image != (Image *) NULL); |
| 596 | assert(image->signature == MagickSignature); |
| 597 | if (image->debug != MagickFalse) |
| 598 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 599 | assert(exception != (ExceptionInfo *) NULL); |
| 600 | assert(exception->signature == MagickSignature); |
| 601 | clone_image=CloneImage(image,0,0,MagickTrue,exception); |
| 602 | if (clone_image == (Image *) NULL) |
| 603 | return((Image *) NULL); |
cristy | b2f4d5d | 2013-05-20 20:10:33 +0000 | [diff] [blame] | 604 | edge_image=EdgeImage(clone_image,radius,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 605 | clone_image=DestroyImage(clone_image); |
| 606 | if (edge_image == (Image *) NULL) |
| 607 | return((Image *) NULL); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 608 | charcoal_image=BlurImage(edge_image,radius,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 609 | edge_image=DestroyImage(edge_image); |
| 610 | if (charcoal_image == (Image *) NULL) |
| 611 | return((Image *) NULL); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 612 | (void) NormalizeImage(charcoal_image,exception); |
cristy | b3e7c6c | 2011-07-24 01:43:55 +0000 | [diff] [blame] | 613 | (void) NegateImage(charcoal_image,MagickFalse,exception); |
cristy | e247eff | 2013-04-15 11:50:40 +0000 | [diff] [blame] | 614 | (void) GrayscaleImage(charcoal_image,image->intensity,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 615 | return(charcoal_image); |
| 616 | } |
| 617 | |
| 618 | /* |
| 619 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 620 | % % |
| 621 | % % |
| 622 | % % |
| 623 | % C o l o r i z e I m a g e % |
| 624 | % % |
| 625 | % % |
| 626 | % % |
| 627 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 628 | % |
| 629 | % ColorizeImage() blends the fill color with each pixel in the image. |
| 630 | % A percentage blend is specified with opacity. Control the application |
| 631 | % of different color components by specifying a different percentage for |
| 632 | % each component (e.g. 90/100/10 is 90% red, 100% green, and 10% blue). |
| 633 | % |
| 634 | % The format of the ColorizeImage method is: |
| 635 | % |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 636 | % Image *ColorizeImage(const Image *image,const char *blend, |
| 637 | % const PixelInfo *colorize,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 638 | % |
| 639 | % A description of each parameter follows: |
| 640 | % |
| 641 | % o image: the image. |
| 642 | % |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 643 | % o blend: A character string indicating the level of blending as a |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | % percentage. |
| 645 | % |
| 646 | % o colorize: A color value. |
| 647 | % |
| 648 | % o exception: return any errors or warnings in this structure. |
| 649 | % |
| 650 | */ |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 651 | MagickExport Image *ColorizeImage(const Image *image,const char *blend, |
| 652 | const PixelInfo *colorize,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 653 | { |
| 654 | #define ColorizeImageTag "Colorize/Image" |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 655 | #define Colorize(pixel,blend_percentage,colorize) \ |
| 656 | (((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 657 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 658 | CacheView |
| 659 | *colorize_view, |
| 660 | *image_view; |
| 661 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | GeometryInfo |
| 663 | geometry_info; |
| 664 | |
| 665 | Image |
| 666 | *colorize_image; |
| 667 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | MagickBooleanType |
| 669 | status; |
| 670 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 671 | MagickOffsetType |
| 672 | progress; |
| 673 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 674 | MagickStatusType |
| 675 | flags; |
| 676 | |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 677 | PixelInfo |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 678 | blend_percentage; |
cristy | c7e6ff6 | 2011-10-03 13:46:11 +0000 | [diff] [blame] | 679 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 680 | ssize_t |
| 681 | y; |
| 682 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 683 | /* |
| 684 | Allocate colorized image. |
| 685 | */ |
| 686 | assert(image != (const Image *) NULL); |
| 687 | assert(image->signature == MagickSignature); |
| 688 | if (image->debug != MagickFalse) |
| 689 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 690 | assert(exception != (ExceptionInfo *) NULL); |
| 691 | assert(exception->signature == MagickSignature); |
cristy | 768165d | 2012-04-09 15:01:35 +0000 | [diff] [blame] | 692 | colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
| 693 | exception); |
| 694 | if (colorize_image == (Image *) NULL) |
| 695 | return((Image *) NULL); |
| 696 | if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse) |
| 697 | { |
| 698 | colorize_image=DestroyImage(colorize_image); |
| 699 | return((Image *) NULL); |
| 700 | } |
cristy | f8da9f9 | 2013-04-16 19:52:28 +0000 | [diff] [blame] | 701 | if ((IsGrayColorspace(image->colorspace) != MagickFalse) || |
cristy | 4dab380 | 2013-03-15 22:08:15 +0000 | [diff] [blame] | 702 | (IsPixelInfoGray(colorize) != MagickFalse)) |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 703 | (void) SetImageColorspace(colorize_image,sRGBColorspace,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 704 | if ((colorize_image->alpha_trait != BlendPixelTrait) && |
| 705 | (colorize->alpha_trait == BlendPixelTrait)) |
cristy | 768165d | 2012-04-09 15:01:35 +0000 | [diff] [blame] | 706 | (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception); |
| 707 | if (blend == (const char *) NULL) |
| 708 | return(colorize_image); |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 709 | GetPixelInfo(image,&blend_percentage); |
| 710 | flags=ParseGeometry(blend,&geometry_info); |
| 711 | blend_percentage.red=geometry_info.rho; |
| 712 | blend_percentage.green=geometry_info.rho; |
| 713 | blend_percentage.blue=geometry_info.rho; |
| 714 | blend_percentage.black=geometry_info.rho; |
cristy | 3ee7de5 | 2012-04-14 23:40:47 +0000 | [diff] [blame] | 715 | blend_percentage.alpha=geometry_info.rho; |
cristy | 20c3aed | 2012-04-10 01:06:21 +0000 | [diff] [blame] | 716 | if ((flags & SigmaValue) != 0) |
| 717 | blend_percentage.green=geometry_info.sigma; |
| 718 | if ((flags & XiValue) != 0) |
| 719 | blend_percentage.blue=geometry_info.xi; |
| 720 | if ((flags & PsiValue) != 0) |
| 721 | blend_percentage.alpha=geometry_info.psi; |
| 722 | if (blend_percentage.colorspace == CMYKColorspace) |
| 723 | { |
| 724 | if ((flags & PsiValue) != 0) |
| 725 | blend_percentage.black=geometry_info.psi; |
| 726 | if ((flags & ChiValue) != 0) |
| 727 | blend_percentage.alpha=geometry_info.chi; |
| 728 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 729 | /* |
| 730 | Colorize DirectClass image. |
| 731 | */ |
| 732 | status=MagickTrue; |
| 733 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 734 | image_view=AcquireVirtualCacheView(image,exception); |
| 735 | colorize_view=AcquireAuthenticCacheView(colorize_image,exception); |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 736 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 737 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 738 | magick_threads(image,colorize_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 739 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 740 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 741 | { |
| 742 | MagickBooleanType |
| 743 | sync; |
| 744 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 745 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 746 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 748 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 749 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 750 | |
cristy | 4a37c62 | 2012-08-23 18:47:56 +0000 | [diff] [blame] | 751 | register ssize_t |
| 752 | x; |
| 753 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 754 | if (status == MagickFalse) |
| 755 | continue; |
| 756 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 757 | q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1, |
| 758 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 759 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 760 | { |
| 761 | status=MagickFalse; |
| 762 | continue; |
| 763 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 764 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 765 | { |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 766 | register ssize_t |
| 767 | i; |
| 768 | |
| 769 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 770 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 771 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 772 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 773 | PixelTrait colorize_traits=GetPixelChannelTraits(colorize_image, |
| 774 | channel); |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 775 | if ((traits == UndefinedPixelTrait) || |
| 776 | (colorize_traits == UndefinedPixelTrait)) |
cristy | d680338 | 2012-04-10 01:41:25 +0000 | [diff] [blame] | 777 | continue; |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 778 | if (((colorize_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 779 | (GetPixelReadMask(image,p) == 0)) |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 780 | { |
| 781 | SetPixelChannel(colorize_image,channel,p[i],q); |
| 782 | continue; |
| 783 | } |
cristy | b711323 | 2013-02-15 00:35:19 +0000 | [diff] [blame] | 784 | SetPixelChannel(colorize_image,channel,ClampToQuantum(Colorize(p[i], |
| 785 | GetPixelInfoChannel(&blend_percentage,channel),GetPixelInfoChannel( |
| 786 | colorize,channel))),q); |
cristy | 0cf6da5 | 2012-08-25 00:35:24 +0000 | [diff] [blame] | 787 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 788 | p+=GetPixelChannels(image); |
| 789 | q+=GetPixelChannels(colorize_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 790 | } |
| 791 | sync=SyncCacheViewAuthenticPixels(colorize_view,exception); |
| 792 | if (sync == MagickFalse) |
| 793 | status=MagickFalse; |
| 794 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 795 | { |
| 796 | MagickBooleanType |
| 797 | proceed; |
| 798 | |
cristy | 319a1e7 | 2010-02-21 15:13:11 +0000 | [diff] [blame] | 799 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 800 | #pragma omp critical (MagickCore_ColorizeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 801 | #endif |
| 802 | proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows); |
| 803 | if (proceed == MagickFalse) |
| 804 | status=MagickFalse; |
| 805 | } |
| 806 | } |
| 807 | image_view=DestroyCacheView(image_view); |
| 808 | colorize_view=DestroyCacheView(colorize_view); |
| 809 | if (status == MagickFalse) |
| 810 | colorize_image=DestroyImage(colorize_image); |
| 811 | return(colorize_image); |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 816 | % % |
| 817 | % % |
| 818 | % % |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 819 | % C o l o r M a t r i x I m a g e % |
| 820 | % % |
| 821 | % % |
| 822 | % % |
| 823 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 824 | % |
| 825 | % ColorMatrixImage() applies color transformation to an image. This method |
| 826 | % permits saturation changes, hue rotation, luminance to alpha, and various |
| 827 | % other effects. Although variable-sized transformation matrices can be used, |
| 828 | % typically one uses a 5x5 matrix for an RGBA image and a 6x6 for CMYKA |
| 829 | % (or RGBA with offsets). The matrix is similar to those used by Adobe Flash |
| 830 | % except offsets are in column 6 rather than 5 (in support of CMYKA images) |
| 831 | % and offsets are normalized (divide Flash offset by 255). |
| 832 | % |
| 833 | % The format of the ColorMatrixImage method is: |
| 834 | % |
| 835 | % Image *ColorMatrixImage(const Image *image, |
| 836 | % const KernelInfo *color_matrix,ExceptionInfo *exception) |
| 837 | % |
| 838 | % A description of each parameter follows: |
| 839 | % |
| 840 | % o image: the image. |
| 841 | % |
| 842 | % o color_matrix: the color matrix. |
| 843 | % |
| 844 | % o exception: return any errors or warnings in this structure. |
| 845 | % |
| 846 | */ |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 847 | /* FUTURE: modify to make use of a MagickMatrix Mutliply function |
| 848 | That should be provided in "matrix.c" |
| 849 | (ASIDE: actually distorts should do this too but currently doesn't) |
| 850 | */ |
| 851 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 852 | MagickExport Image *ColorMatrixImage(const Image *image, |
| 853 | const KernelInfo *color_matrix,ExceptionInfo *exception) |
| 854 | { |
| 855 | #define ColorMatrixImageTag "ColorMatrix/Image" |
| 856 | |
| 857 | CacheView |
| 858 | *color_view, |
| 859 | *image_view; |
| 860 | |
| 861 | double |
| 862 | ColorMatrix[6][6] = |
| 863 | { |
| 864 | { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, |
| 865 | { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 }, |
| 866 | { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 }, |
| 867 | { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0 }, |
| 868 | { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0 }, |
| 869 | { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 } |
| 870 | }; |
| 871 | |
| 872 | Image |
| 873 | *color_image; |
| 874 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 875 | MagickBooleanType |
| 876 | status; |
| 877 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 878 | MagickOffsetType |
| 879 | progress; |
| 880 | |
| 881 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 882 | i; |
| 883 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 884 | ssize_t |
| 885 | u, |
| 886 | v, |
| 887 | y; |
| 888 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 889 | /* |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 890 | Map given color_matrix, into a 6x6 matrix RGBKA and a constant |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 891 | */ |
| 892 | assert(image != (Image *) NULL); |
| 893 | assert(image->signature == MagickSignature); |
| 894 | if (image->debug != MagickFalse) |
| 895 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 896 | assert(exception != (ExceptionInfo *) NULL); |
| 897 | assert(exception->signature == MagickSignature); |
| 898 | i=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 899 | for (v=0; v < (ssize_t) color_matrix->height; v++) |
| 900 | for (u=0; u < (ssize_t) color_matrix->width; u++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 901 | { |
| 902 | if ((v < 6) && (u < 6)) |
| 903 | ColorMatrix[v][u]=color_matrix->values[i]; |
| 904 | i++; |
| 905 | } |
| 906 | /* |
| 907 | Initialize color image. |
| 908 | */ |
cristy | 12550e6 | 2010-06-07 12:46:40 +0000 | [diff] [blame] | 909 | color_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 910 | if (color_image == (Image *) NULL) |
| 911 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 912 | if (SetImageStorageClass(color_image,DirectClass,exception) == MagickFalse) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 913 | { |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 914 | color_image=DestroyImage(color_image); |
| 915 | return((Image *) NULL); |
| 916 | } |
| 917 | if (image->debug != MagickFalse) |
| 918 | { |
| 919 | char |
| 920 | format[MaxTextExtent], |
| 921 | *message; |
| 922 | |
| 923 | (void) LogMagickEvent(TransformEvent,GetMagickModule(), |
| 924 | " ColorMatrix image with color matrix:"); |
| 925 | message=AcquireString(""); |
| 926 | for (v=0; v < 6; v++) |
| 927 | { |
| 928 | *message='\0'; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 929 | (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 930 | (void) ConcatenateString(&message,format); |
| 931 | for (u=0; u < 6; u++) |
| 932 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 933 | (void) FormatLocaleString(format,MaxTextExtent,"%+f ", |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 934 | ColorMatrix[v][u]); |
| 935 | (void) ConcatenateString(&message,format); |
| 936 | } |
| 937 | (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message); |
| 938 | } |
| 939 | message=DestroyString(message); |
| 940 | } |
| 941 | /* |
anthony | fd706f9 | 2012-01-19 04:22:02 +0000 | [diff] [blame] | 942 | Apply the ColorMatrix to image. |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 943 | */ |
| 944 | status=MagickTrue; |
| 945 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 946 | image_view=AcquireVirtualCacheView(image,exception); |
| 947 | color_view=AcquireAuthenticCacheView(color_image,exception); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 948 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 949 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 950 | magick_threads(image,color_image,image->rows,1) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 951 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 952 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 953 | { |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 954 | PixelInfo |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 955 | pixel; |
| 956 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 957 | register const Quantum |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 958 | *restrict p; |
| 959 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 960 | register Quantum |
| 961 | *restrict q; |
| 962 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 963 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 964 | x; |
| 965 | |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 966 | if (status == MagickFalse) |
| 967 | continue; |
| 968 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 969 | q=GetCacheViewAuthenticPixels(color_view,0,y,color_image->columns,1, |
| 970 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 971 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 972 | { |
| 973 | status=MagickFalse; |
| 974 | continue; |
| 975 | } |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 976 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 977 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 978 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 979 | register ssize_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 980 | v; |
| 981 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 982 | size_t |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 983 | height; |
| 984 | |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 985 | GetPixelInfoPixel(image,p,&pixel); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 986 | height=color_matrix->height > 6 ? 6UL : color_matrix->height; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 987 | for (v=0; v < (ssize_t) height; v++) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 988 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 989 | double |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 990 | sum; |
| 991 | |
| 992 | sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 993 | GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 994 | if (image->colorspace == CMYKColorspace) |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 995 | sum+=ColorMatrix[v][3]*GetPixelBlack(image,p); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 996 | if (image->alpha_trait == BlendPixelTrait) |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 997 | sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p); |
| 998 | sum+=QuantumRange*ColorMatrix[v][5]; |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 999 | switch (v) |
| 1000 | { |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 1001 | case 0: pixel.red=sum; break; |
| 1002 | case 1: pixel.green=sum; break; |
| 1003 | case 2: pixel.blue=sum; break; |
| 1004 | case 3: pixel.black=sum; break; |
| 1005 | case 4: pixel.alpha=sum; break; |
| 1006 | default: break; |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 1007 | } |
| 1008 | } |
cristy | fcc25d9 | 2012-02-19 23:06:48 +0000 | [diff] [blame] | 1009 | SetPixelInfoPixel(color_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1010 | p+=GetPixelChannels(image); |
| 1011 | q+=GetPixelChannels(color_image); |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 1012 | } |
| 1013 | if (SyncCacheViewAuthenticPixels(color_view,exception) == MagickFalse) |
| 1014 | status=MagickFalse; |
| 1015 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1016 | { |
| 1017 | MagickBooleanType |
| 1018 | proceed; |
| 1019 | |
| 1020 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 1021 | #pragma omp critical (MagickCore_ColorMatrixImage) |
cristy | e636559 | 2010-04-02 17:31:23 +0000 | [diff] [blame] | 1022 | #endif |
| 1023 | proceed=SetImageProgress(image,ColorMatrixImageTag,progress++, |
| 1024 | image->rows); |
| 1025 | if (proceed == MagickFalse) |
| 1026 | status=MagickFalse; |
| 1027 | } |
| 1028 | } |
| 1029 | color_view=DestroyCacheView(color_view); |
| 1030 | image_view=DestroyCacheView(image_view); |
| 1031 | if (status == MagickFalse) |
| 1032 | color_image=DestroyImage(color_image); |
| 1033 | return(color_image); |
| 1034 | } |
| 1035 | |
| 1036 | /* |
| 1037 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1038 | % % |
| 1039 | % % |
| 1040 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1041 | + D e s t r o y F x I n f o % |
| 1042 | % % |
| 1043 | % % |
| 1044 | % % |
| 1045 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1046 | % |
| 1047 | % DestroyFxInfo() deallocates memory associated with an FxInfo structure. |
| 1048 | % |
| 1049 | % The format of the DestroyFxInfo method is: |
| 1050 | % |
| 1051 | % ImageInfo *DestroyFxInfo(ImageInfo *fx_info) |
| 1052 | % |
| 1053 | % A description of each parameter follows: |
| 1054 | % |
| 1055 | % o fx_info: the fx info. |
| 1056 | % |
| 1057 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1058 | MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1059 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1060 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1061 | i; |
| 1062 | |
| 1063 | fx_info->exception=DestroyExceptionInfo(fx_info->exception); |
| 1064 | fx_info->expression=DestroyString(fx_info->expression); |
| 1065 | fx_info->symbols=DestroySplayTree(fx_info->symbols); |
| 1066 | fx_info->colors=DestroySplayTree(fx_info->colors); |
cristy | 0ea377f | 2011-03-24 00:54:19 +0000 | [diff] [blame] | 1067 | for (i=(ssize_t) GetImageListLength(fx_info->images)-1; i >= 0; i--) |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 1068 | fx_info->view[i]=DestroyCacheView(fx_info->view[i]); |
| 1069 | fx_info->view=(CacheView **) RelinquishMagickMemory(fx_info->view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1070 | fx_info->random_info=DestroyRandomInfo(fx_info->random_info); |
| 1071 | fx_info=(FxInfo *) RelinquishMagickMemory(fx_info); |
| 1072 | return(fx_info); |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1077 | % % |
| 1078 | % % |
| 1079 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1080 | + F x E v a l u a t e C h a n n e l E x p r e s s i o n % |
| 1081 | % % |
| 1082 | % % |
| 1083 | % % |
| 1084 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1085 | % |
| 1086 | % FxEvaluateChannelExpression() evaluates an expression and returns the |
| 1087 | % results. |
| 1088 | % |
| 1089 | % The format of the FxEvaluateExpression method is: |
| 1090 | % |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1091 | % double FxEvaluateChannelExpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1092 | % const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1093 | % double *alpha,Exceptioninfo *exception) |
| 1094 | % double FxEvaluateExpression(FxInfo *fx_info, |
| 1095 | % double *alpha,Exceptioninfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1096 | % |
| 1097 | % A description of each parameter follows: |
| 1098 | % |
| 1099 | % o fx_info: the fx info. |
| 1100 | % |
| 1101 | % o channel: the channel. |
| 1102 | % |
| 1103 | % o x,y: the pixel position. |
| 1104 | % |
| 1105 | % o alpha: the result. |
| 1106 | % |
| 1107 | % o exception: return any errors or warnings in this structure. |
| 1108 | % |
| 1109 | */ |
| 1110 | |
cristy | 351842f | 2010-03-07 15:27:38 +0000 | [diff] [blame] | 1111 | static inline double MagickMax(const double x,const double y) |
| 1112 | { |
| 1113 | if (x > y) |
| 1114 | return(x); |
| 1115 | return(y); |
| 1116 | } |
| 1117 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1118 | static double FxChannelStatistics(FxInfo *fx_info,Image *image, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1119 | PixelChannel channel,const char *symbol,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1120 | { |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1121 | ChannelType |
| 1122 | channel_mask; |
| 1123 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1124 | char |
| 1125 | key[MaxTextExtent], |
| 1126 | statistic[MaxTextExtent]; |
| 1127 | |
| 1128 | const char |
| 1129 | *value; |
| 1130 | |
| 1131 | register const char |
| 1132 | *p; |
| 1133 | |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1134 | channel_mask=UndefinedChannel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1135 | for (p=symbol; (*p != '.') && (*p != '\0'); p++) ; |
| 1136 | if (*p == '.') |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1137 | { |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1138 | ssize_t |
| 1139 | option; |
| 1140 | |
| 1141 | option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1); |
| 1142 | if (option >= 0) |
| 1143 | { |
| 1144 | channel=(PixelChannel) option; |
| 1145 | channel_mask=(ChannelType) (channel_mask | (1 << channel)); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 1146 | SetPixelChannelMask(image,channel_mask); |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1147 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1148 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1149 | (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1150 | (double) channel,symbol); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1151 | value=(const char *) GetValueFromSplayTree(fx_info->symbols,key); |
| 1152 | if (value != (const char *) NULL) |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1153 | { |
| 1154 | if (channel_mask != UndefinedChannel) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 1155 | SetPixelChannelMask(image,channel_mask); |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1156 | return(QuantumScale*StringToDouble(value,(char **) NULL)); |
| 1157 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1158 | (void) DeleteNodeFromSplayTree(fx_info->symbols,key); |
| 1159 | if (LocaleNCompare(symbol,"depth",5) == 0) |
| 1160 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1161 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1162 | depth; |
| 1163 | |
cristy | fefab1b | 2011-07-05 00:33:22 +0000 | [diff] [blame] | 1164 | depth=GetImageDepth(image,exception); |
| 1165 | (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1166 | } |
| 1167 | if (LocaleNCompare(symbol,"kurtosis",8) == 0) |
| 1168 | { |
| 1169 | double |
| 1170 | kurtosis, |
| 1171 | skewness; |
| 1172 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1173 | (void) GetImageKurtosis(image,&kurtosis,&skewness,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1174 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1175 | } |
| 1176 | if (LocaleNCompare(symbol,"maxima",6) == 0) |
| 1177 | { |
| 1178 | double |
| 1179 | maxima, |
| 1180 | minima; |
| 1181 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1182 | (void) GetImageRange(image,&minima,&maxima,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1183 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1184 | } |
| 1185 | if (LocaleNCompare(symbol,"mean",4) == 0) |
| 1186 | { |
| 1187 | double |
| 1188 | mean, |
| 1189 | standard_deviation; |
| 1190 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1191 | (void) GetImageMean(image,&mean,&standard_deviation,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1192 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1193 | } |
| 1194 | if (LocaleNCompare(symbol,"minima",6) == 0) |
| 1195 | { |
| 1196 | double |
| 1197 | maxima, |
| 1198 | minima; |
| 1199 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1200 | (void) GetImageRange(image,&minima,&maxima,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1201 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1202 | } |
| 1203 | if (LocaleNCompare(symbol,"skewness",8) == 0) |
| 1204 | { |
| 1205 | double |
| 1206 | kurtosis, |
| 1207 | skewness; |
| 1208 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1209 | (void) GetImageKurtosis(image,&kurtosis,&skewness,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1210 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1211 | } |
| 1212 | if (LocaleNCompare(symbol,"standard_deviation",18) == 0) |
| 1213 | { |
| 1214 | double |
| 1215 | mean, |
| 1216 | standard_deviation; |
| 1217 | |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 1218 | (void) GetImageMean(image,&mean,&standard_deviation,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1219 | (void) FormatLocaleString(statistic,MaxTextExtent,"%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | standard_deviation); |
| 1221 | } |
cristy | 5048d30 | 2012-08-07 01:05:16 +0000 | [diff] [blame] | 1222 | if (channel_mask != UndefinedChannel) |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 1223 | SetPixelChannelMask(image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1224 | (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key), |
| 1225 | ConstantString(statistic)); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1226 | return(QuantumScale*StringToDouble(statistic,(char **) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1227 | } |
| 1228 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1229 | static double |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1230 | FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1231 | const ssize_t,const char *,double *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1232 | |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 1233 | static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta) |
| 1234 | { |
| 1235 | if (beta != 0) |
| 1236 | return(FxGCD(beta,alpha % beta)); |
| 1237 | return(alpha); |
| 1238 | } |
| 1239 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1240 | static inline const char *FxSubexpression(const char *expression, |
| 1241 | ExceptionInfo *exception) |
| 1242 | { |
| 1243 | const char |
| 1244 | *subexpression; |
| 1245 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1246 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1247 | level; |
| 1248 | |
| 1249 | level=0; |
| 1250 | subexpression=expression; |
| 1251 | while ((*subexpression != '\0') && |
| 1252 | ((level != 1) || (strchr(")",(int) *subexpression) == (char *) NULL))) |
| 1253 | { |
| 1254 | if (strchr("(",(int) *subexpression) != (char *) NULL) |
| 1255 | level++; |
| 1256 | else |
| 1257 | if (strchr(")",(int) *subexpression) != (char *) NULL) |
| 1258 | level--; |
| 1259 | subexpression++; |
| 1260 | } |
| 1261 | if (*subexpression == '\0') |
| 1262 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1263 | "UnbalancedParenthesis","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1264 | return(subexpression); |
| 1265 | } |
| 1266 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1267 | static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel, |
cristy | e85007d | 2010-06-06 22:51:36 +0000 | [diff] [blame] | 1268 | const ssize_t x,const ssize_t y,const char *expression, |
| 1269 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1270 | { |
| 1271 | char |
| 1272 | *q, |
| 1273 | subexpression[MaxTextExtent], |
| 1274 | symbol[MaxTextExtent]; |
| 1275 | |
| 1276 | const char |
| 1277 | *p, |
| 1278 | *value; |
| 1279 | |
| 1280 | Image |
| 1281 | *image; |
| 1282 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1283 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1284 | pixel; |
| 1285 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1286 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1287 | alpha, |
| 1288 | beta; |
| 1289 | |
| 1290 | PointInfo |
| 1291 | point; |
| 1292 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1293 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1294 | i; |
| 1295 | |
| 1296 | size_t |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1297 | length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1298 | level; |
| 1299 | |
| 1300 | p=expression; |
| 1301 | i=GetImageIndexInList(fx_info->images); |
| 1302 | level=0; |
| 1303 | point.x=(double) x; |
| 1304 | point.y=(double) y; |
cristy | 02e64f8 | 2013-11-14 16:20:04 +0000 | [diff] [blame] | 1305 | if (isalpha((int) ((unsigned char) *(p+1))) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1306 | { |
| 1307 | if (strchr("suv",(int) *p) != (char *) NULL) |
| 1308 | { |
| 1309 | switch (*p) |
| 1310 | { |
| 1311 | case 's': |
| 1312 | default: |
| 1313 | { |
| 1314 | i=GetImageIndexInList(fx_info->images); |
| 1315 | break; |
| 1316 | } |
| 1317 | case 'u': i=0; break; |
| 1318 | case 'v': i=1; break; |
| 1319 | } |
| 1320 | p++; |
| 1321 | if (*p == '[') |
| 1322 | { |
| 1323 | level++; |
| 1324 | q=subexpression; |
| 1325 | for (p++; *p != '\0'; ) |
| 1326 | { |
| 1327 | if (*p == '[') |
| 1328 | level++; |
| 1329 | else |
| 1330 | if (*p == ']') |
| 1331 | { |
| 1332 | level--; |
| 1333 | if (level == 0) |
| 1334 | break; |
| 1335 | } |
| 1336 | *q++=(*p++); |
| 1337 | } |
| 1338 | *q='\0'; |
| 1339 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1340 | &beta,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1341 | i=(ssize_t) (alpha+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1342 | p++; |
| 1343 | } |
| 1344 | if (*p == '.') |
| 1345 | p++; |
| 1346 | } |
cristy | 02e64f8 | 2013-11-14 16:20:04 +0000 | [diff] [blame] | 1347 | if ((*p == 'p') && (isalpha((int) ((unsigned char) *(p+1))) == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1348 | { |
| 1349 | p++; |
| 1350 | if (*p == '{') |
| 1351 | { |
| 1352 | level++; |
| 1353 | q=subexpression; |
| 1354 | for (p++; *p != '\0'; ) |
| 1355 | { |
| 1356 | if (*p == '{') |
| 1357 | level++; |
| 1358 | else |
| 1359 | if (*p == '}') |
| 1360 | { |
| 1361 | level--; |
| 1362 | if (level == 0) |
| 1363 | break; |
| 1364 | } |
| 1365 | *q++=(*p++); |
| 1366 | } |
| 1367 | *q='\0'; |
| 1368 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1369 | &beta,exception); |
| 1370 | point.x=alpha; |
| 1371 | point.y=beta; |
| 1372 | p++; |
| 1373 | } |
| 1374 | else |
| 1375 | if (*p == '[') |
| 1376 | { |
| 1377 | level++; |
| 1378 | q=subexpression; |
| 1379 | for (p++; *p != '\0'; ) |
| 1380 | { |
| 1381 | if (*p == '[') |
| 1382 | level++; |
| 1383 | else |
| 1384 | if (*p == ']') |
| 1385 | { |
| 1386 | level--; |
| 1387 | if (level == 0) |
| 1388 | break; |
| 1389 | } |
| 1390 | *q++=(*p++); |
| 1391 | } |
| 1392 | *q='\0'; |
| 1393 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression, |
| 1394 | &beta,exception); |
| 1395 | point.x+=alpha; |
| 1396 | point.y+=beta; |
| 1397 | p++; |
| 1398 | } |
| 1399 | if (*p == '.') |
| 1400 | p++; |
| 1401 | } |
| 1402 | } |
| 1403 | length=GetImageListLength(fx_info->images); |
| 1404 | while (i < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1405 | i+=(ssize_t) length; |
cristy | 58a749e | 2014-05-25 17:36:53 +0000 | [diff] [blame] | 1406 | if (length != 0) |
| 1407 | i%=length; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1408 | image=GetImageFromList(fx_info->images,i); |
| 1409 | if (image == (Image *) NULL) |
| 1410 | { |
| 1411 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1412 | "NoSuchImage","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1413 | return(0.0); |
| 1414 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1415 | GetPixelInfo(image,&pixel); |
| 1416 | (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate, |
cristy | 4f82071 | 2011-04-01 12:35:43 +0000 | [diff] [blame] | 1417 | point.x,point.y,&pixel,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1418 | if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) && |
cristy | ba21340 | 2013-06-28 14:05:12 +0000 | [diff] [blame] | 1419 | (LocaleCompare(p,"luma") != 0) && (LocaleCompare(p,"luminance") != 0) && |
| 1420 | (LocaleCompare(p,"hue") != 0) && (LocaleCompare(p,"saturation") != 0) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1421 | (LocaleCompare(p,"lightness") != 0)) |
| 1422 | { |
| 1423 | char |
| 1424 | name[MaxTextExtent]; |
| 1425 | |
| 1426 | (void) CopyMagickString(name,p,MaxTextExtent); |
| 1427 | for (q=name+(strlen(name)-1); q > name; q--) |
| 1428 | { |
| 1429 | if (*q == ')') |
| 1430 | break; |
| 1431 | if (*q == '.') |
| 1432 | { |
| 1433 | *q='\0'; |
| 1434 | break; |
| 1435 | } |
| 1436 | } |
| 1437 | if ((strlen(name) > 2) && |
| 1438 | (GetValueFromSplayTree(fx_info->symbols,name) == (const char *) NULL)) |
| 1439 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1440 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1441 | *color; |
| 1442 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1443 | color=(PixelInfo *) GetValueFromSplayTree(fx_info->colors,name); |
| 1444 | if (color != (PixelInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1445 | { |
| 1446 | pixel=(*color); |
| 1447 | p+=strlen(name); |
| 1448 | } |
| 1449 | else |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 1450 | { |
| 1451 | MagickBooleanType |
| 1452 | status; |
| 1453 | |
| 1454 | status=QueryColorCompliance(name,AllCompliance,&pixel, |
| 1455 | fx_info->exception); |
| 1456 | if (status != MagickFalse) |
| 1457 | { |
| 1458 | (void) AddValueToSplayTree(fx_info->colors,ConstantString( |
| 1459 | name),ClonePixelInfo(&pixel)); |
| 1460 | p+=strlen(name); |
| 1461 | } |
| 1462 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1463 | } |
| 1464 | } |
| 1465 | (void) CopyMagickString(symbol,p,MaxTextExtent); |
| 1466 | StripString(symbol); |
| 1467 | if (*symbol == '\0') |
| 1468 | { |
| 1469 | switch (channel) |
| 1470 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1471 | case RedPixelChannel: return(QuantumScale*pixel.red); |
| 1472 | case GreenPixelChannel: return(QuantumScale*pixel.green); |
| 1473 | case BluePixelChannel: return(QuantumScale*pixel.blue); |
| 1474 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1475 | { |
| 1476 | if (image->colorspace != CMYKColorspace) |
| 1477 | { |
| 1478 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1479 | ImageError,"ColorSeparatedImageRequired","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1480 | image->filename); |
| 1481 | return(0.0); |
| 1482 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1483 | return(QuantumScale*pixel.black); |
| 1484 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1485 | case AlphaPixelChannel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1486 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1487 | double |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1488 | alpha; |
| 1489 | |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 1490 | if (pixel.alpha_trait != BlendPixelTrait) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1491 | return(1.0); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1492 | alpha=(double) (QuantumScale*pixel.alpha); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1493 | return(alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1494 | } |
cristy | a382aca | 2011-12-06 18:22:48 +0000 | [diff] [blame] | 1495 | case IndexPixelChannel: |
| 1496 | return(0.0); |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 1497 | case IntensityPixelChannel: |
cristy | f364ed4 | 2010-12-15 01:54:43 +0000 | [diff] [blame] | 1498 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1499 | return(QuantumScale*GetPixelInfoIntensity(&pixel)); |
cristy | f364ed4 | 2010-12-15 01:54:43 +0000 | [diff] [blame] | 1500 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1501 | default: |
| 1502 | break; |
| 1503 | } |
| 1504 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1505 | "UnableToParseExpression","`%s'",p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1506 | return(0.0); |
| 1507 | } |
| 1508 | switch (*symbol) |
| 1509 | { |
| 1510 | case 'A': |
| 1511 | case 'a': |
| 1512 | { |
| 1513 | if (LocaleCompare(symbol,"a") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1514 | return((double) (QuantumScale*pixel.alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1515 | break; |
| 1516 | } |
| 1517 | case 'B': |
| 1518 | case 'b': |
| 1519 | { |
| 1520 | if (LocaleCompare(symbol,"b") == 0) |
| 1521 | return(QuantumScale*pixel.blue); |
| 1522 | break; |
| 1523 | } |
| 1524 | case 'C': |
| 1525 | case 'c': |
| 1526 | { |
| 1527 | if (LocaleNCompare(symbol,"channel",7) == 0) |
| 1528 | { |
| 1529 | GeometryInfo |
| 1530 | channel_info; |
| 1531 | |
| 1532 | MagickStatusType |
| 1533 | flags; |
| 1534 | |
| 1535 | flags=ParseGeometry(symbol+7,&channel_info); |
| 1536 | if (image->colorspace == CMYKColorspace) |
| 1537 | switch (channel) |
| 1538 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1539 | case CyanPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1540 | { |
| 1541 | if ((flags & RhoValue) == 0) |
| 1542 | return(0.0); |
| 1543 | return(channel_info.rho); |
| 1544 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1545 | case MagentaPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1546 | { |
| 1547 | if ((flags & SigmaValue) == 0) |
| 1548 | return(0.0); |
| 1549 | return(channel_info.sigma); |
| 1550 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1551 | case YellowPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1552 | { |
| 1553 | if ((flags & XiValue) == 0) |
| 1554 | return(0.0); |
| 1555 | return(channel_info.xi); |
| 1556 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1557 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1558 | { |
| 1559 | if ((flags & PsiValue) == 0) |
| 1560 | return(0.0); |
| 1561 | return(channel_info.psi); |
| 1562 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1563 | case AlphaPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1564 | { |
| 1565 | if ((flags & ChiValue) == 0) |
| 1566 | return(0.0); |
| 1567 | return(channel_info.chi); |
| 1568 | } |
| 1569 | default: |
| 1570 | return(0.0); |
| 1571 | } |
| 1572 | switch (channel) |
| 1573 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1574 | case RedPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1575 | { |
| 1576 | if ((flags & RhoValue) == 0) |
| 1577 | return(0.0); |
| 1578 | return(channel_info.rho); |
| 1579 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1580 | case GreenPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1581 | { |
| 1582 | if ((flags & SigmaValue) == 0) |
| 1583 | return(0.0); |
| 1584 | return(channel_info.sigma); |
| 1585 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1586 | case BluePixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1587 | { |
| 1588 | if ((flags & XiValue) == 0) |
| 1589 | return(0.0); |
| 1590 | return(channel_info.xi); |
| 1591 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1592 | case BlackPixelChannel: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1593 | { |
| 1594 | if ((flags & ChiValue) == 0) |
| 1595 | return(0.0); |
| 1596 | return(channel_info.chi); |
| 1597 | } |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 1598 | case AlphaPixelChannel: |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1599 | { |
| 1600 | if ((flags & PsiValue) == 0) |
| 1601 | return(0.0); |
| 1602 | return(channel_info.psi); |
| 1603 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1604 | default: |
| 1605 | return(0.0); |
| 1606 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1607 | } |
| 1608 | if (LocaleCompare(symbol,"c") == 0) |
| 1609 | return(QuantumScale*pixel.red); |
| 1610 | break; |
| 1611 | } |
| 1612 | case 'D': |
| 1613 | case 'd': |
| 1614 | { |
| 1615 | if (LocaleNCompare(symbol,"depth",5) == 0) |
| 1616 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1617 | break; |
| 1618 | } |
| 1619 | case 'G': |
| 1620 | case 'g': |
| 1621 | { |
| 1622 | if (LocaleCompare(symbol,"g") == 0) |
| 1623 | return(QuantumScale*pixel.green); |
| 1624 | break; |
| 1625 | } |
| 1626 | case 'K': |
| 1627 | case 'k': |
| 1628 | { |
| 1629 | if (LocaleNCompare(symbol,"kurtosis",8) == 0) |
| 1630 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1631 | if (LocaleCompare(symbol,"k") == 0) |
| 1632 | { |
| 1633 | if (image->colorspace != CMYKColorspace) |
| 1634 | { |
| 1635 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1636 | OptionError,"ColorSeparatedImageRequired","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1637 | image->filename); |
| 1638 | return(0.0); |
| 1639 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1640 | return(QuantumScale*pixel.black); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1641 | } |
| 1642 | break; |
| 1643 | } |
| 1644 | case 'H': |
| 1645 | case 'h': |
| 1646 | { |
| 1647 | if (LocaleCompare(symbol,"h") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1648 | return((double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1649 | if (LocaleCompare(symbol,"hue") == 0) |
| 1650 | { |
| 1651 | double |
| 1652 | hue, |
| 1653 | lightness, |
| 1654 | saturation; |
| 1655 | |
cristy | 0a39a5c | 2012-06-27 12:51:45 +0000 | [diff] [blame] | 1656 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1657 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1658 | return(hue); |
| 1659 | } |
| 1660 | break; |
| 1661 | } |
| 1662 | case 'I': |
| 1663 | case 'i': |
| 1664 | { |
| 1665 | if ((LocaleCompare(symbol,"image.depth") == 0) || |
| 1666 | (LocaleCompare(symbol,"image.minima") == 0) || |
| 1667 | (LocaleCompare(symbol,"image.maxima") == 0) || |
| 1668 | (LocaleCompare(symbol,"image.mean") == 0) || |
| 1669 | (LocaleCompare(symbol,"image.kurtosis") == 0) || |
| 1670 | (LocaleCompare(symbol,"image.skewness") == 0) || |
| 1671 | (LocaleCompare(symbol,"image.standard_deviation") == 0)) |
| 1672 | return(FxChannelStatistics(fx_info,image,channel,symbol+6,exception)); |
| 1673 | if (LocaleCompare(symbol,"image.resolution.x") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1674 | return(image->resolution.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1675 | if (LocaleCompare(symbol,"image.resolution.y") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1676 | return(image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1677 | if (LocaleCompare(symbol,"intensity") == 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1678 | return(QuantumScale*GetPixelInfoIntensity(&pixel)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1679 | if (LocaleCompare(symbol,"i") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1680 | return((double) x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | } |
| 1683 | case 'J': |
| 1684 | case 'j': |
| 1685 | { |
| 1686 | if (LocaleCompare(symbol,"j") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1687 | return((double) y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1688 | break; |
| 1689 | } |
| 1690 | case 'L': |
| 1691 | case 'l': |
| 1692 | { |
| 1693 | if (LocaleCompare(symbol,"lightness") == 0) |
| 1694 | { |
| 1695 | double |
| 1696 | hue, |
| 1697 | lightness, |
| 1698 | saturation; |
| 1699 | |
cristy | 0a39a5c | 2012-06-27 12:51:45 +0000 | [diff] [blame] | 1700 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1701 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1702 | return(lightness); |
| 1703 | } |
cristy | d3d2a27 | 2013-06-24 16:09:41 +0000 | [diff] [blame] | 1704 | if (LocaleCompare(symbol,"luma") == 0) |
| 1705 | { |
| 1706 | double |
| 1707 | luma; |
| 1708 | |
| 1709 | luma=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue; |
| 1710 | return(QuantumScale*luma); |
| 1711 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1712 | if (LocaleCompare(symbol,"luminance") == 0) |
| 1713 | { |
| 1714 | double |
| 1715 | luminence; |
| 1716 | |
cristy | d3d2a27 | 2013-06-24 16:09:41 +0000 | [diff] [blame] | 1717 | luminence=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1718 | return(QuantumScale*luminence); |
| 1719 | } |
| 1720 | break; |
| 1721 | } |
| 1722 | case 'M': |
| 1723 | case 'm': |
| 1724 | { |
| 1725 | if (LocaleNCompare(symbol,"maxima",6) == 0) |
| 1726 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1727 | if (LocaleNCompare(symbol,"mean",4) == 0) |
| 1728 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1729 | if (LocaleNCompare(symbol,"minima",6) == 0) |
| 1730 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1731 | if (LocaleCompare(symbol,"m") == 0) |
cristy | 1c8e4f6 | 2014-05-26 16:17:53 +0000 | [diff] [blame] | 1732 | return(QuantumScale*pixel.green); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1733 | break; |
| 1734 | } |
| 1735 | case 'N': |
| 1736 | case 'n': |
| 1737 | { |
| 1738 | if (LocaleCompare(symbol,"n") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1739 | return((double) GetImageListLength(fx_info->images)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1740 | break; |
| 1741 | } |
| 1742 | case 'O': |
| 1743 | case 'o': |
| 1744 | { |
| 1745 | if (LocaleCompare(symbol,"o") == 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1746 | return(QuantumScale*pixel.alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1747 | break; |
| 1748 | } |
| 1749 | case 'P': |
| 1750 | case 'p': |
| 1751 | { |
| 1752 | if (LocaleCompare(symbol,"page.height") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1753 | return((double) image->page.height); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1754 | if (LocaleCompare(symbol,"page.width") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1755 | return((double) image->page.width); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1756 | if (LocaleCompare(symbol,"page.x") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1757 | return((double) image->page.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1758 | if (LocaleCompare(symbol,"page.y") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1759 | return((double) image->page.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1760 | break; |
| 1761 | } |
| 1762 | case 'R': |
| 1763 | case 'r': |
| 1764 | { |
| 1765 | if (LocaleCompare(symbol,"resolution.x") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1766 | return(image->resolution.x); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1767 | if (LocaleCompare(symbol,"resolution.y") == 0) |
cristy | 2a11bef | 2011-10-28 18:33:11 +0000 | [diff] [blame] | 1768 | return(image->resolution.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1769 | if (LocaleCompare(symbol,"r") == 0) |
| 1770 | return(QuantumScale*pixel.red); |
| 1771 | break; |
| 1772 | } |
| 1773 | case 'S': |
| 1774 | case 's': |
| 1775 | { |
| 1776 | if (LocaleCompare(symbol,"saturation") == 0) |
| 1777 | { |
| 1778 | double |
| 1779 | hue, |
| 1780 | lightness, |
| 1781 | saturation; |
| 1782 | |
cristy | 0a39a5c | 2012-06-27 12:51:45 +0000 | [diff] [blame] | 1783 | ConvertRGBToHSL(pixel.red,pixel.green,pixel.blue,&hue,&saturation, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 1784 | &lightness); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1785 | return(saturation); |
| 1786 | } |
| 1787 | if (LocaleNCompare(symbol,"skewness",8) == 0) |
| 1788 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1789 | if (LocaleNCompare(symbol,"standard_deviation",18) == 0) |
| 1790 | return(FxChannelStatistics(fx_info,image,channel,symbol,exception)); |
| 1791 | break; |
| 1792 | } |
| 1793 | case 'T': |
| 1794 | case 't': |
| 1795 | { |
| 1796 | if (LocaleCompare(symbol,"t") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1797 | return((double) GetImageIndexInList(fx_info->images)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1798 | break; |
| 1799 | } |
| 1800 | case 'W': |
| 1801 | case 'w': |
| 1802 | { |
| 1803 | if (LocaleCompare(symbol,"w") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1804 | return((double) image->columns); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1805 | break; |
| 1806 | } |
| 1807 | case 'Y': |
| 1808 | case 'y': |
| 1809 | { |
| 1810 | if (LocaleCompare(symbol,"y") == 0) |
cristy | 1c8e4f6 | 2014-05-26 16:17:53 +0000 | [diff] [blame] | 1811 | return(QuantumScale*pixel.blue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1812 | break; |
| 1813 | } |
| 1814 | case 'Z': |
| 1815 | case 'z': |
| 1816 | { |
| 1817 | if (LocaleCompare(symbol,"z") == 0) |
| 1818 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1819 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1820 | depth; |
| 1821 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1822 | depth=(double) GetImageDepth(image,fx_info->exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1823 | return(depth); |
| 1824 | } |
| 1825 | break; |
| 1826 | } |
| 1827 | default: |
| 1828 | break; |
| 1829 | } |
| 1830 | value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol); |
| 1831 | if (value != (const char *) NULL) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1832 | return((double) StringToDouble(value,(char **) NULL)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1833 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1834 | "UnableToParseExpression","`%s'",symbol); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1835 | return(0.0); |
| 1836 | } |
| 1837 | |
| 1838 | static const char *FxOperatorPrecedence(const char *expression, |
| 1839 | ExceptionInfo *exception) |
| 1840 | { |
| 1841 | typedef enum |
| 1842 | { |
| 1843 | UndefinedPrecedence, |
| 1844 | NullPrecedence, |
| 1845 | BitwiseComplementPrecedence, |
| 1846 | ExponentPrecedence, |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 1847 | ExponentialNotationPrecedence, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1848 | MultiplyPrecedence, |
| 1849 | AdditionPrecedence, |
| 1850 | ShiftPrecedence, |
| 1851 | RelationalPrecedence, |
| 1852 | EquivalencyPrecedence, |
| 1853 | BitwiseAndPrecedence, |
| 1854 | BitwiseOrPrecedence, |
| 1855 | LogicalAndPrecedence, |
| 1856 | LogicalOrPrecedence, |
| 1857 | TernaryPrecedence, |
| 1858 | AssignmentPrecedence, |
| 1859 | CommaPrecedence, |
| 1860 | SeparatorPrecedence |
| 1861 | } FxPrecedence; |
| 1862 | |
| 1863 | FxPrecedence |
| 1864 | precedence, |
| 1865 | target; |
| 1866 | |
| 1867 | register const char |
| 1868 | *subexpression; |
| 1869 | |
| 1870 | register int |
| 1871 | c; |
| 1872 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1873 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1874 | level; |
| 1875 | |
| 1876 | c=0; |
| 1877 | level=0; |
| 1878 | subexpression=(const char *) NULL; |
| 1879 | target=NullPrecedence; |
| 1880 | while (*expression != '\0') |
| 1881 | { |
| 1882 | precedence=UndefinedPrecedence; |
cristy | 248a3ec | 2013-08-17 16:25:26 +0000 | [diff] [blame] | 1883 | if ((isspace((int) ((unsigned char) *expression)) != 0) || (c == (int) '@')) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1884 | { |
| 1885 | expression++; |
| 1886 | continue; |
| 1887 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1888 | switch (*expression) |
| 1889 | { |
| 1890 | case 'A': |
| 1891 | case 'a': |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1892 | { |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1893 | #if defined(MAGICKCORE_HAVE_ACOSH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1894 | if (LocaleNCompare(expression,"acosh",5) == 0) |
| 1895 | { |
| 1896 | expression+=5; |
| 1897 | break; |
| 1898 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1899 | #endif |
| 1900 | #if defined(MAGICKCORE_HAVE_ASINH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1901 | if (LocaleNCompare(expression,"asinh",5) == 0) |
| 1902 | { |
| 1903 | expression+=5; |
| 1904 | break; |
| 1905 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1906 | #endif |
| 1907 | #if defined(MAGICKCORE_HAVE_ATANH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 1908 | if (LocaleNCompare(expression,"atanh",5) == 0) |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1909 | { |
| 1910 | expression+=5; |
| 1911 | break; |
| 1912 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 1913 | #endif |
anthony | 62838e5 | 2012-05-24 12:41:54 +0000 | [diff] [blame] | 1914 | if (LocaleNCompare(expression,"atan2",5) == 0) |
| 1915 | { |
| 1916 | expression+=5; |
| 1917 | break; |
| 1918 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1919 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1920 | } |
cristy | f06a561 | 2014-05-27 22:00:22 +0000 | [diff] [blame] | 1921 | case 'E': |
| 1922 | case 'e': |
| 1923 | { |
| 1924 | if ((isdigit((int) ((unsigned char) c)) != 0) && |
| 1925 | ((LocaleNCompare(expression,"E+",2) == 0) || |
| 1926 | (LocaleNCompare(expression,"E-",2) == 0))) |
| 1927 | { |
| 1928 | expression+=2; /* scientific notation */ |
| 1929 | break; |
| 1930 | } |
| 1931 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1932 | case 'J': |
| 1933 | case 'j': |
| 1934 | { |
| 1935 | if ((LocaleNCompare(expression,"j0",2) == 0) || |
| 1936 | (LocaleNCompare(expression,"j1",2) == 0)) |
| 1937 | { |
| 1938 | expression+=2; |
| 1939 | break; |
| 1940 | } |
| 1941 | break; |
| 1942 | } |
cristy | 2def932 | 2010-06-18 23:59:37 +0000 | [diff] [blame] | 1943 | case '#': |
| 1944 | { |
| 1945 | while (isxdigit((int) ((unsigned char) *(expression+1))) != 0) |
| 1946 | expression++; |
| 1947 | break; |
| 1948 | } |
cristy | 488fa88 | 2010-03-01 22:34:24 +0000 | [diff] [blame] | 1949 | default: |
| 1950 | break; |
| 1951 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1952 | if ((c == (int) '{') || (c == (int) '[')) |
| 1953 | level++; |
| 1954 | else |
| 1955 | if ((c == (int) '}') || (c == (int) ']')) |
| 1956 | level--; |
| 1957 | if (level == 0) |
| 1958 | switch ((unsigned char) *expression) |
| 1959 | { |
| 1960 | case '~': |
| 1961 | case '!': |
| 1962 | { |
| 1963 | precedence=BitwiseComplementPrecedence; |
| 1964 | break; |
| 1965 | } |
| 1966 | case '^': |
cristy | 6621e25 | 2010-08-13 00:42:57 +0000 | [diff] [blame] | 1967 | case '@': |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1968 | { |
| 1969 | precedence=ExponentPrecedence; |
| 1970 | break; |
| 1971 | } |
| 1972 | default: |
| 1973 | { |
cristy | 37466eb | 2013-08-17 17:04:59 +0000 | [diff] [blame] | 1974 | if (((c != 0) && ((isdigit((int) ((unsigned char) c)) != 0) || |
| 1975 | (strchr(")",(int) ((unsigned char) c)) != (char *) NULL))) && |
| 1976 | (((islower((int) ((unsigned char) *expression)) != 0) || |
| 1977 | (strchr("(",(int) ((unsigned char) *expression)) != (char *) NULL)) || |
| 1978 | ((isdigit((int) ((unsigned char) c)) == 0) && |
| 1979 | (isdigit((int) ((unsigned char) *expression)) != 0))) && |
| 1980 | (strchr("xy",(int) ((unsigned char) *expression)) == (char *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1981 | precedence=MultiplyPrecedence; |
| 1982 | break; |
| 1983 | } |
| 1984 | case '*': |
| 1985 | case '/': |
| 1986 | case '%': |
| 1987 | { |
| 1988 | precedence=MultiplyPrecedence; |
| 1989 | break; |
| 1990 | } |
| 1991 | case '+': |
| 1992 | case '-': |
| 1993 | { |
| 1994 | if ((strchr("(+-/*%:&^|<>~,",c) == (char *) NULL) || |
| 1995 | (isalpha(c) != 0)) |
| 1996 | precedence=AdditionPrecedence; |
| 1997 | break; |
| 1998 | } |
| 1999 | case LeftShiftOperator: |
| 2000 | case RightShiftOperator: |
| 2001 | { |
| 2002 | precedence=ShiftPrecedence; |
| 2003 | break; |
| 2004 | } |
| 2005 | case '<': |
| 2006 | case LessThanEqualOperator: |
| 2007 | case GreaterThanEqualOperator: |
| 2008 | case '>': |
| 2009 | { |
| 2010 | precedence=RelationalPrecedence; |
| 2011 | break; |
| 2012 | } |
| 2013 | case EqualOperator: |
| 2014 | case NotEqualOperator: |
| 2015 | { |
| 2016 | precedence=EquivalencyPrecedence; |
| 2017 | break; |
| 2018 | } |
| 2019 | case '&': |
| 2020 | { |
| 2021 | precedence=BitwiseAndPrecedence; |
| 2022 | break; |
| 2023 | } |
| 2024 | case '|': |
| 2025 | { |
| 2026 | precedence=BitwiseOrPrecedence; |
| 2027 | break; |
| 2028 | } |
| 2029 | case LogicalAndOperator: |
| 2030 | { |
| 2031 | precedence=LogicalAndPrecedence; |
| 2032 | break; |
| 2033 | } |
| 2034 | case LogicalOrOperator: |
| 2035 | { |
| 2036 | precedence=LogicalOrPrecedence; |
| 2037 | break; |
| 2038 | } |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 2039 | case ExponentialNotation: |
| 2040 | { |
| 2041 | precedence=ExponentialNotationPrecedence; |
| 2042 | break; |
| 2043 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2044 | case ':': |
| 2045 | case '?': |
| 2046 | { |
| 2047 | precedence=TernaryPrecedence; |
| 2048 | break; |
| 2049 | } |
| 2050 | case '=': |
| 2051 | { |
| 2052 | precedence=AssignmentPrecedence; |
| 2053 | break; |
| 2054 | } |
| 2055 | case ',': |
| 2056 | { |
| 2057 | precedence=CommaPrecedence; |
| 2058 | break; |
| 2059 | } |
| 2060 | case ';': |
| 2061 | { |
| 2062 | precedence=SeparatorPrecedence; |
| 2063 | break; |
| 2064 | } |
| 2065 | } |
| 2066 | if ((precedence == BitwiseComplementPrecedence) || |
| 2067 | (precedence == TernaryPrecedence) || |
| 2068 | (precedence == AssignmentPrecedence)) |
| 2069 | { |
| 2070 | if (precedence > target) |
| 2071 | { |
| 2072 | /* |
| 2073 | Right-to-left associativity. |
| 2074 | */ |
| 2075 | target=precedence; |
| 2076 | subexpression=expression; |
| 2077 | } |
| 2078 | } |
| 2079 | else |
| 2080 | if (precedence >= target) |
| 2081 | { |
| 2082 | /* |
| 2083 | Left-to-right associativity. |
| 2084 | */ |
| 2085 | target=precedence; |
| 2086 | subexpression=expression; |
| 2087 | } |
| 2088 | if (strchr("(",(int) *expression) != (char *) NULL) |
| 2089 | expression=FxSubexpression(expression,exception); |
| 2090 | c=(int) (*expression++); |
| 2091 | } |
| 2092 | return(subexpression); |
| 2093 | } |
| 2094 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2095 | static double FxEvaluateSubexpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2096 | const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2097 | const char *expression,double *beta,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2098 | { |
| 2099 | char |
| 2100 | *q, |
| 2101 | subexpression[MaxTextExtent]; |
| 2102 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2103 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2104 | alpha, |
| 2105 | gamma; |
| 2106 | |
| 2107 | register const char |
| 2108 | *p; |
| 2109 | |
| 2110 | *beta=0.0; |
| 2111 | if (exception->severity != UndefinedException) |
| 2112 | return(0.0); |
cristy | 248a3ec | 2013-08-17 16:25:26 +0000 | [diff] [blame] | 2113 | while (isspace((int) ((unsigned char) *expression)) != 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2114 | expression++; |
| 2115 | if (*expression == '\0') |
cristy | dc569d8 | 2014-04-20 15:54:56 +0000 | [diff] [blame] | 2116 | return(0.0); |
cristy | 66322f0 | 2010-05-17 11:40:48 +0000 | [diff] [blame] | 2117 | *subexpression='\0'; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2118 | p=FxOperatorPrecedence(expression,exception); |
| 2119 | if (p != (const char *) NULL) |
| 2120 | { |
| 2121 | (void) CopyMagickString(subexpression,expression,(size_t) |
| 2122 | (p-expression+1)); |
| 2123 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta, |
| 2124 | exception); |
| 2125 | switch ((unsigned char) *p) |
| 2126 | { |
| 2127 | case '~': |
| 2128 | { |
| 2129 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2130 | *beta=(double) (~(size_t) *beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2131 | return(*beta); |
| 2132 | } |
| 2133 | case '!': |
| 2134 | { |
| 2135 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2136 | return(*beta == 0.0 ? 1.0 : 0.0); |
| 2137 | } |
| 2138 | case '^': |
| 2139 | { |
| 2140 | *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info, |
| 2141 | channel,x,y,++p,beta,exception)); |
| 2142 | return(*beta); |
| 2143 | } |
| 2144 | case '*': |
cristy | 116af16 | 2010-08-13 01:25:47 +0000 | [diff] [blame] | 2145 | case ExponentialNotation: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2146 | { |
| 2147 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2148 | return(alpha*(*beta)); |
| 2149 | } |
| 2150 | case '/': |
| 2151 | { |
| 2152 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2153 | if (*beta == 0.0) |
| 2154 | { |
| 2155 | if (exception->severity == UndefinedException) |
| 2156 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2157 | OptionError,"DivideByZero","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2158 | return(0.0); |
| 2159 | } |
| 2160 | return(alpha/(*beta)); |
| 2161 | } |
| 2162 | case '%': |
| 2163 | { |
| 2164 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2165 | *beta=fabs(floor(((double) *beta)+0.5)); |
| 2166 | if (*beta == 0.0) |
| 2167 | { |
| 2168 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2169 | OptionError,"DivideByZero","`%s'",expression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2170 | return(0.0); |
| 2171 | } |
| 2172 | return(fmod((double) alpha,(double) *beta)); |
| 2173 | } |
| 2174 | case '+': |
| 2175 | { |
| 2176 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2177 | return(alpha+(*beta)); |
| 2178 | } |
| 2179 | case '-': |
| 2180 | { |
| 2181 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2182 | return(alpha-(*beta)); |
| 2183 | } |
| 2184 | case LeftShiftOperator: |
| 2185 | { |
| 2186 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2187 | *beta=(double) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2188 | return(*beta); |
| 2189 | } |
| 2190 | case RightShiftOperator: |
| 2191 | { |
| 2192 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2193 | *beta=(double) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2194 | return(*beta); |
| 2195 | } |
| 2196 | case '<': |
| 2197 | { |
| 2198 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2199 | return(alpha < *beta ? 1.0 : 0.0); |
| 2200 | } |
| 2201 | case LessThanEqualOperator: |
| 2202 | { |
| 2203 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2204 | return(alpha <= *beta ? 1.0 : 0.0); |
| 2205 | } |
| 2206 | case '>': |
| 2207 | { |
| 2208 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2209 | return(alpha > *beta ? 1.0 : 0.0); |
| 2210 | } |
| 2211 | case GreaterThanEqualOperator: |
| 2212 | { |
| 2213 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2214 | return(alpha >= *beta ? 1.0 : 0.0); |
| 2215 | } |
| 2216 | case EqualOperator: |
| 2217 | { |
| 2218 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | c06e20e | 2014-05-15 15:31:50 +0000 | [diff] [blame] | 2219 | return(fabs(alpha-(*beta)) < MagickEpsilon ? 1.0 : 0.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2220 | } |
| 2221 | case NotEqualOperator: |
| 2222 | { |
| 2223 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | 972050b | 2012-06-04 22:09:17 +0000 | [diff] [blame] | 2224 | return(fabs(alpha-(*beta)) >= MagickEpsilon ? 1.0 : 0.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2225 | } |
| 2226 | case '&': |
| 2227 | { |
| 2228 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2229 | *beta=(double) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2230 | return(*beta); |
| 2231 | } |
| 2232 | case '|': |
| 2233 | { |
| 2234 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2235 | *beta=(double) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2236 | return(*beta); |
| 2237 | } |
| 2238 | case LogicalAndOperator: |
| 2239 | { |
| 2240 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2241 | *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0; |
| 2242 | return(*beta); |
| 2243 | } |
| 2244 | case LogicalOrOperator: |
| 2245 | { |
| 2246 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2247 | *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0; |
| 2248 | return(*beta); |
| 2249 | } |
| 2250 | case '?': |
| 2251 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2252 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2253 | gamma; |
| 2254 | |
| 2255 | (void) CopyMagickString(subexpression,++p,MaxTextExtent); |
| 2256 | q=subexpression; |
| 2257 | p=StringToken(":",&q); |
| 2258 | if (q == (char *) NULL) |
| 2259 | { |
| 2260 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2261 | OptionError,"UnableToParseExpression","`%s'",subexpression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2262 | return(0.0); |
| 2263 | } |
cristy | 972050b | 2012-06-04 22:09:17 +0000 | [diff] [blame] | 2264 | if (fabs((double) alpha) >= MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2265 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception); |
| 2266 | else |
| 2267 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception); |
| 2268 | return(gamma); |
| 2269 | } |
| 2270 | case '=': |
| 2271 | { |
| 2272 | char |
| 2273 | numeric[MaxTextExtent]; |
| 2274 | |
| 2275 | q=subexpression; |
| 2276 | while (isalpha((int) ((unsigned char) *q)) != 0) |
| 2277 | q++; |
| 2278 | if (*q != '\0') |
| 2279 | { |
| 2280 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2281 | OptionError,"UnableToParseExpression","`%s'",subexpression); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2282 | return(0.0); |
| 2283 | } |
| 2284 | ClearMagickException(exception); |
| 2285 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2286 | (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 2287 | *beta); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2288 | (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression); |
| 2289 | (void) AddValueToSplayTree(fx_info->symbols,ConstantString( |
| 2290 | subexpression),ConstantString(numeric)); |
| 2291 | return(*beta); |
| 2292 | } |
| 2293 | case ',': |
| 2294 | { |
| 2295 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2296 | return(alpha); |
| 2297 | } |
| 2298 | case ';': |
| 2299 | { |
| 2300 | *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception); |
| 2301 | return(*beta); |
| 2302 | } |
| 2303 | default: |
| 2304 | { |
| 2305 | gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta, |
| 2306 | exception); |
| 2307 | return(gamma); |
| 2308 | } |
| 2309 | } |
| 2310 | } |
| 2311 | if (strchr("(",(int) *expression) != (char *) NULL) |
| 2312 | { |
| 2313 | (void) CopyMagickString(subexpression,expression+1,MaxTextExtent); |
| 2314 | subexpression[strlen(subexpression)-1]='\0'; |
| 2315 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta, |
| 2316 | exception); |
| 2317 | return(gamma); |
| 2318 | } |
cristy | 8b8a3ae | 2010-10-23 18:49:46 +0000 | [diff] [blame] | 2319 | switch (*expression) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2320 | { |
| 2321 | case '+': |
| 2322 | { |
| 2323 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2324 | exception); |
| 2325 | return(1.0*gamma); |
| 2326 | } |
| 2327 | case '-': |
| 2328 | { |
| 2329 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2330 | exception); |
| 2331 | return(-1.0*gamma); |
| 2332 | } |
| 2333 | case '~': |
| 2334 | { |
| 2335 | gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta, |
| 2336 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2337 | return((double) (~(size_t) (gamma+0.5))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2338 | } |
| 2339 | case 'A': |
| 2340 | case 'a': |
| 2341 | { |
| 2342 | if (LocaleNCompare(expression,"abs",3) == 0) |
| 2343 | { |
| 2344 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2345 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2346 | return((double) fabs((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2347 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2348 | #if defined(MAGICKCORE_HAVE_ACOSH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2349 | if (LocaleNCompare(expression,"acosh",5) == 0) |
| 2350 | { |
| 2351 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2352 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2353 | return((double) acosh((double) alpha)); |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2354 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2355 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2356 | if (LocaleNCompare(expression,"acos",4) == 0) |
| 2357 | { |
| 2358 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2359 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2360 | return((double) acos((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2361 | } |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2362 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2363 | if (LocaleNCompare(expression,"airy",4) == 0) |
| 2364 | { |
| 2365 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2366 | exception); |
| 2367 | if (alpha == 0.0) |
cristy | 2dd0322 | 2010-03-30 22:12:11 +0000 | [diff] [blame] | 2368 | return(1.0); |
| 2369 | gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha); |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2370 | return(gamma*gamma); |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2371 | } |
cristy | 43c22f4 | 2010-03-30 12:34:07 +0000 | [diff] [blame] | 2372 | #endif |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2373 | #if defined(MAGICKCORE_HAVE_ASINH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2374 | if (LocaleNCompare(expression,"asinh",5) == 0) |
| 2375 | { |
| 2376 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2377 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2378 | return((double) asinh((double) alpha)); |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2379 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2380 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2381 | if (LocaleNCompare(expression,"asin",4) == 0) |
| 2382 | { |
| 2383 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2384 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2385 | return((double) asin((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2386 | } |
| 2387 | if (LocaleNCompare(expression,"alt",3) == 0) |
| 2388 | { |
| 2389 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2390 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2391 | return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2392 | } |
| 2393 | if (LocaleNCompare(expression,"atan2",5) == 0) |
| 2394 | { |
| 2395 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2396 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2397 | return((double) atan2((double) alpha,(double) *beta)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2398 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2399 | #if defined(MAGICKCORE_HAVE_ATANH) |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2400 | if (LocaleNCompare(expression,"atanh",5) == 0) |
| 2401 | { |
| 2402 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2403 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2404 | return((double) atanh((double) alpha)); |
cristy | 363772a | 2011-07-28 23:25:33 +0000 | [diff] [blame] | 2405 | } |
cristy | b33454f | 2011-08-03 02:10:45 +0000 | [diff] [blame] | 2406 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2407 | if (LocaleNCompare(expression,"atan",4) == 0) |
| 2408 | { |
| 2409 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2410 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2411 | return((double) atan((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2412 | } |
| 2413 | if (LocaleCompare(expression,"a") == 0) |
| 2414 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2415 | break; |
| 2416 | } |
| 2417 | case 'B': |
| 2418 | case 'b': |
| 2419 | { |
| 2420 | if (LocaleCompare(expression,"b") == 0) |
| 2421 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2422 | break; |
| 2423 | } |
| 2424 | case 'C': |
| 2425 | case 'c': |
| 2426 | { |
| 2427 | if (LocaleNCompare(expression,"ceil",4) == 0) |
| 2428 | { |
| 2429 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2430 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2431 | return((double) ceil((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2432 | } |
| 2433 | if (LocaleNCompare(expression,"cosh",4) == 0) |
| 2434 | { |
| 2435 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2436 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2437 | return((double) cosh((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2438 | } |
| 2439 | if (LocaleNCompare(expression,"cos",3) == 0) |
| 2440 | { |
| 2441 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2442 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2443 | return((double) cos((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2444 | } |
| 2445 | if (LocaleCompare(expression,"c") == 0) |
| 2446 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2447 | break; |
| 2448 | } |
| 2449 | case 'D': |
| 2450 | case 'd': |
| 2451 | { |
| 2452 | if (LocaleNCompare(expression,"debug",5) == 0) |
| 2453 | { |
| 2454 | const char |
| 2455 | *type; |
| 2456 | |
| 2457 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2458 | exception); |
| 2459 | if (fx_info->images->colorspace == CMYKColorspace) |
| 2460 | switch (channel) |
| 2461 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2462 | case CyanPixelChannel: type="cyan"; break; |
| 2463 | case MagentaPixelChannel: type="magenta"; break; |
| 2464 | case YellowPixelChannel: type="yellow"; break; |
| 2465 | case AlphaPixelChannel: type="opacity"; break; |
| 2466 | case BlackPixelChannel: type="black"; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2467 | default: type="unknown"; break; |
| 2468 | } |
| 2469 | else |
| 2470 | switch (channel) |
| 2471 | { |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2472 | case RedPixelChannel: type="red"; break; |
| 2473 | case GreenPixelChannel: type="green"; break; |
| 2474 | case BluePixelChannel: type="blue"; break; |
| 2475 | case AlphaPixelChannel: type="opacity"; break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2476 | default: type="unknown"; break; |
| 2477 | } |
| 2478 | (void) CopyMagickString(subexpression,expression+6,MaxTextExtent); |
| 2479 | if (strlen(subexpression) > 1) |
| 2480 | subexpression[strlen(subexpression)-1]='\0'; |
| 2481 | if (fx_info->file != (FILE *) NULL) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2482 | (void) FormatLocaleFile(fx_info->file,"%s[%.20g,%.20g].%s: " |
| 2483 | "%s=%.*g\n",fx_info->images->filename,(double) x,(double) y,type, |
| 2484 | subexpression,GetMagickPrecision(),(double) alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2485 | return(0.0); |
| 2486 | } |
cristy | 5597a8d | 2011-11-04 00:25:32 +0000 | [diff] [blame] | 2487 | if (LocaleNCompare(expression,"drc",3) == 0) |
| 2488 | { |
| 2489 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2490 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2491 | return((double) (alpha/(*beta*(alpha-1.0)+1.0))); |
cristy | 5597a8d | 2011-11-04 00:25:32 +0000 | [diff] [blame] | 2492 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2493 | break; |
| 2494 | } |
| 2495 | case 'E': |
| 2496 | case 'e': |
| 2497 | { |
| 2498 | if (LocaleCompare(expression,"epsilon") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2499 | return((double) MagickEpsilon); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2500 | if (LocaleNCompare(expression,"exp",3) == 0) |
| 2501 | { |
| 2502 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2503 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2504 | return((double) exp((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2505 | } |
| 2506 | if (LocaleCompare(expression,"e") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2507 | return((double) 2.7182818284590452354); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2508 | break; |
| 2509 | } |
| 2510 | case 'F': |
| 2511 | case 'f': |
| 2512 | { |
| 2513 | if (LocaleNCompare(expression,"floor",5) == 0) |
| 2514 | { |
| 2515 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2516 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2517 | return((double) floor((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2518 | } |
| 2519 | break; |
| 2520 | } |
| 2521 | case 'G': |
| 2522 | case 'g': |
| 2523 | { |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2524 | if (LocaleNCompare(expression,"gauss",5) == 0) |
| 2525 | { |
| 2526 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2527 | exception); |
| 2528 | gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2529 | return((double) gamma); |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2530 | } |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 2531 | if (LocaleNCompare(expression,"gcd",3) == 0) |
| 2532 | { |
| 2533 | MagickOffsetType |
| 2534 | gcd; |
| 2535 | |
| 2536 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2537 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 2538 | gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+ |
| 2539 | 0.5)); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2540 | return((double) gcd); |
cristy | b0aad4c | 2011-11-02 19:30:35 +0000 | [diff] [blame] | 2541 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2542 | if (LocaleCompare(expression,"g") == 0) |
| 2543 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2544 | break; |
| 2545 | } |
| 2546 | case 'H': |
| 2547 | case 'h': |
| 2548 | { |
| 2549 | if (LocaleCompare(expression,"h") == 0) |
| 2550 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2551 | if (LocaleCompare(expression,"hue") == 0) |
| 2552 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2553 | if (LocaleNCompare(expression,"hypot",5) == 0) |
| 2554 | { |
| 2555 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2556 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2557 | return((double) hypot((double) alpha,(double) *beta)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2558 | } |
| 2559 | break; |
| 2560 | } |
| 2561 | case 'K': |
| 2562 | case 'k': |
| 2563 | { |
| 2564 | if (LocaleCompare(expression,"k") == 0) |
| 2565 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2566 | break; |
| 2567 | } |
| 2568 | case 'I': |
| 2569 | case 'i': |
| 2570 | { |
| 2571 | if (LocaleCompare(expression,"intensity") == 0) |
| 2572 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2573 | if (LocaleNCompare(expression,"int",3) == 0) |
| 2574 | { |
| 2575 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2576 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2577 | return((double) floor(alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2578 | } |
cristy | 82b2072 | 2011-11-05 21:52:36 +0000 | [diff] [blame] | 2579 | #if defined(MAGICKCORE_HAVE_ISNAN) |
cristy | 639399c | 2011-11-02 19:16:15 +0000 | [diff] [blame] | 2580 | if (LocaleNCompare(expression,"isnan",5) == 0) |
| 2581 | { |
| 2582 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2583 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2584 | return((double) !!isnan((double) alpha)); |
cristy | 639399c | 2011-11-02 19:16:15 +0000 | [diff] [blame] | 2585 | } |
cristy | 82b2072 | 2011-11-05 21:52:36 +0000 | [diff] [blame] | 2586 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2587 | if (LocaleCompare(expression,"i") == 0) |
| 2588 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2589 | break; |
| 2590 | } |
| 2591 | case 'J': |
| 2592 | case 'j': |
| 2593 | { |
| 2594 | if (LocaleCompare(expression,"j") == 0) |
| 2595 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2596 | #if defined(MAGICKCORE_HAVE_J0) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2597 | if (LocaleNCompare(expression,"j0",2) == 0) |
| 2598 | { |
| 2599 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2600 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2601 | return((double) j0((double) alpha)); |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2602 | } |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2603 | #endif |
| 2604 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2605 | if (LocaleNCompare(expression,"j1",2) == 0) |
| 2606 | { |
| 2607 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2608 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2609 | return((double) j1((double) alpha)); |
cristy | ee56cf1 | 2010-03-01 22:17:06 +0000 | [diff] [blame] | 2610 | } |
cristy | 161b926 | 2010-03-20 19:34:32 +0000 | [diff] [blame] | 2611 | #endif |
cristy | aa018fa | 2010-04-08 23:03:54 +0000 | [diff] [blame] | 2612 | #if defined(MAGICKCORE_HAVE_J1) |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2613 | if (LocaleNCompare(expression,"jinc",4) == 0) |
| 2614 | { |
| 2615 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2616 | exception); |
cristy | 0946a82 | 2010-03-12 17:14:58 +0000 | [diff] [blame] | 2617 | if (alpha == 0.0) |
| 2618 | return(1.0); |
cristy | c90d70d | 2012-11-03 23:53:13 +0000 | [diff] [blame] | 2619 | gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha)); |
cristy | fce2f7b | 2010-03-12 00:29:49 +0000 | [diff] [blame] | 2620 | return(gamma); |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2621 | } |
cristy | aa018fa | 2010-04-08 23:03:54 +0000 | [diff] [blame] | 2622 | #endif |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2623 | break; |
| 2624 | } |
| 2625 | case 'L': |
| 2626 | case 'l': |
| 2627 | { |
| 2628 | if (LocaleNCompare(expression,"ln",2) == 0) |
| 2629 | { |
| 2630 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta, |
| 2631 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2632 | return((double) log((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2633 | } |
cristy | c8ed532 | 2010-08-31 12:07:59 +0000 | [diff] [blame] | 2634 | if (LocaleNCompare(expression,"logtwo",6) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2635 | { |
cristy | c8ed532 | 2010-08-31 12:07:59 +0000 | [diff] [blame] | 2636 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2637 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2638 | return((double) log10((double) alpha))/log10(2.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2639 | } |
| 2640 | if (LocaleNCompare(expression,"log",3) == 0) |
| 2641 | { |
| 2642 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2643 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2644 | return((double) log10((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2645 | } |
| 2646 | if (LocaleCompare(expression,"lightness") == 0) |
| 2647 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2648 | break; |
| 2649 | } |
| 2650 | case 'M': |
| 2651 | case 'm': |
| 2652 | { |
| 2653 | if (LocaleCompare(expression,"MaxRGB") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2654 | return((double) QuantumRange); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2655 | if (LocaleNCompare(expression,"maxima",6) == 0) |
| 2656 | break; |
| 2657 | if (LocaleNCompare(expression,"max",3) == 0) |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2658 | { |
| 2659 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2660 | exception); |
| 2661 | return(alpha > *beta ? alpha : *beta); |
| 2662 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2663 | if (LocaleNCompare(expression,"minima",6) == 0) |
| 2664 | break; |
| 2665 | if (LocaleNCompare(expression,"min",3) == 0) |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2666 | { |
| 2667 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2668 | exception); |
| 2669 | return(alpha < *beta ? alpha : *beta); |
| 2670 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2671 | if (LocaleNCompare(expression,"mod",3) == 0) |
| 2672 | { |
| 2673 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2674 | exception); |
cristy | 984049c | 2011-11-03 18:34:58 +0000 | [diff] [blame] | 2675 | gamma=alpha-floor((double) (alpha/(*beta)))*(*beta); |
| 2676 | return(gamma); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2677 | } |
| 2678 | if (LocaleCompare(expression,"m") == 0) |
| 2679 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2680 | break; |
| 2681 | } |
| 2682 | case 'N': |
| 2683 | case 'n': |
| 2684 | { |
cristy | ad3502e | 2011-11-02 19:10:45 +0000 | [diff] [blame] | 2685 | if (LocaleNCompare(expression,"not",3) == 0) |
| 2686 | { |
| 2687 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2688 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2689 | return((double) (alpha < MagickEpsilon)); |
cristy | ad3502e | 2011-11-02 19:10:45 +0000 | [diff] [blame] | 2690 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2691 | if (LocaleCompare(expression,"n") == 0) |
| 2692 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2693 | break; |
| 2694 | } |
| 2695 | case 'O': |
| 2696 | case 'o': |
| 2697 | { |
| 2698 | if (LocaleCompare(expression,"Opaque") == 0) |
| 2699 | return(1.0); |
| 2700 | if (LocaleCompare(expression,"o") == 0) |
| 2701 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2702 | break; |
| 2703 | } |
| 2704 | case 'P': |
| 2705 | case 'p': |
| 2706 | { |
cristy | 670aa3c | 2011-11-03 00:54:00 +0000 | [diff] [blame] | 2707 | if (LocaleCompare(expression,"phi") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2708 | return((double) MagickPHI); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2709 | if (LocaleCompare(expression,"pi") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2710 | return((double) MagickPI); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2711 | if (LocaleNCompare(expression,"pow",3) == 0) |
| 2712 | { |
| 2713 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2714 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2715 | return((double) pow((double) alpha,(double) *beta)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2716 | } |
| 2717 | if (LocaleCompare(expression,"p") == 0) |
| 2718 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2719 | break; |
| 2720 | } |
| 2721 | case 'Q': |
| 2722 | case 'q': |
| 2723 | { |
| 2724 | if (LocaleCompare(expression,"QuantumRange") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2725 | return((double) QuantumRange); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2726 | if (LocaleCompare(expression,"QuantumScale") == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2727 | return((double) QuantumScale); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2728 | break; |
| 2729 | } |
| 2730 | case 'R': |
| 2731 | case 'r': |
| 2732 | { |
| 2733 | if (LocaleNCompare(expression,"rand",4) == 0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2734 | return((double) GetPseudoRandomValue(fx_info->random_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2735 | if (LocaleNCompare(expression,"round",5) == 0) |
| 2736 | { |
| 2737 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2738 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2739 | return((double) floor((double) alpha+0.5)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2740 | } |
| 2741 | if (LocaleCompare(expression,"r") == 0) |
| 2742 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2743 | break; |
| 2744 | } |
| 2745 | case 'S': |
| 2746 | case 's': |
| 2747 | { |
| 2748 | if (LocaleCompare(expression,"saturation") == 0) |
| 2749 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2750 | if (LocaleNCompare(expression,"sign",4) == 0) |
| 2751 | { |
| 2752 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2753 | exception); |
| 2754 | return(alpha < 0.0 ? -1.0 : 1.0); |
| 2755 | } |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2756 | if (LocaleNCompare(expression,"sinc",4) == 0) |
| 2757 | { |
| 2758 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2759 | exception); |
| 2760 | if (alpha == 0) |
| 2761 | return(1.0); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2762 | gamma=(double) (sin((double) (MagickPI*alpha))/ |
cristy | a6a09e7 | 2010-03-02 14:51:02 +0000 | [diff] [blame] | 2763 | (MagickPI*alpha)); |
| 2764 | return(gamma); |
| 2765 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2766 | if (LocaleNCompare(expression,"sinh",4) == 0) |
| 2767 | { |
| 2768 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2769 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2770 | return((double) sinh((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2771 | } |
| 2772 | if (LocaleNCompare(expression,"sin",3) == 0) |
| 2773 | { |
| 2774 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2775 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2776 | return((double) sin((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2777 | } |
| 2778 | if (LocaleNCompare(expression,"sqrt",4) == 0) |
| 2779 | { |
| 2780 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2781 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2782 | return((double) sqrt((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2783 | } |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2784 | if (LocaleNCompare(expression,"squish",6) == 0) |
| 2785 | { |
| 2786 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta, |
| 2787 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2788 | return((double) (1.0/(1.0+exp((double) (-alpha))))); |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2789 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2790 | if (LocaleCompare(expression,"s") == 0) |
| 2791 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2792 | break; |
| 2793 | } |
| 2794 | case 'T': |
| 2795 | case 't': |
| 2796 | { |
| 2797 | if (LocaleNCompare(expression,"tanh",4) == 0) |
| 2798 | { |
| 2799 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta, |
| 2800 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2801 | return((double) tanh((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2802 | } |
| 2803 | if (LocaleNCompare(expression,"tan",3) == 0) |
| 2804 | { |
| 2805 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta, |
| 2806 | exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2807 | return((double) tan((double) alpha)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2808 | } |
| 2809 | if (LocaleCompare(expression,"Transparent") == 0) |
| 2810 | return(0.0); |
cristy | 16788e4 | 2010-08-13 13:44:26 +0000 | [diff] [blame] | 2811 | if (LocaleNCompare(expression,"trunc",5) == 0) |
| 2812 | { |
| 2813 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2814 | exception); |
| 2815 | if (alpha >= 0.0) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2816 | return((double) floor((double) alpha)); |
| 2817 | return((double) ceil((double) alpha)); |
cristy | 16788e4 | 2010-08-13 13:44:26 +0000 | [diff] [blame] | 2818 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2819 | if (LocaleCompare(expression,"t") == 0) |
| 2820 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2821 | break; |
| 2822 | } |
| 2823 | case 'U': |
| 2824 | case 'u': |
| 2825 | { |
| 2826 | if (LocaleCompare(expression,"u") == 0) |
| 2827 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2828 | break; |
| 2829 | } |
| 2830 | case 'V': |
| 2831 | case 'v': |
| 2832 | { |
| 2833 | if (LocaleCompare(expression,"v") == 0) |
| 2834 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2835 | break; |
| 2836 | } |
| 2837 | case 'W': |
| 2838 | case 'w': |
| 2839 | { |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2840 | if (LocaleNCompare(expression,"while",5) == 0) |
| 2841 | { |
| 2842 | do |
| 2843 | { |
| 2844 | alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta, |
| 2845 | exception); |
| 2846 | } while (fabs((double) alpha) >= MagickEpsilon); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2847 | return((double) *beta); |
cristy | 9eeedea | 2011-11-02 19:04:05 +0000 | [diff] [blame] | 2848 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2849 | if (LocaleCompare(expression,"w") == 0) |
| 2850 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2851 | break; |
| 2852 | } |
| 2853 | case 'Y': |
| 2854 | case 'y': |
| 2855 | { |
| 2856 | if (LocaleCompare(expression,"y") == 0) |
| 2857 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2858 | break; |
| 2859 | } |
| 2860 | case 'Z': |
| 2861 | case 'z': |
| 2862 | { |
| 2863 | if (LocaleCompare(expression,"z") == 0) |
| 2864 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2865 | break; |
| 2866 | } |
| 2867 | default: |
| 2868 | break; |
| 2869 | } |
| 2870 | q=(char *) expression; |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2871 | alpha=InterpretSiPrefixValue(expression,&q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2872 | if (q == expression) |
| 2873 | return(FxGetSymbol(fx_info,channel,x,y,expression,exception)); |
| 2874 | return(alpha); |
| 2875 | } |
| 2876 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 2877 | MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2878 | double *alpha,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2879 | { |
| 2880 | MagickBooleanType |
| 2881 | status; |
| 2882 | |
cristy | 541ae57 | 2011-08-05 19:08:59 +0000 | [diff] [blame] | 2883 | status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha, |
| 2884 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2885 | return(status); |
| 2886 | } |
| 2887 | |
| 2888 | MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2889 | double *alpha,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2890 | { |
| 2891 | FILE |
| 2892 | *file; |
| 2893 | |
| 2894 | MagickBooleanType |
| 2895 | status; |
| 2896 | |
| 2897 | file=fx_info->file; |
| 2898 | fx_info->file=(FILE *) NULL; |
cristy | 541ae57 | 2011-08-05 19:08:59 +0000 | [diff] [blame] | 2899 | status=FxEvaluateChannelExpression(fx_info,GrayPixelChannel,0,0,alpha, |
| 2900 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2901 | fx_info->file=file; |
| 2902 | return(status); |
| 2903 | } |
| 2904 | |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 2905 | MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info, |
cristy | 0568ffc | 2011-07-25 16:54:14 +0000 | [diff] [blame] | 2906 | const PixelChannel channel,const ssize_t x,const ssize_t y, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2907 | double *alpha,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2908 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2909 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2910 | beta; |
| 2911 | |
| 2912 | beta=0.0; |
| 2913 | *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta, |
| 2914 | exception); |
| 2915 | return(exception->severity == OptionError ? MagickFalse : MagickTrue); |
| 2916 | } |
| 2917 | |
| 2918 | /* |
| 2919 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2920 | % % |
| 2921 | % % |
| 2922 | % % |
| 2923 | % F x I m a g e % |
| 2924 | % % |
| 2925 | % % |
| 2926 | % % |
| 2927 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2928 | % |
| 2929 | % FxImage() applies a mathematical expression to the specified image. |
| 2930 | % |
| 2931 | % The format of the FxImage method is: |
| 2932 | % |
| 2933 | % Image *FxImage(const Image *image,const char *expression, |
| 2934 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2935 | % |
| 2936 | % A description of each parameter follows: |
| 2937 | % |
| 2938 | % o image: the image. |
| 2939 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2940 | % o expression: A mathematical expression. |
| 2941 | % |
| 2942 | % o exception: return any errors or warnings in this structure. |
| 2943 | % |
| 2944 | */ |
| 2945 | |
| 2946 | static FxInfo **DestroyFxThreadSet(FxInfo **fx_info) |
| 2947 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2948 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2949 | i; |
| 2950 | |
| 2951 | assert(fx_info != (FxInfo **) NULL); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 2952 | for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2953 | if (fx_info[i] != (FxInfo *) NULL) |
| 2954 | fx_info[i]=DestroyFxInfo(fx_info[i]); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 2955 | fx_info=(FxInfo **) RelinquishMagickMemory(fx_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2956 | return(fx_info); |
| 2957 | } |
| 2958 | |
| 2959 | static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression, |
| 2960 | ExceptionInfo *exception) |
| 2961 | { |
| 2962 | char |
| 2963 | *fx_expression; |
| 2964 | |
| 2965 | FxInfo |
| 2966 | **fx_info; |
| 2967 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2968 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2969 | alpha; |
| 2970 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2971 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2972 | i; |
| 2973 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2974 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2975 | number_threads; |
| 2976 | |
cristy | 9357bdd | 2012-07-30 12:28:34 +0000 | [diff] [blame] | 2977 | number_threads=(size_t) GetMagickResourceLimit(ThreadResource); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 2978 | fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2979 | if (fx_info == (FxInfo **) NULL) |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 2980 | { |
| 2981 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 2982 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
| 2983 | return((FxInfo **) NULL); |
| 2984 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2985 | (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info)); |
| 2986 | if (*expression != '@') |
| 2987 | fx_expression=ConstantString(expression); |
| 2988 | else |
cristy | 3a5987c | 2013-11-07 14:18:46 +0000 | [diff] [blame] | 2989 | fx_expression=FileToString(expression+1,~0UL,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2990 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2991 | { |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 2992 | MagickBooleanType |
| 2993 | status; |
| 2994 | |
cristy | db07095 | 2012-04-20 14:33:00 +0000 | [diff] [blame] | 2995 | fx_info[i]=AcquireFxInfo(image,fx_expression,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2996 | if (fx_info[i] == (FxInfo *) NULL) |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 2997 | break; |
| 2998 | status=FxPreprocessExpression(fx_info[i],&alpha,exception); |
| 2999 | if (status == MagickFalse) |
| 3000 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3001 | } |
| 3002 | fx_expression=DestroyString(fx_expression); |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3003 | if (i < (ssize_t) number_threads) |
| 3004 | fx_info=DestroyFxThreadSet(fx_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3005 | return(fx_info); |
| 3006 | } |
| 3007 | |
| 3008 | MagickExport Image *FxImage(const Image *image,const char *expression, |
| 3009 | ExceptionInfo *exception) |
| 3010 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3011 | #define FxImageTag "Fx/Image" |
| 3012 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3013 | CacheView |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3014 | *fx_view, |
| 3015 | *image_view; |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3016 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3017 | FxInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3018 | **restrict fx_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3019 | |
| 3020 | Image |
| 3021 | *fx_image; |
| 3022 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3023 | MagickBooleanType |
| 3024 | status; |
| 3025 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3026 | MagickOffsetType |
| 3027 | progress; |
| 3028 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3029 | ssize_t |
| 3030 | y; |
| 3031 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3032 | assert(image != (Image *) NULL); |
| 3033 | assert(image->signature == MagickSignature); |
| 3034 | if (image->debug != MagickFalse) |
| 3035 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3036 | fx_info=AcquireFxThreadSet(image,expression,exception); |
| 3037 | if (fx_info == (FxInfo **) NULL) |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3038 | return((Image *) NULL); |
| 3039 | fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
| 3040 | if (fx_image == (Image *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3041 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3042 | fx_info=DestroyFxThreadSet(fx_info); |
| 3043 | return((Image *) NULL); |
| 3044 | } |
cristy | 65d161b | 2012-10-07 20:39:52 +0000 | [diff] [blame] | 3045 | if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse) |
| 3046 | { |
| 3047 | fx_info=DestroyFxThreadSet(fx_info); |
| 3048 | fx_image=DestroyImage(fx_image); |
| 3049 | return((Image *) NULL); |
| 3050 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3051 | /* |
| 3052 | Fx image. |
| 3053 | */ |
| 3054 | status=MagickTrue; |
| 3055 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3056 | image_view=AcquireVirtualCacheView(image,exception); |
| 3057 | fx_view=AcquireAuthenticCacheView(fx_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3058 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3059 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 3060 | magick_threads(image,fx_image,fx_image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3061 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3062 | for (y=0; y < (ssize_t) fx_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3063 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3064 | const int |
| 3065 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3066 | |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3067 | register const Quantum |
| 3068 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3069 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3070 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3071 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3072 | |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3073 | register ssize_t |
| 3074 | x; |
| 3075 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3076 | if (status == MagickFalse) |
| 3077 | continue; |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3078 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3079 | q=QueueCacheViewAuthenticPixels(fx_view,0,y,fx_image->columns,1,exception); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3080 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3081 | { |
| 3082 | status=MagickFalse; |
| 3083 | continue; |
| 3084 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3085 | for (x=0; x < (ssize_t) fx_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3086 | { |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3087 | register ssize_t |
| 3088 | i; |
| 3089 | |
| 3090 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3091 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3092 | double |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3093 | alpha; |
| 3094 | |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3095 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3096 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 3097 | PixelTrait fx_traits=GetPixelChannelTraits(fx_image,channel); |
cristy | 010d7d1 | 2011-08-31 01:02:48 +0000 | [diff] [blame] | 3098 | if ((traits == UndefinedPixelTrait) || |
| 3099 | (fx_traits == UndefinedPixelTrait)) |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3100 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 3101 | if (((fx_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 3102 | (GetPixelReadMask(image,p) == 0)) |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3103 | { |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 3104 | SetPixelChannel(fx_image,channel,p[i],q); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3105 | continue; |
| 3106 | } |
| 3107 | alpha=0.0; |
cristy | a382aca | 2011-12-06 18:22:48 +0000 | [diff] [blame] | 3108 | (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha, |
| 3109 | exception); |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 3110 | q[i]=ClampToQuantum(QuantumRange*alpha); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3111 | } |
| 3112 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3113 | q+=GetPixelChannels(fx_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3114 | } |
| 3115 | if (SyncCacheViewAuthenticPixels(fx_view,exception) == MagickFalse) |
| 3116 | status=MagickFalse; |
| 3117 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3118 | { |
| 3119 | MagickBooleanType |
| 3120 | proceed; |
| 3121 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3122 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3123 | #pragma omp critical (MagickCore_FxImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3124 | #endif |
| 3125 | proceed=SetImageProgress(image,FxImageTag,progress++,image->rows); |
| 3126 | if (proceed == MagickFalse) |
| 3127 | status=MagickFalse; |
| 3128 | } |
| 3129 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3130 | fx_view=DestroyCacheView(fx_view); |
cristy | 79cedc7 | 2011-07-25 00:41:15 +0000 | [diff] [blame] | 3131 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3132 | fx_info=DestroyFxThreadSet(fx_info); |
| 3133 | if (status == MagickFalse) |
| 3134 | fx_image=DestroyImage(fx_image); |
| 3135 | return(fx_image); |
| 3136 | } |
| 3137 | |
| 3138 | /* |
| 3139 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3140 | % % |
| 3141 | % % |
| 3142 | % % |
| 3143 | % I m p l o d e I m a g e % |
| 3144 | % % |
| 3145 | % % |
| 3146 | % % |
| 3147 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3148 | % |
| 3149 | % ImplodeImage() creates a new image that is a copy of an existing |
| 3150 | % one with the image pixels "implode" by the specified percentage. It |
| 3151 | % allocates the memory necessary for the new Image structure and returns a |
| 3152 | % pointer to the new image. |
| 3153 | % |
| 3154 | % The format of the ImplodeImage method is: |
| 3155 | % |
| 3156 | % Image *ImplodeImage(const Image *image,const double amount, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3157 | % const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3158 | % |
| 3159 | % A description of each parameter follows: |
| 3160 | % |
| 3161 | % o implode_image: Method ImplodeImage returns a pointer to the image |
| 3162 | % after it is implode. A null image is returned if there is a memory |
| 3163 | % shortage. |
| 3164 | % |
| 3165 | % o image: the image. |
| 3166 | % |
| 3167 | % o amount: Define the extent of the implosion. |
| 3168 | % |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3169 | % o method: the pixel interpolation method. |
| 3170 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3171 | % o exception: return any errors or warnings in this structure. |
| 3172 | % |
| 3173 | */ |
| 3174 | MagickExport Image *ImplodeImage(const Image *image,const double amount, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3175 | const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3176 | { |
| 3177 | #define ImplodeImageTag "Implode/Image" |
| 3178 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3179 | CacheView |
| 3180 | *image_view, |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3181 | *implode_view, |
| 3182 | *interpolate_view; |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3183 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3184 | Image |
| 3185 | *implode_image; |
| 3186 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3187 | MagickBooleanType |
| 3188 | status; |
| 3189 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3190 | MagickOffsetType |
| 3191 | progress; |
| 3192 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3193 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3194 | radius; |
| 3195 | |
| 3196 | PointInfo |
| 3197 | center, |
| 3198 | scale; |
| 3199 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3200 | ssize_t |
| 3201 | y; |
| 3202 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3203 | /* |
| 3204 | Initialize implode image attributes. |
| 3205 | */ |
| 3206 | assert(image != (Image *) NULL); |
| 3207 | assert(image->signature == MagickSignature); |
| 3208 | if (image->debug != MagickFalse) |
| 3209 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3210 | assert(exception != (ExceptionInfo *) NULL); |
| 3211 | assert(exception->signature == MagickSignature); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 3212 | implode_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
| 3213 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3214 | if (implode_image == (Image *) NULL) |
| 3215 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 3216 | if (SetImageStorageClass(implode_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3217 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3218 | implode_image=DestroyImage(implode_image); |
| 3219 | return((Image *) NULL); |
| 3220 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3221 | if (implode_image->background_color.alpha != OpaqueAlpha) |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3222 | implode_image->alpha_trait=BlendPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3223 | /* |
| 3224 | Compute scaling factor. |
| 3225 | */ |
| 3226 | scale.x=1.0; |
| 3227 | scale.y=1.0; |
| 3228 | center.x=0.5*image->columns; |
| 3229 | center.y=0.5*image->rows; |
| 3230 | radius=center.x; |
| 3231 | if (image->columns > image->rows) |
| 3232 | scale.y=(double) image->columns/(double) image->rows; |
| 3233 | else |
| 3234 | if (image->columns < image->rows) |
| 3235 | { |
| 3236 | scale.x=(double) image->rows/(double) image->columns; |
| 3237 | radius=center.y; |
| 3238 | } |
| 3239 | /* |
| 3240 | Implode image. |
| 3241 | */ |
| 3242 | status=MagickTrue; |
| 3243 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3244 | image_view=AcquireVirtualCacheView(image,exception); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3245 | interpolate_view=AcquireVirtualCacheView(image,exception); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3246 | implode_view=AcquireAuthenticCacheView(implode_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3247 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3248 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 3249 | magick_threads(image,implode_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3250 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3251 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3252 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3253 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3254 | distance; |
| 3255 | |
| 3256 | PointInfo |
| 3257 | delta; |
| 3258 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3259 | register const Quantum |
| 3260 | *restrict p; |
| 3261 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3262 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3263 | x; |
| 3264 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3265 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3266 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3267 | |
| 3268 | if (status == MagickFalse) |
| 3269 | continue; |
cristy | 1665ce1 | 2013-04-19 12:18:43 +0000 | [diff] [blame] | 3270 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3271 | q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3272 | exception); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3273 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3274 | { |
| 3275 | status=MagickFalse; |
| 3276 | continue; |
| 3277 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3278 | delta.y=scale.y*(double) (y-center.y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3279 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3280 | { |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3281 | register ssize_t |
| 3282 | i; |
| 3283 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3284 | /* |
| 3285 | Determine if the pixel is within an ellipse. |
| 3286 | */ |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 3287 | if (GetPixelReadMask(image,p) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 3288 | { |
cristy | c3a5802 | 2013-10-09 23:22:42 +0000 | [diff] [blame] | 3289 | SetPixelBackgoundColor(implode_image,q); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 3290 | p+=GetPixelChannels(image); |
| 3291 | q+=GetPixelChannels(implode_image); |
| 3292 | continue; |
| 3293 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3294 | delta.x=scale.x*(double) (x-center.x); |
| 3295 | distance=delta.x*delta.x+delta.y*delta.y; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3296 | if (distance >= (radius*radius)) |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3297 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3298 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3299 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3300 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 3301 | PixelTrait implode_traits=GetPixelChannelTraits(implode_image, |
| 3302 | channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3303 | if ((traits == UndefinedPixelTrait) || |
| 3304 | (implode_traits == UndefinedPixelTrait)) |
| 3305 | continue; |
cristy | a6d7a9b | 2012-01-18 20:04:48 +0000 | [diff] [blame] | 3306 | SetPixelChannel(implode_image,channel,p[i],q); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3307 | } |
| 3308 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3309 | { |
| 3310 | double |
| 3311 | factor; |
| 3312 | |
| 3313 | /* |
| 3314 | Implode the pixel. |
| 3315 | */ |
| 3316 | factor=1.0; |
| 3317 | if (distance > 0.0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3318 | factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/ |
| 3319 | 2)),-amount); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3320 | status=InterpolatePixelChannels(image,interpolate_view,implode_image, |
| 3321 | method,(double) (factor*delta.x/scale.x+center.x),(double) (factor* |
| 3322 | delta.y/scale.y+center.y),q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3323 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 3324 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3325 | q+=GetPixelChannels(implode_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3326 | } |
| 3327 | if (SyncCacheViewAuthenticPixels(implode_view,exception) == MagickFalse) |
| 3328 | status=MagickFalse; |
| 3329 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3330 | { |
| 3331 | MagickBooleanType |
| 3332 | proceed; |
| 3333 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3334 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3335 | #pragma omp critical (MagickCore_ImplodeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3336 | #endif |
| 3337 | proceed=SetImageProgress(image,ImplodeImageTag,progress++,image->rows); |
| 3338 | if (proceed == MagickFalse) |
| 3339 | status=MagickFalse; |
| 3340 | } |
| 3341 | } |
| 3342 | implode_view=DestroyCacheView(implode_view); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 3343 | interpolate_view=DestroyCacheView(interpolate_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3344 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3345 | if (status == MagickFalse) |
| 3346 | implode_image=DestroyImage(implode_image); |
| 3347 | return(implode_image); |
| 3348 | } |
| 3349 | |
| 3350 | /* |
| 3351 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3352 | % % |
| 3353 | % % |
| 3354 | % % |
| 3355 | % M o r p h I m a g e s % |
| 3356 | % % |
| 3357 | % % |
| 3358 | % % |
| 3359 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3360 | % |
| 3361 | % The MorphImages() method requires a minimum of two images. The first |
| 3362 | % image is transformed into the second by a number of intervening images |
| 3363 | % as specified by frames. |
| 3364 | % |
| 3365 | % The format of the MorphImage method is: |
| 3366 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3367 | % Image *MorphImages(const Image *image,const size_t number_frames, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3368 | % ExceptionInfo *exception) |
| 3369 | % |
| 3370 | % A description of each parameter follows: |
| 3371 | % |
| 3372 | % o image: the image. |
| 3373 | % |
| 3374 | % o number_frames: Define the number of in-between image to generate. |
| 3375 | % The more in-between frames, the smoother the morph. |
| 3376 | % |
| 3377 | % o exception: return any errors or warnings in this structure. |
| 3378 | % |
| 3379 | */ |
cristy | 7de7f74 | 2012-12-14 00:28:27 +0000 | [diff] [blame] | 3380 | MagickExport Image *MorphImages(const Image *image,const size_t number_frames, |
| 3381 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3382 | { |
| 3383 | #define MorphImageTag "Morph/Image" |
| 3384 | |
cristy | fab8364 | 2012-12-14 00:31:38 +0000 | [diff] [blame] | 3385 | double |
| 3386 | alpha, |
| 3387 | beta; |
| 3388 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3389 | Image |
| 3390 | *morph_image, |
| 3391 | *morph_images; |
| 3392 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3393 | MagickBooleanType |
| 3394 | status; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3395 | |
| 3396 | MagickOffsetType |
| 3397 | scene; |
| 3398 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3399 | register const Image |
| 3400 | *next; |
| 3401 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3402 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3403 | i; |
| 3404 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3405 | ssize_t |
| 3406 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3407 | |
| 3408 | /* |
| 3409 | Clone first frame in sequence. |
| 3410 | */ |
| 3411 | assert(image != (Image *) NULL); |
| 3412 | assert(image->signature == MagickSignature); |
| 3413 | if (image->debug != MagickFalse) |
| 3414 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3415 | assert(exception != (ExceptionInfo *) NULL); |
| 3416 | assert(exception->signature == MagickSignature); |
| 3417 | morph_images=CloneImage(image,0,0,MagickTrue,exception); |
| 3418 | if (morph_images == (Image *) NULL) |
| 3419 | return((Image *) NULL); |
| 3420 | if (GetNextImageInList(image) == (Image *) NULL) |
| 3421 | { |
| 3422 | /* |
| 3423 | Morph single image. |
| 3424 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3425 | for (i=1; i < (ssize_t) number_frames; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3426 | { |
| 3427 | morph_image=CloneImage(image,0,0,MagickTrue,exception); |
| 3428 | if (morph_image == (Image *) NULL) |
| 3429 | { |
| 3430 | morph_images=DestroyImageList(morph_images); |
| 3431 | return((Image *) NULL); |
| 3432 | } |
| 3433 | AppendImageToList(&morph_images,morph_image); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3434 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3435 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3436 | MagickBooleanType |
| 3437 | proceed; |
| 3438 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3439 | proceed=SetImageProgress(image,MorphImageTag,(MagickOffsetType) i, |
| 3440 | number_frames); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 3441 | if (proceed == MagickFalse) |
| 3442 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3443 | } |
| 3444 | } |
| 3445 | return(GetFirstImageInList(morph_images)); |
| 3446 | } |
| 3447 | /* |
| 3448 | Morph image sequence. |
| 3449 | */ |
| 3450 | status=MagickTrue; |
| 3451 | scene=0; |
| 3452 | next=image; |
| 3453 | for ( ; GetNextImageInList(next) != (Image *) NULL; next=GetNextImageInList(next)) |
| 3454 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3455 | for (i=0; i < (ssize_t) number_frames; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3456 | { |
| 3457 | CacheView |
| 3458 | *image_view, |
| 3459 | *morph_view; |
| 3460 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3461 | beta=(double) (i+1.0)/(double) (number_frames+1.0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3462 | alpha=1.0-beta; |
cristy | 15b98cd | 2010-09-12 19:42:50 +0000 | [diff] [blame] | 3463 | morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta* |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 3464 | GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta* |
| 3465 | GetNextImageInList(next)->rows+0.5),next->filter,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3466 | if (morph_image == (Image *) NULL) |
| 3467 | { |
| 3468 | morph_images=DestroyImageList(morph_images); |
| 3469 | return((Image *) NULL); |
| 3470 | } |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3471 | status=SetImageStorageClass(morph_image,DirectClass,exception); |
| 3472 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3473 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3474 | morph_image=DestroyImage(morph_image); |
| 3475 | return((Image *) NULL); |
| 3476 | } |
| 3477 | AppendImageToList(&morph_images,morph_image); |
| 3478 | morph_images=GetLastImageInList(morph_images); |
cristy | 15b98cd | 2010-09-12 19:42:50 +0000 | [diff] [blame] | 3479 | morph_image=ResizeImage(GetNextImageInList(next),morph_images->columns, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 3480 | morph_images->rows,GetNextImageInList(next)->filter,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3481 | if (morph_image == (Image *) NULL) |
| 3482 | { |
| 3483 | morph_images=DestroyImageList(morph_images); |
| 3484 | return((Image *) NULL); |
| 3485 | } |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3486 | image_view=AcquireVirtualCacheView(morph_image,exception); |
| 3487 | morph_view=AcquireAuthenticCacheView(morph_images,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3488 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3489 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 3490 | magick_threads(morph_image,morph_image,morph_image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3491 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3492 | for (y=0; y < (ssize_t) morph_images->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3493 | { |
| 3494 | MagickBooleanType |
| 3495 | sync; |
| 3496 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3497 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3498 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3499 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3500 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3501 | x; |
| 3502 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3503 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3504 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3505 | |
| 3506 | if (status == MagickFalse) |
| 3507 | continue; |
| 3508 | p=GetCacheViewVirtualPixels(image_view,0,y,morph_image->columns,1, |
| 3509 | exception); |
| 3510 | q=GetCacheViewAuthenticPixels(morph_view,0,y,morph_images->columns,1, |
| 3511 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3512 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3513 | { |
| 3514 | status=MagickFalse; |
| 3515 | continue; |
| 3516 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3517 | for (x=0; x < (ssize_t) morph_images->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3518 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3519 | register ssize_t |
| 3520 | i; |
| 3521 | |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 3522 | for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3523 | { |
cristy | 031a246 | 2013-05-24 13:29:27 +0000 | [diff] [blame] | 3524 | PixelChannel channel=GetPixelChannelChannel(morph_image,i); |
| 3525 | PixelTrait traits=GetPixelChannelTraits(morph_image,channel); |
| 3526 | PixelTrait morph_traits=GetPixelChannelTraits(morph_images,channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3527 | if ((traits == UndefinedPixelTrait) || |
| 3528 | (morph_traits == UndefinedPixelTrait)) |
| 3529 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 3530 | if (((morph_traits & CopyPixelTrait) != 0) || |
cristy | 031a246 | 2013-05-24 13:29:27 +0000 | [diff] [blame] | 3531 | (GetPixelReadMask(morph_images,p) == 0)) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3532 | { |
| 3533 | SetPixelChannel(morph_image,channel,p[i],q); |
| 3534 | continue; |
| 3535 | } |
| 3536 | SetPixelChannel(morph_image,channel,ClampToQuantum(alpha* |
| 3537 | GetPixelChannel(morph_images,channel,q)+beta*p[i]),q); |
| 3538 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3539 | p+=GetPixelChannels(morph_image); |
| 3540 | q+=GetPixelChannels(morph_images); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3541 | } |
| 3542 | sync=SyncCacheViewAuthenticPixels(morph_view,exception); |
| 3543 | if (sync == MagickFalse) |
| 3544 | status=MagickFalse; |
| 3545 | } |
| 3546 | morph_view=DestroyCacheView(morph_view); |
| 3547 | image_view=DestroyCacheView(image_view); |
| 3548 | morph_image=DestroyImage(morph_image); |
| 3549 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3550 | if (i < (ssize_t) number_frames) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3551 | break; |
| 3552 | /* |
| 3553 | Clone last frame in sequence. |
| 3554 | */ |
| 3555 | morph_image=CloneImage(GetNextImageInList(next),0,0,MagickTrue,exception); |
| 3556 | if (morph_image == (Image *) NULL) |
| 3557 | { |
| 3558 | morph_images=DestroyImageList(morph_images); |
| 3559 | return((Image *) NULL); |
| 3560 | } |
| 3561 | AppendImageToList(&morph_images,morph_image); |
| 3562 | morph_images=GetLastImageInList(morph_images); |
| 3563 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 3564 | { |
| 3565 | MagickBooleanType |
| 3566 | proceed; |
| 3567 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3568 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 3569 | #pragma omp critical (MagickCore_MorphImages) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3570 | #endif |
| 3571 | proceed=SetImageProgress(image,MorphImageTag,scene, |
| 3572 | GetImageListLength(image)); |
| 3573 | if (proceed == MagickFalse) |
| 3574 | status=MagickFalse; |
| 3575 | } |
| 3576 | scene++; |
| 3577 | } |
| 3578 | if (GetNextImageInList(next) != (Image *) NULL) |
| 3579 | { |
| 3580 | morph_images=DestroyImageList(morph_images); |
| 3581 | return((Image *) NULL); |
| 3582 | } |
| 3583 | return(GetFirstImageInList(morph_images)); |
| 3584 | } |
| 3585 | |
| 3586 | /* |
| 3587 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3588 | % % |
| 3589 | % % |
| 3590 | % % |
| 3591 | % P l a s m a I m a g e % |
| 3592 | % % |
| 3593 | % % |
| 3594 | % % |
| 3595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3596 | % |
| 3597 | % PlasmaImage() initializes an image with plasma fractal values. The image |
| 3598 | % must be initialized with a base color and the random number generator |
| 3599 | % seeded before this method is called. |
| 3600 | % |
| 3601 | % The format of the PlasmaImage method is: |
| 3602 | % |
| 3603 | % MagickBooleanType PlasmaImage(Image *image,const SegmentInfo *segment, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3604 | % size_t attenuate,size_t depth,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3605 | % |
| 3606 | % A description of each parameter follows: |
| 3607 | % |
| 3608 | % o image: the image. |
| 3609 | % |
| 3610 | % o segment: Define the region to apply plasma fractals values. |
| 3611 | % |
glennrp | 7dae1ca | 2010-09-16 12:17:35 +0000 | [diff] [blame] | 3612 | % o attenuate: Define the plasma attenuation factor. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3613 | % |
| 3614 | % o depth: Limit the plasma recursion depth. |
| 3615 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3616 | % o exception: return any errors or warnings in this structure. |
| 3617 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3618 | */ |
| 3619 | |
| 3620 | static inline Quantum PlasmaPixel(RandomInfo *random_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3621 | const double pixel,const double noise) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3622 | { |
| 3623 | Quantum |
| 3624 | plasma; |
| 3625 | |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 3626 | plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)- |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3627 | noise/2.0); |
| 3628 | return(plasma); |
| 3629 | } |
| 3630 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3631 | static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view, |
| 3632 | CacheView *u_view,CacheView *v_view,RandomInfo *random_info, |
| 3633 | const SegmentInfo *segment,size_t attenuate,size_t depth, |
| 3634 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3635 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3636 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3637 | plasma; |
| 3638 | |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3639 | register const Quantum |
| 3640 | *restrict u, |
| 3641 | *restrict v; |
| 3642 | |
| 3643 | register Quantum |
| 3644 | *restrict q; |
| 3645 | |
| 3646 | register ssize_t |
| 3647 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3648 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3649 | ssize_t |
| 3650 | x, |
| 3651 | x_mid, |
| 3652 | y, |
| 3653 | y_mid; |
| 3654 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3655 | if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0)) |
| 3656 | return(MagickTrue); |
| 3657 | if (depth != 0) |
| 3658 | { |
| 3659 | SegmentInfo |
| 3660 | local_info; |
| 3661 | |
| 3662 | /* |
| 3663 | Divide the area into quadrants and recurse. |
| 3664 | */ |
| 3665 | depth--; |
| 3666 | attenuate++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3667 | x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5); |
| 3668 | y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3669 | local_info=(*segment); |
| 3670 | local_info.x2=(double) x_mid; |
| 3671 | local_info.y2=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3672 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3673 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3674 | local_info=(*segment); |
| 3675 | local_info.y1=(double) y_mid; |
| 3676 | local_info.x2=(double) x_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3677 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3678 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3679 | local_info=(*segment); |
| 3680 | local_info.x1=(double) x_mid; |
| 3681 | local_info.y2=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3682 | (void) PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3683 | &local_info,attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3684 | local_info=(*segment); |
| 3685 | local_info.x1=(double) x_mid; |
| 3686 | local_info.y1=(double) y_mid; |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3687 | return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info, |
| 3688 | &local_info,attenuate,depth,exception)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3689 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3690 | x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5); |
| 3691 | y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3692 | if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) && |
| 3693 | (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid)) |
| 3694 | return(MagickFalse); |
| 3695 | /* |
| 3696 | Average pixels and apply plasma. |
| 3697 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3698 | plasma=(double) QuantumRange/(2.0*attenuate); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3699 | if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid)) |
| 3700 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3701 | /* |
| 3702 | Left pixel. |
| 3703 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3704 | x=(ssize_t) ceil(segment->x1-0.5); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 3705 | u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5),1,1, |
| 3706 | exception); |
| 3707 | v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5),1,1, |
| 3708 | exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3709 | q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3710 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3711 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3712 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3713 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3714 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3715 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3716 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3717 | if (traits == UndefinedPixelTrait) |
| 3718 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3719 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3720 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3721 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3722 | if (segment->x1 != segment->x2) |
| 3723 | { |
| 3724 | /* |
| 3725 | Right pixel. |
| 3726 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3727 | x=(ssize_t) ceil(segment->x2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3728 | u=GetCacheViewVirtualPixels(u_view,x,(ssize_t) ceil(segment->y1-0.5), |
| 3729 | 1,1,exception); |
| 3730 | v=GetCacheViewVirtualPixels(v_view,x,(ssize_t) ceil(segment->y2-0.5), |
| 3731 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3732 | q=QueueCacheViewAuthenticPixels(image_view,x,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3733 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3734 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3735 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3736 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3737 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3738 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3739 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3740 | if (traits == UndefinedPixelTrait) |
| 3741 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3742 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3743 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3744 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3745 | } |
| 3746 | } |
| 3747 | if ((segment->y1 != (double) y_mid) || (segment->y2 != (double) y_mid)) |
| 3748 | { |
| 3749 | if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid)) |
| 3750 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3751 | /* |
| 3752 | Bottom pixel. |
| 3753 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3754 | y=(ssize_t) ceil(segment->y2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3755 | u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y, |
| 3756 | 1,1,exception); |
| 3757 | v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y, |
| 3758 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3759 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3760 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3761 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3762 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3763 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3764 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3765 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3766 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3767 | if (traits == UndefinedPixelTrait) |
| 3768 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3769 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3770 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3771 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3772 | } |
| 3773 | if (segment->y1 != segment->y2) |
| 3774 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3775 | /* |
| 3776 | Top pixel. |
| 3777 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3778 | y=(ssize_t) ceil(segment->y1-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3779 | u=GetCacheViewVirtualPixels(u_view,(ssize_t) ceil(segment->x1-0.5),y, |
| 3780 | 1,1,exception); |
| 3781 | v=GetCacheViewVirtualPixels(v_view,(ssize_t) ceil(segment->x2-0.5),y, |
| 3782 | 1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3783 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3784 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3785 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3786 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3787 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3788 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3789 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3790 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3791 | if (traits == UndefinedPixelTrait) |
| 3792 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3793 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3794 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3795 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3796 | } |
| 3797 | } |
| 3798 | if ((segment->x1 != segment->x2) || (segment->y1 != segment->y2)) |
| 3799 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3800 | /* |
| 3801 | Middle pixel. |
| 3802 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3803 | x=(ssize_t) ceil(segment->x1-0.5); |
| 3804 | y=(ssize_t) ceil(segment->y1-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3805 | u=GetCacheViewVirtualPixels(u_view,x,y,1,1,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3806 | x=(ssize_t) ceil(segment->x2-0.5); |
| 3807 | y=(ssize_t) ceil(segment->y2-0.5); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3808 | v=GetCacheViewVirtualPixels(v_view,x,y,1,1,exception); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3809 | q=QueueCacheViewAuthenticPixels(image_view,x_mid,y_mid,1,1,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3810 | if ((u == (const Quantum *) NULL) || (v == (const Quantum *) NULL) || |
| 3811 | (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3812 | return(MagickTrue); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3813 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 3814 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 3815 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 3816 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3817 | if (traits == UndefinedPixelTrait) |
| 3818 | continue; |
cristy | 6e56499 | 2013-05-24 01:21:04 +0000 | [diff] [blame] | 3819 | q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3820 | } |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3821 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3822 | } |
| 3823 | if (((segment->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0)) |
| 3824 | return(MagickTrue); |
| 3825 | return(MagickFalse); |
| 3826 | } |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3827 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3828 | MagickExport MagickBooleanType PlasmaImage(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3829 | const SegmentInfo *segment,size_t attenuate,size_t depth, |
| 3830 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3831 | { |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3832 | CacheView |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3833 | *image_view, |
| 3834 | *u_view, |
| 3835 | *v_view; |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3836 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3837 | MagickBooleanType |
| 3838 | status; |
| 3839 | |
| 3840 | RandomInfo |
| 3841 | *random_info; |
| 3842 | |
| 3843 | if (image->debug != MagickFalse) |
| 3844 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3845 | assert(image != (Image *) NULL); |
| 3846 | assert(image->signature == MagickSignature); |
| 3847 | if (image->debug != MagickFalse) |
| 3848 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3849 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3850 | return(MagickFalse); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3851 | image_view=AcquireAuthenticCacheView(image,exception); |
| 3852 | u_view=AcquireVirtualCacheView(image,exception); |
| 3853 | v_view=AcquireVirtualCacheView(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3854 | random_info=AcquireRandomInfo(); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3855 | status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment, |
| 3856 | attenuate,depth,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3857 | random_info=DestroyRandomInfo(random_info); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 3858 | v_view=DestroyCacheView(v_view); |
| 3859 | u_view=DestroyCacheView(u_view); |
cristy | c5c6f66 | 2010-09-22 14:23:02 +0000 | [diff] [blame] | 3860 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3861 | return(status); |
| 3862 | } |
| 3863 | |
| 3864 | /* |
| 3865 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3866 | % % |
| 3867 | % % |
| 3868 | % % |
| 3869 | % P o l a r o i d I m a g e % |
| 3870 | % % |
| 3871 | % % |
| 3872 | % % |
| 3873 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3874 | % |
| 3875 | % PolaroidImage() simulates a Polaroid picture. |
| 3876 | % |
| 3877 | % The format of the AnnotateImage method is: |
| 3878 | % |
| 3879 | % Image *PolaroidImage(const Image *image,const DrawInfo *draw_info, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3880 | % const char *caption,const double angle, |
| 3881 | % const PixelInterpolateMethod method,ExceptionInfo exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3882 | % |
| 3883 | % A description of each parameter follows: |
| 3884 | % |
| 3885 | % o image: the image. |
| 3886 | % |
| 3887 | % o draw_info: the draw info. |
| 3888 | % |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3889 | % o caption: the Polaroid caption. |
| 3890 | % |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 3891 | % o angle: Apply the effect along this angle. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3892 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3893 | % o method: the pixel interpolation method. |
| 3894 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3895 | % o exception: return any errors or warnings in this structure. |
| 3896 | % |
| 3897 | */ |
| 3898 | MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3899 | const char *caption,const double angle,const PixelInterpolateMethod method, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 3900 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3901 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3902 | Image |
| 3903 | *bend_image, |
| 3904 | *caption_image, |
| 3905 | *flop_image, |
| 3906 | *picture_image, |
| 3907 | *polaroid_image, |
| 3908 | *rotate_image, |
| 3909 | *trim_image; |
| 3910 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3911 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3912 | height; |
| 3913 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3914 | ssize_t |
| 3915 | quantum; |
| 3916 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3917 | /* |
| 3918 | Simulate a Polaroid picture. |
| 3919 | */ |
| 3920 | assert(image != (Image *) NULL); |
| 3921 | assert(image->signature == MagickSignature); |
| 3922 | if (image->debug != MagickFalse) |
| 3923 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3924 | assert(exception != (ExceptionInfo *) NULL); |
| 3925 | assert(exception->signature == MagickSignature); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3926 | quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3927 | image->rows)/25.0,10.0); |
| 3928 | height=image->rows+2*quantum; |
| 3929 | caption_image=(Image *) NULL; |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3930 | if (caption != (const char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3931 | { |
| 3932 | char |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3933 | geometry[MaxTextExtent], |
| 3934 | *text; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3935 | |
| 3936 | DrawInfo |
| 3937 | *annotate_info; |
| 3938 | |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3939 | ImageInfo |
| 3940 | *image_info; |
| 3941 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3942 | MagickBooleanType |
| 3943 | status; |
| 3944 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 3945 | ssize_t |
| 3946 | count; |
| 3947 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3948 | TypeMetric |
| 3949 | metrics; |
| 3950 | |
| 3951 | /* |
| 3952 | Generate caption image. |
| 3953 | */ |
| 3954 | caption_image=CloneImage(image,image->columns,1,MagickTrue,exception); |
| 3955 | if (caption_image == (Image *) NULL) |
| 3956 | return((Image *) NULL); |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3957 | image_info=AcquireImageInfo(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3958 | annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info); |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3959 | text=InterpretImageProperties(image_info,(Image *) image,caption, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3960 | exception); |
cristy | 72e0b77 | 2013-04-28 14:29:45 +0000 | [diff] [blame] | 3961 | image_info=DestroyImageInfo(image_info); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3962 | (void) CloneString(&annotate_info->text,text); |
cristy | 6b1d05e | 2010-09-22 19:17:27 +0000 | [diff] [blame] | 3963 | count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics, |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3964 | &text,exception); |
| 3965 | status=SetImageExtent(caption_image,image->columns,(size_t) ((count+1)* |
| 3966 | (metrics.ascent-metrics.descent)+0.5),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3967 | if (status == MagickFalse) |
| 3968 | caption_image=DestroyImage(caption_image); |
| 3969 | else |
| 3970 | { |
| 3971 | caption_image->background_color=image->border_color; |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3972 | (void) SetImageBackgroundColor(caption_image,exception); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3973 | (void) CloneString(&annotate_info->text,text); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3974 | (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3975 | metrics.ascent); |
| 3976 | if (annotate_info->gravity == UndefinedGravity) |
| 3977 | (void) CloneString(&annotate_info->geometry,AcquireString( |
| 3978 | geometry)); |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 3979 | (void) AnnotateImage(caption_image,annotate_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3980 | height+=caption_image->rows; |
| 3981 | } |
| 3982 | annotate_info=DestroyDrawInfo(annotate_info); |
cristy | e9e3d38 | 2011-12-14 01:50:13 +0000 | [diff] [blame] | 3983 | text=DestroyString(text); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3984 | } |
| 3985 | picture_image=CloneImage(image,image->columns+2*quantum,height,MagickTrue, |
| 3986 | exception); |
| 3987 | if (picture_image == (Image *) NULL) |
| 3988 | { |
| 3989 | if (caption_image != (Image *) NULL) |
| 3990 | caption_image=DestroyImage(caption_image); |
| 3991 | return((Image *) NULL); |
| 3992 | } |
| 3993 | picture_image->background_color=image->border_color; |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3994 | (void) SetImageBackgroundColor(picture_image,exception); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 3995 | (void) CompositeImage(picture_image,image,OverCompositeOp,MagickTrue,quantum, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 3996 | quantum,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3997 | if (caption_image != (Image *) NULL) |
| 3998 | { |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 3999 | (void) CompositeImage(picture_image,caption_image,OverCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4000 | MagickTrue,quantum,(ssize_t) (image->rows+3*quantum/2),exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4001 | caption_image=DestroyImage(caption_image); |
| 4002 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4003 | (void) QueryColorCompliance("none",AllCompliance, |
| 4004 | &picture_image->background_color,exception); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4005 | (void) SetImageAlphaChannel(picture_image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4006 | rotate_image=RotateImage(picture_image,90.0,exception); |
| 4007 | picture_image=DestroyImage(picture_image); |
| 4008 | if (rotate_image == (Image *) NULL) |
| 4009 | return((Image *) NULL); |
| 4010 | picture_image=rotate_image; |
| 4011 | bend_image=WaveImage(picture_image,0.01*picture_image->rows,2.0* |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 4012 | picture_image->columns,method,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4013 | picture_image=DestroyImage(picture_image); |
| 4014 | if (bend_image == (Image *) NULL) |
| 4015 | return((Image *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4016 | picture_image=bend_image; |
| 4017 | rotate_image=RotateImage(picture_image,-90.0,exception); |
| 4018 | picture_image=DestroyImage(picture_image); |
| 4019 | if (rotate_image == (Image *) NULL) |
| 4020 | return((Image *) NULL); |
| 4021 | picture_image=rotate_image; |
| 4022 | picture_image->background_color=image->background_color; |
anthony | f46d426 | 2012-03-26 03:30:34 +0000 | [diff] [blame] | 4023 | polaroid_image=ShadowImage(picture_image,80.0,2.0,quantum/3,quantum/3, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4024 | exception); |
| 4025 | if (polaroid_image == (Image *) NULL) |
| 4026 | { |
| 4027 | picture_image=DestroyImage(picture_image); |
| 4028 | return(picture_image); |
| 4029 | } |
| 4030 | flop_image=FlopImage(polaroid_image,exception); |
| 4031 | polaroid_image=DestroyImage(polaroid_image); |
| 4032 | if (flop_image == (Image *) NULL) |
| 4033 | { |
| 4034 | picture_image=DestroyImage(picture_image); |
| 4035 | return(picture_image); |
| 4036 | } |
| 4037 | polaroid_image=flop_image; |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4038 | (void) CompositeImage(polaroid_image,picture_image,OverCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4039 | MagickTrue,(ssize_t) (-0.01*picture_image->columns/2.0),0L,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4040 | picture_image=DestroyImage(picture_image); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4041 | (void) QueryColorCompliance("none",AllCompliance, |
| 4042 | &polaroid_image->background_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4043 | rotate_image=RotateImage(polaroid_image,angle,exception); |
| 4044 | polaroid_image=DestroyImage(polaroid_image); |
| 4045 | if (rotate_image == (Image *) NULL) |
| 4046 | return((Image *) NULL); |
| 4047 | polaroid_image=rotate_image; |
| 4048 | trim_image=TrimImage(polaroid_image,exception); |
| 4049 | polaroid_image=DestroyImage(polaroid_image); |
| 4050 | if (trim_image == (Image *) NULL) |
| 4051 | return((Image *) NULL); |
| 4052 | polaroid_image=trim_image; |
| 4053 | return(polaroid_image); |
| 4054 | } |
| 4055 | |
| 4056 | /* |
| 4057 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4058 | % % |
| 4059 | % % |
| 4060 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4061 | % S e p i a T o n e I m a g e % |
| 4062 | % % |
| 4063 | % % |
| 4064 | % % |
| 4065 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4066 | % |
| 4067 | % MagickSepiaToneImage() applies a special effect to the image, similar to the |
| 4068 | % effect achieved in a photo darkroom by sepia toning. Threshold ranges from |
| 4069 | % 0 to QuantumRange and is a measure of the extent of the sepia toning. A |
| 4070 | % threshold of 80% is a good starting point for a reasonable tone. |
| 4071 | % |
| 4072 | % The format of the SepiaToneImage method is: |
| 4073 | % |
| 4074 | % Image *SepiaToneImage(const Image *image,const double threshold, |
| 4075 | % ExceptionInfo *exception) |
| 4076 | % |
| 4077 | % A description of each parameter follows: |
| 4078 | % |
| 4079 | % o image: the image. |
| 4080 | % |
| 4081 | % o threshold: the tone threshold. |
| 4082 | % |
| 4083 | % o exception: return any errors or warnings in this structure. |
| 4084 | % |
| 4085 | */ |
| 4086 | MagickExport Image *SepiaToneImage(const Image *image,const double threshold, |
| 4087 | ExceptionInfo *exception) |
| 4088 | { |
| 4089 | #define SepiaToneImageTag "SepiaTone/Image" |
| 4090 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4091 | CacheView |
| 4092 | *image_view, |
| 4093 | *sepia_view; |
| 4094 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4095 | Image |
| 4096 | *sepia_image; |
| 4097 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4098 | MagickBooleanType |
| 4099 | status; |
| 4100 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4101 | MagickOffsetType |
| 4102 | progress; |
| 4103 | |
| 4104 | ssize_t |
| 4105 | y; |
| 4106 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4107 | /* |
| 4108 | Initialize sepia-toned image attributes. |
| 4109 | */ |
| 4110 | assert(image != (const Image *) NULL); |
| 4111 | assert(image->signature == MagickSignature); |
| 4112 | if (image->debug != MagickFalse) |
| 4113 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4114 | assert(exception != (ExceptionInfo *) NULL); |
| 4115 | assert(exception->signature == MagickSignature); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4116 | sepia_image=CloneImage(image,0,0,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4117 | if (sepia_image == (Image *) NULL) |
| 4118 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4119 | if (SetImageStorageClass(sepia_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4120 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4121 | sepia_image=DestroyImage(sepia_image); |
| 4122 | return((Image *) NULL); |
| 4123 | } |
| 4124 | /* |
| 4125 | Tone each row of the image. |
| 4126 | */ |
| 4127 | status=MagickTrue; |
| 4128 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4129 | image_view=AcquireVirtualCacheView(image,exception); |
| 4130 | sepia_view=AcquireAuthenticCacheView(sepia_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4131 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 4132 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 4133 | magick_threads(image,sepia_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4134 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4135 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4136 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4137 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4138 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4139 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4140 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4141 | x; |
| 4142 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4143 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4144 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4145 | |
| 4146 | if (status == MagickFalse) |
| 4147 | continue; |
| 4148 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4149 | q=GetCacheViewAuthenticPixels(sepia_view,0,y,sepia_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4150 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4151 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4152 | { |
| 4153 | status=MagickFalse; |
| 4154 | continue; |
| 4155 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4156 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4157 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4158 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4159 | intensity, |
| 4160 | tone; |
| 4161 | |
cristy | f13c594 | 2012-08-08 23:50:11 +0000 | [diff] [blame] | 4162 | intensity=GetPixelIntensity(image,p); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4163 | tone=intensity > threshold ? (double) QuantumRange : intensity+ |
| 4164 | (double) QuantumRange-threshold; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4165 | SetPixelRed(sepia_image,ClampToQuantum(tone),q); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4166 | tone=intensity > (7.0*threshold/6.0) ? (double) QuantumRange : |
| 4167 | intensity+(double) QuantumRange-7.0*threshold/6.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4168 | SetPixelGreen(sepia_image,ClampToQuantum(tone),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4169 | tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4170 | SetPixelBlue(sepia_image,ClampToQuantum(tone),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4171 | tone=threshold/7.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4172 | if ((double) GetPixelGreen(image,q) < tone) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4173 | SetPixelGreen(sepia_image,ClampToQuantum(tone),q); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4174 | if ((double) GetPixelBlue(image,q) < tone) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4175 | SetPixelBlue(sepia_image,ClampToQuantum(tone),q); |
cristy | c8a5f0e | 2014-04-04 11:36:37 +0000 | [diff] [blame] | 4176 | SetPixelAlpha(sepia_image,GetPixelAlpha(image,p),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4177 | p+=GetPixelChannels(image); |
| 4178 | q+=GetPixelChannels(sepia_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4179 | } |
| 4180 | if (SyncCacheViewAuthenticPixels(sepia_view,exception) == MagickFalse) |
| 4181 | status=MagickFalse; |
| 4182 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 4183 | { |
| 4184 | MagickBooleanType |
| 4185 | proceed; |
| 4186 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4187 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 4188 | #pragma omp critical (MagickCore_SepiaToneImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4189 | #endif |
| 4190 | proceed=SetImageProgress(image,SepiaToneImageTag,progress++, |
| 4191 | image->rows); |
| 4192 | if (proceed == MagickFalse) |
| 4193 | status=MagickFalse; |
| 4194 | } |
| 4195 | } |
| 4196 | sepia_view=DestroyCacheView(sepia_view); |
| 4197 | image_view=DestroyCacheView(image_view); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 4198 | (void) NormalizeImage(sepia_image,exception); |
| 4199 | (void) ContrastImage(sepia_image,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4200 | if (status == MagickFalse) |
| 4201 | sepia_image=DestroyImage(sepia_image); |
| 4202 | return(sepia_image); |
| 4203 | } |
| 4204 | |
| 4205 | /* |
| 4206 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4207 | % % |
| 4208 | % % |
| 4209 | % % |
| 4210 | % S h a d o w I m a g e % |
| 4211 | % % |
| 4212 | % % |
| 4213 | % % |
| 4214 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4215 | % |
| 4216 | % ShadowImage() simulates a shadow from the specified image and returns it. |
| 4217 | % |
| 4218 | % The format of the ShadowImage method is: |
| 4219 | % |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4220 | % Image *ShadowImage(const Image *image,const double alpha, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4221 | % const double sigma,const ssize_t x_offset,const ssize_t y_offset, |
| 4222 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4223 | % |
| 4224 | % A description of each parameter follows: |
| 4225 | % |
| 4226 | % o image: the image. |
| 4227 | % |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4228 | % o alpha: percentage transparency. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4229 | % |
| 4230 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 4231 | % |
| 4232 | % o x_offset: the shadow x-offset. |
| 4233 | % |
| 4234 | % o y_offset: the shadow y-offset. |
| 4235 | % |
| 4236 | % o exception: return any errors or warnings in this structure. |
| 4237 | % |
| 4238 | */ |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4239 | MagickExport Image *ShadowImage(const Image *image,const double alpha, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4240 | const double sigma,const ssize_t x_offset,const ssize_t y_offset, |
| 4241 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4242 | { |
| 4243 | #define ShadowImageTag "Shadow/Image" |
| 4244 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4245 | CacheView |
| 4246 | *image_view; |
| 4247 | |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4248 | ChannelType |
| 4249 | channel_mask; |
| 4250 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4251 | Image |
| 4252 | *border_image, |
| 4253 | *clone_image, |
| 4254 | *shadow_image; |
| 4255 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4256 | MagickBooleanType |
| 4257 | status; |
| 4258 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4259 | RectangleInfo |
| 4260 | border_info; |
| 4261 | |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4262 | ssize_t |
| 4263 | y; |
| 4264 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4265 | assert(image != (Image *) NULL); |
| 4266 | assert(image->signature == MagickSignature); |
| 4267 | if (image->debug != MagickFalse) |
| 4268 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4269 | assert(exception != (ExceptionInfo *) NULL); |
| 4270 | assert(exception->signature == MagickSignature); |
| 4271 | clone_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4272 | if (clone_image == (Image *) NULL) |
| 4273 | return((Image *) NULL); |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 4274 | if (IsGrayColorspace(image->colorspace) != MagickFalse) |
cristy | 0c81d06 | 2013-04-21 15:22:02 +0000 | [diff] [blame] | 4275 | (void) SetImageColorspace(clone_image,sRGBColorspace,exception); |
cristy | 0ce0876 | 2012-06-30 01:33:18 +0000 | [diff] [blame] | 4276 | (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod, |
cristy | 387430f | 2012-02-07 13:09:46 +0000 | [diff] [blame] | 4277 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4278 | border_info.width=(size_t) floor(2.0*sigma+0.5); |
| 4279 | border_info.height=(size_t) floor(2.0*sigma+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4280 | border_info.x=0; |
| 4281 | border_info.y=0; |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4282 | (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color, |
| 4283 | exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4284 | clone_image->alpha_trait=BlendPixelTrait; |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4285 | border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4286 | clone_image=DestroyImage(clone_image); |
| 4287 | if (border_image == (Image *) NULL) |
| 4288 | return((Image *) NULL); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4289 | if (border_image->alpha_trait != BlendPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4290 | (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4291 | /* |
| 4292 | Shadow image. |
| 4293 | */ |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4294 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4295 | image_view=AcquireAuthenticCacheView(border_image,exception); |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4296 | for (y=0; y < (ssize_t) border_image->rows; y++) |
| 4297 | { |
| 4298 | PixelInfo |
| 4299 | background_color; |
| 4300 | |
| 4301 | register Quantum |
| 4302 | *restrict q; |
| 4303 | |
| 4304 | register ssize_t |
| 4305 | x; |
| 4306 | |
| 4307 | if (status == MagickFalse) |
| 4308 | continue; |
| 4309 | q=QueueCacheViewAuthenticPixels(image_view,0,y,border_image->columns,1, |
| 4310 | exception); |
| 4311 | if (q == (Quantum *) NULL) |
| 4312 | { |
| 4313 | status=MagickFalse; |
| 4314 | continue; |
| 4315 | } |
| 4316 | background_color=border_image->background_color; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4317 | background_color.alpha_trait=BlendPixelTrait; |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4318 | for (x=0; x < (ssize_t) border_image->columns; x++) |
| 4319 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4320 | if (border_image->alpha_trait == BlendPixelTrait) |
cristy | 70cddf7 | 2011-12-10 22:42:42 +0000 | [diff] [blame] | 4321 | background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0; |
| 4322 | SetPixelInfoPixel(border_image,&background_color,q); |
| 4323 | q+=GetPixelChannels(border_image); |
| 4324 | } |
| 4325 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 4326 | status=MagickFalse; |
| 4327 | } |
| 4328 | image_view=DestroyCacheView(image_view); |
| 4329 | if (status == MagickFalse) |
| 4330 | { |
| 4331 | border_image=DestroyImage(border_image); |
| 4332 | return((Image *) NULL); |
| 4333 | } |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4334 | channel_mask=SetImageChannelMask(border_image,AlphaChannel); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4335 | shadow_image=BlurImage(border_image,0.0,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4336 | border_image=DestroyImage(border_image); |
| 4337 | if (shadow_image == (Image *) NULL) |
| 4338 | return((Image *) NULL); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4339 | (void) SetPixelChannelMask(shadow_image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4340 | if (shadow_image->page.width == 0) |
| 4341 | shadow_image->page.width=shadow_image->columns; |
| 4342 | if (shadow_image->page.height == 0) |
| 4343 | shadow_image->page.height=shadow_image->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4344 | shadow_image->page.width+=x_offset-(ssize_t) border_info.width; |
| 4345 | shadow_image->page.height+=y_offset-(ssize_t) border_info.height; |
| 4346 | shadow_image->page.x+=x_offset-(ssize_t) border_info.width; |
| 4347 | shadow_image->page.y+=y_offset-(ssize_t) border_info.height; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4348 | return(shadow_image); |
| 4349 | } |
| 4350 | |
| 4351 | /* |
| 4352 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4353 | % % |
| 4354 | % % |
| 4355 | % % |
| 4356 | % S k e t c h I m a g e % |
| 4357 | % % |
| 4358 | % % |
| 4359 | % % |
| 4360 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4361 | % |
| 4362 | % SketchImage() simulates a pencil sketch. We convolve the image with a |
| 4363 | % Gaussian operator of the given radius and standard deviation (sigma). For |
| 4364 | % reasonable results, radius should be larger than sigma. Use a radius of 0 |
| 4365 | % and SketchImage() selects a suitable radius for you. Angle gives the angle |
| 4366 | % of the sketch. |
| 4367 | % |
| 4368 | % The format of the SketchImage method is: |
| 4369 | % |
| 4370 | % Image *SketchImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4371 | % const double sigma,const double angle,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4372 | % |
| 4373 | % A description of each parameter follows: |
| 4374 | % |
| 4375 | % o image: the image. |
| 4376 | % |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4377 | % o radius: the radius of the Gaussian, in pixels, not counting the |
| 4378 | % center pixel. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4379 | % |
| 4380 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 4381 | % |
cristy | f7ef025 | 2011-09-09 14:50:06 +0000 | [diff] [blame] | 4382 | % o angle: apply the effect along this angle. |
| 4383 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4384 | % o exception: return any errors or warnings in this structure. |
| 4385 | % |
| 4386 | */ |
| 4387 | MagickExport Image *SketchImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4388 | const double sigma,const double angle,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4389 | { |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 4390 | CacheView |
| 4391 | *random_view; |
| 4392 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4393 | Image |
| 4394 | *blend_image, |
| 4395 | *blur_image, |
| 4396 | *dodge_image, |
| 4397 | *random_image, |
| 4398 | *sketch_image; |
| 4399 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4400 | MagickBooleanType |
| 4401 | status; |
| 4402 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4403 | RandomInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 4404 | **restrict random_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4405 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 4406 | ssize_t |
| 4407 | y; |
| 4408 | |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4409 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4410 | unsigned long |
| 4411 | key; |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4412 | #endif |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4413 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4414 | /* |
| 4415 | Sketch image. |
| 4416 | */ |
| 4417 | random_image=CloneImage(image,image->columns << 1,image->rows << 1, |
| 4418 | MagickTrue,exception); |
| 4419 | if (random_image == (Image *) NULL) |
| 4420 | return((Image *) NULL); |
| 4421 | status=MagickTrue; |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4422 | random_info=AcquireRandomInfoThreadSet(); |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4423 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4424 | key=GetRandomSecretKey(random_info[0]); |
glennrp | f7659d7 | 2012-09-24 18:14:56 +0000 | [diff] [blame] | 4425 | #endif |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4426 | random_view=AcquireAuthenticCacheView(random_image,exception); |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4427 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 57340e0 | 2012-05-05 00:53:23 +0000 | [diff] [blame] | 4428 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 4429 | magick_threads(random_image,random_image,random_image->rows,key == ~0UL) |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4430 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4431 | for (y=0; y < (ssize_t) random_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4432 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 4433 | const int |
| 4434 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 4435 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4436 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4437 | x; |
| 4438 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4439 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4440 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4441 | |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4442 | if (status == MagickFalse) |
| 4443 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4444 | q=QueueCacheViewAuthenticPixels(random_view,0,y,random_image->columns,1, |
| 4445 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4446 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4447 | { |
| 4448 | status=MagickFalse; |
| 4449 | continue; |
| 4450 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4451 | for (x=0; x < (ssize_t) random_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4452 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4453 | double |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4454 | value; |
| 4455 | |
| 4456 | register ssize_t |
| 4457 | i; |
| 4458 | |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 4459 | if (GetPixelReadMask(random_image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 4460 | { |
| 4461 | q+=GetPixelChannels(random_image); |
| 4462 | continue; |
| 4463 | } |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4464 | value=GetPseudoRandomValue(random_info[id]); |
| 4465 | for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++) |
| 4466 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 4467 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 4468 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4469 | if (traits == UndefinedPixelTrait) |
| 4470 | continue; |
| 4471 | q[i]=ClampToQuantum(QuantumRange*value); |
| 4472 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4473 | q+=GetPixelChannels(random_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4474 | } |
| 4475 | if (SyncCacheViewAuthenticPixels(random_view,exception) == MagickFalse) |
| 4476 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4477 | } |
| 4478 | random_view=DestroyCacheView(random_view); |
cristy | 1b78443 | 2009-12-19 02:20:40 +0000 | [diff] [blame] | 4479 | random_info=DestroyRandomInfoThreadSet(random_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4480 | if (status == MagickFalse) |
| 4481 | { |
| 4482 | random_image=DestroyImage(random_image); |
| 4483 | return(random_image); |
| 4484 | } |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 4485 | blur_image=MotionBlurImage(random_image,radius,sigma,angle,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4486 | random_image=DestroyImage(random_image); |
| 4487 | if (blur_image == (Image *) NULL) |
| 4488 | return((Image *) NULL); |
cristy | 800446a | 2013-05-20 20:15:38 +0000 | [diff] [blame] | 4489 | dodge_image=EdgeImage(blur_image,radius,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4490 | blur_image=DestroyImage(blur_image); |
| 4491 | if (dodge_image == (Image *) NULL) |
| 4492 | return((Image *) NULL); |
cristy | e23ec9d | 2011-08-16 18:15:40 +0000 | [diff] [blame] | 4493 | (void) NormalizeImage(dodge_image,exception); |
cristy | b3e7c6c | 2011-07-24 01:43:55 +0000 | [diff] [blame] | 4494 | (void) NegateImage(dodge_image,MagickFalse,exception); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4495 | (void) TransformImage(&dodge_image,(char *) NULL,"50%",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4496 | sketch_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4497 | if (sketch_image == (Image *) NULL) |
| 4498 | { |
| 4499 | dodge_image=DestroyImage(dodge_image); |
| 4500 | return((Image *) NULL); |
| 4501 | } |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4502 | (void) CompositeImage(sketch_image,dodge_image,ColorDodgeCompositeOp, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4503 | MagickTrue,0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4504 | dodge_image=DestroyImage(dodge_image); |
| 4505 | blend_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4506 | if (blend_image == (Image *) NULL) |
| 4507 | { |
| 4508 | sketch_image=DestroyImage(sketch_image); |
| 4509 | return((Image *) NULL); |
| 4510 | } |
| 4511 | (void) SetImageArtifact(blend_image,"compose:args","20x80"); |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4512 | (void) CompositeImage(sketch_image,blend_image,BlendCompositeOp,MagickTrue, |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4513 | 0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4514 | blend_image=DestroyImage(blend_image); |
| 4515 | return(sketch_image); |
| 4516 | } |
| 4517 | |
| 4518 | /* |
| 4519 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4520 | % % |
| 4521 | % % |
| 4522 | % % |
| 4523 | % S o l a r i z e I m a g e % |
| 4524 | % % |
| 4525 | % % |
| 4526 | % % |
| 4527 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4528 | % |
| 4529 | % SolarizeImage() applies a special effect to the image, similar to the effect |
| 4530 | % achieved in a photo darkroom by selectively exposing areas of photo |
| 4531 | % sensitive paper to light. Threshold ranges from 0 to QuantumRange and is a |
| 4532 | % measure of the extent of the solarization. |
| 4533 | % |
| 4534 | % The format of the SolarizeImage method is: |
| 4535 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4536 | % MagickBooleanType SolarizeImage(Image *image,const double threshold, |
| 4537 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4538 | % |
| 4539 | % A description of each parameter follows: |
| 4540 | % |
| 4541 | % o image: the image. |
| 4542 | % |
| 4543 | % o threshold: Define the extent of the solarization. |
| 4544 | % |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4545 | % o exception: return any errors or warnings in this structure. |
| 4546 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4547 | */ |
| 4548 | MagickExport MagickBooleanType SolarizeImage(Image *image, |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4549 | const double threshold,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4550 | { |
| 4551 | #define SolarizeImageTag "Solarize/Image" |
| 4552 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4553 | CacheView |
| 4554 | *image_view; |
| 4555 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4556 | MagickBooleanType |
| 4557 | status; |
| 4558 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4559 | MagickOffsetType |
| 4560 | progress; |
| 4561 | |
| 4562 | ssize_t |
| 4563 | y; |
| 4564 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4565 | assert(image != (Image *) NULL); |
| 4566 | assert(image->signature == MagickSignature); |
| 4567 | if (image->debug != MagickFalse) |
| 4568 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 4569 | if (IsGrayColorspace(image->colorspace) != MagickFalse) |
cristy | 0c81d06 | 2013-04-21 15:22:02 +0000 | [diff] [blame] | 4570 | (void) SetImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4571 | if (image->storage_class == PseudoClass) |
| 4572 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4573 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4574 | i; |
| 4575 | |
| 4576 | /* |
| 4577 | Solarize colormap. |
| 4578 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4579 | for (i=0; i < (ssize_t) image->colors; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4580 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4581 | if ((double) image->colormap[i].red > threshold) |
cristy | 6e963d8 | 2012-06-19 15:23:24 +0000 | [diff] [blame] | 4582 | image->colormap[i].red=QuantumRange-image->colormap[i].red; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4583 | if ((double) image->colormap[i].green > threshold) |
cristy | 13ceedd | 2013-12-02 17:57:23 +0000 | [diff] [blame] | 4584 | image->colormap[i].green=QuantumRange-image->colormap[i].green; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4585 | if ((double) image->colormap[i].blue > threshold) |
cristy | 13ceedd | 2013-12-02 17:57:23 +0000 | [diff] [blame] | 4586 | image->colormap[i].blue=QuantumRange-image->colormap[i].blue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4587 | } |
| 4588 | } |
| 4589 | /* |
| 4590 | Solarize image. |
| 4591 | */ |
| 4592 | status=MagickTrue; |
| 4593 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4594 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4595 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 4596 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 4597 | magick_threads(image,image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4598 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4599 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4600 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4601 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4602 | x; |
| 4603 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4604 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4605 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4606 | |
| 4607 | if (status == MagickFalse) |
| 4608 | continue; |
cristy | 5cbc016 | 2011-08-29 00:36:28 +0000 | [diff] [blame] | 4609 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4610 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4611 | { |
| 4612 | status=MagickFalse; |
| 4613 | continue; |
| 4614 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4615 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4616 | { |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4617 | register ssize_t |
| 4618 | i; |
| 4619 | |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 4620 | if (GetPixelReadMask(image,q) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 4621 | { |
| 4622 | q+=GetPixelChannels(image); |
| 4623 | continue; |
| 4624 | } |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4625 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 4626 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 4627 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 4628 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4629 | if ((traits == UndefinedPixelTrait) || |
| 4630 | ((traits & CopyPixelTrait) != 0)) |
| 4631 | continue; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4632 | if ((double) q[i] > threshold) |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4633 | q[i]=QuantumRange-q[i]; |
| 4634 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4635 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4636 | } |
| 4637 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 4638 | status=MagickFalse; |
| 4639 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 4640 | { |
| 4641 | MagickBooleanType |
| 4642 | proceed; |
| 4643 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 4644 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 4645 | #pragma omp critical (MagickCore_SolarizeImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4646 | #endif |
| 4647 | proceed=SetImageProgress(image,SolarizeImageTag,progress++,image->rows); |
| 4648 | if (proceed == MagickFalse) |
| 4649 | status=MagickFalse; |
| 4650 | } |
| 4651 | } |
| 4652 | image_view=DestroyCacheView(image_view); |
| 4653 | return(status); |
| 4654 | } |
| 4655 | |
| 4656 | /* |
| 4657 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4658 | % % |
| 4659 | % % |
| 4660 | % % |
| 4661 | % S t e g a n o I m a g e % |
| 4662 | % % |
| 4663 | % % |
| 4664 | % % |
| 4665 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4666 | % |
| 4667 | % SteganoImage() hides a digital watermark within the image. Recover |
| 4668 | % the hidden watermark later to prove that the authenticity of an image. |
| 4669 | % Offset defines the start position within the image to hide the watermark. |
| 4670 | % |
| 4671 | % The format of the SteganoImage method is: |
| 4672 | % |
| 4673 | % Image *SteganoImage(const Image *image,Image *watermark, |
| 4674 | % ExceptionInfo *exception) |
| 4675 | % |
| 4676 | % A description of each parameter follows: |
| 4677 | % |
| 4678 | % o image: the image. |
| 4679 | % |
| 4680 | % o watermark: the watermark image. |
| 4681 | % |
| 4682 | % o exception: return any errors or warnings in this structure. |
| 4683 | % |
| 4684 | */ |
| 4685 | MagickExport Image *SteganoImage(const Image *image,const Image *watermark, |
| 4686 | ExceptionInfo *exception) |
| 4687 | { |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4688 | #define GetBit(alpha,i) ((((size_t) (alpha) >> (size_t) (i)) & 0x01) != 0) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4689 | #define SetBit(alpha,i,set) (Quantum) ((set) != 0 ? (size_t) (alpha) \ |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4690 | | (one << (size_t) (i)) : (size_t) (alpha) & ~(one << (size_t) (i))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4691 | #define SteganoImageTag "Stegano/Image" |
| 4692 | |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4693 | CacheView |
| 4694 | *stegano_view, |
| 4695 | *watermark_view; |
| 4696 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4697 | Image |
| 4698 | *stegano_image; |
| 4699 | |
| 4700 | int |
| 4701 | c; |
| 4702 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4703 | MagickBooleanType |
| 4704 | status; |
| 4705 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4706 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4707 | pixel; |
| 4708 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4709 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4710 | *q; |
| 4711 | |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4712 | register ssize_t |
| 4713 | x; |
| 4714 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4715 | size_t |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4716 | depth, |
| 4717 | one; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4718 | |
cristy | e1bf8ad | 2010-09-19 17:07:03 +0000 | [diff] [blame] | 4719 | ssize_t |
| 4720 | i, |
| 4721 | j, |
| 4722 | k, |
| 4723 | y; |
| 4724 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4725 | /* |
| 4726 | Initialize steganographic image attributes. |
| 4727 | */ |
| 4728 | assert(image != (const Image *) NULL); |
| 4729 | assert(image->signature == MagickSignature); |
| 4730 | if (image->debug != MagickFalse) |
| 4731 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 4732 | assert(watermark != (const Image *) NULL); |
| 4733 | assert(watermark->signature == MagickSignature); |
| 4734 | assert(exception != (ExceptionInfo *) NULL); |
| 4735 | assert(exception->signature == MagickSignature); |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 4736 | one=1UL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4737 | stegano_image=CloneImage(image,0,0,MagickTrue,exception); |
| 4738 | if (stegano_image == (Image *) NULL) |
| 4739 | return((Image *) NULL); |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4740 | stegano_image->depth=MAGICKCORE_QUANTUM_DEPTH; |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4741 | if (SetImageStorageClass(stegano_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4742 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4743 | stegano_image=DestroyImage(stegano_image); |
| 4744 | return((Image *) NULL); |
| 4745 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4746 | /* |
| 4747 | Hide watermark in low-order bits of image. |
| 4748 | */ |
| 4749 | c=0; |
| 4750 | i=0; |
| 4751 | j=0; |
| 4752 | depth=stegano_image->depth; |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4753 | k=stegano_image->offset; |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4754 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4755 | watermark_view=AcquireVirtualCacheView(watermark,exception); |
| 4756 | stegano_view=AcquireAuthenticCacheView(stegano_image,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4757 | for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4758 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4759 | for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4760 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4761 | for (x=0; (x < (ssize_t) watermark->columns) && (j < (ssize_t) depth); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4762 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4763 | ssize_t |
| 4764 | offset; |
| 4765 | |
cristy | f05d494 | 2012-03-17 16:26:09 +0000 | [diff] [blame] | 4766 | (void) GetOneCacheViewVirtualPixelInfo(watermark_view,x,y,&pixel, |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4767 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 4768 | offset=k/(ssize_t) stegano_image->columns; |
| 4769 | if (offset >= (ssize_t) stegano_image->rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4770 | break; |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4771 | q=GetCacheViewAuthenticPixels(stegano_view,k % (ssize_t) |
| 4772 | stegano_image->columns,k/(ssize_t) stegano_image->columns,1,1, |
| 4773 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 4774 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4775 | break; |
| 4776 | switch (c) |
| 4777 | { |
| 4778 | case 0: |
| 4779 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4780 | SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j, |
| 4781 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4782 | break; |
| 4783 | } |
| 4784 | case 1: |
| 4785 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4786 | SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j, |
| 4787 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4788 | break; |
| 4789 | } |
| 4790 | case 2: |
| 4791 | { |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4792 | SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j, |
| 4793 | GetBit(GetPixelInfoIntensity(&pixel),i)),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4794 | break; |
| 4795 | } |
| 4796 | } |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4797 | if (SyncCacheViewAuthenticPixels(stegano_view,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4798 | break; |
| 4799 | c++; |
| 4800 | if (c == 3) |
| 4801 | c=0; |
| 4802 | k++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4803 | if (k == (ssize_t) (stegano_image->columns*stegano_image->columns)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4804 | k=0; |
cristy | f61b183 | 2012-04-01 01:38:19 +0000 | [diff] [blame] | 4805 | if (k == stegano_image->offset) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4806 | j++; |
| 4807 | } |
| 4808 | } |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4809 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4810 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4811 | MagickBooleanType |
| 4812 | proceed; |
| 4813 | |
| 4814 | proceed=SetImageProgress(image,SteganoImageTag,(MagickOffsetType) |
| 4815 | (depth-i),depth); |
| 4816 | if (proceed == MagickFalse) |
| 4817 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4818 | } |
| 4819 | } |
cristy | b0d3bb9 | 2010-09-22 14:37:58 +0000 | [diff] [blame] | 4820 | stegano_view=DestroyCacheView(stegano_view); |
| 4821 | watermark_view=DestroyCacheView(watermark_view); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4822 | if (status == MagickFalse) |
cristy | fab8364 | 2012-12-14 00:31:38 +0000 | [diff] [blame] | 4823 | stegano_image=DestroyImage(stegano_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4824 | return(stegano_image); |
| 4825 | } |
| 4826 | |
| 4827 | /* |
| 4828 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4829 | % % |
| 4830 | % % |
| 4831 | % % |
| 4832 | % S t e r e o A n a g l y p h I m a g e % |
| 4833 | % % |
| 4834 | % % |
| 4835 | % % |
| 4836 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4837 | % |
| 4838 | % StereoAnaglyphImage() combines two images and produces a single image that |
| 4839 | % is the composite of a left and right image of a stereo pair. Special |
| 4840 | % red-green stereo glasses are required to view this effect. |
| 4841 | % |
| 4842 | % The format of the StereoAnaglyphImage method is: |
| 4843 | % |
| 4844 | % Image *StereoImage(const Image *left_image,const Image *right_image, |
| 4845 | % ExceptionInfo *exception) |
| 4846 | % Image *StereoAnaglyphImage(const Image *left_image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4847 | % 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] | 4848 | % ExceptionInfo *exception) |
| 4849 | % |
| 4850 | % A description of each parameter follows: |
| 4851 | % |
| 4852 | % o left_image: the left image. |
| 4853 | % |
| 4854 | % o right_image: the right image. |
| 4855 | % |
| 4856 | % o exception: return any errors or warnings in this structure. |
| 4857 | % |
| 4858 | % o x_offset: amount, in pixels, by which the left image is offset to the |
| 4859 | % right of the right image. |
| 4860 | % |
| 4861 | % o y_offset: amount, in pixels, by which the left image is offset to the |
| 4862 | % bottom of the right image. |
| 4863 | % |
| 4864 | % |
| 4865 | */ |
| 4866 | MagickExport Image *StereoImage(const Image *left_image, |
| 4867 | const Image *right_image,ExceptionInfo *exception) |
| 4868 | { |
| 4869 | return(StereoAnaglyphImage(left_image,right_image,0,0,exception)); |
| 4870 | } |
| 4871 | |
| 4872 | MagickExport Image *StereoAnaglyphImage(const Image *left_image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4873 | 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] | 4874 | ExceptionInfo *exception) |
| 4875 | { |
| 4876 | #define StereoImageTag "Stereo/Image" |
| 4877 | |
| 4878 | const Image |
| 4879 | *image; |
| 4880 | |
| 4881 | Image |
| 4882 | *stereo_image; |
| 4883 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4884 | MagickBooleanType |
| 4885 | status; |
| 4886 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 4887 | ssize_t |
| 4888 | y; |
| 4889 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4890 | assert(left_image != (const Image *) NULL); |
| 4891 | assert(left_image->signature == MagickSignature); |
| 4892 | if (left_image->debug != MagickFalse) |
| 4893 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 4894 | left_image->filename); |
| 4895 | assert(right_image != (const Image *) NULL); |
| 4896 | assert(right_image->signature == MagickSignature); |
| 4897 | assert(exception != (ExceptionInfo *) NULL); |
| 4898 | assert(exception->signature == MagickSignature); |
| 4899 | assert(right_image != (const Image *) NULL); |
| 4900 | image=left_image; |
| 4901 | if ((left_image->columns != right_image->columns) || |
| 4902 | (left_image->rows != right_image->rows)) |
| 4903 | ThrowImageException(ImageError,"LeftAndRightImageSizesDiffer"); |
| 4904 | /* |
| 4905 | Initialize stereo image attributes. |
| 4906 | */ |
| 4907 | stereo_image=CloneImage(left_image,left_image->columns,left_image->rows, |
| 4908 | MagickTrue,exception); |
| 4909 | if (stereo_image == (Image *) NULL) |
| 4910 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 4911 | if (SetImageStorageClass(stereo_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4912 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4913 | stereo_image=DestroyImage(stereo_image); |
| 4914 | return((Image *) NULL); |
| 4915 | } |
cristy | 079c78d | 2012-07-03 11:53:48 +0000 | [diff] [blame] | 4916 | (void) SetImageColorspace(stereo_image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4917 | /* |
| 4918 | Copy left image to red channel and right image to blue channel. |
| 4919 | */ |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4920 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4921 | for (y=0; y < (ssize_t) stereo_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4922 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4923 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4924 | *restrict p, |
| 4925 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4926 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4927 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4928 | x; |
| 4929 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4930 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4931 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4932 | |
| 4933 | p=GetVirtualPixels(left_image,-x_offset,y-y_offset,image->columns,1, |
| 4934 | exception); |
| 4935 | q=GetVirtualPixels(right_image,0,y,right_image->columns,1,exception); |
| 4936 | r=QueueAuthenticPixels(stereo_image,0,y,stereo_image->columns,1,exception); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4937 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL) || |
| 4938 | (r == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4939 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4940 | for (x=0; x < (ssize_t) stereo_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4941 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4942 | SetPixelRed(image,GetPixelRed(left_image,p),r); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4943 | SetPixelGreen(image,GetPixelGreen(right_image,q),r); |
| 4944 | SetPixelBlue(image,GetPixelBlue(right_image,q),r); |
| 4945 | if ((GetPixelAlphaTraits(stereo_image) & CopyPixelTrait) != 0) |
| 4946 | SetPixelAlpha(image,(GetPixelAlpha(left_image,p)+ |
| 4947 | GetPixelAlpha(right_image,q))/2,r); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4948 | p+=GetPixelChannels(left_image); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4949 | q+=GetPixelChannels(right_image); |
| 4950 | r+=GetPixelChannels(stereo_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4951 | } |
| 4952 | if (SyncAuthenticPixels(stereo_image,exception) == MagickFalse) |
| 4953 | break; |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4954 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4955 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4956 | MagickBooleanType |
| 4957 | proceed; |
| 4958 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4959 | proceed=SetImageProgress(image,StereoImageTag,(MagickOffsetType) y, |
| 4960 | stereo_image->rows); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 4961 | if (proceed == MagickFalse) |
| 4962 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4963 | } |
| 4964 | } |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 4965 | if (status == MagickFalse) |
cristy | fab8364 | 2012-12-14 00:31:38 +0000 | [diff] [blame] | 4966 | stereo_image=DestroyImage(stereo_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4967 | return(stereo_image); |
| 4968 | } |
| 4969 | |
| 4970 | /* |
| 4971 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4972 | % % |
| 4973 | % % |
| 4974 | % % |
| 4975 | % S w i r l I m a g e % |
| 4976 | % % |
| 4977 | % % |
| 4978 | % % |
| 4979 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4980 | % |
| 4981 | % SwirlImage() swirls the pixels about the center of the image, where |
| 4982 | % degrees indicates the sweep of the arc through which each pixel is moved. |
| 4983 | % You get a more dramatic effect as the degrees move from 1 to 360. |
| 4984 | % |
| 4985 | % The format of the SwirlImage method is: |
| 4986 | % |
| 4987 | % Image *SwirlImage(const Image *image,double degrees, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4988 | % const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4989 | % |
| 4990 | % A description of each parameter follows: |
| 4991 | % |
| 4992 | % o image: the image. |
| 4993 | % |
| 4994 | % o degrees: Define the tightness of the swirling effect. |
| 4995 | % |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 4996 | % o method: the pixel interpolation method. |
| 4997 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4998 | % o exception: return any errors or warnings in this structure. |
| 4999 | % |
| 5000 | */ |
| 5001 | MagickExport Image *SwirlImage(const Image *image,double degrees, |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5002 | const PixelInterpolateMethod method,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5003 | { |
| 5004 | #define SwirlImageTag "Swirl/Image" |
| 5005 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5006 | CacheView |
| 5007 | *image_view, |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5008 | *interpolate_view, |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5009 | *swirl_view; |
| 5010 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5011 | Image |
| 5012 | *swirl_image; |
| 5013 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5014 | MagickBooleanType |
| 5015 | status; |
| 5016 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5017 | MagickOffsetType |
| 5018 | progress; |
| 5019 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5020 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5021 | radius; |
| 5022 | |
| 5023 | PointInfo |
| 5024 | center, |
| 5025 | scale; |
| 5026 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5027 | ssize_t |
| 5028 | y; |
| 5029 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5030 | /* |
| 5031 | Initialize swirl image attributes. |
| 5032 | */ |
| 5033 | assert(image != (const Image *) NULL); |
| 5034 | assert(image->signature == MagickSignature); |
| 5035 | if (image->debug != MagickFalse) |
| 5036 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5037 | assert(exception != (ExceptionInfo *) NULL); |
| 5038 | assert(exception->signature == MagickSignature); |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5039 | swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5040 | if (swirl_image == (Image *) NULL) |
| 5041 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5042 | if (SetImageStorageClass(swirl_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5043 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5044 | swirl_image=DestroyImage(swirl_image); |
| 5045 | return((Image *) NULL); |
| 5046 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5047 | if (swirl_image->background_color.alpha != OpaqueAlpha) |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5048 | swirl_image->alpha_trait=BlendPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5049 | /* |
| 5050 | Compute scaling factor. |
| 5051 | */ |
| 5052 | center.x=(double) image->columns/2.0; |
| 5053 | center.y=(double) image->rows/2.0; |
| 5054 | radius=MagickMax(center.x,center.y); |
| 5055 | scale.x=1.0; |
| 5056 | scale.y=1.0; |
| 5057 | if (image->columns > image->rows) |
| 5058 | scale.y=(double) image->columns/(double) image->rows; |
| 5059 | else |
| 5060 | if (image->columns < image->rows) |
| 5061 | scale.x=(double) image->rows/(double) image->columns; |
| 5062 | degrees=(double) DegreesToRadians(degrees); |
| 5063 | /* |
| 5064 | Swirl image. |
| 5065 | */ |
| 5066 | status=MagickTrue; |
| 5067 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5068 | image_view=AcquireVirtualCacheView(image,exception); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5069 | interpolate_view=AcquireVirtualCacheView(image,exception); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5070 | swirl_view=AcquireAuthenticCacheView(swirl_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5071 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 5072 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 5073 | magick_threads(image,swirl_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5074 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5075 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5076 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5077 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5078 | distance; |
| 5079 | |
| 5080 | PointInfo |
| 5081 | delta; |
| 5082 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5083 | register const Quantum |
| 5084 | *restrict p; |
| 5085 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5086 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5087 | x; |
| 5088 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5089 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5090 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5091 | |
| 5092 | if (status == MagickFalse) |
| 5093 | continue; |
cristy | 1665ce1 | 2013-04-19 12:18:43 +0000 | [diff] [blame] | 5094 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5095 | q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5096 | exception); |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5097 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5098 | { |
| 5099 | status=MagickFalse; |
| 5100 | continue; |
| 5101 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5102 | delta.y=scale.y*(double) (y-center.y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5103 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5104 | { |
| 5105 | /* |
| 5106 | Determine if the pixel is within an ellipse. |
| 5107 | */ |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 5108 | if (GetPixelReadMask(image,p) == 0) |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 5109 | { |
cristy | c3a5802 | 2013-10-09 23:22:42 +0000 | [diff] [blame] | 5110 | SetPixelBackgoundColor(swirl_image,q); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 5111 | p+=GetPixelChannels(image); |
| 5112 | q+=GetPixelChannels(swirl_image); |
| 5113 | continue; |
| 5114 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5115 | delta.x=scale.x*(double) (x-center.x); |
| 5116 | distance=delta.x*delta.x+delta.y*delta.y; |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5117 | if (distance >= (radius*radius)) |
| 5118 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5119 | register ssize_t |
| 5120 | i; |
| 5121 | |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5122 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5123 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5124 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 5125 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 5126 | PixelTrait swirl_traits=GetPixelChannelTraits(swirl_image,channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5127 | if ((traits == UndefinedPixelTrait) || |
| 5128 | (swirl_traits == UndefinedPixelTrait)) |
| 5129 | continue; |
| 5130 | SetPixelChannel(swirl_image,channel,p[i],q); |
| 5131 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5132 | } |
| 5133 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5134 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5135 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5136 | cosine, |
| 5137 | factor, |
| 5138 | sine; |
| 5139 | |
| 5140 | /* |
| 5141 | Swirl the pixel. |
| 5142 | */ |
| 5143 | factor=1.0-sqrt((double) distance)/radius; |
| 5144 | sine=sin((double) (degrees*factor*factor)); |
| 5145 | cosine=cos((double) (degrees*factor*factor)); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5146 | status=InterpolatePixelChannels(image,interpolate_view,swirl_image, |
| 5147 | method,((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double) |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5148 | ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5149 | } |
cristy | 6d18802 | 2011-09-12 13:23:33 +0000 | [diff] [blame] | 5150 | p+=GetPixelChannels(image); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5151 | q+=GetPixelChannels(swirl_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5152 | } |
| 5153 | if (SyncCacheViewAuthenticPixels(swirl_view,exception) == MagickFalse) |
| 5154 | status=MagickFalse; |
| 5155 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5156 | { |
| 5157 | MagickBooleanType |
| 5158 | proceed; |
| 5159 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5160 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5161 | #pragma omp critical (MagickCore_SwirlImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5162 | #endif |
| 5163 | proceed=SetImageProgress(image,SwirlImageTag,progress++,image->rows); |
| 5164 | if (proceed == MagickFalse) |
| 5165 | status=MagickFalse; |
| 5166 | } |
| 5167 | } |
| 5168 | swirl_view=DestroyCacheView(swirl_view); |
cristy | 5ee937c | 2013-04-19 12:55:16 +0000 | [diff] [blame] | 5169 | interpolate_view=DestroyCacheView(interpolate_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5170 | image_view=DestroyCacheView(image_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5171 | if (status == MagickFalse) |
| 5172 | swirl_image=DestroyImage(swirl_image); |
| 5173 | return(swirl_image); |
| 5174 | } |
| 5175 | |
| 5176 | /* |
| 5177 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5178 | % % |
| 5179 | % % |
| 5180 | % % |
| 5181 | % T i n t I m a g e % |
| 5182 | % % |
| 5183 | % % |
| 5184 | % % |
| 5185 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5186 | % |
| 5187 | % TintImage() applies a color vector to each pixel in the image. The length |
| 5188 | % of the vector is 0 for black and white and at its maximum for the midtones. |
| 5189 | % The vector weighting function is f(x)=(1-(4.0*((x-0.5)*(x-0.5)))) |
| 5190 | % |
| 5191 | % The format of the TintImage method is: |
| 5192 | % |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5193 | % Image *TintImage(const Image *image,const char *blend, |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5194 | % const PixelInfo *tint,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5195 | % |
| 5196 | % A description of each parameter follows: |
| 5197 | % |
| 5198 | % o image: the image. |
| 5199 | % |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5200 | % o blend: A color value used for tinting. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5201 | % |
| 5202 | % o tint: A color value used for tinting. |
| 5203 | % |
| 5204 | % o exception: return any errors or warnings in this structure. |
| 5205 | % |
| 5206 | */ |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5207 | MagickExport Image *TintImage(const Image *image,const char *blend, |
cristy | 28474bf | 2011-09-11 23:32:52 +0000 | [diff] [blame] | 5208 | const PixelInfo *tint,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5209 | { |
| 5210 | #define TintImageTag "Tint/Image" |
| 5211 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 5212 | CacheView |
| 5213 | *image_view, |
| 5214 | *tint_view; |
| 5215 | |
cristy | f54150e | 2013-04-11 01:25:47 +0000 | [diff] [blame] | 5216 | double |
| 5217 | intensity; |
| 5218 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5219 | GeometryInfo |
| 5220 | geometry_info; |
| 5221 | |
| 5222 | Image |
| 5223 | *tint_image; |
| 5224 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5225 | MagickBooleanType |
| 5226 | status; |
| 5227 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5228 | MagickOffsetType |
| 5229 | progress; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5230 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5231 | PixelInfo |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5232 | color_vector; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5233 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5234 | MagickStatusType |
| 5235 | flags; |
| 5236 | |
| 5237 | ssize_t |
| 5238 | y; |
| 5239 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5240 | /* |
| 5241 | Allocate tint image. |
| 5242 | */ |
| 5243 | assert(image != (const Image *) NULL); |
| 5244 | assert(image->signature == MagickSignature); |
| 5245 | if (image->debug != MagickFalse) |
| 5246 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5247 | assert(exception != (ExceptionInfo *) NULL); |
| 5248 | assert(exception->signature == MagickSignature); |
| 5249 | tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
| 5250 | if (tint_image == (Image *) NULL) |
| 5251 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5252 | if (SetImageStorageClass(tint_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5253 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5254 | tint_image=DestroyImage(tint_image); |
| 5255 | return((Image *) NULL); |
| 5256 | } |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 5257 | if ((IsGrayColorspace(image->colorspace) != MagickFalse) && |
cristy | 4dab380 | 2013-03-15 22:08:15 +0000 | [diff] [blame] | 5258 | (IsPixelInfoGray(tint) == MagickFalse)) |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 5259 | (void) SetImageColorspace(tint_image,sRGBColorspace,exception); |
cristy | aed9c38 | 2011-10-03 17:54:21 +0000 | [diff] [blame] | 5260 | if (blend == (const char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5261 | return(tint_image); |
| 5262 | /* |
| 5263 | Determine RGB values of the color. |
| 5264 | */ |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5265 | GetPixelInfo(image,&color_vector); |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5266 | flags=ParseGeometry(blend,&geometry_info); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5267 | color_vector.red=geometry_info.rho; |
| 5268 | color_vector.green=geometry_info.rho; |
| 5269 | color_vector.blue=geometry_info.rho; |
cristy | 92ac572 | 2013-03-09 15:09:38 +0000 | [diff] [blame] | 5270 | color_vector.alpha=(MagickRealType) OpaqueAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5271 | if ((flags & SigmaValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5272 | color_vector.green=geometry_info.sigma; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5273 | if ((flags & XiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5274 | color_vector.blue=geometry_info.xi; |
cristy | b817c3f | 2011-10-03 14:00:35 +0000 | [diff] [blame] | 5275 | if ((flags & PsiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5276 | color_vector.alpha=geometry_info.psi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5277 | if (image->colorspace == CMYKColorspace) |
| 5278 | { |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5279 | color_vector.black=geometry_info.rho; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5280 | if ((flags & PsiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5281 | color_vector.black=geometry_info.psi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5282 | if ((flags & ChiValue) != 0) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5283 | color_vector.alpha=geometry_info.chi; |
cristy | 76f512e | 2011-09-12 01:26:56 +0000 | [diff] [blame] | 5284 | } |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5285 | intensity=(double) GetPixelInfoIntensity(tint); |
cristy | f54150e | 2013-04-11 01:25:47 +0000 | [diff] [blame] | 5286 | color_vector.red=(double) (color_vector.red*tint->red/100.0-intensity); |
| 5287 | color_vector.green=(double) (color_vector.green*tint->green/100.0-intensity); |
| 5288 | color_vector.blue=(double) (color_vector.blue*tint->blue/100.0-intensity); |
| 5289 | color_vector.black=(double) (color_vector.black*tint->black/100.0-intensity); |
| 5290 | color_vector.alpha=(double) (color_vector.alpha*tint->alpha/100.0-intensity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5291 | /* |
| 5292 | Tint image. |
| 5293 | */ |
| 5294 | status=MagickTrue; |
| 5295 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5296 | image_view=AcquireVirtualCacheView(image,exception); |
| 5297 | tint_view=AcquireAuthenticCacheView(tint_image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5298 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 5299 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 5300 | magick_threads(image,tint_image,image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5301 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5302 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5303 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5304 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5305 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5306 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5307 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5308 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5309 | |
cristy | 6b91acb | 2011-04-19 12:23:54 +0000 | [diff] [blame] | 5310 | register ssize_t |
| 5311 | x; |
| 5312 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5313 | if (status == MagickFalse) |
| 5314 | continue; |
| 5315 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 5316 | q=QueueCacheViewAuthenticPixels(tint_view,0,y,tint_image->columns,1, |
| 5317 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5318 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5319 | { |
| 5320 | status=MagickFalse; |
| 5321 | continue; |
| 5322 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5323 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5324 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5325 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5326 | pixel; |
| 5327 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5328 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5329 | weight; |
| 5330 | |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5331 | register ssize_t |
| 5332 | i; |
| 5333 | |
| 5334 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 5335 | { |
cristy | 5a23c55 | 2013-02-13 14:34:28 +0000 | [diff] [blame] | 5336 | PixelChannel channel=GetPixelChannelChannel(image,i); |
| 5337 | PixelTrait traits=GetPixelChannelTraits(image,channel); |
| 5338 | PixelTrait tint_traits=GetPixelChannelTraits(tint_image,channel); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5339 | if ((traits == UndefinedPixelTrait) || |
| 5340 | (tint_traits == UndefinedPixelTrait)) |
| 5341 | continue; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5342 | if (((tint_traits & CopyPixelTrait) != 0) || |
cristy | 883fde1 | 2013-04-08 00:50:13 +0000 | [diff] [blame] | 5343 | (GetPixelReadMask(image,p) == 0)) |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5344 | { |
| 5345 | SetPixelChannel(tint_image,channel,p[i],q); |
| 5346 | continue; |
| 5347 | } |
| 5348 | } |
| 5349 | GetPixelInfo(image,&pixel); |
| 5350 | weight=QuantumScale*GetPixelRed(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5351 | pixel.red=(double) GetPixelRed(image,p)+color_vector.red*(1.0-(4.0* |
| 5352 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5353 | weight=QuantumScale*GetPixelGreen(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5354 | pixel.green=(double) GetPixelGreen(image,p)+color_vector.green*(1.0-(4.0* |
| 5355 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5356 | weight=QuantumScale*GetPixelBlue(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5357 | pixel.blue=(double) GetPixelBlue(image,p)+color_vector.blue*(1.0-(4.0* |
| 5358 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5359 | weight=QuantumScale*GetPixelBlack(image,p)-0.5; |
cristy | 1eced09 | 2012-08-10 23:10:56 +0000 | [diff] [blame] | 5360 | pixel.black=(double) GetPixelBlack(image,p)+color_vector.black*(1.0-(4.0* |
| 5361 | (weight*weight))); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5362 | SetPixelInfoPixel(tint_image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5363 | p+=GetPixelChannels(image); |
| 5364 | q+=GetPixelChannels(tint_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5365 | } |
| 5366 | if (SyncCacheViewAuthenticPixels(tint_view,exception) == MagickFalse) |
| 5367 | status=MagickFalse; |
| 5368 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5369 | { |
| 5370 | MagickBooleanType |
| 5371 | proceed; |
| 5372 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5373 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5374 | #pragma omp critical (MagickCore_TintImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5375 | #endif |
| 5376 | proceed=SetImageProgress(image,TintImageTag,progress++,image->rows); |
| 5377 | if (proceed == MagickFalse) |
| 5378 | status=MagickFalse; |
| 5379 | } |
| 5380 | } |
| 5381 | tint_view=DestroyCacheView(tint_view); |
| 5382 | image_view=DestroyCacheView(image_view); |
| 5383 | if (status == MagickFalse) |
| 5384 | tint_image=DestroyImage(tint_image); |
| 5385 | return(tint_image); |
| 5386 | } |
| 5387 | |
| 5388 | /* |
| 5389 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5390 | % % |
| 5391 | % % |
| 5392 | % % |
| 5393 | % V i g n e t t e I m a g e % |
| 5394 | % % |
| 5395 | % % |
| 5396 | % % |
| 5397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5398 | % |
| 5399 | % VignetteImage() softens the edges of the image in vignette style. |
| 5400 | % |
| 5401 | % The format of the VignetteImage method is: |
| 5402 | % |
| 5403 | % Image *VignetteImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5404 | % const double sigma,const ssize_t x,const ssize_t y, |
cristy | 05c0c9a | 2011-09-05 23:16:13 +0000 | [diff] [blame] | 5405 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5406 | % |
| 5407 | % A description of each parameter follows: |
| 5408 | % |
| 5409 | % o image: the image. |
| 5410 | % |
| 5411 | % o radius: the radius of the pixel neighborhood. |
| 5412 | % |
| 5413 | % o sigma: the standard deviation of the Gaussian, in pixels. |
| 5414 | % |
| 5415 | % o x, y: Define the x and y ellipse offset. |
| 5416 | % |
| 5417 | % o exception: return any errors or warnings in this structure. |
| 5418 | % |
| 5419 | */ |
| 5420 | MagickExport Image *VignetteImage(const Image *image,const double radius, |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5421 | const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5422 | { |
| 5423 | char |
| 5424 | ellipse[MaxTextExtent]; |
| 5425 | |
| 5426 | DrawInfo |
| 5427 | *draw_info; |
| 5428 | |
| 5429 | Image |
| 5430 | *canvas_image, |
| 5431 | *blur_image, |
| 5432 | *oval_image, |
| 5433 | *vignette_image; |
| 5434 | |
| 5435 | assert(image != (Image *) NULL); |
| 5436 | assert(image->signature == MagickSignature); |
| 5437 | if (image->debug != MagickFalse) |
| 5438 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5439 | assert(exception != (ExceptionInfo *) NULL); |
| 5440 | assert(exception->signature == MagickSignature); |
| 5441 | canvas_image=CloneImage(image,0,0,MagickTrue,exception); |
| 5442 | if (canvas_image == (Image *) NULL) |
| 5443 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5444 | if (SetImageStorageClass(canvas_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5445 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5446 | canvas_image=DestroyImage(canvas_image); |
| 5447 | return((Image *) NULL); |
| 5448 | } |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5449 | canvas_image->alpha_trait=BlendPixelTrait; |
cristy | 9862146 | 2011-12-31 22:31:11 +0000 | [diff] [blame] | 5450 | oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows, |
| 5451 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5452 | if (oval_image == (Image *) NULL) |
| 5453 | { |
| 5454 | canvas_image=DestroyImage(canvas_image); |
| 5455 | return((Image *) NULL); |
| 5456 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 5457 | (void) QueryColorCompliance("#000000",AllCompliance, |
| 5458 | &oval_image->background_color,exception); |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 5459 | (void) SetImageBackgroundColor(oval_image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5460 | draw_info=CloneDrawInfo((const ImageInfo *) NULL,(const DrawInfo *) NULL); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 5461 | (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->fill, |
| 5462 | exception); |
| 5463 | (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke, |
| 5464 | exception); |
cristy | 1707c6c | 2012-01-18 23:30:54 +0000 | [diff] [blame] | 5465 | (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g," |
| 5466 | "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x, |
| 5467 | image->rows/2.0-y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5468 | draw_info->primitive=AcquireString(ellipse); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 5469 | (void) DrawImage(oval_image,draw_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5470 | draw_info=DestroyDrawInfo(draw_info); |
cristy | aa2c16c | 2012-03-25 22:21:35 +0000 | [diff] [blame] | 5471 | blur_image=BlurImage(oval_image,radius,sigma,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5472 | oval_image=DestroyImage(oval_image); |
| 5473 | if (blur_image == (Image *) NULL) |
| 5474 | { |
| 5475 | canvas_image=DestroyImage(canvas_image); |
| 5476 | return((Image *) NULL); |
| 5477 | } |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5478 | blur_image->alpha_trait=UndefinedPixelTrait; |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 5479 | (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue, |
| 5480 | 0,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5481 | blur_image=DestroyImage(blur_image); |
| 5482 | vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception); |
| 5483 | canvas_image=DestroyImage(canvas_image); |
cristy | 66d2612 | 2012-06-23 21:56:40 +0000 | [diff] [blame] | 5484 | if (vignette_image != (Image *) NULL) |
| 5485 | (void) TransformImageColorspace(vignette_image,image->colorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5486 | return(vignette_image); |
| 5487 | } |
| 5488 | |
| 5489 | /* |
| 5490 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5491 | % % |
| 5492 | % % |
| 5493 | % % |
| 5494 | % W a v e I m a g e % |
| 5495 | % % |
| 5496 | % % |
| 5497 | % % |
| 5498 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5499 | % |
| 5500 | % WaveImage() creates a "ripple" effect in the image by shifting the pixels |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 5501 | % vertically along a sine wave whose amplitude and wavelength is specified |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5502 | % by the given parameters. |
| 5503 | % |
| 5504 | % The format of the WaveImage method is: |
| 5505 | % |
| 5506 | % Image *WaveImage(const Image *image,const double amplitude, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5507 | % const double wave_length,const PixelInterpolateMethod method, |
| 5508 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5509 | % |
| 5510 | % A description of each parameter follows: |
| 5511 | % |
| 5512 | % o image: the image. |
| 5513 | % |
| 5514 | % o amplitude, wave_length: Define the amplitude and wave length of the |
| 5515 | % sine wave. |
| 5516 | % |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5517 | % o interpolate: the pixel interpolation method. |
| 5518 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5519 | % o exception: return any errors or warnings in this structure. |
| 5520 | % |
| 5521 | */ |
| 5522 | MagickExport Image *WaveImage(const Image *image,const double amplitude, |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5523 | const double wave_length,const PixelInterpolateMethod method, |
| 5524 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5525 | { |
| 5526 | #define WaveImageTag "Wave/Image" |
| 5527 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5528 | CacheView |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5529 | *image_view, |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 5530 | *wave_view; |
| 5531 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5532 | Image |
| 5533 | *wave_image; |
| 5534 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5535 | MagickBooleanType |
| 5536 | status; |
| 5537 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5538 | MagickOffsetType |
| 5539 | progress; |
| 5540 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5541 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5542 | *sine_map; |
| 5543 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5544 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5545 | i; |
| 5546 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5547 | ssize_t |
| 5548 | y; |
| 5549 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5550 | /* |
| 5551 | Initialize wave image attributes. |
| 5552 | */ |
| 5553 | assert(image != (Image *) NULL); |
| 5554 | assert(image->signature == MagickSignature); |
| 5555 | if (image->debug != MagickFalse) |
| 5556 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 5557 | assert(exception != (ExceptionInfo *) NULL); |
| 5558 | assert(exception->signature == MagickSignature); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5559 | wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5560 | fabs(amplitude)),MagickTrue,exception); |
| 5561 | if (wave_image == (Image *) NULL) |
| 5562 | return((Image *) NULL); |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 5563 | if (SetImageStorageClass(wave_image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5564 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5565 | wave_image=DestroyImage(wave_image); |
| 5566 | return((Image *) NULL); |
| 5567 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5568 | if (wave_image->background_color.alpha != OpaqueAlpha) |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 5569 | wave_image->alpha_trait=BlendPixelTrait; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5570 | /* |
| 5571 | Allocate sine map. |
| 5572 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5573 | sine_map=(double *) AcquireQuantumMemory((size_t) wave_image->columns, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5574 | sizeof(*sine_map)); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5575 | if (sine_map == (double *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5576 | { |
| 5577 | wave_image=DestroyImage(wave_image); |
| 5578 | ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); |
| 5579 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5580 | for (i=0; i < (ssize_t) wave_image->columns; i++) |
cristy | 4205a3c | 2010-09-12 20:19:59 +0000 | [diff] [blame] | 5581 | sine_map[i]=fabs(amplitude)+amplitude*sin((double) ((2.0*MagickPI*i)/ |
| 5582 | wave_length)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5583 | /* |
| 5584 | Wave image. |
| 5585 | */ |
| 5586 | status=MagickTrue; |
| 5587 | progress=0; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 5588 | image_view=AcquireVirtualCacheView(image,exception); |
| 5589 | wave_view=AcquireAuthenticCacheView(wave_image,exception); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5590 | (void) SetCacheViewVirtualPixelMethod(image_view, |
| 5591 | BackgroundVirtualPixelMethod); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5592 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 5593 | #pragma omp parallel for schedule(static,4) shared(progress,status) \ |
cristy | 5e6b259 | 2012-12-19 14:08:11 +0000 | [diff] [blame] | 5594 | magick_threads(image,wave_image,wave_image->rows,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5595 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5596 | for (y=0; y < (ssize_t) wave_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5597 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 5598 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 5599 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5600 | |
cristy | e97bb92 | 2011-04-03 01:36:52 +0000 | [diff] [blame] | 5601 | register ssize_t |
| 5602 | x; |
| 5603 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5604 | if (status == MagickFalse) |
| 5605 | continue; |
| 5606 | q=QueueCacheViewAuthenticPixels(wave_view,0,y,wave_image->columns,1, |
| 5607 | exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 5608 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5609 | { |
| 5610 | status=MagickFalse; |
| 5611 | continue; |
| 5612 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5613 | for (x=0; x < (ssize_t) wave_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5614 | { |
cristy | 5c4e258 | 2011-09-11 19:21:03 +0000 | [diff] [blame] | 5615 | status=InterpolatePixelChannels(image,image_view,wave_image,method, |
| 5616 | (double) x,(double) (y-sine_map[x]),q,exception); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 5617 | q+=GetPixelChannels(wave_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5618 | } |
| 5619 | if (SyncCacheViewAuthenticPixels(wave_view,exception) == MagickFalse) |
| 5620 | status=MagickFalse; |
| 5621 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 5622 | { |
| 5623 | MagickBooleanType |
| 5624 | proceed; |
| 5625 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 5626 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 69cfa02 | 2012-01-23 12:47:29 +0000 | [diff] [blame] | 5627 | #pragma omp critical (MagickCore_WaveImage) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5628 | #endif |
| 5629 | proceed=SetImageProgress(image,WaveImageTag,progress++,image->rows); |
| 5630 | if (proceed == MagickFalse) |
| 5631 | status=MagickFalse; |
| 5632 | } |
| 5633 | } |
| 5634 | wave_view=DestroyCacheView(wave_view); |
cristy | d76c51e | 2011-03-26 00:21:26 +0000 | [diff] [blame] | 5635 | image_view=DestroyCacheView(image_view); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5636 | sine_map=(double *) RelinquishMagickMemory(sine_map); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5637 | if (status == MagickFalse) |
| 5638 | wave_image=DestroyImage(wave_image); |
| 5639 | return(wave_image); |
| 5640 | } |