/src/imagemagick/coders/pnm.c
Line | Count | Source |
1 | | /* |
2 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
3 | | % % |
4 | | % % |
5 | | % % |
6 | | % PPPP N N M M % |
7 | | % P P NN N MM MM % |
8 | | % PPPP N N N M M M % |
9 | | % P N NN M M % |
10 | | % P N N M M % |
11 | | % % |
12 | | % % |
13 | | % Read/Write PBMPlus Portable Anymap Image Format % |
14 | | % % |
15 | | % Software Design % |
16 | | % Cristy % |
17 | | % July 1992 % |
18 | | % % |
19 | | % % |
20 | | % Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization % |
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 | | % https://imagemagick.org/script/license.php % |
27 | | % % |
28 | | % Unless required by applicable law or agreed to in writing, software % |
29 | | % distributed under the License is distributed on an "AS IS" BASIS, % |
30 | | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
31 | | % See the License for the specific language governing permissions and % |
32 | | % limitations under the License. % |
33 | | % % |
34 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
35 | | % |
36 | | % |
37 | | */ |
38 | | |
39 | | /* |
40 | | Include declarations. |
41 | | */ |
42 | | #include "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" |
50 | | #include "MagickCore/colorspace-private.h" |
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" |
68 | | #include "coders/coders-private.h" |
69 | | |
70 | | /* |
71 | | Typedef declarations. |
72 | | */ |
73 | | typedef struct _CommentInfo |
74 | | { |
75 | | char |
76 | | *comment; |
77 | | |
78 | | size_t |
79 | | extent; |
80 | | } CommentInfo; |
81 | | |
82 | | /* |
83 | | Forward declarations. |
84 | | */ |
85 | | static MagickBooleanType |
86 | | WritePNMImage(const ImageInfo *,Image *,ExceptionInfo *); |
87 | | |
88 | | /* |
89 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
90 | | % % |
91 | | % % |
92 | | % % |
93 | | % I s P N M % |
94 | | % % |
95 | | % % |
96 | | % % |
97 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
98 | | % |
99 | | % IsPNM() returns MagickTrue if the image format type, identified by the |
100 | | % magick string, is PNM. |
101 | | % |
102 | | % The format of the IsPNM method is: |
103 | | % |
104 | | % MagickBooleanType IsPNM(const unsigned char *magick,const size_t extent) |
105 | | % |
106 | | % A description of each parameter follows: |
107 | | % |
108 | | % o magick: compare image format pattern against these bytes. |
109 | | % |
110 | | % o extent: Specifies the extent of the magick string. |
111 | | % |
112 | | */ |
113 | | static MagickBooleanType IsPNM(const unsigned char *magick,const size_t extent) |
114 | 0 | { |
115 | 0 | if (extent < 2) |
116 | 0 | return(MagickFalse); |
117 | 0 | if ((*magick == (unsigned char) 'P') && |
118 | 0 | ((magick[1] == '1') || (magick[1] == '2') || (magick[1] == '3') || |
119 | 0 | (magick[1] == '4') || (magick[1] == '5') || (magick[1] == '6') || |
120 | 0 | (magick[1] == '7') || (magick[1] == 'F') || (magick[1] == 'f') || |
121 | 0 | (magick[1] == 'H') || (magick[1] == 'h'))) |
122 | 0 | return(MagickTrue); |
123 | 0 | return(MagickFalse); |
124 | 0 | } |
125 | | |
126 | | /* |
127 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
128 | | % % |
129 | | % % |
130 | | % % |
131 | | % R e a d P N M I m a g e % |
132 | | % % |
133 | | % % |
134 | | % % |
135 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
136 | | % |
137 | | % ReadPNMImage() reads a Portable Anymap image file and returns it. |
138 | | % It allocates the memory necessary for the new Image structure and returns |
139 | | % a pointer to the new image. |
140 | | % |
141 | | % The format of the ReadPNMImage method is: |
142 | | % |
143 | | % Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) |
144 | | % |
145 | | % A description of each parameter follows: |
146 | | % |
147 | | % o image_info: the image info. |
148 | | % |
149 | | % o exception: return any errors or warnings in this structure. |
150 | | % |
151 | | */ |
152 | | |
153 | | static int PNMComment(Image *image,CommentInfo *comment_info, |
154 | | ExceptionInfo *exception) |
155 | 6.05k | { |
156 | 6.05k | int |
157 | 6.05k | c; |
158 | | |
159 | 6.05k | char |
160 | 6.05k | *p; |
161 | | |
162 | | /* |
163 | | Read comment. |
164 | | */ |
165 | 6.05k | (void) exception; |
166 | 6.05k | p=comment_info->comment+strlen(comment_info->comment); |
167 | 164k | for (c='#'; (c != EOF) && (c != (int) '\n') && (c != (int) '\r'); p++) |
168 | 157k | { |
169 | 157k | if ((size_t) (p-comment_info->comment+1) >= comment_info->extent) |
170 | 11 | { |
171 | 11 | comment_info->extent<<=1; |
172 | 11 | comment_info->comment=(char *) ResizeQuantumMemory( |
173 | 11 | comment_info->comment,comment_info->extent, |
174 | 11 | sizeof(*comment_info->comment)); |
175 | 11 | if (comment_info->comment == (char *) NULL) |
176 | 0 | return(-1); |
177 | 11 | p=comment_info->comment+strlen(comment_info->comment); |
178 | 11 | } |
179 | 157k | c=ReadBlobByte(image); |
180 | 157k | if (c != EOF) |
181 | 157k | { |
182 | 157k | *p=(char) c; |
183 | 157k | *(p+1)='\0'; |
184 | 157k | } |
185 | 157k | } |
186 | 6.05k | return(c); |
187 | 6.05k | } |
188 | | |
189 | | static unsigned int PNMInteger(Image *image,CommentInfo *comment_info, |
190 | | const unsigned int base,ExceptionInfo *exception) |
191 | 166k | { |
192 | 166k | int |
193 | 166k | c; |
194 | | |
195 | 166k | unsigned int |
196 | 166k | value; |
197 | | |
198 | | /* |
199 | | Skip any leading whitespace. |
200 | | */ |
201 | 166k | do |
202 | 180k | { |
203 | 180k | c=ReadBlobByte(image); |
204 | 180k | if (c == EOF) |
205 | 2.85k | return(0); |
206 | 178k | if (c == (int) '#') |
207 | 1.75k | c=PNMComment(image,comment_info,exception); |
208 | 178k | } while ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r')); |
209 | 163k | if (base == 2) |
210 | 61.4k | return((unsigned int) (c-(int) '0')); |
211 | | /* |
212 | | Evaluate number. |
213 | | */ |
214 | 102k | value=0; |
215 | 178k | while (isdigit((int) ((unsigned char) c)) != 0) |
216 | 76.5k | { |
217 | 76.5k | if (value <= (unsigned int) (INT_MAX/10)) |
218 | 75.2k | { |
219 | 75.2k | value*=10; |
220 | 75.2k | if (value <= (unsigned int) (INT_MAX-(c-(int) '0'))) |
221 | 74.4k | value+=(unsigned int) (c-(int) '0'); |
222 | 75.2k | } |
223 | 76.5k | c=ReadBlobByte(image); |
224 | 76.5k | if (c == EOF) |
225 | 293 | return(value); |
226 | 76.5k | } |
227 | 102k | if (c == (int) '#') |
228 | 828 | c=PNMComment(image,comment_info,exception); |
229 | 102k | return(value); |
230 | 102k | } |
231 | | |
232 | | static char *PNMString(Image *image,char *string,const size_t extent) |
233 | 3.30k | { |
234 | 3.30k | int |
235 | 3.30k | c; |
236 | | |
237 | 3.30k | size_t |
238 | 3.30k | i; |
239 | | |
240 | 31.0k | for (i=0; i < (extent-1L); i++) |
241 | 30.5k | { |
242 | 30.5k | c=ReadBlobByte(image); |
243 | 30.5k | if (c == EOF) |
244 | 576 | { |
245 | 576 | if (i == 0) |
246 | 159 | return((char *) NULL); |
247 | 417 | break; |
248 | 576 | } |
249 | 30.0k | string[i]=(char) c; |
250 | 30.0k | if (c == '\n' || c == '\r') |
251 | 2.29k | break; |
252 | 30.0k | } |
253 | 3.14k | string[i]='\0'; |
254 | 3.14k | return(string); |
255 | 3.30k | } |
256 | | |
257 | | static inline MagickBooleanType PNMEOFBlob(const Image *image,ssize_t x,ssize_t y) |
258 | 127k | { |
259 | 127k | if (EOFBlob(image) == MagickFalse) |
260 | 125k | return(MagickFalse); |
261 | 1.77k | if (x < (ssize_t) image->columns-1) |
262 | 792 | return(MagickTrue); |
263 | 979 | if (y != (ssize_t) image->rows-1) |
264 | 492 | return(MagickTrue); |
265 | 487 | return(MagickFalse); |
266 | 979 | } |
267 | | |
268 | | static Image *ReadPNMImage(const ImageInfo *image_info,ExceptionInfo *exception) |
269 | 17.0k | { |
270 | 17.0k | #define ThrowPNMException(exception,message) \ |
271 | 5 | { \ |
272 | 10.1k | if (comment_info.comment != (char *) NULL) \ |
273 | 2.43k | comment_info.comment=DestroyString(comment_info.comment); \ |
274 | 10.1k | if (quantum_info != (QuantumInfo *) NULL) \ |
275 | 5 | quantum_info=DestroyQuantumInfo(quantum_info); \ |
276 | 10.1k | ThrowReaderException((exception),(message)); \ |
277 | 0 | } |
278 | | |
279 | 17.0k | char |
280 | 17.0k | format; |
281 | | |
282 | 17.0k | ColorspaceType |
283 | 17.0k | colorspace; |
284 | | |
285 | 17.0k | CommentInfo |
286 | 17.0k | comment_info; |
287 | | |
288 | 17.0k | const void |
289 | 17.0k | *stream; |
290 | | |
291 | 17.0k | double |
292 | 17.0k | quantum_scale; |
293 | | |
294 | 17.0k | Image |
295 | 17.0k | *image; |
296 | | |
297 | 17.0k | MagickBooleanType |
298 | 17.0k | is_gray = MagickTrue, |
299 | 17.0k | is_mono = MagickTrue, |
300 | 17.0k | status; |
301 | | |
302 | 17.0k | QuantumAny |
303 | 17.0k | max_value; |
304 | | |
305 | 17.0k | QuantumInfo |
306 | 17.0k | *quantum_info; |
307 | | |
308 | 17.0k | QuantumType |
309 | 17.0k | quantum_type; |
310 | | |
311 | 17.0k | size_t |
312 | 17.0k | depth, |
313 | 17.0k | extent; |
314 | | |
315 | 17.0k | ssize_t |
316 | 17.0k | count, |
317 | 17.0k | row, |
318 | 17.0k | y; |
319 | | |
320 | 17.0k | unsigned char |
321 | 17.0k | *pixels; |
322 | | |
323 | | /* |
324 | | Open image file. |
325 | | */ |
326 | 17.0k | assert(image_info != (const ImageInfo *) NULL); |
327 | 17.0k | assert(image_info->signature == MagickCoreSignature); |
328 | 17.0k | assert(exception != (ExceptionInfo *) NULL); |
329 | 17.0k | assert(exception->signature == MagickCoreSignature); |
330 | 17.0k | if (IsEventLogging() != MagickFalse) |
331 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
332 | 0 | image_info->filename); |
333 | 17.0k | image=AcquireImage(image_info,exception); |
334 | 17.0k | status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); |
335 | 17.0k | if (status == MagickFalse) |
336 | 3 | { |
337 | 3 | image=DestroyImageList(image); |
338 | 3 | return((Image *) NULL); |
339 | 3 | } |
340 | | /* |
341 | | Read PNM image. |
342 | | */ |
343 | 17.0k | comment_info.comment=(char *) NULL; |
344 | 17.0k | quantum_info=(QuantumInfo *) NULL; |
345 | 17.0k | count=ReadBlob(image,1,(unsigned char *) &format); |
346 | 17.0k | do |
347 | 19.5k | { |
348 | | /* |
349 | | Initialize image structure. |
350 | | */ |
351 | 19.5k | comment_info.comment=AcquireString(NULL); |
352 | 19.5k | comment_info.extent=MagickPathExtent; |
353 | 19.5k | if ((count != 1) || (format != 'P')) |
354 | 19.4k | ThrowPNMException(CorruptImageError,"ImproperImageHeader"); |
355 | 19.4k | max_value=1; |
356 | 19.4k | colorspace=UndefinedColorspace; |
357 | 19.4k | quantum_type=UndefinedQuantum; |
358 | 19.4k | quantum_scale=1.0; |
359 | 19.4k | format=(char) ReadBlobByte(image); |
360 | 19.4k | if (format != '7') |
361 | 15.1k | { |
362 | | /* |
363 | | PBM, PGM, PPM, and PNM. |
364 | | */ |
365 | 15.1k | if (ReadBlobByte(image) == '4') |
366 | 1.46k | image->alpha_trait=BlendPixelTrait; |
367 | 15.1k | image->columns=(size_t) PNMInteger(image,&comment_info,10,exception); |
368 | 15.1k | image->rows=(size_t) PNMInteger(image,&comment_info,10,exception); |
369 | 15.1k | if ((format == 'f') || (format == 'F') || (format == 'h') || |
370 | 12.8k | (format == 'H')) |
371 | 3.30k | { |
372 | 3.30k | char |
373 | 3.30k | scale[32]; |
374 | | |
375 | 3.30k | if (PNMString(image,scale,sizeof(scale)) != (char *) NULL) |
376 | 3.14k | quantum_scale=StringToDouble(scale,(char **) NULL); |
377 | 3.30k | } |
378 | 11.8k | else |
379 | 11.8k | { |
380 | 11.8k | if ((format == '1') || (format == '4')) |
381 | 4.96k | max_value=1; /* bitmap */ |
382 | 6.88k | else |
383 | 6.88k | max_value=(QuantumAny) PNMInteger(image,&comment_info,10, |
384 | 6.88k | exception); |
385 | 11.8k | } |
386 | 15.1k | } |
387 | 4.30k | else |
388 | 4.30k | { |
389 | 4.30k | char |
390 | 4.30k | keyword[MagickPathExtent], |
391 | 4.30k | value[MagickPathExtent]; |
392 | | |
393 | 4.30k | int |
394 | 4.30k | c; |
395 | | |
396 | 4.30k | char |
397 | 4.30k | *p; |
398 | | |
399 | | /* |
400 | | PAM. |
401 | | */ |
402 | 81.0k | for (c=ReadBlobByte(image); c != EOF; c=ReadBlobByte(image)) |
403 | 79.7k | { |
404 | 85.0k | while (isspace((int) ((unsigned char) c)) != 0) |
405 | 5.23k | c=ReadBlobByte(image); |
406 | 79.7k | if (c == '#') |
407 | 1.19k | { |
408 | | /* |
409 | | Comment. |
410 | | */ |
411 | 4.66k | while (c == '#') |
412 | 3.46k | { |
413 | 3.46k | c=PNMComment(image,&comment_info,exception); |
414 | 3.46k | c=ReadBlobByte(image); |
415 | 3.46k | } |
416 | 2.82k | while (isspace((int) ((unsigned char) c)) != 0) |
417 | 1.63k | c=ReadBlobByte(image); |
418 | 1.19k | } |
419 | 79.7k | p=keyword; |
420 | 79.7k | do |
421 | 297k | { |
422 | 297k | if ((size_t) (p-keyword) < (MagickPathExtent-1)) |
423 | 294k | *p++=(char) c; |
424 | 297k | c=ReadBlobByte(image); |
425 | 297k | } while (isalnum((int) ((unsigned char) c))); |
426 | 79.7k | *p='\0'; |
427 | 79.7k | if (LocaleCompare(keyword,"endhdr") == 0) |
428 | 3.07k | break; |
429 | 100k | while (isspace((int) ((unsigned char) c)) != 0) |
430 | 23.7k | c=ReadBlobByte(image); |
431 | 76.7k | p=value; |
432 | 256k | while (isalnum((int) ((unsigned char) c)) || (c == '_')) |
433 | 179k | { |
434 | 179k | if ((size_t) (p-value) < (MagickPathExtent-1)) |
435 | 177k | *p++=(char) c; |
436 | 179k | c=ReadBlobByte(image); |
437 | 179k | } |
438 | 76.7k | *p='\0'; |
439 | | /* |
440 | | Assign a value to the specified keyword. |
441 | | */ |
442 | 76.7k | if (LocaleCompare(keyword,"depth") == 0) |
443 | 408 | (void) StringToUnsignedLong(value); |
444 | 76.7k | if (LocaleCompare(keyword,"height") == 0) |
445 | 4.38k | image->rows=StringToUnsignedLong(value); |
446 | 76.7k | if (LocaleCompare(keyword,"maxval") == 0) |
447 | 2.92k | max_value=StringToUnsignedLong(value); |
448 | 76.7k | if ((quantum_type == UndefinedQuantum) && |
449 | 46.9k | (LocaleCompare(keyword,"TUPLTYPE") == 0)) |
450 | 2.89k | { |
451 | 2.89k | if (LocaleCompare(value,"BLACKANDWHITE") == 0) |
452 | 40 | { |
453 | 40 | colorspace=GRAYColorspace; |
454 | 40 | quantum_type=GrayQuantum; |
455 | 40 | } |
456 | 2.89k | if (LocaleCompare(value,"BLACKANDWHITE_ALPHA") == 0) |
457 | 62 | { |
458 | 62 | colorspace=GRAYColorspace; |
459 | 62 | image->alpha_trait=BlendPixelTrait; |
460 | 62 | quantum_type=GrayAlphaQuantum; |
461 | 62 | } |
462 | 2.89k | if (LocaleCompare(value,"GRAYSCALE") == 0) |
463 | 404 | { |
464 | 404 | colorspace=GRAYColorspace; |
465 | 404 | quantum_type=GrayQuantum; |
466 | 404 | } |
467 | 2.89k | if (LocaleCompare(value,"GRAYSCALE_ALPHA") == 0) |
468 | 428 | { |
469 | 428 | colorspace=GRAYColorspace; |
470 | 428 | image->alpha_trait=BlendPixelTrait; |
471 | 428 | quantum_type=GrayAlphaQuantum; |
472 | 428 | } |
473 | 2.89k | if (LocaleCompare(value,"RGB_ALPHA") == 0) |
474 | 363 | { |
475 | 363 | image->alpha_trait=BlendPixelTrait; |
476 | 363 | quantum_type=RGBAQuantum; |
477 | 363 | } |
478 | 2.89k | if (LocaleCompare(value,"CMYK") == 0) |
479 | 716 | { |
480 | 716 | colorspace=CMYKColorspace; |
481 | 716 | quantum_type=CMYKQuantum; |
482 | 716 | } |
483 | 2.89k | if (LocaleCompare(value,"CMYK_ALPHA") == 0) |
484 | 439 | { |
485 | 439 | colorspace=CMYKColorspace; |
486 | 439 | image->alpha_trait=BlendPixelTrait; |
487 | 439 | quantum_type=CMYKAQuantum; |
488 | 439 | } |
489 | 2.89k | } |
490 | 76.7k | if (LocaleCompare(keyword,"width") == 0) |
491 | 4.53k | image->columns=StringToUnsignedLong(value); |
492 | 76.7k | } |
493 | 4.30k | } |
494 | 19.4k | if (quantum_type == UndefinedQuantum) |
495 | 17.0k | quantum_type=RGBQuantum; |
496 | 19.4k | if ((image->columns == 0) || (image->rows == 0)) |
497 | 17.6k | ThrowPNMException(CorruptImageError,"NegativeOrZeroImageSize"); |
498 | 17.6k | if ((max_value == 0) || (max_value > 4294967295UL)) |
499 | 17.4k | ThrowPNMException(CorruptImageError,"ImproperImageHeader"); |
500 | 108k | for (depth=1; GetQuantumRange(depth) < max_value; depth++) ; |
501 | 17.4k | image->depth=depth; |
502 | 17.4k | if ((image_info->ping != MagickFalse) && (image_info->number_scenes != 0)) |
503 | 0 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
504 | 0 | break; |
505 | 17.4k | if ((MagickSizeType) (image->columns*image->rows/8) > GetBlobSize(image)) |
506 | 17.1k | ThrowPNMException(CorruptImageError,"InsufficientImageDataInFile"); |
507 | 17.1k | status=SetImageExtent(image,image->columns,image->rows,exception); |
508 | 17.1k | if (status == MagickFalse) |
509 | 300 | { |
510 | 300 | if (comment_info.comment != (char *) NULL) |
511 | 300 | comment_info.comment=DestroyString(comment_info.comment); |
512 | 300 | if (quantum_info != (QuantumInfo *) NULL) |
513 | 0 | quantum_info=DestroyQuantumInfo(quantum_info); |
514 | 300 | return(DestroyImageList(image)); |
515 | 300 | } |
516 | 16.8k | if (colorspace != UndefinedColorspace) |
517 | 2.02k | (void) SetImageColorspace(image,colorspace,exception); |
518 | 16.8k | (void) ResetImagePixels(image,exception); |
519 | | /* |
520 | | Convert PNM pixels to runextent-encoded MIFF packets. |
521 | | */ |
522 | 16.8k | row=0; |
523 | 16.8k | y=0; |
524 | 16.8k | switch (format) |
525 | 16.8k | { |
526 | 830 | case '1': |
527 | 830 | { |
528 | | /* |
529 | | Convert PBM image to pixel packets. |
530 | | */ |
531 | 830 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
532 | 22.5k | for (y=0; y < (ssize_t) image->rows; y++) |
533 | 21.9k | { |
534 | 21.9k | ssize_t |
535 | 21.9k | x; |
536 | | |
537 | 21.9k | Quantum |
538 | 21.9k | *magick_restrict q; |
539 | | |
540 | 21.9k | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
541 | 21.9k | if (q == (Quantum *) NULL) |
542 | 0 | break; |
543 | 83.4k | for (x=0; x < (ssize_t) image->columns; x++) |
544 | 61.6k | { |
545 | 61.6k | SetPixelGray(image,PNMInteger(image,&comment_info,2,exception) == |
546 | 61.6k | 0 ? QuantumRange : 0,q); |
547 | 61.6k | if (PNMEOFBlob(image,x,y) != MagickFalse) |
548 | 215 | break; |
549 | 61.4k | q+=(ptrdiff_t) GetPixelChannels(image); |
550 | 61.4k | } |
551 | 21.9k | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
552 | 0 | break; |
553 | 21.9k | if (image->previous == (Image *) NULL) |
554 | 21.3k | { |
555 | 21.3k | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
556 | 21.3k | image->rows); |
557 | 21.3k | if (status == MagickFalse) |
558 | 0 | break; |
559 | 21.3k | } |
560 | 21.9k | if (PNMEOFBlob(image,x,y) != MagickFalse) |
561 | 215 | break; |
562 | 21.9k | } |
563 | 830 | image->type=BilevelType; |
564 | 830 | break; |
565 | 0 | } |
566 | 342 | case '2': |
567 | 342 | { |
568 | 342 | Quantum |
569 | 342 | intensity; |
570 | | |
571 | | /* |
572 | | Convert PGM image to pixel packets. |
573 | | */ |
574 | 342 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
575 | 6.28k | for (y=0; y < (ssize_t) image->rows; y++) |
576 | 6.10k | { |
577 | 6.10k | ssize_t |
578 | 6.10k | x; |
579 | | |
580 | 6.10k | Quantum |
581 | 6.10k | *magick_restrict q; |
582 | | |
583 | 6.10k | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
584 | 6.10k | if (q == (Quantum *) NULL) |
585 | 0 | break; |
586 | 20.0k | for (x=0; x < (ssize_t) image->columns; x++) |
587 | 14.0k | { |
588 | 14.0k | intensity=ScaleAnyToQuantum(PNMInteger(image,&comment_info,10, |
589 | 14.0k | exception),max_value); |
590 | 14.0k | if (PNMEOFBlob(image,x,y) != MagickFalse) |
591 | 161 | break; |
592 | 13.9k | SetPixelGray(image,intensity,q); |
593 | 13.9k | q+=(ptrdiff_t) GetPixelChannels(image); |
594 | 13.9k | } |
595 | 6.10k | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
596 | 0 | break; |
597 | 6.10k | if (image->previous == (Image *) NULL) |
598 | 5.14k | { |
599 | 5.14k | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
600 | 5.14k | image->rows); |
601 | 5.14k | if (status == MagickFalse) |
602 | 0 | break; |
603 | 5.14k | } |
604 | 6.10k | if (PNMEOFBlob(image,x,y) != MagickFalse) |
605 | 161 | break; |
606 | 6.10k | } |
607 | 342 | image->type=GrayscaleType; |
608 | 342 | break; |
609 | 0 | } |
610 | 603 | case '3': |
611 | 603 | { |
612 | | /* |
613 | | Convert PNM image to pixel packets. |
614 | | */ |
615 | 5.82k | for (y=0; y < (ssize_t) image->rows; y++) |
616 | 5.50k | { |
617 | 5.50k | Quantum |
618 | 5.50k | *magick_restrict q; |
619 | | |
620 | 5.50k | ssize_t |
621 | 5.50k | x; |
622 | | |
623 | 5.50k | q=QueueAuthenticPixels(image,0,y,image->columns,1,exception); |
624 | 5.50k | if (q == (Quantum *) NULL) |
625 | 0 | break; |
626 | 23.3k | for (x=0; x < (ssize_t) image->columns; x++) |
627 | 18.1k | { |
628 | 18.1k | Quantum |
629 | 18.1k | pixel; |
630 | | |
631 | 18.1k | pixel=ScaleAnyToQuantum(PNMInteger(image,&comment_info,10, |
632 | 18.1k | exception),max_value); |
633 | 18.1k | if (PNMEOFBlob(image,x,y) != MagickFalse) |
634 | 249 | break; |
635 | 17.8k | SetPixelRed(image,pixel,q); |
636 | 17.8k | pixel=ScaleAnyToQuantum(PNMInteger(image,&comment_info,10, |
637 | 17.8k | exception),max_value); |
638 | 17.8k | SetPixelGreen(image,pixel,q); |
639 | 17.8k | pixel=ScaleAnyToQuantum(PNMInteger(image,&comment_info,10, |
640 | 17.8k | exception),max_value); |
641 | 17.8k | SetPixelBlue(image,pixel,q); |
642 | 17.8k | if ((is_gray != MagickFalse) && |
643 | 4.73k | (IsPixelGray(image,q) == MagickFalse)) |
644 | 327 | is_gray=MagickFalse; |
645 | 17.8k | if ((is_mono != MagickFalse) && |
646 | 4.73k | (IsPixelMonochrome(image,q) == MagickFalse)) |
647 | 327 | is_mono=MagickFalse; |
648 | 17.8k | q+=(ptrdiff_t) GetPixelChannels(image); |
649 | 17.8k | } |
650 | 5.50k | if (SyncAuthenticPixels(image,exception) == MagickFalse) |
651 | 0 | break; |
652 | 5.50k | if (image->previous == (Image *) NULL) |
653 | 4.91k | { |
654 | 4.91k | status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y, |
655 | 4.91k | image->rows); |
656 | 4.91k | if (status == MagickFalse) |
657 | 0 | break; |
658 | 4.91k | } |
659 | 5.50k | if (PNMEOFBlob(image,x,y) != MagickFalse) |
660 | 283 | break; |
661 | 5.50k | } |
662 | 603 | if (is_gray != MagickFalse) |
663 | 238 | image->type=GrayscaleType; |
664 | 603 | if (is_mono != MagickFalse) |
665 | 238 | image->type=BilevelType; |
666 | 603 | break; |
667 | 0 | } |
668 | 3.58k | case '4': |
669 | 3.58k | { |
670 | | /* |
671 | | Convert PBM raw image to pixel packets. |
672 | | */ |
673 | 3.58k | (void) SetImageColorspace(image,GRAYColorspace,exception); |
674 | 3.58k | quantum_type=GrayQuantum; |
675 | 3.58k | if (image->storage_class == PseudoClass) |
676 | 0 | quantum_type=IndexQuantum; |
677 | 3.58k | quantum_info=AcquireQuantumInfo(image_info,image); |
678 | 3.58k | if (quantum_info == (QuantumInfo *) NULL) |
679 | 3.58k | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
680 | 3.58k | SetQuantumMinIsWhite(quantum_info,MagickTrue); |
681 | 3.58k | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
682 | 3.58k | pixels=GetQuantumPixels(quantum_info); |
683 | 96.0k | for (y=0; y < (ssize_t) image->rows; y++) |
684 | 92.5k | { |
685 | 92.5k | MagickBooleanType |
686 | 92.5k | sync; |
687 | | |
688 | 92.5k | Quantum |
689 | 92.5k | *magick_restrict q; |
690 | | |
691 | 92.5k | ssize_t |
692 | 92.5k | offset; |
693 | | |
694 | 92.5k | size_t |
695 | 92.5k | length; |
696 | | |
697 | 92.5k | stream=ReadBlobStream(image,extent,pixels,&count); |
698 | 92.5k | if (count != (ssize_t) extent) |
699 | 117 | break; |
700 | 92.4k | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
701 | 0 | (image->previous == (Image *) NULL)) |
702 | 0 | { |
703 | 0 | MagickBooleanType |
704 | 0 | proceed; |
705 | |
|
706 | 0 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
707 | 0 | row,image->rows); |
708 | 0 | if (proceed == MagickFalse) |
709 | 0 | break; |
710 | 0 | } |
711 | 92.4k | offset=row++; |
712 | 92.4k | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
713 | 92.4k | if (q == (Quantum *) NULL) |
714 | 0 | break; |
715 | 92.4k | length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
716 | 92.4k | quantum_type,(unsigned char *) stream,exception); |
717 | 92.4k | if (length != extent) |
718 | 0 | break; |
719 | 92.4k | sync=SyncAuthenticPixels(image,exception); |
720 | 92.4k | if (sync == MagickFalse) |
721 | 0 | break; |
722 | 92.4k | } |
723 | 3.58k | quantum_info=DestroyQuantumInfo(quantum_info); |
724 | 3.58k | SetQuantumImageType(image,quantum_type); |
725 | 3.58k | break; |
726 | 3.58k | } |
727 | 1.17k | case '5': |
728 | 1.17k | { |
729 | | /* |
730 | | Convert PGM raw image to pixel packets. |
731 | | */ |
732 | 1.17k | (void) SetImageColorspace(image,GRAYColorspace,exception); |
733 | 1.17k | quantum_type=GrayQuantum; |
734 | 1.17k | extent=(image->depth <= 8 ? 1 : image->depth <= 16 ? 2 : 4)* |
735 | 1.17k | image->columns; |
736 | 1.17k | quantum_info=AcquireQuantumInfo(image_info,image); |
737 | 1.17k | if (quantum_info == (QuantumInfo *) NULL) |
738 | 1.17k | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
739 | 1.17k | pixels=GetQuantumPixels(quantum_info); |
740 | 13.2k | for (y=0; y < (ssize_t) image->rows; y++) |
741 | 12.6k | { |
742 | 12.6k | const unsigned char |
743 | 12.6k | *magick_restrict p; |
744 | | |
745 | 12.6k | MagickBooleanType |
746 | 12.6k | sync; |
747 | | |
748 | 12.6k | Quantum |
749 | 12.6k | *magick_restrict q; |
750 | | |
751 | 12.6k | ssize_t |
752 | 12.6k | offset, |
753 | 12.6k | x; |
754 | | |
755 | 12.6k | stream=ReadBlobStream(image,extent,pixels,&count); |
756 | 12.6k | if (count != (ssize_t) extent) |
757 | 595 | break; |
758 | 12.0k | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
759 | 0 | (image->previous == (Image *) NULL)) |
760 | 0 | { |
761 | 0 | MagickBooleanType |
762 | 0 | proceed; |
763 | |
|
764 | 0 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
765 | 0 | row,image->rows); |
766 | 0 | if (proceed == MagickFalse) |
767 | 0 | break; |
768 | 0 | } |
769 | 12.0k | offset=row++; |
770 | 12.0k | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
771 | 12.0k | if (q == (Quantum *) NULL) |
772 | 0 | break; |
773 | 12.0k | p=(unsigned char *) stream; |
774 | 12.0k | switch (image->depth) |
775 | 12.0k | { |
776 | 1.32k | case 8: |
777 | 1.92k | case 16: |
778 | 1.92k | case 32: |
779 | 1.92k | { |
780 | 1.92k | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
781 | 1.92k | quantum_type,(unsigned char *) stream,exception); |
782 | 1.92k | break; |
783 | 1.92k | } |
784 | 10.1k | default: |
785 | 10.1k | { |
786 | 10.1k | switch (image->depth) |
787 | 10.1k | { |
788 | 570 | case 1: |
789 | 1.20k | case 2: |
790 | 2.33k | case 3: |
791 | 3.07k | case 4: |
792 | 3.61k | case 5: |
793 | 5.32k | case 6: |
794 | 5.84k | case 7: |
795 | 5.84k | { |
796 | 5.84k | unsigned char |
797 | 5.84k | pixel; |
798 | | |
799 | 21.3k | for (x=0; x < (ssize_t) image->columns; x++) |
800 | 15.4k | { |
801 | 15.4k | p=PushCharPixel(p,&pixel); |
802 | 15.4k | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
803 | 15.4k | q+=(ptrdiff_t) GetPixelChannels(image); |
804 | 15.4k | } |
805 | 5.84k | break; |
806 | 5.32k | } |
807 | 519 | case 9: |
808 | 1.21k | case 10: |
809 | 1.60k | case 11: |
810 | 2.04k | case 12: |
811 | 2.45k | case 13: |
812 | 2.83k | case 14: |
813 | 3.23k | case 15: |
814 | 3.23k | { |
815 | 3.23k | unsigned short |
816 | 3.23k | pixel; |
817 | | |
818 | 8.64k | for (x=0; x < (ssize_t) image->columns; x++) |
819 | 5.40k | { |
820 | 5.40k | p=PushShortPixel(MSBEndian,p,&pixel); |
821 | 5.40k | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
822 | 5.40k | q+=(ptrdiff_t) GetPixelChannels(image); |
823 | 5.40k | } |
824 | 3.23k | break; |
825 | 2.83k | } |
826 | 1.06k | default: |
827 | 1.06k | { |
828 | 1.06k | unsigned int |
829 | 1.06k | pixel; |
830 | | |
831 | 3.83k | for (x=0; x < (ssize_t) image->columns; x++) |
832 | 2.76k | { |
833 | 2.76k | p=PushLongPixel(MSBEndian,p,&pixel); |
834 | 2.76k | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value),q); |
835 | 2.76k | q+=(ptrdiff_t) GetPixelChannels(image); |
836 | 2.76k | } |
837 | 1.06k | break; |
838 | 2.83k | } |
839 | 10.1k | } |
840 | 10.1k | break; |
841 | 10.1k | } |
842 | 12.0k | } |
843 | 12.0k | sync=SyncAuthenticPixels(image,exception); |
844 | 12.0k | if (sync == MagickFalse) |
845 | 0 | break; |
846 | 12.0k | } |
847 | 1.17k | quantum_info=DestroyQuantumInfo(quantum_info); |
848 | 1.17k | SetQuantumImageType(image,quantum_type); |
849 | 1.17k | break; |
850 | 1.17k | } |
851 | 4.39k | case '6': |
852 | 4.39k | { |
853 | | /* |
854 | | Convert PNM raster image to pixel packets. |
855 | | */ |
856 | 4.39k | quantum_type=RGBQuantum; |
857 | 4.39k | extent=3*(size_t) (image->depth <= 8 ? 1 : image->depth <= 16 ? 2 : 4)* |
858 | 4.39k | image->columns; |
859 | 4.39k | quantum_info=AcquireQuantumInfo(image_info,image); |
860 | 4.39k | if (quantum_info == (QuantumInfo *) NULL) |
861 | 4.39k | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
862 | 4.39k | (void) SetQuantumEndian(image,quantum_info,MSBEndian); |
863 | 4.39k | pixels=GetQuantumPixels(quantum_info); |
864 | 29.3k | for (y=0; y < (ssize_t) image->rows; y++) |
865 | 27.8k | { |
866 | 27.8k | const unsigned char |
867 | 27.8k | *magick_restrict p; |
868 | | |
869 | 27.8k | MagickBooleanType |
870 | 27.8k | sync; |
871 | | |
872 | 27.8k | Quantum |
873 | 27.8k | *magick_restrict q; |
874 | | |
875 | 27.8k | ssize_t |
876 | 27.8k | offset, |
877 | 27.8k | x; |
878 | | |
879 | 27.8k | stream=ReadBlobStream(image,extent,pixels,&count); |
880 | 27.8k | if (count != (ssize_t) extent) |
881 | 2.96k | break; |
882 | 24.9k | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
883 | 0 | (image->previous == (Image *) NULL)) |
884 | 0 | { |
885 | 0 | MagickBooleanType |
886 | 0 | proceed; |
887 | |
|
888 | 0 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
889 | 0 | row,image->rows); |
890 | 0 | if (proceed == MagickFalse) |
891 | 0 | break; |
892 | 0 | } |
893 | 24.9k | offset=row++; |
894 | 24.9k | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
895 | 24.9k | if (q == (Quantum *) NULL) |
896 | 0 | break; |
897 | 24.9k | p=(unsigned char *) stream; |
898 | 24.9k | switch (image->depth) |
899 | 24.9k | { |
900 | 864 | case 1: |
901 | 2.63k | case 2: |
902 | 5.43k | case 3: |
903 | 6.34k | case 4: |
904 | 8.02k | case 5: |
905 | 11.6k | case 6: |
906 | 12.2k | case 7: |
907 | 12.2k | { |
908 | 12.2k | unsigned char |
909 | 12.2k | pixel; |
910 | | |
911 | 46.9k | for (x=0; x < (ssize_t) image->columns; x++) |
912 | 34.6k | { |
913 | 34.6k | p=PushCharPixel(p,&pixel); |
914 | 34.6k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
915 | 34.6k | p=PushCharPixel(p,&pixel); |
916 | 34.6k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
917 | 34.6k | p=PushCharPixel(p,&pixel); |
918 | 34.6k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
919 | 34.6k | SetPixelAlpha(image,OpaqueAlpha,q); |
920 | 34.6k | if ((is_gray != MagickFalse) && |
921 | 4.05k | (IsPixelGray(image,q) == MagickFalse)) |
922 | 1.39k | is_gray=MagickFalse; |
923 | 34.6k | if ((is_mono != MagickFalse) && |
924 | 4.01k | (IsPixelMonochrome(image,q) == MagickFalse)) |
925 | 1.39k | is_mono=MagickFalse; |
926 | 34.6k | q+=(ptrdiff_t) GetPixelChannels(image); |
927 | 34.6k | } |
928 | 12.2k | break; |
929 | 11.6k | } |
930 | 1.10k | case 8: |
931 | 1.10k | { |
932 | 3.99k | for (x=0; x < (ssize_t) image->columns; x++) |
933 | 2.89k | { |
934 | 2.89k | SetPixelRed(image,ScaleCharToQuantum(*p++),q); |
935 | 2.89k | SetPixelGreen(image,ScaleCharToQuantum(*p++),q); |
936 | 2.89k | SetPixelBlue(image,ScaleCharToQuantum(*p++),q); |
937 | 2.89k | SetPixelAlpha(image,OpaqueAlpha,q); |
938 | 2.89k | if ((is_gray != MagickFalse) && |
939 | 968 | (IsPixelGray(image,q) == MagickFalse)) |
940 | 89 | is_gray=MagickFalse; |
941 | 2.89k | if ((is_mono != MagickFalse) && |
942 | 717 | (IsPixelMonochrome(image,q) == MagickFalse)) |
943 | 91 | is_mono=MagickFalse; |
944 | 2.89k | q+=(ptrdiff_t) GetPixelChannels(image); |
945 | 2.89k | } |
946 | 1.10k | break; |
947 | 11.6k | } |
948 | 2.48k | case 9: |
949 | 3.49k | case 10: |
950 | 3.89k | case 11: |
951 | 4.48k | case 12: |
952 | 5.42k | case 13: |
953 | 6.16k | case 14: |
954 | 6.64k | case 15: |
955 | 6.64k | { |
956 | 6.64k | unsigned short |
957 | 6.64k | pixel; |
958 | | |
959 | 23.8k | for (x=0; x < (ssize_t) image->columns; x++) |
960 | 17.1k | { |
961 | 17.1k | p=PushShortPixel(MSBEndian,p,&pixel); |
962 | 17.1k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
963 | 17.1k | p=PushShortPixel(MSBEndian,p,&pixel); |
964 | 17.1k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
965 | 17.1k | p=PushShortPixel(MSBEndian,p,&pixel); |
966 | 17.1k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
967 | 17.1k | SetPixelAlpha(image,OpaqueAlpha,q); |
968 | 17.1k | if ((is_gray != MagickFalse) && |
969 | 4.03k | (IsPixelGray(image,q) == MagickFalse)) |
970 | 1.25k | is_gray=MagickFalse; |
971 | 17.1k | if ((is_mono != MagickFalse) && |
972 | 4.02k | (IsPixelMonochrome(image,q) == MagickFalse)) |
973 | 1.25k | is_mono=MagickFalse; |
974 | 17.1k | q+=(ptrdiff_t) GetPixelChannels(image); |
975 | 17.1k | } |
976 | 6.64k | break; |
977 | 6.16k | } |
978 | 2.59k | case 16: |
979 | 2.59k | { |
980 | 2.59k | unsigned short |
981 | 2.59k | pixel; |
982 | | |
983 | 10.6k | for (x=0; x < (ssize_t) image->columns; x++) |
984 | 8.04k | { |
985 | 8.04k | p=PushShortPixel(MSBEndian,p,&pixel); |
986 | 8.04k | SetPixelRed(image,ScaleShortToQuantum(pixel),q); |
987 | 8.04k | p=PushShortPixel(MSBEndian,p,&pixel); |
988 | 8.04k | SetPixelGreen(image,ScaleShortToQuantum(pixel),q); |
989 | 8.04k | p=PushShortPixel(MSBEndian,p,&pixel); |
990 | 8.04k | SetPixelBlue(image,ScaleShortToQuantum(pixel),q); |
991 | 8.04k | SetPixelAlpha(image,OpaqueAlpha,q); |
992 | 8.04k | if ((is_gray != MagickFalse) && |
993 | 1.75k | (IsPixelGray(image,q) == MagickFalse)) |
994 | 545 | is_gray=MagickFalse; |
995 | 8.04k | if ((is_mono != MagickFalse) && |
996 | 1.73k | (IsPixelMonochrome(image,q) == MagickFalse)) |
997 | 545 | is_mono=MagickFalse; |
998 | 8.04k | q+=(ptrdiff_t) GetPixelChannels(image); |
999 | 8.04k | } |
1000 | 2.59k | break; |
1001 | 6.16k | } |
1002 | 0 | case 32: |
1003 | 0 | { |
1004 | 0 | unsigned int |
1005 | 0 | pixel; |
1006 | |
|
1007 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
1008 | 0 | { |
1009 | 0 | p=PushLongPixel(MSBEndian,p,&pixel); |
1010 | 0 | SetPixelRed(image,ScaleLongToQuantum(pixel),q); |
1011 | 0 | p=PushLongPixel(MSBEndian,p,&pixel); |
1012 | 0 | SetPixelGreen(image,ScaleLongToQuantum(pixel),q); |
1013 | 0 | p=PushLongPixel(MSBEndian,p,&pixel); |
1014 | 0 | SetPixelBlue(image,ScaleLongToQuantum(pixel),q); |
1015 | 0 | SetPixelAlpha(image,OpaqueAlpha,q); |
1016 | 0 | if ((is_gray != MagickFalse) && |
1017 | 0 | (IsPixelGray(image,q) == MagickFalse)) |
1018 | 0 | is_gray=MagickFalse; |
1019 | 0 | if ((is_mono != MagickFalse) && |
1020 | 0 | (IsPixelMonochrome(image,q) == MagickFalse)) |
1021 | 0 | is_mono=MagickFalse; |
1022 | 0 | q+=(ptrdiff_t) GetPixelChannels(image); |
1023 | 0 | } |
1024 | 0 | break; |
1025 | 6.16k | } |
1026 | 2.27k | default: |
1027 | 2.27k | { |
1028 | 2.27k | unsigned int |
1029 | 2.27k | pixel; |
1030 | | |
1031 | 8.26k | for (x=0; x < (ssize_t) image->columns; x++) |
1032 | 5.99k | { |
1033 | 5.99k | p=PushLongPixel(MSBEndian,p,&pixel); |
1034 | 5.99k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
1035 | 5.99k | p=PushLongPixel(MSBEndian,p,&pixel); |
1036 | 5.99k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value),q); |
1037 | 5.99k | p=PushLongPixel(MSBEndian,p,&pixel); |
1038 | 5.99k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value),q); |
1039 | 5.99k | SetPixelAlpha(image,OpaqueAlpha,q); |
1040 | 5.99k | if ((is_gray != MagickFalse) && |
1041 | 3.19k | (IsPixelGray(image,q) == MagickFalse)) |
1042 | 497 | is_gray=MagickFalse; |
1043 | 5.99k | if ((is_mono != MagickFalse) && |
1044 | 3.19k | (IsPixelMonochrome(image,q) == MagickFalse)) |
1045 | 497 | is_mono=MagickFalse; |
1046 | 5.99k | q+=(ptrdiff_t) GetPixelChannels(image); |
1047 | 5.99k | } |
1048 | 2.27k | break; |
1049 | 6.16k | } |
1050 | 24.9k | } |
1051 | 24.9k | sync=SyncAuthenticPixels(image,exception); |
1052 | 24.9k | if (sync == MagickFalse) |
1053 | 0 | break; |
1054 | 24.9k | } |
1055 | 4.39k | if (is_gray != MagickFalse) |
1056 | 544 | image->type=GrayscaleType; |
1057 | 4.39k | if (is_mono != MagickFalse) |
1058 | 540 | image->type=BilevelType; |
1059 | 4.39k | quantum_info=DestroyQuantumInfo(quantum_info); |
1060 | 4.39k | break; |
1061 | 4.39k | } |
1062 | 3.14k | case '7': |
1063 | 3.14k | { |
1064 | 3.14k | size_t |
1065 | 3.14k | channels; |
1066 | | |
1067 | | /* |
1068 | | Convert PAM raster image to pixel packets. |
1069 | | */ |
1070 | 3.14k | switch (quantum_type) |
1071 | 3.14k | { |
1072 | 428 | case GrayQuantum: |
1073 | 902 | case GrayAlphaQuantum: |
1074 | 902 | { |
1075 | 902 | channels=1; |
1076 | 902 | break; |
1077 | 428 | } |
1078 | 693 | case CMYKQuantum: |
1079 | 1.12k | case CMYKAQuantum: |
1080 | 1.12k | { |
1081 | 1.12k | channels=4; |
1082 | 1.12k | break; |
1083 | 693 | } |
1084 | 1.11k | default: |
1085 | 1.11k | { |
1086 | 1.11k | channels=3; |
1087 | 1.11k | break; |
1088 | 693 | } |
1089 | 3.14k | } |
1090 | 3.14k | if (image->alpha_trait != UndefinedPixelTrait) |
1091 | 1.25k | channels++; |
1092 | 3.14k | extent=channels*(image->depth <= 8 ? 1 : image->depth <= 16 ? 2 : 4)* |
1093 | 3.14k | image->columns; |
1094 | 3.14k | quantum_info=AcquireQuantumInfo(image_info,image); |
1095 | 3.14k | if (quantum_info == (QuantumInfo *) NULL) |
1096 | 3.14k | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
1097 | 3.14k | pixels=GetQuantumPixels(quantum_info); |
1098 | 59.2k | for (y=0; y < (ssize_t) image->rows; y++) |
1099 | 58.0k | { |
1100 | 58.0k | const unsigned char |
1101 | 58.0k | *magick_restrict p; |
1102 | | |
1103 | 58.0k | MagickBooleanType |
1104 | 58.0k | sync; |
1105 | | |
1106 | 58.0k | Quantum |
1107 | 58.0k | *magick_restrict q; |
1108 | | |
1109 | 58.0k | ssize_t |
1110 | 58.0k | offset, |
1111 | 58.0k | x; |
1112 | | |
1113 | 58.0k | stream=ReadBlobStream(image,extent,pixels,&count); |
1114 | 58.0k | if (count != (ssize_t) extent) |
1115 | 1.95k | break; |
1116 | 56.0k | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
1117 | 0 | (image->previous == (Image *) NULL)) |
1118 | 0 | { |
1119 | 0 | MagickBooleanType |
1120 | 0 | proceed; |
1121 | |
|
1122 | 0 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
1123 | 0 | row,image->rows); |
1124 | 0 | if (proceed == MagickFalse) |
1125 | 0 | break; |
1126 | 0 | } |
1127 | 56.0k | offset=row++; |
1128 | 56.0k | q=QueueAuthenticPixels(image,0,offset,image->columns,1,exception); |
1129 | 56.0k | if (q == (Quantum *) NULL) |
1130 | 0 | break; |
1131 | 56.0k | p=(unsigned char *) stream; |
1132 | 56.0k | switch (image->depth) |
1133 | 56.0k | { |
1134 | 4.14k | case 8: |
1135 | 10.8k | case 16: |
1136 | 16.0k | case 32: |
1137 | 16.0k | { |
1138 | 16.0k | (void) ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
1139 | 16.0k | quantum_type,(unsigned char *) stream,exception); |
1140 | 16.0k | break; |
1141 | 10.8k | } |
1142 | 39.9k | default: |
1143 | 39.9k | { |
1144 | 39.9k | switch (quantum_type) |
1145 | 39.9k | { |
1146 | 10.4k | case GrayQuantum: |
1147 | 15.0k | case GrayAlphaQuantum: |
1148 | 15.0k | { |
1149 | 15.0k | switch (image->depth) |
1150 | 15.0k | { |
1151 | 2.53k | case 1: |
1152 | 3.43k | case 2: |
1153 | 3.86k | case 3: |
1154 | 4.95k | case 4: |
1155 | 5.36k | case 5: |
1156 | 6.27k | case 6: |
1157 | 7.16k | case 7: |
1158 | 7.16k | case 8: |
1159 | 7.16k | { |
1160 | 7.16k | unsigned char |
1161 | 7.16k | pixel; |
1162 | | |
1163 | 23.8k | for (x=0; x < (ssize_t) image->columns; x++) |
1164 | 16.6k | { |
1165 | 16.6k | p=PushCharPixel(p,&pixel); |
1166 | 16.6k | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value), |
1167 | 16.6k | q); |
1168 | 16.6k | SetPixelAlpha(image,OpaqueAlpha,q); |
1169 | 16.6k | if (image->alpha_trait != UndefinedPixelTrait) |
1170 | 4.84k | { |
1171 | 4.84k | p=PushCharPixel(p,&pixel); |
1172 | 4.84k | if (image->depth != 1) |
1173 | 1.98k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1174 | 1.98k | max_value),q); |
1175 | 2.86k | else |
1176 | 2.86k | SetPixelAlpha(image,QuantumRange- |
1177 | 2.86k | ScaleAnyToQuantum(pixel,max_value),q); |
1178 | 4.84k | } |
1179 | 16.6k | q+=(ptrdiff_t) GetPixelChannels(image); |
1180 | 16.6k | } |
1181 | 7.16k | break; |
1182 | 7.16k | } |
1183 | 657 | case 9: |
1184 | 1.52k | case 10: |
1185 | 2.66k | case 11: |
1186 | 3.50k | case 12: |
1187 | 3.91k | case 13: |
1188 | 4.31k | case 14: |
1189 | 5.20k | case 15: |
1190 | 5.20k | case 16: |
1191 | 5.20k | { |
1192 | 5.20k | unsigned short |
1193 | 5.20k | pixel; |
1194 | | |
1195 | 13.4k | for (x=0; x < (ssize_t) image->columns; x++) |
1196 | 8.26k | { |
1197 | 8.26k | p=PushShortPixel(MSBEndian,p,&pixel); |
1198 | 8.26k | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value), |
1199 | 8.26k | q); |
1200 | 8.26k | SetPixelAlpha(image,OpaqueAlpha,q); |
1201 | 8.26k | if (image->alpha_trait != UndefinedPixelTrait) |
1202 | 1.90k | { |
1203 | 1.90k | p=PushShortPixel(MSBEndian,p,&pixel); |
1204 | 1.90k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1205 | 1.90k | max_value),q); |
1206 | 1.90k | } |
1207 | 8.26k | q+=(ptrdiff_t) GetPixelChannels(image); |
1208 | 8.26k | } |
1209 | 5.20k | break; |
1210 | 5.20k | } |
1211 | 2.69k | default: |
1212 | 2.69k | { |
1213 | 2.69k | unsigned int |
1214 | 2.69k | pixel; |
1215 | | |
1216 | 7.40k | for (x=0; x < (ssize_t) image->columns; x++) |
1217 | 4.70k | { |
1218 | 4.70k | p=PushLongPixel(MSBEndian,p,&pixel); |
1219 | 4.70k | SetPixelGray(image,ScaleAnyToQuantum(pixel,max_value), |
1220 | 4.70k | q); |
1221 | 4.70k | SetPixelAlpha(image,OpaqueAlpha,q); |
1222 | 4.70k | if (image->alpha_trait != UndefinedPixelTrait) |
1223 | 1.61k | { |
1224 | 1.61k | p=PushLongPixel(MSBEndian,p,&pixel); |
1225 | 1.61k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1226 | 1.61k | max_value),q); |
1227 | 1.61k | } |
1228 | 4.70k | q+=(ptrdiff_t) GetPixelChannels(image); |
1229 | 4.70k | } |
1230 | 2.69k | } |
1231 | 15.0k | } |
1232 | 15.0k | break; |
1233 | 15.0k | } |
1234 | 15.0k | case CMYKQuantum: |
1235 | 13.3k | case CMYKAQuantum: |
1236 | 13.3k | { |
1237 | 13.3k | switch (image->depth) |
1238 | 13.3k | { |
1239 | 2.60k | case 1: |
1240 | 3.01k | case 2: |
1241 | 3.61k | case 3: |
1242 | 4.01k | case 4: |
1243 | 4.57k | case 5: |
1244 | 5.01k | case 6: |
1245 | 5.71k | case 7: |
1246 | 5.71k | case 8: |
1247 | 5.71k | { |
1248 | 5.71k | unsigned char |
1249 | 5.71k | pixel; |
1250 | | |
1251 | 13.7k | for (x=0; x < (ssize_t) image->columns; x++) |
1252 | 8.01k | { |
1253 | 8.01k | p=PushCharPixel(p,&pixel); |
1254 | 8.01k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
1255 | 8.01k | p=PushCharPixel(p,&pixel); |
1256 | 8.01k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value), |
1257 | 8.01k | q); |
1258 | 8.01k | p=PushCharPixel(p,&pixel); |
1259 | 8.01k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value), |
1260 | 8.01k | q); |
1261 | 8.01k | p=PushCharPixel(p,&pixel); |
1262 | 8.01k | SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value), |
1263 | 8.01k | q); |
1264 | 8.01k | SetPixelAlpha(image,OpaqueAlpha,q); |
1265 | 8.01k | if (image->alpha_trait != UndefinedPixelTrait) |
1266 | 2.04k | { |
1267 | 2.04k | p=PushCharPixel(p,&pixel); |
1268 | 2.04k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1269 | 2.04k | max_value),q); |
1270 | 2.04k | } |
1271 | 8.01k | q+=(ptrdiff_t) GetPixelChannels(image); |
1272 | 8.01k | } |
1273 | 5.71k | break; |
1274 | 5.71k | } |
1275 | 610 | case 9: |
1276 | 1.45k | case 10: |
1277 | 1.77k | case 11: |
1278 | 3.25k | case 12: |
1279 | 3.71k | case 13: |
1280 | 4.17k | case 14: |
1281 | 5.43k | case 15: |
1282 | 5.43k | case 16: |
1283 | 5.43k | { |
1284 | 5.43k | unsigned short |
1285 | 5.43k | pixel; |
1286 | | |
1287 | 12.7k | for (x=0; x < (ssize_t) image->columns; x++) |
1288 | 7.36k | { |
1289 | 7.36k | p=PushShortPixel(MSBEndian,p,&pixel); |
1290 | 7.36k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
1291 | 7.36k | p=PushShortPixel(MSBEndian,p,&pixel); |
1292 | 7.36k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value), |
1293 | 7.36k | q); |
1294 | 7.36k | p=PushShortPixel(MSBEndian,p,&pixel); |
1295 | 7.36k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value), |
1296 | 7.36k | q); |
1297 | 7.36k | p=PushShortPixel(MSBEndian,p,&pixel); |
1298 | 7.36k | SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value), |
1299 | 7.36k | q); |
1300 | 7.36k | SetPixelAlpha(image,OpaqueAlpha,q); |
1301 | 7.36k | if (image->alpha_trait != UndefinedPixelTrait) |
1302 | 2.31k | { |
1303 | 2.31k | p=PushShortPixel(MSBEndian,p,&pixel); |
1304 | 2.31k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1305 | 2.31k | max_value),q); |
1306 | 2.31k | } |
1307 | 7.36k | q+=(ptrdiff_t) GetPixelChannels(image); |
1308 | 7.36k | } |
1309 | 5.43k | break; |
1310 | 5.43k | } |
1311 | 2.21k | default: |
1312 | 2.21k | { |
1313 | 2.21k | unsigned int |
1314 | 2.21k | pixel; |
1315 | | |
1316 | 6.04k | for (x=0; x < (ssize_t) image->columns; x++) |
1317 | 3.82k | { |
1318 | 3.82k | p=PushLongPixel(MSBEndian,p,&pixel); |
1319 | 3.82k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value), |
1320 | 3.82k | q); |
1321 | 3.82k | p=PushLongPixel(MSBEndian,p,&pixel); |
1322 | 3.82k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value), |
1323 | 3.82k | q); |
1324 | 3.82k | p=PushLongPixel(MSBEndian,p,&pixel); |
1325 | 3.82k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value), |
1326 | 3.82k | q); |
1327 | 3.82k | p=PushLongPixel(MSBEndian,p,&pixel); |
1328 | 3.82k | SetPixelBlack(image,ScaleAnyToQuantum(pixel,max_value), |
1329 | 3.82k | q); |
1330 | 3.82k | SetPixelAlpha(image,OpaqueAlpha,q); |
1331 | 3.82k | if (image->alpha_trait != UndefinedPixelTrait) |
1332 | 1.83k | { |
1333 | 1.83k | p=PushLongPixel(MSBEndian,p,&pixel); |
1334 | 1.83k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1335 | 1.83k | max_value),q); |
1336 | 1.83k | } |
1337 | 3.82k | q+=(ptrdiff_t) GetPixelChannels(image); |
1338 | 3.82k | } |
1339 | 2.21k | break; |
1340 | 5.43k | } |
1341 | 13.3k | } |
1342 | 13.3k | break; |
1343 | 13.3k | } |
1344 | 13.3k | default: |
1345 | 11.5k | { |
1346 | 11.5k | switch (image->depth) |
1347 | 11.5k | { |
1348 | 1.69k | case 1: |
1349 | 2.17k | case 2: |
1350 | 2.67k | case 3: |
1351 | 3.11k | case 4: |
1352 | 3.55k | case 5: |
1353 | 4.25k | case 6: |
1354 | 4.85k | case 7: |
1355 | 4.85k | case 8: |
1356 | 4.85k | { |
1357 | 4.85k | unsigned char |
1358 | 4.85k | pixel; |
1359 | | |
1360 | 15.2k | for (x=0; x < (ssize_t) image->columns; x++) |
1361 | 10.3k | { |
1362 | 10.3k | p=PushCharPixel(p,&pixel); |
1363 | 10.3k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
1364 | 10.3k | p=PushCharPixel(p,&pixel); |
1365 | 10.3k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value), |
1366 | 10.3k | q); |
1367 | 10.3k | p=PushCharPixel(p,&pixel); |
1368 | 10.3k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value), |
1369 | 10.3k | q); |
1370 | 10.3k | SetPixelAlpha(image,OpaqueAlpha,q); |
1371 | 10.3k | if (image->alpha_trait != UndefinedPixelTrait) |
1372 | 1.18k | { |
1373 | 1.18k | p=PushCharPixel(p,&pixel); |
1374 | 1.18k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1375 | 1.18k | max_value),q); |
1376 | 1.18k | } |
1377 | 10.3k | q+=(ptrdiff_t) GetPixelChannels(image); |
1378 | 10.3k | } |
1379 | 4.85k | break; |
1380 | 4.85k | } |
1381 | 737 | case 9: |
1382 | 1.37k | case 10: |
1383 | 1.77k | case 11: |
1384 | 2.42k | case 12: |
1385 | 2.99k | case 13: |
1386 | 3.59k | case 14: |
1387 | 4.58k | case 15: |
1388 | 4.58k | case 16: |
1389 | 4.58k | { |
1390 | 4.58k | unsigned short |
1391 | 4.58k | pixel; |
1392 | | |
1393 | 10.7k | for (x=0; x < (ssize_t) image->columns; x++) |
1394 | 6.11k | { |
1395 | 6.11k | p=PushShortPixel(MSBEndian,p,&pixel); |
1396 | 6.11k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value),q); |
1397 | 6.11k | p=PushShortPixel(MSBEndian,p,&pixel); |
1398 | 6.11k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value), |
1399 | 6.11k | q); |
1400 | 6.11k | p=PushShortPixel(MSBEndian,p,&pixel); |
1401 | 6.11k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value), |
1402 | 6.11k | q); |
1403 | 6.11k | SetPixelAlpha(image,OpaqueAlpha,q); |
1404 | 6.11k | if (image->alpha_trait != UndefinedPixelTrait) |
1405 | 1.44k | { |
1406 | 1.44k | p=PushShortPixel(MSBEndian,p,&pixel); |
1407 | 1.44k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1408 | 1.44k | max_value),q); |
1409 | 1.44k | } |
1410 | 6.11k | q+=(ptrdiff_t) GetPixelChannels(image); |
1411 | 6.11k | } |
1412 | 4.58k | break; |
1413 | 4.58k | } |
1414 | 2.12k | default: |
1415 | 2.12k | { |
1416 | 2.12k | unsigned int |
1417 | 2.12k | pixel; |
1418 | | |
1419 | 6.95k | for (x=0; x < (ssize_t) image->columns; x++) |
1420 | 4.82k | { |
1421 | 4.82k | p=PushLongPixel(MSBEndian,p,&pixel); |
1422 | 4.82k | SetPixelRed(image,ScaleAnyToQuantum(pixel,max_value), |
1423 | 4.82k | q); |
1424 | 4.82k | p=PushLongPixel(MSBEndian,p,&pixel); |
1425 | 4.82k | SetPixelGreen(image,ScaleAnyToQuantum(pixel,max_value), |
1426 | 4.82k | q); |
1427 | 4.82k | p=PushLongPixel(MSBEndian,p,&pixel); |
1428 | 4.82k | SetPixelBlue(image,ScaleAnyToQuantum(pixel,max_value), |
1429 | 4.82k | q); |
1430 | 4.82k | SetPixelAlpha(image,OpaqueAlpha,q); |
1431 | 4.82k | if (image->alpha_trait != UndefinedPixelTrait) |
1432 | 1.45k | { |
1433 | 1.45k | p=PushLongPixel(MSBEndian,p,&pixel); |
1434 | 1.45k | SetPixelAlpha(image,ScaleAnyToQuantum(pixel, |
1435 | 1.45k | max_value),q); |
1436 | 1.45k | } |
1437 | 4.82k | q+=(ptrdiff_t) GetPixelChannels(image); |
1438 | 4.82k | } |
1439 | 2.12k | break; |
1440 | 4.58k | } |
1441 | 11.5k | } |
1442 | 11.5k | break; |
1443 | 11.5k | } |
1444 | 39.9k | } |
1445 | 39.9k | } |
1446 | 56.0k | } |
1447 | 56.0k | sync=SyncAuthenticPixels(image,exception); |
1448 | 56.0k | if (sync == MagickFalse) |
1449 | 0 | break; |
1450 | 56.0k | } |
1451 | 3.14k | quantum_info=DestroyQuantumInfo(quantum_info); |
1452 | 3.14k | SetQuantumImageType(image,quantum_type); |
1453 | 3.14k | break; |
1454 | 3.14k | } |
1455 | 537 | case 'F': |
1456 | 861 | case 'f': |
1457 | 861 | { |
1458 | | /* |
1459 | | Convert PFM raster image to pixel packets. |
1460 | | */ |
1461 | 861 | if (format != 'f') |
1462 | 537 | quantum_type=image->alpha_trait != UndefinedPixelTrait ? RGBAQuantum : |
1463 | 537 | RGBQuantum; |
1464 | 324 | else |
1465 | 324 | { |
1466 | 324 | (void) SetImageColorspace(image,GRAYColorspace,exception); |
1467 | 324 | quantum_type=GrayQuantum; |
1468 | 324 | } |
1469 | 861 | image->endian=quantum_scale < 0.0 ? LSBEndian : MSBEndian; |
1470 | 861 | image->depth=32; |
1471 | 861 | quantum_info=AcquireQuantumInfo(image_info,image); |
1472 | 861 | if (quantum_info == (QuantumInfo *) NULL) |
1473 | 861 | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
1474 | 861 | status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); |
1475 | 861 | if (status == MagickFalse) |
1476 | 861 | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
1477 | 861 | SetQuantumScale(quantum_info,(double) QuantumRange*fabs(quantum_scale)); |
1478 | 861 | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
1479 | 861 | pixels=GetQuantumPixels(quantum_info); |
1480 | 6.62k | for (y=0; y < (ssize_t) image->rows; y++) |
1481 | 6.26k | { |
1482 | 6.26k | MagickBooleanType |
1483 | 6.26k | sync; |
1484 | | |
1485 | 6.26k | Quantum |
1486 | 6.26k | *magick_restrict q; |
1487 | | |
1488 | 6.26k | size_t |
1489 | 6.26k | length; |
1490 | | |
1491 | 6.26k | ssize_t |
1492 | 6.26k | offset; |
1493 | | |
1494 | 6.26k | stream=ReadBlobStream(image,extent,pixels,&count); |
1495 | 6.26k | if (count != (ssize_t) extent) |
1496 | 497 | break; |
1497 | 5.76k | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
1498 | 0 | (image->previous == (Image *) NULL)) |
1499 | 0 | { |
1500 | 0 | MagickBooleanType |
1501 | 0 | proceed; |
1502 | |
|
1503 | 0 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
1504 | 0 | row,image->rows); |
1505 | 0 | if (proceed == MagickFalse) |
1506 | 0 | break; |
1507 | 0 | } |
1508 | 5.76k | offset=row++; |
1509 | 5.76k | q=QueueAuthenticPixels(image,0,((ssize_t) image->rows-offset-1), |
1510 | 5.76k | image->columns,1,exception); |
1511 | 5.76k | if (q == (Quantum *) NULL) |
1512 | 0 | break; |
1513 | 5.76k | length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
1514 | 5.76k | quantum_type,(unsigned char *) stream,exception); |
1515 | 5.76k | if (length != extent) |
1516 | 0 | break; |
1517 | 5.76k | sync=SyncAuthenticPixels(image,exception); |
1518 | 5.76k | if (sync == MagickFalse) |
1519 | 0 | break; |
1520 | 5.76k | } |
1521 | 861 | quantum_info=DestroyQuantumInfo(quantum_info); |
1522 | 861 | SetQuantumImageType(image,quantum_type); |
1523 | 861 | break; |
1524 | 861 | } |
1525 | 880 | case 'H': |
1526 | 1.90k | case 'h': |
1527 | 1.90k | { |
1528 | | /* |
1529 | | Convert PFM raster image to pixel packets. |
1530 | | */ |
1531 | 1.90k | if (format != 'h') |
1532 | 880 | quantum_type=image->alpha_trait != UndefinedPixelTrait ? RGBAQuantum : |
1533 | 880 | RGBQuantum; |
1534 | 1.02k | else |
1535 | 1.02k | { |
1536 | 1.02k | (void) SetImageColorspace(image,GRAYColorspace,exception); |
1537 | 1.02k | quantum_type=GrayQuantum; |
1538 | 1.02k | } |
1539 | 1.90k | image->endian=quantum_scale < 0.0 ? LSBEndian : MSBEndian; |
1540 | 1.90k | image->depth=16; |
1541 | 1.90k | quantum_info=AcquireQuantumInfo(image_info,image); |
1542 | 1.90k | if (quantum_info == (QuantumInfo *) NULL) |
1543 | 1.90k | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
1544 | 1.90k | status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); |
1545 | 1.90k | if (status == MagickFalse) |
1546 | 1.90k | ThrowPNMException(ResourceLimitError,"MemoryAllocationFailed"); |
1547 | 1.90k | SetQuantumScale(quantum_info,(double) QuantumRange*fabs(quantum_scale)); |
1548 | 1.90k | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
1549 | 1.90k | pixels=GetQuantumPixels(quantum_info); |
1550 | 15.3k | for (y=0; y < (ssize_t) image->rows; y++) |
1551 | 14.4k | { |
1552 | 14.4k | MagickBooleanType |
1553 | 14.4k | sync; |
1554 | | |
1555 | 14.4k | Quantum |
1556 | 14.4k | *magick_restrict q; |
1557 | | |
1558 | 14.4k | size_t |
1559 | 14.4k | length; |
1560 | | |
1561 | 14.4k | ssize_t |
1562 | 14.4k | offset; |
1563 | | |
1564 | 14.4k | stream=ReadBlobStream(image,extent,pixels,&count); |
1565 | 14.4k | if (count != (ssize_t) extent) |
1566 | 913 | break; |
1567 | 13.4k | if ((image->progress_monitor != (MagickProgressMonitor) NULL) && |
1568 | 0 | (image->previous == (Image *) NULL)) |
1569 | 0 | { |
1570 | 0 | MagickBooleanType |
1571 | 0 | proceed; |
1572 | |
|
1573 | 0 | proceed=SetImageProgress(image,LoadImageTag,(MagickOffsetType) |
1574 | 0 | row,image->rows); |
1575 | 0 | if (proceed == MagickFalse) |
1576 | 0 | break; |
1577 | 0 | } |
1578 | 13.4k | offset=row++; |
1579 | 13.4k | q=QueueAuthenticPixels(image,0,((ssize_t) image->rows-offset-1), |
1580 | 13.4k | image->columns,1,exception); |
1581 | 13.4k | if (q == (Quantum *) NULL) |
1582 | 0 | break; |
1583 | 13.4k | length=ImportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
1584 | 13.4k | quantum_type,(unsigned char *) stream,exception); |
1585 | 13.4k | if (length != extent) |
1586 | 0 | break; |
1587 | 13.4k | sync=SyncAuthenticPixels(image,exception); |
1588 | 13.4k | if (sync == MagickFalse) |
1589 | 0 | break; |
1590 | 13.4k | } |
1591 | 1.90k | quantum_info=DestroyQuantumInfo(quantum_info); |
1592 | 1.90k | SetQuantumImageType(image,quantum_type); |
1593 | 1.90k | break; |
1594 | 1.90k | } |
1595 | 5 | default: |
1596 | 5 | ThrowPNMException(CorruptImageError,"ImproperImageHeader"); |
1597 | 16.8k | } |
1598 | 16.8k | if (*comment_info.comment != '\0') |
1599 | 749 | (void) SetImageProperty(image,"comment",comment_info.comment,exception); |
1600 | 16.8k | comment_info.comment=DestroyString(comment_info.comment); |
1601 | 16.8k | if (y < (ssize_t) image->rows) |
1602 | 9.13k | ThrowPNMException(CorruptImageError,"UnableToReadImageData"); |
1603 | | /* |
1604 | | Proceed to next image. |
1605 | | */ |
1606 | 9.13k | if (image_info->number_scenes != 0) |
1607 | 202 | if (image->scene >= (image_info->scene+image_info->number_scenes-1)) |
1608 | 2 | break; |
1609 | 9.13k | if ((format == '1') || (format == '2') || (format == '3')) |
1610 | 1.11k | do |
1611 | 16.9k | { |
1612 | | /* |
1613 | | Skip to end of line. |
1614 | | */ |
1615 | 16.9k | count=ReadBlob(image,1,(unsigned char *) &format); |
1616 | 16.9k | if (count != 1) |
1617 | 748 | break; |
1618 | 16.2k | if (format == 'P') |
1619 | 184 | break; |
1620 | 16.2k | } while (format != '\n'); |
1621 | 9.13k | count=ReadBlob(image,1,(unsigned char *) &format); |
1622 | 9.13k | if ((count == 1) && (format == 'P')) |
1623 | 2.56k | { |
1624 | | /* |
1625 | | Allocate next image structure. |
1626 | | */ |
1627 | 2.56k | AcquireNextImage(image_info,image,exception); |
1628 | 2.56k | if (GetNextImageInList(image) == (Image *) NULL) |
1629 | 0 | { |
1630 | 0 | status=MagickFalse; |
1631 | 0 | break; |
1632 | 0 | } |
1633 | 2.56k | image=SyncNextImageInList(image); |
1634 | 2.56k | status=SetImageProgress(image,LoadImagesTag,TellBlob(image), |
1635 | 2.56k | GetBlobSize(image)); |
1636 | 2.56k | if (status == MagickFalse) |
1637 | 0 | break; |
1638 | 2.56k | } |
1639 | 9.13k | } while ((count == 1) && (format == 'P')); |
1640 | 6.57k | (void) CloseBlob(image); |
1641 | 6.57k | if (comment_info.comment != (char *) NULL) |
1642 | 0 | comment_info.comment=DestroyString(comment_info.comment); |
1643 | 6.57k | if (quantum_info != (QuantumInfo *) NULL) |
1644 | 0 | quantum_info=DestroyQuantumInfo(quantum_info); |
1645 | 6.57k | if (status == MagickFalse) |
1646 | 0 | return(DestroyImageList(image)); |
1647 | 6.57k | return(GetFirstImageInList(image)); |
1648 | 6.57k | } |
1649 | | |
1650 | | /* |
1651 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1652 | | % % |
1653 | | % % |
1654 | | % % |
1655 | | % R e g i s t e r P N M I m a g e % |
1656 | | % % |
1657 | | % % |
1658 | | % % |
1659 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1660 | | % |
1661 | | % RegisterPNMImage() adds properties for the PNM image format to |
1662 | | % the list of supported formats. The properties include the image format |
1663 | | % tag, a method to read and/or write the format, whether the format |
1664 | | % supports the saving of more than one frame to the same file or blob, |
1665 | | % whether the format supports native in-memory I/O, and a brief |
1666 | | % description of the format. |
1667 | | % |
1668 | | % The format of the RegisterPNMImage method is: |
1669 | | % |
1670 | | % size_t RegisterPNMImage(void) |
1671 | | % |
1672 | | */ |
1673 | | ModuleExport size_t RegisterPNMImage(void) |
1674 | 9 | { |
1675 | 9 | MagickInfo |
1676 | 9 | *entry; |
1677 | | |
1678 | 9 | entry=AcquireMagickInfo("PNM","PAM","Common 2-dimensional bitmap format"); |
1679 | 9 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
1680 | 9 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
1681 | 9 | entry->mime_type=ConstantString("image/x-portable-anymap"); |
1682 | 9 | entry->flags|=CoderDecoderSeekableStreamFlag; |
1683 | 9 | (void) RegisterMagickInfo(entry); |
1684 | 9 | entry=AcquireMagickInfo("PNM","PBM", |
1685 | 9 | "Portable bitmap format (black and white)"); |
1686 | 9 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
1687 | 9 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
1688 | 9 | entry->mime_type=ConstantString("image/x-portable-bitmap"); |
1689 | 9 | entry->flags|=CoderDecoderSeekableStreamFlag; |
1690 | 9 | (void) RegisterMagickInfo(entry); |
1691 | 9 | entry=AcquireMagickInfo("PNM","PFM","Portable float format"); |
1692 | 9 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
1693 | 9 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
1694 | 9 | entry->flags|=CoderEndianSupportFlag; |
1695 | 9 | entry->flags|=CoderDecoderSeekableStreamFlag; |
1696 | 9 | (void) RegisterMagickInfo(entry); |
1697 | 9 | entry=AcquireMagickInfo("PNM","PGM","Portable graymap format (gray scale)"); |
1698 | 9 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
1699 | 9 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
1700 | 9 | entry->mime_type=ConstantString("image/x-portable-greymap"); |
1701 | 9 | entry->flags|=CoderDecoderSeekableStreamFlag; |
1702 | 9 | (void) RegisterMagickInfo(entry); |
1703 | 9 | entry=AcquireMagickInfo("PNM","PHM","Portable half float format"); |
1704 | 9 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
1705 | 9 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
1706 | 9 | entry->flags|=CoderEndianSupportFlag; |
1707 | 9 | entry->flags|=CoderDecoderSeekableStreamFlag; |
1708 | 9 | (void) RegisterMagickInfo(entry); |
1709 | 9 | entry=AcquireMagickInfo("PNM","PNM","Portable anymap"); |
1710 | 9 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
1711 | 9 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
1712 | 9 | entry->magick=(IsImageFormatHandler *) IsPNM; |
1713 | 9 | entry->mime_type=ConstantString("image/x-portable-pixmap"); |
1714 | 9 | entry->flags|=CoderDecoderSeekableStreamFlag; |
1715 | 9 | (void) RegisterMagickInfo(entry); |
1716 | 9 | entry=AcquireMagickInfo("PNM","PPM","Portable pixmap format (color)"); |
1717 | 9 | entry->decoder=(DecodeImageHandler *) ReadPNMImage; |
1718 | 9 | entry->encoder=(EncodeImageHandler *) WritePNMImage; |
1719 | 9 | entry->mime_type=ConstantString("image/x-portable-pixmap"); |
1720 | 9 | entry->flags|=CoderDecoderSeekableStreamFlag; |
1721 | 9 | (void) RegisterMagickInfo(entry); |
1722 | 9 | return(MagickImageCoderSignature); |
1723 | 9 | } |
1724 | | |
1725 | | /* |
1726 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1727 | | % % |
1728 | | % % |
1729 | | % % |
1730 | | % U n r e g i s t e r P N M I m a g e % |
1731 | | % % |
1732 | | % % |
1733 | | % % |
1734 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1735 | | % |
1736 | | % UnregisterPNMImage() removes format registrations made by the |
1737 | | % PNM module from the list of supported formats. |
1738 | | % |
1739 | | % The format of the UnregisterPNMImage method is: |
1740 | | % |
1741 | | % UnregisterPNMImage(void) |
1742 | | % |
1743 | | */ |
1744 | | ModuleExport void UnregisterPNMImage(void) |
1745 | 0 | { |
1746 | 0 | (void) UnregisterMagickInfo("PAM"); |
1747 | 0 | (void) UnregisterMagickInfo("PBM"); |
1748 | 0 | (void) UnregisterMagickInfo("PGM"); |
1749 | 0 | (void) UnregisterMagickInfo("PNM"); |
1750 | 0 | (void) UnregisterMagickInfo("PPM"); |
1751 | 0 | } |
1752 | | |
1753 | | /* |
1754 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1755 | | % % |
1756 | | % % |
1757 | | % % |
1758 | | % W r i t e P N M I m a g e % |
1759 | | % % |
1760 | | % % |
1761 | | % % |
1762 | | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
1763 | | % |
1764 | | % WritePNMImage() writes an image to a file in the PNM rasterfile format. |
1765 | | % |
1766 | | % The format of the WritePNMImage method is: |
1767 | | % |
1768 | | % MagickBooleanType WritePNMImage(const ImageInfo *image_info, |
1769 | | % Image *image,ExceptionInfo *exception) |
1770 | | % |
1771 | | % A description of each parameter follows. |
1772 | | % |
1773 | | % o image_info: the image info. |
1774 | | % |
1775 | | % o image: The image. |
1776 | | % |
1777 | | % o exception: return any errors or warnings in this structure. |
1778 | | % |
1779 | | */ |
1780 | | static MagickBooleanType WritePNMImage(const ImageInfo *image_info,Image *image, |
1781 | | ExceptionInfo *exception) |
1782 | 2.00k | { |
1783 | 2.00k | char |
1784 | 2.00k | buffer[MagickPathExtent], |
1785 | 2.00k | format, |
1786 | 2.00k | magick[MagickPathExtent]; |
1787 | | |
1788 | 2.00k | const char |
1789 | 2.00k | *value; |
1790 | | |
1791 | 2.00k | MagickBooleanType |
1792 | 2.00k | added_newline, |
1793 | 2.00k | status; |
1794 | | |
1795 | 2.00k | MagickOffsetType |
1796 | 2.00k | scene; |
1797 | | |
1798 | 2.00k | Quantum |
1799 | 2.00k | index; |
1800 | | |
1801 | 2.00k | QuantumAny |
1802 | 2.00k | pixel; |
1803 | | |
1804 | 2.00k | QuantumInfo |
1805 | 2.00k | *quantum_info; |
1806 | | |
1807 | 2.00k | QuantumType |
1808 | 2.00k | quantum_type; |
1809 | | |
1810 | 2.00k | size_t |
1811 | 2.00k | extent, |
1812 | 2.00k | number_scenes, |
1813 | 2.00k | packet_size; |
1814 | | |
1815 | 2.00k | ssize_t |
1816 | 2.00k | count, |
1817 | 2.00k | y; |
1818 | | |
1819 | 2.00k | unsigned char |
1820 | 2.00k | *q; |
1821 | | |
1822 | | /* |
1823 | | Open output image file. |
1824 | | */ |
1825 | 2.00k | assert(image_info != (const ImageInfo *) NULL); |
1826 | 2.00k | assert(image_info->signature == MagickCoreSignature); |
1827 | 2.00k | assert(image != (Image *) NULL); |
1828 | 2.00k | assert(image->signature == MagickCoreSignature); |
1829 | 2.00k | assert(exception != (ExceptionInfo *) NULL); |
1830 | 2.00k | assert(exception->signature == MagickCoreSignature); |
1831 | 2.00k | if (IsEventLogging() != MagickFalse) |
1832 | 0 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
1833 | 2.00k | status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); |
1834 | 2.00k | if (status == MagickFalse) |
1835 | 0 | return(status); |
1836 | 2.00k | scene=0; |
1837 | 2.00k | number_scenes=GetImageListLength(image); |
1838 | 2.00k | do |
1839 | 2.00k | { |
1840 | 2.00k | QuantumAny |
1841 | 2.00k | max_value; |
1842 | | |
1843 | | /* |
1844 | | Write PNM file header. |
1845 | | */ |
1846 | 2.00k | packet_size=3; |
1847 | 2.00k | quantum_type=RGBQuantum; |
1848 | 2.00k | (void) CopyMagickString(magick,image_info->magick,MagickPathExtent); |
1849 | 2.00k | max_value=GetQuantumRange(image->depth); |
1850 | 2.00k | switch (magick[1]) |
1851 | 2.00k | { |
1852 | 0 | case 'A': |
1853 | 0 | case 'a': |
1854 | 0 | { |
1855 | 0 | format='7'; |
1856 | 0 | break; |
1857 | 0 | } |
1858 | 0 | case 'B': |
1859 | 0 | case 'b': |
1860 | 0 | { |
1861 | 0 | format='4'; |
1862 | 0 | if (image_info->compression == NoCompression) |
1863 | 0 | format='1'; |
1864 | 0 | break; |
1865 | 0 | } |
1866 | 0 | case 'F': |
1867 | 0 | case 'f': |
1868 | 0 | { |
1869 | 0 | format='F'; |
1870 | 0 | if (image_info->type == TrueColorType) |
1871 | 0 | break; |
1872 | 0 | if (IdentifyImageCoderGray(image,exception) != MagickFalse) |
1873 | 0 | format='f'; |
1874 | 0 | break; |
1875 | 0 | } |
1876 | 0 | case 'G': |
1877 | 0 | case 'g': |
1878 | 0 | { |
1879 | 0 | format='5'; |
1880 | 0 | if (image_info->compression == NoCompression) |
1881 | 0 | format='2'; |
1882 | 0 | break; |
1883 | 0 | } |
1884 | 0 | case 'H': |
1885 | 0 | case 'h': |
1886 | 0 | { |
1887 | 0 | format='H'; |
1888 | 0 | if (image_info->type == TrueColorType) |
1889 | 0 | break; |
1890 | 0 | if (IdentifyImageCoderGray(image,exception) != MagickFalse) |
1891 | 0 | format='h'; |
1892 | 0 | break; |
1893 | 0 | } |
1894 | 2.00k | case 'N': |
1895 | 2.00k | case 'n': |
1896 | 2.00k | { |
1897 | 2.00k | ImageType |
1898 | 2.00k | type; |
1899 | | |
1900 | 2.00k | format='6'; |
1901 | 2.00k | if (image_info->type == TrueColorType) |
1902 | 0 | break; |
1903 | 2.00k | type=IdentifyImageCoderGrayType(image,exception); |
1904 | 2.00k | if (IsGrayImageType(type) != MagickFalse) |
1905 | 1.16k | { |
1906 | 1.16k | format='5'; |
1907 | 1.16k | if (image_info->compression == NoCompression) |
1908 | 0 | format='2'; |
1909 | 1.16k | if (type == BilevelType) |
1910 | 613 | { |
1911 | 613 | format='4'; |
1912 | 613 | if (image_info->compression == NoCompression) |
1913 | 0 | format='1'; |
1914 | 613 | } |
1915 | 1.16k | } |
1916 | 2.00k | break; |
1917 | 2.00k | } |
1918 | 0 | default: |
1919 | 0 | { |
1920 | 0 | format='6'; |
1921 | 0 | if (image_info->compression == NoCompression) |
1922 | 0 | format='3'; |
1923 | 0 | break; |
1924 | 2.00k | } |
1925 | 2.00k | } |
1926 | 2.00k | (void) FormatLocaleString(buffer,MagickPathExtent,"P%c\n",format); |
1927 | 2.00k | (void) WriteBlobString(image,buffer); |
1928 | 2.00k | value=GetImageProperty(image,"comment",exception); |
1929 | 2.00k | if (value != (const char *) NULL) |
1930 | 137 | { |
1931 | 137 | const char |
1932 | 137 | *p; |
1933 | | |
1934 | | /* |
1935 | | Write comments to file. |
1936 | | */ |
1937 | 137 | (void) WriteBlobByte(image,'#'); |
1938 | 78.8k | for (p=value; *p != '\0'; p++) |
1939 | 78.6k | { |
1940 | 78.6k | (void) WriteBlobByte(image,(unsigned char) *p); |
1941 | 78.6k | if ((*p == '\n') || (*p == '\r')) |
1942 | 2.33k | (void) WriteBlobByte(image,'#'); |
1943 | 78.6k | } |
1944 | 137 | (void) WriteBlobByte(image,'\n'); |
1945 | 137 | } |
1946 | 2.00k | if (format != '7') |
1947 | 2.00k | { |
1948 | 2.00k | (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g %.20g\n", |
1949 | 2.00k | (double) image->columns,(double) image->rows); |
1950 | 2.00k | (void) WriteBlobString(image,buffer); |
1951 | 2.00k | } |
1952 | 0 | else |
1953 | 0 | { |
1954 | 0 | char |
1955 | 0 | type[MagickPathExtent]; |
1956 | | |
1957 | | /* |
1958 | | PAM header. |
1959 | | */ |
1960 | 0 | (void) FormatLocaleString(buffer,MagickPathExtent, |
1961 | 0 | "WIDTH %.20g\nHEIGHT %.20g\n",(double) image->columns,(double) |
1962 | 0 | image->rows); |
1963 | 0 | (void) WriteBlobString(image,buffer); |
1964 | 0 | quantum_type=GetQuantumType(image,exception); |
1965 | 0 | if (quantum_type == IndexQuantum) |
1966 | 0 | { |
1967 | 0 | if (image->colorspace == CMYKColorspace) |
1968 | 0 | quantum_type=CMYKQuantum; |
1969 | 0 | else if (image->colorspace == GRAYColorspace) |
1970 | 0 | quantum_type=GrayQuantum; |
1971 | 0 | } |
1972 | 0 | switch (quantum_type) |
1973 | 0 | { |
1974 | 0 | case CMYKQuantum: |
1975 | 0 | case CMYKAQuantum: |
1976 | 0 | { |
1977 | 0 | packet_size=4; |
1978 | 0 | (void) CopyMagickString(type,"CMYK",MagickPathExtent); |
1979 | 0 | break; |
1980 | 0 | } |
1981 | 0 | case GrayQuantum: |
1982 | 0 | case GrayAlphaQuantum: |
1983 | 0 | { |
1984 | 0 | packet_size=1; |
1985 | 0 | (void) CopyMagickString(type,"GRAYSCALE",MagickPathExtent); |
1986 | 0 | if (GetQuantumRange(image->depth) == 1) |
1987 | 0 | (void) CopyMagickString(type,"BLACKANDWHITE",MagickPathExtent); |
1988 | 0 | break; |
1989 | 0 | } |
1990 | 0 | default: |
1991 | 0 | { |
1992 | 0 | quantum_type=RGBQuantum; |
1993 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
1994 | 0 | quantum_type=RGBAQuantum; |
1995 | 0 | packet_size=3; |
1996 | 0 | (void) CopyMagickString(type,"RGB",MagickPathExtent); |
1997 | 0 | break; |
1998 | 0 | } |
1999 | 0 | } |
2000 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2001 | 0 | { |
2002 | 0 | packet_size++; |
2003 | 0 | (void) ConcatenateMagickString(type,"_ALPHA",MagickPathExtent); |
2004 | 0 | } |
2005 | 0 | if (image->depth > 32) |
2006 | 0 | image->depth=32; |
2007 | 0 | (void) FormatLocaleString(buffer,MagickPathExtent, |
2008 | 0 | "DEPTH %.20g\nMAXVAL %.20g\n",(double) packet_size,(double) |
2009 | 0 | ((MagickOffsetType) GetQuantumRange(image->depth))); |
2010 | 0 | (void) WriteBlobString(image,buffer); |
2011 | 0 | (void) FormatLocaleString(buffer,MagickPathExtent, |
2012 | 0 | "TUPLTYPE %s\nENDHDR\n",type); |
2013 | 0 | (void) WriteBlobString(image,buffer); |
2014 | 0 | } |
2015 | | /* |
2016 | | Convert runextent encoded to PNM raster pixels. |
2017 | | */ |
2018 | 2.00k | switch (format) |
2019 | 2.00k | { |
2020 | 0 | case '1': |
2021 | 0 | { |
2022 | 0 | unsigned char |
2023 | 0 | pixels[70]; |
2024 | | |
2025 | | /* |
2026 | | Convert image to a PBM image. |
2027 | | */ |
2028 | 0 | (void) SetImageType(image,BilevelType,exception); |
2029 | 0 | extent=1; |
2030 | 0 | q=pixels; |
2031 | 0 | added_newline=MagickFalse; |
2032 | 0 | for (y=0; y < (ssize_t) image->rows; y++) |
2033 | 0 | { |
2034 | 0 | const Quantum |
2035 | 0 | *magick_restrict p; |
2036 | |
|
2037 | 0 | ssize_t |
2038 | 0 | x; |
2039 | |
|
2040 | 0 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2041 | 0 | if (p == (const Quantum *) NULL) |
2042 | 0 | break; |
2043 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2044 | 0 | { |
2045 | 0 | if (q != pixels) |
2046 | 0 | { |
2047 | 0 | if ((size_t) (q-pixels+(ssize_t) extent+1) < sizeof(pixels)) |
2048 | 0 | *q++=' '; |
2049 | 0 | else |
2050 | 0 | { |
2051 | 0 | *q++='\n'; |
2052 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2053 | 0 | q=pixels; |
2054 | 0 | added_newline=MagickTrue; |
2055 | 0 | } |
2056 | 0 | } |
2057 | 0 | *q++=(unsigned char) (GetPixelLuma(image,p) >= ((double) |
2058 | 0 | QuantumRange/2.0) ? '0' : '1'); |
2059 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2060 | 0 | } |
2061 | 0 | if (added_newline == MagickFalse) |
2062 | 0 | { |
2063 | 0 | *q++='\n'; |
2064 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2065 | 0 | q=pixels; |
2066 | 0 | } |
2067 | 0 | if (image->previous == (Image *) NULL) |
2068 | 0 | { |
2069 | 0 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2070 | 0 | image->rows); |
2071 | 0 | if (status == MagickFalse) |
2072 | 0 | break; |
2073 | 0 | } |
2074 | 0 | } |
2075 | 0 | if (q != pixels) |
2076 | 0 | { |
2077 | 0 | *q++='\n'; |
2078 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2079 | 0 | } |
2080 | 0 | break; |
2081 | 0 | } |
2082 | 0 | case '2': |
2083 | 0 | { |
2084 | 0 | unsigned char |
2085 | 0 | pixels[70]; |
2086 | | |
2087 | | /* |
2088 | | Convert image to a PGM image. |
2089 | | */ |
2090 | 0 | if (image->depth <= 8) |
2091 | 0 | (void) WriteBlobString(image,"255\n"); |
2092 | 0 | else |
2093 | 0 | if (image->depth <= 16) |
2094 | 0 | (void) WriteBlobString(image,"65535\n"); |
2095 | 0 | else |
2096 | 0 | (void) WriteBlobString(image,"4294967295\n"); |
2097 | 0 | q=pixels; |
2098 | 0 | added_newline=MagickFalse; |
2099 | 0 | for (y=0; y < (ssize_t) image->rows; y++) |
2100 | 0 | { |
2101 | 0 | const Quantum |
2102 | 0 | *magick_restrict p; |
2103 | |
|
2104 | 0 | ssize_t |
2105 | 0 | x; |
2106 | |
|
2107 | 0 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2108 | 0 | if (p == (const Quantum *) NULL) |
2109 | 0 | break; |
2110 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2111 | 0 | { |
2112 | 0 | index=ClampToQuantum(GetPixelLuma(image,p)); |
2113 | 0 | if (image->depth <= 8) |
2114 | 0 | count=(ssize_t) FormatLocaleString(buffer,MagickPathExtent,"%u", |
2115 | 0 | ScaleQuantumToChar(index)); |
2116 | 0 | else |
2117 | 0 | if (image->depth <= 16) |
2118 | 0 | count=(ssize_t) FormatLocaleString(buffer,MagickPathExtent, |
2119 | 0 | "%u",ScaleQuantumToShort(index)); |
2120 | 0 | else |
2121 | 0 | count=(ssize_t) FormatLocaleString(buffer,MagickPathExtent, |
2122 | 0 | "%u",ScaleQuantumToLong(index)); |
2123 | 0 | extent=(size_t) count; |
2124 | 0 | if (q != pixels) |
2125 | 0 | { |
2126 | 0 | if ((size_t) (q-pixels+(ssize_t) extent+1) < sizeof(pixels)) |
2127 | 0 | *q++=' '; |
2128 | 0 | else |
2129 | 0 | { |
2130 | 0 | *q++='\n'; |
2131 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2132 | 0 | q=pixels; |
2133 | 0 | added_newline=MagickTrue; |
2134 | 0 | } |
2135 | 0 | } |
2136 | 0 | (void) memcpy((char *) q,buffer,extent); |
2137 | 0 | q+=(ptrdiff_t) extent; |
2138 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2139 | 0 | } |
2140 | 0 | if (added_newline == MagickFalse) |
2141 | 0 | { |
2142 | 0 | *q++='\n'; |
2143 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2144 | 0 | q=pixels; |
2145 | 0 | } |
2146 | 0 | if (image->previous == (Image *) NULL) |
2147 | 0 | { |
2148 | 0 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2149 | 0 | image->rows); |
2150 | 0 | if (status == MagickFalse) |
2151 | 0 | break; |
2152 | 0 | } |
2153 | 0 | } |
2154 | 0 | if (q != pixels) |
2155 | 0 | { |
2156 | 0 | *q++='\n'; |
2157 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2158 | 0 | } |
2159 | 0 | break; |
2160 | 0 | } |
2161 | 0 | case '3': |
2162 | 0 | { |
2163 | 0 | unsigned char |
2164 | 0 | pixels[70]; |
2165 | | |
2166 | | /* |
2167 | | Convert image to a PNM image. |
2168 | | */ |
2169 | 0 | if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse) |
2170 | 0 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
2171 | 0 | if (image->depth <= 8) |
2172 | 0 | (void) WriteBlobString(image,"255\n"); |
2173 | 0 | else |
2174 | 0 | if (image->depth <= 16) |
2175 | 0 | (void) WriteBlobString(image,"65535\n"); |
2176 | 0 | else |
2177 | 0 | (void) WriteBlobString(image,"4294967295\n"); |
2178 | 0 | q=pixels; |
2179 | 0 | added_newline=MagickFalse; |
2180 | 0 | for (y=0; y < (ssize_t) image->rows; y++) |
2181 | 0 | { |
2182 | 0 | const Quantum |
2183 | 0 | *magick_restrict p; |
2184 | |
|
2185 | 0 | ssize_t |
2186 | 0 | x; |
2187 | |
|
2188 | 0 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2189 | 0 | if (p == (const Quantum *) NULL) |
2190 | 0 | break; |
2191 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2192 | 0 | { |
2193 | 0 | if (image->depth <= 8) |
2194 | 0 | count=(ssize_t) FormatLocaleString(buffer,MagickPathExtent, |
2195 | 0 | "%u %u %u",ScaleQuantumToChar(GetPixelRed(image,p)), |
2196 | 0 | ScaleQuantumToChar(GetPixelGreen(image,p)), |
2197 | 0 | ScaleQuantumToChar(GetPixelBlue(image,p))); |
2198 | 0 | else |
2199 | 0 | if (image->depth <= 16) |
2200 | 0 | count=(ssize_t) FormatLocaleString(buffer,MagickPathExtent, |
2201 | 0 | "%u %u %u",ScaleQuantumToShort(GetPixelRed(image,p)), |
2202 | 0 | ScaleQuantumToShort(GetPixelGreen(image,p)), |
2203 | 0 | ScaleQuantumToShort(GetPixelBlue(image,p))); |
2204 | 0 | else |
2205 | 0 | count=(ssize_t) FormatLocaleString(buffer,MagickPathExtent, |
2206 | 0 | "%u %u %u",ScaleQuantumToLong(GetPixelRed(image,p)), |
2207 | 0 | ScaleQuantumToLong(GetPixelGreen(image,p)), |
2208 | 0 | ScaleQuantumToLong(GetPixelBlue(image,p))); |
2209 | 0 | extent=(size_t) count; |
2210 | 0 | if (q != pixels) |
2211 | 0 | { |
2212 | 0 | if ((size_t) (q-pixels+(ssize_t) extent+1) < sizeof(pixels)) |
2213 | 0 | *q++=' '; |
2214 | 0 | else |
2215 | 0 | { |
2216 | 0 | *q++='\n'; |
2217 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2218 | 0 | q=pixels; |
2219 | 0 | added_newline=MagickTrue; |
2220 | 0 | } |
2221 | 0 | } |
2222 | 0 | (void) memcpy((char *) q,buffer,extent); |
2223 | 0 | q+=(ptrdiff_t) extent; |
2224 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2225 | 0 | } |
2226 | 0 | if (added_newline == MagickFalse) |
2227 | 0 | { |
2228 | 0 | *q++='\n'; |
2229 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2230 | 0 | q=pixels; |
2231 | 0 | } |
2232 | 0 | if (image->previous == (Image *) NULL) |
2233 | 0 | { |
2234 | 0 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2235 | 0 | image->rows); |
2236 | 0 | if (status == MagickFalse) |
2237 | 0 | break; |
2238 | 0 | } |
2239 | 0 | } |
2240 | 0 | if (q != pixels) |
2241 | 0 | { |
2242 | 0 | *q++='\n'; |
2243 | 0 | (void) WriteBlob(image,(size_t) (q-pixels),pixels); |
2244 | 0 | } |
2245 | 0 | break; |
2246 | 0 | } |
2247 | 613 | case '4': |
2248 | 613 | { |
2249 | 613 | unsigned char |
2250 | 613 | *pixels; |
2251 | | |
2252 | | /* |
2253 | | Convert image to a PBM image. |
2254 | | */ |
2255 | 613 | (void) SetImageType(image,BilevelType,exception); |
2256 | 613 | image->depth=1; |
2257 | 613 | quantum_info=AcquireQuantumInfo(image_info,image); |
2258 | 613 | if (quantum_info == (QuantumInfo *) NULL) |
2259 | 613 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2260 | 613 | SetQuantumMinIsWhite(quantum_info,MagickTrue); |
2261 | 613 | (void) SetQuantumEndian(image,quantum_info,MSBEndian); |
2262 | 613 | pixels=GetQuantumPixels(quantum_info); |
2263 | 16.9k | for (y=0; y < (ssize_t) image->rows; y++) |
2264 | 16.3k | { |
2265 | 16.3k | const Quantum |
2266 | 16.3k | *magick_restrict p; |
2267 | | |
2268 | 16.3k | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2269 | 16.3k | if (p == (const Quantum *) NULL) |
2270 | 0 | break; |
2271 | 16.3k | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
2272 | 16.3k | GrayQuantum,pixels,exception); |
2273 | 16.3k | count=WriteBlob(image,extent,pixels); |
2274 | 16.3k | if (count != (ssize_t) extent) |
2275 | 0 | break; |
2276 | 16.3k | if (image->previous == (Image *) NULL) |
2277 | 16.3k | { |
2278 | 16.3k | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2279 | 16.3k | image->rows); |
2280 | 16.3k | if (status == MagickFalse) |
2281 | 0 | break; |
2282 | 16.3k | } |
2283 | 16.3k | } |
2284 | 613 | quantum_info=DestroyQuantumInfo(quantum_info); |
2285 | 613 | break; |
2286 | 613 | } |
2287 | 556 | case '5': |
2288 | 556 | { |
2289 | 556 | unsigned char |
2290 | 556 | *pixels; |
2291 | | |
2292 | | /* |
2293 | | Convert image to a PGM image. |
2294 | | */ |
2295 | 556 | if (image->depth > 32) |
2296 | 0 | image->depth=32; |
2297 | 556 | (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g\n",(double) |
2298 | 556 | ((MagickOffsetType) GetQuantumRange(image->depth))); |
2299 | 556 | (void) WriteBlobString(image,buffer); |
2300 | 556 | quantum_info=AcquireQuantumInfo(image_info,image); |
2301 | 556 | if (quantum_info == (QuantumInfo *) NULL) |
2302 | 556 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2303 | 556 | (void) SetQuantumEndian(image,quantum_info,MSBEndian); |
2304 | 556 | pixels=GetQuantumPixels(quantum_info); |
2305 | 556 | extent=GetQuantumExtent(image,quantum_info,GrayQuantum); |
2306 | 6.36k | for (y=0; y < (ssize_t) image->rows; y++) |
2307 | 5.80k | { |
2308 | 5.80k | const Quantum |
2309 | 5.80k | *magick_restrict p; |
2310 | | |
2311 | 5.80k | ssize_t |
2312 | 5.80k | x; |
2313 | | |
2314 | 5.80k | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2315 | 5.80k | if (p == (const Quantum *) NULL) |
2316 | 0 | break; |
2317 | 5.80k | q=pixels; |
2318 | 5.80k | switch (image->depth) |
2319 | 5.80k | { |
2320 | 961 | case 8: |
2321 | 1.59k | case 16: |
2322 | 2.15k | case 32: |
2323 | 2.15k | { |
2324 | 2.15k | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
2325 | 2.15k | GrayQuantum,pixels,exception); |
2326 | 2.15k | break; |
2327 | 1.59k | } |
2328 | 3.64k | default: |
2329 | 3.64k | { |
2330 | 3.64k | if (image->depth <= 8) |
2331 | 1.33k | { |
2332 | 7.79k | for (x=0; x < (ssize_t) image->columns; x++) |
2333 | 6.45k | { |
2334 | 6.45k | if (IsPixelGray(image,p) == MagickFalse) |
2335 | 0 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma( |
2336 | 0 | image,p)),max_value); |
2337 | 6.45k | else |
2338 | 6.45k | { |
2339 | 6.45k | if (image->depth == 8) |
2340 | 0 | pixel=ScaleQuantumToChar(GetPixelRed(image,p)); |
2341 | 6.45k | else |
2342 | 6.45k | pixel=ScaleQuantumToAny(GetPixelRed(image,p), |
2343 | 6.45k | max_value); |
2344 | 6.45k | } |
2345 | 6.45k | q=PopCharPixel((unsigned char) pixel,q); |
2346 | 6.45k | p+=(ptrdiff_t) GetPixelChannels(image); |
2347 | 6.45k | } |
2348 | 1.33k | extent=(size_t) (q-pixels); |
2349 | 1.33k | break; |
2350 | 1.33k | } |
2351 | 2.31k | if (image->depth <= 16) |
2352 | 1.05k | { |
2353 | 2.99k | for (x=0; x < (ssize_t) image->columns; x++) |
2354 | 1.94k | { |
2355 | 1.94k | if (IsPixelGray(image,p) == MagickFalse) |
2356 | 0 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image, |
2357 | 0 | p)),max_value); |
2358 | 1.94k | else |
2359 | 1.94k | { |
2360 | 1.94k | if (image->depth == 16) |
2361 | 0 | pixel=ScaleQuantumToShort(GetPixelRed(image,p)); |
2362 | 1.94k | else |
2363 | 1.94k | pixel=ScaleQuantumToAny(GetPixelRed(image,p), |
2364 | 1.94k | max_value); |
2365 | 1.94k | } |
2366 | 1.94k | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2367 | 1.94k | p+=(ptrdiff_t) GetPixelChannels(image); |
2368 | 1.94k | } |
2369 | 1.05k | extent=(size_t) (q-pixels); |
2370 | 1.05k | break; |
2371 | 1.05k | } |
2372 | 8.49k | for (x=0; x < (ssize_t) image->columns; x++) |
2373 | 7.23k | { |
2374 | 7.23k | if (IsPixelGray(image,p) == MagickFalse) |
2375 | 0 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p)), |
2376 | 0 | max_value); |
2377 | 7.23k | else |
2378 | 7.23k | { |
2379 | 7.23k | if (image->depth == 16) |
2380 | 0 | pixel=ScaleQuantumToLong(GetPixelRed(image,p)); |
2381 | 7.23k | else |
2382 | 7.23k | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2383 | 7.23k | } |
2384 | 7.23k | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2385 | 7.23k | p+=(ptrdiff_t) GetPixelChannels(image); |
2386 | 7.23k | } |
2387 | 1.25k | extent=(size_t) (q-pixels); |
2388 | 1.25k | break; |
2389 | 2.31k | } |
2390 | 5.80k | } |
2391 | 5.80k | count=WriteBlob(image,extent,pixels); |
2392 | 5.80k | if (count != (ssize_t) extent) |
2393 | 0 | break; |
2394 | 5.80k | if (image->previous == (Image *) NULL) |
2395 | 5.80k | { |
2396 | 5.80k | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2397 | 5.80k | image->rows); |
2398 | 5.80k | if (status == MagickFalse) |
2399 | 0 | break; |
2400 | 5.80k | } |
2401 | 5.80k | } |
2402 | 556 | quantum_info=DestroyQuantumInfo(quantum_info); |
2403 | 556 | break; |
2404 | 556 | } |
2405 | 831 | case '6': |
2406 | 831 | { |
2407 | 831 | unsigned char |
2408 | 831 | *pixels; |
2409 | | |
2410 | | /* |
2411 | | Convert image to a PNM image. |
2412 | | */ |
2413 | 831 | if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse) |
2414 | 242 | (void) TransformImageColorspace(image,sRGBColorspace,exception); |
2415 | 831 | if (image->depth > 32) |
2416 | 0 | image->depth=32; |
2417 | 831 | (void) FormatLocaleString(buffer,MagickPathExtent,"%.20g\n",(double) |
2418 | 831 | ((MagickOffsetType) GetQuantumRange(image->depth))); |
2419 | 831 | (void) WriteBlobString(image,buffer); |
2420 | 831 | quantum_info=AcquireQuantumInfo(image_info,image); |
2421 | 831 | if (quantum_info == (QuantumInfo *) NULL) |
2422 | 831 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2423 | 831 | (void) SetQuantumEndian(image,quantum_info,MSBEndian); |
2424 | 831 | pixels=GetQuantumPixels(quantum_info); |
2425 | 831 | extent=GetQuantumExtent(image,quantum_info,quantum_type); |
2426 | 13.6k | for (y=0; y < (ssize_t) image->rows; y++) |
2427 | 12.7k | { |
2428 | 12.7k | const Quantum |
2429 | 12.7k | *magick_restrict p; |
2430 | | |
2431 | 12.7k | ssize_t |
2432 | 12.7k | x; |
2433 | | |
2434 | 12.7k | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2435 | 12.7k | if (p == (const Quantum *) NULL) |
2436 | 0 | break; |
2437 | 12.7k | q=pixels; |
2438 | 12.7k | switch (image->depth) |
2439 | 12.7k | { |
2440 | 1.38k | case 8: |
2441 | 3.03k | case 16: |
2442 | 4.35k | case 32: |
2443 | 4.35k | { |
2444 | 4.35k | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
2445 | 4.35k | quantum_type,pixels,exception); |
2446 | 4.35k | break; |
2447 | 3.03k | } |
2448 | 8.42k | default: |
2449 | 8.42k | { |
2450 | 8.42k | if (image->depth <= 8) |
2451 | 4.42k | { |
2452 | 14.8k | for (x=0; x < (ssize_t) image->columns; x++) |
2453 | 10.4k | { |
2454 | 10.4k | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2455 | 10.4k | q=PopCharPixel((unsigned char) pixel,q); |
2456 | 10.4k | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
2457 | 10.4k | q=PopCharPixel((unsigned char) pixel,q); |
2458 | 10.4k | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
2459 | 10.4k | q=PopCharPixel((unsigned char) pixel,q); |
2460 | 10.4k | p+=(ptrdiff_t) GetPixelChannels(image); |
2461 | 10.4k | } |
2462 | 4.42k | extent=(size_t) (q-pixels); |
2463 | 4.42k | break; |
2464 | 4.42k | } |
2465 | 4.00k | if (image->depth <= 16) |
2466 | 1.70k | { |
2467 | 4.28k | for (x=0; x < (ssize_t) image->columns; x++) |
2468 | 2.58k | { |
2469 | 2.58k | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2470 | 2.58k | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2471 | 2.58k | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
2472 | 2.58k | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2473 | 2.58k | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
2474 | 2.58k | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2475 | 2.58k | p+=(ptrdiff_t) GetPixelChannels(image); |
2476 | 2.58k | } |
2477 | 1.70k | extent=(size_t) (q-pixels); |
2478 | 1.70k | break; |
2479 | 1.70k | } |
2480 | 8.87k | for (x=0; x < (ssize_t) image->columns; x++) |
2481 | 6.57k | { |
2482 | 6.57k | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2483 | 6.57k | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2484 | 6.57k | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
2485 | 6.57k | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2486 | 6.57k | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
2487 | 6.57k | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2488 | 6.57k | p+=(ptrdiff_t) GetPixelChannels(image); |
2489 | 6.57k | } |
2490 | 2.29k | extent=(size_t) (q-pixels); |
2491 | 2.29k | break; |
2492 | 4.00k | } |
2493 | 12.7k | } |
2494 | 12.7k | count=WriteBlob(image,extent,pixels); |
2495 | 12.7k | if (count != (ssize_t) extent) |
2496 | 0 | break; |
2497 | 12.7k | if (image->previous == (Image *) NULL) |
2498 | 12.7k | { |
2499 | 12.7k | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2500 | 12.7k | image->rows); |
2501 | 12.7k | if (status == MagickFalse) |
2502 | 0 | break; |
2503 | 12.7k | } |
2504 | 12.7k | } |
2505 | 831 | quantum_info=DestroyQuantumInfo(quantum_info); |
2506 | 831 | break; |
2507 | 831 | } |
2508 | 0 | case '7': |
2509 | 0 | { |
2510 | 0 | unsigned char |
2511 | 0 | *pixels; |
2512 | | |
2513 | | /* |
2514 | | Convert image to a PAM. |
2515 | | */ |
2516 | 0 | if (image->depth > 32) |
2517 | 0 | image->depth=32; |
2518 | 0 | quantum_info=AcquireQuantumInfo(image_info,image); |
2519 | 0 | if (quantum_info == (QuantumInfo *) NULL) |
2520 | 0 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2521 | 0 | (void) SetQuantumEndian(image,quantum_info,MSBEndian); |
2522 | 0 | pixels=GetQuantumPixels(quantum_info); |
2523 | 0 | for (y=0; y < (ssize_t) image->rows; y++) |
2524 | 0 | { |
2525 | 0 | const Quantum |
2526 | 0 | *magick_restrict p; |
2527 | |
|
2528 | 0 | ssize_t |
2529 | 0 | x; |
2530 | |
|
2531 | 0 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2532 | 0 | if (p == (const Quantum *) NULL) |
2533 | 0 | break; |
2534 | 0 | q=pixels; |
2535 | 0 | switch (image->depth) |
2536 | 0 | { |
2537 | 0 | case 8: |
2538 | 0 | case 16: |
2539 | 0 | case 32: |
2540 | 0 | { |
2541 | 0 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
2542 | 0 | quantum_type,pixels,exception); |
2543 | 0 | break; |
2544 | 0 | } |
2545 | 0 | default: |
2546 | 0 | { |
2547 | 0 | switch (quantum_type) |
2548 | 0 | { |
2549 | 0 | case GrayQuantum: |
2550 | 0 | case GrayAlphaQuantum: |
2551 | 0 | { |
2552 | 0 | if (image->depth <= 8) |
2553 | 0 | { |
2554 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2555 | 0 | { |
2556 | 0 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma( |
2557 | 0 | image,p)),max_value); |
2558 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2559 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2560 | 0 | { |
2561 | 0 | pixel=(unsigned char) ScaleQuantumToAny( |
2562 | 0 | GetPixelAlpha(image,p),max_value); |
2563 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2564 | 0 | } |
2565 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2566 | 0 | } |
2567 | 0 | break; |
2568 | 0 | } |
2569 | 0 | if (image->depth <= 16) |
2570 | 0 | { |
2571 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2572 | 0 | { |
2573 | 0 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma( |
2574 | 0 | image,p)),max_value); |
2575 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2576 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2577 | 0 | { |
2578 | 0 | pixel=(unsigned char) ScaleQuantumToAny( |
2579 | 0 | GetPixelAlpha(image,p),max_value); |
2580 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2581 | 0 | } |
2582 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2583 | 0 | } |
2584 | 0 | break; |
2585 | 0 | } |
2586 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2587 | 0 | { |
2588 | 0 | pixel=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image, |
2589 | 0 | p)),max_value); |
2590 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2591 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2592 | 0 | { |
2593 | 0 | pixel=(unsigned char) ScaleQuantumToAny( |
2594 | 0 | GetPixelAlpha(image,p),max_value); |
2595 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2596 | 0 | } |
2597 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2598 | 0 | } |
2599 | 0 | break; |
2600 | 0 | } |
2601 | 0 | case CMYKQuantum: |
2602 | 0 | case CMYKAQuantum: |
2603 | 0 | { |
2604 | 0 | if (image->depth <= 8) |
2605 | 0 | { |
2606 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2607 | 0 | { |
2608 | 0 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2609 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2610 | 0 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
2611 | 0 | max_value); |
2612 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2613 | 0 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
2614 | 0 | max_value); |
2615 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2616 | 0 | pixel=ScaleQuantumToAny(GetPixelBlack(image,p), |
2617 | 0 | max_value); |
2618 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2619 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2620 | 0 | { |
2621 | 0 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
2622 | 0 | max_value); |
2623 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2624 | 0 | } |
2625 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2626 | 0 | } |
2627 | 0 | break; |
2628 | 0 | } |
2629 | 0 | if (image->depth <= 16) |
2630 | 0 | { |
2631 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2632 | 0 | { |
2633 | 0 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2634 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2635 | 0 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
2636 | 0 | max_value); |
2637 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2638 | 0 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
2639 | 0 | max_value); |
2640 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2641 | 0 | pixel=ScaleQuantumToAny(GetPixelBlack(image,p), |
2642 | 0 | max_value); |
2643 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2644 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2645 | 0 | { |
2646 | 0 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
2647 | 0 | max_value); |
2648 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2649 | 0 | } |
2650 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2651 | 0 | } |
2652 | 0 | break; |
2653 | 0 | } |
2654 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2655 | 0 | { |
2656 | 0 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2657 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2658 | 0 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
2659 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2660 | 0 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
2661 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2662 | 0 | pixel=ScaleQuantumToAny(GetPixelBlack(image,p),max_value); |
2663 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2664 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2665 | 0 | { |
2666 | 0 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
2667 | 0 | max_value); |
2668 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2669 | 0 | } |
2670 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2671 | 0 | } |
2672 | 0 | break; |
2673 | 0 | } |
2674 | 0 | default: |
2675 | 0 | { |
2676 | 0 | if (image->depth <= 8) |
2677 | 0 | { |
2678 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2679 | 0 | { |
2680 | 0 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2681 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2682 | 0 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
2683 | 0 | max_value); |
2684 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2685 | 0 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
2686 | 0 | max_value); |
2687 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2688 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2689 | 0 | { |
2690 | 0 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
2691 | 0 | max_value); |
2692 | 0 | q=PopCharPixel((unsigned char) pixel,q); |
2693 | 0 | } |
2694 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2695 | 0 | } |
2696 | 0 | break; |
2697 | 0 | } |
2698 | 0 | if (image->depth <= 16) |
2699 | 0 | { |
2700 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2701 | 0 | { |
2702 | 0 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2703 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2704 | 0 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p), |
2705 | 0 | max_value); |
2706 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2707 | 0 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p), |
2708 | 0 | max_value); |
2709 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2710 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2711 | 0 | { |
2712 | 0 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
2713 | 0 | max_value); |
2714 | 0 | q=PopShortPixel(MSBEndian,(unsigned short) pixel,q); |
2715 | 0 | } |
2716 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2717 | 0 | } |
2718 | 0 | break; |
2719 | 0 | } |
2720 | 0 | for (x=0; x < (ssize_t) image->columns; x++) |
2721 | 0 | { |
2722 | 0 | pixel=ScaleQuantumToAny(GetPixelRed(image,p),max_value); |
2723 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2724 | 0 | pixel=ScaleQuantumToAny(GetPixelGreen(image,p),max_value); |
2725 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2726 | 0 | pixel=ScaleQuantumToAny(GetPixelBlue(image,p),max_value); |
2727 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2728 | 0 | if (image->alpha_trait != UndefinedPixelTrait) |
2729 | 0 | { |
2730 | 0 | pixel=ScaleQuantumToAny(GetPixelAlpha(image,p), |
2731 | 0 | max_value); |
2732 | 0 | q=PopLongPixel(MSBEndian,(unsigned int) pixel,q); |
2733 | 0 | } |
2734 | 0 | p+=(ptrdiff_t) GetPixelChannels(image); |
2735 | 0 | } |
2736 | 0 | break; |
2737 | 0 | } |
2738 | 0 | } |
2739 | 0 | extent=(size_t) (q-pixels); |
2740 | 0 | break; |
2741 | 0 | } |
2742 | 0 | } |
2743 | 0 | count=WriteBlob(image,extent,pixels); |
2744 | 0 | if (count != (ssize_t) extent) |
2745 | 0 | break; |
2746 | 0 | if (image->previous == (Image *) NULL) |
2747 | 0 | { |
2748 | 0 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2749 | 0 | image->rows); |
2750 | 0 | if (status == MagickFalse) |
2751 | 0 | break; |
2752 | 0 | } |
2753 | 0 | } |
2754 | 0 | quantum_info=DestroyQuantumInfo(quantum_info); |
2755 | 0 | break; |
2756 | 0 | } |
2757 | 0 | case 'F': |
2758 | 0 | case 'f': |
2759 | 0 | { |
2760 | 0 | unsigned char |
2761 | 0 | *pixels; |
2762 | |
|
2763 | 0 | (void) WriteBlobString(image,image->endian == LSBEndian ? "-1.0\n" : |
2764 | 0 | "1.0\n"); |
2765 | 0 | image->depth=32; |
2766 | 0 | quantum_type=format == 'f' ? GrayQuantum : RGBQuantum; |
2767 | 0 | quantum_info=AcquireQuantumInfo(image_info,image); |
2768 | 0 | if (quantum_info == (QuantumInfo *) NULL) |
2769 | 0 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2770 | 0 | status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); |
2771 | 0 | if (status == MagickFalse) |
2772 | 0 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2773 | 0 | pixels=GetQuantumPixels(quantum_info); |
2774 | 0 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
2775 | 0 | { |
2776 | 0 | const Quantum |
2777 | 0 | *magick_restrict p; |
2778 | |
|
2779 | 0 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2780 | 0 | if (p == (const Quantum *) NULL) |
2781 | 0 | break; |
2782 | 0 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
2783 | 0 | quantum_type,pixels,exception); |
2784 | 0 | (void) WriteBlob(image,extent,pixels); |
2785 | 0 | if (image->previous == (Image *) NULL) |
2786 | 0 | { |
2787 | 0 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2788 | 0 | image->rows); |
2789 | 0 | if (status == MagickFalse) |
2790 | 0 | break; |
2791 | 0 | } |
2792 | 0 | } |
2793 | 0 | quantum_info=DestroyQuantumInfo(quantum_info); |
2794 | 0 | break; |
2795 | 0 | } |
2796 | 0 | case 'H': |
2797 | 0 | case 'h': |
2798 | 0 | { |
2799 | 0 | unsigned char |
2800 | 0 | *pixels; |
2801 | |
|
2802 | 0 | (void) WriteBlobString(image,image->endian == LSBEndian ? "-1.0\n" : |
2803 | 0 | "1.0\n"); |
2804 | 0 | image->depth=16; |
2805 | 0 | quantum_type=format == 'h' ? GrayQuantum : RGBQuantum; |
2806 | 0 | quantum_info=AcquireQuantumInfo(image_info,image); |
2807 | 0 | if (quantum_info == (QuantumInfo *) NULL) |
2808 | 0 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2809 | 0 | status=SetQuantumFormat(image,quantum_info,FloatingPointQuantumFormat); |
2810 | 0 | if (status == MagickFalse) |
2811 | 0 | ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed"); |
2812 | 0 | pixels=GetQuantumPixels(quantum_info); |
2813 | 0 | for (y=(ssize_t) image->rows-1; y >= 0; y--) |
2814 | 0 | { |
2815 | 0 | const Quantum |
2816 | 0 | *magick_restrict p; |
2817 | |
|
2818 | 0 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
2819 | 0 | if (p == (const Quantum *) NULL) |
2820 | 0 | break; |
2821 | 0 | extent=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info, |
2822 | 0 | quantum_type,pixels,exception); |
2823 | 0 | (void) WriteBlob(image,extent,pixels); |
2824 | 0 | if (image->previous == (Image *) NULL) |
2825 | 0 | { |
2826 | 0 | status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y, |
2827 | 0 | image->rows); |
2828 | 0 | if (status == MagickFalse) |
2829 | 0 | break; |
2830 | 0 | } |
2831 | 0 | } |
2832 | 0 | quantum_info=DestroyQuantumInfo(quantum_info); |
2833 | 0 | break; |
2834 | 0 | } |
2835 | 0 | default: |
2836 | 0 | break; |
2837 | 2.00k | } |
2838 | 2.00k | if (GetNextImageInList(image) == (Image *) NULL) |
2839 | 2.00k | break; |
2840 | 0 | image=SyncNextImageInList(image); |
2841 | 0 | status=SetImageProgress(image,SaveImagesTag,scene++,number_scenes); |
2842 | 0 | if (status == MagickFalse) |
2843 | 0 | break; |
2844 | 0 | } while (image_info->adjoin != MagickFalse); |
2845 | 2.00k | if (CloseBlob(image) == MagickFalse) |
2846 | 0 | status=MagickFalse; |
2847 | 2.00k | return(status); |
2848 | 2.00k | } |