Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: rdjpgcom.c

Issue 1953443002: Update to libjpeg_turbo 1.4.90 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « rdjpgcom.1 ('k') | rdppm.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * rdjpgcom.c 2 * rdjpgcom.c
3 * 3 *
4 * This file was part of the Independent JPEG Group's software:
4 * Copyright (C) 1994-1997, Thomas G. Lane. 5 * Copyright (C) 1994-1997, Thomas G. Lane.
5 * Modified 2009 by Bill Allombert, Guido Vollbeding. 6 * Modified 2009 by Bill Allombert, Guido Vollbeding.
6 * This file is part of the Independent JPEG Group's software. 7 * It was modified by The libjpeg-turbo Project to include only code relevant
7 * For conditions of distribution and use, see the accompanying README file. 8 * to libjpeg-turbo.
9 * For conditions of distribution and use, see the accompanying README.ijg
10 * file.
8 * 11 *
9 * This file contains a very simple stand-alone application that displays 12 * This file contains a very simple stand-alone application that displays
10 * the text in COM (comment) markers in a JFIF file. 13 * the text in COM (comment) markers in a JFIF file.
11 * This may be useful as an example of the minimum logic needed to parse 14 * This may be useful as an example of the minimum logic needed to parse
12 * JPEG markers. 15 * JPEG markers.
13 */ 16 */
14 17
15 #define JPEG_CJPEG_DJPEG» /* to get the command-line config symbols */ 18 #define JPEG_CJPEG_DJPEG /* to get the command-line config symbols */
16 #include "jinclude.h"» » /* get auto-config symbols, <stdio.h> */ 19 #include "jinclude.h" /* get auto-config symbols, <stdio.h> */
17 20
18 #ifdef HAVE_LOCALE_H 21 #ifdef HAVE_LOCALE_H
19 #include <locale.h>» » /* Bill Allombert: use locale for isprint */ 22 #include <locale.h> /* Bill Allombert: use locale for isprint */
20 #endif 23 #endif
21 #include <ctype.h>» » /* to declare isupper(), tolower() */ 24 #include <ctype.h> /* to declare isupper(), tolower() */
22 #ifdef USE_SETMODE 25 #ifdef USE_SETMODE
23 #include <fcntl.h>» » /* to declare setmode()'s parameter macros */ 26 #include <fcntl.h> /* to declare setmode()'s parameter macros */
24 /* If you have setmode() but not <io.h>, just delete this line: */ 27 /* If you have setmode() but not <io.h>, just delete this line: */
25 #include <io.h>»» » /* to declare setmode() */ 28 #include <io.h> /* to declare setmode() */
26 #endif 29 #endif
27 30
28 #ifdef USE_CCOMMAND» » /* command-line reader for Macintosh */ 31 #ifdef USE_CCOMMAND /* command-line reader for Macintosh */
29 #ifdef __MWERKS__ 32 #ifdef __MWERKS__
30 #include <SIOUX.h> /* Metrowerks needs this */ 33 #include <SIOUX.h> /* Metrowerks needs this */
31 #include <console.h>» » /* ... and this */ 34 #include <console.h> /* ... and this */
32 #endif 35 #endif
33 #ifdef THINK_C 36 #ifdef THINK_C
34 #include <console.h>» » /* Think declares it here */ 37 #include <console.h> /* Think declares it here */
35 #endif 38 #endif
36 #endif 39 #endif
37 40
38 #ifdef DONT_USE_B_MODE» » /* define mode parameters for fopen() */ 41 #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
39 #define READ_BINARY» "r" 42 #define READ_BINARY "r"
40 #else 43 #else
41 #ifdef VMS» » » /* VMS is very nonstandard */ 44 #define READ_BINARY "rb"
42 #define READ_BINARY» "rb", "ctx=stm"
43 #else» » » » /* standard ANSI-compliant case */
44 #define READ_BINARY» "rb"
45 #endif
46 #endif 45 #endif
47 46
48 #ifndef EXIT_FAILURE» » /* define exit() codes if not provided */ 47 #ifndef EXIT_FAILURE /* define exit() codes if not provided */
49 #define EXIT_FAILURE 1 48 #define EXIT_FAILURE 1
50 #endif 49 #endif
51 #ifndef EXIT_SUCCESS 50 #ifndef EXIT_SUCCESS
52 #ifdef VMS
53 #define EXIT_SUCCESS 1 /* VMS is very nonstandard */
54 #else
55 #define EXIT_SUCCESS 0 51 #define EXIT_SUCCESS 0
56 #endif 52 #endif
57 #endif
58 53
59 54
60 /* 55 /*
61 * These macros are used to read the input file. 56 * These macros are used to read the input file.
62 * To reuse this code in another application, you might need to change these. 57 * To reuse this code in another application, you might need to change these.
63 */ 58 */
64 59
65 static FILE * infile;» » /* input JPEG file */ 60 static FILE *infile; /* input JPEG file */
66 61
67 /* Return next input byte, or EOF if no more */ 62 /* Return next input byte, or EOF if no more */
68 #define NEXTBYTE() getc(infile) 63 #define NEXTBYTE() getc(infile)
69 64
70 65
71 /* Error exit handler */ 66 /* Error exit handler */
72 #define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE)) 67 #define ERREXIT(msg) (fprintf(stderr, "%s\n", msg), exit(EXIT_FAILURE))
73 68
74 69
75 /* Read one byte, testing for EOF */ 70 /* Read one byte, testing for EOF */
(...skipping 24 matching lines...) Expand all
100 return (((unsigned int) c1) << 8) + ((unsigned int) c2); 95 return (((unsigned int) c1) << 8) + ((unsigned int) c2);
101 } 96 }
102 97
103 98
104 /* 99 /*
105 * JPEG markers consist of one or more 0xFF bytes, followed by a marker 100 * JPEG markers consist of one or more 0xFF bytes, followed by a marker
106 * code byte (which is not an FF). Here are the marker codes of interest 101 * code byte (which is not an FF). Here are the marker codes of interest
107 * in this program. (See jdmarker.c for a more complete list.) 102 * in this program. (See jdmarker.c for a more complete list.)
108 */ 103 */
109 104
110 #define M_SOF0 0xC0» » /* Start Of Frame N */ 105 #define M_SOF0 0xC0 /* Start Of Frame N */
111 #define M_SOF1 0xC1» » /* N indicates which compression process */ 106 #define M_SOF1 0xC1 /* N indicates which compression process */
112 #define M_SOF2 0xC2» » /* Only SOF0-SOF2 are now in common use */ 107 #define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
113 #define M_SOF3 0xC3 108 #define M_SOF3 0xC3
114 #define M_SOF5 0xC5» » /* NB: codes C4 and CC are NOT SOF markers */ 109 #define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
115 #define M_SOF6 0xC6 110 #define M_SOF6 0xC6
116 #define M_SOF7 0xC7 111 #define M_SOF7 0xC7
117 #define M_SOF9 0xC9 112 #define M_SOF9 0xC9
118 #define M_SOF10 0xCA 113 #define M_SOF10 0xCA
119 #define M_SOF11 0xCB 114 #define M_SOF11 0xCB
120 #define M_SOF13 0xCD 115 #define M_SOF13 0xCD
121 #define M_SOF14 0xCE 116 #define M_SOF14 0xCE
122 #define M_SOF15 0xCF 117 #define M_SOF15 0xCF
123 #define M_SOI 0xD8» » /* Start Of Image (beginning of datastream) */ 118 #define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */
124 #define M_EOI 0xD9» » /* End Of Image (end of datastream) */ 119 #define M_EOI 0xD9 /* End Of Image (end of datastream) */
125 #define M_SOS 0xDA» » /* Start Of Scan (begins compressed data) */ 120 #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
126 #define M_APP0» 0xE0» » /* Application-specific marker, type N */ 121 #define M_APP0 0xE0 /* Application-specific marker, type N */
127 #define M_APP12»0xEC» » /* (we don't bother to list all 16 APPn's) */ 122 #define M_APP12 0xEC /* (we don't bother to list all 16 APPn's) */
128 #define M_COM 0xFE» » /* COMment */ 123 #define M_COM 0xFE /* COMment */
129 124
130 125
131 /* 126 /*
132 * Find the next JPEG marker and return its marker code. 127 * Find the next JPEG marker and return its marker code.
133 * We expect at least one FF byte, possibly more if the compressor used FFs 128 * We expect at least one FF byte, possibly more if the compressor used FFs
134 * to pad the file. 129 * to pad the file.
135 * There could also be non-FF garbage between markers. The treatment of such 130 * There could also be non-FF garbage between markers. The treatment of such
136 * garbage is unspecified; we choose to skip over it but emit a warning msg. 131 * garbage is unspecified; we choose to skip over it but emit a warning msg.
137 * NB: this routine must not be used after seeing SOS marker, since it will 132 * NB: this routine must not be used after seeing SOS marker, since it will
138 * not deal correctly with FF/00 sequences in the compressed image data... 133 * not deal correctly with FF/00 sequences in the compressed image data...
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 putc(ch, stdout); 241 putc(ch, stdout);
247 /* Emit the character in a readable form. 242 /* Emit the character in a readable form.
248 * Nonprintables are converted to \nnn form, 243 * Nonprintables are converted to \nnn form,
249 * while \ is converted to \\. 244 * while \ is converted to \\.
250 * Newlines in CR, CR/LF, or LF form will be printed as one newline. 245 * Newlines in CR, CR/LF, or LF form will be printed as one newline.
251 */ 246 */
252 } else if (ch == '\r') { 247 } else if (ch == '\r') {
253 printf("\n"); 248 printf("\n");
254 } else if (ch == '\n') { 249 } else if (ch == '\n') {
255 if (lastch != '\r') 250 if (lastch != '\r')
256 » printf("\n"); 251 printf("\n");
257 } else if (ch == '\\') { 252 } else if (ch == '\\') {
258 printf("\\\\"); 253 printf("\\\\");
259 } else if (isprint(ch)) { 254 } else if (isprint(ch)) {
260 putc(ch, stdout); 255 putc(ch, stdout);
261 } else { 256 } else {
262 printf("\\%03o", ch); 257 printf("\\%03o", ch);
263 } 258 }
264 lastch = ch; 259 lastch = ch;
265 length--; 260 length--;
266 } 261 }
(...skipping 10 matching lines...) Expand all
277 * Process a SOFn marker. 272 * Process a SOFn marker.
278 * This code is only needed if you want to know the image dimensions... 273 * This code is only needed if you want to know the image dimensions...
279 */ 274 */
280 275
281 static void 276 static void
282 process_SOFn (int marker) 277 process_SOFn (int marker)
283 { 278 {
284 unsigned int length; 279 unsigned int length;
285 unsigned int image_height, image_width; 280 unsigned int image_height, image_width;
286 int data_precision, num_components; 281 int data_precision, num_components;
287 const char * process; 282 const char *process;
288 int ci; 283 int ci;
289 284
290 length = read_2_bytes();» /* usual parameter length count */ 285 length = read_2_bytes(); /* usual parameter length count */
291 286
292 data_precision = read_1_byte(); 287 data_precision = read_1_byte();
293 image_height = read_2_bytes(); 288 image_height = read_2_bytes();
294 image_width = read_2_bytes(); 289 image_width = read_2_bytes();
295 num_components = read_1_byte(); 290 num_components = read_1_byte();
296 291
297 switch (marker) { 292 switch (marker) {
298 case M_SOF0:» process = "Baseline"; break; 293 case M_SOF0: process = "Baseline"; break;
299 case M_SOF1:» process = "Extended sequential"; break; 294 case M_SOF1: process = "Extended sequential"; break;
300 case M_SOF2:» process = "Progressive"; break; 295 case M_SOF2: process = "Progressive"; break;
301 case M_SOF3:» process = "Lossless"; break; 296 case M_SOF3: process = "Lossless"; break;
302 case M_SOF5:» process = "Differential sequential"; break; 297 case M_SOF5: process = "Differential sequential"; break;
303 case M_SOF6:» process = "Differential progressive"; break; 298 case M_SOF6: process = "Differential progressive"; break;
304 case M_SOF7:» process = "Differential lossless"; break; 299 case M_SOF7: process = "Differential lossless"; break;
305 case M_SOF9:» process = "Extended sequential, arithmetic coding"; break; 300 case M_SOF9: process = "Extended sequential, arithmetic coding"; break;
306 case M_SOF10:»process = "Progressive, arithmetic coding"; break; 301 case M_SOF10: process = "Progressive, arithmetic coding"; break;
307 case M_SOF11:»process = "Lossless, arithmetic coding"; break; 302 case M_SOF11: process = "Lossless, arithmetic coding"; break;
308 case M_SOF13:»process = "Differential sequential, arithmetic coding"; break; 303 case M_SOF13: process = "Differential sequential, arithmetic coding"; break;
309 case M_SOF14:»process = "Differential progressive, arithmetic coding"; break; 304 case M_SOF14: process = "Differential progressive, arithmetic coding"; break;
310 case M_SOF15:»process = "Differential lossless, arithmetic coding"; break; 305 case M_SOF15: process = "Differential lossless, arithmetic coding"; break;
311 default:» process = "Unknown"; break; 306 default: process = "Unknown"; break;
312 } 307 }
313 308
314 printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n", 309 printf("JPEG image is %uw * %uh, %d color components, %d bits per sample\n",
315 » image_width, image_height, num_components, data_precision); 310 image_width, image_height, num_components, data_precision);
316 printf("JPEG process: %s\n", process); 311 printf("JPEG process: %s\n", process);
317 312
318 if (length != (unsigned int) (8 + num_components * 3)) 313 if (length != (unsigned int) (8 + num_components * 3))
319 ERREXIT("Bogus SOF marker length"); 314 ERREXIT("Bogus SOF marker length");
320 315
321 for (ci = 0; ci < num_components; ci++) { 316 for (ci = 0; ci < num_components; ci++) {
322 (void) read_1_byte();» /* Component ID code */ 317 (void) read_1_byte(); /* Component ID code */
323 (void) read_1_byte();» /* H, V sampling factors */ 318 (void) read_1_byte(); /* H, V sampling factors */
324 (void) read_1_byte();» /* Quantization table number */ 319 (void) read_1_byte(); /* Quantization table number */
325 } 320 }
326 } 321 }
327 322
328 323
329 /* 324 /*
330 * Parse the marker stream until SOS or EOI is seen; 325 * Parse the marker stream until SOS or EOI is seen;
331 * display any COM markers. 326 * display any COM markers.
332 * While the companion program wrjpgcom will always insert COM markers before 327 * While the companion program wrjpgcom will always insert COM markers before
333 * SOFn, other implementations might not, so we scan to SOS before stopping. 328 * SOFn, other implementations might not, so we scan to SOS before stopping.
334 * If we were only interested in the image dimensions, we would stop at SOFn. 329 * If we were only interested in the image dimensions, we would stop at SOFn.
(...skipping 10 matching lines...) Expand all
345 if (first_marker() != M_SOI) 340 if (first_marker() != M_SOI)
346 ERREXIT("Expected SOI marker first"); 341 ERREXIT("Expected SOI marker first");
347 342
348 /* Scan miscellaneous markers until we reach SOS. */ 343 /* Scan miscellaneous markers until we reach SOS. */
349 for (;;) { 344 for (;;) {
350 marker = next_marker(); 345 marker = next_marker();
351 switch (marker) { 346 switch (marker) {
352 /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, 347 /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,
353 * treated as SOFn. C4 in particular is actually DHT. 348 * treated as SOFn. C4 in particular is actually DHT.
354 */ 349 */
355 case M_SOF0:» » /* Baseline */ 350 case M_SOF0: /* Baseline */
356 case M_SOF1:» » /* Extended sequential, Huffman */ 351 case M_SOF1: /* Extended sequential, Huffman */
357 case M_SOF2:» » /* Progressive, Huffman */ 352 case M_SOF2: /* Progressive, Huffman */
358 case M_SOF3:» » /* Lossless, Huffman */ 353 case M_SOF3: /* Lossless, Huffman */
359 case M_SOF5:» » /* Differential sequential, Huffman */ 354 case M_SOF5: /* Differential sequential, Huffman */
360 case M_SOF6:» » /* Differential progressive, Huffman */ 355 case M_SOF6: /* Differential progressive, Huffman */
361 case M_SOF7:» » /* Differential lossless, Huffman */ 356 case M_SOF7: /* Differential lossless, Huffman */
362 case M_SOF9:» » /* Extended sequential, arithmetic */ 357 case M_SOF9: /* Extended sequential, arithmetic */
363 case M_SOF10:» » /* Progressive, arithmetic */ 358 case M_SOF10: /* Progressive, arithmetic */
364 case M_SOF11:» » /* Lossless, arithmetic */ 359 case M_SOF11: /* Lossless, arithmetic */
365 case M_SOF13:» » /* Differential sequential, arithmetic */ 360 case M_SOF13: /* Differential sequential, arithmetic */
366 case M_SOF14:» » /* Differential progressive, arithmetic */ 361 case M_SOF14: /* Differential progressive, arithmetic */
367 case M_SOF15:» » /* Differential lossless, arithmetic */ 362 case M_SOF15: /* Differential lossless, arithmetic */
368 if (verbose) 363 if (verbose)
369 » process_SOFn(marker); 364 process_SOFn(marker);
370 else 365 else
371 » skip_variable(); 366 skip_variable();
372 break; 367 break;
373 368
374 case M_SOS:»» » /* stop before hitting compressed data */ 369 case M_SOS: /* stop before hitting compressed data */
375 return marker; 370 return marker;
376 371
377 case M_EOI:»» » /* in case it's a tables-only JPEG stream */ 372 case M_EOI: /* in case it's a tables-only JPEG stream */
378 return marker; 373 return marker;
379 374
380 case M_COM: 375 case M_COM:
381 process_COM(raw); 376 process_COM(raw);
382 break; 377 break;
383 378
384 case M_APP12: 379 case M_APP12:
385 /* Some digital camera makers put useful textual information into 380 /* Some digital camera makers put useful textual information into
386 * APP12 markers, so we print those out too when in -verbose mode. 381 * APP12 markers, so we print those out too when in -verbose mode.
387 */ 382 */
388 if (verbose) { 383 if (verbose) {
389 » printf("APP12 contains:\n"); 384 printf("APP12 contains:\n");
390 » process_COM(raw); 385 process_COM(raw);
391 } else 386 } else
392 » skip_variable(); 387 skip_variable();
393 break; 388 break;
394 389
395 default:» » » /* Anything else just gets skipped */ 390 default: /* Anything else just gets skipped */
396 skip_variable();» » /* we assume it has a parameter count... */ 391 skip_variable(); /* we assume it has a parameter count... */
397 break; 392 break;
398 } 393 }
399 } /* end loop */ 394 } /* end loop */
400 } 395 }
401 396
402 397
403 /* Command line parsing code */ 398 /* Command line parsing code */
404 399
405 static const char * progname;» /* program name for error messages */ 400 static const char *progname; /* program name for error messages */
406 401
407 402
408 static void 403 static void
409 usage (void) 404 usage (void)
410 /* complain about bad command line */ 405 /* complain about bad command line */
411 { 406 {
412 fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n"); 407 fprintf(stderr, "rdjpgcom displays any textual comments in a JPEG file.\n");
413 408
414 fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname); 409 fprintf(stderr, "Usage: %s [switches] [inputfile]\n", progname);
415 410
416 fprintf(stderr, "Switches (names may be abbreviated):\n"); 411 fprintf(stderr, "Switches (names may be abbreviated):\n");
417 fprintf(stderr, " -raw Display non-printable characters in comments (u nsafe)\n"); 412 fprintf(stderr, " -raw Display non-printable characters in comments (u nsafe)\n");
418 fprintf(stderr, " -verbose Also display dimensions of JPEG image\n"); 413 fprintf(stderr, " -verbose Also display dimensions of JPEG image\n");
419 414
420 exit(EXIT_FAILURE); 415 exit(EXIT_FAILURE);
421 } 416 }
422 417
423 418
424 static int 419 static int
425 keymatch (char * arg, const char * keyword, int minchars) 420 keymatch (char *arg, const char *keyword, int minchars)
426 /* Case-insensitive matching of (possibly abbreviated) keyword switches. */ 421 /* Case-insensitive matching of (possibly abbreviated) keyword switches. */
427 /* keyword is the constant keyword (must be lower case already), */ 422 /* keyword is the constant keyword (must be lower case already), */
428 /* minchars is length of minimum legal abbreviation. */ 423 /* minchars is length of minimum legal abbreviation. */
429 { 424 {
430 register int ca, ck; 425 register int ca, ck;
431 register int nmatched = 0; 426 register int nmatched = 0;
432 427
433 while ((ca = *arg++) != '\0') { 428 while ((ca = *arg++) != '\0') {
434 if ((ck = *keyword++) == '\0') 429 if ((ck = *keyword++) == '\0')
435 return 0;»» » /* arg longer than keyword, no good */ 430 return 0; /* arg longer than keyword, no good */
436 if (isupper(ca))» » /* force arg to lcase (assume ck is already) */ 431 if (isupper(ca)) /* force arg to lcase (assume ck is already) */
437 ca = tolower(ca); 432 ca = tolower(ca);
438 if (ca != ck) 433 if (ca != ck)
439 return 0;»» » /* no good */ 434 return 0; /* no good */
440 nmatched++;»» » /* count matched characters */ 435 nmatched++; /* count matched characters */
441 } 436 }
442 /* reached end of argument; fail if it's too short for unique abbrev */ 437 /* reached end of argument; fail if it's too short for unique abbrev */
443 if (nmatched < minchars) 438 if (nmatched < minchars)
444 return 0; 439 return 0;
445 return 1;» » » /* A-OK */ 440 return 1; /* A-OK */
446 } 441 }
447 442
448 443
449 /* 444 /*
450 * The main program. 445 * The main program.
451 */ 446 */
452 447
453 int 448 int
454 main (int argc, char **argv) 449 main (int argc, char **argv)
455 { 450 {
456 int argn; 451 int argn;
457 char * arg; 452 char *arg;
458 int verbose = 0, raw = 0; 453 int verbose = 0, raw = 0;
459 454
460 /* On Mac, fetch a command line. */ 455 /* On Mac, fetch a command line. */
461 #ifdef USE_CCOMMAND 456 #ifdef USE_CCOMMAND
462 argc = ccommand(&argv); 457 argc = ccommand(&argv);
463 #endif 458 #endif
464 459
465 progname = argv[0]; 460 progname = argv[0];
466 if (progname == NULL || progname[0] == 0) 461 if (progname == NULL || progname[0] == 0)
467 progname = "rdjpgcom";» /* in case C library doesn't provide it */ 462 progname = "rdjpgcom"; /* in case C library doesn't provide it */
468 463
469 /* Parse switches, if any */ 464 /* Parse switches, if any */
470 for (argn = 1; argn < argc; argn++) { 465 for (argn = 1; argn < argc; argn++) {
471 arg = argv[argn]; 466 arg = argv[argn];
472 if (arg[0] != '-') 467 if (arg[0] != '-')
473 break;» » » /* not switch, must be file name */ 468 break; /* not switch, must be file name */
474 arg++;» » » /* advance over '-' */ 469 arg++; /* advance over '-' */
475 if (keymatch(arg, "verbose", 1)) { 470 if (keymatch(arg, "verbose", 1)) {
476 verbose++; 471 verbose++;
477 } else if (keymatch(arg, "raw", 1)) { 472 } else if (keymatch(arg, "raw", 1)) {
478 raw = 1; 473 raw = 1;
479 } else 474 } else
480 usage(); 475 usage();
481 } 476 }
482 477
483 /* Open the input file. */ 478 /* Open the input file. */
484 /* Unix style: expect zero or one file name */ 479 /* Unix style: expect zero or one file name */
485 if (argn < argc-1) { 480 if (argn < argc-1) {
486 fprintf(stderr, "%s: only one input file\n", progname); 481 fprintf(stderr, "%s: only one input file\n", progname);
487 usage(); 482 usage();
488 } 483 }
489 if (argn < argc) { 484 if (argn < argc) {
490 if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) { 485 if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {
491 fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]); 486 fprintf(stderr, "%s: can't open %s\n", progname, argv[argn]);
492 exit(EXIT_FAILURE); 487 exit(EXIT_FAILURE);
493 } 488 }
494 } else { 489 } else {
495 /* default input file is stdin */ 490 /* default input file is stdin */
496 #ifdef USE_SETMODE» » /* need to hack file mode? */ 491 #ifdef USE_SETMODE /* need to hack file mode? */
497 setmode(fileno(stdin), O_BINARY); 492 setmode(fileno(stdin), O_BINARY);
498 #endif 493 #endif
499 #ifdef USE_FDOPEN» » /* need to re-open in binary mode? */ 494 #ifdef USE_FDOPEN /* need to re-open in binary mode? */
500 if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) { 495 if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {
501 fprintf(stderr, "%s: can't open stdin\n", progname); 496 fprintf(stderr, "%s: can't open stdin\n", progname);
502 exit(EXIT_FAILURE); 497 exit(EXIT_FAILURE);
503 } 498 }
504 #else 499 #else
505 infile = stdin; 500 infile = stdin;
506 #endif 501 #endif
507 } 502 }
508 503
509 /* Scan the JPEG headers. */ 504 /* Scan the JPEG headers. */
510 (void) scan_JPEG_header(verbose, raw); 505 (void) scan_JPEG_header(verbose, raw);
511 506
512 /* All done. */ 507 /* All done. */
513 exit(EXIT_SUCCESS); 508 exit(EXIT_SUCCESS);
514 return 0;» » » /* suppress no-return-value warnings */ 509 return 0; /* suppress no-return-value warnings */
515 } 510 }
OLDNEW
« no previous file with comments | « rdjpgcom.1 ('k') | rdppm.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698