cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % CCCC OOO N N SSSSS TTTTT IIIII TTTTT U U TTTTT EEEEE % |
| 7 | % C O O NN N SS T I T U U T E % |
| 8 | % C O O N N N ESSS T I T U U T EEE % |
| 9 | % C O O N NN SS T I T U U T E % |
| 10 | % CCCC OOO N N SSSSS T IIIII T UUU T EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Methods to Consitute an Image % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % October 1998 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 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 | Include declarations. |
| 41 | */ |
| 42 | #include "magick/studio.h" |
| 43 | #include "magick/blob.h" |
| 44 | #include "magick/blob-private.h" |
| 45 | #include "magick/exception.h" |
| 46 | #include "magick/exception-private.h" |
| 47 | #include "magick/cache.h" |
| 48 | #include "magick/client.h" |
| 49 | #include "magick/constitute.h" |
| 50 | #include "magick/delegate.h" |
| 51 | #include "magick/geometry.h" |
| 52 | #include "magick/identify.h" |
| 53 | #include "magick/image-private.h" |
| 54 | #include "magick/list.h" |
| 55 | #include "magick/magick.h" |
| 56 | #include "magick/memory_.h" |
| 57 | #include "magick/monitor.h" |
cristy | 36507e6 | 2010-02-11 00:26:48 +0000 | [diff] [blame] | 58 | #include "magick/monitor-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 59 | #include "magick/option.h" |
| 60 | #include "magick/pixel.h" |
| 61 | #include "magick/policy.h" |
| 62 | #include "magick/profile.h" |
| 63 | #include "magick/property.h" |
| 64 | #include "magick/quantum.h" |
| 65 | #include "magick/resize.h" |
| 66 | #include "magick/resource_.h" |
| 67 | #include "magick/semaphore.h" |
| 68 | #include "magick/statistic.h" |
| 69 | #include "magick/stream.h" |
| 70 | #include "magick/string_.h" |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 71 | #include "magick/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 72 | #include "magick/timer.h" |
| 73 | #include "magick/transform.h" |
| 74 | #include "magick/utility.h" |
| 75 | |
| 76 | static SemaphoreInfo |
| 77 | *constitute_semaphore = (SemaphoreInfo *) NULL; |
| 78 | |
| 79 | /* |
| 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 81 | % % |
| 82 | % % |
| 83 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 84 | + C o n s t i t u t e C o m p o n e n t G e n e s i s % |
| 85 | % % |
| 86 | % % |
| 87 | % % |
| 88 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 89 | % |
| 90 | % ConstituteComponentGenesis() instantiates the constitute component. |
| 91 | % |
| 92 | % The format of the ConstituteComponentGenesis method is: |
| 93 | % |
| 94 | % MagickBooleanType ConstituteComponentGenesis(void) |
| 95 | % |
| 96 | */ |
| 97 | MagickExport MagickBooleanType ConstituteComponentGenesis(void) |
| 98 | { |
cristy | 165b609 | 2009-10-26 13:52:10 +0000 | [diff] [blame] | 99 | AcquireSemaphoreInfo(&constitute_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 100 | return(MagickTrue); |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 105 | % % |
| 106 | % % |
| 107 | % % |
| 108 | + C o n s t i t u t e C o m p o n e n t T e r m i n u s % |
| 109 | % % |
| 110 | % % |
| 111 | % % |
| 112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 113 | % |
| 114 | % ConstituteComponentTerminus() destroys the constitute component. |
| 115 | % |
| 116 | % The format of the ConstituteComponentTerminus method is: |
| 117 | % |
| 118 | % ConstituteComponentTerminus(void) |
| 119 | % |
| 120 | */ |
| 121 | MagickExport void ConstituteComponentTerminus(void) |
| 122 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 123 | if (constitute_semaphore == (SemaphoreInfo *) NULL) |
| 124 | AcquireSemaphoreInfo(&constitute_semaphore); |
| 125 | DestroySemaphoreInfo(&constitute_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* |
| 129 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 130 | % % |
| 131 | % % |
| 132 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 133 | % C o n s t i t u t e I m a g e % |
| 134 | % % |
| 135 | % % |
| 136 | % % |
| 137 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 138 | % |
| 139 | % ConstituteImage() returns an image from the pixel data you supply. |
| 140 | % The pixel data must be in scanline order top-to-bottom. The data can be |
| 141 | % char, short int, int, float, or double. Float and double require the |
| 142 | % pixels to be normalized [0..1], otherwise [0..QuantumRange]. For example, to |
| 143 | % create a 640x480 image from unsigned red-green-blue character data, use: |
| 144 | % |
| 145 | % image = ConstituteImage(640,480,"RGB",CharPixel,pixels,&exception); |
| 146 | % |
| 147 | % The format of the ConstituteImage method is: |
| 148 | % |
cristy | 0758f9e | 2010-05-28 01:44:10 +0000 | [diff] [blame] | 149 | % Image *ConstituteImage(const size_t columns,const size_t rows, |
| 150 | % const char *map,const StorageType storage,const void *pixels, |
| 151 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | % |
| 153 | % A description of each parameter follows: |
| 154 | % |
| 155 | % o columns: width in pixels of the image. |
| 156 | % |
| 157 | % o rows: height in pixels of the image. |
| 158 | % |
| 159 | % o map: This string reflects the expected ordering of the pixel array. |
| 160 | % It can be any combination or order of R = red, G = green, B = blue, |
| 161 | % A = alpha (0 is transparent), O = opacity (0 is opaque), C = cyan, |
| 162 | % Y = yellow, M = magenta, K = black, I = intensity (for grayscale), |
| 163 | % P = pad. |
| 164 | % |
| 165 | % o storage: Define the data type of the pixels. Float and double types are |
| 166 | % expected to be normalized [0..1] otherwise [0..QuantumRange]. Choose |
| 167 | % from these types: CharPixel, DoublePixel, FloatPixel, IntegerPixel, |
| 168 | % LongPixel, QuantumPixel, or ShortPixel. |
| 169 | % |
| 170 | % o pixels: This array of values contain the pixel components as defined by |
| 171 | % map and type. You must preallocate this array where the expected |
| 172 | % length varies depending on the values of width, height, map, and type. |
| 173 | % |
| 174 | % o exception: return any errors or warnings in this structure. |
| 175 | % |
| 176 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 177 | MagickExport Image *ConstituteImage(const size_t columns, |
| 178 | const size_t rows,const char *map,const StorageType storage, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 179 | const void *pixels,ExceptionInfo *exception) |
| 180 | { |
| 181 | Image |
| 182 | *image; |
| 183 | |
| 184 | MagickBooleanType |
| 185 | status; |
| 186 | |
| 187 | /* |
| 188 | Allocate image structure. |
| 189 | */ |
| 190 | assert(map != (const char *) NULL); |
| 191 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",map); |
| 192 | assert(pixels != (void *) NULL); |
| 193 | assert(exception != (ExceptionInfo *) NULL); |
| 194 | assert(exception->signature == MagickSignature); |
| 195 | image=AcquireImage((ImageInfo *) NULL); |
| 196 | if (image == (Image *) NULL) |
| 197 | return((Image *) NULL); |
| 198 | if ((columns == 0) || (rows == 0)) |
| 199 | ThrowImageException(OptionError,"NonZeroWidthAndHeightRequired"); |
| 200 | image->columns=columns; |
| 201 | image->rows=rows; |
| 202 | (void) SetImageBackgroundColor(image); |
| 203 | status=ImportImagePixels(image,0,0,columns,rows,map,storage,pixels); |
| 204 | if (status == MagickFalse) |
| 205 | { |
| 206 | InheritException(exception,&image->exception); |
| 207 | image=DestroyImage(image); |
| 208 | } |
| 209 | return(image); |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 214 | % % |
| 215 | % % |
| 216 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 217 | % P i n g I m a g e % |
| 218 | % % |
| 219 | % % |
| 220 | % % |
| 221 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 222 | % |
| 223 | % PingImage() returns all the properties of an image or image sequence |
| 224 | % except for the pixels. It is much faster and consumes far less memory |
| 225 | % than ReadImage(). On failure, a NULL image is returned and exception |
| 226 | % describes the reason for the failure. |
| 227 | % |
| 228 | % The format of the PingImage method is: |
| 229 | % |
| 230 | % Image *PingImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 231 | % |
| 232 | % A description of each parameter follows: |
| 233 | % |
| 234 | % o image_info: Ping the image defined by the file or filename members of |
| 235 | % this structure. |
| 236 | % |
| 237 | % o exception: return any errors or warnings in this structure. |
| 238 | % |
| 239 | */ |
| 240 | |
| 241 | #if defined(__cplusplus) || defined(c_plusplus) |
| 242 | extern "C" { |
| 243 | #endif |
| 244 | |
| 245 | static size_t PingStream(const Image *magick_unused(image), |
| 246 | const void *magick_unused(pixels),const size_t columns) |
| 247 | { |
| 248 | return(columns); |
| 249 | } |
| 250 | |
| 251 | #if defined(__cplusplus) || defined(c_plusplus) |
| 252 | } |
| 253 | #endif |
| 254 | |
| 255 | MagickExport Image *PingImage(const ImageInfo *image_info, |
| 256 | ExceptionInfo *exception) |
| 257 | { |
| 258 | Image |
| 259 | *image; |
| 260 | |
| 261 | ImageInfo |
| 262 | *ping_info; |
| 263 | |
| 264 | assert(image_info != (ImageInfo *) NULL); |
| 265 | assert(image_info->signature == MagickSignature); |
| 266 | if (image_info->debug != MagickFalse) |
| 267 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 268 | image_info->filename); |
| 269 | assert(exception != (ExceptionInfo *) NULL); |
| 270 | ping_info=CloneImageInfo(image_info); |
| 271 | ping_info->ping=MagickTrue; |
| 272 | image=ReadStream(ping_info,&PingStream,exception); |
| 273 | if (image != (Image *) NULL) |
| 274 | { |
| 275 | ResetTimer(&image->timer); |
| 276 | if (ping_info->verbose != MagickFalse) |
| 277 | (void) IdentifyImage(image,stdout,MagickFalse); |
| 278 | } |
| 279 | ping_info=DestroyImageInfo(ping_info); |
| 280 | return(image); |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 285 | % % |
| 286 | % % |
| 287 | % % |
| 288 | % P i n g I m a g e s % |
| 289 | % % |
| 290 | % % |
| 291 | % % |
| 292 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 293 | % |
| 294 | % PingImages() pings one or more images and returns them as an image list. |
| 295 | % |
| 296 | % The format of the PingImage method is: |
| 297 | % |
| 298 | % Image *PingImages(const ImageInfo *image_info,ExceptionInfo *exception) |
| 299 | % |
| 300 | % A description of each parameter follows: |
| 301 | % |
| 302 | % o image_info: the image info. |
| 303 | % |
| 304 | % o exception: return any errors or warnings in this structure. |
| 305 | % |
| 306 | */ |
| 307 | MagickExport Image *PingImages(const ImageInfo *image_info, |
| 308 | ExceptionInfo *exception) |
| 309 | { |
| 310 | char |
| 311 | filename[MaxTextExtent]; |
| 312 | |
| 313 | Image |
| 314 | *image, |
| 315 | *images; |
| 316 | |
| 317 | ImageInfo |
| 318 | *read_info; |
| 319 | |
| 320 | /* |
| 321 | Ping image list from a file. |
| 322 | */ |
| 323 | assert(image_info != (ImageInfo *) NULL); |
| 324 | assert(image_info->signature == MagickSignature); |
| 325 | if (image_info->debug != MagickFalse) |
| 326 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 327 | image_info->filename); |
| 328 | assert(exception != (ExceptionInfo *) NULL); |
| 329 | (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename, |
| 330 | (int) image_info->scene,filename); |
| 331 | if (LocaleCompare(filename,image_info->filename) != 0) |
| 332 | { |
| 333 | ExceptionInfo |
| 334 | *sans; |
| 335 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 336 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 337 | extent, |
| 338 | scene; |
| 339 | |
| 340 | /* |
| 341 | Images of the form image-%d.png[1-5]. |
| 342 | */ |
| 343 | read_info=CloneImageInfo(image_info); |
| 344 | sans=AcquireExceptionInfo(); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 345 | (void) SetImageInfo(read_info,0,sans); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 346 | sans=DestroyExceptionInfo(sans); |
| 347 | (void) CopyMagickString(filename,read_info->filename,MaxTextExtent); |
| 348 | images=NewImageList(); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 349 | extent=(ssize_t) (read_info->scene+read_info->number_scenes); |
| 350 | for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 351 | { |
| 352 | (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(int) |
| 353 | scene,read_info->filename); |
| 354 | image=PingImage(read_info,exception); |
| 355 | if (image == (Image *) NULL) |
| 356 | continue; |
| 357 | AppendImageToList(&images,image); |
| 358 | } |
| 359 | read_info=DestroyImageInfo(read_info); |
| 360 | return(images); |
| 361 | } |
| 362 | return(PingImage(image_info,exception)); |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 367 | % % |
| 368 | % % |
| 369 | % % |
| 370 | % R e a d I m a g e % |
| 371 | % % |
| 372 | % % |
| 373 | % % |
| 374 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 375 | % |
| 376 | % ReadImage() reads an image or image sequence from a file or file handle. |
| 377 | % The method returns a NULL if there is a memory shortage or if the image |
| 378 | % cannot be read. On failure, a NULL image is returned and exception |
| 379 | % describes the reason for the failure. |
| 380 | % |
| 381 | % The format of the ReadImage method is: |
| 382 | % |
| 383 | % Image *ReadImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 384 | % |
| 385 | % A description of each parameter follows: |
| 386 | % |
| 387 | % o image_info: Read the image defined by the file or filename members of |
| 388 | % this structure. |
| 389 | % |
| 390 | % o exception: return any errors or warnings in this structure. |
| 391 | % |
| 392 | */ |
| 393 | MagickExport Image *ReadImage(const ImageInfo *image_info, |
| 394 | ExceptionInfo *exception) |
| 395 | { |
| 396 | char |
| 397 | filename[MaxTextExtent], |
| 398 | magick[MaxTextExtent], |
| 399 | magick_filename[MaxTextExtent]; |
| 400 | |
| 401 | const char |
| 402 | *value; |
| 403 | |
| 404 | const DelegateInfo |
| 405 | *delegate_info; |
| 406 | |
| 407 | const MagickInfo |
| 408 | *magick_info; |
| 409 | |
| 410 | ExceptionInfo |
| 411 | *sans_exception; |
| 412 | |
| 413 | GeometryInfo |
| 414 | geometry_info; |
| 415 | |
| 416 | Image |
| 417 | *image, |
| 418 | *next; |
| 419 | |
| 420 | ImageInfo |
| 421 | *read_info; |
| 422 | |
| 423 | MagickStatusType |
| 424 | flags, |
| 425 | thread_support; |
| 426 | |
| 427 | PolicyDomain |
| 428 | domain; |
| 429 | |
| 430 | PolicyRights |
| 431 | rights; |
| 432 | |
| 433 | /* |
| 434 | Determine image type from filename prefix or suffix (e.g. image.jpg). |
| 435 | */ |
| 436 | assert(image_info != (ImageInfo *) NULL); |
| 437 | assert(image_info->signature == MagickSignature); |
| 438 | assert(image_info->filename != (char *) NULL); |
| 439 | if (image_info->debug != MagickFalse) |
| 440 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 441 | image_info->filename); |
| 442 | assert(exception != (ExceptionInfo *) NULL); |
| 443 | read_info=CloneImageInfo(image_info); |
| 444 | (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 445 | (void) SetImageInfo(read_info,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 446 | (void) CopyMagickString(filename,read_info->filename,MaxTextExtent); |
| 447 | (void) CopyMagickString(magick,read_info->magick,MaxTextExtent); |
| 448 | domain=CoderPolicyDomain; |
| 449 | rights=ReadPolicyRights; |
| 450 | if (IsRightsAuthorized(domain,rights,read_info->magick) == MagickFalse) |
| 451 | { |
cristy | a9197f6 | 2010-01-12 02:23:34 +0000 | [diff] [blame] | 452 | errno=EPERM; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 453 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
| 454 | "NotAuthorized","`%s'",read_info->filename); |
| 455 | return((Image *) NULL); |
| 456 | } |
| 457 | /* |
| 458 | Call appropriate image reader based on image type. |
| 459 | */ |
| 460 | sans_exception=AcquireExceptionInfo(); |
| 461 | magick_info=GetMagickInfo(read_info->magick,sans_exception); |
| 462 | sans_exception=DestroyExceptionInfo(sans_exception); |
| 463 | if (magick_info != (const MagickInfo *) NULL) |
| 464 | { |
| 465 | if (GetMagickEndianSupport(magick_info) == MagickFalse) |
| 466 | read_info->endian=UndefinedEndian; |
| 467 | else |
| 468 | if ((image_info->endian == UndefinedEndian) && |
| 469 | (GetMagickRawSupport(magick_info) != MagickFalse)) |
| 470 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 471 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 472 | lsb_first; |
| 473 | |
| 474 | lsb_first=1; |
| 475 | read_info->endian=(*(char *) &lsb_first) == 1 ? LSBEndian : |
| 476 | MSBEndian; |
| 477 | } |
| 478 | } |
| 479 | if ((magick_info != (const MagickInfo *) NULL) && |
| 480 | (GetMagickSeekableStream(magick_info) != MagickFalse)) |
| 481 | { |
| 482 | MagickBooleanType |
| 483 | status; |
| 484 | |
| 485 | image=AcquireImage(read_info); |
| 486 | (void) CopyMagickString(image->filename,read_info->filename, |
| 487 | MaxTextExtent); |
| 488 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 489 | if (status == MagickFalse) |
| 490 | { |
| 491 | read_info=DestroyImageInfo(read_info); |
| 492 | image=DestroyImage(image); |
| 493 | return((Image *) NULL); |
| 494 | } |
| 495 | if (IsBlobSeekable(image) == MagickFalse) |
| 496 | { |
| 497 | /* |
| 498 | Coder requires a seekable stream. |
| 499 | */ |
| 500 | *read_info->filename='\0'; |
| 501 | status=ImageToFile(image,read_info->filename,exception); |
| 502 | if (status == MagickFalse) |
| 503 | { |
| 504 | (void) CloseBlob(image); |
| 505 | read_info=DestroyImageInfo(read_info); |
| 506 | image=DestroyImage(image); |
| 507 | return((Image *) NULL); |
| 508 | } |
| 509 | read_info->temporary=MagickTrue; |
| 510 | } |
| 511 | (void) CloseBlob(image); |
| 512 | image=DestroyImage(image); |
| 513 | } |
| 514 | image=NewImageList(); |
cristy | 4e1dff6 | 2009-10-25 20:36:03 +0000 | [diff] [blame] | 515 | if (constitute_semaphore == (SemaphoreInfo *) NULL) |
| 516 | AcquireSemaphoreInfo(&constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 517 | if ((magick_info != (const MagickInfo *) NULL) && |
| 518 | (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL)) |
| 519 | { |
| 520 | thread_support=GetMagickThreadSupport(magick_info); |
| 521 | if ((thread_support & DecoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 522 | LockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 523 | image=GetImageDecoder(magick_info)(read_info,exception); |
| 524 | if ((thread_support & DecoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 525 | UnlockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 526 | } |
| 527 | else |
| 528 | { |
| 529 | delegate_info=GetDelegateInfo(read_info->magick,(char *) NULL,exception); |
| 530 | if (delegate_info == (const DelegateInfo *) NULL) |
| 531 | { |
cristy | 3a7b2b8 | 2010-04-28 22:14:19 +0000 | [diff] [blame] | 532 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 533 | MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'", |
| 534 | read_info->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 535 | if (read_info->temporary != MagickFalse) |
| 536 | (void) RelinquishUniqueFileResource(read_info->filename); |
| 537 | read_info=DestroyImageInfo(read_info); |
| 538 | return((Image *) NULL); |
| 539 | } |
| 540 | /* |
| 541 | Let our decoding delegate process the image. |
| 542 | */ |
| 543 | image=AcquireImage(read_info); |
| 544 | if (image == (Image *) NULL) |
| 545 | { |
| 546 | read_info=DestroyImageInfo(read_info); |
| 547 | return((Image *) NULL); |
| 548 | } |
| 549 | (void) CopyMagickString(image->filename,read_info->filename, |
| 550 | MaxTextExtent); |
| 551 | *read_info->filename='\0'; |
| 552 | if (GetDelegateThreadSupport(delegate_info) == MagickFalse) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 553 | LockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | (void) InvokeDelegate(read_info,image,read_info->magick,(char *) NULL, |
| 555 | exception); |
| 556 | if (GetDelegateThreadSupport(delegate_info) == MagickFalse) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 557 | UnlockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 558 | image=DestroyImageList(image); |
| 559 | read_info->temporary=MagickTrue; |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 560 | (void) SetImageInfo(read_info,0,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 561 | magick_info=GetMagickInfo(read_info->magick,exception); |
| 562 | if ((magick_info == (const MagickInfo *) NULL) || |
| 563 | (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL)) |
| 564 | { |
| 565 | if (IsPathAccessible(read_info->filename) != MagickFalse) |
| 566 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 567 | MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'", |
| 568 | read_info->filename); |
| 569 | else |
| 570 | ThrowFileException(exception,FileOpenError,"UnableToOpenFile", |
| 571 | read_info->filename); |
| 572 | read_info=DestroyImageInfo(read_info); |
| 573 | return((Image *) NULL); |
| 574 | } |
| 575 | thread_support=GetMagickThreadSupport(magick_info); |
| 576 | if ((thread_support & DecoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 577 | LockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 578 | image=(Image *) (GetImageDecoder(magick_info))(read_info,exception); |
| 579 | if ((thread_support & DecoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 580 | UnlockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 581 | } |
| 582 | if (read_info->temporary != MagickFalse) |
| 583 | { |
| 584 | (void) RelinquishUniqueFileResource(read_info->filename); |
| 585 | read_info->temporary=MagickFalse; |
| 586 | if (image != (Image *) NULL) |
| 587 | (void) CopyMagickString(image->filename,filename,MaxTextExtent); |
| 588 | } |
| 589 | if (image == (Image *) NULL) |
| 590 | { |
| 591 | read_info=DestroyImageInfo(read_info); |
| 592 | return(image); |
| 593 | } |
| 594 | if (exception->severity >= ErrorException) |
| 595 | (void) LogMagickEvent(ExceptionEvent,GetMagickModule(), |
| 596 | "Coder (%s) generated an image despite an error (%d), " |
| 597 | "notify the developers",image->magick,exception->severity); |
| 598 | if (IsBlobTemporary(image) != MagickFalse) |
| 599 | (void) RelinquishUniqueFileResource(read_info->filename); |
| 600 | if ((GetNextImageInList(image) != (Image *) NULL) && |
| 601 | (IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse)) |
| 602 | { |
| 603 | Image |
| 604 | *clones; |
| 605 | |
| 606 | clones=CloneImages(image,read_info->scenes,exception); |
| 607 | if (clones == (Image *) NULL) |
| 608 | (void) ThrowMagickException(exception,GetMagickModule(),OptionError, |
| 609 | "SubimageSpecificationReturnsNoImages","`%s'",read_info->filename); |
| 610 | else |
| 611 | { |
| 612 | image=DestroyImageList(image); |
| 613 | image=GetFirstImageInList(clones); |
| 614 | } |
| 615 | } |
| 616 | if (GetBlobError(image) != MagickFalse) |
| 617 | { |
| 618 | ThrowFileException(exception,FileOpenError, |
| 619 | "AnErrorHasOccurredReadingFromFile",read_info->filename); |
| 620 | image=DestroyImageList(image); |
| 621 | read_info=DestroyImageInfo(read_info); |
| 622 | return((Image *) NULL); |
| 623 | } |
| 624 | for (next=image; next != (Image *) NULL; next=GetNextImageInList(next)) |
| 625 | { |
| 626 | char |
cristy | ad126fb | 2011-03-12 14:59:23 +0000 | [diff] [blame] | 627 | magick_path[MaxTextExtent], |
cristy | 7734b60 | 2010-09-13 18:32:30 +0000 | [diff] [blame] | 628 | *property, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 629 | timestamp[MaxTextExtent]; |
| 630 | |
cristy | 05e38ec | 2010-08-20 15:20:12 +0000 | [diff] [blame] | 631 | const char |
| 632 | *option; |
| 633 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 634 | const StringInfo |
| 635 | *profile; |
| 636 | |
| 637 | next->taint=MagickFalse; |
cristy | ad126fb | 2011-03-12 14:59:23 +0000 | [diff] [blame] | 638 | GetPathComponent(magick_filename,MagickPath,magick_path); |
| 639 | if (*magick_path == '\0') |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 640 | (void) CopyMagickString(next->magick,magick,MaxTextExtent); |
| 641 | (void) CopyMagickString(next->magick_filename,magick_filename, |
| 642 | MaxTextExtent); |
| 643 | if (IsBlobTemporary(image) != MagickFalse) |
| 644 | (void) CopyMagickString(next->filename,filename,MaxTextExtent); |
cristy | ad126fb | 2011-03-12 14:59:23 +0000 | [diff] [blame] | 645 | if (next->magick_columns == 0) |
| 646 | next->magick_columns=next->columns; |
| 647 | if (next->magick_rows == 0) |
| 648 | next->magick_rows=next->rows; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 649 | value=GetImageProperty(next,"tiff:Orientation"); |
| 650 | if (value == (char *) NULL) |
| 651 | value=GetImageProperty(next,"exif:Orientation"); |
| 652 | if (value != (char *) NULL) |
| 653 | { |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 654 | next->orientation=(OrientationType) StringToLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 655 | (void) DeleteImageProperty(next,"tiff:Orientation"); |
| 656 | (void) DeleteImageProperty(next,"exif:Orientation"); |
| 657 | } |
cristy | 9a98aa4 | 2010-05-14 16:07:28 +0000 | [diff] [blame] | 658 | value=GetImageProperty(next,"exif:XResolution"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 659 | if (value != (char *) NULL) |
| 660 | { |
| 661 | geometry_info.rho=next->x_resolution; |
| 662 | geometry_info.sigma=1.0; |
| 663 | flags=ParseGeometry(value,&geometry_info); |
| 664 | if (geometry_info.sigma != 0) |
| 665 | next->x_resolution=geometry_info.rho/geometry_info.sigma; |
| 666 | (void) DeleteImageProperty(next,"exif:XResolution"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 667 | } |
cristy | 9a98aa4 | 2010-05-14 16:07:28 +0000 | [diff] [blame] | 668 | value=GetImageProperty(next,"exif:YResolution"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 669 | if (value != (char *) NULL) |
| 670 | { |
| 671 | geometry_info.rho=next->y_resolution; |
| 672 | geometry_info.sigma=1.0; |
| 673 | flags=ParseGeometry(value,&geometry_info); |
| 674 | if (geometry_info.sigma != 0) |
| 675 | next->y_resolution=geometry_info.rho/geometry_info.sigma; |
| 676 | (void) DeleteImageProperty(next,"exif:YResolution"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 677 | } |
| 678 | value=GetImageProperty(next,"tiff:ResolutionUnit"); |
| 679 | if (value == (char *) NULL) |
| 680 | value=GetImageProperty(next,"exif:ResolutionUnit"); |
| 681 | if (value != (char *) NULL) |
| 682 | { |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 683 | next->units=(ResolutionType) (StringToLong(value)-1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 684 | (void) DeleteImageProperty(next,"exif:ResolutionUnit"); |
| 685 | (void) DeleteImageProperty(next,"tiff:ResolutionUnit"); |
| 686 | } |
| 687 | if (next->page.width == 0) |
| 688 | next->page.width=next->columns; |
| 689 | if (next->page.height == 0) |
| 690 | next->page.height=next->rows; |
cristy | 7734b60 | 2010-09-13 18:32:30 +0000 | [diff] [blame] | 691 | option=GetImageOption(read_info,"caption"); |
| 692 | if (option != (const char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 693 | { |
cristy | 7734b60 | 2010-09-13 18:32:30 +0000 | [diff] [blame] | 694 | property=InterpretImageProperties(read_info,next,option); |
| 695 | (void) SetImageProperty(next,"caption",property); |
| 696 | property=DestroyString(property); |
| 697 | } |
| 698 | option=GetImageOption(read_info,"comment"); |
| 699 | if (option != (const char *) NULL) |
| 700 | { |
| 701 | property=InterpretImageProperties(read_info,next,option); |
| 702 | (void) SetImageProperty(next,"comment",property); |
| 703 | property=DestroyString(property); |
| 704 | } |
| 705 | option=GetImageOption(read_info,"label"); |
| 706 | if (option != (const char *) NULL) |
| 707 | { |
| 708 | property=InterpretImageProperties(read_info,next,option); |
| 709 | (void) SetImageProperty(next,"label",property); |
| 710 | property=DestroyString(property); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 711 | } |
| 712 | if (LocaleCompare(next->magick,"TEXT") == 0) |
| 713 | (void) ParseAbsoluteGeometry("0x0+0+0",&next->page); |
| 714 | if ((read_info->extract != (char *) NULL) && |
| 715 | (read_info->stream == (StreamHandler) NULL)) |
| 716 | { |
| 717 | RectangleInfo |
| 718 | geometry; |
| 719 | |
| 720 | flags=ParseAbsoluteGeometry(read_info->extract,&geometry); |
| 721 | if ((next->columns != geometry.width) || |
| 722 | (next->rows != geometry.height)) |
| 723 | { |
| 724 | if (((flags & XValue) != 0) || ((flags & YValue) != 0)) |
| 725 | { |
| 726 | Image |
| 727 | *crop_image; |
| 728 | |
| 729 | crop_image=CropImage(next,&geometry,exception); |
| 730 | if (crop_image != (Image *) NULL) |
| 731 | ReplaceImageInList(&next,crop_image); |
| 732 | } |
| 733 | else |
| 734 | if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) |
| 735 | { |
| 736 | Image |
| 737 | *size_image; |
| 738 | |
| 739 | flags=ParseRegionGeometry(next,read_info->extract,&geometry, |
| 740 | exception); |
| 741 | size_image=ResizeImage(next,geometry.width,geometry.height, |
| 742 | next->filter,next->blur,exception); |
| 743 | if (size_image != (Image *) NULL) |
| 744 | ReplaceImageInList(&next,size_image); |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | profile=GetImageProfile(next,"icc"); |
| 749 | if (profile == (const StringInfo *) NULL) |
| 750 | profile=GetImageProfile(next,"icm"); |
| 751 | if (profile != (const StringInfo *) NULL) |
| 752 | { |
| 753 | next->color_profile.length=GetStringInfoLength(profile); |
| 754 | next->color_profile.info=GetStringInfoDatum(profile); |
| 755 | } |
| 756 | profile=GetImageProfile(next,"iptc"); |
| 757 | if (profile == (const StringInfo *) NULL) |
| 758 | profile=GetImageProfile(next,"8bim"); |
| 759 | if (profile != (const StringInfo *) NULL) |
| 760 | { |
| 761 | next->iptc_profile.length=GetStringInfoLength(profile); |
| 762 | next->iptc_profile.info=GetStringInfoDatum(profile); |
| 763 | } |
| 764 | (void) FormatMagickTime(GetBlobProperties(next)->st_mtime,MaxTextExtent, |
| 765 | timestamp); |
| 766 | (void) SetImageProperty(next,"date:modify",timestamp); |
| 767 | (void) FormatMagickTime(GetBlobProperties(next)->st_ctime,MaxTextExtent, |
| 768 | timestamp); |
| 769 | (void) SetImageProperty(next,"date:create",timestamp); |
cristy | 74f82a6 | 2010-08-19 22:24:53 +0000 | [diff] [blame] | 770 | option=GetImageOption(image_info,"delay"); |
| 771 | if (option != (const char *) NULL) |
| 772 | { |
| 773 | GeometryInfo |
| 774 | geometry_info; |
| 775 | |
| 776 | flags=ParseGeometry(option,&geometry_info); |
| 777 | if ((flags & GreaterValue) != 0) |
| 778 | { |
cristy | 7734b60 | 2010-09-13 18:32:30 +0000 | [diff] [blame] | 779 | if (next->delay > (size_t) floor(geometry_info.rho+0.5)) |
| 780 | next->delay=(size_t) floor(geometry_info.rho+0.5); |
cristy | 74f82a6 | 2010-08-19 22:24:53 +0000 | [diff] [blame] | 781 | } |
| 782 | else |
| 783 | if ((flags & LessValue) != 0) |
| 784 | { |
cristy | 7734b60 | 2010-09-13 18:32:30 +0000 | [diff] [blame] | 785 | if (next->delay < (size_t) floor(geometry_info.rho+0.5)) |
| 786 | next->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); |
cristy | 74f82a6 | 2010-08-19 22:24:53 +0000 | [diff] [blame] | 787 | } |
| 788 | else |
cristy | 7734b60 | 2010-09-13 18:32:30 +0000 | [diff] [blame] | 789 | next->delay=(size_t) floor(geometry_info.rho+0.5); |
cristy | 74f82a6 | 2010-08-19 22:24:53 +0000 | [diff] [blame] | 790 | if ((flags & SigmaValue) != 0) |
cristy | 7734b60 | 2010-09-13 18:32:30 +0000 | [diff] [blame] | 791 | next->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); |
cristy | 74f82a6 | 2010-08-19 22:24:53 +0000 | [diff] [blame] | 792 | } |
| 793 | option=GetImageOption(image_info,"dispose"); |
| 794 | if (option != (const char *) NULL) |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 795 | next->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions, |
cristy | 74f82a6 | 2010-08-19 22:24:53 +0000 | [diff] [blame] | 796 | MagickFalse,option); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 797 | if (read_info->verbose != MagickFalse) |
cristy | 5443963 | 2010-07-15 00:43:34 +0000 | [diff] [blame] | 798 | (void) IdentifyImage(next,stderr,MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 799 | image=next; |
| 800 | } |
| 801 | read_info=DestroyImageInfo(read_info); |
| 802 | return(GetFirstImageInList(image)); |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 807 | % % |
| 808 | % % |
| 809 | % % |
| 810 | % R e a d I m a g e s % |
| 811 | % % |
| 812 | % % |
| 813 | % % |
| 814 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 815 | % |
| 816 | % ReadImages() reads one or more images and returns them as an image list. |
| 817 | % |
| 818 | % The format of the ReadImage method is: |
| 819 | % |
| 820 | % Image *ReadImages(const ImageInfo *image_info,ExceptionInfo *exception) |
| 821 | % |
| 822 | % A description of each parameter follows: |
| 823 | % |
| 824 | % o image_info: the image info. |
| 825 | % |
| 826 | % o exception: return any errors or warnings in this structure. |
| 827 | % |
| 828 | */ |
| 829 | MagickExport Image *ReadImages(const ImageInfo *image_info, |
| 830 | ExceptionInfo *exception) |
| 831 | { |
| 832 | char |
| 833 | filename[MaxTextExtent]; |
| 834 | |
| 835 | Image |
| 836 | *image, |
| 837 | *images; |
| 838 | |
| 839 | ImageInfo |
| 840 | *read_info; |
| 841 | |
| 842 | /* |
| 843 | Read image list from a file. |
| 844 | */ |
| 845 | assert(image_info != (ImageInfo *) NULL); |
| 846 | assert(image_info->signature == MagickSignature); |
| 847 | if (image_info->debug != MagickFalse) |
| 848 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 849 | image_info->filename); |
| 850 | assert(exception != (ExceptionInfo *) NULL); |
| 851 | (void) InterpretImageFilename(image_info,(Image *) NULL,image_info->filename, |
| 852 | (int) image_info->scene,filename); |
| 853 | if (LocaleCompare(filename,image_info->filename) != 0) |
| 854 | { |
| 855 | ExceptionInfo |
| 856 | *sans; |
| 857 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 858 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 859 | extent, |
| 860 | scene; |
| 861 | |
| 862 | /* |
| 863 | Images of the form image-%d.png[1-5]. |
| 864 | */ |
| 865 | read_info=CloneImageInfo(image_info); |
| 866 | sans=AcquireExceptionInfo(); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 867 | (void) SetImageInfo(read_info,0,sans); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 868 | sans=DestroyExceptionInfo(sans); |
| 869 | (void) CopyMagickString(filename,read_info->filename,MaxTextExtent); |
| 870 | images=NewImageList(); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 871 | extent=(ssize_t) (read_info->scene+read_info->number_scenes); |
| 872 | for (scene=(ssize_t) read_info->scene; scene < (ssize_t) extent; scene++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 873 | { |
| 874 | (void) InterpretImageFilename(image_info,(Image *) NULL,filename,(int) |
| 875 | scene,read_info->filename); |
| 876 | image=ReadImage(read_info,exception); |
| 877 | if (image == (Image *) NULL) |
| 878 | continue; |
| 879 | AppendImageToList(&images,image); |
| 880 | } |
| 881 | read_info=DestroyImageInfo(read_info); |
| 882 | return(images); |
| 883 | } |
| 884 | return(ReadImage(image_info,exception)); |
| 885 | } |
| 886 | |
| 887 | /* |
| 888 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 889 | % % |
| 890 | % % |
| 891 | % % |
| 892 | + R e a d I n l i n e I m a g e % |
| 893 | % % |
| 894 | % % |
| 895 | % % |
| 896 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 897 | % |
| 898 | % ReadInlineImage() reads a Base64-encoded inline image or image sequence. |
| 899 | % The method returns a NULL if there is a memory shortage or if the image |
| 900 | % cannot be read. On failure, a NULL image is returned and exception |
| 901 | % describes the reason for the failure. |
| 902 | % |
| 903 | % The format of the ReadInlineImage method is: |
| 904 | % |
| 905 | % Image *ReadInlineImage(const ImageInfo *image_info,const char *content, |
| 906 | % ExceptionInfo *exception) |
| 907 | % |
| 908 | % A description of each parameter follows: |
| 909 | % |
| 910 | % o image_info: the image info. |
| 911 | % |
| 912 | % o content: the image encoded in Base64. |
| 913 | % |
| 914 | % o exception: return any errors or warnings in this structure. |
| 915 | % |
| 916 | */ |
| 917 | MagickExport Image *ReadInlineImage(const ImageInfo *image_info, |
| 918 | const char *content,ExceptionInfo *exception) |
| 919 | { |
| 920 | Image |
| 921 | *image; |
| 922 | |
| 923 | ImageInfo |
| 924 | *read_info; |
| 925 | |
| 926 | unsigned char |
| 927 | *blob; |
| 928 | |
| 929 | size_t |
| 930 | length; |
| 931 | |
| 932 | register const char |
| 933 | *p; |
| 934 | |
cristy | d5562a9 | 2010-06-05 13:43:49 +0000 | [diff] [blame] | 935 | /* |
| 936 | Skip over header (e.g. data:image/gif;base64,). |
| 937 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 938 | image=NewImageList(); |
| 939 | for (p=content; (*p != ',') && (*p != '\0'); p++) ; |
| 940 | if (*p == '\0') |
| 941 | ThrowReaderException(CorruptImageError,"CorruptImage"); |
| 942 | p++; |
| 943 | length=0; |
| 944 | blob=Base64Decode(p,&length); |
| 945 | if (length == 0) |
| 946 | ThrowReaderException(CorruptImageError,"CorruptImage"); |
| 947 | read_info=CloneImageInfo(image_info); |
| 948 | (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL, |
| 949 | (void *) NULL); |
cristy | cc1fc8a | 2010-06-05 13:35:05 +0000 | [diff] [blame] | 950 | *read_info->filename='\0'; |
| 951 | *read_info->magick='\0'; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 952 | image=BlobToImage(read_info,blob,length,exception); |
| 953 | blob=(unsigned char *) RelinquishMagickMemory(blob); |
| 954 | read_info=DestroyImageInfo(read_info); |
| 955 | return(image); |
| 956 | } |
| 957 | |
| 958 | /* |
| 959 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 960 | % % |
| 961 | % % |
| 962 | % % |
| 963 | % W r i t e I m a g e % |
| 964 | % % |
| 965 | % % |
| 966 | % % |
| 967 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 968 | % |
cristy | 96581e8 | 2011-02-01 01:10:11 +0000 | [diff] [blame] | 969 | % WriteImage() writes an image or an image sequence to a file or file handle. |
| 970 | % If writing to a file is on disk, the name is defined by the filename member |
| 971 | % of the image structure. WriteImage() returns MagickFalse is there is a |
| 972 | % memory shortage or if the image cannot be written. Check the exception |
| 973 | % member of image to determine the cause for any failure. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 974 | % |
| 975 | % The format of the WriteImage method is: |
| 976 | % |
| 977 | % MagickBooleanType WriteImage(const ImageInfo *image_info,Image *image) |
| 978 | % |
| 979 | % A description of each parameter follows: |
| 980 | % |
| 981 | % o image_info: the image info. |
| 982 | % |
| 983 | % o image: the image. |
| 984 | % |
| 985 | */ |
| 986 | MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info, |
| 987 | Image *image) |
| 988 | { |
| 989 | char |
| 990 | filename[MaxTextExtent]; |
| 991 | |
cristy | 4c49134 | 2009-11-02 01:46:10 +0000 | [diff] [blame] | 992 | const char |
| 993 | *option; |
| 994 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 995 | const DelegateInfo |
| 996 | *delegate_info; |
| 997 | |
| 998 | const MagickInfo |
| 999 | *magick_info; |
| 1000 | |
| 1001 | ExceptionInfo |
| 1002 | *sans_exception; |
| 1003 | |
| 1004 | ImageInfo |
| 1005 | *write_info; |
| 1006 | |
| 1007 | MagickBooleanType |
| 1008 | status, |
| 1009 | temporary; |
| 1010 | |
| 1011 | MagickStatusType |
| 1012 | thread_support; |
| 1013 | |
| 1014 | PolicyDomain |
| 1015 | domain; |
| 1016 | |
| 1017 | PolicyRights |
| 1018 | rights; |
| 1019 | |
| 1020 | /* |
| 1021 | Determine image type from filename prefix or suffix (e.g. image.jpg). |
| 1022 | */ |
| 1023 | assert(image_info != (ImageInfo *) NULL); |
| 1024 | assert(image_info->signature == MagickSignature); |
| 1025 | if (image->debug != MagickFalse) |
| 1026 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 1027 | image_info->filename); |
| 1028 | assert(image != (Image *) NULL); |
| 1029 | assert(image->signature == MagickSignature); |
| 1030 | sans_exception=AcquireExceptionInfo(); |
| 1031 | write_info=CloneImageInfo(image_info); |
| 1032 | (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent); |
| 1033 | if (*write_info->magick == '\0') |
| 1034 | (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 1035 | (void) SetImageInfo(write_info,1,sans_exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1036 | if (LocaleCompare(write_info->magick,"clipmask") == 0) |
| 1037 | { |
| 1038 | if (image->clip_mask == (Image *) NULL) |
| 1039 | { |
| 1040 | (void) ThrowMagickException(&image->exception,GetMagickModule(), |
| 1041 | OptionError,"NoClipPathDefined","`%s'",image->filename); |
| 1042 | return(MagickFalse); |
| 1043 | } |
| 1044 | image=image->clip_mask; |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 1045 | (void) SetImageInfo(write_info,1,sans_exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1046 | } |
| 1047 | (void) CopyMagickString(filename,image->filename,MaxTextExtent); |
| 1048 | (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent); |
| 1049 | domain=CoderPolicyDomain; |
| 1050 | rights=WritePolicyRights; |
| 1051 | if (IsRightsAuthorized(domain,rights,write_info->magick) == MagickFalse) |
| 1052 | { |
| 1053 | sans_exception=DestroyExceptionInfo(sans_exception); |
cristy | a9197f6 | 2010-01-12 02:23:34 +0000 | [diff] [blame] | 1054 | errno=EPERM; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1055 | ThrowBinaryException(PolicyError,"NotAuthorized",filename); |
| 1056 | } |
| 1057 | magick_info=GetMagickInfo(write_info->magick,sans_exception); |
| 1058 | sans_exception=DestroyExceptionInfo(sans_exception); |
| 1059 | if (magick_info != (const MagickInfo *) NULL) |
| 1060 | { |
| 1061 | if (GetMagickEndianSupport(magick_info) == MagickFalse) |
| 1062 | image->endian=UndefinedEndian; |
| 1063 | else |
| 1064 | if ((image_info->endian == UndefinedEndian) && |
| 1065 | (GetMagickRawSupport(magick_info) != MagickFalse)) |
| 1066 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1067 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1068 | lsb_first; |
| 1069 | |
| 1070 | lsb_first=1; |
| 1071 | image->endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian; |
| 1072 | } |
| 1073 | } |
| 1074 | (void) SyncImageProfiles(image); |
cristy | 4c49134 | 2009-11-02 01:46:10 +0000 | [diff] [blame] | 1075 | option=GetImageOption(image_info,"delegate:bimodal"); |
cristy | 91c0925 | 2011-02-14 00:00:33 +0000 | [diff] [blame] | 1076 | if ((option != (const char *) NULL) && |
cristy | 4c49134 | 2009-11-02 01:46:10 +0000 | [diff] [blame] | 1077 | (IsMagickTrue(option) != MagickFalse) && |
| 1078 | (write_info->page == (char *) NULL) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1079 | (GetPreviousImageInList(image) == (Image *) NULL) && |
| 1080 | (GetNextImageInList(image) == (Image *) NULL) && |
| 1081 | (IsTaintImage(image) == MagickFalse)) |
| 1082 | { |
| 1083 | delegate_info=GetDelegateInfo(image->magick,write_info->magick, |
| 1084 | &image->exception); |
| 1085 | if ((delegate_info != (const DelegateInfo *) NULL) && |
| 1086 | (GetDelegateMode(delegate_info) == 0) && |
| 1087 | (IsPathAccessible(image->magick_filename) != MagickFalse)) |
| 1088 | { |
| 1089 | /* |
| 1090 | Process image with bi-modal delegate. |
| 1091 | */ |
| 1092 | (void) CopyMagickString(image->filename,image->magick_filename, |
| 1093 | MaxTextExtent); |
| 1094 | status=InvokeDelegate(write_info,image,image->magick, |
| 1095 | write_info->magick,&image->exception); |
| 1096 | write_info=DestroyImageInfo(write_info); |
| 1097 | (void) CopyMagickString(image->filename,filename,MaxTextExtent); |
| 1098 | return(status); |
| 1099 | } |
| 1100 | } |
| 1101 | status=MagickFalse; |
| 1102 | temporary=MagickFalse; |
| 1103 | if ((magick_info != (const MagickInfo *) NULL) && |
| 1104 | (GetMagickSeekableStream(magick_info) != MagickFalse)) |
| 1105 | { |
| 1106 | char |
| 1107 | filename[MaxTextExtent]; |
| 1108 | |
| 1109 | (void) CopyMagickString(filename,image->filename,MaxTextExtent); |
| 1110 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,&image->exception); |
| 1111 | (void) CopyMagickString(image->filename,filename,MaxTextExtent); |
| 1112 | if (status != MagickFalse) |
| 1113 | { |
cristy | e92a6fd | 2010-02-04 01:36:45 +0000 | [diff] [blame] | 1114 | if (IsBlobSeekable(image) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1115 | { |
| 1116 | /* |
| 1117 | A seekable stream is required by the encoder. |
| 1118 | */ |
cristy | 5443963 | 2010-07-15 00:43:34 +0000 | [diff] [blame] | 1119 | write_info->adjoin=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1120 | (void) CopyMagickString(write_info->filename,image->filename, |
| 1121 | MaxTextExtent); |
| 1122 | (void) AcquireUniqueFilename(image->filename); |
| 1123 | temporary=MagickTrue; |
| 1124 | } |
| 1125 | (void) CloseBlob(image); |
| 1126 | } |
| 1127 | } |
cristy | 4e1dff6 | 2009-10-25 20:36:03 +0000 | [diff] [blame] | 1128 | if (constitute_semaphore == (SemaphoreInfo *) NULL) |
| 1129 | AcquireSemaphoreInfo(&constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1130 | if ((magick_info != (const MagickInfo *) NULL) && |
| 1131 | (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL)) |
| 1132 | { |
| 1133 | /* |
| 1134 | Call appropriate image writer based on image type. |
| 1135 | */ |
| 1136 | thread_support=GetMagickThreadSupport(magick_info); |
| 1137 | if ((thread_support & EncoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1138 | LockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1139 | status=GetImageEncoder(magick_info)(write_info,image); |
| 1140 | if ((thread_support & EncoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1141 | UnlockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1142 | } |
| 1143 | else |
| 1144 | { |
| 1145 | delegate_info=GetDelegateInfo((char *) NULL,write_info->magick, |
| 1146 | &image->exception); |
| 1147 | if (delegate_info != (DelegateInfo *) NULL) |
| 1148 | { |
| 1149 | /* |
| 1150 | Process the image with delegate. |
| 1151 | */ |
| 1152 | *write_info->filename='\0'; |
| 1153 | if (GetDelegateThreadSupport(delegate_info) == MagickFalse) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1154 | LockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1155 | status=InvokeDelegate(write_info,image,(char *) NULL, |
| 1156 | write_info->magick,&image->exception); |
| 1157 | if (GetDelegateThreadSupport(delegate_info) == MagickFalse) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1158 | UnlockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1159 | (void) CopyMagickString(image->filename,filename,MaxTextExtent); |
| 1160 | } |
| 1161 | else |
| 1162 | { |
| 1163 | sans_exception=AcquireExceptionInfo(); |
| 1164 | magick_info=GetMagickInfo(write_info->magick,sans_exception); |
| 1165 | sans_exception=DestroyExceptionInfo(sans_exception); |
| 1166 | if ((write_info->affirm == MagickFalse) && |
| 1167 | (magick_info == (const MagickInfo *) NULL)) |
| 1168 | { |
| 1169 | (void) CopyMagickString(write_info->magick,image->magick, |
| 1170 | MaxTextExtent); |
| 1171 | magick_info=GetMagickInfo(write_info->magick,&image->exception); |
| 1172 | } |
| 1173 | if ((magick_info == (const MagickInfo *) NULL) || |
| 1174 | (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL)) |
cristy | 1a8fced | 2010-03-15 18:05:43 +0000 | [diff] [blame] | 1175 | { |
cristy | 91c0925 | 2011-02-14 00:00:33 +0000 | [diff] [blame] | 1176 | char |
| 1177 | extension[MaxTextExtent]; |
| 1178 | |
| 1179 | GetPathComponent(image->filename,ExtensionPath,extension); |
| 1180 | if (*extension != '\0') |
| 1181 | magick_info=GetMagickInfo(extension,&image->exception); |
| 1182 | else |
| 1183 | magick_info=GetMagickInfo(image->magick,&image->exception); |
cristy | 1a8fced | 2010-03-15 18:05:43 +0000 | [diff] [blame] | 1184 | (void) CopyMagickString(image->filename,filename,MaxTextExtent); |
cristy | 924c872 | 2010-03-15 17:50:24 +0000 | [diff] [blame] | 1185 | } |
cristy | 1a8fced | 2010-03-15 18:05:43 +0000 | [diff] [blame] | 1186 | if ((magick_info == (const MagickInfo *) NULL) || |
| 1187 | (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL)) |
| 1188 | (void) ThrowMagickException(&image->exception,GetMagickModule(), |
| 1189 | MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'", |
| 1190 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1191 | else |
| 1192 | { |
| 1193 | /* |
| 1194 | Call appropriate image writer based on image type. |
| 1195 | */ |
| 1196 | thread_support=GetMagickThreadSupport(magick_info); |
| 1197 | if ((thread_support & EncoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1198 | LockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1199 | status=GetImageEncoder(magick_info)(write_info,image); |
| 1200 | if ((thread_support & EncoderThreadSupport) == 0) |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1201 | UnlockSemaphoreInfo(constitute_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1202 | } |
| 1203 | } |
| 1204 | } |
| 1205 | if (GetBlobError(image) != MagickFalse) |
| 1206 | ThrowFileException(&image->exception,FileOpenError, |
| 1207 | "AnErrorHasOccurredWritingToFile",image->filename); |
| 1208 | if (temporary == MagickTrue) |
| 1209 | { |
| 1210 | /* |
| 1211 | Copy temporary image file to permanent. |
| 1212 | */ |
| 1213 | status=OpenBlob(write_info,image,ReadBinaryBlobMode,&image->exception); |
| 1214 | if (status != MagickFalse) |
| 1215 | status=ImageToFile(image,write_info->filename,&image->exception); |
cristy | a890294 | 2010-07-30 00:49:52 +0000 | [diff] [blame] | 1216 | (void) CloseBlob(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1217 | (void) RelinquishUniqueFileResource(image->filename); |
| 1218 | (void) CopyMagickString(image->filename,write_info->filename, |
| 1219 | MaxTextExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | } |
| 1221 | if ((LocaleCompare(write_info->magick,"info") != 0) && |
| 1222 | (write_info->verbose != MagickFalse)) |
| 1223 | (void) IdentifyImage(image,stdout,MagickFalse); |
| 1224 | write_info=DestroyImageInfo(write_info); |
| 1225 | return(status); |
| 1226 | } |
| 1227 | |
| 1228 | /* |
| 1229 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1230 | % % |
| 1231 | % % |
| 1232 | % % |
| 1233 | % W r i t e I m a g e s % |
| 1234 | % % |
| 1235 | % % |
| 1236 | % % |
| 1237 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1238 | % |
cristy | 96581e8 | 2011-02-01 01:10:11 +0000 | [diff] [blame] | 1239 | % WriteImages() writes an image sequence into one or more files. While |
| 1240 | % WriteImage() can write an image sequence, it is limited to writing |
| 1241 | % the sequence into a single file using a format which supports multiple |
| 1242 | % frames. WriteImages(), however, does not have this limitation, instead it |
| 1243 | % generates multiple output files if necessary (or when requested). When |
| 1244 | % ImageInfo's adjoin flag is set to MagickFalse, the file name is expected |
| 1245 | % to include a printf-style formatting string for the frame number (e.g. |
| 1246 | % "image%02d.png"). |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1247 | % |
| 1248 | % The format of the WriteImages method is: |
| 1249 | % |
| 1250 | % MagickBooleanType WriteImages(const ImageInfo *image_info,Image *images, |
| 1251 | % const char *filename,ExceptionInfo *exception) |
| 1252 | % |
| 1253 | % A description of each parameter follows: |
| 1254 | % |
| 1255 | % o image_info: the image info. |
| 1256 | % |
| 1257 | % o images: the image list. |
| 1258 | % |
| 1259 | % o filename: the image filename. |
| 1260 | % |
| 1261 | % o exception: return any errors or warnings in this structure. |
| 1262 | % |
| 1263 | */ |
| 1264 | MagickExport MagickBooleanType WriteImages(const ImageInfo *image_info, |
| 1265 | Image *images,const char *filename,ExceptionInfo *exception) |
| 1266 | { |
cristy | 36507e6 | 2010-02-11 00:26:48 +0000 | [diff] [blame] | 1267 | #define WriteImageTag "Write/Image" |
| 1268 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1269 | BlobInfo |
| 1270 | *blob; |
| 1271 | |
| 1272 | ExceptionInfo |
| 1273 | *sans_exception; |
| 1274 | |
| 1275 | ImageInfo |
| 1276 | *write_info; |
| 1277 | |
cristy | 36507e6 | 2010-02-11 00:26:48 +0000 | [diff] [blame] | 1278 | MagickBooleanType |
| 1279 | proceed; |
| 1280 | |
| 1281 | MagickOffsetType |
| 1282 | i; |
| 1283 | |
| 1284 | MagickProgressMonitor |
| 1285 | progress_monitor; |
| 1286 | |
| 1287 | MagickSizeType |
| 1288 | number_images; |
| 1289 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1290 | MagickStatusType |
| 1291 | status; |
| 1292 | |
| 1293 | register Image |
| 1294 | *p; |
| 1295 | |
| 1296 | assert(image_info != (const ImageInfo *) NULL); |
| 1297 | assert(image_info->signature == MagickSignature); |
| 1298 | assert(images != (Image *) NULL); |
| 1299 | assert(images->signature == MagickSignature); |
| 1300 | if (images->debug != MagickFalse) |
| 1301 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename); |
| 1302 | assert(exception != (ExceptionInfo *) NULL); |
| 1303 | write_info=CloneImageInfo(image_info); |
| 1304 | images=GetFirstImageInList(images); |
| 1305 | blob=CloneBlobInfo(images->blob); /* thread specific I/O handler */ |
| 1306 | DestroyBlob(images); |
| 1307 | images->blob=blob; |
| 1308 | if (filename != (const char *) NULL) |
| 1309 | for (p=images; p != (Image *) NULL; p=GetNextImageInList(p)) |
| 1310 | (void) CopyMagickString(p->filename,filename,MaxTextExtent); |
| 1311 | (void) CopyMagickString(write_info->filename,images->filename,MaxTextExtent); |
| 1312 | if (*write_info->magick == '\0') |
| 1313 | (void) CopyMagickString(write_info->magick,images->magick,MaxTextExtent); |
| 1314 | sans_exception=AcquireExceptionInfo(); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 1315 | (void) SetImageInfo(write_info,(unsigned int) GetImageListLength(images), |
| 1316 | sans_exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1317 | sans_exception=DestroyExceptionInfo(sans_exception); |
| 1318 | p=images; |
| 1319 | for ( ; GetNextImageInList(p) != (Image *) NULL; p=GetNextImageInList(p)) |
| 1320 | if (p->scene >= GetNextImageInList(p)->scene) |
| 1321 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1322 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1323 | i; |
| 1324 | |
| 1325 | /* |
| 1326 | Generate consistent scene numbers. |
| 1327 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1328 | i=(ssize_t) images->scene; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1329 | for (p=images; p != (Image *) NULL; p=GetNextImageInList(p)) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1330 | p->scene=(size_t) i++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1331 | break; |
| 1332 | } |
| 1333 | /* |
| 1334 | Write images. |
| 1335 | */ |
| 1336 | status=MagickTrue; |
cristy | 466802f | 2010-02-24 14:18:37 +0000 | [diff] [blame] | 1337 | progress_monitor=(MagickProgressMonitor) NULL; |
cristy | 36507e6 | 2010-02-11 00:26:48 +0000 | [diff] [blame] | 1338 | i=0; |
| 1339 | number_images=GetImageListLength(images); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1340 | for (p=images; p != (Image *) NULL; p=GetNextImageInList(p)) |
| 1341 | { |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 1342 | if (number_images != 1) |
| 1343 | progress_monitor=SetImageProgressMonitor(p,(MagickProgressMonitor) NULL, |
| 1344 | p->client_data); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1345 | status&=WriteImage(write_info,p); |
| 1346 | GetImageException(p,exception); |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 1347 | if (number_images != 1) |
| 1348 | (void) SetImageProgressMonitor(p,progress_monitor,p->client_data); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1349 | if (write_info->adjoin != MagickFalse) |
| 1350 | break; |
cristy | 8b27a6d | 2010-02-14 03:31:15 +0000 | [diff] [blame] | 1351 | if (number_images != 1) |
| 1352 | { |
| 1353 | proceed=SetImageProgress(p,WriteImageTag,i++,number_images); |
| 1354 | if (proceed == MagickFalse) |
| 1355 | break; |
| 1356 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1357 | } |
| 1358 | write_info=DestroyImageInfo(write_info); |
| 1359 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1360 | } |