cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % IIIII M M AAA GGGG EEEEE % |
| 7 | % I MM MM A A G E % |
| 8 | % I M M M AAAAA G GG EEE % |
| 9 | % I M M A A G G E % |
| 10 | % IIIII M M A A GGGG EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 16af1cb | 2009-12-11 21:38:29 +0000 | [diff] [blame] | 20 | % Copyright 1999-2010 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 | */ |
| 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" |
cristy | 316d517 | 2009-09-17 19:31:25 +0000 | [diff] [blame] | 54 | #include "magick/colormap.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 55 | #include "magick/colorspace.h" |
| 56 | #include "magick/colorspace-private.h" |
| 57 | #include "magick/composite.h" |
| 58 | #include "magick/composite-private.h" |
| 59 | #include "magick/compress.h" |
| 60 | #include "magick/constitute.h" |
| 61 | #include "magick/deprecate.h" |
| 62 | #include "magick/display.h" |
| 63 | #include "magick/draw.h" |
| 64 | #include "magick/enhance.h" |
| 65 | #include "magick/exception.h" |
| 66 | #include "magick/exception-private.h" |
| 67 | #include "magick/gem.h" |
| 68 | #include "magick/geometry.h" |
cristy | f2e1166 | 2009-10-14 01:24:43 +0000 | [diff] [blame] | 69 | #include "magick/histogram.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | #include "magick/image-private.h" |
cristy | f2e1166 | 2009-10-14 01:24:43 +0000 | [diff] [blame] | 71 | #include "magick/list.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 72 | #include "magick/magic.h" |
| 73 | #include "magick/magick.h" |
| 74 | #include "magick/memory_.h" |
| 75 | #include "magick/module.h" |
| 76 | #include "magick/monitor.h" |
| 77 | #include "magick/monitor-private.h" |
| 78 | #include "magick/option.h" |
| 79 | #include "magick/paint.h" |
| 80 | #include "magick/pixel-private.h" |
| 81 | #include "magick/profile.h" |
| 82 | #include "magick/property.h" |
| 83 | #include "magick/quantize.h" |
| 84 | #include "magick/random_.h" |
| 85 | #include "magick/segment.h" |
| 86 | #include "magick/semaphore.h" |
| 87 | #include "magick/signature-private.h" |
| 88 | #include "magick/statistic.h" |
| 89 | #include "magick/string_.h" |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 90 | #include "magick/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 91 | #include "magick/thread-private.h" |
| 92 | #include "magick/threshold.h" |
| 93 | #include "magick/timer.h" |
| 94 | #include "magick/utility.h" |
| 95 | #include "magick/version.h" |
| 96 | #include "magick/xwindow-private.h" |
| 97 | |
| 98 | /* |
| 99 | Constant declaration. |
| 100 | */ |
| 101 | const char |
cristy | 7138c59 | 2009-09-08 13:58:52 +0000 | [diff] [blame] | 102 | BackgroundColor[] = "#ffffff", /* white */ |
| 103 | BorderColor[] = "#dfdfdf", /* gray */ |
| 104 | DefaultTileFrame[] = "15x15+3+3", |
| 105 | DefaultTileGeometry[] = "120x120+4+3>", |
| 106 | DefaultTileLabel[] = "%f\n%G\n%b", |
| 107 | ForegroundColor[] = "#000", /* black */ |
| 108 | LoadImageTag[] = "Load/Image", |
| 109 | LoadImagesTag[] = "Load/Images", |
| 110 | MatteColor[] = "#bdbdbd", /* gray */ |
| 111 | PSDensityGeometry[] = "72.0x72.0", |
| 112 | PSPageGeometry[] = "612x792", |
| 113 | SaveImageTag[] = "Save/Image", |
| 114 | SaveImagesTag[] = "Save/Images", |
| 115 | TransparentColor[] = "#00000000"; /* transparent black */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | |
| 117 | const double |
| 118 | DefaultResolution = 72.0; |
| 119 | |
| 120 | /* |
| 121 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 122 | % % |
| 123 | % % |
| 124 | % % |
| 125 | % A c q u i r e I m a g e % |
| 126 | % % |
| 127 | % % |
| 128 | % % |
| 129 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 130 | % |
| 131 | % AcquireImage() returns a pointer to an image structure initialized to |
| 132 | % default values. |
| 133 | % |
| 134 | % The format of the AcquireImage method is: |
| 135 | % |
| 136 | % Image *AcquireImage(const ImageInfo *image_info) |
| 137 | % |
| 138 | % A description of each parameter follows: |
| 139 | % |
| 140 | % o image_info: Many of the image default values are set from this |
| 141 | % structure. For example, filename, compression, depth, background color, |
| 142 | % and others. |
| 143 | % |
| 144 | */ |
| 145 | MagickExport Image *AcquireImage(const ImageInfo *image_info) |
| 146 | { |
| 147 | Image |
| 148 | *image; |
| 149 | |
| 150 | MagickStatusType |
| 151 | flags; |
| 152 | |
| 153 | /* |
| 154 | Allocate image structure. |
| 155 | */ |
| 156 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
cristy | 9082321 | 2009-12-12 20:48:33 +0000 | [diff] [blame] | 157 | image=(Image *) AcquireAlignedMemory(1,sizeof(*image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | if (image == (Image *) NULL) |
| 159 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 160 | (void) ResetMagickMemory(image,0,sizeof(*image)); |
| 161 | /* |
| 162 | Initialize Image structure. |
| 163 | */ |
| 164 | (void) CopyMagickString(image->magick,"MIFF",MaxTextExtent); |
| 165 | image->storage_class=DirectClass; |
| 166 | image->depth=MAGICKCORE_QUANTUM_DEPTH; |
| 167 | image->colorspace=RGBColorspace; |
| 168 | image->interlace=NoInterlace; |
| 169 | image->ticks_per_second=UndefinedTicksPerSecond; |
| 170 | image->compose=OverCompositeOp; |
| 171 | image->blur=1.0; |
| 172 | GetExceptionInfo(&image->exception); |
| 173 | (void) QueryColorDatabase(BackgroundColor,&image->background_color, |
| 174 | &image->exception); |
| 175 | (void) QueryColorDatabase(BorderColor,&image->border_color,&image->exception); |
| 176 | (void) QueryColorDatabase(MatteColor,&image->matte_color,&image->exception); |
| 177 | (void) QueryColorDatabase(TransparentColor,&image->transparent_color, |
| 178 | &image->exception); |
| 179 | image->x_resolution=DefaultResolution; |
| 180 | image->y_resolution=DefaultResolution; |
| 181 | image->units=PixelsPerInchResolution; |
| 182 | GetTimerInfo(&image->timer); |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 183 | image->ping=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | image->cache=AcquirePixelCache(0); |
| 185 | image->blob=CloneBlobInfo((BlobInfo *) NULL); |
| 186 | image->debug=IsEventLogging(); |
| 187 | image->reference_count=1; |
| 188 | image->semaphore=AllocateSemaphoreInfo(); |
| 189 | image->signature=MagickSignature; |
| 190 | if (image_info == (ImageInfo *) NULL) |
| 191 | return(image); |
| 192 | /* |
| 193 | Transfer image info. |
| 194 | */ |
| 195 | SetBlobExempt(image,image_info->file != (FILE *) NULL ? MagickTrue : |
| 196 | MagickFalse); |
| 197 | (void) CopyMagickString(image->filename,image_info->filename,MaxTextExtent); |
| 198 | (void) CopyMagickString(image->magick_filename,image_info->filename, |
| 199 | MaxTextExtent); |
| 200 | (void) CopyMagickString(image->magick,image_info->magick,MaxTextExtent); |
| 201 | if (image_info->size != (char *) NULL) |
| 202 | { |
| 203 | (void) ParseAbsoluteGeometry(image_info->size,&image->extract_info); |
| 204 | image->columns=image->extract_info.width; |
| 205 | image->rows=image->extract_info.height; |
| 206 | image->offset=image->extract_info.x; |
| 207 | image->extract_info.x=0; |
| 208 | image->extract_info.y=0; |
| 209 | } |
| 210 | if (image_info->extract != (char *) NULL) |
| 211 | { |
| 212 | RectangleInfo |
| 213 | geometry; |
| 214 | |
| 215 | flags=ParseAbsoluteGeometry(image_info->extract,&geometry); |
| 216 | if (((flags & XValue) != 0) || ((flags & YValue) != 0)) |
| 217 | { |
| 218 | image->extract_info=geometry; |
| 219 | Swap(image->columns,image->extract_info.width); |
| 220 | Swap(image->rows,image->extract_info.height); |
| 221 | } |
| 222 | } |
| 223 | image->compression=image_info->compression; |
| 224 | image->quality=image_info->quality; |
| 225 | image->endian=image_info->endian; |
| 226 | image->interlace=image_info->interlace; |
| 227 | image->units=image_info->units; |
| 228 | if (image_info->density != (char *) NULL) |
| 229 | { |
| 230 | GeometryInfo |
| 231 | geometry_info; |
| 232 | |
| 233 | flags=ParseGeometry(image_info->density,&geometry_info); |
| 234 | image->x_resolution=geometry_info.rho; |
| 235 | image->y_resolution=geometry_info.sigma; |
| 236 | if ((flags & SigmaValue) == 0) |
| 237 | image->y_resolution=image->x_resolution; |
| 238 | } |
| 239 | if (image_info->page != (char *) NULL) |
| 240 | { |
| 241 | char |
| 242 | *geometry; |
| 243 | |
| 244 | image->page=image->extract_info; |
| 245 | geometry=GetPageGeometry(image_info->page); |
| 246 | (void) ParseAbsoluteGeometry(geometry,&image->page); |
| 247 | geometry=DestroyString(geometry); |
| 248 | } |
| 249 | if (image_info->depth != 0) |
| 250 | image->depth=image_info->depth; |
| 251 | image->dither=image_info->dither; |
| 252 | image->background_color=image_info->background_color; |
| 253 | image->border_color=image_info->border_color; |
| 254 | image->matte_color=image_info->matte_color; |
| 255 | image->transparent_color=image_info->transparent_color; |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 256 | image->ping=image_info->ping; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | image->progress_monitor=image_info->progress_monitor; |
| 258 | image->client_data=image_info->client_data; |
| 259 | if (image_info->cache != (void *) NULL) |
| 260 | ClonePixelCacheMethods(image->cache,image_info->cache); |
| 261 | (void) SetImageVirtualPixelMethod(image,image_info->virtual_pixel_method); |
cristy | 6b9aca1 | 2010-02-21 01:50:11 +0000 | [diff] [blame] | 262 | (void) SyncImageSettings(image_info,image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 263 | return(image); |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 268 | % % |
| 269 | % % |
| 270 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 271 | % A c q u i r e I m a g e I n f o % |
| 272 | % % |
| 273 | % % |
| 274 | % % |
| 275 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 276 | % |
| 277 | % AcquireImageInfo() allocates the ImageInfo structure. |
| 278 | % |
| 279 | % The format of the AcquireImageInfo method is: |
| 280 | % |
| 281 | % ImageInfo *AcquireImageInfo(void) |
| 282 | % |
| 283 | */ |
| 284 | MagickExport ImageInfo *AcquireImageInfo(void) |
| 285 | { |
| 286 | ImageInfo |
| 287 | *image_info; |
| 288 | |
cristy | 9082321 | 2009-12-12 20:48:33 +0000 | [diff] [blame] | 289 | image_info=(ImageInfo *) AcquireAlignedMemory(1,sizeof(*image_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 290 | if (image_info == (ImageInfo *) NULL) |
| 291 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 292 | GetImageInfo(image_info); |
| 293 | return(image_info); |
| 294 | } |
| 295 | |
| 296 | /* |
| 297 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 298 | % % |
| 299 | % % |
| 300 | % % |
| 301 | % A c q u i r e N e x t I m a g e % |
| 302 | % % |
| 303 | % % |
| 304 | % % |
| 305 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 306 | % |
| 307 | % AcquireNextImage() initializes the next image in a sequence to |
| 308 | % default values. The next member of image points to the newly allocated |
| 309 | % image. If there is a memory shortage, next is assigned NULL. |
| 310 | % |
| 311 | % The format of the AcquireNextImage method is: |
| 312 | % |
| 313 | % void AcquireNextImage(const ImageInfo *image_info,Image *image) |
| 314 | % |
| 315 | % A description of each parameter follows: |
| 316 | % |
| 317 | % o image_info: Many of the image default values are set from this |
| 318 | % structure. For example, filename, compression, depth, background color, |
| 319 | % and others. |
| 320 | % |
| 321 | % o image: the image. |
| 322 | % |
| 323 | */ |
| 324 | MagickExport void AcquireNextImage(const ImageInfo *image_info,Image *image) |
| 325 | { |
| 326 | /* |
| 327 | Allocate image structure. |
| 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->next=AcquireImage(image_info); |
| 334 | if (GetNextImageInList(image) == (Image *) NULL) |
| 335 | return; |
| 336 | (void) CopyMagickString(GetNextImageInList(image)->filename,image->filename, |
| 337 | MaxTextExtent); |
| 338 | if (image_info != (ImageInfo *) NULL) |
| 339 | (void) CopyMagickString(GetNextImageInList(image)->filename, |
| 340 | image_info->filename,MaxTextExtent); |
| 341 | DestroyBlob(GetNextImageInList(image)); |
| 342 | image->next->blob=ReferenceBlob(image->blob); |
| 343 | image->next->endian=image->endian; |
| 344 | image->next->scene=image->scene+1; |
| 345 | image->next->previous=image; |
| 346 | } |
| 347 | |
| 348 | /* |
| 349 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 350 | % % |
| 351 | % % |
| 352 | % % |
| 353 | % A p p e n d I m a g e s % |
| 354 | % % |
| 355 | % % |
| 356 | % % |
| 357 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 358 | % |
| 359 | % AppendImages() takes all images from the current image pointer to the end |
| 360 | % of the image list and appends them to each other top-to-bottom if the |
| 361 | % stack parameter is true, otherwise left-to-right. |
| 362 | % |
| 363 | % The current gravity setting now effects how the image is justified in the |
| 364 | % final image. |
| 365 | % |
| 366 | % The format of the AppendImages method is: |
| 367 | % |
| 368 | % Image *AppendImages(const Image *image,const MagickBooleanType stack, |
| 369 | % ExceptionInfo *exception) |
| 370 | % |
| 371 | % A description of each parameter follows: |
| 372 | % |
| 373 | % o image: the image sequence. |
| 374 | % |
| 375 | % o stack: A value other than 0 stacks the images top-to-bottom. |
| 376 | % |
| 377 | % o exception: return any errors or warnings in this structure. |
| 378 | % |
| 379 | */ |
| 380 | MagickExport Image *AppendImages(const Image *image, |
| 381 | const MagickBooleanType stack,ExceptionInfo *exception) |
| 382 | { |
| 383 | #define AppendImageTag "Append/Image" |
| 384 | |
| 385 | CacheView |
| 386 | *append_view, |
| 387 | *image_view; |
| 388 | |
| 389 | Image |
| 390 | *append_image; |
| 391 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 392 | MagickBooleanType |
| 393 | matte, |
| 394 | proceed, |
| 395 | status; |
| 396 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 397 | MagickOffsetType |
| 398 | n; |
| 399 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 400 | RectangleInfo |
| 401 | geometry; |
| 402 | |
| 403 | register const Image |
| 404 | *next; |
| 405 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 406 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 407 | height, |
| 408 | number_images, |
| 409 | width; |
| 410 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 411 | ssize_t |
| 412 | x_offset, |
| 413 | y, |
| 414 | y_offset; |
| 415 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 416 | /* |
| 417 | Ensure the image have the same column width. |
| 418 | */ |
| 419 | assert(image != (Image *) NULL); |
| 420 | assert(image->signature == MagickSignature); |
| 421 | if (image->debug != MagickFalse) |
| 422 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 423 | assert(exception != (ExceptionInfo *) NULL); |
| 424 | assert(exception->signature == MagickSignature); |
| 425 | matte=image->matte; |
| 426 | number_images=1; |
| 427 | width=image->columns; |
| 428 | height=image->rows; |
| 429 | next=GetNextImageInList(image); |
| 430 | for ( ; next != (Image *) NULL; next=GetNextImageInList(next)) |
| 431 | { |
| 432 | if (next->matte != MagickFalse) |
| 433 | matte=MagickTrue; |
| 434 | number_images++; |
| 435 | if (stack != MagickFalse) |
| 436 | { |
| 437 | if (next->columns > width) |
| 438 | width=next->columns; |
| 439 | height+=next->rows; |
| 440 | continue; |
| 441 | } |
| 442 | width+=next->columns; |
| 443 | if (next->rows > height) |
| 444 | height=next->rows; |
| 445 | } |
| 446 | /* |
| 447 | Initialize append next attributes. |
| 448 | */ |
| 449 | append_image=CloneImage(image,width,height,MagickTrue,exception); |
| 450 | if (append_image == (Image *) NULL) |
| 451 | return((Image *) NULL); |
| 452 | if (SetImageStorageClass(append_image,DirectClass) == MagickFalse) |
| 453 | { |
| 454 | InheritException(exception,&append_image->exception); |
| 455 | append_image=DestroyImage(append_image); |
| 456 | return((Image *) NULL); |
| 457 | } |
| 458 | append_image->matte=matte; |
| 459 | (void) SetImageBackgroundColor(append_image); |
| 460 | status=MagickTrue; |
| 461 | x_offset=0; |
| 462 | y_offset=0; |
| 463 | append_view=AcquireCacheView(append_image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 464 | for (n=0; n < (MagickOffsetType) number_images; n++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 465 | { |
| 466 | SetGeometry(append_image,&geometry); |
| 467 | GravityAdjustGeometry(image->columns,image->rows,image->gravity,&geometry); |
| 468 | if (stack != MagickFalse) |
| 469 | x_offset-=geometry.x; |
| 470 | else |
| 471 | y_offset-=geometry.y; |
| 472 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 473 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 474 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 475 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 476 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 477 | { |
| 478 | MagickBooleanType |
| 479 | sync; |
| 480 | |
| 481 | register const IndexPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 482 | *restrict indexes; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 483 | |
| 484 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 485 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 486 | |
| 487 | register IndexPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 488 | *restrict append_indexes; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 489 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 490 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 491 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 492 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 493 | register ssize_t |
| 494 | x; |
| 495 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 496 | if (status == MagickFalse) |
| 497 | continue; |
| 498 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 499 | q=QueueCacheViewAuthenticPixels(append_view,x_offset,y+y_offset, |
| 500 | image->columns,1,exception); |
| 501 | if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) |
| 502 | { |
| 503 | status=MagickFalse; |
| 504 | continue; |
| 505 | } |
| 506 | indexes=GetCacheViewVirtualIndexQueue(image_view); |
| 507 | append_indexes=GetCacheViewAuthenticIndexQueue(append_view); |
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 | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 510 | SetRedPixelComponent(q,GetRedPixelComponent(p)); |
| 511 | SetGreenPixelComponent(q,GetGreenPixelComponent(p)); |
| 512 | SetBluePixelComponent(q,GetBluePixelComponent(p)); |
| 513 | SetOpacityPixelComponent(q,OpaqueOpacity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 514 | if (image->matte != MagickFalse) |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 515 | SetOpacityPixelComponent(q,GetOpacityPixelComponent(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 516 | if (image->colorspace == CMYKColorspace) |
| 517 | append_indexes[x]=indexes[x]; |
| 518 | p++; |
| 519 | q++; |
| 520 | } |
| 521 | sync=SyncCacheViewAuthenticPixels(append_view,exception); |
| 522 | if (sync == MagickFalse) |
cristy | a65f35b | 2010-04-20 01:10:41 +0000 | [diff] [blame] | 523 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 524 | } |
| 525 | image_view=DestroyCacheView(image_view); |
| 526 | proceed=SetImageProgress(image,AppendImageTag,n,number_images); |
| 527 | if (proceed == MagickFalse) |
| 528 | break; |
| 529 | if (stack == MagickFalse) |
| 530 | { |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 531 | x_offset+=(ssize_t) image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 532 | y_offset=0; |
| 533 | } |
| 534 | else |
| 535 | { |
| 536 | x_offset=0; |
cristy | eaedf06 | 2010-05-29 22:36:02 +0000 | [diff] [blame] | 537 | y_offset+=(ssize_t) image->rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 538 | } |
| 539 | image=GetNextImageInList(image); |
| 540 | } |
| 541 | append_view=DestroyCacheView(append_view); |
| 542 | if (status == MagickFalse) |
| 543 | append_image=DestroyImage(append_image); |
| 544 | return(append_image); |
| 545 | } |
| 546 | |
| 547 | /* |
| 548 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 549 | % % |
| 550 | % % |
| 551 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 552 | % C a t c h I m a g e E x c e p t i o n % |
| 553 | % % |
| 554 | % % |
| 555 | % % |
| 556 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 557 | % |
| 558 | % CatchImageException() returns if no exceptions are found in the image |
| 559 | % sequence, otherwise it determines the most severe exception and reports |
| 560 | % it as a warning or error depending on the severity. |
| 561 | % |
| 562 | % The format of the CatchImageException method is: |
| 563 | % |
| 564 | % ExceptionType CatchImageException(Image *image) |
| 565 | % |
| 566 | % A description of each parameter follows: |
| 567 | % |
| 568 | % o image: An image sequence. |
| 569 | % |
| 570 | */ |
| 571 | MagickExport ExceptionType CatchImageException(Image *image) |
| 572 | { |
| 573 | ExceptionInfo |
| 574 | *exception; |
| 575 | |
| 576 | ExceptionType |
| 577 | severity; |
| 578 | |
| 579 | assert(image != (const Image *) NULL); |
| 580 | assert(image->signature == MagickSignature); |
| 581 | if (image->debug != MagickFalse) |
| 582 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 583 | exception=AcquireExceptionInfo(); |
| 584 | GetImageException(image,exception); |
| 585 | CatchException(exception); |
| 586 | severity=exception->severity; |
| 587 | exception=DestroyExceptionInfo(exception); |
| 588 | return(severity); |
| 589 | } |
| 590 | |
| 591 | /* |
| 592 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 593 | % % |
| 594 | % % |
| 595 | % % |
| 596 | % C l i p I m a g e P a t h % |
| 597 | % % |
| 598 | % % |
| 599 | % % |
| 600 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 601 | % |
| 602 | % ClipImagePath() sets the image clip mask based any clipping path information |
| 603 | % if it exists. |
| 604 | % |
| 605 | % The format of the ClipImagePath method is: |
| 606 | % |
| 607 | % MagickBooleanType ClipImagePath(Image *image,const char *pathname, |
| 608 | % const MagickBooleanType inside) |
| 609 | % |
| 610 | % A description of each parameter follows: |
| 611 | % |
| 612 | % o image: the image. |
| 613 | % |
| 614 | % o pathname: name of clipping path resource. If name is preceded by #, use |
| 615 | % clipping path numbered by name. |
| 616 | % |
| 617 | % o inside: if non-zero, later operations take effect inside clipping path. |
| 618 | % Otherwise later operations take effect outside clipping path. |
| 619 | % |
| 620 | */ |
| 621 | |
| 622 | MagickExport MagickBooleanType ClipImage(Image *image) |
| 623 | { |
| 624 | return(ClipImagePath(image,"#1",MagickTrue)); |
| 625 | } |
| 626 | |
| 627 | MagickExport MagickBooleanType ClipImagePath(Image *image,const char *pathname, |
| 628 | const MagickBooleanType inside) |
| 629 | { |
| 630 | #define ClipImagePathTag "ClipPath/Image" |
| 631 | |
| 632 | char |
| 633 | *property; |
| 634 | |
| 635 | const char |
| 636 | *value; |
| 637 | |
| 638 | Image |
| 639 | *clip_mask; |
| 640 | |
| 641 | ImageInfo |
| 642 | *image_info; |
| 643 | |
| 644 | assert(image != (const Image *) NULL); |
| 645 | assert(image->signature == MagickSignature); |
| 646 | if (image->debug != MagickFalse) |
| 647 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 648 | assert(pathname != NULL); |
| 649 | property=AcquireString(pathname); |
| 650 | (void) FormatMagickString(property,MaxTextExtent,"8BIM:1999,2998:%s", |
| 651 | pathname); |
| 652 | value=GetImageProperty(image,property); |
| 653 | property=DestroyString(property); |
| 654 | if (value == (const char *) NULL) |
| 655 | { |
| 656 | ThrowFileException(&image->exception,OptionError,"NoClipPathDefined", |
| 657 | image->filename); |
| 658 | return(MagickFalse); |
| 659 | } |
| 660 | image_info=AcquireImageInfo(); |
| 661 | (void) CopyMagickString(image_info->filename,image->filename,MaxTextExtent); |
| 662 | (void) ConcatenateMagickString(image_info->filename,pathname,MaxTextExtent); |
| 663 | clip_mask=BlobToImage(image_info,value,strlen(value),&image->exception); |
| 664 | image_info=DestroyImageInfo(image_info); |
| 665 | if (clip_mask == (Image *) NULL) |
| 666 | return(MagickFalse); |
| 667 | if (clip_mask->storage_class == PseudoClass) |
| 668 | { |
| 669 | (void) SyncImage(clip_mask); |
| 670 | if (SetImageStorageClass(clip_mask,DirectClass) == MagickFalse) |
| 671 | return(MagickFalse); |
| 672 | } |
| 673 | if (inside == MagickFalse) |
| 674 | (void) NegateImage(clip_mask,MagickFalse); |
| 675 | (void) FormatMagickString(clip_mask->magick_filename,MaxTextExtent, |
| 676 | "8BIM:1999,2998:%s\nPS",pathname); |
| 677 | (void) SetImageClipMask(image,clip_mask); |
| 678 | clip_mask=DestroyImage(clip_mask); |
| 679 | return(MagickTrue); |
| 680 | } |
| 681 | |
| 682 | /* |
| 683 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 684 | % % |
| 685 | % % |
| 686 | % % |
| 687 | % C l o n e I m a g e % |
| 688 | % % |
| 689 | % % |
| 690 | % % |
| 691 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 692 | % |
| 693 | % CloneImage() copies an image and returns the copy as a new image object. |
| 694 | % If the specified columns and rows is 0, an exact copy of the image is |
| 695 | % returned, otherwise the pixel data is undefined and must be initialized |
| 696 | % with the QueueAuthenticPixels() and SyncAuthenticPixels() methods. On |
| 697 | % failure, a NULL image is returned and exception describes the reason for the |
| 698 | % failure. |
| 699 | % |
| 700 | % The format of the CloneImage method is: |
| 701 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 702 | % Image *CloneImage(const Image *image,const size_t columns, |
| 703 | % const size_t rows,const MagickBooleanType orphan, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 704 | % ExceptionInfo *exception) |
| 705 | % |
| 706 | % A description of each parameter follows: |
| 707 | % |
| 708 | % o image: the image. |
| 709 | % |
| 710 | % o columns: the number of columns in the cloned image. |
| 711 | % |
| 712 | % o rows: the number of rows in the cloned image. |
| 713 | % |
| 714 | % o detach: With a value other than 0, the cloned image is detached from |
| 715 | % its parent I/O stream. |
| 716 | % |
| 717 | % o exception: return any errors or warnings in this structure. |
| 718 | % |
| 719 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 720 | MagickExport Image *CloneImage(const Image *image,const size_t columns, |
| 721 | const size_t rows,const MagickBooleanType detach, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 722 | ExceptionInfo *exception) |
| 723 | { |
| 724 | Image |
| 725 | *clone_image; |
| 726 | |
| 727 | MagickRealType |
| 728 | scale; |
| 729 | |
| 730 | size_t |
| 731 | length; |
| 732 | |
| 733 | /* |
| 734 | Clone the image. |
| 735 | */ |
| 736 | assert(image != (const Image *) NULL); |
| 737 | assert(image->signature == MagickSignature); |
| 738 | if (image->debug != MagickFalse) |
| 739 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 740 | assert(exception != (ExceptionInfo *) NULL); |
| 741 | assert(exception->signature == MagickSignature); |
cristy | 9082321 | 2009-12-12 20:48:33 +0000 | [diff] [blame] | 742 | clone_image=(Image *) AcquireAlignedMemory(1,sizeof(*clone_image)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 743 | if (clone_image == (Image *) NULL) |
| 744 | ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); |
| 745 | (void) ResetMagickMemory(clone_image,0,sizeof(*clone_image)); |
| 746 | clone_image->signature=MagickSignature; |
| 747 | clone_image->storage_class=image->storage_class; |
| 748 | clone_image->colorspace=image->colorspace; |
| 749 | clone_image->matte=image->matte; |
| 750 | clone_image->columns=image->columns; |
| 751 | clone_image->rows=image->rows; |
| 752 | clone_image->dither=image->dither; |
| 753 | if (image->colormap != (PixelPacket *) NULL) |
| 754 | { |
| 755 | /* |
| 756 | Allocate and copy the image colormap. |
| 757 | */ |
| 758 | clone_image->colors=image->colors; |
| 759 | length=(size_t) image->colors; |
| 760 | clone_image->colormap=(PixelPacket *) AcquireQuantumMemory(length, |
| 761 | sizeof(*clone_image->colormap)); |
| 762 | if (clone_image->colormap == (PixelPacket *) NULL) |
| 763 | ThrowImageException(ResourceLimitError,"MemoryAllocationFailed"); |
| 764 | (void) CopyMagickMemory(clone_image->colormap,image->colormap,length* |
| 765 | sizeof(*clone_image->colormap)); |
| 766 | } |
| 767 | (void) CloneImageProfiles(clone_image,image); |
| 768 | (void) CloneImageProperties(clone_image,image); |
| 769 | (void) CloneImageArtifacts(clone_image,image); |
| 770 | GetTimerInfo(&clone_image->timer); |
| 771 | GetExceptionInfo(&clone_image->exception); |
| 772 | InheritException(&clone_image->exception,&image->exception); |
| 773 | if (image->ascii85 != (void *) NULL) |
| 774 | Ascii85Initialize(clone_image); |
| 775 | clone_image->magick_columns=image->magick_columns; |
| 776 | clone_image->magick_rows=image->magick_rows; |
| 777 | clone_image->type=image->type; |
| 778 | (void) CopyMagickString(clone_image->magick_filename,image->magick_filename, |
| 779 | MaxTextExtent); |
| 780 | (void) CopyMagickString(clone_image->magick,image->magick,MaxTextExtent); |
| 781 | (void) CopyMagickString(clone_image->filename,image->filename,MaxTextExtent); |
| 782 | clone_image->progress_monitor=image->progress_monitor; |
| 783 | clone_image->client_data=image->client_data; |
| 784 | clone_image->reference_count=1; |
| 785 | clone_image->next=NewImageList(); |
| 786 | clone_image->previous=NewImageList(); |
| 787 | clone_image->list=NewImageList(); |
| 788 | clone_image->clip_mask=NewImageList(); |
| 789 | clone_image->mask=NewImageList(); |
| 790 | if (detach == MagickFalse) |
| 791 | clone_image->blob=ReferenceBlob(image->blob); |
| 792 | else |
| 793 | clone_image->blob=CloneBlobInfo((BlobInfo *) NULL); |
cristy | 7372451 | 2010-04-12 14:43:14 +0000 | [diff] [blame] | 794 | clone_image->ping=image->ping; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 795 | clone_image->debug=IsEventLogging(); |
| 796 | clone_image->semaphore=AllocateSemaphoreInfo(); |
| 797 | if ((columns == 0) && (rows == 0)) |
| 798 | { |
| 799 | if (image->montage != (char *) NULL) |
| 800 | (void) CloneString(&clone_image->montage,image->montage); |
| 801 | if (image->directory != (char *) NULL) |
| 802 | (void) CloneString(&clone_image->directory,image->directory); |
| 803 | if (image->clip_mask != (Image *) NULL) |
| 804 | clone_image->clip_mask=CloneImage(image->clip_mask,0,0,MagickTrue, |
| 805 | exception); |
| 806 | if (image->mask != (Image *) NULL) |
| 807 | clone_image->mask=CloneImage(image->mask,0,0,MagickTrue,exception); |
| 808 | clone_image->cache=ReferencePixelCache(image->cache); |
| 809 | return(clone_image); |
| 810 | } |
| 811 | scale=(MagickRealType) columns/(MagickRealType) image->columns; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 812 | clone_image->page.width=(size_t) floor(scale*image->page.width+0.5); |
| 813 | clone_image->page.x=(ssize_t) ceil(scale*image->page.x-0.5); |
| 814 | clone_image->tile_offset.x=(ssize_t) ceil(scale*image->tile_offset.x-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 815 | scale=(MagickRealType) rows/(MagickRealType) image->rows; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 816 | clone_image->page.height=(size_t) floor(scale*image->page.height+0.5); |
| 817 | clone_image->page.y=(ssize_t) ceil(scale*image->page.y-0.5); |
| 818 | clone_image->tile_offset.y=(ssize_t) ceil(scale*image->tile_offset.y-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 819 | clone_image->columns=columns; |
| 820 | clone_image->rows=rows; |
| 821 | clone_image->cache=ClonePixelCache(image->cache); |
| 822 | return(clone_image); |
| 823 | } |
| 824 | |
| 825 | /* |
| 826 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 827 | % % |
| 828 | % % |
| 829 | % % |
| 830 | % C l o n e I m a g e I n f o % |
| 831 | % % |
| 832 | % % |
| 833 | % % |
| 834 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 835 | % |
| 836 | % CloneImageInfo() makes a copy of the given image info structure. If |
| 837 | % NULL is specified, a new image info structure is created initialized to |
| 838 | % default values. |
| 839 | % |
| 840 | % The format of the CloneImageInfo method is: |
| 841 | % |
| 842 | % ImageInfo *CloneImageInfo(const ImageInfo *image_info) |
| 843 | % |
| 844 | % A description of each parameter follows: |
| 845 | % |
| 846 | % o image_info: the image info. |
| 847 | % |
| 848 | */ |
| 849 | MagickExport ImageInfo *CloneImageInfo(const ImageInfo *image_info) |
| 850 | { |
| 851 | ImageInfo |
| 852 | *clone_info; |
| 853 | |
| 854 | clone_info=AcquireImageInfo(); |
| 855 | if (image_info == (ImageInfo *) NULL) |
| 856 | return(clone_info); |
| 857 | clone_info->compression=image_info->compression; |
| 858 | clone_info->temporary=image_info->temporary; |
| 859 | clone_info->adjoin=image_info->adjoin; |
| 860 | clone_info->antialias=image_info->antialias; |
| 861 | clone_info->scene=image_info->scene; |
| 862 | clone_info->number_scenes=image_info->number_scenes; |
| 863 | clone_info->depth=image_info->depth; |
| 864 | if (image_info->size != (char *) NULL) |
| 865 | (void) CloneString(&clone_info->size,image_info->size); |
| 866 | if (image_info->extract != (char *) NULL) |
| 867 | (void) CloneString(&clone_info->extract,image_info->extract); |
| 868 | if (image_info->scenes != (char *) NULL) |
| 869 | (void) CloneString(&clone_info->scenes,image_info->scenes); |
| 870 | if (image_info->page != (char *) NULL) |
| 871 | (void) CloneString(&clone_info->page,image_info->page); |
| 872 | clone_info->interlace=image_info->interlace; |
| 873 | clone_info->endian=image_info->endian; |
| 874 | clone_info->units=image_info->units; |
| 875 | clone_info->quality=image_info->quality; |
| 876 | if (image_info->sampling_factor != (char *) NULL) |
| 877 | (void) CloneString(&clone_info->sampling_factor, |
| 878 | image_info->sampling_factor); |
| 879 | if (image_info->server_name != (char *) NULL) |
| 880 | (void) CloneString(&clone_info->server_name,image_info->server_name); |
| 881 | if (image_info->font != (char *) NULL) |
| 882 | (void) CloneString(&clone_info->font,image_info->font); |
| 883 | if (image_info->texture != (char *) NULL) |
| 884 | (void) CloneString(&clone_info->texture,image_info->texture); |
| 885 | if (image_info->density != (char *) NULL) |
| 886 | (void) CloneString(&clone_info->density,image_info->density); |
| 887 | clone_info->pointsize=image_info->pointsize; |
| 888 | clone_info->fuzz=image_info->fuzz; |
| 889 | clone_info->pen=image_info->pen; |
| 890 | clone_info->background_color=image_info->background_color; |
| 891 | clone_info->border_color=image_info->border_color; |
| 892 | clone_info->matte_color=image_info->matte_color; |
| 893 | clone_info->transparent_color=image_info->transparent_color; |
| 894 | clone_info->dither=image_info->dither; |
| 895 | clone_info->monochrome=image_info->monochrome; |
| 896 | clone_info->colors=image_info->colors; |
| 897 | clone_info->colorspace=image_info->colorspace; |
| 898 | clone_info->type=image_info->type; |
| 899 | clone_info->orientation=image_info->orientation; |
| 900 | clone_info->preview_type=image_info->preview_type; |
| 901 | clone_info->group=image_info->group; |
| 902 | clone_info->ping=image_info->ping; |
| 903 | clone_info->verbose=image_info->verbose; |
| 904 | if (image_info->view != (char *) NULL) |
| 905 | (void) CloneString(&clone_info->view,image_info->view); |
| 906 | if (image_info->authenticate != (char *) NULL) |
| 907 | (void) CloneString(&clone_info->authenticate,image_info->authenticate); |
| 908 | (void) CloneImageOptions(clone_info,image_info); |
| 909 | clone_info->progress_monitor=image_info->progress_monitor; |
| 910 | clone_info->client_data=image_info->client_data; |
| 911 | clone_info->cache=image_info->cache; |
| 912 | if (image_info->cache != (void *) NULL) |
| 913 | clone_info->cache=ReferencePixelCache(image_info->cache); |
| 914 | if (image_info->profile != (void *) NULL) |
| 915 | clone_info->profile=(void *) CloneStringInfo((StringInfo *) |
| 916 | image_info->profile); |
| 917 | SetImageInfoFile(clone_info,image_info->file); |
| 918 | SetImageInfoBlob(clone_info,image_info->blob,image_info->length); |
| 919 | clone_info->stream=image_info->stream; |
| 920 | clone_info->virtual_pixel_method=image_info->virtual_pixel_method; |
| 921 | (void) CopyMagickString(clone_info->magick,image_info->magick,MaxTextExtent); |
| 922 | (void) CopyMagickString(clone_info->unique,image_info->unique,MaxTextExtent); |
| 923 | (void) CopyMagickString(clone_info->zero,image_info->zero,MaxTextExtent); |
| 924 | (void) CopyMagickString(clone_info->filename,image_info->filename, |
| 925 | MaxTextExtent); |
| 926 | clone_info->subimage=image_info->scene; /* deprecated */ |
| 927 | clone_info->subrange=image_info->number_scenes; /* deprecated */ |
| 928 | clone_info->channel=image_info->channel; |
| 929 | clone_info->debug=IsEventLogging(); |
| 930 | clone_info->signature=image_info->signature; |
| 931 | return(clone_info); |
| 932 | } |
| 933 | |
| 934 | /* |
| 935 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 936 | % % |
| 937 | % % |
| 938 | % % |
| 939 | % C o m b i n e I m a g e s % |
| 940 | % % |
| 941 | % % |
| 942 | % % |
| 943 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 944 | % |
| 945 | % CombineImages() combines one or more images into a single image. The |
| 946 | % grayscale value of the pixels of each image in the sequence is assigned in |
| 947 | % order to the specified channels of the combined image. The typical |
| 948 | % ordering would be image 1 => Red, 2 => Green, 3 => Blue, etc. |
| 949 | % |
| 950 | % The format of the CombineImages method is: |
| 951 | % |
| 952 | % Image *CombineImages(const Image *image,const ChannelType channel, |
| 953 | % ExceptionInfo *exception) |
| 954 | % |
| 955 | % A description of each parameter follows: |
| 956 | % |
| 957 | % o image: the image. |
| 958 | % |
| 959 | % o exception: return any errors or warnings in this structure. |
| 960 | % |
| 961 | */ |
| 962 | MagickExport Image *CombineImages(const Image *image,const ChannelType channel, |
| 963 | ExceptionInfo *exception) |
| 964 | { |
| 965 | #define CombineImageTag "Combine/Image" |
| 966 | |
| 967 | CacheView |
| 968 | *combine_view; |
| 969 | |
| 970 | const Image |
| 971 | *next; |
| 972 | |
| 973 | Image |
| 974 | *combine_image; |
| 975 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 976 | MagickBooleanType |
| 977 | status; |
| 978 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 979 | MagickOffsetType |
| 980 | progress; |
| 981 | |
| 982 | ssize_t |
| 983 | y; |
| 984 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 985 | /* |
| 986 | Ensure the image are the same size. |
| 987 | */ |
| 988 | assert(image != (const Image *) NULL); |
| 989 | assert(image->signature == MagickSignature); |
| 990 | if (image->debug != MagickFalse) |
| 991 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 992 | assert(exception != (ExceptionInfo *) NULL); |
| 993 | assert(exception->signature == MagickSignature); |
| 994 | for (next=image; next != (Image *) NULL; next=GetNextImageInList(next)) |
| 995 | { |
| 996 | if ((next->columns != image->columns) || (next->rows != image->rows)) |
| 997 | ThrowImageException(OptionError,"ImagesAreNotTheSameSize"); |
| 998 | } |
| 999 | combine_image=CloneImage(image,0,0,MagickTrue,exception); |
| 1000 | if (combine_image == (Image *) NULL) |
| 1001 | return((Image *) NULL); |
| 1002 | if (SetImageStorageClass(combine_image,DirectClass) == MagickFalse) |
| 1003 | { |
| 1004 | InheritException(exception,&combine_image->exception); |
| 1005 | combine_image=DestroyImage(combine_image); |
| 1006 | return((Image *) NULL); |
| 1007 | } |
| 1008 | if ((channel & OpacityChannel) != 0) |
| 1009 | combine_image->matte=MagickTrue; |
| 1010 | (void) SetImageBackgroundColor(combine_image); |
| 1011 | /* |
| 1012 | Combine images. |
| 1013 | */ |
| 1014 | status=MagickTrue; |
| 1015 | progress=0; |
| 1016 | combine_view=AcquireCacheView(combine_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1017 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 1018 | #pragma omp parallel for schedule(dynamic,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1020 | for (y=0; y < (ssize_t) combine_image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1021 | { |
| 1022 | CacheView |
| 1023 | *image_view; |
| 1024 | |
| 1025 | const Image |
| 1026 | *next; |
| 1027 | |
| 1028 | PixelPacket |
| 1029 | *pixels; |
| 1030 | |
| 1031 | register const PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1032 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1033 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1034 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1035 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1036 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 1037 | register ssize_t |
| 1038 | x; |
| 1039 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1040 | if (status == MagickFalse) |
| 1041 | continue; |
| 1042 | pixels=GetCacheViewAuthenticPixels(combine_view,0,y,combine_image->columns, |
| 1043 | 1,exception); |
| 1044 | if (pixels == (PixelPacket *) NULL) |
| 1045 | { |
| 1046 | status=MagickFalse; |
| 1047 | continue; |
| 1048 | } |
| 1049 | next=image; |
| 1050 | if (((channel & RedChannel) != 0) && (next != (Image *) NULL)) |
| 1051 | { |
| 1052 | image_view=AcquireCacheView(next); |
| 1053 | p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception); |
| 1054 | if (p == (const PixelPacket *) NULL) |
| 1055 | continue; |
| 1056 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1057 | for (x=0; x < (ssize_t) combine_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1058 | { |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1059 | SetRedPixelComponent(q,PixelIntensityToQuantum(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1060 | p++; |
| 1061 | q++; |
| 1062 | } |
| 1063 | image_view=DestroyCacheView(image_view); |
| 1064 | next=GetNextImageInList(next); |
| 1065 | } |
| 1066 | if (((channel & GreenChannel) != 0) && (next != (Image *) NULL)) |
| 1067 | { |
| 1068 | image_view=AcquireCacheView(next); |
| 1069 | p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception); |
| 1070 | if (p == (const PixelPacket *) NULL) |
| 1071 | continue; |
| 1072 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1073 | for (x=0; x < (ssize_t) combine_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1074 | { |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1075 | SetGreenPixelComponent(q,PixelIntensityToQuantum(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1076 | p++; |
| 1077 | q++; |
| 1078 | } |
| 1079 | image_view=DestroyCacheView(image_view); |
| 1080 | next=GetNextImageInList(next); |
| 1081 | } |
| 1082 | if (((channel & BlueChannel) != 0) && (next != (Image *) NULL)) |
| 1083 | { |
| 1084 | image_view=AcquireCacheView(next); |
| 1085 | p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception); |
| 1086 | if (p == (const PixelPacket *) NULL) |
| 1087 | continue; |
| 1088 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1089 | for (x=0; x < (ssize_t) combine_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1090 | { |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1091 | SetBluePixelComponent(q,PixelIntensityToQuantum(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1092 | p++; |
| 1093 | q++; |
| 1094 | } |
| 1095 | image_view=DestroyCacheView(image_view); |
| 1096 | next=GetNextImageInList(next); |
| 1097 | } |
| 1098 | if (((channel & OpacityChannel) != 0) && (next != (Image *) NULL)) |
| 1099 | { |
| 1100 | image_view=AcquireCacheView(next); |
| 1101 | p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception); |
| 1102 | if (p == (const PixelPacket *) NULL) |
| 1103 | continue; |
| 1104 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1105 | for (x=0; x < (ssize_t) combine_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1106 | { |
cristy | ce70c17 | 2010-01-07 17:15:30 +0000 | [diff] [blame] | 1107 | SetOpacityPixelComponent(q,PixelIntensityToQuantum(p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1108 | p++; |
| 1109 | q++; |
| 1110 | } |
| 1111 | image_view=DestroyCacheView(image_view); |
| 1112 | next=GetNextImageInList(next); |
| 1113 | } |
| 1114 | if (((channel & IndexChannel) != 0) && |
| 1115 | (image->colorspace == CMYKColorspace) && (next != (Image *) NULL)) |
| 1116 | { |
| 1117 | IndexPacket |
| 1118 | *indexes; |
| 1119 | |
| 1120 | image_view=AcquireCacheView(next); |
| 1121 | p=GetCacheViewVirtualPixels(image_view,0,y,next->columns,1,exception); |
| 1122 | if (p == (const PixelPacket *) NULL) |
| 1123 | continue; |
| 1124 | indexes=GetCacheViewAuthenticIndexQueue(combine_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1125 | for (x=0; x < (ssize_t) combine_image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1126 | { |
| 1127 | indexes[x]=PixelIntensityToQuantum(p); |
| 1128 | p++; |
| 1129 | } |
| 1130 | image_view=DestroyCacheView(image_view); |
| 1131 | next=GetNextImageInList(next); |
| 1132 | } |
| 1133 | if (SyncCacheViewAuthenticPixels(combine_view,exception) == MagickFalse) |
| 1134 | status=MagickFalse; |
| 1135 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1136 | { |
| 1137 | MagickBooleanType |
| 1138 | proceed; |
| 1139 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1140 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1141 | #pragma omp critical (MagickCore_CombineImages) |
| 1142 | #endif |
| 1143 | proceed=SetImageProgress(image,CombineImageTag,progress++, |
| 1144 | combine_image->rows); |
| 1145 | if (proceed == MagickFalse) |
| 1146 | status=MagickFalse; |
| 1147 | } |
| 1148 | } |
| 1149 | combine_view=DestroyCacheView(combine_view); |
| 1150 | if (status == MagickFalse) |
| 1151 | combine_image=DestroyImage(combine_image); |
| 1152 | return(combine_image); |
| 1153 | } |
| 1154 | |
| 1155 | /* |
| 1156 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1157 | % % |
| 1158 | % % |
| 1159 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1160 | % D e s t r o y I m a g e % |
| 1161 | % % |
| 1162 | % % |
| 1163 | % % |
| 1164 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1165 | % |
| 1166 | % DestroyImage() dereferences an image, deallocating memory associated with |
| 1167 | % the image if the reference count becomes zero. |
| 1168 | % |
| 1169 | % The format of the DestroyImage method is: |
| 1170 | % |
| 1171 | % Image *DestroyImage(Image *image) |
| 1172 | % |
| 1173 | % A description of each parameter follows: |
| 1174 | % |
| 1175 | % o image: the image. |
| 1176 | % |
| 1177 | */ |
| 1178 | MagickExport Image *DestroyImage(Image *image) |
| 1179 | { |
| 1180 | MagickBooleanType |
| 1181 | destroy; |
| 1182 | |
| 1183 | /* |
| 1184 | Dereference image. |
| 1185 | */ |
| 1186 | assert(image != (Image *) NULL); |
| 1187 | assert(image->signature == MagickSignature); |
| 1188 | if (image->debug != MagickFalse) |
| 1189 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1190 | destroy=MagickFalse; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1191 | LockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1192 | image->reference_count--; |
| 1193 | if (image->reference_count == 0) |
| 1194 | destroy=MagickTrue; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1195 | UnlockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1196 | if (destroy == MagickFalse) |
| 1197 | return((Image *) NULL); |
| 1198 | /* |
| 1199 | Destroy image. |
| 1200 | */ |
| 1201 | DestroyImagePixels(image); |
| 1202 | if (image->clip_mask != (Image *) NULL) |
| 1203 | image->clip_mask=DestroyImage(image->clip_mask); |
| 1204 | if (image->mask != (Image *) NULL) |
| 1205 | image->mask=DestroyImage(image->mask); |
| 1206 | if (image->montage != (char *) NULL) |
| 1207 | image->montage=DestroyString(image->montage); |
| 1208 | if (image->directory != (char *) NULL) |
| 1209 | image->directory=DestroyString(image->directory); |
| 1210 | if (image->colormap != (PixelPacket *) NULL) |
| 1211 | image->colormap=(PixelPacket *) RelinquishMagickMemory(image->colormap); |
| 1212 | if (image->geometry != (char *) NULL) |
| 1213 | image->geometry=DestroyString(image->geometry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1214 | DestroyImageProfiles(image); |
| 1215 | DestroyImageProperties(image); |
| 1216 | DestroyImageArtifacts(image); |
| 1217 | if (image->ascii85 != (Ascii85Info*) NULL) |
| 1218 | image->ascii85=(Ascii85Info *) RelinquishMagickMemory(image->ascii85); |
| 1219 | DestroyBlob(image); |
| 1220 | (void) DestroyExceptionInfo(&image->exception); |
| 1221 | if (image->semaphore != (SemaphoreInfo *) NULL) |
| 1222 | DestroySemaphoreInfo(&image->semaphore); |
| 1223 | image->signature=(~MagickSignature); |
| 1224 | image=(Image *) RelinquishMagickMemory(image); |
| 1225 | return(image); |
| 1226 | } |
| 1227 | |
| 1228 | /* |
| 1229 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1230 | % % |
| 1231 | % % |
| 1232 | % % |
| 1233 | % D e s t r o y I m a g e I n f o % |
| 1234 | % % |
| 1235 | % % |
| 1236 | % % |
| 1237 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1238 | % |
| 1239 | % DestroyImageInfo() deallocates memory associated with an ImageInfo |
| 1240 | % structure. |
| 1241 | % |
| 1242 | % The format of the DestroyImageInfo method is: |
| 1243 | % |
| 1244 | % ImageInfo *DestroyImageInfo(ImageInfo *image_info) |
| 1245 | % |
| 1246 | % A description of each parameter follows: |
| 1247 | % |
| 1248 | % o image_info: the image info. |
| 1249 | % |
| 1250 | */ |
| 1251 | MagickExport ImageInfo *DestroyImageInfo(ImageInfo *image_info) |
| 1252 | { |
| 1253 | assert(image_info != (ImageInfo *) NULL); |
| 1254 | assert(image_info->signature == MagickSignature); |
| 1255 | if (image_info->debug != MagickFalse) |
| 1256 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1257 | image_info->filename); |
| 1258 | if (image_info->size != (char *) NULL) |
| 1259 | image_info->size=DestroyString(image_info->size); |
| 1260 | if (image_info->extract != (char *) NULL) |
| 1261 | image_info->extract=DestroyString(image_info->extract); |
| 1262 | if (image_info->scenes != (char *) NULL) |
| 1263 | image_info->scenes=DestroyString(image_info->scenes); |
| 1264 | if (image_info->page != (char *) NULL) |
| 1265 | image_info->page=DestroyString(image_info->page); |
| 1266 | if (image_info->sampling_factor != (char *) NULL) |
| 1267 | image_info->sampling_factor=DestroyString( |
| 1268 | image_info->sampling_factor); |
| 1269 | if (image_info->server_name != (char *) NULL) |
| 1270 | image_info->server_name=DestroyString( |
| 1271 | image_info->server_name); |
| 1272 | if (image_info->font != (char *) NULL) |
| 1273 | image_info->font=DestroyString(image_info->font); |
| 1274 | if (image_info->texture != (char *) NULL) |
| 1275 | image_info->texture=DestroyString(image_info->texture); |
| 1276 | if (image_info->density != (char *) NULL) |
| 1277 | image_info->density=DestroyString(image_info->density); |
| 1278 | if (image_info->view != (char *) NULL) |
| 1279 | image_info->view=DestroyString(image_info->view); |
| 1280 | if (image_info->authenticate != (char *) NULL) |
| 1281 | image_info->authenticate=DestroyString( |
| 1282 | image_info->authenticate); |
| 1283 | DestroyImageOptions(image_info); |
| 1284 | if (image_info->cache != (void *) NULL) |
| 1285 | image_info->cache=DestroyPixelCache(image_info->cache); |
| 1286 | if (image_info->profile != (StringInfo *) NULL) |
| 1287 | image_info->profile=(void *) DestroyStringInfo((StringInfo *) |
| 1288 | image_info->profile); |
| 1289 | image_info->signature=(~MagickSignature); |
| 1290 | image_info=(ImageInfo *) RelinquishMagickMemory(image_info); |
| 1291 | return(image_info); |
| 1292 | } |
| 1293 | |
| 1294 | /* |
| 1295 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1296 | % % |
| 1297 | % % |
| 1298 | % % |
| 1299 | + D i s a s s o c i a t e I m a g e S t r e a m % |
| 1300 | % % |
| 1301 | % % |
| 1302 | % % |
| 1303 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1304 | % |
| 1305 | % DisassociateImageStream() disassociates the image stream. |
| 1306 | % |
| 1307 | % The format of the DisassociateImageStream method is: |
| 1308 | % |
| 1309 | % MagickBooleanType DisassociateImageStream(const Image *image) |
| 1310 | % |
| 1311 | % A description of each parameter follows: |
| 1312 | % |
| 1313 | % o image: the image. |
| 1314 | % |
| 1315 | */ |
| 1316 | MagickExport void DisassociateImageStream(Image *image) |
| 1317 | { |
| 1318 | assert(image != (const Image *) NULL); |
| 1319 | assert(image->signature == MagickSignature); |
| 1320 | if (image->debug != MagickFalse) |
| 1321 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1322 | (void) DetachBlob(image->blob); |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1327 | % % |
| 1328 | % % |
| 1329 | % % |
| 1330 | % G e t I m a g e A l p h a C h a n n e l % |
| 1331 | % % |
| 1332 | % % |
| 1333 | % % |
| 1334 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1335 | % |
| 1336 | % GetImageAlphaChannel() returns MagickFalse if the image alpha channel is |
| 1337 | % not activated. That is, the image is RGB rather than RGBA or CMYK rather |
| 1338 | % than CMYKA. |
| 1339 | % |
| 1340 | % The format of the GetImageAlphaChannel method is: |
| 1341 | % |
| 1342 | % MagickBooleanType GetImageAlphaChannel(const Image *image) |
| 1343 | % |
| 1344 | % A description of each parameter follows: |
| 1345 | % |
| 1346 | % o image: the image. |
| 1347 | % |
| 1348 | */ |
| 1349 | MagickExport MagickBooleanType GetImageAlphaChannel(const Image *image) |
| 1350 | { |
| 1351 | assert(image != (const Image *) NULL); |
| 1352 | if (image->debug != MagickFalse) |
| 1353 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1354 | assert(image->signature == MagickSignature); |
| 1355 | return(image->matte); |
| 1356 | } |
| 1357 | |
| 1358 | /* |
| 1359 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1360 | % % |
| 1361 | % % |
| 1362 | % % |
| 1363 | % G e t I m a g e C l i p M a s k % |
| 1364 | % % |
| 1365 | % % |
| 1366 | % % |
| 1367 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1368 | % |
| 1369 | % GetImageClipMask() returns the clip path associated with the image. |
| 1370 | % |
| 1371 | % The format of the GetImageClipMask method is: |
| 1372 | % |
| 1373 | % Image *GetImageClipMask(const Image *image,ExceptionInfo *exception) |
| 1374 | % |
| 1375 | % A description of each parameter follows: |
| 1376 | % |
| 1377 | % o image: the image. |
| 1378 | % |
| 1379 | */ |
| 1380 | MagickExport Image *GetImageClipMask(const Image *image, |
| 1381 | ExceptionInfo *exception) |
| 1382 | { |
| 1383 | assert(image != (const Image *) NULL); |
| 1384 | if (image->debug != MagickFalse) |
| 1385 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1386 | assert(image->signature == MagickSignature); |
| 1387 | if (image->clip_mask == (Image *) NULL) |
| 1388 | return((Image *) NULL); |
| 1389 | return(CloneImage(image->clip_mask,0,0,MagickTrue,exception)); |
| 1390 | } |
| 1391 | |
| 1392 | /* |
| 1393 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1394 | % % |
| 1395 | % % |
| 1396 | % % |
| 1397 | % G e t I m a g e E x c e p t i o n % |
| 1398 | % % |
| 1399 | % % |
| 1400 | % % |
| 1401 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1402 | % |
| 1403 | % GetImageException() traverses an image sequence and returns any |
| 1404 | % error more severe than noted by the exception parameter. |
| 1405 | % |
| 1406 | % The format of the GetImageException method is: |
| 1407 | % |
| 1408 | % void GetImageException(Image *image,ExceptionInfo *exception) |
| 1409 | % |
| 1410 | % A description of each parameter follows: |
| 1411 | % |
| 1412 | % o image: Specifies a pointer to a list of one or more images. |
| 1413 | % |
| 1414 | % o exception: return the highest severity exception. |
| 1415 | % |
| 1416 | */ |
| 1417 | MagickExport void GetImageException(Image *image,ExceptionInfo *exception) |
| 1418 | { |
| 1419 | register Image |
| 1420 | *next; |
| 1421 | |
| 1422 | assert(image != (Image *) NULL); |
| 1423 | assert(image->signature == MagickSignature); |
| 1424 | if (image->debug != MagickFalse) |
| 1425 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1426 | assert(exception != (ExceptionInfo *) NULL); |
| 1427 | assert(exception->signature == MagickSignature); |
| 1428 | for (next=image; next != (Image *) NULL; next=GetNextImageInList(next)) |
| 1429 | { |
| 1430 | if (next->exception.severity == UndefinedException) |
| 1431 | continue; |
| 1432 | if (next->exception.severity > exception->severity) |
| 1433 | InheritException(exception,&next->exception); |
| 1434 | next->exception.severity=UndefinedException; |
| 1435 | } |
| 1436 | } |
| 1437 | |
| 1438 | /* |
| 1439 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1440 | % % |
| 1441 | % % |
| 1442 | % % |
| 1443 | % G e t I m a g e I n f o % |
| 1444 | % % |
| 1445 | % % |
| 1446 | % % |
| 1447 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1448 | % |
| 1449 | % GetImageInfo() initializes image_info to default values. |
| 1450 | % |
| 1451 | % The format of the GetImageInfo method is: |
| 1452 | % |
| 1453 | % void GetImageInfo(ImageInfo *image_info) |
| 1454 | % |
| 1455 | % A description of each parameter follows: |
| 1456 | % |
| 1457 | % o image_info: the image info. |
| 1458 | % |
| 1459 | */ |
| 1460 | MagickExport void GetImageInfo(ImageInfo *image_info) |
| 1461 | { |
| 1462 | ExceptionInfo |
| 1463 | *exception; |
| 1464 | |
| 1465 | /* |
| 1466 | File and image dimension members. |
| 1467 | */ |
| 1468 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1469 | assert(image_info != (ImageInfo *) NULL); |
| 1470 | (void) ResetMagickMemory(image_info,0,sizeof(*image_info)); |
| 1471 | image_info->adjoin=MagickTrue; |
| 1472 | image_info->interlace=NoInterlace; |
| 1473 | image_info->channel=DefaultChannels; |
| 1474 | image_info->quality=UndefinedCompressionQuality; |
| 1475 | image_info->antialias=MagickTrue; |
| 1476 | image_info->dither=MagickTrue; |
| 1477 | exception=AcquireExceptionInfo(); |
| 1478 | (void) QueryColorDatabase(BackgroundColor,&image_info->background_color, |
| 1479 | exception); |
| 1480 | (void) QueryColorDatabase(BorderColor,&image_info->border_color,exception); |
| 1481 | (void) QueryColorDatabase(MatteColor,&image_info->matte_color,exception); |
| 1482 | (void) QueryColorDatabase(TransparentColor,&image_info->transparent_color, |
| 1483 | exception); |
| 1484 | exception=DestroyExceptionInfo(exception); |
| 1485 | image_info->debug=IsEventLogging(); |
| 1486 | image_info->signature=MagickSignature; |
| 1487 | } |
| 1488 | |
| 1489 | /* |
| 1490 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1491 | % % |
| 1492 | % % |
| 1493 | % % |
cristy | 15781e5 | 2009-12-05 23:05:27 +0000 | [diff] [blame] | 1494 | % G e t I m a g e I n f o F i l e % |
| 1495 | % % |
| 1496 | % % |
| 1497 | % % |
| 1498 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1499 | % |
| 1500 | % GetImageInfoFile() returns the image info file member. |
| 1501 | % |
| 1502 | % The format of the GetImageInfoFile method is: |
| 1503 | % |
| 1504 | % FILE *GetImageInfoFile(const ImageInfo *image_info) |
| 1505 | % |
| 1506 | % A description of each parameter follows: |
| 1507 | % |
| 1508 | % o image_info: the image info. |
| 1509 | % |
| 1510 | */ |
| 1511 | MagickExport FILE *GetImageInfoFile(const ImageInfo *image_info) |
| 1512 | { |
| 1513 | return(image_info->file); |
| 1514 | } |
| 1515 | |
| 1516 | /* |
| 1517 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1518 | % % |
| 1519 | % % |
| 1520 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1521 | % G e t I m a g e M a s k % |
| 1522 | % % |
| 1523 | % % |
| 1524 | % % |
| 1525 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1526 | % |
| 1527 | % GetImageMask() returns the mask associated with the image. |
| 1528 | % |
| 1529 | % The format of the GetImageMask method is: |
| 1530 | % |
| 1531 | % Image *GetImageMask(const Image *image,ExceptionInfo *exception) |
| 1532 | % |
| 1533 | % A description of each parameter follows: |
| 1534 | % |
| 1535 | % o image: the image. |
| 1536 | % |
| 1537 | */ |
| 1538 | MagickExport Image *GetImageMask(const Image *image,ExceptionInfo *exception) |
| 1539 | { |
| 1540 | assert(image != (const Image *) NULL); |
| 1541 | if (image->debug != MagickFalse) |
| 1542 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1543 | assert(image->signature == MagickSignature); |
| 1544 | if (image->mask == (Image *) NULL) |
| 1545 | return((Image *) NULL); |
| 1546 | return(CloneImage(image->mask,0,0,MagickTrue,exception)); |
| 1547 | } |
| 1548 | |
| 1549 | /* |
| 1550 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1551 | % % |
| 1552 | % % |
| 1553 | % % |
| 1554 | + G e t I m a g e R e f e r e n c e C o u n t % |
| 1555 | % % |
| 1556 | % % |
| 1557 | % % |
| 1558 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1559 | % |
| 1560 | % GetImageReferenceCount() returns the image reference count. |
| 1561 | % |
| 1562 | % The format of the GetReferenceCount method is: |
| 1563 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1564 | % ssize_t GetImageReferenceCount(Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1565 | % |
| 1566 | % A description of each parameter follows: |
| 1567 | % |
| 1568 | % o image: the image. |
| 1569 | % |
| 1570 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1571 | MagickExport ssize_t GetImageReferenceCount(Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1572 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1573 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1574 | reference_count; |
| 1575 | |
| 1576 | assert(image != (Image *) NULL); |
| 1577 | assert(image->signature == MagickSignature); |
| 1578 | if (image->debug != MagickFalse) |
| 1579 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1580 | LockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1581 | reference_count=image->reference_count; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1582 | UnlockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1583 | return(reference_count); |
| 1584 | } |
| 1585 | |
| 1586 | /* |
| 1587 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1588 | % % |
| 1589 | % % |
| 1590 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1591 | % G e t I m a g e V i r t u a l P i x e l M e t h o d % |
| 1592 | % % |
| 1593 | % % |
| 1594 | % % |
| 1595 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1596 | % |
| 1597 | % GetImageVirtualPixelMethod() gets the "virtual pixels" method for the |
| 1598 | % image. A virtual pixel is any pixel access that is outside the boundaries |
| 1599 | % of the image cache. |
| 1600 | % |
| 1601 | % The format of the GetImageVirtualPixelMethod() method is: |
| 1602 | % |
| 1603 | % VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image) |
| 1604 | % |
| 1605 | % A description of each parameter follows: |
| 1606 | % |
| 1607 | % o image: the image. |
| 1608 | % |
| 1609 | */ |
| 1610 | MagickExport VirtualPixelMethod GetImageVirtualPixelMethod(const Image *image) |
| 1611 | { |
| 1612 | assert(image != (Image *) NULL); |
| 1613 | assert(image->signature == MagickSignature); |
| 1614 | if (image->debug != MagickFalse) |
| 1615 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1616 | return(GetPixelCacheVirtualMethod(image)); |
| 1617 | } |
| 1618 | |
| 1619 | /* |
| 1620 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1621 | % % |
| 1622 | % % |
| 1623 | % % |
| 1624 | % I n t e r p r e t I m a g e F i l e n a m e % |
| 1625 | % % |
| 1626 | % % |
| 1627 | % % |
| 1628 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1629 | % |
| 1630 | % InterpretImageFilename() interprets embedded characters in an image filename. |
| 1631 | % The filename length is returned. |
| 1632 | % |
| 1633 | % The format of the InterpretImageFilename method is: |
| 1634 | % |
| 1635 | % size_t InterpretImageFilename(const ImageInfo *image_info, |
| 1636 | % Image *image,const char *format,int value,char *filename) |
| 1637 | % |
| 1638 | % A description of each parameter follows. |
| 1639 | % |
| 1640 | % o image_info: the image info.. |
| 1641 | % |
| 1642 | % o image: the image. |
| 1643 | % |
| 1644 | % o format: A filename describing the format to use to write the numeric |
| 1645 | % argument. Only the first numeric format identifier is replaced. |
| 1646 | % |
| 1647 | % o value: Numeric value to substitute into format filename. |
| 1648 | % |
| 1649 | % o filename: return the formatted filename in this character buffer. |
| 1650 | % |
| 1651 | */ |
| 1652 | MagickExport size_t InterpretImageFilename(const ImageInfo *image_info, |
| 1653 | Image *image,const char *format,int value,char *filename) |
| 1654 | { |
| 1655 | char |
| 1656 | *q; |
| 1657 | |
| 1658 | int |
| 1659 | c; |
| 1660 | |
| 1661 | MagickBooleanType |
| 1662 | canonical; |
| 1663 | |
| 1664 | register const char |
| 1665 | *p; |
| 1666 | |
| 1667 | canonical=MagickFalse; |
| 1668 | (void) CopyMagickString(filename,format,MaxTextExtent); |
| 1669 | for (p=strchr(format,'%'); p != (char *) NULL; p=strchr(p+1,'%')) |
| 1670 | { |
| 1671 | q=(char *) p+1; |
| 1672 | if (*q == '%') |
| 1673 | { |
| 1674 | p=q+1; |
| 1675 | continue; |
| 1676 | } |
| 1677 | if (*q == '0') |
| 1678 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1679 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1680 | value; |
| 1681 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1682 | value=(ssize_t) strtol(q,&q,10); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1683 | } |
| 1684 | switch (*q) |
| 1685 | { |
| 1686 | case 'd': |
| 1687 | case 'o': |
| 1688 | case 'x': |
| 1689 | { |
| 1690 | q++; |
| 1691 | c=(*q); |
| 1692 | *q='\0'; |
| 1693 | (void) FormatMagickString(filename+(p-format),(size_t) (MaxTextExtent- |
| 1694 | (p-format)),p,value); |
| 1695 | *q=c; |
| 1696 | (void) ConcatenateMagickString(filename,q,MaxTextExtent); |
| 1697 | canonical=MagickTrue; |
| 1698 | if (*(q-1) != '%') |
| 1699 | break; |
| 1700 | p++; |
| 1701 | break; |
| 1702 | } |
| 1703 | case '[': |
| 1704 | { |
| 1705 | char |
| 1706 | pattern[MaxTextExtent]; |
| 1707 | |
| 1708 | const char |
| 1709 | *value; |
| 1710 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1711 | register char |
| 1712 | *r; |
| 1713 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1714 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1715 | i; |
| 1716 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 1717 | ssize_t |
| 1718 | depth; |
| 1719 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1720 | /* |
| 1721 | Image option. |
| 1722 | */ |
| 1723 | if (strchr(p,']') == (char *) NULL) |
| 1724 | break; |
| 1725 | depth=1; |
| 1726 | r=q+1; |
| 1727 | for (i=0; (i < (MaxTextExtent-1L)) && (*r != '\0'); i++) |
| 1728 | { |
| 1729 | if (*r == '[') |
| 1730 | depth++; |
| 1731 | if (*r == ']') |
| 1732 | depth--; |
| 1733 | if (depth <= 0) |
| 1734 | break; |
| 1735 | pattern[i]=(*r++); |
| 1736 | } |
| 1737 | pattern[i]='\0'; |
| 1738 | if (LocaleNCompare(pattern,"filename:",9) != 0) |
| 1739 | break; |
| 1740 | value=(const char *) NULL; |
| 1741 | if ((image_info != (const ImageInfo *) NULL) && |
| 1742 | (image != (const Image *) NULL)) |
cristy | 86fe49e | 2010-06-25 01:18:11 +0000 | [diff] [blame^] | 1743 | value=GetMagickProperty(image_info,image,pattern); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1744 | else |
| 1745 | if (image != (Image *) NULL) |
cristy | 86fe49e | 2010-06-25 01:18:11 +0000 | [diff] [blame^] | 1746 | value=GetImageProperty(image,pattern); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1747 | else |
| 1748 | if (image_info != (ImageInfo *) NULL) |
cristy | 86fe49e | 2010-06-25 01:18:11 +0000 | [diff] [blame^] | 1749 | value=GetImageOption(image_info,pattern); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1750 | if (value == (const char *) NULL) |
| 1751 | break; |
| 1752 | q--; |
| 1753 | c=(*q); |
| 1754 | *q='\0'; |
| 1755 | (void) CopyMagickString(filename+(p-format),value,(size_t) |
| 1756 | (MaxTextExtent-(p-format))); |
| 1757 | *q=c; |
| 1758 | (void) ConcatenateMagickString(filename,r+1,MaxTextExtent); |
| 1759 | canonical=MagickTrue; |
| 1760 | if (*(q-1) != '%') |
| 1761 | break; |
| 1762 | p++; |
| 1763 | break; |
| 1764 | } |
| 1765 | default: |
| 1766 | break; |
| 1767 | } |
| 1768 | } |
| 1769 | for (q=filename; *q != '\0'; q++) |
| 1770 | if ((*q == '%') && (*(q+1) == '%')) |
| 1771 | (void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename))); |
| 1772 | if (canonical == MagickFalse) |
| 1773 | (void) CopyMagickString(filename,format,MaxTextExtent); |
| 1774 | return(strlen(filename)); |
| 1775 | } |
| 1776 | |
| 1777 | /* |
| 1778 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1779 | % % |
| 1780 | % % |
| 1781 | % % |
| 1782 | % I s H i g h D y n a m i c R a n g e I m a g e % |
| 1783 | % % |
| 1784 | % % |
| 1785 | % % |
| 1786 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1787 | % |
| 1788 | % IsHighDynamicRangeImage() returns MagickTrue if any pixel component is |
| 1789 | % non-integer or exceeds the bounds of the quantum depth (e.g. for Q16 |
| 1790 | % 0..65535. |
| 1791 | % |
| 1792 | % The format of the IsHighDynamicRangeImage method is: |
| 1793 | % |
| 1794 | % MagickBooleanType IsHighDynamicRangeImage(const Image *image, |
| 1795 | % ExceptionInfo *exception) |
| 1796 | % |
| 1797 | % A description of each parameter follows: |
| 1798 | % |
| 1799 | % o image: the image. |
| 1800 | % |
| 1801 | % o exception: return any errors or warnings in this structure. |
| 1802 | % |
| 1803 | */ |
| 1804 | MagickExport MagickBooleanType IsHighDynamicRangeImage(const Image *image, |
| 1805 | ExceptionInfo *exception) |
| 1806 | { |
| 1807 | #if !defined(MAGICKCORE_HDRI_SUPPORT) |
| 1808 | (void) image; |
| 1809 | (void) exception; |
| 1810 | return(MagickFalse); |
| 1811 | #else |
| 1812 | CacheView |
| 1813 | *image_view; |
| 1814 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1815 | MagickBooleanType |
| 1816 | status; |
| 1817 | |
| 1818 | MagickPixelPacket |
| 1819 | zero; |
| 1820 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 1821 | ssize_t |
| 1822 | y; |
| 1823 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1824 | assert(image != (Image *) NULL); |
| 1825 | assert(image->signature == MagickSignature); |
| 1826 | if (image->debug != MagickFalse) |
| 1827 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1828 | status=MagickTrue; |
| 1829 | GetMagickPixelPacket(image,&zero); |
| 1830 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1831 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 1832 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1833 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1834 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1835 | { |
| 1836 | MagickPixelPacket |
| 1837 | pixel; |
| 1838 | |
| 1839 | register const IndexPacket |
| 1840 | *indexes; |
| 1841 | |
| 1842 | register const PixelPacket |
| 1843 | *p; |
| 1844 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1845 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1846 | x; |
| 1847 | |
| 1848 | if (status == MagickFalse) |
| 1849 | continue; |
| 1850 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 1851 | if (p == (const PixelPacket *) NULL) |
| 1852 | { |
| 1853 | status=MagickFalse; |
| 1854 | continue; |
| 1855 | } |
| 1856 | indexes=GetCacheViewVirtualIndexQueue(image_view); |
| 1857 | pixel=zero; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1858 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1859 | { |
| 1860 | SetMagickPixelPacket(image,p,indexes+x,&pixel); |
| 1861 | if ((pixel.red < 0.0) || (pixel.red > QuantumRange) || |
| 1862 | (pixel.red != (QuantumAny) pixel.red)) |
| 1863 | break; |
| 1864 | if ((pixel.green < 0.0) || (pixel.green > QuantumRange) || |
| 1865 | (pixel.green != (QuantumAny) pixel.green)) |
| 1866 | break; |
| 1867 | if ((pixel.blue < 0.0) || (pixel.blue > QuantumRange) || |
| 1868 | (pixel.blue != (QuantumAny) pixel.blue)) |
| 1869 | break; |
| 1870 | if (pixel.matte != MagickFalse) |
| 1871 | { |
| 1872 | if ((pixel.opacity < 0.0) || (pixel.opacity > QuantumRange) || |
| 1873 | (pixel.opacity != (QuantumAny) pixel.opacity)) |
| 1874 | break; |
| 1875 | } |
| 1876 | if (pixel.colorspace == CMYKColorspace) |
| 1877 | { |
| 1878 | if ((pixel.index < 0.0) || (pixel.index > QuantumRange) || |
| 1879 | (pixel.index != (QuantumAny) pixel.index)) |
| 1880 | break; |
| 1881 | } |
| 1882 | p++; |
| 1883 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1884 | if (x < (ssize_t) image->columns) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1885 | status=MagickFalse; |
| 1886 | } |
| 1887 | image_view=DestroyCacheView(image_view); |
| 1888 | return(status != MagickFalse ? MagickFalse : MagickTrue); |
| 1889 | #endif |
| 1890 | } |
| 1891 | |
| 1892 | /* |
| 1893 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1894 | % % |
| 1895 | % % |
| 1896 | % % |
| 1897 | % I s I m a g e O b j e c t % |
| 1898 | % % |
| 1899 | % % |
| 1900 | % % |
| 1901 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1902 | % |
| 1903 | % IsImageObject() returns MagickTrue if the image sequence contains a valid |
| 1904 | % set of image objects. |
| 1905 | % |
| 1906 | % The format of the IsImageObject method is: |
| 1907 | % |
| 1908 | % MagickBooleanType IsImageObject(const Image *image) |
| 1909 | % |
| 1910 | % A description of each parameter follows: |
| 1911 | % |
| 1912 | % o image: the image. |
| 1913 | % |
| 1914 | */ |
| 1915 | MagickExport MagickBooleanType IsImageObject(const Image *image) |
| 1916 | { |
| 1917 | register const Image |
| 1918 | *p; |
| 1919 | |
| 1920 | assert(image != (Image *) NULL); |
| 1921 | if (image->debug != MagickFalse) |
| 1922 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1923 | for (p=image; p != (Image *) NULL; p=GetNextImageInList(p)) |
| 1924 | if (p->signature != MagickSignature) |
| 1925 | return(MagickFalse); |
| 1926 | return(MagickTrue); |
| 1927 | } |
| 1928 | |
| 1929 | /* |
| 1930 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1931 | % % |
| 1932 | % % |
| 1933 | % % |
| 1934 | % I s T a i n t I m a g e % |
| 1935 | % % |
| 1936 | % % |
| 1937 | % % |
| 1938 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1939 | % |
| 1940 | % IsTaintImage() returns MagickTrue any pixel in the image has been altered |
| 1941 | % since it was first constituted. |
| 1942 | % |
| 1943 | % The format of the IsTaintImage method is: |
| 1944 | % |
| 1945 | % MagickBooleanType IsTaintImage(const Image *image) |
| 1946 | % |
| 1947 | % A description of each parameter follows: |
| 1948 | % |
| 1949 | % o image: the image. |
| 1950 | % |
| 1951 | */ |
| 1952 | MagickExport MagickBooleanType IsTaintImage(const Image *image) |
| 1953 | { |
| 1954 | char |
| 1955 | magick[MaxTextExtent], |
| 1956 | filename[MaxTextExtent]; |
| 1957 | |
| 1958 | register const Image |
| 1959 | *p; |
| 1960 | |
| 1961 | assert(image != (Image *) NULL); |
| 1962 | if (image->debug != MagickFalse) |
| 1963 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1964 | assert(image->signature == MagickSignature); |
| 1965 | (void) CopyMagickString(magick,image->magick,MaxTextExtent); |
| 1966 | (void) CopyMagickString(filename,image->filename,MaxTextExtent); |
| 1967 | for (p=image; p != (Image *) NULL; p=GetNextImageInList(p)) |
| 1968 | { |
| 1969 | if (p->taint != MagickFalse) |
| 1970 | return(MagickTrue); |
| 1971 | if (LocaleCompare(p->magick,magick) != 0) |
| 1972 | return(MagickTrue); |
| 1973 | if (LocaleCompare(p->filename,filename) != 0) |
| 1974 | return(MagickTrue); |
| 1975 | } |
| 1976 | return(MagickFalse); |
| 1977 | } |
| 1978 | |
| 1979 | /* |
| 1980 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1981 | % % |
| 1982 | % % |
| 1983 | % % |
| 1984 | % M o d i f y I m a g e % |
| 1985 | % % |
| 1986 | % % |
| 1987 | % % |
| 1988 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1989 | % |
| 1990 | % ModifyImage() ensures that there is only a single reference to the image |
| 1991 | % to be modified, updating the provided image pointer to point to a clone of |
| 1992 | % the original image if necessary. |
| 1993 | % |
| 1994 | % The format of the ModifyImage method is: |
| 1995 | % |
| 1996 | % MagickBooleanType ModifyImage(Image *image,ExceptionInfo *exception) |
| 1997 | % |
| 1998 | % A description of each parameter follows: |
| 1999 | % |
| 2000 | % o image: the image. |
| 2001 | % |
| 2002 | % o exception: return any errors or warnings in this structure. |
| 2003 | % |
| 2004 | */ |
| 2005 | MagickExport MagickBooleanType ModifyImage(Image **image, |
| 2006 | ExceptionInfo *exception) |
| 2007 | { |
| 2008 | Image |
| 2009 | *clone_image; |
| 2010 | |
| 2011 | assert(image != (Image **) NULL); |
| 2012 | assert(*image != (Image *) NULL); |
| 2013 | assert((*image)->signature == MagickSignature); |
| 2014 | if ((*image)->debug != MagickFalse) |
| 2015 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename); |
| 2016 | if (GetImageReferenceCount(*image) <= 1) |
| 2017 | return(MagickTrue); |
| 2018 | clone_image=CloneImage(*image,0,0,MagickTrue,exception); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2019 | LockSemaphoreInfo((*image)->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2020 | (*image)->reference_count--; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2021 | UnlockSemaphoreInfo((*image)->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2022 | *image=clone_image; |
| 2023 | return(MagickTrue); |
| 2024 | } |
| 2025 | |
| 2026 | /* |
| 2027 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2028 | % % |
| 2029 | % % |
| 2030 | % % |
| 2031 | % N e w M a g i c k I m a g e % |
| 2032 | % % |
| 2033 | % % |
| 2034 | % % |
| 2035 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2036 | % |
| 2037 | % NewMagickImage() creates a blank image canvas of the specified size and |
| 2038 | % background color. |
| 2039 | % |
| 2040 | % The format of the NewMagickImage method is: |
| 2041 | % |
| 2042 | % Image *NewMagickImage(const ImageInfo *image_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2043 | % const size_t width,const size_t height, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2044 | % const MagickPixelPacket *background) |
| 2045 | % |
| 2046 | % A description of each parameter follows: |
| 2047 | % |
| 2048 | % o image: the image. |
| 2049 | % |
| 2050 | % o width: the image width. |
| 2051 | % |
| 2052 | % o height: the image height. |
| 2053 | % |
| 2054 | % o background: the image color. |
| 2055 | % |
| 2056 | */ |
| 2057 | MagickExport Image *NewMagickImage(const ImageInfo *image_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2058 | const size_t width,const size_t height, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2059 | const MagickPixelPacket *background) |
| 2060 | { |
| 2061 | CacheView |
| 2062 | *image_view; |
| 2063 | |
| 2064 | ExceptionInfo |
| 2065 | *exception; |
| 2066 | |
| 2067 | Image |
| 2068 | *image; |
| 2069 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2070 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2071 | y; |
| 2072 | |
| 2073 | MagickBooleanType |
| 2074 | status; |
| 2075 | |
| 2076 | assert(image_info != (const ImageInfo *) NULL); |
| 2077 | if (image_info->debug != MagickFalse) |
| 2078 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 2079 | assert(image_info->signature == MagickSignature); |
| 2080 | assert(background != (const MagickPixelPacket *) NULL); |
| 2081 | image=AcquireImage(image_info); |
| 2082 | image->columns=width; |
| 2083 | image->rows=height; |
| 2084 | image->colorspace=background->colorspace; |
| 2085 | image->matte=background->matte; |
| 2086 | image->fuzz=background->fuzz; |
| 2087 | image->depth=background->depth; |
| 2088 | status=MagickTrue; |
| 2089 | exception=(&image->exception); |
| 2090 | image_view=AcquireCacheView(image); |
cristy | 48974b9 | 2009-12-19 02:36:06 +0000 | [diff] [blame] | 2091 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 2092 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 2093 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2094 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2095 | { |
| 2096 | register IndexPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2097 | *restrict indexes; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2098 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2099 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2100 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2101 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2102 | register ssize_t |
| 2103 | x; |
| 2104 | |
cristy | 48974b9 | 2009-12-19 02:36:06 +0000 | [diff] [blame] | 2105 | if (status == MagickFalse) |
| 2106 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2107 | q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 2108 | if (q == (PixelPacket *) NULL) |
| 2109 | { |
| 2110 | status=MagickFalse; |
| 2111 | continue; |
| 2112 | } |
| 2113 | indexes=GetCacheViewAuthenticIndexQueue(image_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2114 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2115 | { |
| 2116 | SetPixelPacket(image,background,q,indexes+x); |
| 2117 | q++; |
| 2118 | } |
| 2119 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 2120 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2121 | } |
| 2122 | image_view=DestroyCacheView(image_view); |
| 2123 | if (status == MagickFalse) |
| 2124 | image=DestroyImage(image); |
| 2125 | return(image); |
| 2126 | } |
| 2127 | |
| 2128 | /* |
| 2129 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2130 | % % |
| 2131 | % % |
| 2132 | % % |
| 2133 | % R e f e r e n c e I m a g e % |
| 2134 | % % |
| 2135 | % % |
| 2136 | % % |
| 2137 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2138 | % |
| 2139 | % ReferenceImage() increments the reference count associated with an image |
| 2140 | % returning a pointer to the image. |
| 2141 | % |
| 2142 | % The format of the ReferenceImage method is: |
| 2143 | % |
| 2144 | % Image *ReferenceImage(Image *image) |
| 2145 | % |
| 2146 | % A description of each parameter follows: |
| 2147 | % |
| 2148 | % o image: the image. |
| 2149 | % |
| 2150 | */ |
| 2151 | MagickExport Image *ReferenceImage(Image *image) |
| 2152 | { |
| 2153 | assert(image != (Image *) NULL); |
| 2154 | if (image->debug != MagickFalse) |
| 2155 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 2156 | assert(image->signature == MagickSignature); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2157 | LockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2158 | image->reference_count++; |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 2159 | UnlockSemaphoreInfo(image->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2160 | return(image); |
| 2161 | } |
| 2162 | |
| 2163 | /* |
| 2164 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2165 | % % |
| 2166 | % % |
| 2167 | % % |
| 2168 | % R e s e t I m a g e P a g e % |
| 2169 | % % |
| 2170 | % % |
| 2171 | % % |
| 2172 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2173 | % |
| 2174 | % ResetImagePage() resets the image page canvas and position. |
| 2175 | % |
| 2176 | % The format of the ResetImagePage method is: |
| 2177 | % |
| 2178 | % MagickBooleanType ResetImagePage(Image *image,const char *page) |
| 2179 | % |
| 2180 | % A description of each parameter follows: |
| 2181 | % |
| 2182 | % o image: the image. |
| 2183 | % |
| 2184 | % o page: the relative page specification. |
| 2185 | % |
| 2186 | */ |
| 2187 | MagickExport MagickBooleanType ResetImagePage(Image *image,const char *page) |
| 2188 | { |
| 2189 | MagickStatusType |
| 2190 | flags; |
| 2191 | |
| 2192 | RectangleInfo |
| 2193 | geometry; |
| 2194 | |
| 2195 | assert(image != (Image *) NULL); |
| 2196 | assert(image->signature == MagickSignature); |
| 2197 | if (image->debug != MagickFalse) |
| 2198 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 2199 | flags=ParseAbsoluteGeometry(page,&geometry); |
| 2200 | if ((flags & WidthValue) != 0) |
| 2201 | { |
| 2202 | if ((flags & HeightValue) == 0) |
| 2203 | geometry.height=geometry.width; |
| 2204 | image->page.width=geometry.width; |
| 2205 | image->page.height=geometry.height; |
| 2206 | } |
| 2207 | if ((flags & AspectValue) != 0) |
| 2208 | { |
| 2209 | if ((flags & XValue) != 0) |
| 2210 | image->page.x+=geometry.x; |
| 2211 | if ((flags & YValue) != 0) |
| 2212 | image->page.y+=geometry.y; |
| 2213 | } |
| 2214 | else |
| 2215 | { |
| 2216 | if ((flags & XValue) != 0) |
| 2217 | { |
| 2218 | image->page.x=geometry.x; |
| 2219 | if ((image->page.width == 0) && (geometry.x > 0)) |
| 2220 | image->page.width=image->columns+geometry.x; |
| 2221 | } |
| 2222 | if ((flags & YValue) != 0) |
| 2223 | { |
| 2224 | image->page.y=geometry.y; |
| 2225 | if ((image->page.height == 0) && (geometry.y > 0)) |
| 2226 | image->page.height=image->rows+geometry.y; |
| 2227 | } |
| 2228 | } |
| 2229 | return(MagickTrue); |
| 2230 | } |
| 2231 | |
| 2232 | /* |
| 2233 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2234 | % % |
| 2235 | % % |
| 2236 | % % |
| 2237 | % S e p a r a t e I m a g e C h a n n e l % |
| 2238 | % % |
| 2239 | % % |
| 2240 | % % |
| 2241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2242 | % |
| 2243 | % SeparateImageChannel() separates a channel from the image and returns it as |
| 2244 | % a grayscale image. A channel is a particular color component of each pixel |
| 2245 | % in the image. |
| 2246 | % |
| 2247 | % The format of the SeparateImageChannel method is: |
| 2248 | % |
| 2249 | % MagickBooleanType SeparateImageChannel(Image *image, |
| 2250 | % const ChannelType channel) |
| 2251 | % |
| 2252 | % A description of each parameter follows: |
| 2253 | % |
| 2254 | % o image: the image. |
| 2255 | % |
| 2256 | % o channel: Identify which channel to extract: RedChannel, GreenChannel, |
| 2257 | % BlueChannel, OpacityChannel, CyanChannel, MagentaChannel, |
| 2258 | % YellowChannel, or BlackChannel. |
| 2259 | % |
| 2260 | */ |
| 2261 | MagickExport MagickBooleanType SeparateImageChannel(Image *image, |
| 2262 | const ChannelType channel) |
| 2263 | { |
| 2264 | #define SeparateImageTag "Separate/Image" |
| 2265 | |
| 2266 | CacheView |
| 2267 | *image_view; |
| 2268 | |
| 2269 | ExceptionInfo |
| 2270 | *exception; |
| 2271 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2272 | MagickBooleanType |
| 2273 | status; |
| 2274 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2275 | MagickOffsetType |
| 2276 | progress; |
| 2277 | |
| 2278 | ssize_t |
| 2279 | y; |
| 2280 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2281 | assert(image != (Image *) NULL); |
| 2282 | assert(image->signature == MagickSignature); |
| 2283 | if (image->debug != MagickFalse) |
| 2284 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 2285 | if (SetImageStorageClass(image,DirectClass) == MagickFalse) |
| 2286 | return(MagickFalse); |
| 2287 | /* |
| 2288 | Separate image channels. |
| 2289 | */ |
| 2290 | status=MagickTrue; |
cristy | 11b66ce | 2010-03-11 13:34:19 +0000 | [diff] [blame] | 2291 | if (channel == GrayChannels) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2292 | image->matte=MagickTrue; |
| 2293 | progress=0; |
| 2294 | exception=(&image->exception); |
| 2295 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 2296 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 2297 | #pragma omp parallel for schedule(dynamic,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2298 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2299 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2300 | { |
| 2301 | register IndexPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2302 | *restrict indexes; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2303 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2304 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2305 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2306 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2307 | register ssize_t |
| 2308 | x; |
| 2309 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2310 | if (status == MagickFalse) |
| 2311 | continue; |
| 2312 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 2313 | if (q == (PixelPacket *) NULL) |
| 2314 | { |
| 2315 | status=MagickFalse; |
| 2316 | continue; |
| 2317 | } |
| 2318 | indexes=GetCacheViewAuthenticIndexQueue(image_view); |
| 2319 | switch (channel) |
| 2320 | { |
| 2321 | case RedChannel: |
| 2322 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2323 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2324 | { |
| 2325 | q->green=q->red; |
| 2326 | q->blue=q->red; |
| 2327 | q++; |
| 2328 | } |
| 2329 | break; |
| 2330 | } |
| 2331 | case GreenChannel: |
| 2332 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2333 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2334 | { |
| 2335 | q->red=q->green; |
| 2336 | q->blue=q->green; |
| 2337 | q++; |
| 2338 | } |
| 2339 | break; |
| 2340 | } |
| 2341 | case BlueChannel: |
| 2342 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2343 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2344 | { |
| 2345 | q->red=q->blue; |
| 2346 | q->green=q->blue; |
| 2347 | q++; |
| 2348 | } |
| 2349 | break; |
| 2350 | } |
| 2351 | case OpacityChannel: |
| 2352 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2353 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2354 | { |
| 2355 | q->red=q->opacity; |
| 2356 | q->green=q->opacity; |
| 2357 | q->blue=q->opacity; |
| 2358 | q++; |
| 2359 | } |
| 2360 | break; |
| 2361 | } |
| 2362 | case BlackChannel: |
| 2363 | { |
| 2364 | if ((image->storage_class != PseudoClass) && |
| 2365 | (image->colorspace != CMYKColorspace)) |
| 2366 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2367 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2368 | { |
| 2369 | q->red=indexes[x]; |
| 2370 | q->green=indexes[x]; |
| 2371 | q->blue=indexes[x]; |
| 2372 | q++; |
| 2373 | } |
| 2374 | break; |
| 2375 | } |
| 2376 | case TrueAlphaChannel: |
| 2377 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2378 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2379 | { |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 2380 | q->red=(Quantum) GetAlphaPixelComponent(q); |
| 2381 | q->green=(Quantum) GetAlphaPixelComponent(q); |
| 2382 | q->blue=(Quantum) GetAlphaPixelComponent(q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2383 | q++; |
| 2384 | } |
| 2385 | break; |
| 2386 | } |
| 2387 | case GrayChannels: |
| 2388 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2389 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2390 | { |
| 2391 | q->opacity=(Quantum) (QuantumRange-PixelIntensityToQuantum(q)); |
| 2392 | q++; |
| 2393 | } |
| 2394 | break; |
| 2395 | } |
| 2396 | default: |
| 2397 | break; |
| 2398 | } |
| 2399 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 2400 | status=MagickFalse; |
| 2401 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 2402 | { |
| 2403 | MagickBooleanType |
| 2404 | proceed; |
| 2405 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 2406 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2407 | #pragma omp critical (MagickCore_SeparateImageChannel) |
| 2408 | #endif |
| 2409 | proceed=SetImageProgress(image,SeparateImageTag,progress++,image->rows); |
| 2410 | if (proceed == MagickFalse) |
| 2411 | status=MagickFalse; |
| 2412 | } |
| 2413 | } |
| 2414 | image_view=DestroyCacheView(image_view); |
cristy | 11b66ce | 2010-03-11 13:34:19 +0000 | [diff] [blame] | 2415 | if (channel != GrayChannels) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2416 | image->matte=MagickFalse; |
| 2417 | (void) SetImageColorspace(image,RGBColorspace); |
| 2418 | return(status); |
| 2419 | } |
| 2420 | |
| 2421 | /* |
| 2422 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2423 | % % |
| 2424 | % % |
| 2425 | % % |
| 2426 | % S e p a r a t e I m a g e s % |
| 2427 | % % |
| 2428 | % % |
| 2429 | % % |
| 2430 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2431 | % |
| 2432 | % SeparateImages() returns a separate grayscale image for each channel |
| 2433 | % specified. |
| 2434 | % |
| 2435 | % The format of the SeparateImages method is: |
| 2436 | % |
| 2437 | % MagickBooleanType SeparateImages(const Image *image, |
| 2438 | % const ChannelType channel,ExceptionInfo *exception) |
| 2439 | % |
| 2440 | % A description of each parameter follows: |
| 2441 | % |
| 2442 | % o image: the image. |
| 2443 | % |
| 2444 | % o channel: Identify which channels to extract: RedChannel, GreenChannel, |
| 2445 | % BlueChannel, OpacityChannel, CyanChannel, MagentaChannel, |
| 2446 | % YellowChannel, or BlackChannel. |
| 2447 | % |
| 2448 | % o exception: return any errors or warnings in this structure. |
| 2449 | % |
| 2450 | */ |
| 2451 | MagickExport Image *SeparateImages(const Image *image,const ChannelType channel, |
| 2452 | ExceptionInfo *exception) |
| 2453 | { |
| 2454 | Image |
| 2455 | *images, |
| 2456 | *separate_image; |
| 2457 | |
| 2458 | assert(image != (Image *) NULL); |
| 2459 | assert(image->signature == MagickSignature); |
| 2460 | if (image->debug != MagickFalse) |
| 2461 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 2462 | images=NewImageList(); |
| 2463 | if ((channel & RedChannel) != 0) |
| 2464 | { |
| 2465 | separate_image=CloneImage(image,0,0,MagickTrue,exception); |
| 2466 | (void) SeparateImageChannel(separate_image,RedChannel); |
| 2467 | AppendImageToList(&images,separate_image); |
| 2468 | } |
| 2469 | if ((channel & GreenChannel) != 0) |
| 2470 | { |
| 2471 | separate_image=CloneImage(image,0,0,MagickTrue,exception); |
| 2472 | (void) SeparateImageChannel(separate_image,GreenChannel); |
| 2473 | AppendImageToList(&images,separate_image); |
| 2474 | } |
| 2475 | if ((channel & BlueChannel) != 0) |
| 2476 | { |
| 2477 | separate_image=CloneImage(image,0,0,MagickTrue,exception); |
| 2478 | (void) SeparateImageChannel(separate_image,BlueChannel); |
| 2479 | AppendImageToList(&images,separate_image); |
| 2480 | } |
| 2481 | if (((channel & BlackChannel) != 0) && (image->colorspace == CMYKColorspace)) |
| 2482 | { |
| 2483 | separate_image=CloneImage(image,0,0,MagickTrue,exception); |
| 2484 | (void) SeparateImageChannel(separate_image,BlackChannel); |
| 2485 | AppendImageToList(&images,separate_image); |
| 2486 | } |
| 2487 | if ((channel & OpacityChannel) != 0) |
| 2488 | { |
| 2489 | separate_image=CloneImage(image,0,0,MagickTrue,exception); |
| 2490 | (void) SeparateImageChannel(separate_image,OpacityChannel); |
| 2491 | AppendImageToList(&images,separate_image); |
| 2492 | } |
| 2493 | return(images); |
| 2494 | } |
| 2495 | |
| 2496 | /* |
| 2497 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2498 | % % |
| 2499 | % % |
| 2500 | % % |
| 2501 | % S e t I m a g e A l p h a C h a n n e l % |
| 2502 | % % |
| 2503 | % % |
| 2504 | % % |
| 2505 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2506 | % |
| 2507 | % SetImageAlphaChannel() activates, deactivates, resets, or sets the alpha |
| 2508 | % channel. |
| 2509 | % |
| 2510 | % The format of the SetImageAlphaChannel method is: |
| 2511 | % |
| 2512 | % MagickBooleanType SetImageAlphaChannel(Image *image, |
| 2513 | % const AlphaChannelType alpha_type) |
| 2514 | % |
| 2515 | % A description of each parameter follows: |
| 2516 | % |
| 2517 | % o image: the image. |
| 2518 | % |
| 2519 | % o alpha_type: The alpha channel type: ActivateAlphaChannel, |
| 2520 | % CopyAlphaChannel, DeactivateAlphaChannel, ExtractAlphaChannel, |
| 2521 | % OpaqueAlphaChannel, ResetAlphaChannel, SetAlphaChannel, |
| 2522 | % ShapeAlphaChannel, and TransparentAlphaChannel. |
| 2523 | % |
| 2524 | */ |
| 2525 | MagickExport MagickBooleanType SetImageAlphaChannel(Image *image, |
| 2526 | const AlphaChannelType alpha_type) |
| 2527 | { |
| 2528 | MagickBooleanType |
| 2529 | status; |
| 2530 | |
| 2531 | assert(image != (Image *) NULL); |
| 2532 | if (image->debug != MagickFalse) |
| 2533 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 2534 | assert(image->signature == MagickSignature); |
| 2535 | status=MagickFalse; |
| 2536 | switch (alpha_type) |
| 2537 | { |
| 2538 | case ActivateAlphaChannel: |
| 2539 | { |
| 2540 | image->matte=MagickTrue; |
| 2541 | break; |
| 2542 | } |
| 2543 | case BackgroundAlphaChannel: |
| 2544 | { |
| 2545 | CacheView |
| 2546 | *image_view; |
| 2547 | |
| 2548 | ExceptionInfo |
| 2549 | *exception; |
| 2550 | |
| 2551 | IndexPacket |
| 2552 | index; |
| 2553 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2554 | MagickBooleanType |
| 2555 | status; |
| 2556 | |
| 2557 | MagickPixelPacket |
| 2558 | background; |
| 2559 | |
| 2560 | PixelPacket |
| 2561 | pixel; |
| 2562 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2563 | ssize_t |
| 2564 | y; |
| 2565 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2566 | /* |
| 2567 | Set transparent pixels to background color. |
| 2568 | */ |
| 2569 | if (image->matte == MagickFalse) |
| 2570 | break; |
| 2571 | if (SetImageStorageClass(image,DirectClass) == MagickFalse) |
| 2572 | break; |
| 2573 | GetMagickPixelPacket(image,&background); |
| 2574 | SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *) |
| 2575 | NULL,&background); |
| 2576 | if (image->colorspace == CMYKColorspace) |
| 2577 | ConvertRGBToCMYK(&background); |
| 2578 | index=0; |
| 2579 | SetPixelPacket(image,&background,&pixel,&index); |
| 2580 | status=MagickTrue; |
| 2581 | exception=(&image->exception); |
| 2582 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 2583 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 2584 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2585 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2586 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2587 | { |
| 2588 | register IndexPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2589 | *restrict indexes; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2590 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2591 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2592 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2593 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2594 | register ssize_t |
| 2595 | x; |
| 2596 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2597 | if (status == MagickFalse) |
| 2598 | continue; |
| 2599 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 2600 | exception); |
| 2601 | if (q == (PixelPacket *) NULL) |
| 2602 | { |
| 2603 | status=MagickFalse; |
| 2604 | continue; |
| 2605 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2606 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2607 | { |
| 2608 | if (q->opacity == TransparentOpacity) |
| 2609 | { |
| 2610 | q->red=pixel.red; |
| 2611 | q->green=pixel.green; |
| 2612 | q->blue=pixel.blue; |
| 2613 | } |
| 2614 | q++; |
| 2615 | } |
| 2616 | if (image->colorspace == CMYKColorspace) |
| 2617 | { |
| 2618 | indexes=GetCacheViewAuthenticIndexQueue(image_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2619 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2620 | indexes[x]=index; |
| 2621 | } |
| 2622 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 2623 | status=MagickFalse; |
| 2624 | } |
| 2625 | image_view=DestroyCacheView(image_view); |
| 2626 | return(status); |
| 2627 | } |
| 2628 | case DeactivateAlphaChannel: |
| 2629 | { |
| 2630 | image->matte=MagickFalse; |
| 2631 | break; |
| 2632 | } |
| 2633 | case ShapeAlphaChannel: |
| 2634 | case CopyAlphaChannel: |
| 2635 | { |
| 2636 | /* |
| 2637 | Special usage case for SeparateImageChannel(): copy grayscale color to |
| 2638 | the alpha channel. |
| 2639 | */ |
| 2640 | status=SeparateImageChannel(image,GrayChannels); |
| 2641 | image->matte=MagickTrue; /* make sure transparency is now on! */ |
| 2642 | if (alpha_type == ShapeAlphaChannel) |
| 2643 | { |
| 2644 | MagickPixelPacket |
| 2645 | background; |
| 2646 | |
| 2647 | /* |
| 2648 | Reset all color channels to background color. |
| 2649 | */ |
| 2650 | GetMagickPixelPacket(image,&background); |
| 2651 | SetMagickPixelPacket(image,&(image->background_color),(IndexPacket *) |
| 2652 | NULL,&background); |
cristy | 308b4e6 | 2009-09-21 14:40:44 +0000 | [diff] [blame] | 2653 | (void) LevelColorsImage(image,&background,&background,MagickTrue); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2654 | } |
| 2655 | break; |
| 2656 | } |
| 2657 | case ExtractAlphaChannel: |
| 2658 | { |
| 2659 | status=SeparateImageChannel(image,TrueAlphaChannel); |
| 2660 | image->matte=MagickFalse; |
| 2661 | break; |
| 2662 | } |
cristy | f64d18b | 2010-04-30 12:47:03 +0000 | [diff] [blame] | 2663 | case ResetAlphaChannel: /* deprecated */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2664 | case OpaqueAlphaChannel: |
| 2665 | { |
| 2666 | status=SetImageOpacity(image,OpaqueOpacity); |
| 2667 | image->matte=MagickTrue; |
| 2668 | break; |
| 2669 | } |
| 2670 | case TransparentAlphaChannel: |
| 2671 | { |
| 2672 | status=SetImageOpacity(image,TransparentOpacity); |
| 2673 | image->matte=MagickTrue; |
| 2674 | break; |
| 2675 | } |
| 2676 | case SetAlphaChannel: |
| 2677 | { |
| 2678 | if (image->matte == MagickFalse) |
| 2679 | { |
| 2680 | status=SetImageOpacity(image,OpaqueOpacity); |
| 2681 | image->matte=MagickTrue; |
| 2682 | } |
| 2683 | break; |
| 2684 | } |
| 2685 | case UndefinedAlphaChannel: |
| 2686 | break; |
| 2687 | } |
| 2688 | return(status); |
| 2689 | } |
| 2690 | |
| 2691 | /* |
| 2692 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2693 | % % |
| 2694 | % % |
| 2695 | % % |
| 2696 | % S e t I m a g e B a c k g r o u n d C o l o r % |
| 2697 | % % |
| 2698 | % % |
| 2699 | % % |
| 2700 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2701 | % |
| 2702 | % SetImageBackgroundColor() initializes the image pixels to the image |
| 2703 | % background color. The background color is defined by the background_color |
| 2704 | % member of the image structure. |
| 2705 | % |
| 2706 | % The format of the SetImage method is: |
| 2707 | % |
| 2708 | % MagickBooleanType SetImageBackgroundColor(Image *image) |
| 2709 | % |
| 2710 | % A description of each parameter follows: |
| 2711 | % |
| 2712 | % o image: the image. |
| 2713 | % |
| 2714 | */ |
| 2715 | MagickExport MagickBooleanType SetImageBackgroundColor(Image *image) |
| 2716 | { |
| 2717 | CacheView |
| 2718 | *image_view; |
| 2719 | |
| 2720 | ExceptionInfo |
| 2721 | *exception; |
| 2722 | |
| 2723 | IndexPacket |
| 2724 | index; |
| 2725 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2726 | MagickBooleanType |
| 2727 | status; |
| 2728 | |
| 2729 | MagickPixelPacket |
| 2730 | background; |
| 2731 | |
| 2732 | PixelPacket |
| 2733 | pixel; |
| 2734 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2735 | ssize_t |
| 2736 | y; |
| 2737 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2738 | assert(image != (Image *) NULL); |
| 2739 | if (image->debug != MagickFalse) |
| 2740 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 2741 | assert(image->signature == MagickSignature); |
| 2742 | if (SetImageStorageClass(image,DirectClass) == MagickFalse) |
| 2743 | return(MagickFalse); |
| 2744 | if (image->background_color.opacity != OpaqueOpacity) |
| 2745 | image->matte=MagickTrue; |
| 2746 | GetMagickPixelPacket(image,&background); |
| 2747 | SetMagickPixelPacket(image,&image->background_color,(const IndexPacket *) |
| 2748 | NULL,&background); |
| 2749 | if (image->colorspace == CMYKColorspace) |
| 2750 | ConvertRGBToCMYK(&background); |
| 2751 | index=0; |
| 2752 | SetPixelPacket(image,&background,&pixel,&index); |
| 2753 | /* |
| 2754 | Set image background color. |
| 2755 | */ |
| 2756 | status=MagickTrue; |
| 2757 | exception=(&image->exception); |
| 2758 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 2759 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 2760 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2761 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2762 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2763 | { |
| 2764 | register IndexPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2765 | *restrict indexes; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2766 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2767 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2768 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2769 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2770 | register ssize_t |
| 2771 | x; |
| 2772 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2773 | if (status == MagickFalse) |
| 2774 | continue; |
| 2775 | q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 2776 | if (q == (PixelPacket *) NULL) |
| 2777 | { |
| 2778 | status=MagickFalse; |
| 2779 | continue; |
| 2780 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2781 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2782 | *q++=pixel; |
| 2783 | if (image->colorspace == CMYKColorspace) |
| 2784 | { |
| 2785 | indexes=GetCacheViewAuthenticIndexQueue(image_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2786 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2787 | indexes[x]=index; |
| 2788 | } |
| 2789 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 2790 | status=MagickFalse; |
| 2791 | } |
| 2792 | image_view=DestroyCacheView(image_view); |
| 2793 | return(status); |
| 2794 | } |
| 2795 | |
| 2796 | /* |
| 2797 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2798 | % % |
| 2799 | % % |
| 2800 | % % |
cristy | a5b77cb | 2010-05-07 19:34:48 +0000 | [diff] [blame] | 2801 | % S e t I m a g e C o l o r % |
| 2802 | % % |
| 2803 | % % |
| 2804 | % % |
| 2805 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2806 | % |
| 2807 | % SetImageColor() set the entire image canvas to the specified color. |
| 2808 | % |
| 2809 | % The format of the SetImageColor method is: |
| 2810 | % |
| 2811 | % MagickBooleanType SetImageColor(Image *image, |
| 2812 | % const MagickPixelPacket *color) |
| 2813 | % |
| 2814 | % A description of each parameter follows: |
| 2815 | % |
| 2816 | % o image: the image. |
| 2817 | % |
| 2818 | % o background: the image color. |
| 2819 | % |
| 2820 | */ |
| 2821 | MagickExport MagickBooleanType SetImageColor(Image *image, |
| 2822 | const MagickPixelPacket *color) |
| 2823 | { |
| 2824 | CacheView |
| 2825 | *image_view; |
| 2826 | |
| 2827 | ExceptionInfo |
| 2828 | *exception; |
| 2829 | |
cristy | a5b77cb | 2010-05-07 19:34:48 +0000 | [diff] [blame] | 2830 | MagickBooleanType |
| 2831 | status; |
| 2832 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2833 | ssize_t |
| 2834 | y; |
| 2835 | |
cristy | a5b77cb | 2010-05-07 19:34:48 +0000 | [diff] [blame] | 2836 | assert(image != (Image *) NULL); |
| 2837 | if (image->debug != MagickFalse) |
| 2838 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 2839 | assert(image->signature == MagickSignature); |
| 2840 | assert(color != (const MagickPixelPacket *) NULL); |
| 2841 | image->colorspace=color->colorspace; |
| 2842 | image->matte=color->matte; |
| 2843 | image->fuzz=color->fuzz; |
| 2844 | image->depth=color->depth; |
| 2845 | status=MagickTrue; |
| 2846 | exception=(&image->exception); |
| 2847 | image_view=AcquireCacheView(image); |
| 2848 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 2849 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 2850 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2851 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | a5b77cb | 2010-05-07 19:34:48 +0000 | [diff] [blame] | 2852 | { |
| 2853 | register IndexPacket |
| 2854 | *restrict indexes; |
| 2855 | |
cristy | a5b77cb | 2010-05-07 19:34:48 +0000 | [diff] [blame] | 2856 | register PixelPacket |
| 2857 | *restrict q; |
| 2858 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 2859 | register ssize_t |
| 2860 | x; |
| 2861 | |
cristy | a5b77cb | 2010-05-07 19:34:48 +0000 | [diff] [blame] | 2862 | if (status == MagickFalse) |
| 2863 | continue; |
| 2864 | q=QueueCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 2865 | if (q == (PixelPacket *) NULL) |
| 2866 | { |
| 2867 | status=MagickFalse; |
| 2868 | continue; |
| 2869 | } |
| 2870 | indexes=GetCacheViewAuthenticIndexQueue(image_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2871 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | a5b77cb | 2010-05-07 19:34:48 +0000 | [diff] [blame] | 2872 | { |
| 2873 | SetPixelPacket(image,color,q,indexes+x); |
| 2874 | q++; |
| 2875 | } |
| 2876 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 2877 | status=MagickFalse; |
| 2878 | } |
| 2879 | image_view=DestroyCacheView(image_view); |
| 2880 | return(status); |
| 2881 | } |
| 2882 | |
| 2883 | /* |
| 2884 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2885 | % % |
| 2886 | % % |
| 2887 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2888 | % S e t I m a g e S t o r a g e C l a s s % |
| 2889 | % % |
| 2890 | % % |
| 2891 | % % |
| 2892 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2893 | % |
| 2894 | % SetImageStorageClass() sets the image class: DirectClass for true color |
| 2895 | % images or PseudoClass for colormapped images. |
| 2896 | % |
| 2897 | % The format of the SetImageStorageClass method is: |
| 2898 | % |
| 2899 | % MagickBooleanType SetImageStorageClass(Image *image, |
| 2900 | % const ClassType storage_class) |
| 2901 | % |
| 2902 | % A description of each parameter follows: |
| 2903 | % |
| 2904 | % o image: the image. |
| 2905 | % |
| 2906 | % o storage_class: The image class. |
| 2907 | % |
| 2908 | */ |
| 2909 | MagickExport MagickBooleanType SetImageStorageClass(Image *image, |
| 2910 | const ClassType storage_class) |
| 2911 | { |
| 2912 | Cache |
| 2913 | cache; |
| 2914 | |
| 2915 | if (image->storage_class == storage_class) |
| 2916 | return(MagickTrue); |
| 2917 | image->storage_class=storage_class; |
| 2918 | cache=GetImagePixelCache(image,MagickTrue,&image->exception); |
| 2919 | return(cache == (Cache) NULL ? MagickFalse : MagickTrue); |
| 2920 | } |
| 2921 | |
| 2922 | /* |
| 2923 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2924 | % % |
| 2925 | % % |
| 2926 | % % |
| 2927 | % S e t I m a g e C l i p M a s k % |
| 2928 | % % |
| 2929 | % % |
| 2930 | % % |
| 2931 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2932 | % |
| 2933 | % SetImageClipMask() associates a clip path with the image. The clip path |
| 2934 | % must be the same dimensions as the image. Set any pixel component of |
| 2935 | % the clip path to TransparentOpacity to prevent that corresponding image |
| 2936 | % pixel component from being updated when SyncAuthenticPixels() is applied. |
| 2937 | % |
| 2938 | % The format of the SetImageClipMask method is: |
| 2939 | % |
| 2940 | % MagickBooleanType SetImageClipMask(Image *image,const Image *clip_mask) |
| 2941 | % |
| 2942 | % A description of each parameter follows: |
| 2943 | % |
| 2944 | % o image: the image. |
| 2945 | % |
| 2946 | % o clip_mask: the image clip path. |
| 2947 | % |
| 2948 | */ |
| 2949 | MagickExport MagickBooleanType SetImageClipMask(Image *image, |
| 2950 | const Image *clip_mask) |
| 2951 | { |
| 2952 | assert(image != (Image *) NULL); |
| 2953 | if (image->debug != MagickFalse) |
| 2954 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 2955 | assert(image->signature == MagickSignature); |
| 2956 | if (clip_mask != (const Image *) NULL) |
| 2957 | if ((clip_mask->columns != image->columns) || |
| 2958 | (clip_mask->rows != image->rows)) |
| 2959 | ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename); |
| 2960 | if (image->clip_mask != (Image *) NULL) |
| 2961 | image->clip_mask=DestroyImage(image->clip_mask); |
| 2962 | image->clip_mask=NewImageList(); |
| 2963 | if (clip_mask == (Image *) NULL) |
| 2964 | return(MagickTrue); |
| 2965 | if (SetImageStorageClass(image,DirectClass) == MagickFalse) |
| 2966 | return(MagickFalse); |
| 2967 | image->clip_mask=CloneImage(clip_mask,0,0,MagickTrue,&image->exception); |
| 2968 | if (image->clip_mask == (Image *) NULL) |
| 2969 | return(MagickFalse); |
| 2970 | return(MagickTrue); |
| 2971 | } |
| 2972 | |
| 2973 | /* |
| 2974 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2975 | % % |
| 2976 | % % |
| 2977 | % % |
| 2978 | % S e t I m a g e E x t e n t % |
| 2979 | % % |
| 2980 | % % |
| 2981 | % % |
| 2982 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2983 | % |
| 2984 | % SetImageExtent() sets the image size (i.e. columns & rows). |
| 2985 | % |
| 2986 | % The format of the SetImageExtent method is: |
| 2987 | % |
| 2988 | % MagickBooleanType SetImageExtent(Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2989 | % const size_t columns,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2990 | % |
| 2991 | % A description of each parameter follows: |
| 2992 | % |
| 2993 | % o image: the image. |
| 2994 | % |
| 2995 | % o columns: The image width in pixels. |
| 2996 | % |
| 2997 | % o rows: The image height in pixels. |
| 2998 | % |
| 2999 | */ |
| 3000 | MagickExport MagickBooleanType SetImageExtent(Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3001 | const size_t columns,const size_t rows) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3002 | { |
| 3003 | Cache |
| 3004 | cache; |
| 3005 | |
| 3006 | if ((columns != 0) && (rows != 0)) |
| 3007 | { |
| 3008 | image->columns=columns; |
| 3009 | image->rows=rows; |
| 3010 | } |
| 3011 | cache=GetImagePixelCache(image,MagickTrue,&image->exception); |
| 3012 | return(cache == (Cache) NULL ? MagickFalse : MagickTrue); |
| 3013 | } |
| 3014 | |
| 3015 | /* |
| 3016 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3017 | % % |
| 3018 | % % |
| 3019 | % % |
| 3020 | + S e t I m a g e I n f o % |
| 3021 | % % |
| 3022 | % % |
| 3023 | % % |
| 3024 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3025 | % |
| 3026 | % SetImageInfo() initializes the `magick' field of the ImageInfo structure. |
| 3027 | % It is set to a type of image format based on the prefix or suffix of the |
| 3028 | % filename. For example, `ps:image' returns PS indicating a Postscript image. |
| 3029 | % JPEG is returned for this filename: `image.jpg'. The filename prefix has |
| 3030 | % precendence over the suffix. Use an optional index enclosed in brackets |
| 3031 | % after a file name to specify a desired scene of a multi-resolution image |
| 3032 | % format like Photo CD (e.g. img0001.pcd[4]). A True (non-zero) return value |
| 3033 | % indicates success. |
| 3034 | % |
| 3035 | % The format of the SetImageInfo method is: |
| 3036 | % |
| 3037 | % MagickBooleanType SetImageInfo(ImageInfo *image_info, |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3038 | % const unsigned int frames,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3039 | % |
| 3040 | % A description of each parameter follows: |
| 3041 | % |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3042 | % o image_info: the image info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3043 | % |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3044 | % o frames: the number of images you intend to write. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3045 | % |
| 3046 | % o exception: return any errors or warnings in this structure. |
| 3047 | % |
| 3048 | */ |
| 3049 | MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info, |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3050 | const unsigned int frames,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3051 | { |
| 3052 | char |
| 3053 | extension[MaxTextExtent], |
| 3054 | filename[MaxTextExtent], |
| 3055 | magic[MaxTextExtent], |
| 3056 | *q, |
| 3057 | subimage[MaxTextExtent]; |
| 3058 | |
| 3059 | const MagicInfo |
| 3060 | *magic_info; |
| 3061 | |
| 3062 | const MagickInfo |
| 3063 | *magick_info; |
| 3064 | |
| 3065 | ExceptionInfo |
| 3066 | *sans_exception; |
| 3067 | |
| 3068 | Image |
| 3069 | *image; |
| 3070 | |
| 3071 | MagickBooleanType |
| 3072 | status; |
| 3073 | |
| 3074 | register const char |
| 3075 | *p; |
| 3076 | |
| 3077 | ssize_t |
| 3078 | count; |
| 3079 | |
| 3080 | unsigned char |
| 3081 | magick[2*MaxTextExtent]; |
| 3082 | |
| 3083 | /* |
| 3084 | Look for 'image.format' in filename. |
| 3085 | */ |
| 3086 | assert(image_info != (ImageInfo *) NULL); |
| 3087 | assert(image_info->signature == MagickSignature); |
| 3088 | if (image_info->debug != MagickFalse) |
| 3089 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 3090 | image_info->filename); |
| 3091 | *subimage='\0'; |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3092 | if (frames == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3093 | { |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3094 | GetPathComponent(image_info->filename,SubimagePath,subimage); |
| 3095 | if (*subimage != '\0') |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3096 | { |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3097 | /* |
| 3098 | Look for scene specification (e.g. img0001.pcd[4]). |
| 3099 | */ |
| 3100 | if (IsSceneGeometry(subimage,MagickFalse) == MagickFalse) |
| 3101 | { |
| 3102 | if (IsGeometry(subimage) != MagickFalse) |
| 3103 | (void) CloneString(&image_info->extract,subimage); |
| 3104 | } |
| 3105 | else |
| 3106 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3107 | size_t |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3108 | first, |
| 3109 | last; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3110 | |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3111 | (void) CloneString(&image_info->scenes,subimage); |
| 3112 | image_info->scene=StringToUnsignedLong(image_info->scenes); |
| 3113 | image_info->number_scenes=image_info->scene; |
| 3114 | p=image_info->scenes; |
| 3115 | for (q=(char *) image_info->scenes; *q != '\0'; p++) |
| 3116 | { |
| 3117 | while ((isspace((int) ((unsigned char) *p)) != 0) || |
| 3118 | (*p == ',')) |
| 3119 | p++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3120 | first=(size_t) strtol(p,&q,10); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3121 | last=first; |
| 3122 | while (isspace((int) ((unsigned char) *q)) != 0) |
| 3123 | q++; |
| 3124 | if (*q == '-') |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3125 | last=(size_t) strtol(q+1,&q,10); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3126 | if (first > last) |
| 3127 | Swap(first,last); |
| 3128 | if (first < image_info->scene) |
| 3129 | image_info->scene=first; |
| 3130 | if (last > image_info->number_scenes) |
| 3131 | image_info->number_scenes=last; |
| 3132 | p=q; |
| 3133 | } |
| 3134 | image_info->number_scenes-=image_info->scene-1; |
| 3135 | image_info->subimage=image_info->scene; |
| 3136 | image_info->subrange=image_info->number_scenes; |
| 3137 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3138 | } |
| 3139 | } |
| 3140 | *extension='\0'; |
| 3141 | GetPathComponent(image_info->filename,ExtensionPath,extension); |
| 3142 | #if defined(MAGICKCORE_ZLIB_DELEGATE) |
| 3143 | if (*extension != '\0') |
| 3144 | if ((LocaleCompare(extension,"gz") == 0) || |
| 3145 | (LocaleCompare(extension,"Z") == 0) || |
| 3146 | (LocaleCompare(extension,"wmz") == 0)) |
| 3147 | { |
| 3148 | char |
| 3149 | path[MaxTextExtent]; |
| 3150 | |
| 3151 | (void) CopyMagickString(path,image_info->filename,MaxTextExtent); |
| 3152 | path[strlen(path)-strlen(extension)-1]='\0'; |
| 3153 | GetPathComponent(path,ExtensionPath,extension); |
| 3154 | } |
| 3155 | #endif |
| 3156 | #if defined(MAGICKCORE_BZLIB_DELEGATE) |
| 3157 | if (*extension != '\0') |
| 3158 | if (LocaleCompare(extension,"bz2") == 0) |
| 3159 | { |
| 3160 | char |
| 3161 | path[MaxTextExtent]; |
| 3162 | |
| 3163 | (void) CopyMagickString(path,image_info->filename,MaxTextExtent); |
| 3164 | path[strlen(path)-strlen(extension)-1]='\0'; |
| 3165 | GetPathComponent(path,ExtensionPath,extension); |
| 3166 | } |
| 3167 | #endif |
| 3168 | image_info->affirm=MagickFalse; |
| 3169 | sans_exception=AcquireExceptionInfo(); |
| 3170 | if (*extension != '\0') |
| 3171 | { |
| 3172 | MagickFormatType |
| 3173 | format_type; |
| 3174 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3175 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3176 | i; |
| 3177 | |
| 3178 | static const char |
| 3179 | *format_type_formats[] = |
| 3180 | { |
| 3181 | "AUTOTRACE", |
| 3182 | "BROWSE", |
| 3183 | "DCRAW", |
| 3184 | "EDIT", |
| 3185 | "EPHEMERAL", |
| 3186 | "LAUNCH", |
| 3187 | "MPEG:DECODE", |
| 3188 | "MPEG:ENCODE", |
| 3189 | "PRINT", |
| 3190 | "PS:ALPHA", |
| 3191 | "PS:CMYK", |
| 3192 | "PS:COLOR", |
| 3193 | "PS:GRAY", |
| 3194 | "PS:MONO", |
| 3195 | "SCAN", |
| 3196 | "SHOW", |
| 3197 | "WIN", |
| 3198 | (char *) NULL |
| 3199 | }; |
| 3200 | |
| 3201 | /* |
| 3202 | User specified image format. |
| 3203 | */ |
| 3204 | (void) CopyMagickString(magic,extension,MaxTextExtent); |
| 3205 | LocaleUpper(magic); |
| 3206 | /* |
| 3207 | Look for explicit image formats. |
| 3208 | */ |
| 3209 | format_type=UndefinedFormatType; |
| 3210 | i=0; |
cristy | dd9a253 | 2010-02-20 19:26:46 +0000 | [diff] [blame] | 3211 | while ((format_type == UndefinedFormatType) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3212 | (format_type_formats[i] != (char *) NULL)) |
| 3213 | { |
| 3214 | if ((*magic == *format_type_formats[i]) && |
| 3215 | (LocaleCompare(magic,format_type_formats[i]) == 0)) |
| 3216 | format_type=ExplicitFormatType; |
| 3217 | i++; |
| 3218 | } |
| 3219 | magick_info=GetMagickInfo(magic,sans_exception); |
| 3220 | if ((magick_info != (const MagickInfo *) NULL) && |
| 3221 | (magick_info->format_type != UndefinedFormatType)) |
| 3222 | format_type=magick_info->format_type; |
| 3223 | if (format_type == UndefinedFormatType) |
| 3224 | (void) CopyMagickString(image_info->magick,magic,MaxTextExtent); |
| 3225 | else |
| 3226 | if (format_type == ExplicitFormatType) |
| 3227 | { |
| 3228 | image_info->affirm=MagickTrue; |
| 3229 | (void) CopyMagickString(image_info->magick,magic,MaxTextExtent); |
| 3230 | } |
| 3231 | if (LocaleCompare(magic,"RGB") == 0) |
| 3232 | image_info->affirm=MagickFalse; /* maybe SGI disguised as RGB */ |
| 3233 | } |
| 3234 | /* |
| 3235 | Look for explicit 'format:image' in filename. |
| 3236 | */ |
| 3237 | *magic='\0'; |
| 3238 | GetPathComponent(image_info->filename,MagickPath,magic); |
| 3239 | if (*magic == '\0') |
| 3240 | (void) CopyMagickString(magic,image_info->magick,MaxTextExtent); |
| 3241 | else |
| 3242 | { |
| 3243 | /* |
| 3244 | User specified image format. |
| 3245 | */ |
| 3246 | LocaleUpper(magic); |
| 3247 | if (IsMagickConflict(magic) == MagickFalse) |
| 3248 | { |
| 3249 | (void) CopyMagickString(image_info->magick,magic,MaxTextExtent); |
| 3250 | if (LocaleCompare(magic,"EPHEMERAL") != 0) |
| 3251 | image_info->affirm=MagickTrue; |
| 3252 | else |
| 3253 | image_info->temporary=MagickTrue; |
| 3254 | } |
| 3255 | } |
| 3256 | magick_info=GetMagickInfo(magic,sans_exception); |
| 3257 | sans_exception=DestroyExceptionInfo(sans_exception); |
| 3258 | if ((magick_info == (const MagickInfo *) NULL) || |
| 3259 | (GetMagickEndianSupport(magick_info) == MagickFalse)) |
| 3260 | image_info->endian=UndefinedEndian; |
| 3261 | GetPathComponent(image_info->filename,CanonicalPath,filename); |
| 3262 | (void) CopyMagickString(image_info->filename,filename,MaxTextExtent); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3263 | if ((image_info->adjoin != MagickFalse) && (frames > 1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3264 | { |
| 3265 | /* |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3266 | Test for multiple image support (e.g. image%02d.png). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3267 | */ |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3268 | (void) InterpretImageFilename(image_info,(Image *) NULL, |
| 3269 | image_info->filename,(int) image_info->scene,filename); |
| 3270 | if ((LocaleCompare(filename,image_info->filename) != 0) && |
| 3271 | (strchr(filename,'%') == (char *) NULL)) |
| 3272 | image_info->adjoin=MagickFalse; |
| 3273 | } |
| 3274 | if ((image_info->adjoin != MagickFalse) && (frames > 0)) |
| 3275 | { |
| 3276 | /* |
| 3277 | Some image formats do not support multiple frames per file. |
| 3278 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3279 | magick_info=GetMagickInfo(magic,exception); |
| 3280 | if (magick_info != (const MagickInfo *) NULL) |
| 3281 | if (GetMagickAdjoin(magick_info) == MagickFalse) |
| 3282 | image_info->adjoin=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3283 | } |
| 3284 | if (image_info->affirm != MagickFalse) |
| 3285 | return(MagickTrue); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3286 | if (frames == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3287 | { |
| 3288 | /* |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3289 | Determine the image format from the first few bytes of the file. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3290 | */ |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3291 | image=AcquireImage(image_info); |
| 3292 | (void) CopyMagickString(image->filename,image_info->filename, |
| 3293 | MaxTextExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3294 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 3295 | if (status == MagickFalse) |
| 3296 | { |
| 3297 | image=DestroyImage(image); |
| 3298 | return(MagickFalse); |
| 3299 | } |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 3300 | if ((IsBlobSeekable(image) == MagickFalse) || |
| 3301 | (IsBlobExempt(image) != MagickFalse)) |
| 3302 | { |
| 3303 | /* |
| 3304 | Copy standard input or pipe to temporary file. |
| 3305 | */ |
| 3306 | *filename='\0'; |
| 3307 | status=ImageToFile(image,filename,exception); |
| 3308 | (void) CloseBlob(image); |
| 3309 | if (status == MagickFalse) |
| 3310 | { |
| 3311 | image=DestroyImage(image); |
| 3312 | return(MagickFalse); |
| 3313 | } |
| 3314 | SetImageInfoFile(image_info,(FILE *) NULL); |
| 3315 | (void) CopyMagickString(image->filename,filename,MaxTextExtent); |
| 3316 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 3317 | if (status == MagickFalse) |
| 3318 | { |
| 3319 | image=DestroyImage(image); |
| 3320 | return(MagickFalse); |
| 3321 | } |
| 3322 | (void) CopyMagickString(image_info->filename,filename,MaxTextExtent); |
| 3323 | image_info->temporary=MagickTrue; |
| 3324 | } |
| 3325 | (void) ResetMagickMemory(magick,0,sizeof(magick)); |
| 3326 | count=ReadBlob(image,2*MaxTextExtent,magick); |
| 3327 | (void) CloseBlob(image); |
| 3328 | image=DestroyImage(image); |
| 3329 | /* |
| 3330 | Check magic.xml configuration file. |
| 3331 | */ |
| 3332 | sans_exception=AcquireExceptionInfo(); |
| 3333 | magic_info=GetMagicInfo(magick,(size_t) count,sans_exception); |
| 3334 | if ((magic_info != (const MagicInfo *) NULL) && |
| 3335 | (GetMagicName(magic_info) != (char *) NULL)) |
| 3336 | { |
| 3337 | (void) CopyMagickString(image_info->magick,GetMagicName(magic_info), |
| 3338 | MaxTextExtent); |
| 3339 | magick_info=GetMagickInfo(image_info->magick,sans_exception); |
| 3340 | if ((magick_info == (const MagickInfo *) NULL) || |
| 3341 | (GetMagickEndianSupport(magick_info) == MagickFalse)) |
| 3342 | image_info->endian=UndefinedEndian; |
| 3343 | sans_exception=DestroyExceptionInfo(sans_exception); |
| 3344 | return(MagickTrue); |
| 3345 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3346 | magick_info=GetMagickInfo(image_info->magick,sans_exception); |
| 3347 | if ((magick_info == (const MagickInfo *) NULL) || |
| 3348 | (GetMagickEndianSupport(magick_info) == MagickFalse)) |
| 3349 | image_info->endian=UndefinedEndian; |
| 3350 | sans_exception=DestroyExceptionInfo(sans_exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3351 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3352 | return(MagickTrue); |
| 3353 | } |
| 3354 | |
| 3355 | /* |
| 3356 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3357 | % % |
| 3358 | % % |
| 3359 | % % |
| 3360 | % S e t I m a g e I n f o B l o b % |
| 3361 | % % |
| 3362 | % % |
| 3363 | % % |
| 3364 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3365 | % |
| 3366 | % SetImageInfoBlob() sets the image info blob member. |
| 3367 | % |
| 3368 | % The format of the SetImageInfoBlob method is: |
| 3369 | % |
| 3370 | % void SetImageInfoBlob(ImageInfo *image_info,const void *blob, |
| 3371 | % const size_t length) |
| 3372 | % |
| 3373 | % A description of each parameter follows: |
| 3374 | % |
| 3375 | % o image_info: the image info. |
| 3376 | % |
| 3377 | % o blob: the blob. |
| 3378 | % |
| 3379 | % o length: the blob length. |
| 3380 | % |
| 3381 | */ |
| 3382 | MagickExport void SetImageInfoBlob(ImageInfo *image_info,const void *blob, |
| 3383 | const size_t length) |
| 3384 | { |
| 3385 | assert(image_info != (ImageInfo *) NULL); |
| 3386 | assert(image_info->signature == MagickSignature); |
| 3387 | if (image_info->debug != MagickFalse) |
| 3388 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 3389 | image_info->filename); |
| 3390 | image_info->blob=(void *) blob; |
| 3391 | image_info->length=length; |
| 3392 | } |
| 3393 | |
| 3394 | /* |
| 3395 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3396 | % % |
| 3397 | % % |
| 3398 | % % |
| 3399 | % S e t I m a g e I n f o F i l e % |
| 3400 | % % |
| 3401 | % % |
| 3402 | % % |
| 3403 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3404 | % |
| 3405 | % SetImageInfoFile() sets the image info file member. |
| 3406 | % |
| 3407 | % The format of the SetImageInfoFile method is: |
| 3408 | % |
| 3409 | % void SetImageInfoFile(ImageInfo *image_info,FILE *file) |
| 3410 | % |
| 3411 | % A description of each parameter follows: |
| 3412 | % |
| 3413 | % o image_info: the image info. |
| 3414 | % |
| 3415 | % o file: the file. |
| 3416 | % |
| 3417 | */ |
| 3418 | MagickExport void SetImageInfoFile(ImageInfo *image_info,FILE *file) |
| 3419 | { |
| 3420 | assert(image_info != (ImageInfo *) NULL); |
| 3421 | assert(image_info->signature == MagickSignature); |
| 3422 | if (image_info->debug != MagickFalse) |
| 3423 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 3424 | image_info->filename); |
| 3425 | image_info->file=file; |
| 3426 | } |
| 3427 | |
| 3428 | /* |
| 3429 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3430 | % % |
| 3431 | % % |
| 3432 | % % |
| 3433 | % S e t I m a g e M a s k % |
| 3434 | % % |
| 3435 | % % |
| 3436 | % % |
| 3437 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3438 | % |
| 3439 | % SetImageMask() associates a mask with the image. The mask must be the same |
| 3440 | % dimensions as the image. |
| 3441 | % |
| 3442 | % The format of the SetImageMask method is: |
| 3443 | % |
| 3444 | % MagickBooleanType SetImageMask(Image *image,const Image *mask) |
| 3445 | % |
| 3446 | % A description of each parameter follows: |
| 3447 | % |
| 3448 | % o image: the image. |
| 3449 | % |
| 3450 | % o mask: the image mask. |
| 3451 | % |
| 3452 | */ |
| 3453 | MagickExport MagickBooleanType SetImageMask(Image *image, |
| 3454 | const Image *mask) |
| 3455 | { |
| 3456 | assert(image != (Image *) NULL); |
| 3457 | if (image->debug != MagickFalse) |
| 3458 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3459 | assert(image->signature == MagickSignature); |
| 3460 | if (mask != (const Image *) NULL) |
| 3461 | if ((mask->columns != image->columns) || (mask->rows != image->rows)) |
| 3462 | ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename); |
| 3463 | if (image->mask != (Image *) NULL) |
| 3464 | image->mask=DestroyImage(image->mask); |
| 3465 | image->mask=NewImageList(); |
| 3466 | if (mask == (Image *) NULL) |
| 3467 | return(MagickTrue); |
| 3468 | if (SetImageStorageClass(image,DirectClass) == MagickFalse) |
| 3469 | return(MagickFalse); |
| 3470 | image->mask=CloneImage(mask,0,0,MagickTrue,&image->exception); |
| 3471 | if (image->mask == (Image *) NULL) |
| 3472 | return(MagickFalse); |
| 3473 | return(MagickTrue); |
| 3474 | } |
| 3475 | |
| 3476 | /* |
| 3477 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3478 | % % |
| 3479 | % % |
| 3480 | % % |
| 3481 | % S e t I m a g e O p a c i t y % |
| 3482 | % % |
| 3483 | % % |
| 3484 | % % |
| 3485 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3486 | % |
| 3487 | % SetImageOpacity() sets the opacity levels of the image. |
| 3488 | % |
| 3489 | % The format of the SetImageOpacity method is: |
| 3490 | % |
| 3491 | % MagickBooleanType SetImageOpacity(Image *image,const Quantum opacity) |
| 3492 | % |
| 3493 | % A description of each parameter follows: |
| 3494 | % |
| 3495 | % o image: the image. |
| 3496 | % |
| 3497 | % o opacity: the level of transparency: 0 is fully opaque and QuantumRange is |
| 3498 | % fully transparent. |
| 3499 | % |
| 3500 | */ |
| 3501 | MagickExport MagickBooleanType SetImageOpacity(Image *image, |
| 3502 | const Quantum opacity) |
| 3503 | { |
| 3504 | CacheView |
| 3505 | *image_view; |
| 3506 | |
| 3507 | ExceptionInfo |
| 3508 | *exception; |
| 3509 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3510 | MagickBooleanType |
| 3511 | status; |
| 3512 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 3513 | ssize_t |
| 3514 | y; |
| 3515 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3516 | assert(image != (Image *) NULL); |
| 3517 | if (image->debug != MagickFalse) |
| 3518 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3519 | assert(image->signature == MagickSignature); |
| 3520 | image->matte=opacity != OpaqueOpacity ? MagickTrue : MagickFalse; |
| 3521 | status=MagickTrue; |
| 3522 | exception=(&image->exception); |
| 3523 | image_view=AcquireCacheView(image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3524 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 3525 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3526 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3527 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3528 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3529 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3530 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3531 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 3532 | register ssize_t |
| 3533 | x; |
| 3534 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3535 | if (status == MagickFalse) |
| 3536 | continue; |
| 3537 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 3538 | if (q == (PixelPacket *) NULL) |
| 3539 | { |
| 3540 | status=MagickFalse; |
| 3541 | continue; |
| 3542 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3543 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3544 | { |
cristy | 46f0820 | 2010-01-10 04:04:21 +0000 | [diff] [blame] | 3545 | SetOpacityPixelComponent(q,opacity); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3546 | q++; |
| 3547 | } |
| 3548 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 3549 | status=MagickFalse; |
| 3550 | } |
| 3551 | image_view=DestroyCacheView(image_view); |
| 3552 | return(status); |
| 3553 | } |
| 3554 | |
| 3555 | /* |
| 3556 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3557 | % % |
| 3558 | % % |
| 3559 | % % |
| 3560 | % S e t I m a g e T y p e % |
| 3561 | % % |
| 3562 | % % |
| 3563 | % % |
| 3564 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3565 | % |
| 3566 | % SetImageType() sets the type of image. Choose from these types: |
| 3567 | % |
| 3568 | % Bilevel Grayscale GrayscaleMatte |
| 3569 | % Palette PaletteMatte TrueColor |
| 3570 | % TrueColorMatte ColorSeparation ColorSeparationMatte |
| 3571 | % OptimizeType |
| 3572 | % |
| 3573 | % The format of the SetImageType method is: |
| 3574 | % |
| 3575 | % MagickBooleanType SetImageType(Image *image,const ImageType type) |
| 3576 | % |
| 3577 | % A description of each parameter follows: |
| 3578 | % |
| 3579 | % o image: the image. |
| 3580 | % |
| 3581 | % o type: Image type. |
| 3582 | % |
| 3583 | */ |
| 3584 | MagickExport MagickBooleanType SetImageType(Image *image,const ImageType type) |
| 3585 | { |
| 3586 | const char |
| 3587 | *artifact; |
| 3588 | |
| 3589 | ImageInfo |
| 3590 | *image_info; |
| 3591 | |
| 3592 | MagickBooleanType |
| 3593 | status; |
| 3594 | |
| 3595 | QuantizeInfo |
| 3596 | *quantize_info; |
| 3597 | |
| 3598 | assert(image != (Image *) NULL); |
| 3599 | if (image->debug != MagickFalse) |
| 3600 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3601 | assert(image->signature == MagickSignature); |
| 3602 | status=MagickTrue; |
| 3603 | image_info=AcquireImageInfo(); |
| 3604 | image_info->dither=image->dither; |
| 3605 | artifact=GetImageArtifact(image,"dither"); |
| 3606 | if (artifact != (const char *) NULL) |
| 3607 | (void) SetImageOption(image_info,"dither",artifact); |
| 3608 | switch (type) |
| 3609 | { |
| 3610 | case BilevelType: |
| 3611 | { |
| 3612 | if (IsGrayImage(image,&image->exception) == MagickFalse) |
| 3613 | status=TransformImageColorspace(image,GRAYColorspace); |
| 3614 | if (IsMonochromeImage(image,&image->exception) == MagickFalse) |
| 3615 | { |
| 3616 | quantize_info=AcquireQuantizeInfo(image_info); |
| 3617 | quantize_info->number_colors=2; |
| 3618 | quantize_info->colorspace=GRAYColorspace; |
| 3619 | status=QuantizeImage(quantize_info,image); |
| 3620 | quantize_info=DestroyQuantizeInfo(quantize_info); |
| 3621 | } |
| 3622 | image->matte=MagickFalse; |
| 3623 | break; |
| 3624 | } |
| 3625 | case GrayscaleType: |
| 3626 | { |
| 3627 | if (IsGrayImage(image,&image->exception) == MagickFalse) |
| 3628 | status=TransformImageColorspace(image,GRAYColorspace); |
| 3629 | image->matte=MagickFalse; |
| 3630 | break; |
| 3631 | } |
| 3632 | case GrayscaleMatteType: |
| 3633 | { |
| 3634 | if (IsGrayImage(image,&image->exception) == MagickFalse) |
| 3635 | status=TransformImageColorspace(image,GRAYColorspace); |
| 3636 | if (image->matte == MagickFalse) |
| 3637 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); |
| 3638 | break; |
| 3639 | } |
| 3640 | case PaletteType: |
| 3641 | { |
| 3642 | if (image->colorspace != RGBColorspace) |
| 3643 | status=TransformImageColorspace(image,RGBColorspace); |
| 3644 | if ((image->storage_class == DirectClass) || (image->colors > 256)) |
| 3645 | { |
| 3646 | quantize_info=AcquireQuantizeInfo(image_info); |
| 3647 | quantize_info->number_colors=256; |
| 3648 | status=QuantizeImage(quantize_info,image); |
| 3649 | quantize_info=DestroyQuantizeInfo(quantize_info); |
| 3650 | } |
| 3651 | image->matte=MagickFalse; |
| 3652 | break; |
| 3653 | } |
| 3654 | case PaletteBilevelMatteType: |
| 3655 | { |
| 3656 | if (image->colorspace != RGBColorspace) |
| 3657 | status=TransformImageColorspace(image,RGBColorspace); |
| 3658 | if (image->matte == MagickFalse) |
| 3659 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); |
| 3660 | (void) BilevelImageChannel(image,AlphaChannel,(double) QuantumRange/2.0); |
| 3661 | quantize_info=AcquireQuantizeInfo(image_info); |
| 3662 | status=QuantizeImage(quantize_info,image); |
| 3663 | quantize_info=DestroyQuantizeInfo(quantize_info); |
| 3664 | break; |
| 3665 | } |
| 3666 | case PaletteMatteType: |
| 3667 | { |
| 3668 | if (image->colorspace != RGBColorspace) |
| 3669 | status=TransformImageColorspace(image,RGBColorspace); |
| 3670 | if (image->matte == MagickFalse) |
| 3671 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); |
| 3672 | quantize_info=AcquireQuantizeInfo(image_info); |
| 3673 | quantize_info->colorspace=TransparentColorspace; |
| 3674 | status=QuantizeImage(quantize_info,image); |
| 3675 | quantize_info=DestroyQuantizeInfo(quantize_info); |
| 3676 | break; |
| 3677 | } |
| 3678 | case TrueColorType: |
| 3679 | { |
| 3680 | if (image->colorspace != RGBColorspace) |
| 3681 | status=TransformImageColorspace(image,RGBColorspace); |
| 3682 | if (image->storage_class != DirectClass) |
| 3683 | status=SetImageStorageClass(image,DirectClass); |
| 3684 | image->matte=MagickFalse; |
| 3685 | break; |
| 3686 | } |
| 3687 | case TrueColorMatteType: |
| 3688 | { |
| 3689 | if (image->colorspace != RGBColorspace) |
| 3690 | status=TransformImageColorspace(image,RGBColorspace); |
| 3691 | if (image->storage_class != DirectClass) |
| 3692 | status=SetImageStorageClass(image,DirectClass); |
| 3693 | if (image->matte == MagickFalse) |
| 3694 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); |
| 3695 | break; |
| 3696 | } |
| 3697 | case ColorSeparationType: |
| 3698 | { |
| 3699 | if (image->colorspace != CMYKColorspace) |
| 3700 | { |
| 3701 | if (image->colorspace != RGBColorspace) |
| 3702 | status=TransformImageColorspace(image,RGBColorspace); |
| 3703 | status=TransformImageColorspace(image,CMYKColorspace); |
| 3704 | } |
| 3705 | if (image->storage_class != DirectClass) |
| 3706 | status=SetImageStorageClass(image,DirectClass); |
| 3707 | image->matte=MagickFalse; |
| 3708 | break; |
| 3709 | } |
| 3710 | case ColorSeparationMatteType: |
| 3711 | { |
| 3712 | if (image->colorspace != CMYKColorspace) |
| 3713 | { |
| 3714 | if (image->colorspace != RGBColorspace) |
| 3715 | status=TransformImageColorspace(image,RGBColorspace); |
| 3716 | status=TransformImageColorspace(image,CMYKColorspace); |
| 3717 | } |
| 3718 | if (image->storage_class != DirectClass) |
| 3719 | status=SetImageStorageClass(image,DirectClass); |
| 3720 | if (image->matte == MagickFalse) |
| 3721 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel); |
| 3722 | break; |
| 3723 | } |
| 3724 | case OptimizeType: |
| 3725 | case UndefinedType: |
| 3726 | break; |
| 3727 | } |
| 3728 | image->type=type; |
| 3729 | image_info=DestroyImageInfo(image_info); |
| 3730 | return(status); |
| 3731 | } |
| 3732 | |
| 3733 | /* |
| 3734 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3735 | % % |
| 3736 | % % |
| 3737 | % % |
| 3738 | % S e t I m a g e V i r t u a l P i x e l M e t h o d % |
| 3739 | % % |
| 3740 | % % |
| 3741 | % % |
| 3742 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3743 | % |
| 3744 | % SetImageVirtualPixelMethod() sets the "virtual pixels" method for the |
| 3745 | % image and returns the previous setting. A virtual pixel is any pixel access |
| 3746 | % that is outside the boundaries of the image cache. |
| 3747 | % |
| 3748 | % The format of the SetImageVirtualPixelMethod() method is: |
| 3749 | % |
| 3750 | % VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image, |
| 3751 | % const VirtualPixelMethod virtual_pixel_method) |
| 3752 | % |
| 3753 | % A description of each parameter follows: |
| 3754 | % |
| 3755 | % o image: the image. |
| 3756 | % |
| 3757 | % o virtual_pixel_method: choose the type of virtual pixel. |
| 3758 | % |
| 3759 | */ |
| 3760 | MagickExport VirtualPixelMethod SetImageVirtualPixelMethod(const Image *image, |
| 3761 | const VirtualPixelMethod virtual_pixel_method) |
| 3762 | { |
| 3763 | assert(image != (const Image *) NULL); |
| 3764 | assert(image->signature == MagickSignature); |
| 3765 | if (image->debug != MagickFalse) |
| 3766 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3767 | return(SetPixelCacheVirtualMethod(image,virtual_pixel_method)); |
| 3768 | } |
| 3769 | |
| 3770 | /* |
| 3771 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3772 | % % |
| 3773 | % % |
| 3774 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3775 | % S t r i p I m a g e % |
| 3776 | % % |
| 3777 | % % |
| 3778 | % % |
| 3779 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3780 | % |
cristy | 376bda9 | 2009-12-22 21:15:23 +0000 | [diff] [blame] | 3781 | % StripImage() strips an image of all profiles and comments. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3782 | % |
| 3783 | % The format of the StripImage method is: |
| 3784 | % |
| 3785 | % MagickBooleanType StripImage(Image *image) |
| 3786 | % |
| 3787 | % A description of each parameter follows: |
| 3788 | % |
| 3789 | % o image: the image. |
| 3790 | % |
| 3791 | */ |
| 3792 | MagickExport MagickBooleanType StripImage(Image *image) |
| 3793 | { |
| 3794 | assert(image != (Image *) NULL); |
| 3795 | if (image->debug != MagickFalse) |
| 3796 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3797 | DestroyImageProfiles(image); |
cristy | 6b9aca1 | 2010-02-21 01:50:11 +0000 | [diff] [blame] | 3798 | (void) DeleteImageProperty(image,"comment"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3799 | return(MagickTrue); |
| 3800 | } |
| 3801 | |
| 3802 | /* |
| 3803 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3804 | % % |
| 3805 | % % |
| 3806 | % % |
| 3807 | + S y n c I m a g e % |
| 3808 | % % |
| 3809 | % % |
| 3810 | % % |
| 3811 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3812 | % |
| 3813 | % SyncImage() initializes the red, green, and blue intensities of each pixel |
| 3814 | % as defined by the colormap index. |
| 3815 | % |
| 3816 | % The format of the SyncImage method is: |
| 3817 | % |
| 3818 | % MagickBooleanType SyncImage(Image *image) |
| 3819 | % |
| 3820 | % A description of each parameter follows: |
| 3821 | % |
| 3822 | % o image: the image. |
| 3823 | % |
| 3824 | */ |
| 3825 | |
| 3826 | static inline IndexPacket PushColormapIndex(Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3827 | const size_t index,MagickBooleanType *range_exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3828 | { |
| 3829 | if (index < image->colors) |
| 3830 | return((IndexPacket) index); |
| 3831 | *range_exception=MagickTrue; |
| 3832 | return((IndexPacket) 0); |
| 3833 | } |
| 3834 | |
| 3835 | MagickExport MagickBooleanType SyncImage(Image *image) |
| 3836 | { |
| 3837 | CacheView |
| 3838 | *image_view; |
| 3839 | |
| 3840 | ExceptionInfo |
| 3841 | *exception; |
| 3842 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3843 | MagickBooleanType |
| 3844 | range_exception, |
| 3845 | status; |
| 3846 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 3847 | ssize_t |
| 3848 | y; |
| 3849 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3850 | assert(image != (Image *) NULL); |
| 3851 | if (image->debug != MagickFalse) |
| 3852 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 3853 | assert(image->signature == MagickSignature); |
| 3854 | if (image->storage_class == DirectClass) |
| 3855 | return(MagickFalse); |
| 3856 | range_exception=MagickFalse; |
| 3857 | status=MagickTrue; |
| 3858 | exception=(&image->exception); |
| 3859 | image_view=AcquireCacheView(image); |
cristy | 48974b9 | 2009-12-19 02:36:06 +0000 | [diff] [blame] | 3860 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 3861 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 3862 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3863 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3864 | { |
| 3865 | IndexPacket |
| 3866 | index; |
| 3867 | |
| 3868 | PixelPacket |
| 3869 | pixel; |
| 3870 | |
| 3871 | register IndexPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3872 | *restrict indexes; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3873 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3874 | register PixelPacket |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3875 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3876 | |
cristy | cb6d09b | 2010-06-19 01:59:36 +0000 | [diff] [blame] | 3877 | register ssize_t |
| 3878 | x; |
| 3879 | |
cristy | 48974b9 | 2009-12-19 02:36:06 +0000 | [diff] [blame] | 3880 | if (status == MagickFalse) |
| 3881 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3882 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
| 3883 | if (q == (PixelPacket *) NULL) |
| 3884 | { |
| 3885 | status=MagickFalse; |
| 3886 | continue; |
| 3887 | } |
| 3888 | indexes=GetCacheViewAuthenticIndexQueue(image_view); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3889 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3890 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3891 | index=PushColormapIndex(image,(size_t) indexes[x], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3892 | &range_exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3893 | pixel=image->colormap[(ssize_t) index]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3894 | q->red=pixel.red; |
| 3895 | q->green=pixel.green; |
| 3896 | q->blue=pixel.blue; |
cristy | d027259 | 2010-04-21 01:01:49 +0000 | [diff] [blame] | 3897 | if (image->matte != MagickFalse) |
| 3898 | q->opacity=pixel.opacity; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3899 | q++; |
| 3900 | } |
| 3901 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 3902 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3903 | } |
| 3904 | image_view=DestroyCacheView(image_view); |
| 3905 | if (range_exception != MagickFalse) |
| 3906 | (void) ThrowMagickException(&image->exception,GetMagickModule(), |
| 3907 | CorruptImageError,"InvalidColormapIndex","`%s'",image->filename); |
| 3908 | return(status); |
| 3909 | } |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 3910 | |
| 3911 | /* |
| 3912 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3913 | % % |
| 3914 | % % |
| 3915 | % % |
| 3916 | % S y n c I m a g e S e t t i n g s % |
| 3917 | % % |
| 3918 | % % |
| 3919 | % % |
| 3920 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3921 | % |
| 3922 | % SyncImageSettings() sync the image info options to the image. |
| 3923 | % |
| 3924 | % The format of the SyncImageSettings method is: |
| 3925 | % |
| 3926 | % MagickBooleanType SyncImageSettings(const ImageInfo *image_info, |
| 3927 | % Image *image) |
| 3928 | % MagickBooleanType SyncImagesSettings(const ImageInfo *image_info, |
| 3929 | % Image *image) |
| 3930 | % |
| 3931 | % A description of each parameter follows: |
| 3932 | % |
| 3933 | % o image_info: the image info. |
| 3934 | % |
| 3935 | % o image: the image. |
| 3936 | % |
| 3937 | */ |
| 3938 | |
| 3939 | MagickExport MagickBooleanType SyncImagesSettings(ImageInfo *image_info, |
| 3940 | Image *images) |
| 3941 | { |
| 3942 | Image |
| 3943 | *image; |
| 3944 | |
| 3945 | assert(image_info != (const ImageInfo *) NULL); |
| 3946 | assert(image_info->signature == MagickSignature); |
| 3947 | assert(images != (Image *) NULL); |
| 3948 | assert(images->signature == MagickSignature); |
| 3949 | if (images->debug != MagickFalse) |
| 3950 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename); |
| 3951 | image=images; |
| 3952 | for ( ; image != (Image *) NULL; image=GetNextImageInList(image)) |
| 3953 | (void) SyncImageSettings(image_info,image); |
| 3954 | (void) DeleteImageOption(image_info,"page"); |
| 3955 | return(MagickTrue); |
| 3956 | } |
| 3957 | |
| 3958 | MagickExport MagickBooleanType SyncImageSettings(const ImageInfo *image_info, |
| 3959 | Image *image) |
| 3960 | { |
| 3961 | char |
| 3962 | property[MaxTextExtent]; |
| 3963 | |
| 3964 | const char |
| 3965 | *value, |
| 3966 | *option; |
| 3967 | |
| 3968 | GeometryInfo |
| 3969 | geometry_info; |
| 3970 | |
| 3971 | MagickStatusType |
| 3972 | flags; |
| 3973 | |
cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 3974 | ResolutionType |
| 3975 | units; |
| 3976 | |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 3977 | /* |
| 3978 | Sync image options. |
| 3979 | */ |
| 3980 | assert(image_info != (const ImageInfo *) NULL); |
| 3981 | assert(image_info->signature == MagickSignature); |
| 3982 | assert(image != (Image *) NULL); |
| 3983 | assert(image->signature == MagickSignature); |
| 3984 | if (image->debug != MagickFalse) |
| 3985 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3986 | option=GetImageOption(image_info,"background"); |
| 3987 | if (option != (const char *) NULL) |
| 3988 | (void) QueryColorDatabase(option,&image->background_color, |
| 3989 | &image->exception); |
| 3990 | option=GetImageOption(image_info,"bias"); |
| 3991 | if (option != (const char *) NULL) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 3992 | image->bias=SiPrefixToDouble(option,QuantumRange); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 3993 | option=GetImageOption(image_info,"black-point-compensation"); |
| 3994 | if (option != (const char *) NULL) |
| 3995 | image->black_point_compensation=(MagickBooleanType) ParseMagickOption( |
| 3996 | MagickBooleanOptions,MagickFalse,option); |
| 3997 | option=GetImageOption(image_info,"blue-primary"); |
| 3998 | if (option != (const char *) NULL) |
| 3999 | { |
| 4000 | flags=ParseGeometry(option,&geometry_info); |
| 4001 | image->chromaticity.blue_primary.x=geometry_info.rho; |
| 4002 | image->chromaticity.blue_primary.y=geometry_info.sigma; |
| 4003 | if ((flags & SigmaValue) == 0) |
| 4004 | image->chromaticity.blue_primary.y=image->chromaticity.blue_primary.x; |
| 4005 | } |
| 4006 | option=GetImageOption(image_info,"bordercolor"); |
| 4007 | if (option != (const char *) NULL) |
| 4008 | (void) QueryColorDatabase(option,&image->border_color,&image->exception); |
| 4009 | option=GetImageOption(image_info,"colors"); |
| 4010 | if (option != (const char *) NULL) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 4011 | image->colors=StringToUnsignedLong(option); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4012 | option=GetImageOption(image_info,"compose"); |
| 4013 | if (option != (const char *) NULL) |
| 4014 | image->compose=(CompositeOperator) ParseMagickOption(MagickComposeOptions, |
| 4015 | MagickFalse,option); |
| 4016 | option=GetImageOption(image_info,"compress"); |
| 4017 | if (option != (const char *) NULL) |
| 4018 | image->compression=(CompressionType) ParseMagickOption( |
| 4019 | MagickCompressOptions,MagickFalse,option); |
| 4020 | option=GetImageOption(image_info,"debug"); |
| 4021 | if (option != (const char *) NULL) |
| 4022 | image->debug=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions, |
| 4023 | MagickFalse,option); |
| 4024 | option=GetImageOption(image_info,"delay"); |
| 4025 | if (option != (const char *) NULL) |
| 4026 | { |
| 4027 | GeometryInfo |
| 4028 | geometry_info; |
| 4029 | |
| 4030 | flags=ParseGeometry(option,&geometry_info); |
| 4031 | if ((flags & GreaterValue) != 0) |
| 4032 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4033 | if (image->delay > (size_t) floor(geometry_info.rho+0.5)) |
| 4034 | image->delay=(size_t) floor(geometry_info.rho+0.5); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4035 | } |
| 4036 | else |
| 4037 | if ((flags & LessValue) != 0) |
| 4038 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4039 | if (image->delay < (size_t) floor(geometry_info.rho+0.5)) |
| 4040 | image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4041 | } |
| 4042 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4043 | image->delay=(size_t) floor(geometry_info.rho+0.5); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4044 | if ((flags & SigmaValue) != 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4045 | image->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4046 | } |
| 4047 | option=GetImageOption(image_info,"density"); |
| 4048 | if (option != (const char *) NULL) |
| 4049 | { |
| 4050 | GeometryInfo |
| 4051 | geometry_info; |
| 4052 | |
| 4053 | /* |
| 4054 | Set image density. |
| 4055 | */ |
| 4056 | flags=ParseGeometry(option,&geometry_info); |
| 4057 | image->x_resolution=geometry_info.rho; |
| 4058 | image->y_resolution=geometry_info.sigma; |
| 4059 | if ((flags & SigmaValue) == 0) |
| 4060 | image->y_resolution=image->x_resolution; |
| 4061 | } |
| 4062 | option=GetImageOption(image_info,"depth"); |
| 4063 | if (option != (const char *) NULL) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 4064 | image->depth=StringToUnsignedLong(option); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4065 | option=GetImageOption(image_info,"dispose"); |
| 4066 | if (option != (const char *) NULL) |
| 4067 | image->dispose=(DisposeType) ParseMagickOption(MagickDisposeOptions, |
| 4068 | MagickFalse,option); |
| 4069 | option=GetImageOption(image_info,"endian"); |
| 4070 | if (option != (const char *) NULL) |
| 4071 | image->endian=(EndianType) ParseMagickOption(MagickEndianOptions, |
| 4072 | MagickFalse,option); |
| 4073 | if (image_info->extract != (char *) NULL) |
| 4074 | (void) ParseAbsoluteGeometry(image_info->extract,&image->extract_info); |
| 4075 | option=GetImageOption(image_info,"filter"); |
| 4076 | if (option != (const char *) NULL) |
| 4077 | image->filter=(FilterTypes) ParseMagickOption(MagickFilterOptions, |
| 4078 | MagickFalse,option); |
| 4079 | option=GetImageOption(image_info,"fuzz"); |
| 4080 | if (option != (const char *) NULL) |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 4081 | image->fuzz=SiPrefixToDouble(option,QuantumRange); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4082 | option=GetImageOption(image_info,"gravity"); |
| 4083 | if (option != (const char *) NULL) |
| 4084 | image->gravity=(GravityType) ParseMagickOption(MagickGravityOptions, |
| 4085 | MagickFalse,option); |
| 4086 | option=GetImageOption(image_info,"green-primary"); |
| 4087 | if (option != (const char *) NULL) |
| 4088 | { |
| 4089 | flags=ParseGeometry(option,&geometry_info); |
| 4090 | image->chromaticity.green_primary.x=geometry_info.rho; |
| 4091 | image->chromaticity.green_primary.y=geometry_info.sigma; |
| 4092 | if ((flags & SigmaValue) == 0) |
| 4093 | image->chromaticity.green_primary.y=image->chromaticity.green_primary.x; |
| 4094 | } |
| 4095 | option=GetImageOption(image_info,"intent"); |
| 4096 | if (option != (const char *) NULL) |
| 4097 | image->rendering_intent=(RenderingIntent) ParseMagickOption( |
| 4098 | MagickIntentOptions,MagickFalse,option); |
| 4099 | option=GetImageOption(image_info,"interlace"); |
| 4100 | if (option != (const char *) NULL) |
| 4101 | image->interlace=(InterlaceType) ParseMagickOption(MagickInterlaceOptions, |
| 4102 | MagickFalse,option); |
| 4103 | option=GetImageOption(image_info,"interpolate"); |
| 4104 | if (option != (const char *) NULL) |
| 4105 | image->interpolate=(InterpolatePixelMethod) ParseMagickOption( |
| 4106 | MagickInterpolateOptions,MagickFalse,option); |
| 4107 | option=GetImageOption(image_info,"loop"); |
| 4108 | if (option != (const char *) NULL) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 4109 | image->iterations=StringToUnsignedLong(option); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4110 | option=GetImageOption(image_info,"mattecolor"); |
| 4111 | if (option != (const char *) NULL) |
| 4112 | (void) QueryColorDatabase(option,&image->matte_color,&image->exception); |
| 4113 | option=GetImageOption(image_info,"orient"); |
| 4114 | if (option != (const char *) NULL) |
| 4115 | image->orientation=(OrientationType) ParseMagickOption( |
| 4116 | MagickOrientationOptions,MagickFalse,option); |
| 4117 | option=GetImageOption(image_info,"quality"); |
| 4118 | if (option != (const char *) NULL) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 4119 | image->quality=StringToUnsignedLong(option); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4120 | option=GetImageOption(image_info,"page"); |
| 4121 | if (option != (const char *) NULL) |
| 4122 | { |
| 4123 | char |
| 4124 | *geometry; |
| 4125 | |
| 4126 | geometry=GetPageGeometry(option); |
| 4127 | flags=ParseAbsoluteGeometry(geometry,&image->page); |
| 4128 | geometry=DestroyString(geometry); |
| 4129 | } |
| 4130 | option=GetImageOption(image_info,"red-primary"); |
| 4131 | if (option != (const char *) NULL) |
| 4132 | { |
| 4133 | flags=ParseGeometry(option,&geometry_info); |
| 4134 | image->chromaticity.red_primary.x=geometry_info.rho; |
| 4135 | image->chromaticity.red_primary.y=geometry_info.sigma; |
| 4136 | if ((flags & SigmaValue) == 0) |
| 4137 | image->chromaticity.red_primary.y=image->chromaticity.red_primary.x; |
| 4138 | } |
| 4139 | if (image_info->quality != UndefinedCompressionQuality) |
| 4140 | image->quality=image_info->quality; |
| 4141 | option=GetImageOption(image_info,"scene"); |
| 4142 | if (option != (const char *) NULL) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 4143 | image->scene=StringToUnsignedLong(option); |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4144 | option=GetImageOption(image_info,"taint"); |
| 4145 | if (option != (const char *) NULL) |
| 4146 | image->taint=(MagickBooleanType) ParseMagickOption(MagickBooleanOptions, |
| 4147 | MagickFalse,option); |
| 4148 | option=GetImageOption(image_info,"tile-offset"); |
| 4149 | if (option != (const char *) NULL) |
| 4150 | { |
| 4151 | char |
| 4152 | *geometry; |
| 4153 | |
| 4154 | geometry=GetPageGeometry(option); |
| 4155 | flags=ParseAbsoluteGeometry(geometry,&image->tile_offset); |
| 4156 | geometry=DestroyString(geometry); |
| 4157 | } |
| 4158 | option=GetImageOption(image_info,"transparent-color"); |
| 4159 | if (option != (const char *) NULL) |
| 4160 | (void) QueryColorDatabase(option,&image->transparent_color, |
| 4161 | &image->exception); |
| 4162 | option=GetImageOption(image_info,"type"); |
| 4163 | if (option != (const char *) NULL) |
| 4164 | image->type=(ImageType) ParseMagickOption(MagickTypeOptions,MagickFalse, |
| 4165 | option); |
| 4166 | option=GetImageOption(image_info,"units"); |
| 4167 | if (option != (const char *) NULL) |
cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 4168 | units=(ResolutionType) ParseMagickOption(MagickResolutionOptions, |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4169 | MagickFalse,option); |
cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 4170 | else |
| 4171 | units = image_info->units; |
| 4172 | if (units != UndefinedResolution) |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4173 | { |
cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 4174 | if (image->units != units) |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4175 | switch (image->units) |
| 4176 | { |
| 4177 | case PixelsPerInchResolution: |
| 4178 | { |
cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 4179 | if (units == PixelsPerCentimeterResolution) |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4180 | { |
| 4181 | image->x_resolution/=2.54; |
| 4182 | image->y_resolution/=2.54; |
| 4183 | } |
| 4184 | break; |
| 4185 | } |
| 4186 | case PixelsPerCentimeterResolution: |
| 4187 | { |
cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 4188 | if (units == PixelsPerInchResolution) |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4189 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4190 | image->x_resolution=(double) ((size_t) (100.0*2.54* |
cristy | 1f9ce9f | 2010-04-28 11:55:12 +0000 | [diff] [blame] | 4191 | image->x_resolution+0.5))/100.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4192 | image->y_resolution=(double) ((size_t) (100.0*2.54* |
cristy | 1f9ce9f | 2010-04-28 11:55:12 +0000 | [diff] [blame] | 4193 | image->y_resolution+0.5))/100.0; |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4194 | } |
| 4195 | break; |
| 4196 | } |
| 4197 | default: |
| 4198 | break; |
| 4199 | } |
cristy | 19eb641 | 2010-04-23 14:42:29 +0000 | [diff] [blame] | 4200 | image->units=units; |
cristy | 1626d33 | 2009-11-10 16:58:17 +0000 | [diff] [blame] | 4201 | } |
| 4202 | option=GetImageOption(image_info,"white-point"); |
| 4203 | if (option != (const char *) NULL) |
| 4204 | { |
| 4205 | flags=ParseGeometry(option,&geometry_info); |
| 4206 | image->chromaticity.white_point.x=geometry_info.rho; |
| 4207 | image->chromaticity.white_point.y=geometry_info.sigma; |
| 4208 | if ((flags & SigmaValue) == 0) |
| 4209 | image->chromaticity.white_point.y=image->chromaticity.white_point.x; |
| 4210 | } |
| 4211 | ResetImageOptionIterator(image_info); |
| 4212 | for (option=GetNextImageOption(image_info); option != (const char *) NULL; ) |
| 4213 | { |
| 4214 | value=GetImageOption(image_info,option); |
| 4215 | if (value != (const char *) NULL) |
| 4216 | { |
| 4217 | (void) FormatMagickString(property,MaxTextExtent,"%s",option); |
| 4218 | (void) SetImageArtifact(image,property,value); |
| 4219 | } |
| 4220 | option=GetNextImageOption(image_info); |
| 4221 | } |
| 4222 | return(MagickTrue); |
| 4223 | } |