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