cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % PPPP N N M M % |
| 7 | % P P NN N MM MM % |
| 8 | % PPPP N N N M M M % |
| 9 | % P N NN M M % |
| 10 | % P N N M M % |
| 11 | % % |
| 12 | % % |
| 13 | % Read/Write PBMPlus Portable Anymap Image Format % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | fe676ee | 2013-11-18 13:03:38 +0000 | [diff] [blame] | 20 | % Copyright 1999-2014 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" |
| 43 | #include "MagickCore/attribute.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/blob-private.h" |
| 46 | #include "MagickCore/cache.h" |
| 47 | #include "MagickCore/color.h" |
| 48 | #include "MagickCore/color-private.h" |
| 49 | #include "MagickCore/colorspace.h" |
cristy | 510d06a | 2011-07-06 23:43:54 +0000 | [diff] [blame] | 50 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 51 | #include "MagickCore/exception.h" |
| 52 | #include "MagickCore/exception-private.h" |
| 53 | #include "MagickCore/image.h" |
| 54 | #include "MagickCore/image-private.h" |
| 55 | #include "MagickCore/list.h" |
| 56 | #include "MagickCore/magick.h" |
| 57 | #include "MagickCore/memory_.h" |
| 58 | #include "MagickCore/module.h" |
| 59 | #include "MagickCore/monitor.h" |
| 60 | #include "MagickCore/monitor-private.h" |
| 61 | #include "MagickCore/pixel-accessor.h" |
| 62 | #include "MagickCore/property.h" |
| 63 | #include "MagickCore/quantum-private.h" |
| 64 | #include "MagickCore/static.h" |
| 65 | #include "MagickCore/statistic.h" |
| 66 | #include "MagickCore/string_.h" |
| 67 | #include "MagickCore/string-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 68 | |
| 69 | /* |
| 70 | Forward declarations. |
| 71 | */ |
| 72 | static MagickBooleanType |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 73 | WritePNMImage(const ImageInfo *,Image *,ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 77 | % % |
| 78 | % % |
| 79 | % % |
| 80 | % I s P N M % |
| 81 | % % |
| 82 | % % |
| 83 | % % |
| 84 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 85 | % |
| 86 | % IsPNM() returns MagickTrue if the image format type, identified by the |
| 87 | % magick string, is PNM. |
| 88 | % |
| 89 | % The format of the IsPNM method is: |
| 90 | % |
| 91 | % MagickBooleanType IsPNM(const unsigned char *magick,const size_t extent) |
| 92 | % |
| 93 | % A description of each parameter follows: |
| 94 | % |
| 95 | % o magick: compare image format pattern against these bytes. |
| 96 | % |
| 97 | % o extent: Specifies the extent of the magick string. |
| 98 | % |
| 99 | */ |
| 100 | static MagickBooleanType IsPNM(const unsigned char *magick,const size_t extent) |
| 101 | { |
| 102 | if (extent < 2) |
| 103 | return(MagickFalse); |
| 104 | if ((*magick == (unsigned char) 'P') && |
| 105 | ((magick[1] == '1') || (magick[1] == '2') || (magick[1] == '3') || |
| 106 | (magick[1] == '4') || (magick[1] == '5') || (magick[1] == '6') || |
| 107 | (magick[1] == '7') || (magick[1] == 'F') || (magick[1] == 'f'))) |
| 108 | return(MagickTrue); |
| 109 | return(MagickFalse); |
| 110 | } |
| 111 | |
| 112 | /* |
| 113 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 114 | % % |
| 115 | % % |
| 116 | % % |
| 117 | % R e a d P N M I m a g e % |
| 118 | % % |
| 119 | % % |
| 120 | % % |
| 121 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 122 | % |
| 123 | % ReadPNMImage() reads a Portable Anymap image file and returns it. |
| 124 | % It allocates the memory necessary for the new Image structure and returns |
| 125 | % a pointer to the new image. |
| 126 | % |
| 127 | % The format of the ReadPNMImage method is: |
| 128 | % |
| 129 | % Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 130 | % |
| 131 | % A description of each parameter follows: |
| 132 | % |
| 133 | % o image_info: the image info. |
| 134 | % |
| 135 | % o exception: return any errors or warnings in this structure. |
| 136 | % |
| 137 | */ |
| 138 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 139 | static inline ssize_t ConstrainPixel(Image *image,const ssize_t offset, |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 140 | const size_t extent,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 142 | if ((offset < 0) || (offset > (ssize_t) extent)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 143 | { |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 144 | (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError, |
| 145 | "InvalidPixel","`%s'",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 146 | return(0); |
| 147 | } |
| 148 | return(offset); |
| 149 | } |
| 150 | |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 151 | static void PNMComment(Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 152 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 153 | int |
| 154 | c; |
| 155 | |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 156 | char |
| 157 | *comment; |
| 158 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | register char |
| 160 | *p; |
| 161 | |
| 162 | size_t |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 163 | extent; |
| 164 | |
| 165 | /* |
| 166 | Read comment. |
| 167 | */ |
| 168 | comment=AcquireString(GetImageProperty(image,"comment",exception)); |
| 169 | extent=strlen(comment); |
| 170 | p=comment+strlen(comment); |
| 171 | for (c='#'; (c != EOF) && (c != (int) '\n'); p++) |
| 172 | { |
| 173 | if ((size_t) (p-comment+1) >= extent) |
| 174 | { |
| 175 | extent<<=1; |
| 176 | comment=(char *) ResizeQuantumMemory(comment,extent+MaxTextExtent, |
| 177 | sizeof(*comment)); |
| 178 | if (comment == (char *) NULL) |
| 179 | break; |
| 180 | p=comment+strlen(comment); |
| 181 | } |
| 182 | c=ReadBlobByte(image); |
| 183 | if (c != EOF) |
| 184 | { |
| 185 | *p=(char) c; |
| 186 | *(p+1)='\0'; |
| 187 | } |
| 188 | } |
| 189 | if (comment == (char *) NULL) |
| 190 | return; |
| 191 | (void) SetImageProperty(image,"comment",comment,exception); |
| 192 | comment=DestroyString(comment); |
| 193 | } |
| 194 | |
| 195 | static size_t PNMInteger(Image *image,const unsigned int base, |
| 196 | ExceptionInfo *exception) |
| 197 | { |
| 198 | int |
| 199 | c; |
| 200 | |
| 201 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 202 | value; |
| 203 | |
| 204 | /* |
| 205 | Skip any leading whitespace. |
| 206 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 207 | do |
| 208 | { |
| 209 | c=ReadBlobByte(image); |
| 210 | if (c == EOF) |
| 211 | return(0); |
| 212 | if (c == (int) '#') |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 213 | PNMComment(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 214 | } while (isdigit(c) == MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 215 | if (base == 2) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 216 | return((size_t) (c-(int) '0')); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 217 | /* |
| 218 | Evaluate number. |
| 219 | */ |
| 220 | value=0; |
| 221 | do |
| 222 | { |
| 223 | value*=10; |
| 224 | value+=c-(int) '0'; |
| 225 | c=ReadBlobByte(image); |
| 226 | if (c == EOF) |
| 227 | return(value); |
| 228 | } while (isdigit(c) != MagickFalse); |
| 229 | return(value); |
| 230 | } |
| 231 | |
| 232 | static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) |
| 233 | { |
| 234 | char |
| 235 | format; |
| 236 | |
| 237 | double |
| 238 | quantum_scale; |
| 239 | |
| 240 | Image |
| 241 | *image; |
| 242 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 243 | MagickBooleanType |
| 244 | status; |
| 245 | |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 246 | QuantumAny |
| 247 | max_value; |
| 248 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 249 | QuantumInfo |
| 250 | *quantum_info; |
| 251 | |
| 252 | QuantumType |
| 253 | quantum_type; |
| 254 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 255 | size_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 256 | depth, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | extent, |
| 258 | packet_size; |
| 259 | |
| 260 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 261 | count, |
| 262 | row, |
| 263 | y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 265 | /* |
| 266 | Open image file. |
| 267 | */ |
| 268 | assert(image_info != (const ImageInfo *) NULL); |
| 269 | assert(image_info->signature == MagickSignature); |
| 270 | if (image_info->debug != MagickFalse) |
| 271 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 272 | image_info->filename); |
| 273 | assert(exception != (ExceptionInfo *) NULL); |
| 274 | assert(exception->signature == MagickSignature); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 275 | image=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 276 | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
| 277 | if (status == MagickFalse) |
| 278 | { |
| 279 | image=DestroyImageList(image); |
| 280 | return((Image *) NULL); |
| 281 | } |
| 282 | /* |
| 283 | Read PNM image. |
| 284 | */ |
| 285 | count=ReadBlob(image,1,(unsigned char *) &format); |
| 286 | do |
| 287 | { |
| 288 | /* |
| 289 | Initialize image structure. |
| 290 | */ |
| 291 | if ((count != 1) || (format != 'P')) |
| 292 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 293 | max_value=1; |
| 294 | quantum_type=RGBQuantum; |
| 295 | quantum_scale=1.0; |
| 296 | format=(char) ReadBlobByte(image); |
| 297 | if (format != '7') |
| 298 | { |
| 299 | /* |
| 300 | PBM, PGM, PPM, and PNM. |
| 301 | */ |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 302 | image->columns=PNMInteger(image,10,exception); |
| 303 | image->rows=PNMInteger(image,10,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 304 | if ((format == 'f') || (format == 'F')) |
| 305 | { |
| 306 | char |
| 307 | scale[MaxTextExtent]; |
| 308 | |
| 309 | (void) ReadBlobString(image,scale); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 310 | quantum_scale=StringToDouble(scale,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | } |
| 312 | else |
| 313 | { |
| 314 | if ((format == '1') || (format == '4')) |
| 315 | max_value=1; /* bitmap */ |
| 316 | else |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 317 | max_value=PNMInteger(image,10,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | else |
| 321 | { |
| 322 | char |
| 323 | keyword[MaxTextExtent], |
| 324 | value[MaxTextExtent]; |
| 325 | |
| 326 | int |
| 327 | c; |
| 328 | |
| 329 | register char |
| 330 | *p; |
| 331 | |
| 332 | /* |
| 333 | PAM. |
| 334 | */ |
| 335 | for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image)) |
| 336 | { |
| 337 | while (isspace((int) ((unsigned char) c)) != 0) |
| 338 | c=ReadBlobByte(image); |
cristy | a4068ab | 2013-05-19 11:51:07 +0000 | [diff] [blame] | 339 | if (c == '#') |
| 340 | { |
| 341 | /* |
| 342 | Comment. |
| 343 | */ |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 344 | PNMComment(image,exception); |
| 345 | c=ReadBlobByte(image); |
cristy | a4068ab | 2013-05-19 11:51:07 +0000 | [diff] [blame] | 346 | while (isspace((int) ((unsigned char) c)) != 0) |
| 347 | c=ReadBlobByte(image); |
| 348 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 349 | p=keyword; |
| 350 | do |
| 351 | { |
| 352 | if ((size_t) (p-keyword) < (MaxTextExtent-1)) |
| 353 | *p++=c; |
| 354 | c=ReadBlobByte(image); |
| 355 | } while (isalnum(c)); |
| 356 | *p='\0'; |
| 357 | if (LocaleCompare(keyword,"endhdr") == 0) |
| 358 | break; |
| 359 | while (isspace((int) ((unsigned char) c)) != 0) |
cristy | 4e285b9 | 2013-05-24 17:42:57 +0000 | [diff] [blame] | 360 | c=ReadBlobByte(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 361 | p=value; |
| 362 | while (isalnum(c) || (c == '_')) |
| 363 | { |
| 364 | if ((size_t) (p-value) < (MaxTextExtent-1)) |
| 365 | *p++=c; |
| 366 | c=ReadBlobByte(image); |
| 367 | } |
| 368 | *p='\0'; |
| 369 | /* |
| 370 | Assign a value to the specified keyword. |
| 371 | */ |
| 372 | if (LocaleCompare(keyword,"depth") == 0) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 373 | packet_size=StringToUnsignedLong(value); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 374 | (void) packet_size; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 375 | if (LocaleCompare(keyword,"height") == 0) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 376 | image->rows=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 377 | if (LocaleCompare(keyword,"maxval") == 0) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 378 | max_value=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 379 | if (LocaleCompare(keyword,"TUPLTYPE") == 0) |
| 380 | { |
| 381 | if (LocaleCompare(value,"BLACKANDWHITE") == 0) |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 382 | { |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 383 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 384 | quantum_type=GrayQuantum; |
| 385 | } |
cristy | 7a20199 | 2012-05-12 23:30:43 +0000 | [diff] [blame] | 386 | if (LocaleCompare(value,"BLACKANDWHITE_ALPHA") == 0) |
| 387 | { |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 388 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 389 | image->alpha_trait=BlendPixelTrait; |
cristy | 7a20199 | 2012-05-12 23:30:43 +0000 | [diff] [blame] | 390 | quantum_type=GrayAlphaQuantum; |
| 391 | } |
| 392 | if (LocaleCompare(value,"GRAYSCALE") == 0) |
| 393 | { |
| 394 | quantum_type=GrayQuantum; |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 395 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 7a20199 | 2012-05-12 23:30:43 +0000 | [diff] [blame] | 396 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 397 | if (LocaleCompare(value,"GRAYSCALE_ALPHA") == 0) |
| 398 | { |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 399 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 400 | image->alpha_trait=BlendPixelTrait; |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 401 | quantum_type=GrayAlphaQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 402 | } |
| 403 | if (LocaleCompare(value,"RGB_ALPHA") == 0) |
| 404 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 405 | image->alpha_trait=BlendPixelTrait; |
cristy | 7a20199 | 2012-05-12 23:30:43 +0000 | [diff] [blame] | 406 | quantum_type=RGBAQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 407 | } |
| 408 | if (LocaleCompare(value,"CMYK") == 0) |
| 409 | { |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 410 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 7a20199 | 2012-05-12 23:30:43 +0000 | [diff] [blame] | 411 | quantum_type=CMYKQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 412 | } |
| 413 | if (LocaleCompare(value,"CMYK_ALPHA") == 0) |
| 414 | { |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 415 | (void) SetImageColorspace(image,CMYKColorspace,exception); |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 416 | image->alpha_trait=BlendPixelTrait; |
cristy | 7a20199 | 2012-05-12 23:30:43 +0000 | [diff] [blame] | 417 | quantum_type=CMYKAQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 | } |
| 419 | } |
| 420 | if (LocaleCompare(keyword,"width") == 0) |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 421 | image->columns=StringToUnsignedLong(value); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | if ((image->columns == 0) || (image->rows == 0)) |
| 425 | ThrowReaderException(CorruptImageError,"NegativeOrZeroImageSize"); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 426 | if (max_value > 4294967295) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 427 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
cristy | 3f1ee59 | 2011-06-15 23:03:58 +0000 | [diff] [blame] | 428 | for (depth=1; GetQuantumRange(depth) < max_value; depth++) ; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 429 | image->depth=depth; |
| 430 | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
| 431 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 432 | break; |
| 433 | /* |
| 434 | Convert PNM pixels to runextent-encoded MIFF packets. |
| 435 | */ |
| 436 | status=MagickTrue; |
| 437 | row=0; |
| 438 | switch (format) |
| 439 | { |
| 440 | case '1': |
| 441 | { |
| 442 | /* |
| 443 | Convert PBM image to pixel packets. |
| 444 | */ |
cristy | 4e285b9 | 2013-05-24 17:42:57 +0000 | [diff] [blame] | 445 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 446 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 447 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 448 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 449 | x; |
| 450 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 451 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 452 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 453 | |
| 454 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 455 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 456 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 457 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 458 | { |
cristy | 0852850 | 2012-01-01 00:52:17 +0000 | [diff] [blame] | 459 | SetPixelGray(image,PNMInteger(image,2,exception) == 0 ? |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 460 | QuantumRange : 0,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 461 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 462 | } |
| 463 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 464 | break; |
| 465 | if (image->previous == (Image *) NULL) |
| 466 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 467 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 468 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 469 | if (status == MagickFalse) |
| 470 | break; |
| 471 | } |
| 472 | } |
| 473 | image->type=BilevelType; |
| 474 | break; |
| 475 | } |
| 476 | case '2': |
| 477 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 478 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 479 | intensity; |
| 480 | |
| 481 | /* |
| 482 | Convert PGM image to pixel packets. |
| 483 | */ |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 484 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 485 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 486 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 487 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 488 | x; |
| 489 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 490 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 491 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 492 | |
| 493 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | b3a73b5 | 2011-07-26 01:34:43 +0000 | [diff] [blame] | 494 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 495 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 496 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 497 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 498 | intensity=ScaleAnyToQuantum(PNMInteger(image,10,exception),max_value); |
| 499 | SetPixelGray(image,intensity,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 500 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 501 | } |
| 502 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 503 | break; |
| 504 | if (image->previous == (Image *) NULL) |
| 505 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 506 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 507 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 508 | if (status == MagickFalse) |
| 509 | break; |
| 510 | } |
| 511 | } |
| 512 | image->type=GrayscaleType; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 513 | break; |
| 514 | } |
| 515 | case '3': |
| 516 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 517 | /* |
| 518 | Convert PNM image to pixel packets. |
| 519 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 520 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 521 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 522 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 523 | x; |
| 524 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 525 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 526 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 527 | |
| 528 | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 529 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 530 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 531 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 532 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 533 | double |
| 534 | pixel; |
| 535 | |
| 536 | pixel=ScaleAnyToQuantum(PNMInteger(image,10,exception),max_value); |
| 537 | SetPixelRed(image,pixel,q); |
| 538 | pixel=ScaleAnyToQuantum(PNMInteger(image,10,exception),max_value); |
| 539 | SetPixelGreen(image,pixel,q); |
| 540 | pixel=ScaleAnyToQuantum(PNMInteger(image,10,exception),max_value); |
| 541 | SetPixelBlue(image,pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 542 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 543 | } |
| 544 | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
| 545 | break; |
| 546 | if (image->previous == (Image *) NULL) |
| 547 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 548 | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
| 549 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 550 | if (status == MagickFalse) |
| 551 | break; |
| 552 | } |
| 553 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | case '4': |
| 557 | { |
| 558 | /* |
| 559 | Convert PBM raw image to pixel packets. |
| 560 | */ |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 561 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 562 | quantum_type=GrayQuantum; |
| 563 | if (image->storage_class == PseudoClass) |
| 564 | quantum_type=IndexQuantum; |
| 565 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 566 | if (quantum_info == (QuantumInfo *) NULL) |
| 567 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 568 | SetQuantumMinIsWhite(quantum_info,MagickTrue); |
| 569 | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 570 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 571 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 572 | MagickBooleanType |
| 573 | sync; |
| 574 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 575 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 576 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 577 | |
| 578 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 579 | count, |
| 580 | offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 581 | |
| 582 | size_t |
| 583 | length; |
| 584 | |
| 585 | unsigned char |
| 586 | *pixels; |
| 587 | |
| 588 | if (status == MagickFalse) |
| 589 | continue; |
| 590 | pixels=GetQuantumPixels(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 591 | { |
| 592 | count=ReadBlob(image,extent,pixels); |
| 593 | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
| 594 | (image->previous == (Image *) NULL)) |
| 595 | { |
| 596 | MagickBooleanType |
| 597 | proceed; |
| 598 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 599 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
| 600 | row,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 601 | if (proceed == MagickFalse) |
| 602 | status=MagickFalse; |
| 603 | } |
| 604 | offset=row++; |
| 605 | } |
| 606 | if (count != (ssize_t) extent) |
| 607 | status=MagickFalse; |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 608 | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 609 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 610 | { |
| 611 | status=MagickFalse; |
| 612 | continue; |
| 613 | } |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 614 | length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 615 | quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 616 | if (length != extent) |
| 617 | status=MagickFalse; |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 618 | sync=SyncAuthenticPixels(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 619 | if (sync == MagickFalse) |
| 620 | status=MagickFalse; |
| 621 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 622 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 623 | if (status == MagickFalse) |
| 624 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 625 | SetQuantumImageType(image,quantum_type); |
| 626 | break; |
| 627 | } |
| 628 | case '5': |
| 629 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 630 | /* |
| 631 | Convert PGM raw image to pixel packets. |
| 632 | */ |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 633 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 634 | quantum_type=GrayQuantum; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 635 | if (image->depth <= 8) |
| 636 | extent=image->columns; |
| 637 | else |
| 638 | if (image->depth <= 16) |
| 639 | extent=2*image->columns; |
| 640 | else |
| 641 | extent=4*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 642 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 643 | if (quantum_info == (QuantumInfo *) NULL) |
| 644 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 645 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 646 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 647 | MagickBooleanType |
| 648 | sync; |
| 649 | |
| 650 | register const unsigned char |
cristy | 3f2302b | 2010-03-11 03:16:37 +0000 | [diff] [blame] | 651 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 652 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 653 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 654 | x; |
| 655 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 656 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 657 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 658 | |
| 659 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 660 | count, |
| 661 | offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 662 | |
| 663 | unsigned char |
| 664 | *pixels; |
| 665 | |
| 666 | if (status == MagickFalse) |
| 667 | continue; |
| 668 | pixels=GetQuantumPixels(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 669 | { |
| 670 | count=ReadBlob(image,extent,pixels); |
| 671 | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
| 672 | (image->previous == (Image *) NULL)) |
| 673 | { |
| 674 | MagickBooleanType |
| 675 | proceed; |
| 676 | |
cristy | 3457521 | 2010-11-06 12:39:23 +0000 | [diff] [blame] | 677 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
| 678 | row,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 679 | if (proceed == MagickFalse) |
| 680 | status=MagickFalse; |
| 681 | } |
| 682 | offset=row++; |
| 683 | } |
| 684 | if (count != (ssize_t) extent) |
| 685 | status=MagickFalse; |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 686 | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 687 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 688 | { |
| 689 | status=MagickFalse; |
| 690 | continue; |
| 691 | } |
| 692 | p=pixels; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 693 | switch (image->depth) |
| 694 | { |
| 695 | case 8: |
| 696 | case 16: |
| 697 | case 32: |
| 698 | { |
| 699 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 700 | quantum_type,pixels,exception); |
| 701 | break; |
| 702 | } |
| 703 | default: |
| 704 | { |
| 705 | unsigned int |
| 706 | pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 707 | |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 708 | if (image->depth <= 8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 709 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 710 | unsigned char |
| 711 | pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 712 | |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 713 | for (x=0; x < (ssize_t) image->columns; x++) |
| 714 | { |
| 715 | p=PushCharPixel(p,&pixel); |
| 716 | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 717 | q+=GetPixelChannels(image); |
| 718 | } |
| 719 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 720 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 721 | if (image->depth <= 16) |
| 722 | { |
| 723 | unsigned short |
| 724 | pixel; |
| 725 | |
| 726 | for (x=0; x < (ssize_t) image->columns; x++) |
| 727 | { |
| 728 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 729 | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 730 | q+=GetPixelChannels(image); |
| 731 | } |
| 732 | break; |
| 733 | } |
| 734 | for (x=0; x < (ssize_t) image->columns; x++) |
| 735 | { |
| 736 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 737 | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 738 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 739 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 740 | break; |
| 741 | } |
| 742 | } |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 743 | sync=SyncAuthenticPixels(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 744 | if (sync == MagickFalse) |
| 745 | status=MagickFalse; |
| 746 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 748 | if (status == MagickFalse) |
| 749 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 750 | SetQuantumImageType(image,quantum_type); |
| 751 | break; |
| 752 | } |
| 753 | case '6': |
| 754 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 755 | /* |
| 756 | Convert PNM raster image to pixel packets. |
| 757 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 758 | quantum_type=RGBQuantum; |
| 759 | extent=3*(image->depth <= 8 ? 1 : 2)*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 760 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 761 | if (quantum_info == (QuantumInfo *) NULL) |
| 762 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 70d7eae | 2012-11-17 19:40:21 +0000 | [diff] [blame] | 763 | (void) SetQuantumEndian(image,quantum_info,MSBEndian); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 764 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 765 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 766 | MagickBooleanType |
| 767 | sync; |
| 768 | |
| 769 | register const unsigned char |
cristy | 3f2302b | 2010-03-11 03:16:37 +0000 | [diff] [blame] | 770 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 771 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 772 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 773 | x; |
| 774 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 775 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 776 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 777 | |
| 778 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 779 | count, |
| 780 | offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 781 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 782 | unsigned char |
| 783 | *pixels; |
| 784 | |
| 785 | if (status == MagickFalse) |
| 786 | continue; |
| 787 | pixels=GetQuantumPixels(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 788 | { |
| 789 | count=ReadBlob(image,extent,pixels); |
| 790 | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
| 791 | (image->previous == (Image *) NULL)) |
| 792 | { |
| 793 | MagickBooleanType |
| 794 | proceed; |
| 795 | |
cristy | 3457521 | 2010-11-06 12:39:23 +0000 | [diff] [blame] | 796 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
| 797 | row,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 798 | if (proceed == MagickFalse) |
| 799 | status=MagickFalse; |
| 800 | } |
| 801 | offset=row++; |
| 802 | } |
| 803 | if (count != (ssize_t) extent) |
| 804 | status=MagickFalse; |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 805 | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 806 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 807 | { |
| 808 | status=MagickFalse; |
| 809 | continue; |
| 810 | } |
| 811 | p=pixels; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 812 | switch (image->depth) |
| 813 | { |
| 814 | case 8: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 815 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 816 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 817 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 818 | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
| 819 | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
| 820 | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
| 821 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 822 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 823 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 824 | break; |
| 825 | } |
| 826 | case 16: |
| 827 | { |
| 828 | unsigned short |
| 829 | pixel; |
| 830 | |
| 831 | for (x=0; x < (ssize_t) image->columns; x++) |
| 832 | { |
| 833 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 834 | SetPixelRed(image,ScaleShortToQuantum(pixel),q); |
| 835 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 836 | SetPixelGreen(image,ScaleShortToQuantum(pixel),q); |
| 837 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 838 | SetPixelBlue(image,ScaleShortToQuantum(pixel),q); |
| 839 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 840 | q+=GetPixelChannels(image); |
| 841 | } |
| 842 | break; |
| 843 | } |
| 844 | case 32: |
| 845 | { |
| 846 | unsigned int |
| 847 | pixel; |
| 848 | |
| 849 | for (x=0; x < (ssize_t) image->columns; x++) |
| 850 | { |
| 851 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 852 | SetPixelRed(image,ScaleLongToQuantum(pixel),q); |
| 853 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 854 | SetPixelGreen(image,ScaleLongToQuantum(pixel),q); |
| 855 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 856 | SetPixelBlue(image,ScaleLongToQuantum(pixel),q); |
| 857 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 858 | q+=GetPixelChannels(image); |
| 859 | } |
| 860 | break; |
| 861 | } |
| 862 | default: |
| 863 | { |
| 864 | unsigned int |
| 865 | pixel; |
| 866 | |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 867 | if (image->depth <= 8) |
| 868 | { |
| 869 | unsigned char |
| 870 | pixel; |
| 871 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 872 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 873 | { |
| 874 | p=PushCharPixel(p,&pixel); |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 875 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 876 | p=PushCharPixel(p,&pixel); |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 877 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 878 | p=PushCharPixel(p,&pixel); |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 879 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 880 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 881 | q+=GetPixelChannels(image); |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 882 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 883 | break; |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 884 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 885 | if (image->depth <= 16) |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 886 | { |
| 887 | unsigned short |
| 888 | pixel; |
| 889 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 890 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 891 | { |
| 892 | p=PushShortPixel(MSBEndian,p,&pixel); |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 893 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 894 | p=PushShortPixel(MSBEndian,p,&pixel); |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 895 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 896 | p=PushShortPixel(MSBEndian,p,&pixel); |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 897 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 898 | SetPixelAlpha(image,OpaqueAlpha,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 899 | q+=GetPixelChannels(image); |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 900 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 901 | break; |
cristy | e90d740 | 2010-03-14 18:21:29 +0000 | [diff] [blame] | 902 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 903 | for (x=0; x < (ssize_t) image->columns; x++) |
| 904 | { |
| 905 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 906 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 907 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 908 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 909 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 910 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 911 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 912 | q+=GetPixelChannels(image); |
| 913 | } |
| 914 | break; |
| 915 | } |
| 916 | } |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 917 | sync=SyncAuthenticPixels(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 918 | if (sync == MagickFalse) |
| 919 | status=MagickFalse; |
| 920 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 921 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 922 | if (status == MagickFalse) |
| 923 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 924 | break; |
| 925 | } |
| 926 | case '7': |
| 927 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 928 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 929 | channels; |
| 930 | |
| 931 | /* |
| 932 | Convert PAM raster image to pixel packets. |
| 933 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 934 | switch (quantum_type) |
| 935 | { |
| 936 | case GrayQuantum: |
| 937 | case GrayAlphaQuantum: |
| 938 | { |
| 939 | channels=1; |
| 940 | break; |
| 941 | } |
| 942 | case CMYKQuantum: |
| 943 | case CMYKAQuantum: |
| 944 | { |
| 945 | channels=4; |
| 946 | break; |
| 947 | } |
| 948 | default: |
| 949 | { |
| 950 | channels=3; |
| 951 | break; |
| 952 | } |
| 953 | } |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 954 | if (image->alpha_trait == BlendPixelTrait) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 955 | channels++; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 956 | if (image->depth <= 8) |
| 957 | extent=channels*image->columns; |
| 958 | else |
| 959 | if (image->depth <= 16) |
| 960 | extent=2*channels*image->columns; |
| 961 | else |
| 962 | extent=4*channels*image->columns; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 963 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 964 | if (quantum_info == (QuantumInfo *) NULL) |
| 965 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 966 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 967 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 968 | MagickBooleanType |
| 969 | sync; |
| 970 | |
| 971 | register const unsigned char |
cristy | 3f2302b | 2010-03-11 03:16:37 +0000 | [diff] [blame] | 972 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 973 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 974 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 975 | x; |
| 976 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 977 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 978 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 979 | |
| 980 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 981 | count, |
| 982 | offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 983 | |
| 984 | unsigned char |
| 985 | *pixels; |
| 986 | |
| 987 | if (status == MagickFalse) |
| 988 | continue; |
| 989 | pixels=GetQuantumPixels(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 990 | { |
| 991 | count=ReadBlob(image,extent,pixels); |
| 992 | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
| 993 | (image->previous == (Image *) NULL)) |
| 994 | { |
| 995 | MagickBooleanType |
| 996 | proceed; |
| 997 | |
cristy | 3457521 | 2010-11-06 12:39:23 +0000 | [diff] [blame] | 998 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
| 999 | row,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1000 | if (proceed == MagickFalse) |
| 1001 | status=MagickFalse; |
| 1002 | } |
| 1003 | offset=row++; |
| 1004 | } |
| 1005 | if (count != (ssize_t) extent) |
| 1006 | status=MagickFalse; |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 1007 | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1008 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1009 | { |
| 1010 | status=MagickFalse; |
| 1011 | continue; |
| 1012 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1013 | p=pixels; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1014 | switch (image->depth) |
| 1015 | { |
| 1016 | case 8: |
| 1017 | case 16: |
| 1018 | case 32: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1020 | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 1021 | quantum_type,pixels,exception); |
| 1022 | break; |
| 1023 | } |
| 1024 | default: |
| 1025 | { |
| 1026 | switch (quantum_type) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1027 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1028 | case GrayQuantum: |
| 1029 | case GrayAlphaQuantum: |
| 1030 | { |
| 1031 | unsigned int |
| 1032 | pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1033 | |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1034 | if (image->depth <= 8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1035 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1036 | unsigned char |
| 1037 | pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1038 | |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1039 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1040 | { |
| 1041 | p=PushCharPixel(p,&pixel); |
| 1042 | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1043 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1044 | if (image->alpha_trait == BlendPixelTrait) |
| 1045 | { |
| 1046 | p=PushCharPixel(p,&pixel); |
| 1047 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
| 1048 | max_value),q); |
| 1049 | } |
| 1050 | q+=GetPixelChannels(image); |
| 1051 | } |
| 1052 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1053 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1054 | if (image->depth <= 16) |
| 1055 | { |
| 1056 | unsigned short |
| 1057 | pixel; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1058 | |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1059 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1060 | { |
| 1061 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1062 | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1063 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1064 | if (image->alpha_trait == BlendPixelTrait) |
| 1065 | { |
| 1066 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1067 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
| 1068 | max_value),q); |
| 1069 | } |
| 1070 | q+=GetPixelChannels(image); |
| 1071 | } |
| 1072 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1073 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1074 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1075 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1076 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1077 | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1078 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1079 | if (image->alpha_trait == BlendPixelTrait) |
| 1080 | { |
| 1081 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1082 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1083 | } |
| 1084 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1085 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1086 | break; |
| 1087 | } |
| 1088 | case CMYKQuantum: |
| 1089 | case CMYKAQuantum: |
| 1090 | { |
| 1091 | unsigned int |
| 1092 | pixel; |
| 1093 | |
| 1094 | if (image->depth <= 8) |
| 1095 | { |
| 1096 | unsigned char |
| 1097 | pixel; |
| 1098 | |
| 1099 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1100 | { |
| 1101 | p=PushCharPixel(p,&pixel); |
| 1102 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1103 | p=PushCharPixel(p,&pixel); |
| 1104 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1105 | p=PushCharPixel(p,&pixel); |
| 1106 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1107 | p=PushCharPixel(p,&pixel); |
| 1108 | SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1109 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1110 | if (image->alpha_trait == BlendPixelTrait) |
| 1111 | { |
| 1112 | p=PushCharPixel(p,&pixel); |
| 1113 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
| 1114 | max_value),q); |
| 1115 | } |
| 1116 | q+=GetPixelChannels(image); |
| 1117 | } |
| 1118 | break; |
| 1119 | } |
| 1120 | if (image->depth <= 16) |
| 1121 | { |
| 1122 | unsigned short |
| 1123 | pixel; |
| 1124 | |
| 1125 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1126 | { |
| 1127 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1128 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1129 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1130 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1131 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1132 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1133 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1134 | SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1135 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1136 | if (image->alpha_trait == BlendPixelTrait) |
| 1137 | { |
| 1138 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1139 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
| 1140 | max_value),q); |
| 1141 | } |
| 1142 | q+=GetPixelChannels(image); |
| 1143 | } |
| 1144 | } |
| 1145 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1146 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1147 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1148 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1149 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1150 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1151 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1152 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1153 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1154 | SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1155 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1156 | if (image->alpha_trait == BlendPixelTrait) |
| 1157 | { |
| 1158 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1159 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1160 | } |
| 1161 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1162 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1163 | break; |
| 1164 | } |
| 1165 | default: |
| 1166 | { |
| 1167 | unsigned int |
| 1168 | pixel; |
| 1169 | |
| 1170 | if (image->depth <= 8) |
| 1171 | { |
| 1172 | unsigned char |
| 1173 | pixel; |
| 1174 | |
| 1175 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1176 | { |
| 1177 | p=PushCharPixel(p,&pixel); |
| 1178 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1179 | p=PushCharPixel(p,&pixel); |
| 1180 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1181 | p=PushCharPixel(p,&pixel); |
| 1182 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1183 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1184 | if (image->alpha_trait == BlendPixelTrait) |
| 1185 | { |
| 1186 | p=PushCharPixel(p,&pixel); |
| 1187 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1188 | } |
| 1189 | q+=GetPixelChannels(image); |
| 1190 | } |
| 1191 | break; |
| 1192 | } |
| 1193 | if (image->depth <= 16) |
| 1194 | { |
| 1195 | unsigned short |
| 1196 | pixel; |
| 1197 | |
| 1198 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1199 | { |
| 1200 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1201 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1202 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1203 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1204 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1205 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1206 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1207 | if (image->alpha_trait == BlendPixelTrait) |
| 1208 | { |
| 1209 | p=PushShortPixel(MSBEndian,p,&pixel); |
| 1210 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
| 1211 | max_value),q); |
| 1212 | } |
| 1213 | q+=GetPixelChannels(image); |
| 1214 | } |
| 1215 | break; |
| 1216 | } |
| 1217 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1218 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1219 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1220 | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1221 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1222 | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1223 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1224 | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1225 | SetPixelAlpha(image,OpaqueAlpha,q); |
| 1226 | if (image->alpha_trait == BlendPixelTrait) |
| 1227 | { |
| 1228 | p=PushLongPixel(MSBEndian,p,&pixel); |
| 1229 | SetPixelAlpha(image,ScaleAnyToQuantum(pixel,max_value),q); |
| 1230 | } |
| 1231 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1232 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1233 | break; |
| 1234 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1235 | } |
| 1236 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1237 | } |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 1238 | sync=SyncAuthenticPixels(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1239 | if (sync == MagickFalse) |
| 1240 | status=MagickFalse; |
| 1241 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1242 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1243 | if (status == MagickFalse) |
| 1244 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 1245 | SetQuantumImageType(image,quantum_type); |
| 1246 | break; |
| 1247 | } |
| 1248 | case 'F': |
| 1249 | case 'f': |
| 1250 | { |
| 1251 | /* |
| 1252 | Convert PFM raster image to pixel packets. |
| 1253 | */ |
cristy | af6eb93 | 2012-01-01 01:22:59 +0000 | [diff] [blame] | 1254 | if (format == 'f') |
cristy | 4e285b9 | 2013-05-24 17:42:57 +0000 | [diff] [blame] | 1255 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1256 | quantum_type=format == 'f' ? GrayQuantum : RGBQuantum; |
| 1257 | image->endian=quantum_scale < 0.0 ? LSBEndian : MSBEndian; |
| 1258 | image->depth=32; |
| 1259 | quantum_info=AcquireQuantumInfo(image_info,image); |
| 1260 | if (quantum_info == (QuantumInfo *) NULL) |
| 1261 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1262 | status=SetQuantumDepth(image,quantum_info,32); |
| 1263 | if (status == MagickFalse) |
| 1264 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1265 | status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); |
| 1266 | if (status == MagickFalse) |
| 1267 | ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 243166e | 2012-11-03 19:16:10 +0000 | [diff] [blame] | 1268 | SetQuantumScale(quantum_info,(double) QuantumRange*fabs(quantum_scale)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1269 | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1270 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1271 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1272 | MagickBooleanType |
| 1273 | sync; |
| 1274 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1275 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1276 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1277 | |
| 1278 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 1279 | count, |
| 1280 | offset; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1281 | |
| 1282 | size_t |
| 1283 | length; |
| 1284 | |
| 1285 | unsigned char |
| 1286 | *pixels; |
| 1287 | |
| 1288 | if (status == MagickFalse) |
| 1289 | continue; |
| 1290 | pixels=GetQuantumPixels(quantum_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1291 | { |
| 1292 | count=ReadBlob(image,extent,pixels); |
| 1293 | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
| 1294 | (image->previous == (Image *) NULL)) |
| 1295 | { |
| 1296 | MagickBooleanType |
| 1297 | proceed; |
| 1298 | |
cristy | 3457521 | 2010-11-06 12:39:23 +0000 | [diff] [blame] | 1299 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
| 1300 | row,image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1301 | if (proceed == MagickFalse) |
| 1302 | status=MagickFalse; |
| 1303 | } |
| 1304 | offset=row++; |
| 1305 | } |
| 1306 | if ((size_t) count != extent) |
| 1307 | status=MagickFalse; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1308 | q=QueueAuthenticPixels(image,0,(ssize_t) (image->rows-offset-1), |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 1309 | image->columns,1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1310 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1311 | { |
| 1312 | status=MagickFalse; |
| 1313 | continue; |
| 1314 | } |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 1315 | length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 1316 | quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1317 | if (length != extent) |
| 1318 | status=MagickFalse; |
cristy | aa74011 | 2010-03-30 17:58:44 +0000 | [diff] [blame] | 1319 | sync=SyncAuthenticPixels(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1320 | if (sync == MagickFalse) |
| 1321 | status=MagickFalse; |
| 1322 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1323 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1324 | if (status == MagickFalse) |
| 1325 | ThrowReaderException(CorruptImageError,"UnableToReadImageData"); |
| 1326 | SetQuantumImageType(image,quantum_type); |
| 1327 | break; |
| 1328 | } |
| 1329 | default: |
| 1330 | ThrowReaderException(CorruptImageError,"ImproperImageHeader"); |
| 1331 | } |
| 1332 | if (EOFBlob(image) != MagickFalse) |
cristy | 5d79223 | 2012-01-31 17:02:45 +0000 | [diff] [blame] | 1333 | { |
| 1334 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1335 | CorruptImageError,"UnexpectedEndOfFile","`%s'",image->filename); |
| 1336 | break; |
| 1337 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1338 | /* |
| 1339 | Proceed to next image. |
| 1340 | */ |
| 1341 | if (image_info->number_scenes != 0) |
| 1342 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
| 1343 | break; |
| 1344 | if ((format == '1') || (format == '2') || (format == '3')) |
| 1345 | do |
| 1346 | { |
| 1347 | /* |
| 1348 | Skip to end of line. |
| 1349 | */ |
| 1350 | count=ReadBlob(image,1,(unsigned char *) &format); |
| 1351 | if (count == 0) |
| 1352 | break; |
| 1353 | if ((count != 0) && (format == 'P')) |
| 1354 | break; |
| 1355 | } while (format != '\n'); |
| 1356 | count=ReadBlob(image,1,(unsigned char *) &format); |
| 1357 | if ((count == 1) && (format == 'P')) |
| 1358 | { |
| 1359 | /* |
| 1360 | Allocate next image structure. |
| 1361 | */ |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1362 | AcquireNextImage(image_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1363 | if (GetNextImageInList(image) == (Image *) NULL) |
| 1364 | { |
| 1365 | image=DestroyImageList(image); |
| 1366 | return((Image *) NULL); |
| 1367 | } |
| 1368 | image=SyncNextImageInList(image); |
| 1369 | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
| 1370 | GetBlobSize(image)); |
| 1371 | if (status == MagickFalse) |
| 1372 | break; |
| 1373 | } |
| 1374 | } while ((count == 1) && (format == 'P')); |
| 1375 | (void) CloseBlob(image); |
| 1376 | return(GetFirstImageInList(image)); |
| 1377 | } |
| 1378 | |
| 1379 | /* |
| 1380 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1381 | % % |
| 1382 | % % |
| 1383 | % % |
| 1384 | % R e g i s t e r P N M I m a g e % |
| 1385 | % % |
| 1386 | % % |
| 1387 | % % |
| 1388 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1389 | % |
| 1390 | % RegisterPNMImage() adds properties for the PNM image format to |
| 1391 | % the list of supported formats. The properties include the image format |
| 1392 | % tag, a method to read and/or write the format, whether the format |
| 1393 | % supports the saving of more than one frame to the same file or blob, |
| 1394 | % whether the format supports native in-memory I/O, and a brief |
| 1395 | % description of the format. |
| 1396 | % |
| 1397 | % The format of the RegisterPNMImage method is: |
| 1398 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1399 | % size_t RegisterPNMImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1400 | % |
| 1401 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1402 | ModuleExport size_t RegisterPNMImage(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1403 | { |
| 1404 | MagickInfo |
| 1405 | *entry; |
| 1406 | |
| 1407 | entry=SetMagickInfo("PAM"); |
| 1408 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
| 1409 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
| 1410 | entry->description=ConstantString("Common 2-dimensional bitmap format"); |
cristy | f0d061c | 2013-08-09 12:17:54 +0000 | [diff] [blame] | 1411 | entry->mime_type=ConstantString("image/x-portable-pixmap"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1412 | entry->module=ConstantString("PNM"); |
| 1413 | (void) RegisterMagickInfo(entry); |
| 1414 | entry=SetMagickInfo("PBM"); |
| 1415 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
| 1416 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
| 1417 | entry->description=ConstantString("Portable bitmap format (black and white)"); |
cristy | f0d061c | 2013-08-09 12:17:54 +0000 | [diff] [blame] | 1418 | entry->mime_type=ConstantString("image/x-portable-bitmap"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1419 | entry->module=ConstantString("PNM"); |
| 1420 | (void) RegisterMagickInfo(entry); |
| 1421 | entry=SetMagickInfo("PFM"); |
| 1422 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
| 1423 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
cristy | e96405a | 2010-05-19 02:24:31 +0000 | [diff] [blame] | 1424 | entry->endian_support=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1425 | entry->description=ConstantString("Portable float format"); |
| 1426 | entry->module=ConstantString("PFM"); |
| 1427 | (void) RegisterMagickInfo(entry); |
| 1428 | entry=SetMagickInfo("PGM"); |
| 1429 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
| 1430 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
| 1431 | entry->description=ConstantString("Portable graymap format (gray scale)"); |
cristy | f0d061c | 2013-08-09 12:17:54 +0000 | [diff] [blame] | 1432 | entry->mime_type=ConstantString("image/x-portable-greymap"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1433 | entry->module=ConstantString("PNM"); |
| 1434 | (void) RegisterMagickInfo(entry); |
| 1435 | entry=SetMagickInfo("PNM"); |
| 1436 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
| 1437 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
| 1438 | entry->magick=(IsImageFormatHandler *) IsPNM; |
| 1439 | entry->description=ConstantString("Portable anymap"); |
cristy | f0d061c | 2013-08-09 12:17:54 +0000 | [diff] [blame] | 1440 | entry->mime_type=ConstantString("image/x-portable-pixmap"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1441 | entry->module=ConstantString("PNM"); |
| 1442 | (void) RegisterMagickInfo(entry); |
| 1443 | entry=SetMagickInfo("PPM"); |
| 1444 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
| 1445 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
| 1446 | entry->description=ConstantString("Portable pixmap format (color)"); |
cristy | f0d061c | 2013-08-09 12:17:54 +0000 | [diff] [blame] | 1447 | entry->mime_type=ConstantString("image/x-portable-pixmap"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1448 | entry->module=ConstantString("PNM"); |
| 1449 | (void) RegisterMagickInfo(entry); |
| 1450 | return(MagickImageCoderSignature); |
| 1451 | } |
| 1452 | |
| 1453 | /* |
| 1454 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1455 | % % |
| 1456 | % % |
| 1457 | % % |
| 1458 | % U n r e g i s t e r P N M I m a g e % |
| 1459 | % % |
| 1460 | % % |
| 1461 | % % |
| 1462 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1463 | % |
| 1464 | % UnregisterPNMImage() removes format registrations made by the |
| 1465 | % PNM module from the list of supported formats. |
| 1466 | % |
| 1467 | % The format of the UnregisterPNMImage method is: |
| 1468 | % |
| 1469 | % UnregisterPNMImage(void) |
| 1470 | % |
| 1471 | */ |
| 1472 | ModuleExport void UnregisterPNMImage(void) |
| 1473 | { |
| 1474 | (void) UnregisterMagickInfo("PAM"); |
| 1475 | (void) UnregisterMagickInfo("PBM"); |
| 1476 | (void) UnregisterMagickInfo("PGM"); |
| 1477 | (void) UnregisterMagickInfo("PNM"); |
| 1478 | (void) UnregisterMagickInfo("PPM"); |
| 1479 | } |
| 1480 | |
| 1481 | /* |
| 1482 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1483 | % % |
| 1484 | % % |
| 1485 | % % |
| 1486 | % W r i t e P N M I m a g e % |
| 1487 | % % |
| 1488 | % % |
| 1489 | % % |
| 1490 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1491 | % |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1492 | % WritePNMImage() writes an image to a file in the PNM rasterfile format. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1493 | % |
| 1494 | % The format of the WritePNMImage method is: |
| 1495 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1496 | % MagickBooleanType WritePNMImage(const ImageInfo *image_info, |
| 1497 | % Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1498 | % |
| 1499 | % A description of each parameter follows. |
| 1500 | % |
| 1501 | % o image_info: the image info. |
| 1502 | % |
| 1503 | % o image: The image. |
| 1504 | % |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1505 | % o exception: return any errors or warnings in this structure. |
| 1506 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1507 | */ |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1508 | static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image, |
| 1509 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1510 | { |
| 1511 | char |
| 1512 | buffer[MaxTextExtent], |
| 1513 | format, |
| 1514 | magick[MaxTextExtent]; |
| 1515 | |
| 1516 | const char |
| 1517 | *value; |
| 1518 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1519 | MagickBooleanType |
| 1520 | status; |
| 1521 | |
| 1522 | MagickOffsetType |
| 1523 | scene; |
| 1524 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1525 | Quantum |
| 1526 | index; |
| 1527 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1528 | QuantumAny |
| 1529 | pixel; |
| 1530 | |
| 1531 | QuantumInfo |
| 1532 | *quantum_info; |
| 1533 | |
| 1534 | QuantumType |
| 1535 | quantum_type; |
| 1536 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1537 | register unsigned char |
| 1538 | *pixels, |
| 1539 | *q; |
| 1540 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1541 | size_t |
| 1542 | extent, |
| 1543 | packet_size; |
| 1544 | |
cristy | 95802a7 | 2010-09-05 19:07:17 +0000 | [diff] [blame] | 1545 | ssize_t |
cristy | aff6d80 | 2011-04-26 01:46:31 +0000 | [diff] [blame] | 1546 | count, |
| 1547 | y; |
cristy | 95802a7 | 2010-09-05 19:07:17 +0000 | [diff] [blame] | 1548 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1549 | /* |
| 1550 | Open output image file. |
| 1551 | */ |
| 1552 | assert(image_info != (const ImageInfo *) NULL); |
| 1553 | assert(image_info->signature == MagickSignature); |
| 1554 | assert(image != (Image *) NULL); |
| 1555 | assert(image->signature == MagickSignature); |
| 1556 | if (image->debug != MagickFalse) |
| 1557 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 3a37efd | 2011-08-28 20:31:03 +0000 | [diff] [blame] | 1558 | assert(exception != (ExceptionInfo *) NULL); |
| 1559 | assert(exception->signature == MagickSignature); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1560 | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1561 | if (status == MagickFalse) |
| 1562 | return(status); |
| 1563 | scene=0; |
| 1564 | do |
| 1565 | { |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 1566 | QuantumAny |
| 1567 | max_value; |
| 1568 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1569 | /* |
| 1570 | Write PNM file header. |
| 1571 | */ |
| 1572 | packet_size=3; |
| 1573 | quantum_type=RGBQuantum; |
| 1574 | (void) CopyMagickString(magick,image_info->magick,MaxTextExtent); |
cristy | 92beec6 | 2013-08-26 12:23:46 +0000 | [diff] [blame] | 1575 | max_value=GetQuantumRange(image->depth); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1576 | switch (magick[1]) |
| 1577 | { |
| 1578 | case 'A': |
| 1579 | case 'a': |
| 1580 | { |
| 1581 | format='7'; |
| 1582 | break; |
| 1583 | } |
| 1584 | case 'B': |
| 1585 | case 'b': |
| 1586 | { |
| 1587 | format='4'; |
| 1588 | if (image_info->compression == NoCompression) |
| 1589 | format='1'; |
| 1590 | break; |
| 1591 | } |
| 1592 | case 'F': |
| 1593 | case 'f': |
| 1594 | { |
| 1595 | format='F'; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1596 | if (IsImageGray(image,exception) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1597 | format='f'; |
| 1598 | break; |
| 1599 | } |
| 1600 | case 'G': |
| 1601 | case 'g': |
| 1602 | { |
| 1603 | format='5'; |
| 1604 | if (image_info->compression == NoCompression) |
| 1605 | format='2'; |
| 1606 | break; |
| 1607 | } |
| 1608 | case 'N': |
| 1609 | case 'n': |
| 1610 | { |
| 1611 | if ((image_info->type != TrueColorType) && |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1612 | (IsImageGray(image,exception) != MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1613 | { |
| 1614 | format='5'; |
| 1615 | if (image_info->compression == NoCompression) |
| 1616 | format='2'; |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1617 | if (IsImageMonochrome(image,exception) != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1618 | { |
| 1619 | format='4'; |
| 1620 | if (image_info->compression == NoCompression) |
| 1621 | format='1'; |
| 1622 | } |
| 1623 | break; |
| 1624 | } |
| 1625 | } |
| 1626 | default: |
| 1627 | { |
| 1628 | format='6'; |
| 1629 | if (image_info->compression == NoCompression) |
| 1630 | format='3'; |
| 1631 | break; |
| 1632 | } |
| 1633 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1634 | (void) FormatLocaleString(buffer,MaxTextExtent,"P%c\n",format); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1635 | (void) WriteBlobString(image,buffer); |
cristy | d15e659 | 2011-10-15 00:13:06 +0000 | [diff] [blame] | 1636 | value=GetImageProperty(image,"comment",exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1637 | if (value != (const char *) NULL) |
| 1638 | { |
| 1639 | register const char |
| 1640 | *p; |
| 1641 | |
| 1642 | /* |
| 1643 | Write comments to file. |
| 1644 | */ |
| 1645 | (void) WriteBlobByte(image,'#'); |
| 1646 | for (p=value; *p != '\0'; p++) |
| 1647 | { |
| 1648 | (void) WriteBlobByte(image,(unsigned char) *p); |
cristy | 542ea78 | 2013-05-24 15:53:01 +0000 | [diff] [blame] | 1649 | if ((*p == '\n') || (*p == '\r')) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1650 | (void) WriteBlobByte(image,'#'); |
| 1651 | } |
| 1652 | (void) WriteBlobByte(image,'\n'); |
| 1653 | } |
| 1654 | if (format != '7') |
| 1655 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1656 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g %.20g\n", |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1657 | (double) image->columns,(double) image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1658 | (void) WriteBlobString(image,buffer); |
| 1659 | } |
| 1660 | else |
| 1661 | { |
| 1662 | char |
| 1663 | type[MaxTextExtent]; |
| 1664 | |
| 1665 | /* |
| 1666 | PAM header. |
| 1667 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1668 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1669 | "WIDTH %.20g\nHEIGHT %.20g\n",(double) image->columns,(double) |
| 1670 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1671 | (void) WriteBlobString(image,buffer); |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1672 | quantum_type=GetQuantumType(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1673 | switch (quantum_type) |
| 1674 | { |
| 1675 | case CMYKQuantum: |
| 1676 | case CMYKAQuantum: |
| 1677 | { |
| 1678 | packet_size=4; |
| 1679 | (void) CopyMagickString(type,"CMYK",MaxTextExtent); |
| 1680 | break; |
| 1681 | } |
| 1682 | case GrayQuantum: |
| 1683 | case GrayAlphaQuantum: |
| 1684 | { |
| 1685 | packet_size=1; |
| 1686 | (void) CopyMagickString(type,"GRAYSCALE",MaxTextExtent); |
| 1687 | break; |
| 1688 | } |
| 1689 | default: |
| 1690 | { |
| 1691 | quantum_type=RGBQuantum; |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 1692 | if (image->alpha_trait == BlendPixelTrait) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1693 | quantum_type=RGBAQuantum; |
| 1694 | packet_size=3; |
| 1695 | (void) CopyMagickString(type,"RGB",MaxTextExtent); |
| 1696 | break; |
| 1697 | } |
| 1698 | } |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 1699 | if (image->alpha_trait == BlendPixelTrait) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1700 | { |
| 1701 | packet_size++; |
| 1702 | (void) ConcatenateMagickString(type,"_ALPHA",MaxTextExtent); |
| 1703 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1704 | if (image->depth > 32) |
| 1705 | image->depth=32; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1706 | (void) FormatLocaleString(buffer,MaxTextExtent, |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 1707 | "DEPTH %.20g\nMAXVAL %.20g\n",(double) packet_size,(double) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 1708 | ((MagickOffsetType) GetQuantumRange(image->depth))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1709 | (void) WriteBlobString(image,buffer); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1710 | (void) FormatLocaleString(buffer,MaxTextExtent,"TUPLTYPE %s\nENDHDR\n", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1711 | type); |
| 1712 | (void) WriteBlobString(image,buffer); |
| 1713 | } |
| 1714 | /* |
| 1715 | Convert runextent encoded to PNM raster pixels. |
| 1716 | */ |
| 1717 | switch (format) |
| 1718 | { |
| 1719 | case '1': |
| 1720 | { |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1721 | unsigned char |
| 1722 | pixels[2048]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1723 | |
| 1724 | /* |
| 1725 | Convert image to a PBM image. |
| 1726 | */ |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1727 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1728 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1729 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1730 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1731 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1732 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1733 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1734 | x; |
| 1735 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1736 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1737 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1738 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1739 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1740 | { |
cristy | d032322 | 2013-04-07 16:13:21 +0000 | [diff] [blame] | 1741 | pixel=ClampToQuantum(GetPixelLuma(image,p)); |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1742 | *q++=(unsigned char) (pixel >= (Quantum) (QuantumRange/2) ? |
| 1743 | '0' : '1'); |
| 1744 | *q++=' '; |
| 1745 | if ((q-pixels+2) >= 80) |
| 1746 | { |
| 1747 | *q++='\n'; |
| 1748 | (void) WriteBlob(image,q-pixels,pixels); |
| 1749 | q=pixels; |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1750 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1751 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1752 | } |
| 1753 | if (image->previous == (Image *) NULL) |
| 1754 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1755 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1756 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1757 | if (status == MagickFalse) |
| 1758 | break; |
| 1759 | } |
| 1760 | } |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1761 | if (q != pixels) |
| 1762 | { |
| 1763 | *q++='\n'; |
| 1764 | (void) WriteBlob(image,q-pixels,pixels); |
| 1765 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1766 | break; |
| 1767 | } |
| 1768 | case '2': |
| 1769 | { |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1770 | unsigned char |
| 1771 | pixels[2048]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1772 | |
| 1773 | /* |
| 1774 | Convert image to a PGM image. |
| 1775 | */ |
| 1776 | if (image->depth <= 8) |
| 1777 | (void) WriteBlobString(image,"255\n"); |
| 1778 | else |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1779 | if (image->depth <= 16) |
| 1780 | (void) WriteBlobString(image,"65535\n"); |
| 1781 | else |
| 1782 | (void) WriteBlobString(image,"4294967295\n"); |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1783 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1784 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1785 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1786 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1787 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1788 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1789 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1790 | x; |
| 1791 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1792 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1793 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1794 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1795 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1796 | { |
cristy | d032322 | 2013-04-07 16:13:21 +0000 | [diff] [blame] | 1797 | index=ClampToQuantum(GetPixelLuma(image,p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1798 | if (image->depth <= 8) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1799 | count=(ssize_t) FormatLocaleString(buffer,MaxTextExtent,"%u ", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1800 | ScaleQuantumToChar(index)); |
| 1801 | else |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1802 | if (image->depth <= 16) |
| 1803 | count=(ssize_t) FormatLocaleString(buffer,MaxTextExtent,"%u ", |
| 1804 | ScaleQuantumToShort(index)); |
| 1805 | else |
| 1806 | count=(ssize_t) FormatLocaleString(buffer,MaxTextExtent,"%u ", |
| 1807 | ScaleQuantumToLong(index)); |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1808 | extent=(size_t) count; |
| 1809 | (void) strncpy((char *) q,buffer,extent); |
| 1810 | q+=extent; |
| 1811 | if ((q-pixels+extent) >= 80) |
| 1812 | { |
| 1813 | *q++='\n'; |
| 1814 | (void) WriteBlob(image,q-pixels,pixels); |
| 1815 | q=pixels; |
| 1816 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1817 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1818 | } |
| 1819 | if (image->previous == (Image *) NULL) |
| 1820 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1821 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1822 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1823 | if (status == MagickFalse) |
| 1824 | break; |
| 1825 | } |
| 1826 | } |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1827 | if (q != pixels) |
| 1828 | { |
| 1829 | *q++='\n'; |
| 1830 | (void) WriteBlob(image,q-pixels,pixels); |
| 1831 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1832 | break; |
| 1833 | } |
| 1834 | case '3': |
| 1835 | { |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1836 | unsigned char |
| 1837 | pixels[2048]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1838 | |
| 1839 | /* |
| 1840 | Convert image to a PNM image. |
| 1841 | */ |
cristy | 3d9f5ba | 2012-06-26 13:37:31 +0000 | [diff] [blame] | 1842 | if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse) |
cristy | 8d218d7 | 2012-06-25 18:01:54 +0000 | [diff] [blame] | 1843 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1844 | if (image->depth <= 8) |
| 1845 | (void) WriteBlobString(image,"255\n"); |
| 1846 | else |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1847 | if (image->depth <= 16) |
| 1848 | (void) WriteBlobString(image,"65535\n"); |
| 1849 | else |
| 1850 | (void) WriteBlobString(image,"4294967295\n"); |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1851 | q=pixels; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1852 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1853 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1854 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1855 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1856 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1857 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1858 | x; |
| 1859 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1860 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1861 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1862 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1863 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1864 | { |
| 1865 | if (image->depth <= 8) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1866 | count=(ssize_t) FormatLocaleString(buffer,MaxTextExtent, |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1867 | "%u %u %u ",ScaleQuantumToChar(GetPixelRed(image,p)), |
| 1868 | ScaleQuantumToChar(GetPixelGreen(image,p)), |
| 1869 | ScaleQuantumToChar(GetPixelBlue(image,p))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1870 | else |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1871 | if (image->depth <= 16) |
| 1872 | count=(ssize_t) FormatLocaleString(buffer,MaxTextExtent, |
| 1873 | "%u %u %u ",ScaleQuantumToShort(GetPixelRed(image,p)), |
| 1874 | ScaleQuantumToShort(GetPixelGreen(image,p)), |
| 1875 | ScaleQuantumToShort(GetPixelBlue(image,p))); |
| 1876 | else |
| 1877 | count=(ssize_t) FormatLocaleString(buffer,MaxTextExtent, |
| 1878 | "%u %u %u ",ScaleQuantumToLong(GetPixelRed(image,p)), |
| 1879 | ScaleQuantumToLong(GetPixelGreen(image,p)), |
| 1880 | ScaleQuantumToLong(GetPixelBlue(image,p))); |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1881 | extent=(size_t) count; |
| 1882 | (void) strncpy((char *) q,buffer,extent); |
| 1883 | q+=extent; |
| 1884 | if ((q-pixels+extent) >= 80) |
| 1885 | { |
| 1886 | *q++='\n'; |
| 1887 | (void) WriteBlob(image,q-pixels,pixels); |
| 1888 | q=pixels; |
| 1889 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1890 | p+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1891 | } |
| 1892 | if (image->previous == (Image *) NULL) |
| 1893 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1894 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1895 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1896 | if (status == MagickFalse) |
| 1897 | break; |
| 1898 | } |
| 1899 | } |
cristy | 661b5ad | 2010-01-13 00:54:42 +0000 | [diff] [blame] | 1900 | if (q != pixels) |
| 1901 | { |
| 1902 | *q++='\n'; |
| 1903 | (void) WriteBlob(image,q-pixels,pixels); |
| 1904 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1905 | break; |
| 1906 | } |
| 1907 | case '4': |
| 1908 | { |
| 1909 | /* |
| 1910 | Convert image to a PBM image. |
| 1911 | */ |
| 1912 | image->depth=1; |
| 1913 | quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); |
| 1914 | if (quantum_info == (QuantumInfo *) NULL) |
| 1915 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1916 | quantum_info->min_is_white=MagickTrue; |
| 1917 | pixels=GetQuantumPixels(quantum_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1918 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1919 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1920 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1921 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1922 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1923 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1924 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1925 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1926 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1927 | GrayQuantum,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1928 | count=WriteBlob(image,extent,pixels); |
| 1929 | if (count != (ssize_t) extent) |
| 1930 | break; |
| 1931 | if (image->previous == (Image *) NULL) |
| 1932 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1933 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 1934 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1935 | if (status == MagickFalse) |
| 1936 | break; |
| 1937 | } |
| 1938 | } |
| 1939 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 1940 | break; |
| 1941 | } |
| 1942 | case '5': |
| 1943 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1944 | /* |
| 1945 | Convert image to a PGM image. |
| 1946 | */ |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1947 | if (image->depth > 32) |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 1948 | image->depth=32; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1949 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 1950 | ((MagickOffsetType) GetQuantumRange(image->depth))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1951 | (void) WriteBlobString(image,buffer); |
| 1952 | quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); |
| 1953 | if (quantum_info == (QuantumInfo *) NULL) |
| 1954 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 1955 | quantum_info->min_is_white=MagickTrue; |
| 1956 | pixels=GetQuantumPixels(quantum_info); |
| 1957 | extent=GetQuantumExtent(image,quantum_info,GrayQuantum); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1958 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1959 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1960 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1961 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1962 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1963 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1964 | x; |
| 1965 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 1966 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1967 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1968 | break; |
| 1969 | q=pixels; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1970 | switch (image->depth) |
| 1971 | { |
| 1972 | case 8: |
| 1973 | case 16: |
| 1974 | case 32: |
| 1975 | { |
| 1976 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 1977 | GrayQuantum,pixels,exception); |
| 1978 | break; |
| 1979 | } |
| 1980 | default: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1981 | { |
| 1982 | if (image->depth <= 8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1983 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1984 | for (x=0; x < (ssize_t) image->columns; x++) |
| 1985 | { |
| 1986 | if (IsPixelGray(image,p) == MagickFalse) |
| 1987 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma( |
| 1988 | image,p)),max_value); |
| 1989 | else |
| 1990 | { |
| 1991 | if (image->depth == 8) |
| 1992 | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
| 1993 | else |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 1994 | pixel=ScaleQuantumToAny(GetPixelRed(image,p), |
| 1995 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 1996 | } |
| 1997 | q=PopCharPixel((unsigned char) pixel,q); |
| 1998 | p+=GetPixelChannels(image); |
| 1999 | } |
cristy | 66d892b | 2013-10-03 11:39:44 +0000 | [diff] [blame] | 2000 | extent=(size_t) (q-pixels); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2001 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2002 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2003 | if (image->depth <= 16) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2004 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2005 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2006 | { |
| 2007 | if (IsPixelGray(image,p) == MagickFalse) |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2008 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image, |
| 2009 | p)),max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2010 | else |
| 2011 | { |
| 2012 | if (image->depth == 16) |
| 2013 | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
| 2014 | else |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2015 | pixel=ScaleQuantumToAny(GetPixelRed(image,p), |
| 2016 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2017 | } |
| 2018 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2019 | p+=GetPixelChannels(image); |
| 2020 | } |
cristy | 66d892b | 2013-10-03 11:39:44 +0000 | [diff] [blame] | 2021 | extent=(size_t) (q-pixels); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2022 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2023 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2024 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2025 | { |
| 2026 | if (IsPixelGray(image,p) == MagickFalse) |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2027 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p)), |
| 2028 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2029 | else |
| 2030 | { |
| 2031 | if (image->depth == 16) |
| 2032 | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
| 2033 | else |
| 2034 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2035 | } |
| 2036 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2037 | p+=GetPixelChannels(image); |
| 2038 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2039 | extent=(size_t) (q-pixels); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2040 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2041 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2042 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2043 | count=WriteBlob(image,extent,pixels); |
| 2044 | if (count != (ssize_t) extent) |
| 2045 | break; |
| 2046 | if (image->previous == (Image *) NULL) |
| 2047 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 2048 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 2049 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2050 | if (status == MagickFalse) |
| 2051 | break; |
| 2052 | } |
| 2053 | } |
| 2054 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 2055 | break; |
| 2056 | } |
| 2057 | case '6': |
| 2058 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2059 | /* |
| 2060 | Convert image to a PNM image. |
| 2061 | */ |
cristy | 3d9f5ba | 2012-06-26 13:37:31 +0000 | [diff] [blame] | 2062 | if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse) |
cristy | 8d218d7 | 2012-06-25 18:01:54 +0000 | [diff] [blame] | 2063 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2064 | if (image->depth > 32) |
| 2065 | image->depth=32; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2066 | (void) FormatLocaleString(buffer,MaxTextExtent,"%.20g\n",(double) |
cristy | 2b9582a | 2011-07-04 17:38:56 +0000 | [diff] [blame] | 2067 | ((MagickOffsetType) GetQuantumRange(image->depth))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2068 | (void) WriteBlobString(image,buffer); |
| 2069 | quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); |
| 2070 | if (quantum_info == (QuantumInfo *) NULL) |
| 2071 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
cristy | 70d7eae | 2012-11-17 19:40:21 +0000 | [diff] [blame] | 2072 | (void) SetQuantumEndian(image,quantum_info,MSBEndian); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2073 | pixels=GetQuantumPixels(quantum_info); |
| 2074 | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2075 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2076 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2077 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2078 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2079 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2080 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2081 | x; |
| 2082 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 2083 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2084 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2085 | break; |
| 2086 | q=pixels; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2087 | switch (image->depth) |
| 2088 | { |
| 2089 | case 8: |
| 2090 | case 16: |
| 2091 | case 32: |
| 2092 | { |
| 2093 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 2094 | quantum_type,pixels,exception); |
| 2095 | break; |
| 2096 | } |
| 2097 | default: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2098 | { |
| 2099 | if (image->depth <= 8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2100 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2101 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2102 | { |
| 2103 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2104 | q=PopCharPixel((unsigned char) pixel,q); |
| 2105 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
| 2106 | q=PopCharPixel((unsigned char) pixel,q); |
| 2107 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
| 2108 | q=PopCharPixel((unsigned char) pixel,q); |
| 2109 | p+=GetPixelChannels(image); |
| 2110 | } |
cristy | 5838dba | 2013-10-03 11:42:05 +0000 | [diff] [blame] | 2111 | extent=(size_t) (q-pixels); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2112 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2113 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2114 | if (image->depth <= 16) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2115 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2116 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2117 | { |
| 2118 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2119 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2120 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
| 2121 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2122 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
| 2123 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2124 | p+=GetPixelChannels(image); |
| 2125 | } |
cristy | 5838dba | 2013-10-03 11:42:05 +0000 | [diff] [blame] | 2126 | extent=(size_t) (q-pixels); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2127 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2128 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2129 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2130 | { |
| 2131 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2132 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2133 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
| 2134 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2135 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
| 2136 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2137 | p+=GetPixelChannels(image); |
| 2138 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2139 | extent=(size_t) (q-pixels); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2140 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2141 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2142 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2143 | count=WriteBlob(image,extent,pixels); |
| 2144 | if (count != (ssize_t) extent) |
| 2145 | break; |
| 2146 | if (image->previous == (Image *) NULL) |
| 2147 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 2148 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 2149 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2150 | if (status == MagickFalse) |
| 2151 | break; |
| 2152 | } |
| 2153 | } |
| 2154 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 2155 | break; |
| 2156 | } |
| 2157 | case '7': |
| 2158 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2159 | /* |
| 2160 | Convert image to a PAM. |
| 2161 | */ |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2162 | if (image->depth > 32) |
| 2163 | image->depth=32; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2164 | quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); |
| 2165 | pixels=GetQuantumPixels(quantum_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2166 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2167 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2168 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2169 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2170 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2171 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2172 | x; |
| 2173 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 2174 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2175 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2176 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2177 | q=pixels; |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2178 | switch (image->depth) |
| 2179 | { |
| 2180 | case 8: |
| 2181 | case 16: |
| 2182 | case 32: |
| 2183 | { |
| 2184 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
| 2185 | quantum_type,pixels,exception); |
| 2186 | break; |
| 2187 | } |
| 2188 | default: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2189 | { |
| 2190 | switch (quantum_type) |
| 2191 | { |
| 2192 | case GrayQuantum: |
| 2193 | case GrayAlphaQuantum: |
| 2194 | { |
| 2195 | if (image->depth <= 8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2196 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2197 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2198 | { |
| 2199 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma( |
| 2200 | image,p)),max_value); |
| 2201 | q=PopCharPixel((unsigned char) pixel,q); |
| 2202 | if (image->alpha_trait == BlendPixelTrait) |
| 2203 | { |
| 2204 | pixel=(unsigned char) ScaleQuantumToAny( |
| 2205 | GetPixelAlpha(image,p),max_value); |
| 2206 | q=PopCharPixel((unsigned char) pixel,q); |
| 2207 | } |
| 2208 | p+=GetPixelChannels(image); |
| 2209 | } |
| 2210 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2211 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2212 | if (image->depth <= 16) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2213 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2214 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2215 | { |
| 2216 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma( |
| 2217 | image,p)),max_value); |
| 2218 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2219 | if (image->alpha_trait == BlendPixelTrait) |
| 2220 | { |
| 2221 | pixel=(unsigned char) ScaleQuantumToAny( |
| 2222 | GetPixelAlpha(image,p),max_value); |
| 2223 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2224 | } |
| 2225 | p+=GetPixelChannels(image); |
| 2226 | } |
| 2227 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2228 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2229 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2230 | { |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2231 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image, |
| 2232 | p)),max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2233 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2234 | if (image->alpha_trait == BlendPixelTrait) |
| 2235 | { |
| 2236 | pixel=(unsigned char) ScaleQuantumToAny( |
| 2237 | GetPixelAlpha(image,p),max_value); |
| 2238 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2239 | } |
| 2240 | p+=GetPixelChannels(image); |
| 2241 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2242 | break; |
| 2243 | } |
| 2244 | case CMYKQuantum: |
| 2245 | case CMYKAQuantum: |
| 2246 | { |
| 2247 | if (image->depth <= 8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2248 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2249 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2250 | { |
| 2251 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2252 | q=PopCharPixel((unsigned char) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2253 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
| 2254 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2255 | q=PopCharPixel((unsigned char) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2256 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
| 2257 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2258 | q=PopCharPixel((unsigned char) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2259 | pixel=ScaleQuantumToAny(GetPixelBlack(image,p), |
| 2260 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2261 | q=PopCharPixel((unsigned char) pixel,q); |
| 2262 | if (image->alpha_trait == BlendPixelTrait) |
| 2263 | { |
| 2264 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
| 2265 | max_value); |
| 2266 | q=PopCharPixel((unsigned char) pixel,q); |
| 2267 | } |
| 2268 | p+=GetPixelChannels(image); |
| 2269 | } |
| 2270 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2271 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2272 | if (image->depth <= 16) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2273 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2274 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2275 | { |
| 2276 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2277 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2278 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
| 2279 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2280 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2281 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
| 2282 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2283 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2284 | pixel=ScaleQuantumToAny(GetPixelBlack(image,p), |
| 2285 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2286 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2287 | if (image->alpha_trait == BlendPixelTrait) |
| 2288 | { |
| 2289 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
| 2290 | max_value); |
| 2291 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2292 | } |
| 2293 | p+=GetPixelChannels(image); |
| 2294 | } |
| 2295 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2296 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2297 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2298 | { |
| 2299 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2300 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2301 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
| 2302 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2303 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
| 2304 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2305 | pixel=ScaleQuantumToAny(GetPixelBlack(image,p),max_value); |
| 2306 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2307 | if (image->alpha_trait == BlendPixelTrait) |
| 2308 | { |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2309 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
| 2310 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2311 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2312 | } |
| 2313 | p+=GetPixelChannels(image); |
| 2314 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2315 | break; |
| 2316 | } |
| 2317 | default: |
| 2318 | { |
| 2319 | if (image->depth <= 8) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2320 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2321 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2322 | { |
| 2323 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2324 | q=PopCharPixel((unsigned char) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2325 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
| 2326 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2327 | q=PopCharPixel((unsigned char) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2328 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
| 2329 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2330 | q=PopCharPixel((unsigned char) pixel,q); |
| 2331 | if (image->alpha_trait == BlendPixelTrait) |
| 2332 | { |
| 2333 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
| 2334 | max_value); |
| 2335 | q=PopCharPixel((unsigned char) pixel,q); |
| 2336 | } |
| 2337 | p+=GetPixelChannels(image); |
| 2338 | } |
| 2339 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2340 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2341 | if (image->depth <= 16) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2342 | { |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2343 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2344 | { |
| 2345 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2346 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2347 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
| 2348 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2349 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2350 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
| 2351 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2352 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2353 | if (image->alpha_trait == BlendPixelTrait) |
| 2354 | { |
| 2355 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
| 2356 | max_value); |
| 2357 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
| 2358 | } |
| 2359 | p+=GetPixelChannels(image); |
| 2360 | } |
| 2361 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2362 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2363 | for (x=0; x < (ssize_t) image->columns; x++) |
| 2364 | { |
| 2365 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
| 2366 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2367 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
| 2368 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2369 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
| 2370 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2371 | if (image->alpha_trait == BlendPixelTrait) |
| 2372 | { |
cristy | eff7fcc | 2013-09-30 10:27:08 +0000 | [diff] [blame] | 2373 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
| 2374 | max_value); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2375 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
| 2376 | } |
| 2377 | p+=GetPixelChannels(image); |
| 2378 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2379 | break; |
| 2380 | } |
| 2381 | } |
| 2382 | extent=(size_t) (q-pixels); |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2383 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2384 | } |
cristy | 67d16d9 | 2013-09-29 18:31:17 +0000 | [diff] [blame] | 2385 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2386 | count=WriteBlob(image,extent,pixels); |
| 2387 | if (count != (ssize_t) extent) |
| 2388 | break; |
| 2389 | if (image->previous == (Image *) NULL) |
| 2390 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 2391 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 2392 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2393 | if (status == MagickFalse) |
| 2394 | break; |
| 2395 | } |
| 2396 | } |
| 2397 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 2398 | break; |
| 2399 | } |
| 2400 | case 'F': |
| 2401 | case 'f': |
| 2402 | { |
cristy | 1715f79 | 2012-11-22 16:56:12 +0000 | [diff] [blame] | 2403 | (void) WriteBlobString(image,image->endian == LSBEndian ? "-1.0\n" : |
| 2404 | "1.0\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2405 | image->depth=32; |
| 2406 | quantum_type=format == 'f' ? GrayQuantum : RGBQuantum; |
| 2407 | quantum_info=AcquireQuantumInfo((const ImageInfo *) NULL,image); |
| 2408 | if (quantum_info == (QuantumInfo *) NULL) |
| 2409 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 2410 | status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); |
| 2411 | if (status == MagickFalse) |
| 2412 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
| 2413 | pixels=GetQuantumPixels(quantum_info); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2414 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2415 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2416 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 2417 | *restrict p; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2418 | |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 2419 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2420 | if (p == (const Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2421 | break; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 2422 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
cristy | 1e178e7 | 2011-08-28 19:44:34 +0000 | [diff] [blame] | 2423 | quantum_type,pixels,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2424 | (void) WriteBlob(image,extent,pixels); |
| 2425 | if (image->previous == (Image *) NULL) |
| 2426 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 2427 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
| 2428 | image->rows); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2429 | if (status == MagickFalse) |
| 2430 | break; |
| 2431 | } |
| 2432 | } |
| 2433 | quantum_info=DestroyQuantumInfo(quantum_info); |
| 2434 | break; |
| 2435 | } |
| 2436 | } |
| 2437 | if (GetNextImageInList(image) == (Image *) NULL) |
| 2438 | break; |
| 2439 | image=SyncNextImageInList(image); |
| 2440 | status=SetImageProgress(image,SaveImagesTag,scene++, |
| 2441 | GetImageListLength(image)); |
| 2442 | if (status == MagickFalse) |
| 2443 | break; |
| 2444 | } while (image_info->adjoin != MagickFalse); |
| 2445 | (void) CloseBlob(image); |
| 2446 | return(MagickTrue); |
| 2447 | } |