| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #include "magick/studio.h" |
|---|
| 44 | #include "magick/color-private.h" |
|---|
| 45 | #include "magick/draw.h" |
|---|
| 46 | #include "magick/gem.h" |
|---|
| 47 | #include "magick/image.h" |
|---|
| 48 | #include "magick/image-private.h" |
|---|
| 49 | #include "magick/log.h" |
|---|
| 50 | #include "magick/memory_.h" |
|---|
| 51 | #include "magick/pixel-private.h" |
|---|
| 52 | #include "magick/quantum.h" |
|---|
| 53 | #include "magick/random_.h" |
|---|
| 54 | #include "magick/resize.h" |
|---|
| 55 | #include "magick/transform.h" |
|---|
| 56 | #include "magick/signature-private.h" |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | MagickExport void ConvertHSBToRGB(const double hue,const double saturation, |
|---|
| 86 | const double brightness,Quantum *red,Quantum *green,Quantum *blue) |
|---|
| 87 | { |
|---|
| 88 | MagickRealType |
|---|
| 89 | f, |
|---|
| 90 | h, |
|---|
| 91 | p, |
|---|
| 92 | q, |
|---|
| 93 | t; |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | assert(red != (Quantum *) NULL); |
|---|
| 99 | assert(green != (Quantum *) NULL); |
|---|
| 100 | assert(blue != (Quantum *) NULL); |
|---|
| 101 | if (saturation == 0.0) |
|---|
| 102 | { |
|---|
| 103 | *red=RoundToQuantum((MagickRealType) QuantumRange*brightness); |
|---|
| 104 | *green=(*red); |
|---|
| 105 | *blue=(*red); |
|---|
| 106 | return; |
|---|
| 107 | } |
|---|
| 108 | h=6.0*(hue-floor(hue)); |
|---|
| 109 | f=h-floor((double) h); |
|---|
| 110 | p=brightness*(1.0-saturation); |
|---|
| 111 | q=brightness*(1.0-saturation*f); |
|---|
| 112 | t=brightness*(1.0-(saturation*(1.0-f))); |
|---|
| 113 | switch ((int) h) |
|---|
| 114 | { |
|---|
| 115 | case 0: |
|---|
| 116 | default: |
|---|
| 117 | { |
|---|
| 118 | *red=RoundToQuantum((MagickRealType) QuantumRange*brightness); |
|---|
| 119 | *green=RoundToQuantum((MagickRealType) QuantumRange*t); |
|---|
| 120 | *blue=RoundToQuantum((MagickRealType) QuantumRange*p); |
|---|
| 121 | break; |
|---|
| 122 | } |
|---|
| 123 | case 1: |
|---|
| 124 | { |
|---|
| 125 | *red=RoundToQuantum((MagickRealType) QuantumRange*q); |
|---|
| 126 | *green=RoundToQuantum((MagickRealType) QuantumRange*brightness); |
|---|
| 127 | *blue=RoundToQuantum((MagickRealType) QuantumRange*p); |
|---|
| 128 | break; |
|---|
| 129 | } |
|---|
| 130 | case 2: |
|---|
| 131 | { |
|---|
| 132 | *red=RoundToQuantum((MagickRealType) QuantumRange*p); |
|---|
| 133 | *green=RoundToQuantum((MagickRealType) QuantumRange*brightness); |
|---|
| 134 | *blue=RoundToQuantum((MagickRealType) QuantumRange*t); |
|---|
| 135 | break; |
|---|
| 136 | } |
|---|
| 137 | case 3: |
|---|
| 138 | { |
|---|
| 139 | *red=RoundToQuantum((MagickRealType) QuantumRange*p); |
|---|
| 140 | *green=RoundToQuantum((MagickRealType) QuantumRange*q); |
|---|
| 141 | *blue=RoundToQuantum((MagickRealType) QuantumRange*brightness); |
|---|
| 142 | break; |
|---|
| 143 | } |
|---|
| 144 | case 4: |
|---|
| 145 | { |
|---|
| 146 | *red=RoundToQuantum((MagickRealType) QuantumRange*t); |
|---|
| 147 | *green=RoundToQuantum((MagickRealType) QuantumRange*p); |
|---|
| 148 | *blue=RoundToQuantum((MagickRealType) QuantumRange*brightness); |
|---|
| 149 | break; |
|---|
| 150 | } |
|---|
| 151 | case 5: |
|---|
| 152 | { |
|---|
| 153 | *red=RoundToQuantum((MagickRealType) QuantumRange*brightness); |
|---|
| 154 | *green=RoundToQuantum((MagickRealType) QuantumRange*p); |
|---|
| 155 | *blue=RoundToQuantum((MagickRealType) QuantumRange*q); |
|---|
| 156 | break; |
|---|
| 157 | } |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | static inline MagickRealType ConvertHueToRGB(MagickRealType m1, |
|---|
| 190 | MagickRealType m2,MagickRealType hue) |
|---|
| 191 | { |
|---|
| 192 | if (hue < 0.0) |
|---|
| 193 | hue+=1.0; |
|---|
| 194 | if (hue > 1.0) |
|---|
| 195 | hue-=1.0; |
|---|
| 196 | if ((6.0*hue) < 1.0) |
|---|
| 197 | return(m1+6.0*(m2-m1)*hue); |
|---|
| 198 | if ((2.0*hue) < 1.0) |
|---|
| 199 | return(m2); |
|---|
| 200 | if ((3.0*hue) < 2.0) |
|---|
| 201 | return(m1+6.0*(m2-m1)*(2.0/3.0-hue)); |
|---|
| 202 | return(m1); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | MagickExport void ConvertHSLToRGB(const double hue,const double saturation, |
|---|
| 206 | const double lightness,Quantum *red,Quantum *green,Quantum *blue) |
|---|
| 207 | { |
|---|
| 208 | MagickRealType |
|---|
| 209 | b, |
|---|
| 210 | g, |
|---|
| 211 | r, |
|---|
| 212 | m1, |
|---|
| 213 | m2; |
|---|
| 214 | |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | assert(red != (Quantum *) NULL); |
|---|
| 219 | assert(green != (Quantum *) NULL); |
|---|
| 220 | assert(blue != (Quantum *) NULL); |
|---|
| 221 | if (saturation == 0) |
|---|
| 222 | { |
|---|
| 223 | *red=RoundToQuantum((MagickRealType) QuantumRange*lightness); |
|---|
| 224 | *green=(*red); |
|---|
| 225 | *blue=(*red); |
|---|
| 226 | return; |
|---|
| 227 | } |
|---|
| 228 | if (lightness <= 0.5) |
|---|
| 229 | m2=lightness*(saturation+1.0); |
|---|
| 230 | else |
|---|
| 231 | m2=(lightness+saturation)-(lightness*saturation); |
|---|
| 232 | m1=2.0*lightness-m2; |
|---|
| 233 | r=ConvertHueToRGB(m1,m2,hue+1.0/3.0); |
|---|
| 234 | g=ConvertHueToRGB(m1,m2,hue); |
|---|
| 235 | b=ConvertHueToRGB(m1,m2,hue-1.0/3.0); |
|---|
| 236 | *red=RoundToQuantum((MagickRealType) QuantumRange*r); |
|---|
| 237 | *green=RoundToQuantum((MagickRealType) QuantumRange*g); |
|---|
| 238 | *blue=RoundToQuantum((MagickRealType) QuantumRange*b); |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | |
|---|
| 256 | |
|---|
| 257 | |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | |
|---|
| 261 | |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | MagickExport void ConvertHWBToRGB(const double hue,const double whiteness, |
|---|
| 269 | const double blackness,Quantum *red,Quantum *green,Quantum *blue) |
|---|
| 270 | { |
|---|
| 271 | MagickRealType |
|---|
| 272 | b, |
|---|
| 273 | f, |
|---|
| 274 | g, |
|---|
| 275 | n, |
|---|
| 276 | r, |
|---|
| 277 | v; |
|---|
| 278 | |
|---|
| 279 | register long |
|---|
| 280 | i; |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | assert(red != (Quantum *) NULL); |
|---|
| 286 | assert(green != (Quantum *) NULL); |
|---|
| 287 | assert(blue != (Quantum *) NULL); |
|---|
| 288 | v=1.0-blackness; |
|---|
| 289 | if (hue == 0.0) |
|---|
| 290 | { |
|---|
| 291 | *red=RoundToQuantum((MagickRealType) QuantumRange*v); |
|---|
| 292 | *green=RoundToQuantum((MagickRealType) QuantumRange*v); |
|---|
| 293 | *blue=RoundToQuantum((MagickRealType) QuantumRange*v); |
|---|
| 294 | return; |
|---|
| 295 | } |
|---|
| 296 | i=(long) floor(6.0*hue); |
|---|
| 297 | f=6.0*hue-i; |
|---|
| 298 | if ((i & 0x01) != 0) |
|---|
| 299 | f=1.0-f; |
|---|
| 300 | n=whiteness+f*(v-whiteness); |
|---|
| 301 | switch (i) |
|---|
| 302 | { |
|---|
| 303 | default: |
|---|
| 304 | case 6: |
|---|
| 305 | case 0: r=v; g=n; b=whiteness; break; |
|---|
| 306 | case 1: r=n; g=v; b=whiteness; break; |
|---|
| 307 | case 2: r=whiteness; g=v; b=n; break; |
|---|
| 308 | case 3: r=whiteness; g=n; b=v; break; |
|---|
| 309 | case 4: r=n; g=whiteness; b=v; break; |
|---|
| 310 | case 5: r=v; g=whiteness; b=n; break; |
|---|
| 311 | } |
|---|
| 312 | *red=RoundToQuantum((MagickRealType) QuantumRange*r); |
|---|
| 313 | *green=RoundToQuantum((MagickRealType) QuantumRange*g); |
|---|
| 314 | *blue=RoundToQuantum((MagickRealType) QuantumRange*b); |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | |
|---|
| 330 | |
|---|
| 331 | |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | |
|---|
| 335 | |
|---|
| 336 | |
|---|
| 337 | |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | |
|---|
| 343 | |
|---|
| 344 | |
|---|
| 345 | MagickExport void ConvertRGBToHSB(const Quantum red,const Quantum green, |
|---|
| 346 | const Quantum blue,double *hue,double *saturation,double *brightness) |
|---|
| 347 | { |
|---|
| 348 | MagickRealType |
|---|
| 349 | delta, |
|---|
| 350 | max, |
|---|
| 351 | min; |
|---|
| 352 | |
|---|
| 353 | |
|---|
| 354 | |
|---|
| 355 | |
|---|
| 356 | assert(hue != (double *) NULL); |
|---|
| 357 | assert(saturation != (double *) NULL); |
|---|
| 358 | assert(brightness != (double *) NULL); |
|---|
| 359 | *hue=0.0; |
|---|
| 360 | *saturation=0.0; |
|---|
| 361 | *brightness=0.0; |
|---|
| 362 | min=(MagickRealType) (red < green ? red : green); |
|---|
| 363 | if ((MagickRealType) blue < min) |
|---|
| 364 | min=(MagickRealType) blue; |
|---|
| 365 | max=(MagickRealType) (red > green ? red : green); |
|---|
| 366 | if ((MagickRealType) blue > max) |
|---|
| 367 | max=(MagickRealType) blue; |
|---|
| 368 | if (max == 0.0) |
|---|
| 369 | return; |
|---|
| 370 | delta=max-min; |
|---|
| 371 | *saturation=(double) (delta/max); |
|---|
| 372 | *brightness=(double) (QuantumScale*max); |
|---|
| 373 | if (delta == 0.0) |
|---|
| 374 | return; |
|---|
| 375 | if ((MagickRealType) red == max) |
|---|
| 376 | *hue=(double) ((green-(MagickRealType) blue)/delta); |
|---|
| 377 | else |
|---|
| 378 | if ((MagickRealType) green == max) |
|---|
| 379 | *hue=(double) (2.0+(blue-(MagickRealType) red)/delta); |
|---|
| 380 | else |
|---|
| 381 | *hue=(double) (4.0+(red-(MagickRealType) green)/delta); |
|---|
| 382 | *hue/=6.0; |
|---|
| 383 | if (*hue < 0.0) |
|---|
| 384 | *hue+=1.0; |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | |
|---|
| 389 | |
|---|
| 390 | |
|---|
| 391 | |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | |
|---|
| 395 | |
|---|
| 396 | |
|---|
| 397 | |
|---|
| 398 | |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | |
|---|
| 402 | |
|---|
| 403 | |
|---|
| 404 | |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | |
|---|
| 408 | |
|---|
| 409 | |
|---|
| 410 | |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | static inline double MagickMax(const double x,const double y) |
|---|
| 417 | { |
|---|
| 418 | if (x > y) |
|---|
| 419 | return(x); |
|---|
| 420 | return(y); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | static inline double MagickMin(const double x,const double y) |
|---|
| 424 | { |
|---|
| 425 | if (x < y) |
|---|
| 426 | return(x); |
|---|
| 427 | return(y); |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | MagickExport void ConvertRGBToHSL(const Quantum red,const Quantum green, |
|---|
| 431 | const Quantum blue,double *hue,double *saturation,double *lightness) |
|---|
| 432 | { |
|---|
| 433 | MagickRealType |
|---|
| 434 | b, |
|---|
| 435 | delta, |
|---|
| 436 | g, |
|---|
| 437 | max, |
|---|
| 438 | min, |
|---|
| 439 | r; |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | assert(hue != (double *) NULL); |
|---|
| 445 | assert(saturation != (double *) NULL); |
|---|
| 446 | assert(lightness != (double *) NULL); |
|---|
| 447 | r=QuantumScale*red; |
|---|
| 448 | g=QuantumScale*green; |
|---|
| 449 | b=QuantumScale*blue; |
|---|
| 450 | max=MagickMax(r,MagickMax(g,b)); |
|---|
| 451 | min=MagickMin(r,MagickMin(g,b)); |
|---|
| 452 | *lightness=(double) ((min+max)/2.0); |
|---|
| 453 | delta=max-min; |
|---|
| 454 | if (delta == 0.0) |
|---|
| 455 | { |
|---|
| 456 | *hue=0.0; |
|---|
| 457 | *saturation=0.0; |
|---|
| 458 | return; |
|---|
| 459 | } |
|---|
| 460 | if (*lightness < 0.5) |
|---|
| 461 | *saturation=(double) (delta/(min+max)); |
|---|
| 462 | else |
|---|
| 463 | *saturation=(double) (delta/(2.0-max-min)); |
|---|
| 464 | if (r == max) |
|---|
| 465 | *hue=((((max-b)/6.0)+(delta/2.0))-(((max-g)/6.0)+(delta/2.0)))/delta; |
|---|
| 466 | else |
|---|
| 467 | if (g == max) |
|---|
| 468 | *hue=(1.0/3.0)+((((max-r)/6.0)+(delta/2.0))-(((max-b)/6.0)+(delta/2.0)))/ |
|---|
| 469 | delta; |
|---|
| 470 | else |
|---|
| 471 | if (b == max) |
|---|
| 472 | *hue=(2.0/3.0)+((((max-g)/6.0)+(delta/2.0))-(((max-r)/6.0)+ |
|---|
| 473 | (delta/2.0)))/delta; |
|---|
| 474 | if (*hue < 0.0) |
|---|
| 475 | *hue+=1.0; |
|---|
| 476 | if (*hue > 1.0) |
|---|
| 477 | *hue-=1.0; |
|---|
| 478 | } |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | |
|---|
| 485 | |
|---|
| 486 | |
|---|
| 487 | |
|---|
| 488 | |
|---|
| 489 | |
|---|
| 490 | |
|---|
| 491 | |
|---|
| 492 | |
|---|
| 493 | |
|---|
| 494 | |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | |
|---|
| 498 | |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | |
|---|
| 502 | |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | |
|---|
| 508 | MagickExport void ConvertRGBToHWB(const Quantum red,const Quantum green, |
|---|
| 509 | const Quantum blue,double *hue,double *whiteness,double *blackness) |
|---|
| 510 | { |
|---|
| 511 | MagickRealType |
|---|
| 512 | f, |
|---|
| 513 | v, |
|---|
| 514 | w; |
|---|
| 515 | |
|---|
| 516 | register long |
|---|
| 517 | i; |
|---|
| 518 | |
|---|
| 519 | |
|---|
| 520 | |
|---|
| 521 | |
|---|
| 522 | assert(hue != (double *) NULL); |
|---|
| 523 | assert(whiteness != (double *) NULL); |
|---|
| 524 | assert(blackness != (double *) NULL); |
|---|
| 525 | w=(MagickRealType) MagickMin((double) red,MagickMin((double) green,(double) |
|---|
| 526 | blue)); |
|---|
| 527 | v=(MagickRealType) MagickMax((double) red,MagickMax((double) green,(double) |
|---|
| 528 | blue)); |
|---|
| 529 | *blackness=1.0-QuantumScale*v; |
|---|
| 530 | *whiteness=QuantumScale*w; |
|---|
| 531 | if (v == w) |
|---|
| 532 | { |
|---|
| 533 | *hue=0.0; |
|---|
| 534 | return; |
|---|
| 535 | } |
|---|
| 536 | f=((MagickRealType) red == w) ? green-(MagickRealType) blue : |
|---|
| 537 | (((MagickRealType) green == w) ? blue-(MagickRealType) red : red- |
|---|
| 538 | (MagickRealType) green); |
|---|
| 539 | i=((MagickRealType) red == w) ? 3 : (((MagickRealType) green == w) ? 5 : 1); |
|---|
| 540 | *hue=((double) i-f/(v-1.0*w))/6.0; |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | |
|---|
| 544 | |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | |
|---|
| 549 | |
|---|
| 550 | |
|---|
| 551 | |
|---|
| 552 | |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | |
|---|
| 557 | |
|---|
| 558 | |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | |
|---|
| 562 | |
|---|
| 563 | |
|---|
| 564 | |
|---|
| 565 | |
|---|
| 566 | |
|---|
| 567 | |
|---|
| 568 | |
|---|
| 569 | |
|---|
| 570 | MagickExport double ExpandAffine(const AffineMatrix *affine) |
|---|
| 571 | { |
|---|
| 572 | assert(affine != (const AffineMatrix *) NULL); |
|---|
| 573 | return(sqrt(fabs(affine->sx*affine->sy-affine->rx*affine->ry))); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | |
|---|
| 577 | |
|---|
| 578 | |
|---|
| 579 | |
|---|
| 580 | |
|---|
| 581 | |
|---|
| 582 | |
|---|
| 583 | |
|---|
| 584 | |
|---|
| 585 | |
|---|
| 586 | |
|---|
| 587 | |
|---|
| 588 | |
|---|
| 589 | |
|---|
| 590 | |
|---|
| 591 | |
|---|
| 592 | |
|---|
| 593 | |
|---|
| 594 | |
|---|
| 595 | |
|---|
| 596 | |
|---|
| 597 | |
|---|
| 598 | |
|---|
| 599 | |
|---|
| 600 | |
|---|
| 601 | |
|---|
| 602 | |
|---|
| 603 | |
|---|
| 604 | |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | MagickExport unsigned long GetOptimalKernelWidth1D(const double radius, |
|---|
| 608 | const double sigma) |
|---|
| 609 | { |
|---|
| 610 | long |
|---|
| 611 | width; |
|---|
| 612 | |
|---|
| 613 | MagickRealType |
|---|
| 614 | normalize, |
|---|
| 615 | value; |
|---|
| 616 | |
|---|
| 617 | register long |
|---|
| 618 | u; |
|---|
| 619 | |
|---|
| 620 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 621 | if (radius > 0.0) |
|---|
| 622 | return((unsigned long) (2.0*ceil(radius)+1.0)); |
|---|
| 623 | if (fabs(sigma) <= MagickEpsilon) |
|---|
| 624 | return(1); |
|---|
| 625 | for (width=5; ; ) |
|---|
| 626 | { |
|---|
| 627 | normalize=0.0; |
|---|
| 628 | for (u=(-width/2); u <= (width/2); u++) |
|---|
| 629 | normalize+=exp(-((double) u*u)/(2.0*sigma*sigma))/(MagickSQ2PI*sigma); |
|---|
| 630 | u=width/2; |
|---|
| 631 | value=exp(-((double) u*u)/(2.0*sigma*sigma))/(MagickSQ2PI*sigma)/normalize; |
|---|
| 632 | if ((long) (QuantumRange*value) <= 0L) |
|---|
| 633 | break; |
|---|
| 634 | width+=2; |
|---|
| 635 | } |
|---|
| 636 | return((unsigned long) (width-2)); |
|---|
| 637 | } |
|---|
| 638 | |
|---|
| 639 | MagickExport unsigned long GetOptimalKernelWidth2D(const double radius, |
|---|
| 640 | const double sigma) |
|---|
| 641 | { |
|---|
| 642 | |
|---|
| 643 | long |
|---|
| 644 | width; |
|---|
| 645 | |
|---|
| 646 | MagickRealType |
|---|
| 647 | alpha, |
|---|
| 648 | normalize, |
|---|
| 649 | value; |
|---|
| 650 | |
|---|
| 651 | register long |
|---|
| 652 | u, |
|---|
| 653 | v; |
|---|
| 654 | |
|---|
| 655 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 656 | if (radius > 0.0) |
|---|
| 657 | return((unsigned long) (2.0*ceil(radius)+1.0)); |
|---|
| 658 | if (fabs(sigma) <= MagickEpsilon) |
|---|
| 659 | return(1); |
|---|
| 660 | for (width=5; ; ) |
|---|
| 661 | { |
|---|
| 662 | normalize=0.0; |
|---|
| 663 | for (v=(-width/2); v <= (width/2); v++) |
|---|
| 664 | { |
|---|
| 665 | for (u=(-width/2); u <= (width/2); u++) |
|---|
| 666 | { |
|---|
| 667 | alpha=exp(-((double) u*u+v*v)/(2.0*sigma*sigma)); |
|---|
| 668 | normalize+=alpha/(2.0*MagickPI*sigma*sigma); |
|---|
| 669 | } |
|---|
| 670 | } |
|---|
| 671 | v=width/2; |
|---|
| 672 | value=exp(-((double) v*v)/(2.0*sigma*sigma))/(MagickSQ2PI*sigma)/normalize; |
|---|
| 673 | if ((long) (QuantumRange*value) <= 0L) |
|---|
| 674 | break; |
|---|
| 675 | width+=2; |
|---|
| 676 | } |
|---|
| 677 | return((unsigned long) (width-2)); |
|---|
| 678 | } |
|---|
| 679 | |
|---|
| 680 | MagickExport unsigned long GetOptimalKernelWidth(const double radius, |
|---|
| 681 | const double sigma) |
|---|
| 682 | { |
|---|
| 683 | return(GetOptimalKernelWidth1D(radius,sigma)); |
|---|
| 684 | } |
|---|