| 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/cache-view.h" |
|---|
| 45 | #include "magick/color.h" |
|---|
| 46 | #include "magick/color-private.h" |
|---|
| 47 | #include "magick/colorspace.h" |
|---|
| 48 | #include "magick/enhance.h" |
|---|
| 49 | #include "magick/exception.h" |
|---|
| 50 | #include "magick/exception-private.h" |
|---|
| 51 | #include "magick/gem.h" |
|---|
| 52 | #include "magick/geometry.h" |
|---|
| 53 | #include "magick/image.h" |
|---|
| 54 | #include "magick/image-private.h" |
|---|
| 55 | #include "magick/memory_.h" |
|---|
| 56 | #include "magick/monitor.h" |
|---|
| 57 | #include "magick/monitor-private.h" |
|---|
| 58 | #include "magick/quantum.h" |
|---|
| 59 | #include "magick/quantum-private.h" |
|---|
| 60 | #include "magick/resample.h" |
|---|
| 61 | #include "magick/string_.h" |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | |
|---|
| 83 | |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | |
|---|
| 90 | |
|---|
| 91 | |
|---|
| 92 | static ResampleFilter **DestroyResampleFilterThreadSet(ResampleFilter **filter) |
|---|
| 93 | { |
|---|
| 94 | register long |
|---|
| 95 | i; |
|---|
| 96 | |
|---|
| 97 | assert(filter != (ResampleFilter **) NULL); |
|---|
| 98 | for (i=0; i < (long) GetCacheViewMaximumThreads(); i++) |
|---|
| 99 | if (filter[i] != (ResampleFilter *) NULL) |
|---|
| 100 | filter[i]=DestroyResampleFilter(filter[i]); |
|---|
| 101 | return((ResampleFilter **) RelinquishMagickMemory(filter)); |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | static ResampleFilter **AcquireResampleFilterThreadSet(const Image *image, |
|---|
| 105 | ExceptionInfo *exception) |
|---|
| 106 | { |
|---|
| 107 | register long |
|---|
| 108 | i; |
|---|
| 109 | |
|---|
| 110 | ResampleFilter |
|---|
| 111 | **filter; |
|---|
| 112 | |
|---|
| 113 | filter=(ResampleFilter **) AcquireQuantumMemory(GetCacheViewMaximumThreads(), |
|---|
| 114 | sizeof(*filter)); |
|---|
| 115 | if (filter == (ResampleFilter **) NULL) |
|---|
| 116 | return((ResampleFilter **) NULL); |
|---|
| 117 | (void) ResetMagickMemory(filter,0,GetCacheViewMaximumThreads()* |
|---|
| 118 | sizeof(*filter)); |
|---|
| 119 | for (i=0; i < (long) GetCacheViewMaximumThreads(); i++) |
|---|
| 120 | { |
|---|
| 121 | filter[i]=AcquireResampleFilter(image,exception); |
|---|
| 122 | if (filter[i] == (ResampleFilter *) NULL) |
|---|
| 123 | return(DestroyResampleFilterThreadSet(filter)); |
|---|
| 124 | } |
|---|
| 125 | return(filter); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | MagickExport MagickBooleanType ClutImage(Image *image,const Image *clut_image) |
|---|
| 129 | { |
|---|
| 130 | return(ClutImageChannel(image,DefaultChannels,clut_image)); |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | MagickExport MagickBooleanType ClutImageChannel(Image *image, |
|---|
| 134 | const ChannelType channel,const Image *clut_image) |
|---|
| 135 | { |
|---|
| 136 | #define ClutImageTag "Clut/Image" |
|---|
| 137 | |
|---|
| 138 | long |
|---|
| 139 | adjust, |
|---|
| 140 | progress, |
|---|
| 141 | y; |
|---|
| 142 | |
|---|
| 143 | MagickBooleanType |
|---|
| 144 | status; |
|---|
| 145 | |
|---|
| 146 | ResampleFilter |
|---|
| 147 | **resample_filter; |
|---|
| 148 | |
|---|
| 149 | ViewInfo |
|---|
| 150 | **image_view; |
|---|
| 151 | |
|---|
| 152 | assert(image != (Image *) NULL); |
|---|
| 153 | assert(image->signature == MagickSignature); |
|---|
| 154 | if (image->debug != MagickFalse) |
|---|
| 155 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 156 | assert(clut_image != (Image *) NULL); |
|---|
| 157 | assert(clut_image->signature == MagickSignature); |
|---|
| 158 | if (SetImageStorageClass(image,DirectClass) == MagickFalse) |
|---|
| 159 | return(MagickFalse); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | status=MagickTrue; |
|---|
| 164 | progress=0; |
|---|
| 165 | adjust=clut_image->interpolate == IntegerInterpolatePixel ? 0 : 1; |
|---|
| 166 | resample_filter=AcquireResampleFilterThreadSet(clut_image,&image->exception); |
|---|
| 167 | image_view=AcquireCacheViewThreadSet(image); |
|---|
| 168 | #pragma omp parallel for |
|---|
| 169 | for (y=0; y < (long) image->rows; y++) |
|---|
| 170 | { |
|---|
| 171 | MagickPixelPacket |
|---|
| 172 | pixel; |
|---|
| 173 | |
|---|
| 174 | register IndexPacket |
|---|
| 175 | *indexes; |
|---|
| 176 | |
|---|
| 177 | register long |
|---|
| 178 | id, |
|---|
| 179 | x; |
|---|
| 180 | |
|---|
| 181 | register PixelPacket |
|---|
| 182 | *q; |
|---|
| 183 | |
|---|
| 184 | if (status == MagickFalse) |
|---|
| 185 | continue; |
|---|
| 186 | id=GetCacheViewThreadId(); |
|---|
| 187 | q=GetCacheViewPixels(image_view[id],0,y,image->columns,1); |
|---|
| 188 | if (q == (PixelPacket *) NULL) |
|---|
| 189 | { |
|---|
| 190 | status=MagickFalse; |
|---|
| 191 | continue; |
|---|
| 192 | } |
|---|
| 193 | indexes=GetCacheViewIndexes(image_view[id]); |
|---|
| 194 | GetMagickPixelPacket(clut_image,&pixel); |
|---|
| 195 | for (x=0; x < (long) image->columns; x++) |
|---|
| 196 | { |
|---|
| 197 | if ((channel & RedChannel) != 0) |
|---|
| 198 | { |
|---|
| 199 | pixel=ResamplePixelColor(resample_filter[id],QuantumScale*q->red* |
|---|
| 200 | (clut_image->columns-adjust),QuantumScale*q->red* |
|---|
| 201 | (clut_image->rows-adjust)); |
|---|
| 202 | q->red=RoundToQuantum(pixel.red); |
|---|
| 203 | } |
|---|
| 204 | if ((channel & GreenChannel) != 0) |
|---|
| 205 | { |
|---|
| 206 | pixel=ResamplePixelColor(resample_filter[id],QuantumScale*q->green* |
|---|
| 207 | (clut_image->columns-adjust),QuantumScale*q->green* |
|---|
| 208 | (clut_image->rows-adjust)); |
|---|
| 209 | q->green=RoundToQuantum(pixel.green); |
|---|
| 210 | } |
|---|
| 211 | if ((channel & BlueChannel) != 0) |
|---|
| 212 | { |
|---|
| 213 | pixel=ResamplePixelColor(resample_filter[id],QuantumScale*q->blue* |
|---|
| 214 | (clut_image->columns-adjust),QuantumScale*q->blue* |
|---|
| 215 | (clut_image->rows-adjust)); |
|---|
| 216 | q->blue=RoundToQuantum(pixel.blue); |
|---|
| 217 | } |
|---|
| 218 | if ((channel & OpacityChannel) != 0) |
|---|
| 219 | { |
|---|
| 220 | if (clut_image->matte == MagickFalse) |
|---|
| 221 | { |
|---|
| 222 | |
|---|
| 223 | |
|---|
| 224 | |
|---|
| 225 | pixel=ResamplePixelColor(resample_filter[id],QuantumScale* |
|---|
| 226 | (QuantumRange-q->opacity)*(clut_image->columns+adjust), |
|---|
| 227 | QuantumScale*(QuantumRange-q->opacity)*(clut_image->rows+ |
|---|
| 228 | adjust)); |
|---|
| 229 | q->opacity=(Quantum) (QuantumRange-MagickPixelIntensityToQuantum( |
|---|
| 230 | &pixel)); |
|---|
| 231 | } |
|---|
| 232 | else |
|---|
| 233 | if (image->matte == MagickFalse) |
|---|
| 234 | { |
|---|
| 235 | |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | pixel=ResamplePixelColor(resample_filter[id],QuantumScale* |
|---|
| 239 | PixelIntensity(q)*(clut_image->columns-adjust),QuantumScale* |
|---|
| 240 | PixelIntensity(q)*(clut_image->rows-adjust)); |
|---|
| 241 | q->opacity=RoundToQuantum(pixel.opacity); |
|---|
| 242 | } |
|---|
| 243 | else |
|---|
| 244 | { |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | pixel=ResamplePixelColor(resample_filter[id],QuantumScale* |
|---|
| 249 | q->opacity*(clut_image->columns-adjust),QuantumScale* |
|---|
| 250 | q->opacity* (clut_image->rows-adjust)); |
|---|
| 251 | q->opacity=RoundToQuantum(pixel.opacity); |
|---|
| 252 | } |
|---|
| 253 | } |
|---|
| 254 | if (((channel & IndexChannel) != 0) && |
|---|
| 255 | (image->colorspace == CMYKColorspace)) |
|---|
| 256 | { |
|---|
| 257 | pixel=ResamplePixelColor(resample_filter[id],QuantumScale*indexes[x]* |
|---|
| 258 | (clut_image->columns-adjust),QuantumScale*indexes[x]* |
|---|
| 259 | (clut_image->rows-adjust)); |
|---|
| 260 | indexes[x]=RoundToQuantum(pixel.index); |
|---|
| 261 | } |
|---|
| 262 | q++; |
|---|
| 263 | } |
|---|
| 264 | if (SyncCacheView(image_view[id]) == MagickFalse) |
|---|
| 265 | status=MagickFalse; |
|---|
| 266 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
|---|
| 267 | { |
|---|
| 268 | MagickBooleanType |
|---|
| 269 | proceed; |
|---|
| 270 | |
|---|
| 271 | #pragma omp critical |
|---|
| 272 | proceed=SetImageProgress(image,ClutImageTag,progress++,image->rows); |
|---|
| 273 | if (proceed == MagickFalse) |
|---|
| 274 | status=MagickFalse; |
|---|
| 275 | } |
|---|
| 276 | } |
|---|
| 277 | image_view=DestroyCacheViewThreadSet(image_view); |
|---|
| 278 | resample_filter=DestroyResampleFilterThreadSet(resample_filter); |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | if ((clut_image->matte == MagickTrue) && ((channel & OpacityChannel) != 0)) |
|---|
| 283 | (void) SetImageAlphaChannel(image,ActivateAlphaChannel); |
|---|
| 284 | return(status); |
|---|
| 285 | } |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | |
|---|
| 303 | |
|---|
| 304 | |
|---|
| 305 | |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | static void Contrast(const int sign,Quantum *red,Quantum *green,Quantum *blue) |
|---|
| 316 | { |
|---|
| 317 | double |
|---|
| 318 | brightness, |
|---|
| 319 | hue, |
|---|
| 320 | saturation; |
|---|
| 321 | |
|---|
| 322 | |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | assert(red != (Quantum *) NULL); |
|---|
| 326 | assert(green != (Quantum *) NULL); |
|---|
| 327 | assert(blue != (Quantum *) NULL); |
|---|
| 328 | hue=0.0; |
|---|
| 329 | saturation=0.0; |
|---|
| 330 | brightness=0.0; |
|---|
| 331 | ConvertRGBToHSB(*red,*green,*blue,&hue,&saturation,&brightness); |
|---|
| 332 | brightness+=0.5*sign*(0.5*(sin(MagickPI*(brightness-0.5))+1.0)-brightness); |
|---|
| 333 | if (brightness > 1.0) |
|---|
| 334 | brightness=1.0; |
|---|
| 335 | else |
|---|
| 336 | if (brightness < 0.0) |
|---|
| 337 | brightness=0.0; |
|---|
| 338 | ConvertHSBToRGB(hue,saturation,brightness,red,green,blue); |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | MagickExport MagickBooleanType ContrastImage(Image *image, |
|---|
| 342 | const MagickBooleanType sharpen) |
|---|
| 343 | { |
|---|
| 344 | #define ContrastImageTag "Contrast/Image" |
|---|
| 345 | |
|---|
| 346 | int |
|---|
| 347 | sign; |
|---|
| 348 | |
|---|
| 349 | long |
|---|
| 350 | progress, |
|---|
| 351 | y; |
|---|
| 352 | |
|---|
| 353 | MagickBooleanType |
|---|
| 354 | status; |
|---|
| 355 | |
|---|
| 356 | register long |
|---|
| 357 | i; |
|---|
| 358 | |
|---|
| 359 | ViewInfo |
|---|
| 360 | **image_view; |
|---|
| 361 | |
|---|
| 362 | assert(image != (Image *) NULL); |
|---|
| 363 | assert(image->signature == MagickSignature); |
|---|
| 364 | if (image->debug != MagickFalse) |
|---|
| 365 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 366 | sign=sharpen != MagickFalse ? 1 : -1; |
|---|
| 367 | if (image->storage_class == PseudoClass) |
|---|
| 368 | { |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | for (i=0; i < (long) image->colors; i++) |
|---|
| 373 | Contrast(sign,&image->colormap[i].red,&image->colormap[i].green, |
|---|
| 374 | &image->colormap[i].blue); |
|---|
| 375 | } |
|---|
| 376 | |
|---|
| 377 | |
|---|
| 378 | |
|---|
| 379 | status=MagickTrue; |
|---|
| 380 | progress=0; |
|---|
| 381 | image_view=AcquireCacheViewThreadSet(image); |
|---|
| 382 | #pragma omp parallel for |
|---|
| 383 | for (y=0; y < (long) image->rows; y++) |
|---|
| 384 | { |
|---|
| 385 | register long |
|---|
| 386 | id, |
|---|
| 387 | x; |
|---|
| 388 | |
|---|
| 389 | register PixelPacket |
|---|
| 390 | *q; |
|---|
| 391 | |
|---|
| 392 | if (status == MagickFalse) |
|---|
| 393 | continue; |
|---|
| 394 | id=GetCacheViewThreadId(); |
|---|
| 395 | q=GetCacheViewPixels(image_view[id],0,y,image->columns,1); |
|---|
| 396 | if (q == (PixelPacket *) NULL) |
|---|
| 397 | { |
|---|
| 398 | status=MagickFalse; |
|---|
| 399 | continue; |
|---|
| 400 | } |
|---|
| 401 | for (x=0; x < (long) image->columns; x++) |
|---|
| 402 | { |
|---|
| 403 | Contrast(sign,&q->red,&q->green,&q->blue); |
|---|
| 404 | q++; |
|---|
| 405 | } |
|---|
| 406 | if (SyncCacheView(image_view[id]) == MagickFalse) |
|---|
| 407 | status=MagickFalse; |
|---|
| 408 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
|---|
| 409 | { |
|---|
| 410 | MagickBooleanType |
|---|
| 411 | proceed; |
|---|
| 412 | |
|---|
| 413 | #pragma omp critical |
|---|
| 414 | proceed=SetImageProgress(image,ContrastImageTag,progress++,image->rows); |
|---|
| 415 | if (proceed == MagickFalse) |
|---|
| 416 | status=MagickFalse; |
|---|
| 417 | } |
|---|
| 418 | } |
|---|
| 419 | image_view=DestroyCacheViewThreadSet(image_view); |
|---|
| 420 | return(status); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | |
|---|
| 426 | |
|---|
| 427 | |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | |
|---|
| 433 | |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | |
|---|
| 437 | |
|---|
| 438 | |
|---|
| 439 | |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | |
|---|
| 443 | |
|---|
| 444 | |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | |
|---|
| 450 | |
|---|
| 451 | |
|---|
| 452 | |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | |
|---|
| 459 | |
|---|
| 460 | |
|---|
| 461 | |
|---|
| 462 | |
|---|
| 463 | |
|---|
| 464 | MagickExport MagickBooleanType ContrastStretchImage(Image *image, |
|---|
| 465 | const char *levels) |
|---|
| 466 | { |
|---|
| 467 | double |
|---|
| 468 | black_point, |
|---|
| 469 | white_point; |
|---|
| 470 | |
|---|
| 471 | GeometryInfo |
|---|
| 472 | geometry_info; |
|---|
| 473 | |
|---|
| 474 | MagickBooleanType |
|---|
| 475 | status; |
|---|
| 476 | |
|---|
| 477 | MagickStatusType |
|---|
| 478 | flags; |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | if (levels == (char *) NULL) |
|---|
| 484 | return(MagickFalse); |
|---|
| 485 | flags=ParseGeometry(levels,&geometry_info); |
|---|
| 486 | black_point=geometry_info.rho; |
|---|
| 487 | white_point=(double) image->columns*image->rows; |
|---|
| 488 | if ((flags & SigmaValue) != 0) |
|---|
| 489 | white_point=geometry_info.sigma; |
|---|
| 490 | if ((flags & PercentValue) != 0) |
|---|
| 491 | { |
|---|
| 492 | black_point*=(double) QuantumRange/100.0; |
|---|
| 493 | white_point*=(double) QuantumRange/100.0; |
|---|
| 494 | } |
|---|
| 495 | if ((flags & SigmaValue) == 0) |
|---|
| 496 | white_point=(double) image->columns*image->rows-black_point; |
|---|
| 497 | status=ContrastStretchImageChannel(image,DefaultChannels,black_point, |
|---|
| 498 | white_point); |
|---|
| 499 | return(status); |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | MagickExport MagickBooleanType ContrastStretchImageChannel(Image *image, |
|---|
| 503 | const ChannelType channel,const double black_point,const double white_point) |
|---|
| 504 | { |
|---|
| 505 | #define MaxRange(color) ((MagickRealType) ScaleQuantumToMap((Quantum) (color))) |
|---|
| 506 | #define ContrastStretchImageTag "ContrastStretch/Image" |
|---|
| 507 | |
|---|
| 508 | double |
|---|
| 509 | intensity; |
|---|
| 510 | |
|---|
| 511 | long |
|---|
| 512 | progress, |
|---|
| 513 | y; |
|---|
| 514 | |
|---|
| 515 | MagickBooleanType |
|---|
| 516 | status; |
|---|
| 517 | |
|---|
| 518 | MagickPixelPacket |
|---|
| 519 | black, |
|---|
| 520 | *histogram, |
|---|
| 521 | *stretch_map, |
|---|
| 522 | white; |
|---|
| 523 | |
|---|
| 524 | register long |
|---|
| 525 | i; |
|---|
| 526 | |
|---|
| 527 | ViewInfo |
|---|
| 528 | **image_view; |
|---|
| 529 | |
|---|
| 530 | |
|---|
| 531 | |
|---|
| 532 | |
|---|
| 533 | assert(image != (Image *) NULL); |
|---|
| 534 | assert(image->signature == MagickSignature); |
|---|
| 535 | if (image->debug != MagickFalse) |
|---|
| 536 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 537 | histogram=(MagickPixelPacket *) AcquireQuantumMemory(MaxMap+1UL, |
|---|
| 538 | sizeof(*histogram)); |
|---|
| 539 | stretch_map=(MagickPixelPacket *) AcquireQuantumMemory(MaxMap+1UL, |
|---|
| 540 | sizeof(*stretch_map)); |
|---|
| 541 | if ((histogram == (MagickPixelPacket *) NULL) || |
|---|
| 542 | (stretch_map == (MagickPixelPacket *) NULL)) |
|---|
| 543 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
|---|
| 544 | image->filename); |
|---|
| 545 | |
|---|
| 546 | |
|---|
| 547 | |
|---|
| 548 | status=MagickTrue; |
|---|
| 549 | (void) ResetMagickMemory(histogram,0,(MaxMap+1)*sizeof(*histogram)); |
|---|
| 550 | image_view=AcquireCacheViewThreadSet(image); |
|---|
| 551 | #pragma omp parallel for |
|---|
| 552 | for (y=0; y < (long) image->rows; y++) |
|---|
| 553 | { |
|---|
| 554 | IndexPacket |
|---|
| 555 | *indexes; |
|---|
| 556 | |
|---|
| 557 | register const PixelPacket |
|---|
| 558 | *p; |
|---|
| 559 | |
|---|
| 560 | register long |
|---|
| 561 | id, |
|---|
| 562 | x; |
|---|
| 563 | |
|---|
| 564 | if (status == MagickFalse) |
|---|
| 565 | continue; |
|---|
| 566 | id=GetCacheViewThreadId(); |
|---|
| 567 | p=AcquireCacheViewPixels(image_view[id],0,y,image->columns,1, |
|---|
| 568 | &image->exception); |
|---|
| 569 | if (p == (const PixelPacket *) NULL) |
|---|
| 570 | { |
|---|
| 571 | status=MagickFalse; |
|---|
| 572 | continue; |
|---|
| 573 | } |
|---|
| 574 | indexes=GetCacheViewIndexes(image_view[id]); |
|---|
| 575 | if (channel == DefaultChannels) |
|---|
| 576 | #pragma omp parallel for |
|---|
| 577 | for (x=0; x < (long) image->columns; x++) |
|---|
| 578 | { |
|---|
| 579 | Quantum |
|---|
| 580 | intensity; |
|---|
| 581 | |
|---|
| 582 | intensity=PixelIntensityToQuantum(p+x); |
|---|
| 583 | histogram[ScaleQuantumToMap(intensity)].red++; |
|---|
| 584 | histogram[ScaleQuantumToMap(intensity)].green++; |
|---|
| 585 | histogram[ScaleQuantumToMap(intensity)].blue++; |
|---|
| 586 | histogram[ScaleQuantumToMap(intensity)].index++; |
|---|
| 587 | } |
|---|
| 588 | else |
|---|
| 589 | #pragma omp parallel for |
|---|
| 590 | for (x=0; x < (long) image->columns; x++) |
|---|
| 591 | { |
|---|
| 592 | if ((channel & RedChannel) != 0) |
|---|
| 593 | histogram[ScaleQuantumToMap((p+x)->red)].red++; |
|---|
| 594 | if ((channel & GreenChannel) != 0) |
|---|
| 595 | histogram[ScaleQuantumToMap((p+x)->green)].green++; |
|---|
| 596 | if ((channel & BlueChannel) != 0) |
|---|
| 597 | histogram[ScaleQuantumToMap((p+x)->blue)].blue++; |
|---|
| 598 | if ((channel & OpacityChannel) != 0) |
|---|
| 599 | histogram[ScaleQuantumToMap((p+x)->opacity)].opacity++; |
|---|
| 600 | if (((channel & IndexChannel) != 0) && |
|---|
| 601 | (image->colorspace == CMYKColorspace)) |
|---|
| 602 | histogram[ScaleQuantumToMap(indexes[x])].index++; |
|---|
| 603 | } |
|---|
| 604 | } |
|---|
| 605 | |
|---|
| 606 | |
|---|
| 607 | |
|---|
| 608 | black.red=0.0; |
|---|
| 609 | white.red=MaxRange(QuantumRange); |
|---|
| 610 | if ((channel & RedChannel) != 0) |
|---|
| 611 | { |
|---|
| 612 | intensity=0.0; |
|---|
| 613 | for (i=0; i <= (long) MaxMap; i++) |
|---|
| 614 | { |
|---|
| 615 | intensity+=histogram[i].red; |
|---|
| 616 | if (intensity > black_point) |
|---|
| 617 | break; |
|---|
| 618 | } |
|---|
| 619 | black.red=(MagickRealType) i; |
|---|
| 620 | intensity=0.0; |
|---|
| 621 | for (i=(long) MaxMap; i != 0; i--) |
|---|
| 622 | { |
|---|
| 623 | intensity+=histogram[i].red; |
|---|
| 624 | if (intensity > ((double) image->columns*image->rows-white_point)) |
|---|
| 625 | break; |
|---|
| 626 | } |
|---|
| 627 | white.red=(MagickRealType) i; |
|---|
| 628 | } |
|---|
| 629 | black.green=0.0; |
|---|
| 630 | white.green=MaxRange(QuantumRange); |
|---|
| 631 | if ((channel & GreenChannel) != 0) |
|---|
| 632 | { |
|---|
| 633 | intensity=0.0; |
|---|
| 634 | for (i=0; i <= (long) MaxMap; i++) |
|---|
| 635 | { |
|---|
| 636 | intensity+=histogram[i].green; |
|---|
| 637 | if (intensity > black_point) |
|---|
| 638 | break; |
|---|
| 639 | } |
|---|
| 640 | black.green=(MagickRealType) i; |
|---|
| 641 | intensity=0.0; |
|---|
| 642 | for (i=(long) MaxMap; i != 0; i--) |
|---|
| 643 | { |
|---|
| 644 | intensity+=histogram[i].green; |
|---|
| 645 | if (intensity > ((double) image->columns*image->rows-white_point)) |
|---|
| 646 | break; |
|---|
| 647 | } |
|---|
| 648 | white.green=(MagickRealType) i; |
|---|
| 649 | } |
|---|
| 650 | black.blue=0.0; |
|---|
| 651 | white.blue=MaxRange(QuantumRange); |
|---|
| 652 | if ((channel & BlueChannel) != 0) |
|---|
| 653 | { |
|---|
| 654 | intensity=0.0; |
|---|
| 655 | for (i=0; i <= (long) MaxMap; i++) |
|---|
| 656 | { |
|---|
| 657 | intensity+=histogram[i].blue; |
|---|
| 658 | if (intensity > black_point) |
|---|
| 659 | break; |
|---|
| 660 | } |
|---|
| 661 | black.blue=(MagickRealType) i; |
|---|
| 662 | intensity=0.0; |
|---|
| 663 | for (i=(long) MaxMap; i != 0; i--) |
|---|
| 664 | { |
|---|
| 665 | intensity+=histogram[i].blue; |
|---|
| 666 | if (intensity > ((double) image->columns*image->rows-white_point)) |
|---|
| 667 | break; |
|---|
| 668 | } |
|---|
| 669 | white.blue=(MagickRealType) i; |
|---|
| 670 | } |
|---|
| 671 | black.opacity=0.0; |
|---|
| 672 | white.opacity=MaxRange(QuantumRange); |
|---|
| 673 | if ((channel & OpacityChannel) != 0) |
|---|
| 674 | { |
|---|
| 675 | intensity=0.0; |
|---|
| 676 | for (i=0; i <= (long) MaxMap; i++) |
|---|
| 677 | { |
|---|
| 678 | intensity+=histogram[i].opacity; |
|---|
| 679 | if (intensity > black_point) |
|---|
| 680 | break; |
|---|
| 681 | } |
|---|
| 682 | black.opacity=(MagickRealType) i; |
|---|
| 683 | intensity=0.0; |
|---|
| 684 | for (i=(long) MaxMap; i != 0; i--) |
|---|
| 685 | { |
|---|
| 686 | intensity+=histogram[i].opacity; |
|---|
| 687 | if (intensity > ((double) image->columns*image->rows-white_point)) |
|---|
| 688 | break; |
|---|
| 689 | } |
|---|
| 690 | white.opacity=(MagickRealType) i; |
|---|
| 691 | } |
|---|
| 692 | black.index=0.0; |
|---|
| 693 | white.index=MaxRange(QuantumRange); |
|---|
| 694 | if (((channel & IndexChannel) != 0) && (image->colorspace == CMYKColorspace)) |
|---|
| 695 | { |
|---|
| 696 | intensity=0.0; |
|---|
| 697 | for (i=0; i <= (long) MaxMap; i++) |
|---|
| 698 | { |
|---|
| 699 | intensity+=histogram[i].index; |
|---|
| 700 | if (intensity > black_point) |
|---|
| 701 | break; |
|---|
| 702 | } |
|---|
| 703 | black.index=(MagickRealType) i; |
|---|
| 704 | intensity=0.0; |
|---|
| 705 | for (i=(long) MaxMap; i != 0; i--) |
|---|
| 706 | { |
|---|
| 707 | intensity+=histogram[i].index; |
|---|
| 708 | if (intensity > ((double) image->columns*image->rows-white_point)) |
|---|
| 709 | break; |
|---|
| 710 | } |
|---|
| 711 | white.index=(MagickRealType) i; |
|---|
| 712 | } |
|---|
| 713 | histogram=(MagickPixelPacket *) RelinquishMagickMemory(histogram); |
|---|
| 714 | |
|---|
| 715 | |
|---|
| 716 | |
|---|
| 717 | (void) ResetMagickMemory(stretch_map,0,(MaxMap+1)*sizeof(*stretch_map)); |
|---|
| 718 | #pragma omp parallel for |
|---|
| 719 | for (i=0; i <= (long) MaxMap; i++) |
|---|
| 720 | { |
|---|
| 721 | if ((channel & RedChannel) != 0) |
|---|
| 722 | { |
|---|
| 723 | if (i < (long) black.red) |
|---|
| 724 | stretch_map[i].red=0.0; |
|---|
| 725 | else |
|---|
| 726 | if (i > (long) white.red) |
|---|
| 727 | stretch_map[i].red=(MagickRealType) QuantumRange; |
|---|
| 728 | else |
|---|
| 729 | if (black.red != white.red) |
|---|
| 730 | stretch_map[i].red=(MagickRealType) ScaleMapToQuantum( |
|---|
| 731 | (MagickRealType) (MaxMap*(i-black.red)/(white.red-black.red))); |
|---|
| 732 | } |
|---|
| 733 | if ((channel & GreenChannel) != 0) |
|---|
| 734 | { |
|---|
| 735 | if (i < (long) black.green) |
|---|
| 736 | stretch_map[i].green=0.0; |
|---|
| 737 | else |
|---|
| 738 | if (i > (long) white.green) |
|---|
| 739 | stretch_map[i].green=(MagickRealType) QuantumRange; |
|---|
| 740 | else |
|---|
| 741 | if (black.green != white.green) |
|---|
| 742 | stretch_map[i].green=(MagickRealType) ScaleMapToQuantum( |
|---|
| 743 | (MagickRealType) (MaxMap*(i-black.green)/(white.green- |
|---|
| 744 | black.green))); |
|---|
| 745 | } |
|---|
| 746 | if ((channel & BlueChannel) != 0) |
|---|
| 747 | { |
|---|
| 748 | if (i < (long) black.blue) |
|---|
| 749 | stretch_map[i].blue=0.0; |
|---|
| 750 | else |
|---|
| 751 | if (i > (long) white.blue) |
|---|
| 752 | stretch_map[i].blue=(MagickRealType) QuantumRange; |
|---|
| 753 | else |
|---|
| 754 | if (black.blue != white.blue) |
|---|
| 755 | stretch_map[i].blue=(MagickRealType) ScaleMapToQuantum( |
|---|
| 756 | (MagickRealType) (MaxMap*(i-black.blue)/(white.blue- |
|---|
| 757 | black.blue))); |
|---|
| 758 | } |
|---|
| 759 | if ((channel & OpacityChannel) != 0) |
|---|
| 760 | { |
|---|
| 761 | if (i < (long) black.opacity) |
|---|
| 762 | stretch_map[i].opacity=0.0; |
|---|
| 763 | else |
|---|
| 764 | if (i > (long) white.opacity) |
|---|
| 765 | stretch_map[i].opacity=(MagickRealType) QuantumRange; |
|---|
| 766 | else |
|---|
| 767 | if (black.opacity != white.opacity) |
|---|
| 768 | stretch_map[i].opacity=(MagickRealType) ScaleMapToQuantum( |
|---|
| 769 | (MagickRealType) (MaxMap*(i-black.opacity)/(white.opacity- |
|---|
| 770 | black.opacity))); |
|---|
| 771 | } |
|---|
| 772 | if (((channel & IndexChannel) != 0) && |
|---|
| 773 | (image->colorspace == CMYKColorspace)) |
|---|
| 774 | { |
|---|
| 775 | if (i < (long) black.index) |
|---|
| 776 | stretch_map[i].index=0.0; |
|---|
| 777 | else |
|---|
| 778 | if (i > (long) white.index) |
|---|
| 779 | stretch_map[i].index=(MagickRealType) QuantumRange; |
|---|
| 780 | else |
|---|
| 781 | if (black.index != white.index) |
|---|
| 782 | stretch_map[i].index=(MagickRealType) ScaleMapToQuantum( |
|---|
| 783 | (MagickRealType) (MaxMap*(i-black.index)/(white.index- |
|---|
| 784 | black.index))); |
|---|
| 785 | } |
|---|
| 786 | } |
|---|
| 787 | |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | if (((channel & OpacityChannel) != 0) || (((channel & IndexChannel) != 0) && |
|---|
| 791 | (image->colorspace == CMYKColorspace))) |
|---|
| 792 | image->storage_class=DirectClass; |
|---|
| 793 | if (image->storage_class == PseudoClass) |
|---|
| 794 | { |
|---|
| 795 | |
|---|
| 796 | |
|---|
| 797 | |
|---|
| 798 | #pragma omp parallel for |
|---|
| 799 | for (i=0; i < (long) image->colors; i++) |
|---|
| 800 | { |
|---|
| 801 | if ((channel & RedChannel) != 0) |
|---|
| 802 | { |
|---|
| 803 | if (black.red != white.red) |
|---|
| 804 | image->colormap[i].red=RoundToQuantum(stretch_map[ |
|---|
| 805 | ScaleQuantumToMap(image->colormap[i].red)].red); |
|---|
| 806 | } |
|---|
| 807 | if ((channel & GreenChannel) != 0) |
|---|
| 808 | { |
|---|
| 809 | if (black.green != white.green) |
|---|
| 810 | image->colormap[i].green=RoundToQuantum(stretch_map[ |
|---|
| 811 | ScaleQuantumToMap(image->colormap[i].green)].green); |
|---|
| 812 | } |
|---|
| 813 | if ((channel & BlueChannel) != 0) |
|---|
| 814 | { |
|---|
| 815 | if (black.blue != white.blue) |
|---|
| 816 | image->colormap[i].blue=RoundToQuantum(stretch_map[ |
|---|
| 817 | ScaleQuantumToMap(image->colormap[i].blue)].blue); |
|---|
| 818 | } |
|---|
| 819 | if ((channel & OpacityChannel) != 0) |
|---|
| 820 | { |
|---|
| 821 | if (black.opacity != white.opacity) |
|---|
| 822 | image->colormap[i].opacity=RoundToQuantum(stretch_map[ |
|---|
| 823 | ScaleQuantumToMap(image->colormap[i].opacity)].opacity); |
|---|
| 824 | } |
|---|
| 825 | } |
|---|
| 826 | } |
|---|
| 827 | |
|---|
| 828 | |
|---|
| 829 | |
|---|
| 830 | status=MagickTrue; |
|---|
| 831 | progress=0; |
|---|
| 832 | #pragma omp parallel for |
|---|
| 833 | for (y=0; y < (long) image->rows; y++) |
|---|
| 834 | { |
|---|
| 835 | IndexPacket |
|---|
| 836 | *indexes; |
|---|
| 837 | |
|---|
| 838 | register long |
|---|
| 839 | id, |
|---|
| 840 | x; |
|---|
| 841 | |
|---|
| 842 | register PixelPacket |
|---|
| 843 | *q; |
|---|
| 844 | |
|---|
| 845 | if (status == MagickFalse) |
|---|
| 846 | continue; |
|---|
| 847 | id=GetCacheViewThreadId(); |
|---|
| 848 | q=GetCacheViewPixels(image_view[id],0,y,image->columns,1); |
|---|
| 849 | if (q == (PixelPacket *) NULL) |
|---|
| 850 | { |
|---|
| 851 | status=MagickFalse; |
|---|
| 852 | continue; |
|---|
| 853 | } |
|---|
| 854 | indexes=GetCacheViewIndexes(image_view[id]); |
|---|
| 855 | for (x=0; x < (long) image->columns; x++) |
|---|
| 856 | { |
|---|
| 857 | if ((channel & RedChannel) != 0) |
|---|
| 858 | { |
|---|
| 859 | if (black.red != white.red) |
|---|
| 860 | q->red=RoundToQuantum(stretch_map[ScaleQuantumToMap( |
|---|
| 861 | q->red)].red); |
|---|
| 862 | } |
|---|
| 863 | if ((channel & GreenChannel) != 0) |
|---|
| 864 | { |
|---|
| 865 | if (black.green != white.green) |
|---|
| 866 | q->green=RoundToQuantum(stretch_map[ScaleQuantumToMap( |
|---|
| 867 | q->green)].green); |
|---|
| 868 | } |
|---|
| 869 | if ((channel & BlueChannel) != 0) |
|---|
| 870 | { |
|---|
| 871 | if (black.blue != white.blue) |
|---|
| 872 | q->blue=RoundToQuantum(stretch_map[ScaleQuantumToMap( |
|---|
| 873 | q->blue)].blue); |
|---|
| 874 | } |
|---|
| 875 | if ((channel & OpacityChannel) != 0) |
|---|
| 876 | { |
|---|
| 877 | if (black.opacity != white.opacity) |
|---|
| 878 | q->opacity=RoundToQuantum(stretch_map[ScaleQuantumToMap( |
|---|
| 879 | q->opacity)].opacity); |
|---|
| 880 | } |
|---|
| 881 | if (((channel & IndexChannel) != 0) && |
|---|
| 882 | (image->colorspace == CMYKColorspace)) |
|---|
| 883 | { |
|---|
| 884 | if (black.index != white.index) |
|---|
| 885 | indexes[x]=(IndexPacket) RoundToQuantum(stretch_map[ |
|---|
| 886 | ScaleQuantumToMap(indexes[x])].index); |
|---|
| 887 | } |
|---|
| 888 | q++; |
|---|
| 889 | } |
|---|
| 890 | if (SyncCacheView(image_view[id]) == MagickFalse) |
|---|
| 891 | status=MagickFalse; |
|---|
| 892 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
|---|
| 893 | { |
|---|
| 894 | MagickBooleanType |
|---|
| 895 | proceed; |
|---|
| 896 | |
|---|
| 897 | #pragma omp critical |
|---|
| 898 | proceed=SetImageProgress(image,ContrastStretchImageTag,progress++, |
|---|
| 899 | image->rows); |
|---|
| 900 | if (proceed == MagickFalse) |
|---|
| 901 | status=MagickFalse; |
|---|
| 902 | } |
|---|
| 903 | } |
|---|
| 904 | image_view=DestroyCacheViewThreadSet(image_view); |
|---|
| 905 | stretch_map=(MagickPixelPacket *) RelinquishMagickMemory(stretch_map); |
|---|
| 906 | return(status); |
|---|
| 907 | } |
|---|
| 908 | |
|---|
| 909 | |
|---|
| 910 | |
|---|
| 911 | |
|---|
| 912 | |
|---|
| 913 | |
|---|
| 914 | |
|---|
| 915 | |
|---|
| 916 | |
|---|
| 917 | |
|---|
| 918 | |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | |
|---|
| 923 | |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | MagickExport Image *EnhanceImage(const Image *image,ExceptionInfo *exception) |
|---|
| 935 | { |
|---|
| 936 | #define Enhance(weight) \ |
|---|
| 937 | mean=((MagickRealType) r->red+pixel.red)/2; \ |
|---|
| 938 | distance=(MagickRealType) r->red-(MagickRealType) pixel.red; \ |
|---|
| 939 | distance_squared=QuantumScale*(2.0*((MagickRealType) QuantumRange+1.0)+ \ |
|---|
| 940 | mean)*distance*distance; \ |
|---|
| 941 | mean=((MagickRealType) r->green+pixel.green)/2; \ |
|---|
| 942 | distance=(MagickRealType) r->green-(MagickRealType) pixel.green; \ |
|---|
| 943 | distance_squared+=4.0*distance*distance; \ |
|---|
| 944 | mean=((MagickRealType) r->blue+pixel.blue)/2; \ |
|---|
| 945 | distance=(MagickRealType) r->blue-(MagickRealType) pixel.blue; \ |
|---|
| 946 | distance_squared+=QuantumScale*(3.0*((MagickRealType) \ |
|---|
| 947 | QuantumRange+1.0)-1.0-mean)*distance*distance; \ |
|---|
| 948 | mean=((MagickRealType) r->opacity+pixel.opacity)/2; \ |
|---|
| 949 | distance=(MagickRealType) r->opacity-(MagickRealType) pixel.opacity; \ |
|---|
| 950 | distance_squared+=QuantumScale*(3.0*((MagickRealType) \ |
|---|
| 951 | QuantumRange+1.0)-1.0-mean)*distance*distance; \ |
|---|
| 952 | if (distance_squared < ((MagickRealType) QuantumRange*(MagickRealType) \ |
|---|
| 953 | QuantumRange/25.0f)) \ |
|---|
| 954 | { \ |
|---|
| 955 | aggregate.red+=(weight)*r->red; \ |
|---|
| 956 | aggregate.green+=(weight)*r->green; \ |
|---|
| 957 | aggregate.blue+=(weight)*r->blue; \ |
|---|
| 958 | aggregate.opacity+=(weight)*r->opacity; \ |
|---|
| 959 | total_weight+=(weight); \ |
|---|
| 960 | } \ |
|---|
| 961 | r++; |
|---|
| 962 | #define EnhanceImageTag "Enhance/Image" |
|---|
| 963 | |
|---|
| 964 | Image |
|---|
| 965 | *enhance_image; |
|---|
| 966 | |
|---|
| 967 | long |
|---|
| 968 | progress, |
|---|
| 969 | y; |
|---|
| 970 | |
|---|
| 971 | MagickBooleanType |
|---|
| 972 | status; |
|---|
| 973 | |
|---|
| 974 | MagickPixelPacket |
|---|
| 975 | zero; |
|---|
| 976 | |
|---|
| 977 | ViewInfo |
|---|
| 978 | **enhance_view, |
|---|
| 979 | **image_view; |
|---|
| 980 | |
|---|
| 981 | |
|---|
| 982 | |
|---|
| 983 | |
|---|
| 984 | assert(image != (const Image *) NULL); |
|---|
| 985 | assert(image->signature == MagickSignature); |
|---|
| 986 | if (image->debug != MagickFalse) |
|---|
| 987 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 988 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 989 | assert(exception->signature == MagickSignature); |
|---|
| 990 | if ((image->columns < 5) || (image->rows < 5)) |
|---|
| 991 | return((Image *) NULL); |
|---|
| 992 | enhance_image=CloneImage(image,0,0,MagickTrue,exception); |
|---|
| 993 | if (enhance_image == (Image *) NULL) |
|---|
| 994 | return((Image *) NULL); |
|---|
| 995 | if (SetImageStorageClass(enhance_image,DirectClass) == MagickFalse) |
|---|
| 996 | { |
|---|
| 997 | InheritException(exception,&enhance_image->exception); |
|---|
| 998 | enhance_image=DestroyImage(enhance_image); |
|---|
| 999 | return((Image *) NULL); |
|---|
| 1000 | } |
|---|
| 1001 | |
|---|
| 1002 | |
|---|
| 1003 | |
|---|
| 1004 | status=MagickTrue; |
|---|
| 1005 | progress=0; |
|---|
| 1006 | (void) ResetMagickMemory(&zero,0,sizeof(zero)); |
|---|
| 1007 | image_view=AcquireCacheViewThreadSet(image); |
|---|
| 1008 | enhance_view=AcquireCacheViewThreadSet(enhance_image); |
|---|
| 1009 | #pragma omp parallel for |
|---|
| 1010 | for (y=0; y < (long) image->rows; y++) |
|---|
| 1011 | { |
|---|
| 1012 | register const PixelPacket |
|---|
| 1013 | *p; |
|---|
| 1014 | |
|---|
| 1015 | register long |
|---|
| 1016 | id, |
|---|
| 1017 | x; |
|---|
| 1018 | |
|---|
| 1019 | register PixelPacket |
|---|
| 1020 | *q; |
|---|
| 1021 | |
|---|
| 1022 | |
|---|
| 1023 | |
|---|
| 1024 | |
|---|
| 1025 | if (status == MagickFalse) |
|---|
| 1026 | continue; |
|---|
| 1027 | id=GetCacheViewThreadId(); |
|---|
| 1028 | p=AcquireCacheViewPixels(image_view[id],-2,y-2,image->columns+4,5, |
|---|
| 1029 | exception); |
|---|
| 1030 | q=GetCacheViewPixels(enhance_view[id],0,y,enhance_image->columns,1); |
|---|
| 1031 | if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) |
|---|
| 1032 | { |
|---|
| 1033 | status=MagickFalse; |
|---|
| 1034 | continue; |
|---|
| 1035 | } |
|---|
| 1036 | for (x=0; x < (long) image->columns; x++) |
|---|
| 1037 | { |
|---|
| 1038 | MagickPixelPacket |
|---|
| 1039 | aggregate; |
|---|
| 1040 | |
|---|
| 1041 | MagickRealType |
|---|
| 1042 | distance, |
|---|
| 1043 | distance_squared, |
|---|
| 1044 | mean, |
|---|
| 1045 | total_weight; |
|---|
| 1046 | |
|---|
| 1047 | PixelPacket |
|---|
| 1048 | pixel; |
|---|
| 1049 | |
|---|
| 1050 | register const PixelPacket |
|---|
| 1051 | *r; |
|---|
| 1052 | |
|---|
| 1053 | |
|---|
| 1054 | |
|---|
| 1055 | |
|---|
| 1056 | aggregate=zero; |
|---|
| 1057 | total_weight=0.0; |
|---|
| 1058 | r=p+2*(image->columns+4)+2; |
|---|
| 1059 | pixel=(*r); |
|---|
| 1060 | r=p; |
|---|
| 1061 | Enhance(5.0); Enhance(8.0); Enhance(10.0); Enhance(8.0); Enhance(5.0); |
|---|
| 1062 | r=p+(image->columns+4); |
|---|
| 1063 | Enhance(8.0); Enhance(20.0); Enhance(40.0); Enhance(20.0); Enhance(8.0); |
|---|
|
|---|