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