| 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/animate.h" |
|---|
| 45 | #include "magick/artifact.h" |
|---|
| 46 | #include "magick/blob.h" |
|---|
| 47 | #include "magick/blob-private.h" |
|---|
| 48 | #include "magick/cache.h" |
|---|
| 49 | #include "magick/cache-private.h" |
|---|
| 50 | #include "magick/cache-view.h" |
|---|
| 51 | #include "magick/client.h" |
|---|
| 52 | #include "magick/color.h" |
|---|
| 53 | #include "magick/color-private.h" |
|---|
| 54 | #include "magick/colorspace.h" |
|---|
| 55 | #include "magick/colorspace-private.h" |
|---|
| 56 | #include "magick/composite.h" |
|---|
| 57 | #include "magick/composite-private.h" |
|---|
| 58 | #include "magick/compress.h" |
|---|
| 59 | #include "magick/constitute.h" |
|---|
| 60 | #include "magick/deprecate.h" |
|---|
| 61 | #include "magick/display.h" |
|---|
| 62 | #include "magick/draw.h" |
|---|
| 63 | #include "magick/enhance.h" |
|---|
| 64 | #include "magick/exception.h" |
|---|
| 65 | #include "magick/exception-private.h" |
|---|
| 66 | #include "magick/gem.h" |
|---|
| 67 | #include "magick/geometry.h" |
|---|
| 68 | #include "magick/list.h" |
|---|
| 69 | #include "magick/image-private.h" |
|---|
| 70 | #include "magick/magic.h" |
|---|
| 71 | #include "magick/magick.h" |
|---|
| 72 | #include "magick/memory_.h" |
|---|
| 73 | #include "magick/module.h" |
|---|
| 74 | #include "magick/monitor.h" |
|---|
| 75 | #include "magick/monitor-private.h" |
|---|
| 76 | #include "magick/option.h" |
|---|
| 77 | #include "magick/paint.h" |
|---|
| 78 | #include "magick/pixel-private.h" |
|---|
| 79 | #include "magick/profile.h" |
|---|
| 80 | #include "magick/property.h" |
|---|
| 81 | #include "magick/quantize.h" |
|---|
| 82 | #include "magick/random_.h" |
|---|
| 83 | #include "magick/segment.h" |
|---|
| 84 | #include "magick/semaphore.h" |
|---|
| 85 | #include "magick/signature-private.h" |
|---|
| 86 | #include "magick/statistic.h" |
|---|
| 87 | #include "magick/string_.h" |
|---|
| 88 | #include "magick/threshold.h" |
|---|
| 89 | #include "magick/timer.h" |
|---|
| 90 | #include "magick/utility.h" |
|---|
| 91 | #include "magick/version.h" |
|---|
| 92 | #include "magick/xwindow-private.h" |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | const char |
|---|
| 98 | *BackgroundColor = "#ffffff", |
|---|
| 99 | *BorderColor = "#dfdfdf", |
|---|
| 100 | *DefaultTileFrame = "15x15+3+3", |
|---|
| 101 | *DefaultTileGeometry = "120x120+4+3>", |
|---|
| 102 | *DefaultTileLabel = "%f\n%wx%h\n%b", |
|---|
| 103 | *ForegroundColor = "#000", |
|---|
| 104 | *LoadImageTag = "Load/Image", |
|---|
| 105 | *LoadImagesTag = "Load/Images", |
|---|
| 106 | *MatteColor = "#bdbdbd", |
|---|
| 107 | *PSDensityGeometry = "72.0x72.0", |
|---|
| 108 | *PSPageGeometry = "612x792", |
|---|
| 109 | *SaveImageTag = "Save/Image", |
|---|
| 110 | *SaveImagesTag = "Save/Images", |
|---|
| 111 | *TransparentColor = "#00000000"; |
|---|
| 112 | |
|---|
| 113 | const double |
|---|
| 114 | DefaultResolution = 72.0; |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | |
|---|
| 141 | MagickExport Image *AcquireImage(const ImageInfo *image_info) |
|---|
| 142 | { |
|---|
| 143 | const char |
|---|
| 144 | *option; |
|---|
| 145 | |
|---|
| 146 | Image |
|---|
| 147 | *image; |
|---|
| 148 | |
|---|
| 149 | MagickStatusType |
|---|
| 150 | flags; |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
|---|
| 156 | image=(Image *) AcquireMagickMemory(sizeof(*image)); |
|---|
| 157 | if (image == (Image *) NULL) |
|---|
| 158 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
|---|
| 159 | (void) ResetMagickMemory(image,0,sizeof(*image)); |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | |
|---|
| 163 | (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent); |
|---|
| 164 | image->storage_class=DirectClass; |
|---|
| 165 | image->depth=MAGICKCORE_QUANTUM_DEPTH; |
|---|
| 166 | image->colorspace=RGBColorspace; |
|---|
| 167 | image->interlace=NoInterlace; |
|---|
| 168 | image->ticks_per_second=UndefinedTicksPerSecond; |
|---|
| 169 | image->compose=OverCompositeOp; |
|---|
| 170 | image->blur=1.0; |
|---|
| 171 | GetExceptionInfo(&image->exception); |
|---|
| 172 | (void) QueryColorDatabase(BackgroundColor,&image->background_color, |
|---|
| 173 | &image->exception); |
|---|
| 174 | (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception); |
|---|
| 175 | (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception); |
|---|
| 176 | (void) QueryColorDatabase(TransparentColor,&image->transparent_color, |
|---|
| 177 | &image->exception); |
|---|
| 178 | image->x_resolution=DefaultResolution; |
|---|
| 179 | image->y_resolution=DefaultResolution; |
|---|
| 180 | image->units=PixelsPerInchResolution; |
|---|
| 181 | GetTimerInfo(&image->timer); |
|---|
| 182 | (void) GetCacheInfo(&image->cache); |
|---|
| 183 | image->blob=CloneBlobInfo((BlobInfo *) NULL); |
|---|
| 184 | image->debug=IsEventLogging(); |
|---|
| 185 | image->reference_count=1; |
|---|
| 186 | image->semaphore=AllocateSemaphoreInfo(); |
|---|
| 187 | image->signature=MagickSignature; |
|---|
| 188 | if (image_info == (ImageInfo *) NULL) |
|---|
| 189 | return(image); |
|---|
| 190 | |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue : |
|---|
| 194 | MagickFalse); |
|---|
| 195 | (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); |
|---|
| 196 | (void) CopyMagickString(image->magick_filename,image_info->filename, |
|---|
| 197 | MaxTextExtent); |
|---|
| 198 | (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent); |
|---|
| 199 | if (image_info->size != (char *) NULL) |
|---|
| 200 | { |
|---|
| 201 | (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info); |
|---|
| 202 | image->columns=image->extract_info.width; |
|---|
| 203 | image->rows=image->extract_info.height; |
|---|
| 204 | image->offset=image->extract_info.x; |
|---|
| 205 | image->extract_info.x=0; |
|---|
| 206 | image->extract_info.y=0; |
|---|
| 207 | } |
|---|
| 208 | if (image_info->extract != (char *) NULL) |
|---|
| 209 | { |
|---|
| 210 | RectangleInfo |
|---|
| 211 | geometry; |
|---|
| 212 | |
|---|
| 213 | flags=ParseAbsoluteGeometry(image_info->extract,&geometry); |
|---|
| 214 | if (((flags & XValue) != 0) || ((flags & YValue) != 0)) |
|---|
| 215 | { |
|---|
| 216 | image->extract_info=geometry; |
|---|
| 217 | Swap(image->columns,image->extract_info.width); |
|---|
| 218 | Swap(image->rows,image->extract_info.height); |
|---|
| 219 | } |
|---|
| 220 | } |
|---|
| 221 | image->compression=image_info->compression; |
|---|
| 222 | image->quality=image_info->quality; |
|---|
| 223 | image->endian=image_info->endian; |
|---|
| 224 | image->interlace=image_info->interlace; |
|---|
| 225 | image->units=image_info->units; |
|---|
| 226 | if (image_info->density != (char *) NULL) |
|---|
| 227 | { |
|---|
| 228 | GeometryInfo |
|---|
| 229 | geometry_info; |
|---|
| 230 | |
|---|
| 231 | flags=ParseGeometry(image_info->density,&geometry_info); |
|---|
| 232 | image->x_resolution=geometry_info.rho; |
|---|
| 233 | image->y_resolution=geometry_info.sigma; |
|---|
| 234 | if ((flags & SigmaValue) == 0) |
|---|
| 235 | image->y_resolution=image->x_resolution; |
|---|
| 236 | } |
|---|
| 237 | if (image_info->page != (char *) NULL) |
|---|
| 238 | { |
|---|
| 239 | char |
|---|
| 240 | *geometry; |
|---|
| 241 | |
|---|
| 242 | image->page=image->extract_info; |
|---|
| 243 | geometry=GetPageGeometry(image_info->page); |
|---|
| 244 | (void) ParseAbsoluteGeometry(geometry,&image->page); |
|---|
| 245 | geometry=DestroyString(geometry); |
|---|
| 246 | } |
|---|
| 247 | if (image_info->depth != 0) |
|---|
| 248 | image->depth=image_info->depth; |
|---|
| 249 | image->dither=image_info->dither; |
|---|
| 250 | image->background_color=image_info->background_color; |
|---|
| 251 | image->border_color=image_info->border_color; |
|---|
| 252 | image->matte_color=image_info->matte_color; |
|---|
| 253 | image->transparent_color=image_info->transparent_color; |
|---|
| 254 | option=GetImageOption(image_info,"tile-offset"); |
|---|
| 255 | if (option != (const char *) NULL) |
|---|
| 256 | { |
|---|
| 257 | char |
|---|
| 258 | *geometry; |
|---|
| 259 | |
|---|
| 260 | geometry=GetPageGeometry(option); |
|---|
| 261 | flags=ParseAbsoluteGeometry(geometry,&image->tile_offset); |
|---|
| 262 | geometry=DestroyString(geometry); |
|---|
| 263 | } |
|---|
| 264 | image->progress_monitor=image_info->progress_monitor; |
|---|
| 265 | image->client_data=image_info->client_data; |
|---|
| 266 | if (image_info->cache != (void *) NULL) |
|---|
| 267 | CloneCacheMethods(image->cache,image_info->cache); |
|---|
| 268 | (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method); |
|---|
| 269 | return(image); |
|---|
| 270 | } |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | |
|---|
| 276 | |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | |
|---|
| 283 | |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | |
|---|
| 287 | |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | |
|---|
| 296 | |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | |
|---|
| 300 | |
|---|
| 301 | static inline unsigned long MagickMax(const unsigned long x, |
|---|
| 302 | const unsigned long y) |
|---|
| 303 | { |
|---|
| 304 | if (x > y) |
|---|
| 305 | return(x); |
|---|
| 306 | return(y); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | static inline unsigned long MagickMin(const unsigned long x, |
|---|
| 310 | const unsigned long y) |
|---|
| 311 | { |
|---|
| 312 | if (x < y) |
|---|
| 313 | return(x); |
|---|
| 314 | return(y); |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | MagickExport MagickBooleanType AcquireImageColormap(Image *image, |
|---|
| 318 | const unsigned long colors) |
|---|
| 319 | { |
|---|
| 320 | register long |
|---|
| 321 | i; |
|---|
| 322 | |
|---|
| 323 | size_t |
|---|
| 324 | length; |
|---|
| 325 | |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | |
|---|
| 329 | assert(image != (Image *) NULL); |
|---|
| 330 | assert(image->signature == MagickSignature); |
|---|
| 331 | if (image->debug != MagickFalse) |
|---|
| 332 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 333 | image->colors=MagickMin(colors,MaxColormapSize); |
|---|
| 334 | length=(size_t) colors; |
|---|
| 335 | if (image->colormap == (PixelPacket *) NULL) |
|---|
| 336 | image->colormap=(PixelPacket *) AcquireQuantumMemory(length, |
|---|
| 337 | sizeof(*image->colormap)); |
|---|
| 338 | else |
|---|
| 339 | image->colormap=(PixelPacket *) ResizeQuantumMemory(image->colormap,length, |
|---|
| 340 | sizeof(*image->colormap)); |
|---|
| 341 | if (image->colormap == (PixelPacket *) NULL) |
|---|
| 342 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
|---|
| 343 | image->filename); |
|---|
| 344 | #pragma omp parallel for schedule(static,64) |
|---|
| 345 | for (i=0; i < (long) image->colors; i++) |
|---|
| 346 | { |
|---|
| 347 | unsigned long |
|---|
| 348 | pixel; |
|---|
| 349 | |
|---|
| 350 | pixel=(unsigned long) (i*(QuantumRange/MagickMax(colors-1,1))); |
|---|
| 351 | image->colormap[i].red=(Quantum) pixel; |
|---|
| 352 | image->colormap[i].green=(Quantum) pixel; |
|---|
| 353 | image->colormap[i].blue=(Quantum) pixel; |
|---|
| 354 | image->colormap[i].opacity=OpaqueOpacity; |
|---|
| 355 | } |
|---|
| 356 | return(SetImageStorageClass(image,PseudoClass)); |
|---|
| 357 | } |
|---|
| 358 | |
|---|
| 359 | |
|---|
| 360 | |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | |
|---|
| 367 | |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | |
|---|
| 371 | |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | |
|---|
| 376 | |
|---|
| 377 | MagickExport ImageInfo *AcquireImageInfo(void) |
|---|
| 378 | { |
|---|
| 379 | ImageInfo |
|---|
| 380 | *image_info; |
|---|
| 381 | |
|---|
| 382 | image_info=(ImageInfo *) AcquireMagickMemory(sizeof(*image_info)); |
|---|
| 383 | if (image_info == (ImageInfo *) NULL) |
|---|
| 384 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
|---|
| 385 | GetImageInfo(image_info); |
|---|
| 386 | return(image_info); |
|---|
| 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 | |
|---|
| 417 | MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image) |
|---|
| 418 | { |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | |
|---|
| 422 | assert(image != (Image *) NULL); |
|---|
| 423 | assert(image->signature == MagickSignature); |
|---|
| 424 | if (image->debug != MagickFalse) |
|---|
| 425 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 426 | image->next=AcquireImage(image_info); |
|---|
| 427 | if (GetNextImageInList(image) == (Image *) NULL) |
|---|
| 428 | return; |
|---|
| 429 | (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename, |
|---|
| 430 | MaxTextExtent); |
|---|
| 431 | if (image_info != (ImageInfo *) NULL) |
|---|
| 432 | (void) CopyMagickString(GetNextImageInList(image)->filename, |
|---|
| 433 | image_info->filename,MaxTextExtent); |
|---|
| 434 | DestroyBlob(GetNextImageInList(image)); |
|---|
| 435 | image->next->blob=ReferenceBlob(image->blob); |
|---|
| 436 | image->next->endian=image->endian; |
|---|
| 437 | image->next->scene=image->scene+1; |
|---|
| 438 | image->next->previous=image; |
|---|
| 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 | |
|---|
| 465 | |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | |
|---|
| 470 | MagickExport Image *AppendImages(const Image *image, |
|---|
| 471 | const MagickBooleanType stack,ExceptionInfo *exception) |
|---|
| 472 | { |
|---|
| 473 | #define AppendImageTag "Append/Image" |
|---|
| 474 | |
|---|
| 475 | Image |
|---|
| 476 | *append_image; |
|---|
| 477 | |
|---|
| 478 | long |
|---|
| 479 | n, |
|---|
| 480 | y; |
|---|
| 481 | |
|---|
| 482 | MagickBooleanType |
|---|
| 483 | matte, |
|---|
| 484 | proceed; |
|---|
| 485 | |
|---|
| 486 | register const Image |
|---|
| 487 | *next; |
|---|
| 488 | |
|---|
| 489 | register long |
|---|
| 490 | i; |
|---|
| 491 | |
|---|
| 492 | unsigned long |
|---|
| 493 | height, |
|---|
| 494 | number_images, |
|---|
| 495 | width; |
|---|
| 496 | |
|---|
| 497 | ViewInfo |
|---|
| 498 | **append_view, |
|---|
| 499 | **image_view; |
|---|
| 500 | |
|---|
| 501 | volatile MagickBooleanType |
|---|
| 502 | status; |
|---|
| 503 | |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | |
|---|
| 507 | assert(image != (Image *) NULL); |
|---|
| 508 | assert(image->signature == MagickSignature); |
|---|
| 509 | if (image->debug != MagickFalse) |
|---|
| 510 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 511 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 512 | assert(exception->signature == MagickSignature); |
|---|
| 513 | matte=image->matte; |
|---|
| 514 | number_images=1; |
|---|
| 515 | width=image->columns; |
|---|
| 516 | height=image->rows; |
|---|
| 517 | next=GetNextImageInList(image); |
|---|
| 518 | for ( ; next != (Image *) NULL; next=GetNextImageInList(next)) |
|---|
| 519 | { |
|---|
| 520 | if (next->matte != MagickFalse) |
|---|
| 521 | matte=MagickTrue; |
|---|
| 522 | number_images++; |
|---|
| 523 | if (stack != MagickFalse) |
|---|
| 524 | { |
|---|
| 525 | if (next->columns > width) |
|---|
| 526 | width=next->columns; |
|---|
| 527 | height+=next->rows; |
|---|
| 528 | continue; |
|---|
| 529 | } |
|---|
| 530 | width+=next->columns; |
|---|
| 531 | if (next->rows > height) |
|---|
| 532 | height=next->rows; |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | |
|---|
| 536 | |
|---|
| 537 | append_image=CloneImage(image,width,height,MagickTrue,exception); |
|---|
| 538 | if (append_image == (Image *) NULL) |
|---|
| 539 | return((Image *) NULL); |
|---|
| 540 | if (SetImageStorageClass(append_image,DirectClass) == MagickFalse) |
|---|
| 541 | { |
|---|
| 542 | InheritException(exception,&append_image->exception); |
|---|
| 543 | append_image=DestroyImage(append_image); |
|---|
| 544 | return((Image *) NULL); |
|---|
| 545 | } |
|---|
| 546 | append_image->matte=matte; |
|---|
| 547 | (void) SetImageBackgroundColor(append_image); |
|---|
| 548 | status=MagickTrue; |
|---|
| 549 | i=0; |
|---|
| 550 | append_view=AcquireCacheViewThreadSet(append_image); |
|---|
| 551 | if (stack != MagickFalse) |
|---|
| 552 | { |
|---|
| 553 | |
|---|
| 554 | |
|---|
| 555 | |
|---|
| 556 | for (n=0; n < (long) number_images; n++) |
|---|
| 557 | { |
|---|
| 558 | image_view=AcquireCacheViewThreadSet(image); |
|---|
| 559 | #pragma omp parallel for schedule(static,64) |
|---|
| 560 | for (y=0; y < (long) image->rows; y++) |
|---|
| 561 | { |
|---|
| 562 | const IndexPacket |
|---|
| 563 | *indexes; |
|---|
| 564 | |
|---|
| 565 | IndexPacket |
|---|
| 566 | *append_indexes; |
|---|
| 567 | |
|---|
| 568 | register const PixelPacket |
|---|
| 569 | *p; |
|---|
| 570 | |
|---|
| 571 | register long |
|---|
| 572 | id, |
|---|
| 573 | x; |
|---|
| 574 | |
|---|
| 575 | register PixelPacket |
|---|
| 576 | *q; |
|---|
| 577 | |
|---|
| 578 | if (status == MagickFalse) |
|---|
| 579 | continue; |
|---|
| 580 | id=GetCacheViewThreadId(); |
|---|
| 581 | p=AcquireCacheViewPixels(image_view[id],0,y,image->columns,1, |
|---|
| 582 | exception); |
|---|
| 583 | q=SetCacheViewPixels(append_view[id],0,i+y,append_image->columns,1); |
|---|
| 584 | if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) |
|---|
| 585 | { |
|---|
| 586 | status=MagickFalse; |
|---|
| 587 | continue; |
|---|
| 588 | } |
|---|
| 589 | indexes=AcquireCacheViewIndexes(image_view[id]); |
|---|
| 590 | append_indexes=GetCacheViewIndexes(append_view[id]); |
|---|
| 591 | for (x=0; x < (long) image->columns; x++) |
|---|
| 592 | { |
|---|
| 593 | q->red=p->red; |
|---|
| 594 | q->green=p->green; |
|---|
| 595 | q->blue=p->blue; |
|---|
| 596 | q->opacity=p->opacity; |
|---|
| 597 | if (append_image->colorspace == CMYKColorspace) |
|---|
| 598 | append_indexes[x]=indexes[x]; |
|---|
| 599 | p++; |
|---|
| 600 | q++; |
|---|
| 601 | } |
|---|
| 602 | if (SyncCacheViewPixels(append_view[id]) == MagickFalse) |
|---|
| 603 | continue; |
|---|
| 604 | } |
|---|
| 605 | image_view=DestroyCacheViewThreadSet(image_view); |
|---|
| 606 | proceed=SetImageProgress(image,AppendImageTag,n,number_images); |
|---|
| 607 | if (proceed == MagickFalse) |
|---|
| 608 | break; |
|---|
| 609 | i+=image->rows; |
|---|
| 610 | image=GetNextImageInList(image); |
|---|
| 611 | } |
|---|
| 612 | append_view=DestroyCacheViewThreadSet(append_view); |
|---|
| 613 | if (status == MagickFalse) |
|---|
| 614 | append_image=DestroyImage(append_image); |
|---|
| 615 | return(append_image); |
|---|
| 616 | } |
|---|
| 617 | |
|---|
| 618 | |
|---|
| 619 | |
|---|
| 620 | for (n=0; n < (long) number_images; n++) |
|---|
| 621 | { |
|---|
| 622 | image_view=AcquireCacheViewThreadSet(image); |
|---|
| 623 | #pragma omp parallel for schedule(static,64) |
|---|
| 624 | for (y=0; y < (long) image->rows; y++) |
|---|
| 625 | { |
|---|
| 626 | const IndexPacket |
|---|
| 627 | *indexes; |
|---|
| 628 | |
|---|
| 629 | IndexPacket |
|---|
| 630 | *append_indexes; |
|---|
| 631 | |
|---|
| 632 | register const PixelPacket |
|---|
| 633 | *p; |
|---|
| 634 | |
|---|
| 635 | register long |
|---|
| 636 | id, |
|---|
| 637 | x; |
|---|
| 638 | |
|---|
| 639 | register PixelPacket |
|---|
| 640 | *q; |
|---|
| 641 | |
|---|
| 642 | if (status == MagickFalse) |
|---|
| 643 | continue; |
|---|
| 644 | id=GetCacheViewThreadId(); |
|---|
| 645 | p=AcquireCacheViewPixels(image_view[id],0,y,image->columns,1,exception); |
|---|
| 646 | q=SetCacheViewPixels(append_view[id],i,y,image->columns,1); |
|---|
| 647 | if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) |
|---|
| 648 | { |
|---|
| 649 | status=MagickFalse; |
|---|
| 650 | continue; |
|---|
| 651 | } |
|---|
| 652 | indexes=AcquireCacheViewIndexes(image_view[id]); |
|---|
| 653 | append_indexes=GetCacheViewIndexes(append_view[id]); |
|---|
| 654 | for (x=0; x < (long) image->columns; x++) |
|---|
| 655 | { |
|---|
| 656 | q->red=p->red; |
|---|
| 657 | q->green=p->green; |
|---|
| 658 | q->blue=p->blue; |
|---|
| 659 | q->opacity=p->opacity; |
|---|
| 660 | if (append_image->colorspace == CMYKColorspace) |
|---|
| 661 | append_indexes[x]=indexes[x]; |
|---|
| 662 | p++; |
|---|
| 663 | q++; |
|---|
| 664 | } |
|---|
| 665 | if (SyncCacheViewPixels(append_view[id]) == MagickFalse) |
|---|
| 666 | continue; |
|---|
| 667 | } |
|---|
| 668 | image_view=DestroyCacheViewThreadSet(image_view); |
|---|
| 669 | proceed=SetImageProgress(image,AppendImageTag,n,number_images); |
|---|
| 670 | if (proceed == MagickFalse) |
|---|
| 671 | break; |
|---|
| 672 | i+=image->columns; |
|---|
| 673 | image=GetNextImageInList(image); |
|---|
| 674 | } |
|---|
| 675 | append_view=DestroyCacheViewThreadSet(append_view); |
|---|
| 676 | if (status == MagickFalse) |
|---|
| 677 | append_image=DestroyImage(append_image); |
|---|
| 678 | return(append_image); |
|---|
| 679 | } |
|---|
| 680 | |
|---|
| 681 | |
|---|
| 682 | |
|---|
| 683 | |
|---|
| 684 | |
|---|
| 685 | |
|---|
| 686 | |
|---|
| 687 | |
|---|
| 688 | |
|---|
| 689 | |
|---|
| 690 | |
|---|
| 691 | |
|---|
| 692 | |
|---|
| 693 | |
|---|
| 694 | |
|---|
| 695 | |
|---|
| 696 | |
|---|
| 697 | |
|---|
| 698 | |
|---|
| 699 | |
|---|
| 700 | |
|---|
| 701 | |
|---|
| 702 | |
|---|
| 703 | |
|---|
| 704 | |
|---|
| 705 | |
|---|
| 706 | |
|---|
| 707 | |
|---|
| 708 | |
|---|
| 709 | |
|---|
| 710 | static MagickPixelPacket **DestroyPixelThreadSet(MagickPixelPacket **pixels) |
|---|
| 711 | { |
|---|
| 712 | register long |
|---|
| 713 | i; |
|---|
| 714 | |
|---|
| 715 | assert(pixels != (MagickPixelPacket **) NULL); |
|---|
| 716 | for (i=0; i < (long) GetCacheViewMaximumThreads(); i++) |
|---|
| 717 | if (pixels[i] != (MagickPixelPacket *) NULL) |
|---|
| 718 | pixels[i]=(MagickPixelPacket *) RelinquishMagickMemory(pixels[i]); |
|---|
| 719 | return((MagickPixelPacket **) RelinquishMagickMemory(pixels)); |
|---|
| 720 | } |
|---|
| 721 | |
|---|
| 722 | static MagickPixelPacket **AcquirePixelThreadSet(const Image *image) |
|---|
| 723 | { |
|---|
| 724 | register long |
|---|
| 725 | i, |
|---|
| 726 | j; |
|---|
| 727 | |
|---|
| 728 | MagickPixelPacket |
|---|
| 729 | **pixels; |
|---|
| 730 | |
|---|
| 731 | pixels=(MagickPixelPacket **) AcquireQuantumMemory( |
|---|
| 732 | GetCacheViewMaximumThreads(),sizeof(*pixels)); |
|---|
| 733 | if (pixels == (MagickPixelPacket **) NULL) |
|---|
| 734 | return((MagickPixelPacket **) NULL); |
|---|
| 735 | (void) ResetMagickMemory(pixels,0,GetCacheViewMaximumThreads()* |
|---|
| 736 | sizeof(*pixels)); |
|---|
| 737 | for (i=0; i < (long) GetCacheViewMaximumThreads(); i++) |
|---|
| 738 | { |
|---|
| 739 | pixels[i]=(MagickPixelPacket *) AcquireQuantumMemory(image->columns, |
|---|
| 740 | sizeof(**pixels)); |
|---|
| 741 | if (pixels[i] == (MagickPixelPacket *) NULL) |
|---|
| 742 | return(DestroyPixelThreadSet(pixels)); |
|---|
| 743 | for (j=0; j < (long) image->columns; j++) |
|---|
| 744 | GetMagickPixelPacket(image,&pixels[i][j]); |
|---|
| 745 | } |
|---|
| 746 | return(pixels); |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | MagickExport Image *AverageImages(const Image *image,ExceptionInfo *exception) |
|---|
| 750 | { |
|---|
| 751 | #define AverageImageTag "Average/Image" |
|---|
| 752 | |
|---|
| 753 | const Image |
|---|
| 754 | *next; |
|---|
| 755 | |
|---|
| 756 | Image |
|---|
| 757 | *average_image; |
|---|
| 758 | |
|---|
| 759 | long |
|---|
| 760 | progress, |
|---|
| 761 | y; |
|---|
| 762 | |
|---|
| 763 | MagickPixelPacket |
|---|
| 764 | **average_pixel, |
|---|
| 765 | zero; |
|---|
| 766 | |
|---|
| 767 | unsigned long |
|---|
| 768 | number_images; |
|---|
| 769 | |
|---|
| 770 | ViewInfo |
|---|
| 771 | **average_view; |
|---|
| 772 | |
|---|
| 773 | volatile MagickBooleanType |
|---|
| 774 | status; |
|---|
| 775 | |
|---|
| 776 | |
|---|
| 777 | |
|---|
| 778 | |
|---|
| 779 | assert(image != (Image *) NULL); |
|---|
| 780 | assert(image->signature == MagickSignature); |
|---|
| 781 | if (image->debug != MagickFalse) |
|---|
| 782 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 783 | assert(exception != (ExceptionInfo *) NULL); |
|---|
| 784 | assert(exception->signature == MagickSignature); |
|---|
| 785 | for (next=image; next != (Image *) NULL; next=GetNextImageInList(next)) |
|---|
| 786 | if ((next->columns != image->columns) || (next->rows != image->rows)) |
|---|
| 787 | ThrowImageException(OptionError,"ImageWidthsOrHeightsDiffer"); |
|---|
| 788 | |
|---|
| 789 | |
|---|
| 790 | |
|---|
| 791 | average_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
|---|
| 792 | exception); |
|---|
| 793 | if (average_image == (Image *) NULL) |
|---|
| 794 | return((Image *) NULL); |
|---|
| 795 | if (SetImageStorageClass(average_image,DirectClass) == MagickFalse) |
|---|
| 796 | { |
|---|
| 797 | InheritException(exception,&average_image->exception); |
|---|
| 798 | average_image=DestroyImage(average_image); |
|---|
| 799 | return((Image *) NULL); |
|---|
| 800 | } |
|---|
| 801 | average_pixel=AcquirePixelThreadSet(image); |
|---|
| 802 | if (average_pixel == (MagickPixelPacket **) NULL) |
|---|
| 803 | { |
|---|
| 804 | average_image=DestroyImage(average_image); |
|---|
| 805 | ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); |
|---|
| 806 | } |
|---|
| 807 | |
|---|
| 808 | |
|---|
| 809 | |
|---|
| 810 | status=MagickTrue; |
|---|
| 811 | progress=0; |
|---|
| 812 | GetMagickPixelPacket(image,&zero); |
|---|
| 813 | number_images=GetImageListLength(image); |
|---|
| 814 | average_view=AcquireCacheViewThreadSet(average_image); |
|---|
| 815 | #pragma omp parallel for schedule(static,64) |
|---|
| 816 | for (y=0; y < (long) average_image->rows; y++) |
|---|
| 817 | { |
|---|
| 818 | const Image |
|---|
| 819 | *next; |
|---|
| 820 | |
|---|
| 821 | IndexPacket |
|---|
| 822 | *average_indexes; |
|---|
| 823 | |
|---|
| 824 | MagickPixelPacket |
|---|
| 825 | pixel; |
|---|
| 826 | |
|---|
| 827 | register long |
|---|
| 828 | i, |
|---|
| 829 | id, |
|---|
| 830 | x; |
|---|
| 831 | |
|---|
| 832 | register PixelPacket |
|---|
| 833 | *q; |
|---|
| 834 | |
|---|
| 835 | ViewInfo |
|---|
| 836 | *image_view; |
|---|
| 837 | |
|---|
| 838 | if (status == MagickFalse) |
|---|
| 839 | continue; |
|---|
| 840 | id=GetCacheViewThreadId(); |
|---|
| 841 | q=SetCacheViewPixels(average_view[id],0,y,average_image->columns,1); |
|---|
| 842 | if (q == (PixelPacket *) NULL) |
|---|
| 843 | { |
|---|
| 844 | status=MagickFalse; |
|---|
| 845 | continue; |
|---|
| 846 | } |
|---|
| 847 | pixel=zero; |
|---|
| 848 | average_indexes=GetCacheViewIndexes(average_view[id]); |
|---|
| 849 | for (x=0; x < (long) average_image->columns; x++) |
|---|
| 850 | average_pixel[id][x]=zero; |
|---|
| 851 | next=image; |
|---|
| 852 | for (i=0; i < (long) number_images; i++) |
|---|
| 853 | { |
|---|
| 854 | register const IndexPacket |
|---|
| 855 | *indexes; |
|---|
| 856 | |
|---|
| 857 | register const PixelPacket |
|---|
| 858 | *p; |
|---|
| 859 | |
|---|
| 860 | image_view=AcquireCacheView(next); |
|---|
| 861 | p=AcquireCacheViewPixels(image_view,0,y,next->columns,1,exception); |
|---|
| 862 | if (p == (const PixelPacket *) NULL) |
|---|
| 863 | { |
|---|
| 864 | image_view=DestroyCacheView(image_view); |
|---|
| 865 | break; |
|---|
| 866 | } |
|---|
| 867 | indexes=AcquireCacheViewIndexes(image_view); |
|---|
| 868 | for (x=0; x < (long) next->columns; x++) |
|---|
| 869 | { |
|---|
| 870 | SetMagickPixelPacket(next,p,indexes+x,&pixel); |
|---|
| 871 | average_pixel[id][x].red+=QuantumScale*pixel.red; |
|---|
| 872 | average_pixel[id][x].green+=QuantumScale*pixel.green; |
|---|
| 873 | average_pixel[id][x].blue+=QuantumScale*pixel.blue; |
|---|
| 874 | average_pixel[id][x].opacity+=QuantumScale*pixel.opacity; |
|---|
| 875 | if (average_image->colorspace == CMYKColorspace) |
|---|
| 876 | average_pixel[id][x].index+=QuantumScale*pixel.index; |
|---|
| 877 | p++; |
|---|
| 878 | } |
|---|
| 879 | image_view=DestroyCacheView(image_view); |
|---|
| 880 | next=GetNextImageInList(next); |
|---|
| 881 | } |
|---|
| 882 | for (x=0; x < (long) average_image->columns; x++) |
|---|
| 883 | { |
|---|
| 884 | average_pixel[id][x].red=(MagickRealType) QuantumRange* |
|---|
| 885 | average_pixel[id][x].red/number_images; |
|---|
| 886 | average_pixel[id][x].green=(MagickRealType) QuantumRange* |
|---|
| 887 | average_pixel[id][x].green/number_images; |
|---|
| 888 | average_pixel[id][x].blue=(MagickRealType) QuantumRange* |
|---|
| 889 | average_pixel[id][x].blue/number_images; |
|---|
| 890 | average_pixel[id][x].opacity=(MagickRealType) QuantumRange* |
|---|
| 891 | average_pixel[id][x].opacity/number_images; |
|---|
| 892 | if (average_image->colorspace == CMYKColorspace) |
|---|
| 893 | average_pixel[id][x].index=(MagickRealType) QuantumRange* |
|---|
| 894 | average_pixel[id][x].index/number_images; |
|---|
| 895 | SetPixelPacket(average_image,&average_pixel[id][x],q,average_indexes+x); |
|---|
| 896 | q++; |
|---|
| 897 | } |
|---|
| 898 | if (SyncCacheViewPixels(average_view[id]) == MagickFalse) |
|---|
| 899 | status=MagickFalse; |
|---|
| 900 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
|---|
| 901 | { |
|---|
| 902 | MagickBooleanType |
|---|
| 903 | proceed; |
|---|
| 904 | |
|---|
| 905 | #pragma omp critical |
|---|
| 906 | proceed=SetImageProgress(image,AverageImageTag,progress++, |
|---|
| 907 | average_image->rows); |
|---|
| 908 | if (proceed == MagickFalse) |
|---|
| 909 | status=MagickFalse; |
|---|
| 910 | } |
|---|
| 911 | } |
|---|
| 912 | average_view=DestroyCacheViewThreadSet(average_view); |
|---|
| 913 | average_pixel=DestroyPixelThreadSet(average_pixel); |
|---|
| 914 | if (status == MagickFalse) |
|---|
| 915 | average_image=DestroyImage(average_image); |
|---|
| 916 | return(average_image); |
|---|
| 917 | } |
|---|
| 918 | |
|---|
| 919 | |
|---|
| 920 | |
|---|
| 921 | |
|---|
| 922 | |
|---|
| 923 | |
|---|
| 924 | |
|---|
| 925 | |
|---|
| 926 | |
|---|
| 927 | |
|---|
| 928 | |
|---|
| 929 | |
|---|
| 930 | |
|---|
| 931 | |
|---|
| 932 | |
|---|
| 933 | |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | |
|---|
| 937 | |
|---|
| 938 | |
|---|
| 939 | |
|---|
| 940 | |
|---|
| 941 | |
|---|
| 942 | |
|---|
| 943 | MagickExport ExceptionType CatchImageException(Image *image) |
|---|
| 944 | { |
|---|
| 945 | ExceptionInfo |
|---|
| 946 | *exception; |
|---|
| 947 | |
|---|
| 948 | ExceptionType |
|---|
| 949 | severity; |
|---|
| 950 | |
|---|
| 951 | assert(image != (const Image *) NULL); |
|---|
| 952 | assert(image->signature == MagickSignature); |
|---|
| 953 | if (image->debug != MagickFalse) |
|---|
| 954 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
|---|
| 955 | exception=AcquireExceptionInfo(); |
|---|
| 956 | GetImageException(image,exception); |
|---|
| 957 | CatchException(exception); |
|---|
| 958 | severity=exception->severity; |
|---|
| 959 | exception=DestroyExceptionInfo(exception); |
|---|
| 960 | return(severity); |
|---|
| 961 | } |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | |
|---|
| 965 | |
|---|
| 966 | |
|---|
| 967 | |
|---|
| 968 | |
|---|
| 969 | |
|---|
| 970 | |
|---|
| 971 | |
|---|
| 972 | |
|---|
| 973 | |
|---|
| 974 | |
|---|
| 975 | |
|---|
| 976 | |
|---|
| 977 | |
|---|
| 978 | |
|---|
| 979 | |
|---|
| 980 | |
|---|
| 981 | |
|---|
| 982 | |
|---|
| 983 | |
|---|
| 984 | |
|---|
| 985 | |
|---|
| 986 | |
|---|
| 987 | |
|---|
| 988 | |
|---|
| 989 | |
|---|
| 990 | |
|---|
| 991 | |
|---|
| 992 | |
|---|
| 993 | |
|---|
| 994 | MagickExport MagickBooleanType ClipImage(Image *image) |
|---|
| 995 | { |
|---|
| 996 | return(ClipImagePath(image,"#1",MagickTrue)); |
|---|