Index: rdjpgcom.1 =================================================================== RCS file: /usr/src/cvs/jpeg/rdjpgcom.1,v retrieving revision 1.1 diff -u -r1.1 rdjpgcom.1 --- rdjpgcom.1 2000/08/11 10:45:32 1.1 +++ rdjpgcom.1 2000/08/11 11:10:23 @@ -7,6 +7,12 @@ .B \-verbose ] [ +.B \-raw +] +[ +.B \-all +] +[ .I filename ] .LP @@ -29,6 +35,14 @@ Causes .B rdjpgcom to also display the JPEG image dimensions. +.TP +.B \-raw +Don't escape non-printing characters or translate carriage +returns to newlines. +.TP +.B \-all +Scan past the image data to reach comments that may have been placed +after it. This is significantly slower, so it's off by default. .PP Switch names may be abbreviated, and are not case sensitive. .SH HINTS Index: rdjpgcom.c =================================================================== RCS file: /usr/src/cvs/jpeg/rdjpgcom.c,v retrieving revision 1.1 diff -u -r1.1 rdjpgcom.c --- rdjpgcom.c 2000/08/11 10:45:35 1.1 +++ rdjpgcom.c 2000/08/11 11:12:45 @@ -116,6 +116,8 @@ #define M_SOF13 0xCD #define M_SOF14 0xCE #define M_SOF15 0xCF +#define M_RST0 0xd0 /* first restart marker */ +#define M_RST7 0xd7 /* last restart marker */ #define M_SOI 0xD8 /* Start Of Image (beginning of datastream) */ #define M_EOI 0xD9 /* End Of Image (end of datastream) */ #define M_SOS 0xDA /* Start Of Scan (begins compressed data) */ @@ -211,6 +213,21 @@ } +static int +skip_compressed(void) +{ + int ch, lch; + + lch = 0; + while ((ch = read_1_byte()) != EOF && + (lch != 0xff || 0 == ch || 0xff == ch || + (ch >= M_RST0 && ch <= M_RST7))) + lch = ch; + + return ch; +} + + /* * Process a COM marker. * We want to print out the marker contents as legible text; @@ -218,7 +235,7 @@ */ static void -process_COM (void) +process_COM (int raw) { unsigned int length; int ch; @@ -238,14 +255,14 @@ * while \ is converted to \\. * Newlines in CR, CR/LF, or LF form will be printed as one newline. */ - if (ch == '\r') { + if (ch == '\r' && !raw) { printf("\n"); - } else if (ch == '\n') { + } else if (ch == '\n' && !raw) { if (lastch != '\r') printf("\n"); - } else if (ch == '\\') { + } else if (ch == '\\' && !raw) { printf("\\\\"); - } else if (isprint(ch)) { + } else if (raw || isprint(ch)) { putc(ch, stdout); } else { printf("\\%03o", ch); @@ -253,7 +270,8 @@ lastch = ch; length--; } - printf("\n"); + if (!raw) + printf("\n"); } @@ -321,17 +339,19 @@ */ static int -scan_JPEG_header (int verbose) +scan_JPEG_header (int verbose, int raw, int all) { int marker; + int after_sos; /* Expect SOI at start of file */ if (first_marker() != M_SOI) ERREXIT("Expected SOI marker first"); - /* Scan miscellaneous markers until we reach SOS. */ + after_sos = 0; for (;;) { - marker = next_marker(); + marker = after_sos ? skip_compressed() : next_marker(); + after_sos = 0; switch (marker) { /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be, * treated as SOFn. C4 in particular is actually DHT. @@ -355,14 +375,19 @@ skip_variable(); break; - case M_SOS: /* stop before hitting compressed data */ - return marker; + case M_SOS: /* compressed data */ + if (!all) + return marker; + + skip_variable(); + after_sos = 1; + break; case M_EOI: /* in case it's a tables-only JPEG stream */ return marker; case M_COM: - process_COM(); + process_COM(raw); break; case M_APP12: @@ -371,7 +396,7 @@ */ if (verbose) { printf("APP12 contains:\n"); - process_COM(); + process_COM(raw); } else skip_variable(); break; @@ -399,6 +424,8 @@ fprintf(stderr, "Switches (names may be abbreviated):\n"); fprintf(stderr, " -verbose Also display dimensions of JPEG image\n"); + fprintf(stderr, " -raw Don't escape non-printable characters\n"); + fprintf(stderr, " -all Scan for comments after image data\n"); exit(EXIT_FAILURE); } @@ -438,7 +465,7 @@ { int argn; char * arg; - int verbose = 0; + int verbose = 0, raw = 0, all = 0; /* On Mac, fetch a command line. */ #ifdef USE_CCOMMAND @@ -457,6 +484,10 @@ arg++; /* advance over '-' */ if (keymatch(arg, "verbose", 1)) { verbose++; + } else if (keymatch(arg, "raw", 1)) { + raw++; + } else if (keymatch(arg, "all", 1)) { + all++; } else usage(); } @@ -488,7 +519,7 @@ } /* Scan the JPEG headers. */ - (void) scan_JPEG_header(verbose); + (void) scan_JPEG_header(verbose, raw, all); /* All done. */ exit(EXIT_SUCCESS);